-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmjsRunJob.m
58 lines (45 loc) · 1.33 KB
/
mjsRunJob.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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
function mjsRunJob(job)
% Standard way to execute a job here in matlab.
%
% mjsRunJob(job)
%
% 2016-2017 Brainard Lab, University of Pennsylvania
parser = inputParser();
parser.addRequired('job', @(val) isstruct(val) || ischar(val));
parser.parse(job);
job = parser.Results.job;
if ischar(job)
job = mjsLoadJob(job);
end
printTimestamp('Starting job named "%s"', job.name);
%% Set up.
if ~isempty(job.setupCommand)
doCommand(job.setupCommand, 'setup');
end
if ~isempty(job.toolboxCommand)
doCommand(job.toolboxCommand, 'toolbox');
end
%% The job.
if ~isempty(job.jobCommand)
doCommand(job.jobCommand, 'job');
end
%% Clean Up.
if ~isempty(job.cleanupCommand)
doCommand(job.cleanupCommand, 'cleanup');
end
printTimestamp('Finished job named "%s"', job.name);
%% Consistent way to fprint with a leading timestamp.
function printTimestamp(messageFormat, varargin)
nowString = datestr(now, 'yyyy-mm-dd HH:MM:SS.FFF');
fprintf(['%s -- ' messageFormat '\n'], nowString, varargin{:});
%% Consistent way to eval() a string or feval() a cell array.
function doCommand(command, name)
if ischar(command)
printTimestamp('...doing %s command <%s>', name, command);
eval(command);
printTimestamp('...did %s command', name);
elseif iscell(command)
for cc = 1:numel(command)
doCommand(command{cc}, name);
end
end