Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
28712 Discussions

problem parsing WRITE format string with (fixed format) continuation

Jean_U
Beginner
1,979 Views
I get an error message when trying to compile the following code snippet:
[plain]      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
[/plain]
The error message I am getting is:
[plain]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: (      ...
      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: ( * ) :: ,  ; + . - % (/ [ : ] /) . ** / // ...
     +s",                   t55,2es12.5)') X,Y
-------^
compilation aborted for formatString.f (code 1)
[/plain]

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.
0 Kudos
8 Replies
TimP
Honored Contributor III
1,979 Views
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.
0 Kudos
Jean_U
Beginner
1,979 Views
Quoting - tim18
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,"***OuterConvergenceofThermalFlux(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:
[cpp]  ***Outer Convergence of Thermal Flux (MG/P

W) Was                                                 0.00000E+00 1.00000E+00
[/cpp]
which clearly is wrong.
0 Kudos
Jean_U
Beginner
1,979 Views
Quoting - tim18
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 :-).
0 Kudos
Steven_L_Intel1
Employee
1,979 Views
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.
0 Kudos
Jean_U
Beginner
1,979 Views
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.
0 Kudos
Steven_L_Intel1
Employee
1,979 Views
I understand that modifying the code is difficult for you - I was just explaining how to fix it if you could. We'll fix this as soon as we can.
0 Kudos
Steven_L_Intel1
Employee
1,979 Views
This has been fixed in our sources - the fix should appear in Update 6 (April).
0 Kudos
Steven_L_Intel1
Employee
1,979 Views
This issue is fixed in Update 6, available now.
0 Kudos
Reply