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

free format write giving different data format than gfortran and lahey fortran compiler

Sanat_Tiwari
Beginner
1,307 Views
I write here a simple fortran code, in which i want to write 4 variables in double precision in free format using write(*,*), but the printed format is different in ifort with gfortran and lahey fortran compiler. This is just a example program. My actual code is very big and i don't want to change it depending on compiler issue. Is there any work around for it?
program main
        Implicit none
        Real*8 a,b,c,d
        a = 2.0d0;b = a+0.20d0;
        c = b-1.2d0; d = 3.0d0;
        write(*,*) a,b,c,d       
 end program main
If I add a format, the results will be same from all compilers. But what to do with free format?
0 Kudos
1 Solution
Arjen_Markus
Honored Contributor II
1,307 Views
List-directed output is not meant to be conform among compilers: it is meant to allow you as a programmer
to get a quick result, but there is no guarantee as to the details of the output.

If you need to have uniform output with different compilers, then use an explicit format. (Even then there
may be variations, such as a leading zero or a plus sign, but you can fine-tune these)

Regards,

Arjen

View solution in original post

0 Kudos
5 Replies
Arjen_Markus
Honored Contributor II
1,308 Views
List-directed output is not meant to be conform among compilers: it is meant to allow you as a programmer
to get a quick result, but there is no guarantee as to the details of the output.

If you need to have uniform output with different compilers, then use an explicit format. (Even then there
may be variations, such as a leading zero or a plus sign, but you can fine-tune these)

Regards,

Arjen
0 Kudos
Sanat_Tiwari
Beginner
1,307 Views
thanks for prompt reply.
I agree with what you said. I do use explicit format for long time. But this time just to get quick result, i tried with free format in a file.
write(12,*) 
which will write data in fort.12 file. But then it gave 3 variable in a row and 4th in 2nd row. The result was 
   2.00000000000000        2.20000000000000        1.00000000000000     
   3.00000000000000  
while I was expecting 
   2.00000000000000        2.20000000000000        1.00000000000000        3.00000000000000
which I get from gfortran and lahey.
What is causing this difference.
0 Kudos
Arjen_Markus
Honored Contributor II
1,307 Views
The length of a (logical) line in a file - you can control that, but hardly anyone does (for
text files). The various compilers use different values and that is most easily seen with
list-directed output.

Regards,

Arjen
0 Kudos
mecej4
Honored Contributor III
1,307 Views
> I was expecting ...

You have no basis for that expectation. The language standard states that the format used for list-directed output (which you call "free format") is "processor dependent".

Given that, perhaps the only basis for expecting one compiler to mimic another could be that the format produced by the latter is so obviously superior that marketing considerations should dictate mimicry. In this case, "obviously superior" is not obvious.

0 Kudos
Sanat_Tiwari
Beginner
1,307 Views
Thanks for your answer. I understand it now.
0 Kudos
Reply