!
!  write_plt3d
!
      subroutine write_plt3d(cphi,x,y,z,phi,ni,nj,nk)
      implicit none
      integer :: ni,nj,nk
      real :: x(ni,nj,nk),y(ni,nj,nk),z(ni,nj,nk),phi(ni,nj,nk)
      character (len=*) :: cphi 
!
      integer :: i,j,k,numblks
!
      open ( unit=77, status='unknown', form='unformatted', file=trim(cphi)//'.xyz' )
      open ( unit=88, status='unknown', form='unformatted', file=trim(cphi)//'.q' )
!
! Note in Paraview reader set:
! - Binary File
! - Multi Grid
! - Has Byte Count (all files written from Fortran do)
! - Little Endian
!
      numblks = 1
      write (77) numblks
      write(77) ni, nj, nk
      write(77)  & 
         ((( x(i,j,k), i=1,ni), j=1,nj), k=1,nk), &
         ((( y(i,j,k), i=1,ni), j=1,nj), k=1,nk), &
         ((( z(i,j,k), i=1,ni), j=1,nj), k=1,nk)

      write (88) numblks
      write(88) ni, nj, nk
      write(88) 0,0,0,0
      write(88) ((( phi(i,j,k), i=1,ni), j=1,nj), k=1,nk)
      write(88) ((( phi(i,j,k), i=1,ni), j=1,nj), k=1,nk)
      write(88) ((( phi(i,j,k), i=1,ni), j=1,nj), k=1,nk)
      write(88) ((( phi(i,j,k), i=1,ni), j=1,nj), k=1,nk)
      write(88) ((( phi(i,j,k), i=1,ni), j=1,nj), k=1,nk)
!
      close(77)
      close(88)
!
      end subroutine write_plt3d 
