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