CONVERT specifier (The GNU Fortran Compiler) (original) (raw)


5.1.17 CONVERT specifier

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—Set conversion for unformatted I/O, for an alternative way of specifying the data format via an environment variable.

Valid values for CONVERT on most systems are:

On POWER systems that support -mabi=ieeelongdouble, there are additional options, which can be combined with the others with commas. Those are

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 usingINQUIRE(CONVERT=ch). The values returned are'BIG_ENDIAN' and 'LITTLE_ENDIAN'.

CONVERT works between big- and little-endian forINTEGER values of all supported kinds and for REALon 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=10) and REAL(KIND=16), probably does not work.

Note that the values specified via the GFORTRAN_CONVERT_UNITenvironment variable overrides the CONVERT specifier in theOPEN 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.