problem parsing WRITE format string with (fixed format) continuation
I get an error message when trying to compile the following code snippet:
program p
X = 0.0D00
Y = 1.0D00
WRITE(*,'(1x," ***Outer Convergence of Thermal Flux (MG/P'//'W) Wa
+s", t55,2es12.5)') X,Y
end program
The error message I am getting is:
formatString.f(5): error #5120: Unterminated character constant
+s", t55,2es12.5)') X,Y
-------^
formatString.f(5): error #5144: Invalid character_kind_parameter. No underscore
+s", t55,2es12.5)') X,Y
----------------------------------------------^
formatString.f(4): error #5082: Syntax error, found ''' when expecting one of: ( <IDENTIFIER>
<CHAR_CON_KIND_PARAM> <CHAR_NAM_KIND_PARAM> <CHARACTER_CONSTANT> <INTEGER_CONSTANT> ...
WRITE(*,'(1x," ***Outer Convergence of Thermal Flux (MG/P'//'W) Wa
------------------------------------------------------------------^
formatString.f(5): error #5082: Syntax error, found CHARACTER_CONSTANT ', t55,2es12.5)') X,Y' when
expecting one of: ( * ) :: , <END-OF-STATEMENT> ; + . - % (/ [ : ] /) . ** / // ...
+s", t55,2es12.5)') X,Y
-------^
compilation aborted for formatString.f (code 1)
As far as I know there should not be an error. The code snippet comes from some automatic reformatting that
happens as a result of source transformation.
| |
Re: problem parsing WRITE format string with (fixed format) continuation
Evidently, you lost the formatting when you posted, so I turned it back to fixed form source. You have incorrectly
nested character strings. If I double the interior ' marks: WRITE(*,'(1x," ***Outer Convergence of Thermal Flux
(MG/P''//''W) +Was", t55,2es12.5)') X,Y this appears to fix it.
| |
Re: problem parsing WRITE format string with (fixed format) continuation
Evidently, you lost the formatting when you posted, so I turned it back to
fixed form source. You have incorrectly nested character strings. If I double the interior ' marks:
WRITE(*,'(1x," ***Outer Convergence of Thermal Flux (MG/P''//''W) +Was",
t55,2es12.5)') X,Y this appears to fix it.
I don't think that is really the issue because there are 2 strings: 1:
'(1x," ***Outer Convergence of Thermal Flux (MG/P' 2:
'W) Was", t55,2es12.5)' (in the second I removed the newline+
continuation) Both strings delimited by apostrophe characters and concatenaded by the // operator. The
fact that each of them also happens to contain a double quote character looks confusing but - as far as I understand the
standard - is ok. So, in other words, changing the single quotes to double quotes around the // like tim18 did would
in effect remove the // operator and instead make it part of the string. Instead of the correct output which is: ***Outer Convergence of Thermal Flux (MG/PW) Was 0.00000E+00 1.00000E+00 the suggested change
produces:
***Outer Convergence of Thermal Flux (MG/P
W) Was 0.00000E+00 1.00000E+00
which clearly is wrong.
| |
Re: problem parsing WRITE format string with (fixed format) continuation
Evidently, you lost the formatting when you posted, so I turned it back to
fixed form source. You have incorrectly nested character strings. If I double the interior ' marks:
WRITE(*,'(1x," ***Outer Convergence of Thermal Flux (MG/P''//''W) +Was",
t55,2es12.5)') X,Y this appears to fix it.
I attached the original file so it keeps the formatting intact. I did follow the procedure posted by Steve on how to
insert code snippets but it looks like that injection logic is way too smart and removes the leading spaces or I have to
add some comment in the beginning :-).
| |
Re: problem parsing WRITE format string with (fixed format) continuation
This is fixed-form source but you have named it with a .f90 file type. Change the file type to .f or .for. However,
even with that the compiler seems to have a problem with this code. It is legal, as far as I can tell. I suggest
rewriting it as follows:
WRITE(*,'(1x," ***Outer Convergence of Thermal Flux (MG/P'// +'W)Was",
t55,2es12.5)') X,Y
I will report this to the developers. The support ID is DPD200140398.
Steve
Attaching or including files in a post
Doctor Fortran blog
@DoctorFortran on Twitter | |
Re: problem parsing WRITE format string with (fixed format) continuation
This is fixed-form source but you have named it with a .f90 file type.
Change the file type to .f or .for. However, even with that the compiler seems to have a problem with this code. It
is legal, as far as I can tell. I suggest rewriting it as follows:
WRITE(*,'(1x," ***Outer Convergence of Thermal Flux (MG/P'// +'W)Was",
t55,2es12.5)') X,Y
I will report this to the developers. The support ID is DPD200140398.
Thanks for forwarding it to the developers. When I experimented with the problem I did compile it with "ifort -fixed
formatString.f90" to reflect the fixed format inside.
It seems like a contrived problem when one looks at the
example but I mentioned in my post that the code is the output of a source transformation process in which things
like this format string concatenation are parsed as string1-operator-string2 etc. and then eventually the AST is
unparsed and reformatted to free or fixed format for a specified line length which leads to this strange looking but
apparently syntactically correct code. IOW, manually fixing the transformation output is not a feasible option.
| | |