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.
The new standard for Fortran provides:
a means of referencing C language procedures and, conversely, a means of specifying that a Fortran subprogram can be referenced from a C function, and
a means of declaring global variables that are linked with external C variables
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.
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.
The Fortran 2003 standard introduces three new intrinsics for processing command-line arguments and environment variables. These are:
GET_COMMAND(command, length, status)
Returns in command the entire command line that invoked the program.
GET_COMMAND_ARGUMENT(number, value, length, status)
Returns a command-line argument in value.
GET_ENVIRONMENT_VARIABLE(name, value, length, status, trim_name)
Return the value of an environment variable.
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.
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.
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:
array components of structures
dummy arrays
array function results
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.
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 |
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.
Three new Fortran 2003 formatted I/O specifiers have been implemented in f95. They may appear on OPEN, READ, WRITE, PRINT, and INQUIRE statements:
DECIMAL=[’POINT’|’COMMA’]
Change the default decimal editing mode. The default uses a period to separate the whole number and decimal parts of a floating-point number formatted with D, E, EN, ES, F, and G editing. ’COMMA’ changes the default to use comma instead of a period, to print, for example, 123,456. The default is ’POINT’, which uses a period, to print, for example, 123.456.
ROUND=[’PROCESSOR_DEFINED’ | ’COMPATIBLE’]
Set the default rounding mode for formatted I/O D, E, EN, ES, F, and G editing. With ’COMPATIBLE’, the value resulting from data conversion is the one closer to the two nearest represetnations, or the value away from zero if the value is halfway between them. With ’PROCESSOR_DEFINED’, the rounding mode is dependent on the processor’s default mode, and is the compiler default if ROUND is not specified.
As an example, WRITE(*,’(f11.4)’) 0.11115 prints 0.1111 in default mode, and 0.1112 in ’COMPATIBLE’ mode.
IOMSG=character-variable
Returns an error message as a string in the specified character variable. This is the same error message that would appear on standard output. Users should allocate a character buffer large enough to hold the longest message. (CHARACTER*256 should be sufficient.)
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}].)
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.