subroutine get_cell_index(xp,ipe,igrid,ixc1,ixc2,ixc3)
! for given point (xp), provide the corrsponding processor (ipe),
! grid number (igrid) and cell index (ixc^D)
double precision :: xp(1:ndim)
integer :: ipe,igrid,ixc1,ixc2,ixc3
double precision :: x3d(1:3)
double precision :: dxb1,dxb2,dxb3,xbmin1,xbmin2,xbmin3,xbmax1,xbmax2,&
xbmax3
integer :: indomain,ixOmin1,ixOmin2,ixOmin3,ixOmax1,ixOmax2,ixOmax3,j
integer :: datas(1:ndim+2)
indomain=0
if (xp(3)>=xprobmin3 .and. xp(3)<xprobmax3) indomain=indomain+1
if (xp(2)>=xprobmin2 .and. xp(2)<xprobmax2) indomain=indomain+1
if (xp(1)>=xprobmin1 .and. xp(1)<xprobmax1) indomain=indomain+1
if (indomain==ndim) then
! find pe and igrid
x3d=0.d0
do j=1,ndim
x3d(j)=xp(j)
enddo
call find_particle_ipe(x3d,igrid,ipe)
if (mype==ipe) then
! looking for the cell index
xbmin1=rnode(rpxmin1_,igrid)
xbmin2=rnode(rpxmin2_,igrid)
xbmin3=rnode(rpxmin3_,igrid)
xbmax1=rnode(rpxmax1_,igrid)
xbmax2=rnode(rpxmax2_,igrid)
xbmax3=rnode(rpxmax3_,igrid)
dxb1=rnode(rpdx1_,igrid)
dxb2=rnode(rpdx2_,igrid)
dxb3=rnode(rpdx3_,igrid)
ixOmin1=ixmlo1
ixOmin2=ixmlo2
ixOmin3=ixmlo3
ixc1=floor((xp(1)-xbmin1)/dxb1)+ixOmin1
ixc2=floor((xp(2)-xbmin2)/dxb2)+ixOmin2
ixc3=floor((xp(3)-xbmin3)/dxb3)+ixOmin3
datas(1)=ixc1
datas(2)=ixc2
datas(3)=ixc3
datas(ndim+1)=ipe
datas(ndim+2)=igrid
endif
call MPI_BCAST(datas,ndim+2,MPI_INTEGER,ipe,icomm,ierrmpi)
endif
ixc1=datas(1)
ixc2=datas(2)
ixc3=datas(3)
ipe=datas(ndim+1)
igrid=datas(ndim+2)
end subroutine get_cell_index