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