2010-06-09 07:22:54 +00:00
|
|
|
function RunOpenEMS(Sim_Path, Sim_File, opts, Settings)
|
|
|
|
% function RunOpenEMS(Sim_Path, Sim_File, opts, Settings)
|
|
|
|
%
|
|
|
|
% Run an openEMS simulation
|
|
|
|
%
|
|
|
|
% example:
|
|
|
|
% Sim_Path = 'MySimPath';
|
|
|
|
% Sim_File = 'helix.xml'; %should be created by WriteOpenEMS
|
|
|
|
% opts = '--engine=fastest';
|
|
|
|
%
|
2010-07-20 09:38:06 +00:00
|
|
|
% optional:
|
2010-06-09 07:22:54 +00:00
|
|
|
% (ssh only on unix with working ssh client)
|
|
|
|
% Settings.SSH.host = '<hostname or ip>'
|
|
|
|
% Settings.SSH.bin = '<path_to_openEMS>/openEMS.sh'
|
2011-07-07 06:11:39 +00:00
|
|
|
% ssh optional:
|
|
|
|
% Settings.SSH.host_list = {'list','of','hosts'}; %searches for a free host
|
2010-06-09 07:22:54 +00:00
|
|
|
%
|
2011-02-24 13:44:29 +00:00
|
|
|
% optional MPI:
|
|
|
|
% Settings.MPI.xxx --> help RunOpenEMS_MPI
|
|
|
|
%
|
2010-06-21 10:17:19 +00:00
|
|
|
% Settings.LogFile = 'openEMS.log'
|
2010-07-20 09:38:06 +00:00
|
|
|
% Settings.Silent = 0
|
2010-06-21 10:17:19 +00:00
|
|
|
%
|
2010-06-09 07:22:54 +00:00
|
|
|
% RunOpenEMS(Sim_Path,Sim_File,opts,Settings)
|
|
|
|
%
|
2011-07-07 06:11:39 +00:00
|
|
|
% See also WriteOpenEMS FindFreeSSH
|
2010-06-09 07:22:54 +00:00
|
|
|
%
|
|
|
|
% openEMS matlab interface
|
|
|
|
% -----------------------
|
|
|
|
% author: Thorsten Liebig
|
|
|
|
|
2011-09-13 08:50:08 +00:00
|
|
|
if nargin < 2
|
2010-06-09 07:22:54 +00:00
|
|
|
error 'specify the Sim_Path and Sim_file to simulate'
|
|
|
|
end
|
|
|
|
|
2011-09-13 08:50:08 +00:00
|
|
|
if nargin < 3
|
|
|
|
opts = '';
|
|
|
|
end
|
|
|
|
|
2010-06-09 07:22:54 +00:00
|
|
|
if (nargin<4)
|
|
|
|
Settings = [];
|
|
|
|
end
|
|
|
|
|
2011-03-21 13:46:35 +00:00
|
|
|
if (isfield(Settings,'MPI') && isunix)
|
2011-02-24 13:44:29 +00:00
|
|
|
if (Settings.MPI.NrProc>1)
|
|
|
|
RunOpenEMS_MPI(Sim_Path, Sim_File, opts, Settings);
|
|
|
|
return;
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2010-06-09 07:22:54 +00:00
|
|
|
savePath = pwd;
|
|
|
|
cd(Sim_Path);
|
|
|
|
|
|
|
|
if (isfield(Settings,'SSH') && isunix)
|
2010-11-25 11:54:02 +00:00
|
|
|
% ssh options: no X forwarding; no password prompt (use pub keys!); no
|
|
|
|
% host checking
|
|
|
|
scp_options = '-C -o "PasswordAuthentication no" -o "StrictHostKeyChecking no"';
|
|
|
|
ssh_options = [scp_options ' -x'];
|
|
|
|
|
2011-07-07 06:11:39 +00:00
|
|
|
if isfield(Settings.SSH,'host_list')
|
|
|
|
host = FindFreeSSH(Settings.SSH.host_list);
|
|
|
|
if ~isempty(host)
|
|
|
|
Settings.SSH.host = host;
|
|
|
|
else
|
|
|
|
error('openEMS:RunOpenEMS', 'unable to find host, abort openEMS');
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2010-08-09 14:56:35 +00:00
|
|
|
% create a tmp working dir
|
2010-11-25 11:54:02 +00:00
|
|
|
[status, result] = unix(['ssh ' ssh_options ' ' Settings.SSH.host ' "mktemp -d /tmp/openEMS_XXXXXXXXXXXX"']);
|
2010-06-09 07:22:54 +00:00
|
|
|
if (status~=0)
|
|
|
|
disp(result);
|
2010-08-09 14:56:35 +00:00
|
|
|
error('openEMS:RunOpenEMS','mktemp failed to create tmp directory!');
|
2010-06-09 07:22:54 +00:00
|
|
|
end
|
2010-08-09 14:56:35 +00:00
|
|
|
ssh_work_path = strtrim(result); %remove tailing \n
|
|
|
|
|
|
|
|
disp(['Running remote openEMS on ' Settings.SSH.host ' at working dir: ' ssh_work_path]);
|
2010-06-09 07:22:54 +00:00
|
|
|
|
2010-11-26 13:48:47 +00:00
|
|
|
%copy openEMS all simulation files to the ssh host
|
|
|
|
[stat, res] = unix(['scp ' scp_options ' * ' Settings.SSH.host ':' ssh_work_path '/']);
|
2010-06-09 07:22:54 +00:00
|
|
|
if (stat~=0)
|
|
|
|
disp(res);
|
|
|
|
error('openEMS:RunOpenEMS','scp failed!');
|
|
|
|
end
|
|
|
|
|
2010-08-09 14:56:35 +00:00
|
|
|
%run openEMS (with log file if requested)
|
2010-06-21 10:17:19 +00:00
|
|
|
if isfield(Settings,'LogFile')
|
|
|
|
append_unix = [' 2>&1 | tee ' Settings.LogFile];
|
|
|
|
else
|
|
|
|
append_unix = [];
|
|
|
|
end
|
2010-11-25 11:54:02 +00:00
|
|
|
status = unix(['ssh ' ssh_options ' ' Settings.SSH.host ' "cd ' ssh_work_path ' && ' Settings.SSH.bin ' ' Sim_File ' ' opts '"' append_unix]);
|
2010-06-09 07:22:54 +00:00
|
|
|
if (status~=0)
|
|
|
|
disp(result);
|
|
|
|
error('openEMS:RunOpenEMS','ssh openEMS failed!');
|
|
|
|
end
|
|
|
|
|
2010-07-20 09:38:06 +00:00
|
|
|
disp( 'Remote simulation done... copying back results and cleaning up...' );
|
2010-06-09 07:22:54 +00:00
|
|
|
|
2010-08-09 14:56:35 +00:00
|
|
|
%copy back all results
|
2011-05-24 09:49:55 +00:00
|
|
|
[stat, res] = unix(['scp -r ' scp_options ' ' Settings.SSH.host ':' ssh_work_path '/* ''' pwd '''/']);
|
2010-06-09 07:22:54 +00:00
|
|
|
if (stat~=0);
|
|
|
|
disp(res);
|
|
|
|
error('openEMS:RunOpenEMS','scp failed!');
|
|
|
|
end
|
|
|
|
|
2010-08-09 14:56:35 +00:00
|
|
|
%cleanup
|
2010-11-25 11:54:02 +00:00
|
|
|
[stat, res] = unix(['ssh ' ssh_options ' ' Settings.SSH.host ' rm -r ' ssh_work_path]);
|
2010-06-09 07:22:54 +00:00
|
|
|
if (stat~=0);
|
|
|
|
disp(res);
|
2010-08-09 14:56:35 +00:00
|
|
|
warning('openEMS:RunOpenEMS','remote cleanup failed!');
|
2010-06-09 07:22:54 +00:00
|
|
|
end
|
|
|
|
else
|
|
|
|
args = [Sim_File ' ' opts];
|
2010-07-20 09:38:06 +00:00
|
|
|
if isfield(Settings,'LogFile') && isfield(Settings,'Silent')
|
|
|
|
invoke_openEMS(args,Settings.LogFile,Settings.Silent);
|
|
|
|
elseif isfield(Settings,'LogFile')
|
2010-06-21 10:17:19 +00:00
|
|
|
invoke_openEMS(args,Settings.LogFile);
|
2010-07-20 09:38:06 +00:00
|
|
|
elseif isfield(Settings,'Silent')
|
|
|
|
invoke_openEMS(args,[],Settings.Silent);
|
2010-06-21 10:17:19 +00:00
|
|
|
else
|
|
|
|
invoke_openEMS(args);
|
|
|
|
end
|
2010-06-09 07:22:54 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
cd(savePath);
|
|
|
|
return
|