!
!  real*8 interface -- gyro-averaged beam-beam fusion
!
!  collection of functions for evaluating fusion reaction rate coefficients
!  <sigma*v> from pretabulated data
!
!  these are gyro-averages over pairs of contributing ptcls "df"
!  each characterized by energy E, and pitch (vpll/v), in the lab frame.
!
!  each contribution to a beam-beam fusion integral can be characterized
!  in terms of an average interaction energy and a variational fraction
!  between zero and one, between pairs of ptcls.  details are developed
!  in the commments below (copied from the old TRANSP BBNEUT package).
!
!  the "average energy" is A, the variational fraction is B/A, the latter
!  always between zero and one.
!
!C	THIS CALCULATES THE NEUTRON PRODUCTION FROM BEAM-BEAM
!C   COLLISION REACTIONS USING THE BEAM DISTRIBUTION FUNCTION
!C   WHICH IS A FUNCTION OF BEAM PARTICLE ENERGY AND PITCH
!C   ANGLE.  IT ALSO USES THE COLLISION CROSS-SECTION ALREADY
!C   INTEGRATED OVER PHASE ANGLE.  THE ARGUMENTS OF THIS
!C   FUNCTION ARE A = VP1**2 + VP2**2 + (VPAR2-VPAR1)**2 AND
!C   B = 2*VP1*VP2, WERE VP1 AND VP2 ARE THE PERPENDICULAR
!C   COMPONENTS OF THE FIRST AND SECOND PARTICLE VELOCITY AND
!C   VPAR1 AND VPAR2 ARE THE PARALLEL COMPONENTS.  THE DISTRIBU-
!C   TION FUNCTION MAY EQUIVALENTLY BE THOUGHT OF AS HAVING
!C   V**2 AND CHI AS ARGUMENTS INSTEAD OF E AND CHI.  IN THESE
!C   TERMS WE HAVE THE FOLLOWING
!C
!C	VP1**2 = V1**2(1 - CHI1**2)
!C	VPAR1 = V1*CHI1
!C
!C	VP2**2 = V2**2(1 - CHI2**2)
!C	VPAR2 = V2*CHI2
!C
!C	A = V1**2*(1-CHI1**2) + V2**2*(1-CHI2**2) +
!C		(V2*CHI2 - V1*CHI1)**2
!C   OR
!C	A = V1**2 + V2**2 - 2.0*V1*CHI1*V2*CHI2
!C
!C	B = 2*SQRT(V1**2*(1-CHI1**2)*V2**2*(1-CHI2**2) )
!C
!C   IN COMPUTING THE GYROPHASE INTEGRAL, E = A-B*COS(PHI), BUT
!C   FOR CONVENIENCE I HAVE USED  E = A*(1-BF*COS(PHI)) AND IT
!C   IS A AND BF WHICH ARE WRITTEN INTO THE DATA FILE WHERE
!C   BF VARIES FROM 0.0 TO 1.0.
!C   (A IS CALLED BBA IN TRANS.COM AND BF IS CALLED BBB)
!C
!C	For cases where the target and projectile species are different,
!C   there is a minor change in A, which is basically the kinetic energy
!C   of the projectile in the target's rest frame.  Let V1 be the velocity
!C   of the target in the lab frame, and let V2 be the velocity of the
!C   projectile in the lab frame.  Also let R = SQRT(m2/m1), where m1 and m2
!C   are the masses (atomic numbers) of the target and projectile species
!C   respectively.  Then, in the target's rest frame,
!C
!C	A = V2*V2 + R*V1*R*V1 - 2.0*R*V1*COS1*V2*COS2
!C
!C	B = 2.0*V1*R*SIN1*V2*SIN2
!C
!C   That is, we replace V1 by R*V1.  B is still an evenly spaced fraction.
!C
!
!  in all the routines, input arrays are the "A" energy eav(1:n), KeV
!  and the variational fraction "B/A", dimensionless, in fvar(1:n).
!  the answer(1:n) is returned in m**3/sec
!
!-----------------------------------------------------
subroutine fusn_bbsigv_DDp(eav,fvar,answer,n)
 
  use hatom_mod
  implicit NONE
 
  integer, intent(in) :: n
  real*8, intent(in) :: eav(n),fvar(n)
  real*8, intent(out) :: answer(n)
 
  !--------------------------------------------
  !  initialize module, if necessary
 
  if(hatom_flag.eq.0) call hatom_init
 
  !--------------------------------------------
 
  call fs_gyroavg_sigmatimesv(Lfs_DDp, eav, fvar, answer, n)
 
end subroutine fusn_bbsigv_DDp
!-----------------------------------------------------
subroutine fusn_bbsigv_DDn(eav,fvar,answer,n)
 
  use hatom_mod
  implicit NONE
 
  integer, intent(in) :: n
  real*8, intent(in) :: eav(n),fvar(n)
  real*8, intent(out) :: answer(n)
 
  !--------------------------------------------
  !  initialize module, if necessary
 
  if(hatom_flag.eq.0) call hatom_init
 
  !--------------------------------------------
 
  call fs_gyroavg_sigmatimesv(Lfs_DDn, eav, fvar, answer, n)
 
end subroutine fusn_bbsigv_DDn
!-----------------------------------------------------
subroutine fusn_bbsigv_TT(eav,fvar,answer,n)
 
  use hatom_mod
  implicit NONE
 
  integer, intent(in) :: n
  real*8, intent(in) :: eav(n),fvar(n)
  real*8, intent(out) :: answer(n)
 
  !--------------------------------------------
  !  initialize module, if necessary
 
  if(hatom_flag.eq.0) call hatom_init
 
  !--------------------------------------------
 
  call fs_gyroavg_sigmatimesv(Lfs_TT, eav, fvar, answer, n)
 
end subroutine fusn_bbsigv_TT
!-----------------------------------------------------
subroutine fusn_bbsigv_dpcTT(eav,fvar,answer,n)
 
  use hatom_mod
  implicit NONE
 
  integer, intent(in) :: n
  real*8, intent(in) :: eav(n),fvar(n)
  real*8, intent(out) :: answer(n)
 
  !--------------------------------------------
  !  initialize module, if necessary
 
  if(hatom_flag.eq.0) call hatom_init
 
  !--------------------------------------------
 
  call fs_gyroavg_sigmatimesv(Lfs_dpcTT, eav, fvar, answer, n)
 
end subroutine fusn_bbsigv_dpcTT
!-----------------------------------------------------
subroutine fusn_bbsigv_DT(eav,fvar,answer,n)
 
  use hatom_mod
  implicit NONE
 
  integer, intent(in) :: n
  real*8, intent(in) :: eav(n),fvar(n)
  real*8, intent(out) :: answer(n)
 
  !--------------------------------------------
  !  initialize module, if necessary
 
  if(hatom_flag.eq.0) call hatom_init
 
  !--------------------------------------------
 
  call fs_gyroavg_sigmatimesv(Lfs_DT, eav, fvar, answer, n)
 
end subroutine fusn_bbsigv_DT
!-----------------------------------------------------
subroutine fusn_bbsigv_D3(eav,fvar,answer,n)
 
  use hatom_mod
  implicit NONE
 
  integer, intent(in) :: n
  real*8, intent(in) :: eav(n),fvar(n)
  real*8, intent(out) :: answer(n)
 
  !--------------------------------------------
  !  initialize module, if necessary
 
  if(hatom_flag.eq.0) call hatom_init
 
  !--------------------------------------------
 
  call fs_gyroavg_sigmatimesv(Lfs_D3, eav, fvar, answer, n)
 
end subroutine fusn_bbsigv_D3
!-----------------------------------------------------
subroutine fusn_bbsigv_T3(eav,fvar,answer,n)
 
  use hatom_mod
  implicit NONE
 
  integer, intent(in) :: n
  real*8, intent(in) :: eav(n),fvar(n)
  real*8, intent(out) :: answer(n)
 
  !--------------------------------------------
  !  initialize module, if necessary
 
  if(hatom_flag.eq.0) call hatom_init
 
  !--------------------------------------------
 
  call fs_gyroavg_sigmatimesv(Lfs_T3, eav, fvar, answer, n)
 
end subroutine fusn_bbsigv_T3
