0
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1 function ltpdasim(block)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
3 % This is the automatic function wrapper
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
4 % ========================================================================
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
5 % ==================== level-2 M file S-function =========================
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
6 % ========================================================================
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
7 % This wrapper is the automatic function, called by every function block
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
8 % in Simulink, able to execute m-file functions retrieving from Simulink:
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
9 % (1) the pointer to the object(s) to be analyzed, coming in as input of
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
10 % the corresponding block (ie, the DATA),
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
11 % (2) the name of the function to be applied on those data, from the tag
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
12 % of the currently executed block (ie, the true FUNCTION),
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
13 % (3) the parameters for that particular block, retrieved from the global
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
14 % shared workspace by the handle of the block (ie, the PARAMETERS).
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
15 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
16 % The output is then generated as:
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
17 % OUTPUT = FUNCTION(DATA,PARAMETERS)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
18 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
19 % This output in the end is saved into the global array containing all
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
20 % the AOs (ie, all the DATA go together with other data): thus this output
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
21 % will be freely accessible by all the other functions.
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
22 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
23 % The only real output to Simulink will be just the ordinal number of the
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
24 % so-generated AO into the global array of AOs.
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
25 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
26 % $Id: ltpdasim.m,v 1.37 2008/12/01 20:03:51 nicola Exp $
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
27
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
28
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
29 setup(block);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
30
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
31
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
32 %% Setup
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
33
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
34 function setup(block)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
35
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
36 % Register dialog parameter: none, because they're retrieved directly
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
37 % from the memory. This will prevent the user to modify the parameters
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
38 % outside the proper parameters panel:
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
39 block.NumDialogPrms = 0;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
40
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
41 % Register number of input and output ports
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
42 block.NumInputPorts = 1;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
43 block.NumOutputPorts = 1;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
44
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
45 % Setup functional port properties to dynamically inherited.
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
46 block.SetPreCompInpPortInfoToDynamic;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
47
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
48 block.InputPort(1).DirectFeedthrough = true;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
49 block.InputPort(1).DatatypeID = 0;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
50 block.InputPort(1).Complexity = 0;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
51 block.OutputPort(1).DatatypeID = 0;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
52 block.OutputPort(1).Complexity = 0;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
53 block.SampleTimes = [0 0];
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
54 block.SetAccelRunOnTLC(false);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
55
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
56 block.OutputPort(1).Dimensions = 1;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
57
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
58 % Register methods
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
59 block.RegBlockMethod('SetInputPortSamplingMode',@SetInpPortFrameData);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
60 block.RegBlockMethod('SetInputPortDimensions', @SetInpPortDims);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
61 block.RegBlockMethod('Outputs', @Outputs);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
62
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
63 function SetInpPortFrameData(block, idx, fd) %#ok<INUSL>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
64 block.InputPort(1).SamplingMode = fd;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
65 block.OutputPort(1).SamplingMode = fd;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
66
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
67 function SetInpPortDims(block, idx, di)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
68 block.InputPort(idx).Dimensions = di;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
69
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
70
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
71 %% Outputs
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
72 function Outputs(block)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
73 global LTPDAinvar gl loop execModels %#ok<NUSED>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
74
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
75 % disp(['The name of the currently executed block is ',get_param(get_param(gcbh,'Parent'),'Name')])
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
76 % disp(['The current size of LTPDAinvar is ',num2str(size(LTPDAinvar,1))])
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
77
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
78 currparent = get_param(gcbh,'Parent');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
79 subsyshandle = get_param(currparent, 'handle');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
80
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
81 % Check if it's a partial execution:
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
82 if ismember('executionList',evalin('base','who'))
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
83 executionList = evalin('base','executionList');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
84 blockIndex = -1;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
85 for i=1:size(executionList,1), if executionList(i)==gcbh, blockIndex = i; break; end; end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
86 if blockIndex == -1 % this block is not included in the list of those to be executed.
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
87 disp([' . Partial execution: block ',get_param(subsyshandle,'Name'),' will be skipped.'])
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
88 block.OutputPort(1).Data = -1;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
89 return
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
90 else
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
91 % Check if the block must receive data from Simulink or retrieve them from a previous calculation:
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
92 if block.InputPort(1).Data(1)==-1
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
93 annotation = find_system(bdroot,'FindAll','on','Type','Annotation','Tag','ltpda model');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
94 execHistory = get_param(annotation,'UserData');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
95 blockIndex = -1;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
96 for i=1:size(execHistory,1), if execHistory{i,2}==subsyshandle, blockIndex = i; end; end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
97 if blockIndex == -1 % something's wrong: the selected block is not included in the previous execution history
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
98 warning(['*** Partial execution: impossible to retrieve inputs. The block ',get_param(subsyshandle,'Name'),' seems to have never been executed.'])
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
99 block.OutputPort(1).Data = -1;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
100 return
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
101 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
102 j=3;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
103 while ~isempty(execHistory{blockIndex,j})
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
104 block.InputPort(1).Data(j-2) = execHistory{blockIndex,j};
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
105 j = j+1;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
106 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
107 disp([' . Partial execution: block ',get_param(subsyshandle,'Name'),' will now be executed with data retrieved from previous calculation.'])
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
108 else
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
109 disp([' . Partial execution: block ',get_param(subsyshandle,'Name'),' will now be executed.'])
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
110 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
111 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
112 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
113
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
114 % Check if the user wants to stop the execution:
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
115 lastChar = get(findobj('Name','LTPDA Progress Bar'),'CurrentCharacter');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
116 if ~isempty(lastChar) && strcmp(lastChar,'x')
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
117 set_param(bdroot, 'SimulationCommand', 'stop')
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
118 return
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
119 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
120
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
121 % Update the progress bar window:
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
122 progressBar = findobj('Tag','progressaxes');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
123 if ~isempty(progressBar)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
124 blocksTotal = get(findobj('Tag','blockstotal'),'UserData');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
125 blocksDone = get(findobj('Tag','done'),'UserData');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
126 blocksToGo = get(findobj('Tag','togo'),'UserData');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
127 set(findobj('Tag','done'),'UserData',blocksDone+1);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
128 set(findobj('Tag','togo'),'UserData',blocksToGo-1);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
129 set(findobj('Tag','done'),'String',['Done: ',num2str(blocksDone+1)]);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
130 set(findobj('Tag','togo'),'String',['To go: ',num2str(blocksToGo-1)]);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
131 currblockname = get_param(get_param(gcbh,'Parent'),'Name');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
132 for i=1:numel(currblockname), if double(currblockname(i))==10, currblockname(i)=' '; end; end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
133 set(findobj('Tag','currentexec'),'String',['Current block: ',currblockname]);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
134 progressSize = get(progressBar,'UserData');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
135 progressPosition = get(progressBar,'Position');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
136 progressPosition(3) = 1+(progressSize(3)/blocksTotal)*(blocksDone+1);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
137 set(progressBar,'Position',progressPosition)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
138 progressBarLoop = findobj('Tag','progressaxes2');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
139 if ~isempty(progressBarLoop)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
140 set(findobj('Tag','done'),'String',['Blocks done: ',num2str(blocksDone+1)]);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
141 loopStatus = getappdata(0,'loopStatus');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
142 progressSize = get(progressBarLoop,'UserData');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
143 progressLoopPosition = get(progressBarLoop,'Position');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
144 progressLoopPosition(3) = 1+(progressSize(3)/loopStatus(1))*loopStatus(2);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
145 set(progressBarLoop,'Position',progressLoopPosition)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
146 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
147 drawnow
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
148 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
149
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
150 % Retrieve the function name from the block tag:
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
151 blocktag = get_param(gcb, 'tag');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
152 if strcmp(blocktag,'generic')
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
153 paramcommand = get_param(get_param(get_param(gcbh,'Parent'), 'handle'),'Description');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
154 eval(paramcommand)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
155 blocktag = functionName;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
156 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
157
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
158 % ========================================================================
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
159 %% For arithmetic blocks
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
160 % ========================================================================
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
161
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
162 if strcmp(blocktag,'arithmetic')
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
163 eq = get_param(currparent,'MaskDescription');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
164 if strcmp(eq,'Arithmetic block: the user can type in the desidered equation.')
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
165 disp(sprintf('Error: in the ''%s'' arithmetic block no equation has been typed in.',get_param(currparent,'Name')))
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
166 close(findobj('Name','LTPDA Progress Bar'))
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
167 error(['Error: in the ',get_param(currparent,'Name'),' arithmetic block no equation has been typed in.'])
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
168 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
169 equation = eq;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
170 equation(strfind(equation,char(10))) = [];
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
171
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
172 paramcommand = get_param(subsyshandle,'Description');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
173 if isempty(paramcommand), paramcommand = 'params=plist(''alpha'',''-->'',''beta'',''-->'');'; end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
174 eval(paramcommand)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
175
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
176 for i=1:nparams(params)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
177 inputBlock = find_system(currparent,'SearchDepth',1,'LookUnderMasks','all','Name',lower(params.params(i).key));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
178 if numel(inputBlock)>1, inputBlock(1)=[]; end % this can happen only when the currparent has the same name: then, ignore the 1st, ie. the currparent itself
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
179 inputNumb = get_param(inputBlock{1},'Tag');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
180 equation = strrep(equation,lower(params.params(i).key),['LTPDAinvar{block.InputPort(1).Data(',inputNumb,'),1}']);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
181 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
182
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
183 try
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
184 outdata = eval(equation);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
185
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
186 % Setting the output signal name:
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
187 ifsetName = get_param(currparent,'UserData');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
188 if ~isempty(ifsetName) && isa(ifsetName,'char')
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
189 % ifsetName = ifsetName;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
190 else
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
191 ifsetName = get_param(currparent,'Name');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
192 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
193 if numel(outdata)==1
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
194 outdata = setName(outdata,ifsetName);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
195 else
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
196 for i=1:size(outdata,1)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
197 for j=1:size(outdata,2)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
198 outdata(i,j) = setName(outdata(i,j),[ifsetName,'_',num2str(i),'-',num2str(j)]);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
199 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
200 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
201 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
202
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
203 x = size(LTPDAinvar,1);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
204 blockName = currparent;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
205 for i=1:numel(blockName), if double(blockName(i))==10, blockName(i)=' '; end; end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
206 LTPDAinvar = [LTPDAinvar;{outdata,0,blockName}];
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
207 block.OutputPort(1).Data = x+1;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
208
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
209 probe = get_param(currparent,'MaskHelp');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
210 if ~isempty(probe) && isa(probe,'char') && strcmp(probe,'probe')
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
211 LTPDAinvar{size(LTPDAinvar,1),2} = 2;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
212 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
213
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
214 return
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
215
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
216 catch err
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
217 disp(sprintf('Something''s wrong in the calculation of the results of the ''%s'' arithmetic block.',get_param(currparent,'Name')))
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
218 disp('The inputs were:')
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
219 for i=1:nparams(params)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
220 disp(['Input ',num2str(i),':'])
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
221 LTPDAinvar{block.InputPort(1).Data(i),1} %#ok<NOPRT>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
222 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
223 disp('The equation was:')
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
224 disp(eq)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
225 close(findobj('Name','LTPDA Progress Bar'))
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
226
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
227 rethrow(err)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
228
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
229 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
230 end % for the arithmetic block
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
231
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
232 % ========================================================================
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
233 %% =================== RETRIEVE THE PARAMETERS LIST ======================
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
234 % ========================================================================
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
235
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
236 % The command line to produce the proper parameters list for the block
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
237 % currently executed is retrieved from the description of this parent subsystem
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
238 paramcommand = get_param(subsyshandle,'Description');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
239 loopExecution = 0;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
240
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
241 if ~isempty(paramcommand)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
242 eval(paramcommand);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
243
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
244 % Verify if a global variable or nested loop variable has been used:
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
245 for i=1:nparams(params)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
246 currVal = params.params(i).val;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
247 if ischar(currVal) && numel(currVal)>5 && strcmp(currVal(1:5),'loop.')
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
248 loopExecution = 1;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
249 try %#ok<ALIGN>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
250 setVal(params.params(i),eval(params.params(i).val));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
251 catch, end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
252 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
253 if ischar(currVal) && numel(currVal)>3 && strcmp(currVal(1:3),'gl.')
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
254 try %#ok<ALIGN>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
255 setVal(params.params(i),eval(params.params(i).val));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
256 catch, end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
257 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
258 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
259
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
260 if ~exist('paramEnabled','var'), paramEnabled = ones(1,nparams(params)); end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
261 currparam = plist();
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
262 for jj=1:nparams(params)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
263 if paramEnabled(jj)==1
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
264 if numel(params.params(jj).key)>6 && strcmpi(params.params(jj).key(1:7),'addPar_'), params.params(jj).setKey(params.params(jj).key(8:end)); end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
265 currparam = append(currparam,params.params(jj));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
266 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
267 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
268 else
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
269 currparam = plist();
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
270 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
271
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
272 % Retrieve parameters from Simulink:
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
273 paramFromSimulink = 0;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
274 for i=1:nparams(currparam)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
275 paramKey2 = currparam.params(i).key;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
276 if numel(paramKey2)>7 && strcmpi(paramKey2(1:7),'addPar_'), paramKey = paramKey2(8:end); else paramKey = paramKey2; end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
277 paramVal = currparam.params(i).val;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
278 if (isa(paramVal,'char') && strcmp(paramVal,'-->')) || (isa(paramVal,'cell') && numel(paramVal)==1 && isa(paramVal{1},'char') && strcmp(paramVal{1},'-->'))
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
279 paramFromSimulink = paramFromSimulink + 1;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
280 mux = find_system(currparent,'SearchDepth',1,'LookUnderMasks','all','BlockType','Mux');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
281 muxWidths = get_param(mux{1},'CompiledPortWidths');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
282 muxWidths = muxWidths.Inport;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
283 inputBlock = find_system(currparent,'SearchDepth',1,'LookUnderMasks','all','Name',lower(paramKey));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
284 if numel(inputBlock)>1, inputBlock(1)=[]; end % this can happen only when the currparent has the same name: then, ignore the 1st, ie. the currparent itself
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
285 inputNumb = str2double(get_param(inputBlock{1},'Tag'));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
286 x = 0;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
287 for j=1:inputNumb-1
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
288 x=x+muxWidths(j);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
289 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
290 paramVal = [LTPDAinvar{block.InputPort(1).Data(x+1)}];
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
291 if muxWidths(inputNumb)>1
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
292 for j=x+2:x+muxWidths(inputNumb)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
293 paramVal = [paramVal,LTPDAinvar{block.InputPort(1).Data(j)}];
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
294 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
295 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
296 currparam = pset(currparam,paramKey2,paramVal);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
297 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
298 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
299
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
300 % ========================================================================
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
301 %% ======================== CALCULATE THE RESULTS =========================
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
302 % ========================================================================
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
303
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
304 y = length(block.InputPort(1).Data) - paramFromSimulink;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
305
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
306 % Check to verify the type of function:
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
307 specFunc = {'display'};
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
308 [meth,clas] = strtok(get(get_param(currparent,'Handle'),'Tag'));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
309 category = '';
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
310 if strcmp(meth,'method')
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
311 clas = strtrim(clas);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
312 infoObj = eval([clas,'.getInfo(''',blocktag,''')']);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
313 category = infoObj.mcategory;
|
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 if ismember(blocktag,specFunc)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
317 % Input, but no parameters and no output
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
318 type = 4;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
319 % ======================================
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
320 elseif strcmp(category,'Output')
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
321 % Input and parameters, but no output
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
322 type = 3;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
323 % ===================================
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
324 elseif ~isempty(utils.prog.find_in_models(currparent,'SearchDepth',1,'LookUnderMasks','all','BlockType','Ground')) || block.InputPort(1).Data(1)==0
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
325 % No input, but parameters and output
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
326 type = 2;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
327 % ===================================
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
328 elseif nparams(currparam)==0
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
329 % Input and output, but no parameters
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
330 type = 1;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
331 % ============================
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
332 else
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
333 % Input, parameters and output
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
334 type = 0;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
335 % ============================
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
336 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
337
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
338
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
339 switch type
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
340 % ====================================================================
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
341 case 4 % Input, but no parameters and no output
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
342 command = 'feval(blocktag,';
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
343 for i=1:y
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
344 dVal = block.InputPort(1).Data(i);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
345 if dVal>0, command = [command sprintf('LTPDAinvar{%d},', dVal)]; end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
346 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
347 command = [command(1:end-1) ');'];
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
348 try
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
349 eval(command)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
350 catch err
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
351 disp('4')
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
352 disp(sprintf('Something''s wrong in the calculation of the results of the %s function.',blocktag))
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
353 disp(sprintf('The name of the currently executed block is %s.',get_param(currparent,'Name')))
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
354 disp(sprintf('The (first) input data ordinal number, in the list of objects, was %d.',block.InputPort(1).Data(1)))
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
355 close(findobj('Name','LTPDA Progress Bar'))
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
356 rethrow(err)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
357 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
358 block.OutputPort(1).Data = 1; % this will be ignored: no output expected.
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
359 return;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
360
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
361 % ====================================================================
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
362 case 3 % Input and parameters, but no output
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
363 try
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
364 command = 'feval(blocktag,';
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
365 for i=1:y
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
366 dVal = block.InputPort(1).Data(i);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
367 if dVal>0, command = [command sprintf('LTPDAinvar{%d},', dVal)]; end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
368 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
369 command = [command 'currparam);'];
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
370 if strcmpi(blocktag,'plot'), figure; end;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
371 eval(command);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
372 catch err
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
373 disp('3')
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
374 disp(sprintf('Something''s wrong in the calculation of the results of the %s function.',blocktag))
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
375 disp(sprintf('The name of the currently executed block is %s.',get_param(currparent,'Name')))
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
376 disp(sprintf('The (first) input data ordinal number, in the list of objects, was %d.',block.InputPort(1).Data(1)))
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
377 disp('The plist passed was:')
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
378 currparam %#ok<NOPRT>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
379 close(findobj('Name','LTPDA Progress Bar'))
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
380 rethrow(err)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
381 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
382 block.OutputPort(1).Data = 1; % this will be ignored: no output expected.
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
383 return;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
384
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
385 % ====================================================================
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
386 case 2 % No input, but parameters and output
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
387 try
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
388 outdata = feval(blocktag,currparam);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
389 catch err
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
390 disp('2')
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
391 disp(sprintf('Something''s wrong in the calculation of the results of the %s function.',blocktag))
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
392 disp(sprintf('The name of the currently executed block is %s.',get_param(currparent,'Name')))
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
393 disp('The plist passed was:')
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
394 currparam %#ok<NOPRT>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
395 close(findobj('Name','LTPDA Progress Bar'))
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
396 rethrow(err)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
397 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
398
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
399 % ====================================================================
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
400 case 1 % Input and output, but no parameters
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
401 try
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
402 command = 'outdata = feval(blocktag,';
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
403 for i=1:y
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
404 dVal = block.InputPort(1).Data(i);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
405 if dVal>0, command = [command sprintf('LTPDAinvar{%d},', dVal)]; end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
406 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
407 command = [command(1:end-1) ');'];
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
408 eval(command);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
409 catch err
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
410 disp('1')
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
411 disp(sprintf('Something''s wrong in the calculation of the results of the %s function.',blocktag))
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
412 disp(sprintf('The name of the currently executed block is %s.',get_param(currparent,'Name')))
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
413 disp(sprintf('The (first) input data ordinal number, in the list of objects, was %d.',block.InputPort(1).Data(1)))
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
414 disp('The plist passed was:')
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
415 currparam %#ok<NOPRT>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
416 close(findobj('Name','LTPDA Progress Bar'))
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
417 rethrow(err)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
418 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
419 % ====================================================================
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
420 case 0 % Input, parameters and output
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
421 try
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
422 command = 'outdata = feval(blocktag,';
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
423 for i=1:y
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
424 dVal = block.InputPort(1).Data(i);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
425 if dVal>0, command = [command sprintf('LTPDAinvar{%d},', dVal)]; end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
426 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
427 command = [command 'currparam);'];
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
428 eval(command);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
429 catch err
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
430 disp('1')
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
431 disp(sprintf('Something''s wrong in the calculation of the results of the %s function.',blocktag))
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
432 disp(sprintf('The name of the currently executed block is %s.',get_param(currparent,'Name')))
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
433 disp(sprintf('The (first) input data ordinal number, in the list of objects, was %d.',block.InputPort(1).Data(1)))
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
434 disp('The plist passed was:')
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
435 currparam %#ok<NOPRT>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
436 close(findobj('Name','LTPDA Progress Bar'))
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
437 rethrow(err)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
438 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
439
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
440 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
441
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
442 %==========================================================================
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
443 %% Cycle to remove objects from memory as soon as they're no longer necessary:
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
444 %==========================================================================
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
445
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
446 if ~getappdata(0,'maintainresults');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
447 portConnectivity = get(subsyshandle,'PortConnectivity');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
448 for i = 1:numel(portConnectivity)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
449 notUsedAnymore = 1;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
450 if isempty(portConnectivity(i).DstBlock)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
451 parentBlock = portConnectivity(i).SrcBlock;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
452 childrenBlocks = utils.prog.findchildren(parentBlock);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
453 for j = 1:numel(childrenBlocks)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
454 if isempty(get_param(childrenBlocks(j),'MaskVariables')), notUsedAnymore = 0; end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
455 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
456 % disp(sprintf('*** (Currently executing block %s)',get_param(currparent,'Name')))
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
457 if notUsedAnymore && LTPDAinvar{block.InputPort(1).Data(i),2}==0
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
458 % disp(['*** Removed object n°.',num2str(block.InputPort(1).Data(i)),', which was a ',class(LTPDAinvar{block.InputPort(1).Data(i),1}),'.'])
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
459 disp(sprintf('*** (Currently executing block %s)',get_param(currparent,'Name')))
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
460 LTPDAinvar(block.InputPort(1).Data(i),:) = [];
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
461
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
462 % Update the execution history:
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
463 ltpda_annotation = find_system(bdroot,'FindAll','on','Type','Annotation','Tag','ltpda model');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
464 execHistory = get_param(ltpda_annotation,'UserData');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
465 for xx=1:size(execHistory,1)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
466 for yy=3:size(execHistory,2),
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
467 if execHistory{xx,yy} == block.InputPort(1).Data(i), execHistory{xx,yy} = -1; end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
468 if execHistory{xx,yy} > block.InputPort(1).Data(i), execHistory{xx,yy} = execHistory{xx,yy}-1; end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
469 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
470 if execHistory{xx,1} == block.InputPort(1).Data(i), execHistory{xx,1} = -1; end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
471 if execHistory{xx,1} > block.InputPort(1).Data(i), execHistory{xx,1} = execHistory{xx,1}-1; end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
472 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
473 set_param(ltpda_annotation,'UserData',execHistory);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
474
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
475 disp('*** LTPDA object cleared from memory, being now unused')
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
476 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
477 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
478 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
479 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
480 % ========================================================================
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
481 %% =============================== OUTPUTS ================================
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
482 % ========================================================================
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
483
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
484 % Set this block status to 'executed':
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
485 set(subsyshandle,'MaskVariables','1');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
486 set(gcbh,'MaskVariables','1');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
487
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
488 signalName = get_param(currparent,'Name');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
489 ifsetName = get_param(currparent,'UserData');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
490 if ~isempty(ifsetName) && isa(ifsetName,'double') && ifsetName==1
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
491 if numel(outdata)==1
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
492 outdata = setName(outdata,signalName);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
493 else
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
494 for i=1:size(outdata,1)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
495 for j=1:size(outdata,2)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
496 outdata(i,j) = set(outdata(i,j),'name',[signalName,'_',num2str(i),'-',num2str(j)]);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
497 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
498 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
499 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
500 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
501
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
502 try
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
503 % To prevent the result calculated here from being canceled at the
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
504 % end of the calculation:
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
505 probe = get_param(currparent,'MaskHelp');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
506 if ~isempty(probe) && isa(probe,'char') && strcmp(probe,'probe'), keepThis = 1;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
507 else keepThis = 0;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
508 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
509
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
510 % Appending the results:
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
511 ltpda_annotation = find_system(bdroot,'FindAll','on','Type','Annotation','Tag','ltpda model');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
512 execHistory = get_param(ltpda_annotation,'UserData');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
513 % If there's a previous execution history, check if the current block belongs to it:
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
514 if ~isempty(execHistory)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
515 member = 0;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
516 for i=1:size(execHistory,1)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
517 if execHistory{i,2}==subsyshandle, member = 1; index = i; break; end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
518 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
519 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
520 if ~isempty(execHistory) && member && ~loopExecution
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
521 x = execHistory{index,1};
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
522 if x==-1, x = size(LTPDAinvar,1)+1; end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
523 for i=1:numel(currparent), if double(currparent(i))==10, currparent(i)=' '; end; end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
524 LTPDAinvar(x,:) = {outdata,keepThis,currparent};
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
525 block.OutputPort(1).Data = x;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
526 execHistory{index,1} = x ;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
527 execHistory{index,2} = subsyshandle ;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
528 for i=1:y , execHistory{index,2+i} = block.InputPort(1).Data(i); end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
529 else
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
530 if isempty(execHistory), execHistory = {}; end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
531 x = size(LTPDAinvar,1);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
532 LTPDAinvar = [LTPDAinvar;{outdata,keepThis,currparent}];
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
533 block.OutputPort(1).Data = x+1;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
534 execHistory{end+1,1} = x+1 ;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
535 execHistory{end,2} = subsyshandle ;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
536 for i=1:y , execHistory{end,2+i} = block.InputPort(1).Data(i); end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
537 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
538
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
539 % Update the execution history:
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
540 % Are stored the the output obj pointer, the handle of the current subsytem and the input obj pointers:
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
541 set_param(ltpda_annotation,'UserData',execHistory);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
542
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
543
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
544 catch
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
545 disp('------------------============================================------------------')
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
546 disp('------------------============================================------------------')
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
547 disp('------------------============================================------------------')
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
548 disp(sprintf('Something''s wrong in appending to the global variable LTPDAinvar the results of the %s function.',blocktag))
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
549 disp(sprintf('The name of the currently executed block is %s.',get_param(currparent,'Name')))
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
550 disp('The data to be saved, calculated into this block, are:')
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
551 outdata %#ok<NOPRT>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
552 disp('------------------============================================------------------')
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
553 disp('------------------============================================------------------')
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
554 disp('------------------============================================------------------')
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
555 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
556
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
557 %==========================================================================
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
558
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
559 % The output to Simulink is just the ordinal number (ONE AND ONLY ONE
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
560 % NUMBER) of the object appended to the global array LTPDAinvar.
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
561
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
562 % endfunction
|