Create Mex files for Matlab, from .FOR files of Fortran
13 Ansichten (letzte 30 Tage)
dpb am 12 Aug. 2023
Bearbeitet: dpb am 13 Aug. 2023
Which OS? For Linux, the GNU Fortran compiler is supported, for Windows and Mac only a recent version of the Intel compiler is supported.
It's unconscionable that TMW supports GNU for Linux but not for Windows and Mac; I, at least, have had no success in figuring out how to link although since it supports the GNU C compiler that the Fortran compiler is built on, it surely should be possible -- excepting for the name-mangling issues.
And, TMW has essentially quit supporting Fortran at all; the example files are still horribly outdated F77-style fixed-format with archaic at best non-standard syntax and other style problems.
You probably have a real challenge on your hands; the alternative may be to write interface routines in C and then have those call the Fortran code instead of trying to build direct Fortran mex interfaces.
@James Tursa is the real guru; hopefully he'll see and comment and have better pointers; my patience was exhausted some years ago and, fortunately, the need for additional support for the application I supported for a client while still consulting has, apparently, either gone away or they've found an alternate way so I've just given up.
James Tursa am 12 Aug. 2023
Bearbeitet: James Tursa am 12 Aug. 2023
So, I haven't had access to a Fortran compiler in over 10 years. And as a result I haven't been maintaining any of my Fortran FEX submissions. Kinda sad that this very fast matrix/array based language with the same memory-element order as MATLAB does not have free solutions for connecting with MATLAB, at least not for Windows, but that's the way it is. And @dpb, the Fortran examples supplied by TMW still have the same bugs in them, and the compile files probably still have the stupid /fixed option (forces free form source code to be compiled as fixed form source code ... generating lots of faux errors), that I pointed out over 10 years ago. I just submitted another request that they change this. Sigh ...
My suggestion depends on what your Fortran code does, and whether it has user I/O. If it is just number crunching, I would probably use whatever Fortran compiler you have to create .obj files. Then write a simple wrapper mex file in C that acts as a conduit for the input & output variables. Then just mex the wrapper C file and Fortran .obj files together.
If your code has user I/O, that is a whole different ball game ...
So, what does your Fortran code do? What are the inputs and outputs? Can you post the interface function signatures for us? Maybe we can quickly write the wrapper code for you.