summaryrefslogtreecommitdiff
path: root/openEMS/matlab/private/invoke_openEMS.m
blob: afb2b463eb27df93c74741b76951f328d4eeb13e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
function invoke_openEMS( opts, logfile, silent )
% function invoke_openEMS( opts, logfile, silent )
%
% internal method to invoke openEMS, use RunOpenEMS instead
%
% See also RunOpenEMS
%
% openEMS matlab interface
% -----------------------
% author: Sebastian Held, Thorsten Liebig

if nargin < 1
    error 'specify the xml file to simulate'
end
if nargin < 3
    silent = 0;
end
if (nargin < 2) || isempty(logfile)
    if isunix
        logfile = '/dev/null';
    else
        logfile = 'nul:';
    end
end

filename = mfilename('fullpath');
dir = fileparts( filename );

if isunix
    openEMS_bin = searchBinary('openEMS.sh', ...
    {[dir filesep '..' filesep '..' filesep], ...  % try devel path
     [dir filesep '..' filesep '..' filesep '..' filesep '..' filesep 'bin' filesep]}); % try (default) install path
else % assume windows
    openEMS_bin = searchBinary('openEMS.exe', [dir filesep '..' filesep '..' filesep]);
end

command = [openEMS_bin ' ' opts];

if ~silent
    if (isunix && nargin>1)
        command = [command ' 2>&1 | tee ' logfile];
    end
else
    command = [command ' > ' logfile ' 2>&1'];
end

system(command);