Main Content

S-Function SimStruct Functions

About SimStruct Functions

The Simulink® software provides a set of functions for accessing the fields of an S-function's simulation data structure (SimStruct). S-function callback methods use these functions to store and retrieve information about an S-function.

Language Support

Some SimStruct functions are available only in some of the languages supported by the Simulink software. The reference page for each SimStruct macro or function lists the languages in which it is available and gives the syntax for these languages.

Note

Most SimStruct functions available in C are implemented as C macros. Individual reference pages indicate any SimStruct macro that becomes a function when you compile your S-function in debug mode (mex -g).

The SimStruct

The file simstruc.h is a C language header file that defines the Simulink data structure and the SimStruct access macros. It encapsulates all the data relating to the model or S-function, including block parameters and outputs.

There is one SimStruct data structure allocated for the Simulink model. Each S-function in the model has its own SimStruct associated with it. The organization of these SimStructs is much like a directory tree. The SimStruct associated with the model is the root SimStruct. The SimStructs associated with the S-functions are the child SimStructs.

SimStruct Macros and Functions Listed by Usage

Buses

MacroDescription
ssGetBusElementComplexSignalGet the signal complexity for a bus element.
ssGetBusElementDataTypeGet the data type identifier for a bus element.
ssGetBusElementDimensionsGet the dimensions of a bus element.
ssGetBusElementNameGet the name of a bus element.
ssGetBusElementNumDimensionsGet the number of dimensions for a bus element.
ssGetBusElementOffsetGet the offset from the start of the bus data type to a bus element.
ssGetNumBusElementsGet the number of elements in a bus signal.
ssGetSFcnParamNameGet the value of a block parameter for an S-function block.
ssIsDataTypeABusDetermine whether a data type identifier represents a bus signal.
ssRegisterTypeFromParameterRegister a data type that a parameter in the Simulink data type table specifies.
ssSetBusInputAsStructSpecify whether to convert the input bus signal for an S-function from virtual to nonvirtual.
ssSetBusOutputAsStructSpecify whether the output bus signal from an S-function must be virtual or nonvirtual.
ssSetBusOutputObjectNameSpecify the name of the bus object that defines the structure and type of the output bus signal.

Data Type

MacroDescription
ssGetDataTypeIdGet the ID for a data type.
ssGetDataTypeIdAliasedThruToGet the ID for the built-in data type associated with a data type alias.
ssGetDataTypeNameGet a data type's name.
ssGetDataTypeSizeGet a data type's size.
ssGetDataTypeZeroGet the zero representation of a data type.
ssGetInputPortDataTypeGet the data type of an input port.
ssGetNumDataTypesGet the number of data types defined by an S-function or the model.
ssGetOutputPortDataTypeGet the data type of an output port.
ssGetOutputPortSignalGet an output signal of any type except double.
ssGetSFcnParamDataTypeGet the data type of a parameter.
ssRegisterDataTypeRegister a data type.
ssSetDataTypeSizeSpecify the size of a data type.
ssSetDataTypeZeroSpecify the zero representation of a data type.
ssSetInputPortDataTypeSpecify the data type of signals accepted by an input port.
ssSetOutputPortDataTypeSpecify the data type of an output port.

Dialog Box Parameters

MacroDescription
ssGetDTypeIdFromMxArrayGet the Simulink data type of a dialog parameter.
ssGetNumSFcnParamsGet the number of parameters that an S-function expects.
ssGetSFcnParamGet a parameter entered by a user in the S-Function block dialog box.
ssGetSFcnParamsCountGet the actual number of parameters specified by the user.
ssSetNumSFcnParamsSet the number of parameters that an S-function expects.
ssSetSFcnParamTunableSpecify the tunability of a dialog box parameter.

Error Handling and Status

MacroDescription
ssGetErrorStatusGet a character vector that identifies the last error.
ssGetLocalErrorStatusGet a character vector that identifies the last error in a thread-safe manner.
ssPrintfPrint a variable-content msg.
ssSetErrorStatusReport errors.
ssSetLocalErrorStatusReport errors in a thread-safe manner.
ssWarningDisplay a warning message.

Function Call

MacroDescription
ssCallSystemWithTidExecute a function-call subsystem connected to an S-function.
ssDisableSystemWithTidDisable a function-call subsystem connected to this S-function block.
ssEnableSystemWithTidEnable a function-call subsystem connected to this S-function.
ssGetCallSystemNumFcnCall-
Destinations
Get the number of function-call destinations.
ssGetExplicitFCSSCtrlDetermine whether this S-function explicitly enables and disables the function-call subsystem that it invokes.
ssSetCallSystemOutputSpecify that an output port element issues a function call.
ssSetExplicitFCSSCtrlSpecify whether an S-function explicitly enables and disables the function-call subsystem that it calls.

Input and Output Ports

I/O Port — Signal Specification

MacroDescription
ssAllowSignalsWithMoreThan2DEnable S-function to work with multidimensional input and output signals.
ssGetInputPortComplexSignalGet the numeric type (complex or real) of an input port.
ssGetInputPortDataTypeGet the data type of an input port.
ssGetInputPortDirectFeedThroughDetermine whether an input port has direct feedthrough.
ssGetInputPortFrameDataDetermine whether a port accepts signal frames.
ssGetInputPortOffsetTimeDetermine the offset time of an input port.
ssGetInputPortRequiredContiguousDetermine whether the signal elements entering a port must be contiguous.
ssGetInputPortSampleTimeDetermine the sample time of an input port.
ssGetInputPortSampleTimeIndexGet the sample time index of an input port.
ssGetInputPortUnitGet unit of input port
ssGetOutputPortComplexSignalGet the numeric type (complex or real) of an output port.
ssGetOutputPortDataTypeGet the data type of an output port.
ssGetOutputPortFrameDataDetermine whether a port outputs signal frames.
ssGetOutputPortOffsetTimeDetermine the offset time of an output port.
ssGetOutputPortSampleTimeDetermine the sample time of an output port.
ssGetOutputPortUnitGet unit of output port
ssRegisterUnitFromExprRegister unit from unit expression
ssSetInputPortComplexSignalSet the numeric type (real or complex) of an input port.
ssSetInputPortDataTypeSet the data type of an input port.
ssSetInputPortDirectFeedThroughSpecify that an input port is a direct-feedthrough port.
ssSetInputPortOffsetTimeSpecify the sample time offset for an input port.
ssSetInputPortRequiredContiguousSpecify that the signal elements entering a port must be contiguous.
ssSetInputPortSampleTimeSet the sample time of an input port.
ssSetInputPortUnitSpecify unit of input port
ssSetNumInputPortsSet the number of input ports on an S-Function block.
ssSetNumOutputPortsSpecify the number of output ports on an S-Function block.
ssSetOneBasedIndexInputPortSpecify that an input port expects one-based indices.
ssSetOneBasedIndexOutputPortSpecify that an output port emits one-based indices.
ssSetOutputPortComplexSignalSpecify the numeric type (real or complex) of this port.
ssSetOutputPortDataTypeSpecify the data type of an output port.
ssSetOutputPortOffsetTimeSpecify the sample time offset value of an output port.
ssSetOutputPortSampleTimeSpecify the sample time of an output port.
ssSetOutputPortUnitSpecify unit of output port
ssSetZeroBasedIndexInputPortSpecify that an input port expects zero-based indices.
ssSetZeroBasedIndexOutputPortSpecify that an output port emits zero-based indices.

I/O Port — Signal Dimensions

MacroDescription
ssAddOutputDimsDependencyRuleRegister a method to handle current dimensions update.
ssAddVariableSizeSignalsRuntimeCheckerRegister a method to check the current input dimensions.
ssAllowSignalsWithMoreThan2DEnable S-function to work with multidimensional signals.
ssGetCurrentInputPortDimensionsGets the current size of dimension dIdx of input port pIdx.
ssGetCurrentInputPortWidthGets the total width (total number of elements) of the signal at input port pIdx
ssGetCurrentOutputPortDimensionsGets the current size of dimension dIdx of the signal at output port pIdx.
ssGetCurrentOutputPortWidthGets the total width (total number of elements) of the signal at output port pIdx.
ssGetInputPortDimensionsGet the dimensions of the signal accepted by an input port.
ssGetInputPortDimensionSizeGet the size of one dimension of the signal entering an input port.
ssGetInputPortDimensionsModeGets the dimensions mode of the input port indexed by pIdx,
ssGetInputPortNumDimensionsGet the dimensionality of the signals accepted by an input port.
ssGetInputPortWidthDetermine the width of an input port.
ssGetOutputPortDimensionsGet the dimensions of the signal leaving an output port.
ssGetOutputPortDimensionSizeGet the size of one dimension of the signal leaving an output port.
ssGetOutputPortDimensionsModeSets the dimensions mode of the output port indexed by pIdx.
ssGetOutputPortNumDimensionsGet the number of dimensions of an output port.
ssGetOutputPortWidthDetermine the width of an output port.
ssSetCurrentOutputPortDimensionsSets the current size corresponding to dimension dIdx of the output signal at port pIdx.
ssSetDWorkRequireResetForSignalSizeSet the block flag for resetting the dIndex DWork size upon subsystem reset.
ssSetInputPortDimensionInfoSet the dimensionality of an input port.
ssSetInputPortDimensionsModeSets the dimensions mode of the input port indexed by pIdx.
ssSetInputPortDimsSameAsOutputPortDimsSet the dimensions of output port outIdx to be equal than the dimensions of input port inpIdx.
ssSetInputPortMatrixDimensionsSpecify dimension information for an input port that accepts matrix signals.
ssSetInputPortVectorDimensionSpecify dimension information for an input port that accepts vector signals.
ssSetInputPortWidthSet the width of a 1-D (vector) input port.
ssSetOutputPortDimensionInfoSpecify the dimensionality of an output port.
ssSetOutputPortDimensionsModeSets the dimensions mode of the output port indexed by pIdx.
ssSetOutputPortMatrixDimensionsSpecify dimension information for an output port that emits matrix signals.
ssSetOutputPortVectorDimensionSpecify dimension information for an output port that emits vector signals.
ssSetOutputPortWidthSpecify the width of a 1-D (vector) output port.
ssSetOutputPortMatrixDimensionsSpecify the dimensions of a 2-D (matrix) signal.
ssRegMdlSetInputPortDimensionsModeFcnRegister the method to handle dimensions mode propagation for each input port.
ssSetSignalSizesComputeTypeSet the type of output dependency on the input signal.
ssSetVectorModeSpecify the vector mode that an S-function supports.

I/O Port — Signal Access

MacroDescription
ssGetInputPortBufferDstPortDetermine the output port that is overwriting an input port's memory buffer.
ssGetInputPortConnectedDetermine whether an S-Function block port is connected to a nonvirtual block.
ssGetInputPortOptimOptsDetermine the reusability setting of the memory allocated to the input port of an S-function.
ssGetInputPortOverWritableDetermine whether an input port can be overwritten.
ssGetInputPortRealSignalGet the address of a real, contiguous signal entering an input port.
ssGetInputPortRealSignalPtrsAccess the signal elements connected to an input port.
ssGetInputPortSignalGet the address of a contiguous signal entering an input port.
ssGetInputPortSignalPtrsGet pointers to input signal elements of type other than double.
ssGetNumInputPortsCan be used in any routine (except mdlInitializeSizes) to determine how many input ports a block has.
ssGetNumOutputPortsCan be used in any routine (except mdlInitializeSizes) to determine how many output ports a block has.
ssGetOutputPortConnectedDetermine whether an output port is connected to a nonvirtual block.
ssGetOutputPortBeingMergedDetermine whether the output of this block is connected to a Merge block.
ssGetOutputPortOptimOptsDetermine the reusability of the memory allocated to the output port of an S-function.
ssGetOutputPortRealSignalAccess the elements of a signal connected to an output port.
ssGetOutputPortSignalGet the vector of signal elements emitted by an output port.
ssSetInputPortOptimOptsSpecify the reusability of the memory allocated to the input port of an S-function.
ssSetInputPortOverWritableSpecify whether an input port is overwritable by an output port.
ssSetOutputPortOptimOptsSpecify the reusability of the memory allocated to the output port of an S-function.
ssSetOutputPortOverwritesInputPortSpecify whether an output port can share its memory buffer with an input port.

Model Reference

MacroDescription
ssRTWGenIsModelReferenceRTWTargetDetermine if the model reference Simulink Coder™ target is generating.
ssRTWGenIsModelReferenceSIMTargetDetermine if the model reference simulation target is generating.
ssSetModelReferenceNormalModeSupportSpecify if S-function can be used in referenced model simulating in normal mode.
ssSetModelReferenceSampleTimeDefaultInheritanceSpecify that a referenced model containing this S-function can inherit its sample time from its parent model.
ssSetModelReferenceSampleTimeDisallowInheritanceSpecify that the use of this S-function in a referenced model prevents the referenced model from inheriting its sample time from its parent model.
ssSetModelReferenceSampleTimeInheritanceRuleSpecify whether use of an S-function in a referenced model prevents the referenced model from inheriting its sample time from the parent model.

Run-Time Parameters

These macros allow you to create, update, and access run-time parameters corresponding to a block's dialog parameters.

MacroDescription
ssGetNumRunTimeParamsGet the number of run-time parameters created by this S-function.
ssGetRunTimeParamInfoGet the attributes of a specified run-time parameter.
ssRegAllTunableParamsAsRunTimeParamsRegister all tunable dialog parameters as run-time parameters.
ssRegDlgParamAsRunTimeParamRegister a run-time parameter.
ssSetNumRunTimeParamsSpecify the number of run-time parameters to be created by this S-function.
ssSetRunTimeParamInfoSpecify the attributes of a specified run-time parameter.
ssUpdateAllTunableParamsAsRunTimeParamsUpdate all run-time parameters corresponding to tunable dialog parameters.
ssUpdateDlgParamAsRunTimeParamUpdate a run-time parameter.
ssUpdateRunTimeParamDataUpdate the value of a specified run-time parameter.
ssUpdateRunTimeParamInfoUpdate the attributes of a specified run-time parameter from the attributes of the corresponding dialog parameters.

Sample Time

MacroDescription
ssGetInputPortSampleTimeDetermine the sample time of an input port.
ssGetInputPortSampleTimeIndexGet the sample time index of an input port.
ssGetNumSampleTimesGet the number of sample times an S-function has.
ssGetOffsetTimeDetermine one of an S-function's sample time offsets.
ssGetOutputPortSampleTimeDetermine the sample time of an output port.
ssGetPortBasedSampleTimeBlockIsTriggeredDetermine whether a block that uses port-based sample times resides in a triggered subsystem.
ssGetSampleTimeDetermine one of an S-function's sample times.
ssGetTNextGet the time of the next sample hit in a discrete S-function with a variable sample time.
ssIsContinuousTaskDetermine whether a specified rate is the continuous rate.
ssIsSampleHitDetermine the sample rate at which an S-function is operating.
ssIsSpecialSampleHitDetermine whether the current sample time hits two specified rates.
ssSampleAndOffsetAreTriggeredDetermine whether a sample time and offset value pair indicate a triggered sample time.
ssSetInputPortSampleTimeSet the sample time of an input port.
ssSetModelReferenceSampleTimeDefaultInheritanceSpecify that a referenced model containing this S-function can inherit its sample time from its parent model.
ssSetModelReferenceSampleTimeDisallowInheritanceSpecify that the use of this S-function in a referenced model prevents the referenced model from inheriting its sample time from its parent model.
ssSetModelReferenceSampleTimeInheritanceRuleSpecify whether use of an S-function in a referenced model prevents the referenced model from inheriting its sample time from the parent model.
ssSetNumSampleTimesSet the number of sample times an S-function has.
ssSetOffsetTimeSpecify the offset of a sample time.
ssSetSampleTimeSpecify a sample time for an S-function.
ssSetTNextSpecify the time of the next sample hit in an S-function.

Simulation Information

MacroDescription
ssGetBlockReductionDetermine whether a block has requested block reduction before the simulation has begun and whether it has actually been reduced after the simulation loop has begun.
ssGetErrorStatusGet a character vector that identifies the last error.
ssGetFixedStepSizeGet the fixed step size of the model containing the S-function.
ssGetMaxStepSizeGet the maximum step size of the model containing the S-function.
ssGetMinStepSizeGet the minimum step size of the model containing the S-function.
ssGetSimModeDetermine the context in which an S-function is being invoked: normal simulation, external-mode simulation, model editor, etc.
ssGetSimStatusDetermine the current simulation status.
ssGetSolverModeGet the solver mode being used to solve the S-function.
ssGetSolverNameGet the name of the solver being used for the simulation.
ssGetStateAbsTolGet the absolute tolerance used by the model's variable-step solver for a specified state.
ssGetStopRequestedGet the value of the simulation stop requested flag.
ssGetTGet the current base simulation time.
ssGetTaskTimeGet the current time for a task.
ssGetTFinalGet the end time of the current simulation.
ssGetTNextGet the time of the next sample hit.
ssGetTStartGet the start time of the current simulation.
ssIsExternalSimDetermine if the model is running in external mode.
ssIsFirstInitCondDetermine whether the current simulation time is equal to the simulation start time.
ssIsMajorTimeStepDetermine whether the current time step is a major time step.
ssIsMinorTimeStepDetermine whether the current time step is a minor time step.
ssIsVariableStepSolverDetermine whether the current solver is a variable-step solver.
ssRTWGenIsAccelerator Determine if the model is running in Accelerator mode.
ssSetStateAbsTolSet the values of the absolute tolerances that the variable-step solver will apply to the S-function states.
ssSetBlockReductionRequest that Simulink attempt to reduce a block.
ssSetOperatingPointComplianceSpecify how Simulink treats an S-function when saving and restoring the simulation state of a model containing the S-function.
ssSetOperatingPointVisibilitySpecify whether or not the simulation state of the S-function is visible (accessible) in the simulation state of the model.
ssSetSolverNeedsResetAsk Simulink to reset the solver.
ssSetStopRequestedAsk Simulink to terminate the simulation at the end of the current time step.

State and Work Vector

MacroDescription
ssGetContStatesGet an S-function's continuous states.
ssGetDiscStatesGet an S-function's discrete states.
ssGetDWorkGet a DWork vector.
ssGetDWorkComplexSignalDetermine whether the elements of a DWork vector are real or complex numbers.
ssGetDWorkDataTypeGet the data type of a DWork vector.
ssGetDWorkNameGet the name of a DWork vector.
ssGetDWorkUsageTypeDetermine how the DWork vector is used in S-function.
ssGetDWorkUsedAsDStateDetermine whether a DWork vector is used as a discrete state vector.
ssGetDWorkWidthGet the size of a DWork vector.
ssGetdXGet the derivatives of the continuous states of an S-function.
ssGetIWorkGet an S-function's integer-valued (int_T) work vector.
ssGetIWorkValueGet a value from a block's integer work vector.
ssGetModeVectorGet an S-function's mode work vector.
ssGetModeVectorValueGet an element of a block's mode vector.
ssGetNonsampledZCsGet an S-function's zero-crossing signals vector.
ssGetNumContStatesDetermine the number of continuous states that an S-function has.
ssGetNumDiscStatesDetermine the number of discrete states that an S-function has.
ssGetNumDWorkGet the number of Dwork vectors used by a block.
ssGetNumIWorkGet the size of an S-function's integer work vector.
ssGetNumModesDetermine the size of an S-function's mode vector.
ssGetNumNonsampledZCsDetermine the number of nonsampled zero crossings that an S-function detects.
ssGetNumPWorkDetermine the size of an S-function's pointer work vector.
ssGetNumRWorkDetermine the size of an S-function's real-valued (real_T) work vector.
ssGetPWorkGet an S-function's pointer (void *) work vector.
ssGetPWorkValueGet a pointer from a pointer work vector.
ssGetRealDiscStatesGet the real (real_T) values of an S-function's discrete state vector.
ssGetRWorkGet an S-function's real-valued (real_T) work vector.
ssGetRWorkValueGet an element of an S-function's real-valued work vector.
ssSetDWorkComplexSignalSpecify whether the elements of a Dwork vector are real or complex.
ssSetDWorkDataTypeSpecify the data type of a Dwork vector.
ssSetDWorkNameSpecify the name of a Dwork vector.
ssSetDWorkUsageTypeSpecify how the DWork vector is used in S-function.
ssSetDWorkUsedAsDStateSpecify that a Dwork vector is used as a discrete state vector.
ssSetDWorkWidthSpecify the width of a Dwork vector.
ssSetIWorkValueSet an element of a block's integer work vector.
ssSetModeVectorValueSet an element of a block's mode vector.
ssSetNumContStatesSpecify the number of continuous states that an S-function has.
ssSetNumDiscStatesSpecify the number of discrete states that an S-function has.
ssSetNumDWorkSpecify the number of Dwork vectors used by a block.
ssSetNumIWorkSpecify the size of an S-function's integer (int_T) work vector.
ssSetNumModesSpecify the number of operating modes that an S-function has.
ssSetNumNonsampledZCsSpecify the number of zero crossings that an S-function detects.
ssSetNumPWorkSpecify the size of an S-function's pointer (void *) work vector.
ssSetNumRWorkSpecify the size of an S-function's real (real_T) work vector.
ssSetPWorkValueSet an element of a block's pointer work vector.
ssSetRWorkValueSet an element of a block's floating-point work vector.

Code Generation

MacroDescription
ssGetDWorkRTWIdentifierGet the identifier used to declare a DWork vector in code generated from the associated S-function.
ssGetDWorkRTWIdentifierMustResolveToSignalObjectGet a flag indicating if a DWork vector resolves to a Simulink.Signal object.
ssGetDWorkRTWStorageClassGet the storage class of a DWork vector in code generated from the associated S-function.
ssGetDWorkRTWTypeQualifierGet the C type qualifier (e.g., const) used to declare a DWork vector in code generated from the associated S-function.
ssGetNumInputPortsGet the number of input ports that a block has
ssGetNumOutputPortsGet the number of output ports that a block has
ssGetPlacementGroupGet the name of the placement group of a block.
ssRTWGenIsCodeGenIdentify any code generation that is not used by the Accelerator.
ssSetArrayLayoutForCodeGenSpecify array layout of the S-function.
ssSetDWorkRTWIdentifierSet the identifier used to declare a DWork vector in code generated from the associated S-function.
ssSetDWorkRTWIdentifierMustResolveToSignalObjectSpecify if a DWork vector resolves to a Simulink.Signal object.
ssSetDWorkRTWStorageClassSet the storage class of a DWork vector in code generated from the associated S-function.
ssSetDWorkRTWTypeQualifierSet the C type qualifier (e.g., const) used to declare a DWork vector in code generated from the associated S-function.
ssSetPlacementGroupSpecify the name of the placement group of a block.
ssWriteRTW2dMatParamWrite a Simulink matrix parameter to the S-function's model.rtw file.
ssWriteRTWMx2dMatParamWrite a MATLAB® matrix parameter to the S-function's model.rtw file.
ssWriteRTWMxVectParamWrite a MATLAB vector parameter to the S-function's model.rtw file.
ssWriteRTWParametersWrite tunable parameters to the S-function's model.rtw file.
ssWriteRTWParamSettingsWrite settings for the S-function's parameters to the model.rtw file.
ssWriteRTWScalarParamWrite a scalar parameter to the S-function's model.rtw file.
ssWriteRTWStrWrite a character vector to the S-function's model.rtw file.
ssWriteRTWStrParamWrite a character vector parameter to the S-function's model.rtw file.
ssWriteRTWStrVectParamWrite a character vector vector parameter to the S-function's model.rtw file.
ssWriteRTWVectParamWrite a Simulink vector parameter to the S-function's model.rtw file.
ssWriteRTWWorkVectWrite the S-function's work vectors to the model.rtw file.

Miscellaneous

MacroDescription
ssCallExternalModeFcnInvoke the external mode function for an S-function.
ssGetModelNameGet the name of an S-Function block or model containing the S-function.
ssGetParentSSGet the parent of an S-function.
ssGetPathGet the path of an S-function or the model containing the S-function.
ssGetRootSSReturn the root (model) SimStruct.
ssGetUserDataAccess user data.
ssSetExternalModeFcnSpecify the external mode function for an S-function.
ssSetOptionsSet various simulation options.
ssSetPlacementGroupSpecify the execution order of a sink or source S-function.
ssSetUserDataSpecify user data.
ssSupportsMultipleExecInstancesAllow an S-function to operate within a For Each Subsystem.