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
if(finlev == 2) then
  lev=2
  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

  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   
endif

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

return
end




