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

Format syntax error

Melven_R_
Beginner
1,266 Views

In my application I obtain a format syntax error, but I  do not recognize why.

I created a minimal example:

program test
  implicit none
  character(len=200) :: formatstr
  character(len=*), parameter :: formatstr2 = '("test",I2.2,"")'

  formatstr = formatstr2
  write(*,'(A)') formatstr
  write(*,'(A)') formatstr2
  write(*,*) formatstr == formatstr2
  write(*,formatstr2) 12
  ! the next line creates an error
  write(*,formatstr) 12

end program test

I obtain the following output:

> ifort -g -traceback test2.f90
> ./a.out
("test",I2.2,"")
("test",I2.2,"")
 T
test12
forrtl: info (58): format syntax error at or near ")
forrtl: severe (62): syntax error in format, unit -1, file /dev/pts/4
Image              PC                Routine            Line        Source
a.out              00000000004286C6  Unknown               Unknown  Unknown
a.out              0000000000409C05  Unknown               Unknown  Unknown
a.out              000000000040314E  MAIN__                     12  test2.f90
a.out              0000000000402E6E  Unknown               Unknown  Unknown
libc.so.6          00007FAC1836CBE5  Unknown               Unknown  Unknown
a.out              0000000000402D79  Unknown               Unknown  Unknown

I tested this with the Intel Fortran Compiler 15.0.1 on a 64bit Linux and with some older version.
The code seems to work fine with both the GNU Fortran compiler (gfortran) and the PGI Fortran compiler (pgf90).

It also works when I change the format string to ("test",I2.2) or ("test",I2.2,"test"),
but in my application the formatstring is generated and thus one may obtain an empty string there.

0 Kudos
1 Solution
Steven_L_Intel1
Employee
1,266 Views

While bpichon is correct, in general, that applies only to character literal constants. Since formatstr2 is enclosed in apostrophes, the " character is just another character. What I think is happening is that the run-time format evaluation is improperly trying to process doubled delimiters and it shouldn't be doing that when not in the middle of a quoted string. So, in the format, """" would output a single " character - "" as it shows here is just an empty string, as properly interpreted as a constant format by the compiler.

I believe this is a bug and I will report it to the developers. The issue ID is DPD200366322.

View solution in original post

0 Kudos
3 Replies
bpichon
Beginner
1,266 Views

That is correct : double "" in format means a single "

1) discard :  ,"" in your string (the easier)

2) double the "" namely  """" (that is en empty string

0 Kudos
Melven_R_
Beginner
1,266 Views

Thanks for the clarification.

The behavior is still strange: The first write statement works fine, the second doesn't.

1) I know, I will probably check if some string is empty and omit it during the construction of the format specifier in my application

2) I couldn't get an empty string this way: With '("test",I2.2,"""")' it then prints a single " at the end

0 Kudos
Steven_L_Intel1
Employee
1,267 Views

While bpichon is correct, in general, that applies only to character literal constants. Since formatstr2 is enclosed in apostrophes, the " character is just another character. What I think is happening is that the run-time format evaluation is improperly trying to process doubled delimiters and it shouldn't be doing that when not in the middle of a quoted string. So, in the format, """" would output a single " character - "" as it shows here is just an empty string, as properly interpreted as a constant format by the compiler.

I believe this is a bug and I will report it to the developers. The issue ID is DPD200366322.

0 Kudos
Reply