/GNU Fortran 7

3.11 GFORTRAN_CONVERT_UNIT—Set endianness 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 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.

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.

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 Runtime Options, for setting a default data representation for the whole program. The CONVERT specifier overrides the -fconvert compile options.

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.

Next: , Previous: , Up: Runtime [Contents][Index]

© Free Software Foundation
Licensed under the GNU Free Documentation License, Version 1.3.