C
C SUBROUTINE 'TWRITE'
C ===================
C
C Output a line of text to the terminal (and log file if required)
C (trailing blanks are removed)
C
      SUBROUTINE TWRITE (STR)
C
C Parameters:
C
C      STR (I)   Character string to be output
C
C====== Specification statements
C
      CHARACTER*(*) STR
      LOGICAL LOG
      COMMON /TTCOMN/ LUNR, LUNW, LUNLR, LUNLW, MODETT, LOG
      SAVE /TTCOMN/
C
C====== Get length to o/p
C
      LL = LEN(STR)
      DO 100 L=LL,1,-1
         IF (STR(L:L).NE.' ') GO TO 120
100   CONTINUE
      L=1
C
C====== Output string
C
120   IF (MODETT.EQ.0) THEN
         IF (LUNW.GT.0) CALL TTSEND (LUNW, STR(1:L), 1)
      ENDIF
      IF (LOG.AND.LUNLW.GT.0) WRITE (LUNLW,1001) STR(1:L)
      RETURN
C
C====== Format statements
C
1001  FORMAT (A)
      END
