comparison m-toolbox/classes/@ssm/setPortProperties.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 % SETPORTPROPERTIES Sets names of the specified SSM ports.
2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3 %
4 % DESCRIPTION: SETPORTPROPERTIES Sets names of the specified SSM ports.
5 %
6 % CALL: obj = obj.setPortProperties(plist);
7 %
8 % <a href="matlab:utils.helper.displayMethodInfo('ssm', 'setPortProperties')">Parameters Description</a>
9 %
10 % VERSION: $Id: setPortProperties.m,v 1.5 2011/04/08 08:56:23 hewitson Exp $
11 %
12 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
13
14 function varargout = setPortProperties(varargin)
15
16 %%% Check if this is a call for parameters
17 if utils.helper.isinfocall(varargin{:})
18 varargout{1} = getInfo(varargin{3});
19 return
20 end
21
22 import utils.const.*
23 utils.helper.msg(msg.PROC3, 'running %s/%s', mfilename('class'), mfilename);
24
25 % Collect input variable names
26 in_names = cell(size(varargin));
27 for ii = 1:nargin,in_names{ii} = inputname(ii);end
28
29 [sys, ssm_invars, rest] = utils.helper.collect_objects(varargin(:), 'ssm', in_names);
30 [pl, invars2, rest] = utils.helper.collect_objects(rest(:), 'plist');
31 if ~isempty(rest)
32 pl = combine(pl, plist(rest{:}));
33 end
34 pl = combine(pl, getDefaultPlist());
35
36 %%% Internal call: Only one object + don't look for a plist
37 internal = strcmp(varargin{end}, 'internal');
38
39 sys = copy(sys, nargout);
40
41 %% parameters
42
43 field = pl.find('field');
44 portIds = pl.find('ports');
45 newNames = pl.find('NEW_NAMES');
46 newDescriptions = pl.find('NEW_DESCRIPTIONS');
47 newUnits = pl.find('NEW_UNITS');
48
49 if ischar(newDescriptions)
50 newDescriptions = {newDescriptions};
51 end
52 if ischar(newNames)
53 newNames = {newNames};
54 end
55
56 % Some error checking....
57 if isempty(field)
58 error('### Please specify the field of the block to modify');
59 end
60
61 %% Loop over the input ssm objects
62 for kk = 1:numel(sys)
63 block = sys(kk).(field);
64
65 [blockPos portPos] = block.findPortWithMixedNames(portIds);
66 if ~isempty(newDescriptions)
67 if numel(newDescriptions) ~= numel(blockPos)
68 error('### Please specify one new description per block');
69 end
70 for ii=1:numel(blockPos)
71 block(blockPos(ii)).ports(portPos(ii)).setDescription(newDescriptions(ii));
72 % setting the new description
73 end
74 end
75 if ~isempty(newNames)
76 if numel(newNames) ~= numel(blockPos)
77 error('### Please specify one new description per block');
78 end
79 for ii=1:numel(blockPos)
80 block(blockPos(ii)).ports(portPos(ii)).setName( newNames(ii), block(blockPos(ii)).name);
81 % setting port name. This call only modifies the blockName.portName
82 % part after the dot. The user shouldn't be able to do otherwise.
83 end
84 end
85 if ~isempty(newUnits)
86 if numel(newUnits) ~= numel(blockPos)
87 error('### Please specify one new description per block');
88 end
89 for ii=1:numel(blockPos)
90 block(blockPos(ii)).ports(portPos(ii)).setUnits(newUnits(ii));
91 % setting units
92 end
93 end
94 if ~internal
95 % append history step
96 sys(kk).addHistory(getInfo('None'), pl, ssm_invars(kk), sys(kk).hist);
97 end
98 end % End loop over block IDs
99
100 %% Set output
101 if nargout == numel(sys)
102 for ii = 1:numel(sys)
103 varargout{ii} = sys(ii);
104 end
105 else
106 varargout{1} = sys;
107 end
108 end
109
110 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
111 % Local Functions %
112 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
113
114 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
115 %
116 % FUNCTION: getInfo
117 %
118 % DESCRIPTION: Get Info Object
119 %
120 % HISTORY: 11-07-07 M Hewitson
121 % Creation.
122 %
123 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
124
125 function ii = getInfo(varargin)
126 if nargin == 1 && strcmpi(varargin{1}, 'None')
127 sets = {};
128 pl = [];
129 else
130 sets = {'Default'};
131 pl = getDefaultPlist;
132 end
133 % Build info object
134 ii = minfo(mfilename, 'ssm', 'ltpda', utils.const.categories.helper, '$Id: setPortProperties.m,v 1.5 2011/04/08 08:56:23 hewitson Exp $', sets, pl);
135 end
136
137 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
138 %
139 % FUNCTION: getDefaultPlist
140 %
141 % DESCRIPTION: Get Default Plist
142 %
143 % HISTORY: 11-07-07 M Hewitson
144 % Creation.
145 %
146 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
147
148 function plo = getDefaultPlist()
149 plo = plist();
150
151 % field
152 p = param({'field', 'The field containing the port being changed.'}, {1, {'inputs', 'outputs', 'states'}, paramValue.SINGLE});
153 plo.append(p);
154
155 % ports
156 p = param({'ports', 'Identifiers (cellstr of "blockNames"/"blockNames.portNames" or "ALL") of the ports you want to modify.'}, paramValue.EMPTY_CELL );
157 plo.append(p);
158
159 % names
160 p = param({'NEW_NAMES', 'The new names(s) you want to set to the port(s). Use a cell-array, one entry for each port.'}, ...
161 paramValue.EMPTY_CELL );
162 plo.append(p);
163
164 % descriptions
165 p = param({'NEW_DESCRIPTIONS', 'The new descriptions(s) you want to set to the port(s). Use a cell-array, one entry for each port.'}, ...
166 paramValue.EMPTY_CELL );
167 plo.append(p);
168
169 % units
170 p = param({'NEW_UNITS', 'The new names(s) you want to set to the port(s). Use a unit vector, one entry for each port.'}, ...
171 {1, {unit.initObjectWithSize(1,0) }, paramValue.OPTIONAL});
172 plo.append(p);
173
174 end
175
176