!!----------------------------------------------------------------------------
!! $Id: dump.f90,v 1.1 1997/12/19 19:37:59 scott Exp $ 
!! subroutine dump_data
!!    This subroutine will output data to a file and to scivis
!!    Author: Scott A. Klasky
!!    Date  : 10/20/97
!!    The metric function that we will use by default will help compute
!!    the nearest neighbor list
!!----------------------------------------------------------------------------
subroutine dump_data(name,time,max_params,params,gf)
use PATHS
use input_params
implicit none
character*(*),intent(IN)                       :: name
real*8,intent(IN)                              :: time
integer,intent(IN)                             :: max_params
real*8,dimension(max_params),intent(IN)        :: params
type (PATH),dimension(:,:),intent(IN)          :: gf

integer                                        :: java_bbser2d,rc
real*8,dimension(:),allocatable                :: gf2d
real*8,dimension(4)                            :: bb
integer                                        :: nx,ny
integer                                        :: i,j,l


   nx = int(params(P_NTIME))
   ny = int(params(P_NPATH))
   allocate (gf2d(nx*ny))
   bb(1) = 1 
   bb(2) = params( P_NTIME)
   bb(3) = 1
   bb(4) = params( P_NPATH)

   l = 0
   do i = 1 , nx
      do j = 1 , ny
         l = l + 1
         gf2d(l) = gf(i,j)%spin
      end do
   end do

   rc = java_bbser2d(name,time,bb,nx,ny,gf2d)
	write(88) gf2d

return
end subroutine dump_data

!!----------------------------------------------------------------------------
!! 
!!----------------------------------------------------------------------------
subroutine dump_dat1d(name,it,time,max_params,params,x2d,gf)
use PATHS
use input_params
implicit none
character*(*),intent(IN)                       :: name
real*8,intent(IN)                              :: time
integer,intent(IN)                             :: max_params
integer                                        :: it
real*8,dimension(max_params),intent(IN)        :: params
type (PATH),dimension(:,:),intent(IN)          :: gf
real*8,dimension(:,:),intent(IN)                :: x2d

integer                                        :: java_cmser,rc
real*8,dimension(:),allocatable                :: y,x,c
integer                                        :: nx,ny,nxy(1)
integer                                        :: i,j,l,nt
real*8,dimension(1) :: t


   nt = 1 !! only 1 time slice
   nx = int(params(P_NTIME))
   ny = int(params(P_NPATH))
	nxy(1) = nx*ny
	allocate(y(nx*ny),x(nx*ny),c(nx*ny))

   l = 0
   t(1) = time
   
   
   do j = 1 , ny
	   do i = 1, nx
         l = l + 1
         c(l) = gf(i,j)%spin
		   y(l) = x2d(i,j)
         x(l) = 1.0d0*(i-1)
		end do !i
   end do !j

   rc = java_cmser(name,1,t,x,y,c,nxy)

return
end subroutine dump_dat1d

!!----------------------------------------------------------------------------
!!
!!----------------------------------------------------------------------------
subroutine dump_dat1d2(name,it,time,max_params,params,gf)
use PATHS
use input_params
implicit none
character*(*),intent(IN)                       :: name
real*8,intent(IN)                              :: time
integer,intent(IN)                             :: max_params
integer                                        :: it
real*8,dimension(max_params),intent(IN)        :: params
type (PATH),dimension(:,:),intent(IN)          :: gf

integer                                        :: java_cmser,rc
real*8,dimension(:),allocatable                :: y,x,c
integer                                        :: nx,ny,nxy(1)
integer                                        :: i,j,l,nt
real*8,dimension(1) :: t


   nt = 1 !! only 1 time slice
   nx = int(params(P_NTIME))
   ny = int(params(P_NPATH))
   nxy(1) = nx*ny
   allocate(y(nx*ny),x(nx*ny),c(nx*ny))

   l = 0
   t(1) = time


   do j = 1 , ny
      do i = 1, nx
         l = l + 1
         c(l) = gf(i,j)%spin
         y(l) = 1.0d0*(j) 
         x(l) = 1.0d0*(i-1)
      end do !i
   end do !j

   rc = java_cmser(name,1,t,x,y,c,nxy)

return
end subroutine dump_dat1d2
!!----------------------------------------------------------------------------
subroutine dump_datar(name,time,max_params,params,gf)
use PATHS
use input_params
implicit none
character*(*),intent(IN)                       :: name
real*8,intent(IN)                              :: time
integer,intent(IN)                             :: max_params
real*8,dimension(max_params),intent(IN)        :: params
real*8,dimension(:,:),intent(IN)               :: gf

integer                                        :: java_bbser2d,rc
real*8,dimension(:),allocatable                :: gf2d
real*8,dimension(4)                            :: bb
integer                                        :: nx,ny
integer                                        :: i,j,l


   nx = int(params(P_NTIME))
   ny = int(params(P_NPATH))
   allocate (gf2d(nx*ny))
   bb(1) = 1
   bb(2) = params( P_NTIME)
   bb(3) = 1
   bb(4) = params( P_NPATH)

   l = 0
   do i = 1 , nx
      do j = 1 , ny
         l = l + 1
         gf2d(l) = gf(i,j)
      end do
   end do

   rc = java_bbser2d(name,time,bb,nx,ny,gf2d)
   write(88) gf2d

return
end subroutine dump_datar

!!----------------------------------------------------------------------------
subroutine dump_data1d(name,time,max_params,params,gf)
use input_params
implicit none
character*(*),intent(IN)                       :: name
real*8,intent(IN)                              :: time
integer,intent(IN)                             :: max_params
real*8,dimension(max_params),intent(IN)        :: params
real*8,dimension(:,:),intent(IN)               :: gf

integer                                        :: i,j,l,nx,ny
real*8,dimension(:),allocatable                :: x,y
integer                                        :: vsrc,java_ser


   nx = int(params(P_NTIME))
   ny = int(params(P_NPATH))
	allocate(x(nx*ny),y(nx*ny))

	l = 0
   do i = 1 ,nx
      do j= 1 , ny
			l = l + 1
			x(l) = 1.0d0*i
			y(l) = gf(i,j)
	   end do !j
	end do !i

	vsrc = java_ser(name,time,x,y,l)

return
end
