! 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 4.4. (File input.) Average pairs of input data values.
  program E04
    implicit none
    integer :: Limit, Loop
    real :: Average, X, Y
! start program E04
    open (unit = 1, file = "e04.txt", status = "old", action = "read", position = "rewind")
    read (unit = 1, fmt = *) Limit
    do Loop = 1, Limit
      read (unit = 1, fmt = *) X, Y
      Average = (X +  Y) / 2.0
      write (unit = *, fmt = *) Loop, X, Y, Average
    end do
    stop
  end program E04
