| Writing S-Functions | ![]() |
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
>> mex -v COMPFLAGS#"$COMPFLAGS /iface:cref" -c sfun_atmos_sub.for -f ..\..\bin\win32\mexopts\df60opts.bat >> mex -v LINKFLAGS#"$LINKFLAGS dfor.lib dfconsol.lib dfport.lib /LIBPATH:$DF_ROOT\DF98\LIB" sfun_atmos.c sfun_atmos_sub.obj
On some UNIX systems where the C and Fortran compilers were installed separately (or aren't aware of each other), you might 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 the path to the mex process explicitly with the -L command. For example:
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. Enter
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 | ![]() |