binary file problem

Roberto Muscari r.muscari@insean.it
Fri Sep 7 14:05:00 GMT 2007


hi all,

I have a problem with binary files read/written by gfortran

AFAIK, binary files in fortran are written in the form:

lenght_of_the_record_1   record_1   lenght_of_the_record_1
lenght_of_the_record_2   record_2   lenght_of_the_record_2
lenght_of_the_record_3   record_3   lenght_of_the_record_3
........


The problem is that g77, g95, pgf90 (PGI compiler), ... write/read the
lenght_of_the_record as an integer*4
whereas in gfortran it is an integer*8 (at least on my 64bit PC)

For example, the program

integer (kind=4) :: i
write(100) i

generates a 8+4+8=20 bytes file if it is compiled with gfortran whereas
it generates a 4+4+4=12 bytes file if it is compiled with other compilers.

For this reason, I can not read the files written with other fortran
compilers with gfortran, and viceversa.

Does anybody know if there is a way to change this behavior of gfortran?

(
roberto ~> gfortran --version
GNU Fortran 95 (GCC) 4.1.1 20070105 (Red Hat 4.1.1-52)
Copyright (C) 2006 Free Software Foundation, Inc.
)

Thanks in advance
Roberto



More information about the Fortran mailing list