%% File : sfun_kflookupnd.tlc generated from sfun_kflookupnd.ttlc revsion 1.4 %% $Date: 2000/05/17 20:17:04 $ %% %% Rob Aberg, 13-Aug-1999 %% Copyright 1990-2000 The MathWorks, Inc. %% %% Abstract: N-D interpolation using output from PreLook-Up %% Index Search block, using calculated index %% and interval fraction values. %implements sfun_kflookupnd "Ada" %% Function: BlockInstanceSetup =================================================== %% Abstract: %% Have mdlhdr.tlc include rtlibsrc.h %% %function BlockInstanceSetup(block, system) void %assign numDims = NumDataInputPorts %assign ttype = LibBlockOutputSignalDataTypeName(0,"") %switch SFcnParamSettings.interpMethod %case 2 %if numDims > 2 %if ttype == "TMW_Types.Real_T" || ttype == "TMW_Types.Real_T'Access" %assign ::CompiledModel.WithRTLookupND = 1 %else %assign ::CompiledModel.WithRTLookupND32 = 1 %endif %endif %break %default %break %endswitch %endfunction %% BlockInstanceData ========================================================== %% Abstract: %% Create persistant data for PWork Vector. %% %function BlockInstanceData(block, system) Output -- Look-Up Table, Interpolated (N-D) (LookupNDInterpIdx) Block: -- % %% %assign bufferSize = SIZE(SFcnParamSettings.tabDims,1) %assign ttype = LibBlockOutputSignalDataTypeName(0,"") %% %% Always declare dimSizes buffer, xxx maxIdx is only if checking is on %% %if UsingMalloc %else maxIdxBuffer : array (0 .. %) of int_T; dimSizesBuffer : array (0 .. %) of int_T; %% Declare index, lambda buffers if table is 3-D or greater %if bufferSize > 2 bpIndexBuffer : array (0 .. %) of int_T; bpLambdaBuffer : array (0 .. %) of %; %endif %assign vCast = "" % := %maxIdxBuffer'access; % := %dimSizesBuffer'access; %if bufferSize > 2 % := %bpIndexBuffer'access; % := %bpLambdaBuffer'access; %endif %endif %endfunction %% Function: Start ============================================================ %% Abstract: %% Set up work vectors %% %function Start(block, system) Output -- Look-Up Table, Interpolated (N-D) (LookupNDInterpIdx) Block: -- % declare %assign ttype = LibBlockOutputSignalDataTypeName(0,"") %assign bufferSize = SIZE(SFcnParamSettings.tabDims,1) %assign dims = SFcnParamSettings.tabDims %assign tlcDimSizes = dims %assign tlcDimSizes[0] = 1 %foreach i = % %assign tlcDimSizes[i+1] = tlcDimSizes[i]*dims[i] %endforeach %assign declDimSizes = "dimSizes : TMW_Types.Int_T_Access" %assign declMaxIdx = "maxIdx : TMW_Types.Int_T_Access" % := )%; % := )%; %foreach idx = % dimSizes(%) = %; %endforeach %foreach idx = % maxIdx(%) = %; %endforeach %if bufferSize > 2 declare %assign declBpIndex = "bpIndex : TMW_Types.Int_T'Access" %assign declBpFraction = "bpFraction : %'Access" % := )%; % := )%; %assign idxVar = "I0" % : int_T; begin for % in 0 .. % loop bpIndex(%) := 0; bpFraction(%) := 0.0; end loop; end; %endif end; %endfunction %% Function: Outputs ========================================================== %% Abstract: %% Perform indicated interpolation, flat or linear %% %function Outputs(block, system) Output -- %-D Look-Up Table, Interpolated (LookupNDInterpIdx) -- Block: % %assign numEl = LibBlockOutputSignalWidth(0) %assign ttype = LibBlockOutputSignalDataTypeName(0,"") %assign tmpIdx = "I1" %assign dims = SFcnParamSettings.tabDims %assign tlcDimSizes = dims %assign tlcDimSizes[0] = 1 %foreach i = % %assign tlcDimSizes[i+1] = tlcDimSizes[i]*dims[i] %endforeach %switch SFcnParamSettings.interpMethod %case 1 %% %% FLAT interpolation (i.e., don't interpolate) %% %assign flatComment = "-- flat, no interpolation" %if NumDataInputPorts > 1 %% %% N-D case %% declare % %if SFcnParamSettings.rangeErrorMode < 0 %%3 maxIdx : int_T; %endif offset : int_T; %if numEl > 1 % : int_T; begin for % in 0 .. % loop %if SFcnParamSettings.rangeErrorMode < 0 %%3 %assign tmp = % maxIdx := %; %endif %assign istr = tmpIdx %assign istr2 = "%*2" %else %assign istr = "0" %assign istr2 = "0" %endif %assign y = LibBlockOutputSignal(0, istr, "", "") %foreach portIdx = NumDataInputPorts %if DataInputPort[portIdx].Width == 2 %% a scalar of (k,f) %assign k = LibBlockInputSignal(portIdx, "0", "", "") %else %assign k = LibBlockInputSignal(portIdx, istr2, "", "") %endif %if tlcDimSizes[portIdx]==1 %if portIdx == 0 offset := int_T(%); %else offset := offset + int_T(%); %endif %else %if portIdx == 0 offset := % * int_T(%); %else offset := offset + % * int_T(%); %endif %endif %endforeach % := %; %if numEl > 1 END_FOR %endif end; %else %% %% 1-D flat case, don't use offset or dimSizes %% %if numEl > 1 declare % % : int_T; begin for % in 0 .. % loop %if SFcnParamSettings.rangeErrorMode < 0 %%3 %assign tmp = % maxIdx : int_T := %; %endif %assign istr = tmpIdx %assign istr2 = "%*2" %else %assign istr = "0" %assign istr2 = "0" %endif %assign u = LibBlockInputSignal(0, istr2, "", "") %assign y = LibBlockOutputSignal(0, istr, "", "") % := %)", "", "")>; %if numEl > 1 end loop; end; %endif %endif %break %case 2 %% %% LINEAR interpolation %% %assign numDims = SIZE(SFcnParamSettings.tabDims,1) %switch numDims %case 1 declare -- Linear 1-D interpolation offset : int_T; %if numEl > 1 % : int_T; begin for % in 0 .. % loop %if SFcnParamSettings.rangeErrorMode < 0 %%3 %assign tmp = % maxIdx : int_T := %; %endif %assign istr = tmpIdx %assign istr2 = "%*2" %assign istr21 = "%*2+1" %else %assign istr = "0" %assign istr2 = "0" %assign istr21 = "1" %endif %assign y = LibBlockOutputSignal(0, istr, "", "") %assign f = LibBlockInputSignal( 0, istr21, "", "") %assign k = LibBlockInputSignal( 0, istr2, "", "") offset := int_T(%); % := % + %*(% - %); %if numEl > 1 end loop; %endif end; %break %case 2 %assign ttype = LibBlockOutputSignalDataTypeName(0,"") declare -- Linear 2-D interpolation ylower : %; yupper : %; offset : int_T; %if numEl > 1 %% xxx clipping code int_T maxIdx = magic; % : int_T; begin for % in 0 .. % loop %if SFcnParamSettings.rangeErrorMode < 0 %%3 %assign tmp = % maxIdx : int_T := %; %endif %assign istr = tmpIdx %assign istr2 = "%*2" %else %assign istr = "0" %assign istr2 = "0" %assign istr21 = "1" %endif %assign y1 = LibBlockParameter(table, "offset", "", "") %assign y2 = LibBlockParameter(table, "offset+1", "", "") %assign y = LibBlockOutputSignal(0, istr, "", "") %if DataInputPort[0].Width == 2 %% a scalar of (k,f) %assign rowIdx = "0" %assign rowIdx1 = "1" %else %assign rowIdx = istr2 %assign rowIdx1 = "%+1" %endif %if DataInputPort[1].Width == 2 %% a scalar of (k,f) %assign colIdx = "0" %assign colIdx1 = "1" %else %assign colIdx = istr2 %assign colIdx1 = "%+1" %endif %assign krow = LibBlockInputSignal(0, rowIdx, "", "") %assign frow = LibBlockInputSignal(0, rowIdx1, "", "") %assign kcol = LibBlockInputSignal(1, colIdx, "", "") %assign fcol = LibBlockInputSignal(1, colIdx1, "", "") offset := int_T(%) + ... %*int_T(%); ylower := % + %*( % - %); offset := offset + %; yupper := % + %*( % - %); % := ylower + %*(yupper - ylower); %if numEl > 1 end loop; %endif end; %break %default %% %% xxx(g#####) REMOVE NEXT 4 LINES FOR ADA CODE GEN %assign errTxt = "Ada code generation not fully implemented at this time "+\ "for Look-Up Table, Interpolated (N-D) (LookupNDInterpIdx)"+\ " Block (G#####)" % %assign t = LibBlockParameterAddr(table,"","",0) declare -- Linear %-D interpolation %assign declBpIndex = "bpIndex : TMW_Types.Int_T'Access" %assign declBpFraction = "bpFraction : %'Access" % := )%; % := )%; %if numEl > 1 %assign tmpIdx = "i" % : int_T; begin for % in 0 .. % loop %if SFcnParamSettings.rangeErrorMode < 0 %%3 %assign tmp = % maxIdx : int_T := %; %endif %assign istr = tmpIdx %assign istr2 = "%*2" %assign istr21 = "%*2+1" %else %assign istr = "0" %assign istr2 = "0" %assign istr21 = "1" %endif %foreach portIdx = numDims bpIndex(%) := )%; bpFraction(%) := %; %endforeach %assign y = LibBlockOutputSignal(0, istr, "", "") % := rt_LookupLinearInterpND_%(%, 0, ... bpIndex, bpFraction, %, %); %if numEl > 1 end loop; %endif end; %endswitch %endswitch %endfunction %% %% Function: Terminate ========================================================= %% Abstract: %% For malloc'ed work vectors, free memory %% %function Terminate(block, system) Output %endfunction %%[EOF] sfun_kflookupnd.tlc