xxsimSetActiveModel

PURPOSE ^

xxsimSetActiveModel - sets one of the opened 20-sim models as active.

SYNOPSIS ^

function [retval] = xxsimSetActiveModel(varargin)

DESCRIPTION ^

 xxsimSetActiveModel - sets one of the opened 20-sim models as active. 
 If no active model is chosen, the model opened last is set as active. 
 If only one model is opened, it is set as active model by default. 

 Syntax: 
     retval = xxsimSetActiveModel(varargin)

 Inputs:
   indentifier/modelName = can be either a unique identifier OR full name of a model.

 Outputs:
   retval = returns true if active model is set properly.

 Examples:
   xxsimSetActiveModel('C:\temp\PID.emx')
   xxsimSetActiveModel(3)
     Note: 3 is an identifier of a model. 
           To retrieve names and identifiers of all models, use xxsimGetModels.

 See also: xxsimGetActiveModel, xxsimGetModels

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

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [retval] = xxsimSetActiveModel(varargin)
0002 % xxsimSetActiveModel - sets one of the opened 20-sim models as active.
0003 % If no active model is chosen, the model opened last is set as active.
0004 % If only one model is opened, it is set as active model by default.
0005 %
0006 % Syntax:
0007 %     retval = xxsimSetActiveModel(varargin)
0008 %
0009 % Inputs:
0010 %   indentifier/modelName = can be either a unique identifier OR full name of a model.
0011 %
0012 % Outputs:
0013 %   retval = returns true if active model is set properly.
0014 %
0015 % Examples:
0016 %   xxsimSetActiveModel('C:\temp\PID.emx')
0017 %   xxsimSetActiveModel(3)
0018 %     Note: 3 is an identifier of a model.
0019 %           To retrieve names and identifiers of all models, use xxsimGetModels.
0020 %
0021 % See also: xxsimGetActiveModel, xxsimGetModels
0022 %
0023 % Author: Controllab Products B.V.
0024 % email: info@controllab.nl
0025 % Website: http://www.controllab.nl
0026 % September 2013
0027 
0028 %------------- BEGIN CODE --------------
0029     %check input arguments
0030     if length(varargin)> 1
0031         error('Too many input arguments.');
0032     end
0033     
0034     %check if the input is an identifier
0035     if isscalar(varargin{1})
0036         identifier = varargin{1};
0037     end
0038     
0039     %check if input is a model name
0040     if ischar(varargin{1})
0041         name = {varargin{1}};
0042         %search through all models and get the identifier of the model
0043         names = xxsimGetModels();
0044         for i = 1: length(names)
0045             if strcmp(names(i).name, name) 
0046                 identifier = names(i).identifier;
0047             end   
0048         end
0049     end
0050   
0051 
0052     % call the interface function
0053     reply = xrlinvoke('xxsim.setActiveModel', struct('identifier', int32(identifier) ));
0054     
0055     if (length(reply) == 0 )
0056         retval = false;
0057         error('could not load the model')
0058     end
0059     
0060     retval = true;
0061 end
0062 %------------- END OF CODE --------------

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