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

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

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 mainIf I add a format, the results will be same from all compilers. But what to do with free format?

sanat
6 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.
Best Reply

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

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.00000000000000which I get from gfortran and lahey.What is causing this difference.

sanat

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

> 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.

Thanks for your answer. I understand it now.

sanat

Leave a Comment

Please sign in to add a comment. Not a member? Join today