The general form of a subscript-triplet specifier is::
[bound1
]:[
bound2
][:
stride
]
The section starts at bound1
and ends at or before
bound2
.
stride
is the increment by which the locations are selected.
bound1
,
bound2
and
stride
must all be scalar integer
expressions. Thus
A(m:m) = 0 ! m to m 1 elt array A(m:n:k) = 0 ! m to n step k A(8:3:-1) = 0 ! 8 to 3 backwards A(8:3) = 2 ! step 1 => Zero size A(M::4) = 1 ! default UPB, step 4 A(::2) = 1.0 ! default LWB and UPB A(m**2:n*k/3) = 1.0are all valid.
If the upper bound ( bound2
) is not a combination of the lower
bound plus multiples of the stride then the actual upper bound is
different to that stated; this is the same principle that is applied to
DO-loops.
Another similarity with the DO-loops is that
when the stride is not specified it is assumed to have a value
of 1. In the above example, this means that A(3:8)
is the
same as A(3:8:1)
but A(8:3)
is a
zero sized section and A(8:3:-1)
is a section that runs
backwards. Zero strides are not allowed.
Other bound specifiers can be absent too, if bound1
or
bound2
is absent then the lower or upper bound of the dimension (as
declared) is implied, if both are missing then the whole dimension is
assumed.
Let us examine the above sections in detail,
A(m:m) = 0
This is a one element array and is distrinct from A(m) which is a scalar reference.
A(m:n:k) = 0
The section runs from m to n in strides of k.
A(8:3:-1) = 0
This section runs from 8 to 3 in steps of -1.
A(8:3) = 2
This section runs from 8 to 3 in steps of 1, ie, this is a zero sized section.
A(M::4) = 1
This section runs from M to the declared upper bound in steps of 4.
A(::2) = 1.0
This section runs from the declared lower bound to the upper bound in strides of 2.
A(m**2:n*k/3:2*k) = 1.0
Here the expressions are evaluated in an unspecified order, if any of the expressions included function calls then it must be ensured that the order of evaluation of the calls is unimportant (see later).