program main
use adaptive

type(ADAPTIVE_MESH), pointer :: parent,base
real, dimension(2) :: rmin 
real, dimension(2) :: rmax 
integer, dimension(2) :: nr 
real, dimension(0:2) :: dr 
integer :: level

real, dimension(:,:,:), target, allocatable :: base_grid
real, dimension(:,:,:,:), target, allocatable :: g1,g2,g3,g4
! grid function (level, time_level,x,y) 
integer finest_level
integer, dimension(maxlevel) :: curmax

!HPF$ PROCESSORS P(2,2)
!HPF$ DISTRIBUTE base_grid(*,BLOCK,BLOCK) onto P

INTERFACE
recursive subroutine propagate(curmax,level,base_grid,base,finest_level, &
                               g1,g2,g3,g4)
use adaptive
use parameters
real, dimension(:,:,:) :: base_grid
real, dimension(:,:,:,:) :: g1,g2,g3,g4
type(ADAPTIVE_MESH), pointer :: base
integer     :: level,finest_level
integer, dimension(maxlevel) :: curmax
!HPF$ PROCESSORS P(2,2)
!HPF$ DISTRIBUTE *(*,BLOCK,BLOCK) onto P :: base_grid
end subroutine propagate
  
END INTERFACE

curmax=0
nullify(base)
!allocate base_grid
nullify(parent)
rmin=(/1.0,1.0/)
rmax=(/100.0,100.0/)
nr=(/100,100/)
dr=(/1.0,1.0,1.0/)
call allocate_ADAPTIVE_MESH(curmax,1,parent,base,rmin,rmax,nr,dr)
allocate(base_grid(2,nr(1),nr(2)))
! initialize base grid
forall(i=1:nr(1),j=1:nr(2)) base_grid(1:2,i,j)=float(i)
!!base_grid=1 !to make IBM happy
! allocate memory for fine grids
allocate(g1(maxlevel,2,nr(1),nr(2)))
allocate(g2(maxlevel,2,nr(1),nr(2)))
allocate(g3(maxlevel,2,nr(1),nr(2)))
allocate(g4(maxlevel,2,nr(1),nr(2)))
level=1
finest_level=1

do i=1,10
write(6,*) '------------------------------------------'
write(6,*) 'coarse step no',i
call propagate(curmax,level,base_grid,base,finest_level,g1,g2,g3,g4) 
enddo

stop
end






