HP Fortran Programmer's Reference (September 2007)

Arrays
Array sections
Chapter 3 69
Section-subscript-list
must specify
section-subscript
for each dimension of the parent
array. The rank of the array section is the number of
subscript-triplets
and
vector
-subscripts
that appear in the s
ection-subscript-list
. Because an array section is also
an array, at least one
subscript-triplet
or
vector-subscript
must be specified.
The following sections provide more information about subscript-triplet and vector-subscript.
Subscript triplet
A subscript triplet selects elements from the parent array to form another array. It specifies
a lower bound, an upper bound, and a stride for any dimension of the parent array. Elements
are selected in a regular manner from a dimension. The stride can, for example, select every
second element.
All three components of a subscript triplet are optional. If a bound is omitted, it is taken from
the parent array. However, an upper bound must be specified if a subscript triplet is used in
the last dimension of an assumed-sized array.
A bound in a subscript triplet need not be within the declared bounds for that dimension of
the parent array if all the elements selected are within its declared bounds. If the stride is
omitted, the default is to increment by one.
The stride must not be zero. If it is positive, the subscripts range from the lower bound up to
and including the upper bound, in steps of stride. When the difference between the upper
bound and lower bound is not a multiple of the stride, the last subscript value selected by the
subscript triplet is the largest integer value that is not greater than the upper bound. The
array expression a(1: 9: 3) selects subscripts 1, 4, and 7 from a.
Strides may also be negative. A negative stride selects elements from the parent array
starting at the lower bound and proceeds backwards through the parent array in steps of the
stride down the last value that is greater than the upper bound. For example, the expression
a(9:1:- 3) selects the subscripts 9, 6, and 3 in that order from a.
If the section bounds are such that no elements are selected in a dimension (for example, the
section a(2:1)), the section has zero-size.
The following example shows subscript triplet notation assigning the same value to a regular
pattern of array elements.
INTEGER, DIMENSION(3,6) :: x,y,z ! declare 3 3x6 arrays
! initialize the arrays, using whole-array assignments.
x = 0; y = 0; z = 0
! assign to elements of x, y, and z, using subscript triplets
x(3,2:4:1) = 1
y(2,2:6:2) = 2
z(1:2,3:6) = 3