9.3.161 UBOUND (ARRAY [, DIM] [, KIND])

Description:  Returns the upper bounds for all dimensions of an array, or the upper bound for a specified dimension. 
Class:  Inquiry function; Generic 
Arguments:  ARRAY Must be an array (of any data type). It must not be an allocatable array that is not allocated, or a disassociated pointer. It can be an assumed-size array if DIM is present with a value less than the rank of ARRAY. 
  DIM (opt) Must be a scalar integer with a value in the range 1 to n, where n is the rank of ARRAY.  
  KIND (opt) Must be a scalar integer initialization expression.  
Results:  The result is of type integer. If KIND is present, the kind parameter of the result is that specified by KIND; otherwise, the kind parameter of the result is that of default integer. If the processor cannot represent the result value in the kind of the result, the result is undefined.

If DIM is present, the result is a scalar. Otherwise, the result is a rank-one array with one element for each dimension of ARRAY. Each element in the result corresponds to a dimension of ARRAY.

If ARRAY is an array section or an array expression that is not a whole array or array structure component, UBOUND (ARRAY, DIM) has a value equal to the number of elements in the given dimension.

If ARRAY is a whole array or array structure component, UBOUND (ARRAY, DIM) has a value equal to the upper bound for subscript DIM of ARRAY (if DIM is nonzero). If DIM has size zero, the corresponding element of the result has the value zero.

The setting of compiler options that specify integer size can affect the result of this function. 

Examples

Consider the following:

REAL ARRAY_A (1:3, 5:8)
REAL ARRAY_B (2:8, -3:20)

UBOUND (ARRAY_A) is (3, 8). UBOUND (ARRAY_A, DIM=2) is 8.

UBOUND (ARRAY_B) is (8, 20). UBOUND (ARRAY_B (5:8, :)) is (4,24) because the number of elements is significant for array section arguments.


Previous Page Next Page Table of Contents