Beginner's Mex Error - MatLab
8 views (last 30 days)
Show older comments
I am beginning to use the mex setup to call fortran files from matlab. What I am trying to do is call a fortran subroutine inside an m-file. From what I've read, I need to run:
mex filename.f90
However, when I do that, I get lots of error messages of the type:
error #5149: Illegal
character in statement label field [s]
However, I am using a .f90 file that is supposedly correct (I got it from another source). Here are the first beginning lines of the fortran file:
subroutine mexFunction(nlhs,plhs,nrhs,prhs)
!--------------------------------------------------------------------
! Matlab gateway for sirff
implicit none
! pointers to input/output data
! always take INTEGER*8, to let it work on 64-bit machines (SGI e.g.)
! 32-bit compilers will correct this to INTEGER*4, so don't worry about the
! warning(s) on this during compilation.
integer(8) :: plhs(*), prhs(*)
I am a beginner to this, so bear with me please. Any help is appreciated.
Thanks.
0 Comments
Answers (2)
James Tursa
on 2 Feb 2015
Edited: James Tursa
on 2 Feb 2015
Check the associated mexopts file for the specific compiler/linker setup you are using and look for the COMPFLAGS line. If there is a "/fixed" option on that line, delete it! I have no idea why TMW continues this practice of forcing the compiler into fixed form mode when it should be left to the file extension (.f or .f90) to determine fixed or free format. E.g.,
Look in the following folder (or similar folder e.g. win64)
[matlabroot '\bin\win32\mexopts']
Older version of MATLAB use .bat files, newer versions of MATLAB use .xml files. Find the file name that is associated with your compiler. E.g., on my system there is the following file:
intel_fortran_13_v2012.xml
and when you open that file there is the following entry:
COMPFLAGS="/nologo /fpp /Qprec /fixed /MD /fp:source /assume:bscc $COMPDEFINES $INCLUDE"
The /fixed option shown is the likely problem. Get rid of it! I.e., edit the file and remove the /fixed text so the line reads:
COMPFLAGS="/nologo /fpp /Qprec /MD /fp:source /assume:bscc $COMPDEFINES $INCLUDE"
As another example, on an older version of MATLAB there is a .bat file, e.g.,
intelf12msvs2010opts.bat
And you will see the same "/fixed" problem on the COMPFLAGS line in that file. Get rid of it.
Finally, before you edit any of these files I would advise copying the entire directory to another location so that you can recover to the original files if necessary.
SIDE COMMENT:
I have no idea what the comment in the code "32-bit compilers will correct this to INTEGER*4" means ... I am unaware of any such "automatic" compiler behavior.
6 Comments
James Tursa
on 3 Feb 2015
Can you run "mex filename.f90 -v" to verify what settings are actually being used?
Quanshangze DU
on 22 Nov 2019
As a complement from the year 2019 ==>
I use MATLAB R2019a on Win10 and the 'mex' function, by the command 'mex -setup', is configured as "MEX configured to use 'Intel Parallel Studio XE 2015 for Fortran with Microsoft Visual Studio 2015' for FORTRAN language compilation."
I met the same problem as presented above because of the 'fixed format' by default. I tried to remove '/fixed' from the file in MATLABroot bin\win64\mexopts. As you may see, there are multiple files of configuration for Fortran, c and cpp, like intel_fortran_xx_vsxxxx.xml, where xx stands for 15/16/17.. and xxxx stand for 2015/17.... These files correspond to, I suppose, the configuration your matlab's mex function takes. I tried to modify the file of my case, namely 'intel_fortran_15_vs2015.xml'. But nothing has changed. Still the problem coming from fixed format. So I modifed all the xml files because of uncertainty.. It turned out meaingless.
So the file to modify is not in the folder '\bin\win64\mexopts', but in '\user\AppData\Roaming\MathWorks\Matlab\R2019a'. Just remove the term '\fixed' in the file 'mex_FORTRAN_win64.xml' and then it will work.
Good luck !
qdu
0 Comments
See Also
Categories
Find more on MATLAB Compiler 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!