Writing S-Functions    

An Example C-MEX S-Function Calling Fortran Code

The subroutine Atmos is in file sfun_atmos_sub.for. The gateway C-MEX S-function is sfun_atmos.c, which is built on UNIX using the command

On Windows, the command is

On some UNIX systems where the C and Fortran compiler were installed separately (or aren't aware of each other), you may need to reference the library libf2c.a. To do this, use the -lf2c flag.

UNIX only: if the libf2c.a library isn't on the library path, you need to add it the path to the mex process explicitly with the -L command, for instance:

This sample is prebuilt and is on the MATLAB search path already, so you can see it working by opening the sample model sfcndemo_atmos.mdl. Just type

at the command prompt, or to get all the S-function demos for Simulink, type sfcndemos at the MATLAB prompt.


 Constructing the Gateway Porting Legacy Code