Writing S-Functions    
mdlTerminate

Perform any actions required at termination of the simulation.

Syntax

Arguments

S
   SimStruct representing an S-Function block.

Description

This method should perform any actions, such as freeing memory, that must be performed at the end of simulation or when an S-Function block is destroyed (e.g., when it is deleted from a model). The option SS_OPTION_CALL_TERMINATE_ON_EXIT (see ssSetOptions) determines whether Simulink invokes this method. If this option is not set, Simulink invokes mdlTerminate at the end of simulation only if the mdlStart method of at least one block in the model has executed during simulation. If this option is set, Simulink always invokes the mdlTerminate method at the end of a simulation run and whenever it destroys a block.

Languages

Ada, C, M

Example

Suppose your S-function allocates blocks of memory in mdlStart and saves pointers to the blocks in a PWork vector. The following code fragment would free this memory.


  mdlStart mdlUpdate