comparison m-toolbox/test/template_test_models/ao_model_a.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 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2 %
3 % DESCRIPTION: Builtin model for A
4 %
5 % This model adds together model 'b' and model 'c'.
6 %
7 %
8 % CALL:
9 % p = ao(plist('built-in','a'))
10 %
11 % INPUTS:
12 %
13 %
14 % OUTPUTS:
15 % - p: an AO object representing a
16 %
17 %
18 % INFO:
19 % <a href="matlab:web(modelOverview(ao_model_a('info')), '-helpbrowser')">Model Information</a>
20 %
21 %
22 % REFERENCES:
23 %
24 %
25 % VERSION: $Id: ao_model_a.m,v 1.4 2010/09/16 09:10:17 hewitson Exp $
26 %
27 % HISTORY:
28 %
29 %
30 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
31
32
33 function varargout = ao_model_a(varargin)
34
35 % Process inputs
36 [info, pl, constructorInfo, fcn] = utils.models.processModelInputs(varargin(:), ...
37 mfilename, ...
38 @getModelDescription, ...
39 @getModelDocumentation, ...
40 @getVersion, ...
41 @versionTable);
42 if ~isempty(info)
43 varargout{1} = info;
44 return;
45 end
46
47 % Build the object
48 out = fcn();
49
50 % Set the method version string in the minfo object
51 if ~isempty(constructorInfo)
52 % If this is a user-call via a constructor, then we add history
53 out = addHistoryStep(out, constructorInfo, pl);
54 end
55
56 if nargout > 0
57 varargout{1} = out;
58 varargout{2} = pl;
59 else
60 error('!!! Invalid number of output')
61 end
62 end
63
64
65 %--------------------------------------------------------------------------
66 % AUTHORS EDIT THIS PART
67 %--------------------------------------------------------------------------
68
69 function desc = getModelDescription
70 desc = 'My nice model which adds together two other models, $b+c$.';
71 end
72
73 function doc = getModelDocumentation
74 doc = sprintf([...
75 'This model does the amazing mathematical plus operation.\n'...
76 '<br><br>\n'...
77 '$b+c$\n'...
78 ]);
79 end
80
81 % default version is always the first one
82 function vt = versionTable()
83
84 vt = {...
85 'Better Version', @version2, ...
86 'Version One', @version1, ...
87 };
88
89 end
90
91 % This version uses:
92 % model b, version 'alpha'
93 % model c, version 'initial'
94 %
95 function varargout = version1(varargin)
96
97 if nargin == 1 && ischar(varargin{1})
98 switch varargin{1}
99 case 'plist'
100
101 % The plist for this version of this model
102 pl = plist();
103
104 % parameter a
105 p = param({'a', 'Parameter a of the model'}, paramValue.DOUBLE_VALUE(1));
106 pl.append(p);
107
108 % set output
109 varargout{1} = pl;
110
111 case 'description'
112 varargout{1} = 'Using model b version ''alpha'' and model c version ''initial''.';
113 case 'info'
114 varargout{1} = [ao_model_b('info', 'alpha') ao_model_c('info', 'initial')];
115 otherwise
116 error('unknown inputs');
117 end
118 return;
119 end
120
121 % build model
122
123 b = ao_model_b(plist('version', 'alpha'));
124 c = ao_model_c(plist('version', 'initial'));
125
126
127 varargout{1} = b+c;
128
129 end
130
131
132 % This version uses:
133 % model b, version 'alpha'
134 % model c, version 'second'
135 %
136 function varargout = version2(varargin)
137
138 if nargin == 1 && ischar(varargin{1})
139 switch varargin{1}
140 case 'plist'
141
142 % The plist for this version of this model
143 pl = plist();
144
145 % parameter a
146 p = param({'a', 'Parameter a of the model'}, paramValue.DOUBLE_VALUE(10));
147 pl.append(p);
148
149 % Expose some parameters of the submodel b
150 plb = ao_model_b('plist', 'alpha');
151 plb = plb.subset('b');
152 pl.combine(plb);
153
154 % set output
155 varargout{1} = pl;
156
157 case 'description'
158 varargout{1} = 'Using model b version ''alpha'' and model c version ''second''.';
159 case 'info'
160 varargout{1} = [ao_model_b('info', 'alpha') ao_model_c('info', 'second')];
161 otherwise
162 error('unknown inputs');
163 end
164 return;
165 end
166
167 % build model
168
169 b = ao_model_b(plist('version', 'alpha'));
170 c = ao_model_c(plist('version', 'second'));
171
172
173 varargout{1} = b+c;
174 end
175
176 %--------------------------------------------------------------------------
177 % AUTHORS SHOULD NOT NEED TO EDIT BELOW HERE
178 %--------------------------------------------------------------------------
179
180
181 %--------------------------------------------------------------------------
182 % Get Version
183 %--------------------------------------------------------------------------
184 function v = getVersion
185
186 v = '$Id: ao_model_a.m,v 1.4 2010/09/16 09:10:17 hewitson Exp $';
187
188 end