module nbatom_mod
  use iso_c_binding, only: fp => c_double
  private :: fp
  save
 
  !  module for monte carlo fast ion code's internal atomic
  !  rate tables ... which have been removed from trcom (port.for comments
  !  copied here)
  !
  !  a step towards modularization ... dmc 27 june 2001
 
  integer :: nbnsvmx                  ! # max no. of energy pts, any specie (excepr thermal)
  integer :: nbnsvmx_f               ! # max no. of energy pts, for fast species gen > '0'
 
  integer, dimension(:), allocatable :: nbnsve
  ! cp ia nbnsve(ibs)                   # of pts in energy grid by species.
 
  integer, dimension(:,:), allocatable :: lbnsve
  ! cp ia lbnsve(irange,ibs)            index of the last grid pt (maximum
  ! c                                   energy) in range ir for species isb
 
  integer, dimension(:), allocatable :: nbnsver
  ! cp ia nbnsver(ibs)                  # of ranges in energy grid by
  ! c                                     species
 
  real(fp), dimension(:,:), allocatable :: eiona,viona
  ! cp ra  viona(3,ib)   fast ion initial velocities by beamline
  ! cp ra  eiona(3,ib)   fast ion initial energies by beamline
 
  real(fp), dimension(:,:), allocatable :: bnsves
  ! cp ra bnsves(ibnsv2,ibs)            energies for n*sigma*v table for
  ! c                                     nutrav per nucleon.
 
  real(fp), dimension(:,:,:), allocatable :: bnsvtot,bnsvexc
  ! cp ra bnsvtot(j,ibnsv2,ibs)         n*sigma*v total-- all thermal species.
  ! cp ra bnsvexc(j,ibnsv2,ibs)         sigmas excitation effect estimate.
  ! c       see nsigexc switch (dmc 4 may 1994)
 
  real(fp), dimension(:,:,:), allocatable :: bnsviif,bnsvief,bnsvizf
  ! cp ra bnsviif(j,ibnsv2,ibs)         n*sigma*v therm. ionization fraction.
  ! cp ra bnsvief(j,ibnsv2,ibs)         n*sigma*v electron ionization fraction.
  ! cp ra bnsvizf(j,ibnsv2,ibs)         n*sigma*v impurity ionization fraction.
 
  real(fp), dimension(:,:,:,:), allocatable :: bnsvcxf
  ! cp ra bnsvcxf(j,ig,ibnsv2,ibs)      n*sigma*v cx fraction by species.
 
  real(fp), dimension(:,:,:,:), allocatable :: bbnsvcx,bbnsvii
  ! cp ra bbnsvcx(imxbzf,ibnsv2,ibs,ibs)  beam-beam n*sigma*v profiles, cx
  ! cp ra bbnsvii(imxbzf,ibnsv2,ibs,ibs)  beam-beam n*sigma*v profiles, ii
 
  real(fp), dimension(:,:,:), allocatable :: bms_exc_2d,sigvnt_2d
  ! n*sigma*v total--all beam ion species for each beam and energy fraction
  ! for excited state model and for ground state model, beam-beam reactions only

  real(fp), dimension(:,:,:), allocatable :: bms_exc_1d,sigvnt_1d
  ! cp ra bms_exc_1d(1:nbnsve(isb0),lcentr:ledge,isb0) excited state 
  ! n*sigma*v total--all thermal+impurities species (no beam species included)
  ! cp ra sigvnt_1d(1:nbnsve(isb0),lcentr:ledge,isb0) ground state 
  ! n*sigma*v total--all thermal+impurities species (no beam species included)
 
 
  integer :: lun_nbatom_mod            ! for messages...
 
  !-----------------------------------------------------
  ! new dmc 6/28/2001
  !  ..tables for cxnsum:  beam ion of known energy
  !      target neutral population of known "t" or 2/3<e>
  !
 
  real(fp), dimension(:,:,:), allocatable :: cxn_thcx_a
  ! cx beyond the plasma bdy  (ig,iengy,isbi)
 
  real(fp), dimension(:,:,:,:), allocatable :: cxn_thcx_wa,cxn_thii_wa
  ! cx & ii, wall neutrals    (ig,j,iengy,isbi)
 
  real(fp), dimension(:,:,:,:), allocatable :: cxn_thcx_ha,cxn_thii_ha
  ! cx & ii, halo neutrals    (ig,j,iengy,isbi)
 
  real(fp), dimension(:,:,:,:), allocatable :: cxn_bbcx_2d,cxn_bbii_2d
  ! cx & ii, beam- nth generation neutrals    (isb0,j,iengy,isbi)
 
  real(fp), dimension(:,:,:), allocatable :: cxn_bbcx,cxn_bbii
  ! cx & ii, beam-beam interactions   (iz0,iengy,izi)
 
  integer :: cxn_zmin          ! min(z) of any fast ion
  integer :: cxn_zmax          ! max(z) of any fast ion
 
  !-----------------------------------------------------
  ! new dmc 6/28/2001
  !  ..tables for btfusn:  for each possible fusion reaction,
  !      beam ion of known energy, target is thermal plasma of temperature t
 
  real(fp), dimension(:,:), allocatable :: btfus_dt,btfus_d3,btfus_ddn, &
       btfus_ddp,btfus_td,btfus_tt,btfus_3d
 
  ! common energy grid for all beam target fusion tables
  ! row "0" of bnsves
  !-----------------------------------------------------
end module nbatom_mod
