Mercurial > hg > ltpda
comparison m-toolbox/classes/@ssm/setPortUnits.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 % SETPORTUNITS Sets units of the specified SSM ports. | |
2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
3 % | |
4 % DESCRIPTION: SETPORTUNITS Sets units of the specified SSM ports. | |
5 % | |
6 % CALL: obj = obj.setPortUnits(plist); | |
7 % | |
8 % | |
9 % <a href="matlab:utils.helper.displayMethodInfo('ssm', 'setPortUnits')">Parameters Description</a> | |
10 % | |
11 % VERSION: $Id: setPortUnits.m,v 1.14 2011/04/08 08:56:22 hewitson Exp $ | |
12 % | |
13 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
14 | |
15 function varargout = setPortUnits(varargin) | |
16 warning('This function is deprecated and will soon be removed. Please use ssm/setPortPorperties instead') | |
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 [sys, ssm_invars, rest] = utils.helper.collect_objects(varargin(:), 'ssm', in_names); | |
32 [pl, invars2, rest] = utils.helper.collect_objects(rest(:), 'plist'); | |
33 if ~isempty(rest) | |
34 pl = combine(pl, plist(rest{:})); | |
35 end | |
36 pl = combine(pl, getDefaultPlist()); | |
37 | |
38 %%% Internal call: Only one object + don't look for a plist | |
39 internal = strcmp(varargin{end}, 'internal'); | |
40 | |
41 sys = copy(sys, nargout); | |
42 | |
43 %% parameters | |
44 | |
45 field = pl.find('field'); | |
46 blockId = pl.find('block'); | |
47 portIds = pl.find('ports'); | |
48 newUnits = pl.find('units'); | |
49 | |
50 if ischar(blockId) | |
51 blockId = {blockId}; | |
52 end | |
53 if ischar(portIds) | |
54 portIds = {portIds}; | |
55 end | |
56 if ischar(newUnits) | |
57 newUnits = {newUnits}; | |
58 end | |
59 if iscellstr(newUnits) | |
60 newUnits2 = unit.initObjectWithSize(1, numel(newUnits)); | |
61 for i=1:numel(newUnits) | |
62 newUnits2(i) = unit(newUnits{i}); | |
63 end | |
64 newUnits = newUnits2; | |
65 end | |
66 | |
67 %% Some error checking.... | |
68 if isempty(field) | |
69 error('### Please specify the field of the block to modify'); | |
70 end | |
71 if numel(newUnits) ~= numel(portIds) | |
72 error('### Please specify one new name per port'); | |
73 end | |
74 if numel(blockId)~=1 | |
75 error('### Please specify the name or the index of the block containing the port(s) to modify'); | |
76 end | |
77 | |
78 %% Loop over the input ssm objects | |
79 for kk = 1:numel(sys) | |
80 blocks = sys(kk).(field); | |
81 | |
82 % get the block | |
83 if isnumeric(blockId) | |
84 block = blocks(blockId); | |
85 else | |
86 pos = findBlockWithNames(blocks, blockId{1}); | |
87 block = blocks(pos); | |
88 end | |
89 | |
90 if isempty(block) | |
91 if isnumeric(blockId) | |
92 error('### block ''%d'' not found in SSM model ''%s'' %s', blockId, sys(kk).name, field); | |
93 else | |
94 error('### block ''%s'' not found in SSM model ''%s'' %s', blockId, sys(kk).name, field); | |
95 end | |
96 end | |
97 | |
98 %% now setting port units | |
99 oldNames = block.portNames; | |
100 oldNames = oldNames{1}; | |
101 if isa(portIds, 'double') | |
102 block.ports(portIds).setUnits(newUnits); | |
103 elseif iscellstr(portIds) | |
104 for i=1:numel(portIds) | |
105 position = strcmpi(oldNames, portIds{i}); | |
106 if sum(position)==0 | |
107 error(['block named ' portIds{i} ' could not be found in system ' sys(kk).name]) | |
108 end | |
109 block.ports(position).setUnits(newUnits(i)); | |
110 end | |
111 end | |
112 if ~internal | |
113 % append history step | |
114 sys(kk).addHistory(getInfo('None'), pl, ssm_invars(kk), sys(kk).hist); | |
115 end | |
116 end % End loop over blocks | |
117 | |
118 %% Set output | |
119 if nargout == numel(sys) | |
120 for ii = 1:numel(sys) | |
121 varargout{ii} = sys(ii); | |
122 end | |
123 else | |
124 varargout{1} = sys; | |
125 end | |
126 end | |
127 | |
128 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
129 % Local Functions % | |
130 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
131 | |
132 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
133 % | |
134 % FUNCTION: getInfo | |
135 % | |
136 % DESCRIPTION: Get Info Object | |
137 % | |
138 % HISTORY: 11-07-07 M Hewitson | |
139 % Creation. | |
140 % | |
141 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
142 | |
143 function ii = getInfo(varargin) | |
144 if nargin == 1 && strcmpi(varargin{1}, 'None') | |
145 sets = {}; | |
146 pl = []; | |
147 else | |
148 sets = {'Default'}; | |
149 pl = getDefaultPlist; | |
150 end | |
151 % Build info object | |
152 ii = minfo(mfilename, 'ssm', 'ltpda', utils.const.categories.helper, '$Id: setPortUnits.m,v 1.14 2011/04/08 08:56:22 hewitson Exp $', sets, pl); | |
153 end | |
154 | |
155 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
156 % | |
157 % FUNCTION: getDefaultPlist | |
158 % | |
159 % DESCRIPTION: Get Default Plist | |
160 % | |
161 % HISTORY: 11-07-07 M Hewitson | |
162 % Creation. | |
163 % | |
164 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
165 | |
166 function plo = getDefaultPlist() | |
167 plo = plist(); | |
168 | |
169 % field | |
170 p = param({'field', 'The field containing the port being changed.'}, {1, {'inputs', 'outputs', 'states'}, paramValue.SINGLE}); | |
171 plo.append(p); | |
172 | |
173 % block | |
174 p = param({'block', 'Identifiers (strings or indices) of the block containing the port you want to modify.'}, paramValue.EMPTY_STRING); | |
175 plo.append(p); | |
176 | |
177 % ports | |
178 p = param({'ports', 'Identifiers (strings or indices) of the ports you want to modify.'}, paramValue.EMPTY_STRING); | |
179 plo.append(p); | |
180 | |
181 % units | |
182 p = param({'units', 'The new units(s) you want to set to the port(s). Use a cell-array, one entry for each port.'}, ... | |
183 {} ); | |
184 plo.append(p); | |
185 | |
186 end | |
187 |