go_last_patn Subroutine

public subroutine go_last_patn(iunps, substring, outline, rew)

Arguments

Type IntentOptional Attributes Name
integer, intent(in) :: iunps
character(len=*), intent(in) :: substring
character(len=150), intent(out) :: outline
logical, intent(in) :: rew

Source Code

  subroutine go_last_patn (iunps, substring, outline, rew)
    !---------------------------------------------------------------------
    !
    implicit none
    integer, intent(in) :: iunps
    logical, intent(in) :: rew
    character (len=*), intent(in) :: substring
    character (len=150), intent(out) :: outline   ! fixed
    character (len=150) :: line
    integer :: ios, nr, mx

    if (rew) rewind (iunps)
    ios=0
    nr=0
    do while (ios==0)
       read (iunps, '(a150)', iostat = ios, err = 300) line
       if (index(line, substring).ge.1 ) then
          nr=nr+1
          !        write (6,*) 'nr', nr
       endif
    enddo

    rewind (iunps)
    ios=0
    mx=0
    do while (ios==0)
       read (iunps, '(a150)', iostat = ios, err = 300) line
       if (index(line, substring).ge.1 ) then
          mx=mx+1
          if (mx.eq.nr) then
             outline=line
             return
          endif
       endif
    enddo
300 continue
  end subroutine go_last_patn