      subroutine write (nunit, string)

c  writes a character string to stream 'nunit'

      character*(*) string
      character*4 chival
      logical opened

      last = len_trim(string)
      nun = nunit
      if (.not.opened(nun)) then
        call warn ('Unit'//chival(nunit)//' has not been opened')
        nun = 6
      end if
      if (last .eq. 0) then
        write (nun, '(a)')
      else
        if (nun .eq. 6) then
          write (nun, '(1x,a)') string(:last)
        else
          write (nun, '(a)') string(:last)
        end if
      end if
      return
      end
