C     @(#)append.f	1.1     02/19/98
C
      subroutine append (subfld,      ! passed
     2                  field,       ! modified
     2                  lfield)      ! modified

c Appends SUBFLD to FIELD using LFIELD as end of FIELD pointer

c if LFIELD equals zero
c    then will set FIELD to SUBFLD and LFIELD to LEN(SUBFLD)
c    remainder of field being filled with blanks
c else if LFIELD is positive
c    On input LFIELD is taken as the current end of FIELD data
c      and SUBFLD will be appended SUBFLD to FIELD although
c      the remainder of FIELD will be unchanged.
c    On output LFIELD will have been incremented by LEN(SUBFLD).

c see also AFFIX subroutine which does not initialise FIELD

      character*(*) subfld, field
      character*8 chival
      integer*4 lfield

      lend = lfield + len (subfld)
      if (lend .gt. len (field))
     2        call abort ('Overflows target string while adding '
     2                    //subfld)
      if (lfield .gt. 0) then
        field (lfield + 1 : lend) = subfld
      else if (lfield .eq. 0) then
        field = subfld
      else
        call abort ('Invalid end of string pointer value'
     2              //chival(lfield))
      end if
      lfield = lend
      return
      end
