You must have Simulink Real-Time Version 1.3 or later to use Fortran for real-time applications. The Simulink Real-Time product supports the Fortran compilers listed here:
The Simulink examples folder contains a tutorial and description on how to incorporate Fortran code into a Simulink model using S-functions. To access the tutorial and description:
Open Custom Code and Hand Coded Blocks using the S-function API (Simulink)
Open the associated model.
Open the Fortran S-functions example model. Fortran S-functions and associated templates appear.
This topic lists the general steps to incorporate Fortran code into a real-time application. Detailed commands follow in the accompanying examples.
Using the Fortran compiler, compile the Fortran subroutines
*.f). Specify particular compiler options.
Write a Simulink C-MEX wrapper S-function. This wrapper S-function calls one or more of the Fortran subroutines in the compiled Fortran object code from step 1.
mex function to compile this C-MEX
S-function using a Microsoft®
Visual C++® compiler. Define several Fortran run-time libraries to be linked in.
This step creates the Simulink S-function MEX-file.
To validate the compiled Fortran code and wrapper S-function, run a simulation C-MEX file with the Simulink software.
Copy the relevant Fortran run-time libraries to the real-time application build folder.
Define the Fortran libraries, and the Fortran object files from step 1, in the Simulink Coder™ dialog box of the Simulink model. Define these libraries and files as additional components to be linked in when the real-time application link takes place.
Initiate the Simulink Real-Time specific Simulink Coder build procedure for the example model. Simulink Coder builds and downloads Simulink Real-Time onto the target computer.