Fortran 2003 Features in the Sun Fortran Compiler
Added 31 Jul 2008
The Sun Studio Fortran compiler, f95, already handles a large number of features that are part of the current Fortran international standard, Fortran 2003.
Introducing Fortran 2003
The current Fortran standard, Fortran 2003, was approved in 2003 by ISO, the international standards organization. This is the same standard that was sometimes referred to in development or earlier documentation as Fortran 2000 or Fortran 200x. Many of the new features in this standard have already been implemented in the Sun Studio Fortran compiler. The features below are all available in Sun Studio 11:
- an extended ALLOCATABLE attribute
- the VALUE type declaration attribute
- stream I/O
- new formatted I/O specifiers
- the VOLATILE type declaration attribute
- the IEEE Technical Report
- the "USE, INTRINSIC" statement
- interoperability with C with the BIND(C) statement
- the PROTECTED type declaration attribute
- Asynchronous I/O
- Command Line Intrinsics
Extended ALLOCATABLE Attribute
The Fortran 2003 draft standard extends the applicable data entities
for the ALLOCATABLE attribute. Fortran 95 limited the ALLOCATABLE
attribute to locally stored array variables. Fortran 2003 draft standard
(and the Sun Studio f95 compiler) extends the application
of the ALLOCATABLE attribute by adding:
- array components of structures
- dummy arrays
- array function results
Allocatable data objects remain forbidden in all places where they
may be storage-associated, such as in COMMON blocks and
EQUIVALENCE groups. Allocatable array components may appear
in SEQUENCE types, but objects of such types are then prohibited
from COMMON and EQUIVALENCE.
These features were first introduce in a Technical Report issued in advance of publication of the Fortran 2003 standard.
The VALUE Attribute
Fortran 2003 introduces the VALUE attribute for subprogram
dummy arguments. Specifying a dummy argument with the VALUE
attribute indicates that the actual argument is passed "by value" rather
than "by reference". The current value of the argument is passed to
the subprogram and cannot be changed in the subprogram.
The following example demonstrates the use of the VALUE
with a C program calling a Fortran subprogram with a literal constant
as an argument.
C code:
#include
int main(int ac, char *av[])
{
to_Fortran(2);
}
Fortran code:
subroutine to_Fortran(i)
integer, value :: i
print *, i
end
Stream I/O
Stream I/O access treats a data file as a continuous sequence
of bytes, addressable by a positive integer starting from 1. 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.
New 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:
-
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 representations, 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 ifROUNDis not specified. As an example,WRITE(*,'(f11.4)')0.11115 prints0.1111in default mode, and0.1112in'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 allocated a character buffer large enough to hold the longest message. (CHARACTER*256should 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. (-iorounding=mode.)
The VOLATILE Attribute
The Fortran 95 compiler now accepts the Fortran 2003 VOLATILE attribute. VOLATILE
imposes limits on optimization. It specifies that the value of an
entity might be changed or referenced by means other than Fortran.
Additionally, for parallel programs written in Sun Fortran, it
can be used to specify that the value of an entity might be changed by
another thread than the current thread. (The Fortran 2003
standard does not specify behavior of parallel programs.)