Function Type:

Maxloc is an array intrinsic function.

Function Purpose:

The Maxloc function searches an array for the location of the largest value contained within it. It will then return that location to an array of rank one. Please note that if there are more than one element in the array that contain the maximum value, then the function will return the location of the element in which it first discovered the maximum value.

Required Arguments:

maxloc (array)

Array can be of any rank. This will be the array through which the computer will search.

Optional Arguments:

maxloc ( array, mask )

Mask =
This argument is used when some restriction is required on the search for the location of the maximum value. By specifying some logical expression after the equals sign, the search can be limited. For example:
		res = maxloc( a, mask = a.le.3.0e3)
will return the location of the maximum value in the array "a" where the elements are less than or equal to three thousand. While in this example:
		res = maxloc ( a, mask =
The computer will only search location in a where the corresponding location in the array "c" is greater than -89.2. The array "c" must have the same shape as the array "a".


For the following examples three arrays will be required. The first array that will be needed is a one dimensional array called result to store the location of the maximum value. The last to arrays will be defined the arrays with the following values:
		numbers = 5  7 -9  8		big = -2 -3  7 -5
		          9  9  5 -6		       4  8 11 -2
		          1  2 -4 -1 		       1 11 -4  5
Obviously both of these arrays are of dimension 3 by 4. The first search to be preformed will be a straight search on the array numbers.
		Result = maxloc(numbers)
The values that will be stored in result are two and one, which indicate that the maximum value in array numbers is at location 2,1. Note that the maximum value of nine appears twice in numbers. Instead of returning two locations, the computer will only return the location where it first found the value of nine. Since the computer searches by first along the rows then through columns, 2,1 is stored in the result and not 2,2.

Also, remember that searches can be conducted with the mask argument. For example,
		result = maxloc( numbers, mask = )
Will store the location 1,4 in result. This is because the search was limited to those elements in "numbers" for which the elements in array "big" were less than zero.

For additional information and examples see:

Lecture nineteen

Examples: sort1.f

Up one level / Home

Written by Jason Wehr : and Maintained by John Mahaffy :