! 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 3.6. (File input.) Count fast and slow molecules.
  program D06
    implicit none
    integer, parameter :: LIMIT = 100
    integer :: Fast_Molecule_Count, Slow_Molecule_Count, Loop
    real :: Boundary, Velocity
! start program D06
    Fast_Molecule_Count = 0
    Slow_Molecule_Count = 0
    open (unit = 1, file = "d06.txt", status = "old", action = "read", position = "rewind")
    read (unit = 1, fmt = *) Boundary
    do Loop = 1, LIMIT
      read (unit = 1, fmt = *) Velocity
      if (Velocity > Boundary) then
        Fast_Molecule_Count = Fast_Molecule_Count + 1
      else
        Slow_Molecule_Count = Slow_Molecule_Count + 1
      end if
    end do
    write (unit = *, fmt = *) Fast_Molecule_Count, Slow_Molecule_Count
    stop
  end program D06
