iload_externaldata_jd

PURPOSE ^

SYNOPSIS ^

function external = iload_externaldata_jd(dkepath,basestr,workdir,opt_gui,style)

DESCRIPTION ^

 This function loads data from external database

 Note : the structure 'external' must have the following fields

   - basestr (string) : name of the tomakak
   - shotnum (string) : shot number

 either
   - shotime (scalar) : shot time (s)
 or 
   - shotimes (scalar array) : shot times (s)

 external data grouped according to the corresponding CPO, such as
   - equil (struct)
   - wave (struct)
   - ohm (struct)
   - transpfaste (struct)
   - ripple (struct)
   - hxr (struct)

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function external = iload_externaldata_jd(dkepath,basestr,workdir,opt_gui,style)
0002     %
0003     % This function loads data from external database
0004     %
0005     % Note : the structure 'external' must have the following fields
0006     %
0007     %   - basestr (string) : name of the tomakak
0008     %   - shotnum (string) : shot number
0009     %
0010     % either
0011     %   - shotime (scalar) : shot time (s)
0012     % or
0013     %   - shotimes (scalar array) : shot times (s)
0014     %
0015     % external data grouped according to the corresponding CPO, such as
0016     %   - equil (struct)
0017     %   - wave (struct)
0018     %   - ohm (struct)
0019     %   - transpfaste (struct)
0020     %   - ripple (struct)
0021     %   - hxr (struct)
0022     %
0023     if nargin < 5,
0024         style = struct;
0025     end
0026     if nargin < 4,
0027         opt_gui = true;
0028     end
0029     if ~isfield(style,'distselectstyle'),
0030         style.distselectstyle = style;
0031     end
0032     %
0033     external = [];
0034     %
0035     % select remote profile for calculation
0036     %
0037     LUKE_REMNUM = getenv('LUKE_REMNUM');
0038     if isempty(LUKE_REMNUM),
0039         remnum = iselect_jd(dkepath.remprofiles,'Select local or remote location for database quest',opt_gui,style.distselectstyle,1,'popupmenu') - 1;
0040     else
0041         remnum = str2double(LUKE_REMNUM); 
0042     end
0043     %
0044     if remnum == 0,
0045         remote = [];
0046     else
0047         remote = dkepath.remote(remnum);
0048     end
0049     %
0050     % load_externaldata file selection
0051     %
0052     if nargin > 1 && ~isempty(basestr),% from irunluke
0053         %
0054         fname = ['load_externaldata_',basestr];
0055         %
0056         if ~exist(fname,'file'),
0057             %
0058             disp(['-----> Database access is not implemented for ',basestr]);
0059             return;    
0060             %
0061         end    
0062         %
0063     else% from iluke
0064         %
0065         basestrs = find_externalbases_jd(dkepath.luke_root);
0066         %
0067         if isempty(basestrs),
0068             external.err = 'No function found to import from database';
0069             return
0070         end
0071         %
0072         LUKE_EXTERNAL = getenv('LUKE_EXTERNAL');
0073         ibasestr = find(strcmp(basestrs,LUKE_EXTERNAL));
0074         %
0075         if isempty(ibasestr),% defautl is TS
0076             ibasestr = find(strcmp(basestrs,'TS'));
0077         end
0078         %
0079         style.butwidth = 150;
0080         baseselect = iselect_jd(basestrs,'Select tokamak (and eventually database function)',opt_gui,style,ibasestr,'popupmenu');
0081         basestr = basestrs{baseselect};
0082         %
0083         fname = ['load_externaldata_',basestr];
0084         %
0085     end
0086     %
0087     iMultiTimes = strfind(basestr,'MultiTimes');
0088     %
0089     % multitimes case only valid for TCV for now... not yet part of generalized process
0090     %
0091     if ~any(iMultiTimes),% select one time
0092         %
0093         % get input arguments for file load_externaldata
0094         %
0095         external_in = feval(fname);% call to load_externaldata with no arguments returns requested options from the function
0096         %
0097         % user-modified options
0098         %
0099         external_in = imod_struct_jd(external_in,'external',0,boolean(opt_gui),external_in,style);
0100         %
0101         [err,~,external_out] = matremote_jd(fname,{external_in,opt_gui},remote);
0102         %
0103         if isempty(err),
0104             external = external_out;
0105         end
0106         %
0107     else
0108         %
0109         external = feval(fname,pwd,opt_gui,style,remote);
0110         %
0111     end
0112 end
0113 %
0114 function basestrs = find_externalbases_jd(luke_root)
0115     %
0116     datadir = [luke_root,'Project_DKE/Database/EXTERNAL_files/'];
0117     %
0118     datafiles = dir(datadir);
0119     %
0120     strtofind = 'load_externaldata_';
0121     %
0122     basestrs = {};
0123     %
0124     for iname = 1:length(datafiles),
0125         if length(datafiles(iname).name) > length(strtofind) && strcmp(datafiles(iname).name(1:length(strtofind)),strtofind) && strcmp(datafiles(iname).name(end-1:end),'.m'),
0126             basestrs = [basestrs,datafiles(iname).name(length(strtofind)+1:end-2)];
0127         end
0128     end    
0129     %
0130 end
0131 %

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