Home > vbmeg > functions > gui > batch > vb_run_batch.m

vb_run_batch

PURPOSE ^

Run batch file created by Batch file builder GUI.

SYNOPSIS ^

function [log_file, Nfail] = vb_run_batch(batch_file, log_file)

DESCRIPTION ^

 Run batch file created by Batch file builder GUI.
 [USAGE]
    vb_run_batch(<batch_file>[,log_file]);
 [IN]
    batch_file : batch file created by Batch file builder GUI.
      log_file : log file(save commandline output)
                 if this field is empty, log_file will be 
                 created by tempname command.
 [OUT]
      log_file : log file name which was saved commandline output.
         Nfail : The number of jobs which failed to execute.

 Copyright (C) 2011, ATR All Rights Reserved.
 License : New BSD License(see VBMEG_LICENSE.txt)

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [log_file, Nfail] = vb_run_batch(batch_file, log_file)
0002 % Run batch file created by Batch file builder GUI.
0003 % [USAGE]
0004 %    vb_run_batch(<batch_file>[,log_file]);
0005 % [IN]
0006 %    batch_file : batch file created by Batch file builder GUI.
0007 %      log_file : log file(save commandline output)
0008 %                 if this field is empty, log_file will be
0009 %                 created by tempname command.
0010 % [OUT]
0011 %      log_file : log file name which was saved commandline output.
0012 %         Nfail : The number of jobs which failed to execute.
0013 %
0014 % Copyright (C) 2011, ATR All Rights Reserved.
0015 % License : New BSD License(see VBMEG_LICENSE.txt)
0016 
0017 %
0018 % --- Check
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 % --- Main Procedure
0042 %
0043 Nfail = 0;
0044 
0045                        
0046 diary(log_file);
0047 b = load(batch_file);
0048 
0049 % Basic settings
0050 proj_root = b.header.proj_root;
0051 
0052 % Execution result will be saved to project file.
0053 proj_file = b.header.proj_file;
0054 set_project_filename(proj_file);
0055 
0056 % not to stop batch processing
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 % Start Batch processing
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         % Get parameter
0086         parm      = parm_set.list{j,1};
0087         parm_type = parm_set.list{j,2};
0088 
0089         % Get job function
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         % Execute job
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 % end of loop for parameters
0111 end % end of loop for parm set
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);

Generated on Mon 22-May-2023 06:53:56 by m2html © 2005