%implements Lookup2D "C"
%include "fixptlook_support.tlc"
%include "fixptlook_search.tlc"
%include "fixptlook2D.tlc"
%function BlockTypeSetup(block, system) void
%endfunction
%function BlockFixptInstanceSetup(block, system) void
%<FixPt_Setup(block, system)>
%endfunction
%function BlockClassicInstanceSetup(block, system) void
%<LibBlockSetIsExpressionCompliant(block)>
%if (SLibIsERTCodeFormat())
%if !(ParamSettings.ColZeroTechnique == "NormalInterp" && ...
ParamSettings.RowZeroTechnique == "NormalInterp")
%if (block.InMask == "yes")
%assign blockName = LibParentMaskBlockName(block)
%else
%assign blockName = LibGetFormattedBlockPath(block)
%endif
%selectfile STDOUT
Note: Removing repeated zero values from the X and Y axes will produce
more efficient code for block: %<blockName>. To locate this block, type
hilite_system('%<blockName>')
at the MATLAB command prompt.
%selectfile NULL_FILE
%endif
%endif
%endfunction
%function BlockInstanceSetup(block, system) void
%if block.InFixptMode
%<BlockFixptInstanceSetup(block, system)>
%else
%<BlockClassicInstanceSetup(block, system)>
%endif
%if GenerateASAP2
%assign group = SLibCreateParameterGroup(block, "Lookup2D")
%assign tmpVar = SLibAddMember(block, group, RowIndex)
%assign tmpVar = SLibAddMember(block, group, ColumnIndex)
%assign tmpVar = SLibAddMember(block, group, Table)
%endif
%endfunction
%function genLookup2DGeneralFcnFromTfl(outputDataType, addrRowValues, numRowValues, ...
addrColValues, numColValues, outputValues, ...
uX, uY, ParamSettingsDotColZeroIndex, colZeroTechnique, ...
outputAtRowZero) void
%createrecord FcnRec{Name "rt_Lookup2D_General"; RetTypeId outputDataType; NumArgs 10}
%addtorecord FcnRec ArgList{Expr "%<addrRowValues>"; TypeId outputDataType; IsPtr 1; IsCplx 0; IsConst 0}
%addtorecord FcnRec ArgList{Expr "%<numRowValues>"; TypeId tSS_INTEGER; IsPtr 0; IsCplx 0; IsConst 0}
%addtorecord FcnRec ArgList{Expr "%<addrColValues>"; TypeId outputDataType; IsPtr 1; IsCplx 0; IsConst 0}
%addtorecord FcnRec ArgList{Expr "%<numColValues>"; TypeId tSS_INTEGER; IsPtr 0; IsCplx 0; IsConst 0}
%addtorecord FcnRec ArgList{Expr "%<outputValues>"; TypeId outputDataType; IsPtr 1; IsCplx 0; IsConst 0}
%addtorecord FcnRec ArgList{Expr "%<uX>"; TypeId outputDataType; IsPtr 0; IsCplx 0; IsConst 0}
%addtorecord FcnRec ArgList{Expr "%<uY>"; TypeId outputDataType; IsPtr 0; IsCplx 0; IsConst 0}
%addtorecord FcnRec ArgList{Expr "%<ParamSettingsDotColZeroIndex>"; TypeId tSS_INTEGER; IsPtr 0; IsCplx 0; IsConst 0}
%addtorecord FcnRec ArgList{Expr "%<colZeroTechnique>"; TypeId tSS_INTEGER; IsPtr 0; IsCplx 0; IsConst 0}
%addtorecord FcnRec ArgList{Expr "%<outputAtRowZero>"; TypeId outputDataType; IsPtr 1; IsCplx 0; IsConst 0}
%return "%<LibGenFcnCall(FcnRec)>"
%endfunction
%function genLookup2DNormalFcnFromTfl(outputDataType, addrRowValues, numRowValues, ...
addrColValues, numColValues, outputValues, ...
uX, uY) void
%createrecord FcnRec{Name "rt_Lookup2D_Normal"; RetTypeId outputDataType; NumArgs 7}
%addtorecord FcnRec ArgList{Expr "%<addrRowValues>"; TypeId outputDataType; IsPtr 1; IsCplx 0; IsConst 0}
%addtorecord FcnRec ArgList{Expr "%<numRowValues>"; TypeId tSS_INTEGER; IsPtr 0; IsCplx 0; IsConst 0}
%addtorecord FcnRec ArgList{Expr "%<addrColValues>"; TypeId outputDataType; IsPtr 1; IsCplx 0; IsConst 0}
%addtorecord FcnRec ArgList{Expr "%<numColValues>"; TypeId tSS_INTEGER; IsPtr 0; IsCplx 0; IsConst 0}
%addtorecord FcnRec ArgList{Expr "%<outputValues>"; TypeId outputDataType; IsPtr 1; IsCplx 0; IsConst 0}
%addtorecord FcnRec ArgList{Expr "%<uX>"; TypeId outputDataType; IsPtr 0; IsCplx 0; IsConst 0}
%addtorecord FcnRec ArgList{Expr "%<uY>"; TypeId outputDataType; IsPtr 0; IsCplx 0; IsConst 0}
%return "%<LibGenFcnCall(FcnRec)>"
%endfunction
%function FixptOutputs(block, system) Output
%assign y0IsComplex = LibBlockOutputSignalIsComplex(0)
%assign u0DT = FixPt_GetInputDataTypeWithBoolReplace(0)
%assign u1DT = FixPt_GetInputDataTypeWithBoolReplace(1)
%assign y0DT = FixPt_GetOutputDataType(0)
%openfile commentBuffer
%<FixPt_GeneralComments()>/
* Lookup Method: %<FixPtLookUpMethodStr>
*
* Row Data parameter uses the same data type and scaling as Input0
* Column Data parameter uses the same data type and scaling as Input1
* Table Data parameter uses the same data type and scaling as Output0
%closefile commentBuffer
%<LibCacheBlockComment(block,commentBuffer)>/
%if FixPt_ParameterCouldBeInlined(RowIndex, "", "", 0)
%assign rowDataEvenSpaceInfo = FixPt_GetBreakPointInfo(RowIndex.Value)
%else
%assign rowDataEvenSpaceInfo = FixPt_BreakPointInfoDefault()
%endif
%if FixPt_ParameterCouldBeInlined(ColumnIndex, "", "", 0)
%assign colDataEvenSpaceInfo = FixPt_GetBreakPointInfo(ColumnIndex.Value)
%else
%assign colDataEvenSpaceInfo = FixPt_BreakPointInfoDefault()
%endif
%if FixPtLookUpMethodStr != "Linear_Endpoint"
{
%endif
%if FixPtLookUpMethodStr == "Linear_Endpoint"
%elseif FixPtLookUpMethodStr == "Below"
%<FixPt_uint_label> iRowIndex1, iColumnIndex1;
%elseif FixPtLookUpMethodStr == "Above"
%<FixPt_uint_label> iRowIndex2, iColumnIndex2;
%elseif FixPtLookUpMethodStr == "Nearest"
%<FixPt_uint_label> iRowIndex1, iColumnIndex1;
%else
%openfile errTxt
The lookup method: %<FixPtLookUpMethodStr> is not supported
for code generation.
Block: '%<LibGetBlockPath(block)>'
%closefile errTxt
%exit %<errTxt>
%endif
%assign u0BreakpointWidth = LibBlockParameterWidth(RowIndex)
%assign rollVars = ["U", "Y"]
%roll sigIdx = RollRegions, lcv = RollThreshold, block, "Roller", rollVars
%assign u0Label = LibBlockInputSignal(0, "", lcv, sigIdx)
%assign u1Label = LibBlockInputSignal(1, "", lcv, sigIdx)
%if FixPtLookUpMethodStr == "Linear_Endpoint"
%assign y0Label = LibBlockOutputSignal(0, "", lcv, sigIdx)
%else
%assign reSigIdx = tRealPart + STRING(sigIdx)
%assign imSigIdx = tImagPart + STRING(sigIdx)
%assign y0ReLabel = LibBlockOutputSignal(0, "", lcv, reSigIdx)
%if y0IsComplex
%assign y0ImLabel = LibBlockOutputSignal(0, "", lcv, imSigIdx)
%endif
%endif
%if FixPtLookUpMethodStr == "Linear_Endpoint"
%<FixPt_SearchAndInterpolate2D(...
y0Label, y0DT,...
u0Label,u0DT,...
u1Label,u1DT,...
Table,y0DT,-1,...
RowIndex, u0DT, rowDataEvenSpaceInfo, -1,...
ColumnIndex, u1DT, colDataEvenSpaceInfo, -1,...
FixPtRoundingMode,FixPtSaturationMode)>/
%elseif FixPtLookUpMethodStr == "Below"
%<FixPt_IndexSearch("iRowIndex1","",...
u0Label,u0DT,...
RowIndex,u0DT,...
rowDataEvenSpaceInfo,-1,...
"Below")>
%<FixPt_IndexSearch("iColumnIndex1","",...
u1Label,u1DT,...
ColumnIndex,u1DT,...
colDataEvenSpaceInfo,-1,...
"Below")>
%<y0ReLabel> = %<LibBlockParameter(Table,...
"iRowIndex1+%<u0BreakpointWidth>*iColumnIndex1", "", "re0")>;
%if y0IsComplex
%<y0ImLabel> = %<LibBlockParameter(Table,...
"iRowIndex1+%<u0BreakpointWidth>*iColumnIndex1", "", "im0")>;
%endif
%elseif FixPtLookUpMethodStr == "Above"
%<FixPt_IndexSearch("","iRowIndex2",...
u0Label,u0DT,...
RowIndex,u0DT,...
rowDataEvenSpaceInfo,-1,...
"Above")>
%<FixPt_IndexSearch("","iColumnIndex2",...
u1Label,u1DT,...
ColumnIndex,u1DT,...
colDataEvenSpaceInfo,-1,...
"Above")>
%<y0ReLabel> = %<LibBlockParameter(Table,...
"iRowIndex2+%<u0BreakpointWidth>*iColumnIndex2", "", "re0")>;
%if y0IsComplex
%<y0ImLabel> = %<LibBlockParameter(Table,...
"iRowIndex2+%<u0BreakpointWidth>*iColumnIndex2", "", "im0")>;
%endif
%else
%<FixPt_IndexSearch("iRowIndex1","",...
u0Label,u0DT,...
RowIndex,u0DT,...
rowDataEvenSpaceInfo,-1,...
"Near")>
%<FixPt_IndexSearch("iColumnIndex1","",...
u1Label,u1DT,...
ColumnIndex,u1DT,...
colDataEvenSpaceInfo,-1,...
"Near")>
%<y0ReLabel> = %<LibBlockParameter(Table,...
"iRowIndex1+%<u0BreakpointWidth>*iColumnIndex1", "", "re0")>;
%if y0IsComplex
%<y0ImLabel> = %<LibBlockParameter(Table,...
"iRowIndex1+%<u0BreakpointWidth>*iColumnIndex1", "", "im0")>;
%endif
%endif
%endroll
%if FixPtLookUpMethodStr != "Linear_Endpoint"
}
%endif
%endfunction
%function ClassicOutputs(block, system) Output
%assign outputDataType = LibBlockOutputSignalAliasedThruDataTypeId(0)
%assign addrColValues = LibBlockParameterBaseAddr(ColumnIndex)
%assign numColValues = SIZE(ColumnIndex.Value, 1)
%assign addrRowValues = LibBlockParameterBaseAddr(RowIndex)
%assign numRowValues = SIZE(RowIndex.Value, 1)
%assign outputValues = LibBlockParameterBaseAddr(Table)
%assign rollVars = ["U", "Y"]
%roll sigIdx = RollRegions, lcv = RollThreshold, block, "Roller", rollVars
%assign uX = LibBlockInputSignal(0, "", lcv, sigIdx)
%assign uY = LibBlockInputSignal(1, "", lcv, sigIdx)
%assign yZ = LibBlockOutputSignal(0, "", lcv, sigIdx)
%if (ParamSettings.ColZeroTechnique == "NormalInterp" && ...
ParamSettings.RowZeroTechnique == "NormalInterp")
%<yZ> = %<genLookup2DNormalFcnFromTfl(outputDataType, addrRowValues, numRowValues, ...
addrColValues, numColValues, outputValues, ...
uX, uY)>;
%else
%assign outputAtRowZero = LibBlockParameterBaseAddr(OutputAtRowZero)
%switch ParamSettings.ColZeroTechnique
%case "NormalInterp"
%assign colZeroTechnique = "NORMAL_INTERP"
%break
%case "AverageValue"
%assign colZeroTechnique = "AVERAGE_VALUE"
%break
%case "MiddleValue"
%assign colZeroTechnique = "MIDDLE_VALUE"
%break
%default
%assign errTxt = "Internal error: ParamSetting 'ColZeroTechnique' " ...
"cannot be '%<ParamSettings.ColZeroTechnique>'."
%<LibBlockReportFatalError(block,errTxt)>
%endswitch
%<yZ> = %<genLookup2DGeneralFcnFromTfl(outputDataType, addrRowValues, numRowValues, ...
addrColValues, numColValues, outputValues, ...
uX, uY, ParamSettings.ColZeroIndex, colZeroTechnique, ...
outputAtRowZero)>;
%endif
%endroll
%endfunction
%function Outputs(block, system) Output
%if block.InFixptMode
%<FixptOutputs(block, system)>
%else
%<ClassicOutputs(block, system)>
%endif
%endfunction
%function BlockOutputSignal(block,system,portIdx,ucv,lcv,idx,retType) void
%if !block.InFixptMode
%switch retType
%case "Signal"
%assign outputDataType = LibBlockOutputSignalAliasedThruDataTypeId(0)
%assign addrColValues = LibBlockParameterBaseAddr(ColumnIndex)
%assign numColValues = SIZE(ColumnIndex.Value, 1)
%assign addrRowValues = LibBlockParameterBaseAddr(RowIndex)
%assign numRowValues = SIZE(RowIndex.Value, 1)
%assign outputValues = LibBlockParameterBaseAddr(Table)
%assign uX = LibBlockInputSignal(0, ucv, lcv, idx)
%assign uY = LibBlockInputSignal(1, ucv, lcv, idx)
%if (ParamSettings.ColZeroTechnique == "NormalInterp" && ...
ParamSettings.RowZeroTechnique == "NormalInterp")
%return "%<genLookup2DNormalFcnFromTfl(outputDataType, ...
addrRowValues, numRowValues, addrColValues, ...
numColValues, outputValues, uX, uY)>"
%else
%assign errTxt = "Expression output is not valid."
%<LibBlockReportFatalError(block,errTxt)>
%endif
%default
%assign errTxt = "Unsupported return type: %<retType>"
%<LibBlockReportError(block,errTxt)>
%endswitch
%endif
%endfunction