Little-endian-to-Big-endian Conversion

The Intel Fortran Compiler can write unformatted sequential files in big-endian format and also can read files produced in big-endian format by using the little-endian-to-big-endian conversion feature.

Both on IA-32-based processors and on Itanium®-based processors, Intel Fortran handles internal data in little-endian format. The little-endian-to-big-endian conversion feature is intended for Fortran unformatted input/output operations in unformatted sequential files. The feature enables:

The little-endian-to-big-endian conversion is accomplished by the following operations:

The feature enables the conversion of variables and arrays (or array subscripts) of basic data types. Derived data types are not supported.

Little-to-Big Endian Conversion Environment Variable

In order to use the little-endian-to-big-endian conversion feature, specify the numbers of the units to be used for conversion purposes by setting the F_UFMTENDIAN environment variable. Then, the READ/WRITE statements that use these unit numbers, will perform relevant conversions. Other READ/WRITE statements will work in the usual way.

In the general case, the variable consists of two parts divided by a semicolon. No spaces are allowed inside the F_UFMTENDIAN value. The variable has the following syntax:

F_UFMTENDIAN=MODE | [MODE;] EXCEPTION

where:

MODE = big | little
EXCEPTION = big:ULIST | little:ULIST | ULIST
ULIST = U | ULIST,U
U = decimal | decimal -decimal

Converted data should have basic data types, or arrays of basic data types. Derived data types are disabled.

Command lines for variable setting with different shells:

Sh: export F_UFMTENDIAN=MODE;EXCEPTION

Csh: setenv F_UFMTENDIAN MODE;EXCEPTION

Note
Environment variable values should be enclosed in quotes if a semicolon is present.

Another Possible Environment Variable Setting

The environment variable can also have the following syntax:

F_UFMTENDIAN=u[,u] . . .

Command lines for the variable setting with different shells:

See error messages that may be issued during the little endian – big endian conversion. They are all fatal. You should contact Intel if such errors occur.

Usage Examples

  1. F_UFMTENDIAN=big

    All input/output operations perform conversion from big-endian to little-endian on READ and from little-endian to big-endian on WRITE.

  2. F_UFMTENDIAN="little;big:10,20"
    or F_UFMTENDIAN=big:10,20
    or F_UFMTENDIAN=10,20

    In this case, only on unit numbers 10 and 20 the input/output operations perform big-little endian conversion.

  3. F_UFMTENDIAN="big;little:8"

    In this case, on unit number 8 no conversion operation occurs. On all other units, the input/output operations perform big-little endian conversion.

  4. F_UFMTENDIAN=10-20

    Define 10, 11, 12, ..., 19, 20 units for conversion purposes; on these units, the input/output operations perform big-little endian conversion.

  5. Assume you set F_UFMTENDIAN=10,100 and run the following program.

    integer*4   cc4
    integer*8   cc8
    integer*4   c4
    integer*8   c8
    c4 = 456
    c8 = 789  

    C  prepare a little endian representation of data

    open(11,file='lit.tmp',form='unformatted')
    write(11) c8
    write(11) c4
    close(11)

    C  prepare a big endian representation of data

    open(10,file='big.tmp',form='unformatted')
    write(10) c8
    write(10) c4
    close(10)

    C  read big endian data and operate with them on
    C  little endian machine.

    open(100,file='big.tmp',form='unformatted')
    read(100) cc8
    read(100) cc4

    C  Any operation with data, which have been read

    C    . . .
    close(100)
    stop
    end

    Now compare lit.tmp and big.tmp files with the help of od utility.

    > od -t x4 lit.tmp

    0000000 00000008 00000315 00000000 00000008
    0000020 00000004 000001c8 00000004
    0000034

    > od -t x4 big.tmp

    0000000 08000000 00000000 15030000 08000000
    0000020 04000000 c8010000 04000000
    0000034

    You can see that the byte order is different in these files.