0
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1 function [cmds, rbs] = parseBlocks(blocks, wb, varID)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
3 cmds = {};
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
4 rbs = [];
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
5 Nrbs = awtinvoke(blocks, 'size');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
6
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
7
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
8 % loop over blocks
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
9 for jj=1:Nrbs
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
10 block = awtinvoke(blocks, 'get', jj-1);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
11
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
12 if ~block.isCommentedOut
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
13 rbs = [rbs block];
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
14 bname = char(block.getName);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
15 % if exist(bname) > 1 || ~isvarname(bname)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
16 % error('The block named "%s" is not a valid variable name. \nPlease rename it.', bname);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
17 % end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
18
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
19 % if this is a MATBlock we treat it differently since it has
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
20 % no plist.
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
21 if isa(block, 'mpipeline.canvas.MATBlock')
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
22
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
23 cmds = parseMATblock(cmds, block, varID);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
24
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
25 elseif isa(block, 'mpipeline.canvas.PipelineBlock')
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
26
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
27 cmds = parsePipelineBlock(cmds, block, varID);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
28
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
29 elseif isa(block, 'mpipeline.canvas.MATfcn')
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
30
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
31 cmds = parseMATfcn(cmds, block, varID);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
32
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
33 elseif isa(block, 'mpipeline.canvas.MTerminal')
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
34 % Terminals are not executed. They are skipped over when asking
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
35 % for source and child blocks; that's handled on the java side.
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
36 elseif isa(block, 'mpipeline.canvas.MConstant')
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
37 % Don't do anything, we did this at the beginning of
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
38 % execution
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
39 elseif isa(block, 'mpipeline.canvas.Mux')
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
40
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
41 cmds = parseMux(cmds, block, varID);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
42
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
43 elseif isa(block, 'mpipeline.canvas.Demux')
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
44
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
45 cmds = parseDemux(cmds, block, varID);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
46
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
47 elseif isa(block, 'mpipeline.canvas.ToWorkspace')
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
48
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
49 cmds = parseToWorkspace(cmds, block, varID);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
50
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
51 else
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
52
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
53 cmds = parseLTPDAblock(cmds, block, wb, varID);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
54
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
55 end % End if on block type
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
56 end % End if block commented out
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
57 end % End loop over blocks
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
58 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
59
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
60
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
61 %--------------------------------------------------------------------------
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
62 % Parse a ToWorkspace block
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
63 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
64 function cmds = parseToWorkspace(cmds, block, varID)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
65
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
66 % loop over inputs to make input vars
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
67 inputs = block.getInputs();
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
68
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
69 % Loop over the inputs to get the variable names of the inputs
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
70 for kk=0:inputs.size()-1
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
71 ip = inputs.get(kk);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
72 % get the block which is connected to this input
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
73 srcblock = block.getSourceBlock(ip.getNumber);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
74 % get the port number at the source block
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
75 srcportNumber = block.getSourceBlockPortNumber(ip.getNumber);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
76 if ~isempty(srcblock)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
77 varname = LTPDAworkbench.getWS_VarName(varID, srcblock, srcportNumber);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
78
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
79 % get class of the object
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
80 cl = evalin('base', [ 'class(' varname ')']);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
81
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
82 % get new var name
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
83 % - this means split the outvar at the last '.'
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
84 nv = getVar(varname);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
85
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
86 if ismember(cl, utils.helper.ltpda_userclasses)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
87 cmd = [nv ' = copy(' varname ',1);'];
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
88 else
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
89 cmd = [nv ' = ' varname ';'];
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
90 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
91
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
92 cmds = [cmds {cmd}];
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
93 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
94 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
95
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
96 assignin('base', 'cmds', cmds);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
97 clear();
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
98 cmds = evalin('base', 'cmds');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
99
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
100 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
101
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
102
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
103 function nv = getVar(ov)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
104
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
105 nv = '';
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
106
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
107 for kk=length(ov):-1:1
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
108 if ov(kk) == '.'
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
109 break
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
110 else
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
111 nv = [nv ov(kk)];
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
112 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
113 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
114
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
115 nv = nv(end:-1:1);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
116
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
117 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
118
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
119 %--------------------------------------------------------------------------
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
120 % Parse a Demux block
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
121 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
122 function cmds = parseDemux(cmds, block, varID)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
123
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
124 % loop over inputs to make input vars
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
125 inputs = block.getInputs();
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
126
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
127 % Demux has one input
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
128 ip = inputs.get(0);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
129 % get the block which is connected to this input
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
130 srcblock = block.getSourceBlock(ip.getNumber);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
131 % get the port number at the source block
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
132 srcportNumber = block.getSourceBlockPortNumber(ip.getNumber);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
133 if ~isempty(srcblock)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
134 varname = LTPDAworkbench.getWS_VarName(varID, srcblock, srcportNumber);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
135 incmd = [varname];
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
136 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
137
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
138 % make output vars
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
139 outputs = block.getOutputs();
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
140 for kk=1:outputs.size()
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
141 outvar = LTPDAworkbench.getWS_VarName(varID, block, kk-1);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
142 cmds = [cmds {[outvar ' = ' incmd '(' num2str(kk) ');']}];
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
143 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
144
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
145
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
146 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
147
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
148 %--------------------------------------------------------------------------
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
149 % Parse a Mux block
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
150 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
151 function cmds = parseMux(cmds, block, varID)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
152
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
153 % loop over inputs to make input vars
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
154 inputs = block.getInputs();
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
155 incmd = '[';
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
156 varnames = {};
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
157
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
158 % Loop over the inputs to get the variable names of the inputs
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
159 for kk=0:inputs.size()-1
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
160 ip = inputs.get(kk);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
161 % get the block which is connected to this input
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
162 srcblock = block.getSourceBlock(ip.getNumber);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
163 % get the port number at the source block
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
164 srcportNumber = block.getSourceBlockPortNumber(ip.getNumber);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
165 if ~isempty(srcblock)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
166 varname = LTPDAworkbench.getWS_VarName(varID, srcblock, srcportNumber);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
167 varnames = [varnames {varname}];
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
168 incmd = [incmd varname ','];
|
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 if incmd(end)==','
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
172 incmd = incmd(1:end-1);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
173 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
174 incmd = strtrim(incmd);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
175 incmd = [incmd ']'];
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
176 % make output vars
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
177 outputs = block.getOutputs();
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
178 if outputs.size() > 1
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
179 error('### Mux blocks should have only one output.');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
180 elseif outputs.size() == 1
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
181 outcmd = '[';
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
182 for kk=1:outputs.size()
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
183 outvar = LTPDAworkbench.getWS_VarName(varID, block, kk-1);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
184 outcmd = [outcmd outvar ' '];
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
185 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
186 outcmd = strtrim(outcmd);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
187 outcmd = [outcmd '] = '];
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
188 else
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
189 outcmd = '';
|
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 cmds = [cmds {[outcmd incmd ';']}];
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
193
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
194
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
195 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
196
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
197
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
198 %--------------------------------------------------------------------------
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
199 % Parse a command from a MATBlock block
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
200 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
201 function cmds = parsePipelineBlock(cmds, block, varID)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
202
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
203 % get variable name
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
204 outvar = LTPDAworkbench.getWS_VarName(varID, block, 0);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
205
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
206 % Get source port that this block links to
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
207 sp = block.getSourcePort;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
208 % get the parent of that port
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
209 sb = sp.getParent;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
210 % get var name
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
211 srcvar = LTPDAworkbench.getWS_VarName(varID, sb, sp.getNumber);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
212
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
213 % build command string
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
214 cmd = [outvar ' = ' srcvar ';'];
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
215
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
216 % we should check if the srcvar exists
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
217 try
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
218 evalin('base', [srcvar ';']);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
219 catch
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
220 utils.helper.errorDlg(sprintf('Source variable [%s] doesn''t exist. Did you run the required pipeline?', srcvar), 'Pipeline Source Error');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
221 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
222
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
223 cmds = [cmds {cmd}];
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
224
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
225 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
226
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
227
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
228 %--------------------------------------------------------------------------
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
229 % Parse a command from a MATBlock block
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
230 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
231 function cmds = parseMATblock(cmds, block, varID)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
232
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
233 % get variable name
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
234 outvar = LTPDAworkbench.getWS_VarName(varID, block, 0);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
235 % get expression
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
236 exp = char(block.getExpression());
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
237
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
238 % can this expression be evaluated or is it a string?
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
239 try
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
240 evalin('base', [exp ';']);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
241 cmd = [outvar ' = ' exp ';'];
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
242 catch
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
243 cmd = [outvar ' = ''' exp ''';'];
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
244 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
245 cmds = [cmds {cmd}];
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
246
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
247 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
248
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
249
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
250 %--------------------------------------------------------------------------
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
251 % Parse a command from an LTPDA block
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
252 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
253 function cmds = parseLTPDAblock(cmds, block, wb, varID)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
254
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
255 % We have a normal LTPDA block with a plist etc....
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
256
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
257 blockclass = char(block.getMinfo().getMclass);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
258 % build command
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
259 cmd = strrep(char(block.getAlgoName), ' ', '_');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
260
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
261 % make plist for this block
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
262 jpl = block.getPlist();
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
263 pl = LTPDAworkbench.jpl2mpl(jpl);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
264 spl = string(pl);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
265
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
266 % We need to skip any PORT_# when making the inputs
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
267 tks = regexpi(spl, 'PORT_(\d+)', 'tokens');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
268 skipports = [];
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
269 for kk=1:numel(tks)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
270 skipports = [skipports str2double(tks{kk}{1})];
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
271 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
272 % skipports = skipports + 1;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
273 % loop over inputs to make input vars
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
274 inputs = block.getInputs();
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
275 incmd = '(';
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
276 varnames = {};
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
277
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
278 % Loop over the inputs to get the variable names of the inputs
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
279 for kk=0:inputs.size()-1
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
280 ip = inputs.get(kk);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
281 if ~any(ip.getNumber==skipports)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
282 % get the block which is connected to this input
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
283 srcblock = block.getSourceBlock(ip.getNumber);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
284 % get the port number at the source block
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
285 srcportNumber = block.getSourceBlockPortNumber(ip.getNumber);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
286 if ~isempty(srcblock)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
287 varname = LTPDAworkbench.getWS_VarName(varID, srcblock, srcportNumber);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
288 varnames = [varnames {varname}];
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
289 incmd = [incmd varname ','];
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
290 end
|
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 incmd = strtrim(incmd);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
294 incmd = [incmd spl ')'];
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
295 % make output vars
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
296 outputs = block.getOutputs();
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
297 if outputs.size() > 0
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
298 outcmd = '[';
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
299 for kk=1:outputs.size()
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
300 output = outputs.get(kk-1);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
301 outvar = LTPDAworkbench.getWS_VarName(varID, block, output.getNumber);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
302 bits = regexp(outvar, '\.', 'split');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
303 if exist(outvar) > 1 && ~allAreVarNames(bits)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
304 error('The block named "%s" is not a valid variable name. \nPlease rename it.', outvar);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
305 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
306 outcmd = [outcmd outvar ' '];
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
307 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
308 outcmd = strtrim(outcmd);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
309 outcmd = [outcmd '] = '];
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
310 else
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
311 outcmd = '';
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
312 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
313
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
314 % Modify plist constructors looking for PORT_#
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
315 for kk=1:pl.nparams
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
316 if ischar(pl.params(kk).getVal)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
317 idxs = regexpi(pl.params(kk).getVal, '(PORT_\d*)', 'tokens');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
318 repstr = pl.params(kk).getVal;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
319 for ii=1:numel(idxs)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
320 pstr = idxs{ii}{1};
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
321 % get port number
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
322 [s,r] = strtok(pstr, '_');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
323 portNumber = str2num(r(2:end));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
324 % Now we need to find the name of the output variable at the
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
325 % other end of this pipe
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
326 sb = block.getSourceBlock(portNumber);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
327 if ~isa(sb, 'mpipeline.canvas.MElementWithPorts')
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
328 error('### Block %s has an input PORT_%d specified in the plist, \nbut the block has no such input, or the input is not connected to a source block', char(block.getName()), portNumber);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
329 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
330 sbp = block.getSourceBlockPortNumber(portNumber);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
331 sbpn = LTPDAworkbench.getWS_VarName(varID, sb, sbp);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
332 % replace the PORT_# string with the correct variable name
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
333 repstr = strrep(repstr, pstr, char(sbpn));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
334 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
335 % If we modified the parameter value string, then we need to
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
336 % remove the string quotes, and replace this in the string
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
337 % representation of the plist (spl)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
338 if ~strcmp(repstr, pl.params(kk).getVal)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
339 repstr = strrep(repstr, '''', '');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
340 spl = strrep(spl, ['''' pl.params(kk).getVal ''''], repstr);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
341 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
342
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
343 % rebuild incmd
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
344 incmd = '(';
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
345 for ll=1:numel(varnames)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
346 incmd = [incmd varnames{ll} ','];
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
347 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
348 incmd = strtrim(incmd);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
349 incmd = [incmd spl ')'];
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
350 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
351 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
352 comment = ['% ' blockclass];
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
353
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
354 % We do something different if this is a modifier
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
355 if block.isModifier
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
356
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
357 mcmd = [cmd incmd ';' comment];
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
358 if outputs.size() > 1
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
359 error('Block %s is set as a modifier but has more than one output. This is not possible.', char(block.getName));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
360 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
361 cmds = [cmds {mcmd}];
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
362 for kk=1:numel(varnames)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
363 ecmd = [outvar '(' num2str(kk) ') = ' varnames{kk} ';'];
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
364 cmds = [cmds {ecmd}];
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
365 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
366
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
367 else
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
368 cmds = [cmds {[outcmd cmd incmd ';' comment]}];
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
369 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
370
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
371 % add command to set name of block if this is a constructor
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
372 cat = char(block.getMinfo.getMcategory);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
373 if outputs.size() == 1 && strcmpi(cat, 'constructor') && (strcmpi(pl.find('name'), 'None') || isempty(pl.find('name')))
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
374 cmd = {[outvar '.setName(''' char(block.getName()) ''')']};
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
375 cmds = [cmds cmd];
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
376 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
377
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
378 % add command to attach workbench if necessary
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
379 if block.isAttachWorkbench
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
380
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
381 % get the workbench in XML format
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
382 if isa(wb, 'LTPDAworkbench')
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
383 xmlout = char(wb.mp.workbenchAsXMLString);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
384 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
385
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
386 for kk=1:outputs.size()
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
387 outvar = LTPDAworkbench.getWS_VarName(varID, block, kk-1);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
388 bits = regexp(outvar, '\.', 'split');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
389 if exist(outvar) > 1 && ~allAreVarNames(bits)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
390 error('The block named "%s" is not a valid variable name. \nPlease rename it.', outvar);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
391 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
392 cmd = {[outvar '.setMdlfile(''' strrep(xmlout, '''', '''''') ''');']};
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
393 cmds = [cmds cmd];
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
394 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
395
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
396 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
397
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
398 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
399
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
400 function res = allAreVarNames(cs)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
401
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
402 res = true;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
403 for jj=1:numel(cs)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
404 if ~isvarname(cs{jj})
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
405 res = false;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
406 break;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
407 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
408 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
409
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
410 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
411
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
412 %--------------------------------------------------------------------------
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
413 % Parse a command from a MATfcn block
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
414 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
415 function cmds = parseMATfcn(cmds, block, varID)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
416
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
417 % build command
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
418 cmd = char(block.getFcnName);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
419
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
420 % loop over inputs to make input vars
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
421 inputs = block.getInputs();
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
422 incmd = '(';
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
423 varnames = {};
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
424
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
425 % Loop over the inputs to get the variable names of the inputs
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
426 for kk=0:inputs.size()-1
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
427 ip = inputs.get(kk);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
428 % get the block which is connected to this input
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
429 srcblock = block.getSourceBlock(ip.getNumber);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
430 % get the port number at the source block
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
431 srcportNumber = block.getSourceBlockPortNumber(ip.getNumber);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
432 if ~isempty(srcblock)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
433 varname = LTPDAworkbench.getWS_VarName(varID, srcblock, srcportNumber);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
434 varnames = [varnames {varname}];
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
435 incmd = [incmd varname ','];
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
436 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
437 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
438 if incmd(end)==','
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
439 incmd = incmd(1:end-1);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
440 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
441 incmd = strtrim(incmd);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
442 incmd = [incmd ')'];
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
443 % make output vars
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
444 outputs = block.getOutputs();
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
445 if outputs.size() > 0
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
446 outcmd = '[';
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
447 for kk=1:outputs.size()
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
448 outvar = LTPDAworkbench.getWS_VarName(varID, block, kk-1);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
449 outcmd = [outcmd outvar ' '];
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
450 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
451 outcmd = strtrim(outcmd);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
452 outcmd = [outcmd '] = '];
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
453 else
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
454 outcmd = '';
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
455 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
456
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
457 cmds = [cmds {[outcmd cmd incmd ';']}];
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
458 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
459
|