User`s guide
3 Writing S-Functions As C-MEX files
3-30
The synopsis is
/* Function: mdlInitializeSizes ===============================================*
Abstract:
* The sizes information is used by Simulink to determine the S-function
* block's characteristics (number of inputs, outputs, states, etc.).
*
* The direct feedthrough flag can be either 1=yes or 0=no. It should be
* set to 1 if the input, "u", is used in the mdlOutput function. Setting
* this to 0 is tells Simulink that "u" will not be used in the
* mdlOutput function. If you violate this, unpredictable results
* will occur.
*
* The NumContStates, NumDiscStates, NumInputs, NumOutputs, NumRWork,
* NumIWork, NumPWork NumModes, and NumNonsampledZCs widths can be set to:
* DYNAMICALLY_SIZED - In this case, they will be set to the actual
* input width, unless you are have a
* mdlSetWorkWidths to set the widths.
* 0 or positive number - This explicitly sets item to the specified
* value.
*/
static void mdlInitializeSizes(SimStruct *S)
{
ssSetNumSFcnParams(S, 0); /* Number of expected parameters */
if (ssGetNumSFcnParams(S) != ssGetSFcnParamsCount(S)) {
/*
* If the the number of expected input parameters is not equal
* to the number of parameters entered in the dialog box return.
* Simulink will generate an error indicating that there is a
* parameter mismatch.
*/
return;
}
ssSetNumContStates( S, 0); /* number of continuous states */
ssSetNumDiscStates( S, 0); /* number of discrete states */
/*
* Configure the input ports. First set the number of input ports,
* then set for each input port index starting at 0, the width
* and wether or not the port has direct feedthrough (1=yes, 0=no).
* The width of a port can be DYNAMICALLY_SIZED or greater than zero.
* A port has direct feedthrough if the input is used in either
* the mdlOutputs or mdlGetTimeOfNextVarHit functions.
*/
if (!ssSetNumInputPorts(S, nInputPorts)) return;
ssSetInputPortWidth(S, inputPortIdx, width);
ssSetInputPortDirectFeedThrough(S, inputPortIdx, needsInput);
/*
* Configure the output ports. First set the number of output ports,
* then set for each output port index starting at 0, the width