! dmc apr 2004 -- all xja routines use bmnmx instead of bmidp -- code
!  now in terms of min and max b on flux surfaces, not midplane values
!----------------------------------------------------------------------
!  xjags0  pick initial guess passing or pinch orbit intercept pair
!    subroutine of xjadep-- first orbit shift estimator
!
subroutine xjags0(zvplldep,i1,i2)
  !
  use nbi_com
  !
  use xjasub_mod
  !
  !
  !  zvplldep (input) pll velocity of neutral at ionization point
  !
  !  output i1 = ptr to inside intercept
  !         i2 = ptr to outside intercept
  !
  !  algorithm:  just choose the intercept with the vpll nearest to
  !  vpll at deposition point
  !
  !============
  implicit none
  integer :: i1,i2,imin,i,icomp
  !============
  real(fp) :: zvplldep,zvdif,zvdifi
  !============
  zvdif=epsinv
  !
  imin=0
  !
  !  find existing intercept with minimum difference in vpll with
  !  the right sign of vpll
  !
  do i=1,4
     if(iloc(i).gt.-1) then
        zvdifi=abs(zvplli(i)-zvplldep)
        if(zvdifi.lt.zvdif) then
           imin=i
           zvdif=zvdifi
        end if
     end if

  end do
  !
  !  index to passing orbits' complimentary intercept
  !  caller needs to check for possibility of trapping
  !
  icomp=5-imin
  i1=max(imin,icomp)
  i2=min(imin,icomp)
  !
  return
end subroutine xjags0
