xxsimSingleStep

PURPOSE ^

xxsimSingleStep - Execute a single simulation step for the active 20-sim model.

SYNOPSIS ^

function [result, info, warnings, errors] = xxsimSingleStep()

DESCRIPTION ^

 xxsimSingleStep - Execute a single simulation step for the active 20-sim model.

 Syntax: 
   [result, info, warning, errors] = xxsimSingleStep()
   result = xxsimSingleStep()

 Inputs:
   takes no arguments.

 Outputs:
   result  =  -1 = an error occurred.
               0 = the run action succeeded, and additional steps can be taken.
               1 = the run action succeeeded, and the simulation is finished.
                   If the function failed, it returns a fault response.
   info    =  returns a struct with information on the simulation run 
                 e.g total simulation time, number of model calculations, 
                     number of output points. 
   warning =  warning(s) during running model, if any.
   errors  =  error(s) during running model, if any.

 Examples:
    [result, info, warnings, errors] = xxsimSingleStep()
        Simulates for one step, and returns the result,
        and all corresponding messages (info, warnings, errors).
    result = xxsimSingleStep()
        Simulates for one step, and returns the result.

 See also: xxsimProcessModel, xxsimGetActiveModel

 Author: Controllab Products B.V.
 email: info@controllab.nl
 Website: http://www.controllab.nl
 November 2015

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [result, info, warnings, errors] = xxsimSingleStep()
0002 % xxsimSingleStep - Execute a single simulation step for the active 20-sim model.
0003 %
0004 % Syntax:
0005 %   [result, info, warning, errors] = xxsimSingleStep()
0006 %   result = xxsimSingleStep()
0007 %
0008 % Inputs:
0009 %   takes no arguments.
0010 %
0011 % Outputs:
0012 %   result  =  -1 = an error occurred.
0013 %               0 = the run action succeeded, and additional steps can be taken.
0014 %               1 = the run action succeeeded, and the simulation is finished.
0015 %                   If the function failed, it returns a fault response.
0016 %   info    =  returns a struct with information on the simulation run
0017 %                 e.g total simulation time, number of model calculations,
0018 %                     number of output points.
0019 %   warning =  warning(s) during running model, if any.
0020 %   errors  =  error(s) during running model, if any.
0021 %
0022 % Examples:
0023 %    [result, info, warnings, errors] = xxsimSingleStep()
0024 %        Simulates for one step, and returns the result,
0025 %        and all corresponding messages (info, warnings, errors).
0026 %    result = xxsimSingleStep()
0027 %        Simulates for one step, and returns the result.
0028 %
0029 % See also: xxsimProcessModel, xxsimGetActiveModel
0030 %
0031 % Author: Controllab Products B.V.
0032 % email: info@controllab.nl
0033 % Website: http://www.controllab.nl
0034 % November 2015
0035 
0036 %------------- BEGIN CODE --------------
0037     
0038     if(nargin>0)
0039         error('Too many input arguments: xxsimSingleStep does not expect any input arguments.');
0040     end;
0041     
0042     global xxsim;
0043     xxsimVerbose = 0;
0044     if exist('xxsim')
0045         xxsimVerbose = xxsim.verbose;
0046     end
0047 
0048     if( xxsimVerbose )
0049         fprintf('Running model : ');
0050     end
0051 
0052     runResult = xrlinvoke('xxsim.simulator.singleStep');
0053     
0054     %The step functions returns the time, result (events and/or outputs)
0055     %if an error occurs the xrlinvoke will return a fault message
0056     
0057     if( isfield(runResult, 'errors') && length(runResult.errors) ~= 0 )
0058         result = -1;
0059     else
0060         result = 1;
0061     end
0062     
0063     % return the simulation result, whether additional steps can be taken or not
0064     if result ~= -1
0065         if isfield(runResult, 'result')
0066             result = runResult.result;
0067         else
0068             result = -1;
0069         end
0070     end
0071     
0072     % return info in the info structure
0073     info = runResult.info;
0074     
0075     %optionally return the outputs as the third variable
0076     if isfield(runResult, 'warnings')
0077         warnings = runResult.warnings;
0078     else
0079         warnings = [];
0080     end
0081     
0082     if isfield(runResult, 'errors')
0083         errors = runResult.errors;
0084     else
0085         errors = [];
0086     end
0087     
0088     if( xxsimVerbose )
0089         if( result )
0090             fprintf('Success\n');
0091         else
0092             fprintf('Failure\n');
0093         end
0094 
0095         % print the errors and warnings
0096         for i = 1:length(runResult.errors)
0097             fprintf('\tError: %s\n',runResult.errors{i});
0098         end
0099         for i = 1:length(runResult.warnings)
0100             fprintf('\tWarning: %s\n', runResult.warnings{i});
0101         end
0102         for i=1:length(runResult.info) 
0103             fprintf('\t%s : %s\n', runResult.info(i).key, runResult.info(i).value);
0104         end
0105         fprintf('\tSimulation: %d error(s), %d warning(s)\n', length(runResult.errors), length(runResult.warnings));
0106     end
0107 end
0108 %------------- END CODE --------------

Generated on Sun 10-Dec-2017 19:24:51