Determine Output Type Using the Input Type
The following sample code from lines 243 through 261 of sfun_user_fxp_asr.c
gives
an example of using the data type of the input to your S-function
to calculate the output data type. Notice that in this code
The output is signed or unsigned to match the input
(a)
.The output is the same word length as the input
(b)
.The fraction length of the output depends on the input fraction length and the number of shifts
(c)
.#define MDL_SET_INPUT_PORT_DATA_TYPE static void mdlSetInputPortDataType(SimStruct *S, int port, DTypeId dataTypeIdInput) { if ( isDataTypeSupported( S, dataTypeIdInput ) ) { DTypeId dataTypeIdOutput; ssSetInputPortDataType( S, port, dataTypeIdInput ); dataTypeIdOutput = ssRegisterDataTypeFxpBinaryPoint( S, ssGetDataTypeFxpIsSigned( S, dataTypeIdInput ),
(a)
ssGetDataTypeFxpWordLength( S, dataTypeIdInput ),(b)
ssGetDataTypeFractionLength( S, dataTypeIdInput ) - V_NUM_BITS_TO_SHIFT_RGHT,(c)
0 /* false means do NOT obey data type override setting for this subsystem */ ); ssSetOutputPortDataType( S, 0, dataTypeIdOutput ); } }