

When you use the C gateway to Fortran, it is possible to use Fortran compilers not supported by the mex command, but only if the object file format is compatible with the C compiler format. If you use the compilers explicitly supported by the mex command this is not a problem.

Your C and Fortran compilers need to use the same object format. Test the installation and setup using sample MEX files from MATLAB's C and Fortran MEX examples in matlabroot /extern/examples/mex, as well as Simulink's examples, which are located in matlabroot /simulink/src.
Simply fortran purchase install#
If you install or change compilers, you must run mex -setup.

Remember that mex -setup needs to find both the C and the Fortran compilers. The following are some tips for creating the C-to-Fortran gateway S-function. It works with a simple Fortran subroutine if you modify the Fortran subroutine name in the code. The file matlabroot/simulink/src/sfungate.c is a C-MEX template file for calling into a Fortran subroutine. If instead your Fortran code already exists as a stand-alone simulation, there is some work to be done to identify parts of the code that need to be registered with Simulink, such as identifying continuous states if you are using variable-step solvers or getting rid of static variables if you want to have multiple copies of the S-function in a Simulink model (see Porting Legacy Code). Using the C-MEX S-function as a gateway is quite simple if you are writing the Fortran code from scratch. To use the features of a level 2 S-function with Fortran code, you must write a skeleton S-function in C that has code for interfacing to Simulink and also calls your Fortran code. Creating Fortran S-Functions (Writing S-Functions) Writing S-Functions
