next up previous
Next: Visualising Array Sections Up: Arrays Previous: Array Conformance

 

Array Sections

The general form of a subscript-triplet specifier is::

 
[ tex2html_wrap_inline21419  bound1  tex2html_wrap_inline21421 ]:[ tex2html_wrap_inline21419  bound2  tex2html_wrap_inline21421 ][: tex2html_wrap_inline21419  stride  tex2html_wrap_inline21421 ]

The section starts at tex2html_wrap_inline21419  bound1 tex2html_wrap_inline21421 and ends at or before tex2html_wrap_inline21419  bound2 tex2html_wrap_inline21421 . tex2html_wrap_inline21419  stride tex2html_wrap_inline21421 is the increment by which the locations are selected. tex2html_wrap_inline21419  bound1 tex2html_wrap_inline21421 , tex2html_wrap_inline21419  bound2 tex2html_wrap_inline21421 and tex2html_wrap_inline21419  stride tex2html_wrap_inline21421 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.0
are all valid.

If the upper bound ( tex2html_wrap_inline21419  bound2 tex2html_wrap_inline21421 ) 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 tex2html_wrap_inline21419  bound1 tex2html_wrap_inline21421 or tex2html_wrap_inline21419  bound2 tex2html_wrap_inline21421 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,


next up previous
Next: Visualising Array Sections Up: Arrays Previous: Array Conformance

Adam Marshall ©University of Liverpool, 1996
Wed Oct 9 17:57:29 BST 1996