fortran 8x, the draft fortran standard revision

8
Fortran 8X, The Draft Fortran Standard Revision 335 Jeanne ADAMS National Center for Atmospheric Research, Chair, X3J3, Box 3000, Boulder. CO 80307, U.S.A. and John REID Harwell Laboratory, Secretary, X3J3, Harwell, Didcot, Oxford- shire OX 31 ORA, U.K. The :Fortran 8x draft standard, as forwarded to X3 for further processing as an American National Standard, is sum- marized. A way to evolve Fortran as a modern language now and into the future is described. Keyword~: Family of Standards, incremental and decremental features, array, precision, derived type, modules. Jeanne Adams is a consultant for the i Advanced Methods Group, Scientific Computing Division, National Center for Atmospheric Research. Pursuing her interests in standards for informa- tion processing, Ms. Adams has at- tended several conferences as an Inter- national Standards Organization (ISO) a delegate to technical committees on information processing. She was chair of the ISO Committee on Information Processing for Programming Lan- guages (SC 5) for many years and is chair of the Fortran Standards Committee (X3J3) of the American National Standards Institute (ANSI). She has con- ducted numerous forums in the United States and in Europe on Fortran Standards and vector processing methods and written journal articles on standards and educational methods using computers. John Reid is a numerical analyst, known for work on sparse matrices, who has written much Fortran soft- ware and is Chairman of IFIP Work- ing Group 2.5 (on Numerical Soft- ware). He has been a member of the ANSI Fortran Committee X3J3 since 1983 and was appointed Secretary in 1987. North-Holland Computer Standards & Interfaces 7 (1988) 335-342 1. Introduction A revision (Fortran 8x) of the current Fortran Standard (Fortran 77), has been forwarded by X3J3, the Fortran Standards Committee, to X3, the Committee on Information Processing under the American National Standards Institute (ANSI). At the same time, an international group of Fortran experts (Working Group 5 of Subcom- mittee 22 under the International Standards Organization (ISO)) has also approved further processing of the draft revision. Both X3J3 and Working Group 5 look forward to the public review of this document, after it is released to the public by the parent committees indicated above. While the entire document will be published when public review is approved, it would be helpful to publish a summary of the contents in anticipation of this review and distrib- ute it as broadly as possible. These notes sum- marize the language contained in the draft revi- sion. 2. History Initial work on the first Fortran standard, For- tran 66, took place in 1962. In 1968 there were enough extensions in Fortran compilers that it was decided to revise the 1966 standard and work began on Fortran 77. During the comment period for Fortran 77, there were 1225 pages of public responses, the largest outpouring of commentary to any standard review document at that time. It was felt that a third revision should be launched as soon as possible, and that Fortran should be modernized and be made more responsive to cur- rent machine architectures. There was consider- able pressure to consider, among other facilities, the many requests for new features received dur- ing the comment period that were rejected by the Committee as premature in 1977. 0920-5489/88/$3.50 © 1988, Elsevier Science Publishers B.V. (North-Holland)

Upload: jeanne-adams

Post on 30-Aug-2016

244 views

Category:

Documents


6 download

TRANSCRIPT

Page 1: Fortran 8x, the draft Fortran standard revision

Fortran 8X, The Draft Fortran Standard Revision

335

Jeanne ADAMS

National Center for Atmospheric Research, Chair, X3J3, Box 3000, Boulder. CO 80307, U.S.A.

and

John REID

Harwell Laboratory, Secretary, X3J3, Harwell, Didcot, Oxford- shire OX 31 ORA, U.K.

The :Fortran 8x draft standard, as forwarded to X3 for further processing as an American National Standard, is sum- marized. A way to evolve Fortran as a modern language now and into the future is described.

Keyword~: Family of Standards, incremental and decremental features, array, precision, derived type, modules.

Jeanne Adams is a consultant for the i Advanced Methods Group, Scientific

Computing Division, National Center for Atmospheric Research. Pursuing her interests in standards for informa- tion processing, Ms. Adams has at- tended several conferences as an Inter- national Standards Organization (ISO)

a delegate to technical committees on information processing. She was chair of the ISO Committee on Information Processing for Programming Lan- guages (SC 5) for many years and is

chair of the Fortran Standards Committee (X3J3) of the American National Standards Institute (ANSI). She has con- ducted numerous forums in the United States and in Europe on Fortran Standards and vector processing methods and written journal articles on standards and educational methods using computers.

John Reid is a numerical analyst, known for work on sparse matrices, who has written much Fortran soft- ware and is Chairman of IFIP Work- ing Group 2.5 (on Numerical Soft- ware). He has been a member of the ANSI Fortran Committee X3J3 since 1983 and was appointed Secretary in 1987.

North-Holland Computer Standards & Interfaces 7 (1988) 335-342

1. Introduction

A revision (Fortran 8x) of the current Fortran Standard (Fortran 77), has been forwarded by X3J3, the Fortran Standards Committee, to X3, the Committee on Information Processing under the American National Standards Institute (ANSI). At the same time, an international group of Fortran experts (Working Group 5 of Subcom- mittee 22 under the International Standards Organization (ISO)) has also approved further processing of the draft revision.

Both X3J3 and Working Group 5 look forward to the public review of this document, after it is released to the public by the parent committees indicated above. While the entire document will be published when public review is approved, it would be helpful to publish a summary of the contents in anticipation of this review and distrib- ute it as broadly as possible. These notes sum- marize the language contained in the draft revi- sion.

2. History

Initial work on the first Fortran standard, For- tran 66, took place in 1962. In 1968 there were enough extensions in Fortran compilers that it was decided to revise the 1966 standard and work began on Fortran 77. During the comment period for Fortran 77, there were 1225 pages of public responses, the largest outpouring of commentary to any standard review document at that time. It was felt that a third revision should be launched as soon as possible, and that Fortran should be modernized and be made more responsive to cur- rent machine architectures. There was consider- able pressure to consider, among other facilities, the many requests for new features received dur- ing the comment period that were rejected by the Committee as premature in 1977.

0920-5489/88/$3.50 © 1988, Elsevier Science Publishers B.V. (North-Holland)

Page 2: Fortran 8x, the draft Fortran standard revision

336 J. Adams, J. Reid / Draft Fortran Standard Revision

3. Language Evolution

If Fortran is to survive and remain useful to a large body of scientific and engineering users, it must continue to grow and change. The standardi- zation of Fortran has progressed for over 20 years, and will continue if an orderly way is found for its development and modernization. The Committee has produced a reference model as a guide to make this continued development possible.

The facilities in Fortran 8x have been placed in three categories, primary features, incremental features and decremental features. See Fig. 1.

Primary Features. Primary features are those from the previous standard that continue to be used by Fortran programmers. These are features that over the period of standardization are char- acteristic of the language, and most used in the large body of software that currently exists. These features are expected to have a long life in several generations of Fortran standardization.

Incremental features. Incremental features are new to Fortran and improve its usefulness. They are derived from current extensions in Fortran

and other high-level languages. The major incre- mental features added to Fortran in this revision are:

array operations generalized numeric precision programmer defined data types module data and procedure definitions procedure enhancements.

Core Fortran. Core Fortran has been men- tioned as the primary plus the incremental fea- tures in an Appendix to the standard. This con- cept does not define a standard-conforming subset of the language, however.

Decremental Features. Decremental features are either removed or are candidates for removal in future revisions of the standard. There are three classes of decremental features; deleted, obsoles- cent and deprecated. Deleted features, such as Hollerith in Fortran 66, are already removed. Ob- solescent features, such as the arithmetic IF state- ment, are largely obsolete in Fortran 77 and are candidates for removal in the next draft revision.

FORTRAN FAMILY OF STANDARDS (Reference Model)

. /

Old Features

(Decremental)

\

Fortran

Intersection (Primary)

New Features

(Incremental)

Fortran 9X

Fo~ran 8X

Fo~ran 77

Core Fortran is

Primary plus Incremental Features

Fig. 1. The Fortran language standard

Page 3: Fortran 8x, the draft Fortran standard revision

J. Adams, J. Reid / Draft Fortran Standard Revision 337

Table 1 Decremental Features

Deleted Obsolescent Deprecated

None Arithmetic IF Noninteger DO Indices Do Termination other than C O N T I N U E or END DO

Shared DO Termination Branching to END IF from outside Alternate R E T U R N PAUSE ASSIGN & Assigned GO TO Assigned F O R M A T Labels

Assumed-size D u m m y Arrays Passing an Array Element to Array BLOCK DATA Storage Association C O M M O N EQUIVALENCE ENTRY Old Source Form Specific Names for Intrinsic Functions Statement Functions Old form of DATA Statement Data Statements among

Executable Statements Computed GO TO DIMENSION D O U B L E PRECISION C H A R A C T E R * len

Deprecated features are those that are superseded in Fortran 8x and are candidates for the obsoles- cent category in the next revision, and possible removal after the year 2000. There are no Fortran 77 features deleted in Fortran 8x. All software currently standard will be standard-conforming with Fortran 8x. See Table 1.

4. Array Operations

An array is a set of scalars of the same type arranged in rectangular fashion. Each element of the set is referenced by subscripting. An array name appearing without subscripts is a whole array. Arrays may be used in whole-array expres- sions such as:

B + C 'SIN(D)

The operations are performed element-by-ele- ment, that is the sine function is applied to each element of D, multiplied by the corresponding element of C, and added to the corresponding element of B. The arrays must have exactly the same shape, but scalars may be intermixed freely. Temporary array storage may be needed for inter- mediate results. Array expressions may be used as actual arguments. They may be used in whole array assignments provided there is exact shape agreement.

Rectangular subarrays, called sections, may be

used as arrays. Examples are A(:, 7) which is the seventh column of A, and A(2:10:2,7) which consists of components 2, 4, 6, 8, 10 of the seventh column of A.

Arrays may be "automatic" (automatically al- located on entry to a procedure and deallocated on return) or "allocatable" (allocated and deallocated by explicit statements). Dummy arrays may be "assumed-shape" (take their shapes from the corresponding actual argument). Arrays may be of size zero. Functions may be array-valued.

Scalar functions may be called "elementally" in the way SIN was called in the above example. There are many new inquiry intrinsics that return array properties of their arguments and many new array-valued intrinsics, for example MATMUL for matrix multiplication, MAXVAL for the largest element, and SUM for summation of the elements of an array.

The executable statement IDENTIFY provides access through an alias name to a section that may be skew. For example,

IDENTIFY (DIAG(I) = A(I, I), I = 1, N)

permits the diagonal of A to be accessed as a rank-one array called DIAG.

Arrays of rank one may be constructed as lists of scalars and other arrays of rank one, possibly repeated. An example of any array constant of size 10 is [1.0, 2.7, 411.0, 2.0]]. There is a RE- SHAPE intrinsic function to allow arrays of other

Page 4: Fortran 8x, the draft Fortran standard revision

338 J. Adams, J. Reid / Draft Fortran Standard Revision

shapes to be constructed. WHERE statements al- low array assignment statements evaluated only for certain array elements. Arrays may be "ranged", in which case the whole array state- ments refer to a subarray that is set and reset by execution of SET RANGE statements.

It is often asked if Fortran will continue with column-major storage order. The answer is that compatibility with Fortran 77 dictates that it will. However, long-term use will de-emphasize the cur- rent dependence on storage association in Fortran.

REAL R(M, N)

END TYPE

might be used for m by n matrices. Indeed, if matrix arithmetic is needed, some such type would be needed.

Derived data provides the language with a powerful form of extendibility. It means that ordinary in-line operator notation will be available for matrices, extended precision arithmetic, inter- val arithmetic and so on.

5. Programmer-Defined Data Types

Fortran 8x permits the construction of derived data types whose values have components that are of intrinsic type or of another derived type. Func- tions may be used to define operations on such types of data and subroutines may be used to define assignments between them. The operators may be intrinsic (for example +, *, or .EQ.) in which case the existing priorities are used for the new operators, or nonintrinsic (for example .MERGE.), in which case the priority is top level for unary operators and bottom level for binary operators.

An example of a type useful for sparse matrices is

TYPE NONZERO REAL VALUE INTEGER/ROW, COLUMN

END TYPE

which allows a matrix nonzero and its row and column numbers to be treated together. A sparse matrix with up to 100 nonzeros may be held in an array declared as:

TYPE (NONZERO): :A(100)

The symbol % is used for components of data of derived type. For example, A(10)%VALUE would be the value of the nonzero stored in A(10). A value may be constructed as a list of component values. For example, A(10) might be set by the statement:

A(10) = NONZERO (6.0, 10, 7)

Derived data types may have parameters. For example,

TYPE MATRIX (M, N)

6. Module Data and Procedure Definitions

Modules are collections of data, type defini- tions, and procedure definitions. For example,

MODULE JKR TYPE MATRIX (M, N)

REAL R(M, N)

END TYPE

TYPE (MATRIX (10, 10))::g, B, C

FUNCTION ADD (A, B) OPERATOR ( + )

TYPE (MATRIX (*, *))g, B, ADD

ADD = A%R + B%R END FUNCTION

END MODULE

is a module containing the definition of the type MATRIX, three matrices (A, B, and C) and the definitions of matrix operations. Entities may be declared PRIVATE, in which case they are availa- ble within the module but not outside it.

A simple USE statement such as:

USE JKR provides access to all the public entities in the module. Another form of the USE statement al- lows for renaming or for accessing only some of the public entities.

Modules provide a safe replacement for COM- MON. Note that the definitions are given only once. It is more general than COMMON in that type and procedure definitions may also be in- cluded.

The "include" facility is available by placing a set of COMMON block definitions in a module and accessing it with a USE statement.

Page 5: Fortran 8x, the draft Fortran standard revision

J. Adams, J. Reid / Draft Fortran Standard Revision 339

7. Procedure Enhancements

A procedure may be called recursively provided its leading statement includes the qualifier RE- CURSIVE. It may be internal, at one level only, to a program unit or to a subprogram in a module. Keyword calls, as in the inpu t /ou tpu t statements of Fortran 77, are available. D u m m y argument names serve as keywords. Arguments may be omitted if declared as OPTIONAL. An intrinsic inquiry, function may be used to determine if an argument is present or not. Several procedures may have the same name (overloading) provided they may be distinguished by the types or ranks of their arguments.

Interface blocks that contain statements like the leading statements of a procedure may be used to specify the interface to an external procedure. For example, this permits keyword calls to be made to a procedure written in assembly language. If a procedure is internal, is accessed from a module, or has an interface block, it is said to have an "explicit" interface. An explicit interface is required for calls to an array-valued function, to use keywords in a call, and for other special uses. In these cases, the interface information is needed so that the operating system can set up linkages before run-time.

8. Generalized Precision

REAL and COMPLEX declarations may be parameterized to indicate the desired precision and exponent range. For example,

REAL (10, 99)

takes the shortest machine representation that gives the equivalent of at least 10 significant deci- mals and a range of at least 10 +99 or 10 -99.

There are many inquiry and manipulation in- trinsic functions that return information on the representation or that manipulate parts of data (for example, to extract the fractional part).

In an expression such as A + B, the precision of the result is the greater of the precisions of A and B and the exponent range is the greater of the exponent ranges. For a general expression, the precision and exponent range may be deduced from its expansion into a sequence of binary oper- ations and the rule for each binary operation.

In a procedure call, the declared precisions and exponent ranges of the dummy and actual argu- ments must match. A dummy argument may be declared as REAL (*, *) or COMPLEX (*, *) and such an argument automatically matches the corresponding actual argument provided all such actual arguments in a given call have the same precision and exponent range. In effect, one ver- sion of the source therefore serves for all possible precisions.

9. Other Additional Features

N A M E L I S T . NAMELIST has been a de facto standard in the industry for some years, and, by popular demand, has been provided in Fortran 8x. A name-directed facility that was developed by the committee has been abandoned.

Source Form. Names may contain up to 31 characters including the Fortran character set has been expanded to include:

v " % & ; ( ) ? [ ] a n d -

As an alternative to the Fortran 77 form, there is a free source form that attaches no particular significance to columns, allows end-of-line com- ments (using ! as a separator), allows several state- ments on a line (using ; as a separator), and uses a terminating & to indicate continuation to the next line. Lines may have a length up to 132 characters and statements up to 2640. Either the old source form or the new source form may be selected.

Relational Operators. The relational operators .LT., .GT., .LE., .GE., .EQ., and .NE. have alter- native spellings ( , ) , ( = , ) , , and () .

Control Structures. There is a CASE construct and a form of the DO loop that does not use labels.

Intrinsic Subroutines. There are intrinsic sub- routines to provide the date and time as up to 9 integers, to provide information on the real-time clock, and to provide random numbers.

Intrinsic Functions. There are many new intrin- sic functions. All the Fortran 77 intrinsics are elemental, that is, they may be called for array arguments and are then applied to every element.

Data Statement. There is a new form for the D A T A statement that associates data values more obviously with data objects, for example

DATA (I = 1, S = 7.9, (A(K) , K = 1, 7, 2)

= [411.2]])

Page 6: Fortran 8x, the draft Fortran standard revision

340 J. Adams, J. Reid / Draft Fortran Standard Revision

10. Features Studied but not Included

Fortran 8x does not include a pointer facility, although this feature has been requested. The committee is not unanimous about the exact form it should take and therefore it has not been in- cluded.

Fortran 8x does not include a BIT data type. Work was concluded on a facility much like type LOGICAL, but it was not included because of the size of the language.

There are no facilities for multiprocessing, since it was felt that more experience in the industry is needed before it is standardized. Note, however, that in Fortran 77 the result of a function must not depend on the order in which its arguments are evaluated. Therefore functional programming may be performed in Fortran 77 and could be implemented with parallel execution of argument evaluations. An example would be to break a summation into two parts thus:

SUM1 (SUM2(A, N / 2 ) ,

SUM3 (A(N/2 + 1), N-N/E))

In the interest of reducing the size of the lan-

guage, the committee also removed condition han- dling, deleted a number of intrinsic functions, removed the passing of an internal procedure as an actual argument and the nesting of internal procedures, deleted vector-valued subscripts and variant structures. Significant blanks and insignifi- cant underscores were removed. The FOR ALL statement was deleted and the IDENTIFY state- ment was simplified.

All the features that the committee prepared and that were deleted because of the size of the language are described in an Appendix to the draft revision.

11. Abbreviated Statement List

The statement list printed in Table 2 is not definitive. The syntax is described in the draft revision in Backus-Naur form (bnf), with various constraints and restrictions listed. The list sup- plied here is just a summary of the language statements. It is intended to present a "quick look" at the syntax and is not a substitute for the bnf in any sense.

Table 2 Abbreviated List of Fortran Statements and Lines

Assignment variable = expr

where variable may be an array or a subobject IF (scalar-logical-expr) action-stmt WHERE (array-logical-expr) array-variable = expr

Data Type and Specification type [[,attribute]... ::] object-list

where type is INTEGER, REAL [(precision)], COMPLEX [(precision)], DOUBLE PRECISION, LOGICAL, CHARACTER [length selector], or TYPE (type-name [(type-param-list)])

attribute is PARAMETER, DATA, PUBLIC, PRIVATE, ALIAS, ALLOCATABLE, SAVE, ARRAY (array-spec), INTENT (intent-spec), OPTIONAL, RANGE [/range-list-name/]

[access] TYPE derived-type-name [(type-parameter-list)] where access is PUBLIC or PRIVATE

END TYPE [type-name] IMPLICIT NONE IMPLICIT implicit-list EXPONENT LETTER [(precision)] letter

Other Data Specification Statements DIMENSION array-bounds-list COMMON [/[block name]/] common-list [[,]/[block name]/common-list]... EQUIVALENCE equivalence-list DATA data-stmt-object-list/value-list/[[,]data-stmt-obj ect-list/value-list/]... DATA (value-definition-fist) PARAMETER (named-constant-definition-list) RANGE [/range-list-name/] array-name-list NAMELIST [/namelist-group-name/] namelist-object-list [[,]/namelist-group-name/namelist-object-list]...

Page 7: Fortran 8x, the draft Fortran standard revision

J. Adams, J. Reid / Draft Fortran Standard Revision 341

Table 2 (continued)

Dynamic Storage Allocation, Ranging, and Aliasing ALLOCATE (array-allocation-list [,STAT = stat-variable]) DEALLOCATE (array-name-list [,STAT = stat-variable]) SET RANGE ([range]) array-name-list SET RANGE ([range])/range-list-name/ IDENTIFY (alias-name = subobject) IDENTIFY (alias-element = parent-element, alias-range)

Control Constructs [do-name:] DO [label][,] do-variable = expr, expr[, expr] [do-name:] DO [iabel][(expr) TIMES] CYCLE [do-name] EXIT [do-name] CONTINUE END DO [do-name] [if-name:] IF (scalar-logical-expr) THEN ELSE [IF (scalar-logical-expr) THEN][if-name] END IF [if-name] [select-name:] SELECT CASE (scalar-expr) CASE (value-range-list)[select-name] CASE DEFAULT [select-name] END SELECT [select-name] GO TO label GO TO (label-list)[,] scalar-integer-expr STOP [access code] WHERE (array-logicai-expr) ELSEWHERE END WHERE

Statement Function function-name ([dummy-argument-list]) = scalar-expr

Program Units and Subprograms [PROGRAM program-name] MODULE module-name USE module-name [,rename-list] USE module-name, ONLY: [only-list] PRIVATE [[: :] use-name-list] PUBLIC [[: :] use-name-list] BLOCK DATA [block-data-name] EXTERNAL external-name-list INTRINSIC intrinsic-procedure-name-list CALL subroutine-name [([actual-argument-list])] [RECURSIVE] SUBROUTINE subroutine-name [([dummy-argument-list])][ASSIGNMENT] [prefix] FUNCTION function-name ([dummy-argument-list])[suffix]

where prefix is type [RECURSIVE] or [RECURSIVE] type suffix is [RESULT (result-name)][OPERATOR (defined-operator)]

or [OPERATOR (defined-operator)][RESULT (result-name)] Statements Related to Program Units and Subprograms

INTFNT (intent-spec)[: :] dummy-argument-list OPTIONAL [::] dummy-argument-list SAVE [[::] object-list] CONTAINS RETURN ENTRY entry-name [([dummy-argument-list])] INTERFACE END INTERFACE END [unit [unit-name]]

where unit may be PROGRAM, MODULE, SUBROUTINE, FUNCTION, BLOCK DATA

Page 8: Fortran 8x, the draft Fortran standard revision

342

Table 2 (continued)

J. Adams, J. Reid / Draft Fortran Standard Revision

Input/Output Statements READ (control-list)[input-list] WRITE (control-list)[output-list] READ format [,input-list] PRINT format [,output-list] REWIND external-unit or REWIND (position-list) ENDFILE external-unit or ENDFILE (position-list) BACKSPACE external-unit or BACKSPACE (position-list) OPEN (connect-list) CLOSE (close-list) INQUIRE (inquire-list)[output-list] FORMAT ([format-spec])

Note that obsolescent features (PAUSE, ASSIGN, ASSIGNED GO TO, arithmetic IF, alternate RETURN) have not been included in this list.