      program adaptive_mesh
      use amr
      use dinterface

      type(LEVEL_INFO), dimension(maxlev) :: lp 
      type(GF3TL),pointer    :: grid
      character(200)         :: grid_name = 'test grid'
      real*8, dimension(3)   :: gmin,gmax,gd
      integer gid,curlev,finlev
      real*8  t
      integer, parameter     :: nsteps = 500

      INTERFACE 
      subroutine initialize_grid_functions(lp,level,t)
      use amr
      type(LEVEL_INFO), dimension(maxlev) :: lp 
      integer                             :: level
      real*8                              :: t 
      end subroutine initialize_grid_functions

      subroutine initialize_base_grid(lp,grid_name)
      use amr
      type(LEVEL_INFO), dimension(maxlev) :: lp 
      character(200)                      :: grid_name 
      end subroutine initialize_base_grid

      subroutine regrid(lp,curlev,finlev,first)
      use amr
      type(LEVEL_INFO), dimension(maxlev) :: lp
      integer curlev,finlev
      logical first
      end subroutine regrid       

      subroutine propagate(lp,crsstp,finlev)
      use amr
      type(LEVEL_INFO),dimension(maxlev) :: lp     
      integer crsstp,finlev    
      end subroutine propagate

      END INTERFACE 

      gid=get_g(-1)
      t=t_init
      curlev=1
      finlev=1  
      call initialize_level_info(lp)

!     test
!      call print_level_info(lp)
 
      call initialize_base_grid(lp,grid_name)
      call initialize_grid_functions(lp,curlev,t)
cc      call regrid(lp,curlev,finlev,.true.)

      write(6,*) ' =========== END OF INITIALIZATION ============'

      call propagate(lp,nsteps,finlev)

      write(6,*) 'END OF PROGRAM'
      stop
      end program

      subroutine initialize_base_grid(lp,grid_name)
      use amr
      type(LEVEL_INFO), dimension(maxlev) :: lp 
      character(200)                      :: grid_name 
   
      type(ADAPTIVE_MESH),pointer         :: ptr
      real*8 xmin,xmax,ymin,ymax,zmin,zmax
      xmin=gxmin
      xmax=gxmax
      ymin=gymax
      ymax=gymax
      zmin=gymax
      zmax=gzmax 

      level=1
      nullify(ptr)
      call initialize_grid(ptr,level,grid_name,xmin,ymin,zmin,
     &  xmax,ymax,zmax,lp(level)%ldr)
      lp(level)%ml=>ptr
      return
      end subroutine initialize_base_grid
 






