0001 function [dkepath,SelectedPathFileName] = load_dkepath_yp(display_mode)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020 if nargin == 0,
0021 display_mode = 1;
0022 end
0023
0024
0025
0026 PathsDir = fileparts(which(mfilename));
0027
0028 PathsDirContents = dir([PathsDir,filesep,'path_*m']);
0029 npathfiles = length(PathsDirContents);
0030 PathFileNames = cell(1,npathfiles);
0031 for ifile = 1:npathfiles,
0032 PathFileNames{ifile} = PathsDirContents(ifile).name(1:end-2);
0033 end
0034
0035
0036
0037 lochostname = hostname_jd;
0038
0039 dkepaths = cell(1,npathfiles);
0040 flag = false(1,npathfiles);
0041
0042 for ifile = 1:npathfiles,
0043
0044 try
0045 dkepaths{ifile} = feval(PathFileNames{ifile});
0046 catch err
0047 dkepaths{ifile} = err.message;
0048 continue
0049 end
0050
0051 if ~iscell(dkepaths{ifile}.hostname),
0052 hostnames = {dkepaths{ifile}.hostname};
0053 else
0054 hostnames = dkepaths{ifile}.hostname;
0055 end
0056
0057 for ihost = 1:length(hostnames),
0058 if ~iscell(hostnames{ihost}),
0059 mhostnames = hostnames(ihost);
0060 else
0061 mhostnames = hostnames{ihost};
0062 end
0063
0064 for imhost = 1:length(mhostnames)
0065 if any(strfind(lochostname,mhostnames{imhost})),
0066
0067
0068
0069 flag(ifile) = true;
0070 break
0071
0072 end
0073 end
0074 end
0075
0076 end
0077
0078 if ~any(flag),
0079
0080 disp(' ');
0081 disp('Warning : no local path profile found. Here is the list of tested profiles :')
0082 disp(' ');
0083
0084 for ifile = 1:npathfiles,
0085 if isstruct(dkepaths{ifile}),
0086 disp(['Profile from ',PathFileNames{ifile},'.m successfully loaded.'])
0087 else
0088 disp(['Error loading profile from ',PathFileNames{ifile},'.m : ',dkepaths{ifile}])
0089 end
0090 end
0091 disp(' ');
0092 disp('Default path profile selected')
0093
0094 dkepath = default_path_profile;
0095 else
0096
0097
0098
0099 ifiles = find(flag);
0100
0101 if sum(flag) > 1,
0102 disp(' ');
0103 iflag = iselect_jd(PathFileNames(flag),'Warning : more than one local path profile found. Please select one of the following profiles :',false);
0104 else
0105 iflag = 1;
0106 end
0107
0108 dkepath = dkepaths{ifiles(iflag)};
0109
0110
0111
0112 username = getenv('USER');
0113
0114 if ~isfield(dkepath,username),
0115 if isfield(dkepath,'default'),
0116 disp(['Warning : user ',username,' not found in file ',PathFileNames{ifiles(iflag)},'.m; selecting profile from default user ',dkepath.default])
0117 username = dkepath.default;
0118 else
0119 error(['Warning : user ',username,' not found in file ',PathFileNames{ifiles(iflag)},'.m; no default user specified.'])
0120 end
0121 end
0122
0123
0124
0125 nusers = length(dkepath.(username));
0126 if nusers > 1,
0127 disp(' ');
0128 disp(['A total of ',num2str(nusers),' profiles are defined for user ',username,' in file ',PathFileNames{ifiles(iflag)},'.m']);
0129 disp(' ');
0130 isel = input_dke_yp(['Please check the file ',PathFileNames{ifiles(iflag)},'.m and select one of the profiles (1 => ',num2str(nusers),') '],1,1:nusers);
0131 else
0132 isel = 1;
0133 end
0134
0135 dkepath.(username) = dkepath.(username)(isel);
0136
0137 dkepath = conc_struct_jd(selectfields_jd(dkepath,{'hostname','machine','computer'}),dkepath.(username));
0138
0139 if iscell(dkepath.machine),
0140 nhost = length(dkepath.machine);
0141 flag = false(1,nhost);
0142 for ihost = 1:nhost,
0143 if isfield(dkepath,dkepath.machine{ihost}),
0144 flag(ihost) = true;
0145 end
0146 end
0147
0148 dkepath.hostname = dkepath.hostname(flag);
0149 dkepath.machine = dkepath.machine(flag);
0150
0151 end
0152
0153
0154
0155 if ~isfield(dkepath,'remote'),
0156 dkepath.remote = [];
0157 end
0158
0159 if iscell(dkepath.machine),
0160 machinestr = dkepath.machine{1};
0161 for ihost = 2:length(dkepath.machine),
0162 machinestr = [machinestr,', ',dkepath.machine{ihost}];
0163 end
0164 else
0165 machinestr = dkepath.machine;
0166 end
0167
0168 SelectedPathFileName = PathFileNames{ifiles(iflag)};
0169
0170 if display_mode,
0171 disp(' ');
0172 disp(['PATH Profile #',num2str(isel),' for user ',username,' from file ',SelectedPathFileName,'.m selected for machine(s) : ',machinestr]);
0173 end
0174
0175 end
0176
0177