function qsub_run_cm(jobfilename, outfilename, flagfilename)
% QSUB_RUN_CM entry point for running a job on a cluster node
% In native MATLAB, it needs to be on MATLABs path on the worker
% machine. This is guaranteed by the MATLAB call in QSUB_SUBMIT_CM.
% In compiled MATLAB, this function must be the entry function of the
% compiled program.
%
% Input arguments:
% This function will be called from a run script created by QSUB_SUBMIT_CM.
% This run script must supply the three file names
% jobfilename - file name of existing .mat file containing the job input
% outfilename - file name of .mat file to write the output
% flagfilename - file to create after successful completion of the job
%
% See also QSUB_SUBMIT_CM, QSUB_CHECK_FINISH
%
% This code has been developed as part of a batch job configuration
% system for MATLAB. See
% http://sourceforge.net/projects/matlabbatch
% for details about the original project.
%_______________________________________________________________________
% Copyright (C) 2007 Freiburg Brain Imaging
% Volkmar Glauche
% $Id: qsub_run_cm.m 409 2009-06-22 09:50:28Z glauche $
rev = '$Rev: 409 $'; %#ok
try
% set up job context
out = struct('out',{{}}, 'err',MException.empty);
load(jobfilename,'-mat','ctx');
if ~isdeployed
path(ctx.path);
end
% load job input data
job = load(jobfilename,'-mat');
if job.noutputs == 0,
% evaluate job function - no output
job.fun(job.job{:});
else
% evaluate job function - capture output
out.out = cell(1,job.noutputs);
[out.out{:}] = deal(job.fun(job.job{:}));
end
% save output
save(outfilename, '-struct', 'out');
catch le,
% display exception on the remote node - this will be recorded in the
% job stdout file
out.err = le;
disp(le);
try
% try to save the original exception
save(outfilename, '-struct', 'out');
catch le1,
disp(le1);
end,
% exit with error
exit(100);
end
try
% success - touch flag file
unix(sprintf('touch %s', flagfilename));
catch le,
% flag file creation failed - exit wit error
disp(le);
exit(100);
end
exit(0);