      subroutine flush (iunit)
      character filename*255, str*1
      logical*4 ex, nmd
      integer*4 iunit, ios
!     get the name of the external file
      inquire (unit=iunit, iostat=ios, err=905, &
              exist=ex, named=nmd, name=filename)
      if (ex .and. nmd) then
!        close unit to flush buffer
         close (unit=iunit, iostat=ios, err=905)
!        reconnect to external file
         open (unit=iunit, iostat=ios, err=905, &
     &         status='unknown', position='append', file=filename)
!        move pointer to the bottom of the file
105      continue
         read (unit=iunit, iostat=ios, err=905, &
                 fmt='(a)', end=905) str
         goto 105
      endif
905   continue
!
      if (ios.gt.0) write(*,*) ' flush: unit=',iunit,', iostat=',ios
      return
      end





