Determine Output Type Using the Input Type - MATLAB & Simulink (original) (raw)

Main Content

The following sample code from lines 242 through 260 of [sfun_user_fxp_asr.c](https://mdsite.deno.dev/matlab:sfunddg%5Fcb%5Fedit%28'sfun%5Fuser%5Ffxp%5Fasr.c'%29;) 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

#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 );
}
}