0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022 function RunBatch(timer,event,b)
0023
0024 if b.hide,
0025 status = Hide('status');
0026 Hide('on');
0027 warning('off','FMAToolbox:Hide:FigureHidden');
0028 end
0029
0030 progress = ['########## 0/' int2str(length(b.field)) ' = 0%% done [starting] ##########\n'];
0031 fprintf(1,progress);
0032 if b.log ~= -1,
0033 try
0034 fprintf(b.log,progress);
0035 catch
0036 fprintf(2,[' (Progress information could not be saved to log file)\n']);
0037 end
0038 end
0039
0040 tic;
0041 while true,
0042
0043 [b,item,line] = GetNextItem(b);
0044 if isempty(item), break; end
0045
0046 i = 1;
0047 clear('args');
0048 while true,
0049
0050 [b,field] = GetNextField(b);
0051 if isempty(field), break; end
0052 args{i} = field;
0053 i = i + 1;
0054 end
0055
0056 try
0057
0058 outputs = cell(1,nargout(b.mfile));
0059 [outputs{:}] = feval(b.mfile,args{:});
0060
0061 data = timer.UserData;
0062 if isempty(data),
0063 data = {outputs{:}};
0064 else
0065 data(end+1,:) = {outputs{:}};
0066 end
0067 timer.UserData = data;
0068 catch
0069
0070 fprintf(2,['Batch: error processing item ' int2str(item) ' on line ' int2str(line) '\n']);
0071 e = lasterror;
0072 fprintf(2,[' ' e.message '\n']);
0073 for j = 1:length(e.stack),
0074 fprintf(2,[' Error in ==> ' e.stack(j).name ' at ' int2str(e.stack(j).line) '\n']);
0075 if strcmp(e.stack(j).name,b.mfile), break; end
0076 end
0077
0078 if b.log ~= -1,
0079 try
0080 fprintf(b.log,['Batch: error processing item ' int2str(item) ' on line ' int2str(line) '\n']);
0081 fprintf(b.log,[' ' e.message '\n']);
0082 for j = 1:length(e.stack),
0083 fprintf(b.log,[' Error in ==> ' e.stack(j).name ' at ' int2str(e.stack(j).line) '\n']);
0084 if strcmp(e.stack(j).name,b.mfile), break; end
0085 end
0086 catch
0087 fprintf(2,[' (Error messages could not be saved to log file)\n']);
0088 end
0089 end
0090 end
0091
0092
0093 t = toc;
0094 proportion = item / length(b.field);
0095 left = t*(1/proportion-1);
0096 if left > 24*3600,
0097 left = strrep(datestr(datenum(0,0,0,0,0,left),'dd-HH:MM:SS'),'-','d ');
0098 else
0099 left = datestr(datenum(0,0,0,0,0,left),'HH:MM:SS');
0100 end
0101 progress = sprintf(['########## ' int2str(item) '/' int2str(length(b.field)) ' = %.2f%%%% done [' left ' left] ##########\n'],100*proportion);
0102 fprintf(1,progress);
0103 if b.log ~= -1,
0104 try
0105 fprintf(b.log,progress);
0106 catch
0107 fprintf(2,[' (Progress information could not be saved to log file)\n']);
0108 end
0109 end
0110 end
0111
0112
0113 t = toc;
0114 done = sprintf('Batch finished in %f s.\n',t);
0115 fprintf(1,done);
0116 if b.log ~= -1,
0117 try
0118 fprintf(b.log,done);
0119 catch
0120 fprintf(2,[' (Elapsed time could not be saved to log file)\n']);
0121 end
0122 end
0123
0124
0125 if b.hide,
0126 Hide(status);
0127 if strcmp(status,'off'), Hide('none'); end
0128 warning('on','FMAToolbox:Hide:FigureHidden');
0129 end
0130