Maxval

Function Type:

The function maxval operates on arrays of either type INTEGER or REAL.

Function Purpose:

This function will return the maximum value contained within the specified array.

Required Arguments:

maxval ( array )

Array can be of any rank or size. It can also be an integer or a real array.

Optional Arguments:

maxval ( array, dim=, mask= )

Dim=

If this is omitted then the function returns the maximum value contained in the entire array. However, with this included, it will force the computer to search out the array of maximum values contained within along the specified dimension. For example, if we are dealing with an array of rank two and DIM=1 is specified, then the function will return the maximum values that appear in each column. Where as if DIM=2 was used then the function will return the maximum values that appear in each row.

Mask =

The mask= argument allows one to place restrictions on the search. For instance,
		result = maxval(a, mask=a.lt.59)
will limit the search for the maximum value to those elements in a that are less than 59.

Results:

The array numbers is defined with the following values:
		numbers =       1  7 -6 -9
				5 -8  7 10
				2 -1  4 33
To find the maximum value in all of array numbers do the following:
		results = maxval(numbers)
Naturally, results will contain the value 33. Now, to find the maximum values in each column the following line of code should be written:
		results = maxval (numbers, dim=1)
This time results will be an array of rank one with the values of ( 5, 7, 7, 33) stored in it. If you wanted to search through the rows only the following line of Fortran should be written:
		results = maxval(numbers, dim=2)
After this search, results will be an array of rank one with the values ( 7, 10, 33 ) stored inside of it. Finally, if you wanted to limit the search to where numbers is less than five, you could type the following:
		results = maxval(numbers, mask = numbers.lt.5 )
In this final example, results will be a scalar with the value of four stored in it. Also, please take note that the mask argument and the dim argument can be used together.

For additional information and examples see:

Lectures nineteen and thirty six

Examples: dimtest.f

Up one level / Home


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