subroutine inject(level,id,p,pp)
use hpfprocessors
use param
integer level,id
real, dimension(:,:,:,:) :: p
real, dimension(:,:,:,:) :: pp
!HPF$ DISTRIBUTE p(*,BLOCK,*,*)
!HPF$ DISTRIBUTE pp(*,BLOCK,*,*)

integer offsetx,offsety,offsetz
integer nx,ny,nz    !number of grid points on this level
integer nxc,nyc,nzc !number of gird points on parent level
type(ADAPTIVE_MESH), pointer :: grid

  grid=>lp(level)%grid
  if(id <> 1) then
    do while (grid%grid_id <> id)
     grid=>grid%neighbor
    enddo
  endif

  nx=grid%nr(1)
  ny=grid%nr(2)
  nz=grid%nr(3)
  
  offsetx=(grid%rmin(1)-grid%parent%rmin(1))+1
  offsety=(grid%rmin(2)-grid%parent%rmin(2))+1
  offsetz=(grid%rmin(3)-grid%parent%rmin(3))+1

  nxc=offsetx+(nx+1)/rho-1
  nyc=offsety+(ny+1)/rho-1 
  nzc=offsetz+(nz+1)/rho-1

!transfer data points from fine grid to coarse one

 pp(:,offsetx:nxc,offsety:nyc,offsetz:nzc)= & 
 p(:,1:nx:rho,1:ny:rho,1:nz:rho)

return
end
