


xxsimSetSettings - Change the value of one or more 20-sim tool or model settings.
Syntax:
result = xxsimSetSettings(keys, values)
Inputs:
keys = a list of keys to apply.
values = a list of accompanying values to apply.
-or-
key_value = a list of key-value structs.
Outputs:
result = returns true if the setting has been set successfully, false otherwise.
Examples:
result = xxsimSetSettings('model.simulator.integrationmethod', 'Euler');
result = xxsimSetSettings({'model.simulator.integrationmethod'}, {'Euler'});
result = xxsimSetSettings({'model.simulator.integrationmethod', 'model.simulator.integrationmethod.Euler.stepsize'}, {'Euler', '0.01'});
result = xxsimSetSettings([struct('key', 'model.simulator.starttime', 'value', '0.0'), struct('key', 'model.simulator.finishtime', 'value', '20.0')]);
See also: xxsimQuerySettings
Author: Controllab Products B.V.
email: info@controllab.nl
Website: http://www.controllab.nl
October 2014

0001 function result = xxsimSetSettings(varargin) 0002 % xxsimSetSettings - Change the value of one or more 20-sim tool or model settings. 0003 % 0004 % Syntax: 0005 % result = xxsimSetSettings(keys, values) 0006 % 0007 % Inputs: 0008 % keys = a list of keys to apply. 0009 % values = a list of accompanying values to apply. 0010 % -or- 0011 % key_value = a list of key-value structs. 0012 % 0013 % Outputs: 0014 % result = returns true if the setting has been set successfully, false otherwise. 0015 % 0016 % Examples: 0017 % result = xxsimSetSettings('model.simulator.integrationmethod', 'Euler'); 0018 % result = xxsimSetSettings({'model.simulator.integrationmethod'}, {'Euler'}); 0019 % result = xxsimSetSettings({'model.simulator.integrationmethod', 'model.simulator.integrationmethod.Euler.stepsize'}, {'Euler', '0.01'}); 0020 % result = xxsimSetSettings([struct('key', 'model.simulator.starttime', 'value', '0.0'), struct('key', 'model.simulator.finishtime', 'value', '20.0')]); 0021 % 0022 % See also: xxsimQuerySettings 0023 % 0024 % Author: Controllab Products B.V. 0025 % email: info@controllab.nl 0026 % Website: http://www.controllab.nl 0027 % October 2014 0028 0029 %------------- BEGIN CODE -------------- 0030 global xxsim; 0031 xxsimVerbose = 0; 0032 if ~isempty(xxsim) 0033 xxsimVerbose = xxsim.verbose; 0034 end 0035 0036 result = false; 0037 0038 % fetch the input arguments 0039 if (nargin == 1) 0040 % array with key,value pairs 0041 key_value_array = varargin{1}; 0042 if isvector(key_value_array) 0043 % check if the first element is indeed a key-value struct 0044 elem_check = key_value_array(1); 0045 if ~isstruct(elem_check) 0046 error('Input argument mismatch. Expected an array of key,value structs'); 0047 else 0048 % ok, we have a struct, now check if this is a key,value struct 0049 if ~isfield(elem_check, 'key') 0050 error('Input argument mismatch. Struct does not contain a key field.'); 0051 end 0052 if ~isfield(elem_check, 'value') 0053 error('Input argument mismatch. Struct does not contain a value field.'); 0054 end 0055 end 0056 elseif (isstruct(key_value_array)) 0057 % ok, we have a struct, now check if this is a key,value struct 0058 if ~isfield(key_value_array, 'key') 0059 error('Input argument mismatch. Struct does not contain a key field.'); 0060 end 0061 if ~isfield(key_value_array, 'value') 0062 error('Input argument mismatch. Struct does not contain a value field.'); 0063 end 0064 else 0065 error('Input argument mismatch. Expected an array of key,value structs'); 0066 end 0067 settings = key_value_array; 0068 elseif (nargin == 2) 0069 % check input arguments 0070 keys = varargin{1}; 0071 values = varargin{2}; 0072 0073 if ~ischar(keys) 0074 use_keys = keys; 0075 else 0076 use_keys = {keys}; 0077 end 0078 0079 if length(use_keys) == 0 0080 error('no keys are given'); 0081 end 0082 0083 if iscell(values) 0084 use_values = values; 0085 else 0086 use_values = {values}; 0087 end 0088 0089 % test if the given arguments have the same length 0090 if length(use_keys) ~= length(use_values) 0091 error('array size mismatch in given keys and values'); 0092 end 0093 0094 % create a an array 'settings' of struct with name and values 0095 for i=1:length(use_keys) 0096 %For matlab compatibility create the first element without index. 0097 if i == 1 0098 settings = struct('key', use_keys{i}, 'value', use_values{i}); 0099 else 0100 settings(i)= struct('key', use_keys{i}, 'value', use_values{i}); 0101 end 0102 end 0103 else 0104 error('Wrong number of arguments. Function expects 1 or 2 arguments.'); 0105 end 0106 0107 if xxsimVerbose 0108 %print the settings 0109 settings 0110 end 0111 0112 % do the actual invoke 0113 result = xrlinvoke('xxsim.setSettings', struct('settings', {{ settings, 'array' }})); 0114 end 0115 %------------- END CODE --------------