Chapter 4. Extensions and Differences
Prev |  | Next

## Chapter 4. Extensions and Differences

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

- Fortran 95 standard differences and incompatibilities with FORTRAN 77 implementations

- CF90 extensions to Fortran 95

- MIPSpro 7 Fortran 90 extensions to Fortran 95

- CF90, MIPSpro Fortran 77 and MIPSpro 7 Fortran 90 differences

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

### 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 CF90 and MIPSpro 7 Fortran 90 compilers.

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 CF90 and MIPSpro 7 Fortran 90 compilers.

Consider the following code fragment:

         DOUBLE PRECISION AVD, BVD, CVD
         AVD = 0.0D0
         WRITE(6, 1) AVD
    1    FORMAT(G28.2)
         END

It generates the following output when compiled by CF90:

    0.0

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

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

### 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)
          END

The preceding code generates the following output for the CF90 compiler:

    % f90 tt.f
    % a.out
     0.E+0
          0.0

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

### List-directed I/O and Hollerith Constants

Fortran 95 does not support Hollerith constants in list-directed input files, but the CF90 and MIPSpro 7 Fortran 90 compilers 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.

### 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 CF90 and MIPSpro 7 Fortran 90 compilers allow 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 CF90 and MIPSpro 7 Fortran 90 compilers fill the field with asterisks. The CF90 and MIPSpro 7 Fortran 90 compilers provide the Fortran 95 form of `Ow` and `Zw` output.

## MIPSpro 7 Fortran 90 extensions to Fortran 95

The MIPSpro 7 Fortran 90 compiler supports the following extensions to Fortran 95:

- 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

- `NAMELIST` I/O:

  - 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.

## CF90, MIPSpro 7 Fortran 90, and MIPSpro Fortran 77 Differences

This section describes differences between the various Fortran compilers supported on IRIX, UNICOS, and UNICOS/mk systems.

### MIPSpro 7 Fortran 90 and CF90 Compiler Differences

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

#### Numerical Model Differences

The model differences are as follows:

- The model for the CF90 `REAL(KIND=16)` data type on CRAY T90 systems that support IEEE floating-point arithmetic is different from the model for the MIPSpro 7 Fortran 90 compiler. This means that the results of math functions, arithmetic calculations, I/O, and other library routines are different for this particular data type.

- The internal size of `INTEGER(KIND=1)`, `INTEGER(KIND=2)`, `LOGICAL(KIND=1)`, and `LOGICAL(KIND=2)` on the MIPSpro 7 Fortran 90 compiler is actually 1 and 2 bytes, respectively. The CF90 compiler treats these kind type parameters as `INTEGER(KIND=4)` and `LOGICAL(KIND=4)`.

- The default sizes of the MIPSpro 7 Fortran 90 integer, real, and logical data types are 32 bits. This differs from the CF90 default of 64 bits. The default data type sizes for the MIPSpro 7 Fortran 90 compiler may be incorrect for routines such as `IRTC(3i)` and SHMEM.

- The MIPSpro 7 Fortran 90 compiler does not support Cray character pointers.

- Pointer arithmetic is in default numeric storage units when using the CF90 compiler. Pointer arithmetic is in bytes when using the MIPSpro 7 Fortran 90 compiler.

For more information on the model, see the `models(3i)` man page.

#### Fortran Statement Differences

The Fortran 95 statement differences are as follows:

- When using the MIPSpro 7 Fortran 90 compiler, the execution of the `STOP` statement does not cause the word `STOP` to be written to `stdout` unless there is an argument to the `STOP` statement. The CF90 compiler always writes `STOP` to `stdout`.

- When using the MIPSpro 7 Fortran 90 compiler, the initialization of entities in a common block in a `DATA` statement can only be done in one program unit. That is, if a common block contains two variables initialized in a `DATA` statement, those `DATA` statements must be in one program unit. The load indicates the presence of multiple initializations, and only one initialization is done.

  With the CF90 compiler, different variables can be initialized in `DATA` statements in separate program units.

#### Function and Procedure Differences

The CF90 typeless functions (such as `MASK(3i)`, `SHIFTL(3i)`, `SHIFTR(3i)`, `SHIFT(3i)`, `CVM(3i)`, and so on) are typed as integer functions by the MIPSpro 7 Fortran 90 compiler. Conversion occur in expressions involving a mixture of floating point and integer functions. When called by the CF90 compiler, these functions are typeless and no conversion occurs when there is a mixture of floating point and these typeless functions.

#### Modules Differences

When using the MIPSpro 7 Fortran 90 compiler, the compilation of Fortran 95 modules creates a `file.mod` for each module in the source file and creates a `file.o` for any module procedures.

To load compiled module procedures, specify `module.o` on the command line.

When using the CF90 compiler, compiling modules creates one `file.o` that contains all the Fortran 95 modules in the source file.

#### I/O Library Differences

The I/O library differences are as follows:

- Direct access formatted output files cannot be read as sequential formatted files by MIPSpro 7 Fortran 90 programs unless an `assign(1)` command with `-s unblocked`, `-F cachea`, or `-F cache` is supplied for the particular file.

- The set of I/O library errors begins at 4000 for MIPSpro 7 Fortran 90 programs. The error numbers begin at 1000 for CF90 programs.

- The `FILENV` environment variable must be set for MIPSpro 7 Fortran 90 programs when using the `assign(1)` command. For CF90 users, this environment variable need not be set.

#### Library Function and Procedure Differences

The library function and intrinsic procedure differences are as follows:

- The `CRI_IEEE_DEFINITIONS` module is available for the MIPSpro 7 Fortran 90 compiler, but the preferred name is `FTN_IEEE_DEFINITIONS` for the IEEE module and the interface to the IEEE procedures.

- The `MAXVAL(3i)` intrinsic procedure returns negative infinity for a zero-sized input array when called from a MIPSpro 7 Fortran 90 program and returns -`HUGE(3i)` when called from a CF90 program. A request for interpretation has been submitted to the Fortran standards committee.

- The `MINVAL(3i)` intrinsic procedure returns positive infinity for a zero-sized input array when called from a MIPSpro 7 Fortran 90 program and returns +`HUGE(3i)` when called from a CF90 program. A request for interpretation has been submitted to the Fortran standards committee.

#### Math Library Differences

The math library differences are as follows:

- The math routines from the MIPSpro 7 Fortran 90 compiler are referenced from the compiler. The results of the math routines from the MIPSpro 7 Fortran 90 compiler may differ from the results returned by the math routines for the CF90 compiler.

- Signaling of errors during references to the MIPSpro 7 Fortran 90 compiler math routines is not turned off. For the CF90 compiler, the math routines turn off signaling of errors and detect input data errors through source code checks.

### MIPSpro FORTRAN 77 and MIPSpro 7 Fortran 90 Compiler Differences

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

#### Intrinsic Function and Subroutine Differences

The MIPSpro FORTRAN 77 compiler supports the `TIME` intrinsic function and the MIPSpro 7 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 7 Fortran 90 compiler.

#### `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 7 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 the IRIX, UNICOS, and UNICOS/mk platforms. For the program to be a standard conforming program with predictable results, you must remove multiple initializations.

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

#### 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 7 Fortran 90 compiler. However, neither form is supported by the Fortran 95 standard or by the MIPSpro 7 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.

#### MIscellaneous Differences

The following miscellaneous items in the MIPSpro Fortran 77 compiler are not in the MIPSpro 7 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:

        FILE='SYS$INPUT', 'SYS$OUTPUT', 'SYS$ERROR'

  - `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.

- `NAMELIST` I/O:

  - 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.

Prev | Table of Contents | Next
Chapter 3. Character Set |  | Chapter 5. Data Representation and Storage