GFORTRAN_CONVERT_UNIT—Set conversion for unformatted I/O#

By setting the GFORTRAN_CONVERT_UNIT variable, it is possible to change the representation of data for unformatted files. The syntax for the GFORTRAN_CONVERT_UNIT variable for most systems is:

GFORTRAN_CONVERT_UNIT: mode | mode ';' exception | exception ;
mode: 'native' | 'swap' | 'big_endian' | 'little_endian' ;
exception: mode ':' unit_list | unit_list ;
unit_list: unit_spec | unit_list unit_spec ;
unit_spec: INTEGER | INTEGER '-' INTEGER ;

The variable consists of an optional default mode, followed by a list of optional exceptions, which are separated by semicolons from the preceding default and each other. Each exception consists of a format and a comma-separated list of units. Valid values for the modes are the same as for the CONVERT specifier:

  • NATIVE Use the native format. This is the default.

  • SWAP Swap between little- and big-endian.

  • LITTLE_ENDIAN Use the little-endian format for unformatted files.

  • BIG_ENDIAN Use the big-endian format for unformatted files.

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

  • R16_IEEE Use IEEE 128-bit format for REAL(KIND=16).

  • R16_IBM Use IBM long double format for REAL(KIND=16).

A missing mode for an exception is taken to mean BIG_ENDIAN. Examples of values for GFORTRAN_CONVERT_UNIT are:

  • 'big_endian' Do all unformatted I/O in big_endian mode.

  • 'little_endian;native:10-20,25' Do all unformatted I/O in little_endian mode, except for units 10 to 20 and 25, which are in native format.

  • '10-20' Units 10 to 20 are big-endian, the rest is native.

  • 'big_endian,r16_ibm' Do all unformatted I/O in big-endian mode and use IBM long double for output of REAL(KIND=16) values.

Setting the environment variables should be done on the command line or via the export command for sh-compatible shells and via setenv for csh-compatible shells.

Example for sh:

$ gfortran foo.f90
$ GFORTRAN_CONVERT_UNIT='big_endian;native:10-20' ./a.out

Example code for csh:

% gfortran foo.f90
% setenv GFORTRAN_CONVERT_UNIT 'big_endian;native:10-20'
% ./a.out

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.

See CONVERT specifier, for an alternative way to specify the data representation for unformatted files. See Influencing runtime behavior, for setting a default data representation for the whole program. The CONVERT specifier overrides the -fconvert compile options.

Note

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.