comparison m-toolbox/classes/@pest/find.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 % FIND Creates analysis objects from the selected parameter(s).
2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3 %
4 % DESCRIPTION: FIND Creates analysis objects from the selected
5 % parameter(s).
6 %
7 % CALL: obj = obj.find();
8 % obj = obj.find('a');
9 % obj = obj.find('a', 'b');
10 % obj = obj.find(plist('params', {'a', 'b'}))
11 %
12 % INPUTS: obj - one pest model.
13 % pl - parameter list
14 %
15 % <a href="matlab:utils.helper.displayMethodInfo('pest', 'find')">Parameters Description</a>
16 %
17 % VERSION: $Id: find.m,v 1.7 2011/04/08 08:56:25 hewitson Exp $
18 %
19 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
20
21 function varargout = find(varargin)
22
23 % Check if this is a call for parameters
24 if utils.helper.isinfocall(varargin{:})
25 varargout{1} = getInfo(varargin{3});
26 return
27 end
28
29 %%% Collect input variable names
30 in_names = cell(size(varargin));
31 for ii = 1:nargin,in_names{ii} = inputname(ii);end
32
33 [objs, obj_invars, rest] = utils.helper.collect_objects(varargin(:), 'pest', in_names);
34 [pls, invars, rest] = utils.helper.collect_objects(rest(:), 'plist');
35
36 inParams = {};
37 out = [];
38 %%% If pls contains only one plist with the key 'params' then set the
39 %%% property with a plist.
40 if length(pls) == 1 && isa(pls, 'plist') && pls.nparams == 1 && pls.isparam('params')
41 inParams = cellstr(find(pls, 'params'));
42 end
43
44 if ~iscellstr(rest)
45 error('### Can not handle the input: %s', utils.helper.val2str(rest));
46 end
47
48 inParams = [inParams rest];
49
50 for objLoop = 1:numel(objs)
51
52 %%% decide whether we modify the input pest object, or create a new one.
53 objs(objLoop) = copy(objs(objLoop), nargout);
54
55 %%% Create from each parameter an AO if the user doesn't specify a
56 %%% parameter name.
57 if isempty(inParams)
58 params = objs(objLoop).names;
59 else
60 params = inParams;
61 end
62
63 for ll=1:numel(params)
64 pname = params{ll};
65 % get index of this param
66 idx = find(strcmp(objs(objLoop).names, pname), 1);
67 if isempty(idx)
68 % Do nothing because it is not possible to create an AO from a not
69 % existing parameter name.
70 else
71 a = ao(objs(objLoop).y(idx));
72 a.setName(pname);
73 if ~isempty(objs(objLoop).dy)
74 a.setDy(objs(objLoop).dy(idx));
75 end
76 if ~isempty(objs(objLoop).yunits)
77 a.setYunits(objs(objLoop).yunits(idx));
78 end
79 if numel(objs(objLoop).models) > 1
80 a.setProcinfo(plist('model', objs(objLoop).models(idx)));
81 else
82 a.setProcinfo(plist('model', objs(objLoop).models));
83 end
84 if ~strcmp(varargin{end}, 'internal')
85 a.addHistory(pest.getInfo('find', 'None'), plist('params', pname), obj_invars(objLoop), objs(objLoop).hist);
86 end
87 out = [out a];
88 end
89 end
90
91 end
92
93 %%% Set output
94 if nargout == numel(out)
95 % List of outputs
96 for ii = 1:numel(out)
97 varargout{ii} = out(ii);
98 end
99 else
100 % Single output
101 varargout{1} = out;
102 end
103
104 end
105
106 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
107 % Local Functions %
108 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
109
110 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
111 %
112 % FUNCTION: getInfo
113 %
114 % DESCRIPTION: Get Info Object
115 %
116 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
117
118 function ii = getInfo(varargin)
119 if nargin == 1 && strcmpi(varargin{1}, 'None')
120 sets = {};
121 pl = [];
122 else
123 sets = {'Default'};
124 pl = getDefaultPlist;
125 end
126 % Build info object
127 ii = minfo(mfilename, 'pest', 'ltpda', utils.const.categories.helper, '$Id: find.m,v 1.7 2011/04/08 08:56:25 hewitson Exp $', sets, pl);
128 end
129
130 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
131 %
132 % FUNCTION: getDefaultPlist
133 %
134 % DESCRIPTION: Get Default Plist
135 %
136 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
137
138 function plout = getDefaultPlist()
139 persistent pl;
140 if exist('pl', 'var')==0 || isempty(pl)
141 pl = buildplist();
142 end
143 plout = pl;
144 end
145
146 function pl = buildplist()
147
148 pl = plist();
149
150 % Params
151 p = param({'params', 'A cell-array of parameter names.'}, {1, {'{}'}, paramValue.OPTIONAL});
152 pl.append(p);
153
154 end
155