External Interfaces/API    

The %val Construct

The %val construct is supported by most, but not all, Fortran compilers. DIGITAL Visual Fortran does support the construct. %val causes the value of the variable, rather than the address of the variable, to be passed to the subroutine. If you are using a Fortran compiler that does not support the %val construct, you must copy the array values into a temporary true Fortran array using special routines. For example, consider a gateway routine that calls its computational routine, yprime, by

If your Fortran compiler does not support the %val construct, you would replace the call to the computational subroutine with

You must also add the following declaration line to the top of the gateway routine.

Note that if you use mxCopyPtrToReal8 or any of the other mxCopy__ routines, the size of the arrays declared in the Fortran gateway routine must be greater than or equal to the size of the inputs to the MEX-file coming in from MATLAB. Otherwise mxCopyPtrToReal8 will not work correctly.


  Fortran MEX-Files Examples of Fortran MEX-Files