Purpose
Returns the upper bound of each
dimension in an array, or the upper bound of a specified dimension.
Argument type and attributes
- ARRAY
- The array whose upper bounds you want to determine. The bounds
of the array must be defined; that is, the corresponding actual argument
cannot be a disassociated pointer or an allocatable array that is
not allocated, and if its size is assumed, you can only examine one
dimension. If ARRAY is an assumed-size array, DIM shall
be present with a value less than the rank of ARRAY.
- DIM (optional)
- An INTEGER scalar. Its value must be in the range
1 ≤ DIM ≤ RANK(ARRAY).
The corresponding actual argument must not be an optional dummy argument. The DIM argument
cannot be present if ARRAY is an assumed-rank
object that is associated with a scalar.
- KIND (optional)
- An INTEGER scalar. The actual argument corresponding
to KIND must be a constant expression.
Result type and attributes
- The result is of type integer
- If KIND is present,
the kind type parameter is that specified by the value of KIND;
otherwise, the kind type parameter is that of the default integer
type.
- If DIM is present, the result is a scalar.
If it is not present, the result is a one-dimensional array with one
element for each dimension in ARRAY.
- If ARRAY is
an assumed-rank object that is associated with a scalar, the result
is a zero-sized array.
- If ARRAY is
an assumed-rank object that is associated with an assumed-size array,
the result of UBOUND(ARRAY, RANK(ARRAY), KIND)
equalsLBOUND(ARRAY, RANK(ARRAY), KIND)
minus two. In this context, if KIND is omitted
for UBOUND(ARRAY, RANK(ARRAY), KIND),
it is also omitted for the corresponding LBOUND(ARRAY, RANK(ARRAY), KIND).
Result value
Each element in the result
corresponds to a dimension of ARRAY.
If ARRAY is a whole array or
array structure component, these values are equal to the upper bounds.
If ARRAY is an array section
or expression that is not a whole array or array structure component,
the values represent the number of elements in each dimension, which
may be different than the declared upper bounds of the original array.
If a dimension is zero-sized, the corresponding element in the result
is zero, regardless of the value of the upper bound.
Examples
! This array illustrates the way UBOUND works with
! different ranges for dimensions.
REAL A(1:10, -4:5, 4:-5)
RES=UBOUND( A )
! The result is (/ 10, 5, 0 /).
RES=UBOUND( A(:,:,:) )
! The result is (/ 10, 10, 0 /) because the argument
! is an array section.
RES=UBOUND( A(4:10,-4:1,:) )
! The result is (/ 7, 6, 0 /), because for an array section,
! it is the number of elements in the corresponding dimensions.