forked from esi-neuroscience/slurmfun
-
Notifications
You must be signed in to change notification settings - Fork 0
/
fexec.m
34 lines (29 loc) · 900 Bytes
/
fexec.m
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
function out = fexec(func, inputVars, outputFile)
%
% input file must contain the variables func, inputVars, outputFile
fprintf('Trying to evaluate %s\n', func2str(func))
try
nOutput = nargout(func);
if nOutput > 1
out = cell(1, nOutput);
[out{:}] = feval(func, inputVars{:});
elseif nOutput == 1
out = feval(func, inputVars{:});
elseif nOutput == 0
out = 'no output';
feval(func, inputVars{:});
else
error('Unsupported number of output arguments (%d)', nOutput)
end
outSize = whos('out');
if outSize.bytes > 2*1024*1024*1024
error(['Size of the output arguments must not exceed 2 GB. ', ...
'For large data please save to disk in your function'])
end
catch me
me.display();
out = me;
end
fprintf('Storing output in %s\n', outputFile)
save(outputFile, 'out', '-v6')
exit