| 1 | %'command_launch_matlab': creates the command strings for opening a new Matlab session |
|---|
| 2 | % and running a programme in a Linux system('GLNX86','GLNXA64','MACI64') |
|---|
| 3 | %------------------------------------------------------------------------ |
|---|
| 4 | % function cmd=command_launch_matlab(filelog,path_uvmat,ActionPath,ActionName,inputxml,option) |
|---|
| 5 | % |
|---|
| 6 | %OUTPUT |
|---|
| 7 | % cmd=set of system commands (char string) to write in an executable file: [fid,message]=fopen(file_exe,'w'); |
|---|
| 8 | % fprintf(fid,cmd); % fill the executable file with the char string cmd |
|---|
| 9 | % fclose(fid); % close the executable file |
|---|
| 10 | % system(['chmod +x ' file_exe]); % set the file to executable |
|---|
| 11 | % system([file_exe ' &'])% execute the command file |
|---|
| 12 | |
|---|
| 13 | % |
|---|
| 14 | %INPUT: |
|---|
| 15 | % filelog: name (char string) of the file to collect the output in the Matlab command window |
|---|
| 16 | % path_uvmat: path to the UVMAT Matlab toolbox |
|---|
| 17 | % ActionPath: path to the Matlab programme to launch |
|---|
| 18 | % ActionName: name of the programme to launch |
|---|
| 19 | % inputxml: full name, including path, of the xml input parameter file for the programme ActionName |
|---|
| 20 | % option: ='bacground' or 'cluster' depending on the launching option |
|---|
| 21 | |
|---|
| 22 | function cmd=command_launch_matlab(filelog,path_uvmat,ActionPath,ActionName,inputxml,option) |
|---|
| 23 | ThreadOption=''; |
|---|
| 24 | if strcmp(option,'cluster') |
|---|
| 25 | ThreadOption='-singleCompThread'; |
|---|
| 26 | inputxml={inputxml};% single input parameter file |
|---|
| 27 | end |
|---|
| 28 | matlab_ver = ver('MATLAB'); |
|---|
| 29 | matlab_version = matlab_ver.Version; |
|---|
| 30 | cmd=[... |
|---|
| 31 | '#!/bin/bash\n'... |
|---|
| 32 | 'source /etc/profile\n'... |
|---|
| 33 | 'module purge\n'... |
|---|
| 34 | 'module load matlab/' matlab_version '\n'...% CHOICE OF THE SAME MATLAB VERSION AS THE CURRENT MATLAB SESSION (not mandatory) |
|---|
| 35 | 'time_start=$(date +%%s)\n'... |
|---|
| 36 | 'matlab -nodisplay -nosplash -nojvm ''' ThreadOption ''' -logfile ''' filelog ''' <<END_MATLAB\n'...%launch the new Matlab session without display |
|---|
| 37 | 'addpath(''' path_uvmat ''');\n'... |
|---|
| 38 | 'current_dir=pwd;\n'... % current working dir |
|---|
| 39 | 'cd(''' ActionPath ''');\n'... |
|---|
| 40 | 'h_fun=str2func(''' ActionName ''');\n'...% create the function handle for the function ActionName |
|---|
| 41 | 'cd(current_dir);\n']; |
|---|
| 42 | % 'addpath(''' ActionPath ''');\n']; |
|---|
| 43 | for iprocess=1:numel(inputxml) |
|---|
| 44 | % cmd=[cmd '' ActionName '(''' inputxml{iprocess} ''');\n']; |
|---|
| 45 | cmd=[cmd ' h_fun (''' inputxml{iprocess} ''');\n']; |
|---|
| 46 | end |
|---|
| 47 | cmd=[cmd 'exit\n' 'END_MATLAB\n']; |
|---|
| 48 | if strcmp(option,'background') |
|---|
| 49 | cmd=[cmd ... |
|---|
| 50 | 'time_end=$(date +%%s)\n'... |
|---|
| 51 | 'echo "global time = " $(($time_end - $time_start)) >> ''' filelog '''\n']; |
|---|
| 52 | end |
|---|
| 53 | |
|---|
| 54 | |
|---|
| 55 | |
|---|