| Description of edl_go |
edl_go
PURPOSE 
EDL_GO The Top interface for doing experiments in EDL
SYNOPSIS 
function edl_go(expdef, type, name, filter, runopt)
DESCRIPTION 
CROSS-REFERENCE INFORMATION 
This function calls:
- edl_batchexp EDL_BATCHEXP Performs Batch experiments according to scheme
- edl_logerror EDL_LOGERROR Logs an error into logger
- edl_readexpdefs EDL_READEXPDEFS Reads in an experiment definition from XML file
- edl_readreport EDL_READREPORT Reads in a EDL report
- edl_readscript EDL_READSCRIPT Reads in a EDL script
- edl_writereport EDL_WRITEREPORT Writes an EDL report
- edl_writescript EDL_WRITESCRIPT Writes an EDL script
- close CLOSE Closes the logger
- incindent INCINDENT Increases the indent by a specified amount
- write WRITE Writes message to a logger
- writeblank WRITEBLANK Writes a blank line to log
- writeinfo WRITEINFO Writes information to logger without time-stamp
- slfilepart SLFILEPARTS Extracts a specified part of a file path string
- raise_lackinput RAISE_LACKINPUT Raises an error indicating lack of input argument
- sladdpath SLADDPATH Adds dirpath to precede the filenames
- slguid SLGUID Generates a GUID (Global Unique Identifier)
- slguidstr SLGUIDSTR Converts a guid to a string
This function is called by:
SUBFUNCTIONS 
- function main_proc_go(expdef, type, name, filter, logger, runopt)
- function log_scriptinfo(s, logger)
- function log_reportinfo(s, logger)
- function log_expinfo(s, logger)
- function log_reftable(s, logger)
- function funcname = prepare_runfunc(funcpath, rootdir)
- function R = take_element(expdef, scope, name)
- function gidstr = init_instance(S, startmsg, logger, genguid, funcloginfo)
- function refs = load_references(name, elem, rootdir)
- function log_params(params, logger)
SOURCE CODE 
0001 function edl_go(expdef, type, name, filter, runopt)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037 if nargin < 3
0038 raise_lackinput('edl_go', 3);
0039 end
0040
0041 need_close_logger = false;
0042 if ischar(expdef)
0043 expdef = edl_readexpdefs(expdef);
0044 need_close_logger = true;
0045 end
0046 if ~isstruct(expdef)
0047 error('sltoolbox:invalidarg', ...
0048 'Experiment definition should either be a filename or the loaded struct');
0049 end
0050
0051 if nargin < 4
0052 filter = [];
0053 end
0054
0055 if nargin < 5
0056 runopt = [];
0057 end
0058
0059 current_folder = cd();
0060
0061
0062
0063 logger = expdef.logger;
0064
0065 try
0066 main_proc_go(expdef, type, name, filter, logger, runopt);
0067 catch
0068 err = lasterror();
0069 edl_logerror('edl_go', err, logger);
0070 lasterror('reset');
0071 end
0072
0073 if need_close_logger
0074 close(logger);
0075 end
0076
0077 cd(current_folder);
0078
0079
0080
0081
0082 function main_proc_go(expdef, type, name, filter, logger, runopt)
0083
0084 rootdir = slfilepart(expdef.selfpath, 'parent');
0085
0086 write(logger, 'on Experiment Definition: %s', expdef.name);
0087 writeblank(logger);
0088
0089 switch type
0090 case 'script'
0091 scope = 'scripts';
0092 curscript = take_element(expdef, scope, name);
0093
0094
0095
0096 gidstr = init_instance(curscript, ...
0097 sprintf('Starting scripting %s', name), ...
0098 logger, true, 'log_scriptinfo');
0099
0100
0101 funcname = prepare_runfunc(curscript.func, rootdir);
0102
0103 scriptpath = sladdpath(curscript.path, rootdir);
0104 ctrlpath = curscript.ctrlpath;
0105 refs = load_references(name, curscript, rootdir);
0106 workdir = curscript.params.workdir;
0107
0108 props = feval(funcname, refs, curscript.params);
0109 edl_writescript(scriptpath, gidstr, workdir, ctrlpath, props);
0110
0111 write(logger, 'Finishing scripting');
0112 writeblank(logger);
0113
0114
0115 case 'experiment'
0116
0117 scope = 'experiments';
0118 curexp = take_element(expdef, scope, name);
0119
0120
0121
0122 init_instance(curexp, ...
0123 sprintf('Starting experiment %s', name), ...
0124 logger, false, 'log_expinfo');
0125
0126
0127
0128 funcname = prepare_runfunc(curexp.func, rootdir);
0129 scriptpath = sladdpath(curexp.scriptpath, rootdir);
0130
0131 edl_batchexp(funcname, scriptpath, expdef.env, logger, filter, runopt);
0132
0133 write(logger, 'Finishing experiment');
0134 writeblank(logger);
0135
0136 case 'report'
0137
0138 scope = 'reports';
0139 curreport = take_element(expdef, scope, name);
0140
0141
0142
0143 gidstr = init_instance(curreport, ...
0144 sprintf('Starting reporting %s', name), ...
0145 logger, true, 'log_reportinfo');
0146
0147
0148 funcname = prepare_runfunc(curreport.func, rootdir);
0149 refs = load_references(name, curreport, rootdir);
0150 reportpath = sladdpath(curreport.path, rootdir);
0151
0152 props = feval(funcname, refs, curreport.params, expdef.env);
0153 edl_writereport(reportpath, gidstr, props);
0154
0155 write(logger, 'Finishing reporting');
0156 writeblank(logger);
0157
0158 otherwise
0159 error('Invalid action type for EDL: %s', type);
0160 end
0161
0162
0163
0164
0165
0166 function log_scriptinfo(s, logger)
0167
0168 writeinfo(logger, 'function = %s', s.func);
0169 writeinfo(logger, 'script path = %s', s.path);
0170 writeinfo(logger, 'control path = %s', s.ctrlpath);
0171 log_reftable(s, logger);
0172 log_params(s.params, logger);
0173
0174 function log_reportinfo(s, logger)
0175
0176 writeinfo(logger, 'function = %s', s.func);
0177 writeinfo(logger, 'script path = %s', s.path);
0178 log_reftable(s, logger);
0179 log_params(s.params, logger);
0180
0181 function log_expinfo(s, logger)
0182
0183 writeinfo(logger, 'function = %s', s.func);
0184 writeinfo(logger, 'script path = %s', s.scriptpath);
0185
0186
0187 function log_reftable(s, logger)
0188
0189 rps = s.refpaths;
0190
0191 if ~isempty(rps)
0192 writeinfo(logger, 'references:');
0193 logger = incindent(logger, 1);
0194
0195 roles = fieldnames(rps);
0196 n = length(roles);
0197 for i = 1 : n
0198 role = roles{i};
0199 writeinfo(logger, '%s = %s', role, rps.(role));
0200 end
0201 end
0202
0203
0204
0205
0206 function funcname = prepare_runfunc(funcpath, rootdir)
0207
0208 funcdir = sladdpath(slfilepart(funcpath, 'parent'), rootdir);
0209 funcname = slfilepart(funcpath, 'title');
0210 cd(funcdir);
0211
0212 function R = take_element(expdef, scope, name)
0213
0214 sset = expdef.(scope);
0215 if ~isfield(sset, name)
0216 error('edl:interperror', ...
0217 'The specified name %s is not found in %s of the experiment definition', ...
0218 name, scope);
0219 end
0220 R = sset.(name);
0221
0222 function gidstr = init_instance(S, startmsg, logger, genguid, funcloginfo)
0223
0224 if genguid
0225 gidstr = slguidstr(slguid);
0226 writeinfo(logger, '[%s]', gidstr);
0227 else
0228 gidstr = '';
0229 end
0230
0231 if ~isempty(startmsg)
0232 write(logger, startmsg);
0233 else
0234 write(logger, 'Start Instance');
0235 end
0236
0237 logger = incindent(logger, 1);
0238
0239 if ~isempty(funcloginfo)
0240 feval(funcloginfo, S, logger);
0241 end
0242
0243 writeblank(logger);
0244
0245
0246 function refs = load_references(name, elem, rootdir)
0247
0248 if isempty(elem.refpaths)
0249 refs = [];
0250 else
0251 fns = fieldnames(elem.refpaths);
0252 n = length(fns);
0253 for i = 1 : n
0254 fn = fns{i};
0255
0256 curscope = elem.refscopes.(fn);
0257 curpath = sladdpath(elem.refpaths.(fn), rootdir);
0258
0259 switch curscope
0260 case 'scripts'
0261 curref = edl_readscript(curpath);
0262 case 'reports'
0263 curref = edl_readreport(curpath);
0264 otherwise
0265 error('edl:interperror', ...
0266 'Invalid scope name %s for item %s in %s', ...
0267 curscope, fn, name);
0268 end
0269
0270 refs.(fn) = curref;
0271 end
0272
0273 end
0274
0275 function log_params(params, logger)
0276
0277 if ~isempty(params)
0278 fns = fieldnames(params);
0279 n = length(fns);
0280 writeinfo(logger, 'parameters: ');
0281 logger = incindent(logger, 1);
0282
0283 for i = 1 : n
0284 fn = fns{i};
0285 writeinfo(logger, '%s = %s', fn, params.(fn));
0286 end
0287
0288 end
0289
0290
0291
0292
0293
Generated on Wed 20-Sep-2006 12:43:11 by m2html © 2003
|
|