This is the automatic function wrapper ======================================================================== ==================== level-2 M file S-function ========================= ======================================================================== This wrapper is the automatic function, called by every function block in Simulink, able to execute m-file functions retrieving from Simulink: (1) the pointer to the AO(s) to be analyzed, coming in as input of the corresponding block (ie, the DATA), (2) the name of the function to be applied on those data, from the tag of the currently executed block (ie, the true FUNCTION), (3) the parameters for that particular block, retrieved from the global shared workspace by the handle of the block (ie, the PARAMETERS). The output is then generated as: OUTPUT = FUNCTION(DATA,PARAMETERS) This output in the end is saved into the global array containing all the AOs (ie, all the DATA go together with other data): thus this output will be freely accessible by all the other functions. The only real output to Simulink will be just the ordinal number of the so-generated AO into the global array of AOs. ======================================================================= For UNIVARIATE analysis functions ======================================================================= (the difference with the other function, 'ltpdasimmulti', is the dimension of the output port, here set = DimInputPorts) $Id: g_arrmult.m,v 1.1 2008/03/01 13:43:20 nicola Exp $
0001 function g_arrmult(block) 0002 0003 % This is the automatic function wrapper 0004 % ======================================================================== 0005 % ==================== level-2 M file S-function ========================= 0006 % ======================================================================== 0007 % This wrapper is the automatic function, called by every function block 0008 % in Simulink, able to execute m-file functions retrieving from Simulink: 0009 % (1) the pointer to the AO(s) to be analyzed, coming in as input of the 0010 % corresponding block (ie, the DATA), 0011 % (2) the name of the function to be applied on those data, from the tag 0012 % of the currently executed block (ie, the true FUNCTION), 0013 % (3) the parameters for that particular block, retrieved from the global 0014 % shared workspace by the handle of the block (ie, the PARAMETERS). 0015 % 0016 % The output is then generated as: 0017 % OUTPUT = FUNCTION(DATA,PARAMETERS) 0018 % 0019 % This output in the end is saved into the global array containing all 0020 % the AOs (ie, all the DATA go together with other data): thus this output 0021 % will be freely accessible by all the other functions. 0022 % 0023 % The only real output to Simulink will be just the ordinal number of the 0024 % so-generated AO into the global array of AOs. 0025 % 0026 % ======================================================================= 0027 % For UNIVARIATE analysis functions 0028 % ======================================================================= 0029 % (the difference with the other function, 'ltpdasimmulti', is the 0030 % dimension of the output port, here set = DimInputPorts) 0031 % 0032 % 0033 % $Id: g_arrmult.m,v 1.1 2008/03/01 13:43:20 nicola Exp $ 0034 0035 setup(block); 0036 0037 %% 0038 function setup(block) 0039 % global LTPDAinvar loopstatus 0040 0041 0042 %% Register dialog parameter: none, because they're retrieved directly 0043 %% from the memory. This will prevent the user to modify the parameters 0044 %% outside the proper parameters panel: 0045 block.NumDialogPrms = 0; 0046 0047 %% Register number of input and output ports 0048 block.NumInputPorts = 1; 0049 block.NumOutputPorts = 1; 0050 0051 %% Setup functional port properties to dynamically inherited. 0052 block.SetPreCompInpPortInfoToDynamic; 0053 block.SetPreCompOutPortInfoToDynamic; 0054 0055 block.InputPort(1).DirectFeedthrough = true; 0056 block.InputPort(1).DatatypeID = 0; 0057 block.InputPort(1).Complexity = 0; 0058 block.OutputPort(1).DatatypeID = 0; 0059 block.OutputPort(1).Complexity = 0; 0060 block.OutputPort(1).Dimensions = 1; 0061 %(block.InputPort(1).Dimensions)^2; 0062 block.SampleTimes = [0 0]; 0063 block.SetAccelRunOnTLC(false); 0064 0065 %% Register methods 0066 block.RegBlockMethod('SetInputPortSamplingMode',@SetInpPortFrameData); 0067 block.RegBlockMethod('SetInputPortDimensions', @SetInpPortDims); 0068 % block.RegBlockMethod('SetOutputPortDimensions', @SetOutPortDims); 0069 block.RegBlockMethod('Outputs', @Outputs); 0070 0071 function SetInpPortFrameData(block, idx, fd) 0072 block.InputPort(1).SamplingMode = fd; 0073 block.OutputPort(1).SamplingMode = fd; 0074 0075 function SetInpPortDims(block, idx, di) 0076 block.InputPort(idx).Dimensions = di; 0077 % outdims=(block.InputPort(1).Dimensions)^2; 0078 % block.OutputPort(1).Dimensions = outdims; 0079 0080 % function SetOutPortDims(block, idx, di) 0081 % block.OutputPort(idx).Dimensions = 1; 0082 0083 0084 %% 0085 function Outputs(block) 0086 global LTPDAinvar 0087 0088 if length(block.InputPort(1).Data)~=2 0089 block.OutputPort(1).Data = block.InputPort(1).Data; 0090 disp('========================================================') 0091 disp('Something''s wrong. Please check ltpdaarrmult.m function') 0092 disp('========================================================') 0093 return 0094 end 0095 0096 outdata = LTPDAinvar{block.InputPort(1).Data(1)} .* LTPDAinvar{block.InputPort(1).Data(2)}; 0097 outdata = num2cell(outdata); 0098 0099 lineHandles = get_param(get_param(gcbh,'Parent'),'LineHandles'); 0100 signalName = get(lineHandles.Outport,'Name'); 0101 if ~isempty(signalName) && numel(outdata)==1 0102 outdata{1} = setnh(outdata{1},'name',signalName); 0103 end 0104 xx = size(LTPDAinvar,1); 0105 LTPDAinvar(xx+1,:) = [outdata,0]; 0106 block.OutputPort(1).Data = xx+1; 0107 0108 %endfunction