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     % Check input arguments
0030     if ~ischar(keys)
0031         use_keys = keys;
0032     else
0033         use_keys = {keys};
0034     end
0035 
0036     if iscell(values)
0037         use_values = values;
0038     else
0039         use_values = {values};
0040     end
0041 
0042     % Check if the submodelPath is a string.
0043     if(~ischar(submodelPath))
0044         error('Please specify a valid submodel name.');
0045     end
0046 
0047     % test if the given arguments have the same length
0048     if length(use_keys) ~= length(use_values)
0049         error('array size mismatch in given keys and values');
0050     end
0051 
0052     % create a an array of struct with name and values
0053     for i=1:length(use_keys)
0054         % Type checks
0055         if(~ischar(use_keys{i}))
0056             error('At least one of your keys is not of type string.');
0057         end        
0058         if(~ischar(use_keys{i}))
0059             error('At least one of your values is not of type string.');
0060         end        
0061 
0062         % For matlab compatibility create the first element without index.
0063         if i == 1
0064             key_val_array = struct('key', use_keys{i}, 'value', use_values{i});
0065         else
0066             key_val_array(i)= struct('key', use_keys{i}, 'value', use_values{i});
0067         end
0068     end
0069     
0070     retval = xrlinvoke('xxsim.model.setSubmodelProperties', struct('submodelName',submodelPath,'submodelProperties',{{key_val_array,'array'}}));
0071 end

Generated on Thu 25-Apr-2024 10:30:24