From: Axel Kohlmeyer (
Date: Wed Jun 17 2009 - 12:01:30 CDT

On Wed, 2009-06-17 at 08:59 -0700, Rob wrote:

dear rob,

> The ABINIT binary data files appear with an undocumented tag at

this is the "record length marker". depending on the
individual compiler, this will contain either the number
of bytes or number of words in the current write statement.
this is necessary for fortran unformatted I/O since fortran
read/write semantics assume writing of 'records' and allow
to do "short reads". i.e. you can do a

write (channel) a,b,c,(d(i),i=1,a)
write (channel) e,f

and a later:

read (channel) a,b
read (channel) e,f

should read back a, b, e, and f and skip over d().

> the start of the file; this tag depends on the endianness and the
> record length.
> With a record length 4 (or 8), it has a 4 (or 8) bytes tag, as follows:
> Little-endian / 4 : 0e 00 00 00
> Little-endian / 8 : 0e 00 00 00 00 00 00 00

exactly. but here you have to be careful in the 8-byte case.
if the first data element being written is an integer that can
be 0, then you cannot tell those two cases apart. so you also
have to know what is the first write statement like. all smart
packages tend to put some version or type info string there
and since i know the folks working on abinit to be smart, too,
i'd expect them to do something similar.

> Big-endian / 4 : 00 00 00 0e
> Big-endian / 8 : 00 00 00 00 00 00 00 0e
> I can use these tags to set the endianness and record length of
> the binary data file, and then read the binary data accordingly.


> However, so far I have only generated binary data files on my
> Linux system. I have no idea how generic these tags are.
> How machine dependent would my code be if I rely on these
> tags.....??What would you guess?

i don't have to guess. i've been writing c code to read and write
fortran unformatted data for over a decade ;). all but the most
exotic (and usually long obsolete) fortran compilers (it is really
a compiler issue) adhere to this scheme, including the fact that
they write the number of bytes and not words.

> I myself don't yet have other architectures to test it on.

i have personal experience on the platforms listed on this page:

> Rob.

Axel Kohlmeyer
   Center for Molecular Modeling   --   University of Pennsylvania
Department of Chemistry, 231 S.34th Street, Philadelphia, PA 19104-6323
tel: 1-215-898-1582,  fax: 1-215-573-6233,  office-tel: 1-215-898-5425
If you make something idiot-proof, the universe creates a better idiot.