xxsimGetVariables

PURPOSE ^

xxsimGetVariables - get specified variables.

SYNOPSIS ^

function retval = xxsimGetVariables(varargin)

DESCRIPTION ^

 xxsimGetVariables - get specified variables. 

 Syntax: 
   retval = xxsimGetVariables('variable_name')
   retval = xxsimGetVariables({'variable1_name', 'variable2_name'})
   retval = xxsimGetVariables({'submodel_names'},{'variable_kinds'})

 Inputs:
   variable_name   =  name of a variable with hierarchy e.g 'PID.Kp'.
   submodel_names  =  (optional) name(s) or submodel(s) in which the variables are found.
                      Note: if no name is specified ({}) all variables are retrieved.
   variable_kinds  =  (optional) kind of the variable requested
                      e.g 'parameter','variable','state','rate', 'initialValue',
                          'dependentRate','algebraic','algebraicin','algebraicout',
                          'constraint','constraintin','constraintout'.
                      Note: if kind is NOT specified all kinds are retrieved.

 Outputs: 
   retval = returns a structure array with the requested variables.
 
 Examples:
   retval = xxsimGetVariables({'PID','Amplifier'}, {'parameter','state'})
   
     - retval now contains the list of parameters and state variables
       found in the submodels PID and Amplifier. 
     - the output is returned in a structure array form. 
       e.g
         retval.name   : returns the name(s) of retrieved variable(s).
         retval.size   : returns the size of the variable(s).
         retval.values : returns the value(s).
         retval.properties : returns the properties of the variable(s). 

 See also: xxsimSetParameters, xxsimSetVariables, xxsimGetParameters

 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 = xxsimGetVariables(varargin)
0002 % xxsimGetVariables - get specified variables.
0003 %
0004 % Syntax:
0005 %   retval = xxsimGetVariables('variable_name')
0006 %   retval = xxsimGetVariables({'variable1_name', 'variable2_name'})
0007 %   retval = xxsimGetVariables({'submodel_names'},{'variable_kinds'})
0008 %
0009 % Inputs:
0010 %   variable_name   =  name of a variable with hierarchy e.g 'PID.Kp'.
0011 %   submodel_names  =  (optional) name(s) or submodel(s) in which the variables are found.
0012 %                      Note: if no name is specified ({}) all variables are retrieved.
0013 %   variable_kinds  =  (optional) kind of the variable requested
0014 %                      e.g 'parameter','variable','state','rate', 'initialValue',
0015 %                          'dependentRate','algebraic','algebraicin','algebraicout',
0016 %                          'constraint','constraintin','constraintout'.
0017 %                      Note: if kind is NOT specified all kinds are retrieved.
0018 %
0019 % Outputs:
0020 %   retval = returns a structure array with the requested variables.
0021 %
0022 % Examples:
0023 %   retval = xxsimGetVariables({'PID','Amplifier'}, {'parameter','state'})
0024 %
0025 %     - retval now contains the list of parameters and state variables
0026 %       found in the submodels PID and Amplifier.
0027 %     - the output is returned in a structure array form.
0028 %       e.g
0029 %         retval.name   : returns the name(s) of retrieved variable(s).
0030 %         retval.size   : returns the size of the variable(s).
0031 %         retval.values : returns the value(s).
0032 %         retval.properties : returns the properties of the variable(s).
0033 %
0034 % See also: xxsimSetParameters, xxsimSetVariables, xxsimGetParameters
0035 %
0036 % Author: Controllab Products B.V.
0037 % email: info@controllab.nl
0038 % Website: http://www.controllab.nl
0039 % September 2013
0040 
0041 %------------- BEGIN CODE --------------
0042 
0043     names = {};
0044     kinds = {};
0045 
0046     %check input arguments
0047     if length(varargin)> 2
0048         error('Too many input arguments.');
0049     end
0050 
0051     if length(varargin)>= 1
0052         if ~ischar(varargin{1})
0053             names = varargin{1};
0054         else
0055             names = {varargin{1}};
0056         end
0057     end
0058 
0059     if length(varargin) == 2
0060         if ~ischar(varargin{2})
0061             kinds = varargin{2};
0062         else
0063             kinds = {varargin{2}};
0064         end
0065     else
0066         kinds = [];
0067     end
0068 
0069 
0070     if length(kinds) == 0
0071         filterArray = [];
0072     end
0073 
0074     for i=1:length(kinds)
0075         filterArray(i) = struct('key', 'kind', 'value', kinds(i));
0076     end
0077 
0078     % and make the actual call to 20-sim
0079     reply = xrlinvoke('xxsim.model.getVariables', struct('variables', {{ names, 'array' }}, 'filters', {{ filterArray, 'array' }} ) );
0080     
0081     retval = reply;
0082     
0083     % matrices are returned as an arry from xrlinvoke
0084     % change the array back to matrix of correct size
0085     
0086     % loop through variables
0087     for i=1:size(reply)
0088         % check if the variable is a matrix
0089         if ~isscalar(reply(i).size) 
0090             retval(i).values = transpose(reshape(reply(i).values, reply(i).size(2),reply(i).size(1)));
0091         end
0092     end
0093 end
0094 %------------- END OF CODE --------------

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