startup_project

PURPOSE ^

LUKE - Function which allows to swap between different LUKE branches or

SYNOPSIS ^

function [project_root_old,pmode_old] = startup_project(project_root,pmode_in,smode_in)

DESCRIPTION ^

LUKE -  Function which allows to swap between different LUKE branches or
versions (interative mode if no arguments). This function must be placed at the
 of the startup.m file. All projects should be placed in the same
 directory

 This function allows to swap between different LUKE branches or versions
 (interative mode if no arguments). This function must be placed at the
 of the startup.m file. All projects should be placed in the same
 directory

   INPUT :

       - project_root: project directory [1,1])
           (default = pwd)
       - pmode_in: project name [1,1])
       - smode_in: working directory number [1,1]

   OUTPUT : 

       - project_root_old: previous project directory [1,1])
       - pmode_old: previous project name [1,1])

 by Y.Peysson (CEA/DSM/IRFM) <yves.peysson@cea.fr> and J. Decker (CEA/DSM/IRFM) <joan.decker@cea.fr>

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [project_root_old,pmode_old] = startup_project(project_root,pmode_in,smode_in)
0002 %LUKE -  Function which allows to swap between different LUKE branches or
0003 %versions (interative mode if no arguments). This function must be placed at the
0004 % of the startup.m file. All projects should be placed in the same
0005 % directory
0006 %
0007 % This function allows to swap between different LUKE branches or versions
0008 % (interative mode if no arguments). This function must be placed at the
0009 % of the startup.m file. All projects should be placed in the same
0010 % directory
0011 %
0012 %   INPUT :
0013 %
0014 %       - project_root: project directory [1,1])
0015 %           (default = pwd)
0016 %       - pmode_in: project name [1,1])
0017 %       - smode_in: working directory number [1,1]
0018 %
0019 %   OUTPUT :
0020 %
0021 %       - project_root_old: previous project directory [1,1])
0022 %       - pmode_old: previous project name [1,1])
0023 %
0024 % by Y.Peysson (CEA/DSM/IRFM) <yves.peysson@cea.fr> and J. Decker (CEA/DSM/IRFM) <joan.decker@cea.fr>
0025 %
0026 clc
0027 close all
0028 %
0029 startup;%load already existing startup file.
0030 %
0031 project_root_old = luke_root(1:strfind(luke_root,'LUKE')-2);
0032 pmode_old = luke_root(strfind(luke_root,'LUKE'):end-1);
0033 %
0034 flag = 0;
0035 %
0036 if nargin == 0,
0037     project_root = project_root_old;%where the LUKE projects are located
0038 end
0039 %
0040 project_list = dir(project_root);%list all projects (including LUKE ones)
0041 %
0042 ipmode_menu = 1;
0043 %
0044 for ilist = 1:length(project_list),
0045     if strfind(project_list(ilist).name,'LUKE') & project_list(ilist).isdir,
0046         if ~strcmp(project_list(ilist).name,'LUKE_SIMULATIONS'),%LUKE_SIMULATIONS is not a LUKE project
0047             pmode_menu_item{ipmode_menu} = project_list(ilist).name;
0048             ipmode_menu = ipmode_menu + 1;
0049         end
0050     end
0051 end
0052 %
0053 pmode_menu0 = ['Choose a project:',char(10)];
0054 %
0055 for ilist = 1:ipmode_menu-1,
0056     pmode_menu0 = [pmode_menu0,' (',int2str(ilist),') ',pmode_menu_item{ilist},char(10)];
0057 end
0058 pmode_menu = [pmode_menu0,' (',int2str(ipmode_menu),') NO PROJECT',char(10)];
0059 %
0060 if nargin <= 1,
0061     pmode = 0;
0062     %
0063     pmode_menu = [pmode_menu,' ? '];
0064     %
0065     while pmode == 0,
0066         pmode = input(pmode_menu);
0067         if pmode == ipmode_menu,%NO PROJECT case
0068             clc;
0069             close all;
0070             clear all;
0071             disp('The Matlab path has been cleaned any LUKE project !');
0072             luke_paths_clean;
0073             return;
0074         elseif pmode > ipmode_menu | pmode < 1,
0075             clc
0076             disp('WARNING: Unknown project !');
0077             pmode = 0;
0078         else
0079             break;
0080         end
0081     end
0082 else 
0083     pmode_in = find(strcmp(pmode_menu_item,pmode_in)>0);
0084     %
0085     if pmode_in <= ipmode_menu-1 & pmode_in >= 1
0086         pmode = pmode_in;
0087         %
0088         disp(['Path set-up for ',pmode_menu_item{pmode},' project.'])
0089     else
0090         clc
0091         disp('WARNING: the requested project is not existing !');
0092         disp(pmode_menu0);      
0093         return;
0094     end
0095 end
0096 %
0097 % Set-up LUKE environment
0098 %
0099 lukebranch = pmode_menu_item{pmode};
0100 %
0101 luke_paths_clean;
0102 %
0103 % Set new path (specific LUKE branch)
0104 %
0105 cd(fullfile(project_root,lukebranch));
0106 luke_root = [pwd,'/'];
0107 addpath(fullfile(luke_root,'Project_DKE','DKE'));
0108 addpath(fullfile(luke_root,'Project_DKE','Database','PATH_files'));
0109 setpath_luke_jd(luke_root);
0110 %
0111 [lukeversion,matver] = LUKEversion_jd;
0112 [status,message_net] = unix('uname -n');%Network name of the machine
0113 %
0114 addpath(fullfile(luke_root,'Project_DKE','MEX','Bin',message_net(1:end-1),['MATLAB',matver],'/'));
0115 %
0116 clc
0117 %
0118 startuppath = which('startup.m');%The default directory for startup.m is the same as the always existing startup.m file
0119 %
0120 if exist(startuppath),%startup.m file already exist
0121     flag = 0;
0122     %
0123     fid = fopen(startuppath,'r+');  
0124     if fid == -1,
0125         disp(['Cannot write to startup.m, no permission.']);
0126         disp(['A new startup.m file will be created in the home or pathdef directory.']);
0127         disp(['This startup.m file will also call the original startup.m file']);
0128         %
0129         origstartuppath = pathforstartup;
0130         %
0131         if strcmp(computer,'PCWIN'),
0132             pathforstartup = which('pathdef.m');%The default directory for startup.m is the same as the always existing startup.m file
0133             pathforstartup = pathforstartup([1:findstr(pathforstartup,'pathdef.m')-1]);
0134         else
0135             pathforstartup = '~/';%The default directory for startup.m is the same as the always existing startup.m file
0136         end
0137         %
0138         startuppath = [pathforstartup,'startup.m'];
0139         %
0140         flag = 2;
0141         %
0142     else
0143         fclose(fid);
0144     end    
0145     %
0146     if exist(startuppath), 
0147         fid = fopen(startuppath,'r');  
0148         sfile = fread(fid);
0149         %
0150         sf1 = strfind(char(sfile'),'%%%%%%%%%%%%%%%%BEGIN-CALL-OLD-STARTUP%%%%%%%%%%%%%%%');
0151         sf2 = strfind(char(sfile'),'%%%%%%%%%%%%%%%%%END-CALL-OLD-STARTUP%%%%%%%%%%%%%%%%');
0152         while length(sf1)>0
0153             sfile = sfile([1:sf1(1)-1,sf2(1)+53:length(sfile)]);
0154             sf1 = strfind(char(sfile'),'%%%%%%%%%%%%%%%%BEGIN-CALL-OLD-STARTUP%%%%%%%%%%%%%%%');
0155             sf2 = strfind(char(sfile'),'%%%%%%%%%%%%%%%%%END-CALL-OLD-STARTUP%%%%%%%%%%%%%%%%');
0156         end
0157         %
0158         sf1 = strfind(char(sfile'),'%%%%%%%%%%%%%%%%%%%BEGIN-LUKE-PATH%%%%%%%%%%%%%%%%%%%');
0159         sf2 = strfind(char(sfile'),'%%%%%%%%%%%%%%%%%%%%END-LUKE-PATH%%%%%%%%%%%%%%%%%%%%');
0160         while length(sf1)>0
0161             sfile = sfile([1:sf1(1)-1,sf2(1)+53:length(sfile)]);
0162             sf1 = strfind(char(sfile'),'%%%%%%%%%%%%%%%%%%%BEGIN-LUKE-PATH%%%%%%%%%%%%%%%%%%%');
0163             sf2 = strfind(char(sfile'),'%%%%%%%%%%%%%%%%%%%%END-LUKE-PATH%%%%%%%%%%%%%%%%%%%%');
0164         end
0165         %
0166         fclose(fid);
0167         fid = fopen(startuppath,'w');  
0168         fwrite(fid,sfile);
0169         fclose(fid); 
0170     end
0171 else,%startup.m file does not exist. It will be created
0172     flag = 1;
0173 end
0174 %
0175 fid = fopen(startuppath,'a+');%Create or open startup.m file and append LUKE path at the end of the existing startup file
0176 %
0177 if flag == 2,
0178     fprintf(fid,'%s\n','%%%%%%%%%%%%%%%%BEGIN-CALL-OLD-STARTUP%%%%%%%%%%%%%%%');
0179     fprintf(fid,'%s\n','initdir = pwd;');
0180     fprintf(fid,'%s\n',['cd ',origstartuppath]);
0181     fprintf(fid,'%s\n','startup');
0182     fprintf(fid,'%s\n','cd(initdir)');
0183     fprintf(fid,'%s\n','%%%%%%%%%%%%%%%%%END-CALL-OLD-STARTUP%%%%%%%%%%%%%%%%');
0184 end
0185 %
0186 fprintf(fid,'%s\n','%%%%%%%%%%%%%%%%%%%BEGIN-LUKE-PATH%%%%%%%%%%%%%%%%%%%');
0187 localpath = [pwd,'/'];
0188 fprintf(fid,'%s\n','if ~isdeployed,');
0189 fprintf(fid,'%s\n',['   luke_root = ''',localpath,''';']);
0190 fprintf(fid,'%s\n','   addpath([luke_root,''Project_DKE/DKE'']);');
0191 fprintf(fid,'%s\n','   addpath([luke_root,''Project_DKE/Database/PATH_files'']);');
0192 fprintf(fid,'%s\n','   setpath_luke_jd(luke_root);');
0193 fprintf(fid,'%s\n','end');
0194 fprintf(fid,'%s\n','%%%%%%%%%%%%%%%%%%%%END-LUKE-PATH%%%%%%%%%%%%%%%%%%%%');
0195 fclose(fid);
0196 %
0197 % menu for the working directory
0198 %
0199 smode_menu0 = ['Choose a working directory:',char(10)];
0200 smode_menu0 = [smode_menu0,'  (1) PACKAGES',char(10)];
0201 smode_menu0 = [smode_menu0,'  (2) PROJECT_DKE',char(10)];
0202 smode_menu0 = [smode_menu0,'  (3) PROJECT_DKE/DATABASE',char(10)];
0203 smode_menu0 = [smode_menu0,'  (4) PROJECT_DKE/DISPLAY',char(10)];
0204 smode_menu0 = [smode_menu0,'  (5) PROJECT_DKE/DKE',char(10)];
0205 smode_menu0 = [smode_menu0,'  (6) PROJECT_DKE/MEX',char(10)];
0206 smode_menu0 = [smode_menu0,'  (7) PROJECT_DKE/MODULES',char(10)];
0207 smode_menu0 = [smode_menu0,'  (8) PROJECT_DKE/PACKAGES',char(10)];
0208 smode_menu0 = [smode_menu0,'  (9) SIMULATIONS/BENCHMARKS',char(10)];
0209 smode_menu0 = [smode_menu0,' (10) SIMULATIONS/EXAMPLES',char(10)];
0210 smode_menu0 = [smode_menu0,' (11) TOOLS',char(10)];
0211 smode_menu0 = [smode_menu0,' (12) LUKE_SIMULATIONS',char(10)];
0212 smode_menu0 = [smode_menu0,' (13) ',lukebranch,char(10),' ? '];
0213 %
0214 if nargin <= 2,
0215     smode = 0;
0216     while smode == 0,
0217         smode = input(smode_menu0);
0218         if smode >=1 & smode <= 13,
0219             break;
0220         else
0221             clc
0222             disp('WARNING: Non existing option !');
0223             smode = 0;
0224         end
0225     end
0226     %
0227     if smode == 1,cd(fullfile(project_root,lukebranch,'Packages'));end
0228     if smode == 2,cd(fullfile(project_root,lukebranch,'Project_DKE'));end
0229     if smode == 3,cd(fullfile(project_root,lukebranch,'Project_DKE/Database'));end
0230     if smode == 4,cd(fullfile(project_root,lukebranch,'Project_DKE/Display'));end
0231     if smode == 5,cd(fullfile(project_root,lukebranch,'Project_DKE/DKE'));end
0232     if smode == 6,cd(fullfile(project_root,lukebranch,'Project_DKE/MEX'));end
0233     if smode == 7,cd(fullfile(project_root,lukebranch,'Project_DKE/Modules'));end
0234     if smode == 8,cd(fullfile(project_root,lukebranch,'Project_DKE/Packages'));end
0235     if smode == 9,cd(fullfile(project_root,lukebranch,'Simulations/Benchmarks'));end
0236     if smode == 10,cd(fullfile(project_root,lukebranch,'Simulations/Examples'));end
0237     if smode == 11,cd(fullfile(project_root,lukebranch,'ToolS'));end
0238     if smode == 12,cd(fullfile(project_root,'LUKE_SIMULATIONS'));end
0239     %
0240     clc
0241     %
0242     if strcmp(lukebranch,'LUKE')
0243         disp(['>> ',lukeversion,' is now in operation (Git: main trunk)']);
0244     else
0245         disp(['>> ',lukeversion,' is now in operation (Git: ',lukebranch,')']);
0246     end
0247     %
0248     if flag,
0249         disp(['>> A startup.m file has been created in the directory ',pathforstartup,', and the LUKE path has been written in it.']);
0250     else
0251         disp(['>> The ',lukebranch,' path has been written in ',startuppath,'.']);
0252         disp([]);
0253     end
0254     %
0255     % Check the path consistency
0256     %
0257     if exist([luke_root,'Project_DKE/Database/PATH_files/PATH_LOCAL.mat']) == 0,
0258         disp(['WARNING: ',lukebranch,' has not been installed.']);
0259     else
0260         load([luke_root,'Project_DKE/Database/PATH_files/PATH_LOCAL.mat']);
0261         %
0262         if isfield(dkepath.(message_net(1:end-1)),'luke_root'),%old dkepath description until CVS branch 19
0263             if strfind(dkepath.(message_net(1:end-1)).luke_root,['/',lukebranch,'/'])
0264                 disp(['>> The dkepath structure in PATH_LOCAL.mat is consistent with ',lukebranch])
0265             else
0266                 disp(['WARNING: The dkepath structure in PATH_LOCAL.mat is not consistent with ',lukebranch]);
0267                 disp(['--> Please set-up and run the file make_path_LOCAL.m of ',lukebranch,' first !']);
0268             end 
0269         else
0270             [s,user] = unix('Users');user = user(1:end-1);
0271             %
0272             if strfind(dkepath.(message_net(1:end-1)).(user).luke_root,['/',lukebranch,'/']),
0273                 disp(['>> The dkepath structure in PATH_LOCAL.mat is consistent with ',lukebranch])
0274             else
0275                 disp(['WARNING: The dkepath structure in PATH_LOCAL.mat is not consistent with ',lukebranch]);
0276                 disp(['--> Please set-up and run the file make_path_LOCAL.m of ',lukebranch,' first !']);
0277             end           
0278          end
0279     end
0280     %
0281     disp(' ');
0282 else
0283     cd(smode_in);
0284 end
0285 
0286 
0287 
0288 
0289

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