## Ubound

### Function Type

Ubound is an inquiry function that will operate on arrays of any type.

### Function Purpose

Ubound will return the upper bounds for the dimensions of an array. This means that it
will give you the largest element contained inside the array. Please take note that you
can not use this function on a disassociated pointer or on an array that was declared
allocatable but has not yet had its dimensions allocated.

### Required Arguments

Ubound (**array**)

**Array**, is the array that you want to find out what are the largest elements contained
inside of it. Remember that the array can be of any variable type.

### Optional Arguments

ubound (array, **dim **)

Dim is included if you want to find out the largest index permissible for a specific
dimension of the array. Note, if dim is not included and array is multidimensional, the
compiler will return a one dimensional INTEGER array whose elements will contain the
upper bound of each dimension of the array.

### Results

The function either returns an INTEGER array with dimension equal to the rank of
**array, **or, if **dim** is specified, returns a scalar INTEGER value. To show you what it
does, suppose we define the array utest as having these dimensions.

Integer utest(1:14,-5:2,-56:-8)

If you later need to work with the value of the largest permitted index for one or more
dimension, you can either obtain the upper bound on each dimension separately or all at
once. To do it separately, the following code would be required.

D1 = ubound(utest,dim=1)
D2 = ubound(utest,dim=2)
D3 = ubound(utest,dim=3)

The results of these operations will associate the values of 14,2 and -8 with the
INTEGER variables D1, D2 ,and D3 respectivily. Now, to find out the values for each
dimension all at once you will need a one dimensional INTEGER array with three
elements and the following bit of code.

results = ubound(utest)

The first element of results will contain 14, the second 2 and the third -8 in this example.

### For additional examples and information see

lecture thirty six

example: pointers.f

## Up** one level / Home**

**
**

Written by Jason Wehr : jcw142@psu.edu and Maintained by John Mahaffy :
jhm@cac.psu.edu