User`s manual
Fortran MEX-Files
3-3
Fortran MEX-Files
Fortran MEX-files are built by using the mex script to compile your Fortran
source code with additional calls to API routines.
MEX-files in Fortran can only create double-precision data and strings, unlike
their C counterparts, which can create any data type supported by MATLAB.
You can treat Fortran MEX-files, once compiled, exactly like M-functions.
The Components of a Fortran MEX-File
This section discusses the specific elements needed in a Fortran MEX-file. The
source code for a Fortran MEX-file, like the C MEX-file, consists of two distinct
parts:
•A computational routine that contains the code for performing the
computations that you want implemented in the MEX-file. Computations
can be numerical computations as well as inputting and outputting data.
•A gateway routine that interfaces the computational routine with MATLAB
by the entry point
mexFunction and its parameters prhs, nrhs, plhs, nlhs,
where
prhs is an array of right-hand input arguments, nrhs is the number
of right-hand input arguments,
plhs is an array of left-hand output
arguments, and
nlhs is the number of left-hand output arguments. The
gateway calls the computational routine as a subroutine.
The computational and gateway routines may be separate or combined. The
following figure, Fortran MEX Cycle, shows how inputs enter an API function,
what functions the gateway routine performs, and how output returns to
MATLAB.