!-----------------------------------------------------------------------
!  boxfind -- given coordinates, figure out location in 3d grid
!
subroutine boxfind(zx,zy,zl,ix,iy,il,inside)
  !
  use nbi_com
  !
  !============
  implicit none
  integer :: inc
  !============
  real(fp) :: zx,zy,zl  ! input 3 space coordinates, [cm]
  integer :: ix,iy,il  ! output 3 space index
  logical inside    ! output .true. if all indices in bounds
  !
  !  if zx is out of bounds low, ix=0 is returned;
  !  if zx is out of bounds high, ix=nxbox+1 is returned
  !  similarly for y and l coordinates!
  !
  !-----------------------------------------------------------------------
  !
  inside=.true.
  !
  if(zx.lt.-xboxhw) then
     ix=0
     inside=.false.
  else if(zx.gt.xboxhw) then
     ix=nxbox+1
     inside=.false.
  else
     inc=real(nxbox)*(zx+xboxhw)/(xboxhw+xboxhw)
     ix=min(nxbox,(1+inc))
  end if
  !
  if(zy.lt.-yboxhw) then
     iy=0
     inside=.false.
  else if(zy.gt.yboxhw) then
     iy=nybox+1
     inside=.false.
  else
     inc=real(nybox)*(zy+yboxhw)/(yboxhw+yboxhw)
     iy=min(nybox,(1+inc))
  end if
  !
  if(zl.lt.xlbox1) then
     il=0
     inside=.false.
  else if(zl.gt.xlbox2) then
     il=nlbox+1
     inside=.false.
  else
     inc=real(nlbox)*(zl-xlbox1)/(xlbox2-xlbox1)
     il=min(nlbox,(1+inc))
  end if
  !
  return
end subroutine boxfind
! 11sep2004 fgtok
