Chapter 4. Extensions and Differences

This chapter describes the differences various Fortran implementations. This chapter is divided into the following sections:

4.1. Fortran 95 Standard Differences and Incompatibilities With FORTRAN 77 Implementations

This section discusses the following topics:

  • Fortran 95 and the G edit descriptor output differences

  • Fortran 95 and list-directed output differences

  • Delimited and undelimited character strings in list-directed I/O

  • List-directed I/O and floating-point zero

4.1.1. Fortran 95 and the G Edit Descriptor Output Differences

The format of a floating-point zero written with a G edit descriptor is different in Fortran 95.

The floating-point zero was written with an Ew.d edit descriptor in FORTRAN 77, but it is written with an Fw.d edit descriptor in the compiler.

The G edit descriptor has been expanded to be a general edit descriptor that can read or write any data type including character, integer, and logical data. FORTRAN 77 allows only floating-point data types.

Fortran 95 is specific about the rounding of floating-point values with the G format. The change in rules may cause asterisks in the output field for some floating-point values. Other values will be written as an Ew.d-formatted value by the compiler.

Consider the following code fragment:

     AVD = 0.0D0
     WRITE(6, 1) AVD
1    FORMAT(G28.2)

It generates the following output when compiled:


4.1.2. Fortran 95 and List-directed Output Differences

Fortran 95 requires a separator between noncharacter data and character data in list-directed output. FORTRAN 77 disallows a separator in this instance.

Consider the following example output list:

'This is a one(',1,')'

This output list generates different output under the two standards:

  • Fortran 95 output:

    >This is a one( 1 )

  • FORTRAN 77 output:

    >This is a one(1)

4.1.3. Delimited and Undelimited Character Strings in List-directed I/O

FORTRAN 77 compilers support only delimited character string input to a list-directed item that will be stored to a list item of type character.

4.1.4. List-directed I/O and Floating-point Zero

Fortran 95 specifies a different form of output constant for a floating-point zero in list-directed output records. Consider the following program:

      PRINT *,0.0
      PRINT 1, 0.0
1     FORMAT(1X,G12.2)

The preceding code generates the following output for the compiler:

% f90 tt.f
% a.out

4.2. Compiler extensions to Fortran 95

This section discusses the following topics:

  • List-directed I/O and Hollerith constants

  • Differences in the B, O, and Z edit descriptors

  • I/O extensions to the standard

4.2.1. List-directed I/O and Hollerith Constants

Fortran 95 does not support Hollerith constants in list-directed input files, but the compiler provides this as an extension. Note that Hollerith data is an deleted feature. See Chapter 6, “Outmoded Features”, for information on deprecated features and preferred alternatives.

4.2.2. Differences in the B, O, and Z Edit Descriptors

The B, O, and Z edit descriptors are available in Fortran 95. They are limited to integer I/O list items.

Signed octal and hexadecimal values are not allowed in Fortran 95. The compiler allows signed input values, but they write only unsigned values.

If the size of the value is less than w in Ow or Zw on output, Fortran 95 requires blank padding on the left. If the edit descriptor Ow.m or Zw.m is used, the field must contain at least m digits. The .m form is one way to get leading zeros with Fortran 95. If the size of the value is greater than w in Ow or Zw on output, the compiler fills the field with asterisks. The compiler provides the Fortran 95 form of Ow and Zw output.

4.2.3. I/O Extensions to Fortran 95

The compiler supports the following extensions to Fortran 95:

  • Auxiliary I/O statements:



  • Formatted I/O:

    • Q edit descriptor returns the number of characters remaining in the record.

    • The dollar sign ($) and backslash (\) edit descriptors suppress the newline character at the end of a record.

    • The field width of a data edit descriptor other than the A format cannot be present. The data edit descriptors are B, D, E, F, G, I, L, O, and Z. The field width defaults to a size chosen by the I/O library. The Fortran 95 standard allows a zero for the field width for the I, B, O, and Z data edit descriptors.

  • Internal I/O:

    • ENCODE statement

    • DECODE statement


    • Skip unmatched namelist groups on input without error.

    • Accept either an ampersand (&) or dollar sign ($) as a prefix to the namelist group name on input. If the dollar sign is used, the slash (/) or $END can be used to terminate the namelist input group. If the ampersand is used, the slash or $END can be used to terminate the namelist input group.

  • Unformatted I/O:

    • Specify FORM='SYSTEM' to ensure that no record headers exist in the file. This is available on all systems but is only necessary where the f77 layer is the default for an unformatted file.

    • Specify FORM='BINARY' to ensure that no record headers exist in the file.

4.3. MIPSpro Fortran 90 and MIPSpro Fortran 77 Differences

The following sections describe various differences found when compiling Fortran programs with the MIPSpro FORTRAN 77 compiler and the MIPSpro Fortran 90 compiler.

4.3.1. Intrinsic Function and Subroutine Differences

The MIPSpro FORTRAN 77 compiler supports the TIME intrinsic function and the MIPSpro Fortran 90 compiler does not.

The Fortran 95 standard defines the DATE_AND_TIME(3i) function, and its use is recommended when using the MIPSpro Fortran 90 compiler.

4.3.2. DATA Statement Initialization Differences

The Fortran 95 standard explicitly disallows multiple explicit intitializations of the same variable or part of a variable. Doing so results in undefined behavior.

Some codes initialize the same local variable or part of a variable in a DATA statement. Some codes initialize data in COMMON blocks more than once, either in the same or in different program units.

The MIPSpro Fortran 90 compiler, like many other implementations, allows COMMON blocks to be initialized in program units other than BLOCKDATA subprograms. Multiple initializations are not detected by the system. As a result, different processors may exhibit different behavior in cases of multiple initializations. For example, one processor may use the last value seen as the value of the initialized variable, while another may use the first value seen. Porting a code from one of these processors to another may result in differing results due to this difference.

Permitting multiple initializations of the same or part of a variable is not an extension. It is a user error that cannot be detected, in all cases, by the compiler. Behavior of multiple intializations is different across different OS platforms. For the program to be a standard conforming program with predictable results, you must remove multiple initializations.

4.3.3. I/O Record Length Differences

Fortran 95 standard I/O always specifies record lengths in I/O statements in bytes. By default, FORTRAN 77 direct-access unformatted I/O specifies the record length in words. This can cause incompatibilities when moving codes from FORTRAN 77 to Fortran 95 and vice versa. The -bytereclen option to the f77(1) command causes the FORTRAN 77 compiler to interpret all record lengths in bytes.

4.3.4. Special File Formats Differences

The MIPSpro FORTRAN 77 compiler permits you to specify the following two special modes in the FORM= clause of the OPEN statement:

  • FORM="BINARY", which permits reading and writing binary data from character variables.

  • FORM="SYSTEM", which allows input ignoring record boundaries.

These special modes are permitted in early releases of the MIPSpro Fortran 90 compiler. However, neither form is supported by the Fortran 95 standard or by the MIPSpro Fortran 90 compiler, releases 7.2 and later. Either type of file access can also be achieved by using the read(2) and write(2) IRIX kernel functions.

4.3.5. Miscellaneous Differences

The following miscellaneous items in the MIPSpro Fortran 77 compiler are not in the MIPSpro Fortran 90 compiler:

  • Keyed access (ACCESS='KEYED'):

    • OPEN statement extensions:

      ACCESS= 'KEYED' specifier
      KEY= () specifier
      RECORDSIZE= specifier (same as RECL)
    • INQUIRE statement extension:

      KEYED= specifier
    • READ statement extensions:

      KEY= specifier
      KEYID= specifier
    • DELETE statement

    • REWRITE statement

    • UNLOCK statement

  • Direct access (ACCESS ='DIRECT'):

    • OPEN statement extension:

      • ASSOCIATEVARIABLE= specifier to retain the REC= information.

      • MAXREC= specifier contains the maximum number of records allowed for a direct access file. If not present, no limit exists.

      • RECORDSIZE= specifier (same as RECL).

    • DEFINE FILE statement for a direct access unformatted file.

    • FIND statement for a direct access file.

    • Record length of one byte indicates a binary data stream without record boundaries.

    • Efficient reading of direct unformatted record in reverse order.

  • Sequential access (ACCESS='SEQUENTIAL'). Extension for ENDFILE to allow multifile file by using a tab character rather than an EOF.

  • stdin, stdout, and stderr I/O:

    • ACCEPT statement on stdin only. Same as a READ statement with an asterisk (*) as the unit.

    • OPEN statement extensions:


    • TYPE statement on stdout only; same as a PRINT statement.

    • Allow the double asterisk (**) to indicate stderr unit; that is, specifying WRITE(**,...).

    • Special compile time option to allow reread from stdin after EOF is -vms_stdin.

  • Unformatted I/O:

    • Allow unformatted I/O on an INTERNAL file.

    • Nonstandard aggregate reference in an I/O list is restricted to unformatted I/O and only one aggregate item is allowed.

  • Formatted I/O:

    • Carriage control with an ASCII NUL to cause overprint with no advance; that is, it does not return to left margin after printing.

    • Variable format in which the width can be an expression that is evaluated at execution.

    • INQUIRE statement extension:

      CARRIAGECONTROL= specifier

    • Allow the use of the letter Q for an exponent letter on input for a floating point value.

    • Special compile time option to interpret the carriage control character and replace it with the proper character in stdout.

  • List-directed I/O:

    • No repeat counts are generated for list-directed output.

    • Allow the use of the letter Q for an exponent letter on input for a floating-point value.


    • No repeat counts are generated for namelist output.

    • Allow the use of the letter Q for an exponent letter on input for a floating point value.

  • INQUIRE statement extensions:

    • ORGANIZATION= specifier specifier to also contain ACCESS= specifications.

    • Use of different-sized variables for more specifiers than allowed in Fortran 95.

  • OPEN statement extensions:

    • DEFAULTFILE= specifier to contain an alternate path or prefix for the opened unit. The specifier is concatenated with the string in the FILE= specifier or with the unit number if FILE= is absent.

    • DISP= specifier to designate how the file is handled after the file is closed. This is another form of the STATUS specifier on the CLOSE statement for Fortran 95.

    • FORM='BINARY' to indicate a formatted read with the A format on binary data. The implemented form of binary is unformatted I/O without record headers.

    • READONLY specifier indicates the file is read only. Fortran 95 provides the ACTION= specifier with more options.

    • RECORDTYPE= specifier to indicate type of records the file can contain. This may be present for direct, sequential, and keyed files.

    • SHARED= specifier indicates the file must be flushed after each record is written.

    • TYPE= specifier is the same as the Fortran 95 STATUS= specifier.

  • Environment variable FORTRAN_BUFFER_SIZE to set buffer size and determine if direct I/O should be used.

  • Interoperability with UNIX routines for I/O such as fseek(3), ftell(3), flush(3), fgetc(3), fstat(2), and others. The PXF interface routines allow the use of these routines with a proper Fortran interface.

  • Ability to query for the error status of the last I/O operation by unit.

  • Allow MP-safe I/O at the subroutine level so non-MP-safe and MP-safe I/O can be mixed in one program but not in a program unit.