iluke_callbacks

PURPOSE ^

callbacks script for iluke

SYNOPSIS ^

This is a script file.

DESCRIPTION ^

 callbacks script for iluke

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 % callbacks script for iluke
0002 
0003 switch action
0004         %
0005     case 'redmine'
0006         %
0007         % Open the web page of redmine for LUKE
0008         %
0009         redmine_LUKE;
0010         %
0011      case 'help'
0012         %
0013         % Open the on-line help of LUKE
0014         %
0015         doc_LUKE;
0016         %
0017     case 'workdir'
0018         %
0019         % changing working directory
0020         %
0021         [pathname] = igetdir_jd(1,['Please select the working directory'],workdir);
0022         %
0023         if pathname ~= 0,
0024             %
0025             workdir = pathname;
0026             %
0027         end  
0028         %
0029         clear pathname
0030         %
0031     case 'import'
0032         %
0033         % importing from METIS or CRONOS simulation
0034         %
0035         sbase = 'before_luke@';
0036         filestr = [sbase,'*.mat'];
0037         %
0038         [filename,pathname] = igetfile_jd(1,filestr,['Please select the METIS/CRONOS ',sbase,' file(s)'],'',0);
0039         %
0040         %
0041         if filename ~= 0,
0042             %
0043             import = load([pathname,filename],'dkeparam','dkedisplay','equil','ohm','transpfaste','ripple','wavestructs');
0044             %
0045             iluke_import;
0046             curtime = 1;
0047             %
0048             clear import
0049             %
0050         end  
0051         %
0052         clear sbase filestr filename pathname
0053         %
0054         %
0055     case 'loadshot'
0056         %
0057         % loading simulation
0058         %
0059         filestr = 'LUKE_*.mat';
0060         %
0061         [filename,pathname] = igetfile_jd(1,filestr,['Please select the LUKE_DATA_*.mat or  LUKE_RESULTS_*.mat file'],'',0);
0062         %
0063         if filename ~= 0,
0064             %
0065             if ~isempty(fieldnames(load([pathname,filename],'lukeobjmod'))),
0066                 %
0067                 % iluke made LUKE_DATA_*.mat file
0068                 %
0069                 load([pathname,filename],'lukeobjmod','dkeparams','dkedisplay','external','equils','ohms','transpfastes','ripples','wavess','fluctparams','wavestructss','wavestructids','outputs','jobs','sdiags','hxr','status','tokamak','shotnum','shotimes');
0070                 lukeobj = conc_struct_jd(lukeobj,lukeobjmod);
0071                 %
0072                 iluke_updateoldsimul;
0073                 %
0074                 if length(shotimes) == 1,% only one time
0075                     curtime = 1;        
0076                 elseif length(shotimes) > 1,% more than one time
0077                     curtime = 0; 
0078                 else% no time
0079                     curtime = -1; 
0080                 end
0081                 %
0082                 iluke_initgraphs;% to initialize graphs according to loaded data
0083                 %
0084                 iluke_update;
0085                 %
0086                 lukeobj.simulfile.string = filename;%[pathname,filename];
0087                 %
0088                 status.data = 1;
0089                 %
0090                 clear lukeobjmod
0091                 %
0092                 if any(status.job > 0),
0093                     if sum(status.job > 0) == 1,% job started for one time only
0094                         curtime = find(status.job > 0);
0095                         iluke_update;
0096                     end
0097                     %
0098                     lukeobj.timeout.value = 1;
0099                     action = 'lukerun';iluke_callbacks;
0100                 else
0101                     lukeobj = iluke_info(lukeobj,'');% disable info display
0102                 end
0103                 %
0104             else
0105                 dataloaded = load([pathname,filename]);
0106                 %
0107                 % recent LUKE_RESULTS_*.mat file with lukestructs
0108                 %
0109                 if isfield(dataloaded,'lukestructs'),
0110                     %
0111                     import = dataloaded.lukestructs;
0112                     %
0113                     iluke_import;
0114                     %
0115                     clear import
0116                     %
0117                 end                    
0118                 %
0119                 clear dataloaded
0120                 %
0121             end
0122             %
0123             workdir = pathname;
0124             %
0125         end  
0126         %
0127         clear filestr filename pathname
0128         %
0129     case 'saveshot'
0130         %
0131         % saving simulation
0132         %
0133         sbase = 'LUKE_DATA';
0134         filestr = [sbase,'_*.mat'];
0135         %
0136         if ~isempty(lukeobj.lukeid.string),
0137             filename = [sbase,'_',lukeobj.lukeid.string,'.mat'];
0138         elseif ntimes == 0,
0139             filename = [sbase,'.mat'];
0140         elseif ntimes == 1 && ~isempty(equils{1}),
0141             filename = [sbase,'_',make_luke_simulid_jd(equils{1},ohms{1},transpfastes{1},ripples{1},wavess{1}),'.mat'];
0142         elseif ntimes == 1
0143             filename = [sbase,'_',tokamak,'_',shotnum,'_',lukeobj.shotimes.string{3},'.mat'];
0144         else
0145             filename = [sbase,'_',tokamak,'_',shotnum,'_MultiTimes.mat'];
0146         end
0147         %
0148         [filename,pathname] = iputfile_jd(1,filestr,['Please provide the ',sbase,' file name'],filename);
0149         %
0150         %
0151         if filename ~= 0,
0152             %
0153             % select fields to save and remote subfields handle
0154             %
0155             lukeobjmod = selectfields_jd(lukeobj,{'tokamak','shotnum','shotimes','data','equil','ohm','transp','ripple','wave','fluct','wavestruct','luke','sdiag','param','lukeid','timedep'});
0156             lukeobjmod = rmfields_jd(lukeobjmod,{'handle','position'},1);
0157             save([pathname,filename],'lukeobjmod','dkeparams','dkedisplay','external','equils','ohms','transpfastes','ripples','wavess','fluctparams','wavestructss','wavestructids','outputs','jobs','sdiags','hxr','status','tokamak','shotnum','shotimes');
0158             %
0159             lukeobj.simulfile.string = filename;%[pathname,filename];
0160             %
0161             status.data = 1;
0162             %
0163             clear lukeobjmod
0164             %
0165         end  
0166         %
0167         clear sbase filestr filename pathname
0168         %
0169     case 'dataimport'
0170         %
0171         % importing external data
0172         %
0173         lukeobj = iluke_info(lukeobj,'');% disable info display
0174         %
0175         if status.data == 2,
0176             opt_continue = iselect_jd({'No','Yes'},'This action will erase unsaved data. Do you want to continue ? ',lukeobj.infopanel.handle,style,1) - 1;
0177         else
0178             opt_continue = 1;
0179         end
0180         %
0181         if opt_continue,
0182             %
0183             newexternal = iload_externaldata_jd(dkepath,'',workdir,lukeobj.infopanel.handle,style);
0184             %
0185             if isfield(newexternal,'err'),
0186                 lukeobj.infotext.string = {'Error loading external data : ',newexternal.err};
0187             else
0188                 %
0189                 external = newexternal;
0190                 status.external = 1;
0191                 tokamak = external.basestr;
0192                 shotnum = external.shotnum;                
0193                 %
0194                 status.equil(:) = -1;
0195                 %
0196                 if isfield(external,'shotimes'),
0197                     external.times = external.shotimes;
0198                     curtime = 0; 
0199                 elseif isfield(external,'shotime'),
0200                     external.times = external.shotime;
0201                     curtime = 1;
0202                 else
0203                     error('shot time information missing from structure ''external''');
0204                 end                    
0205                 ntimes = length(external.times);
0206                 shotimes(end+1:end+ntimes) = external.times;
0207                 %
0208                 status.equil(end+1:end+ntimes) = 2;
0209                 equils(1,end+1:end+ntimes) = {[]};
0210                 %
0211             end
0212             %
0213             clear newexternal
0214             %
0215         end
0216         %
0217         clear opt_continue
0218         %
0219         lukeobj = iluke_info(lukeobj,'text');% enable info display
0220         %
0221     case 'dataload'
0222         %
0223         lukeobj = iluke_info(lukeobj,'');% disable info display
0224         %
0225         % loading external data
0226         %
0227         if status.data == 2,
0228             opt_continue = iselect_jd({'No','Yes'},'This action will erase unsaved data. Do you want to continue ? ',lukeobj.infopanel.handle,style,1) - 1;
0229         else
0230             opt_continue = 1;
0231         end
0232         %
0233         if opt_continue,
0234             %
0235             sbase = 'EXTERNAL';
0236             filestr = [sbase,'_*.mat'];
0237             %
0238             [filename,pathname] = igetfile_jd(1,filestr,['Please select the ',sbase,' file(s)'],'',0);
0239             %
0240             if filename ~= 0,
0241                 %
0242                 load([pathname,filename],'external');
0243                 %
0244                 status.external = 1;
0245                 tokamak = external.basestr;
0246                 shotnum = external.shotnum;   
0247                 %
0248                 status.equil(:) = -1;
0249                 %
0250                 external.pathname = pathname;
0251                 external.filename = filename;
0252                 %
0253                 if isfield(external,'shotimes'),
0254                     external.times = external.shotimes;
0255                     curtime = 0; 
0256                 elseif isfield(external,'shotime'),
0257                     external.times = external.shotime;
0258                     curtime = 1;
0259                 else
0260                     error('shot time information missing from structure ''external''');
0261                 end                    
0262                 ntimes = length(external.times);
0263                 shotimes(end+1:end+ntimes) = external.times;
0264                 %
0265                 status.equil(end+1:end+ntimes) = 2;
0266                 equils(1,end+1:end+ntimes) = {[]};
0267                 %
0268             end  
0269             %
0270             clear sbase filestr filename pathname
0271             %
0272         end
0273         %
0274         clear opt_continue
0275         %
0276         lukeobj = iluke_info(lukeobj,'text');% enable info display
0277         %
0278     case 'datasave'
0279         %
0280         % saving external data
0281         %
0282         sbase = 'EXTERNAL';
0283         filestr = [sbase,'_*.mat'];
0284         if isfield(external,'shotimes'),
0285             shotimestr = 'MultiTimes';
0286         elseif isfield(external,'shotime'),
0287             shotimestr = num2str(external.shotime,'%6.4f');
0288         end
0289         filename = [sbase,'_',external.basestr,'_',external.shotnum,'_',shotimestr,'.mat'];
0290         %
0291         [filename,pathname] = iputfile_jd(1,filestr,['Please provide the ',sbase,' file name'],filename);
0292         %
0293         if filename ~= 0,
0294             %
0295             save([pathname,filename],'external');
0296             %
0297             lukeobj.data.text.string = filename;%[pathname,filename];
0298         end  
0299         %
0300         clear sbase filestr filename pathname shotimestr
0301         %
0302     case 'dataclear'
0303         %
0304         % clearing external data
0305         %
0306         status.external = 0;
0307         status.equil(:) = -1;
0308         %
0309     case 'equilmake'
0310         %
0311         % creating equilibrium structure
0312         %
0313         lukeobj = iluke_info(lukeobj,'');% disable info display
0314         %
0315         select = struct;
0316         %
0317         select.style = style;
0318         %
0319         select.idequil = 1;
0320         select.disp = 1;
0321         select.print = 1;
0322         select.comp = 1;
0323         select.consist = 1;
0324         %
0325         if isfield(external,'equil'),% include data from external structure if available
0326             %
0327             if curtime == 0,% treat all times from external structure if available
0328                 [~,flag_shotimes,flag_external] = intersect(shotimes,external.times);
0329             elseif curtime > 0,% select one time from external structure if available
0330                 flag_external = find(external.times == shotimes(curtime));
0331                 flag_shotimes = curtime;
0332             else
0333                 flag_external = [];% no action
0334                 flag_shotimes = [];% no action
0335             end
0336             %
0337             external_equil = external.equil(flag_external);
0338             %
0339             clear flag_external
0340             %
0341         else
0342             %
0343             if curtime < 1,% new equil
0344                 flag_shotimes = [];
0345             else% replace existing
0346                 flag_shotimes = curtime;
0347             end
0348             %
0349             external_equil = [];% no external structure
0350             %
0351         end
0352         %
0353         if length(external_equil) > 1,% more than one time - case with curtime == 0 and external data with multiple times
0354             %
0355             mdce_mode = iselect_jd(dkepath.distprofiles,'Distribution of calc. : ',lukeobj.infopanel.handle,style.distselectstyle,1,'popupmenu') - 1;
0356             %
0357             if mdce_mode > 2,
0358                 mdce_mode = 2 - mdce_mode;%use of remcomputing with negative mdce_mode
0359             end
0360             %
0361             dkecluster = clustermode_luke(mdce_mode,'',dkepath);%MatLab distributed computing environment
0362             %
0363             select.i_opt = 0;
0364             %
0365             set(lukeobj.busy.handle,'Visible','on');drawnow;
0366             [flag,newequil] = mdce_run('imake_equil_jd',{dkepath,tokamak,'','',workdir,lukeobj.infopanel.handle,select},4,external_equil,dkecluster);
0367             set(lukeobj.busy.handle,'Visible','off');drawnow;
0368             %
0369             clear mdce_mode dkecluster flag 
0370             %
0371         else% treat one time
0372             %
0373             select.busyhandle = lukeobj.busy.handle;
0374             %
0375             newequil = imake_equil_jd(dkepath,tokamak,'',external_equil,workdir,lukeobj.infopanel.handle,select);
0376             %
0377         end
0378         %
0379         if isfield(newequil,'err'),
0380             lukeobj.infotext.string = {'Error creating equil structure(s) : ',newequil.err};
0381         else
0382             %
0383             if length(flag_shotimes) > 1,% more than one time - case with curtime == 0 and external data with multiple times
0384                 %
0385                 equils(1,flag_shotimes) = newequil.';
0386                 %
0387                 status.equil(:,flag_shotimes) = 1;
0388                 status.ohm(:,flag_shotimes) = 0;
0389                 status.transpfaste(:,flag_shotimes) = 0;
0390                 status.ripple(:,flag_shotimes) = 0;
0391                 status.waves(:,flag_shotimes) = 0;
0392                 status.wavestructs(:,flag_shotimes) = 0;
0393                 status.output(:,flag_shotimes) = 0;
0394                 %
0395             elseif length(flag_shotimes) == 1,% replace or fill an existing time
0396                 %
0397                 equils{1,flag_shotimes} = newequil;
0398                 %
0399                 status.equil(:,flag_shotimes) = 1;
0400                 status.ohm(:,flag_shotimes) = 0;
0401                 status.transpfaste(:,flag_shotimes) = 0;
0402                 status.ripple(:,flag_shotimes) = 0;
0403                 status.waves(:,flag_shotimes) = 0;
0404                 status.wavestructs(:,flag_shotimes) = 0;
0405                 status.output(:,flag_shotimes) = 0;
0406                 %
0407             else% new time
0408                 %
0409                 equils{1,end+1} = newequil;
0410                 status.equil(:,end+1) = 3;
0411                 shotimes(1,end+1) = equil.shotime;
0412                 %
0413                 curtime = length(shotimes);
0414                 %
0415             end
0416             %
0417             status.data = 2;
0418             %
0419             lukeobj.lukeid.string = '';
0420             %
0421             action = 'equildisp';iluke_callbacks;
0422             %
0423             clear flag_shotimes
0424             %
0425         end
0426         %
0427         lukeobj = iluke_info(lukeobj,'text');% enable info display
0428         %
0429         clear select newequil external_equil
0430         %
0431     case 'equilload'
0432         %
0433         % loading equil data
0434         %
0435         % if tokamak & shotnum are already specified (from external or existing equil),
0436         % it is required that times are loaded for the same tokamak & shotnum.
0437         % equils are added toor repacing existing shotimes
0438         %
0439         sbase = 'EQUIL';
0440         %
0441         if ~isempty(tokamak),
0442             filestr = [sbase,'_',tokamak];
0443         else
0444             filestr = sbase;
0445         end
0446         %
0447         if ~isempty(shotnum),
0448             filestr = [filestr,'_',shotnum,'_*.mat'];
0449         else
0450             filestr = [filestr,'_*.mat'];
0451         end
0452         %
0453         [filenames,pathname] = igetfile_jd(1,filestr,['Please select the ',sbase,' file(s)'],'',1);
0454         %
0455         if ischar(filenames),
0456             filenames = {filenames};
0457         end
0458         %
0459         nt = length(filenames);
0460         %
0461         for it = 1:nt,
0462             %
0463             load([pathname,filenames{it}],'equil');
0464             %
0465             equil = iluke_equilcorr(equil);
0466             if ~isempty(tokamak) && ~strcmp(tokamak,equil.tokamak),% shotimes are added to the same machine and shot number
0467                 continue
0468             elseif isempty(tokamak)
0469                 tokamak = equil.tokamak;
0470             end
0471             if ~isempty(shotnum) && ~strcmp(shotnum,equil.shotnum),
0472                 continue
0473             elseif isempty(shotnum)
0474                 shotnum = equil.shotnum;
0475             end
0476             %
0477             equil.filename = filenames{it};
0478             equil.pathnames = pathname;
0479             %
0480             equils{end+1} = equil;
0481             status.equil(end+1) = 3;
0482             shotimes(end+1) = equil.shotime;
0483             %
0484             status.data = 2;
0485             %
0486             lukeobj.lukeid.string = '';
0487             %
0488         end  
0489         %
0490         if nt > 1,
0491             curtime = 0;
0492         elseif nt == 1,
0493             curtime = length(shotimes);
0494         end
0495         %
0496         action = 'equildisp';iluke_callbacks;
0497         %
0498         clear sbase filestr filenames pathname it nt equil
0499         %
0500     case 'equilsave'
0501         %
0502         % saving EQUIL structure
0503         %
0504         lukeobj = iluke_info(lukeobj,'');% disable info display
0505         %
0506         % loading external data
0507         %
0508         if curtime == 0,
0509             opt_continue = iselect_jd({'No','Yes'},'Save each structure ''equil'' separately and automatically ? ',lukeobj.infopanel.handle,style,1) - 1;
0510         else
0511             opt_continue = 1;
0512         end
0513         %
0514         if opt_continue,
0515             %
0516             sbase = 'EQUIL';
0517             %
0518             if curtime == 0,
0519                 %
0520                 savetimes = find(status.equil == 1);
0521                 nt = length(savetimes);
0522                 filenames = cell(1,nt);
0523                 for it = 1:nt,
0524                     filenames{it} = [sbase,'_',equils{it}.id,'.mat'];
0525                 end
0526                 pathname = workdir;
0527                 %
0528             elseif curtime > 0 && status.equil(curtime) == 1,
0529                 %
0530                 filestr = [sbase,'_*.mat'];
0531                 %
0532                 filename = [sbase,'_',equils{curtime}.id,'.mat'];
0533                 %
0534                 [filename,pathname] = iputfile_jd(1,filestr,['Please provide the ',sbase,' file name'],filename);
0535                 %
0536                 if filename ~= 0,
0537                     savetimes = curtime;
0538                     filenames = {filename};
0539                 else
0540                     savetimes = [];
0541                 end
0542                 %
0543             else
0544                 savetimes = [];
0545             end
0546             %
0547             nt = length(savetimes);
0548             %
0549             for it = 1:nt,
0550                 %
0551                 equil = equils{savetimes(it)};
0552                 save([pathname,filenames{it}],'equil');
0553                 %
0554                 equils{savetimes(it)}.pathname = pathname;%[pathname,filename];
0555                 equils{savetimes(it)}.filename = filenames{it};%[pathname,filename];
0556             end  
0557             %
0558             clear sbase filestr filename filenames pathname nt it equil savetimes
0559             %
0560         end
0561         %
0562         clear opt_continue
0563         %
0564         lukeobj = iluke_info(lukeobj,'text');% enable info display
0565         %
0566     case 'equilclear'
0567         %
0568         % clearing equil structure
0569         %
0570         lukeobj = iluke_info(lukeobj,'');% disable info display
0571         %
0572         % loading external data
0573         %
0574         if curtime == 0,
0575             opt_continue = iselect_jd({'No','Yes'},'Clear all ''equil'' structures ? ',lukeobj.infopanel.handle,style,1) - 1;
0576         else
0577             opt_continue = 1;
0578         end
0579         %
0580         if opt_continue,
0581             %
0582             if curtime == 0,
0583                 cleartimes = find(status.equil == 1);
0584             elseif curtime > 0 && status.equil(curtime) == 1,
0585                 cleartimes = curtime;
0586                 curtime = 0;
0587             else
0588                 cleartimes = [];
0589             end
0590             %
0591             nt = length(cleartimes);
0592             for it = 1:nt,
0593                 %
0594                 if (~isempty(external) && isfield(external,'shotimes') && any(external.shotimes == shotimes(cleartimes(it))))...
0595                 || (~isempty(external) && isfield(external,'shotime') && external.shotime == shotimes(cleartimes(it))),
0596                     status.equil(cleartimes(it)) = 0;% keep time in shotimes
0597                 else
0598                     status.equil(cleartimes(it)) = -1;% remove time from shotimes
0599                 end
0600                 %
0601                 status.data = 2;
0602                 %
0603                 lukeobj.lukeid.string = '';
0604                 %
0605             end
0606             %
0607             clear cleartimes it nt 
0608             %
0609         end
0610         %
0611         clear opt_continue
0612         %
0613         lukeobj = iluke_info(lukeobj,'text');% enable info display
0614         %
0615     case 'equildisp'
0616         %
0617         % displaying equilibrium data
0618         %
0619         it_g = 2 + curtime;%<new>,<all>,...
0620         %
0621         lukeobj.plot1.gindex(it_g) = 0;
0622         lukeobj.plot2.gindex(it_g) = 0;
0623         lukeobj.plot3.gindex(it_g) = 0;
0624         %
0625         cleartags{it_g} = {'equil'};
0626         %
0627         iluke_update;% initialize display
0628         %
0629         newgraph1_handle = axes('Parent',lukeobj.plot1.handle,'units','pixels','Position',style.graph_position,'FontName',style.fontname,'FontUnits','pixels','FontSize',style.fontsize);% create new graphic objects with requested characteristics
0630         newgraph2_handle = axes('Parent',lukeobj.plot2.handle,'units','pixels','Position',style.graph_position,'FontName',style.fontname,'FontUnits','pixels','FontSize',style.fontsize);
0631         newgraph3_handle = axes('Parent',lukeobj.plot3.handle,'units','pixels','Position',style.graph_position,'FontName',style.fontname,'FontUnits','pixels','FontSize',style.fontsize); 
0632         %
0633         if curtime > 0,
0634             %
0635             equilibrium_jd(equils{curtime},NaN,3,'linear',10,[newgraph1_handle,newgraph2_handle,newgraph3_handle],style);
0636             %
0637             graphs(1) = iluke_graphs(lukeobj.plot1.handle,1,'magnetic equilibrium','equil',curtime);
0638             graphs(2) = iluke_graphs(lukeobj.plot2.handle,2,'temperature and density','equil',curtime);% includes legend
0639             graphs(3) = iluke_graphs(lukeobj.plot3.handle,1,'effective charge','equil',curtime);
0640             %
0641             if isfield(equils{curtime},'info') && isfield(equils{curtime}.info,'txt'),
0642                 lukeobj.infotext.string = equils{curtime}.info.txt;
0643             else
0644                 lukeobj.infotext.string = '';
0645             end
0646             %
0647             lukeobj = iluke_info(lukeobj,'text');% enable info display
0648             %
0649         else
0650             %
0651             luke_disp_equils_mt(equils,1,newgraph1_handle,style)
0652             luke_disp_equils_mt(equils,2,newgraph2_handle,style)
0653             luke_disp_equils_mt(equils,3,newgraph3_handle,style)
0654             %
0655             graphs(1) = iluke_graphs(lukeobj.plot1.handle,2,'temperature and density','equil');
0656             graphs(2) = iluke_graphs(lukeobj.plot2.handle,2,'magnetic field and current','equil');% includes legend
0657             graphs(3) = iluke_graphs(lukeobj.plot3.handle,2,'plasma shape','equil');
0658             %
0659         end
0660         %
0661         ngraphs = length(graphss{it_g});
0662         %
0663         graphss{it_g}(end+1:end+3) = graphs;
0664         %
0665         lukeobj.plot1.gindex(it_g) = ngraphs + 1;
0666         lukeobj.plot2.gindex(it_g) = ngraphs + 2;
0667         lukeobj.plot3.gindex(it_g) = ngraphs + 3;
0668         %
0669         clear it_g ngraphs newgraph1_handle newgraph2_handle newgraph3_handle  
0670         %
0671     case 'ohmmake'
0672         %
0673         % creating ohmic structure
0674         %
0675         lukeobj = iluke_info(lukeobj,'');% disable info display
0676         %
0677         select.style = style;
0678         %
0679         select.idohm = 1;
0680         %
0681         if isfield(external,'ohm'),% include data from external structure if available
0682             %
0683             if curtime == 0,% treat all times from external structure if available
0684                 flag_calc = find(status.ohm >= 0);
0685                 [~,flag_calctimes,flag_external] = intersect(shotimes(flag_calc),external.times);
0686                 flag_shotimes = flag_calc(flag_calctimes);
0687             elseif curtime > 0,% select one time from external structure if available
0688                 flag_external = find(external.times == shotimes(curtime));
0689                 flag_shotimes = curtime;
0690             else
0691                 flag_external = [];% no action
0692                 flag_shotimes = [];% no action
0693             end
0694             %
0695             external_ohm = external.ohm(flag_external);
0696             nt = length(external_ohm);
0697             %
0698             for it = 1:nt,
0699                  external_ohm(it).equil = equils{flag_shotimes(it)};% for distributed computing
0700             end
0701             %
0702             clear flag_external flag_calc flag_calctimes it nt
0703             %
0704         else
0705             %
0706             if curtime < 1,% no action
0707                 flag_shotimes = [];
0708             else% replace existing
0709                 flag_shotimes = curtime;
0710             end
0711             %
0712             external_ohm = [];% no external structure
0713             %
0714         end
0715         %
0716         if length(flag_shotimes) > 1,% more than one time - case with curtime == 0 and external data with multiple times
0717             %
0718             mdce_mode = iselect_jd(dkepath.distprofiles,'Distribution of calc. : ',lukeobj.infopanel.handle,style.distselectstyle,1,'popupmenu') - 1;
0719             %
0720             if mdce_mode > 2,
0721                 mdce_mode = 2 - mdce_mode;%use of remcomputing with negative mdce_mode
0722             end
0723             %
0724             dkecluster = clustermode_luke(mdce_mode,'',dkepath);%MatLab distributed computing environment
0725             %
0726             select.i_opt = 0;
0727             %
0728             set(lukeobj.busy.handle,'Visible','on');drawnow;
0729             [flag,newohm] = mdce_run('imake_ohm_jd',{dkepath,tokamak,'','',workdir,lukeobj.infopanel.handle,select},4,external_ohm,dkecluster);
0730             set(lukeobj.busy.handle,'Visible','off');drawnow;
0731             %
0732             clear mdce_mode dkecluster flag 
0733             %
0734         elseif length(flag_shotimes) == 1% treat one time
0735             %
0736             newohm = imake_ohm_jd(dkepath,tokamak,equils{flag_shotimes},external_ohm,workdir,lukeobj.infopanel.handle,select);
0737             %
0738         else
0739             newohm = [];
0740         end
0741         %
0742         if isfield(newohm,'err'),
0743             lukeobj.infotext.string = {'Error creating structure(s) ''ohm'' : ',newohm.err};
0744         elseif ~isempty(newohm),
0745             %
0746             if length(flag_shotimes) > 1,% more than one time - case with curtime == 0 and external data with multiple times
0747                 %
0748                 ohms(flag_shotimes) = newohm.';
0749                 %
0750             elseif length(flag_shotimes) == 1,% replace or fill an existing time
0751                 %
0752                 ohms{flag_shotimes} = newohm;
0753                 %
0754             end
0755             %
0756             status.ohm(flag_shotimes) = 1;
0757             %
0758             status.data = 2;
0759             %
0760             lukeobj.lukeid.string = '';
0761             %
0762             action = 'ohmdisp';iluke_callbacks;
0763             %
0764             clear flag_shotimes
0765             %
0766         end
0767         %
0768         clear select newohm external_ohm
0769         %
0770         lukeobj = iluke_info(lukeobj,'text');% enable info display
0771         %
0772     case 'ohmload'
0773         %
0774         % loading ohm data
0775         %
0776         sbase = 'OHM';
0777         filestr = [sbase,'_*.mat'];
0778         %
0779         [filename,pathname] = igetfile_jd(1,filestr,['Please select the ',sbase,' file(s)'],'',0);
0780         %
0781         %
0782         if filename ~= 0,
0783             %
0784             load([pathname,filename],'ohm');
0785             %
0786             lukeobj.ohm.text.string = filename;%[pathname,filename];
0787             %
0788             status.ohm = 1;
0789             status.data = 2;
0790             %
0791             lukeobj.lukeid.string = '';
0792             %
0793             action = 'ohmdisp';iluke_callbacks;
0794             %
0795         end  
0796         %
0797         clear sbase filestr filename pathname
0798         %
0799     case 'ohmsave'
0800         %
0801         % saving OHM structure
0802         %
0803         sbase = 'OHM';
0804         filestr = [sbase,'_*.mat'];
0805         filename = [sbase,'_',equil.id,'_',ohm.id,'.mat'];
0806         %
0807         [filename,pathname] = iputfile_jd(1,filestr,['Please provide the ',sbase,' file name'],filename);
0808         %
0809         %
0810         if filename ~= 0,
0811             %
0812             save([pathname,filename],'ohm');
0813             %
0814             lukeobj.ohm.text.string = filename;%[pathname,filename];
0815         end  
0816         %
0817     case 'ohmclear'
0818         %
0819         % clearing ohm structure
0820         %
0821         lukeobj = iluke_info(lukeobj,'');% disable info display
0822         %
0823         % loading external data
0824         %
0825         if curtime == 0,
0826             opt_continue = iselect_jd({'No','Yes'},'Clear all ''ohm'' structures ? ',lukeobj.infopanel.handle,style,1) - 1;
0827         else
0828             opt_continue = 1;
0829         end
0830         %
0831         if opt_continue,
0832             %
0833             if curtime == 0,
0834                 cleartimes = find(status.ohm == 1);
0835             elseif curtime > 0 && status.ohm(curtime) == 1,
0836                 cleartimes = curtime;
0837             else
0838                 cleartimes = [];
0839             end
0840             %
0841             nt = length(cleartimes);
0842             for it = 1:nt,
0843                 %
0844                 status.ohm(cleartimes(it)) = 0;% clear structure
0845                 %
0846                 status.data = 2;
0847                 %
0848                 lukeobj.lukeid.string = '';
0849                 %
0850             end
0851             %
0852             clear cleartimes it nt 
0853             %
0854         end
0855         %
0856         clear opt_continue
0857         %
0858     case 'ohmdisp'
0859         %
0860         % displaying ohm data
0861         %
0862         it_g = 2 + curtime;%<new>,<all>,...
0863         %
0864         lukeobj.plot1.gindex(it_g) = 0;
0865         lukeobj.plot2.gindex(it_g) = 0;
0866         %
0867         cleartags{it_g} = {'ohm'};
0868         %
0869         iluke_update;% initialize display
0870         %
0871         newgraph1_handle = axes('Parent',lukeobj.plot1.handle,'units','pixels','Position',style.graph_position,'FontName',style.fontname,'FontUnits','pixels','FontSize',style.fontsize);% create new graphic objects with requested characteristics
0872         newgraph2_handle = axes('Parent',lukeobj.plot2.handle,'units','pixels','Position',style.graph_position,'FontName',style.fontname,'FontUnits','pixels','FontSize',style.fontsize);
0873         %
0874         if curtime > 1
0875             %
0876             graph_ohm_jd(equils{curtime},ohms{curtime},[newgraph1_handle,newgraph2_handle],style);
0877             %
0878             graphs(1) = iluke_graphs(lukeobj.plot1.handle,1,'loop voltage','ohm');
0879             graphs(2) = iluke_graphs(lukeobj.plot2.handle,1,'critical field','ohm');
0880             %
0881             if isfield(ohms{curtime},'info') && isfield(ohms{curtime}.info,'txt'),
0882                 lukeobj.infotext.string = ohms{curtime}.info.txt;
0883             else
0884                 lukeobj.infotext.string = '';
0885             end
0886             %
0887             lukeobj = iluke_info(lukeobj,'text');% enable info display
0888             %
0889         else
0890             %
0891             luke_disp_ohms_mt(equils(status.ohm == 1),ohms(status.ohm == 1),[newgraph1_handle,newgraph2_handle],style)
0892             %
0893             graphs(1) = iluke_graphs(lukeobj.plot1.handle,2,'center and edge loop voltage','ohm');
0894             graphs(2) = iluke_graphs(lukeobj.plot2.handle,2,'center and edge critical field','ohm');
0895             %
0896         end
0897         %
0898         ngraphs = length(graphss{it_g});
0899         %
0900         graphss{it_g}(end+1:end+2) = graphs;
0901         %
0902         lukeobj.plot1.gindex(it_g) = ngraphs + 1;
0903         lukeobj.plot2.gindex(it_g) = ngraphs + 2;
0904         %
0905         clear it_g ngraphs newgraph1_handle
0906         %
0907     case 'transpmake'
0908         %
0909         % creating transpfaste structure
0910         %
0911         % This section anticipates future transport modeling - disabled for now
0912         %
0913         lukeobj = iluke_info(lukeobj,'');% disable info display
0914         %
0915         select.style = style;
0916         %
0917         if isfield(external,'transpfaste'),% include data from external structure if available
0918             %
0919             if curtime == 0,% treat all times from external structure if available
0920                 flag_calc = find(status.transpfaste >= 0);
0921                 [~,flag_calctimes,flag_external] = intersect(shotimes(flag_calc),external.times);
0922                 flag_shotimes = flag_calc(flag_calctimes);
0923             elseif curtime > 0,% select one time from external structure if available
0924                 flag_external = find(external.times == shotimes(curtime));
0925                 flag_shotimes = curtime;
0926             else
0927                 flag_external = [];% no action
0928                 flag_shotimes = [];% no action
0929             end
0930             %
0931             external_transp = external.transpfaste(flag_external);
0932             nt = length(external_transp);
0933             %
0934             for it = 1:nt,
0935                  external_transp(it).equil = equils{flag_shotimes(it)};% for distributed computing
0936             end
0937             %
0938             clear flag_external flag_calc flag_calctimes it nt
0939             %
0940         else
0941             %
0942             if curtime < 1,% no action
0943                 flag_shotimes = [];
0944             else% replace existing
0945                 flag_shotimes = curtime;
0946             end
0947             %
0948             external_transp = [];% no external structure
0949             %
0950         end
0951         %
0952         if length(flag_shotimes) > 1,% more than one time - case with curtime == 0 and external data with multiple times
0953             %
0954             mdce_mode = iselect_jd(dkepath.distprofiles,'Distribution of calc. : ',lukeobj.infopanel.handle,style.distselectstyle,1,'popupmenu') - 1;
0955             %
0956             if mdce_mode > 2,
0957                 mdce_mode = 2 - mdce_mode;%use of remcomputing with negative mdce_mode
0958             end
0959             %
0960             dkecluster = clustermode_luke(mdce_mode,'',dkepath);%MatLab distributed computing environment
0961             %
0962             select.i_opt = 0;
0963             %
0964             set(lukeobj.busy.handle,'Visible','on');drawnow;
0965 %             [flag,newtranspfaste] = mdce_run('imake_transp_jd',{dkepath,tokamak,'','',workdir,lukeobj.infopanel.handle,select},4,external_transp,dkecluster);
0966             [flag,newtranspfaste] = mdce_run('imake_transp_jd',{dkepath,tokamak,'','',workdir,true,select},4,external_transp,dkecluster);
0967             set(lukeobj.busy.handle,'Visible','off');drawnow;
0968             %
0969             clear mdce_mode dkecluster flag 
0970             %
0971         elseif length(flag_shotimes) == 1% treat one time
0972             %
0973 %             newtranspfaste = imake_transp_jd(dkepath,tokamak,equils{flag_shotimes},external_transp,workdir,lukeobj.infopanel.handle,select);
0974             newtranspfaste = imake_transp_jd(dkepath,tokamak,equils{flag_shotimes},external_transp,workdir,true,select);
0975             %
0976         else
0977             newtranspfaste = [];
0978         end
0979         %
0980         if isfield(newtranspfaste,'err'),
0981             lukeobj.infotext.string = {'Error creating structure(s) ''transpfaste'' : ',newtranspfaste.err};
0982         elseif ~isempty(newtranspfaste),
0983             %
0984             if length(flag_shotimes) > 1,% more than one time - case with curtime == 0 and external data with multiple times
0985                 %
0986                 transpfastes(flag_shotimes) = newtranspfaste.';
0987                 %
0988             elseif length(flag_shotimes) == 1,% replace or fill an existing time
0989                 %
0990                 transpfastes{flag_shotimes} = newtranspfaste;
0991                 %
0992             end
0993             %
0994             status.transpfaste(flag_shotimes) = 1;
0995             %
0996             status.data = 2;
0997             %
0998             lukeobj.lukeid.string = '';
0999             %
1000             action = 'transpdisp';iluke_callbacks;
1001             %
1002             clear flag_shotimes
1003             %
1004         end
1005         %
1006         clear select newtranspfastes external_transp
1007 %         %
1008 %         select.table = 1;
1009 %         %
1010 %         %newtranspfaste = imake_transp_jd('','','','','',lukeobj.infopanel.handle,select);
1011 %         newtranspfaste = imake_transp_jd('','','','','',true,select);
1012 %         %
1013 %         if isfield(transpfaste,'err'),
1014 %             lukeobj.infotext.string = {'Error creating transpfaste structure : ',transpfaste.err};
1015 %             transpfaste = '';
1016 %         else
1017 %             %
1018 %             lukeobj.transp.text.string = '< not saved >';
1019 %             %
1020 %             status.transpfaste = 1;
1021 %             status.data = 2;
1022 %             %
1023 %             lukeobj.lukeid.string = '';
1024 %             %
1025 %             action = 'transpdisp';iluke_callbacks;
1026 %             %
1027 %         end
1028         %
1029         lukeobj = iluke_info(lukeobj,'text');% enable info display
1030         %
1031     case 'transpmodify'
1032         %
1033         % modifying transport parameters
1034         %
1035         if curtime > 0,
1036             transpfaste = transpfastes{curtime};
1037         else
1038             transpfaste = transpfastes{1};
1039         end  
1040         %
1041         if isfield(transpfaste,'orig'),
1042             orig = transpfaste.orig;
1043         else
1044             orig = transpfaste;
1045         end
1046         %
1047         [transpfaste,mod] = imod_struct_jd(transpfaste,'transpfaste',1,true,struct,style);
1048         %
1049         if any(mod),
1050             %
1051             if curtime > 0,
1052                 transpfastes{curtime} = transpfaste;
1053                 %
1054                 transpfastes{curtime}.orig = orig;
1055             else
1056                 for it = 1:ntimes,
1057                     transpfastes{it} = transpfaste;
1058                     %
1059                     transpfastes{it}.orig = orig;
1060                 end
1061                 %
1062                 clear it
1063             end
1064             %
1065             status.data = 2;
1066             %
1067         end
1068         %
1069         clear transpfaste orig mod
1070         %
1071     case 'transpload'
1072         %
1073         % loading transport parameters
1074         %
1075         sbase = 'TRANSP';
1076         filestr = [sbase,'_*.mat'];
1077         %
1078         if curtime > 0,
1079             transp_id = transpfastes{curtime}.id;
1080         else
1081             transp_id = transpfastes{1}.id;
1082         end
1083         pathname = fileparts(which(['TRANSP_',transp_id,'.mat']));
1084         %
1085         [filename,pathname] = igetfile_jd(1,filestr,['Please select the ',sbase,' file(s)'],pathname,0);
1086         %
1087         if filename ~= 0,
1088             %
1089             load([pathname,filename],'transpfaste');
1090             %
1091             if curtime > 0,
1092                 transpfastes{curtime} = transpfaste;
1093             else
1094                 for it = 1:ntimes,
1095                     transpfastes{it} = transpfaste;
1096                 end
1097                 %
1098                 clear it
1099             end
1100         end  
1101         %
1102         action = 'transpdisp';iluke_callbacks;
1103         %
1104         clear sbase filestr filename pathname transpfaste transp_id
1105         %
1106     case 'transpsave'
1107         %
1108         % saving transport parameters
1109         %
1110         if curtime > 0,
1111             transpfaste = transpfastes{curtime};
1112         else
1113             transpfaste = transpfastes{1};
1114         end  
1115         %
1116         sbase = 'TRANSP';
1117         filestr = [sbase,'_*.mat'];
1118         filename = [sbase,'_',transpfaste.id,'.mat'];
1119         %
1120         [filename,pathname] = iputfile_jd(1,filestr,['Please provide the ',sbase,' file name'],filename);
1121         %
1122         %
1123         if filename ~= 0,
1124             %
1125             save([pathname,filename],'transpfaste');
1126             %
1127         end  
1128         %
1129         clear transpfaste sbase filestr filename pathname 
1130         %
1131      case 'transpreset'
1132         %
1133         % resetting transport parameters
1134         %
1135         if curtime > 0,
1136             transpfastes{curtime} = transpfastes{curtime}.orig;
1137         else
1138             for it = 1:ntimes,
1139                 transpfastes{it} = transpfastes{it}.orig;
1140             end
1141             %
1142             clear it
1143         end
1144         %
1145     case 'transpdisp'
1146         %
1147         % displaying transpfaste data
1148         %
1149         it_g = 2 + curtime;%<new>,<all>,...
1150         %
1151         lukeobj.plot1.gindex(it_g) = 0;
1152         lukeobj.plot2.gindex(it_g) = 0;
1153         %
1154         cleartags{it_g} = {'transpfaste'};
1155         %
1156         iluke_update;% initialize display
1157         %
1158         newgraph1_handle = axes('Parent',lukeobj.plot1.handle,'units','pixels','Position',style.graph_position,'FontName',style.fontname,'FontUnits','pixels','FontSize',style.fontsize);% create new graphic objects with requested characteristics
1159         newgraph2_handle = axes('Parent',lukeobj.plot2.handle,'units','pixels','Position',style.graph_position,'FontName',style.fontname,'FontUnits','pixels','FontSize',style.fontsize);
1160         %
1161         if curtime > 1,
1162             %
1163             graph_transp_jd(equils{curtime},transpfastes{curtime},[newgraph1_handle,newgraph2_handle],style);
1164             %
1165             graphs(1) = iluke_graphs(lukeobj.plot1.handle,1,'radial diffusion','transpfaste');
1166             graphs(2) = iluke_graphs(lukeobj.plot2.handle,1,'radial pinch','transpfaste');% includes legend
1167             %
1168             if isfield(transpfastes{curtime},'info') && isfield(transpfastes{curtime}.info,'txt'),
1169                 lukeobj.infotext.string = transpfastes{curtime}.info.txt;
1170             else
1171                 lukeobj.infotext.string = '';
1172             end
1173             %
1174             lukeobj = iluke_info(lukeobj,'text');% enable info display
1175             %
1176         else
1177             %
1178             clear it_g newgraph1_handle newgraph2_handle action           
1179             %
1180             error('Not yet implemented')
1181             %
1182         end
1183         %
1184         ngraphs = length(graphss{it_g});
1185         %
1186         graphss{it_g}(end+1:end+2) = graphs;
1187         %
1188         lukeobj.plot1.gindex(it_g) = ngraphs + 1;
1189         lukeobj.plot2.gindex(it_g) = ngraphs + 2;
1190         %
1191         clear it_g ngraphs newgraph1_handle newgraph2_handle 
1192         %
1193     case 'fluctmodify'
1194         %
1195         % modify fluct parameters
1196         %
1197         if curtime > 0,
1198             fluctparam = fluctparams{curtime};
1199         else
1200             fluctparam = fluctparams{1};
1201         end  
1202         %
1203         if isfield(fluctparam,'orig'),
1204             orig = fluctparam.orig;
1205         else
1206             orig = fluctparam;
1207         end
1208         %
1209         [fluctparam,mod] = imod_struct_jd(fluctparam,'fluctparam',1,true,struct,style);
1210         %
1211         if any(mod),
1212             %
1213             if curtime > 0,
1214                 fluctparams{curtime} = fluctparam;
1215                 fluctparams{curtime}.orig = orig;
1216                 status.fluct(curtime) = 2;%recalculate equil
1217                 status.waves(curtime) = 0;%waves are outdated
1218             else
1219                 for it = 1:ntimes,
1220                     fluctparams{it} = fluctparam;
1221                     fluctparams{it}.orig = orig;
1222                     status.fluct(it) = 2;%recalculate equil
1223                     status.waves(it) = 0;%waves are outdated
1224                 end
1225                 %
1226                 clear it
1227             end
1228             %
1229             if isfield(fluctparam,'id')
1230                 lukeobj.fluct.text.string = fluctparam.id;
1231             else
1232                 lukeobj.fluct.text.string = '< not saved >';
1233             end
1234             %
1235             status.data = 2;
1236             %
1237         end
1238         %
1239         clear fluctparam orig mod
1240         %
1241     case 'fluctload'
1242         %
1243         % loading fluct parameters
1244         %
1245         lukeobj = iluke_info(lukeobj,'');% disable info display
1246         %
1247         sbase = 'FLUCT';
1248         filestr = [sbase,'_*.mat'];
1249         %
1250         [filename,pathname] = igetfile_jd(1,filestr,['Please select the ',sbase,' file(s)'],'',0);
1251         %
1252         if filename ~= 0,
1253             %
1254             data = load([pathname,filename],'fluctparam');
1255             %
1256             if ~isfield(data.fluctparam,'itnmax'),
1257                 itnmax = iselect_jd({},...
1258                     'Number of fluctuating states',...
1259                     lukeobj.infopanel.handle,style.editselectstyle,300,'edit');
1260 %                     'Do you want to specify the number of fluctuating states (for statistics), i.e. [300]? Enter [0] to calculate from dkeparam.tn.',...
1261 %                     lukeobj.infopanel.handle,style.editselectstyle,300,'edit');
1262                 if itnmax > 0,
1263                     data.fluctparam.itnmax = itnmax;
1264                 end
1265                 clear itnmax
1266             end
1267             %
1268             if curtime > 0,
1269                 fluctparams{curtime} = data.fluctparam;
1270                 status.fluct(curtime) = 2;%recalculate equil
1271                 status.waves(curtime) = 0;%waves are outdated
1272             else
1273                 for it = 1:ntimes,
1274                     fluctparams{it} = data.fluctparam;
1275                     status.fluct(it) = 2;%recalculate equil
1276                     status.waves(it) = 0;%waves are outdated
1277                 end
1278                 %
1279                 clear it
1280             end
1281             %
1282             if isfield(data.fluctparam,'id')
1283                 lukeobj.fluct.text.string = data.fluctparam.id;
1284             else
1285                 lukeobj.fluct.text.string = filename;%[pathname,filename];
1286             end
1287             %
1288             status.data = 2;
1289             %
1290             clear data
1291             %
1292         end  
1293         %
1294         clear sbase filestr filename pathname
1295         %
1296         lukeobj = iluke_info(lukeobj,'c3po');% enable c3po display
1297         %
1298     case 'wavestructimport'
1299         %
1300         % creating wavestruct structure from external
1301         %
1302         lukeobj = iluke_info(lukeobj,'');% disable info display
1303         %
1304         iluke_wavestructsimport;
1305         %
1306         action = 'wavemake';iluke_callbacks;
1307         %
1308     case 'wavestructmake'
1309         %
1310         % creating wavestruct structure from scratch
1311         %
1312         lukeobj = iluke_info(lukeobj,'');% disable info display
1313         %
1314         select = struct;
1315         select.style = style;
1316         %
1317         if curtime > 0,
1318             %
1319             flag_shotimes = curtime;
1320             %
1321             launchs{1} = imake_launch_jd(dkepath,tokamak,equils{curtime},'',workdir,lukeobj.infopanel.handle,select);
1322             %
1323         else
1324             %
1325             flag_shotimes = find(status.equil == 1);
1326             %
1327             clear flag_calc flag_calctimes
1328             %
1329             signs.ip = sign(equils{1}.psi_apRp(end));
1330             signs.b0 = sign(equils{1}.ptBPHI(1,1));
1331             %
1332             launchs{1} = imake_launch_jd(dkepath,tokamak,signs,'',workdir,lukeobj.infopanel.handle,select);
1333             %
1334             launchs = repmat(launchs,[1,length(flag_shotimes)]);
1335             %
1336             clear signs
1337             %
1338         end           
1339         %
1340         iluke_newwavestructs;% update wavestructs, status and wavestructids
1341         %
1342         clear select launchs flag_shotimes
1343         %
1344         lukeobj = iluke_info(lukeobj,'c3po');% enable c3po display
1345         %
1346     case 'wavestructload'
1347         %
1348         % loading wavestruct data
1349         %
1350         sbase = 'WAVESTRUCT';
1351         filestr = [sbase,'_*.mat'];
1352         %
1353         [filename,pathname] = igetfile_jd(1,filestr,['Please select the ',sbase,' file(s)'],'',0);
1354         %
1355         %
1356         if filename ~= 0,
1357             %
1358             load([pathname,filename],'wavestruct');
1359             %
1360             if isfield(wavestruct.launch,'aloha'),
1361                 wavestruct.launch.spectrum = wavestruct.launch.aloha;
1362                 wavestruct.launch = rmfield(wavestruct.launch,'aloha');
1363             end
1364             %
1365             if ~isfield(wavestruct,'equil'),
1366                 wavestruct.equil = equil;
1367             end
1368             %
1369             wavestructs{end+1} = wavestruct;
1370             %
1371             lukeobj.wavestruct.select.value = length(wavestructs);
1372             %
1373             status.data = 2;
1374             %
1375             clear wavestruct
1376             %
1377         end  
1378         %
1379         clear sbase filestr filename pathname
1380         %
1381     case 'wavestructsave'
1382         %
1383         % saving wavestruct structure
1384         %
1385         wavestruct = wavestructs{lukeobj.wavestruct.select.value};
1386         %
1387         sbase = 'WAVESTRUCT';
1388         filestr = [sbase,'_*.mat'];
1389         filename = [sbase,'_',equil.id,'_',wavestruct.id,'.mat'];
1390         %
1391         [filename,pathname] = iputfile_jd(1,filestr,['Please provide the ',sbase,' file name'],filename);
1392         %
1393         %
1394         if filename ~= 0,
1395             %
1396             save([pathname,filename],'wavestruct');
1397             %
1398         end  
1399         %
1400         clear wavestruct sbase filestr filename pathname
1401         %
1402     case 'wavestructclear'
1403         %
1404         % clearing wavestruct structure (s)
1405         %
1406         lukeobj = iluke_info(lukeobj,'');% disable info display
1407         %
1408         if curtime == 0,
1409             iw_curtime = 1:length(wavestructids);
1410             opt_continue = iselect_jd({'No','Yes'},['Clear all ''wavestruct'' structures labeled ',lukeobj.wavestruct.select.string{lukeobj.wavestruct.select.value},' ? '],lukeobj.infopanel.handle,style,1) - 1;
1411         else
1412             iw_curtime = find(status.wavestructs(:,curtime) == 1);
1413             opt_continue = 1;
1414         end
1415         %
1416         iw = iw_curtime(lukeobj.wavestruct.select.value);% current index in wavestructss
1417         %
1418         if opt_continue,
1419             %
1420             status.data = 2;
1421             %
1422             if curtime == 0,
1423                 status.wavestructs(iw,:) = 0;
1424             else
1425                 status.wavestructs(iw,curtime) = 0;
1426             end
1427             %
1428         end
1429         %
1430         clear opt_continue iw_curtime iw
1431         %
1432         lukeobj = iluke_info(lukeobj,'c3po');% enable info display
1433         %
1434     case 'anglesmodify'
1435         %
1436         % modifying angles data
1437         %
1438         lukeobj = iluke_info(lukeobj,'');% disable info display
1439         %
1440         if curtime == 0,
1441             iw_curtime = 1:length(wavestructids);
1442         else
1443             iw_curtime = find(status.wavestructs(:,curtime) == 1);
1444         end
1445         iw = iw_curtime(lukeobj.wavestruct.select.value);% current index in wavestructss
1446         %
1447         angles = wavestructss{iw,curtime}.launch.angles;
1448         if isfield(angles,'orig'),
1449             orig = angles.orig;
1450             angles = rmfield(angles,'orig');
1451         else
1452             orig = angles;
1453         end
1454         %
1455         angles.frequency_GHz = angles.freq/1e9;
1456         angles.P0_kW = angles.P0/1e3;
1457         angles.theta_deg = angles.theta*180/pi;
1458         angles.phi_deg = angles.phi*180/pi;
1459         angles.P1_theta_deg = angles.P1_theta*180/pi;
1460         %
1461         [angles,mod] = imod_struct_jd(rmfield(angles,{'freq','P0','theta','phi','P1_theta'}),'angles',1,true,struct,style);%lukeobj.infopanel.handle
1462         %
1463         if any(mod),
1464             angles.freq = angles.frequency_GHz*1e9;
1465             angles.P0 = angles.P0_kW*1e3;
1466             angles.theta = angles.theta_deg*pi/180;
1467             angles.phi = angles.phi_deg*pi/180;
1468             angles.P1_theta = angles.P1_theta_deg*pi/180;
1469             %
1470             angles.orig = orig;
1471             %
1472             launchs{1}{1} = imake_launch_angles_TCV_jd(rmfield(angles,{'frequency_GHz','P0_kW','theta_deg','phi_deg','P1_theta_deg'}));
1473             %
1474             flag_shotimes = curtime;
1475             %
1476             iluke_newwavestructs;
1477             %
1478             clear launchs flag_shotimes
1479             %
1480         end
1481         %
1482         clear iw_curtime iw angles orig mod 
1483         %
1484         lukeobj = iluke_info(lukeobj,'c3po');% enable c3po display
1485         %
1486     case 'anglesload'
1487         %
1488         % loading angles data
1489         %
1490         sbase = 'ANGLES';
1491         filestr = [sbase,'_*.mat'];
1492         %
1493         [filename,pathname] = igetfile_jd(1,filestr,['Please select the ',sbase,' file(s)'],'',0);
1494         %
1495         %
1496         if filename ~= 0,
1497             %
1498             load([pathname,filename],'angles');
1499             %
1500             wavestructs{end+1} = imake_wavestructs_jd(equil,imake_launch_angles_TCV_jd(angles));
1501             %
1502             lukeobj.wavestruct.select.value = length(wavestructs);
1503             %
1504             status.data = 2;
1505             %
1506             clear angles
1507             %
1508         end  
1509         %
1510         clear sbase filestr filename pathname
1511         %
1512     case 'anglessave'
1513         %
1514         % saving angles structure
1515         %
1516         angles = wavestructs{lukeobj.wavestruct.select.value}.launch.angles;
1517         %
1518         sbase = 'ANGLES';
1519         filestr = [sbase,'_*.mat'];
1520         filename = [sbase,'_',angles.id,'.mat'];
1521         %
1522         [filename,pathname] = iputfile_jd(1,filestr,['Please provide the ',sbase,' file name'],filename);
1523         %
1524         %
1525         if filename ~= 0,
1526             %
1527             save([pathname,filename],'angles');
1528             %
1529         end  
1530         %
1531         clear angles sbase filestr filename pathname 
1532         %
1533     case 'anglesreset'
1534         %
1535         % resetting angles data
1536         %
1537         iw = lukeobj.wavestruct.select.value;
1538         %
1539         wavestructs{iw}.launch = imake_launch_angles_TCV_jd(wavestructs{iw}.launch.angles.orig);
1540         wavestructs{iw}.id = [wavestructs{iw}.wavesolver,'_',wavestructs{iw}.launch.id];
1541         %
1542         status.data = 2;
1543         %
1544         clear iw
1545         %
1546     case 'spectrummodify'
1547         %
1548         % modifying spectrum data
1549         %
1550         lukeobj = iluke_info(lukeobj,'');% disable info display
1551         %
1552         iw = lukeobj.wavestruct.select.value;
1553         %
1554         wavestruct = wavestructs{iw};
1555         wavestructs(iw) = [];
1556         %
1557         lukeobj.wavestruct.select.value = length(wavestructs);
1558         %
1559         iluke_update;% to clear older spectrum figures
1560         %
1561         if isfield(wavestruct.launch.spectrum,'orig'),
1562             wavestruct.launch.spectrum = rmfield(wavestruct.launch.spectrum,'orig');
1563         end
1564         %
1565         wavestruct.launch.spectrum.orig = wavestruct.launch.spectrum;
1566         %
1567         lukeobj.plot1.gindex = 0;
1568         %
1569         iluke_update;% initialize display
1570         %
1571         newgraph1_handle = axes('Parent',lukeobj.plot1.handle,'units','pixels','Position',style.graph_position,'FontName',style.fontname,'FontUnits','pixels','FontSize',style.fontsize,'Visible','off');% create new graphic objects with requested characteristics
1572         %
1573         select = struct;
1574         select.style = style;
1575         select.axs = newgraph1_handle;
1576         select.inter = 1;% interactive mode
1577         select.opt_gui = lukeobj.infopanel.handle;
1578         select.mode = 2;% display mode
1579         %
1580         signs.ip = sign(equil.psi_apRp(end));
1581         signs.b0 = sign(equil.ptBPHI(1,1));
1582         %
1583         [wavestruct.launch.bNpar0,wavestruct.launch.bdNpar0,wavestruct.launch.bPlhtot,wavestruct.launch.spectrum.param_tor,wavestruct.launch.spectrum.param_pol] = ...
1584             iproc_spectrum_jd(wavestruct.launch.spectrum,select,signs);
1585         %
1586         if wavestruct.launch.spectrum.param_pol.opt_ny == 1,
1587             wavestruct.launch.rZ0 = mean(wavestruct.launch.rZ0);
1588         end
1589         %
1590         % wavestruct.launch.id = make_launchid_jd(wavestruct.launch);
1591         %
1592         % wavestruct.id = [wavestruct.wavesolver,'_',wavestruct.launch.id];
1593         %
1594         wavestructs{end+1} = wavestruct;
1595         %
1596         status.data = 2;
1597         %
1598         ngraphs = length(graphs);
1599         %
1600         graphs(end+1) = iluke_graphs(lukeobj.plot1.handle,2,['spectrum for ',wavestructs{end}.id],'spectrum');
1601         %
1602         lukeobj.plot1.gindex = ngraphs + 1;
1603         %
1604         lukeobj.wavestruct.select.value = length(wavestructs);
1605         %
1606         clear iw newgraph1_handle specparam select signs wavestruct ngraphs
1607         %
1608         lukeobj = iluke_info(lukeobj,'c3po');% enable c3po display
1609         %
1610     case 'spectrumload'
1611         %
1612         % loading spectrum data
1613         %
1614         filestr = {'*.mat'};
1615         %
1616         [filename,pathname] = igetfile_jd(1,filestr,['Please select the LH spectrum file(s)'],'',0);
1617         %
1618         if filename ~= 0,
1619             %
1620             spectrum = load([pathname,filename]);
1621             %
1622             spectrum.id = filename;
1623             if any(strfind(spectrum.id,'.mat')),
1624                 spectrum.id = spectrum.id(1:end-4);
1625             end
1626             %
1627             lukeobj = iluke_info(lukeobj,'');% disable info display
1628             %
1629             lukeobj.plot1.gindex = 0;
1630             %lukeobj.plot2.gindex = 0;
1631             %
1632             iluke_update;% initialize display
1633             %
1634             newgraph1_handle = axes('Parent',lukeobj.plot1.handle,'units','pixels','Position',style.graph_position,'FontName',style.fontname,'FontUnits','pixels','FontSize',style.fontsize,'Visible','off');% create new graphic objects with requested characteristics
1635             %newgraph2_handle = axes('Parent',lukeobj.plot2.handle,'units','pixels','Position',style.graph_position,'FontName',style.fontname,'FontUnits','pixels','FontSize',style.fontsize,'Visible','off');% create new graphic objects with requested characteristics
1636             %
1637             select = struct;
1638             select.style = style;
1639             select.tail = false;
1640             select.axs = [newgraph1_handle];
1641             select.inter = 0;% non interactive mode
1642             select.mode = 2;% display mode
1643             %
1644             launchs = imake_launch_jd(dkepath,tokamak,equil,spectrum,workdir,lukeobj.infopanel.handle,select);
1645             %
1646             if ~isempty(launchs),
1647                 wavestructs{end+1} = imake_wavestructs_jd(equil,launchs{1});
1648                 %
1649                 ngraphs = length(graphs);
1650                 %
1651                 graphs(end+1) = iluke_graphs(lukeobj.plot1.handle,[1,2],['spectrum for ',wavestructs{end}.id],'spectrum');
1652                 %
1653                 lukeobj.plot1.gindex = ngraphs + 1;
1654                 %
1655                 lukeobj.wavestruct.select.value = length(wavestructs);
1656                 %
1657                 status.data = 2;
1658                 %
1659                 clear ngraphs
1660                 %
1661             else
1662                 %
1663                 delete(newgraph1_handle);
1664                 %
1665             end
1666             %
1667             clear spectrum select newgraph1_handle launchs
1668             %
1669             lukeobj = iluke_info(lukeobj,'c3po');% enable c3po display
1670             %
1671         end  
1672         %
1673         clear filestr filename pathname
1674         %
1675     case 'spectrumsave'
1676         %
1677         % saving spectrum structure
1678         %
1679         spectrum = wavestructs{lukeobj.wavestruct.select.value}.launch.spectrum;
1680         %
1681         sbase = 'SPECTRUM';
1682         filestr = [sbase,'_*.mat'];
1683         filename = [sbase,'_',angles.id,'.mat'];
1684         %
1685         [filename,pathname] = iputfile_jd(1,filestr,['Please provide the ',sbase,' file name'],filename);
1686         %
1687         %
1688         if filename ~= 0,
1689             %
1690             save([pathname,filename],'spectrum');
1691             %
1692         end  
1693         %
1694         clear spectrum sbase filestr filename pathname 
1695         %
1696     case 'spectrumreset'
1697         %
1698         % resetting spectrum data
1699         %
1700         %
1701         iw = lukeobj.wavestruct.select.value;
1702         %
1703         wavestruct = wavestructs{iw};
1704         wavestructs(iw) = [];
1705         %
1706         wavestruct.launch.spectrum = wavestruct.launch.spectrum.orig;
1707         %
1708         lukeobj.plot1.gindex = 0;
1709         %
1710         iluke_update;% to clear older spectrum figures
1711         %
1712         newgraph1_handle = axes('Parent',lukeobj.plot1.handle,'units','pixels','Position',style.graph_position,'FontName',style.fontname,'FontUnits','pixels','FontSize',style.fontsize,'Visible','off');% create new graphic objects with requested characteristics
1713         %
1714         select = struct;
1715         select.style = style;
1716         select.axs = newgraph1_handle;
1717         select.inter = 0;% interactive mode
1718         select.opt_gui = lukeobj.infopanel.handle;
1719         select.mode = 2;% display mode
1720         %
1721         select.opt_ny = wavestruct.launch.spectrum.param_pol.opt_ny;
1722         %
1723         signs.ip = sign(equil.psi_apRp(end));
1724         signs.b0 = sign(equil.ptBPHI(1,1));
1725         %
1726         [wavestruct.launch.bNpar0,wavestruct.launch.bdNpar0,wavestruct.launch.bPlhtot,wavestruct.launch.spectrum.param_tor,wavestruct.launch.spectrum.param_pol] = ...
1727             iproc_spectrum_jd(wavestruct.launch.spectrum,select,signs);
1728         %
1729         if wavestruct.launch.spectrum.param_pol.opt_ny == 1,
1730             wavestruct.launch.rZ0 = mean(wavestruct.launch.rZ0);
1731         end
1732         %
1733         % wavestruct.launch.id = make_launchid_jd(wavestruct.launch);
1734         %
1735         % wavestruct.id = [wavestruct.wavesolver,'_',wavestruct.launch.id];
1736         %
1737         wavestructs{end+1} = wavestruct;
1738         %
1739         status.data = 2;
1740         %
1741         ngraphs = length(graphs);
1742         %
1743         graphs(end+1) = iluke_graphs(lukeobj.plot1.handle,2,['spectrum for ',wavestructs{end}.id],'spectrum');
1744         %
1745         lukeobj.plot1.gindex = ngraphs + 1;
1746         %
1747         lukeobj.wavestruct.select.value = length(wavestructs);
1748         %
1749         clear iw newgraph1_handle specparam select signs wavestruct ngraphs
1750         %
1751     case 'launchmodify'
1752         %
1753         % modifying launch data
1754         %
1755         %lukeobj = iluke_info(lukeobj,'');% disable info display
1756         %
1757         iw = lukeobj.wavestruct.select.value;
1758         %
1759         [wavestructss{iw,curtime},mod] = iluke_launchmodify(wavestructss{iw,curtime},style);        
1760         %
1761         if mod,
1762             status.data = 2;
1763         end
1764         %
1765         clear iw mod
1766         %
1767         %lukeobj = iluke_info(lukeobj,'c3po');% enable c3po display
1768         %
1769     case 'launchload'
1770         %
1771         % creating wavestruct structure from launch file
1772         %
1773         lukeobj = iluke_info(lukeobj,'');% disable info display
1774         %
1775         sbase = 'LAUNCH';
1776         filestr = [sbase,'_*.mat'];
1777         %
1778         [filename,pathname] = igetfile_jd(1,filestr,['Please select the ',sbase,' file'],'',0);
1779         %
1780         %
1781         if filename ~= 0,
1782             %
1783             data = load([pathname,filename],'launch');
1784             %
1785             if curtime > 0,
1786                 flag_shotimes = curtime;
1787             else
1788                 flag_shotimes = find(status.equil == 1);
1789             end
1790             %
1791             launchs = repmat({{data.launch}},[1,length(flag_shotimes)]);
1792             %
1793             iluke_newwavestructs;% update wavestructs, status and wavestructids
1794             %
1795             clear data launchs flag_shotimes
1796             %
1797         end  
1798         %
1799         clear sbase filestr filename pathname
1800         %
1801         lukeobj = iluke_info(lukeobj,'c3po');% enable c3po display
1802         %
1803     case 'launchsave'
1804         %
1805         % saving angles structure
1806         %
1807         iw_curtime = find(status.wavestructs(:,curtime) == 1);
1808         iw = iw_curtime(lukeobj.wavestruct.select.value);% current index in wavestructss
1809         %
1810         launch = wavestructss{iw,curtime}.launch;
1811         %
1812         sbase = 'LAUNCH';
1813         filestr = [sbase,'_*.mat'];
1814         filename = [sbase,'_',launch.id,'.mat'];
1815         %
1816         [filename,pathname] = iputfile_jd(1,filestr,['Please provide the ',sbase,' file name'],filename);
1817         %
1818         %
1819         if filename ~= 0,
1820             %
1821             save([pathname,filename],'launch');
1822             %
1823         end  
1824         %
1825         clear iw_curtime iw launch sbase filestr filename pathname 
1826         %
1827     case 'launchreset'
1828         %
1829         % resetting launch data
1830         %
1831         iw = lukeobj.wavestruct.select.value;
1832         %
1833         wavestructs{iw}.launch = wavestructs{iw}.launch.orig;
1834         wavestructs{iw}.id = [wavestructs{iw}.wavesolver,'_',wavestructs{iw}.launch.id];
1835         %
1836         status.data = 2;
1837         %
1838         clear iw
1839         %
1840     case 'c3poparammodify'
1841         %
1842         % modifying c3po parameters
1843         %
1844         lukeobj = iluke_info(lukeobj,'');% disable info display
1845         %
1846         if curtime > 0,
1847             iw_curtime = find(status.wavestructs(:,curtime) == 1);
1848             iw = iw_curtime(lukeobj.wavestruct.select.value);% current index in wavestructss
1849             %
1850             rtparam = selectfields_jd(wavestructss{iw,curtime},{'rtparam','rayparam','waveparam','fitparam','C3POparam','C3POdisplay'});
1851             if isfield(wavestructss{iw,curtime},'orig'),
1852                 orig = wavestructss{iw,curtime}.orig;
1853             else
1854                 orig = rtparam;
1855             end
1856         else
1857             iw = lukeobj.wavestruct.select.value;
1858             itlist = find(status.wavestructs(iw,:) == 1);% list of times
1859             rtparam = selectfields_jd(wavestructss{iw,itlist(1)},{'rtparam','rayparam','waveparam','fitparam','C3POparam','C3POdisplay'});
1860             if isfield(wavestructss{iw,itlist(1)},'orig'),
1861                 orig = wavestructss{iw,itlist(1)}.orig;
1862             else
1863                 orig = rtparam;
1864             end
1865         end
1866         %
1867         [rtparam,mod] = imod_struct_jd(rtparam,'rtparam',1,lukeobj.infopanel.handle,struct,style);
1868         %
1869         if any(mod),
1870             %
1871             if curtime > 0,
1872                 wavestructss{iw,curtime}.rayparam = rtparam.rayparam;
1873                 wavestructss{iw,curtime}.waveparam = rtparam.waveparam;
1874                 wavestructss{iw,curtime}.fitparam = rtparam.fitparam;
1875                 wavestructss{iw,curtime}.C3POparam = rtparam.C3POparam;
1876                 wavestructss{iw,curtime}.C3POdisplay = rtparam.C3POdisplay;
1877                 wavestructss{iw,curtime}.rtparam = '< not saved >';
1878                 %
1879                 wavestructss{iw,curtime}.orig = orig;
1880             else
1881                 for it = itlist,
1882                     wavestructss{iw,it}.rayparam = rtparam.rayparam;
1883                     wavestructss{iw,it}.waveparam = rtparam.waveparam;
1884                     wavestructss{iw,it}.fitparam = rtparam.fitparam;
1885                     wavestructss{iw,it}.C3POparam = rtparam.C3POparam;
1886                     wavestructss{iw,it}.C3POdisplay = rtparam.C3POdisplay;
1887                     wavestructss{iw,it}.rtparam = '< not saved >';
1888                     %
1889                     wavestructss{iw,it}.orig = orig;
1890                 end
1891                 %
1892                 clear it itlist iwlist
1893             end
1894             %
1895             status.data = 2;
1896             %
1897         end
1898         %
1899         clear iw rtparam orig mod
1900         %
1901         action = 'wavemake';iluke_callbacks;
1902         %
1903     case 'c3poparamload'
1904         %
1905         % loading c3po parameters
1906         %
1907         sbase = 'C3POPARAM';
1908         filestr = [sbase,'_*.mat'];
1909         %
1910         [filename,pathname] = igetfile_jd(1,filestr,['Please select the ',sbase,' file(s)'],'',0);
1911         %
1912         if filename ~= 0,
1913             %
1914             iw = lukeobj.wavestruct.select.value;
1915             %
1916             rtparam = load([pathname,filename],'rayparam','waveparam','fitparam','C3POparam','C3POdisplay');
1917             %
1918             wavestructs{iw}.rayparam = rtparam.rayparam;
1919             wavestructs{iw}.waveparam = rtparam.waveparam;
1920             wavestructs{iw}.fitparam = rtparam.fitparam;
1921             wavestructs{iw}.C3POparam = rtparam.C3POparam;
1922             wavestructs{iw}.C3POdisplay = rtparam.C3POdisplay;
1923             wavestructs{iw}.rtparam = filename;
1924             %
1925             if isfield(wavestructs{iw},'orig'),
1926                 wavestructs{iw} = rmfield(wavestructs{iw},'orig');
1927             end
1928             %
1929             lukeobj.c3poparam.text.string = filename;%[pathname,filename];
1930             %
1931             status.data = 2;
1932             %
1933             clear iw rtparam
1934             %
1935         end  
1936         %
1937         clear sbase filestr filename pathname
1938         %
1939     case 'c3poparamsave'
1940         %
1941         % saving c3po parameters
1942         %
1943         iw = lukeobj.wavestruct.select.value;
1944         %
1945         rtparam = selectfields_jd(wavestructs{iw},{'rtparam','rayparam','waveparam','fitparam','C3POparam','C3POdisplay'});
1946         %
1947         sbase = 'C3POPARAM';
1948         filestr = [sbase,'_*.mat'];
1949         filename = [sbase,'_',wavestructs{iw}.id,'.mat'];
1950         %
1951         [filename,pathname] = iputfile_jd(1,filestr,['Please provide the ',sbase,' file name'],filename);
1952         %
1953         %
1954         if filename ~= 0,
1955             %
1956             save([pathname,filename],'-struct','rtparam');
1957             %
1958             lukeobj.c3poparam.text.string = filename;%[pathname,filename];
1959             %
1960         end  
1961         %
1962         clear iw rtparam sbase filestr filename pathname 
1963         %
1964     case 'c3poparamreset'
1965         %
1966         % resetting c3po parameters
1967         %
1968         iw = lukeobj.wavestruct.select.value;
1969         %
1970         wavestructs{iw}.rayparam = wavestructs{iw}.orig.rayparam;
1971         wavestructs{iw}.waveparam = wavestructs{iw}.orig.waveparam;
1972         wavestructs{iw}.fitparam = wavestructs{iw}.orig.fitparam;
1973         wavestructs{iw}.C3POparam = wavestructs{iw}.orig.C3POparam;
1974         wavestructs{iw}.C3POdisplay = wavestructs{iw}.orig.C3POdisplay;
1975         wavestructs{iw}.rtparam = wavestructs{iw}.orig.rtparam;
1976         %
1977         wavestructs{iw} = rmfield(wavestructs{iw},'orig');
1978         %
1979         status.data = 2;
1980         %
1981         clear iw
1982         %
1983     case 'c3pooptim'
1984         %
1985         % optimize Bt, Zp & launching angles to deposit power in target area
1986         %
1987         lukeobj = iluke_info(lukeobj,'');% disable info display
1988         %
1989         it_g = 2 + curtime;%<new>,<all>,...
1990         %
1991         lukeobj.plot1.gindex(it_g) = 0;
1992         lukeobj.plot2.gindex(it_g) = 0;
1993         lukeobj.plot3.gindex(it_g) = 0;
1994         %
1995         iluke_update;% initialize display
1996         %
1997         newgraph1_handle = axes('Parent',lukeobj.plot1.handle,'units','pixels','Position',style.graph_position,'FontName',style.fontname,'FontUnits','pixels','FontSize',style.fontsize);% create new graphic objects with requested characteristics
1998         newgraph2_handle = axes('Parent',lukeobj.plot2.handle,'units','pixels','Position',style.graph_position,'FontName',style.fontname,'FontUnits','pixels','FontSize',style.fontsize);
1999         newgraph3_handle = axes('Parent',lukeobj.plot3.handle,'units','pixels','Position',style.graph_position,'FontName',style.fontname,'FontUnits','pixels','FontSize',style.fontsize);
2000         %
2001         opt.vessel_opt = 'n';
2002         opt.abs_max = 0;
2003         opt.mode = 'n';
2004         opt.print = -1;
2005         opt.TeNpar = 1;
2006         opt.nospec = 1;
2007         %
2008         opt.nr_dep = 40;
2009         opt.rho_disp = 0:0.1:1;
2010         opt.ymask = NaN;
2011         opt.xvar = 'p';
2012         %
2013         opt.axs = [newgraph1_handle,newgraph2_handle,newgraph3_handle];
2014         opt.font = style;
2015         %
2016         select = struct;
2017         select.style = style;
2018         select.opt_gui = lukeobj.infopanel.handle;
2019         select.opt = opt;
2020         select.busyhandle = lukeobj.busy.handle;
2021         %
2022         iw_curtime = find(status.wavestructs(:,curtime) == 1);
2023         iw = iw_curtime(lukeobj.wavestruct.select.value);% current index in wavestructss
2024         %
2025         if isfield(wavestructss{iw,curtime}.launch,'angles') && isfield(wavestructss{iw,curtime}.launch.angles,'orig'),
2026             wavestructss{iw,curtime}.launch.angles = rmfield(wavestructss{iw,curtime}.launch.angles,'orig');
2027         end
2028         %
2029         if isfield(wavestructss{iw,curtime}.launch,'orig'),
2030             wavestructss{iw,curtime}.launch = rmfield(wavestructss{iw,curtime}.launch,'orig');
2031         end
2032         %
2033         [newwavestruct,flag_Zp] = wave_optim_jd(dkepath,wavestructss{iw,curtime},select);
2034         %
2035         if flag_Zp || ~comp_struct_jd(newwavestruct,wavestructss{iw,curtime},0),
2036             status.data = 2;
2037         end
2038         %
2039         wavestructss{iw,curtime} = newwavestruct;
2040         status.wavestructs(iw,curtime) = 1;
2041         %
2042         if flag_Zp,% Zp was changed, all waves and other existing wavestructs are cleared
2043             %
2044             equils{curtime}.Zp = wavestructss{iw,curtime}.equil.Zp;
2045             %
2046             status.waves(curtime) = 0;
2047             status.output(curtime) = 0;
2048             status.wavestructs([1:iw-1,iw+1:end],curtime) = 0;
2049             %
2050             lukeobj.lukeid.string = '';
2051         end     
2052         %
2053         clear iw_curtime iw newwavestructs flag_Zp newgraph1_handle newgraph2_handle newgraph3_handle opt select
2054         %
2055         lukeobj = iluke_info(lukeobj,'c3po');% enable c3po display
2056         %
2057     case 'c3postart'
2058         %
2059         % running C3PO for current or all wavestructs
2060         %
2061         lukeobj = iluke_info(lukeobj,'');% disable info display
2062         %
2063         calc_mask = zeros(size(status.wavestructs));
2064         %
2065         if curtime > 0,
2066             %
2067             iw_curtime = find(status.wavestructs(:,curtime) == 1);
2068             %
2069             calc_mask(iw_curtime(iw),curtime) = 1;
2070             %
2071             clear iw_curtime
2072             %
2073         else% treat all shot times
2074             %
2075             if ~isscalar(iw),% treat all wavestructs
2076                 %
2077                 calc_mask(status.wavestructs == 1) = 1;
2078                 %
2079             else% treat only wavestructs with  wavestruct.id = wavestruct.select.string{iw};
2080                 %
2081                 calc_mask(iw,status.wavestructs(iw,:) == 1) = 1;
2082                 %
2083             end
2084             %
2085         end
2086         %
2087         mdce_mode = iselect_jd(dkepath.distprofiles,'Distribution of calc. : ',lukeobj.infopanel.handle,style.distselectstyle,1,'popupmenu') - 1;
2088         %
2089         if mdce_mode > 2,
2090             mdce_mode = 2 - mdce_mode;%use of remcomputing with negative mdce_mode
2091         end
2092         %
2093         wavesolverparam.clustermode.wave_solver_yp.scheduler.mode = mdce_mode;
2094         %
2095         set(lukeobj.busy.handle,'Visible','on');drawnow;
2096         [newwaves,it_flag,itn_flag] = iluke_wave_jd(dkepath,equils,wavestructss,calc_mask,wavesolverparam);
2097         set(lukeobj.busy.handle,'Visible','off');drawnow;
2098         %
2099         if ~isempty(newwaves),
2100             %
2101             for iiw = 1:length(it_flag),
2102                 %
2103                 if itn_flag(iiw) == 0,% to fluctuations for this time
2104                     wavess{it_flag(iiw)}{end+1} = newwaves{iiw};
2105                 else
2106                     if (length(wavess{it_flag(iiw)}) < itn_flag(iiw)) || ~iscell(wavess{it_flag(iiw)}{itn_flag(iiw)}),
2107                         wavess{it_flag(iiw)}{itn_flag(iiw)} = {};
2108                     end
2109                     wavess{it_flag(iiw)}{itn_flag(iiw)}{end+1} = newwaves{iiw};
2110                 end
2111                 %
2112                 status.waves(it_flag(iiw)) = 1;
2113                 %
2114             end
2115             %
2116             status.data = 2;
2117             %
2118             lukeobj.lukeid.string = '';
2119             %
2120             if curtime > 0,
2121                 action = 'wavedisp';iluke_callbacks;
2122             end
2123             %
2124         end
2125         %
2126         clear wavestructs it_flag mdce_mode newwaves wavesolverparam
2127         %
2128         lukeobj = iluke_info(lukeobj,'text');% enable info display
2129         %
2130     case 'wavemake'%'newwavemake'%
2131         %
2132         % show run luke pannel
2133         %
2134         if curtime > 0,
2135             lukeobj = iluke_info(lukeobj,'c3po');% enable c3po display
2136         else
2137             lukeobj = iluke_info(lukeobj,'c3po_MultiTimes');% enable c3po display
2138         end
2139         %
2140     case 'oldwavemake'%'wavemake'%
2141         %
2142         % creating wave structure
2143         %
2144         lukeobj = iluke_info(lukeobj,'');% disable info display
2145         %
2146         select.style = style;
2147         %
2148         if isfield(external,'wave'),
2149             external_wave = external.wave;
2150         else
2151             external_wave = '';
2152         end
2153         %
2154         wave = imake_wave_jd(dkepath,tokamak,equil,external_wave,workdir,lukeobj.infopanel.handle,select);
2155         %
2156         if isfield(wave,'err'),
2157             lukeobj.infotext.string = {'Error creating wave structure : ',wave.err};
2158             wave = '';
2159         end
2160         %
2161         if ~isempty(wave),
2162             if isempty(waves),
2163                 waves = {wave};
2164             else
2165                 waves = [waves,wave];
2166             end
2167             %
2168             status.waves = 1;
2169             status.data = 2;
2170             %
2171             lukeobj.lukeid.string = '';
2172             %
2173             action = 'wavedisp';iluke_callbacks;
2174             %
2175         end
2176         %
2177         lukeobj = iluke_info(lukeobj,'text');% enable info display
2178         %
2179     case 'waveload'
2180         %
2181         % loading wave data
2182         %
2183         sbase = 'WAVE';
2184         filestr = [sbase,'_*.mat'];
2185         %
2186         [filenames,pathnames] = igetfile_jd(1,filestr,['Please select the ',sbase,' file(s)'],'',1);
2187         if isnumeric(filenames) || isempty(filenames),
2188             filenames = {};
2189             pathnames = {};
2190         elseif ~iscell(filenames),
2191             filenames = {filenames};
2192             pathnames = {pathnames};
2193         elseif ~iscell(pathnames),
2194             pathnames = repmat({pathnames},[1,length(filenames)]);
2195         end
2196         %
2197         % list of equil ids for identifications
2198         %
2199         equilids = cell(1,ntimes);
2200         for it=1:ntimes,
2201             if status.equil(it) == 1,
2202                 equilids{it} = equils{it}.id;
2203             else
2204                 equilids{it} = '';
2205             end
2206         end
2207         %
2208         % load new waves and identify equilibrium
2209         %
2210         for iw = 1:length(filenames),
2211             load([pathnames{iw},filenames{iw}],'wave');
2212             %
2213             it = strcmp(equilids,wave.equil_id);
2214             %
2215             if isempty(it),
2216                 disp(['WARNING : wave with id ',wave.id,' cannot be identified with any existing equilibrium. Discarded.'])
2217             else
2218                 if length(it) > 1,
2219                     disp(['WARNING : wave with id ',wave.id,' identified with more than one existing equilibrium. First match enforced.'])
2220                     it = it(1);
2221                 end
2222                 %
2223                 wavess{it}{end+1} = wave;
2224                 %
2225                 status.waves(it) = 1;
2226                 status.data = 2;
2227                 %
2228                 lukeobj.lukeid.string = '';
2229             end
2230         end
2231         %
2232         clear sbase filestr filenames pathnames equilids it iw 
2233         %
2234     case 'wavesave'
2235         %
2236         % saving WAVE structure
2237         %
2238         lukeobj = iluke_info(lukeobj,'');% disable info display
2239         %
2240         % loading external data
2241         %
2242         if curtime == 0,
2243             opt_continue = iselect_jd({'No','Yes'},'Save each structure ''wave'' separately and automatically ? ',lukeobj.infopanel.handle,style,1) - 1;
2244         else
2245             opt_continue = 1;
2246         end
2247         %
2248         if opt_continue,
2249             %
2250             sbase = 'WAVE';
2251             %
2252             if curtime == 0,
2253                 %
2254                 pathname = workdir;
2255                 %
2256                 for it = 1:ntimes,
2257                     for iw = 1:length(wavess{it}),
2258                         wave = wavess{it}{iw};
2259                         filename = [sbase,'_',equils{it}.id,'_',wave.id,'.mat'];
2260                         %
2261                         save([pathname,filename],'wave');
2262                         wavess{it}{iw}.pathname = pathname;
2263                         wavess{it}{iw}.filename = filename;
2264                     end
2265                 end
2266                 %
2267                 clear it
2268                 %
2269             else
2270                 %
2271                 filestr = [sbase,'_*.mat'];
2272                 %
2273                 nw = length(wavess{curtime});
2274                 if nw > 1,
2275                     titletext = 'Select the wave structure to save:';   
2276                     s = cell(1,nw);
2277                     for iw = 1:nw,
2278                         s{iw} = ['Wave # ',num2str(iw),' : ',wavess{curtime}{iw}.id];
2279                     end
2280                     %
2281                     iw = iselect_jd(s,titletext,lukeobj.infopanel.handle,style,1);
2282                 else
2283                     iw = 1;
2284                 end
2285                 %
2286                 wave = wavess{curtime}{iw};
2287                 %
2288                 filename = [sbase,'_',equils{curtime}.id,'_',wave.id,'.mat'];
2289                 %
2290                 [filename,pathname] = iputfile_jd(1,filestr,['Please provide the ',sbase,' file name'],filename);
2291                 %
2292                 if filename ~= 0,
2293                     save([pathname,filename],'wave');
2294                     wavess{curtime}{iw}.pathname = pathname;
2295                     wavess{curtime}{iw}.filename = filename;
2296                 end  
2297                 %
2298                 clear filestr nw titletext s 
2299                 %
2300             end
2301             %
2302             clear sbase filename pathname wave iw
2303             %
2304         end
2305         %
2306         clear opt_continue
2307         %
2308         lukeobj = iluke_info(lukeobj,'text');% enable info display
2309         %
2310     case 'waveclear'
2311         %
2312         % clearing wave structure
2313         %
2314         lukeobj = iluke_info(lukeobj,'');% disable info display
2315         %
2316         if curtime == 0,
2317             opt_continue = iselect_jd({'No','Yes'},'Clear all ''wave'' structures ? ',lukeobj.infopanel.handle,style,1) - 1;
2318         else
2319             opt_continue = 1;
2320         end
2321         %
2322         if opt_continue,
2323             %
2324             if curtime == 0,
2325                 if any(status.waves == 1),
2326                     status.data = 2;
2327                     lukeobj.lukeid.string = '';
2328                 end
2329                 status.waves(:) = 0;
2330             else
2331                 %
2332                 titletext = 'Select the wave structure(s) to clear:';   
2333                 nw = length(wavess{curtime});
2334                 s = cell(1,nw);
2335                 for iw = 1:nw,
2336                     s{iw} = ['Wave # ',num2str(iw),' : ',wavess{curtime}{iw}.id];
2337                 end
2338                 %
2339                 iw = iselect_jd(s,titletext,lukeobj.infopanel.handle,style,1,'listbox');
2340                 %
2341                 wavess{curtime}(iw) = [];
2342                 if isempty(wavess{curtime}),
2343                     status.waves(curtime) = 0;
2344                 end
2345                 %
2346                 if ~isempty(iw),
2347                     status.data = 2;
2348                     lukeobj.lukeid.string = '';
2349                 end
2350                 %
2351                 clear titletext nw s iw
2352             end
2353             %
2354         end
2355         %
2356         clear opt_continue
2357         %
2358         lukeobj = iluke_info(lukeobj,'text');% enable info display
2359         %
2360     case 'wavedisp'
2361         %
2362         % displaying wave data
2363         %
2364         %
2365         lukeobj = iluke_info(lukeobj,'');% enable info display
2366         %
2367         it_g = 2 + curtime;%<new>,<all>,...
2368         %
2369         lukeobj.plot1.gindex(it_g) = 0;
2370         lukeobj.plot2.gindex(it_g) = 0;
2371         lukeobj.plot3.gindex(it_g) = 0;
2372         %
2373         cleartags{it_g} = {'waves'};
2374         %
2375         iluke_update;% initialize display
2376         %
2377         newgraph1_handle = axes('Parent',lukeobj.plot1.handle,'units','pixels','Position',style.graph_position,'FontName',style.fontname,'FontUnits','pixels','FontSize',style.fontsize);% create new graphic objects with requested characteristics
2378         newgraph2_handle = axes('Parent',lukeobj.plot2.handle,'units','pixels','Position',style.graph_position,'FontName',style.fontname,'FontUnits','pixels','FontSize',style.fontsize);
2379         newgraph3_handle = axes('Parent',lukeobj.plot3.handle,'units','pixels','Position',style.graph_position,'FontName',style.fontname,'FontUnits','pixels','FontSize',style.fontsize); 
2380         %
2381         if curtime > 0,
2382             %
2383             opt.vessel_opt = 'n';
2384             opt.abs_max = 0;
2385             opt.mode = 'n';
2386             opt.print = -1;
2387             opt.TeNpar = 1;
2388             opt.nospec = 1;
2389             %
2390             opt.axs = [newgraph1_handle,newgraph2_handle,newgraph3_handle];
2391             opt.font = style;
2392             %
2393             opt.nr_dep = 40;
2394             opt.rho_disp = 0:0.1:1;
2395             opt.ymask = NaN;
2396             opt.xvar = 'p';
2397             %
2398             waves = wavess{curtime};
2399             %
2400             if status.fluct(curtime) <= 0,% no fluctuations
2401                 %
2402                 titletext = 'Select the wave structure(s) to plot :';   
2403                 nw = length(waves);
2404                 s = cell(1,nw);
2405                 for iw = 1:nw,
2406                     s{iw} = ['Wave # ',num2str(iw),' : ',waves{iw}.id];
2407                 end
2408                 %
2409                 iw = iselect_jd(s,titletext,lukeobj.infopanel.handle,style,1,'listbox');
2410                 %
2411                 clear s nw titletext
2412                 %
2413                 if length(iw) == 1,% single wave, can be subdivided for plotting
2414                     wave = waves{iw};
2415                     nrays = length(wave.rays);
2416                     if nrays > 1 && iselect_jd({'No','Yes'},'Do you want to subdivide the rays into groups for plotting ? ',lukeobj.infopanel.handle,style,1) == 2,
2417                         %
2418                         raygroups = iselect_jd({},...
2419                             ['Please select groups of rays in the list 1->',num2str(nrays),'. Ex : {1:',num2str(fix(nrays/2)),',',num2str(fix(nrays/2)+1),':',num2str(nrays),'} '],...
2420                             lukeobj.infopanel.handle,style.editselectstyle,{1:nrays},'edit');
2421                         %
2422                         nwaves = length(raygroups);
2423                         waves = cell(1,nwaves);
2424                         for iw = 1:nwaves,
2425                             waves{iw} = wave;
2426                             waves{iw}.id = [waves{iw}.id,'_',num2str(iw)];
2427                             waves{iw}.rays = waves{iw}.rays(raygroups{iw});
2428                         end
2429                         %
2430                         clear nwaves iw
2431                     end
2432                     %
2433                     clear wave nrays 
2434                 else
2435                     waves = waves(iw); 
2436                 end
2437                 %
2438                 lukeobj.wave.text.string = [num2str(length(wavess{curtime})),' wave structure(s)'];
2439                 lukeobj.infotext.string = iluke_waveinfo(wavess{curtime});
2440                 %
2441             else% with fluctuations
2442                 %
2443                 titletext = 'Select the wave structure to plot :';   
2444                 nw = length(waves{1});
2445                 s = cell(1,nw);
2446                 for iw = 1:nw,
2447                     is1 = max(strfind(waves{1}{iw},'WAVE_'));%wavess contains wave files
2448                     is2 = strfind(waves{1}{iw},'_itn_1.mat') - 1;
2449                     s{iw} = ['Wave # ',num2str(iw),' : ',waves{1}{iw}(is1:is2)];
2450                 end
2451                 %
2452                 iw = iselect_jd(s,titletext,lukeobj.infopanel.handle,style,1,'buttongroup');
2453                 %
2454                 clear s nw titletext
2455                 %
2456                 itn_list = iselect_jd({},'Select fluctuations states to show',...
2457                     lukeobj.infopanel.handle,style.editselectstyle,[1,2,3],'edit');
2458                 %
2459                 % load selected waves
2460                 %
2461                 ntn = length(itn_list);
2462                 newwaves = cell(1,ntn);
2463                 for itn = 1:ntn,
2464                     data = load(waves{itn_list(itn)}{iw},'wave');
2465                     newwaves{itn} = data.wave;
2466                 end
2467                 waves = newwaves;
2468                 %
2469                 lukeobj.wave.text.string = [num2str(length(wavess{curtime}{1})),' wave structure(s)'];
2470                 lukeobj.infotext.string = iluke_waveinfo(wavess{curtime});
2471             end
2472             %
2473             graph_wave_jd(equils{curtime},waves,opt.nr_dep,opt,opt.rho_disp,opt.ymask,opt.xvar);
2474             %
2475             clear waves
2476             %
2477             graphs(1) = iluke_graphs(lukeobj.plot1.handle,1,'poloidal view','waves');
2478             graphs(2) = iluke_graphs(lukeobj.plot2.handle,1,'top view','waves');% includes legend
2479             graphs(3) = iluke_graphs(lukeobj.plot3.handle,1,'linear damping','waves');% includes legend
2480             %
2481         else
2482             %
2483             mask_disp = status.fluct <= 0;%select times without fluctuations
2484             %
2485             newgraph4_handle = axes('Parent',lukeobj.plot3.handle,'units','pixels','Position',style.graph_position,'FontName',style.fontname,'FontUnits','pixels','FontSize',style.fontsize); 
2486             newgraph5_handle = axes('Parent',lukeobj.plot3.handle,'units','pixels','Position',style.graph_position,'FontName',style.fontname,'FontUnits','pixels','FontSize',style.fontsize); 
2487             %
2488             set(lukeobj.busy.handle,'Visible','on');drawnow;
2489             %
2490             wave_disp_outputs_mt(wavess(mask_disp),shotimes(mask_disp),style,[newgraph1_handle,newgraph2_handle,newgraph3_handle,newgraph4_handle,newgraph5_handle]);
2491             %
2492             set(lukeobj.busy.handle,'Visible','off');drawnow;
2493             %
2494             graphs(1) = iluke_graphs(lukeobj.plot1.handle,2,'poloidal angle','waves');
2495             graphs(2) = iluke_graphs(lukeobj.plot2.handle,2,'toroidal angle','waves');% includes legend
2496             graphs(3:5) = iluke_graphs(lukeobj.plot3.handle,{[3,6],[2,5],[1,4]},{'wave power','fraction of power absorbed','linear power deposition'},'waves');% includes legend
2497             %
2498             clear newgraph4_handle newgraph5_handle 
2499             %
2500         end
2501         %
2502         ngraphs = length(graphss{it_g});
2503         %
2504         graphss{it_g}(end+1:end+length(graphs)) = graphs;
2505         %
2506         lukeobj.plot1.gindex(it_g) = ngraphs + 1;
2507         lukeobj.plot2.gindex(it_g) = ngraphs + 2;
2508         lukeobj.plot3.gindex(it_g) = ngraphs + 3;
2509         %
2510         clear it_g ngraphs newgraph1_handle newgraph2_handle newgraph3_handle  
2511         %
2512         lukeobj = iluke_info(lukeobj,'text');% enable info display
2513         %
2514     case 'lukerun'
2515         %
2516         % show run luke pannel
2517         %
2518         lukeobj = iluke_info(lukeobj,'luke');% disable info display
2519         %
2520         if curtime == 0,
2521             if ~any(status.job > 0),
2522                 lukeobj.runcheck.visible = 'off';
2523                 lukeobj.lukechecktext.string = '';
2524             else
2525                 lukeobj.runcheck.visible = 'on';
2526                 lukeobj.lukechecktext.string = ['Number of LUKE jobs started : ',num2str(sum(status.job > 0))];
2527             end
2528             %
2529             lukeobj.lukeidtitle.visible = 'off';
2530             lukeobj.lukeid.visible = 'off';
2531             lukeobj.lukeid.string = '';
2532         elseif curtime > 0,
2533             if status.job(curtime) == 0,
2534                 lukeobj.runcheck.visible = 'off';
2535                 lukeobj.lukechecktext.string = '';
2536             else
2537                 lukeobj.runcheck.visible = 'on';
2538                 lukeobj.lukechecktext.string = 'LUKE Job in progress';
2539             end
2540             %
2541             lukeobj.lukeidtitle.visible = 'on';
2542             lukeobj.lukeid.visible = 'on';
2543             lukeobj.lukeid.string = make_luke_simulid_jd(equils{curtime},ohms{curtime},transpfastes{curtime},ripples{curtime},wavess{curtime});
2544         end
2545         %
2546     case 'lukeexport'
2547         %
2548         % exporting LUKE output
2549         %
2550         sbase = 'LUKE_OUTPUT';
2551         filestr = [sbase,'_*.mat'];
2552         filename = [sbase,'_',outputs{curtime}.data_proc.simul.id,'.mat'];
2553         %
2554         [filename,pathname] = iputfile_jd(1,filestr,['Please provide the ',sbase,' file name'],filename);
2555         %
2556         if filename ~= 0,
2557             %
2558             soutput.data_proc = outputs{curtime}.data_proc;
2559             %
2560             if isfield(outputs{curtime},'dke_out'),
2561                 soutput.f = outputs{curtime}.dke_out.XXf0{end};
2562                 soutput.pn = outputs{curtime}.momentumDKE.pn;
2563                 soutput.mhu = outputs{curtime}.momentumDKE.mhu;
2564                 soutput.xrhoG = outputs{curtime}.data_proc.radial.xrhoG;
2565                 soutput.xrhoP = outputs{curtime}.data_proc.radial.xrhoP;
2566                 soutput.xrhoT = outputs{curtime}.data_proc.radial.xrhoT;
2567                 soutput.xrhoV = outputs{curtime}.data_proc.radial.xrhoV;
2568                 soutput.betath_ref = outputs{curtime}.mksa.betath_ref;
2569                 soutput.ne_ref = outputs{curtime}.mksa.ne_ref;
2570                 soutput.xmhuT = sqrt(outputs{curtime}.gridDKE.xmhubounce2);
2571                 %
2572                 soutput.info.data_proc = 'structure summarizing results with simulation parameters, scalar outputs, radial profiles, etc';
2573                 soutput.info.f = '3D distribution function f(pn,mhu,xrho)';
2574                 soutput.info.pn = 'momentum grid normalized to pT = betath_ref*mc';
2575                 soutput.info.mhu = 'pitch angle grid';
2576                 soutput.info.xrhoG = 'radial grid, rho=r(:,theta=0)/r(lcfs,theta=0)';
2577                 soutput.info.xrhoP = 'radial grid, rho=sqrt(normalized poloidal flux)';
2578                 soutput.info.xrhoT = 'radial grid, rho=sqrt(normalized toroidal flux)';
2579                 soutput.info.xrhoV = 'radial grid, rho=sqrt(normalized volume)';
2580                 soutput.info.betath_ref = 'sqrt(Te/mc2)';
2581                 soutput.info.ne_ref = 'n(r) = <f>*ne_ref';
2582                 soutput.info.xmhuT = 'trapped-passing boundary';
2583             end
2584             %
2585             save([pathname,filename],'-struct','soutput');
2586             %
2587         end  
2588         %
2589         clear sbase filestr filename pathname soutput
2590         %
2591     case 'lukeclear'
2592         %
2593         % clearing output structure
2594         %
2595         jobs(:) = {[]};
2596         %
2597         status.output(:) = 0;
2598         status.data = 2;
2599         %
2600         lukeobj = iluke_info(lukeobj,'output');% enable info display
2601         %
2602     case 'lukedisp'
2603         %
2604         % displaying luke data
2605         %
2606         lukeobj = iluke_info(lukeobj,'');% disable info display
2607         %
2608         it_g = 2 + curtime;%<new>,<all>,...
2609         %
2610         lukeobj.plot1.gindex(it_g) = 0;
2611         lukeobj.plot2.gindex(it_g) = 0;
2612         lukeobj.plot3.gindex(it_g) = 0;
2613         %
2614         cleartags{it_g} = {'output'};
2615         %
2616         iluke_update;% initialize display
2617         %
2618         axs(1) = axes('Parent',lukeobj.plot1.handle,'units','pixels','Position',style.graph_position,'FontName',style.fontname,'FontUnits','pixels','FontSize',style.fontsize);% create new graphic objects with requested characteristics
2619         axs(2) = axes('Parent',lukeobj.plot2.handle,'units','pixels','Position',style.graph_position,'FontName',style.fontname,'FontUnits','pixels','FontSize',style.fontsize);
2620         axs(5) = axes('Parent',lukeobj.plot3.handle,'units','pixels','Position',style.graph_position,'FontName',style.fontname,'FontUnits','pixels','FontSize',style.fontsize); 
2621         axs(4) = axes('Parent',lukeobj.plot3.handle,'units','pixels','Position',style.graph_position,'FontName',style.fontname,'FontUnits','pixels','FontSize',style.fontsize);
2622         axs(3) = axes('Parent',lukeobj.plot3.handle,'units','pixels','Position',style.graph_position,'FontName',style.fontname,'FontUnits','pixels','FontSize',style.fontsize);
2623         %
2624         if curtime > 0,
2625             %
2626             opt.gui = lukeobj.infopanel.handle;
2627             opt.style = style;
2628             opt.save = 0;
2629             opt.nr_dep = 0;
2630             opt.spec = 0;
2631             opt.peak = 'y';
2632             opt.wave = 'y';
2633             opt.rho = 't'; 
2634             opt.blist = [];
2635             opt.diaryname = '';
2636             opt.peakmode = 1;
2637             %
2638             opt.axs = axs;
2639             opt.font = style;
2640             %
2641             [outputs{curtime}.data_proc,ir_display] = proc_luke_jd(outputs{curtime},NaN,-1,0.1,[],'',opt);
2642             %
2643             clear opt
2644             %
2645             graphs(1) = iluke_graphs(lukeobj.plot1.handle,2,'RF power profile','output');
2646             graphs(2) = iluke_graphs(lukeobj.plot2.handle,1,'ohmic power profile','output');
2647             %
2648             if ir_display > 0,
2649                 graphs(3:5) = iluke_graphs(lukeobj.plot3.handle,{[3],[1,5],[2,4]},{'current profile',['f1D ir ',num2str(ir_display)],['f2D ir ',num2str(ir_display)]},'output');
2650             else
2651                 graphs(3) = iluke_graphs(lukeobj.plot3.handle,{1},{'current profile'},'output');
2652                 delete(axs(4:5));
2653             end
2654             %
2655             if isfield(outputs{curtime},'info') && isfield(outputs{curtime}.info,'txt'),
2656                 lukeobj.infotext.string = outputs{curtime}.info.txt;
2657             else
2658                 lukeobj.infotext.string = '';
2659             end
2660             %
2661             lukeobj = iluke_info(lukeobj,'text');% enable info display
2662             %
2663         else
2664             %
2665             [outputs,nw] = luke_disp_outputs_mt(equils,outputs,style,axs);
2666             %
2667             graphs(1) = iluke_graphs(lukeobj.plot1.handle,2,'Current','output');
2668             graphs(2) = iluke_graphs(lukeobj.plot2.handle,2,'Power','output');
2669             if nw > 0,% RF wave
2670                 graphs(3:4) = iluke_graphs(lukeobj.plot3.handle,{[1,4],[2,3]},{'RF power deposition','RF power absorption'},'output');
2671                 delete(axs(5));
2672             else
2673                 delete(axs(3:5));
2674             end
2675             %
2676             clear nw
2677         end
2678         %
2679         ngraphs = length(graphss{it_g});
2680         %
2681         graphss{it_g}(end+1:end+length(graphs)) = graphs;
2682         %
2683         lukeobj.plot1.gindex(it_g) = ngraphs + 1;
2684         lukeobj.plot2.gindex(it_g) = ngraphs + 2;
2685         if length(graphs) > 2,
2686             lukeobj.plot3.gindex(it_g) = ngraphs + 3;
2687         end
2688         %
2689         clear it_g ngraphs axs
2690         %
2691         lukeobj = iluke_info(lukeobj,'text');% enable info display
2692         %
2693     case 'lukefluct'
2694         %
2695         % displaying luke fluct data
2696         %
2697         lukeobj = iluke_info(lukeobj,'');% disable info display
2698         %
2699         it_g = 2 + curtime;%<new>,<all>,...
2700         %
2701         lukeobj.plot1.gindex(it_g) = 0;
2702         lukeobj.plot2.gindex(it_g) = 0;
2703         lukeobj.plot3.gindex(it_g) = 0;
2704         %
2705         cleartags{it_g} = {'fluct'};
2706         %
2707         iluke_update;% initialize display
2708         %
2709         axs(1) = axes('Parent',lukeobj.plot1.handle,'units','pixels','Position',style.graph_position,'FontName',style.fontname,'FontUnits','pixels','FontSize',style.fontsize);% create new graphic objects with requested characteristics
2710         axs(2) = axes('Parent',lukeobj.plot2.handle,'units','pixels','Position',style.graph_position,'FontName',style.fontname,'FontUnits','pixels','FontSize',style.fontsize);
2711         axs(3) = axes('Parent',lukeobj.plot3.handle,'units','pixels','Position',style.graph_position,'FontName',style.fontname,'FontUnits','pixels','FontSize',style.fontsize);
2712         axs(4) = axes('Parent',lukeobj.plot3.handle,'units','pixels','Position',style.graph_position,'FontName',style.fontname,'FontUnits','pixels','FontSize',style.fontsize);
2713         axs(5) = axes('Parent',lukeobj.plot3.handle,'units','pixels','Position',style.graph_position,'FontName',style.fontname,'FontUnits','pixels','FontSize',style.fontsize);
2714         %
2715         opt.style = style;
2716         opt.axs = axs;
2717         opt.font = style;
2718         %
2719         fluct_display.mode = 2;
2720         fluct_display.evol = 0;
2721         fluct_display.stat = 0;
2722         %
2723         backup_file = [workdir,filesep,'backup_',make_luke_simulid_jd(equils{curtime},ohms{curtime},transpfastes{curtime},ripples{curtime},wavess{curtime}),'.mat'];
2724         %
2725         set(lukeobj.busy.handle,'Visible','on');drawnow;
2726         %
2727         fproc_fluctn_jd(backup_file,fluct_display,'',NaN,opt);%Zfluct_out = %outputs{curtime}.data_proc
2728         %
2729         set(lukeobj.busy.handle,'Visible','off');drawnow;
2730         %
2731         clear opt fluct_display backup_file
2732         %
2733         graphs(1) = iluke_graphs(lukeobj.plot1.handle,2,'current evolution','fluct');
2734         graphs(2) = iluke_graphs(lukeobj.plot2.handle,2,'current location','fluct');
2735         graphs(3:5) = iluke_graphs(lukeobj.plot3.handle,{[3,6],[1,4],[2,5]},{'power location','current profile','power profile'},'fluct');
2736         %
2737 %         if isfield(outputs{curtime},'info') && isfield(outputs{curtime}.info,'txt'),
2738 %             lukeobj.infotext.string = outputs{curtime}.info.txt;
2739 %         else
2740             lukeobj.infotext.string = '';
2741 %         end
2742         %
2743         ngraphs = length(graphss{it_g});
2744         %
2745         graphss{it_g}(end+1:end+length(graphs)) = graphs;
2746         %
2747         lukeobj.plot1.gindex(it_g) = ngraphs + 1;
2748         lukeobj.plot2.gindex(it_g) = ngraphs + 2;
2749         lukeobj.plot3.gindex(it_g) = ngraphs + 3;
2750         %
2751         clear it_g ngraphs axs
2752         %
2753         lukeobj = iluke_info(lukeobj,'text');% enable info display
2754         %
2755     case 'parammodify'
2756         %
2757         % modifying luke parameters
2758         %
2759         if curtime > 0,
2760             dkeparam = dkeparams{curtime};
2761         else
2762             dkeparam = dkeparams{1};
2763         end  
2764         %
2765         if isfield(dkeparam,'orig'),
2766             orig = dkeparam.orig;
2767         else
2768             orig = dkeparam;
2769         end
2770         %
2771         [dkeparam,mod] = imod_struct_jd(dkeparam,'dkeparam',1,true,struct,style);
2772         %
2773         if any(mod),
2774             %
2775             if curtime > 0,
2776                 dkeparams{curtime} = dkeparam;
2777                 %
2778                 dkeparams{curtime}.orig = orig;
2779             else
2780                 for it = 1:ntimes,
2781                     dkeparams{it} = dkeparam;
2782                     %
2783                     dkeparams{it}.orig = orig;
2784                 end
2785                 %
2786                 clear it
2787             end
2788             %
2789             status.data = 2;
2790             %
2791         end
2792         %
2793         clear dkeparam orig mod
2794         %
2795     case 'paramload'
2796         %
2797         % loading luke parameters
2798         %
2799         sbase = 'DKEPARAM';
2800         filestr = [sbase,'_*.mat'];
2801         %
2802         if curtime > 0,
2803             dkeparam_id = dkeparams{curtime}.id;
2804         else
2805             dkeparam_id = dkeparams{1}.id;
2806         end
2807         pathname = fileparts(which(['DKEPARAM_',dkeparam_id,'.mat']));
2808         %
2809         [filename,pathname] = igetfile_jd(1,filestr,['Please select the ',sbase,' file(s)'],pathname,0);
2810         %
2811         if filename ~= 0,
2812             %
2813             load([pathname,filename],'dkeparam');
2814             %
2815             if curtime > 0,
2816                 dkeparams{curtime} = dkeparam;
2817             else
2818                 for it = 1:ntimes,
2819                     dkeparams{it} = dkeparam;
2820                 end
2821                 %
2822                 clear it
2823             end
2824         end  
2825         %
2826         clear sbase filestr filename pathname dkeparam
2827         %
2828     case 'paramsave'
2829         %
2830         % saving luke parameters
2831         %
2832         if curtime > 0,
2833             dkeparam = dkeparams{curtime};
2834         else
2835             dkeparam = dkeparams{1};
2836         end  
2837         %
2838         sbase = 'DKEPARAM';
2839         filestr = [sbase,'_*.mat'];
2840         filename = [sbase,'_',dkeparam.id,'.mat'];
2841         %
2842         [filename,pathname] = iputfile_jd(1,filestr,['Please provide the ',sbase,' file name'],filename);
2843         %
2844         %
2845         if filename ~= 0,
2846             %
2847             save([pathname,filename],'dkeparam','-v7.3');
2848             %
2849         end  
2850         %
2851         clear dkeparam sbase filestr filename pathname 
2852         %
2853     case 'paramreset'
2854         %
2855         % resetting luke parameters
2856         %
2857         if curtime > 0,
2858             dkeparams{curtime} = dkeparams{curtime}.orig;
2859         else
2860             for it = 1:ntimes,
2861                 dkeparams{it} = dkeparams{it}.orig;
2862             end
2863             %
2864             clear it
2865         end
2866         %
2867     case 'lukestart'
2868         %
2869         % run luke
2870         %
2871         iluke_run;
2872         %
2873     case 'runcheck'
2874         %
2875         % run check
2876         %
2877         iluke_run;
2878         %
2879     case 'sdiagFEB'
2880         %
2881         % fast electron bremsstrahlung pannel
2882         %
2883         lukeobj = iluke_info(lukeobj,'r5x2');% disable info display
2884         %
2885     case 'hxrcamimport'
2886         %
2887         % fast electron bremsstrahlung camera parameters
2888         %
2889         lukeobj = iluke_info(lukeobj,'');% disable info display
2890         %
2891         iluke_hxrcamimport; 
2892         %
2893         lukeobj.hxrcam.select.value = 1;
2894         %
2895         lukeobj = iluke_info(lukeobj,'r5x2');% disable info display
2896         %
2897     case 'hxrcamdisp'
2898         %
2899         % fast electron bremsstrahlung camera display
2900         %
2901         it_g = 2 + curtime;%<new>,<all>,...
2902         %
2903         lukeobj.plot1.gindex(it_g) = 0;
2904         lukeobj.plot2.gindex(it_g) = 0;
2905         %
2906         cleartags{it_g} = {'hxrcam'};
2907         %
2908         iluke_update;% initialize display
2909         %
2910         newgraph1_handle = axes('Parent',lukeobj.plot1.handle,'units','pixels','Position',style.graph_position,'FontName',style.fontname,'FontUnits','pixels','FontSize',style.fontsize);% create new graphic objects with requested characteristics
2911         newgraph2_handle = axes('Parent',lukeobj.plot2.handle,'units','pixels','Position',style.graph_position,'FontName',style.fontname,'FontUnits','pixels','FontSize',style.fontsize);
2912         %
2913         equilibrium_jd(equils{curtime},NaN,3+1i,'linear',10,[newgraph1_handle,newgraph2_handle],style);
2914         %
2915         if lukeobj.hxrcam.select.value == 1,
2916             icams = 1:length(hxr.cam);
2917         else
2918             icams = lukeobj.hxrcam.select.value - 1;
2919         end
2920         %
2921         xlim = [min(equils{curtime}.ptx(end,:)),max(equils{curtime}.ptx(end,:))];
2922         ylim = [min(equils{curtime}.pty(end,:)),max(equils{curtime}.pty(end,:))];
2923         %
2924         iluke_hxrcamdisp(hxr.cam(icams),xlim,ylim,equils{curtime}.Rp,equils{curtime}.Zp,[newgraph1_handle,newgraph2_handle],style)
2925         %
2926         if length(icams) == 1,
2927             camstr = ['Cam #',num2str(hxr.cam{icams}.camnum)];
2928         else
2929             camstr = 'All Cams';
2930         end            
2931         %
2932         graphs(1) = iluke_graphs(lukeobj.plot1.handle,1,[camstr,' HXR Chords, Poloidal view'],'hxrcam');
2933         graphs(2) = iluke_graphs(lukeobj.plot2.handle,1,[camstr,' HXR Chords, Toroidal view'],'hxrcam');
2934         %
2935         ngraphs = length(graphss{it_g});
2936         %
2937         graphss{it_g}(end+1:end+length(graphs)) = graphs;
2938         %
2939         lukeobj.plot1.gindex(it_g) = ngraphs + 1;
2940         lukeobj.plot2.gindex(it_g) = ngraphs + 2;
2941         %
2942         clear it_g xlim ylim icams ngraphs graphs newgraph1_handle newgraph2_handle
2943         %
2944     case 'hxrparammodify'
2945         %
2946         % fast electron bremsstrahlung computing parameters
2947         %
2948         lukeobj = iluke_info(lukeobj,'');% disable info display
2949         %
2950         hxr.param = conc_struct_jd(imod_struct_jd(rmfield(hxr.param,{'kmin','kmax'}),'hxrparam',1,lukeobj.infopanel.handle,struct,style),selectfields_jd(hxr.param,{'kmin','kmax'}));
2951         %
2952         lukeobj = iluke_info(lukeobj,'r5x2');% disable info display
2953         %
2954     case 'hxrexpimport'
2955         %
2956         % fast electron bremsstrahlung experimental data
2957         %
2958         hxr.exp = iluke_hxrexpimport(external.hxr); 
2959         %
2960     case 'hxrexpclear'
2961         %
2962         % fast electron bremsstrahlung experimental data
2963         %
2964         hxr.exp = ''; 
2965         %
2966     case 'hxrexpdisp'
2967         %
2968         % fast electron bremsstrahlung experimental data
2969         %
2970         it_g = 2 + curtime;%<new>,<all>,...
2971         %
2972         lukeobj.plot1.gindex(it_g) = 0;
2973         lukeobj.plot2.gindex(it_g) = 0;
2974         lukeobj.plot3.gindex(it_g) = 0;
2975         %
2976         cleartags{it_g} = {'hxrexp'};
2977         %
2978         iluke_update;% initialize display
2979         %
2980         axs(1) = axes('Parent',lukeobj.plot1.handle,'units','pixels','Position',style.graph_position,'FontName',style.fontname,'FontUnits','pixels','FontSize',style.fontsize);% create new graphic objects with requested characteristics
2981         axs(2) = axes('Parent',lukeobj.plot2.handle,'units','pixels','Position',style.graph_position,'FontName',style.fontname,'FontUnits','pixels','FontSize',style.fontsize);
2982         axs(3) = axes('Parent',lukeobj.plot3.handle,'units','pixels','Position',style.graph_position,'FontName',style.fontname,'FontUnits','pixels','FontSize',style.fontsize);
2983         %
2984         ic = lukeobj.hxrcam.select.value - 1;% selected camera
2985         ichord = lukeobj.hxrchord.select.value - 1;% selected chord
2986         ibin = lukeobj.hxrbin.select.value - 1;% selected energy bin
2987         %
2988         if curtime == 0,
2989             hxrtimes = shotimes;
2990         else
2991             hxrtimes = shotimes(curtime);
2992         end
2993         %
2994         [nobj,graphids] = iluke_hxrexpdisp(hxr,struct,hxrtimes,ic,ichord,ibin,axs,style);
2995         %
2996         for iplot = 1:3,
2997             if nobj(iplot) > 0,
2998                 plotstr = ['plot',num2str(iplot)];
2999                 graphss{it_g}(end+1) = iluke_graphs(lukeobj.(plotstr).handle,nobj(iplot),graphids{iplot},'hxrexp');
3000                 lukeobj.(plotstr).gindex(it_g) = length(graphss{it_g});
3001             else
3002                 delete(axs(iplot));
3003             end
3004         end
3005         %
3006         clear it_g ic ichord ibin nobj graphids iplot axs
3007         %
3008     case 'hxrbremrun'
3009         %
3010         % run r5x2
3011         %
3012         lukeobj = iluke_info(lukeobj,'');% disable info display
3013         %
3014         select.style = style;
3015         select.p_opt = -1;
3016         select.d_opt = 'n';
3017         select.n_opt = -1;
3018         select.t_opt = 0;
3019         %
3020         dkedisplay.fhxr = false;% do not save distribution in R5X2
3021         %
3022         if curtime == 0,% treat all times with LUKE distribution calculated
3023             flag_shotimes = find(status.sdiag(1,:) >= 1);
3024         elseif curtime > 0 && status.sdiag(1,curtime) >= 1,% select one time from external structure if available
3025             flag_shotimes = curtime;
3026         else
3027             flag_shotimes = [];% no action
3028         end
3029         %
3030         ncalc = length(flag_shotimes);
3031         %
3032         if ncalc > 1,% more than one time
3033             %
3034             mdce_mode = iselect_jd(dkepath.distprofiles,'Distribution of calc. : ',lukeobj.infopanel.handle,style.distselectstyle,1,'popupmenu') - 1;
3035             %
3036             if mdce_mode > 2,
3037                 mdce_mode = 2 - mdce_mode;%use of remcomputing with negative mdce_mode
3038             end
3039             %
3040             dkecluster = clustermode_luke(mdce_mode,'',dkepath);%MatLab distributed computing environment
3041             %
3042             set(lukeobj.busy.handle,'Visible','on');drawnow;
3043             [flag,equilHXR,radialHXR,Zbremplasma] = mdce_run('irunhxr_jd',{lukeobj.infopanel.handle,workdir,tokamak,'',hxr,'','','',dkedisplay,select},4,outputs(flag_shotimes),dkecluster);
3044             set(lukeobj.busy.handle,'Visible','off');drawnow;
3045             %
3046             clear mdce_mode dkecluster flag 
3047             %
3048         elseif ncalc == 1% treat one time
3049             %
3050             [equilHXR,radialHXR,Zbremplasma] = irunhxr_jd(lukeobj.infopanel.handle,workdir,tokamak,outputs{flag_shotimes},hxr,'','','',dkedisplay,select);
3051             %
3052         else
3053             equilHXR = [];
3054             radialHXR = [];
3055             Zbremplasma = [];
3056         end
3057         %
3058         if isfield(equilHXR,'err'),
3059             lukeobj.infotext.string = {'Error creating structure(s) ''hxr.brem'' : ',equilHXR.err};
3060         elseif ~isempty(equilHXR),
3061             %
3062             if ncalc > 1,% more than one time
3063                 %
3064                 for icalc = 1:ncalc,
3065                     sdiags{1,flag_shotimes(icalc)}.equilHXR = equilHXR{icalc};
3066                     sdiags{1,flag_shotimes(icalc)}.radialHXR = radialHXR{icalc};
3067                     sdiags{1,flag_shotimes(icalc)}.Zbremplasma = Zbremplasma{icalc};
3068                 end
3069                 %
3070                 clear icalc
3071                 %
3072             elseif ncalc == 1,% replace or fill an existing time
3073                 %
3074                 sdiags{1,flag_shotimes}.equilHXR = equilHXR;
3075                 sdiags{1,flag_shotimes}.radialHXR = radialHXR;
3076                 sdiags{1,flag_shotimes}.Zbremplasma = Zbremplasma;
3077                 %
3078             end
3079             %
3080             status.sdiag(1,flag_shotimes) = 2;
3081             %
3082             status.data = 2;
3083             %
3084             lukeobj.lukeid.string = '';
3085             %
3086             clear flag_shotimes ncalc
3087             %
3088         end
3089         %
3090         clear select equilHXR radialHXR Zbremplasma
3091         %
3092         lukeobj = iluke_info(lukeobj,'r5x2');% enable info display
3093         %
3094         %iluke_r5x2;
3095         %
3096     case 'hxrbremdisp'
3097         %
3098         % fast electron bremsstrahlung calculated data
3099         %
3100         it_g = 2 + curtime;%<new>,<all>,...
3101         %
3102         lukeobj.plot1.gindex(it_g) = 0;
3103         lukeobj.plot2.gindex(it_g) = 0;
3104         lukeobj.plot3.gindex(it_g) = 0;
3105         %
3106         cleartags{it_g} = {'hxrbrem'};
3107         %
3108         iluke_update;% initialize display
3109         %
3110         axs(1) = axes('Parent',lukeobj.plot1.handle,'units','pixels','Position',style.graph_position,'FontName',style.fontname,'FontUnits','pixels','FontSize',style.fontsize);% create new graphic objects with requested characteristics
3111         axs(2) = axes('Parent',lukeobj.plot2.handle,'units','pixels','Position',style.graph_position,'FontName',style.fontname,'FontUnits','pixels','FontSize',style.fontsize);
3112         axs(3) = axes('Parent',lukeobj.plot3.handle,'units','pixels','Position',style.graph_position,'FontName',style.fontname,'FontUnits','pixels','FontSize',style.fontsize);
3113         %
3114 %         ic = lukeobj.hxrcam.select.value - 1;% selected camera
3115 %         ichord = lukeobj.hxrchord.select.value - 1;% selected chord
3116         ir = lukeobj.hxrrho.select.value - 1;% selected radial position
3117         it = lukeobj.hxrtheta.select.value - 1;% selected poloidal position
3118         idir = lukeobj.hxrdir.select.value - 1;% selected direction of emission
3119         ikphot = lukeobj.hxrkphot.select.value - 1;% selected photon energy
3120         %
3121         if curtime == 0,
3122             ihxrtimes = status.sdiag(1,:) >= 2;
3123         else
3124             ihxrtimes = curtime;
3125         end
3126         %
3127         select.style = style;
3128         select.dir = lukeobj.hxrdir.select.string;
3129         %
3130         [nobj,graphids] = iluke_hxrbremdisp(shotimes(ihxrtimes),sdiags(1,ihxrtimes),ikphot,ir,it,idir,axs,select);
3131         %
3132         for iplot = 1:3,
3133             if nobj(iplot) > 0,
3134                 plotstr = ['plot',num2str(iplot)];
3135                 graphss{it_g}(end+1) = iluke_graphs(lukeobj.(plotstr).handle,nobj(iplot),graphids{iplot},'hxrbrem');
3136                 lukeobj.(plotstr).gindex(it_g) = length(graphss{it_g});
3137             else
3138                 delete(axs(iplot));
3139             end
3140         end
3141         %
3142         clear it_g ic ichord ibin nobj graphids iplot axs select
3143         %
3144     case 'hxrdiagrun'
3145         %
3146         % run r5x2
3147         %
3148         lukeobj = iluke_info(lukeobj,'');% disable info display
3149         %
3150         select.style = style;
3151         select.p_opt = -1;
3152         select.d_opt = 'n';
3153         select.s_opt = 'n';
3154         select.n_opt = -1;
3155         select.t_opt = 0;
3156         %
3157         if curtime == 0,% treat all times with LUKE distribution calculated
3158             flag_shotimes = find(status.sdiag(1,:) >= 2);
3159         elseif curtime > 0 && status.sdiag(1,curtime) >= 2,% select one time from external structure if available
3160             flag_shotimes = curtime;
3161         else
3162             flag_shotimes = [];% no action
3163         end
3164         %
3165         ncalc = length(flag_shotimes);
3166         %
3167         if ncalc > 1,% more than one time
3168             %
3169             mdce_mode = iselect_jd(dkepath.distprofiles,'Distribution of calc. : ',lukeobj.infopanel.handle,style.distselectstyle,1,'popupmenu') - 1;
3170             %
3171             if mdce_mode > 2,
3172                 mdce_mode = 2 - mdce_mode;%use of remcomputing with negative mdce_mode
3173             end
3174             %
3175             dkecluster = clustermode_luke(mdce_mode,'',dkepath);%MatLab distributed computing environment
3176             %
3177             set(lukeobj.busy.handle,'Visible','on');drawnow;
3178             [flag,Zbremchord,Zbremplasma,Zbremdiag] = mdce_run('irunhxr_jd',{lukeobj.infopanel.handle,workdir,tokamak,'',hxr,'','','',dkedisplay,select},4,sdiags(1,flag_shotimes),dkecluster);
3179             set(lukeobj.busy.handle,'Visible','off');drawnow;
3180             %
3181             clear mdce_mode dkecluster flag 
3182             %
3183         elseif ncalc == 1% treat one time
3184             %
3185             [Zbremchord,Zbremplasma,Zbremdiag] = irunhxr_jd(lukeobj.infopanel.handle,workdir,tokamak,sdiags{1,flag_shotimes},hxr,'','','',dkedisplay,select);
3186             %
3187         else
3188             Zbremchord = [];
3189             Zbremplasma = [];
3190             Zbremdiag = [];
3191         end
3192         %
3193         if isfield(Zbremchord,'err'),
3194             lukeobj.infotext.string = {'Error creating structure(s) ''hxr.diag'' : ',Zbremchord.err};
3195         elseif ~isempty(Zbremchord),
3196             %
3197             if ncalc > 1,% more than one time
3198                 %
3199                 for icalc = 1:ncalc,
3200                     sdiags{1,flag_shotimes(icalc)}.Zbremchord = Zbremchord{icalc};
3201                     sdiags{1,flag_shotimes(icalc)}.Zbremplasma = Zbremplasma{icalc};
3202                     sdiags{1,flag_shotimes(icalc)}.Zbremdiag = Zbremdiag{icalc};
3203                 end
3204                 %
3205             elseif ncalc == 1,% replace or fill an existing time
3206                 %
3207                 sdiags{1,flag_shotimes}.Zbremchord = Zbremchord;
3208                 sdiags{1,flag_shotimes}.Zbremplasma = Zbremplasma;
3209                 sdiags{1,flag_shotimes}.Zbremdiag = Zbremdiag;
3210                 %
3211             end
3212             %
3213             status.sdiag(1,flag_shotimes) = 3;
3214             %
3215             status.data = 2;
3216             %
3217             lukeobj.lukeid.string = '';
3218             %
3219             clear flag_shotimes ncalc 
3220             %
3221         end
3222         %
3223         clear select Zbremchord Zbremplasma Zbremdiag
3224         %
3225         lukeobj = iluke_info(lukeobj,'r5x2');% enable info display
3226         %
3227         %iluke_r5x2;
3228         %
3229     case 'hxrdiagdisp'
3230         %
3231         % fast electron bremsstrahlung experimental vs LUKE
3232         %
3233         it_g = 2 + curtime;%<new>,<all>,...
3234         %
3235         lukeobj.plot1.gindex(it_g) = 0;
3236         lukeobj.plot2.gindex(it_g) = 0;
3237         lukeobj.plot3.gindex(it_g) = 0;
3238         %
3239         cleartags{it_g} = {'hxrdiag'};
3240         %
3241         iluke_update;% initialize display
3242         %
3243         axs(1) = axes('Parent',lukeobj.plot1.handle,'units','pixels','Position',style.graph_position,'FontName',style.fontname,'FontUnits','pixels','FontSize',style.fontsize);% create new graphic objects with requested characteristics
3244         axs(2) = axes('Parent',lukeobj.plot2.handle,'units','pixels','Position',style.graph_position,'FontName',style.fontname,'FontUnits','pixels','FontSize',style.fontsize);
3245         axs(3) = axes('Parent',lukeobj.plot3.handle,'units','pixels','Position',style.graph_position,'FontName',style.fontname,'FontUnits','pixels','FontSize',style.fontsize);
3246         %
3247         ic = lukeobj.hxrcam.select.value - 1;% selected camera
3248         ichord = lukeobj.hxrchord.select.value - 1;% selected chord
3249         ibin = lukeobj.hxrbin.select.value - 1;% selected energy bin
3250         %
3251         if curtime == 0,
3252             ihxrtimes = status.sdiag(1,:) >= 3;
3253         else
3254             ihxrtimes = curtime;
3255         end
3256         %
3257         if curtime == 0,
3258             hxrtimes = shotimes;
3259         else
3260             hxrtimes = shotimes(curtime);
3261         end
3262         %
3263         [nobj,graphids] = iluke_hxrexpdisp(hxr,sdiags(1,ihxrtimes),shotimes(ihxrtimes),ic,ichord,ibin,axs,style);
3264         %
3265         for iplot = 1:3,
3266             if nobj(iplot) > 0,
3267                 plotstr = ['plot',num2str(iplot)];
3268                 graphss{it_g}(end+1) = iluke_graphs(lukeobj.(plotstr).handle,nobj(iplot),graphids{iplot},'hxrdiag');
3269                 lukeobj.(plotstr).gindex(it_g) = length(graphss{it_g});
3270             else
3271                 delete(axs(iplot));
3272             end
3273         end
3274         %
3275         clear it_g ic ichord ibin nobj graphids iplot axs
3276         %
3277     case 'savegraphs'
3278         %
3279         % save graphs
3280         %
3281         if curtime > 0,
3282             shotimestr = num2str(shotimes(curtime),'%6.4f');
3283         else
3284             shotimestr = '_MultiTimes';
3285         end
3286         %
3287         iluke_print(2,['Fig_',tokamak,'_',shotnum,'_',shotimestr,' ',lukeobj.(['graph',igraph,'sel']).string{lukeobj.(['graph',igraph,'sel']).value}],'figures/',graphss{2+curtime}(lukeobj.(['plot',igraph]).gindex(2+curtime)).handles);
3288         %
3289         clear igraph
3290         %
3291     case 'cleargraphs'
3292         %
3293         % clear all graphs
3294         %
3295         cleartags(:) = {{'all'}};% clear graphss
3296         %
3297         iluke_update
3298         %
3299         for h = [lukeobj.plot1.handle,lukeobj.plot2.handle,lukeobj.plot3.handle],
3300             ch = get(h,'children');
3301             if length(ch) > 3,
3302                 disp('WARNING : some graphs were not deleted by cleartags. Clearing enforced.')
3303                 delete(ch(1:end-3));% keep handles for plot list, print & save
3304             end
3305         end        
3306         %
3307         clear h ch
3308         %
3309 end
3310 %
3311 clear action
3312 %
3313 iluke_update;
3314 %

Community support and wiki are available on Redmine. Last update: 18-Apr-2019.