-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathml_run_process.m
More file actions
executable file
·52 lines (47 loc) · 1.69 KB
/
ml_run_process.m
File metadata and controls
executable file
·52 lines (47 loc) · 1.69 KB
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
48
49
50
51
function out = ml_run_process(processName,inputs,outputs,params)
% out = ml_run_process(processName,inputs,outputs,params)
% runs a mountainlab processors with inputs and outputs being structures
% giving the names inputs and outputs of the function
% params is likewise
conda_path = get_conda_path();
runStr = ['. ' conda_path ' && conda activate mlab && ml-run-process ' processName ' '];
inStr = ['-i ' makeKeyStr(inputs)];
outStr = ['-o ' makeKeyStr(outputs)];
if exist('params','var') && ~isempty(params)
pStr = ['-p ' makeKeyStr(params)];
else
pStr = '';
end
runStr = [runStr ' ' inStr ' ' outStr ' ' pStr];
disp(['Executing command: ' runStr])
[errCode,out] = system(runStr,'-echo');
if errCode~=0
error('Something went wrong! Derp!\n%s',out)
end
function oStr = makeKeyStr(s)
% makes string in key:value format from structure
oStr = '';
FNs = fieldnames(s);
for k=1:numel(FNs)
val = s.(FNs{k});
if iscell(val)
for l=1:numel(val)
tmpV = val{l};
if isnumeric(tmpV)
tmpV = num2str(tmpV);
end
oStr = [oStr FNs{k},':',tmpV];
if l<numel(val) || k<numel(FNs)
oStr = [oStr ' '];
end
end
else
if isnumeric(val)
val = num2str(val);
end
oStr = [oStr,FNs{k},':',val];
if k<numel(FNs)
oStr = [oStr,' '];
end
end
end