!******************* START FILE TFUN_Z.FOR ; GROUP TESZIG *********************
!==============================================================================
!
!  EVALUATE VARIOUS MAXWELLIAN INTEGRALS
!
real(fp) FUNCTION TFUN_Z(W0,TI)
!
!------------------------------------------------------------------------------
!============
! idecl:  explicitize implicit INTEGER declarations:
  use iso_c_binding, only: fp => c_double
  use physconst_mod, only : zero,half,two,sqpi,VC,zm2tocm2 
  use sigtabl_mod, only : VCFAC,ifun,VI,T,B2
  IMPLICIT NONE
  INTEGER iter,nreact,kk,ierr,j
!============
! idecl:  explicitize implicit REAL declarations:
  real(fp) w0,ti,eps,tmass,bmass,c2,b,&
       vmin,vmax,anorm,fsvcx_z,ans,fsvii_z,fsvcxv_z,fsviiv_z,&
       fsvcxp_z
!
!  ** DMC ** JUNE 1989
!
!    IFUN=2 AND IFUN=3 ARE INTERCHANGEABLE -- SIGMA*V INTEGRAND
!    IFUN=4 AND IFUN=5 ARE INTERCHANGEABLE -- SIGMA*V*V**2 INTEGRAND
!    IFUN=6                                -- SIGMA*V*VX INTEGRAND
!
!    THIS ROUTINE IS PART OF THE SIGTAB PROGRAM; THE ATOMIC REACTION
!  UNDER CONSIDERATION IS NOW STORED IN SIGTAB COMMON; IFUN CONTROLS
!  ONLY THE TYPE OF INTEGRATION BEING DONE.  IFUN DOES *NOT* CONTROL
!  THE REACTION UNDER CONSIDERATION, THOUGH THIS IS LESS THAN OBVIOUS
!  FROM LOOKING AT THE CODE.
!
!    THE CODE STRUCTURE HERE IS RICH WITH HISTORY, AS THESE ROUTINES
!  USED TO BE PART OF THE OBSOLETE TESZIG PROGRAM.  HELIUM ATOMIC
!  PHYSICS HAS SINCE BEEN ADDED TO THE SYSTEM.  SEE SUBROUTINE
!  FSVGEN AND ITS CALLERS E.G. FSVCX AND FSVII WHICH NOW FUNCTION
!  EQUIVALENTLY.
!
!    CROSS-SECTIONS ARE NOW ULTIMATELY FOUND IN THE SUBROUTINE SIGALL
!  FROM THE SIGSUB SUBROUTINE LIBRARY ...
!------------------------------------------------------------------------------
  EXTERNAL FSVCX_Z,FSVII_Z,FSVCXV_Z,FSVIIV_Z,FSVCXP_Z
!
!------------------------------------------------------------------------------
  DATA EPS,ITER,NREACT,KK,IERR/3.e-5_fp,256,4,0,6/
  DATA TMASS,BMASS/938.2592e+3_fp,938.2592e+3_fp/
!
!------------------------------------------------------------------------------
!
  c2=VC*VC*zm2tocm2 
  VI=SQRT(two*C2*W0/TMASS)
  T=half*TMASS/C2
  B2=BMASS/(two*C2*TI)
  B=SQRT(B2)
  VMIN=zero
  VMAX=10.0_fp
  VCFAC=VMAX/(VI+13.42_fp/B)
  ANORM=B/(SQPI*VI)   / VCFAC
  TFUN_Z=zero
!
  IF(IFUN.GT.6) GO TO 5
!
  GO TO(5,200,300,400,500,600) IFUN
!      =================================
!..............
5 CONTINUE
  WRITE(6,10) IFUN
10 FORMAT(1X,'IMPROPER IFUN  IFUN=',I2)
  write(6,1009)
1009 FORMAT(/'  ?? (SIGSUB) ABORT subroutine called ...')
  call bad_exit
!..............
200 CALL GAUS6_Z(VMIN,VMAX,FSVCX_Z,ANS,EPS,ITER,J,IERR)
  TFUN_Z=TFUN_Z+ANS*ANORM
  RETURN
!..............
300 CALL GAUS6_Z(VMIN,VMAX,FSVII_Z,ANS,EPS,ITER,J,IERR)
  TFUN_Z=TFUN_Z+ANS*ANORM
  RETURN
!..............
400 CALL GAUS6_Z(VMIN,VMAX,FSVCXV_Z,ANS,EPS,ITER,J,IERR)
  TFUN_Z=TFUN_Z+ANS*ANORM
  RETURN
!..............
500 CALL GAUS6_Z(VMIN,VMAX,FSVIIV_Z,ANS,EPS,ITER,J,IERR)
  TFUN_Z=TFUN_Z+ANS*ANORM
  RETURN
!..............
600 CALL GAUS6_Z(VMIN,VMAX,FSVCXP_Z,ANS,EPS,ITER,J,IERR)
  TFUN_Z=TFUN_Z+ANS*ANORM
!..............
  RETURN
END FUNCTION TFUN_Z
!
!******************* END FILE TFUN_Z.FOR ; GROUP TESZIG ***********************
! 30Jun2000 fgtok -s r8_precision.sub "r8con.csh conversion"
