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

 

Array Sections

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

 
[ tex2html_wrap_inline21746  bound1  tex2html_wrap_inline21748 ]:[ tex2html_wrap_inline21746  bound2  tex2html_wrap_inline21748 ][: tex2html_wrap_inline21746  stride  tex2html_wrap_inline21748 ]

The section starts at tex2html_wrap_inline21746  bound1 tex2html_wrap_inline21748 and ends at or before tex2html_wrap_inline21746  bound2 tex2html_wrap_inline21748 . tex2html_wrap_inline21746  stride tex2html_wrap_inline21748 is the increment by which the locations are selected. tex2html_wrap_inline21746  bound1 tex2html_wrap_inline21748 , tex2html_wrap_inline21746  bound2 tex2html_wrap_inline21748 and tex2html_wrap_inline21746  stride tex2html_wrap_inline21748 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_inline21746  bound2 tex2html_wrap_inline21748 ) 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_inline21746  bound1 tex2html_wrap_inline21748 or tex2html_wrap_inline21746  bound2 tex2html_wrap_inline21748 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 contents
Next: Visualising Array Sections Up: Arrays Previous: Array Conformance

Adam Marshall ©University of Liverpool, 1996
Fri Dec 6 15:03:35 GMT 1996
Not for commercial use.