0001 function ltpdasim(block)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029 setup(block);
0030
0031
0032
0033
0034 function setup(block)
0035
0036
0037
0038
0039 block.NumDialogPrms = 0;
0040
0041
0042 block.NumInputPorts = 1;
0043 block.NumOutputPorts = 1;
0044
0045
0046 block.SetPreCompInpPortInfoToDynamic;
0047
0048
0049 block.InputPort(1).DirectFeedthrough = true;
0050 block.InputPort(1).DatatypeID = 0;
0051 block.InputPort(1).Complexity = 0;
0052 block.OutputPort(1).DatatypeID = 0;
0053 block.OutputPort(1).Complexity = 0;
0054 block.SampleTimes = [0 0];
0055 block.SetAccelRunOnTLC(false);
0056
0057 block.OutputPort(1).Dimensions = 1;
0058
0059
0060 block.RegBlockMethod('SetInputPortSamplingMode',@SetInpPortFrameData);
0061 block.RegBlockMethod('SetInputPortDimensions', @SetInpPortDims);
0062
0063 block.RegBlockMethod('Outputs', @Outputs);
0064
0065 function SetInpPortFrameData(block, idx, fd)
0066 block.InputPort(1).SamplingMode = fd;
0067 block.OutputPort(1).SamplingMode = fd;
0068
0069 function SetInpPortDims(block, idx, di)
0070 block.InputPort(idx).Dimensions = di;
0071
0072
0073
0074
0075
0076
0077
0078
0079
0080
0081
0082
0083
0084
0085
0086
0087
0088 function Outputs(block)
0089 global LTPDAinvar
0090
0091
0092 lastChar = get(gcf,'CurrentCharacter');
0093 if ~isempty(lastChar) && strcmp(lastChar,'x')
0094 set_param(bdroot, 'SimulationCommand', 'stop')
0095 return
0096 end
0097
0098
0099 blocksTotal = get(findobj('Tag','blockstotal'),'UserData');
0100 blocksDone = get(findobj('Tag','done'),'UserData');
0101 blocksToGo = get(findobj('Tag','togo'),'UserData');
0102 set(findobj('Tag','done'),'UserData',blocksDone+1);
0103 set(findobj('Tag','togo'),'UserData',blocksToGo-1);
0104 set(findobj('Tag','done'),'String',['Done: ',num2str(blocksDone+1)]);
0105 set(findobj('Tag','togo'),'String',['To go: ',num2str(blocksToGo-1)]);
0106 set(findobj('Tag','currentexec'),'String',['Currently executed block: ',get_param(get_param(gcbh,'Parent'),'Name')]);
0107 progressBar = findobj('Tag','progressaxes');
0108 progressSize = get(progressBar,'UserData');
0109 progressPosition = get(progressBar,'Position');
0110 progressPosition(3) = 1+(progressSize(3)/blocksTotal)*(blocksDone+1);
0111 set(progressBar,'Position',progressPosition)
0112 pause(0.1)
0113
0114
0115 blocktag = get_param(gcb, 'tag');
0116
0117
0118 blocktag = lower(blocktag);
0119
0120
0121
0122
0123
0124
0125
0126 currparent = get_param(gcbh,'Parent');
0127 subsyshandle=get_param(currparent, 'handle');
0128
0129
0130
0131 paramcommand = get_param(subsyshandle,'Description');
0132
0133 if ~isempty(paramcommand)
0134 eval(paramcommand);
0135 if ~exist('paramEnabled','var'), paramEnabled = ones(1,nparams(params)); end
0136 currparam = plist();
0137 for jj=1:nparams(params)
0138 if paramEnabled(jj)==1
0139 try
0140 if strcmpi(params.params(jj).key(1:7),'addPar_'), params.params(jj).key(1:7)=[]; end
0141 catch end
0142
0143
0144
0145
0146 currparam = append(currparam,params.params(jj));
0147 end
0148 end
0149 else
0150 currparam = plist();
0151 end
0152
0153
0154 paramFromSimulink = 0;
0155 for i=1:nparams(currparam)
0156 paramKey = get(currparam.params(i),'key');
0157 paramVal = get(currparam.params(i),'val');
0158 if (isa(paramVal,'char') && strcmp(paramVal,'-->')) || (isa(paramVal,'cell') && numel(paramVal)==1 && isa(paramVal{1},'char') && strcmp(paramVal{1},'-->'))
0159 paramFromSimulink = paramFromSimulink + 1;
0160 mux = find_system(currparent,'SearchDepth',1,'LookUnderMasks','all','BlockType','Mux');
0161 muxWidths = get_param(mux{1},'CompiledPortWidths');
0162 muxWidths = muxWidths.Inport;
0163 inputBlock = find_system(currparent,'SearchDepth',1,'LookUnderMasks','all','Name',lower(paramKey));
0164 inputNumb = str2double(get_param(inputBlock{1},'Tag'));
0165 x = 0;
0166 for j=1:inputNumb-1
0167 x=x+muxWidths(j);
0168 end
0169 paramVal = [LTPDAinvar{block.InputPort(1).Data(x+1)}];
0170 if muxWidths(inputNumb)>1
0171 for j=x+2:x+muxWidths(inputNumb)
0172 paramVal = [paramVal,LTPDAinvar{block.InputPort(1).Data(j)}];
0173 end
0174 end
0175 currparam = pset(currparam,paramKey,paramVal);
0176 end
0177 end
0178
0179
0180
0181
0182
0183
0184 y = length(block.InputPort(1).Data) - paramFromSimulink;
0185
0186
0187 specFunc = {'display'};
0188 [func,classes] = strtok(get(get_param(currparent,'Handle'),'Tag'));
0189 if strcmp(func,'method')
0190 category = eval(sprintf([blocktag,'(%s,''Category'')'],strtrim(classes)));
0191 end
0192
0193 if ismember(blocktag,specFunc)
0194
0195 type = 4;
0196
0197 elseif (exist('category','var') && strcmp(category,'Output'))
0198
0199 type = 3;
0200
0201 elseif ~isempty(find_system(currparent,'SearchDepth',1,'LookUnderMasks','all','BlockType','Constant'))
0202
0203 type = 2;
0204
0205 else
0206
0207 type = 1;
0208
0209 end
0210
0211
0212 switch type
0213
0214 case 4
0215 inputlist = 'LTPDAinvar{block.InputPort(1).Data(1)}';
0216 for i=2:y
0217 inputlist = [inputlist,',LTPDAinvar{block.InputPort(1).Data(',num2str(i),')}'];
0218 end
0219 command = ['feval(blocktag,',inputlist,')'];
0220 block.OutputPort(1).Data = block.InputPort(1).Data;
0221 try
0222 eval(command)
0223 catch
0224 disp('4')
0225 disp(sprintf('Something''s wrong in the calculation of the results of the %s function.',blocktag))
0226 disp(sprintf('The name of the currently executed block is %s.',get_param(currparent,'Name')))
0227 disp(sprintf('The (first) input data ordinal number, in the list of objects, was %d.',block.InputPort(1).Data(1)))
0228 rethrow(lasterror)
0229 end
0230
0231 block.OutputPort(1).Data = 1;
0232 return;
0233
0234
0235 case 3
0236 try
0237 inputlist = 'LTPDAinvar{block.InputPort(1).Data(1)}';
0238 for i=2:y
0239 inputlist = [inputlist,',LTPDAinvar{block.InputPort(1).Data(',num2str(i),')}'];
0240 end
0241 command = ['feval(blocktag,',inputlist,',currparam);'];
0242 eval(command);
0243 catch
0244 disp('3')
0245 disp(sprintf('Something''s wrong in the calculation of the results of the %s function.',blocktag))
0246 disp(sprintf('The name of the currently executed block is %s.',get_param(currparent,'Name')))
0247 disp(sprintf('The (first) input data ordinal number, in the list of objects, was %d.',block.InputPort(1).Data(1)))
0248 disp('The plist passed was:')
0249 currparam
0250 rethrow(lasterror)
0251 end
0252
0253 block.OutputPort(1).Data = 1;
0254 return;
0255
0256
0257 case 2
0258 try
0259 outdata = feval(blocktag,currparam);
0260 catch
0261 disp('2')
0262 disp(sprintf('Something''s wrong in the calculation of the results of the %s function.',blocktag))
0263 disp(sprintf('The name of the currently executed block is %s.',get_param(currparent,'Name')))
0264 disp('The plist passed was:')
0265 currparam
0266 rethrow(lasterror)
0267 end
0268
0269
0270 case 1
0271 try
0272 inputlist = 'LTPDAinvar{block.InputPort(1).Data(1)}';
0273 for i=2:y
0274 inputlist = [inputlist,',LTPDAinvar{block.InputPort(1).Data(',num2str(i),')}'];
0275 end
0276 command = ['outdata = feval(blocktag,',inputlist,',currparam);'];
0277 eval(command);
0278 catch
0279 disp('1')
0280 disp(sprintf('Something''s wrong in the calculation of the results of the %s function.',blocktag))
0281 disp(sprintf('The name of the currently executed block is %s.',get_param(currparent,'Name')))
0282 disp(sprintf('The (first) input data ordinal number, in the list of objects, was %d.',block.InputPort(1).Data(1)))
0283 disp('The plist passed was:')
0284 currparam
0285 rethrow(lasterror)
0286 end
0287
0288 end
0289
0290
0291
0292
0293
0294
0295
0296 signalName = get_param(currparent,'Name');
0297 if ~isempty(get_param(currparent,'UserData'))
0298 if numel(outdata)==1
0299 outdata = setnh(outdata,'name',signalName);
0300 else
0301 for i=1:size(outdata,1)
0302 for j=1:size(outdata,2)
0303 outdata(i,j) = setnh(outdata(i,j),'name',[signalName,'_',num2str(i),'-',num2str(j)]);
0304 end
0305 end
0306 end
0307 end
0308
0309 try
0310
0311
0312
0313
0314
0315
0316
0317
0318
0319
0320
0321 x = size(LTPDAinvar,1);
0322 LTPDAinvar = [LTPDAinvar;{outdata,0}];
0323 block.OutputPort(1).Data = x+1;
0324
0325
0326
0327 probe = get_param(currparent,'UserData');
0328 if ~isempty(probe) && isa(probe,'char') && strcmp(probe,'probe')
0329 LTPDAinvar{size(LTPDAinvar,1),2} = 2;
0330 end
0331
0332 catch
0333 disp('------------------============================================------------------')
0334 disp(sprintf('Something''s wrong in appending to the global variable LTPDAinvar the results of the %s function.',blocktag))
0335 disp(sprintf('The name of the currently executed block is %s.',get_param(currparent,'Name')))
0336 disp('The data to be saved, calculated into this block, are:')
0337 outdata
0338 size(outdata)
0339 disp('------------------============================================------------------')
0340 end
0341
0342
0343
0344
0345