Mercurial > hg > ltpda
comparison m-toolbox/classes/@ao/fromParameter.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 % FROMPARAMETER Construct an ao from a param object | |
2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
3 % | |
4 % FUNCTION: fromParameter | |
5 % | |
6 % DESCRIPTION: Construct an ao from a param object | |
7 % | |
8 % CALL: a = fromParameter(a, pl) | |
9 % | |
10 % PARAMETER: pl: Parameter list object | |
11 % | |
12 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
13 function a = fromParameter(a, pli) | |
14 | |
15 VERSION = '$Id: fromParameter.m,v 1.2 2011/07/06 06:37:06 mauro Exp $'; | |
16 % get AO info | |
17 ii = ao.getInfo('ao', 'From Parameter'); | |
18 | |
19 % Set the method version string in the minfo object | |
20 ii.setMversion([VERSION '-->' ii.mversion]); | |
21 | |
22 % Add default values | |
23 pl = parse(pli, ii.plists); | |
24 pl = parse(pl, plist('fcn', [])); | |
25 pl.getSetRandState(); | |
26 | |
27 pin = find(pl, 'parameter'); | |
28 name = ''; | |
29 pval = []; | |
30 switch class(pin) | |
31 case 'plist' | |
32 key = find(pl, 'key'); | |
33 if isempty(key) | |
34 error('When inputting a plist, the required key should be specified'); | |
35 end | |
36 | |
37 pidx = pin.getIndexForKey(key); | |
38 p = pin.params(pidx); | |
39 name = p.key; | |
40 pval = p.val; | |
41 | |
42 case 'param' | |
43 | |
44 name = pin.key; | |
45 pval = pin.val; | |
46 | |
47 case 'paramValue' | |
48 | |
49 pval = pin; | |
50 | |
51 case 'char' | |
52 pl_model_list = plist.getBuiltInModels(); | |
53 if any(strcmp(pl_model_list(:,1), pin)) | |
54 pl_model = plist(plist('built-in', pin)); | |
55 else | |
56 error('The input name ''%s'' is not a supported built-in model', pin); | |
57 end | |
58 | |
59 key = find(pl, 'key'); | |
60 if isempty(key) | |
61 error('When inputting a plist, the required key should be specified'); | |
62 end | |
63 | |
64 pidx = pl_model.getIndexForKey(key); | |
65 p = pl_model.params(pidx); | |
66 name = p.key; | |
67 pval = p.val; | |
68 otherwise | |
69 error('The input parameter class is not supported [%s]', class(pin)); | |
70 end | |
71 | |
72 | |
73 yunits = ''; | |
74 props = []; | |
75 switch class(pval) | |
76 case 'double' | |
77 dval = pval; | |
78 case 'paramValue' | |
79 dval = pval.getVal; | |
80 | |
81 % do we have other properties? | |
82 propnames = fieldnames(pval.property); | |
83 if ismember('unit', propnames) | |
84 yunits = pval.getProperty('unit'); | |
85 end | |
86 if ismember('units', propnames) | |
87 yunits = pval.getProperty('units'); | |
88 end | |
89 | |
90 props = pval.property; | |
91 | |
92 otherwise | |
93 error('Unsupported value class [%s] for key %s', class(pval), name); | |
94 end | |
95 | |
96 data = cdata(dval); | |
97 data.setYunits(yunits); | |
98 a.setName(name); | |
99 a.data = data; | |
100 a.setProcinfo(plist('properties', props)); | |
101 | |
102 % Add history | |
103 a.addHistory(ii, pl, [], []); | |
104 | |
105 end | |
106 |