User`s guide
3 Writing S-Functions As C-MEX files
3-28
mdlInitializeSizes function. Supplied ma cros set values for the structure
fields. If a value is not specified, it is initialized to zero.
There are additional macros that get various values. For a complete list of
built-in macros that work with C language S-functions, see “The C MEX
S-Function SimStruct” on page 3–97.
mdlInitializeSizes
mdlInitializeSizes is the first routine Simulink calls when interacting with
an S-function. This routine specifies the
sizes informatio n Simulink uses to
determine the S-function block’s characteristics (number of inputs, outputs,
states, etc.).
The d irect feedthrough flag for each input port can be set to either
1=yes or
0=no. It should be set to 1 if the input, u,isusedinthemdlOutput or
mdlGetTimeOfNextVarHit routine. Setting the directfeedthrough flag to0 tells
Simulink tha t
u wil l not be used in either of these S-function routines.
Violating this will lead to unpredictable results.
You can set the parameters
NumContStates, NumDiscStates, NumInputs,
NumOutputs, NumRWork, NumIWork, NumPWork, NumModes,andNumNonsampledZCs
to a fixe d no nnegative integer or tell Simulink to size them dynamica lly:
• DYNAMICALLY_SIZED — Sets lengths of states, work vectors, and so on to
values inherit ed from the driving block. It sets widths to the actual input
width, according to the scalar expansion rules unless you use
mdlSetWorkWidths to set the widths.
•
0 or positive number — Sets lengths (or widths) to the specified value. The
default is
0.
In addition, you can use these macros to set and verify information in your
mdlInitializeSizes routine:
• Use
ssGetInputPortConnected(S) and ssGetOutputPortConnected(S)
macrosafter settingthe numberofi nput andoutputports todetermine ifthe
ports are connected.
• Use
ssSetSFcnParamNotTunable(S,paramIdx) when a parameter cannot
change during simulation, where
paramIdx starts at 0. When a parameter
has been speci fied as “not tunable,” Simulink will is sue an error during