- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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?
1 Solution
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
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
Link Copied
5 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
text files). The various compilers use different values and that is most easily seen with
list-directed output.
Regards,
Arjen
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
> 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.
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks for your answer. I understand it now.

Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page