      SUBROUTINE oldBUFR_WRITE(kunit,
     $                         kbuf, kbufsize, 
     $                         kret)

      implicit none

c
c***  SUBROUTINE BUFR_WRITE(kunit,
c    $                      kbuf, kbufsize, 
c    $                      kret)
c
c     Sami Saarinen, ECMWF, 19/10/95
c
c***  Purpose:
c
c     To write data from the BUFR file
c
c***  Externals:
c
c     PBWRITE   - Writes the next BUFR-report(s) to BUFR-file
c
c***  Notes:
c
c     Coded in Fortran-90
c
c***  Input variables
      integer, intent(in) :: kunit           ! PBIO file pointer
      integer, intent(in) :: kbufsize        ! Length of the input kbuf-array
      integer, intent(in) :: kbuf(kbufsize)  ! Output array for BUFR-data
c***  Output variables
      integer, intent(out):: kret  ! Return code:
                                   !   >= 0 , # of kbuf-words written
                                   ! -1 = Error in writing data
c-----------------------------------------------------------------------
! === END OF INTERFACE BLOCK ===
      integer iret_pbio
      integer nobytes

c-----------------------------------------------------------------------
c
c     1. Write BUFR-reports (messages) to BUFR-file
c        ------------------------------------------
c

      inquire(iolength=nobytes) kbufsize

      call PBWRITE(kunit, kbuf, nobytes * kbufsize, iret_pbio)

      if ( iret_pbio <  0 .or.
     $     iret_pbio /= nobytes * kbufsize ) then
         kret = -1
         return
      endif

      kret = kbufsize

      return
      END SUBROUTINE oldBUFR_WRITE

