comparison m-toolbox/classes/@ssmblock/findPorts.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: MAKEPORTINDEX2 gives a an array of port positions
5 %
6 % CALL: [blockNumber portNumber] = makePortIndex(varargin)
7 %
8 % makePortIndex(ssmblock, cellstr)
9 % makePortIndex(ssmblock, str)
10 %
11 % INPUTS:
12 % select - input index:
13 % - cellstr,
14 % - cell array including
15 % - 'ALL'/'NONE' to index all/no content,
16 % - chars with port/block names
17 % - a str for one variable name only, 'ALL'/'NONE'
18 %
19 % OUTPUTS:
20 % blockNumber - block index
21 % portNumber - port index
22 %
23 % ***** There are no parameters *****
24 %
25 % VERSION: '$Id: findPorts.m,v 1.3 2010/08/27 12:55:30 adrien Exp $'
26 %
27 %
28 % HISTORY:
29 % 24-09-2008 A Grynagier
30 %
31 % TO DO :
32 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
33
34 function [blockNumber portNumber] = findPorts(block, data)
35 error('This function is deprecated and will be deleted')
36
37
38 if ~isa(block, 'ssmblock')
39 error('block is not an ssmblock object')
40 end
41 if ischar(data)
42 data = {data};
43 end
44
45 if iscellstr(data)
46 if numel(data) == 1 && strcmpi(data{1}, 'all')
47 [blockNumber portNumber] = forAll(block);
48 elseif numel(data) == 1 && strcmpi(data{1}, 'none')
49 [blockNumber portNumber] = forNone();
50 else
51 [blockNumber portNumber] = fromNames(block, data);
52 end
53 else
54 display(data)
55 error('parameter ''data'' is of wrong type')
56 end
57 end
58
59 function [blockNumber portNumber] = forAll(block)
60 nBlocks = numel(block) ;
61 nPorts = block.Nports;
62 nPortsTot = sum(nPorts);
63
64 blockNumber = zeros(nPortsTot,1);
65 portNumber = zeros(nPortsTot,1);
66
67 k = 1;
68 for i=1:nBlocks
69 for j=1:nPorts(i)
70 blockNumber(k) = i;
71 portNumber(k) = j;
72 k = k+1;
73 end
74 end
75 end
76
77 function [blockNumber portNumber] = forNone()
78 blockNumber = zeros(1,0);
79 portNumber = zeros(1,0);
80 end
81
82 function [blockNumber portNumber] = fromNames(block, data)
83 nBlocks = numel(block) ;
84 nPorts = block.Nports;
85
86 blockNumber = zeros(1,0);
87 portNumber = zeros(1,0);
88 portNames = block.portNames;
89
90 for i=1:numel(data)
91 [isin, pos] = posBlock(block, data{i});
92 if isin
93 % indexing full block
94 blockNumber = [blockNumber ones(1,nPorts(pos))*pos]; %#ok<AGROW>
95 portNumber = [portNumber 1:nPorts(pos)]; %#ok<AGROW>
96 else
97 % looking for a port to index
98 for ii = 1:nBlocks
99 found = strcmpi(portNames{ii}, data{i});
100 wasFound = sum(found)>0;
101 if wasFound;
102 blockNumber = [blockNumber ii]; %#ok<AGROW>
103 portNumber = [portNumber find(found)]; %#ok<AGROW>
104 break
105 end
106 end
107 if ~wasFound
108 display(['block or port ' data{i} ' was not found!'])
109 end
110 end
111 end
112 end
113