I am trying to create a mex file for FORTRAN90 code. I get an error because of '&' and long sentences in the FORTRAN90 code

7 ビュー (過去 30 日間)
The FORTRAN90 code I am trying to mex has a main code with several modules. I am working with MATLAB 2017 and Intel Parallel Studio XE 2017 for fortran compiler. I have been able to mex some of the modules using
mex -c modulename.f90.
I got stuck with an error in a module that has '&' and some parts of the code that have long sentences. For example in this code:
if( .NOT. allocated(x) ) then
allocate( dset(n), aset(n), x0(n), g(n), g0(n), gF(n), &
& v(m+1), q(m+1), w(m+1), p(n), s(m+1), y(m+1), &
& B(n,m+1), B0(n,m+1), BB(m+1,m+1), T(m+1,m+1), R(m+1,m+1), F(n), &
& F0(n), tempM1(m+1), tempM2(m+1), brow(m+1), rrow(m+1), &
& trow(m+1), zrow(m+1), tempN1(n), tempN2(n) )
end if
real(rp), public :: tol1, tol2, tol3, tol4, tol5, wparam, fx, fx0, sigma
I get ' error #5082: Syntax error, found '&' when expecting one of: [ IDENTIFIER allocate( dset(n), aset(n), x0(n), g(n), g0(n), gF(n), &'. The same error appears wherever & is present.
Another error I get is 'error #6418: This name has already been assigned a data type. [FX] real(rp), public :: tol1, tol2, tol3, tol4, tol5, wparam, fx, fx'.
How can I get rid of these errors? Any help is appreciated.
  3 件のコメント
Shubham Baisthakur
Shubham Baisthakur 2021 年 4 月 22 日
I am facing the similar issue. Where can I find the mexopt files to change the COMPFLAG?
PS: I am using MATLAB R2020a
James Tursa
James Tursa 2021 年 4 月 22 日
E.g., in Win64
C:\Program Files\MATLAB\R2020a\bin\win64\mexopts

サインインしてコメントする。

採用された回答

James Tursa
James Tursa 2017 年 4 月 5 日
編集済み: James Tursa 2017 年 4 月 5 日
This is usually caused by TMW including a compiler option in the mex option files to force fixed field source even if the file has a .f90 extension. Normally, files ending in .f or .for are compiled as fixed field and files ending in .f90 are compiled as free field. But TMW has an option in their compiler flags to override that. I have no idea why they continue to do this. To fix it, edit the appropriate mexopts file(s) on your system. E.g., on my system there are these files:
intelf11msvs2008engmatopts.bat
intelf11msvs2008opts.bat
:
intelf11msvs2008shellengmatopts.bat
intelf11msvs2008shellopts.bat
:
etc
In these files you will see a COMPFLAGS line like this:
set COMPFLAGS=/fpp /Qprec /I"%MATLAB%/extern/include" /c /nologo /fixed /fp:source /MD /assume:bscc
See that /fixed option? GET RID OF IT!!! It should never have been there in the first place and I have been unsuccessful in getting TMW to remove it. E.g., I typically do this just so that it is documented what was there originally in a rem statement:
rem set COMPFLAGS=/fpp /Qprec /I"%MATLAB%/extern/include" /c /nologo /fixed /fp:source /MD /assume:bscc
set COMPFLAGS=/fpp /Qprec /I"%MATLAB%/extern/include" /c /nologo /fp:source /MD /assume:bscc
  8 件のコメント
James Tursa
James Tursa 2017 年 4 月 6 日
That would indicate, as I suspected, that the source code is still being compiled as a fixed format file for some reason. You might use the -v option to see where that might be coming from.
Abhishek Subramanian
Abhishek Subramanian 2017 年 4 月 6 日
Ahh yes, I forgot to look at that. I just did. There was a /fixed in a file named 'C:\Users\User\AppData\Roaming\MathWorks\MATLAB\R2017a\mex_FORTRAN_win64'. I removed that and it now works on fortran90 files with & as shown in the original question. Thanks!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeWrite C Functions Callable from MATLAB (MEX Files) についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by