imake_launch_jd

PURPOSE ^

SYNOPSIS ^

function launchs = imake_launch_jd(dkepath,basestr,equil,external,workdir,opt_gui,select)

DESCRIPTION ^

 This function manages and standardizes the heterogeneous external data 
 from different sources and tokamaks, then builds the launch structure.

 In interactive mode, the RF wave types and launching structures and
 selected from user input

 In non-interactive mode, in the presence of external data, all the RF
 structures listed in external are processed with default missing parameters

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function launchs = imake_launch_jd(dkepath,basestr,equil,external,workdir,opt_gui,select)
0002 %
0003 % This function manages and standardizes the heterogeneous external data
0004 % from different sources and tokamaks, then builds the launch structure.
0005 %
0006 % In interactive mode, the RF wave types and launching structures and
0007 % selected from user input
0008 %
0009 % In non-interactive mode, in the presence of external data, all the RF
0010 % structures listed in external are processed with default missing parameters
0011 %
0012 if nargin < 7,
0013     select = struct;
0014 end
0015 %
0016 if nargin < 6,
0017     opt_gui = true;
0018 end
0019 %
0020 if nargin < 5,
0021     workdir = pwd;
0022 end
0023 %
0024 if nargin < 4,
0025     external = '';
0026 end
0027 %
0028 if nargin < 3,
0029     error('Not enough arguments')
0030 end
0031 %
0032 if isempty(equil) && isfield(external,'equil'),
0033     equil = external.equil;
0034 end
0035 %
0036 if ~isfield(select,'style'),
0037     select.style = struct;
0038 end
0039 %
0040 if isfield(equil,'psi_apRp'),
0041     signs.ip = sign(equil.psi_apRp(end));
0042 elseif isfield(equil,'ip'),
0043     signs.ip = sign(equil.ip);
0044 else
0045     signs.ip = 1;
0046 end
0047 %
0048 if isfield(equil,'ptBPHI'),
0049     signs.b0 = sign(equil.ptBPHI(1,1));
0050 elseif isfield(equil,'b0'),
0051     signs.b0 = sign(equil.b0);
0052 else
0053     signs.b0 = 1;
0054 end
0055 %
0056 launchs = {};
0057 %
0058 if ~isempty(external),% import wave data from external structure
0059     %
0060     if isempty(equil),
0061         error('no equilibrium provided')
0062     end        
0063     %
0064     if isfield(equil,'shotnum'),
0065         shotnum = equil.shotnum;
0066     else
0067         istru = find(equil.id == '_');
0068         if length(istru) >= 2 && strcmp(equil.id(1:istru(1)-1),basestr),
0069             shotnum = equil.id(istru(1)+1:istru(2)-1);
0070         else           
0071             disp('-----> Shot number information missing. Abort imake_launch_jd.m');
0072             return
0073         end
0074     end
0075     %
0076     if strcmp(basestr,'TCV'),% TCV launching data
0077         %
0078         % BUILDING LAUNCH
0079         %
0080         type = 'EC';
0081         %
0082         for l_opt = external.laun,
0083             angles = imake_angles_TCV_jd(external,shotnum,l_opt,true,'',opt_gui,select.style);
0084             %
0085             if isnan(angles.P0) || angles.P0 == 0,
0086                 continue
0087             end
0088             %
0089             launch = imake_launch_angles_TCV_jd(angles);
0090             launch.type = type;
0091             %
0092             launchs{end+1} = launch;
0093         end
0094         %
0095     elseif strcmp(basestr,'TS') || strcmp(basestr,'WEST'),
0096         %
0097         % Case of LH spectrum from ALOHA file
0098         %
0099         if isfield(external,'antenna'),
0100             %
0101             spectrum = struct;
0102             if isfield(external,'id'),
0103                 spectrum.id = external.id;
0104             end
0105             %
0106             disp('********************************************************************************************')
0107             disp('WARNING: check that the ALOHA power spectrum generates a co-current or a counter current. ')
0108             disp('Do a flipud(antenna.dP_nz) and fliplr(antenna.dP) accordingly in the ALOHA file before ');
0109             disp('using ALOHA data in irunluke_jd. Co-current: Npar0(main peak) < 0 if sign(Ip)*sign(Bt) > 0');
0110             disp(' and Npar0(main peak) > 0 if sign(Ip)*sign(Bt) < 0');
0111             disp('********************************************************************************************')
0112             %
0113             spectrum.dP = external.antenna.dP;
0114             spectrum.dP_nz = external.antenna.dP_nz;
0115             spectrum.nz = external.antenna.nz;
0116             spectrum.ny = external.antenna.ny;
0117             %
0118             while 1,
0119                 opt_module = iselect_jd({'full antenna','upper module','lower module'},'This ALOHA spectrum corresponds to :',opt_gui,select.style,1);
0120                 %
0121                 if opt_module > 1,
0122                     pfac = 1/2;
0123                     pstr = ' (half antenna)';
0124                 else
0125                     pfac = 1;
0126                     pstr = '';
0127                 end                
0128                 %
0129                 val(1) = sum(external.antenna.dP_nz*external.antenna.dnz);
0130                 s{1} = ['Power from ALOHA spectrum',pstr,'        : PLH = ',num2str(val(1)/1e6),' MW'];
0131                 %
0132                 if isfield(equil,'shotnum') && ~isempty(str2double(equil.shotnum)) && isfield(equil,'shotime') && ~isempty(str2double(equil.shotime)),% shot number and time info
0133                     %
0134                     filename = [workdir,'GPHYB_',equil.shotnum,'.mat'];
0135                     %
0136                     if exist(filename,'file'),%power from file
0137                         %
0138                         load(filename,'tplh','tbase')
0139                         %
0140                         xplh = pfac*1e6*interp1(tbase(:,1),tplh,str2double(equil.shotime));
0141                         %
0142                         xplh = xplh(xplh > 0);
0143                         %
0144                         if length(xplh) == 1,
0145                             val(end+1) = xplh;
0146                             s{end+1} = ['Power from GPHYB_* file',pstr,'          : PLH = ',num2str(xplh/1e6),' MW'];
0147                         elseif length(xplh) == 2,
0148                             val(end+1:end+2) = xplh;
0149                             s{end+1} = ['Power from GPHYB_* file, ant. #1',pstr,' : PLH = ',num2str(xplh(1)/1e6),' MW'];
0150                             s{end+1} = ['Power from GPHYB_* file, ant. #2',pstr,' : PLH = ',num2str(xplh(2)/1e6),' MW'];
0151                         end
0152                         %
0153                     end
0154                     %
0155                     if exist('tsbase','file') == 3% power from TS database
0156                         %
0157                         [tplh,tbase] = tsbase(str2double(equil.shotnum),'GPHYB');
0158                         %
0159                         xplh = pfac*1e6*interp1(tbase(:,1),tplh(:,1:2),str2double(equil.shotime));
0160                         %
0161                         xplh = xplh(xplh > 0);
0162                         %
0163                         if length(xplh) == 1,
0164                             val(end+1) = xplh;
0165                             s{end+1} = ['Power from TSBASE',pstr,'                : PLH = ',num2str(xplh/1e6),' MW'];
0166                         elseif length(xplh) == 2,
0167                             val(end+1:end+2) = xplh;
0168                             s{end+1} = ['Power from TSBASE, ant. #1',pstr,'       : PLH = ',num2str(xplh(1)/1e6),' MW'];
0169                             s{end+1} = ['Power from TSBASE, ant. #2',pstr,'       : PLH = ',num2str(xplh(2)/1e6),' MW'];
0170                         end
0171                         %
0172                     end
0173                     %
0174                 end
0175                 %
0176                 s{end+1} = 'Specify power manually';
0177                 %
0178                 locstyle = select.style;
0179                 locstyle.textwidth = 600;
0180                 %
0181                 opt_Plhtot = iselect_jd(s,['LH power associated with this spectrum',pstr,' :'],opt_gui,locstyle,length(s)-1);
0182                 %
0183                 if opt_Plhtot < length(s),
0184                     spectrum.Plhtot = val(opt_Plhtot);
0185                 else
0186                     spectrum.Plhtot = 1e6*iselect_jd({},['Specify LH power',pstr,' (MW) :'],opt_gui,select.style,val(1)/1e6);
0187                 end
0188                 %
0189                 data = struct;
0190                 data.spectrum = spectrum;
0191                 select.mode = 2;%display fitted ALOHA spectra
0192                 %
0193                 launchs{1} = imake_launch_LH_jd(basestr,signs,data,opt_gui,select);
0194                 %
0195                 if opt_module == 2,
0196                     launchs{1}.rZ0 = launchs{1}.rZ0(launchs{1}.rZ0 >= 0);
0197                 elseif opt_module == 3,
0198                     launchs{1}.rZ0 = launchs{1}.rZ0(launchs{1}.rZ0 <= 0);
0199                 end  
0200                 %
0201                 disp('------------------------------------------------');
0202                 for ib = 1:length(launchs{1}.bNpar0),
0203                     disp(['Npar0 = ',num2str(launchs{1}.bNpar0(ib)),' - Power = ',num2str(launchs{1}.bPlhtot(ib)/1e6),' (MW)']);
0204                 end
0205                 disp(' ');disp('------------------------------------------------');
0206                 disp(['Total LH power in the launched spectrum (',int2str(length(launchs{1}.bNpar0)),' rays) : ',num2str(sum(launchs{1}.bPlhtot)/1e6),' (MW)']);
0207                 disp('------------------------------------------------');disp(' ');
0208                 %
0209                 opt_OK = iselect_jd({'Yes','No'},'Confirm the LH power spectrum deduced from ALOHA:',opt_gui,select.style,1);
0210                 %
0211                 if opt_OK == 1,
0212                     break
0213                 else
0214                     clear('s');
0215                 end                       
0216             end
0217         %
0218         % Case of structure external
0219         %
0220         else
0221             %
0222             % WAVE TYPE
0223             %
0224             if isfield(external,'LH') && isfield(external,'EC')
0225                 %
0226                 t_opt = input_dke_yp('Option for wave type : 0 (LH), 1 (EC)',0,0:1,'',[1,1]);
0227                 %
0228                 if t_opt == 0,
0229                     %
0230                     type = 'LH';
0231                 else
0232                     %
0233                     type = 'EC';
0234                 end
0235                 %
0236             elseif isfield(external,'LH'),
0237                 %
0238                 type = 'LH';
0239                 %
0240             elseif isfield(external,'EC'),
0241                 %
0242                 type = 'EC';
0243                 %
0244             else
0245                 disp('WAVE type not recognized in external structure. Aborted')
0246                 return
0247             end
0248             %
0249             % BUILDING LAUNCH
0250             %
0251             if strcmp(type,'LH'),
0252                 %
0253                 launch = imake_launch_LH_jd(basestr,equil,external.LH);
0254                 %
0255             elseif strcmp(type,'EC'),
0256                 %
0257                 launch = imake_launch_TS_jd(external.EC); 
0258                 %
0259             end
0260         end
0261         %
0262     elseif strcmp(basestr,'EAST') || strcmp(basestr,'HL2A'),
0263         %
0264         % Case of LH spectrum from ALOHA file
0265         %
0266         if isfield(external,'LH'),
0267             %
0268             select.position_rZ0_opt = 'y';
0269             %
0270             fnames = fieldnames(external.LH);
0271             %
0272             for a_opt = 1:length(fnames),
0273                 %
0274                 fname = fnames{a_opt};
0275                 %
0276                 if isfield(external.LH.(fname),'aloha') && isfield(external.LH.(fname),'power_spectrum') && isfield(external,'antenna')
0277                     aloha_opt = input_dke_yp([fname,' : Calculation of the power spectrum using ALOHA [0] or consider an external power spectrum [1] or an already calculated ALOHA spectrum [2] ? '],0,0:2,'',[1,1]);
0278                 elseif isfield(external.LH.(fname),'aloha') && isfield(external.LH.(fname),'power_spectrum') && ~isfield(external,'antenna')
0279                      aloha_opt = input_dke_yp([fname,' : Calculation of the power spectrum using ALOHA [0] or consider an external power spectrum [1] ? '],0,0:1,'',[1,1]);
0280                 elseif isfield(external.LH.(fname),'aloha') && ~isfield(external.LH.(fname),'power_spectrum') && isfield(external,'antenna')
0281                       aloha_opt = input_dke_yp([fname,' : Calculation of the power spectrum using ALOHA [0] or consider an already calculated ALOHA spectrum [1] ? '],0,0:1,'',[1,1]);
0282                       if aloha_opt == 1,
0283                           aloha_opt = 2;
0284                       end
0285                 elseif ~isfield(external.LH.(fname),'aloha') && isfield(external.LH.(fname),'power_spectrum') && isfield(external,'antenna')
0286                       aloha_opt = input_dke_yp('Consider an external power spectrum [0] or an already calculated ALOHA spectrum [1] ? ',0,0:1,'',[1,1]);
0287                       aloha_opt = aloha_opt + 1;
0288                 end
0289                 %
0290                 if isfield(external.LH.(fname),'aloha') && ~isfield(external.LH.(fname),'power_spectrum') && ~isfield(external,'antenna')
0291                     aloha_opt = 0;
0292                 end
0293                 %
0294                 if ~isfield(external.LH.(fname),'aloha') && isfield(external.LH.(fname),'power_spectrum') && ~isfield(external,'antenna')
0295                     aloha_opt = 1;
0296                 end
0297                 %
0298                 if ~isfield(external.LH.(fname),'aloha') && ~isfield(external.LH.(fname),'power_spectrum') && isfield(external,'antenna')
0299                     aloha_opt = 2;
0300                 end
0301                 %
0302                 if ~isfield(external.LH.(fname),'aloha') && ~isfield(external.LH.(fname),'power_spectrum') && ~isfield(external,'antenna')
0303                     error('ERROR: no data for the LH power spectrum in the external structure.')
0304                 end
0305                 %
0306                 if aloha_opt == 0,% calculate power spectrum with ALOHA
0307                     %
0308                     if strcmp(basestr,'EAST')
0309                         external.antenna = make_aloha_EAST_yp(external.LH.(fname).aloha,external.LH.(fname).antenna_measured);
0310                     elseif strcmp(basestr,'HL2A')
0311                         external.antenna = make_aloha_HL2A_yp(external.LH.(fname).aloha,external.LH.(fname).antenna_measured);
0312                     else
0313                         error(['Wrong basestr = ''',basestr,''' in imake_launch_jd.m'])
0314                     end
0315                     %
0316                     if isfield(external.antenna,'job')
0317                         launch.job = external.antenna.job;%remote ALOHA calculation
0318                         launch.id = [fname,'_ALOHA_nlh_optim_rc'];
0319                         launch.basestr = basestr;
0320                         launch.signs = signs;
0321                         launchs = [launchs,launch];
0322                     else
0323                         aloha_opt = 2;% for post-processing analysis when ALOHA is results are obtained
0324                     end
0325                 end
0326                 %
0327                 if aloha_opt == 2
0328                     launch = build_spectrum_from_aloha(external,basestr,signs,opt_gui,select);
0329                     %
0330                     if isfield(external.antenna,'id')
0331                         launch.id = external.antenna.id;
0332                     end
0333                     %
0334                     if ~isempty(launch)
0335                         launchs = [launchs,launch];
0336                     else
0337                         return
0338                     end
0339                 end
0340                 %
0341                 if aloha_opt == 1,% Case of LH spectrum from file
0342                     %
0343                     if isfield(external.LH.(fname),'power_spectrum'),
0344                         %
0345                         data = struct;
0346                         %
0347                         launchsfile = ['get_launchs_',basestr];
0348                         %
0349                         if isfield(external.LH.(fname),'id') && exist(launchsfile,'file');
0350                             [~,a_list] = feval(launchsfile);
0351                             na_list = length(a_list);
0352                             a_opt = false(1,na_list);
0353                             %
0354                             for ia_list = 1:na_list,
0355                                 %
0356                                 a_opt(ia_list) = any(strfind(lower(external.LH.(fname).id),lower(a_list{ia_list})));
0357                                 %
0358                             end
0359                             %
0360                             if sum(a_opt) == 1,
0361                                 data.id = a_list{a_opt};
0362                             else
0363                                 disp(['The antenna index could not be determined from the filename']);
0364                             end
0365                             %
0366                         end
0367                         %
0368                         data.id = fname;
0369                         data.omega_rf = 2*pi*1e9*external.LH.(fname).frequency.flh;
0370                         data.rZ0 = sort(external.LH.(fname).position.Z);
0371                         %
0372                         if isfield(external.LH.(fname).power_spectrum,'dn_par'),% lobes already processed
0373                             %
0374                             data.bNpar0 = external.LH.(fname).power_spectrum.n_par;
0375                             data.bdNpar0 = external.LH.(fname).power_spectrum.dn_par;
0376                             data.bPlhtot = external.LH.(fname).power_spectrum.power*1e6;
0377                             %
0378                         else% spectrum to be processed
0379                             %
0380                             spectrum = struct;
0381                             if isfield(external.LH.(fname),'id'),
0382                                 spectrum.id = external.LH.(fname).id;
0383                             end
0384                             spectrum.dP_nz = external.LH.(fname).power_spectrum.power;
0385                             spectrum.nz = external.LH.(fname).power_spectrum.n_par;
0386                             %
0387                             data.spectrum = spectrum;
0388                             %
0389                         end
0390                         %
0391                         launch = imake_launch_LH_jd(basestr,signs,data,opt_gui,select);
0392                         %
0393                         launchs = [launchs,launch];
0394                         %
0395                         % Case of structure external
0396                         %
0397                     else
0398                         %
0399                         data = struct;
0400                         data.id = fname;
0401                         %
0402                         data.omega_rf = 2*pi*1e9*external.LH.(fname).frequency.flh;
0403                         data.rZ0 = sort(external.LH.(fname).position.Z);
0404                         %
0405                         data.bNpar0 = external.LH.(fname).power_spectrum.n_par;
0406                         data.bdNpar0 = external.LH.(fname).power_spectrum.dn_par;
0407                         data.bPlhtot = external.LH.(fname).power_spectrum.power*1e6;
0408                         %
0409                         launch = imake_launch_LH_jd(basestr,signs,data,opt_gui,select);
0410                         %
0411                         launchs = [launchs,launch];
0412                         %
0413                     end
0414                 end
0415             end
0416         end
0417         %
0418         if isfield(external,'EC'),
0419             %
0420             fnames = fieldnames(external.EC);
0421             %
0422             for l_opt = 1:length(fnames),% launcher list
0423                 %
0424                 fname = fnames{l_opt};
0425                 %
0426                 external.EC.(fname).id = fname;
0427                 %
0428                 launch = imake_launch_EAST_jd(external.EC.(fname));
0429                 %
0430                 launchs = [launchs,launch];
0431                 %
0432             end
0433             %
0434         end
0435     elseif strcmp(basestr,'AUG'),% AUG launching data
0436         %
0437         % BUILDING LAUNCH
0438         %
0439         type = 'EC';
0440         %
0441         if isfield(external,'mmode'),% array of wave structure for each gyrotron
0442             nw = size(external,1);% number of gyrotrons
0443             gyrotrons = cell(1,nw);
0444             for iw=1:nw
0445                 gyrotrons{iw} = external(iw,:);
0446                 gyrotrons{iw}.id = ['EC_gy',num2str(iw)];
0447             end
0448         else % each gyrotron is represented by a field in wave structure
0449             fnames = fieldnames(rmfield(external,'equil'));
0450             nw = length(fnames);
0451             gyrotrons = cell(1,nw);
0452             for iw=1:nw
0453                 gyrotrons{iw} = external.(fnames{iw});
0454                 gyrotrons{iw}.id = fnames{iw};
0455             end
0456         end
0457         %
0458         for iw = 1:nw 
0459             launch.id = gyrotrons{iw}.id;
0460             launch.type = type;
0461             launch.mmode = gyrotrons{iw}.mmode;
0462             launch.omega_rf = gyrotrons{iw}.f_GHz*2*pi*1e9;
0463             launch.yR_L = gyrotrons{iw}.R_L;
0464             launch.yZ_L = gyrotrons{iw}.Z_L;
0465             launch.yphi_L = 0;
0466             launch.yalpha_L = gyrotrons{iw}.alpha_L;
0467             launch.ybeta_L = gyrotrons{iw}.beta_L;
0468             launch.yP_L = gyrotrons{iw}.P_MW*1e6;
0469             %
0470             if isfield(gyrotrons{iw},'w0')
0471                 launch.w0 = gyrotrons{iw}.w0;
0472             else
0473                 launch.w0 = 0.02;% test values
0474             end
0475             if isfield(gyrotrons{iw},'z0')
0476                 launch.z_L = gyrotrons{iw}.z0;
0477             else
0478                 launch.z_L = 0.4;% test values
0479             end
0480             %
0481             launch.dNpar0 = NaN;%Calculated from waist and focal point
0482             %
0483             launch.external = gyrotrons{iw};
0484             %
0485             launchs{end+1} = launch;
0486         end
0487         %
0488     else            
0489         %
0490         disp(['-----> wave data not yet implemented for :',basestr]);
0491         return      
0492         %
0493     end
0494     %
0495 else% create default launch structure
0496     %
0497     % WAVE TYPE
0498     %
0499     % We allow to create structures with arbitrary wave type even is the
0500     % system is not installed, for predictive calculations
0501     %
0502     if any(strcmp(basestr,{'TCV','ITER','D3D'})),
0503         t_opt_presel = 2;
0504     elseif any(strcmp(basestr,{'TS','JET','FTU','EAST'})),
0505         t_opt_presel = 1;
0506     else
0507         t_opt_presel = 1;
0508     end
0509     %
0510     t_opt = iselect_jd({'LH','EC'},'Specify wave type',opt_gui,select.style,t_opt_presel) - 1;
0511     %
0512     if t_opt == 0,
0513         %
0514         type = 'LH';
0515     else
0516         %
0517         type = 'EC';
0518     end
0519     %
0520     % BUILDING LAUNCH
0521     %
0522     if strcmp(type,'LH'),
0523         %
0524         select.inter = 1;%interactive mode
0525         %
0526         launch = imake_launch_LH_jd(basestr,signs,struct,opt_gui,select);
0527         %
0528     elseif strcmp(type,'EC'),
0529         %
0530         if strcmp(basestr,'TCV'),% TCV launching data
0531             %
0532             % default angles (perpendicular midplane launching)
0533             %
0534             angles = imake_angles_TCV_jd('',NaN,NaN,1,NaN,opt_gui,select.style);
0535             %
0536             launch = imake_launch_angles_TCV_jd(angles);
0537             %
0538         elseif strcmp(basestr,'TS')
0539             %
0540             launch = imake_launch_TS_jd('');
0541             %
0542         elseif strcmp(basestr,'EAST')
0543             %
0544             launch = imake_launch_EAST_jd('',opt_gui,select.style);
0545             %
0546         elseif strcmp(basestr,'KSTAR')
0547             %
0548             launch = imake_launch_KSTAR_jd('',opt_gui,select.style);
0549             %
0550         else
0551             %
0552             launch = imake_launch_EC_jd;
0553             %
0554         end
0555     else
0556         %
0557         disp('-----> wave type not yet implemented');
0558         %
0559     end   
0560     %
0561     launchs{1} = launch;
0562     %
0563 end
0564 %

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