module trxpl_gs2_module
  !
  !  MODULE to help with acquisition of TRANSP data for GS2
  !
 
  implicit NONE
  save

  !--  TRANSP run identification information

  character*200 :: transp_path = ' '
  real*8 :: transp_time = 0.0d0
  real*8 :: transp_delt = 0.0d0
  real*8 :: transp_x = 0.0d0
 
  !--  file information

  character*128 :: mpath0,mpath ! (untranslated, translated) template file path
  character*128 :: opath0,opath ! (untranslated, translated) namelist file path

  character*50 :: hostname
  character*50 :: username

  character*50 :: ofile_prefix  ! default output filename: prefix
  character*50 :: ofile_suffix  ! default output filename: suffix

  !--  basic scalar information
 
  integer, parameter :: max_species = 100
 
  integer :: num_species = 0
 
  integer :: num_refn = 1     ! density reference specie, electrons by default.
  integer :: num_reft = 1     ! temperature ref. specie, electrons by default.
  character*2 :: tref_lbl     ! "Ti" or "Te"
  real*8 :: tref              ! actual reference temperature, KeV
  real*8 :: nref              ! actual reference density, m**-3

  real*8 :: ne_grad           ! unrenormalized grad(ne) (for testing)
  real*8 :: sumnz_grad        ! unrenormalized grad(nZ) sum (for testing)
 
  real*8 :: mass_ref = 2.0d0     ! reference mass (AMU, usually:  deuterons)
 
  real*8 :: aminor               ! midplane minor radius (m)
 
  real*8 :: rbzvac               ! vac. R*Bt = g @ bdy.
  real*8 :: r0
  real*8 :: b_t0                 ! (R*Bt)/R0, R0=(Rmin+Rmax)/2, LCFS
 
  !-- Beta as defined per Martha Redi's request
  !   dmc Dec 2002
 
  real*8 :: beta                 ! 403.0*nref*Tref/B_T0/1.d5
 
  !--  profile interpolation option
 
  integer :: iorder              ! 1 for Hermite, 2 for Spline fits
 
  !--  specie information -- physical units
 
  integer id_te,id_ne,id_ti,id_tx,id_tmj,id_rho,id_zeff  ! xplasma id's
 
  real*8 :: zeff_tr,zeff_calc    ! Zeff from TRANSP; Zeff from sum(nZ)/ne
  real*8 :: renorm_nz,renorm_gradnz  ! quasineutrality renormalizations
 
  real*8, dimension(max_species) :: Aplas
  real*8, dimension(max_species) :: Zplas
  integer id_zprof(max_species)  ! Z profiles (for aggregate ion groups)
  integer id_aprof(max_species)  ! A profiles (for aggregate ion groups)
 
  real*8, dimension(max_species) :: Tconv  ! T profile conversion factor
 
  integer id_norig(max_species)  ! spline id -- original density data
  integer id_nsmoo(max_species)  ! spline id -- smoothed density data
  logical nsmoo(max_species)     ! flag to use smoothed data
  real*8 :: dx_smooth_n(max_species)  ! smoothing parameters
 
  integer id_torig(max_species)  ! spline id -- original temperature data
  integer id_tsmoo(max_species)  ! spline id -- smoothed temperature data
  logical tsmoo(max_species)     ! flag to use smoothed data
  real*8 :: dx_smooth_t(max_species)  ! smoothing parameters
 
  logical gsmoo                  ! .TRUE. if ANY profile has been smoothed
  logical gaggr                  ! .TRUE. if ANY ions have been "aggregated".

  logical tmjtx                  ! .TRUE. if TMJ & TX are used, allowing
                                 ! the thermal bulk ion and thermal impurity
                                 ! temperatures to be different
 
  integer ltype(max_species)     ! species type code
                                 !  0 - electrons
                                 !  1 - thermal ions non-impurity
                                 !  2 - impurity
                                 !  3 - beam ion
                                 !  4 - RF tail ions
                                 !  5 - fusion products

  logical fast_aggr              ! .TRUE. if thermal & fast species may be
                                 ! aggregated (default answer: no; user
                                 ! override is allowed).
 
  character*30 slabel(max_species) ! label for each specie
 
  !
  !  GS2 output vectors n/ne, T/Te, m/mref, Z, (1/T)*(dT/drho),
  !                     (1/n)*(dn/drho), "uprime", and collisionality
 
  real*8 nvec(max_species)
  real*8 tvec(max_species)
  real*8 avec(max_species)
  real*8 zvec(max_species)
  real*8 npvec(max_species)
  real*8 tpvec(max_species)
  real*8 upvec(max_species)
  real*8 nuvec(max_species)
 
  character*10, parameter :: zeff_lbl = 'zeff=     '
  character*10, parameter :: num_lbl  = 'nspec=    '
  character*10, parameter :: nvec_lbl = 'dens=     '
  character*10, parameter :: tvec_lbl = 'temp=     '
  character*10, parameter :: avec_lbl = 'mass=     '
  character*10, parameter :: zvec_lbl = 'z=        '
  character*10, parameter :: npvec_lbl= 'fprim=    '
  character*10, parameter :: tpvec_lbl= 'tprim=    '
  character*10, parameter :: upvec_lbl= 'uprim=    '
  character*10, parameter :: nuvec_lbl= 'vnewk=    '
  character*10, parameter :: beta_lbl=  'beta=     '
  character*10, parameter :: irho_lbl=  'irho=     '
  character*10, parameter :: iflux_lbl= 'iflux=    '
  character*10, parameter :: lqeq_lbl=  'local_eq= '
  character*10, parameter :: irhoc_lbl= 'rhoc=     '
 
  character*24, parameter :: nlist_zeff = 'parameters'
  character*24, parameter :: nlist_nspc = 'species_knobs'
  character*24, parameter :: nlist_root = 'species_parameters_'
  character*24, parameter :: nlist_grid = 'theta_grid_eik_knobs'
  character*24, parameter :: nlist_grd2 = 'theta_grid_parameters'
 
  !
  contains
    subroutine trxpl_gs2_reset

      transp_path = ' '
      transp_time = 0.0d0
      transp_delt = 0.0d0
      transp_x = 0.0d0

    end subroutine trxpl_gs2_reset
end module trxpl_gs2_module
