Subscript Triplets

A subscript triplet is a set of three values representing the lower bound of the array section, the upper bound of the array section, and the increment (stride) between them. It takes the following form:

[first-bound] : [last-bound] [:stride]

first-bound
Is a scalar integer (or other numeric) expression representing the first value in the subscript sequence. If omitted, the declared lower bound of the dimension is used.

last-bound
Is a scalar integer (or other numeric) expression representing the last value in the subscript sequence. If omitted, the declared upper bound of the dimension is used.

When indicating sections of an assumed-size array, this subscript must be specified.

stride
Is a scalar integer (or other numeric) expression representing the increment between successive subscripts in the sequence. It must have a nonzero value. If it is omitted, it is assumed to be 1.

The stride has the following effects:

If a range specified by the stride is empty, the array section has a size of zero.

A subscript in a subscript triplet need not be within the declared bounds for that dimension if all values used to select the array elements are within the declared bounds. For example, if an array has been declared as A(15), the array section specified as A(4:16:10) is valid. The section is a rank-one array with shape (2) and size 2. It consists of elements A(4) and A(14).

If the subscript triplet does not specify bounds or stride, but only a colon (:), the entire declared range for the dimension is used.

If you leave out all subscripts, the section defaults to the entire extent in that dimension. For example:

 REAL A(10)
 A(1:5:2) = 3.0   ! Sets elements A(1), A(3), A(5) to 3.0
 A(:5:2) = 3.0    ! Same as the previous statement
                  !   because the lower bound defaults to 1
 A(2::3) = 3.0    ! Sets elements A(2), A(5), A(8) to 3.0
                  ! The upper bound defaults to 10
 A(7:9) = 3.0     ! Sets elements A(7), A(8), A(9) to 3.0
                  ! The stride defaults to 1
 A(:) = 3.0       ! Same as A = 3.0; sets all elements of
                  !   A to 3.0

For More Information: