Mercurial > hg > ltpda
comparison m-toolbox/classes/@ssm/duplicateInput.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 % DUPLICATEINPUT copies the specified input blocks. | |
2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
3 % | |
4 % DESCRIPTION: DUPLICATEINPUT copies the specified input blocks. | |
5 % | |
6 % CALL: obj = obj.duplicateInput( blockIndex, newBlockNames); | |
7 % obj = obj.duplicateInput( blockNames, newBlockNames); | |
8 % | |
9 % blockname may be a double, a string or a cellstr | |
10 % newBlockNames may be a string or a cellstr | |
11 % | |
12 % <a href="matlab:utils.helper.displayMethodInfo('ssm', 'duplicateInput')">Parameters Description</a> | |
13 % | |
14 % VERSION: $Id: duplicateInput.m,v 1.7 2011/04/08 08:56:22 hewitson Exp $ | |
15 % | |
16 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
17 | |
18 function varargout = duplicateInput(varargin) | |
19 | |
20 %%% Check if this is a call for parameters | |
21 if utils.helper.isinfocall(varargin{:}) | |
22 varargout{1} = getInfo(varargin{3}); | |
23 return | |
24 end | |
25 | |
26 import utils.const.* | |
27 utils.helper.msg(msg.PROC3, 'running %s/%s', mfilename('class'), mfilename); | |
28 | |
29 % Collect input variable names | |
30 in_names = cell(size(varargin)); | |
31 for ii = 1:nargin,in_names{ii} = inputname(ii);end | |
32 | |
33 [sys, ssm_invars, rest] = utils.helper.collect_objects(varargin(:), 'ssm', in_names); | |
34 [pl, invars2, rest] = utils.helper.collect_objects(rest(:), 'plist'); | |
35 if ~isempty(rest) | |
36 pl = combine(pl, plist(rest{:})); | |
37 end | |
38 pl = combine(pl, getDefaultPlist()); | |
39 | |
40 %%% Internal call: Only one object + don't look for a plist | |
41 internal = strcmp(varargin{end}, 'internal'); | |
42 | |
43 sys = copy(sys, nargout); | |
44 | |
45 %% parameters | |
46 blockIds = pl.find('blocks'); | |
47 newNames = pl.find('names'); | |
48 | |
49 if ischar(newNames) | |
50 newNames = {newNames}; | |
51 end | |
52 if ischar(blockIds) | |
53 blockIds = {blockIds}; | |
54 end | |
55 | |
56 %% Some error checking.... | |
57 if numel(newNames) ~= numel(blockIds) | |
58 error('### Please specify one new name per block'); | |
59 end | |
60 | |
61 %% Loop over the input ssm objects | |
62 for kk = 1:numel(sys) | |
63 blocks0 = sys(kk).inputs; | |
64 % collecting the blocks indexes | |
65 if isnumeric(blockIds) | |
66 positions = blockIds; | |
67 else | |
68 positions = zeros(1,0); | |
69 for ii=1:numel(blockIds) | |
70 [pos2, res2] = findBlockWithNames(blocks0, newNames{ii}, false); | |
71 if res2 | |
72 warning('### input blocks ''%s'' already exists in SSM model ''%s'', duplication of ''%s'' is impossible', newNames{ii}, sys(kk).name, blockIds{ii}); | |
73 beep; | |
74 else | |
75 [pos, res] = findBlockWithNames(blocks0, blockIds{ii}); | |
76 if res | |
77 positions = [positions pos]; %#ok<AGROW> | |
78 else | |
79 warning('### input blocks ''%s'' not found in SSM model ''%s'' ', blockIds{ii}, sys(kk).name); | |
80 end | |
81 end | |
82 end | |
83 end | |
84 | |
85 %% now copying input | |
86 Ni = sys(kk).Ninputs; | |
87 sys(kk).bmats = [sys(kk).bmats sys(kk).bmats(:,positions) ]; | |
88 sys(kk).dmats = [sys(kk).dmats sys(kk).dmats(:,positions) ]; | |
89 sys(kk).inputs = [sys(kk).inputs copy(sys(kk).inputs(positions),true) ]; | |
90 | |
91 for ii=1:numel(positions) | |
92 sys(kk).inputs(Ni+ii).setBlockNames(newNames{ii}); | |
93 end | |
94 | |
95 % append history step | |
96 if ~internal | |
97 sys(kk).addHistory(getInfo('None'), pl, ssm_invars(kk), sys(kk).hist); | |
98 end | |
99 end % End loop over blocks | |
100 | |
101 %% Set output | |
102 if nargout == numel(sys) | |
103 for ii = 1:numel(sys) | |
104 varargout{ii} = sys(ii); | |
105 end | |
106 else | |
107 varargout{1} = sys; | |
108 end | |
109 end | |
110 | |
111 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
112 % Local Functions % | |
113 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
114 | |
115 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
116 % | |
117 % FUNCTION: getInfo | |
118 % | |
119 % DESCRIPTION: Get Info Object | |
120 % | |
121 % HISTORY: 11-07-07 M Hewitson | |
122 % Creation. | |
123 % | |
124 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
125 | |
126 function ii = getInfo(varargin) | |
127 if nargin == 1 && strcmpi(varargin{1}, 'None') | |
128 sets = {}; | |
129 pl = []; | |
130 else | |
131 sets = {'Default'}; | |
132 pl = getDefaultPlist; | |
133 end | |
134 % Build info object | |
135 ii = minfo(mfilename, 'ssm', 'ltpda', utils.const.categories.helper, '$Id: duplicateInput.m,v 1.7 2011/04/08 08:56:22 hewitson Exp $', sets, pl); | |
136 end | |
137 | |
138 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
139 % | |
140 % FUNCTION: getDefaultPlist | |
141 % | |
142 % DESCRIPTION: Get Default Plist | |
143 % | |
144 % HISTORY: 11-07-07 M Hewitson | |
145 % Creation. | |
146 % | |
147 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
148 | |
149 function plo = getDefaultPlist() | |
150 plo = plist(); | |
151 | |
152 % blocks | |
153 p = param({'blocks', 'Identifiers (strings or indices) of the input blocks you want to copy.'}, paramValue.EMPTY_STRING); | |
154 plo.append(p); | |
155 | |
156 % names | |
157 p = param({'names', 'The new name(s) you want to set to the new inputs. Use a cell-array, one entry for each of them.'}, ... | |
158 paramValue.EMPTY_STRING); | |
159 plo.append(p); | |
160 | |
161 end | |
162 |