fortran 90 mex on Mac

3 views (last 30 days)
Petar Bakalov
Petar Bakalov on 24 Oct 2011
I have some fortran 90 code and I have written a mex gateway function for it. Everything compiled and worked OK under Windows. Now I tried compiling on a mac and I run into some problems.
First hurdle was making mex work with the provided examples (yprimef.F). Thanks to some previous posts, after editing my mexopts.sh, I managed to compile and the example seems to work OK.
However, when I try to mex my .f90 files (which are in free-form source), I get the following:
Warning: FD_CVg.f90:1: Illegal preprocessor directive
Warning: FD_CVg.f90:56: Illegal preprocessor directive
Warning: FD_CVg.f90:67: Illegal preprocessor directive
FD_CVg.f90:17.6:
MWPOINTER PLHS(*), PRHS(*)
1
Error: Unclassifiable statement at (1)
FD_CVg.f90:27.6:
MWPOINTER MXCREATEDOUBLEMATRIX, MXGETPR
1
Error: Unclassifiable statement at (1)
FD_CVg.f90:32.6:
MWSIZE MXGETM, MXGETN
1
Error: Unclassifiable statement at (1)
FD_CVg.f90:41.6:
MWPOINTER tp,ndp,nap,edp,eap,eoxp,toxp,skindp,qfp,fmp,vgminp, &
1
Error: Unclassifiable statement at (1)
FD_CVg.f90:49.6:
MWSIZE M, N, NEL
1
Error: Unclassifiable statement at (1)
... and so on ...
the lines 1, 56 and 67 that trigger warnings are:
#include <fintrf.h>
#if defined MSWIND
#endif
respectively.
Any suggestions how to fix that?
(Using gfortran with xcode 3.2 on Mac OS X 10.6.8 with 64 bit matlab)

Accepted Answer

fabio freschi
fabio freschi on 29 Oct 2011
The preprocessor directives are not recognized. If your gfortran version supports the -cpp (C PreProcessor) flag, use it. Otherwise just change the file extension to F90 (uppercase F): the preprocessor is automatically invoked.
Fabio
  1 Comment
Petar Bakalov
Petar Bakalov on 3 Nov 2011
Hello,
I checked, and indeed, changing the extension to F90 allows the mex to compile. Many thanks for that!
However, when I call the mex function ML crashes. (In the meantime I tinkered further with my mexopts.sh file, and now also the example mex-function yprime causes ML to crash, even though it seems to compile fine.)
In any case, the original problem of the post is solved, and I will start another thread for the rest.

Sign in to comment.

More Answers (3)

James Tursa
James Tursa on 24 Oct 2011
Is there a "/fixed" option (or similar) on the COMPFLAGS line in the mexopts file? If so, remove it. That is the typical problem with compiling free format source code on PC's. Don't know if this applies to mac or not.

Petar Bakalov
Petar Bakalov on 25 Oct 2011
I looked for something of the kind in the mexopts.sh file, and also checked a few other options files in /Applications/MATLAB_R2011b.app/bin, but didn't find anything.
Further suggestions would be appreciated, as it would be somewhat tedious translating all the code to fixed form... (I assume that not only the gateway function, but also the subroutines called from it would have to be rewritten.)

Petar Bakalov
Petar Bakalov on 29 Oct 2011
Thanks for the tip, Fabio. I will try this when I have the mac on Monday and let you know whether it worked out.

Categories

Find more on Fortran with MATLAB in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!