HP Fortran Programmer's Reference (September 2007)

Arrays
Array constructors
Chapter 3 75
Array constructors
An array constructor is used to assign values to an array. The generated values are
supplied from a list of scalar values, arrays of any rank, and implied DO specifications. An
array constructor may appear in any context in which a rank-one array expression is allowed.
An array with a rank greater than one may be constructed by using the RESHAPE intrinsic
function. The type of an array constructor is taken from the values in the list, which must all
have the same type and type parameters (including character length). The extent is taken
from the number of values specified.
The syntax of an array constructor is:
(/
ac-value-list
/)
where
ac-value-list
is a comma-separated list of one or more
ac-values
. Each
ac-value
may be any of the following:
Scalar expressions, for example:
(/ 1.2, 0.0, 2.3 /)
An array expression, for example:
(/ x(0:5) /)
where the values in x(0) through x(5) become the values of the array constructor. If the
array the value list has a rank greater than one, the values are generated in
column-major order, as explained in “Array fundamentals” on page 57.
An implied-DO specification, taking the form:
(
ac-value-list
,
do-var
=
expr1
,
expr2
[,
expr3
])
where
do-var
is the name of a scalar integer variable,
expr1
is the initial value,
expr2
is
the final value, and
expr2
is the stride (the default is 1). For example:
(/ i, i = 1, 10 )
When used to initialize an array in a type declaration or in an assignment statement, all
elements in the array must be initialized. For example, the following is illegal:
INTEGER :: i(10) = (/ 1, 2, 3 /) ! ILLEGAL: too few
! initializers
If no values are supplied, the array constructor is zero-sized. For example, the size of the
following array constructor:
(/ ( i, i=10,n) /)