Fortran 2003 Features in the Sun Fortran Compiler

   

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

 int main(int ac, char *av[])
            

 {
            

 to_Fortran(2);
            

 }
            

</stdlib.h>
          

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 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 allocated 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. (-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.)

IEEE Technical Report (SPARC only)


Support for exceptions and IEEE Arithmetic was added to Fortran 2003. This feature was first published as a Technical Report in advance of publication of Fortran 2003, and is often referred to as the "IEEE Technical Report". Some small changes were made to the feature after the report was issued. In these cases, Sun supports the version of the feature as specified in the Fortran 2003 standard.

New intrinsic modules IEEE_ARITHMETIC, and IEEE_FEATURES provide this support. Full support of these features is provided by:

        USE, INTRINSIC :: IEEE_ARITHMETIC
        USE, INTRINSIC :: IEEE_FEATURES

If only support for exceptions is required,

        USE, INTRINSIC :: IEEE_EXCEPTIONS

may be used.  It is automatically implied by use of IEEE_ARITHMETIC. These modules define a set of derived types, constants, rounding modes, inquiry functions, elemental functions, kind functions, and elemental and non-elemental subroutines.

"USE, INTRINSIC" statement


A new qualifier " INTRINSIC" can now be added to the USE statement to gain access to modules which are intrinsically part of the compiler and not supplied as ordinary modules.  The standard intrinsic modules available with the compiler are

    ISO_C_BINDING
    ISO_FORTRAN_ENV
    IEEE_EXCEPTIONS
    IEEE_ARITHMETIC
    IEEE_FEATURES

The ISO_FORTRAN_ENV intrinsic module provides public entities relating to the Fortran environment, including named constants for

    CHARACTER_STORAGE_SIZE
    ERROR_UNIT
    FILE_STORAGE_SIZE
    INPUT_UNIT, IOSTAT_END
    OSTAT_EOR
    NUMERIC_STORAGE_SIZE
    OUTPUT_UNIT

The 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 should only be defined within the module that declares them. Note that Fortran 2003 does not require that all violations of this rule should be caught, but Sun Fortran tries to diagnose as many of these as it can.

Asynchronous I/O


The compiler recognizes the ASYNCHRONOUS specifier on I/O statements:
               
    ASYNCHRONOUS=['YES' | 'NO']

 
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', Fortran 2003 does not require actual asynchronous I/O. In Sun Studio 11 Fortran, I/O is always synchronous.

Command Line Intrinsics


Fortran 2003 introduces three new intrinsics for processing command-line arguments and environment variables. The new intrinsics 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.

 

Conclusions


.f03.F03

Related Information