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 views (last 30 days)
  
       Show older comments
    
    Abhishek Subramanian
 on 5 Apr 2017
  
    
    
    
    
    Commented: James Tursa
      
      
 on 22 Apr 2021
            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 Comments
  Shubham Baisthakur
 on 22 Apr 2021
				I am facing the similar issue. Where can I find the mexopt files to change the COMPFLAG?
PS: I am using MATLAB R2020a
Accepted Answer
  James Tursa
      
      
 on 5 Apr 2017
        
      Edited: James Tursa
      
      
 on 5 Apr 2017
  
      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 Comments
  James Tursa
      
      
 on 6 Apr 2017
				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.
More Answers (0)
See Also
Categories
				Find more on Write C Functions Callable from MATLAB (MEX Files) 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!


