MATLAB: How to create Fortran 90 MEX files

90fortranMATLABmexsupport

How do I create Fortran 90 MEX files?
I would like to create MEX files from Fortran 90 source code. How can I do this?

Best Answer

For MATLAB 6.5 (R13), we are shipping an options file called f90opts.sh for Fortran 90 source code on Unix. This options file is able to compile fixed format Fortran 90 source code. You can set up this options file by using the following code:
mex -setup
and selecting f90opts.sh.
Similarly, on the PC, there is a df65opts.bat file that can be selected. This file is the same as the df60opts.bat file, except that it now can use the fpp (fortran preprocessor). Note however that Fortran 90 is already supported in both Visual Fortran 6.0 and 6.5 for MATLAB R12.1. Therefore Fortran 90 is already supported on the PC. This file can be invoked as follows:
mex -f <matlab>\bin\win32\mexopts\df65opts.bat <yourfortranfile.F>
Notes:
1. The Fortran 90 compiler for Linux we looked at was Vast Fortran 90, which is essentially a translator from Fortran 90 to Fortran 77. Consequently, on Linux, we only have Fortran 77 support.
2. In the event that you prefer to use the free form source code rather than the fixed form, please remove the -fixed or -qfixed flag from the f90opts.sh options file for your architecture.