0
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1 % SSMBLOCK a helper class for the SSM class.
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
3 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
4 % SSMBLOCK a helper class for the SSM class.
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
5 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
6 % SUPERCLASSES: ltpda_nuo < ltpda_obj
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
7 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
8 % CONSTRUCTORS:
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
9 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
10 % sb = ssmblock(name);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
11 % sb = ssmblock(name, ports);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
12 % sb = ssmblock(name, ports, desc);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
13 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
14 % VERSION: $Id: ssmblock.m,v 1.29 2011/03/28 17:02:29 ingo Exp $
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
15 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
16 % SEE ALSO: ltpda_obj, ltpda_nuo, ssm
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
17 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
18 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
19
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
20 classdef (Hidden = true) ssmblock < ltpda_nuo
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
21
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
22 %% -------- Public (read/write) Properties -------
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
23 properties
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
24 end % -------- Public (read/write) Properties -------
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
25
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
26 %% -------- Private read-only Properties --------
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
27 properties (SetAccess = protected)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
28 name = ''; % name of the block
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
29 ports = ssmport.initObjectWithSize(1,0); % empty array of SSMPort objects
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
30 description = ''; % description of the block
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
31 end % -------- Private read-only Properties --------
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
32
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
33 %% -------- Dependant Properties ---------
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
34 properties (Dependent)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
35
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
36 end %-------- Dependant Hidden Properties ---------
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
37
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
38 %% -------- constructor ------
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
39 methods
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
40
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
41 function sb = ssmblock(varargin)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
42 switch nargin
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
43 case 0
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
44 % Empty constructor
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
45 case 1
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
46 if isstruct(varargin{1})
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
47 % from struct
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
48 sb = fromStruct(sb, varargin{1});
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
49 elseif isa(varargin{1}, 'ssmblock')
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
50 % copy constructor
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
51 sb = copy(varargin{1},1);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
52 else
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
53 error('### Unknown single argument constructor: ssmblock(%s)', class(varargin{1}));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
54 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
55 case 2
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
56 if isa(varargin{1}, 'org.apache.xerces.dom.DeferredElementImpl') && ...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
57 isa(varargin{2}, 'history')
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
58 sb = fromDom(sb, varargin{1}, varargin{2});
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
59 else
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
60 error('### Unknown two argument constructor: ssmblock(%s, %s)', class(varargin{1}), class(varargin{2}));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
61 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
62 otherwise
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
63 error('### Unknown argument constructor');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
64 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
65 end % -------- constructor ------
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
66
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
67 end % -------- constructor methods ------
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
68
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
69 %% -------- Declaration of Hidden Public methods --------
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
70 methods(Access = public, Hidden = true)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
71
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
72 varargout = attachToDom(varargin)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
73
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
74 function clearAllUnits(inputs)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
75 for kk=1:numel(inputs)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
76 inputs(kk).ports.clearAllUnits;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
77 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
78 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
79
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
80 %% counting methods for ssmblock arrays
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
81 % these methods are for a whole array object, therefore cannot be
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
82 % implemented as class methods
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
83 function Nblocks = Nblocks(block)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
84 Nblocks = numel(block);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
85 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
86
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
87 function Nports = Nports(block)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
88 Nports = zeros(1, numel(block));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
89 for i=1:numel(block)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
90 Nports(i) = numel(block(i).ports);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
91 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
92 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
93
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
94 %% "properties" methods for ssmblock arrays
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
95 % these methods are for a whole array object, therefore cannot be
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
96 % implemented as class methods
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
97 function blocknames = blockNames(block)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
98 blocknames = cell(1, numel(block));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
99 for i=1:numel(block)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
100 blocknames{i} = block(i).name;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
101 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
102 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
103
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
104 function blockDescriptions = blockDescriptions(block)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
105 blockDescriptions = cell(1, numel(block));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
106 for i=1:numel(block)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
107 blockDescriptions{i} = block(i).description;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
108 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
109 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
110
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
111 function ports = getPorts(varargin)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
112 warning('LTPDA:ssmblock', 'This function is outdated and will be deleted');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
113 ports = [];
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
114 for kk=1:nargin
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
115 if isa(varargin{kk}, 'ssmblock')
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
116 for ll=1:numel(varargin{kk})
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
117 ports = [ports varargin{kk}(ll).ports]; %#ok<AGROW>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
118 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
119 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
120 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
121 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
122
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
123 %% "properties" methods for ssmblock.ports in ssmblock arrays
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
124 % these methods are for a whole array object, therefore cannot be
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
125 % implemented as class methods
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
126 function portnames = portNames(block)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
127 portnames = cell(1, numel(block));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
128 for i=1:numel(block)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
129 portnames{i} = block(i).ports.portNames;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
130 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
131 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
132
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
133 function portDescriptions = portDescriptions(block)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
134 portDescriptions = cell(1, numel(block));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
135 for i=1:numel(block)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
136 portDescriptions{i} = block(i).ports.portDescriptions;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
137 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
138 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
139
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
140 function portUnits = portUnits(block)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
141 portUnits = cell(1, numel(block));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
142 for i=1:numel(block)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
143 portUnits{i} = block(i).ports.portUnits;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
144 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
145 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
146
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
147 %% setting methods for ssmblock arrays
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
148 function block = setBlockNames(block, blockNames)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
149 if ischar(blockNames), blockNames = {blockNames}; end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
150 % checking name format is correct
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
151 for i=1:numel(block)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
152 blockName = blockNames{i};
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
153 if numel(strfind(blockName,'.'))>0
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
154 error('The "." is not allowed in ssmport name')
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
155 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
156 if numel(strfind(blockName,' '))>0
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
157 error('The space " " is not allowed in ssmport name')
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
158 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
159 % modifying the port names so the prefix ("blockName.") is updated
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
160 block(i).ports.modifyBlockName(block(i).name, upper(blockName));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
161 block(i).name = upper(blockName);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
162 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
163 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
164
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
165 function block = setBlockDescriptions(block, desc)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
166 if ischar(desc), desc = {desc}; end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
167 for i=1:numel(block)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
168 block(i).description = desc{i};
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
169 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
170 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
171
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
172 function block = setPortsWithSize(block, size)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
173 for i=1:numel(block)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
174 block(i).ports = ssmport.initObjectWithSize(1, size(i));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
175 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
176 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
177
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
178
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
179 %% setting methods for ssmblock.ports in ssmblock arrays
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
180 function block = setPortDescriptions(block, portDesc)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
181 for i=1:numel(block)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
182 block(i).ports.setDescription(portDesc{i});
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
183 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
184 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
185
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
186 function block = setPortUnits(block, portUnits)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
187 for i=1:numel(block)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
188 block(i).ports.setUnits(portUnits{i});
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
189 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
190 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
191
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
192 % function block = setPortNames(block, portNames, blockName)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
193 function block = setPortNames(block, portNames)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
194 for i=1:numel(block)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
195 % block(i).ports.setName(portNames{i}, blockName{i});
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
196 block(i).ports.setName(portNames{i}, block(i).name);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
197 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
198 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
199
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
200 %% searching functions
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
201
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
202 % searching ssmblock with Block names
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
203 function [pos, logic] = findBlockWithNames(varargin)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
204 block = varargin{1};
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
205 names = varargin{2};
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
206 if nargin == 2
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
207 doWarningMSG = true;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
208 elseif nargin == 3
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
209 doWarningMSG = varargin{3};
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
210 else
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
211 error('### unknown call')
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
212 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
213 % returns position of names found in ssmblock
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
214 if ischar(names), names = {names}; end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
215 pos = zeros(1, numel(names));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
216 logic = false(1, numel(names));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
217 blockNames = block.blockNames;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
218 for i=1:numel(names)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
219 logic_i = strcmpi(blockNames, names{i});
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
220 if sum(logic_i)>0;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
221 pos(i) = find(logic_i,1);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
222 logic(i) = true;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
223 else
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
224 % the case where "blockname" was not found
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
225 if doWarningMSG
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
226 display(['### No matching block was found for ' names{i} ' !!!'] )
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
227 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
228 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
229 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
230 % removing position for not-found entries
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
231 pos = pos(logic);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
232 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
233
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
234 % searching Ports with Port and Block names
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
235 function [blockPos portPos logic] = findPortWithMixedNames(block, names)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
236 % takes as an input:
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
237 % 'ALL' / 'NONE' / cellstr(blockNames || blockName.portNames)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
238 % returns : position of port/block, and a logical array telling if
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
239 % the name was found
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
240 if ischar(names)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
241 if strcmpi(names, 'ALL')
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
242 % case 'ALL'
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
243 logic = true;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
244 blockPos = zeros(1, 0);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
245 portPos = zeros(1, 0);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
246 Nports = block.Nports;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
247 for i=1:numel(block)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
248 blockPos = [blockPos ones(1,Nports(i))*i]; %#ok<AGROW>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
249 portPos = [portPos 1:Nports(i)]; %#ok<AGROW>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
250 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
251 return
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
252 elseif strcmpi(names, 'NONE')
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
253 % case 'NONE'
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
254 logic = true;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
255 blockPos = zeros(1, 0);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
256 portPos = zeros(1, 0);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
257 return
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
258 else
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
259 % case 'portName' or 'blockName' with an input string
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
260 names = {names};
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
261 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
262 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
263 % case 'portName' or 'blockName'
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
264 logic = false(1, numel(names));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
265 blockPos = zeros(1, 0);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
266 portPos = zeros(1, 0);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
267 portNames = block.portNames;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
268 blockNames = block.blockNames;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
269 Nports = block.Nports;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
270 for i=1:numel(names)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
271 found = strcmpi(blockNames, names{i});
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
272 if sum(found)>0;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
273 % case where the "blockName" is provided
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
274 position = find(strcmpi(blockNames, names{i}), 1);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
275 blockPos = [blockPos ones(1,Nports(position))*position]; %#ok<AGROW>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
276 portPos = [portPos 1:Nports(position)]; %#ok<AGROW>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
277 logic(i) = true;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
278 else
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
279 % case where a "(*)portname" is provided
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
280 blockName = ssmblock.splitName(names{i});
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
281 % case where the "blockName.portname" is provided
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
282 posBlock = findBlockWithNames(block, blockName, false);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
283 if ~posBlock == 0
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
284 for j=posBlock
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
285 posPortLogic = strcmpi(portNames{j}, names{i});
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
286 if sum(posPortLogic)>0;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
287 blockPos = [blockPos, j]; %#ok<AGROW>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
288 portPos = [portPos find(posPortLogic, 1)]; %#ok<AGROW>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
289 logic(i) = true;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
290 break;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
291 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
292 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
293 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
294 % the case where no (*).portname / blockname was found
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
295 if ~logic(i)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
296 % possibility where the block name is not matching between port and block
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
297 for jj=1:numel(blockNames)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
298 posPortLogic = strcmpi(portNames{jj}, names{i});
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
299 if sum(posPortLogic)>0;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
300 blockPos = [blockPos, jj]; %#ok<AGROW>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
301 portPos = [portPos find(posPortLogic, 1)]; %#ok<AGROW>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
302 logic(i) = true;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
303 break;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
304 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
305 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
306 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
307 if ~logic(i)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
308 display(['### No matching block/port was found for key "' names{i} '" !!!'] )
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
309 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
310 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
311 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
312 blockPos = blockPos(blockPos>0);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
313 portPos = portPos(portPos>0);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
314 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
315
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
316 % searching Block Names with a given Block
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
317 function index = makeBlockLogicalIndex(block, names)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
318 % returns a binary index for the ssmblock
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
319 if ischar(names), names = {names}; end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
320 blockNames = block.blockNames;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
321 index = false(1, numel(block));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
322 for i=1:numel(names)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
323 found = strcmpi(blockNames, names{i});
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
324 index = index + found;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
325 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
326 index = index>0;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
327 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
328
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
329 % searching in Mixed Names with a given Block/Ports
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
330 function index = makePortLogicalIndex(block, names)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
331 % takes as an input:
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
332 % 'ALL'/'NONE'/cellstr(portnames)/
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
333 % cellstr(blockName.portnames)/ cellstr(blockName_portnames)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
334 % returns a binary index for the ssmblock
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
335 Nports = block.Nports;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
336 index = cell(1, numel(block));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
337 if ischar(names)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
338 if strcmpi(names, 'ALL')
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
339 % case 'ALL'
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
340 for i=1:numel(block)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
341 index{i} = true(1,Nports(i));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
342 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
343 return
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
344 elseif strcmpi(names, 'NONE')
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
345 % case 'NONE'
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
346 for i=1:numel(block)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
347 index{i} = false(1,Nports(i));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
348 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
349 return
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
350 else
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
351 % case 'portName' or 'blockName'
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
352 names = {names};
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
353 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
354 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
355 if iscellstr(names)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
356 % case {'portName' or 'blockName'}
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
357 [blockPos portPos] = findPortWithMixedNames(block, names);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
358 blockPos = blockPos(blockPos>0);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
359 portPos = portPos(portPos>0);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
360 for i=1:numel(block)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
361 index{i} = false(1,Nports(i));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
362 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
363 for i=1:numel(blockPos)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
364 index{blockPos(i)}(portPos(i)) = true;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
365 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
366 else
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
367 % case {{logical} or {double}}
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
368 if ~numel(names)==numel(block)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
369 error('Number of logical/double does not match the number of blocks')
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
370 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
371 for i=1:numel(block)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
372 if isa(names{i},'logical')
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
373 index{i} = names{i};
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
374 elseif isa(names{i},'double')
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
375 index{i} = false(1,Nports(i));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
376 index{i}(names{i}) = true(1, numel(names{i}));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
377 if max(names{i})>Nports(i)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
378 error(['index is too large for indexed field : ' num2str(max(names{i}))...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
379 ' instead of ' num2str(Nports(i)) ' for the block called ' block.blockNames{i}]);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
380 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
381 else
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
382 display(names)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
383 error(['input field names is not "ALL", "NONE", not a cellstr, nor a cell with logical/binaries '...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
384 'but instead it is of class ' class(names{i}) ' for the block called ' block.blockNames{i}])
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
385 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
386 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
387 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
388 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
389
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
390 %% indexing functions
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
391 function varargout = applyBlockPositionIndex(block, pos)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
392 % selects blocks depending on a double array index, order is not modified
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
393 block = copy(block, nargout);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
394 warning('LTPDA:ssmblock', 'this function was modified, check behavior is okay')
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
395 index = false(1, numel(block));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
396 for i=1:numel(pos)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
397 index(pos(i)) =true;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
398 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
399 varargout = {block(index)};
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
400 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
401
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
402 function varargout = applyPortPositionIndex(block, blockPos, portPos)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
403 % selects ports depending on a double array index. Order of blocks
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
404 % and ports are not modified
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
405 block = copy(block, nargout);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
406 Nports = block.Nports;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
407 index = cell(1, numel(block));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
408 for i=1:numel(block)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
409 index{i} = false(1,Nports(i));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
410 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
411 for i=1:numel(blockPos)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
412 if ~blockPos(i)==0
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
413 index{blockPos(i)}(portPos(i)) = true;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
414 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
415 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
416 for i=1:numel(block)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
417 block(i).ports = block(i).ports(index{i});
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
418 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
419 varargout = {block};
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
420 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
421
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
422 function varargout = applyBlockLogicalIndex(block, logic)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
423 % selects blocks depending on a double array index, order is not
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
424 % modified
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
425 block = copy(block, nargout);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
426 varargout = {block(logic)};
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
427 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
428
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
429 function varargout = applyPortLogicalIndex(block, logic)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
430 % selects ports depending on a double array index. Order of blocks
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
431 % and ports are not modified
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
432 block = copy(block, nargout);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
433 for i=1:numel(block)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
434 block(i).ports = block(i).ports(logic{i});
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
435 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
436 varargout = {block};
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
437 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
438
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
439 %% older search functions
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
440 % simple block names search
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
441 % deprecated and replaced by findBlockWithNames
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
442 function [res, pos] = posBlock(varargin)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
443 error('this function is deprecated and replaced by findBlockWithNames');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
444 objs = varargin{1};
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
445 name = varargin{2};
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
446 if ~ischar(name)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
447 error('### The ''name'' must be a string but it is from the class %s.', class(name));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
448 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
449 res = 0;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
450 pos = 0;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
451 for ii = 1:numel(objs)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
452 if strcmpi(objs(ii).name, name)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
453 res = 1;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
454 pos = ii;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
455 break
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
456 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
457 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
458 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
459
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
460 % logical port indexing using complex entries
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
461 % deprecated and replaced by makePortLogicalIndex
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
462 varargout = makePortIndex(varargin) % can be removed now
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
463
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
464 % simple block names search
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
465 % deprecated and replaced by findPortWithMixedNames
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
466 [blockNumber portNumber] = findPorts(block, data) % can be removed now
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
467
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
468 %% older indexing functions
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
469 % simple block names search
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
470 % deprecated and replaced by applyPortLogicalIndex
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
471 function varargout = blocksPrune(sb, id)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
472 error('this function is deprecated and replaced by applyPortLogicalIndex');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
473 % Check input objects
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
474 if ~isa(sb, 'ssmblock')
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
475 error('### The first input must be a ssmblock.');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
476 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
477 if ~isa(id, 'cell')
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
478 error('### The second input must be a cell array.')
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
479 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
480 % Decide on a deep copy or a modify
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
481 sb = copy(sb, nargout);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
482 for ii=1:numel(sb)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
483 sb(ii).ports = sb(ii).ports(id{ii});
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
484 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
485 varargout{1} = sb;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
486 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
487
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
488 function block2 = mergeBlocksWithPositionIndex(block, blockIndex, portIndex, blockName)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
489 % takes as an input indexes of a ssmblock array, and returns one
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
490 % block with all the selected ports within
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
491 [groupedBlockIndex, groupedPortIndex, groupSize, nGroups, globalPortIndex] = ssmblock.groupIndexes(blockIndex, portIndex);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
492
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
493 if numel(blockIndex)~=numel(portIndex)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
494 error('different lengths of indexes!')
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
495 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
496 nPorts = numel(blockIndex);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
497 block2 = ssmblock;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
498 if numel(strfind(blockName,'.'))>0
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
499 error('The "." is not allowed in ssmport name')
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
500 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
501 if numel(strfind(blockName,' '))>0
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
502 error('The space " " is not allowed in ssmport name')
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
503 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
504 block2.name = upper(blockName);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
505
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
506 block2.ports = ssmport.initObjectWithSize(1,nPorts);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
507 for ii=1:nGroups
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
508 block2.ports(globalPortIndex{ii}) = block(groupedBlockIndex(ii)).ports(groupedPortIndex{ii});
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
509 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
510 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
511
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
512 function varargout = combine(varargin)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
513 objs = utils.helper.collect_objects(varargin(:), 'ssmblock');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
514 pos = findBlockWithNames(objs, objs.blockNames, false);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
515 keep = (pos == 1:numel(pos));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
516 varargout{1} = objs(keep);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
517 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
518
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
519 end % -------- Declaration of Public Hidden methods --------
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
520
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
521 %% -------- Declaration of Private Static methods --------
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
522 methods (Static=true, Access=private)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
523 end % -------- Declaration of Private Static methods --------
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
524
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
525 %% -------- Declaration of Public Static methods --------
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
526 methods (Static=true)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
527
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
528 function out = VEROUT()
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
529 out = '$Id: ssmblock.m,v 1.29 2011/03/28 17:02:29 ingo Exp $';
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
530 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
531
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
532 function ii = getInfo(varargin)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
533 ii = utils.helper.generic_getInfo(varargin{:}, 'ssmblock');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
534 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
535
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
536 function out = SETS()
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
537 out = {'Default'};
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
538 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
539
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
540 function out = getDefaultPlist(set)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
541 switch lower(set)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
542 case 'default'
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
543 out = plist();
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
544 otherwise
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
545 error('### Unknown set [%s]', set);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
546 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
547 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
548
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
549 function obj = initObjectWithSize(n,m)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
550 obj = ssmblock.newarray([n m]);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
551 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
552
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
553 end %% -------- Declaration of Public Static methods --------
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
554
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
555 %% -------- Declaration of Hidden Static methods --------
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
556 methods(Static = true, Hidden = true)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
557
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
558 varargout = loadobj(varargin)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
559 varargout = update_struct(varargin);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
560
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
561 %% factory constructors
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
562 function sb = makeBlocksWithSize(sizes, names)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
563 if ~isa(sizes,'double')
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
564 error('### first argument must be a double');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
565 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
566 if ischar(names)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
567 names = {names};
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
568 elseif ~iscellstr(names)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
569 error('### second argument must be a char/cellstr');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
570 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
571 Nsb = numel(sizes);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
572 sb = ssmblock.initObjectWithSize(1,Nsb);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
573 sb.setBlockNames(names);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
574 for ii=1:Nsb
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
575 sb(ii).ports = ssmport.initObjectWithSize(1,sizes(ii));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
576 sb(ii).ports.setName('', sb(ii).name);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
577 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
578 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
579
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
580 function sb = makeBlocksWithData(names, descriptions, varnames, varunits, vardescriptions)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
581 if ~iscellstr(names)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
582 error('first argument must be a cellstr');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
583 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
584 Nsb = numel(names);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
585 % checking which parameters to set
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
586 setdescriptions = Nsb == numel(descriptions);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
587 setvarnames = Nsb == numel(varnames);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
588 setvarunits = Nsb == numel(varunits);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
589 setvardescriptions = Nsb == numel(vardescriptions);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
590 sb = ssmblock.initObjectWithSize(1,Nsb);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
591 for ii=1:Nsb
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
592 if setdescriptions
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
593 sb(ii).description = descriptions{ii};
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
594 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
595 if setvarnames||setvarunits||setvardescriptions
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
596 % checking if ports can be initialized
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
597 if setvarnames
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
598 Nports = numel(varnames{ii});
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
599 elseif setvarunits
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
600 Nports = numel(varunits{ii});
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
601 elseif setvardescriptions
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
602 Nports = numel(vardescriptions{ii});
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
603 else
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
604 Nports = 0;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
605 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
606 sb(ii).ports = ssmport.initObjectWithSize(1,Nports);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
607 % setting ports properties
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
608 if setvarnames
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
609 sb(ii).ports.setName(varnames{ii}, upper(names{ii}));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
610 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
611 if setvarunits
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
612 sb(ii).ports.setUnits(varunits{ii});
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
613 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
614 if setvardescriptions
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
615 sb(ii).ports.setDescription(vardescriptions{ii});
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
616 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
617 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
618 % setting name in the end so the port name prefixes are modified
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
619 sb(ii).setBlockNames(names{ii});
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
620 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
621
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
622 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
623
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
624 %% index transformation for ssmports and blockMat in ssm/reshuffle,
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
625 function [groupedBlockIndex, groupedPortIndex, groupSize, nGroups, globalPortIndex] = groupIndexes(blockIndex, portIndex)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
626 % groupedBlockIndex : block # (double array) (same block can be
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
627 % repeated, but never twice sided-by-side, Preserves the order
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
628 % provided by user)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
629 % groupedPortIndex : port # (cell array of doubles, Preserves the order
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
630 % provided by user)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
631 % groupSize : numel of each double in the cell array groupedPortIndex
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
632 % nGroups : numel of the cell array
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
633 % globalPortIndex : first index for each port if aill arrays are concatenated
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
634 %% detecting groups
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
635 diffBlock = [[0 find(diff(blockIndex)~=0)]+1 numel(blockIndex)+1];
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
636 if diffBlock(end)==1
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
637 nGroups = 0;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
638 else
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
639 nGroups = numel(diffBlock)-1;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
640 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
641 %% creating output index arrays
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
642 groupedPortIndex = cell(1, nGroups);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
643 groupedBlockIndex = zeros(1, nGroups);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
644 groupSize = zeros(1, nGroups);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
645 for kk=1:nGroups
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
646 groupedPortIndex{kk} = portIndex(diffBlock(kk):diffBlock(kk+1)-1);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
647 groupedBlockIndex(kk) = blockIndex(diffBlock(kk));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
648 groupSize(kk) = diffBlock(kk+1)-diffBlock(kk);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
649 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
650 %% final cumulative index
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
651 globalPortIndex = cell(1, nGroups);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
652 sumGroupedSize = cumsum([1 groupSize]);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
653 for kk=1:nGroups
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
654 globalPortIndex{kk} = sumGroupedSize(kk):(sumGroupedSize(kk+1)-1);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
655 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
656 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
657
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
658
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
659 %% string support for names
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
660 function [blockName, portName] = splitName(name)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
661 location = strfind(name, '.');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
662 if numel(location)>0
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
663 if numel(location)>1
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
664 error('There were more than one dot in a name!')
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
665 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
666 blockName = name(1:(location-1));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
667 portName = name((location+1):end);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
668 else
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
669 error(['Could not find the "." in the port named "' name '". ' ...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
670 'The indexing has changed! Please copy the portname with a "." as in "BLOCKNAME.portname".' ])
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
671 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
672 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
673
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
674 function [blockName, portName, worked] = reSplitName(blockName, portName)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
675 warning('This function is deprecated and will be removed. Please report if it was found to be used')
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
676 location = strfind(portName, '_');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
677 worked = numel(location)>0;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
678 if worked
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
679 blockName = [blockName '_' portName(1:(location(1)-1))];
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
680 portName = portName((location(1)+1):end);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
681 else
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
682 blockName = '';
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
683 portName = '';
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
684 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
685 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
686
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
687 end %% -------- Declaration of Hidden Static methods --------
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
688
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
689 %% -------- Declaration of Private methods --------
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
690 methods(Access = private)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
691 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
692
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
693 methods (Access = protected)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
694 varargout = fromStruct(varargin)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
695 varargout = fromDom(varargin)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
696 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
697
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
698 end
|