Mercurial > hg > ltpda
comparison m-toolbox/classes/@ssmblock/makePortIndex.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 % MAKEPORTINDEX gives indexes of selected in a series of list in a cell array | |
2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
3 % | |
4 % DESCRIPTION: MAKEPORTINDEX gives a cell array of binary indexes | |
5 % | |
6 % CALL: varargout = makePortIndex(varargin) | |
7 % | |
8 % makePortIndex(cellstr, embeddedplist) | |
9 % makePortIndex(embeddedplist_selection, embeddedplist) | |
10 % makePortIndex(cellstr, embeddedplist) | |
11 % makePortIndex(char, embeddedplist) | |
12 % makePortIndex('all', sizes) | |
13 % makePortIndex('none', sizes) | |
14 % makePortIndex('all', embeddedplist) | |
15 % makePortIndex('none', embeddedplist) | |
16 % makePortIndex(mixed_cell, sizes) | |
17 % makePortIndex(mixed_cell, embeddedplist) | |
18 % | |
19 % INPUTS: | |
20 % select - input index: | |
21 % - cellstr, | |
22 % - cell array including | |
23 % - array indexes with doubles or logicals, | |
24 % - 'ALL'/'NONE' to index all/no content, | |
25 % - a str for one variable name only | |
26 % - a cellstr for multiple variables | |
27 % - a str for one variable name only | |
28 % names - embedded plist giving block position names, used in case of cellstr | |
29 % sizes - vector giving block sizes, required in case of mixed cell | |
30 % array | |
31 % indexing | |
32 % | |
33 % OUTPUTS: | |
34 % index_out - index for the cell array of logical arrays | |
35 % | |
36 % ***** There are no parameters ***** | |
37 % | |
38 % VERSION: '$Id: makePortIndex.m,v 1.8 2010/08/27 12:55:30 adrien Exp $' | |
39 % | |
40 % | |
41 % HISTORY: | |
42 % 24-09-2008 A Grynagier | |
43 % | |
44 % TO DO : | |
45 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
46 | |
47 function varargout = makePortIndex(varargin) | |
48 | |
49 error('this function is deprecated and replaced by makePortLogicalIndex'); | |
50 | |
51 select = varargin{2}; | |
52 if isempty(select) | |
53 index_out = from_cellstr({}, varargin{1}); | |
54 elseif iscellstr(select) | |
55 index_out = from_cellstr(select, varargin{1}); | |
56 elseif isa(select, 'cell') | |
57 index_out = from_mixed_cell(select, varargin{1}); | |
58 elseif isa(select,'char') | |
59 index_out = from_char(select, varargin{1}); | |
60 elseif isa(select,'plist') | |
61 index_out = from_plist(select, varargin{1}); | |
62 else | |
63 error('parameter ''select'' is of wrong type') | |
64 end | |
65 varargout = {index_out}; | |
66 end | |
67 | |
68 function index_out = from_plist(select, sb) %#ok<INUSD,STOUT> | |
69 error('not implemented yet! - to do when GUI input plist is defined') | |
70 end | |
71 | |
72 function index_out = from_cellstr(select, sb) | |
73 if ~isa(sb,'ssmblock') | |
74 error(['second argument ''sb'' is not a ssmblock but a ' class(sb)]) | |
75 end | |
76 | |
77 % detecting block sizes | |
78 Nblocks = numel(sb); | |
79 sizes = sb.Nports; | |
80 | |
81 % initializing output | |
82 index_out = cell(1,Nblocks); | |
83 for i=1:Nblocks | |
84 index_out{i} = false(1, sizes(i)); | |
85 end | |
86 | |
87 % looking for names | |
88 for i=1:numel(select) | |
89 %looking for block names | |
90 [isin, pos] = posBlock(sb, select{i}); | |
91 if isin | |
92 index_out{pos} = true(size(index_out{pos})); | |
93 else | |
94 % otherwise looking for variable names | |
95 for j=1:Nblocks | |
96 [isin, pos] = posPort(sb(j).ports, select{i}); | |
97 if isin | |
98 index_out{j}(pos) = true; | |
99 break; | |
100 end | |
101 end | |
102 end | |
103 end | |
104 | |
105 end | |
106 | |
107 function index_out = from_char(select, argument2) | |
108 | |
109 % looking at second input if it is | |
110 if ~(isa(argument2,'ssmblock') || isa(argument2,'double')) | |
111 display(argument2) | |
112 display(class(argument2)) | |
113 error('second argument ''sizes'' is not a ssmblock nor a double array') | |
114 end | |
115 | |
116 | |
117 if strcmpi(select, 'ALL') | |
118 if isa(argument2,'ssmblock') | |
119 Nblocks = numel(argument2); | |
120 sizes = argument2.Nports; | |
121 else | |
122 sizes = argument2; | |
123 Nblocks = numel(sizes); | |
124 end | |
125 index_out = cell(1, Nblocks); | |
126 % index all positions | |
127 for i=1:Nblocks | |
128 index_out{i} = true(1,sizes(i)); | |
129 end | |
130 elseif strcmpi(select, 'NONE') | |
131 if isa(argument2,'ssmblock') | |
132 Nblocks = numel(argument2); | |
133 sizes = argument2.Nports; | |
134 else | |
135 sizes = argument2; | |
136 Nblocks = numel(sizes); | |
137 end | |
138 index_out = cell(1, Nblocks); | |
139 % index all positions | |
140 for i=1:Nblocks | |
141 index_out{i} = false(1,sizes(i)); | |
142 end | |
143 else | |
144 if isa(argument2,'ssmblock') | |
145 % warning('adding ''{'' ''}'' around variable name for indexing'); %#ok<*WNTAG> | |
146 index_out = from_cellstr({select}, argument2); | |
147 else | |
148 warning('error in the call index_out(char, embeddedplist) because the plist is not a plist'); | |
149 end | |
150 end | |
151 | |
152 end | |
153 | |
154 function index_out = from_mixed_cell(select, argument2) | |
155 if isa(argument2,'ssmblock') | |
156 % detecting block sizes | |
157 Nblocks = numel(argument2); | |
158 sizes = argument2.Nports; | |
159 forbidchar = false; | |
160 else | |
161 sizes = argument2; | |
162 Nblocks = numel(sizes); | |
163 forbidchar = true; | |
164 end | |
165 | |
166 index_out = cell(1,Nblocks); | |
167 % going through blocks | |
168 for i=1:Nblocks | |
169 if iscellstr(select{i}) % variable names indexing | |
170 if forbidchar | |
171 error('trying to index using variable names without variable name information') | |
172 end | |
173 index_out{i} = false(1,sizes(i)); | |
174 for j=1:sizes(i) | |
175 index_out{i}(j) = (sum(strcmpi(argument2(i).ports(j).name, select{i}))>0); | |
176 end | |
177 elseif isa(select{i}, 'char') | |
178 if strcmpi(select{i}, 'ALL') % keyword indexing | |
179 index_out{i} = true(1, sizes(i)); | |
180 elseif strcmpi(select{i}, 'none') % keyword indexing | |
181 index_out{i} = false(1, sizes(i)); | |
182 else % variable names indexing | |
183 if forbidchar | |
184 error('trying to index using variable names without variable name information') | |
185 end | |
186 index_out{i} = false(1,sizes(i)); | |
187 for j=1:sizes(i) | |
188 index_out{i}(j) = (sum(strcmpi(argument2(i).ports(j).name, select{i}))>0); | |
189 end | |
190 end | |
191 elseif isa(select{i},'double') % double indexing | |
192 index_out{i} = false(1, sizes(i)); | |
193 for j=1:length(select{i}) | |
194 index_out{i}(select{i}(j))=true; | |
195 end | |
196 elseif isa(select{i},'logical') % logical indexing | |
197 index_out{i} = select{i}; | |
198 if ~length(select{i})==sizes(i) | |
199 error(['parameter ''select'' is of wrong size for block numer ', num2str(i)]); | |
200 end | |
201 else | |
202 error('parameter ''select'' is of wrong type') | |
203 end | |
204 end | |
205 end | |
206 | |
207 function [res, pos] = posPort(objs, name) | |
208 %%%%%%%%%% Some plausibility checks %%%%%%%%%% | |
209 if ~ischar(name) | |
210 error('### The ''name'' must be a string but it is from the class %s.', class(name)); | |
211 end | |
212 res = 0; | |
213 pos = 0; | |
214 for ii = 1:numel(objs) | |
215 if strcmpi(objs(ii).name, name) | |
216 res = 1; | |
217 pos = ii; | |
218 break | |
219 end | |
220 end | |
221 end |