Fortran – Location Functions

Fortran location functionss

In this guide, we will discuss Fortran Location Functions. The following table describes the location functions:

FunctionDescription
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

Next Topic : Click Here

This Post Has 2 Comments

Leave a Reply