Fortran - Location Functions


Advertisements

The following table describes the location functions:

Function Description
maxloc(array, mask) It returns the position of the greatest element in the array array, if mask is included only for those which fulfil the conditions in mask, position is returned and the result is an integer vector.
minloc(array, mask) It returns the position of the smallest element in the array array, if mask is included only for those which fulfil the conditions in mask, position is returned and the result is an integer vector.

Example

The following example demonstrates the concept:

program arrayLocation
implicit none

   real, dimension(1:6) :: a = (/ 21.0, 12.0,33.0, 24.0, 15.0, 16.0 /)
   Print *, maxloc(a)
   Print *, minloc(a)
   
end program arrayLocation   

When the above code is compiled and executed, it produces the following result:

3
2
fortran_arrays.htm
Advertisements