comparison m-toolbox/classes/@ssm/modelHelper_declareParameters.m @ 0:f0afece42f48

Import.
author Daniele Nicolodi <nicolodi@science.unitn.it>
date Wed, 23 Nov 2011 19:22:13 +0100
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:f0afece42f48
1 % modelHelper_declareParameters builds parameters plists for the ssm params field.
2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3 %
4 % DESCRIPTION: modelHelper_declareParameters
5 % - builds parameters plists for the ssm params field.
6 % - declares them in the caller workspace
7 %
8 % CALL: params = modelHelper_declareParameters(pl, paramNames, paramValues, paramDescriptions, paramUnits)
9 %
10 % INPUTS:
11 % 'paramNames' - cellstr containing the parameters names
12 % 'paramValues' - double array of same size
13 % 'paramDescriptions' - cellstr of same size
14 % 'paramUnits' - unit array of same size
15 % 'pl' - input plist to the model
16 %
17 % OUTPUTS:
18 %
19 % 'params' - params plist of the symbolic ssm parameters.
20 %
21 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
22
23 function [params, numParams] = modelHelper_declareParameters(pl, paramNames, paramValues, paramDescriptions, paramUnits)
24 %% using input plist to process parameters
25
26 setNames = find(pl, 'param names');
27 setValues = find(pl, 'param values');
28 withParams = find(pl, 'symbolic params');
29
30 if ~isempty(find(pl, 'withparams'))
31 error('The WITHPARAMS key has been changed to SYMBOLIC PARAMS. Please check your plist');
32 end
33 if ~isempty(find(pl, 'setnames'))
34 error('The SETNAMES key has been changed to PARAM NAMES. Please check your plist');
35 end
36 if ~isempty(find(pl, 'setvalues'))
37 error('The SETVALUES key has been changed to PARAM VALUES. Please check your plist');
38 end
39
40 if ~(numel(setValues)==numel(setNames))
41 error('The number of values is not the same as the number of parameters to set')
42 end
43
44 %% interface simplification for the user
45 if ischar(setNames)
46 if ~( strcmpi(setNames, 'all') || strcmpi(setNames, '') || strcmpi(setNames, 'none') ) % if this is not a special user call
47 setNames = {setNames};
48 elseif strcmpi(setNames, '') || strcmpi(setNames, 'none') % if the user does not want any parameter
49 setNames = cell(1,0);
50 end
51 end
52 if ischar(withParams)
53 if ~( strcmpi(withParams, 'all') || strcmpi(withParams, '') || strcmpi(withParams, 'none') ) % if this is not a special user call
54 withParams = {withParams};
55 elseif strcmpi(withParams, '') || strcmpi(withParams, 'none') % if the user does not want any parameter
56 withParams = cell(1,0);
57 end
58 end
59
60 %% setting parameters if desired
61 for i= 1:numel(setNames)
62 setParamPosition = strcmpi(setNames{i}, paramNames);
63 paramValues(setParamPosition) = setValues(i);
64 end
65
66 %% finding symbolic parameters
67 if strcmpi(withParams, 'ALL')
68 paramPos = true(size(paramNames));
69 else
70 paramPos = logical(ismember(paramNames, withParams));
71 end
72 % declaring the parameters used
73 for i_params=1:numel(paramNames)
74 if paramPos(i_params)
75 assignin('caller', paramNames{i_params}, sym(paramNames{i_params}) );
76 else
77 assignin('caller',paramNames{i_params},paramValues(i_params));
78 end
79 end
80
81 %% deleting fields relevant to unused numerical parameters and building plist
82 numParamNames = paramNames(~paramPos);
83 numParamValues = paramValues(~paramPos);
84 paramNames = paramNames(paramPos);
85 paramValues = paramValues(paramPos);
86 if ~ isempty(paramDescriptions)
87 numParamDescriptions = paramDescriptions(~paramPos);
88 paramDescriptions = paramDescriptions(paramPos);
89 else
90 numParamDescriptions = [];
91 end
92 if ~ isempty(paramUnits)
93 numParamUnits = paramUnits(~paramPos);
94 paramUnits = paramUnits(paramPos);
95 else
96 numParamUnits = [];
97 end
98
99 params = ssm.buildParamPlist(paramNames, paramValues, paramDescriptions, paramUnits, plist);
100 numParams = ssm.buildParamPlist(numParamNames, numParamValues, numParamDescriptions, numParamUnits, plist);
101
102 params.setName('params');
103 numParams.setName('numparams');
104 end