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