Lahey/Fujitsu Fortran

# MAXLOC Function

### Description

The MAXLOC function returns the location of the first element in array having the maximum value of all the elements identified by mask.

```Syntax
MAXLOC (array [, dim] [, mask] )
```

### Required Arguments

array is an INTENT(IN) array of type INTEGER or REAL.

### Optional Arguments

dim is an INTENT(IN) scalar INTEGER in the range 1 ≤ dimn, where n is the rank of array. The corresponding actual argument must not be an optional dummy argument.

mask is an INTENT(IN) scalar or array of type LOGICAL and must be conformable with array.

### Result

The result is of type default INTEGER.

If dim is present, the result is an array of rank n-1 where n is the rank of array. The result values are the locations containing the maximum value along dimension dim.

If dim is absent, the result is an array of rank one whose size is the rank of array. Each element contains the subscript value of the first element in array to have the maximum value of all of the elements of array.

If mask is present, the elements of array for which mask is false are not considered.

```Example
integer :: i6(6) = (/-14,3,0,-2,19,1/)
integer :: i23(2,3) = reshape((/-14,3,0,-2,19,1/),shape(i23))
write(*,'(2i4)') i23         ! writes -14   3
!          0  -2
!         19   1
write(*,*) maxloc(i6)        ! writes 5
write(*,*) maxloc(i23)       ! writes 1  3
write(*,*) maxloc(i23,dim=1) ! writes 2  1  1
write(*,*) maxloc(i23,dim=2) ! writes 3  1