HP Fortran Programmer's Reference (September 2007)

Arrays
Array sections
Chapter 370
! The arrays x, y, and z now have the following values:
! x y z
! 0 0 0 0 0 0 0 0 0 0 0 0 0 0 3 3 3 3
! 0 0 0 0 0 0 0 2 0 2 0 2 0 0 3 3 3 3
! 0 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0
In the following example of an array substring, the variable dates(5:10) is an array section
that includes elements 5 through to 10 of the parent array dates, and the variable
dates(5:10)(8:11) is also an array section of the array dates but only contains the last 4
character positions of the elements 5 through to 10.
CHARACTER(11) :: dates(20)
dates(5:10)(8:11) = ”1776”
Vector subscripts
A vector subscript is any expression that results in a rank-one array with integer value.
The values of the array select the corresponding elements of the parent array for a given
dimension. Vector subscripts can describe an irregular pattern and may be useful for indirect
array addressing. For example, if v represents a rank-one integer array initialized with the
values 4, 3, 1, 7, then the array section a(v) is a rank-one array composed of the array
elements a(4), a(3), a(1), and a(7)—in that order.
Vector subscripts are commonly specified using array constructors, which are described in the
next section. For example, the expressions a(v) and a((/ 4, 3, 1, 7/)) reference the same
section of the array a.
Vector subscripts may not appear:
On the right hand side of a pointer assignment statement.
In an I/O statement as an internal file.
As an actual argument that is associated with a dummy argument declared with
INTENT(OUT) or INTENT(INOUT) or with no INTENT.
A vector subscript may specify the same element more than once. When a vector subscript of
this form specifies an array section, the array section is known as a
many-one array
section
. An example of a
many-one array section
is:
a( (/ 4, 3, 4, 7/) )
where element 4 has been selected twice. A many-one array section may not appear in either
an input list or on the left-hand side of an assignment statement.
The following example, vector_sub.f90, illustrates an array section using a section subscript
list.