C----------------------------------------------------------------------
        subroutine ftpbyx(ounit,recnum,nbytes,nbuff,status)

C       low-level routine to write bytes to an output file

C       ounit   i  fortran unit number
C       recnum  i  direct access file record number
C       nbytes  i  number of bytes to write
C       nbuff   i  number of the buffer to be written
C       status  i  output error status

        integer ounit,recnum,nbytes,nbuff,status
        character*2880 buff1,buff2,buff3,buff4,buff5,buff6
        character*2880 buff7,buff8,buff9,buff10,buff11,buff12
        common/ft00b1/buff1
        common/ft00b2/buff2
        common/ft00b3/buff3
        common/ft00b4/buff4
        common/ft00b5/buff5
        common/ft00b6/buff6
        common/ft00b7/buff7
        common/ft00b8/buff8
        common/ft00b9/buff9
        common/ft0b10/buff10
        common/ft0b11/buff11
        common/ft0b12/buff12
        
C       Note: we have to use separate buffers, rather than one big array
C       of buffers, because some compilers have a limit on the length of
C       a character array (e.g., 32K).

        if (status .gt. 0)return

        if (nbuff .eq. 1)then
                write(ounit,rec=recnum,err=900)buff1(1:nbytes)
        else if (nbuff .eq. 2)then
                write(ounit,rec=recnum,err=900)buff2(1:nbytes)
        else if (nbuff .eq. 3)then
                write(ounit,rec=recnum,err=900)buff3(1:nbytes)
        else if (nbuff .eq. 4)then
                write(ounit,rec=recnum,err=900)buff4(1:nbytes)
        else if (nbuff .eq. 5)then
                write(ounit,rec=recnum,err=900)buff5(1:nbytes)
        else if (nbuff .eq. 6)then
                write(ounit,rec=recnum,err=900)buff6(1:nbytes)
        else if (nbuff .eq. 7)then
                write(ounit,rec=recnum,err=900)buff7(1:nbytes)
        else if (nbuff .eq. 8)then
                write(ounit,rec=recnum,err=900)buff8(1:nbytes)
        else if (nbuff .eq. 9)then
                write(ounit,rec=recnum,err=900)buff9(1:nbytes)
        else if (nbuff .eq. 10)then
                write(ounit,rec=recnum,err=900)buff10(1:nbytes)
        else if (nbuff .eq. 11)then
                write(ounit,rec=recnum,err=900)buff11(1:nbytes)
        else if (nbuff .eq. 12)then
                write(ounit,rec=recnum,err=900)buff12(1:nbytes)
        else
             status=102
        end if
        return

900     status=106
        end
