subroutine injection(lev,grid,base_grid,g)
use parameters
use adaptive
real,dimension(:,:,:) :: base_grid 
real,dimension(:,:,:,:,:), target :: g
integer :: lev
type(ADAPTIVE_MESH), pointer :: grid

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

integer offsetx,offsety,nx,ny,grid_id,parent_id
type(ADAPTIVE_MESH),pointer :: parent

parent=>grid%parent
grid_id=grid%grid_id
parent_id=parent%grid_id

offsetx=(grid%rmin(1)-parent%rmin(1))+1
offsety=(grid%rmin(2)-parent%rmin(2))+1
nx=grid%nr(1)/rho
ny=grid%nr(2)/rho

if(lev==2) then
  base_grid(1:2,offsetx:nx,offsety:ny) = &
   g(lev,grid_id,1:2,1:grid%nr(1):rho,1:grid%nr(2):rho)
 
!  write(6,*) 'base_grid(2,5,5)',base_grid(2,5,5)
endif

if(lev==3) then
!  write(6,*) 'offsetx,offsety',offsetx,offsety
!  write(6,*) 'nx,ny',nx,ny
  g(lev-1,parent_id,1:2,offsetx:nx,offsety:ny) = &
    g(lev,grid_id,1:2,1:grid%nr(1):rho,1:grid%nr(2):rho)

!  write(6,*) 'g(2,1,2,5,5)',g(2,1,2,5,5)
endif

return
end
