setpath_luke_jd

PURPOSE ^

SYNOPSIS ^

function dkepath = setpath_luke_jd(dkepath,link_mode,test_mode,display_mode,inter_mode)

DESCRIPTION ^

 LUKE - This function sets the path such that the simulations run on the specified LUKE version.

 Actions :
   - remove exisiting LUKE paths
   - load LUKE_PATH.mat and process for hostname and username and test the consistency with the local script in interactive mode
   - test remote connections
   - compile MEX files if needed
   - setup new LUKE paths, including MEX files and matrix inverters

 INPUTS :

   - dkepath :
       o '' (or nargin == 0) : LUKE_PATH.mat is searched for in the current path
       o luke_root (string)  : LUKE root path
       o dkepath (struct)    : an existing dkepath structure (setpath_luke_jd then used to reset paths, recompile MEX, or test remote connections)

   - link_mode : connection mode prescription
       o -2  : disable remote profiles
       o -1  : local profiles only
       o NaN : (default) use value from remote.link_mode
       o []  : give priority to (0) ssh key pair, (1) ssh bridge, (2) url/ftp bridge
       o 0   : ssh key pair enforced
       o 1   : ssh bridge enforced
       o 2   : url/ftp bridge enforced

   - test_mode : test the connections

 OUTPUTS : 

   - dkepath : structure containing LUKE path and remote LUKE data specific to local filesystem, hostname and username.
               if nargout = 0, dkepath is saved in matlab application data

 by Joan Decker CEA-IRFM (joan.decker@cea.fr) and Y.Peysson CEA-IRFM <yves.peysson@cea.fr>

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function dkepath = setpath_luke_jd(dkepath,link_mode,test_mode,display_mode,inter_mode)
0002 %
0003 % LUKE - This function sets the path such that the simulations run on the specified LUKE version.
0004 %
0005 % Actions :
0006 %   - remove exisiting LUKE paths
0007 %   - load LUKE_PATH.mat and process for hostname and username and test the consistency with the local script in interactive mode
0008 %   - test remote connections
0009 %   - compile MEX files if needed
0010 %   - setup new LUKE paths, including MEX files and matrix inverters
0011 %
0012 % INPUTS :
0013 %
0014 %   - dkepath :
0015 %       o '' (or nargin == 0) : LUKE_PATH.mat is searched for in the current path
0016 %       o luke_root (string)  : LUKE root path
0017 %       o dkepath (struct)    : an existing dkepath structure (setpath_luke_jd then used to reset paths, recompile MEX, or test remote connections)
0018 %
0019 %   - link_mode : connection mode prescription
0020 %       o -2  : disable remote profiles
0021 %       o -1  : local profiles only
0022 %       o NaN : (default) use value from remote.link_mode
0023 %       o []  : give priority to (0) ssh key pair, (1) ssh bridge, (2) url/ftp bridge
0024 %       o 0   : ssh key pair enforced
0025 %       o 1   : ssh bridge enforced
0026 %       o 2   : url/ftp bridge enforced
0027 %
0028 %   - test_mode : test the connections
0029 %
0030 % OUTPUTS :
0031 %
0032 %   - dkepath : structure containing LUKE path and remote LUKE data specific to local filesystem, hostname and username.
0033 %               if nargout = 0, dkepath is saved in matlab application data
0034 %
0035 % by Joan Decker CEA-IRFM (joan.decker@cea.fr) and Y.Peysson CEA-IRFM <yves.peysson@cea.fr>
0036 
0037 %
0038 if nargin == 0 || isempty(dkepath),
0039     %
0040     filenames = which('LUKE_PATH.mat','-all');
0041     %
0042     if length(filenames) > 1,
0043         ifile = iselect_jd(filenames,'Warning : more than one LUKE_PATH.mat file found. Please select one of the following :',false);
0044     elseif isempty(filenames),
0045         error('No LUKE_PATH.mat found on the matlab path')
0046     else
0047         ifile = 1;
0048     end
0049     %
0050     load(filenames{ifile},'dkepath');
0051     %
0052 elseif ischar(dkepath),% luke_root
0053     %
0054     luke_root = dkepath;
0055     %
0056     if ~strcmp(luke_root(end),filesep),
0057         luke_root = [luke_root,filesep];
0058     end
0059     %
0060     filename = [luke_root,'Project_DKE/Database/PATH_files/LUKE_PATH.mat'];
0061     %
0062     if ~exist(filename,'file'),
0063         error(['The file ',filename,' does not exist'])
0064     else
0065         load(filename,'dkepath');
0066     end
0067     %
0068 elseif ~isfield(dkepath,'luke_root'),
0069     %
0070     error('Input variable ''dkepath'' cannot be identified');
0071     %
0072 end
0073 %
0074 if ~strcmp(dkepath.luke_root(end),filesep),
0075     dkepath.luke_root = [dkepath.luke_root,filesep];
0076 end
0077 %
0078 luke_root = dkepath.luke_root;
0079 %
0080 if nargin < 2,
0081     link_mode = NaN;
0082 end
0083 %
0084 if nargin < 3,
0085     test_mode = 0;
0086 end
0087 %
0088 if nargin < 4,
0089     display_mode = 1;%display the available remote profiles
0090 end
0091 %
0092 if nargin < 5,
0093     inter_mode = 0;%interactive mode disabled
0094 end
0095 %
0096 %remove old DKE and packages path
0097 %
0098 P = [path,':'];
0099 %
0100 while ~isempty(P),
0101     %
0102     ilim = find(P == ':',1,'first');
0103     pathline = P(1:ilim-1);
0104     %
0105     if ~isempty(pathline(strfind(pathline,luke_root)+length(luke_root):end)),
0106         rmpath(pathline);
0107     end
0108     P(1:ilim) = '';
0109 end
0110 %
0111 % Path for LUKE and Modules
0112 %
0113 addpath([luke_root,'Project_DKE/Modules/MHDK']);
0114 addpath([luke_root,'Project_DKE/Modules/FEB/Response']);
0115 addpath([luke_root,'Project_DKE/Modules/FEB/Pile-up']);
0116 addpath([luke_root,'Project_DKE/Modules/FEB']);
0117 addpath([luke_root,'Project_DKE/Modules/ALOHA']);
0118 addpath([luke_root,'Project_DKE/Modules/AMR']);
0119 addpath([luke_root,'Project_DKE/Modules/ACCOME']);
0120 addpath([luke_root,'Project_DKE/Modules/Helena']);
0121 addpath([luke_root,'Project_DKE/Modules/R2D2']);
0122 addpath([luke_root,'Project_DKE/Modules/R2D2/MEX/Bin']);
0123 addpath([luke_root,'Project_DKE/Modules/EFIT']);
0124 addpath([luke_root,'Project_DKE/Modules/C3PO']);
0125 addpath([luke_root,'Project_DKE/Modules/Ripple']);
0126 addpath([luke_root,'Project_DKE/Modules/Ripple/TS']);
0127 addpath([luke_root,'Project_DKE/Modules/Cronos']);
0128 addpath([luke_root,'Project_DKE/Modules/ITM']);
0129 addpath([luke_root,'Project_DKE/Modules/METIS']);
0130 addpath([luke_root,'Project_DKE/Display']);
0131 addpath([luke_root,'Project_DKE/Packages']);
0132 addpath([luke_root,'Project_DKE/Packages/MUMPS']);
0133 addpath([luke_root,'Project_DKE/Packages/PARDISO']);
0134 addpath([luke_root,'Project_DKE/Packages/PETSc']);
0135 addpath([luke_root,'Project_DKE/Packages/MDCE']);
0136 addpath([luke_root,'Project_DKE/Database/DISPLAY_files']);
0137 addpath([luke_root,'Project_DKE/Database/DKEPARAM_files']);
0138 addpath([luke_root,'Project_DKE/Database/EQUIL_files']);
0139 addpath([luke_root,'Project_DKE/Database/FLUCT_files']);
0140 addpath([luke_root,'Project_DKE/Database/HXR_files']);
0141 addpath([luke_root,'Project_DKE/Database/WAVE_files']);
0142 addpath([luke_root,'Project_DKE/Database/OHM_files']);
0143 addpath([luke_root,'Project_DKE/Database/TRANSP_files']);
0144 addpath([luke_root,'Project_DKE/Database/RIPPLE_files']);
0145 addpath([luke_root,'Project_DKE/Database/EXTERNAL_files']);
0146 addpath([luke_root,'Project_DKE/Database/EXTERNAL_files/TSBase/TSBase']);
0147 addpath([luke_root,'Project_DKE/Database/PATH_files']);
0148 addpath([luke_root,'Project_DKE/DKE']);
0149 addpath([luke_root,'Tools']);
0150 %
0151 % check if dkepath structure has changed in the local path file and may be inconsistent with
0152 % data in LUKE_PATH.mat. In that case, LUKE_PATH.mat is rebuild
0153 % dynamically.
0154 %
0155 if inter_mode,
0156     %
0157     [dkepath_from_script,SelectedPathFileName] = load_dkepath_yp(1);
0158     res = comp_struct_jd(dkepath,dkepath_from_script,0,'profilestr','','dkepath_from_LUKE_PATH',['dkepath_from_',SelectedPathFileName]);
0159     %
0160     if res,
0161         if display_mode,
0162             disp(' ')
0163             disp(['---> The ''dkepath'' structure in ',luke_root,'Project_DKE/Database/PATH_files/LUKE_PATH.mat is consistent'])
0164             disp(['     with the script ',luke_root,'Project_DKE/Database/PATH_files/',SelectedPathFileName,'.m'])
0165         end
0166     else
0167         disp(' ')
0168         disp(['---> WARNING: the ''dkepath'' structure in ',luke_root,'Project_DKE/Database/PATH_files/LUKE_PATH.mat is NOT consistent'])
0169         disp(['     with the script ',luke_root,'Project_DKE/Database/PATH_files/',SelectedPathFileName,'.m.'])
0170         disp(' ')
0171         %
0172         disp(' ');
0173         disp('---------------------');
0174         disp(' ');
0175         comp_struct_jd(dkepath,dkepath_from_script,1,'profilestr','','dkepath_from_LUKE_PATH',['dkepath_from_',SelectedPathFileName]);
0176         disp(' ');
0177         disp('---------------------');
0178         disp(' ');
0179         %
0180         update_LUKE_PATH = input_dke_yp('Update LUKE_PATH.mat ? (0) no, (1) yes',0,0:1);
0181         %
0182         if update_LUKE_PATH,
0183             dirinit = pwd;
0184             cd(luke_root);
0185             make_path_LOCAL;
0186             cd(dirinit);
0187             dkepath = dkepath_from_script;
0188             %
0189         else
0190             disp(' ')
0191             disp(['---> WARNING: the ''dkepath'' structure in ',luke_root,'LUKE_PATH.mat has not been updated'])
0192             disp(' ') 
0193         end
0194     end
0195 end
0196 %
0197 % identify local hostname if multiple profiles on the same filesystem
0198 %
0199 % Load all path files and select local path profile according to hostname
0200 %
0201 if isfield(dkepath,'hostname') && iscell(dkepath.hostname),
0202     %
0203     lochostname = hostname_jd;
0204     nhosts = length(dkepath.hostname);
0205     flag = zeros(1,nhosts);
0206     mflags = cell(1,nhosts);
0207     for ihost = 1:nhosts,
0208         if iscell(dkepath.hostname{ihost}),
0209             mflags{ihost} = false(1,length(dkepath.hostname{ihost}));
0210             for imhost = 1:length(dkepath.hostname{ihost}),
0211                 mflags{ihost}(imhost) = any(strfind(lochostname,dkepath.hostname{ihost}{imhost}));
0212             end
0213         else
0214             mflags{ihost} = any(strfind(lochostname,dkepath.hostname{ihost}));
0215         end
0216         flag(ihost) = sum(mflags{ihost});
0217     end
0218     flagsum = sum(flag);
0219     %
0220     if flagsum == 0,
0221         error('The local hostname could not be identified in dkepath')
0222     elseif flagsum > 1,
0223         disp('WARNING : more than one positive identification for local hostname in dkepath. First match enforced.')
0224     end
0225     ihost = find(flag > 0,1,'first');
0226     imhost = find(mflags{ihost},1,'first');
0227     %
0228     dkepath = conc_struct_jd(dkepath,dkepath.(dkepath.machine{ihost}));% add fields specific to local profile
0229     %
0230     dkepath = rmfield(dkepath,dkepath.machine);% remove profile-specific fields
0231     %
0232     if iscell(dkepath.hostname{ihost}),
0233         dkepath.hostname = dkepath.hostname{ihost}{imhost};
0234     else
0235         dkepath.hostname = dkepath.hostname{ihost};
0236     end
0237     dkepath.machine = dkepath.machine{ihost};
0238     %
0239 end
0240 %
0241 % Path for extra libraries
0242 %
0243 if isfield(dkepath,'extrapaths'),
0244     extrapathsfields = fieldnames(dkepath.extrapaths);
0245     for ifield = 1:length(extrapathsfields)
0246         addpath(dkepath.extrapaths.(extrapathsfields{ifield}));
0247     end
0248 end
0249 %
0250 % Path for machine specific libraries
0251 %
0252 if isfield(dkepath,'speclibpath'),
0253     speclibpathfields = fieldnames(dkepath.speclibpath);
0254     for ifield = 1:length(speclibpathfields)
0255         addpath(dkepath.speclibpath.(speclibpathfields{ifield}));
0256     end
0257 end 
0258 %
0259 % Path for MEX files
0260 %
0261 [dummy,matver] = LUKEversion_jd;
0262 %
0263 sourcepath.DKE = [luke_root,'Project_DKE/MEX/Source/'];
0264 sourcepath.C3PO = [luke_root,'Project_DKE/Modules/C3PO/MEX/Source/'];
0265 sourcepath.helmex = [luke_root,'Project_DKE/Modules/Helena/MEX/Source/'];
0266 %
0267 if isfield(dkepath,['mex',matver]),
0268     mexpath = dkepath.(['mex',matver]);
0269     force_compile = 0;
0270 else
0271     mexpath = [luke_root,'Project_DKE/MEX/Bin'];
0272     force_compile = 1;
0273 end
0274 mex_compile_luke(sourcepath,mexpath,dkepath.compiler_opt,force_compile);
0275 %
0276 addpath(mexpath);
0277 %
0278 % Path for external packages
0279 %
0280 if isfield(dkepath,'MUMPS') 
0281     if isfield(dkepath.MUMPS,['mex',matver]),
0282         addpath(dkepath.MUMPS.(['mex',matver]));
0283     elseif isfield(dkepath.MUMPS,'mex'),
0284         addpath(dkepath.MUMPS.mex);
0285     end
0286 end
0287 %
0288 if isfield(dkepath,'SUPERLU') && isfield(dkepath.SUPERLU,'mex'),
0289     addpath(dkepath.SUPERLU.mex);
0290 end
0291 %
0292 if isfield(dkepath,'PARDISO') 
0293     if isfield(dkepath.PARDISO,['mex',matver]),
0294         addpath(dkepath.PARDISO.(['mex',matver]));
0295     elseif isfield(dkepath.PARDISO,'mex'),
0296         addpath(dkepath.PARDISO.mex);
0297     end
0298 end
0299 %
0300 % update and verify remote profiles
0301 %
0302 dkepath = update_remote_jd(dkepath,link_mode,test_mode,display_mode);
0303 %
0304 if nargout == 0,
0305     setappdata(0,'dkepath',dkepath');
0306 end
0307 %
0308 if ~isempty(dkepath.remote),
0309     info_dke_yp(2,'To check if the remote profiles are currently functionning within LUKE environment, run ''check_remote_yp;''')
0310     disp (' ');
0311 end
0312 %

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