irunluke_jd

PURPOSE ^

SYNOPSIS ^

function irunluke_jd(basestr,signs,opt_gui)

DESCRIPTION ^

 This script interactively loads the equilibrium, profiles and launching data, and runs LUKE with
 either C3PO, TORAY or ART ray-tracing data

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 
0002 function irunluke_jd(basestr,signs,opt_gui)
0003     %
0004     % This script interactively loads the equilibrium, profiles and launching data, and runs LUKE with
0005     % either C3PO, TORAY or ART ray-tracing data
0006     %
0007     if nargin < 3,
0008         opt_gui = input_dke_yp('Graphical User Interface mode (yes:1,no:0)',0,[0,1]) == 1;
0009     elseif ~isscalar(opt_gui) || ~any(opt_gui == [0,1]),
0010         error('opt_gui must be a logical scalar')
0011     elseif ~islogical(opt_gui),
0012             opt_gui = opt_gui == 1;
0013     end
0014     %
0015     opt_status_windows = input_dke_yp('Independent simulations status windows (yes:1,no:0)',0,[0,1]) == 1;
0016     %
0017     if nargin < 2,
0018         signs = '';
0019     end
0020     if nargin < 1,
0021         basestr = input_dke_yp('Enter the machine name (such as ''ITER'', ''TCV'', ''TS'', ''JET'', ''COMPASS'', ''SST1'', ''EAST'', ''HL2A'', ''CMOD'', ''WEST'', ''D3D'',...)',' ');
0022     end
0023     %
0024     if input_dke_yp('Clear all figures (yes:1,no:0)',0,[0,1]) == 1,
0025         close all;
0026     end
0027     %
0028     clc
0029     %
0030     if opt_status_windows,
0031         tprintf('Working LUKE simulation status','');
0032         tprintf('LUKE simulations status','');
0033     end
0034     %
0035     quitmsg = '-----> Run aborted';
0036     warning off
0037     %
0038     isel = 1;
0039     %
0040     status.data = 0;
0041     status.dkeparam = 0;
0042     status.equil = 0;
0043     status.waves = 0;
0044     status.ohm = 0;
0045     status.transpfaste = 0;
0046     status.ripple = 0;
0047     status.external = 0;
0048     %
0049     status.output = 0;
0050     %
0051     fileids.data = '';
0052     fileids.dkeparam = '';
0053     fileids.equil = '';
0054     fileids.waves = '';
0055     fileids.ohm = '';
0056     fileids.transpfaste = '';
0057     fileids.ripple = '';
0058     fileids.external = '';
0059     %
0060     paths.data = '';
0061     paths.dkeparam = '';
0062     paths.equil = '';
0063     paths.waves = '';
0064     paths.ohm = '';
0065     paths.transpfaste = '';
0066     paths.ripple = '';
0067     paths.external = '';
0068     %
0069     dkeparam = '';
0070     equil = '';
0071     waves = '';
0072     ohm = '';
0073     transpfaste = '';
0074     ripple = '';
0075     external = '';
0076     %
0077     output = '';
0078     luke_job = '';
0079     %
0080     workdir = [pwd,'/'];
0081     %
0082     dkepath = load_structures_yp('dkepath','','');
0083     if isfield(dkepath,'remote'),
0084         remote = dkepath.remote;
0085     else
0086         remote = '';
0087     end
0088     %
0089     nrem = length(remote);
0090     %
0091     while isel >= 0,
0092         %
0093         % CLEAR outdated structures and DEFINE STATUS
0094         %
0095         if status.data == 1,
0096             statstr.data = fileids.data;
0097         elseif status.data == 2,
0098             statstr.data = [fileids.data,' < data modified, consider a save >'];
0099         else 
0100             statstr.data = '< No data yet >';
0101         end
0102         %
0103         statstr.workdir = workdir;
0104         statstr.dkepath = dkepath.luke_root;
0105         %
0106         if status.dkeparam == 1,
0107     %         statstr.dkeparam = dkeparam.id;
0108             if isempty(fileids.dkeparam),
0109                 statstr.dkeparam = ['< dkeparam structure not saved >'];
0110             else
0111                 statstr.dkeparam = fileids.dkeparam;
0112             end
0113         else
0114             if ~isempty(dkeparam),
0115                 disp('The structure ''dkeparam'' is outdated and cleared.');
0116                 dkeparam = '';
0117                 ostr = ' outdated.';
0118             else
0119                 ostr = '';
0120             end            
0121             statstr.dkeparam = ['<',ostr,' Must load/create a structure ''dkeparam'' >'];
0122         end
0123         %
0124         if status.equil == 1,
0125             statstr.equil = equil.id;
0126         else 
0127             if ~isempty(equil),
0128                 disp('The structure ''equil'' is outdated and cleared.')
0129                 equil = '';
0130                 ostr = ' outdated.';
0131             else
0132                 ostr = '';
0133             end            
0134             statstr.equil = ['<',ostr,' Must load/create a structure ''equil'' >'];
0135         end
0136         %
0137         if status.waves == 1,
0138             statstr.waves = waves{1}.id;
0139             for iw = 2:length(waves),
0140                 statstr.waves = [statstr.waves,'; ',waves{iw}.id];
0141             end
0142         else 
0143             if ~isempty(waves),
0144                 disp('The structure ''waves'' is outdated and cleared.')
0145                 waves = '';
0146                 ostr = ' outdated.';
0147             else
0148                 ostr = '';
0149             end            
0150             statstr.waves = ['<',ostr,' The ''wave'' structures are optional >'];
0151         end
0152         %
0153         if status.ohm == 1,
0154             statstr.ohm = ohm.id;
0155         else 
0156             if ~isempty(ohm),
0157                 disp('The structure ''ohm'' is outdated and cleared.')
0158                 ohm = '';
0159                 ostr = ' outdated.';
0160             else
0161                 ostr = '';
0162             end            
0163             statstr.ohm = ['<',ostr,' The ''ohm'' structure is optional >'];
0164         end
0165         %
0166         if status.transpfaste == 1,
0167             statstr.transpfaste = transpfaste.id;
0168         else 
0169             if ~isempty(transpfaste),
0170                 disp('The structure ''transpfaste'' is outdated and cleared.')
0171                 transpfaste = '';
0172                 ostr = ' outdated.';
0173             else
0174                 ostr = '';
0175             end            
0176             statstr.transpfaste = ['<',ostr,' The ''transpfaste'' structure is optional >'];
0177         end
0178         %
0179         if status.ripple == 1,
0180             statstr.ripple = ripple.id;
0181         else 
0182             if ~isempty(ripple),
0183                 disp('The structure ''ripple'' is outdated and cleared.')
0184                 ripple = '';
0185                 ostr = ' outdated.';
0186             else
0187                 ostr = '';
0188             end            
0189             statstr.ripple = ['<',ostr,' The ''ripple'' structure is optional >'];
0190         end
0191         %
0192         if status.external == 1,
0193             statstr.external = external.id;
0194         else 
0195             if ~isempty(external),
0196                 disp('The structure ''external'' is outdated and cleared.')
0197                 external = '';
0198                 ostr = ' outdated.';
0199             else
0200                 ostr = '';
0201             end   
0202             statstr.external = ['<',ostr,' No data from external database in memory. >'];
0203         end
0204         %
0205         if status.output == 1,
0206             statstr.output = id_simul;
0207         else 
0208             if ~isempty(output),
0209                 disp('The structure ''output'' is outdated and cleared.')
0210                 output = '';
0211                 ostr = ' outdated.';
0212             else
0213                 ostr = '';
0214             end   
0215             %
0216             if ~isempty(luke_job),
0217                 %
0218                 if ~isempty(luke_job.id),
0219                     idstr = ['id ',luke_job.id];
0220                 else
0221                     idstr = ['timeid ',luke_job.timeid];
0222                 end
0223                 if ~isempty(luke_job.remote.host),
0224                     hoststr = ['on host ',luke_job.remote.host];
0225                 else
0226                     hoststr = 'on localhost';
0227                 end
0228                 statstr.output = ['< LUKE is currently running under job ',idstr,' ',hoststr,' >'];
0229                 %
0230             elseif ~isempty(dkeparam) && ~isempty(equil),
0231                 %
0232                 flag_wave = 0;
0233                 flag_launch = 0;
0234                 %
0235                 if exist('waves')
0236                     for iw = 1:length(waves),
0237                         if isfield(waves{iw},'job')
0238                             flag_wave = flag_wave + 1;
0239                         end
0240                         %
0241                         if isfield(waves{iw},'launchs')
0242                             for il = 1:length(waves{iw}.launchs),
0243                                 if  isfield(waves{iw}.launchs{il},'job')
0244                                     flag_wave = flag_wave + 1;
0245                                     flag_launch = flag_launch + 1;
0246                                 end
0247                             end  
0248                         end
0249                     end
0250                 end
0251                 %
0252                 if flag_wave == 0,
0253                     statstr.output = ['<',ostr,' You can start LUKE now. >'];
0254                 else
0255                     if flag_launch == 0,
0256                         statstr.output = ['<',ostr,' You cannot start LUKE now until batch ray-tracing calculations are not completed. >'];
0257                     else
0258                         statstr.output = ['<',ostr,' You cannot start LUKE now until batch coupling and ray-tracing calculations are not completed. >'];
0259                     end
0260                 end
0261                 %
0262             else
0263                 %
0264                 statstr.output = ['<',ostr,' First build required structures. >'];
0265                 %
0266             end
0267         end
0268         %
0269         if ~isempty(equil),
0270             id_simul_o = equil.id;
0271         else
0272             id_simul_o = basestr;
0273         end
0274         for iw = 1:length(waves),
0275             id_simul_o = [id_simul_o,'_',waves{iw}.id];
0276         end
0277         if ~isempty(ohm),
0278             id_simul_o = [id_simul_o,'_',ohm.id];
0279         end
0280         if ~isempty(transpfaste),
0281             id_simul_o = [id_simul_o,'_',transpfaste.id];
0282         end
0283         if ~isempty(ripple),
0284             id_simul_o = [id_simul_o,'_',ripple.id];
0285         end
0286         %
0287         % MAIN MENU
0288         %
0289         disp(' ');
0290         disp([' ----------- < ',LUKEversion_jd,' Version > ----------- '])
0291         disp(' ');
0292         disp(['Machine : ',basestr]);
0293         disp(' ');
0294         disp('************* STATUS *************')
0295         disp(' ');
0296         disp(['LUKE data              : ',statstr.data]);
0297         disp(['Work directory         : ',statstr.workdir]);
0298         disp(['LUKE path              : ',statstr.dkepath]);
0299         disp(['LUKE parameters        : ',statstr.dkeparam]);
0300         disp(['Equilibrium            : ',statstr.equil]);
0301         disp(['RF waves               : ',statstr.waves]);
0302         disp(['Ohmic E-field          : ',statstr.ohm]);
0303         disp(['Fast electron transport: ',statstr.transpfaste]);
0304         disp(['Magnetic ripple losses : ',statstr.ripple]);
0305         disp(' ');
0306         disp(['LUKE output            : ',statstr.output]);
0307         disp(['External database      : ',statstr.external]);
0308         %
0309         if exist('tprintf.m','file') & opt_status_windows == 1,%second window display
0310             tprintf('Working LUKE simulation status');%clear window
0311             tprintf('Working LUKE simulation status',[' ----------- < ',LUKEversion_jd,' Version > ----------- ']);
0312             tprintf('Working LUKE simulation status',' ');
0313             tprintf('Working LUKE simulation status',['Machine : ',basestr]);
0314             tprintf('Working LUKE simulation status',' ');
0315             tprintf('Working LUKE simulation status','************* STATUS *************');
0316             tprintf('Working LUKE simulation status',' ');
0317             tprintf('Working LUKE simulation status',['LUKE data              : ',statstr.data]);
0318             tprintf('Working LUKE simulation status',['Work directory         : ',statstr.workdir]);
0319             tprintf('Working LUKE simulation status',['LUKE path              : ',statstr.dkepath]);
0320             tprintf('Working LUKE simulation status',['LUKE parameters        : ',statstr.dkeparam]);
0321             tprintf('Working LUKE simulation status',['Equilibrium            : ',statstr.equil]);
0322             tprintf('Working LUKE simulation status',['RF waves               : ',statstr.waves]);
0323             tprintf('Working LUKE simulation status',['Ohmic E-field          : ',statstr.ohm]);
0324             tprintf('Working LUKE simulation status',['Fast electron transport: ',statstr.transpfaste]);
0325             tprintf('Working LUKE simulation status',['Magnetic ripple losses : ',statstr.ripple]);
0326             tprintf('Working LUKE simulation status',' ');
0327             tprintf('Working LUKE simulation status',['LUKE output            : ',statstr.output]);
0328             tprintf('Working LUKE simulation status',['External database      : ',statstr.external]);
0329             %
0330         end
0331         %
0332         disp(' ');
0333         disp('************** MENU **************')
0334         disp(' ');
0335         disp('Please select one of the following options:');
0336         disp(' ');
0337         disp('[1]   Load existing data file');
0338         disp('[2]   Save current data in file');
0339         disp('[3]   Specify work directory');
0340         disp('[4]   Load/clear data from external database');
0341         disp(' ');
0342         disp('[6]   Load/create/modify ''dkeparam'' structure (LUKE parameters)');
0343         disp('[7]   Load/create/modify ''equil'' structure (Plasma equilibrium)');
0344         disp('[8]   Load/create/modify ''wave'' structures (RF waves)');
0345         disp('[9]   Load/create/modify ''ohm'' structure (Ohmic E-field)');
0346         disp('[10]  Load/create/modify ''transpfaste'' structure (Fast electron transport)');
0347         disp('[11]  Load/create/modify ''ripple'' structure (Magnetic ripple losses)');
0348         disp(' ');
0349         disp('[12]  Display equilibrium data');
0350         disp('[13]  Display RF wave data');
0351         disp('[14]  Display LUKE results');
0352         disp(' ');
0353         disp('[15]  Calculate HXR emission');
0354         disp('[16]  Generate LUKE run script');
0355         disp(' ');
0356         disp('[17]  Go to command line')
0357         disp('[18]  Close all figures')
0358         disp('[19]  LUKE documentation')
0359         disp('[20]  LUKE project management (redmine): bug report, documentation, tutorial, repositories, etc')
0360         disp('[21]  Check job status of all simulations in the local folder')        
0361         disp(' ');
0362         disp('[0]   Run LUKE or load BATCH LUKE results');
0363         disp('[-1]  Exit LUKE');
0364         disp('[-2]  Exit LUKE, close all figures and removes all variables, globals, functions and MEX links');
0365         disp(' ');
0366         %
0367         isel = input('? [-1] :');
0368         %
0369         clc
0370         %
0371         if isempty(isel) || ~isnumeric(isel) || ~any(isel == [-2:4,6:21]),
0372             isel = -1;
0373         end
0374         %
0375         try
0376             %
0377             if isel == 1,
0378                 %
0379                 % LOAD DATA FILE
0380                 %
0381                 if status.data == 2 && input_dke_yp('--> Previous data is not saved. Are you sure you want to load new file (y/n)','n',{'y','n'}) == 'n',
0382                     continue;
0383                 end
0384                 %
0385                 disp('');
0386                 disp('************** LOAD DATA FILE **************')
0387                 disp('');
0388                 %
0389                 [data_file,data_path] = igetfile_jd(opt_gui,{'LUKE_DATA_*.mat';'LUKE_RESULTS_*.mat';'last_luke@*';'before_luke@*'},'Please select a LUKE data file');
0390                 %
0391                 if data_file == 0,
0392                     disp('-----> No LUKE data file specified.');
0393                 else
0394                     %
0395                     clear fileids paths
0396                     %
0397                     if strfind(data_file,'LUKE_DATA_'),
0398                         %
0399                         load([data_path,data_file],'basestr','signs','status','fileids','paths','id_simul','luke_job',...
0400                             'dkeparam','dkedisplay','equil','waves','ohm','transpfaste','ripple','output','external');
0401                         disp(['-----> The data file ',[data_path,data_file],' is loaded.']);
0402                         %
0403                         if exist('equil','var') && isfield(equil,'tokamak'),
0404                             basestr = equil.tokamak;
0405                         else
0406                             basestr = data_file(11:9 + find(data_file(11:end) == '_',1,'first'));
0407                             %basestr = input_dke_yp('Please enter the tokamak name',basestr);
0408                         end
0409                         %
0410                         fileids.data = data_file;
0411                         paths.data = data_path;
0412                         %
0413                         if ~isfield(fileids,'dkeparam') || (~isempty(fileids.dkeparam) && ~exist([paths.dkeparam,'DKEPARAM_',fileids.dkeparam,'.mat'],'file')),
0414                             fileids.dkeparam = '';
0415                             paths.dkeparam = '';
0416                         end
0417                         %
0418                         if ~isfield(status,'dkeparam'),
0419                             if ~isempty(dkeparam),
0420                                 status.dkeparam = 1;
0421                             else
0422                                 status.dkeparam = 0;
0423                             end
0424                         end
0425                         %
0426                         if ~isfield(fileids,'equil') || (~isempty(fileids.equil) && ~exist([paths.equil,'EQUIL_',fileids.equil,'.mat'],'file')),
0427                             fileids.equil = '';
0428                             paths.equil = '';
0429                         end
0430                         %
0431                         if ~isfield(fileids,'waves'),
0432                             %
0433                             fileids.waves = '';
0434                             paths.waves = '';
0435                             %
0436                         end
0437                         for iw = 1:length(waves),
0438                             if (length(fileids.waves) < iw) || (~isempty(fileids.waves{iw}) && ~exist([paths.waves{iw},'WAVE_',equil.id,'_',fileids.waves{iw},'.mat'],'file')),
0439                                 fileids.waves{iw} = '';
0440                                 paths.waves{iw} = '';
0441                             end
0442                         end
0443                         %
0444                         if ~isfield(fileids,'ohm') || (~isempty(fileids.ohm) && ~exist([paths.ohm,'OHM_',equil.id,'_',fileids.ohm,'.mat'],'file')),
0445                             fileids.ohm = '';
0446                             paths.ohm = '';
0447                         end
0448                         %
0449                         if ~isfield(fileids,'transpfaste') || (~isempty(fileids.transpfaste) && ~exist([paths.transpfaste,'TRANSP_',equil.id,'_',fileids.transpfaste,'.mat'],'file')),
0450                             fileids.transpfaste = '';
0451                             paths.transpfaste = '';
0452                         end
0453                         %
0454                         if ~isfield(fileids,'ripple') || (~isempty(fileids.ripple) && ~exist([paths.ripple,'RIPPLE_',equil.id,'_',fileids.ripple,'.mat'],'file')),
0455                             fileids.ripple = '';
0456                             paths.ripple = '';
0457                         end
0458                         %
0459                         if ~isfield(status,'ripple'),
0460                             status.ripple = 0;
0461                         end
0462                         %
0463                         if ~isfield(fileids,'external') || (~isempty(fileids.external) && ~exist([paths.external,'EXTERNAL_',fileids.external,'.mat'],'file')),
0464                             fileids.external = '';
0465                             paths.external = '';
0466                         end
0467                         %
0468                         if ~isfield(status,'external'),
0469                             status.external = 0;
0470                         end
0471                         %
0472                         if status.output == 1 && ~exist('id_simul','var'),
0473                             id_simul = output.dke_out.simul.id;
0474                         end
0475                         %
0476                         status.data = 1;
0477                         %
0478                     elseif strfind(data_file,'LUKE_RESULTS_'),
0479                         %
0480                         data = load([data_path,data_file],'lukestructs');
0481                         disp(['-----> The data file ',[data_path,data_file],' is loaded.']);
0482                         %
0483                         if isfield(data,'lukestructs'),% new run_lukert output
0484                             %
0485                             data = data.lukestructs;
0486                             %
0487                             if iscell(data) && length(data) == 1,
0488                                 data = data{1};
0489                             end
0490                             %
0491                         else% old run_lukert output
0492                             %
0493                             data = load([data_path,data_file],'basestr','id_simul','simul','rho_S','id_dkeparam','path_dkeparam',...
0494                                 'id_equil','path_equil','ids_wave','paths_wave','id_ohm','path_ohm','id_transpfaste','path_transpfaste','id_ripple','path_ripple',...
0495                                 'luke_input','dkeparam','dkedisplay','equil','waves','ohm','transpfaste','ripple',...
0496                                 'Znorm','Zcurr','ZP0','dke_out','radialDKE','equilDKE','momentumDKE','gridDKE','Zmomcoef','Zbouncecoef','Zmripple','mksa','XXsinksource');
0497                             %
0498                         end
0499                         %
0500                         if isfield(data,'output'),
0501                             output = data.output;
0502                         else
0503                             %
0504                             output.Znorm = data.Znorm;
0505                             output.Zcurr = data.Zcurr;
0506                             output.ZP0 = data.ZP0;
0507                             output.dke_out = data.dke_out;
0508                             output.radialDKE = data.radialDKE;
0509                             output.equilDKE = data.equilDKE;
0510                             output.momentumDKE = data.momentumDKE;
0511                             output.gridDKE = data.gridDKE;
0512                             output.Zmomcoef = data.Zmomcoef;
0513                             output.Zbouncecoef = data.Zbouncecoef;
0514                             output.Zmripple = data.Zmripple;
0515                             output.mksa = data.mksa;
0516                             output.XXsinksource = data.XXsinksource;  
0517                             %
0518                         end
0519                         %
0520                         if isfield(data,'basestr'),
0521                             basestr = data.basestr;
0522                         else
0523                             basestr = data_file(14:12 + find(data_file(14:end) == '_',1,'first'));
0524                             basestr = input_dke_yp('Please enter the tokamak name',basestr);
0525                         end
0526                         %
0527                         fileids.data = data_file;
0528                         paths.data = data_path;
0529                         %
0530                         if isfield(data,'luke_input'),
0531                             dkeparam = data.luke_input.dkeparam;
0532                             dkedisplay = data.luke_input.dkedisplay;
0533                             equil = data.luke_input.equil;
0534                             waves = data.luke_input.waves;
0535                             ohm = data.luke_input.ohm;
0536                             transpfaste = data.luke_input.transpfaste;
0537                             ripple = data.luke_input.ripple;
0538                             %
0539                             if isfield(data.luke_input,'id_simul'),
0540                                 id_simul = data.luke_input.id_simul;
0541                             else
0542                                 id_simul = data.luke_input.simul_in;
0543                             end
0544                         else
0545                             dkeparam = data.dkeparam;
0546                             dkedisplay = data.dkedisplay;
0547                             equil = data.equil;
0548                             if isfield(data,'waves'),
0549                                 waves = data.waves;
0550                             else
0551                                 waves = '';
0552                             end
0553                             if isfield(data,'ohm'),
0554                                 ohm = data.ohm;
0555                             else
0556                                 ohm = '';
0557                             end
0558                             if isfield(data,'transpfaste'),
0559                                 transpfaste = data.transpfaste;
0560                             else
0561                                 transpfaste = '';
0562                             end
0563                             if isfield(data,'ripple'),
0564                                 ripple = data.ripple;
0565                             else
0566                                 ripple = '';
0567                             end
0568                             %
0569                             if isfield(data,'simul') && isfield(data.simul,'id'),
0570                                 id_simul = data.simul.id;
0571                             elseif isfield(output,'dke_out') && isfield(output.dke_out,'simul') && isfield(output.dke_out.simul,'id'),
0572                                 id_simul = output.dke_out.simul.id;
0573                             else
0574                                 id_simul = data.id_simul;
0575                             end
0576                         end
0577                         %
0578                         if isempty(waves),
0579                             if isfield(output,'dke_out') && isfield(output.dke_out,'waves'),
0580                                 waves = output.dke_out.waves;
0581                             else
0582                                 waves = '';
0583                             end
0584                         end
0585                         %
0586                         if isfield(data,'luke_input') && isfield(data.luke_input,'wavestructs') && ~isempty(data.luke_input.wavestructs)
0587                             %
0588                             external.id = ['wavestructs : ',num2str(length(data.luke_input.wavestructs)),' waves'];
0589                             external.wave.wavestructs = data.luke_input.wavestructs;
0590                             %
0591                             status.external = 1;
0592                             %
0593                         else
0594                             %
0595                             status.external = 0;
0596                             %
0597                         end
0598                         %
0599                         if isfield(data,'id_dkeparam') && ~isempty(data.id_dkeparam) && exist([data.path_dkeparam,'DKEPARAM_',data.id_dkeparam,'.mat'],'file'),
0600                             fileids.dkeparam = data.id_dkeparam;
0601                             paths.dkeparam = data.path_dkeparam;
0602                         else
0603                             fileids.dkeparam = '';
0604                             paths.dkeparam = '';
0605                         end
0606                         %
0607                         if ~isfield(data,'path_equil'),
0608                             data.path_equil = '';
0609                         end
0610                         %
0611                         if isfield(data,'id_equil') && ~isempty(data.id_equil) && exist([data.path_equil,'EQUIL_',data.id_equil,'.mat'],'file'),
0612                             fileids.equil = data.id_equil;
0613                             paths.equil = data.path_equil;
0614                         else
0615                             fileids.equil = '';
0616                             paths.equil = '';
0617                         end
0618                         %
0619                         for iw = 1:length(waves),
0620                             if isfield(data,'ids_wave') && length(data.ids_wave) >= iw && ~isempty(data.ids_wave{iw}) && ...
0621                                     ((iscell(data.paths_wave) && exist([data.paths_wave{iw},'WAVE_',data.ids_wave{iw},'.mat'],'file')) || (~iscell(data.paths_wave) && exist([data.paths_wave,'WAVE_',data.ids_wave{iw},'.mat'],'file'))),
0622                                 fileids.waves{iw} = data.ids_wave{iw};
0623                                 paths.waves{iw} = data.paths_wave{iw};
0624                             else
0625                                 fileids.waves{iw} = '';
0626                                 paths.waves{iw} = '';
0627                             end
0628                         end
0629                         %
0630                         if isfield(data,'id_ohm') && ~isempty(data.id_ohm) && exist([data.path_ohm,'OHM_',data.id_ohm,'.mat'],'file'),
0631                             fileids.ohm = data.id_ohm;
0632                             paths.ohm = data.path_ohm;
0633                         else
0634                             fileids.ohm = '';
0635                             paths.ohm = '';
0636                         end
0637                         %
0638                         if isfield(data,'id_transpfaste') && ~isempty(data.id_transpfaste) && exist([data.path_transpfaste,'TRANSP_',data.id_transpfaste,'.mat'],'file'),
0639                             fileids.transpfaste = data.id_transpfaste;
0640                             paths.transpfaste = data.path_transpfaste;
0641                         else
0642                             fileids.transpfaste = '';
0643                             paths.transpfaste = '';
0644                         end
0645                         %
0646                         if isfield(data,'id_ripple') && ~isempty(data.id_ripple) && exist([data.path_ripple,'RIPPLE_',data.id_ripple,'.mat'],'file'),
0647                             fileids.ripple = data.id_ripple;
0648                             paths.ripple = data.path_ripple;
0649                         else
0650                             fileids.ripple = '';
0651                             paths.ripple = '';
0652                         end
0653                         %
0654                         fileids.external = '';
0655                         paths.external = '';
0656                         %
0657                         status.dkeparam = 1;
0658                         status.equil = 1;
0659                         status.output = 1;
0660                         %
0661                         if ~isfield(dkeparam,'rho_S') && isfield(data,'rho_S'),
0662                             dkeparam.rho_S = data.rho_S;
0663                         end
0664                         %
0665                         if ~isempty(waves),
0666                             status.waves = 1;
0667                         end                    
0668                         %
0669                         if ~isempty(ohm),
0670                             status.ohm = 1;
0671                             if ~isfield(ohm,'id'),
0672                                 ohm.id = 'OHM';
0673                             end
0674                         end                    
0675                         %
0676                         if ~isempty(transpfaste),
0677                             status.transpfaste = 1;
0678                             if ~isfield(transpfaste,'id'),
0679                                 transpfaste.id = 'TRANSP';
0680                             end
0681                         end                    
0682                         %
0683                         if ~isempty(ripple),
0684                             status.ripple = 1;
0685                             if ~isfield(ripple,'id'),
0686                                 ripple.id = 'RIPPLE';
0687                             end
0688                         end                    
0689                         %
0690                         luke_job = '';
0691                         status.data = 2;
0692                         %
0693                         clear data
0694                         %
0695                     elseif strfind(data_file,'last_luke@'),
0696                         %
0697                         data = load([data_path,data_file],'par','tokamak','dkeparam','dkedisplay','equil','ohm','transpfaste','ripple',...
0698                             'Znorm_RF','Zcurr_RF','ZP0_RF','dke_out_RF','radialDKE','equilDKE','momentumDKE','gridDKE','Zmomcoef','Zbouncecoef','Zmripple','mksa','XXsinksource');
0699                         %
0700                         if isfield(data,'tokamak'),
0701                             basestr = data.tokamak;
0702                         end
0703                         %
0704                         fileids.data = data_file;
0705                         paths.data = data_path;
0706                         %
0707                         disp(['-----> The data file ',fileids.data,' is loaded.']);
0708                         %
0709                         output.Znorm = data.Znorm_RF;
0710                         output.Zcurr = data.Zcurr_RF;
0711                         output.ZP0 = data.ZP0_RF;
0712                         output.dke_out = data.dke_out_RF;
0713                         output.radialDKE = data.radialDKE;
0714                         output.equilDKE = data.equilDKE;
0715                         output.momentumDKE = data.momentumDKE;
0716                         output.gridDKE = data.gridDKE;
0717                         output.Zmomcoef = data.Zmomcoef;
0718                         output.Zbouncecoef = data.Zbouncecoef;
0719                         output.Zmripple = data.Zmripple;
0720                         output.mksa = data.mksa;
0721                         %
0722                         % TODO: to correct in zstarwars, then remove here
0723                         %
0724                         if isfield(data,'XXsinksource'),    
0725                             output.XXsinksource = data.XXsinksource;
0726                         else
0727                             output.XXsinksource = '';
0728                         end
0729                         %
0730                         status.dkeparam = 1;
0731                         status.equil = 1;
0732                         status.output = 1;
0733                         %
0734                         dkeparam = data.dkeparam;
0735                         dkedisplay = data.dkedisplay;
0736                         equil = data.equil;
0737                         ohm = data.ohm;
0738                         transpfaste = data.transpfaste;
0739                         ripple = data.ripple;
0740                         %
0741                         waves = output.dke_out.waves;
0742                         %
0743                         if ~isfield(dkeparam,'rho_S') && isfield(data,'par') && isfield(data.par,'rho_S'),
0744                             dkeparam.rho_S = data.par.rho_S;
0745                         end
0746                         %
0747                         fileids.dkeparam = '';
0748                         fileids.equil = '';
0749                         fileids.ohm = '';
0750                         fileids.transpfaste = '';
0751                         fileids.ripple = '';
0752                         fileids.external = '';
0753                         %
0754                         paths.dkeparam = '';
0755                         paths.equil = '';
0756                         paths.ohm = '';
0757                         paths.transpfaste = '';
0758                         paths.ripple = '';
0759                         paths.external = '';
0760                         %
0761                         for iw = 1:length(waves),
0762                             fileids.waves{iw} = '';
0763                             paths.waves{iw} = '';
0764                         end
0765                         %
0766                         id_simul = output.dke_out.simul.id;
0767                         %
0768                         if ~isempty(waves),
0769                             status.waves = 1;
0770                         end                    
0771                         %
0772                         if ~isempty(ohm),
0773                             status.ohm = 1;
0774                             if ~isfield(ohm,'id'),
0775                                 ohm.id = 'OHM';
0776                             end
0777                         end                    
0778                         %
0779                         if ~isempty(transpfaste),
0780                             status.transpfaste = 1;
0781                             if ~isfield(transpfaste,'id'),
0782                                 transpfaste.id = 'TRANSP';
0783                             end
0784                         end                    
0785                         %
0786                         if ~isempty(ripple),
0787                             status.ripple = 1;
0788                             if ~isfield(ripple,'id'),
0789                                 ripple.id = 'RIPPLE';
0790                             end
0791                         end                    
0792                         %
0793                         luke_job = '';
0794                         %
0795                         status.external = 0;
0796                         status.data = 2;
0797                         %
0798                         clear data
0799                         %
0800                     elseif strfind(data_file,'before_luke@'),
0801                         %
0802                         data = load([data_path,data_file],'par','dkeparam','dkedisplay','equil','ohm','transpfaste','ripple','wavestructs');
0803                         %
0804                         fileids.data = data_file;
0805                         paths.data = data_path;
0806                         %
0807                         disp(['-----> The data file ',fileids.data,' is loaded.']);
0808                         %
0809                         output = '';
0810                         %
0811                         status.dkeparam = 1;
0812                         status.equil = 1;
0813                         status.output = 0;
0814                         %
0815                         dkeparam = data.dkeparam;
0816                         dkedisplay = data.dkedisplay;
0817                         equil = data.equil;
0818                         ohm = data.ohm;
0819                         transpfaste = data.transpfaste;
0820                         ripple = data.ripple;
0821                         %
0822                         waves = '';
0823                         %
0824                         if ~isfield(dkeparam,'rho_S') && isfield(data,'par') && isfield(data.par,'rho_S'),
0825                             dkeparam.rho_S = data.par.rho_S;
0826                         end
0827                         %
0828                         fileids.dkeparam = '';
0829                         fileids.equil = '';
0830                         fileids.ohm = '';
0831                         fileids.waves = '';
0832                         fileids.transpfaste = '';
0833                         fileids.ripple = '';
0834                         fileids.external = '';
0835                         %
0836                         paths.dkeparam = '';
0837                         paths.equil = '';
0838                         paths.ohm = '';
0839                         paths.waves = '';                       
0840                         paths.transpfaste = '';
0841                         paths.ripple = '';
0842                         paths.external = '';
0843                         %
0844                         status.waves = 0;
0845                         %
0846                         if ~isempty(ohm),
0847                             status.ohm = 1;
0848                             if ~isfield(ohm,'id'),
0849                                 ohm.id = 'OHM';
0850                             end
0851                         end                    
0852                         %
0853                         if ~isempty(transpfaste),
0854                             status.transpfaste = 1;
0855                             if ~isfield(transpfaste,'id'),
0856                                 transpfaste.id = 'TRANSP';
0857                             end
0858                         end                    
0859                         %
0860                         if ~isempty(ripple),
0861                             status.ripple = 1;
0862                             if ~isfield(ripple,'id'),
0863                                 ripple.id = 'RIPPLE';
0864                             end
0865                         end                    
0866                         %
0867                         external.id = ['wavestructs : ',num2str(length(data.wavestructs)),' waves'];
0868                         external.wave.wavestructs = data.wavestructs;
0869                         %
0870                         status.external = 1;
0871                         status.data = 2;
0872                         %
0873                         luke_job = '';
0874                         %
0875                         clear data
0876                         %
0877                     else
0878                         disp('-----> Invalid LUKE data file.');
0879                         continue
0880                     end  
0881                     %
0882                     workdir = data_path;
0883                     %
0884                     if ~strcmp(workdir,[pwd,'/']) && input_dke_yp('Do you want to move to the source directory (y/n)','y',{'y','n'}) == 'y',
0885                         cd(workdir);
0886                     end
0887                     %
0888                 end
0889                 %
0890             elseif isel == 2,
0891                 %
0892                 % SAVE DATA FILE
0893                 %
0894                 disp(' ');
0895                 disp('************** SAVE DATA FILE **************')
0896                 disp(' ');
0897                 %
0898                 if ~isempty(output) && isstruct(output),
0899                     if isfield(output.dke_out,'waves') && iscell(output.dke_out.waves) && ~isempty(output.dke_out.waves),
0900                         if isfield(output.dke_out.waves{1}.rayparam,'colldamp') && output.dke_out.waves{1}.rayparam.colldamp == 1,
0901                             output.dke_out.waves = proc_wave_alphaphi_luke_jd(output,output.dke_out.waves,1);%update rays with LUKE absorption (RLA + NRCA absorption)
0902                         end
0903                     end
0904                 end
0905                 %
0906                 sd = pwd;
0907                 cd(workdir);
0908                 %
0909                 [data_file,data_path] = iputfile_jd(opt_gui,'LUKE_DATA_*.mat','Please provide a LUKE data file name',[workdir,'LUKE_DATA_',id_simul_o,'.mat']);
0910                 %
0911                 if data_file == 0,
0912                     disp('-----> No LUKE data file specified.');
0913                 else
0914                     newdatafile = [data_path,data_file];
0915                     if ~isempty(fileids.data) & ~strcmp([paths.data,fileids.data],newdatafile),
0916                         c_opt = input('The data file name has changed. Do you want to keep old data file (y/n)? [y] : ','s');
0917                         if strcmp(c_opt,'n'),
0918                             delete([paths.data,fileids.data])
0919                             disp(['-----> The file ',[paths.data,fileids.data],' has been deleted']);
0920                         end
0921                     end
0922                     %
0923                     fileids.data = data_file;
0924                     paths.data = data_path;
0925                     %
0926                     save(newdatafile);
0927                     disp(['-----> The data are saved in file ',newdatafile,'.']);
0928                     %
0929                     workdir = data_path;
0930                     status.data = 1;
0931                 end  
0932                 %
0933                 cd(sd);
0934                 %
0935             elseif isel == 3,
0936                 %
0937                 % WORKING DIRECTORY
0938                 %
0939                 disp(' ');
0940                 disp('************** WORK DIRECTORY **************')
0941                 disp(' ');
0942                 %
0943                 newworkdir = igetdir_jd(opt_gui,'Please select the work directory',workdir); 
0944                 %
0945                 if newworkdir == 0,
0946                     disp('-----> No work directory specified.');
0947                 else
0948                     %
0949                     if ~strcmp(newworkdir,workdir) 
0950                         disp(['-----> The working directory is : ',newworkdir]);
0951                         %
0952                         if status.data >= 1,
0953                             disp('-----> The working directory has changed, consider saving data.');
0954                             fileids.data = '';
0955                         end
0956                         %
0957                     end
0958                     %
0959                     workdir = newworkdir;
0960                     %
0961                 end
0962                 %
0963                 if ~strcmp(workdir,[pwd,'/']) && input_dke_yp('Do you want to move to the working directory (y/n)','y',{'y','n'}) == 'y',
0964                     cd(workdir);
0965                 end
0966                 %
0967             elseif isel == 4,
0968                 %
0969                 % LOAD DATA FROM EXTERNAL DATABASE
0970                 %
0971                 disp(' ');
0972                 disp('************** EXTERNAL DATA **************')
0973                 disp(' ');
0974                 %
0975                 % treatment of the external structure
0976                 %
0977                 smakecmd = 'iload_externaldata_jd';
0978                 %
0979                 [external,paths.external,fileids.external,newstruct] = ...
0980                     imake_struct_jd(dkepath,external,'external',paths.external,fileids.external,'',basestr,smakecmd,NaN,status.external,'EXTERNAL',workdir,'',opt_gui,0,0,1,0);
0981                 %
0982                 % structure interdependences
0983                 %
0984                 if newstruct == 1,
0985                     if ~isempty(external),
0986                         status.external = 1;
0987                     else
0988                         status.external = 0;
0989                     end
0990                     %
0991                     if isfield(external,'basestr'),
0992                         basestr = external.basestr;
0993                     end
0994                     %
0995                     status.equil = 0;
0996                     status.waves = 0;
0997                     status.ohm = 0;
0998                     status.transpfaste = 0;
0999                     status.output = 0;
1000                     status.data = 2;
1001                 end
1002                 %
1003                 clear newstruct smakecmd
1004                 %
1005             elseif isel == 6,
1006                 %
1007                 % LUKE PARAMETERS
1008                 %
1009                 disp(' ');
1010                 disp('************** LUKE PARAMETERS **************')
1011                 disp(' ');
1012                 %
1013                 % determine default DKEPARAM file
1014                 %
1015                 if status.equil == 1;
1016                     param_id = equil.id;
1017                 else
1018                     param_id = basestr;
1019                 end
1020                 dkeparam_file = ['DKEPARAM_',param_id,'.mat'];
1021                 if exist([workdir,dkeparam_file],'file'),
1022                     dkeparam_default = [workdir,dkeparam_file];
1023                 else
1024                     %
1025                     dkeparam_file = '';
1026                     locfiles = what(workdir);
1027                     for ifile = 1:length(locfiles.mat),
1028                         if strfind(locfiles.mat{ifile},'DKEPARAM_'),
1029                             dkeparam_file = locfiles.mat{ifile};
1030                             break
1031                         end
1032                     end
1033                     %
1034                     if ~isempty(dkeparam_file),
1035                         dkeparam_default = [workdir,dkeparam_file];
1036                     else
1037                         %
1038                         if strcmp(basestr,'TCV'),
1039                             dkeparam_file = 'DKEPARAM_EC_RT.mat';
1040                         else
1041                             dkeparam_file = 'DKEPARAM_LH_RT.mat';
1042                         end
1043                         dkeparam_default = which(dkeparam_file);    
1044                     end
1045                 end
1046                 %
1047                 % treatment of the dkeparam structure
1048                 %
1049                 smakecmd = '';
1050                 %
1051                 [dkeparam,paths.dkeparam,fileids.dkeparam,newstruct] = ...
1052                     imake_struct_jd(dkepath,dkeparam,'dkeparam',paths.dkeparam,fileids.dkeparam,equil,basestr,smakecmd,'',status.dkeparam,'DKEPARAM',workdir,dkeparam_default,opt_gui,0,1,1,0);
1053                 %
1054                 if ~isempty(dkeparam) && ~isfield(dkeparam,'rho_S'),
1055                     dkeparam.rho_S = 20;
1056                 end
1057                 %
1058                 % structure interdependences
1059                 %
1060                 if newstruct == 1,
1061                     if ~isempty(dkeparam),
1062                         status.dkeparam = 1;
1063                     else
1064                         status.dkeparam = 0;
1065                     end
1066                     status.output = 0;
1067                     status.data = 2;
1068                 end
1069                 %
1070                 clear newstruct smakecmd dkeparam_default param_id dkeparam_file locfiles ifile
1071                 %
1072             elseif isel == 7,
1073                 %
1074                 % EQUILIBRIUM
1075                 %
1076                 disp(' ');
1077                 disp('************** EQUILIBRIUM **************')
1078                 disp(' ');
1079                 %
1080                 % treatment of the equil structure
1081                 %
1082                 smakecmd = 'imake_equil_jd';
1083                 %
1084                 [equil,paths.equil,fileids.equil,newstruct] = ...
1085                     imake_struct_jd(dkepath,equil,'equil',paths.equil,fileids.equil,signs,basestr,smakecmd,external,status.equil,'EQUIL',workdir,'',opt_gui,0,0,1,0);
1086                 %
1087                 if input_dke_yp('Do you want to check the toroidal MHD equilibrium consistency (y/n)','y',{'y','n'}) == 'y',
1088                     equil = equilconsistency_yp(equil);
1089                 end
1090                 %
1091                 if isempty(equil)
1092                     signs = [];
1093                 elseif isfield(equil,'signs'),
1094                     signs = equil.signs;
1095                 end
1096                 %
1097                 if isfield(equil,'tokamak'),
1098                     basestr = equil.tokamak;
1099                 end
1100                 %
1101                 % structure interdependences
1102                 %
1103                 if newstruct == 1,
1104                     if ~isempty(equil),
1105                         status.equil = 1;
1106                     else
1107                         status.equil = 0;
1108                     end
1109                     status.waves = 0;
1110                     status.ohm = 0;
1111                     status.transpfaste = 0;
1112                     status.output = 0;
1113                     status.data = 2;
1114                 end
1115                 %
1116                 clear newstruct smakecmd
1117                 %
1118             elseif isel == 8,
1119                 %
1120                 % WAVES
1121                 %
1122                 disp(' ');
1123                 disp('************** WAVES **************')
1124                 disp(' ');
1125                 %
1126                 % treatment of the waves structure
1127                 %
1128                 smakecmd = 'imake_wave_jd';
1129                 %
1130                 flag_launch = 1;
1131                 %
1132                 for iw = 1:length(waves)     
1133                     if isfield(waves{iw},'launchs'),
1134                         for iw = 1:length(waves{iw}.launchs)   
1135                             if isfield(waves{iw}.launchs{il},'job'),%check running ALOHA job
1136                                 %
1137                                 for ij = 1:length(waves{iw}.launchs{il}.job)
1138                                     %
1139                                     if ~isempty(waves{iw}.launchs{il}.job{ij})
1140                                         %
1141                                         [err,job,sc] = matremote_jd(waves{iw}.launchs{il}.job{ij});%check if each job is done
1142                                         %
1143                                         if isempty(err) 
1144                                             if ~isempty(sc) 
1145                                                 %
1146                                                 disp([waves{iw}.launchs{il}.id,' : ALOHA job ',int2str(ij),'/',int2str(length(waves{iw}.launchs{il}.job)),' is done.']);
1147                                                 %
1148                                                 waves{iw}.launchs{il}.job{ij} = '';
1149                                                 waves{iw}.launchs{il}.temp{ij} = sc;
1150                                                 %
1151                                                 clear err job sc
1152                                             else
1153                                                 if isempty(job.remote.host)
1154                                                     disp([waves{iw}.launchs{il}.id,' : ALOHA job ',int2str(ij),'/',int2str(length(waves{iw}.launchs{il}.job)),'  is still running on the local host to find density in front of the grill consistent with RC'])
1155                                                 else
1156                                                     disp([waves{iw}.launchs{il}.id,' : ALOHA job ',int2str(ij),'/',int2str(length(waves{iw}.launchs{il}.job)),'  is still running on host : ',job.remote.host,' to find density in front of the grill consistent with RC'])
1157                                                 end
1158                                                 %
1159                                                 waves{iw}.launchs{il}.temp{ij} = '';
1160                                                 %
1161                                                 clear err job sc
1162                                             end
1163                                         else
1164                                             disp(['WARNING: ',waves{iw}.launchs{il}.id,' : ALOHA job ',int2str(ij),'/',int2str(length(waves{iw}.launchs{il}.job)),'failed. ALOHA calculation must be redone.']);
1165                                             waves{iw}.launchs{il}.job{ij} = '';
1166                                             waves{iw}.launchs{il}.temp{ij} = '';
1167                                         end
1168                                     end
1169                                 end
1170                                 %
1171                                 flag_job = length(waves{iw}.launchs{il}.job);
1172                                 for ij = 1:length(waves{iw}.launchs{il}.job)%test if all jobs are done
1173                                     if isempty(waves{iw}.launchs{il}.job{ij})
1174                                         flag_job = flag_job - 1;
1175                                     end
1176                                 end
1177                                 %
1178                                 if flag_job == 0, % all jobs done
1179                                     %
1180                                     antenna.aloha = waves{iw}.launchs{il}.temp{1};
1181                                     %
1182                                     if length(waves{iw}.launchs{il}.job) > 1
1183                                         for ij=1:length(waves{iw}.launchs{il}.job)
1184                                             RC{ij} = waves{iw}.launchs{il}.temp{ij}.results.RC;
1185                                             dP_nz{ij} = waves{iw}.launchs{il}.temp{ij}.results.dP_nz;
1186                                             ne0{ij} = waves{iw}.launchs{il}.temp{ij}.plasma.ne0;
1187                                         end
1188                                         %
1189                                         antenna.aloha.results.RC = RC;
1190                                         antenna.aloha.results.dP_nz = dP_nz;
1191                                         antenna.aloha.plasma.ne0 = ne0;
1192                                     end 
1193                                     %
1194                                     waves{iw}.launchs{il} = rmfield(waves{iw}.launchs{il},'job');
1195                                     waves{iw}.launchs{il}.antenna.aloha = antenna.aloha;
1196                                     waves{iw}.launchs{il}.antenna.id = waves{iw}.launchs{il}.id;
1197                                     %
1198                                     waves{iw}.launchs{il} = rmfield(build_spectrum_from_aloha(waves{iw}.launchs{il},waves{iw}.launchs{il}.basestr,waves{iw}.launchs{il}.signs,false),'tail');%build launch structure for C3PO/LUKE
1199                                     %
1200                                     waves{iw}.launchs{il}.id = waves{iw}.launchs{il}.antenna.id;
1201                                     %
1202                                     waves{iw} = imake_wave_jd(dkepath,basestr,equil,waves{iw}.launchs{il},workdir,false);
1203                                 else
1204                                     flag_launch = 0;
1205                                 end
1206                                 %
1207                             end
1208                         end
1209                     end
1210                 end
1211                 %
1212                 status.data = 2;%data must be saved
1213                 %
1214                 if flag_launch,
1215                     for iw = 1:length(waves)
1216                         if isfield(waves{iw},'job')
1217                             %
1218                             if isempty(waves{iw}.job.remote.host)
1219                                 disp(['Ray-tracing calculations have been send on the local host for wave # ',int2str(iw)]);
1220                             else
1221                                 disp(['Ray-tracing calculations have been send on the remote host: ',waves{iw}.job.remote.host,' for wave # ',int2str(iw)])
1222                             end
1223                             disp('The job status is checked ...')
1224                             %
1225                             [err,job,wave_tmp] = matremote_jd(waves{iw}.job);
1226                             %
1227                             if isempty(err) && isempty(wave_tmp),
1228                                 disp(['The job is still running. Check again !'])
1229                             elseif isempty(err) && ~isempty(wave_tmp),
1230                                 disp(['The job is done !'])
1231                                 n_rf_list = waves{iw}.n_rf_list;
1232                                 %
1233                                 % Wave processing and relativistic linear damping
1234                                 %
1235                                 waves{iw} = wave_process_jd(equil,wave_tmp,n_rf_list);
1236                                 %
1237                             elseif ~isempty(err)
1238                                 disperr_jd(err);
1239                                 disp(['The ''waves'' #',int2str(iw),' must be cleared.'])
1240                                 irmwave = iw;
1241                             end            
1242                         end 
1243                     end
1244                     %
1245                     if isempty(waves),
1246                         status.waves = 0;
1247                     end
1248                     %
1249                     for iw = 1:length(waves),
1250                         if ~isfield(waves{iw},'job'),%batch ray tracing calculations
1251                             if ~isfield(waves{iw},'colldamp'),%backward compatibility
1252                                 if ~isfield(waves{iw}.rayparam,'colldamp'),%backward compatibility
1253                                     waves{iw}.colldamp = 0;
1254                                 else
1255                                     waves{iw}.colldamp = waves{iw}.rayparam.colldamp;
1256                                 end
1257                             end
1258                         end
1259                     end
1260                 end
1261                 %
1262                 waves0 = waves;
1263                 %
1264                 [waves,paths.waves,fileids.waves,newstruct] = imake_struct_jd(dkepath,waves,'wave',paths.waves,fileids.waves,equil,basestr,smakecmd,external,status.waves,'WAVE',workdir,'',opt_gui,1,1,0);
1265                 %
1266                 
1267                 %
1268                 flag_wave = 1;
1269                 flag_launch = 1;
1270                 %
1271                 if ~isempty(waves),
1272                     for iw = 1:length(waves),
1273                         if isfield(waves{iw},'job'),%batch ray tracing calculations
1274                             flag_wave = 0;
1275                             break;
1276                         else
1277                             if isfield(waves{iw},'launchs'),%batch ray tracing calculations
1278                                 for il = 1:length(waves{iw}.launchs),
1279                                     if isfield(waves{iw}.launchs{il},'job'),%batch ALOHA calculations
1280                                         flag_wave = 0;
1281                                         flag_launch = 0;
1282                                         break;
1283                                     end
1284                                 end
1285                             end
1286                         end
1287                         %
1288                     end
1289                     %
1290                     if flag_wave == 1,
1291                         for iw = 1:length(waves),
1292                             if ~isfield(waves{iw},'colldamp'),%backward compatibility
1293                                 waves{iw}.colldamp = waves{iw}.rayparam.colldamp;
1294                             end
1295                         end
1296                         %
1297                         flag_colldamp = 0;
1298                         %
1299                         if ~isempty(waves0),
1300                             for iw = 1:length(waves),
1301                                 if waves{iw}.colldamp ~= waves0{iw}.colldamp,
1302                                     flag_colldamp = 1 + i*waves{iw}.colldamp;
1303                                 end
1304                             end
1305                         end
1306                         %
1307                         if real(flag_colldamp) == 1,
1308                             if imag(flag_colldamp) == 0,
1309                                 disp(['WARNING: The non-resonant collisional absorption is disabled for all waves.'])
1310                             else 
1311                                 disp(['WARNING: The non-resonant collisional absorption is enabled for all waves.'])
1312                             end
1313                             %
1314                             figure,plot(waves{1}.rays{1}.ss,waves{1}.rays{1}.sP_2piRp_lin_coll,'r-');drawnow
1315                             %
1316                             for iw = 1:length(waves),
1317                                 waves{iw}.rayparam.colldamp = imag(flag_colldamp);
1318                                 %
1319                                 for ir = 1:length(waves{iw}.rays)
1320                                     if isfield(waves{iw}.rays{ir},'stau_coll')
1321                                         waves{iw}.rays{ir} = rmfield(waves{iw}.rays{ir},'stau_coll');
1322                                     end    
1323                                     if isfield(waves{iw}.rays{ir},'sP_2piRp_coll')
1324                                         waves{iw}.rays{ir} = rmfield(waves{iw}.rays{ir},'sP_2piRp_coll');
1325                                     end    
1326                                     if isfield(waves{iw}.rays{ir},'sdP_2piRp_ds_coll')
1327                                         waves{iw}.rays{ir} = rmfield(waves{iw}.rays{ir},'sdP_2piRp_ds_coll');
1328                                     end    
1329                                     if isfield(waves{iw}.rays{ir},'sP_2piRp_lin_coll')
1330                                         waves{iw}.rays{ir} = rmfield(waves{iw}.rays{ir},'sP_2piRp_lin_coll');
1331                                     end    
1332                                     if isfield(waves{iw}.rays{ir},'sdP_2piRp_ds_lin_coll')
1333                                         waves{iw}.rays{ir} = rmfield(waves{iw}.rays{ir},'sdP_2piRp_ds_lin_coll');
1334                                     end    
1335                                     if isfield(waves{iw}.rays{ir},'salphaphi_coll')
1336                                         waves{iw}.rays{ir} = rmfield(waves{iw}.rays{ir},'salphaphi_coll');
1337                                     end    
1338                                 end
1339                                 %
1340                                 waves{iw} = wave_process_jd(equil,waves{iw},waves{iw}.n_rf_list);
1341                             end
1342                             %
1343                             hold on,plot(waves{1}.rays{1}.ss,waves{1}.rays{1}.sP_2piRp_lin_coll,'b--');drawnow;hold off
1344                             %
1345                             for iw = 1:length(waves),
1346                                 if imag(flag_colldamp) == 0,
1347                                     waves{iw}.id =  [waves{iw}.id,'_nocoll'];
1348                                 elseif imag(flag_colldamp) == 1,
1349                                     if strfind(waves{iw}.id,'_nocoll');
1350                                         waves{iw}.id = waves{iw}.id(1:strfind(waves{iw}.id,'_nocoll')-1);
1351                                     end
1352                                 end
1353                             end
1354                         end
1355                     end
1356                 end
1357                 %
1358                 clear waves0
1359                 %
1360                 % structure interdependences
1361                 %
1362                 if newstruct == 1,
1363                     if ~isempty(waves),
1364                         status.waves = 1;
1365                     else
1366                         status.waves = 0;
1367                     end
1368                     status.output = 0;
1369                     status.data = 2;
1370                 end
1371                 %
1372                 clear newstruct smakecmd
1373                 %
1374             elseif isel == 9,
1375                 %
1376                 % OHM
1377                 %
1378                 disp(' ');
1379                 disp('************** OHM **************')
1380                 disp(' ');
1381                 %
1382                 % treatment of the ohm structure
1383                 %
1384                 smakecmd = 'imake_ohm_jd';
1385                 %
1386                 [ohm,paths.ohm,fileids.ohm,newstruct] = ...
1387                     imake_struct_jd(dkepath,ohm,'ohm',paths.ohm,fileids.ohm,equil,basestr,smakecmd,external,status.ohm,'OHM',workdir,'',opt_gui,0,1,1);
1388                 %
1389                 % structure interdependences
1390                 %
1391                 if newstruct == 1,
1392                     if ~isempty(ohm),
1393                         status.ohm = 1;
1394                     else
1395                         status.ohm = 0;
1396                     end
1397                     status.output = 0;
1398                     status.data = 2;
1399                 end
1400                 %
1401                 clear newstruct smakecmd
1402                 %
1403             elseif isel == 10,
1404                 %
1405                 % TRANSPORT
1406                 %
1407                 disp(' ');
1408                 disp('************** FAST ELECTRON TRANSPORT **************')
1409                 disp(' ');
1410                 %
1411                 % treatment of the transpfaste structure
1412                 %
1413                 smakecmd = 'imake_transp_jd';
1414                 %
1415                 [transpfaste,paths.transpfaste,fileids.transpfaste,newstruct] = ...
1416                     imake_struct_jd(dkepath,transpfaste,'transpfaste',paths.transpfaste,fileids.transpfaste,equil,basestr,smakecmd,external,status.transpfaste,'TRANSP',workdir,'',opt_gui,0,1,1);
1417                 %
1418                 % structure interdependences
1419                 %
1420                 if newstruct == 1,
1421                     if ~isempty(transpfaste),
1422                         status.transpfaste = 1;
1423                     else
1424                         status.transpfaste = 0;
1425                     end
1426                     status.output = 0;
1427                     status.data = 2;
1428                 end
1429                 %
1430                 clear newstruct smakecmd
1431                 %
1432             elseif isel == 11,
1433                 %
1434                 % MAGNETIC RIPPLE LOSSES
1435                 %
1436                 disp(' ');
1437                 disp('************** MAGNETIC RIPPLE LOSSES **************')
1438                 disp(' ');
1439                 %
1440                 if ~(strcmp(basestr,'TS') || strcmp(basestr,'WEST'))  ;
1441                     disp('-----> The magnetic ripple calculations is implemented for Tore Supra or WEST tokamak only.');
1442                     continue
1443                 end
1444                 %
1445                 % treatment of the ripple structure
1446                 %
1447                 smakecmd = 'imake_ripple_yp';
1448                 %
1449                 [ripple,paths.ripple,fileids.ripple,newstruct] = ...
1450                     imake_struct_jd(dkepath,ripple,'ripple',paths.ripple,fileids.ripple,equil,basestr,smakecmd,external,status.ripple,'RIPPLE',workdir,'',opt_gui,0,1,1);
1451                 %
1452                 % structure interdependences
1453                 %
1454                 if newstruct == 1,
1455                     if ~isempty(ripple),
1456                         status.ripple = 1;
1457                     else
1458                         status.ripple = 0;
1459                     end
1460                     status.output = 0;
1461                     status.data = 2;
1462                 end
1463                 %
1464                 clear newstruct smakecmd
1465                 %
1466             elseif isel == 12,
1467                 %
1468                 % DISPLAY LUKE EQUILIBRIUM
1469                 %
1470                 if status.equil == 1,
1471                     equilibrium_jd(equil,NaN,2,NaN,NaN,NaN);
1472                 else
1473                     disp('-----> The equilibrium structure does not exist.');
1474                 end
1475                 %
1476             elseif isel == 13,
1477                 %
1478                 % DISPLAY WAVE DATA
1479                 %
1480                 if status.waves == 1,
1481                     %
1482                     nw = length(waves);
1483                     %
1484                     if strcmp(basestr,'TCV')
1485                         g_opt.vessel_opt = input_dke_yp('Do you want to display TCV vessel and tiles','y',{'y','n'});
1486                     else
1487                         g_opt.vessel_opt = 'n';
1488                     end
1489                     %
1490                     w_list = input_dke_yp('List of waves to display',1:nw,[1;nw],'');
1491                     %
1492                     if status.output == 1,
1493                         g_opt.luke = input_dke_yp('Do you want to show waves using LUKE absorption (n/y)','y',{'n','y'}) == 'y';
1494                         %
1495                         if g_opt.luke,
1496                             for iw = w_list,
1497                                 if ~isfield(waves{iw},'simul') || ~comp_struct_jd(waves{iw}.simul,output.dke_out.simul,0),
1498                                     if isfield(waves{iw},'simul'),
1499                                         disp(['WARNING : LUKE data in wave # ',num2str(iw),' outdated, recalculating...'])
1500                                     else
1501                                         disp(['WARNING : LUKE data in wave # ',num2str(iw),' missing, calculating now...'])
1502                                     end
1503                                     %
1504                                     %waves(iw) = proc_wave_alphaphi_luke_jd(output,waves(iw),1);%tmp version to deal with old waves
1505                                     %waves(iw) = alphaphi_luke_jd(waves(iw),output.dke_out,output.ZP0,output.equilDKE,output.mksa);
1506                                     %
1507                                 end
1508                             end
1509                             %
1510                             waves = proc_wave_alphaphi_luke_jd(output,waves,1);
1511                             %
1512                         end
1513                         %
1514                     else
1515                         g_opt.luke = false;
1516                     end          
1517                     %
1518                     waves(w_list) = proc_wave_alphaphi_luke_jd('',waves(w_list),0);%tmp command to correct old waves
1519                     %
1520                     nr_dep = 40;
1521                     rho_disp = 0:0.1:1;
1522                     %
1523                     if length(w_list) == 1 && input_dke_yp('Do you want to split the wave into subwaves (n/y)','y',{'n','y'}) == 'y',
1524                         %
1525                         wave = waves{w_list};
1526                         nrays = length(wave.rays);
1527                         %
1528                         if strcmp(wave.rayinit.launch.type,'LH') && input_dke_yp('Do you want to define the subwaves by initial lobe?','y',{'n','y'}) == 'y',
1529                             raygroups = repmat({[]},[1,length(wave.rayinit.launch.bNpar0)]);
1530                             for iray = 1:nrays,
1531                                 raygroups{find(wave.rays{iray}.rayinits{1}.yNpar0 == wave.rayinit.launch.bNpar0,1,'first')}(end+1) = iray;
1532                             end
1533                         else%if strcmp(wave.rayinit.launch.type,'LH') && input_dke_yp('Do you want to define the subwaves by initial vertical position?','y',{'n','y'}) == 'y',
1534                             % TODO
1535                         %else
1536                             keyboard;%raygroups = {1:24,25:48,49:72,73:96};%input_dke_yp(['Please regroup the ',num2str(nrays),' rays in cells of arrays'],{1:nrays});
1537                         end      
1538                         %
1539                         dispwaves = {};
1540                         for iw = 1:length(raygroups),
1541                             if ~isempty(raygroups{iw}),
1542                                 dispwaves{end+1} = wave;
1543                                 dispwaves{end}.id = [dispwaves{end}.id,'_',num2str(iw)];
1544                                 dispwaves{end}.rays = dispwaves{end}.rays(raygroups{iw});
1545                             end
1546                         end
1547                         %
1548                         w_list = input_dke_yp('List of subwaves to display',1:length(dispwaves),[1;length(dispwaves)],'');
1549                         dispwaves = dispwaves(w_list);
1550                         %
1551                     else
1552                         dispwaves = waves(w_list);
1553                     end
1554                     %
1555                     ymask = NaN;
1556                     %
1557                     graph_wave_jd(equil,dispwaves,nr_dep,g_opt,rho_disp,ymask);
1558                     %
1559                     clear rayinits nw wave dispwaves
1560                     %
1561                 else
1562                     disp('-----> The equilibrium structure does not exist.');
1563                 end
1564                 %
1565             elseif isel == 14,
1566                 %
1567                 % DISPLAY LUKE RESULTS
1568                 %
1569                 if status.output == 1,
1570                     %
1571                     ir_display = input(['Index of flux-surface for distribution (1-',num2str(length(output.equilDKE.xrho)),', 0 to skip) ? [0] : ']);
1572                     if isempty(ir_display) || ~isnumeric(ir_display) || ir_display > length(output.equilDKE.xrho),
1573                         ir_display = 0;
1574                     end
1575                     %
1576                     pnmax = input(['Maximum value of p/pT for display: (-1) auto, (0) grid, or specify (0-',num2str(dkeparam.pnmax_S),')? [0] : ']);
1577                     if isempty(pnmax),
1578                         pnmax = 0;
1579                     end
1580                     %
1581                     if ~isnumeric(pnmax) || (~any(pnmax == [0,-1]) && (pnmax < 0 || pnmax > dkeparam.pnmax_S)),
1582                         disp('-----> Invalid choice.');
1583                         continue
1584                     end
1585                     %
1586                     if pnmax == -1,
1587                         pnmax = NaN;
1588                     elseif pnmax == 0,
1589                         pnmax = dkeparam.pnmax_S;
1590                     end
1591                     %
1592                     p_opt = input('Option for output figures? -1 (nothing), 0 (print), 1 (print and save), 2 (save) [-1] : ');
1593                     if isempty(p_opt) || ~isnumeric(p_opt) || ~any(p_opt == [0,1,2]),
1594                         p_opt = -1;
1595                     end
1596                     %
1597                     dp_cyl = 0.1;
1598                     %
1599                     sd = pwd;
1600                     cd(workdir)
1601                     data_proc = proc_luke_jd(output,ir_display,p_opt,dp_cyl,pnmax);
1602                     %
1603                     opt.procsave = input_dke_yp('Do you want to save the processed data','y',{'y','n'},'',[1,1]);
1604                     %
1605                     if opt.procsave == 'y',
1606                         %
1607                         [proc_file,proc_path] = iputfile_jd(opt_gui,'PROC_LUKE_DATA_*.mat','Please provide a LUKE PROC data file name',[workdir,'PROC_LUKE_DATA_',id_simul_o,'.mat']);
1608                         %
1609                         if proc_file == 0,
1610                             disp('-----> No PROC_LUKE data file specified.');
1611                         else
1612                             %
1613                             save([proc_path,proc_file],'data_proc');
1614                             disp(['-----> The proc data are saved in file ',proc_path,proc_file,'.']);
1615                             %
1616                         end                      
1617                     end
1618                     %
1619                     cd(sd);
1620                 else
1621                     disp('-----> The output structure does not exist.');
1622                 end
1623                 %
1624             elseif isel == 15,
1625                 %
1626                 % CALCULATE HXR EMISSION
1627                 %
1628                 if status.output == 0;
1629                     disp('-----> First run LUKE!');
1630                     continue
1631                 end
1632                 %
1633                 irunhxr_jd(opt_gui,workdir,basestr,output,external,id_simul,equil,dkeparam,dkedisplay);
1634                 %
1635             elseif isel == 16,
1636                 %
1637                 % GENERATE LUKE RUN SCRIPT
1638                 %
1639                 imake_rundke_jd(paths,fileids,status,workdir,id_simul_o,opt_gui);
1640                 %
1641             elseif isel == 17,
1642                 %
1643                 disp('-----> Type ''return'' to return to menu');    
1644                 disp('-----> Type ''dbquit'' to abort run and leave workspace.');
1645                 disp(' ');
1646                 keyboard
1647                 %
1648             elseif isel == 18,
1649                 %
1650                 close all;    
1651                 %
1652             elseif isel == 19,
1653                 %
1654                 doc_LUKE(dkepath);
1655                 %
1656             elseif isel == 20,
1657                 %
1658                 redmine_opt = input_dke_yp('Do you want to access REDMINE for LUKE in the Matlab browser (y/n)? [y] : ','y',{'y','n'},'',[1,1]);
1659                 %
1660                 if strcmp(redmine_opt,'y'),
1661                     %
1662                     redmine_LUKE;
1663                     %
1664                 else
1665                     %
1666                     redmine_LUKE('-browser');
1667                     %
1668                 end
1669                 %
1670              elseif isel == 21,
1671                 %
1672                 [joblist,C3PO_status,LUKE_status,orphan_batch_dir,dirsearch] = jobstatus_yp(pwd);
1673                 %
1674                 if exist('joblist'),
1675                     if opt_status_windows == 1 & exist('tprintf.m','file'),
1676                         tprintf('LUKE simulations status',' ');
1677                         tprintf('LUKE simulations status',['-------------------------------------------------------------------------------------']);
1678                         tprintf('LUKE simulations status',['-------------------------------------------------------------------------------------']);
1679                         tprintf('LUKE simulations status',['-------------------------------------------------------------------------------------']);
1680                         tprintf('LUKE simulations status',['Simulations status in folder : ',dirsearch]);
1681                         tprintf('LUKE simulations status',['-------------------------------------------------------------------------------------']);
1682                         tprintf('LUKE simulations status',['-------------------------------------------------------------------------------------']);
1683                         tprintf('LUKE simulations status',['-------------------------------------------------------------------------------------']);
1684                         tprintf('LUKE simulations status',['Total number of simulations : ',int2str(length(joblist))]);
1685                         for iw = 1:length(C3PO_status)
1686                             tprintf('LUKE simulations status',['Total number of simulations for wave #',int2str(iw),' not done (C3PO): ',int2str(C3PO_status(iw).notdone)]);
1687                             tprintf('LUKE simulations status',['Total number of simulations for wave #',int2str(iw),' completed (C3PO): ',int2str(C3PO_status(iw).completed)]);
1688                             tprintf('LUKE simulations status',['Total number of simulations for wave #',int2str(iw),' running (C3PO) : ',int2str(C3PO_status(iw).running)]);
1689                         end
1690                         tprintf('LUKE simulations status',['Total number of simulations not done (LUKE): ',int2str(LUKE_status.notdone)]);
1691                         tprintf('LUKE simulations status',['Total number of simulations completed (LUKE): ',int2str(LUKE_status.completed)]);
1692                         tprintf('LUKE simulations status',['Total number of simulations running (LUKE) : ',int2str(LUKE_status.running)]);
1693                         tprintf('LUKE simulations status',['-------------------------------------------------------------------------------------']);
1694                         tprintf('LUKE simulations status',['-------------------------------------------------------------------------------------']);
1695                         tprintf('LUKE simulations status',['-------------------------------------------------------------------------------------']);
1696                         %
1697                         for ii = 1:length(joblist),
1698                             tprintf('LUKE simulations status',[' - id_simul : ',joblist(ii).id_simul]);
1699                             %
1700                             for iw = 1:length(joblist(ii).C3PO)
1701                                 if strcmp(joblist(ii).C3PO(iw).status,'C3PO ray tracing calculations not done'),
1702                                     tprintf('LUKE simulations status',[' - C3PO (wave #',int2str(iw),') status: **** ',joblist(ii).C3PO(iw).status,' ****']);
1703                                 else
1704                                     tprintf('LUKE simulations status',[' - C3PO (wave #',int2str(iw),') status: ',joblist(ii).C3PO(iw).status]);
1705                                 end
1706                                 if strcmp(joblist(ii).C3PO(iw).status,'C3PO ray tracing calculations running'),
1707                                     tprintf('LUKE simulations status',[' - C3PO (wave #',int2str(iw),') remote host address : ',joblist(ii).C3PO(iw).host]);
1708                                     tprintf('LUKE simulations status',[' - C3PO (wave #',int2str(iw),') remote jobid : ',joblist(ii).C3PO(iw).jobid]);
1709                                     tprintf('LUKE simulations status',[' - C3PO (wave #',int2str(iw),') batch directory : ',joblist(ii).C3PO(iw).batch_dir]);
1710                                 end
1711                             end
1712                             %
1713                             if strcmp(joblist(ii).LUKE.status,'LUKE Fokker-Planck calculations not done'),
1714                                 tprintf('LUKE simulations status',[' - LUKE status: **** ',joblist(ii).LUKE.status, ' ****']);
1715                             else
1716                                 tprintf('LUKE simulations status',[' - LUKE status: ',joblist(ii).LUKE.status]);
1717                             end
1718                             if strcmp(joblist(ii).LUKE.status,'LUKE Fokker-Planck calculations running'),
1719                                 tprintf('LUKE simulations status',[' - LUKE remote host address : ',joblist(ii).LUKE.host]);
1720                                 tprintf('LUKE simulations status',[' - LUKE remote jobid : ',joblist(ii).LUKE.jobid]);
1721                                 tprintf('LUKE simulations status',[' - LUKE batch directory : ',joblist(ii).LUKE.batch_dir]);
1722                             end
1723                             %
1724                             tprintf('LUKE simulations status',['-------------------------------------------------------------------------------------']);
1725                             tprintf('LUKE simulations status',['-------------------------------------------------------------------------------------']);
1726                         end
1727                         %
1728                         tprintf('LUKE simulations status',['List of orphan batch directories ']);
1729                         tprintf('LUKE simulations status',['-------------------------------------------------------------------------------------']);
1730                         tprintf('LUKE simulations status',['-------------------------------------------------------------------------------------']);
1731                         %
1732                         for io = 1:length(orphan_batch_dir)
1733                             if orphan_batch_dir(io).status == 1,
1734                                 tprintf('LUKE simulations status',[' - batch directory : ',orphan_batch_dir(io).name,' is orphan. You can delete it.']);
1735                             end
1736                         end
1737                         %
1738                         tprintf('LUKE simulations status',['-------------------------------------------------------------------------------------']);
1739                         tprintf('LUKE simulations status',['-------------------------------------------------------------------------------------']);
1740                         %
1741                     else
1742                         disp(' ');
1743                         disp(['-------------------------------------------------------------------------------------']);
1744                         disp(['-------------------------------------------------------------------------------------']);
1745                         disp(['-------------------------------------------------------------------------------------']);
1746                         disp(['Simulations status in folder : ',dirsearch]);
1747                         disp(['-------------------------------------------------------------------------------------']);
1748                         disp(['-------------------------------------------------------------------------------------']);
1749                         disp(['-------------------------------------------------------------------------------------']);
1750                         disp(['Total number of simulations : ',int2str(length(joblist))]);
1751                         for iw = 1:length(C3PO_status)
1752                             disp(['Total number of simulations for wave #',int2str(iw),' not done (C3PO): ',int2str(C3PO_status(iw).notdone)]);
1753                             disp(['Total number of simulations for wave #',int2str(iw),' completed (C3PO): ',int2str(C3PO_status(iw).completed)]);
1754                             disp(['Total number of simulations for wave #',int2str(iw),' running (C3PO) : ',int2str(C3PO_status(iw).running)]);
1755                         end
1756                         disp(['Total number of simulations not done (LUKE): ',int2str(LUKE_status.notdone)]);
1757                         disp(['Total number of simulations completed (LUKE): ',int2str(LUKE_status.completed)]);
1758                         disp(['Total number of simulations running (LUKE) : ',int2str(LUKE_status.running)]);
1759                         disp(['-------------------------------------------------------------------------------------']);
1760                         disp(['-------------------------------------------------------------------------------------']);
1761                         disp(['-------------------------------------------------------------------------------------']);
1762                         %
1763                         for ii = 1:length(joblist),
1764                             disp([' - id_simul : ',joblist(ii).id_simul]);
1765                             %
1766                             for iw = 1:length(joblist(ii).C3PO)
1767                                 if strcmp(joblist(ii).C3PO(iw).status,'C3PO ray tracing calculations not done'),
1768                                     disp([' - C3PO (wave #',int2str(iw),') status: **** ',joblist(ii).C3PO(iw).status,' ****']);
1769                                 else
1770                                     disp([' - C3PO (wave #',int2str(iw),') status: ',joblist(ii).C3PO(iw).status]);
1771                                 end
1772                                 if strcmp(joblist(ii).C3PO(iw).status,'C3PO ray tracing calculations running'),
1773                                     disp([' - C3PO (wave #',int2str(iw),') remote host address : ',joblist(ii).C3PO(iw).host]);
1774                                     disp([' - C3PO (wave #',int2str(iw),') remote jobid : ',joblist(ii).C3PO(iw).jobid]);
1775                                     disp([' - C3PO (wave #',int2str(iw),') batch directory : ',joblist(ii).C3PO(iw).batch_dir]);
1776                                 end
1777                             end
1778                             %
1779                             if strcmp(joblist(ii).LUKE.status,'LUKE Fokker-Planck calculations not done'),
1780                                 disp([' - LUKE status: **** ',joblist(ii).LUKE.status, ' ****']);
1781                             else
1782                                 disp([' - LUKE status: ',joblist(ii).LUKE.status]);
1783                             end
1784                             if strcmp(joblist(ii).LUKE.status,'LUKE Fokker-Planck calculations running'),
1785                                 disp([' - LUKE remote host address : ',joblist(ii).LUKE.host]);
1786                                 disp([' - LUKE remote jobid : ',joblist(ii).LUKE.jobid]);
1787                                 disp([' - LUKE batch directory : ',joblist(ii).LUKE.batch_dir]);
1788                             end
1789                             %
1790                             disp(['-------------------------------------------------------------------------------------']);
1791                             disp(['-------------------------------------------------------------------------------------']);
1792                         end
1793                         %
1794                         disp(['List of orphan batch directories ']);
1795                         disp(['-------------------------------------------------------------------------------------']);
1796                         disp(['-------------------------------------------------------------------------------------']);
1797                         %
1798                         for io = 1:length(orphan_batch_dir)
1799                             if orphan_batch_dir(io).status == 1,
1800                                 disp([' - batch directory : ',orphan_batch_dir(io).name,' is orphan. You can delete it.']);
1801                             end
1802                         end
1803                         %
1804                         disp(['-------------------------------------------------------------------------------------']);
1805                         disp(['-------------------------------------------------------------------------------------']);
1806                     end
1807                 end
1808             elseif isel == 0,
1809                 %
1810                 flag_runluke = 1;
1811                 %
1812                 if isfield(luke_job,'remote') && input_dke_yp(['-----> There is a pending remote LUKE batch run.\n',...
1813                     'Do you want to check the run (y/n)'],'y',{'y','n'}) == 'y',
1814                     %
1815                     % THERE IS A BATCH RUN OF LUKE
1816                     %
1817                     if ~exist(luke_job.localdatapath,'dir'),
1818                         disp(['WARNING : The directory ',luke_job.localdatapath,' does not exist. Working directory used.']);
1819                         %
1820                         luke_job.localdatapath = workdir;
1821                     end
1822                     %
1823                     flag_runluke = 0;
1824                     %
1825                     lukestructs.job = luke_job;
1826                     %
1827                     luke_job = '';
1828                 end
1829                 %
1830                 if flag_runluke == 1,
1831                     %
1832                     % RUN LUKE
1833                     %
1834                     if isempty(dkeparam) || isempty(equil),
1835                         disp('-----> the structures dkeparam and equil must exist to run LUKE.');
1836                         continue
1837                     end  
1838                     %
1839                     flag_wave = 0;
1840                     if exist('waves')
1841                         for iw = 1:length(waves),
1842                             if isfield(waves{iw},'job')
1843                                 flag_wave = flag_wave + 1;
1844                             end
1845                         end
1846                     end
1847                     %
1848                     if flag_wave > 0,
1849                         disp('-----> All batch ray-tracing must be completed to run LUKE.');
1850                         continue
1851                     end  
1852                     %
1853                     % DISPLAY
1854                     %
1855                     dkedisplay_file = 'DISPLAY_PARTIAL_VISUAL.mat';
1856                     dkedisplay_file = which(dkedisplay_file);
1857                     if isempty(dkedisplay_file),
1858                         disp(quitmsg)
1859                         return
1860                     end
1861                     load(dkedisplay_file,'dkedisplay');
1862                     %
1863                     display_mode = input('Option for run evolution display: 0 (none), 1 (partial), 2 (full) [0] : ');
1864                     if isempty(display_mode) || ~isnumeric(display_mode) || ~any(display_mode == [0,1,2]),
1865                         display_mode = 0;
1866                     end
1867                     dkedisplay.display_mode = display_mode; 
1868                     %
1869                     dkeparam.psin_S = [];%Normalized poloidal flux grid where calculations are performed (0 < psin_S < 1) (If one value: local calculation only, not used if empty)
1870                     %
1871                     % MUMPSMEX
1872                     %
1873                     if exist('dmumpsmex','file') == 3;
1874                         dkeparam.invproc = -2;
1875                     end
1876                     %
1877                     id_simul = input(['Please provide a name for the run [',id_simul_o,'] : '],'s');
1878                     if isempty(id_simul),
1879                         id_simul = id_simul_o;
1880                     end
1881                     %
1882                     % REMOTE PARAMETERS
1883                     %
1884                     returnmode = input_dke_yp('Do you want to wait for results (y/n)','n',{'y','n'}) == 'n';
1885                     dkepath = lukeschedulerparam(dkepath,0,[],returnmode,transpfaste,opt_gui);
1886                     %
1887                     disp(' ');
1888                     disp('************** RUN LUKE **************')
1889                     disp(' ');
1890                     %
1891                     lukestructs.simul_in = id_simul;
1892                     lukestructs.dkeparam = dkeparam;
1893                     lukestructs.dkedisplay = dkedisplay;
1894                     lukestructs.equil = equil;
1895                     lukestructs.waves = waves;
1896                     lukestructs.ohm = ohm;
1897                     lukestructs.transpfaste = transpfaste;
1898                     lukestructs.ripple = ripple;
1899                     %
1900                 end
1901                 %
1902                 lukestructs = run_lukert(lukestructs,dkepath);
1903                 %
1904                 if isfield(lukestructs,'output'),%job was run successfully
1905                     %
1906                     disp('LUKE run completed');
1907                     %
1908                     output = lukestructs.output;
1909                     %
1910                     status.output = 1;
1911                     status.data = 2;
1912                     %
1913                 elseif isfield(lukestructs,'err'),%job failed
1914                     %
1915                     disp('Remote LUKE run failed for the following reason :');
1916                     %
1917                     disperr_jd(lukestructs.err)
1918                     %
1919                 elseif isfield(lukestructs,'job'),%job running, to be checked later
1920                     %
1921                     disp('LUKE run running.');
1922                     %
1923                     luke_job = lukestructs.job;
1924                     %
1925                     output = '';
1926                     %
1927                     status.output = 0;
1928                     status.data = 2;
1929                     %
1930                 else
1931                     %
1932                     error('LUKE output not recognized')
1933                     %
1934                 end
1935                 %
1936                 clear lukestructs
1937                 %
1938                 if status.output == 1 && status.data == 2 && status.waves ~= 0 && input_dke_yp('--> Do you want to update the waves structures with LUKE absorption (y/n)','y',{'y','n'}) == 'y',
1939                     waves = output.dke_out.waves;
1940                 end
1941                 %
1942             elseif isel < 0 && status.data == 2,
1943                 if input_dke_yp('--> Data is not saved. Are you sure you want to quit LUKE (y/n)','n',{'y','n'}) == 'n',
1944                     isel = 1;
1945                 end
1946             end
1947             %
1948         catch lsterr
1949             %
1950             disp('The action was cancelled due to the following error:')
1951             disp(' ');
1952             disp(lsterr.message);
1953             for il = 1:length(lsterr.stack),
1954                 disp(['In ',lsterr.stack(il).file,' at line ',num2str(lsterr.stack(il).line)]);
1955             end
1956             %
1957         end
1958     end
1959     %
1960     if isel == -2,
1961         close all
1962         clear all    
1963     end
1964     %
1965     disp(' ');
1966     disp('************** EXIT LUKE **************')
1967     disp(' ');
1968     %
1969 end
1970 %
1971 
1972 
1973 
1974 
1975

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