User`s guide

Overview of the C MEX S-Function Routines
3-45
Specify vector widths in mdlInitializeSizes. There are three choices:
0 (the default). This indicates that the vector is not used by your S-function.
A positive nonzero integer. This is the width of the vector that will be
available for use by
mdlStart, mdlInitializeConditions, and S -function
routines called in the simulation loop.
The
DYNAMICALLY_SIZED define. The default behavior for dynamically si zed
vectors is to set them to the overall block width. Simulink does this after
propagating line widths and sample times. The block width is the width of
the signal passing through your block. In general this is equal to the output
port width.
If the default behavior of dynamically s ized vectors does not meet your needs,
use
mdlSetWorkWidths and the macros listed in Table 3-4: “Macros Used in
Specifying Vector Widths” on page 3–44 to set explicitly the sizes of the work
vectors. Also,
mdlSetWorkWidths allows you to set your work vector lengths as
a functi on of the block sample time and/or port widths.
The continuous states a re used when you have a state that needs to be
integrated by one of Simulink’s solvers. When you specify continuous states,
you must return the states’ derivatives in
mdlDerivatives. The discrete state
vector is used to maintain state information that changes at fixed intervals.
Typically the discrete sta te vector is updated in place in
mdlUpdate.
The integer, real and pointer work vectorsare s torage locations that do not get
logged by Simulink during simulations. They maintain persistent data
between calls to your S-function.
Work Vectors and Zero Crossings
The mode-work vector and the nonsampled zero-crossing vector are typically
used with zero crossings. Elements of the mode vector are integer values. You
specify the number of mode-vector elements in
mdlInitializeSizes using
ssSetNumModes(S,num). You can then access the mode vector using
ssGetModeVector. The mode vector is used to determine how the mdlOutput
routine should operate when the solvers are honing in on zero crossings. The
zero crossings or state events (i.e., discontinuities in the first derivatives) of
some signal, usually a function of an input to your S-function, are track ed by
thesolverbylookingat the nonsampledzero crossings.To registernonsampled
zero crossings, set the number of nonsampled zero crossings in
mdlInitializeSizes using ssSetNumNonsampledZCs(S, num). Then, define