User`s guide

Fully Inlined S-Function with the mdlRTW Routine
4-39
%function Outputs(block, system) Output
/* %<Type> Block: %<Name> */
{
%assign rollVars = [“U”, “Y”]
%%
%% Load XData and YData as local variables
%%
real_T *xData = %<LibBlockParameterAddr(XData, ““, ““, 0)>;
real_T *yData = %<LibBlockParameterAddr(YData, ““, ““, 0)>;
%assign xDataLen = SIZE(XData.Value, 1)
%%
%% When the XData is evenly spaced, we use the direct lookup algorithm
%% to locate the lookup index.
%%
%if SFcnParamSettings.XSpacing == “EvenlySpaced”
real_T spacing = xData[1] - xData[0];
%roll idx = RollRegions, lcv = RollThreshold, block, “Roller”, rollVars
%assign u = LibBlockInputSignal(0, ““, lcv, idx)
%assign y = LibBlockOutputSignal(0, ““, lcv, idx)
if ( %<u> <= xData[0] ) {
%<y> = yData[0];
} else if ( %<u> >= yData[%<xDataLen-1>] ) {
%<y> = yData[%<xDataLen-1>];
} else {
int_T idx = (int_T)( ( %<u> - xData[0] ) / spacing );
%<y> = yData[idx];
}
%%
%% Generate an empty line if we are not rolling,
%% so that it looks nice in the generated code.
%%
%if lcv == “
%endif
%endroll
%else
%% When the XData is unevenly spaced, we use a bisection search to
%% locate the lookup index.
int_T idx;
%assign xDataAddr = LibBlockParameterAddr(XData, ““, ““, 0)
%roll idx = RollRegions, lcv = RollThreshold, block, “Roller”, rollVars
%assign u = LibBlockInputSignal(0, ““, lcv, idx)
idx = GetDirectLookupIndex(xData, %<xDataLen>, %<u>);
%assign y = LibBlockOutputSignal(0, ““, lcv, idx)
%<y> = yData[idx];
%%
%% Generate an empty line if we are not rolling,
%% so that it looks nice in the generated code.
%%
%if lcv == “