!******************** start file fshlos.for ; group fshlos ******************
!
!	this subroutine serves to determine the rate at which
!	ions are lost due to a fishbone oscillation
!
!	it is assumed that this subroutine is called only
!	when the fishbone is "on" and particles are being
!	lost
!
!	rob goldston  6-10-82
!
subroutine fshlos(zvpvc1,zxc1,zthc1,zvpvc2,zxc2,zthc2, &
     zevolt,zfrate)
  !
  !	this subroutine is called from nbinj in transp.
  !	it obtains information about the ion under consideration
  !	only thru the subroutine call
  !	general characterstics of the fishbone come from trans.com
  !
  !
  !
  !
  !	input data from subroutine arguments
  !	------------------------------------
  !
  !	zvpvc1		vpar/v 		2 midplane crossings ago
  !	zxc1		"xi"  location       "		"
  !	zthc1		poloidal angle       "		"
  !
  !	zvpvc2		vpar/v		last midplane crossing
  !	zxc2		"xi"  location       "		"
  !	zthc2		poloidal angle	     "		"
  !
  !	zevolt		particle energy (ev)
  !
  !
  !	output data through subroutine argument
  !	---------------------------------------
  !
  !	zfrate		rate of loss due to fish-bone (1/sec)
  !
  !	common variables from trans.com
  !	-------------------------------
  !
  !	fvpvmx
  !	fvpvmn  ! stan kaye apr 1986
  !	fbemin
  !	fbemax
  !	fbltim
  !
  use nbi_com
  !
  !============
  implicit none
  real(fp) :: zxc1,zthc1,zvpvc2,zxc2,zthc2,zevolt,zfrate,zvpvc1,zx1
  real(fp) :: zx2,zxav
  !============
  zfrate=0.0_fp
  !
  if(zevolt.le.fbemin.or.zevolt.ge.fbemax) return
  !
  if(nfbon_species.eq.1) then
     if(nlfprod(lsbeam)) return
  end if
  !
  if(nfbon_species.eq.2) then
     if(.not.nlfprod(lsbeam)) return
  end if
  !
  if(nfbon_vpvopt.eq.0) then
     !
     !  legacy vpll/v criterion for fishbone loss eligibility
     !
     zx1=abs(zvpvc1)
     zx2=abs(zvpvc2)
     !
     if( ((zx1.gt.fvpvmx).or.(zx1.lt.fvpvmn)) .and. &
          ((zx2.gt.fvpvmx).or.(zx2.lt.fvpvmn)) ) return

  else
     !
     !  eligible only if trapped & trapping depth is at or exceeds the input
     !  threshold
     !
     if(dtrap.lt.fbtrap_depth) return
     !
  end if
  !
  !  if reach this line:
  !  **eligible for loss**
  !      unless excluded by spatial criterion
  !
  zxav = (xjav-lcentr)/nzones
  zxav = max(0.0_fp,min(1.0_fp,zxav))

  if(zxav.lt.xfishmin) return
  if(zxav.gt.xfishmax) return
  !
  !  **eligible for loss**
  !
  zfrate=1.0_fp/fbltim
  !
  return
end subroutine fshlos
!******************** end file fshlos.for ; group fshlos ******************
