C LAST UPDATE: 
C+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
C
C**************************
C**     LDM_ADDOUT       **
C**************************
C
C
      SUBROUTINE LDM_ADDOUT (LIN, STR, IUN, TERM)
C
      INCLUDE 'implicit_none.finc'
C
C Purpose: Add string to output buffer & output/clear/add if no room
C
C ***** 'LDM' SERVICE ROUTINE ONLY *****
C
C Author:  John W. Campbell, June 1993
C
C Arguments:
C
      CHARACTER*(*) LIN
      CHARACTER*(*) STR
      INTEGER IUN
      LOGICAL TERM

C LIN     (R/W)  Line buffer
C STR     (R)    String to be added
C IUN     (R)    Unit number for output when required
C TERM    (R)    Terminal output flag .TRUE. = terminal otherwise .FALSE.
C
C====== Parameter statements
C 

C
C====== GLOBALS:
C

C
C====== FUNCTION TYPES:
C
      INTEGER LENSTR
C
C====== LOCALS:
C
      INTEGER LLIN
      INTEGER L1
      INTEGER L2

C     INTEGER LLIN     !Length of 'LIN' buffer
C     INTEGER L1       !Current significant length of 'LIN'
C     INTEGER L2       !Significant length of 'STR'
C
C-------------------------------------------------------------------------------
C
      LLIN = LEN (LIN)
      IF (LIN.EQ.' ') THEN
         LIN = STR
         RETURN
      ELSE
         L1 = LENSTR (LIN)
         L2 = LENSTR (STR)
         IF (L1+L2+1.GT.LLIN) THEN
            IF (TERM) THEN
               CALL TTSEND (IUN,LIN(1:LENSTR(LIN)),1)
            ELSE
                WRITE(IUN,1000) LIN(1:LENSTR(LIN))
            END IF
            LIN = STR
            RETURN
         ELSE
            LIN = LIN(1:L1+1)//STR
         END IF
      END IF
      RETURN
C
C====== Format statements
C
1000  FORMAT (A)
      END
