Mercurial > hg > ltpda
comparison m-toolbox/classes/@ao/simplifyYunits.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 % SIMPLIFYYUNITS simplify the 'yunits' property of the ao. | |
2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
3 % | |
4 % DESCRIPTION: SIMPLIFYYUNITS sets the 'yunits' property of the ao. | |
5 % | |
6 % CALL: ao = simplifyYunits(ao) | |
7 % obj = obj.simplifyYunits(pl); | |
8 % | |
9 % <a href="matlab:utils.helper.displayMethodInfo('ao', 'simplifyYunits')">Parameters Description</a> | |
10 % | |
11 % VERSION: $Id: simplifyYunits.m,v 1.20 2011/05/22 22:20:26 mauro Exp $ | |
12 % | |
13 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
14 | |
15 function varargout = simplifyYunits(varargin) | |
16 | |
17 % Check if this is a call from a class method | |
18 callerIsMethod = utils.helper.callerIsMethod; | |
19 | |
20 if callerIsMethod | |
21 as = varargin{1}; | |
22 if nargin == 2 | |
23 pls = varargin{2}; | |
24 else | |
25 pls = plist(); | |
26 end | |
27 | |
28 else | |
29 %%% Check if this is a call for parameters | |
30 if utils.helper.isinfocall(varargin{:}) | |
31 varargout{1} = getInfo(varargin{3}); | |
32 return | |
33 end | |
34 | |
35 import utils.const.* | |
36 utils.helper.msg(msg.PROC3, 'running %s/%s', mfilename('class'), mfilename); | |
37 | |
38 % Collect input variable names | |
39 in_names = cell(size(varargin)); | |
40 for ii = 1:nargin,in_names{ii} = inputname(ii);end | |
41 | |
42 % Collect all AOs | |
43 [as, ao_invars] = utils.helper.collect_objects(varargin(:), 'ao', in_names); | |
44 | |
45 % Apply defaults to plist | |
46 pls = applyDefaults(getDefaultPlist, varargin{:}); | |
47 | |
48 end | |
49 | |
50 % Decide on a deep copy or a modify | |
51 bs = copy(as, nargout); | |
52 | |
53 % check if simplifying the prefixes or not: 'yes'/'no' or true/false or 'true'/'false' | |
54 prefixes = utils.prog.yes2true(find(pls, 'prefixes')); | |
55 | |
56 % gathering exception list | |
57 exceptions = find(pls, 'exceptions'); | |
58 if isempty(exceptions) | |
59 exceptions = cell(0); | |
60 elseif ~iscell(exceptions) | |
61 exceptions = cellstr(exceptions); | |
62 end | |
63 | |
64 % Loop over AOs | |
65 for jj = 1:numel(bs) | |
66 | |
67 % Count the prefix values first before we compute this value to the | |
68 % data because then is the error not so large. | |
69 prfval = 1; | |
70 | |
71 % simplify prefixes first | |
72 if prefixes | |
73 yun = copy(bs(jj).data.yunits, true); | |
74 vals = yun.vals; | |
75 exps = yun.exps; | |
76 | |
77 % Get the different unit-string of the y-axis. | |
78 % Use for this the char-method because this method adds the prefix | |
79 % to the unit. | |
80 strs = {}; | |
81 yuns = yun.split(); | |
82 for kk = 1:numel(yuns) | |
83 strs{end+1} = char(yuns(kk)); | |
84 end | |
85 | |
86 % Run over all y-units parts because it might be that one of the parts is | |
87 % in the exception list. | |
88 for ii = 1:numel(vals) | |
89 str = strs{ii}(2:end-1); | |
90 str = strtok(str, '^'); | |
91 if ~(any(ismember(str, exceptions))) | |
92 prfval = prfval .* prod(vals(ii) .^ exps(ii)); | |
93 vals(ii) = 1; | |
94 yun.setVals(vals); | |
95 end | |
96 end | |
97 bs(jj).data.setYunits(yun); | |
98 end | |
99 | |
100 % Multiply the prefix value to the y-data | |
101 bs(jj).data.setY(bs(jj).y .* prfval); | |
102 | |
103 % simplify the units | |
104 bs(jj).data.setYunits(simplify(bs(jj).data.yunits, exceptions)); | |
105 | |
106 if ~callerIsMethod | |
107 bs(jj).addHistory(getInfo('None'), pls, ao_invars(jj), bs(jj).hist); | |
108 end | |
109 end | |
110 | |
111 % Set output | |
112 varargout = utils.helper.setoutputs(nargout, bs); | |
113 end | |
114 | |
115 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
116 % Local Functions % | |
117 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
118 %-------------------------------------------------------------------------- | |
119 % Get Info Object | |
120 %-------------------------------------------------------------------------- | |
121 function ii = getInfo(varargin) | |
122 | |
123 if nargin == 1 && strcmpi(varargin{1}, 'None') | |
124 sets = {}; | |
125 pl = []; | |
126 else | |
127 sets = {'Default'}; | |
128 pl = getDefaultPlist(); | |
129 end | |
130 % Build info object | |
131 ii = minfo(mfilename, 'ao', 'ltpda', utils.const.categories.helper, '$Id: simplifyYunits.m,v 1.20 2011/05/22 22:20:26 mauro Exp $', sets, pl); | |
132 end | |
133 | |
134 %-------------------------------------------------------------------------- | |
135 % Get Default Plist | |
136 %-------------------------------------------------------------------------- | |
137 function plout = getDefaultPlist() | |
138 persistent pl; | |
139 if ~exist('pl', 'var') || isempty(pl) | |
140 pl = buildplist(); | |
141 end | |
142 plout = pl; | |
143 end | |
144 | |
145 function pl = buildplist() | |
146 pl = plist(); | |
147 | |
148 % Prefixes | |
149 p = param({'prefixes', 'also simplify the prefixes and scale the data'}, paramValue.TRUE_FALSE); | |
150 pl.append(p); | |
151 | |
152 % Exceptions | |
153 p = param({'exceptions', 'A string or cell of strings of units which are not simplyfied.'}, ... | |
154 paramValue.EMPTY_STRING); | |
155 pl.append(p); | |
156 | |
157 end |