subroutine propagate(lp,level,base_grid,base,finest_level,g)
use adaptive
real, dimension(:,:,:) :: base_grid
real, dimension(:,:,:,:,:), target :: g
type(ADAPTIVE_MESH), pointer :: base
integer     :: level,finest_level
type(LEVEL_INFO), dimension(maxlevel) :: lp

real, dimension(2,mxf,myf) :: gridpointer
type(ADAPTIVE_MESH), pointer :: grid,child,sibling,parent

!HPF$ PROCESSORS P(PX,PY)
!HPF$ DISTRIBUTE *(*,BLOCK,BLOCK) onto *P :: base_grid
!HPF$ DISTRIBUTE (*,BLOCK,BLOCK) onto P :: gridpointer
!HPF$ DISTRIBUTE (*,*,*,BLOCK,BLOCK) onto *P :: g

INTERFACE
  subroutine update(a,t,dr,nx,ny)
  use parameters
  real, dimension(:,:,:) :: a
  real t
  integer nx,ny
  real, dimension(0:2) :: dr
!HPF$ PROCESSORS P(PX,PY)
!HPF$ DISTRIBUTE *(*,BLOCK,BLOCK) onto *P :: a
  end subroutine update

END INTERFACE

write(6,*) 'PROPAGATE at level',level

if(.not.associated(base)) then
write(6,*) '???'
stop
endif


do istep=1,2
write(6,*) 'step',istep,' on level',level

! do one step on the current level 
! update all grids on the current level, from 1 to curmax
!   write(6,*) lp%curmax

!   (level == 1)

lev=1
write(6,*) 'call update base grid'
write(6,*) 't,dr',base%t,lp(lev)%dr
 call update(base_grid,base%t,lp(lev)%dr,base%nr(1),base%nr(2))
write(6,*) 'base grid updated' 

! if there are finer levels, update them ...

if(finest_level==2) then

     lev=2
     grid=>lp(lev)%head
write(6,*) 'grid associated'

!     gridpointer=>g(lev,grid%grid_id,:,:,:)
     gridpointer=g(lev,grid%grid_id,:,:,:)
     DO WHILE (associated(grid))
write(6,*) 'call update: first fine step'
       call update(gridpointer,grid%t,lp(lev)%dr,grid%nr(2),grid%nr(2))
       call update(gridpointer,grid%t,lp(lev)%dr,grid%nr(1),grid%nr(2))
!       call update(g(lev,grid%grid_id,:,:,:),grid%t,lp(lev)%dr)
!       call update(g(lev,grid%grid_id,:,:,:),grid%t,lp(lev)%dr)
       grid=>grid%sibling
     ENDDO ! WHILE

endif !finest_level==2

enddo

! update coarser level
!if(level>1) then
!grid=>lp(level)%head
!DO WHILE(associated(grid))
! parent=>grid%parent
! grid_id=grid%grid_id
! prnt_id=parent%grid_id
!write(6,*) 'INJECT:',grid_id,prnt_id
!call inject(lev,grid_id,prnt_id,g)
!grid=>grid%sibling
!enddo 
!endif
return
end








