Previous: Cray pointers, Up: Extensions

7.13 CONVERT specifier

gfortran 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 are:

Using the option could look like this:

       open(file='big.dat',form='unformatted',access='sequential', &

The value of the conversion can be queried by using INQUIRE(CONVERT=ch). The values returned are 'BIG_ENDIAN' and 'LITTLE_ENDIAN'.

CONVERT works between big- and little-endian for INTEGER values of all supported kinds and for REAL on IEEE sytems of kinds 4 and 8. Conversion between different “extended double” types on different architectures such as m68k and x86_64, which gfortran supports as REAL(KIND=10) 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 a user who does not have the source code of his 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.