Intel® Fortran Compiler 18.0 Developer Guide and Reference

UBOUND

Inquiry Intrinsic Function (Generic): Returns the upper bounds for all dimensions of an array, or the upper bound for a specified dimension.

result = UBOUND (array [, dim] [, kind])

array

(Input) Must be an array; it can be assumed-rank. It may be 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

(Input; optional) Must be a scalar integer with a value in the range 1 to n, where n is the rank of array.

kind

(Input; optional) Must be a scalar integer constant expression.

Results

The result type is 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.

The following rule applies if array is not assumed-rank:

The following rules apply if array is assumed-rank:

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 specifying integer size can affect this function.

Example

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.

The following shows another example:

  REAL ar1(2:3, 4:5, -1:14), vec1(35)
  INTEGER res1(3), res2, res3(1)
  res1 = UBOUND (ar1)          ! returns [3, 5, 14]
  res2 = UBOUND (ar1, DIM= 3)  ! returns 14
  res3 = UBOUND (vec1)         ! returns [35]
  END

See Also