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