xxsimSetSubmodelProperties

PURPOSE ^

xxsimSetSubmodelProperties - Set submodel properties of a submodel (name, description, version, etc.).

SYNOPSIS ^

function retval = xxsimSetSubmodelProperties(submodelPath, keys, values)

DESCRIPTION ^

 xxsimSetSubmodelProperties - Set submodel properties of a submodel (name, description, version, etc.).

 Syntax: 
   retval = xxsimSetSubmodelProperties('submodel_name', keys, values)

 Inputs:
   submodelPath  =  (optional) path to the submodel to obtain the properties of, using dots to separate hierarchy in the model.
                    Note: if no name is specified, the top-level main model is selected.
    keys          =  (required) the list of properties to set as cell array
    values        =  (required) the list of values to set as cell array
 The size of the keys and values arrays should match
 
 Outputs: 
   retval = returns 1 on success, 0 on failure.
 
 Examples:
   retval = xxsimSetSubmodelProperties('PID', {'description', 'author'}, {'My new description', 'John Doe'})
    retval = xxsimSetSubmodelProperties('PID', 'description', 'My new description')

 See also: xxsimGetSubmodelProperties

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

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function retval = xxsimSetSubmodelProperties(submodelPath, keys, values)
0002 % xxsimSetSubmodelProperties - Set submodel properties of a submodel (name, description, version, etc.).
0003 %
0004 % Syntax:
0005 %   retval = xxsimSetSubmodelProperties('submodel_name', keys, values)
0006 %
0007 % Inputs:
0008 %   submodelPath  =  (optional) path to the submodel to obtain the properties of, using dots to separate hierarchy in the model.
0009 %                    Note: if no name is specified, the top-level main model is selected.
0010 %    keys          =  (required) the list of properties to set as cell array
0011 %    values        =  (required) the list of values to set as cell array
0012 % The size of the keys and values arrays should match
0013 %
0014 % Outputs:
0015 %   retval = returns 1 on success, 0 on failure.
0016 %
0017 % Examples:
0018 %   retval = xxsimSetSubmodelProperties('PID', {'description', 'author'}, {'My new description', 'John Doe'})
0019 %    retval = xxsimSetSubmodelProperties('PID', 'description', 'My new description')
0020 %
0021 % See also: xxsimGetSubmodelProperties
0022 %
0023 % Author: Controllab Products B.V.
0024 % email: info@controllab.nl
0025 % Website: http://www.controllab.nl
0026 % May 2018
0027 
0028 %------------- BEGIN CODE --------------
0029     use_keys = {};
0030     use_values = {};
0031 
0032     % Check input arguments
0033     if ~ischar(keys)
0034         use_keys = keys;
0035     else
0036         use_keys = {keys};
0037     end
0038 
0039     if iscell(values)
0040         use_values = values;
0041     else
0042         use_values = {values};
0043     end
0044 
0045     % Check if the submodelPath is a string.
0046     if(~ischar(submodelPath))
0047         error('Please specify a valid submodel name.');
0048     end;
0049 
0050     % test if the given arguments have the same length
0051     if length(use_keys) ~= length(use_values)
0052         error('array size mismatch in given keys and values');
0053     end
0054 
0055     % create a an array of struct with name and values
0056     for i=1:length(use_keys)
0057         % Type checks
0058         if(~ischar(use_keys{i}))
0059             error('At least one of your keys is not of type string.');
0060         end;        
0061         if(~ischar(use_keys{i}))
0062             error('At least one of your values is not of type string.');
0063         end;        
0064 
0065         % For matlab compatibility create the first element without index.
0066         if i == 1
0067             key_val_array = struct('key', use_keys{i}, 'value', use_values{i});
0068         else
0069             key_val_array(i)= struct('key', use_keys{i}, 'value', use_values{i});
0070         end
0071     end
0072     
0073     retval = xrlinvoke('xxsim.model.setSubmodelProperties', struct('submodelName',submodelPath,'submodelProperties',{{key_val_array,'array'}}));
0074 end

Generated on Mon 08-Jul-2019 16:49:39