0001 function [log_file, Nfail] = vb_run_batch(batch_file, log_file)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020 if ~exist('batch_file', 'var') || exist(batch_file, 'file') ~= 2
0021 error('Invalid batch_file');
0022 end
0023 if ~exist('log_file', 'var')
0024 log_file = tempname;
0025 end
0026
0027 diary off;
0028 if exist(log_file, 'file') == 2
0029 res = questdlg('Specified logfile already exist. What to do?', ...
0030 'Confirm', 'Overwrite', 'Add', 'Cancel', ...
0031 'Overwrite');
0032 if strcmpi(res, 'overwrite')
0033 delete(log_file);
0034 elseif strcmpi(res, 'cancel')
0035 disp('Batch processing was cancelled.');
0036 return;
0037 end
0038 end
0039
0040
0041
0042
0043 Nfail = 0;
0044
0045
0046 diary(log_file);
0047 b = load(batch_file);
0048
0049
0050 proj_root = b.header.proj_root;
0051
0052
0053 proj_file = b.header.proj_file;
0054 set_project_filename(proj_file);
0055
0056
0057 [verbose_level,verbose_str] = vb_get_verbose;
0058
0059 vb_set_verbose('WARNING');
0060
0061 seconds = 3;
0062 fprintf('batch processing will start in %d seconds.\n', seconds);
0063 for k=1:seconds
0064 fprintf('%d ', seconds - k+1);
0065 pause(1);
0066 end
0067 fprintf('\n');
0068
0069
0070
0071
0072 fprintf('=============================================================\n');
0073 fprintf('[VBMEG] : Start batch processing (%s)\n', datestr(now));
0074 fprintf('=============================================================\n');
0075
0076 Nparm_set = size(b.parm_set,1);
0077
0078 for k=1:Nparm_set
0079 parm_set = b.parm_set{k};
0080 Nparm = size(parm_set.list, 1);
0081
0082 fprintf('Parameter set for %s\n', parm_set.set_name);
0083 for j=1:Nparm
0084 try
0085
0086 parm = parm_set.list{j,1};
0087 parm_type = parm_set.list{j,2};
0088
0089
0090 [job_func] = vb_judge_function_name(parm, parm_type);
0091
0092 if strcmpi(job_func, 'unknown')
0093 disp('%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%');
0094 fprintf('!!!!! Unknown parameter(type: %s) for %s - %d\n', ...
0095 parm_type, parm_set.set_name, j);
0096 disp('%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%');
0097 error('Unknown parameter.');
0098 end
0099
0100
0101 disp('%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%');
0102 fprintf('* %s(proj_root, parm) for %s - %d\n', job_func, parm_set.set_name, j);
0103 disp('%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%');
0104 feval(job_func, proj_root, parm);
0105 catch
0106 err = lasterror;
0107 disp(err.message);
0108 Nfail = Nfail + 1;
0109 end
0110 end
0111 end
0112
0113 fprintf('=============================================================\n');
0114 fprintf('[VBMEG] : Finished processing (%s)\n', datestr(now));
0115 fprintf('=============================================================\n');
0116 fprintf('The number of errors = %d\n', Nfail);
0117 diary off;
0118
0119 vb_set_verbose(verbose_str);