! Program Example from "Essential Fortran 90 & 95" by Loren P. Meissner
! Copyright 1996. Copying for sale requires permission from the author.
! Otherwise, distribution is permitted if these three lines are included.

! Example 5.17. (File input: "f16.txt".) Location of an array element.
  program F17
    implicit none
    integer, parameter :: N = 10
    real, dimension(N, N) :: Z
    integer, dimension(2) :: ZMax, ZMin
    integer :: I
! start program F17
    open (unit = 1, file = "f16.txt", status = "old", action = "read", position = "rewind")
    do I = 1, N
      read (unit = 1, fmt = *) Z(I, :)
    end do
    ZMax = maxloc (Z)  ! Array assignment
    ZMin = minloc (Z)
    write (unit = *, fmt = *) " Location and value of Max: ", ZMax, Z(ZMax(1), ZMax(2))
    write (unit = *, fmt = *) " Location and value of Min: ", ZMin, Z(ZMin(1), ZMin(2))
    stop
  end program F17
