User`s manual
3 Creating Fortran MEX-Files
3-6
The Gateway Routine
The entry point to the gateway subroutine must be named mexFunction and
must contain these parameters.
subroutine mexFunction(nlhs, plhs, nrhs, prhs)
integer plhs(*), prhs(*)
integer nlhs, nrhs
Note Fortran is case-insensitive. This document uses mixed-case function
names for ease of reading.
In a Fortran MEX-file, the parameters
nlhs and nrhs contain the number of
left- and right-hand arguments with which the MEX-file is invoked.
prhs is a
length
nrhs array that contains pointers to the right-hand side inputs to the
MEX-file, and
plhs is a length nlhs array that contains pointers to the
left-hand side outputs that your Fortran function generates.
In the syntax of the MATLAB language, functions have the general form
[a,b,c,…] = fun(d,e,f,…)
where the ellipsis (…) denotes additional terms of the same format. The a,b,c,…
are left-hand arguments and the
d,e,f,… are right-hand arguments.
As an example of the gateway routine, consider invoking a MEX-file from the
MATLAB workspace with the command
x = fun(y,z);
the MATLAB interpreter calls mexFunction with the arguments
nlhs = 1
nrhs = 2
plhs
prhs
•
Ø
•
Y
•
Z