User`s guide
Fully Inlined S-Function with the mdlRTW Routine
4-23
index in the XData for the current x input value when the XData is unevenly
spaced. The
GetDirectLookupIndex routine is cal led from both the S-function
andthegenerated code.H ere theexampleusesthewrapper conceptforsharing
C code between Simulink MEX-files and the generated code.
If the
XData is evenly spaced, then both the S-function main module and the
generated code contain the lookup algorithm (not a call to the algorithm) to
compute the y-value of a given x-value because the algorithm is short. This
demonstrates the use of a fully inlined S-function for generating optimal code.
The inlined TLC file, which performs either a wrapper call or embeds the
optimal C code, is
sfun_directlook.tlc (see page 4–38).
Error Handling
In this example, the mdlCheckParameters routine on page 4–29 verifies that:
• The new parameter settings are correct.
•
XData and YData are vectors of the same length containing real finite
numbers.
•
XDataEvenlySpaced is a scalar.
• The
XData vector is a monotonically increasing vector and evenly spaced if
needed.
Notethatthe
mdlInitilizeSizes routineexplicitlycalls mdlCheckParameters
after it has verified the number of parameters passed to the S-function are
correct. After Simulink calls
mdlInitializeSizes, it will then call
mdlCheckParameters whenever you change the parameters or there is a need
to re-evaluate them.
User Data Caching
The mdlStart routine on page 4–32 illustrates how to cache information that
does not change during the simulation (or while the generated code is
executing).Theexamplecachesthevalueofthe
XDataEvenlySpaced parameter
in
UserData,afieldoftheSimStruct.The
ssSetSFcnParamNotTunable(S, XDATAEVENLYSPACED_PIDX);
line in mdlInitializeSizes tells Simulink to disallow changes to the
XDataEvenlySpaced parameter. During execution, mdlOutputs accesses the
value of
XDataEvenlySpaced from the UserData rather than calling the