Mercurial > hg > ltpda
comparison m-toolbox/classes/@ssm/setBlockNames.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 % SETBLOCKNAMES Sets names of the specified SSM blocks. | |
2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
3 % | |
4 % DESCRIPTION: SETBLOCKNAMES Sets names of the specified SSM blocks. | |
5 % | |
6 % CALL: obj = obj.setBlockNames(plist); | |
7 % | |
8 % | |
9 % <a href="matlab:utils.helper.displayMethodInfo('ssm', 'setBlockNames')">Parameters Description</a> | |
10 % | |
11 % VERSION: $Id: setBlockNames.m,v 1.14 2011/04/08 08:56:22 hewitson Exp $ | |
12 % | |
13 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
14 | |
15 function varargout = setBlockNames(varargin) | |
16 warning('This function is deprecated and will soon be removed. Please use ssm/setBlockPorperties instead') | |
17 %%% Check if this is a call for parameters | |
18 if utils.helper.isinfocall(varargin{:}) | |
19 varargout{1} = getInfo(varargin{3}); | |
20 return | |
21 end | |
22 | |
23 import utils.const.* | |
24 utils.helper.msg(msg.PROC3, 'running %s/%s', mfilename('class'), mfilename); | |
25 | |
26 % Collect input variable names | |
27 in_names = cell(size(varargin)); | |
28 for ii = 1:nargin,in_names{ii} = inputname(ii);end | |
29 | |
30 [ssms, ssm_invars, rest] = utils.helper.collect_objects(varargin(:), 'ssm', in_names); | |
31 [pl, invars2, rest] = utils.helper.collect_objects(rest(:), 'plist'); | |
32 if ~isempty(rest) | |
33 pl = combine(pl, plist(rest{:})); | |
34 end | |
35 pl = combine(pl, getDefaultPlist()); | |
36 | |
37 %%% Internal call: Only one object + don't look for a plist | |
38 internal = strcmp(varargin{end}, 'internal'); | |
39 | |
40 sys = copy(ssms, nargout); | |
41 | |
42 %% parameters | |
43 | |
44 field = pl.find('field'); | |
45 blockIds = pl.find('blocks'); | |
46 newNames = pl.find('names'); | |
47 | |
48 if ischar(newNames) | |
49 newNames = {newNames}; | |
50 end | |
51 if ischar(blockIds) | |
52 blockIds = {blockIds}; | |
53 end | |
54 | |
55 % Some error checking.... | |
56 if isempty(field) | |
57 error('### Please specify the field of the block to modify'); | |
58 end | |
59 if numel(newNames) ~= numel(blockIds) | |
60 error('### Please specify one new name per old name/position'); | |
61 end | |
62 | |
63 %% Loop over the input ssm objects | |
64 for kk = 1:numel(sys) | |
65 block = sys(kk).(field); | |
66 if isa(blockIds, 'double') | |
67 block(blockIds).setBlockNames(newNames); | |
68 elseif iscellstr(blockIds) | |
69 for i=1:numel(blockIds) | |
70 oldNames = block.blockNames; | |
71 position = strcmpi(oldNames, blockIds{i}); | |
72 if sum(position)==0 | |
73 error(['block named ' blockIds{i} ' could not be found in system ' sys(kk).name]) | |
74 end | |
75 block(position).setBlockNames(newNames); | |
76 end | |
77 end | |
78 if ~internal | |
79 % append history step | |
80 sys(kk).addHistory(getInfo('None'), pl, ssm_invars(kk), sys(kk).hist); | |
81 end | |
82 end % End loop over block IDs | |
83 | |
84 %% Set output | |
85 if nargout == numel(sys) | |
86 for ii = 1:numel(sys) | |
87 varargout{ii} = sys(ii); | |
88 end | |
89 else | |
90 varargout{1} = sys; | |
91 end | |
92 end | |
93 | |
94 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
95 % Local Functions % | |
96 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
97 | |
98 %-------------------------------------------------------------------------- | |
99 % Get Info Object | |
100 %-------------------------------------------------------------------------- | |
101 | |
102 function ii = getInfo(varargin) | |
103 if nargin == 1 && strcmpi(varargin{1}, 'None') | |
104 sets = {}; | |
105 pl = []; | |
106 else | |
107 sets = {'Default'}; | |
108 pl = getDefaultPlist; | |
109 end | |
110 % Build info object | |
111 ii = minfo(mfilename, 'ssm', 'ltpda', utils.const.categories.helper, '$Id: setBlockNames.m,v 1.14 2011/04/08 08:56:22 hewitson Exp $', sets, pl); | |
112 end | |
113 | |
114 %-------------------------------------------------------------------------- | |
115 % Get Default Plist | |
116 %-------------------------------------------------------------------------- | |
117 | |
118 function plo = getDefaultPlist() | |
119 plo = plist(); | |
120 | |
121 % field | |
122 p = param({'field', 'The field being changed'}, {1, {'inputs', 'outputs', 'states'}, paramValue.SINGLE}); | |
123 plo.append(p); | |
124 | |
125 % blocks | |
126 p = param({'blocks', 'Identifiers (strings or indices) of the blocks you want to modify'}, {1, {[]}, paramValue.SINGLE}); | |
127 plo.append(p); | |
128 | |
129 % names | |
130 p = param({'names', 'The new name(s) you want to set to the block(s). Use a cell-array, one entry for each block.'}, ... | |
131 {1, {[]}, paramValue.SINGLE}); | |
132 plo.append(p); | |
133 | |
134 end | |
135 |