Fortran code in Matlab

30 views (last 30 days)
afaq ahmad
afaq ahmad on 2 Dec 2021
Edited: dpb on 5 Dec 2021
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 Comments
dpb
dpb on 3 Dec 2021
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.

Sign in to comment.

Accepted Answer

dpb
dpb on 3 Dec 2021
Edited: dpb on 3 Dec 2021
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 Comments
dpb
dpb on 5 Dec 2021
"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.

Sign in to comment.

More Answers (1)

James Tursa
James Tursa on 3 Dec 2021
Edited: James Tursa on 3 Dec 2021
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 Comments
dpb
dpb on 3 Dec 2021
"//" 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! :)

Sign in to comment.

Products


Release

R2018a

Community Treasure Hunt

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

Start Hunting!