      SUBROUTINE FINDFIL(IO,KEY,LINE,LENGTH,EXT,DATE)
      CHARACTER*(*) IO,KEY,LINE,EXT
      CHARACTER*50 ATIME
      INTEGER*4 DATE(2),TDATE(2),SDATE(2)
      EXTERNAL SS$_ABORT
10    CONTINUE
      L = INDEX(LINE,KEY)
D     TYPE 100,' KEY,LINE = ',KEY,LINE
      IF(L.EQ.0)RETURN
      K = 1
20    CONTINUE
D     TYPE 100,' LOOKING FOR FILE IN ',LINE(K:L)
100   FORMAT(10A)
      J = MAX(INDEX(LINE(K:L),' '),INDEX(LINE(K:L),','))
      J = MAX(J,INDEX(LINE(K:L),'='))
      J = MAX(J,INDEX(LINE(K:L),'+'))
D     TYPE *,' J,K,L = ',J,K,L
      IF(J.GT.0)THEN
         K = K + J
         GOTO 20
      END IF
      TDATE(1) = 0
      TDATE(2) = 0
      LL = INDEX(LINE(K:L),'!')
D     TYPE 100,' FINAL FILE = ',LINE(K:K+LL-2)
      CALL GETDATE(IO,LINE(K:K+LL-2),EXT,TDATE)
      CALL SYS$ASCTIM(,ATIME,TDATE,)
D     TYPE 100,' REVISION WAS ',ATIME
D     TYPE 101,DATE(2),DATE(1),TDATE(2),TDATE(1)
101   FORMAT(' DATE & TDATE OF 2 & 1',4Z10)
      IF(IO.EQ.'I')THEN
         IF(TDATE(1).EQ.0 .AND. TDATE(2).EQ.0)THEN
C           TYPE *,'FATAL ERROR ** Unable to find input file : '//
C    .         LINE(K:K+LL-2)//EXT
C           TYPE *,'NOTE: An extra extension in the above filename'//
C    .         ' may be ignored!'
C           CALL SYS$EXIT(SS$_ABORT)
C
C        If we can't find input file, just assume it is about
C        to be created, perhaps by an unconditional line, so give
C        it a current date.
C
            TDATE(1) = 'FFFFFFFF'X
            TDATE(2) = '7FFFFFFF'X
         END IF
         CALL SUBQUAD(TDATE,DATE,SDATE)
         IF(SDATE(2).GE.0)THEN
            DATE(1) = TDATE(1)
            DATE(2) = TDATE(2)
         END IF
      ELSE
         CALL SUBQUAD(TDATE,DATE,SDATE)
         IF(SDATE(2).LT.0)THEN
            DATE(1) = TDATE(1)
            DATE(2) = TDATE(2)
         END IF
      END IF
D     TYPE 101,DATE(2),DATE(1)
      LINE = LINE(1:L-1)//LINE(L+2:)
      LENGTH = LENGTH - 2
      GOTO 10
      END
