0001 function external = load_externaldata_TCV_MultiTimes(workdir,opt_gui,style,remote)
0002
0003
0004
0005 diagnames = {'BT','IP','VLOOP','NE','TE','TI','ZEFF','ZAXIS','ECRH','EQUIL','HXR'};
0006
0007 shotdata = iget_datainput_TCV(diagnames,workdir,opt_gui,style);
0008
0009
0010
0011 datainput = struct;
0012 datainput.shot = shotdata.shotnum;
0013 if ~isempty(shotdata.times),
0014 datainput.t = shotdata.times;
0015 end
0016 datainput.dtres=[];
0017 if ~isempty(shotdata.dtmax),
0018 datainput.dtreslim = shotdata.dtmax;
0019 end
0020 if ~isempty(shotdata.outputdir),
0021 datainput.outputpath = shotdata.outputdir;
0022 end
0023 datainput.flagTPG = shotdata.flagTPG;
0024 datainput.flagFF = shotdata.flagFF;
0025
0026 if ~shotdata.flagHXR,
0027 diagnames(strcmp(diagnames,'HXR')) = [];
0028 end
0029
0030 if ~shotdata.flagZeff,
0031 diagnames(strcmp(diagnames,'ZEFF')) = [];
0032 end
0033
0034 ndiag = length(diagnames);
0035
0036 for idiag = 1:ndiag,
0037
0038 datainput.diag{idiag}.name = diagnames{idiag};
0039
0040 if strcmp(diagnames{idiag},'ECRH'),
0041 if ~isempty(shotdata.isel),
0042 datainput.diag{idiag}.isel = shotdata.isel;
0043 else
0044 datainput.diag{idiag}.isel = 1:6;
0045 end
0046 end
0047
0048 end
0049
0050 if ~isempty(remote),
0051 remote.funcopy = 0;
0052 end
0053
0054 [err,~,dataoutput] = matremote_jd('luke_get_trdata',{datainput},remote);
0055 if ~isempty(err),
0056 disperr_jd(err);
0057 external = '';
0058 return
0059 else
0060 disp(['Data successfully loaded for shot ',num2str(shotdata.shotnum)])
0061 end
0062
0063
0064
0065 external = struct;
0066 external.basestr = 'TCV';
0067 external.shotnum = num2str(shotdata.shotnum);
0068
0069
0070
0071 shotimes = dataoutput.te.time;
0072
0073 shotimes = intersect(shotimes,dataoutput.ne.time);
0074 if ~all(isnan(dataoutput.ti.data(:))),
0075 shotimes = intersect(shotimes,dataoutput.ti.time);
0076 else
0077 disp('No ti data');
0078 end
0079 if shotdata.flagZeff,
0080 shotimes = intersect(shotimes,dataoutput.zeff.time);
0081 end
0082 shotimes = intersect(shotimes,dataoutput.zaxis.time);
0083 shotimes = intersect(shotimes,dataoutput.ip.time);
0084 shotimes = intersect(shotimes,dataoutput.vloop.time);
0085
0086 nlaun = length(dataoutput.ecrh.isel);
0087
0088 for iisel = 1:nlaun,
0089 shotimes = intersect(shotimes,dataoutput.ecrh.ang{iisel}.time);
0090 shotimes = intersect(shotimes,dataoutput.ecrh.pow{iisel}.time);
0091 if isfield(dataoutput.ecrh,'xfrac'),
0092 shotimes = intersect(shotimes,dataoutput.ecrh.xfrac{iisel}.time);
0093 end
0094 if isfield(dataoutput.ecrh,'xfrac_FF'),
0095 shotimes = intersect(shotimes,dataoutput.ecrh.xfrac_FF{iisel}.time);
0096 end
0097 if isfield(dataoutput.ecrh,'xfrac_TPG'),
0098 shotimes = intersect(shotimes,dataoutput.ecrh.xfrac_TPG{iisel}.time);
0099 end
0100 if isfield(dataoutput.ecrh,'stray'),
0101 shotimes = intersect(shotimes,dataoutput.ecrh.stray{iisel}.time);
0102 end
0103 end
0104
0105 discnshotimes = setdiff(dataoutput.te.time,shotimes);
0106 if ~isempty(discnshotimes),
0107 disp(['WARNING : ',num2str(length(discnshotimes)),'/',num2str(length(dataoutput.te.time)),' times were discarded as they are missing from some diagnostics']);
0108 end
0109
0110 external.shotimes = shotimes;
0111 nt = length(external.shotimes);
0112
0113 Xfrac_FF = NaN(nt,nlaun);
0114 Xfrac_TPG = NaN(nt,nlaun);
0115
0116 for it = 1:nt,
0117 shotime = external.shotimes(it);
0118
0119 external.equil(it).basestr = external.basestr;
0120 external.equil(it).shotnum = external.shotnum;
0121 external.equil(it).shotime = shotime;
0122
0123 if isfield(dataoutput.equil,'eqdsk'),
0124 external.equil(it).magnetic.eqdsk = dataoutput.equil.eqdsk{it};
0125 elseif isfield(dataoutput.equil,'data') && isempty(remote),
0126 eqdsk_file = [dataoutput.equil.data,filesep,'eqdsk.',external.shotnum,'t',num2str(shotime,'%6.4f')];
0127 if exist(eqdsk_file,'file'),
0128 external.equil(it).magnetic.eqdsk = fileread(eqdsk_file);
0129 else
0130 error(['File ',eqdsk_file,' could not be found. Aborted.']);
0131 end
0132 else
0133 error('eqdsk data could not be retrieved. Aborted.');
0134 end
0135
0136 external.equil(it).prof.te = dataprocess(dataoutput.te,'te',shotime);
0137 external.equil(it).prof.ne = dataprocess(dataoutput.ne,'ne',shotime);
0138
0139 if all(isnan(dataoutput.ti.data(:))),
0140 external.equil(it).prof.ti = [];
0141 else
0142 external.equil(it).prof.ti = dataprocess(dataoutput.ti,'ti',shotime);
0143 end
0144
0145 if shotdata.flagZeff,
0146 external.equil(it).prof.zeff = dataprocess(dataoutput.zeff,'zeff',shotime);
0147 else
0148 external.equil(it).prof.zeff = NaN;
0149 end
0150
0151 external.equil(it).prof.zaxis = dataprocess(dataoutput.zaxis,'zaxis',shotime);
0152 external.equil(it).prof.ip = dataprocess(dataoutput.ip,'ip',shotime);
0153 external.equil(it).prof.btsign = dataoutput.btsign.data;
0154 external.equil(it).prof.ipsign = dataoutput.ipsign.data;
0155
0156 external.ohm(it).vloop = dataprocess(dataoutput.vloop,'vloop',shotime);
0157
0158 external.wave(it).laun = dataoutput.ecrh.isel;
0159 for iisel = 1:nlaun,
0160
0161 angles = selectfields_jd(dataoutput.ecrh.ang{iisel},{'freq','P1_R','P1_theta','P2_R','P2_d','P1_Z','P2_Z','P3_Z'});
0162
0163 angles.theta = dataprocess(dataoutput.ecrh.ang{iisel},'theta',shotime,'theta');
0164 angles.phi = dataprocess(dataoutput.ecrh.ang{iisel},'phi',shotime,'phi');
0165 angles.theta_eff = dataprocess(dataoutput.ecrh.ang{iisel},'theta_eff',shotime,'theta_eff');
0166 angles.phi_eff = dataprocess(dataoutput.ecrh.ang{iisel},'phi_eff',shotime,'phi_eff');
0167
0168 angles.P0 = dataprocess(dataoutput.ecrh.pow{iisel},'pow',shotime);
0169 if isfield(dataoutput.ecrh,'xfrac'),
0170 angles.Xfrac = dataprocess(dataoutput.ecrh.xfrac{iisel},'xfrac',shotime);
0171 end
0172 if isfield(dataoutput.ecrh,'xfrac_FF'),
0173 angles.Xfrac_FF = dataprocess(dataoutput.ecrh.xfrac_FF{iisel},'xfrac_FF',shotime);
0174 Xfrac_FF(it,iisel) = angles.Xfrac_FF;
0175 end
0176 if isfield(dataoutput.ecrh,'xfrac_TPG'),
0177 angles.Xfrac_TPG = dataprocess(dataoutput.ecrh.xfrac_TPG{iisel},'xfrac_TPG',shotime);
0178 Xfrac_TPG(it,iisel) = angles.Xfrac_TPG;
0179 end
0180 if isfield(dataoutput.ecrh,'stray'),
0181 angles.stray = dataprocess(dataoutput.ecrh.stray{iisel},'stray',shotime);
0182 end
0183
0184 external.wave(it).angles(iisel) = angles;
0185
0186 end
0187
0188 if shotdata.flagHXR,
0189 external.hxr = dataoutput.hxr;
0190 end
0191
0192 end
0193
0194 if ~isfield(angles,'Xfrac'),
0195 Xfrac_list{1} = 'FF code, mean Xfrac';
0196 Xfrac_list{2} = 'TPG code, mean Xfrac';
0197 for iisel = 1:nlaun,
0198 mask = ~isnan(Xfrac_FF(:,iisel));
0199 if ~any(mask),
0200 mXfrac_FF = NaN;
0201 else
0202 mXfrac_FF = mean(Xfrac_FF(mask,iisel));
0203 end
0204
0205 mask = ~isnan(Xfrac_TPG(:,iisel));
0206 if ~any(mask),
0207 mXfrac_TPG = NaN;
0208 else
0209 mXfrac_TPG = mean(Xfrac_TPG(mask,iisel));
0210 end
0211
0212 Xfrac_list{1} = [Xfrac_list{1},' : L',num2str(iisel),' = ',num2str(mXfrac_FF,'%0.2f')];
0213 Xfrac_list{2} = [Xfrac_list{2},' : L',num2str(iisel),' = ',num2str(mXfrac_TPG,'%0.2f')];
0214 end
0215
0216 Xfrac_opt = iselect_jd(Xfrac_list,'Which X mode fraction do you want to select ?',opt_gui,style.buttonselectstyle,1);
0217
0218 for it = 1:nt,
0219 for iisel = 1:nlaun,
0220 if Xfrac_opt == 1,
0221 external.wave(it).angles(iisel).Xfrac = external.wave(it).angles(iisel).Xfrac_FF;
0222 else
0223 external.wave(it).angles(iisel).Xfrac = external.wave(it).angles(iisel).Xfrac_TPG;
0224 end
0225 end
0226 end
0227
0228 end
0229
0230 external.id = ['TCV_',external.shotnum,'_MultiTimes'];
0231
0232 end
0233
0234 function dataout = dataprocess(datain,dataname,shotime,fname)
0235
0236 if nargin < 4,
0237 fname = 'data';
0238 end
0239
0240 itdata = datain.time == shotime;
0241 if any(itdata),
0242 if isfield(datain,'rho'),
0243 dataout = struct;
0244 dataout.rho = datain.rho;
0245 dataout.data = datain.(fname)(:,itdata);
0246 else
0247 dataout = datain.(fname)(itdata);
0248 end
0249 else
0250 error(['Time ',num2str(shotime),' not found in ',dataname,' data. aborted.']);
0251 end
0252
0253 end
0254
0255
0256
0257
0258
0259
0260
0261
0262
0263
0264
0265
0266
0267
0268
0269
0270
0271
0272
0273
0274
0275
0276
0277
0278
0279
0280
0281
0282
0283
0284
0285
0286
0287
0288
0289
0290
0291
0292
0293
0294
0295
0296
0297
0298
0299
0300
0301
0302
0303
0304
0305
0306
0307
0308
0309
0310
0311
0312
0313
0314
0315
0316
0317
0318
0319
0320
0321
0322
0323
0324
0325
0326
0327
0328
0329
0330
0331
0332
0333
0334
0335
0336
0337
0338
0339
0340
0341
0342
0343
0344
0345
0346
0347
0348
0349
0350
0351
0352
0353
0354
0355
0356
0357
0358
0359
0360
0361
0362
0363
0364
0365
0366
0367
0368
0369
0370
0371
0372
0373
0374
0375
0376
0377
0378
0379
0380
0381
0382
0383
0384
0385
0386
0387
0388
0389
0390
0391
0392
0393
0394
0395
0396