module EOS_Omni_Module

  implicit none

  ! conversion factors between cgs and M_Sun = c = G = 1
  ! see EOS_Omni/doc/units.py
  real*8,parameter :: rho_gf = 1.61887093132742d-18
  real*8,parameter :: press_gf = 1.80123683248503d-39
  real*8,parameter :: eps_gf = 1.11265005605362d-21
  real*8,parameter :: time_gf = 2.03040204956746d05
  real*8,parameter :: mass_gf =  5.02916918125126d-34
  real*8,parameter :: length_gf = 6.77269222552442d-06
  ! conversion between temperature in K and in MeV
  real*8,parameter :: temp_gf = 8.617332478d-11
  
  ! Inverses of the numbers above, calculated manually instead of by
  ! the compiler
  
  real*8,parameter :: inv_rho_gf = 6.17714470405638d17
  real*8,parameter :: inv_press_gf = 5.55174079257738d38
  real*8,parameter :: inv_eps_gf = 8.98755178736818d20
  real*8,parameter :: inv_time_gf = 4.92513293223396d-6
  real*8,parameter :: inv_mass_gf = 1.98840000000000d33
  real*8,parameter :: inv_length_gf = 1.47651770773117d05
  real*8,parameter :: inv_temp_gf = 1.1604519177518033d10

  real*8,parameter :: clite = 2.99792458d10
  real*8,parameter :: cliteinv2 = 1.11265005605362d-21
  real*8,parameter :: kBerg   = 1.38064852e-16
  real*8,parameter :: amu     = 1.6605402d-24
  
  ! eos limits
  ! the default limits are set in EOS_Omni_Startup
  ! must be reset when EOS with more specific limits is initialized
  real*8 :: eos_rhomin,eos_rhomax
  real*8 :: eos_tempmin,eos_tempmax
  real*8 :: eos_yemin,eos_yemax
  real*8 :: eos_epsmin,eos_epsmax
!  real*8 :: eos_pressmin,eos_pressmax

  ! Helmholtz EOS
  ! parameters for table distributed with FLASH 4.3 and 3.3
  integer, parameter :: HEOSIMAX = 211, HEOSJMAX = 71
  ! parameters for table distributed with version downloaded from http://cococubed.asu.edu/code_pages/eos.shtml (not to be used here)
  !integer,parameter :: EOSIMAX=271,EOSJMAX=101
  
  ! Helmholtz EOS table quantities
  real*8, allocatable, dimension(:,:) :: heos_f, heos_ft, heos_ftt, heos_fd, heos_fdd, &
       heos_fdt, heos_fddt, heos_fdtt, heos_fddtt, &
       heos_dpdf, heos_dpdft, heos_dpdfd, heos_dpdfdt, &
       heos_ef, heos_eft, heos_efd, heos_efdt, &
       heos_xf, heos_xft, heos_xfd, heos_xfdt
       
  real*8 :: heos_tlo, heos_tstpi
  real*8 :: heos_dlo, heos_dstpi
  
  real*8, allocatable, dimension(:) :: heos_dt,heos_dtSqr,heos_dtInv,heos_dtSqrInv,heos_t
  real*8, allocatable, dimension(:) :: heos_dd,heos_ddSqr,heos_ddInv,heos_ddSqrInv,heos_d     
       
  ! further Helmholtz EOS parameters
  real*8, parameter :: heos_coulombMult = 1.0d0
  real*8, parameter :: Qalpha = 28.29566*1.60217648740d-6
  
end module EOS_Omni_Module
