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 the
CONVERT specifier on the
OPEN statement. See GFORTRAN_CONVERT_UNIT, for an alternative way of specifying the data format via an environment variable.
Valid values for
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.
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
REAL 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 supports as
REAL(KIND=16), will 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.
© Free Software Foundation
Licensed under the GNU Free Documentation License, Version 1.3.