Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
Comunicados
FPGA community forums and blogs on community.intel.com are migrating to the new Altera Community and are read-only. For urgent support needs during this transition, please visit the FPGA Design Resources page or contact an Altera Authorized Distributor.
29282 Discussões

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

Sanat_Tiwari
Principiante
1.376 Visualizações
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 Solução
Arjen_Markus
Colaborador honorário II
1.376 Visualizações
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

Ver solução na publicação original

5 Respostas
Arjen_Markus
Colaborador honorário II
1.377 Visualizações
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
Sanat_Tiwari
Principiante
1.376 Visualizações
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.
Arjen_Markus
Colaborador honorário II
1.376 Visualizações
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
mecej4
Colaborador honorário III
1.376 Visualizações
> 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.

Sanat_Tiwari
Principiante
1.376 Visualizações
Thanks for your answer. I understand it now.
Responder