Chapter 19
Essentials of Essentials of Fortran-90/95/2003
Miscellaneous
[Return to Math 60 Homepage |
Return to Brief Contents Page]
[Return to Full Contents Page]
Contents
The Fortran-90 standard (i.e., language definition)
introduced the concept of obsolescence and some authors
also speak about deprecation.
These terms apply to those features that may,
in fact, be removed from future revisions of Fortran (i.e., no
longer included in future "standards") or have been rendered
unnecessary. Most of these
statements are no longer needed because of the introduction of
newer, more versatile statements and structures, and therefore should be
avoided as much as possible to conform to good programming
practices. Fortran-95 and Fortran-2003 continue
to list certain statements as obsolescent.
Note that compilers will continue
to support obsolescent statements and features,
and some new compilers may even continue to support features
that have been recently removed. Future compilers, however,
will not be required to support features once designated
as obsolescent and then subsequently removed from the
official definition of Fortran.
Fortran-90 "obsolescent" statements and features
include the following:
- the arithmetic IF statement;
- the PAUSE statment (which can be
simulated by a READ awaiting input);
- real variables as DO loop control variables;
- ending several DO loops with the same statement;
- ending a DO loop with a statement other than a
CONTINUE or END DO;
- statements that require statement number
variables, such as ASSIGN or assigned GO TO;
- the use of an assigned integer as a FORMAT specification;
- H (Hollerith) character string field descriptors
in FORMAT statements;
- branching to an END IF;
- alternative RETURN in subprograms.
Of these features, the following have been removed from Fortran-95
and, thus, may not be supported by Fortran-95 compilers:
- H (Hollerith) character string field descriptors
in FORMAT statements;
- real variables as DO loop control variables;
- branching to an END IF from outside the IF block;
- the PAUSE statment;
- statements that require statement number
variables, such as ASSIGN or assigned GO TO;
- the use of an assigned integer as a FORMAT specification;
Newly declared "obsolescent" statements and features for
Fortran-95 include the following:
- Computed GO TO;
- statement functions;
- DATA statements after the first executable statement;
- Fixed-form source code;
- assumed-size arrays (arrays declared in subprograms with
the upper bound in the last dimension an *).
- CHARACTER*n style declarations
- Assumed-length character functions.
The following has been removed from Fortran-2003 and, thus,
may not be supported by Fortran-2003 compilers:
- carriage control in output Format statements.
The following are mentioned as "deprecated" (or "redundant")
features by certain authors. This designation has no offical status
in Fortran standards but are suggestive of features that
may, in fact, be eventually listed as "obsolescent." They
should also be avoided in new Fortran code, since they can be replicated by
newer features which can lead to code that is more
easily understandable. Since many of these features are
very common in older code that is still widely used, the
features will probably continue to be supported in the near
future.
- COMMON blocks;
- BLOCK DATA subprograms;
- EQUIVALENCE statements;
- Alternative ENTRY into subroutines;
- Implicit data typing of identifiers;
- The DO WHILE form of the DO loop;
- DOUBLE PRECISION real declarations;
- Independent DIMENSION and PARAMETER statements;
The major new features of Fortran-95 (not present in Fortran-90)
include the following:
- the FORALL statement (cf.
section 6.11.3);
- a FORALL statement can include a WHERE
statement;
- the ELSEWHERE clause can include a mask
and may be repeated (cf. section 8.12);
- designation of user-defined subprograms as PURE -- A function
with no side effects can be designated as PURE and a
subroutine that only affect the values of arguments with INTENT
IN OUT or OUT can also be so designated. The
advantage of knowing that a subprogram is "pure" is that this
simplifies parallel execution.
- designation of user-defined subprograms as ELEMENTAL -- A function
with only scalar dummy arguments (not pointers or subprograms)
and (if a function) with scalar result (not pointer) can be
designated as ELEMENTAL and similarly for a subroutine.
Such a function is applied independently to elements of an
arrays, e.g., as in SQRT(A) where A is an array.
Once again, the advantage of knowing that a subprogram is "elemental"
is that this simplifies parallel execution.
- A function NULL to nullify a pointer which may also
be done at initialization
(cf. section 17.4);
- Initialization of components of a derived type (cf.
section 15.2);
- Revised definitions and extensions to functions MINLOC,
MAXLOC, CEILING, and FLOOR;
- A new intrinsic subroutine CPU_TIME(TIME) which
takes a scalar real variable TIME and returns the
present processor time in seconds;
- A new intrinsic function SIGN to distinguish
between positive and negative zero if the processor supports
this distinctions;
- Automatic deallocation of allocatable arrays when exiting the
program segment in which it was declared.
Some authors have stated that Fortran-2003 is a major revision,
as was Fortran-90 (unlike Fortran-95). On the other hand, many
of the additions deal with advanced features or features that would
seldom be used by beginning Fortran programmers.
We briefly deal with five significant new additions to Fortran
introduced with the Fortran-2003 standard:
Allocatable Components of Derived Types,
"Class" Variables,
Function Pointers,
C Interoperability,
and Command Line Arguments.
The Fortran 2003 specifies that components of derived types may have
an allocatable attribute. For example,
TYPE STACK
INTEGER :: TOP
INTEGER, ALLOCATABLE :: INFO(:)
END TYPE STACK
A variable of this type (e.g., if A were declared to be of
type STACK would first be declared and then the INFO
component would be allocated by a statement such as
ALLOCATE(A%INFO(M))
where M had been assigned a value before this statement.
The keyword CLASS may be used in place of TYPE when
declaring polymorphic variables of a derived type, i.e., variables whose
data type may, in fact, vary at run time.
For example,
TYPE POINT
REAL :: X, Y
END TYPE POINT
CLASS(POINT), POINTER :: P
Variable P is declared to be of user declared type POINT
and any of its extensions (cf. section 19.3.6 below).
One may now declare identifiers as pointers to functions and
subroutines. (This may be done in several different ways.)
If, for example, FUNCPT has been declared as a pointer
to a function, then it can be used in a pointer assignment
statement, such as
FUNCPT => COS
Fortran-2003 provides a standardized mechanism for interoperation with
the programming language C. Lists are available which indicate the
Fortran data type and the corresponding C data type,
A program must make use of an intrisic module named ISO_C_BINDING
containing predefined names which link Fortran "kind" values with
corresponding C data types. For example,
USE ISO_C_BINDING
INTEGER(KIND=C_INT) :: M, N, I
REAL(KIND=C_DOUBLE) :: X, Y
corresponds to declaring m, n, i to be of standard C type int
and x and y to be of standard C type double.
Arrays in the other language are usually declared with arguments
listed in reverse order.
A programmer should consult an advanced manual about other details,
such as the using Fortran procedures in C codes and invoking a C
function from Fortran code.
C (and C++) have always had the ability to compile a main program
with run-time parameters (argc and argv), which return the run-time
command line argument strings and the number of arguments. Fortran 2003
has standardized a similar feature.
Fortran-2003 has included various other features including those
that may be familiar to
programmers who have used object-oriented concepts in C++ or similar
languages. The following list give an overview of some of these
new features:
- One may define a new derived type and
then extend that type to another new derived type by including all the components
in the base (parent) type within the new type. This allows the
second derived type to "inherit" the structure of the
base type. For example, one could define
TYPE TWODIM
INTEGER :: LENGTH
INTEGER :: WIDTH
END TYPE TWODIM
and then extend it to a new type via
TYPE, EXTENDS(TWODIM) :: THREEDIM
INTEGER :: HEIGHT
END TYPE THREEDIM
The resulting type THREEDIM would have (i.e., "inherit")
all the components of type TWODIM in addition
to having its own component.
- Similar in structure to the SELECT CASE construct (cf.
section 16.1), the SELECT
TYPE construct can choose among various alternatives
depending on what the actual type of an identifier is (which
had been declared via a CLASS statement).
- Fortran-2003 also provides for a "finalization" designation of
subprograms within a module. This corresponds to a "destructor"
in a C++ class.
- Fortran-2003 has also changed some of the restriction in using
array constructors. One syntactical change is the optional use
of [ and ] in place of (/ and /).
- Some other features of Fortran-2003 include floating-point exception
handling, extending input/output facilities, introducing the possibility
of "submodules."
For other information on Fortran 2003, one should check
published manuals or visit on-line information available. Recommended
are English-language papers authored by John Reid, who is the convenor
of the the ISO Fortran Working Group, for example
High Performance Fortran or "HPF" is a superset of Fortran-90/95.
The main extension are compiler directives that begin with
!HPF$. Such statements are seen as comments by
other compilers, but are interpreted by HPF compilers to optimize
the performance of the code on parallel machines.
HPF also includes a few additional intrinsic functions pertinent
to executing code on parallel machines.
Further information about HPF should be obtained from detailed
manuals for the machine being used.
This page is maintained by Dennis C. Smolarski, S.J.
dsmolarski@math.scu.edu
© Copyright 1999-2005 Dennis C. Smolarski, S.J., All rights reserved.
Last changed: 29 June 2005.