Fortran code in Matlab

22 次查看(过去 30 天)
afaq ahmad
afaq ahmad 2021-12-2
编辑: dpb 2021-12-5
I have a Fortran code which I need to simulate in Simulink. Before creating a C mex file, I am only compiling the Fortran code in Matlab using Intel Parallel Studio XE 2015. However, I get the following error when I compile it.
SUBG.f(1078): error #5078: Unrecognized token '&' skipped
* & /' large nromalization factor in fixvol.'
-----------^
And here is the snippet of the code where the error lies.
if (abs(1.0-xnormc).gt.0.05 .or. abs(1.0-xnormr).gt.0.05) then
write (lutty,1800) xnormc,xnormr
1800 format (/' *****Warning'\
& /' large nromalization factor in fixvol.'!In this line the problem lies
& /' for coal =',f8.2,' for rock =',f8.2)
endif
Moreover, I searched the internet for the said problem and found out that it mostly occurs when an
unknown character sneaks up in the code while copying-pasting it into Matlab.
Anywork around about this problem!
Thankyou.
  11 个评论
James Tursa
James Tursa 2021-12-3
编辑:James Tursa 2021-12-3
"Does this mean my Matlab handles both fixed and free format?"
Unfortunately, no it doesn't. MATLAB keeps putting the silly /fixed option in their mex build files, which forces the compiler to treat .f90 files as fixed format. I've been complaining to TMW for years about this but it never gets fixed. My advice to you is to edit the mex build files, find the COMPFLAGS (or similar) line, and delete the /fixed option from it. Then your compiler will understand .f90 free format files.
dpb
dpb 2021-12-3
if (abs(1.0-xnormc).gt.0.05 .or. abs(1.0-xnormr).gt.0.05) then
write (lutty,1800) xnormc,xnormr
1800 format (/' *****Warning'\
& /' large nromalization factor in fixvol.'!In this line the problem lies
& /' for coal =',f8.2,' for rock =',f8.2)
endif
I wonder what it is expected for the above line of output to look like in the first place now that look at it in more depth.
It would seem funny to have
*****Warning large nromalization factor in fixvol.
for coal =',f8.2,' for rock =',f8.2)
if the succeeding \ and / do actually cancel each other.
*****Warning
large nromalization factor in fixvol.
for coal =',f8.2,' for rock =',f8.2)
might seem more like what might have been intended in which case just dumping the "\" would produce output.
*****Warning large nromalization factor in fixvol.
for coal =',f8.2,' for rock =',f8.2)
might be another choice in which case the FORMAT statement should look like--
1800 format (/' *****Warning large nromalization factor in fixvol.'
& /' for coal =',f8.2,' for rock =',f8.2)
or some variant thereof.
One notes as a nit the word "normalization" has a typo in the "r" and "o" are swapped.

请先登录,再进行评论。

采纳的回答

dpb
dpb 2021-12-3
编辑:dpb 2021-12-3
Try adding additional switch to handle the backlash edit descriptor James' keen eyes spotted (I used the DEC DVF/CVF compiler for so long that I got inured to it being an extension; there it was enabled by default).
Searching the Intel doc shows it is not enabled by default there.
Set
Compatibility > Use PowerStation I/O Format (
/fpscomp:ioformat
as additional switch to pass to the compiler from mex.
The link to the Intel doc -- if you have the compiler installed, you should have the help files local as well, but this is the option needed to get that specific extension recognized. <Documentation/fortran-compiler-compatibility-options/fpscomp>
Does seem like the compiler could have generated a more useful error message flagging the extension semantics in the FORMAT statement.
  10 个评论
afaq ahmad
afaq ahmad 2021-12-5
I took the hint from what you did and made another subroutine of the exact same lines but with backslash removed.And guess what? Matlab compiled it successfully with the generic ''-c mex filename.f'' command with no additional flags. So it is highly likely that the bug is in some other line, but Matlab won't tell me exactly. I gotta hunt for that line.
dpb
dpb 2021-12-5
编辑:dpb 2021-12-5
"Matlab compiled it successfully with the generic ''-c mex filename.f'' command"
That should be
mex -c filename.f
leading a command with a "-c" would be a syntax error.
"..., but Matlab won't tell me exactly."
This has essentially nothing to do with MATLAB -- it is the Fortran compiler being dispatched by the mex command that is all that matters here. All MATLAB is doing is hiding what is really going on by use of the mex function to build the make file it passes to the specific command toolset.
Again I tell you -- compile the file directly with the Intel compiler and you'll have full control to determine what it sees/doesn't see for input switches and all error messages.
And also again, attach the full file as it existed originally and somebody can compile it independently as well with multiple compilers which, as observed above, have different diagnostics and can be extremely helpful with odd syntax issues.
It is possible that if a closing quote on a string constant or closing parenthesis is missing or past column 72 and is thus skipped the compiler can get confused and then not flag an error until somewhere in the source code past that location. When that happens, however, it almost always will start a cascade of errors, not just a single error and the given line definitely has a syntax error in it unless the Intel compiler can handle the backslash edit descriptor extension as described earlier.
Unfortunately, so far after several hours of download and install time, I'm yet unable to manage to get a working version of the Intel compiler installed so i can't try to compile it here with that compiler.

请先登录,再进行评论。

更多回答(1 个)

James Tursa
James Tursa 2021-12-3
编辑:James Tursa 2021-12-3
I'm trying to figure out the purpose of the backslash \. If this was the last character in the format statement then I would assume this is for the purpose of suppressing the newline. But you have it in the middle of the format statement, which means the compiler might interpret this as the start of an escape sequence, but there is no valid escape sequence character following this backslash. Maybe the compiler is trying to put the \& together as an escape sequence and then reports that the & is skipped because it isn't one of the valid escape sequence characters? Why is that backslash there? Why not a forward slash?
  3 个评论
Walter Roberson
Walter Roberson 2021-12-3
Looks to me as if maybe it has to do with continuation, but it does not appear to be a standard representation.
dpb
dpb 2021-12-3
编辑:dpb 2021-12-4
"//" is the Fortran string catenation syntax; inside a FORMAT statement the "\" outside a quoted string can only be the DEC backslash edit descriptor extension.
But, while the Intel compiler supports it (and many others as well), it is NOT active by default so the Intel compiler barfs on it.
That's also why the MS Powerstation compiler didn't -- those extensions are all enabled by default in it.
We're going to know realsoonnow™ as OP is actively pursuing this track.
I'm pretty-much convinced this will prove to be it...now whether it should really be there where it is at all or not to produce the desired output string is another kettle o' carp! :)

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Write C Functions Callable from MATLAB (MEX Files) 的更多信息

标签

产品


版本

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by