!******************** start file limlos.for ; group limlos *************
subroutine xlimlos(ilim)
  !
  !  limlos -- rewritten as xlimlos -- dmc 10/21/01
  !      instead of checking all limiters, use dlim(r,z) fast map
  !      which returns +d if item is beyond limiters by distance d
  !      and therefore definitely lost, and -d if item is inside the
  !      limiters by distance d, and only lost if rlar.gt.d or
  !      -rlar.lt.dlim(r,z)...
  !
  use xstraln_calls
  use nbi_com
  !
  !
  !       ------------------------------
  !       input variables from module
  !       ------------------------------
  !
  ! 	xion            flux surf. location of guiding ctr
  !       xiliml          *min flux surface locn. for limlos check
  !          (namelist)
  !
  !	rmjion		major radius of gyro-center
  !	yion		y location of gyro-center relative
  !			 to plasma midplane
  !
  !	rlar		larmor radius of ion
  !	nout		unit number for error messages
  !
  !
  !       -----------------------------------------------
  !       output variable via subroutine calling argument
  !       -----------------------------------------------
  !
  !
  !	ilim			!0 for particle clear of all limiters
  !				!1 for particle striking a limiter
  !
  !
  !=========================================
  !
  !
  !       ----------------------
  !       0.1     initialization
  !       ----------------------
  !
  !
  !-------------------------------------------------
  !
  !  dmc - *scalar code* pretest - for speed of pre-vector vsn
  !   *** using new input variable xion ***
  !
  !============
  implicit none
  integer :: ilim,iwarn
  !============
  real(fp) :: zphiang,zdist
  !============
  ilim=0
  !
  !  if rlar.gt.0.0 but xion.lt.xiliml (.lt.1.0) namelist input,
  !  then (for speed) assume inside plasma
  !
  !  if xiliml=0.0 execute full limlos check unconditionally
  !
  !
  if(xion.lt.xiliml) return
  !
  !  if rlar=0.0 then xion.lt.1.0 means inside plasma
  if((rlar.eq.0.0_fp).and.(xion.lt.1.0_fp)) return
  !
  !  ok, get distance to limiter
  !
  zphiang=0.0_fp  ! axisymmetry assumed
  !
  call xs_frz(idxs_dlim,0.01_fp,zphiang,rmjion,yion,100.0_fp,zdist, &
       iwarn)
  zdist=-zdist
  !
  !  if the larmor radius is equal to or larger than the distance to the
  !  limiter, we treat this as a lost orbit
  !
  if(rlar.ge.zdist) then
     ilim=1
  else
     ilim=0
  end if
  !
  return
end subroutine xlimlos
