! 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.5. (File input.) Compute square roots of input values.
  program E05
    implicit none
    integer, parameter :: N = 20
    integer :: I
    real :: X
! start program E05
    open (unit = 1, file = "e05.txt", status = "old", action = "read", position = "rewind")
    do I = 1, N
      read (unit = 1, fmt = *) X
      if (X <= 0) then
        exit
      else
        write (unit = *, fmt = *) sqrt( X )
      end if
    end do
    write (unit = *, fmt = *) " Number of valid input values: ", I - 1
    stop
  end program E05
