Mercurial > hg > ltpda
comparison m-toolbox/classes/@smodel/simplifyUnits.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 % SIMPLIFYUNITS simplify the x and/or y units of the model. | |
2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
3 % | |
4 % DESCRIPTION: SIMPLIFYUNITS simplify the x and/or y units of the model. | |
5 % | |
6 % CALL: m = simplifyUnits(m) | |
7 % obj = obj.simplifyUnits(pl); | |
8 % | |
9 % <a href="matlab:utils.helper.displayMethodInfo('smodel', 'simplifyUnits')">Parameters Description</a> | |
10 % | |
11 % VERSION: $Id: simplifyUnits.m,v 1.7 2011/04/08 08:56:30 hewitson Exp $ | |
12 % | |
13 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
14 | |
15 function varargout = simplifyUnits(varargin) | |
16 | |
17 %%% Check if this is a call for parameters | |
18 if utils.helper.isinfocall(varargin{:}) | |
19 varargout{1} = getInfo(varargin{3}); | |
20 return | |
21 end | |
22 | |
23 import utils.const.* | |
24 utils.helper.msg(msg.PROC3, 'running %s/%s', mfilename('class'), mfilename); | |
25 | |
26 % Collect input variable names | |
27 in_names = cell(size(varargin)); | |
28 for ii = 1:nargin,in_names{ii} = inputname(ii);end | |
29 | |
30 % Collect all AOs | |
31 [mdls, mdl_invars,rest] = utils.helper.collect_objects(varargin(:), 'smodel', in_names); | |
32 [pls, invars, rest] = utils.helper.collect_objects(rest(:), 'plist'); | |
33 | |
34 %%% Combine plists | |
35 pls = parse(pls, getDefaultPlist); | |
36 | |
37 % Decide on a deep copy or a modify | |
38 bs = copy(mdls, nargout); | |
39 | |
40 % The ports to simplify | |
41 axis = find(pls, 'axis'); | |
42 | |
43 % gathering exception list | |
44 exceptions = find(pls, 'exceptions'); | |
45 if isempty(exceptions) | |
46 exceptions = cell(0); | |
47 elseif ~iscell(exceptions) | |
48 exceptions = cellstr(exceptions); | |
49 end | |
50 | |
51 % Loop over AOs | |
52 for j=1:numel(bs) | |
53 | |
54 switch upper(axis) | |
55 case 'X' | |
56 | |
57 bs(j).setXunits(simplify(bs(j).xunits, exceptions)); | |
58 | |
59 case 'Y' | |
60 | |
61 bs(j).setYunits(simplify(bs(j).yunits, exceptions)); | |
62 | |
63 case 'XY' | |
64 | |
65 bs(j).setXunits(simplify(bs(j).xunits, exceptions)); | |
66 bs(j).setYunits(simplify(bs(j).yunits, exceptions)); | |
67 | |
68 otherwise | |
69 error('ltpda:smodel:simplifyUnits', 'unrecognized axis option'); | |
70 end | |
71 | |
72 if ~strcmp(varargin{end}, 'internal') | |
73 bs(j).addHistory(getInfo('None'), pls, mdl_invars(j), bs(j).hist); | |
74 end | |
75 end | |
76 | |
77 % Set output | |
78 if nargout == numel(bs) | |
79 % List of outputs | |
80 for ii = 1:numel(bs) | |
81 varargout{ii} = bs(ii); | |
82 end | |
83 else | |
84 % Single output | |
85 varargout{1} = bs; | |
86 end | |
87 end | |
88 | |
89 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
90 % Local Functions % | |
91 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
92 | |
93 | |
94 %-------------------------------------------------------------------------- | |
95 % Get Info Object | |
96 %-------------------------------------------------------------------------- | |
97 function ii = getInfo(varargin) | |
98 | |
99 if nargin == 1 && strcmpi(varargin{1}, 'None') | |
100 sets = {}; | |
101 pl = []; | |
102 else | |
103 sets = {'Default'}; | |
104 pl = getDefaultPlist; | |
105 end | |
106 % Build info object | |
107 ii = minfo(mfilename, 'smodel', 'ltpda', utils.const.categories.helper, '$Id: simplifyUnits.m,v 1.7 2011/04/08 08:56:30 hewitson Exp $', sets, pl); | |
108 end | |
109 | |
110 %-------------------------------------------------------------------------- | |
111 % Get Default Plist | |
112 %-------------------------------------------------------------------------- | |
113 function plout = getDefaultPlist() | |
114 persistent pl; | |
115 if exist('pl', 'var')==0 || isempty(pl) | |
116 pl = buildplist(); | |
117 end | |
118 plout = pl; | |
119 end | |
120 | |
121 function pl = buildplist() | |
122 pl = plist(); | |
123 | |
124 % Exceptions | |
125 p = param({'exceptions', 'A string or cell of strings of units which are not simplyfied.'}, ... | |
126 paramValue.EMPTY_STRING); | |
127 pl.append(p); | |
128 | |
129 % Port | |
130 p = param({'axis', 'The axis to simplify the units of.'}, ... | |
131 {3, {'X', 'Y', 'XY'}, paramValue.SINGLE}); | |
132 pl.append(p); | |
133 | |
134 end | |
135 |