! 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 7.3. Linear search.
  program H03
    use H03M
    implicit none
    integer :: I, EoF, Location
    character(len = NAME_LENGTH), dimension(ARRAY_SIZE) :: Data
    character(len = NAME_LENGTH) :: Search_Key
    character(len = 9) :: Exit_Code
! start program H03
    open (unit = 1, file = "words.txt", status = "old", action = "read", position = "rewind")
    do I = 1, ARRAY_SIZE - 1
      read (unit = 1, fmt = *, iostat = EoF) Data(I)
      if (EoF < 0) then
        exit
      end if
    end do
    call Fill( Data(: I - 1) )
    read (unit = *, fmt = *) Search_Key
    call Search( Search_Key, Exit_Code, Location )
    select case (Exit_Code)
    case ("FOUND    ")
      call Update( Search_Key, Location )
    case ("NOT FOUND")
      call Insert( Search_Key, Location )
    end select
    call Print_It ( )
    stop
  end program H03
