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(:) ! the whole array A(3:9) ! A(m) to A(n) in steps of 1 A(3:9:1) ! as above A(m:n) ! A(m) to A(n) A(m:n:k) ! A(m) to A(n) in steps of k A(8:3:-1) ! A(8) to A(3) in steps of -1 A(8:3) ! A(8) to A(3) step 1 => Zero size A(m:) ! from A(m) to default UPB A(:n) ! from default LWB to A(n) A(::2) ! from default LWB to UPB step 2 A(m:m) ! 1 element section A(m) ! scalar element - not a sectionare 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(:)
This runs from the declared lower bound to the declared upper bound so refers to the whole array.
A(3:9)
Defines the 7 element section running from A(3) to A(9). The stride is missing therefore is assumed to be 1.
A(3:9:1)
Exactly the same section as above.
A(m:n)
From element A(m) to A(n).
A(m:n:k)
The section runs from m to n in strides of k.
A(8:3:-1)
This section runs from 8 to 3 in steps of -1.
A(8:3)
This section runs from 8 to 3 in steps of 1, ie, this is a zero sized section.
A(m:)
This section runs from M to the declared upper bound in steps of 1.
A(:n)
This section runs from the declared lower bound to n in steps of 1.
A(::2)
This section runs from the declared lower bound to the upper bound in strides of 2.
A(m:m)
This is a one element array and is distinct from A(m) which is a scalar reference.
Return to corresponding overview page