GNU Fortran allows the conversion of unformatted data between little-
and big-endian representation to facilitate moving of data
between different systems. The conversion can be indicated with
CONVERT specifier on the
See GFORTRAN_CONVERT_UNIT, for an alternative way of specifying
the data format via an environment variable.
Valid values for
CONVERT on most systems are:
CONVERT='NATIVE'Use the native format. This is the default.
CONVERT='SWAP'Swap between little- and big-endian.
CONVERT='LITTLE_ENDIAN'Use the little-endian representation for unformatted files.
CONVERT='BIG_ENDIAN'Use the big-endian representation for unformatted files.
On POWER systems which support -mabi=ieeelongdouble, there are additional options, which can be combined with the others with commas. Those are
CONVERT='R16_IEEE'Use IEEE 128-bit format for
long doubleformat for real
Using the option could look like this:
open(file='big.dat',form='unformatted',access='sequential', & convert='big_endian')
The value of the conversion can be queried by using
INQUIRE(CONVERT=ch). The values returned are
CONVERT works between big- and little-endian for
INTEGER values of all supported kinds and for
on IEEE systems of kinds 4 and 8. Conversion between different
“extended double” types on different architectures such as
m68k and x86_64, which GNU Fortran
probably not work.
Note that the values specified via the GFORTRAN_CONVERT_UNIT environment variable will override the CONVERT specifier in the open statement. This is to give control over data formats to users who do not have the source code of their program available.
Using anything but the native representation for unformatted data carries a significant speed overhead. If speed in this area matters to you, it is best if you use this only for data that needs to be portable.