Sun Studio 12: Fortran User's Guide

4.6 Fortran 2003 Features

A number of new features in the Fortran 2003 standard appear in this release of the f95 compiler. For details, refer to the Fortran 2003 standard.

4.6.1 Interoperability with C Functions

The new standard for Fortran provides:

The ISO_C_BINDING module provides access to named constants that are kind type parameters representing data that is compatible with C types.

The draft standard also introduces the BIND(C) attribute. A Fortran derived type is interoperable with C if it has the BIND attribute.

This release of the Fortran 95 compiler implements these features as described in the chapter 15 of the draft standard. Fortran also provides facilities for defining derived types and enumerations that correspond to C types, as described in chapter 4 of the standard.

4.6.2 IEEE Floating-Point Exception Handling

New intrinsic modules IEEE_ARITHMETIC, and IEEE_FEATURES provide support for exceptions and IEEE arithmetic in the Fortran language. Full support of these features is provided by:

USE, INTRINSIC :: IEEE_ARITHMETIC

USE, INTRINSIC :: IEEE_FEATURES

The INTRINSIC keyword is new in Fortran 2003.These modules define a set of derived types, constants, rounding modes, inquiry functions, elemental functions, kind functions, and elemental and non-elemental subroutines. The details are contained in Chapter 14 of the draft standard for Fortran 2003.

4.6.3 Command-Line Argument Intrinsics

The Fortran 2003 standard introduces three new intrinsics for processing command-line arguments and environment variables. These are:

4.6.4 PROTECTED Attribute

The Fortran 95 compiler now accepts the Fortran 2003 PROTECTED attribute. PROTECTED imposes limitations on the usage of module entities. Objects with the PROTECTED attribute are only definable within the module that declares them.

4.6.5 Fortran 2003 Asynchronous I/O

The compiler recognizes the ASYNCHRONOUS specifier on I/O statements:

ASYNCHRONOUS=[’YES’ | ’NO’]

This syntax is as proposed in the Fortran 2003 standard, Chapter 9. In combination with the WAIT statement it allows the programmer to specify I/O processes that may be overlapped with computation. While the compiler recognizes ASYNCHRONOUS=’YES’, the draft standard does not require actual asynchronous I/O. In this release of the compiler, I/O is always synchronous.

4.6.6 Extended ALLOCATABLE Attribute

Fortran 2003 extends the data entities allowed for the ALLOCATABLE attribute. Previously this attribute was limited to locally stored array variables. It is now allowed with:

Allocatable entities remain forbidden in all places where they may be storage-associated: COMMON blocks and EQUIVALENCE statements. Allocatable array components may appear in SEQUENCE types, but objects of such types are then prohibited from COMMON and EQUIVALENCE.

4.6.7 VALUE Attribute

The f95 compiler accepts the Fortran 2003 VALUE type declaration attribute.

Specifying a subprogram dummy input argument with this attribute indicates that the actual argument is passed “by value”. The following example demonstrates the use of the VALUE attribute with a C main program calling a Fortran 95 subprogram with a literal value as an argument:


C code:
#include <stdlib.h>
int main(int ac, char *av[])
{
    to_fortran(2);
}

Fortran code:
       subroutine to_fortran(i)
       integer, value :: i
       print *, i
       end

4.6.8 Fortran 2003 Stream I/O

The Fortran 2003 standard defines a new “stream” I/O scheme. Stream I/O access treats a data file as a continuous sequence of bytes, addressable by a positive integer starting from 1. The data file can be connected for either formatted or unformatted access.

Declare a stream I/O file with the ACCESS=’STREAM’ specifier on the OPEN statement. File positioning to a byte address requires a POS=scalar_integer_expression specifier on a READ or WRITE statement. The INQUIRE statement accepts ACCESS=’STREAM’, a specifier STREAM=scalar_character_variable, and POS=scalar_integer_variable.

4.6.9 Fortran 2003 Formatted I/O Features

Three new Fortran 2003 formatted I/O specifiers have been implemented in f95. They may appear on OPEN, READ, WRITE, PRINT, and INQUIRE statements:

When used in INQUIRE statements, these specifiers declare a character variable for returning the current values.

New edit descriptors DP, DC, RP, and RC change the defaults within a single FORMAT statement to decimal point, decimal comma, processor-defined rounding, and compatible rounding respectively. For example:

WRITE(*,’(I5,DC,F10.3)’) N, W

prints a comma instead of a period in the F10.3 output item.

See also the -iorounding compiler command-line option for changing the floating-point rounding modes on formatted I/O. (3.4.49 –iorounding[={compatible|processor-defined}].)

4.6.10 Fortran 2003 FLUSH I/O Statement

The f95 compiler accepts the Fortran 2003 FLUSH statement. The FLUSH statement makes data written to an external file available to other processes, or causes data placed in an external file by means other than Fortran to be available to a READ statement.