Fortran string formatting problem


I am writing out to a file using a formatted string.
I was an exponent scientific format with 3 digits in the exponent.

Here is a test.f code:

       program test
       implicit none
       integer :: iseq
       real(8) :: time
       character (1) :: snl='6'
       time = 3.456
       iseq = 2
       write(*,"(i"//snl//"."//snl//",'    ',ES25.16E3)") iseq,time
       write(*,"(i"//snl//"."//snl//",a,ES25.16E3)") iseq,'    ',time
       end program test

When I run this using gfortran, I get what I expect:

$ gfortran test.f ;./a.out
000003      3.4560000896453857E+000
000003      3.4560000896453857E+000

with 6 spaces between the int and the float (the 4 I ask for, plus the 2 from the 25-width (to cover the sign and an additional space) but when I run with nvfortran, I get:

$ nvfortran test.f -o a.out.nv;./a.out.nv
000003       3.4560000896453857E+00
000003       3.4560000896453857E+00

which has 7 spaces and there are only 2 digits for the exponential!

This is a HUGE problem as we need this format to be correct for some python post processing scripts.
Even worse, on the NCSA Delta machine, this same code sometimes outputs

000003   3.4560000896453857E+00

with only 3 spaces in between!

If this is a bug, is there any way I can make the code output the correct format in the mean time (work around)?


– Ron


If I use “E” instead of “ES”, I get:
000003 0.3456000089645386E+001
with 6 spaces and 3 digits in the E but now its not in ES format.

I think I can use this as a work around for now

Hi Ron,

We’ve gotten one other report on this. See: [nvfortran] Incorrect format specification of double variables

As I noted there, it’s been like this before even PGI was founded in the 1980s and what was later called pghpf was still a development project at Floating Point Systems. In all that time, you’re only the second person to report it.

Unfortunately engineering didn’t do anything with the first report and I’m not sure they’ll act now especially since our Fortran compiler is being completely redone as part of the Flang F18 project, but I’ll see what I can do.


1 Like