module nbi_halo_mod_def
 
  use iso_c_binding, only: fp => c_double
  implicit none

  save
  public
  logical :: il_3dhalo_den ! if 3d halo model is set
                           ! and all beams have been set in 3d-boxes
                           ! then il_3dhalo_den will be set .true.
                           ! and halo density, vol av halo e and 
                           ! vol av halo omega from 3d halo model 
                           ! (not frantic one, set in parms.for)
                           ! will be used
  integer :: maxpts=50  ! standard grid array size for structure
 
  type :: trhalo
 
     integer :: maxpts    ! max dimension of intercept and vector arrays
 
     integer :: guard     ! =12345 if track arrays are allocated.
 
     
     real(fp), dimension(3) :: pta,ptb ! track start & stop points (as used)
                                     ! in cartesian coordinates [x,y,z] [m,m,m]
     real(fp) :: weight   ! track weight
     integer :: idbox   ! box id
     integer :: izone_pl(2) !track zone # when neutral enters/exits plasma
     integer :: idgen   ! generation id
     integer :: ipitch  ! pitch angle grid index, is not zero for a fast neutral of gen.>=1
                        ! for thermal and fast of "0" gen. equals 0
     integer :: igyro   ! gyro angle grid index, is not zero for a fast neutral of gen.>=1
                        ! for thermal and fast of "0" gen. equals 0
     real(fp) :: zspecies ! z of neutral associated with track
     real(fp) :: aspecies ! a of neutral associated with track
     real(fp) :: vneut    ! velocity of neutral [m/sec] at start point, lab frame
     character*5 :: type! type of species: 'fastb''fastf'  or 'therm'

     ! data on box zones crossed
     real(fp), dimension(:), allocatable :: xlngtk    ! segment lengths [m]
     real(fp), dimension(:), allocatable :: pdep      ! survival probability to end of box zone
     real(fp), dimension(:), allocatable :: dkappa    ! decay factor
 
  end type trhalo

  type(trhalo),allocatable,dimension(:) :: itrackh          ! xstraln track data structure
  
  logical,allocatable,dimension(:) :: itrackh_rqinit ! needs-initialization flag
  
  integer, dimension(:), allocatable :: indxs 
  real(fp), dimension(:), allocatable :: drndm
#ifdef __DEBUG
  real(fp), dimension(:,:,:), allocatable :: tuben0_g !neutral density in tube by generations (up to 5). "0" generation is a beam neutral density.
#endif
end module nbi_halo_mod_def
