An array consists of a number of elements of the same type. An element is
identified by the name of the array together with one or more indexes, one for
each dimension of the array.
ar is a one dimensional array of INTEGERs with
index in the range from 0 to 9.
beta is a two dimensional array of REALs with
first index in the range from 1 to 9 and second index in the range from 1 to
A particular element of ar is represented by
ar(expr) where expr is an integer
expression. Similarly an element of the two dimensional array beta is
represented by beta(expr1,expr2).
If the lower bound for an index is 1 (unity) then it may be omitted. For
The rank of an array or scalar is the number of dimensions. A scalar has
The shape of an array or scalar is a list of integers, one for each
dimension, giving the number of elements along each dimension in turn.
ar has shape (10). beta has shape
(9,10). A scalar has shape ( ).
Individual elements can be assigned values just like simple variables:
In addition, every element of an array can be assigned a particular value:
One array can be copied, element by element, into another provided that the two
have the same shape.
Assignment is permissible if the array on the left is conformable to the
object on the right. Two objects are conformable if they have the same
shape or if one is a scalar.
Any intrinsic function that
is classed as elemental can be used in an array expression to carry out
assignment on an element by element basis:
! Values are assigned to the elements of a, b, and c
An array constructor is used to build an array from a list of values between
"(/" and "/)". For example, given a REAL array x with shape (4):
x = (/ 1.4, 0.5, 1.0, 1.5 /)
All the components must have the same type and type attributes.
The rank of an array constructor is one. An intrinsic function called
RESHAPE can be used to convert to rank greater than one.
WHERE statement and construct
Element by element array assignments (A = B) can be made conditional by using a
WHERE statement or WHERE construct. The two forms are analogous to the IF
statement and the IF construct.
The form of the WHERE statement is:
WHERE (a>0.0) a=1.0/a ! a is a known REAL array
The form of the WHERE construct is:
a=a/b ! a and b are known INTEGER arrays
The ELSEWHERE section is optional.
If the ELSEWHERE section consists of one WHERE construct, then ELSE and WHERE
can be reduced to ELSEWHERE provided that one of the associated ENDWHEREs is
Like other constructs, WHERE constructs can be named.
Optionally, the same name may be used after ELSEWHERE and after ELSEWHERE (mask_expression).
SUM(a) sums the elements an
DOT_PRODUCT(a,b) forms an inner product.
MATMUL(a,b) forms a matrix product.
MAXLOC(a) returns the location of
the largest value (also MINLOC).
MAXVAL(a) returns the largest value
The following more advanced topics are not described here:
The FORALL construct