source: trunk/src/command_launch_matlab.m @ 1201

Last change on this file since 1201 was 1201, checked in by sommeria, 5 hours ago

various improvements...

File size: 2.6 KB
RevLine 
[1201]1%'command_launch_matlab': creates the command strings for opening a new Matlab session
[1179]2% and running a programme in a Linux system('GLNX86','GLNXA64','MACI64')
[1134]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');
[1201]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
[1134]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
22function cmd=command_launch_matlab(filelog,path_uvmat,ActionPath,ActionName,inputxml,option)
23ThreadOption='';
24if strcmp(option,'cluster')
25    ThreadOption='-singleCompThread';
26    inputxml={inputxml};% single input parameter file
27end
28matlab_ver = ver('MATLAB');
29matlab_version = matlab_ver.Version;
[1201]30% matlab launch options:
31  % -nodisplay: no graphic display
32  % -nodesktop: disables the desktop environment.
33   % replaces -nojvm: no Java-related overhead (useful for scripts or batch jobs)
34   % TODO : replace all these options by -batch for newer Matlab versions
[1134]35cmd=[...
36    '#!/bin/bash\n'...
37    'source /etc/profile\n'...
38    'module purge\n'...
39    'module load matlab/' matlab_version '\n'...% CHOICE OF THE SAME MATLAB VERSION AS THE CURRENT MATLAB SESSION (not mandatory)
40    'time_start=$(date +%%s)\n'...
[1201]41    'matlab -nodisplay -nosplash -nodesktop ''' ThreadOption ''' -logfile ''' filelog ''' <<END_MATLAB\n'...%launch the new Matlab session  without display
[1134]42    'addpath(''' path_uvmat ''');\n'...
[1184]43    'current_dir=pwd;\n'... % current working dir
44    'cd(''' ActionPath ''');\n'...
[1201]45    'h_fun=str2func(''' ActionName ''');\n'...% create the function handle for the function ActionName
46    'cd(current_dir);\n'];
[1134]47for iprocess=1:numel(inputxml)
[1201]48    cmd=[cmd ' h_fun  (''' inputxml{iprocess} ''');\n'];
[1134]49end
50cmd=[cmd  'exit\n' 'END_MATLAB\n'];
[1201]51if strcmp(option,'background')
[1134]52    cmd=[cmd ...
[1201]53        'time_end=$(date +%%s)\n'...
54        'echo "global time = " $(($time_end - $time_start)) >> ''' filelog '''\n'];
55end
[1134]56
57
58
Note: See TracBrowser for help on using the repository browser.