subroutine dumpdata(finlev)
use gridfunctions

type(ADAPTIVE_MESH),pointer :: grid
integer gridno,finlev
integer lev
integer, SAVE :: timestep=0

gridno=0

!first the base grid

lev=1
grid=>lp(1)%grid
write(72,*) lev
write(72,*) grid%nr(1:2)
write(72,*) grid%rmin(1:2)
write(72,*) grid%rmax(1:2)

gridno=gridno+1
!do i=1,grid%nr(1)
! do j=1,grid%nr(2)
!   write(72,*) g1(1,i,j,1)
! enddo
!enddo

!now level 2
  lev=2
  if(allocated(g21)) then
   grid=>lp(2)%grid
   write(72,*) lev
   write(72,*) grid%nr(1:2)
   write(72,*) grid%rmin(1:2)
   write(72,*) grid%rmax(1:2)

   gridno=gridno+1
!   do i=1,grid%nr(1)
!    do j=1,grid%nr(2)
!     write(72,*) g21(1,i,j,1)
!     enddo
!   enddo
  endif

  if(allocated(g22)) then 
   grid=>grid%neighbor
   write(72,*) lev
   write(72,*) grid%nr(1:2)
   write(72,*) grid%rmin(1:2)
   write(72,*) grid%rmax(1:2)

   gridno=gridno+1
!   do i=1,grid%nr(1)
!   do j=1,grid%nr(2)
!    write(72,*) g22(1,i,j,1)
!    enddo
!   enddo
  endif   

  if(allocated(g23)) then 
   grid=>grid%neighbor
   write(72,*) lev
   write(72,*) grid%nr(1:2)
   write(72,*) grid%rmin(1:2)
   write(72,*) grid%rmax(1:2)

   gridno=gridno+1
!   do i=1,grid%nr(1)
!   do j=1,grid%nr(2)
!    write(72,*) g23(1,i,j,1)
!    enddo
!   enddo
  endif   

!now level 3
  lev=3
  if(allocated(g31)) then
   grid=>lp(3)%grid
   write(72,*) lev
   write(72,*) grid%nr(1),grid%nr(2)-1
   write(72,*) grid%rmin(1:2)
   write(72,*) grid%rmax(1),grid%rmax(2)-0.25

   gridno=gridno+1
!   do i=1,grid%nr(1)
!    do j=1,grid%nr(2)-1
!     write(72,*) g31(1,i,j,1)
!     enddo
!   enddo
!write(72,*) g31(1,:,1,1)  
!stop

  endif


  if(allocated(g32)) then 
   grid=>grid%neighbor
   write(72,*) lev
   write(72,*) grid%nr(1),grid%nr(2)-1
   write(72,*) grid%rmin(1:2)
   write(72,*) grid%rmax(1),grid%rmax(2)-0.25

   gridno=gridno+1
!   do i=1,grid%nr(1)
!   do j=1,grid%nr(2)-1
!    write(72,*) g32(1,i,j,1)
!    enddo
!   enddo
  endif   

  if(allocated(g33)) then 
   grid=>grid%neighbor
   write(72,*) lev
   write(72,*) grid%nr(1),grid%nr(2)-1
   write(72,*) grid%rmin(1:2)
   write(72,*) grid%rmax(1),grid%rmax(2)-0.25

   gridno=gridno+1
!   do i=1,grid%nr(1)
!   do j=1,grid%nr(2)-1
!    write(72,*) g33(1,i,j,1)
!    enddo
!   enddo
  endif   

write(73,*) timestep,gridno
timestep=timestep+1

return
end




