search_file Subroutine

subroutine search_file(filename, text, found, rc)

Arguments

Type IntentOptional Attributes Name
character(len=*), intent(in) :: filename
character(len=*), intent(in) :: text
logical, intent(out) :: found
integer, intent(out) :: rc

Source Code

  subroutine search_file (filename, text, found, rc)
    character(*), intent(in)  :: filename
    character(*), intent(in)  :: text
    logical,      intent(out) :: found
    integer,      intent(out) :: rc

    character(ESMF_MAXSTR)    :: record
    integer :: ioerr
    integer :: unitno

    rc    = ESMF_FAILURE
    found = .false.

    call ESMF_UtilIOUnitGet (unitno)
    open (unit=unitno, file=filename, status='old',  &
        action='read', position='rewind', iostat=ioerr)
    if (ioerr /= 0) then
      print *, 'Could not open file: ', trim (filename), ', iostat =', ioerr
      return
    end if

    do
      read (unitno, '(a)', iostat=ioerr) record
      if (ioerr /= 0) exit
      found = index (record, text) > 0
      if (found) exit
    end do

    close (unitno)

    rc = ESMF_SUCCESS

  end subroutine search_file