xxsimRun - runs the active 20-sim model with saved settings Syntax: [result, info, warning, errors] = xxsimRun(continueSimulation) result = xxsimRun(continueSimulation) Inputs: continueSimulation = (optional) boolean indicating whether an attempt should be made to continue the simulation or that a new run should be started. Default is false (= new simulation run). Outputs: result = returns true if the model runs without error info = returns a struct with information on the simulation run e.g total simulation time, number of model calculations, number of output points.. warnings = warning(s) during running model if any errors = error(s) during running model if any Examples: [result, info, warnings, errors] = xxsimRun(true); Note: true indicates that the simulation continues from the point that the simulation was stopped before. Use false to start a new run. See also: xxsimProcessModel, xxsimGetActiveModel Author: Controllab Products B.V. email: info@controllab.nl Website: http://www.controllab.nl September 2013
0001 function [result, info, warnings, errors] = xxsimRun(varargin) 0002 % xxsimRun - runs the active 20-sim model with saved settings 0003 % 0004 % Syntax: 0005 % [result, info, warning, errors] = xxsimRun(continueSimulation) 0006 % result = xxsimRun(continueSimulation) 0007 % 0008 % Inputs: 0009 % continueSimulation = (optional) boolean indicating whether an attempt should be made to continue the simulation 0010 % or that a new run should be started. Default is false (= new simulation run). 0011 % 0012 % Outputs: 0013 % result = returns true if the model runs without error 0014 % info = returns a struct with information on the simulation run 0015 % e.g total simulation time, number of model calculations, 0016 % number of output points.. 0017 % warnings = warning(s) during running model if any 0018 % errors = error(s) during running model if any 0019 % 0020 % Examples: [result, info, warnings, errors] = xxsimRun(true); 0021 % Note: true indicates that the simulation continues from the point that the simulation was stopped before. 0022 % Use false to start a new run. 0023 % 0024 % See also: xxsimProcessModel, xxsimGetActiveModel 0025 % 0026 % Author: Controllab Products B.V. 0027 % email: info@controllab.nl 0028 % Website: http://www.controllab.nl 0029 % September 2013 0030 0031 %------------- BEGIN CODE -------------- 0032 global xxsim; 0033 xxsimVerbose = 0; 0034 if exist('xxsim') 0035 xxsimVerbose = xxsim.verbose; 0036 end 0037 0038 continueSimulation = false; 0039 if length(varargin)> 1 0040 error('Too many input arguments.'); 0041 end 0042 if length(varargin)== 1 0043 if ~islogical(varargin{1}) 0044 error('argument should be boolean: continueSimulation'); 0045 end 0046 continueSimulation = varargin{1}; 0047 end 0048 0049 if( xxsimVerbose ) 0050 fprintf('Running model : '); 0051 end 0052 0053 runResult = xrlinvoke('xxsim.simulator.run', struct('continueSimulation', continueSimulation)); 0054 0055 %The step functions returns the time, result (events and/or outputs) 0056 %if an error occurs the xrlinvoke will return a fault message 0057 0058 if( isfield(runResult, 'errors') && length(runResult.errors) ~= 0 ) 0059 result = 0; 0060 else 0061 result = 1; 0062 end 0063 0064 % check if the simulation itself returned an error 0065 if result ~= 0 0066 if isfield(runResult, 'result') 0067 if runResult.result < 0 0068 result = 0; 0069 end 0070 else 0071 result = 0; 0072 end 0073 end 0074 0075 % return info in the info structure 0076 info = runResult.info; 0077 0078 %optionally return the outputs as the third variable 0079 if isfield(runResult, 'warnings') 0080 warnings = runResult.warnings; 0081 else 0082 warnings = []; 0083 end 0084 0085 if isfield(runResult, 'errors') 0086 errors = runResult.errors; 0087 else 0088 errors = []; 0089 end 0090 0091 if( xxsimVerbose ) 0092 if( result ) 0093 fprintf('Success\n'); 0094 else 0095 fprintf('Failure\n'); 0096 end 0097 0098 % print the errors and warnings 0099 for i = 1:length(runResult.errors) 0100 fprintf('\tError: %s\n',runResult.errors{i}); 0101 end 0102 for i = 1:length(runResult.warnings) 0103 fprintf('\tWarning: %s\n', runResult.warnings{i}); 0104 end 0105 for i=1:length(runResult.info) 0106 fprintf('\t%s : %s\n', runResult.info(i).key, runResult.info(i).value); 0107 end 0108 fprintf('\tSimulation: %d error(s), %d warning(s)\n', length(runResult.errors), length(runResult.warnings)); 0109 end 0110 end 0111 %------------- END CODE --------------