20
The new features of Fortran 2003 David Muxworthy BSI Fortran Convenor

The new features of Fortran 2003Pages in Fortran Standards 0 100 200 300 400 500 600 700 1 9 6 6 1 9 6 7 1 9 6 8 1 9 6 9 1 9 7 0 1 9 7 1 1 9 7 2 1 9 7 3 1 9 7 4 1 9 7 5 1 9 7 6 1 9

  • Upload
    others

  • View
    6

  • Download
    0

Embed Size (px)

Citation preview

Page 1: The new features of Fortran 2003Pages in Fortran Standards 0 100 200 300 400 500 600 700 1 9 6 6 1 9 6 7 1 9 6 8 1 9 6 9 1 9 7 0 1 9 7 1 1 9 7 2 1 9 7 3 1 9 7 4 1 9 7 5 1 9 7 6 1 9

The new features of Fortran 2003

David MuxworthyBSI Fortran Convenor

Page 2: The new features of Fortran 2003Pages in Fortran Standards 0 100 200 300 400 500 600 700 1 9 6 6 1 9 6 7 1 9 6 8 1 9 6 9 1 9 7 0 1 9 7 1 1 9 7 2 1 9 7 3 1 9 7 4 1 9 7 5 1 9 7 6 1 9

Pages in Fortran Standards

0

100

200

300

400

500

600

70019

6619

6719

6819

6919

7019

7119

7219

7319

7419

7519

7619

7719

7819

7919

8019

8119

8219

8319

8419

8519

8619

8719

8819

8919

9019

9119

9219

9319

9419

9519

9619

9719

9819

9920

0020

0120

0220

0320

0420

0520

0620

0720

08

Year

Pag

es

Page 3: The new features of Fortran 2003Pages in Fortran Standards 0 100 200 300 400 500 600 700 1 9 6 6 1 9 6 7 1 9 6 8 1 9 6 9 1 9 7 0 1 9 7 1 1 9 7 2 1 9 7 3 1 9 7 4 1 9 7 5 1 9 7 6 1 9

Major extensions

• Standardized interoperability with C• Object-oriented support• Derived-type enhancements• IEEE 754 support• Numerous data manipulation enhancements• Numerous input/output enhancements

Page 4: The new features of Fortran 2003Pages in Fortran Standards 0 100 200 300 400 500 600 700 1 9 6 6 1 9 6 7 1 9 6 8 1 9 6 9 1 9 7 0 1 9 7 1 1 9 7 2 1 9 7 3 1 9 7 4 1 9 7 5 1 9 7 6 1 9

Minor incompatibilitieswith Fortran 95

• carriage control for printer output has been removed from the standard

• list-directed and namelist output of real zeros is changed

output of real zeros in these contexts always uses F rather than E format

• if the processor can distinguish +0.0 and -0.0, use is made of this by ATAN2 and by LOG, SQRT if they have complex arguments

e.g. result of ATAN2 or LOG may be -π rather than π

Page 5: The new features of Fortran 2003Pages in Fortran Standards 0 100 200 300 400 500 600 700 1 9 6 6 1 9 6 7 1 9 6 8 1 9 6 9 1 9 7 0 1 9 7 1 1 9 7 2 1 9 7 3 1 9 7 4 1 9 7 5 1 9 7 6 1 9

Characters andsource form

• the default character set is extended to include: ~ | \ [ ] { } @ # grave accent, circumflex accent

(but not acute accent) only [ and ] are used and are synonyms for (/ and /)

• variable names may be to 63 characters

• statements may be up to 256 lines

Page 6: The new features of Fortran 2003Pages in Fortran Standards 0 100 200 300 400 500 600 700 1 9 6 6 1 9 6 7 1 9 6 8 1 9 6 9 1 9 7 0 1 9 7 1 1 9 7 2 1 9 7 3 1 9 7 4 1 9 7 5 1 9 7 6 1 9

'International'(non-anglophone) usage

• explicit accommodation of 10646 characters (but not necessary for processors to support 10646)

• ability to specify decimal separator in internal or external files as POINT or COMMA

Page 7: The new features of Fortran 2003Pages in Fortran Standards 0 100 200 300 400 500 600 700 1 9 6 6 1 9 6 7 1 9 6 8 1 9 6 9 1 9 7 0 1 9 7 1 1 9 7 2 1 9 7 3 1 9 7 4 1 9 7 5 1 9 7 6 1 9

Data types and specifications

Many new facilities, including:• deferred type parameters length type parameters of certain entities may be changed during

execution

• VOLATILE attribute for interacting with non-Fortran processes

• ASYNCHRONOUS attribute for specifying that a variable may be subject to asynchronous

input/output

• type specification for array constructors, e.g. [CHARACTER(LEN=8) :: ’Fortran’, ’C’, ’Algol 68’]

Page 8: The new features of Fortran 2003Pages in Fortran Standards 0 100 200 300 400 500 600 700 1 9 6 6 1 9 6 7 1 9 6 8 1 9 6 9 1 9 7 0 1 9 7 1 1 9 7 2 1 9 7 3 1 9 7 4 1 9 7 5 1 9 7 6 1 9

More data manipulation enhancements

• specification and initialization expressions are extended by removal of some restrictions

• complex literals are extended to accept named constants, e.g.

(0., PI) where PI is a previously declared real constant

• MIN and MAX extended to accept character arguments

Page 9: The new features of Fortran 2003Pages in Fortran Standards 0 100 200 300 400 500 600 700 1 9 6 6 1 9 6 7 1 9 6 8 1 9 6 9 1 9 7 0 1 9 7 1 1 9 7 2 1 9 7 3 1 9 7 4 1 9 7 5 1 9 7 6 1 9

Derived type enhancements

• the kind, length and shape of derived type components may be specified when the type is used

• different components may have different accessibility

• improved structure constructors• finalizers• derived-type input/output• components may be allocatable

Page 10: The new features of Fortran 2003Pages in Fortran Standards 0 100 200 300 400 500 600 700 1 9 6 6 1 9 6 7 1 9 6 8 1 9 6 9 1 9 7 0 1 9 7 1 1 9 7 2 1 9 7 3 1 9 7 4 1 9 7 5 1 9 7 6 1 9

ASSOCIATE construct

This allows a complex expression or object to be denoted by a simple symbol

Examples:associate ( z => exp(-(x**2+y**2)) * cos(theta) ) print *, a+z, a-zend associate

associate ( array => ax%b(i,:)%c ) array(n)%ev = array(n-1)%evend associate

Page 11: The new features of Fortran 2003Pages in Fortran Standards 0 100 200 300 400 500 600 700 1 9 6 6 1 9 6 7 1 9 6 8 1 9 6 9 1 9 7 0 1 9 7 1 1 9 7 2 1 9 7 3 1 9 7 4 1 9 7 5 1 9 7 6 1 9

Enumerators

Enumerators are provided to interoperate with thecorresponding C enumeration type

Example:enum, bind(c)

enumerator :: red = 4, blue = 9enumerator yellow

end enum

Page 12: The new features of Fortran 2003Pages in Fortran Standards 0 100 200 300 400 500 600 700 1 9 6 6 1 9 6 7 1 9 6 8 1 9 6 9 1 9 7 0 1 9 7 1 1 9 7 2 1 9 7 3 1 9 7 4 1 9 7 5 1 9 7 6 1 9

Procedure pointers

Pointers are extended to point to procedures, aswell as variables, using a new PROCEDUREstatement.

Example:procedure (real_func), pointer :: p=> null()where the interface to real_func has already been

defined...p => besselwrite (*, *) p(2.5) !-- bessel(2.5)

Page 13: The new features of Fortran 2003Pages in Fortran Standards 0 100 200 300 400 500 600 700 1 9 6 6 1 9 6 7 1 9 6 8 1 9 6 9 1 9 7 0 1 9 7 1 1 9 7 2 1 9 7 3 1 9 7 4 1 9 7 5 1 9 7 6 1 9

Input/output enhancements

There are many detailed enhancements, including:• asynchronous transfer• stream, rather than record, access• named constants for preconnected units• FLUSH statement• access to error messages• derived-type i/o• control over rounding mode at internal to external

real number conversion

Page 14: The new features of Fortran 2003Pages in Fortran Standards 0 100 200 300 400 500 600 700 1 9 6 6 1 9 6 7 1 9 6 8 1 9 6 9 1 9 7 0 1 9 7 1 1 9 7 2 1 9 7 3 1 9 7 4 1 9 7 5 1 9 7 6 1 9

IEEE support

If the processor supports some or all of IEC 60559(IEEE 754) arithmetic, the standard providesfacilities to:• query which IEEE facilities are provided• access the facilities for IEEE arithmetic, exception

handling, rounding, use of certain IEEE functions, etc.

Page 15: The new features of Fortran 2003Pages in Fortran Standards 0 100 200 300 400 500 600 700 1 9 6 6 1 9 6 7 1 9 6 8 1 9 6 9 1 9 7 0 1 9 7 1 1 9 7 2 1 9 7 3 1 9 7 4 1 9 7 5 1 9 7 6 1 9

Enhanced access to system environment

new procedures, including• GET_COMMAND• GET_COMMAND_ARGUMENT• GET_ENVIRONMENT_VARIABLE• COMMAND_ARGUMENT_COUNT

IOMSG=character-variable specifier in OPEN, CLOSE, READ, WRITE

Page 16: The new features of Fortran 2003Pages in Fortran Standards 0 100 200 300 400 500 600 700 1 9 6 6 1 9 6 7 1 9 6 8 1 9 6 9 1 9 7 0 1 9 7 1 1 9 7 2 1 9 7 3 1 9 7 4 1 9 7 5 1 9 7 6 1 9

Interoperability with CUses intrinsic module ISO_C_BINDING to define named

constants and derived typesallows for interoperability of:• intrinsic types• pointer types• derived types• scalars and arrays• procedures and procedure interfaces• C global variables• C functionsbut not (yet):• procedures with data pointer, allocatable, assumed-shape

array or optional dummy arguments

Page 17: The new features of Fortran 2003Pages in Fortran Standards 0 100 200 300 400 500 600 700 1 9 6 6 1 9 6 7 1 9 6 8 1 9 6 9 1 9 7 0 1 9 7 1 1 9 7 2 1 9 7 3 1 9 7 4 1 9 7 5 1 9 7 6 1 9

Interoperability with Cexample part 1

C Function Prototype: int C_Library_Function(void* sendbuf, int sendcount, int

*recvcounts);Fortran Module:module ftn_c

interface integer (c_int) function C_Library_Function &

(sendbuf, sendcount, recvcounts), & bind(c,name=’C_Library_Function’) use iso_c_binding implicit none type (c_ptr), value :: sendbuf integer (c_int), value :: sendcount type (c_ptr), value :: recvcounts end function C_Library_Function

end interfaceend module ftn_c

Page 18: The new features of Fortran 2003Pages in Fortran Standards 0 100 200 300 400 500 600 700 1 9 6 6 1 9 6 7 1 9 6 8 1 9 6 9 1 9 7 0 1 9 7 1 1 9 7 2 1 9 7 3 1 9 7 4 1 9 7 5 1 9 7 6 1 9

Interoperability with Cexample part 2

Fortran Calling Sequence:

use iso_c_binding, only: c_int, c_float, c_locuse ftn_c...real (c_float), target :: send(100)integer (c_int) :: sendcountinteger (c_int), allocatable, target ::

recvcounts(100)...allocate( recvcounts(100) )...call C_Library_Function(c_loc(send), sendcount, & c_loc(recvcounts))

Page 19: The new features of Fortran 2003Pages in Fortran Standards 0 100 200 300 400 500 600 700 1 9 6 6 1 9 6 7 1 9 6 8 1 9 6 9 1 9 7 0 1 9 7 1 1 9 7 2 1 9 7 3 1 9 7 4 1 9 7 5 1 9 7 6 1 9

Object-oriented support

• enhanced data abstraction one type may extend the definition of another

• polymorphism allows type of a variable to vary at run time

• dynamic type allocation

• SELECT TYPE construct

• type-bound procedures

Page 20: The new features of Fortran 2003Pages in Fortran Standards 0 100 200 300 400 500 600 700 1 9 6 6 1 9 6 7 1 9 6 8 1 9 6 9 1 9 7 0 1 9 7 1 1 9 7 2 1 9 7 3 1 9 7 4 1 9 7 5 1 9 7 6 1 9

Further information

For a far more detailed (38 page) overview of thenew features in Fortran 2003 relative toFortran 95 see "The New Features of Fortran 2003"by John Reid, at

ftp://ftp.nag.co.uk/sc22wg5/N1601-N1650/N1648.pdf