CONVERT specifier (The GNU Fortran Compiler)

#### 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:

- `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 that 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 `REAL(KIND=16)`.
- `CONVERT='R16_IBM'` Use IBM `long double` format for `REAL(KIND=16)`.

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 `'BIG_ENDIAN'` and `'LITTLE_ENDIAN'`.

`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=10)` and `REAL(KIND=16)`, probably does not work.

Note that the values specified via the `GFORTRAN_CONVERT_UNIT` environment variable overrides 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.