C
C SUBROUTINE 'TREAD'
C ==================
C
C Read a line of text from the terminal (and write it to a log file if required)
C
      SUBROUTINE TREAD (STR, EOF)
C
C Parameters:
C
C      STR (O)   Returned character string
C      EOF (O)   Logical flag = .true. if end of file (or read error) 
C                encountered else .false.
C
C====== Specification statements
C
      CHARACTER*(*) STR
      LOGICAL EOF
      LOGICAL LOG
      COMMON /TTCOMN/ LUNR, LUNW, LUNLR, LUNLW, MODETT, LOG
      SAVE /TTCOMN/
C
C====== Get string
C
      EOF = .FALSE.
      IF (MODETT.EQ.0) THEN
         IF (LUNR.GT.0) READ (LUNR,'(A)',END=200,ERR=200) STR
      ELSE
         STR = '**Mode not implemented**'
         EOF = .TRUE.
      ENDIF
      IF (LOG.AND.LUNLR.GT.0) THEN
         LL = LEN(STR)
         DO 100 L=LL,1,-1
            IF (STR(L:L).NE.' ') GO TO 120
100      CONTINUE
         L=1
120      WRITE (LUNLR,1001) STR(1:L)
      ENDIF
      RETURN
C
C====== End of file (or error in read)
C
200   STR = '*End of file*'
      EOF = .TRUE.
      RETURN
C
C====== Format statements
C
1001  FORMAT (A)
      END
