! 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.15. (File input.) Count large and medium cats.
  program D15
    implicit none
    integer :: Hi_Count, Mid_Count
    real, parameter :: MID_BOUNDARY = 2.7, HI_BOUNDARY = 4.3
    real :: Next_Weight
! start program D15
    Hi_Count = 0
    Mid_Count = 0
    open (unit = 1, file = "db.txt", status = "old", action = "read", position = "rewind")
    read (unit = 1, fmt = *) Next_Weight
    if (Next_Weight > HI_BOUNDARY) then
      Hi_Count = Hi_Count + 1
    else if (Next_Weight > MID_BOUNDARY) then
      Mid_Count = Mid_Count + 1
    else  ! Do nothing.
    end if
    write (unit = *, fmt = *) Hi_Count, Mid_Count
    stop
  end program D15
