Writing S-Functions    

Creating Level 1 Fortran S-Functions

The Fortran MEX Template File

A template file for Fortran MEX S-functions is located at matlabroot/simulink/src/sfuntmpl_fortran.for. The template file compiles as is and copies the input to the output.

To use the template to create a new Fortran S-function:

  1. Create a copy under another filename.
  2. Edit the copy to perform the operations you need.
  3. Compile the edited file into a MEX file, using the mex command.
  4. Include the MEX file in your model, using the S-Function block.

  Level 1 Versus Level 2 S-Functions Example