Reading 32bit unformatted files in 64bit systems
Janne Blomqvist
blomqvist.janne@gmail.com
Fri Dec 30 12:09:00 GMT 2011
2011/12/30 Ignacio Fernández Galván <jellby@yahoo.com>:
> Hi all,
>
> I'm trying to read unformatted fortran files in an x86_64 system. The files are DCD trajectories, roughly described here: http://www.lrz.de/~heller/ego/manual/node93.html
>
> I don't seem to get meaningful results, and I believe the problem is that the DCD files are generated in 32bit systems. I try something simple:
>
> PROGRAM ReadDCD
> IMPLICIT NONE
> CHARACTER(LEN=4) :: HDR
> INTEGER :: NSET,ISTRT,NSAVC,NFIXED,ZEROS5(5),ZEROS9(9)
> DOUBLE PRECISION :: DELTA
>
> OPEN(10,FILE='traj.dcd',FORM='UNFORMATTED',STATUS='OLD',ACTION='READ')
> READ(10) HDR,NSET,ISTRT,NSAVC,ZEROS5(:),NFIXED,DELTA,ZEROS9(:)
> CLOSE(10)
> WRITE(6,*) HDR,NSET,ISTRT,NSAVC,ZEROS5(:),NFIXED,DELTA,ZEROS9(:)
> END PROGRAM ReadDCD
>
> Compile and run it and get:
>
> CORD 1677721600 -402456576 -402456576 0 ...
>
> which doesn't make sense, since the corresponding hex data in the "traj.dcd" file are:
>
> 43 4F 52 44 00 00 00 64 00 00 03 E8 00 00 03 E8 00 00 00 00
>
> ("CORD" plus four 4-byte numbers: 100, 1000, 1000, 0)
>
> I tried with the -m32 flag, but it doesn't change anything. Is it possible at all to read these files? What am I doing wrong?
>
> My system is Ubuntu Oneiric, with default gfortran (gcc 4.6.1).
The 32-bit vs. 64-bit issue does not seem relevant here. The binary
file formats supported by gfortran do not depend on the "bitness". Of
course, if one writes bitness-dependent data into the file (e.g.
pointer values or INTEGER(kind=C_SIZE_T) integers), then the resulting
files will be different on 32 and 64-bit targets. But of the file
format related stuff controlled by the compiler (file storage unit,
possible header sizes, etc.), none is dependent on the "bitness".
The real problem, AFAICS, is that merely saying that the format is
"FORTRAN UNFORMATTED" is not enough, the format also depends on the
ACCESS= specifier. GFortran supports the 3 unformatted access methods
that the Fortran standard mandates, namely ACCESS="sequential" (the
default), ACCESS="direct", and ACCESS="stream". From briefly looking
at the DCD description in the link you provided and the hex dump, the
only access method that seems to fit is "stream" [1], which is a bit
strange since IIRC x-plor is a F77 program while access="stream" was
added only in the Fortran 2003 standard.
[1] "sequential" does not seem to fit, because the hex dump does not
contain the record length fields which should be present before and
after each record. OTOH, "direct" does not fit either since the 4'th
record with the coordinates is variable sized, and "direct" uses fixed
size records.
Anyway, hope this helps, and good luck.
--
Janne Blomqvist
More information about the Fortran
mailing list