subroutine f_dump_2d(lb,ub,s, gf, name, params)
  use tensors
  use input_params

  INTERFACE

     subroutine dump_2d(params, name, u)
       use input_params  
       implicit none
       real*8, dimension(100) :: params
       character*(*) name
       real*8, dimension(:,:,:) :: u
     end subroutine dump_2d

  END INTERFACE

  implicit none
  integer, dimension(3)         :: lb,ub,s
  real*8, dimension(s(1),s(2),s(3)), target :: gf 
  real*8,dimension(100) :: params
  character (LEN=40)    :: name

  call dump_2d(params,name,gf)

  return
end

subroutine dump_2d(params, name, u)
  use input_params  
  implicit none

  INTERFACE
     
     subroutine dump_2d_slice(name, time, u, nx,ny,nz, yslice, &
          xmin,zmin, h)
       implicit none
       
       integer nx,ny,nz
       character*(*) name
       integer yslice
       real*8 time, xmin, zmin, h
       real*8, dimension(:,:,:) :: u
     end subroutine dump_2d_slice
     
  END INTERFACE

  real*8, dimension(100) :: params
  character*(*) name
  real*8, dimension(:,:,:) :: u

  ! Locals

  real*8 xmin, zmin, time, h 
  integer i, j, nx, ny, nz, yslice, sh(3)

  sh = shape(u)
  nx = sh(1)
  ny = sh(2)
  nz = sh(3)

  time = params(P_CURRENTTIME)
  h = params(P_GRIDSPACING)
  xmin = params(P_XMIN)
  zmin = params(P_ZMIN)
  yslice = (sh(2)+1)/2

  call dump_2d_slice(name, time, u, nx, ny, nz, yslice, &
       xmin, zmin, h)

end subroutine dump_2d


subroutine dump_2d_slice(name, time, u, nx,ny,nz, yslice, &
     xmin,zmin, h)
  implicit none
  
  integer nx,ny,nz
  character*(*) name
  integer yslice
  real*8 time, xmin, zmin, h
  real*8, dimension(:,:,:) :: u
  
  integer jerr,java_ser2d
  
  
  integer i,j,l
  real*8,allocatable,dimension(:) :: fxz,x2d,z2d
  
  allocate(x2d(nx*nz),z2d(nx*nz),fxz(nx*nz))
  
  l = 0
  do j = 1 , nz
     do i = 1 , nx
        
        l = l + 1
        x2d(l) = xmin + h*(i-1)
        z2d(l) = zmin + h*(j-1)
        fxz(l)  = u(i,yslice,j)
        
     end do
  end do
  
  
  jerr = java_ser2d(name,time,x2d,z2d,fxz,nx*nz)
      if (jerr .ne. 0) then
     pause
     jerr = java_ser2d(name,time,x2d,z2d,fxz,nx*nz)  
  end if
  
end
                
