Are Fortran mex files restricted to fixed format?

조회 수: 3 (최근 30일)
Josh G.
Josh G. 2019년 3월 28일
댓글: Josh G. 2019년 4월 8일
I'm learning to mex Fortran files and am having trouble with the timestwo.F tutorial. I'm able to compile and run the built-in, fixed format example file without a problem. However, when I tried to compile my own free format file named timestwo.f90, I got a bunch of errors about invalid preprocessor directives.
From a MATLAB Answers question, I found that I needed to capitalize the f in the file extension. mex timestwo.F90 completes successfully. When I try to use the function, though, I get an error:
Invalid MEX-file '/home/user/Documents/MATLAB/mex/timestwo.mexa64': /home/user/Documents/MATLAB/mex/timestwo.mexa64: undefined
symbol: mxgetdoubles_
The only difference between my file and the example file is that mine is free format and doesn't include the #if MX_HAS_INTERLEAVED_COMPLEX check found in the example file. Is this an issue with support for free format source?

답변 (1개)

Josh G.
Josh G. 2019년 3월 28일
I figured this out a few minutes after posting my question by trying something I thought I had already tried: adding the -R2018a option. My guess is I had to both add -R2018a to the mex options and change the file extension to .F90, which I had probably tried individually but not simultaneously. I'll leave the question up in case someone has this same problem in the future when getting into using Fortran mex files.
  댓글 수: 2
James Tursa
James Tursa 2019년 4월 3일
편집: James Tursa 2019년 4월 3일
The -R2018a option is related to whether you are using the old separate complex data format interface or the new interleaved complex data format interface. This has nothing to do with your fixed or free format source code problems.
In the past, the free format problem has been caused by MATLAB having a "/fixed" COMPFLAGS option in their build files, forcing the compilation to be fixed format regardless of extension. Alas, I just checked a Fortran build file for version R2018b WIN64 and this silly option is still there in spite of my repeated attempts at getting TMW to remove it. This may be the root cause of your fixed/free problems. The solution is to edit the build files (e.g., intel_fortran_18_vs2017.xml) and remove the "/fixed" option from the COMPFLAGS line. That will let the compiler choose fixed or free format based on file extension (.f or .f90 respectively) as it should be. I wouldn't think the compiler would care about upper/lower case for the extension, but maybe something in the MATLAB build scripts does.
@TMW, are you ever going to remove that "/fixed" option? It only causes problems!
Josh G.
Josh G. 2019년 4월 8일
Using the -R2018a option was why my code started working, but you're right that it has nothing to do with formatting.
It turns out mxGetDoubles was introduced in R2018b; you have to use mxGetPr for pre-R2018b compatibility.
I'm on Linux, so fortunately I don't have a fixed format flag built into the gfortran mexopts file, but over the past week I've had to work on a Windows system a good bit and have had to deal with repeatedly removing the /fixed flag while resetting the compiler configuration. It's beyond me why they would include that when it doesn't cause any problems to remove it.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Fortran with MATLAB에 대해 자세히 알아보기

태그

제품


릴리스

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by