























































































































 


































































































































































 








































































































































































































 




























































 










 








































































































































































































































 










                                
                                

                                
                                

                                
                                

                                

























































































subroutine EOS_Omni_EOS_Press(eoskey,keytemp,rf_precision,npoints,&
                              rho,eps,temp,ye,press,keyerr,anyerr)

  use EOS_Omni_Module
  implicit none
  REAL*8 barotropiceos_gammath
  integer, parameter :: cctki_use_barotropiceos_gammath = kind(barotropiceos_gammath)
  REAL*8 gl_gamma
  integer, parameter :: cctki_use_gl_gamma = kind(gl_gamma)
  REAL*8 gl_k
  integer, parameter :: cctki_use_gl_k = kind(gl_k)
  REAL*8 hybrid_gamma (10)
  integer, parameter :: cctki_use_hybrid_gamma = kind(hybrid_gamma)
  REAL*8 hybrid_gamma1
  integer, parameter :: cctki_use_hybrid_gamma1 = kind(hybrid_gamma1)
  REAL*8 hybrid_gamma2
  integer, parameter :: cctki_use_hybrid_gamma2 = kind(hybrid_gamma2)
  REAL*8 hybrid_gamma_th
  integer, parameter :: cctki_use_hybrid_gamma_th = kind(hybrid_gamma_th)
  REAL*8 hybrid_k0
  integer, parameter :: cctki_use_hybrid_k0 = kind(hybrid_k0)
  REAL*8 hybrid_k1
  integer, parameter :: cctki_use_hybrid_k1 = kind(hybrid_k1)
  REAL*8 hybrid_rho (9)
  integer, parameter :: cctki_use_hybrid_rho = kind(hybrid_rho)
  REAL*8 hybrid_rho_nuc
  integer, parameter :: cctki_use_hybrid_rho_nuc = kind(hybrid_rho_nuc)
  REAL*8 poly_gamma
  integer, parameter :: cctki_use_poly_gamma = kind(poly_gamma)
  REAL*8 poly_gamma_initial
  integer, parameter :: cctki_use_poly_gamma_initial = kind(poly_gamma_initial)
  REAL*8 poly_k
  integer, parameter :: cctki_use_poly_k = kind(poly_k)
  integer*8 barotropiceos_table_name
  integer, parameter :: cctki_use_barotropiceos_table_name = kind(barotropiceos_table_name)
  integer*8 coldeos_table_name
  integer, parameter :: cctki_use_coldeos_table_name = kind(coldeos_table_name)
  integer*8 dump_nuceos_table_name
  integer, parameter :: cctki_use_dump_nuceos_table_name = kind(dump_nuceos_table_name)
  integer*8 nuceos_table_name
  integer, parameter :: cctki_use_nuceos_table_name = kind(nuceos_table_name)
  INTEGER*4 barotropiceos_read_table
  integer, parameter :: cctki_use_barotropiceos_read_table = kind(barotropiceos_read_table)
  INTEGER*4 barotropiceos_use_thermal_gamma_law
  integer, parameter :: cctki_use_barotropiceos_use_thermal_gamma_law = kind(barotropiceos_use_thermal_gamma_law)
  INTEGER*4 coldeos_read_table
  integer, parameter :: cctki_use_coldeos_read_table = kind(coldeos_read_table)
  INTEGER*4 coldeos_use_thermal_gamma_law
  integer, parameter :: cctki_use_coldeos_use_thermal_gamma_law = kind(coldeos_use_thermal_gamma_law)
  INTEGER*4 do_energy_shift
  integer, parameter :: cctki_use_do_energy_shift = kind(do_energy_shift)
  INTEGER*4 dump_nuceos_table
  integer, parameter :: cctki_use_dump_nuceos_table = kind(dump_nuceos_table)
  INTEGER*4 n_pieces
  integer, parameter :: cctki_use_n_pieces = kind(n_pieces)
  INTEGER*4 nuceos_read_table
  integer, parameter :: cctki_use_nuceos_read_table = kind(nuceos_read_table)
  INTEGER*4 read_table_on_single_process
  integer, parameter :: cctki_use_read_table_on_single_process = kind(read_table_on_single_process)
  INTEGER*4 reader_process
  integer, parameter :: cctki_use_reader_process = kind(reader_process)
  COMMON /EOS_Omnirest/barotropiceos_gammath, gl_gamma, gl_k, hybrid_gamma, hybrid_gamma1, hybrid_gamma2, hybrid_gamma_th, hybrid_k&
  &0, hybrid_k1, hybrid_rho, hybrid_rho_nuc, poly_gamma, poly_gamma_initial, poly_k, barotropiceos_table_name, coldeos_table_name, &
  &dump_nuceos_table_name, nuceos_table_name, barotropiceos_read_table, barotropiceos_use_thermal_gamma_law, coldeos_read_table, co&
  &ldeos_use_thermal_gamma_law, do_energy_shift, dump_nuceos_table, n_pieces, nuceos_read_table, read_table_on_single_process, read&
  &er_process
  REAL*8 CCTKH5
  integer, parameter :: cctki_use_CCTKH5 = kind(CCTKH5)
  REAL*8 CCTKH19
  integer, parameter :: cctki_use_CCTKH19 = kind(CCTKH19)
  REAL*8 CCTKH29
  integer, parameter :: cctki_use_CCTKH29 = kind(CCTKH29)
  REAL*8 CCTKH31
  integer, parameter :: cctki_use_CCTKH31 = kind(CCTKH31)
  REAL*8 CCTKH33
  integer, parameter :: cctki_use_CCTKH33 = kind(CCTKH33)
  REAL*8 CCTKH35
  integer, parameter :: cctki_use_CCTKH35 = kind(CCTKH35)
  REAL*8 CCTKH37
  integer, parameter :: cctki_use_CCTKH37 = kind(CCTKH37)
  REAL*8 CCTKH39
  integer, parameter :: cctki_use_CCTKH39 = kind(CCTKH39)
  REAL*8 CCTKH41
  integer, parameter :: cctki_use_CCTKH41 = kind(CCTKH41)
  REAL*8 CCTKH43
  integer, parameter :: cctki_use_CCTKH43 = kind(CCTKH43)
  REAL*8 CCTKH45
  integer, parameter :: cctki_use_CCTKH45 = kind(CCTKH45)
  integer*8 CCTKH2
  integer, parameter :: cctki_use_CCTKH2 = kind(CCTKH2)
  integer*8 CCTKH3
  integer, parameter :: cctki_use_CCTKH3 = kind(CCTKH3)
  integer*8 CCTKH6
  integer, parameter :: cctki_use_CCTKH6 = kind(CCTKH6)
  integer*8 CCTKH9
  integer, parameter :: cctki_use_CCTKH9 = kind(CCTKH9)
  integer*8 CCTKH10
  integer, parameter :: cctki_use_CCTKH10 = kind(CCTKH10)
  integer*8 CCTKH11
  integer, parameter :: cctki_use_CCTKH11 = kind(CCTKH11)
  integer*8 CCTKH15
  integer, parameter :: cctki_use_CCTKH15 = kind(CCTKH15)
  integer*8 out_dir
  integer, parameter :: cctki_use_out_dir = kind(out_dir)
  integer*8 CCTKH21
  integer, parameter :: cctki_use_CCTKH21 = kind(CCTKH21)
  integer*8 CCTKH22
  integer, parameter :: cctki_use_CCTKH22 = kind(CCTKH22)
  integer*8 CCTKH23
  integer, parameter :: cctki_use_CCTKH23 = kind(CCTKH23)
  integer*8 CCTKH25
  integer, parameter :: cctki_use_CCTKH25 = kind(CCTKH25)
  integer*8 CCTKH47
  integer, parameter :: cctki_use_CCTKH47 = kind(CCTKH47)
  integer*8 CCTKH49
  integer, parameter :: cctki_use_CCTKH49 = kind(CCTKH49)
  integer*8 CCTKH51
  integer, parameter :: cctki_use_CCTKH51 = kind(CCTKH51)
  integer*8 CCTKH53
  integer, parameter :: cctki_use_CCTKH53 = kind(CCTKH53)
  integer*8 CCTKH54
  integer, parameter :: cctki_use_CCTKH54 = kind(CCTKH54)
  integer*8 CCTKH57
  integer, parameter :: cctki_use_CCTKH57 = kind(CCTKH57)
  INTEGER*4 CCTKH0
  integer, parameter :: cctki_use_CCTKH0 = kind(CCTKH0)
  INTEGER*4 CCTKH1
  integer, parameter :: cctki_use_CCTKH1 = kind(CCTKH1)
  INTEGER*4 CCTKH4
  integer, parameter :: cctki_use_CCTKH4 = kind(CCTKH4)
  INTEGER*4 CCTKH7
  integer, parameter :: cctki_use_CCTKH7 = kind(CCTKH7)
  INTEGER*4 CCTKH8
  integer, parameter :: cctki_use_CCTKH8 = kind(CCTKH8)
  INTEGER*4 CCTKH12
  integer, parameter :: cctki_use_CCTKH12 = kind(CCTKH12)
  INTEGER*4 CCTKH13
  integer, parameter :: cctki_use_CCTKH13 = kind(CCTKH13)
  INTEGER*4 CCTKH14
  integer, parameter :: cctki_use_CCTKH14 = kind(CCTKH14)
  INTEGER*4 CCTKH16
  integer, parameter :: cctki_use_CCTKH16 = kind(CCTKH16)
  INTEGER*4 CCTKH17
  integer, parameter :: cctki_use_CCTKH17 = kind(CCTKH17)
  INTEGER*4 CCTKH18
  integer, parameter :: cctki_use_CCTKH18 = kind(CCTKH18)
  INTEGER*4 CCTKH20
  integer, parameter :: cctki_use_CCTKH20 = kind(CCTKH20)
  INTEGER*4 CCTKH24
  integer, parameter :: cctki_use_CCTKH24 = kind(CCTKH24)
  INTEGER*4 CCTKH26
  integer, parameter :: cctki_use_CCTKH26 = kind(CCTKH26)
  INTEGER*4 CCTKH27
  integer, parameter :: cctki_use_CCTKH27 = kind(CCTKH27)
  INTEGER*4 CCTKH28
  integer, parameter :: cctki_use_CCTKH28 = kind(CCTKH28)
  INTEGER*4 CCTKH30
  integer, parameter :: cctki_use_CCTKH30 = kind(CCTKH30)
  INTEGER*4 CCTKH32
  integer, parameter :: cctki_use_CCTKH32 = kind(CCTKH32)
  INTEGER*4 CCTKH34
  integer, parameter :: cctki_use_CCTKH34 = kind(CCTKH34)
  INTEGER*4 CCTKH36
  integer, parameter :: cctki_use_CCTKH36 = kind(CCTKH36)
  INTEGER*4 CCTKH38
  integer, parameter :: cctki_use_CCTKH38 = kind(CCTKH38)
  INTEGER*4 CCTKH40
  integer, parameter :: cctki_use_CCTKH40 = kind(CCTKH40)
  INTEGER*4 CCTKH42
  integer, parameter :: cctki_use_CCTKH42 = kind(CCTKH42)
  INTEGER*4 CCTKH44
  integer, parameter :: cctki_use_CCTKH44 = kind(CCTKH44)
  INTEGER*4 CCTKH46
  integer, parameter :: cctki_use_CCTKH46 = kind(CCTKH46)
  INTEGER*4 CCTKH48
  integer, parameter :: cctki_use_CCTKH48 = kind(CCTKH48)
  INTEGER*4 CCTKH50
  integer, parameter :: cctki_use_CCTKH50 = kind(CCTKH50)
  INTEGER*4 CCTKH52
  integer, parameter :: cctki_use_CCTKH52 = kind(CCTKH52)
  INTEGER*4 CCTKH55
  integer, parameter :: cctki_use_CCTKH55 = kind(CCTKH55)
  INTEGER*4 CCTKH56
  integer, parameter :: cctki_use_CCTKH56 = kind(CCTKH56)
  COMMON /IOrest/CCTKH5, CCTKH19, CCTKH29, CCTKH31, CCTKH33, CCTKH35, CCTKH37, CCTKH39, CCTKH41, CCTKH43, CCTKH45, CCTKH2, CCTKH3, &
  &CCTKH6, CCTKH9, CCTKH10, CCTKH11, CCTKH15, out_dir, CCTKH21, CCTKH22, CCTKH23, CCTKH25, CCTKH47, CCTKH49, CCTKH51, CCTKH53, CCTK&
  &H54, CCTKH57, CCTKH0, CCTKH1, CCTKH4, CCTKH7, CCTKH8, CCTKH12, CCTKH13, CCTKH14, CCTKH16, CCTKH17, CCTKH18, CCTKH20, CCTKH24, CC&
  &TKH26, CCTKH27, CCTKH28, CCTKH30, CCTKH32, CCTKH34, CCTKH36, CCTKH38, CCTKH40, CCTKH42, CCTKH44, CCTKH46, CCTKH48, CCTKH50, CCTK&
  &H52, CCTKH55, CCTKH56
  

  INTEGER*4, intent(in)     :: eoskey,keytemp,npoints
  INTEGER*4, intent(out)    :: keyerr(npoints)
  INTEGER*4, intent(out)    :: anyerr
  REAL*8, intent(in)    :: rf_precision
  REAL*8, intent(in)    :: rho(npoints),ye(npoints)
  REAL*8, intent(inout) :: eps(npoints), temp(npoints)
  REAL*8, intent(out)   :: press(npoints)

  
  integer          :: i,p
  character(256)   :: warnstring
  real*8           :: hybrideos_local_gamma, hybrideos_local_k
  real*8           :: hybrideos_local_eps, hybrideos_p_poly, hybrideos_p_th
  real*8,parameter :: zero = 0.0d0
  
  real*8, dimension(1) :: xrho,xye,xtemp,xenr,xent
  real*8, dimension(1) :: xprs,xmunu,xcs2
  real*8, dimension(1) :: xdedt,xdpderho,xdpdrhoe
  
  integer :: ir
  real*8 :: press_cold, press_th
  real*8 :: eps_cold, eps_th
  real*8 :: gamma

  anyerr    = 0
  keyerr(:) = 0

  select case (eoskey)
     case (1)
        
        if(keytemp.eq.1) then
           do i=1,npoints
              eps(i) = press_gf * poly_k_cgs * &
                   (rho(i)*inv_rho_gf)**(poly_gamma) / &
                   (poly_gamma - 1.0d0) / rho(i)
           enddo
        endif
        do i=1,npoints
           press(i) = press_gf * poly_k_cgs * &
                (rho(i)*inv_rho_gf)**poly_gamma
        enddo
     case (2)
        
        if(keytemp.eq.1) then
           do i=1,npoints
              eps(i) = press_gf * gl_k_cgs * &
                   (rho(i)*inv_rho_gf)**(gl_gamma) / &
                   (gl_gamma - 1.0d0) / rho(i)
           enddo
        endif
        do i=1,npoints
           press(i) = (gl_gamma - 1.0d0) * rho(i) * eps(i)

        enddo
     case (3)
        
        do i=1,npoints
           hybrideos_local_gamma = hybrideos_gamma(1)
           hybrideos_local_k = hybrideos_k(1)
           hybrideos_local_eps = hybrideos_eps(1)
           if (n_pieces .gt. 1) then
              do p = 1,n_pieces-1
                 if (rho(i) .gt. hybrideos_rho(p)) then
                    hybrideos_local_gamma = hybrideos_gamma(p+1)
                    hybrideos_local_k = hybrideos_k(p+1)
                    hybrideos_local_eps = hybrideos_eps(p+1)
                 end if
              end do
           end if
           if (keytemp .eq. 1) then
              
              eps(i)=hybrideos_local_k/(hybrideos_local_gamma - 1.0)*rho(i)**(hybrideos_local_gamma - 1.0) + hybrideos_local_eps
           end if
           hybrideos_p_poly = hybrideos_local_k * (rho(i))**hybrideos_local_gamma
           hybrideos_p_th = (hybrid_gamma_th-1.0)* (rho(i)*eps(i) - &
                hybrideos_p_poly/(hybrideos_local_gamma-1) - &
                hybrideos_local_eps * rho(i))
           hybrideos_p_th = max(zero, hybrideos_p_th)
           press(i) = hybrideos_p_poly + hybrideos_p_th
        enddo

     case (4)
        
        if(keytemp.eq.1) then
           call nuc_eos_m_kt1_press_eps(npoints,rho,temp,ye,&
                eps,press,keyerr,anyerr)
        else if(keytemp.eq.0) then
           call nuc_eos_m_kt0_press(npoints,rho,temp,ye,eps,press,&
                rf_precision,keyerr,anyerr)
        else
           call CCTK_Error(110,"EOS_Omni_SingleVarCalls.F90","EOS_Omni","This keytemp is not suppported!")
           STOP
        endif
     case (5)
        
        do i=1,npoints
           if(rho(i).lt.coldeos_rhomin) then
              press(i) = coldeos_low_kappa * rho(i)**coldeos_low_gamma
              eps(i) = press(i) / (coldeos_low_gamma - 1.0) / rho(i) 
              cycle
           else if(rho(i).gt.coldeos_rhomax) then
              keyerr(i) = 103
              anyerr = 1
           else
              xrho(1) = log10(rho(i))
              ir = 2 + INT( (xrho(1) - coldeos_logrho(1) - 1.0d-10) * coldeos_dlrhoi )
           endif
           ir = max(2, min(ir,coldeos_nrho))

           gamma = (coldeos_gamma(ir) - coldeos_gamma(ir-1)) / &
                (coldeos_logrho(ir) - coldeos_logrho(ir-1)) * &
                (xrho(1) - coldeos_logrho(ir-1)) + coldeos_gamma(ir-1)

           eps_cold = (coldeos_eps(ir) - coldeos_eps(ir-1)) / &
                    (coldeos_logrho(ir) - coldeos_logrho(ir-1)) * &
                    (xrho(1) - coldeos_logrho(ir-1)) + coldeos_eps(ir-1)

           if(keytemp.eq.0) then
              eps_th = max(0.0d0,eps(i) - eps_cold)
           else if (keytemp.eq.1) then
              eps_th = 0.0d0
              eps(i) = eps_cold
           endif

           press_cold = coldeos_kappa * rho(i)**gamma
           press_th = coldeos_thfac*(coldeos_gammath - 1.0d0)*rho(i)*eps_th
           press(i) = press_cold + press_th
        enddo

     case (6)
        
        do i=1,npoints
           if(rho(i).lt.barotropiceos_rhomin) then
              press(i) = barotropiceos_low_kappa * rho(i)**barotropiceos_low_gamma
              eps(i) = press(i) / (barotropiceos_low_gamma - 1.0) / rho(i) 
              cycle
           else if(rho(i).gt.barotropiceos_rhomax) then
              keyerr(i) = 103
              anyerr = 1
           else
              xrho(1) = log10(rho(i))
              ir = 2 + &
                   INT( (xrho(1) - barotropiceos_logrho(1) - 1.0d-10) &
                   * barotropiceos_dlrhoi )
           endif
           ir = max(2, min(ir,barotropiceos_nrho))

           xprs(1) = (barotropiceos_logpress(ir) - barotropiceos_logpress(ir-1)) / &
                (barotropiceos_logrho(ir) - barotropiceos_logrho(ir-1)) * &
                (xrho(1) - barotropiceos_logrho(ir-1)) + barotropiceos_logpress(ir-1)

           xenr(1) = (barotropiceos_logeps(ir) - barotropiceos_logeps(ir-1)) / &
                (barotropiceos_logrho(ir) - barotropiceos_logrho(ir-1)) * &
                (xrho(1) - barotropiceos_logrho(ir-1)) + barotropiceos_logeps(ir-1)

           xtemp(1) = (barotropiceos_temp(ir) - barotropiceos_temp(ir-1)) / &
                (barotropiceos_logrho(ir) - barotropiceos_logrho(ir-1)) * &
                (xrho(1) - barotropiceos_logrho(ir-1)) + barotropiceos_temp(ir-1)

           xye(1) = (barotropiceos_ye(ir) - barotropiceos_ye(ir-1)) / &
                (barotropiceos_logrho(ir) - barotropiceos_logrho(ir-1)) * &
                (xrho(1) - barotropiceos_logrho(ir-1)) + barotropiceos_ye(ir-1)

           press_cold = 10.0**xprs(1)
           eps_cold = 10.0**xenr(1) - barotropiceos_energyshift

           if(keytemp.eq.0) then
              eps_th = max(0.0d0,eps(i) - eps_cold)
           else if (keytemp.eq.1) then
              eps_th = 0.0d0
              eps(i) = eps_cold
           endif
           press_th = coldeos_thfac*(barotropiceos_gammath - 1.0d0)*rho(i)*eps_th
           press(i) = press_cold + press_th

        enddo

     case DEFAULT
        write(warnstring,*) "eoskey ",eoskey," not implemented!"
        call CCTK_Error(199,"EOS_Omni_SingleVarCalls.F90","EOS_Omni",warnstring)
        STOP
     end select

end subroutine EOS_Omni_EOS_Press

subroutine EOS_Omni_EOS_PressOMP(eoskey,keytemp,rf_precision,npoints,&
                              rho,eps,temp,ye,press,keyerr,anyerr)

  use EOS_Omni_Module

  use OMP_LIB


  implicit none
  REAL*8 barotropiceos_gammath
  integer, parameter :: cctki_use_barotropiceos_gammath = kind(barotropiceos_gammath)
  REAL*8 gl_gamma
  integer, parameter :: cctki_use_gl_gamma = kind(gl_gamma)
  REAL*8 gl_k
  integer, parameter :: cctki_use_gl_k = kind(gl_k)
  REAL*8 hybrid_gamma (10)
  integer, parameter :: cctki_use_hybrid_gamma = kind(hybrid_gamma)
  REAL*8 hybrid_gamma1
  integer, parameter :: cctki_use_hybrid_gamma1 = kind(hybrid_gamma1)
  REAL*8 hybrid_gamma2
  integer, parameter :: cctki_use_hybrid_gamma2 = kind(hybrid_gamma2)
  REAL*8 hybrid_gamma_th
  integer, parameter :: cctki_use_hybrid_gamma_th = kind(hybrid_gamma_th)
  REAL*8 hybrid_k0
  integer, parameter :: cctki_use_hybrid_k0 = kind(hybrid_k0)
  REAL*8 hybrid_k1
  integer, parameter :: cctki_use_hybrid_k1 = kind(hybrid_k1)
  REAL*8 hybrid_rho (9)
  integer, parameter :: cctki_use_hybrid_rho = kind(hybrid_rho)
  REAL*8 hybrid_rho_nuc
  integer, parameter :: cctki_use_hybrid_rho_nuc = kind(hybrid_rho_nuc)
  REAL*8 poly_gamma
  integer, parameter :: cctki_use_poly_gamma = kind(poly_gamma)
  REAL*8 poly_gamma_initial
  integer, parameter :: cctki_use_poly_gamma_initial = kind(poly_gamma_initial)
  REAL*8 poly_k
  integer, parameter :: cctki_use_poly_k = kind(poly_k)
  integer*8 barotropiceos_table_name
  integer, parameter :: cctki_use_barotropiceos_table_name = kind(barotropiceos_table_name)
  integer*8 coldeos_table_name
  integer, parameter :: cctki_use_coldeos_table_name = kind(coldeos_table_name)
  integer*8 dump_nuceos_table_name
  integer, parameter :: cctki_use_dump_nuceos_table_name = kind(dump_nuceos_table_name)
  integer*8 nuceos_table_name
  integer, parameter :: cctki_use_nuceos_table_name = kind(nuceos_table_name)
  INTEGER*4 barotropiceos_read_table
  integer, parameter :: cctki_use_barotropiceos_read_table = kind(barotropiceos_read_table)
  INTEGER*4 barotropiceos_use_thermal_gamma_law
  integer, parameter :: cctki_use_barotropiceos_use_thermal_gamma_law = kind(barotropiceos_use_thermal_gamma_law)
  INTEGER*4 coldeos_read_table
  integer, parameter :: cctki_use_coldeos_read_table = kind(coldeos_read_table)
  INTEGER*4 coldeos_use_thermal_gamma_law
  integer, parameter :: cctki_use_coldeos_use_thermal_gamma_law = kind(coldeos_use_thermal_gamma_law)
  INTEGER*4 do_energy_shift
  integer, parameter :: cctki_use_do_energy_shift = kind(do_energy_shift)
  INTEGER*4 dump_nuceos_table
  integer, parameter :: cctki_use_dump_nuceos_table = kind(dump_nuceos_table)
  INTEGER*4 n_pieces
  integer, parameter :: cctki_use_n_pieces = kind(n_pieces)
  INTEGER*4 nuceos_read_table
  integer, parameter :: cctki_use_nuceos_read_table = kind(nuceos_read_table)
  INTEGER*4 read_table_on_single_process
  integer, parameter :: cctki_use_read_table_on_single_process = kind(read_table_on_single_process)
  INTEGER*4 reader_process
  integer, parameter :: cctki_use_reader_process = kind(reader_process)
  COMMON /EOS_Omnirest/barotropiceos_gammath, gl_gamma, gl_k, hybrid_gamma, hybrid_gamma1, hybrid_gamma2, hybrid_gamma_th, hybrid_k&
  &0, hybrid_k1, hybrid_rho, hybrid_rho_nuc, poly_gamma, poly_gamma_initial, poly_k, barotropiceos_table_name, coldeos_table_name, &
  &dump_nuceos_table_name, nuceos_table_name, barotropiceos_read_table, barotropiceos_use_thermal_gamma_law, coldeos_read_table, co&
  &ldeos_use_thermal_gamma_law, do_energy_shift, dump_nuceos_table, n_pieces, nuceos_read_table, read_table_on_single_process, read&
  &er_process
  REAL*8 CCTKH5
  integer, parameter :: cctki_use_CCTKH5 = kind(CCTKH5)
  REAL*8 CCTKH19
  integer, parameter :: cctki_use_CCTKH19 = kind(CCTKH19)
  REAL*8 CCTKH29
  integer, parameter :: cctki_use_CCTKH29 = kind(CCTKH29)
  REAL*8 CCTKH31
  integer, parameter :: cctki_use_CCTKH31 = kind(CCTKH31)
  REAL*8 CCTKH33
  integer, parameter :: cctki_use_CCTKH33 = kind(CCTKH33)
  REAL*8 CCTKH35
  integer, parameter :: cctki_use_CCTKH35 = kind(CCTKH35)
  REAL*8 CCTKH37
  integer, parameter :: cctki_use_CCTKH37 = kind(CCTKH37)
  REAL*8 CCTKH39
  integer, parameter :: cctki_use_CCTKH39 = kind(CCTKH39)
  REAL*8 CCTKH41
  integer, parameter :: cctki_use_CCTKH41 = kind(CCTKH41)
  REAL*8 CCTKH43
  integer, parameter :: cctki_use_CCTKH43 = kind(CCTKH43)
  REAL*8 CCTKH45
  integer, parameter :: cctki_use_CCTKH45 = kind(CCTKH45)
  integer*8 CCTKH2
  integer, parameter :: cctki_use_CCTKH2 = kind(CCTKH2)
  integer*8 CCTKH3
  integer, parameter :: cctki_use_CCTKH3 = kind(CCTKH3)
  integer*8 CCTKH6
  integer, parameter :: cctki_use_CCTKH6 = kind(CCTKH6)
  integer*8 CCTKH9
  integer, parameter :: cctki_use_CCTKH9 = kind(CCTKH9)
  integer*8 CCTKH10
  integer, parameter :: cctki_use_CCTKH10 = kind(CCTKH10)
  integer*8 CCTKH11
  integer, parameter :: cctki_use_CCTKH11 = kind(CCTKH11)
  integer*8 CCTKH15
  integer, parameter :: cctki_use_CCTKH15 = kind(CCTKH15)
  integer*8 out_dir
  integer, parameter :: cctki_use_out_dir = kind(out_dir)
  integer*8 CCTKH21
  integer, parameter :: cctki_use_CCTKH21 = kind(CCTKH21)
  integer*8 CCTKH22
  integer, parameter :: cctki_use_CCTKH22 = kind(CCTKH22)
  integer*8 CCTKH23
  integer, parameter :: cctki_use_CCTKH23 = kind(CCTKH23)
  integer*8 CCTKH25
  integer, parameter :: cctki_use_CCTKH25 = kind(CCTKH25)
  integer*8 CCTKH47
  integer, parameter :: cctki_use_CCTKH47 = kind(CCTKH47)
  integer*8 CCTKH49
  integer, parameter :: cctki_use_CCTKH49 = kind(CCTKH49)
  integer*8 CCTKH51
  integer, parameter :: cctki_use_CCTKH51 = kind(CCTKH51)
  integer*8 CCTKH53
  integer, parameter :: cctki_use_CCTKH53 = kind(CCTKH53)
  integer*8 CCTKH54
  integer, parameter :: cctki_use_CCTKH54 = kind(CCTKH54)
  integer*8 CCTKH57
  integer, parameter :: cctki_use_CCTKH57 = kind(CCTKH57)
  INTEGER*4 CCTKH0
  integer, parameter :: cctki_use_CCTKH0 = kind(CCTKH0)
  INTEGER*4 CCTKH1
  integer, parameter :: cctki_use_CCTKH1 = kind(CCTKH1)
  INTEGER*4 CCTKH4
  integer, parameter :: cctki_use_CCTKH4 = kind(CCTKH4)
  INTEGER*4 CCTKH7
  integer, parameter :: cctki_use_CCTKH7 = kind(CCTKH7)
  INTEGER*4 CCTKH8
  integer, parameter :: cctki_use_CCTKH8 = kind(CCTKH8)
  INTEGER*4 CCTKH12
  integer, parameter :: cctki_use_CCTKH12 = kind(CCTKH12)
  INTEGER*4 CCTKH13
  integer, parameter :: cctki_use_CCTKH13 = kind(CCTKH13)
  INTEGER*4 CCTKH14
  integer, parameter :: cctki_use_CCTKH14 = kind(CCTKH14)
  INTEGER*4 CCTKH16
  integer, parameter :: cctki_use_CCTKH16 = kind(CCTKH16)
  INTEGER*4 CCTKH17
  integer, parameter :: cctki_use_CCTKH17 = kind(CCTKH17)
  INTEGER*4 CCTKH18
  integer, parameter :: cctki_use_CCTKH18 = kind(CCTKH18)
  INTEGER*4 CCTKH20
  integer, parameter :: cctki_use_CCTKH20 = kind(CCTKH20)
  INTEGER*4 CCTKH24
  integer, parameter :: cctki_use_CCTKH24 = kind(CCTKH24)
  INTEGER*4 CCTKH26
  integer, parameter :: cctki_use_CCTKH26 = kind(CCTKH26)
  INTEGER*4 CCTKH27
  integer, parameter :: cctki_use_CCTKH27 = kind(CCTKH27)
  INTEGER*4 CCTKH28
  integer, parameter :: cctki_use_CCTKH28 = kind(CCTKH28)
  INTEGER*4 CCTKH30
  integer, parameter :: cctki_use_CCTKH30 = kind(CCTKH30)
  INTEGER*4 CCTKH32
  integer, parameter :: cctki_use_CCTKH32 = kind(CCTKH32)
  INTEGER*4 CCTKH34
  integer, parameter :: cctki_use_CCTKH34 = kind(CCTKH34)
  INTEGER*4 CCTKH36
  integer, parameter :: cctki_use_CCTKH36 = kind(CCTKH36)
  INTEGER*4 CCTKH38
  integer, parameter :: cctki_use_CCTKH38 = kind(CCTKH38)
  INTEGER*4 CCTKH40
  integer, parameter :: cctki_use_CCTKH40 = kind(CCTKH40)
  INTEGER*4 CCTKH42
  integer, parameter :: cctki_use_CCTKH42 = kind(CCTKH42)
  INTEGER*4 CCTKH44
  integer, parameter :: cctki_use_CCTKH44 = kind(CCTKH44)
  INTEGER*4 CCTKH46
  integer, parameter :: cctki_use_CCTKH46 = kind(CCTKH46)
  INTEGER*4 CCTKH48
  integer, parameter :: cctki_use_CCTKH48 = kind(CCTKH48)
  INTEGER*4 CCTKH50
  integer, parameter :: cctki_use_CCTKH50 = kind(CCTKH50)
  INTEGER*4 CCTKH52
  integer, parameter :: cctki_use_CCTKH52 = kind(CCTKH52)
  INTEGER*4 CCTKH55
  integer, parameter :: cctki_use_CCTKH55 = kind(CCTKH55)
  INTEGER*4 CCTKH56
  integer, parameter :: cctki_use_CCTKH56 = kind(CCTKH56)
  COMMON /IOrest/CCTKH5, CCTKH19, CCTKH29, CCTKH31, CCTKH33, CCTKH35, CCTKH37, CCTKH39, CCTKH41, CCTKH43, CCTKH45, CCTKH2, CCTKH3, &
  &CCTKH6, CCTKH9, CCTKH10, CCTKH11, CCTKH15, out_dir, CCTKH21, CCTKH22, CCTKH23, CCTKH25, CCTKH47, CCTKH49, CCTKH51, CCTKH53, CCTK&
  &H54, CCTKH57, CCTKH0, CCTKH1, CCTKH4, CCTKH7, CCTKH8, CCTKH12, CCTKH13, CCTKH14, CCTKH16, CCTKH17, CCTKH18, CCTKH20, CCTKH24, CC&
  &TKH26, CCTKH27, CCTKH28, CCTKH30, CCTKH32, CCTKH34, CCTKH36, CCTKH38, CCTKH40, CCTKH42, CCTKH44, CCTKH46, CCTKH48, CCTKH50, CCTK&
  &H52, CCTKH55, CCTKH56

  INTEGER*4, intent(in)     :: eoskey,keytemp,npoints
  INTEGER*4, intent(out)    :: keyerr(npoints)
  INTEGER*4, intent(out)    :: anyerr
  REAL*8, intent(in)    :: rf_precision
  REAL*8, intent(in)    :: rho(npoints),ye(npoints)
  REAL*8, intent(inout) :: eps(npoints), temp(npoints)
  REAL*8, intent(out)   :: press(npoints)

  
  integer          :: i,p
  character(256)   :: warnstring
  real*8           :: hybrideos_local_gamma,  hybrideos_local_k_cgs, hybrideos_local_k, hybrideos_local_eps, &
                      hybrideos_p_poly, hybrideos_p_th
  real*8,parameter :: zero = 0.0d0
  
  real*8, dimension(1) :: xrho,xye,xtemp,xenr,xent
  real*8, dimension(1) :: xprs,xmunu,xcs2
  real*8, dimension(1) :: xdedt,xdpderho,xdpdrhoe
  
  integer :: ir
  real*8 :: press_cold, press_th
  real*8 :: eps_cold, eps_th
  real*8 :: gamma
  integer :: num_threads, my_thread_num, slice_len, slice_min, slice_max
  
  INTEGER*4 :: my_anyerr

  anyerr    = 0
  keyerr(:) = 0

  select case (eoskey)
     case (1)
        
        if(keytemp.eq.1) then
           !$OMP PARALLEL DO
           do i=1,npoints
              eps(i) = press_gf * poly_k_cgs * &
                   (rho(i)*inv_rho_gf)**(poly_gamma) / &
                   (poly_gamma - 1.0d0) / rho(i)
           enddo
           !$OMP END PARALLEL DO
        endif
        !$OMP PARALLEL DO
        do i=1,npoints
           press(i) = press_gf * poly_k_cgs * &
                (rho(i)*inv_rho_gf)**poly_gamma
        enddo
        !$OMP END PARALLEL DO
     case (2)
        
        if(keytemp.eq.1) then
           !$OMP PARALLEL DO
           do i=1,npoints
              eps(i) = press_gf * gl_k_cgs * &
                   (rho(i)*inv_rho_gf)**(gl_gamma) / &
                   (gl_gamma - 1.0d0) / rho(i)
           enddo
           !$OMP END PARALLEL DO
        endif
        !$OMP PARALLEL DO
        do i=1,npoints
           press(i) = (gl_gamma - 1.0d0) * rho(i) * eps(i)
        enddo
        !$OMP END PARALLEL DO

     case (3)
        
        !$OMP PARALLEL DO PRIVATE(hybrideos_local_gamma,hybrideos_local_k_cgs, hybrideos_local_k, &
        !$OMP hybrideos_local_eps, hybrideos_p_poly, hybrideos_p_th)
        do i=1,npoints
           hybrideos_local_gamma = hybrideos_gamma(1)
           hybrideos_local_k = hybrideos_k(1)
           hybrideos_local_eps = hybrideos_eps(1)
           if (n_pieces .gt. 1) then
              do p = 1,n_pieces-1
                 if (rho(i) .gt. hybrideos_rho(p)) then
                    hybrideos_local_gamma = hybrideos_gamma(p+1)
                    hybrideos_local_k = hybrideos_k(p+1)
                    hybrideos_local_eps = hybrideos_eps(p+1)
                 end if
              end do
           end if
           if (keytemp .eq. 1) then
              
              eps(i)=hybrideos_local_k/(hybrideos_local_gamma - 1.0)* &
                   rho(i)**(hybrideos_local_gamma - 1.0) + hybrideos_local_eps
           end if
           hybrideos_p_poly = hybrideos_local_k * (rho(i))**hybrideos_local_gamma
           hybrideos_p_th = (hybrid_gamma_th-1)* (rho(i)*eps(i) - &
                hybrideos_p_poly/(hybrideos_local_gamma-1) - &
                hybrideos_local_eps * rho(i))
           hybrideos_p_th = max(zero, hybrideos_p_th)
           press(i) = hybrideos_p_poly + hybrideos_p_th
        enddo
        !$OMP END PARALLEL DO

     case (4)
        
        my_anyerr = 0
        !$OMP PARALLEL REDUCTION(+: my_anyerr)

        num_threads = omp_get_num_threads()
        my_thread_num = omp_get_thread_num()




        slice_len = (npoints + num_threads-1)/num_threads
        slice_min = 1 + my_thread_num * slice_len
        slice_max = min(slice_min + slice_len - 1, npoints)
        if(keytemp.eq.1) then
           call nuc_eos_m_kt1_press_eps(slice_max-slice_min+1,&
                rho(slice_min:slice_max),temp(slice_min:slice_max),&
                ye(slice_min:slice_max),eps(slice_min:slice_max),&
                press(slice_min:slice_max),keyerr(slice_min:slice_max),&
                my_anyerr)
        else
           call nuc_eos_m_kt0_press(slice_max-slice_min+1,&
                rho(slice_min:slice_max),temp(slice_min:slice_max),&
                ye(slice_min:slice_max),eps(slice_min:slice_max),&
                press(slice_min:slice_max),&
                rf_precision,keyerr(slice_min:slice_max),anyerr)
        endif
        !$OMP END PARALLEL
        
        
        if(my_anyerr.ne.0) then
           anyerr = 1
        end if
     case (5)
        
        !$OMP PARALLEL DO PRIVATE(xrho,ir,gamma,eps_cold,eps_th, &
        !$OMP press_cold,press_th)
        do i=1,npoints
           if(rho(i).lt.coldeos_rhomin) then
              press(i) = coldeos_low_kappa * rho(i)**coldeos_low_gamma
              eps(i) = press(i) / (coldeos_low_gamma - 1.0) / rho(i) 
              cycle
           else if(rho(i).gt.coldeos_rhomax) then
              keyerr(i) = 103
              !$OMP CRITICAL
              anyerr = 1
              !$OMP END CRITICAL
           else
              xrho(1) = log10(rho(i))
              ir = 2 + INT( (xrho(1) - coldeos_logrho(1) - 1.0d-10) * coldeos_dlrhoi )
           endif
           ir = max(2, min(ir,coldeos_nrho))

           gamma = (coldeos_gamma(ir) - coldeos_gamma(ir-1)) / &
                (coldeos_logrho(ir) - coldeos_logrho(ir-1)) * &
                (xrho(1) - coldeos_logrho(ir-1)) + coldeos_gamma(ir-1)

           eps_cold = (coldeos_eps(ir) - coldeos_eps(ir-1)) / &
                    (coldeos_logrho(ir) - coldeos_logrho(ir-1)) * &
                    (xrho(1) - coldeos_logrho(ir-1)) + coldeos_eps(ir-1)

           if(keytemp.eq.0) then
              eps_th = max(0.0d0,eps(i) - eps_cold)
           else if (keytemp.eq.1) then
              eps_th = 0.0d0
              eps(i) = eps_cold
           endif

           press_cold = coldeos_kappa * rho(i)**gamma
           press_th = coldeos_thfac*(coldeos_gammath - 1.0d0)*rho(i)*eps_th
           press(i) = press_cold + press_th
        enddo
        !$OMP END PARALLEL DO

     case (6)
        
        !$OMP PARALLEL DO PRIVATE(xrho,xprs,xenr,xye,ir, &
        !$OMP press_cold,eps_cold,eps_th,press_th)
        do i=1,npoints
           if(rho(i).lt.barotropiceos_rhomin) then
              press(i) = barotropiceos_low_kappa * rho(i)**barotropiceos_low_gamma
              eps(i) = press(i) / (barotropiceos_low_gamma - 1.0) / rho(i) 
              cycle
           else if(rho(i).gt.barotropiceos_rhomax) then
              keyerr(i) = 103
              anyerr = 1
           else
              xrho(1) = log10(rho(i))
              ir = 2 + &
                   INT( (xrho(1) - barotropiceos_logrho(1) - 1.0d-10) &
                   * barotropiceos_dlrhoi )
           endif
           ir = max(2, min(ir,barotropiceos_nrho))

           xprs(1) = (barotropiceos_logpress(ir) - barotropiceos_logpress(ir-1)) / &
                (barotropiceos_logrho(ir) - barotropiceos_logrho(ir-1)) * &
                (xrho(1) - barotropiceos_logrho(ir-1)) + barotropiceos_logpress(ir-1)

           xenr(1) = (barotropiceos_logeps(ir) - barotropiceos_logeps(ir-1)) / &
                (barotropiceos_logrho(ir) - barotropiceos_logrho(ir-1)) * &
                (xrho(1) - barotropiceos_logrho(ir-1)) + barotropiceos_logeps(ir-1)

           xtemp(1) = (barotropiceos_temp(ir) - barotropiceos_temp(ir-1)) / &
                (barotropiceos_logrho(ir) - barotropiceos_logrho(ir-1)) * &
                (xrho(1) - barotropiceos_logrho(ir-1)) + barotropiceos_temp(ir-1)

           xye(1) = (barotropiceos_ye(ir) - barotropiceos_ye(ir-1)) / &
                (barotropiceos_logrho(ir) - barotropiceos_logrho(ir-1)) * &
                (xrho(1) - barotropiceos_logrho(ir-1)) + barotropiceos_ye(ir-1)

           press_cold = 10.0**xprs(1)
           eps_cold = 10.0**xenr(1) - barotropiceos_energyshift

           if(keytemp.eq.0) then
              eps_th = max(0.0d0,eps(i) - eps_cold)
           else if (keytemp.eq.1) then
              eps_th = 0.0d0
              eps(i) = eps_cold
           endif
           press_th = coldeos_thfac*(barotropiceos_gammath - 1.0d0)*rho(i)*eps_th
           press(i) = press_cold + press_th

        enddo
        !$OMP END PARALLEL DO


     case DEFAULT
        write(warnstring,*) "eoskey ",eoskey," not implemented!"
        call CCTK_Error(440,"EOS_Omni_SingleVarCalls.F90","EOS_Omni",warnstring)
        STOP
     end select

end subroutine EOS_Omni_EOS_PressOMP


subroutine EOS_Omni_EOS_DPressByDRho(eoskey,keytemp,rf_precision,npoints,&
                              rho,eps,temp,ye,dpdrhoe,keyerr,anyerr)

  use EOS_Omni_Module
  implicit none
  REAL*8 barotropiceos_gammath
  integer, parameter :: cctki_use_barotropiceos_gammath = kind(barotropiceos_gammath)
  REAL*8 gl_gamma
  integer, parameter :: cctki_use_gl_gamma = kind(gl_gamma)
  REAL*8 gl_k
  integer, parameter :: cctki_use_gl_k = kind(gl_k)
  REAL*8 hybrid_gamma (10)
  integer, parameter :: cctki_use_hybrid_gamma = kind(hybrid_gamma)
  REAL*8 hybrid_gamma1
  integer, parameter :: cctki_use_hybrid_gamma1 = kind(hybrid_gamma1)
  REAL*8 hybrid_gamma2
  integer, parameter :: cctki_use_hybrid_gamma2 = kind(hybrid_gamma2)
  REAL*8 hybrid_gamma_th
  integer, parameter :: cctki_use_hybrid_gamma_th = kind(hybrid_gamma_th)
  REAL*8 hybrid_k0
  integer, parameter :: cctki_use_hybrid_k0 = kind(hybrid_k0)
  REAL*8 hybrid_k1
  integer, parameter :: cctki_use_hybrid_k1 = kind(hybrid_k1)
  REAL*8 hybrid_rho (9)
  integer, parameter :: cctki_use_hybrid_rho = kind(hybrid_rho)
  REAL*8 hybrid_rho_nuc
  integer, parameter :: cctki_use_hybrid_rho_nuc = kind(hybrid_rho_nuc)
  REAL*8 poly_gamma
  integer, parameter :: cctki_use_poly_gamma = kind(poly_gamma)
  REAL*8 poly_gamma_initial
  integer, parameter :: cctki_use_poly_gamma_initial = kind(poly_gamma_initial)
  REAL*8 poly_k
  integer, parameter :: cctki_use_poly_k = kind(poly_k)
  integer*8 barotropiceos_table_name
  integer, parameter :: cctki_use_barotropiceos_table_name = kind(barotropiceos_table_name)
  integer*8 coldeos_table_name
  integer, parameter :: cctki_use_coldeos_table_name = kind(coldeos_table_name)
  integer*8 dump_nuceos_table_name
  integer, parameter :: cctki_use_dump_nuceos_table_name = kind(dump_nuceos_table_name)
  integer*8 nuceos_table_name
  integer, parameter :: cctki_use_nuceos_table_name = kind(nuceos_table_name)
  INTEGER*4 barotropiceos_read_table
  integer, parameter :: cctki_use_barotropiceos_read_table = kind(barotropiceos_read_table)
  INTEGER*4 barotropiceos_use_thermal_gamma_law
  integer, parameter :: cctki_use_barotropiceos_use_thermal_gamma_law = kind(barotropiceos_use_thermal_gamma_law)
  INTEGER*4 coldeos_read_table
  integer, parameter :: cctki_use_coldeos_read_table = kind(coldeos_read_table)
  INTEGER*4 coldeos_use_thermal_gamma_law
  integer, parameter :: cctki_use_coldeos_use_thermal_gamma_law = kind(coldeos_use_thermal_gamma_law)
  INTEGER*4 do_energy_shift
  integer, parameter :: cctki_use_do_energy_shift = kind(do_energy_shift)
  INTEGER*4 dump_nuceos_table
  integer, parameter :: cctki_use_dump_nuceos_table = kind(dump_nuceos_table)
  INTEGER*4 n_pieces
  integer, parameter :: cctki_use_n_pieces = kind(n_pieces)
  INTEGER*4 nuceos_read_table
  integer, parameter :: cctki_use_nuceos_read_table = kind(nuceos_read_table)
  INTEGER*4 read_table_on_single_process
  integer, parameter :: cctki_use_read_table_on_single_process = kind(read_table_on_single_process)
  INTEGER*4 reader_process
  integer, parameter :: cctki_use_reader_process = kind(reader_process)
  COMMON /EOS_Omnirest/barotropiceos_gammath, gl_gamma, gl_k, hybrid_gamma, hybrid_gamma1, hybrid_gamma2, hybrid_gamma_th, hybrid_k&
  &0, hybrid_k1, hybrid_rho, hybrid_rho_nuc, poly_gamma, poly_gamma_initial, poly_k, barotropiceos_table_name, coldeos_table_name, &
  &dump_nuceos_table_name, nuceos_table_name, barotropiceos_read_table, barotropiceos_use_thermal_gamma_law, coldeos_read_table, co&
  &ldeos_use_thermal_gamma_law, do_energy_shift, dump_nuceos_table, n_pieces, nuceos_read_table, read_table_on_single_process, read&
  &er_process
  REAL*8 CCTKH5
  integer, parameter :: cctki_use_CCTKH5 = kind(CCTKH5)
  REAL*8 CCTKH19
  integer, parameter :: cctki_use_CCTKH19 = kind(CCTKH19)
  REAL*8 CCTKH29
  integer, parameter :: cctki_use_CCTKH29 = kind(CCTKH29)
  REAL*8 CCTKH31
  integer, parameter :: cctki_use_CCTKH31 = kind(CCTKH31)
  REAL*8 CCTKH33
  integer, parameter :: cctki_use_CCTKH33 = kind(CCTKH33)
  REAL*8 CCTKH35
  integer, parameter :: cctki_use_CCTKH35 = kind(CCTKH35)
  REAL*8 CCTKH37
  integer, parameter :: cctki_use_CCTKH37 = kind(CCTKH37)
  REAL*8 CCTKH39
  integer, parameter :: cctki_use_CCTKH39 = kind(CCTKH39)
  REAL*8 CCTKH41
  integer, parameter :: cctki_use_CCTKH41 = kind(CCTKH41)
  REAL*8 CCTKH43
  integer, parameter :: cctki_use_CCTKH43 = kind(CCTKH43)
  REAL*8 CCTKH45
  integer, parameter :: cctki_use_CCTKH45 = kind(CCTKH45)
  integer*8 CCTKH2
  integer, parameter :: cctki_use_CCTKH2 = kind(CCTKH2)
  integer*8 CCTKH3
  integer, parameter :: cctki_use_CCTKH3 = kind(CCTKH3)
  integer*8 CCTKH6
  integer, parameter :: cctki_use_CCTKH6 = kind(CCTKH6)
  integer*8 CCTKH9
  integer, parameter :: cctki_use_CCTKH9 = kind(CCTKH9)
  integer*8 CCTKH10
  integer, parameter :: cctki_use_CCTKH10 = kind(CCTKH10)
  integer*8 CCTKH11
  integer, parameter :: cctki_use_CCTKH11 = kind(CCTKH11)
  integer*8 CCTKH15
  integer, parameter :: cctki_use_CCTKH15 = kind(CCTKH15)
  integer*8 out_dir
  integer, parameter :: cctki_use_out_dir = kind(out_dir)
  integer*8 CCTKH21
  integer, parameter :: cctki_use_CCTKH21 = kind(CCTKH21)
  integer*8 CCTKH22
  integer, parameter :: cctki_use_CCTKH22 = kind(CCTKH22)
  integer*8 CCTKH23
  integer, parameter :: cctki_use_CCTKH23 = kind(CCTKH23)
  integer*8 CCTKH25
  integer, parameter :: cctki_use_CCTKH25 = kind(CCTKH25)
  integer*8 CCTKH47
  integer, parameter :: cctki_use_CCTKH47 = kind(CCTKH47)
  integer*8 CCTKH49
  integer, parameter :: cctki_use_CCTKH49 = kind(CCTKH49)
  integer*8 CCTKH51
  integer, parameter :: cctki_use_CCTKH51 = kind(CCTKH51)
  integer*8 CCTKH53
  integer, parameter :: cctki_use_CCTKH53 = kind(CCTKH53)
  integer*8 CCTKH54
  integer, parameter :: cctki_use_CCTKH54 = kind(CCTKH54)
  integer*8 CCTKH57
  integer, parameter :: cctki_use_CCTKH57 = kind(CCTKH57)
  INTEGER*4 CCTKH0
  integer, parameter :: cctki_use_CCTKH0 = kind(CCTKH0)
  INTEGER*4 CCTKH1
  integer, parameter :: cctki_use_CCTKH1 = kind(CCTKH1)
  INTEGER*4 CCTKH4
  integer, parameter :: cctki_use_CCTKH4 = kind(CCTKH4)
  INTEGER*4 CCTKH7
  integer, parameter :: cctki_use_CCTKH7 = kind(CCTKH7)
  INTEGER*4 CCTKH8
  integer, parameter :: cctki_use_CCTKH8 = kind(CCTKH8)
  INTEGER*4 CCTKH12
  integer, parameter :: cctki_use_CCTKH12 = kind(CCTKH12)
  INTEGER*4 CCTKH13
  integer, parameter :: cctki_use_CCTKH13 = kind(CCTKH13)
  INTEGER*4 CCTKH14
  integer, parameter :: cctki_use_CCTKH14 = kind(CCTKH14)
  INTEGER*4 CCTKH16
  integer, parameter :: cctki_use_CCTKH16 = kind(CCTKH16)
  INTEGER*4 CCTKH17
  integer, parameter :: cctki_use_CCTKH17 = kind(CCTKH17)
  INTEGER*4 CCTKH18
  integer, parameter :: cctki_use_CCTKH18 = kind(CCTKH18)
  INTEGER*4 CCTKH20
  integer, parameter :: cctki_use_CCTKH20 = kind(CCTKH20)
  INTEGER*4 CCTKH24
  integer, parameter :: cctki_use_CCTKH24 = kind(CCTKH24)
  INTEGER*4 CCTKH26
  integer, parameter :: cctki_use_CCTKH26 = kind(CCTKH26)
  INTEGER*4 CCTKH27
  integer, parameter :: cctki_use_CCTKH27 = kind(CCTKH27)
  INTEGER*4 CCTKH28
  integer, parameter :: cctki_use_CCTKH28 = kind(CCTKH28)
  INTEGER*4 CCTKH30
  integer, parameter :: cctki_use_CCTKH30 = kind(CCTKH30)
  INTEGER*4 CCTKH32
  integer, parameter :: cctki_use_CCTKH32 = kind(CCTKH32)
  INTEGER*4 CCTKH34
  integer, parameter :: cctki_use_CCTKH34 = kind(CCTKH34)
  INTEGER*4 CCTKH36
  integer, parameter :: cctki_use_CCTKH36 = kind(CCTKH36)
  INTEGER*4 CCTKH38
  integer, parameter :: cctki_use_CCTKH38 = kind(CCTKH38)
  INTEGER*4 CCTKH40
  integer, parameter :: cctki_use_CCTKH40 = kind(CCTKH40)
  INTEGER*4 CCTKH42
  integer, parameter :: cctki_use_CCTKH42 = kind(CCTKH42)
  INTEGER*4 CCTKH44
  integer, parameter :: cctki_use_CCTKH44 = kind(CCTKH44)
  INTEGER*4 CCTKH46
  integer, parameter :: cctki_use_CCTKH46 = kind(CCTKH46)
  INTEGER*4 CCTKH48
  integer, parameter :: cctki_use_CCTKH48 = kind(CCTKH48)
  INTEGER*4 CCTKH50
  integer, parameter :: cctki_use_CCTKH50 = kind(CCTKH50)
  INTEGER*4 CCTKH52
  integer, parameter :: cctki_use_CCTKH52 = kind(CCTKH52)
  INTEGER*4 CCTKH55
  integer, parameter :: cctki_use_CCTKH55 = kind(CCTKH55)
  INTEGER*4 CCTKH56
  integer, parameter :: cctki_use_CCTKH56 = kind(CCTKH56)
  COMMON /IOrest/CCTKH5, CCTKH19, CCTKH29, CCTKH31, CCTKH33, CCTKH35, CCTKH37, CCTKH39, CCTKH41, CCTKH43, CCTKH45, CCTKH2, CCTKH3, &
  &CCTKH6, CCTKH9, CCTKH10, CCTKH11, CCTKH15, out_dir, CCTKH21, CCTKH22, CCTKH23, CCTKH25, CCTKH47, CCTKH49, CCTKH51, CCTKH53, CCTK&
  &H54, CCTKH57, CCTKH0, CCTKH1, CCTKH4, CCTKH7, CCTKH8, CCTKH12, CCTKH13, CCTKH14, CCTKH16, CCTKH17, CCTKH18, CCTKH20, CCTKH24, CC&
  &TKH26, CCTKH27, CCTKH28, CCTKH30, CCTKH32, CCTKH34, CCTKH36, CCTKH38, CCTKH40, CCTKH42, CCTKH44, CCTKH46, CCTKH48, CCTKH50, CCTK&
  &H52, CCTKH55, CCTKH56

  INTEGER*4, intent(in)     :: eoskey,keytemp,npoints
  INTEGER*4, intent(out)    :: keyerr(npoints)
  INTEGER*4, intent(out)    :: anyerr
  REAL*8, intent(in)    :: rf_precision
  REAL*8, intent(in)    :: rho(npoints),ye(npoints)
  REAL*8, intent(inout) :: eps(npoints), temp(npoints)
  REAL*8, intent(out)   :: dpdrhoe(npoints)

  
  integer          :: i,p
  character(256)   :: warnstring
  real*8           :: hybrideos_local_gamma, hybrideos_local_k_cgs, hybrideos_local_k, hybrideos_local_eps, &
                      hybrideos_dp_poly, hybrideos_dp_th1, hybrideos_dp_th2, hybrideos_dp_th
  real*8,parameter :: zero = 0.0d0
  
  real*8, dimension(1) :: xrho,xye,xtemp,xenr,xent
  real*8, dimension(1) :: xprs,xmunu,xcs2
  real*8, dimension(1) :: xdedt,xdpderho,xdpdrhoe
  
  integer :: ir
  real*8 :: press_cold, press_th
  real*8 :: eps_cold, eps_th
  real*8 :: gamma, cs2, h

  anyerr    = 0
  keyerr(:) = 0

  select case (eoskey)
     case (1)
        
        if(keytemp.eq.1) then
           do i=1,npoints
              eps(i) = press_gf * poly_k_cgs * &
                   (rho(i)*inv_rho_gf)**(poly_gamma) / &
                   (poly_gamma - 1.0d0) / rho(i)
           enddo
        endif
        do i=1,npoints
           dpdrhoe(i) = press_gf * poly_k_cgs *  &
                poly_gamma * inv_rho_gf *        & 
                (rho(i)*inv_rho_gf) ** (poly_gamma - 1.d0)
        enddo
     case (2)
        
        if(keytemp.eq.1) then
           do i=1,npoints
              eps(i) = press_gf * gl_k_cgs * &
                   (rho(i)*inv_rho_gf)**(gl_gamma) / &
                   (gl_gamma - 1.0d0) / rho(i)
           enddo
        endif
        do i=1,npoints
           dpdrhoe(i) = (gl_gamma-1.0d0) * &
                eps(i)
        enddo
     case (3)
        
        do i=1,npoints
           hybrideos_local_gamma = hybrideos_gamma(1)
           hybrideos_local_k = hybrideos_k(1)
           hybrideos_local_eps = hybrideos_eps(1)
           if (n_pieces .gt. 1) then
              do p = 1,n_pieces-1
                 if (rho(i) .gt. hybrideos_rho(p)) then
                    hybrideos_local_gamma = hybrideos_gamma(p+1)
                    hybrideos_local_k = hybrideos_k(p+1)
                    hybrideos_local_eps = hybrideos_eps(p+1)
                 end if
              end do
           end if
           if (keytemp .eq. 1) then
              
              eps(i)=hybrideos_local_k/(hybrideos_local_gamma - 1.0)* &
                   rho(i)**(hybrideos_local_gamma - 1.0) + hybrideos_local_eps
           end if
           hybrideos_dp_poly = hybrideos_local_gamma * hybrideos_local_k * &
                rho(i)**(hybrideos_local_gamma - 1.0d0)
           
           hybrideos_dp_th = (hybrid_gamma_th - 1.0d0) * (eps(i) - &
                hybrideos_dp_poly/(hybrideos_local_gamma - 1.0d0) - &
                hybrideos_local_eps)

           dpdrhoe(i) = hybrideos_dp_poly + max(0.0d0,hybrideos_dp_th)

        enddo

     case (4)
        if(keytemp.eq.1) then
           call nuc_eos_m_kt1_short(npoints,rho,temp,ye,&
                eps,xprs,xent,xcs2,xdedt,xdpderho,dpdrhoe,xmunu,&
                keyerr,anyerr)
        else if(keytemp.eq.0) then
           call nuc_eos_m_kt0_short(npoints,rho,temp,ye,&
                eps,xprs,xent,xcs2,xdedt,xdpderho,dpdrhoe,xmunu,rf_precision,&
                keyerr,anyerr)
        else
           call CCTK_Error(550,"EOS_Omni_SingleVarCalls.F90","EOS_Omni","This keytemp is not supported!")
           STOP
        endif
        
     case (5)
        
        
        
        do i=1,npoints
           if(rho(i).lt.coldeos_rhomin) then
              dpdrhoe(i) = coldeos_low_kappa * coldeos_low_gamma * &
                   rho(i)**(coldeos_low_gamma-1.0d0)
              cycle
           else if(rho(i).gt.coldeos_rhomax) then
              keyerr(i) = 103
              anyerr = 1
           else
              xrho(1) = log10(rho(i))
              ir = 2 + INT( (xrho(1) - coldeos_logrho(1) - 1.0d-10) * coldeos_dlrhoi )
           endif
           ir = max(2, min(ir,coldeos_nrho))

           gamma = (coldeos_gamma(ir) - coldeos_gamma(ir-1)) / &
                (coldeos_logrho(ir) - coldeos_logrho(ir-1)) * &
                (xrho(1) - coldeos_logrho(ir-1)) + coldeos_gamma(ir-1)
           
           
           cs2 = (coldeos_cs2(ir) - coldeos_cs2(ir-1)) / &
                (coldeos_cs2(ir) - coldeos_cs2(ir-1)) * &
                (xrho(1) - coldeos_logrho(ir-1)) + coldeos_cs2(ir-1)

           eps_cold = (coldeos_eps(ir) - coldeos_eps(ir-1)) / &
                    (coldeos_logrho(ir) - coldeos_logrho(ir-1)) * &
                    (xrho(1) - coldeos_logrho(ir-1)) + coldeos_eps(ir-1)

           if(keytemp.eq.0) then
              eps_th = max(0.0d0,eps(i) - eps_cold)
           else if (keytemp.eq.1) then
              eps_th = 0.0d0
              eps(i) = eps_cold
           endif

           press_cold = coldeos_kappa * rho(i)**gamma
           press_th = coldeos_thfac*(coldeos_gammath - 1.0d0)*rho(i)*eps_th
           
           
           
           h = 1.0d0 + eps_cold + press_cold / rho(i)
           dpdrhoe(i) = cs2*h + press_th / rho(i)

        enddo

     case DEFAULT
        write(warnstring,*) "eoskey ",eoskey," not implemented!"
        call CCTK_Error(604,"EOS_Omni_SingleVarCalls.F90","EOS_Omni",warnstring)
        STOP
   end select
     
end subroutine EOS_Omni_EOS_DPressByDRho

subroutine EOS_Omni_EOS_DPressByDEps(eoskey,keytemp,rf_precision,npoints,&
                              rho,eps,temp,ye,dpdepsrho,keyerr,anyerr)

  use EOS_Omni_Module
  implicit none
  REAL*8 barotropiceos_gammath
  integer, parameter :: cctki_use_barotropiceos_gammath = kind(barotropiceos_gammath)
  REAL*8 gl_gamma
  integer, parameter :: cctki_use_gl_gamma = kind(gl_gamma)
  REAL*8 gl_k
  integer, parameter :: cctki_use_gl_k = kind(gl_k)
  REAL*8 hybrid_gamma (10)
  integer, parameter :: cctki_use_hybrid_gamma = kind(hybrid_gamma)
  REAL*8 hybrid_gamma1
  integer, parameter :: cctki_use_hybrid_gamma1 = kind(hybrid_gamma1)
  REAL*8 hybrid_gamma2
  integer, parameter :: cctki_use_hybrid_gamma2 = kind(hybrid_gamma2)
  REAL*8 hybrid_gamma_th
  integer, parameter :: cctki_use_hybrid_gamma_th = kind(hybrid_gamma_th)
  REAL*8 hybrid_k0
  integer, parameter :: cctki_use_hybrid_k0 = kind(hybrid_k0)
  REAL*8 hybrid_k1
  integer, parameter :: cctki_use_hybrid_k1 = kind(hybrid_k1)
  REAL*8 hybrid_rho (9)
  integer, parameter :: cctki_use_hybrid_rho = kind(hybrid_rho)
  REAL*8 hybrid_rho_nuc
  integer, parameter :: cctki_use_hybrid_rho_nuc = kind(hybrid_rho_nuc)
  REAL*8 poly_gamma
  integer, parameter :: cctki_use_poly_gamma = kind(poly_gamma)
  REAL*8 poly_gamma_initial
  integer, parameter :: cctki_use_poly_gamma_initial = kind(poly_gamma_initial)
  REAL*8 poly_k
  integer, parameter :: cctki_use_poly_k = kind(poly_k)
  integer*8 barotropiceos_table_name
  integer, parameter :: cctki_use_barotropiceos_table_name = kind(barotropiceos_table_name)
  integer*8 coldeos_table_name
  integer, parameter :: cctki_use_coldeos_table_name = kind(coldeos_table_name)
  integer*8 dump_nuceos_table_name
  integer, parameter :: cctki_use_dump_nuceos_table_name = kind(dump_nuceos_table_name)
  integer*8 nuceos_table_name
  integer, parameter :: cctki_use_nuceos_table_name = kind(nuceos_table_name)
  INTEGER*4 barotropiceos_read_table
  integer, parameter :: cctki_use_barotropiceos_read_table = kind(barotropiceos_read_table)
  INTEGER*4 barotropiceos_use_thermal_gamma_law
  integer, parameter :: cctki_use_barotropiceos_use_thermal_gamma_law = kind(barotropiceos_use_thermal_gamma_law)
  INTEGER*4 coldeos_read_table
  integer, parameter :: cctki_use_coldeos_read_table = kind(coldeos_read_table)
  INTEGER*4 coldeos_use_thermal_gamma_law
  integer, parameter :: cctki_use_coldeos_use_thermal_gamma_law = kind(coldeos_use_thermal_gamma_law)
  INTEGER*4 do_energy_shift
  integer, parameter :: cctki_use_do_energy_shift = kind(do_energy_shift)
  INTEGER*4 dump_nuceos_table
  integer, parameter :: cctki_use_dump_nuceos_table = kind(dump_nuceos_table)
  INTEGER*4 n_pieces
  integer, parameter :: cctki_use_n_pieces = kind(n_pieces)
  INTEGER*4 nuceos_read_table
  integer, parameter :: cctki_use_nuceos_read_table = kind(nuceos_read_table)
  INTEGER*4 read_table_on_single_process
  integer, parameter :: cctki_use_read_table_on_single_process = kind(read_table_on_single_process)
  INTEGER*4 reader_process
  integer, parameter :: cctki_use_reader_process = kind(reader_process)
  COMMON /EOS_Omnirest/barotropiceos_gammath, gl_gamma, gl_k, hybrid_gamma, hybrid_gamma1, hybrid_gamma2, hybrid_gamma_th, hybrid_k&
  &0, hybrid_k1, hybrid_rho, hybrid_rho_nuc, poly_gamma, poly_gamma_initial, poly_k, barotropiceos_table_name, coldeos_table_name, &
  &dump_nuceos_table_name, nuceos_table_name, barotropiceos_read_table, barotropiceos_use_thermal_gamma_law, coldeos_read_table, co&
  &ldeos_use_thermal_gamma_law, do_energy_shift, dump_nuceos_table, n_pieces, nuceos_read_table, read_table_on_single_process, read&
  &er_process
  REAL*8 CCTKH5
  integer, parameter :: cctki_use_CCTKH5 = kind(CCTKH5)
  REAL*8 CCTKH19
  integer, parameter :: cctki_use_CCTKH19 = kind(CCTKH19)
  REAL*8 CCTKH29
  integer, parameter :: cctki_use_CCTKH29 = kind(CCTKH29)
  REAL*8 CCTKH31
  integer, parameter :: cctki_use_CCTKH31 = kind(CCTKH31)
  REAL*8 CCTKH33
  integer, parameter :: cctki_use_CCTKH33 = kind(CCTKH33)
  REAL*8 CCTKH35
  integer, parameter :: cctki_use_CCTKH35 = kind(CCTKH35)
  REAL*8 CCTKH37
  integer, parameter :: cctki_use_CCTKH37 = kind(CCTKH37)
  REAL*8 CCTKH39
  integer, parameter :: cctki_use_CCTKH39 = kind(CCTKH39)
  REAL*8 CCTKH41
  integer, parameter :: cctki_use_CCTKH41 = kind(CCTKH41)
  REAL*8 CCTKH43
  integer, parameter :: cctki_use_CCTKH43 = kind(CCTKH43)
  REAL*8 CCTKH45
  integer, parameter :: cctki_use_CCTKH45 = kind(CCTKH45)
  integer*8 CCTKH2
  integer, parameter :: cctki_use_CCTKH2 = kind(CCTKH2)
  integer*8 CCTKH3
  integer, parameter :: cctki_use_CCTKH3 = kind(CCTKH3)
  integer*8 CCTKH6
  integer, parameter :: cctki_use_CCTKH6 = kind(CCTKH6)
  integer*8 CCTKH9
  integer, parameter :: cctki_use_CCTKH9 = kind(CCTKH9)
  integer*8 CCTKH10
  integer, parameter :: cctki_use_CCTKH10 = kind(CCTKH10)
  integer*8 CCTKH11
  integer, parameter :: cctki_use_CCTKH11 = kind(CCTKH11)
  integer*8 CCTKH15
  integer, parameter :: cctki_use_CCTKH15 = kind(CCTKH15)
  integer*8 out_dir
  integer, parameter :: cctki_use_out_dir = kind(out_dir)
  integer*8 CCTKH21
  integer, parameter :: cctki_use_CCTKH21 = kind(CCTKH21)
  integer*8 CCTKH22
  integer, parameter :: cctki_use_CCTKH22 = kind(CCTKH22)
  integer*8 CCTKH23
  integer, parameter :: cctki_use_CCTKH23 = kind(CCTKH23)
  integer*8 CCTKH25
  integer, parameter :: cctki_use_CCTKH25 = kind(CCTKH25)
  integer*8 CCTKH47
  integer, parameter :: cctki_use_CCTKH47 = kind(CCTKH47)
  integer*8 CCTKH49
  integer, parameter :: cctki_use_CCTKH49 = kind(CCTKH49)
  integer*8 CCTKH51
  integer, parameter :: cctki_use_CCTKH51 = kind(CCTKH51)
  integer*8 CCTKH53
  integer, parameter :: cctki_use_CCTKH53 = kind(CCTKH53)
  integer*8 CCTKH54
  integer, parameter :: cctki_use_CCTKH54 = kind(CCTKH54)
  integer*8 CCTKH57
  integer, parameter :: cctki_use_CCTKH57 = kind(CCTKH57)
  INTEGER*4 CCTKH0
  integer, parameter :: cctki_use_CCTKH0 = kind(CCTKH0)
  INTEGER*4 CCTKH1
  integer, parameter :: cctki_use_CCTKH1 = kind(CCTKH1)
  INTEGER*4 CCTKH4
  integer, parameter :: cctki_use_CCTKH4 = kind(CCTKH4)
  INTEGER*4 CCTKH7
  integer, parameter :: cctki_use_CCTKH7 = kind(CCTKH7)
  INTEGER*4 CCTKH8
  integer, parameter :: cctki_use_CCTKH8 = kind(CCTKH8)
  INTEGER*4 CCTKH12
  integer, parameter :: cctki_use_CCTKH12 = kind(CCTKH12)
  INTEGER*4 CCTKH13
  integer, parameter :: cctki_use_CCTKH13 = kind(CCTKH13)
  INTEGER*4 CCTKH14
  integer, parameter :: cctki_use_CCTKH14 = kind(CCTKH14)
  INTEGER*4 CCTKH16
  integer, parameter :: cctki_use_CCTKH16 = kind(CCTKH16)
  INTEGER*4 CCTKH17
  integer, parameter :: cctki_use_CCTKH17 = kind(CCTKH17)
  INTEGER*4 CCTKH18
  integer, parameter :: cctki_use_CCTKH18 = kind(CCTKH18)
  INTEGER*4 CCTKH20
  integer, parameter :: cctki_use_CCTKH20 = kind(CCTKH20)
  INTEGER*4 CCTKH24
  integer, parameter :: cctki_use_CCTKH24 = kind(CCTKH24)
  INTEGER*4 CCTKH26
  integer, parameter :: cctki_use_CCTKH26 = kind(CCTKH26)
  INTEGER*4 CCTKH27
  integer, parameter :: cctki_use_CCTKH27 = kind(CCTKH27)
  INTEGER*4 CCTKH28
  integer, parameter :: cctki_use_CCTKH28 = kind(CCTKH28)
  INTEGER*4 CCTKH30
  integer, parameter :: cctki_use_CCTKH30 = kind(CCTKH30)
  INTEGER*4 CCTKH32
  integer, parameter :: cctki_use_CCTKH32 = kind(CCTKH32)
  INTEGER*4 CCTKH34
  integer, parameter :: cctki_use_CCTKH34 = kind(CCTKH34)
  INTEGER*4 CCTKH36
  integer, parameter :: cctki_use_CCTKH36 = kind(CCTKH36)
  INTEGER*4 CCTKH38
  integer, parameter :: cctki_use_CCTKH38 = kind(CCTKH38)
  INTEGER*4 CCTKH40
  integer, parameter :: cctki_use_CCTKH40 = kind(CCTKH40)
  INTEGER*4 CCTKH42
  integer, parameter :: cctki_use_CCTKH42 = kind(CCTKH42)
  INTEGER*4 CCTKH44
  integer, parameter :: cctki_use_CCTKH44 = kind(CCTKH44)
  INTEGER*4 CCTKH46
  integer, parameter :: cctki_use_CCTKH46 = kind(CCTKH46)
  INTEGER*4 CCTKH48
  integer, parameter :: cctki_use_CCTKH48 = kind(CCTKH48)
  INTEGER*4 CCTKH50
  integer, parameter :: cctki_use_CCTKH50 = kind(CCTKH50)
  INTEGER*4 CCTKH52
  integer, parameter :: cctki_use_CCTKH52 = kind(CCTKH52)
  INTEGER*4 CCTKH55
  integer, parameter :: cctki_use_CCTKH55 = kind(CCTKH55)
  INTEGER*4 CCTKH56
  integer, parameter :: cctki_use_CCTKH56 = kind(CCTKH56)
  COMMON /IOrest/CCTKH5, CCTKH19, CCTKH29, CCTKH31, CCTKH33, CCTKH35, CCTKH37, CCTKH39, CCTKH41, CCTKH43, CCTKH45, CCTKH2, CCTKH3, &
  &CCTKH6, CCTKH9, CCTKH10, CCTKH11, CCTKH15, out_dir, CCTKH21, CCTKH22, CCTKH23, CCTKH25, CCTKH47, CCTKH49, CCTKH51, CCTKH53, CCTK&
  &H54, CCTKH57, CCTKH0, CCTKH1, CCTKH4, CCTKH7, CCTKH8, CCTKH12, CCTKH13, CCTKH14, CCTKH16, CCTKH17, CCTKH18, CCTKH20, CCTKH24, CC&
  &TKH26, CCTKH27, CCTKH28, CCTKH30, CCTKH32, CCTKH34, CCTKH36, CCTKH38, CCTKH40, CCTKH42, CCTKH44, CCTKH46, CCTKH48, CCTKH50, CCTK&
  &H52, CCTKH55, CCTKH56

  INTEGER*4, intent(in)     :: eoskey,keytemp,npoints
  INTEGER*4, intent(out)    :: keyerr(npoints)
  INTEGER*4, intent(out)    :: anyerr
  REAL*8, intent(in)    :: rf_precision
  REAL*8, intent(in)    :: rho(npoints),ye(npoints)
  REAL*8, intent(inout) :: eps(npoints), temp(npoints)
  REAL*8, intent(out)   :: dpdepsrho(npoints)

  
  integer          :: i,p
  character(256)   :: warnstring
  
  real*8, dimension(1) :: xrho,xye,xtemp,xenr,xent
  real*8, dimension(1) :: xprs,xmunu,xcs2
  real*8, dimension(1) :: xdedt,xdpderho,xdpdrhoe
  
  integer :: ir
  real*8 :: eps_cold, eps_th

  anyerr    = 0
  keyerr(:) = 0

  select case (eoskey)
     case (1)
        
        if(keytemp.eq.1) then
           do i=1,npoints
              eps(i) = press_gf * poly_k_cgs * &
                   (rho(i)*inv_rho_gf)**(poly_gamma) / &
                   (poly_gamma - 1.0d0) / rho(i)
           enddo
        endif
        do i=1,npoints
           dpdepsrho(i) = 0.0d0
        enddo
     case (2)
        
        if(keytemp.eq.1) then
           do i=1,npoints
              eps(i) = press_gf * gl_k_cgs * &
                   (rho(i)*inv_rho_gf)**(gl_gamma) / &
                   (gl_gamma - 1.0d0) / rho(i)
           enddo
        endif
        do i=1,npoints
           dpdepsrho(i) = (gl_gamma - 1.0d0) * &
                rho(i)
        enddo
     case (3)
        
        do i=1,npoints
           dpdepsrho(i) = (hybrid_gamma_th - 1.0d0) * rho(i)
        enddo
     case (4)
        if(keytemp.eq.1) then
           call nuc_eos_m_kt1_short(npoints,rho,temp,ye,&
                eps,xprs,xent,xcs2,xdedt,dpdepsrho,xdpdrhoe,xmunu,&
                keyerr,anyerr)
        else if(keytemp.eq.0) then
           call nuc_eos_m_kt0_short(npoints,rho,temp,ye,&
                eps,xprs,xent,xcs2,xdedt,dpdepsrho,xdpdrhoe,xmunu,rf_precision,&
                keyerr,anyerr)
        else 
           call CCTK_Error(680,"EOS_Omni_SingleVarCalls.F90","EOS_Omni","This keytemp is not supported!")
           STOP
        endif
     case (5)
        
        
        do i=1,npoints
           if(rho(i).lt.coldeos_rhomin) then
              dpdepsrho(i) = 0.0d0
              cycle
           else if(rho(i).gt.coldeos_rhomax) then
              keyerr(i) = 103
              anyerr = 1
           else
              xrho(1) = log10(rho(i))
              ir = 2 + INT( (xrho(1) - coldeos_logrho(1) - 1.0d-10) * coldeos_dlrhoi )
           endif
           ir = max(2, min(ir,coldeos_nrho))

           eps_cold = (coldeos_eps(ir) - coldeos_eps(ir-1)) / &
                    (coldeos_logrho(ir) - coldeos_logrho(ir-1)) * &
                    (xrho(1) - coldeos_logrho(ir-1)) + coldeos_eps(ir-1)

           if(keytemp.eq.0) then
              eps_th = max(0.0d0,eps(i) - eps_cold)
           else if (keytemp.eq.1) then
              eps_th = 0.0d0
              eps(i) = eps_cold
           endif

           dpdepsrho(i) = coldeos_thfac * (coldeos_gammath - 1.0d0)*rho(i)

        enddo
     case DEFAULT
        write(warnstring,*) "eoskey ",eoskey," not implemented!"
        call CCTK_Error(715,"EOS_Omni_SingleVarCalls.F90","EOS_Omni",warnstring)
        STOP
   end select
     
end subroutine EOS_Omni_EOS_DPressByDEps

subroutine EOS_Omni_EOS_cs2(eoskey,keytemp,rf_precision,npoints,&
                            rho,eps,temp,ye,cs2,keyerr,anyerr)

  use EOS_Omni_Module
  implicit none
  REAL*8 barotropiceos_gammath
  integer, parameter :: cctki_use_barotropiceos_gammath = kind(barotropiceos_gammath)
  REAL*8 gl_gamma
  integer, parameter :: cctki_use_gl_gamma = kind(gl_gamma)
  REAL*8 gl_k
  integer, parameter :: cctki_use_gl_k = kind(gl_k)
  REAL*8 hybrid_gamma (10)
  integer, parameter :: cctki_use_hybrid_gamma = kind(hybrid_gamma)
  REAL*8 hybrid_gamma1
  integer, parameter :: cctki_use_hybrid_gamma1 = kind(hybrid_gamma1)
  REAL*8 hybrid_gamma2
  integer, parameter :: cctki_use_hybrid_gamma2 = kind(hybrid_gamma2)
  REAL*8 hybrid_gamma_th
  integer, parameter :: cctki_use_hybrid_gamma_th = kind(hybrid_gamma_th)
  REAL*8 hybrid_k0
  integer, parameter :: cctki_use_hybrid_k0 = kind(hybrid_k0)
  REAL*8 hybrid_k1
  integer, parameter :: cctki_use_hybrid_k1 = kind(hybrid_k1)
  REAL*8 hybrid_rho (9)
  integer, parameter :: cctki_use_hybrid_rho = kind(hybrid_rho)
  REAL*8 hybrid_rho_nuc
  integer, parameter :: cctki_use_hybrid_rho_nuc = kind(hybrid_rho_nuc)
  REAL*8 poly_gamma
  integer, parameter :: cctki_use_poly_gamma = kind(poly_gamma)
  REAL*8 poly_gamma_initial
  integer, parameter :: cctki_use_poly_gamma_initial = kind(poly_gamma_initial)
  REAL*8 poly_k
  integer, parameter :: cctki_use_poly_k = kind(poly_k)
  integer*8 barotropiceos_table_name
  integer, parameter :: cctki_use_barotropiceos_table_name = kind(barotropiceos_table_name)
  integer*8 coldeos_table_name
  integer, parameter :: cctki_use_coldeos_table_name = kind(coldeos_table_name)
  integer*8 dump_nuceos_table_name
  integer, parameter :: cctki_use_dump_nuceos_table_name = kind(dump_nuceos_table_name)
  integer*8 nuceos_table_name
  integer, parameter :: cctki_use_nuceos_table_name = kind(nuceos_table_name)
  INTEGER*4 barotropiceos_read_table
  integer, parameter :: cctki_use_barotropiceos_read_table = kind(barotropiceos_read_table)
  INTEGER*4 barotropiceos_use_thermal_gamma_law
  integer, parameter :: cctki_use_barotropiceos_use_thermal_gamma_law = kind(barotropiceos_use_thermal_gamma_law)
  INTEGER*4 coldeos_read_table
  integer, parameter :: cctki_use_coldeos_read_table = kind(coldeos_read_table)
  INTEGER*4 coldeos_use_thermal_gamma_law
  integer, parameter :: cctki_use_coldeos_use_thermal_gamma_law = kind(coldeos_use_thermal_gamma_law)
  INTEGER*4 do_energy_shift
  integer, parameter :: cctki_use_do_energy_shift = kind(do_energy_shift)
  INTEGER*4 dump_nuceos_table
  integer, parameter :: cctki_use_dump_nuceos_table = kind(dump_nuceos_table)
  INTEGER*4 n_pieces
  integer, parameter :: cctki_use_n_pieces = kind(n_pieces)
  INTEGER*4 nuceos_read_table
  integer, parameter :: cctki_use_nuceos_read_table = kind(nuceos_read_table)
  INTEGER*4 read_table_on_single_process
  integer, parameter :: cctki_use_read_table_on_single_process = kind(read_table_on_single_process)
  INTEGER*4 reader_process
  integer, parameter :: cctki_use_reader_process = kind(reader_process)
  COMMON /EOS_Omnirest/barotropiceos_gammath, gl_gamma, gl_k, hybrid_gamma, hybrid_gamma1, hybrid_gamma2, hybrid_gamma_th, hybrid_k&
  &0, hybrid_k1, hybrid_rho, hybrid_rho_nuc, poly_gamma, poly_gamma_initial, poly_k, barotropiceos_table_name, coldeos_table_name, &
  &dump_nuceos_table_name, nuceos_table_name, barotropiceos_read_table, barotropiceos_use_thermal_gamma_law, coldeos_read_table, co&
  &ldeos_use_thermal_gamma_law, do_energy_shift, dump_nuceos_table, n_pieces, nuceos_read_table, read_table_on_single_process, read&
  &er_process
  REAL*8 CCTKH5
  integer, parameter :: cctki_use_CCTKH5 = kind(CCTKH5)
  REAL*8 CCTKH19
  integer, parameter :: cctki_use_CCTKH19 = kind(CCTKH19)
  REAL*8 CCTKH29
  integer, parameter :: cctki_use_CCTKH29 = kind(CCTKH29)
  REAL*8 CCTKH31
  integer, parameter :: cctki_use_CCTKH31 = kind(CCTKH31)
  REAL*8 CCTKH33
  integer, parameter :: cctki_use_CCTKH33 = kind(CCTKH33)
  REAL*8 CCTKH35
  integer, parameter :: cctki_use_CCTKH35 = kind(CCTKH35)
  REAL*8 CCTKH37
  integer, parameter :: cctki_use_CCTKH37 = kind(CCTKH37)
  REAL*8 CCTKH39
  integer, parameter :: cctki_use_CCTKH39 = kind(CCTKH39)
  REAL*8 CCTKH41
  integer, parameter :: cctki_use_CCTKH41 = kind(CCTKH41)
  REAL*8 CCTKH43
  integer, parameter :: cctki_use_CCTKH43 = kind(CCTKH43)
  REAL*8 CCTKH45
  integer, parameter :: cctki_use_CCTKH45 = kind(CCTKH45)
  integer*8 CCTKH2
  integer, parameter :: cctki_use_CCTKH2 = kind(CCTKH2)
  integer*8 CCTKH3
  integer, parameter :: cctki_use_CCTKH3 = kind(CCTKH3)
  integer*8 CCTKH6
  integer, parameter :: cctki_use_CCTKH6 = kind(CCTKH6)
  integer*8 CCTKH9
  integer, parameter :: cctki_use_CCTKH9 = kind(CCTKH9)
  integer*8 CCTKH10
  integer, parameter :: cctki_use_CCTKH10 = kind(CCTKH10)
  integer*8 CCTKH11
  integer, parameter :: cctki_use_CCTKH11 = kind(CCTKH11)
  integer*8 CCTKH15
  integer, parameter :: cctki_use_CCTKH15 = kind(CCTKH15)
  integer*8 out_dir
  integer, parameter :: cctki_use_out_dir = kind(out_dir)
  integer*8 CCTKH21
  integer, parameter :: cctki_use_CCTKH21 = kind(CCTKH21)
  integer*8 CCTKH22
  integer, parameter :: cctki_use_CCTKH22 = kind(CCTKH22)
  integer*8 CCTKH23
  integer, parameter :: cctki_use_CCTKH23 = kind(CCTKH23)
  integer*8 CCTKH25
  integer, parameter :: cctki_use_CCTKH25 = kind(CCTKH25)
  integer*8 CCTKH47
  integer, parameter :: cctki_use_CCTKH47 = kind(CCTKH47)
  integer*8 CCTKH49
  integer, parameter :: cctki_use_CCTKH49 = kind(CCTKH49)
  integer*8 CCTKH51
  integer, parameter :: cctki_use_CCTKH51 = kind(CCTKH51)
  integer*8 CCTKH53
  integer, parameter :: cctki_use_CCTKH53 = kind(CCTKH53)
  integer*8 CCTKH54
  integer, parameter :: cctki_use_CCTKH54 = kind(CCTKH54)
  integer*8 CCTKH57
  integer, parameter :: cctki_use_CCTKH57 = kind(CCTKH57)
  INTEGER*4 CCTKH0
  integer, parameter :: cctki_use_CCTKH0 = kind(CCTKH0)
  INTEGER*4 CCTKH1
  integer, parameter :: cctki_use_CCTKH1 = kind(CCTKH1)
  INTEGER*4 CCTKH4
  integer, parameter :: cctki_use_CCTKH4 = kind(CCTKH4)
  INTEGER*4 CCTKH7
  integer, parameter :: cctki_use_CCTKH7 = kind(CCTKH7)
  INTEGER*4 CCTKH8
  integer, parameter :: cctki_use_CCTKH8 = kind(CCTKH8)
  INTEGER*4 CCTKH12
  integer, parameter :: cctki_use_CCTKH12 = kind(CCTKH12)
  INTEGER*4 CCTKH13
  integer, parameter :: cctki_use_CCTKH13 = kind(CCTKH13)
  INTEGER*4 CCTKH14
  integer, parameter :: cctki_use_CCTKH14 = kind(CCTKH14)
  INTEGER*4 CCTKH16
  integer, parameter :: cctki_use_CCTKH16 = kind(CCTKH16)
  INTEGER*4 CCTKH17
  integer, parameter :: cctki_use_CCTKH17 = kind(CCTKH17)
  INTEGER*4 CCTKH18
  integer, parameter :: cctki_use_CCTKH18 = kind(CCTKH18)
  INTEGER*4 CCTKH20
  integer, parameter :: cctki_use_CCTKH20 = kind(CCTKH20)
  INTEGER*4 CCTKH24
  integer, parameter :: cctki_use_CCTKH24 = kind(CCTKH24)
  INTEGER*4 CCTKH26
  integer, parameter :: cctki_use_CCTKH26 = kind(CCTKH26)
  INTEGER*4 CCTKH27
  integer, parameter :: cctki_use_CCTKH27 = kind(CCTKH27)
  INTEGER*4 CCTKH28
  integer, parameter :: cctki_use_CCTKH28 = kind(CCTKH28)
  INTEGER*4 CCTKH30
  integer, parameter :: cctki_use_CCTKH30 = kind(CCTKH30)
  INTEGER*4 CCTKH32
  integer, parameter :: cctki_use_CCTKH32 = kind(CCTKH32)
  INTEGER*4 CCTKH34
  integer, parameter :: cctki_use_CCTKH34 = kind(CCTKH34)
  INTEGER*4 CCTKH36
  integer, parameter :: cctki_use_CCTKH36 = kind(CCTKH36)
  INTEGER*4 CCTKH38
  integer, parameter :: cctki_use_CCTKH38 = kind(CCTKH38)
  INTEGER*4 CCTKH40
  integer, parameter :: cctki_use_CCTKH40 = kind(CCTKH40)
  INTEGER*4 CCTKH42
  integer, parameter :: cctki_use_CCTKH42 = kind(CCTKH42)
  INTEGER*4 CCTKH44
  integer, parameter :: cctki_use_CCTKH44 = kind(CCTKH44)
  INTEGER*4 CCTKH46
  integer, parameter :: cctki_use_CCTKH46 = kind(CCTKH46)
  INTEGER*4 CCTKH48
  integer, parameter :: cctki_use_CCTKH48 = kind(CCTKH48)
  INTEGER*4 CCTKH50
  integer, parameter :: cctki_use_CCTKH50 = kind(CCTKH50)
  INTEGER*4 CCTKH52
  integer, parameter :: cctki_use_CCTKH52 = kind(CCTKH52)
  INTEGER*4 CCTKH55
  integer, parameter :: cctki_use_CCTKH55 = kind(CCTKH55)
  INTEGER*4 CCTKH56
  integer, parameter :: cctki_use_CCTKH56 = kind(CCTKH56)
  COMMON /IOrest/CCTKH5, CCTKH19, CCTKH29, CCTKH31, CCTKH33, CCTKH35, CCTKH37, CCTKH39, CCTKH41, CCTKH43, CCTKH45, CCTKH2, CCTKH3, &
  &CCTKH6, CCTKH9, CCTKH10, CCTKH11, CCTKH15, out_dir, CCTKH21, CCTKH22, CCTKH23, CCTKH25, CCTKH47, CCTKH49, CCTKH51, CCTKH53, CCTK&
  &H54, CCTKH57, CCTKH0, CCTKH1, CCTKH4, CCTKH7, CCTKH8, CCTKH12, CCTKH13, CCTKH14, CCTKH16, CCTKH17, CCTKH18, CCTKH20, CCTKH24, CC&
  &TKH26, CCTKH27, CCTKH28, CCTKH30, CCTKH32, CCTKH34, CCTKH36, CCTKH38, CCTKH40, CCTKH42, CCTKH44, CCTKH46, CCTKH48, CCTKH50, CCTK&
  &H52, CCTKH55, CCTKH56

  INTEGER*4, intent(in)     :: eoskey,keytemp,npoints
  INTEGER*4, intent(out)    :: keyerr(npoints)
  INTEGER*4, intent(out)    :: anyerr
  REAL*8, intent(in)    :: rf_precision
  REAL*8, intent(in)    :: rho(npoints),ye(npoints)
  REAL*8, intent(inout) :: eps(npoints), temp(npoints)
  REAL*8, intent(out)   :: cs2(npoints)

  
  integer          :: i,p
  character(256)   :: warnstring
  real*8, dimension(1) :: xpress,xdpdrhoe,xdpderho
  real*8           :: hybrideos_local_gamma, hybrideos_local_k, hybrideos_local_eps, &
                      hybrideos_p_poly, hybrideos_p_th
  real*8,parameter :: zero = 0.0d0
  
  real*8, dimension(1) :: xrho,xye,xtemp,xenr,xent
  real*8, dimension(1) :: xprs,xmunu,xcs2
  real*8, dimension(1) :: xdedt
  
  integer :: ir
  real*8 :: press_cold, press_th
  real*8 :: eps_cold, eps_th
  real*8 :: gamma, cs2_cold, cs2_th, h, h_cold

  anyerr    = 0
  keyerr(:) = 0

  select case (eoskey)
     case (1)
        
        if(keytemp.eq.1) then
           do i=1,npoints
              eps(i) = press_gf * poly_k_cgs * &
                   (rho(i)*inv_rho_gf)**(poly_gamma) / &
                   (poly_gamma - 1.0d0) / rho(i)
           enddo
        endif
        do i=1,npoints
           xpress = press_gf*poly_k_cgs * &
                (rho(i)*inv_rho_gf)**(poly_gamma)
           cs2(i) = poly_gamma * xpress(1) / rho(i) / &
                (1 + eps(i) + xpress(1)/rho(i))
        enddo
     case (2)
        
        if(keytemp.eq.1) then
           do i=1,npoints
              eps(i) = press_gf * gl_k_cgs * &
                   (rho(i)*inv_rho_gf)**(gl_gamma) / &
                   (gl_gamma - 1.0d0) / rho(i)
           enddo
        endif
        do i=1,npoints
           xpress(1) = (gl_gamma-1.0d0)*rho(i)*eps(i)
           xdpdrhoe(1) = (gl_gamma-1.0d0)*eps(i)
           xdpderho(1) = (gl_gamma-1.0d0)*rho(i)
           cs2(i) = (xdpdrhoe(1) + xpress(1) * xdpderho(1) / (rho(i)**2)) / &
                (1.0d0 + eps(i) + xpress(1)/rho(i))
        enddo
     case(3)
        
        do i=1,npoints
           hybrideos_local_gamma = hybrideos_gamma(1)
           hybrideos_local_k = hybrideos_k(1)
           hybrideos_local_eps = hybrideos_eps(1)
           if (n_pieces .gt. 1) then
              do p = 1,n_pieces-1
                 if (rho(i) .gt. hybrideos_rho(p)) then
                    hybrideos_local_gamma = hybrideos_gamma(p+1)
                    hybrideos_local_k = hybrideos_k(p+1)
                    hybrideos_local_eps = hybrideos_eps(p+1)
                 end if
              end do
           end if
           if (keytemp .eq. 1) then
              
              eps(i)=hybrideos_local_k/(hybrideos_local_gamma - 1.0)* &
                   rho(i)**(hybrideos_local_gamma - 1.0) + hybrideos_local_eps
           end if
           hybrideos_p_poly = hybrideos_local_k * (rho(i))**hybrideos_local_gamma
           hybrideos_p_th = (hybrid_gamma_th-1)* (rho(i)*eps(i) - &
                hybrideos_p_poly/(hybrideos_local_gamma-1) - &
                hybrideos_local_eps * rho(i))
           hybrideos_p_th = max(zero, hybrideos_p_th)
           xpress(1) = hybrideos_p_poly + hybrideos_p_th
           cs2(i) = (hybrideos_local_gamma * hybrideos_p_poly + &
                     hybrid_gamma_th * hybrideos_p_th) / rho(i) / &
                    (1.0d0 + eps(i) + xpress(1)/rho(i))
        enddo
     case(4)
        
        if(keytemp.eq.1) then
           call nuc_eos_m_kt1_press_eps_cs2(npoints,rho,temp,ye,&
                eps,xprs,cs2,keyerr,anyerr)
        else if(keytemp.eq.0) then
           call nuc_eos_m_kt0_press_cs2(npoints,rho,temp,ye,&
                eps,xprs,cs2,rf_precision,keyerr,anyerr)
        else
           call CCTK_Error(827,"EOS_Omni_SingleVarCalls.F90","EOS_Omni","This keytemp is not supported!")
           STOP
        endif
     case (5)
        
        
        
        do i=1,npoints
           if(rho(i).lt.coldeos_rhomin) then
              xprs(1) = coldeos_low_kappa * rho(i)**coldeos_low_gamma
              eps(i) = xprs(1) / (coldeos_low_gamma - 1.0d0) / rho(i)
              cs2(i) = coldeos_low_kappa * coldeos_low_gamma * &
                   rho(i)**(coldeos_low_gamma-1.0d0) / &
                   (1.0d0 + eps(i) + xprs(1))
              cycle
           else if(rho(i).gt.coldeos_rhomax) then
              keyerr(i) = 103
              anyerr = 1
                 else
              xrho(1) = log10(rho(i))
              ir = 2 + INT( (xrho(1) - coldeos_logrho(1) - 1.0d-10) * coldeos_dlrhoi )
           endif
           ir = max(2, min(ir,coldeos_nrho))

           gamma = (coldeos_gamma(ir) - coldeos_gamma(ir-1)) / &
                (coldeos_logrho(ir) - coldeos_logrho(ir-1)) * &
                (xrho(1) - coldeos_logrho(ir-1)) + coldeos_gamma(ir-1)

           
           cs2_cold = (coldeos_cs2(ir) - coldeos_cs2(ir-1)) / &
                (coldeos_cs2(ir) - coldeos_cs2(ir-1)) * &
                (xrho(1) - coldeos_logrho(ir-1)) + coldeos_cs2(ir-1)

           eps_cold = (coldeos_eps(ir) - coldeos_eps(ir-1)) / &
                    (coldeos_logrho(ir) - coldeos_logrho(ir-1)) * &
                    (xrho(1) - coldeos_logrho(ir-1)) + coldeos_eps(ir-1)

           if(keytemp.eq.0) then
              eps_th = max(0.0d0,eps(i) - eps_cold)
           else if (keytemp.eq.1) then
              eps_th = 0.0d0
              eps(i) = eps_cold
           endif

           press_cold = coldeos_kappa * rho(i)**gamma
           press_th = coldeos_thfac*(coldeos_gammath - 1.0d0)*rho(i)*eps_th

           xdpdrhoe(1) = coldeos_thfac*(coldeos_gammath - 1.0d0)*eps_th
           xdpderho(1) = coldeos_thfac*(coldeos_gammath - 1.0d0)*rho(i)
           cs2_th = (xdpdrhoe(1) + press_th * xdpderho(1) / (rho(i)**2))

           h = 1.0d0 + eps(i) + (press_cold+press_th) / rho(i)
           h_cold = 1.0d0 + eps_cold + press_cold / rho(i)
           
           cs2(i) = (cs2_cold * h_cold + cs2_th) / h
        enddo
           
     case DEFAULT
        write(warnstring,*) "eoskey ",eoskey," not implemented!"
        call CCTK_Error(886,"EOS_Omni_SingleVarCalls.F90","EOS_Omni",warnstring)
        STOP
   end select
     
end subroutine EOS_Omni_EOS_cs2


subroutine EOS_Omni_EOS_eps_from_press(eoskey,keytemp,rf_precision,npoints,&
                              rho,eps,temp,ye,press,xeps,keyerr,anyerr)

  use EOS_Omni_Module
  implicit none
  REAL*8 barotropiceos_gammath
  integer, parameter :: cctki_use_barotropiceos_gammath = kind(barotropiceos_gammath)
  REAL*8 gl_gamma
  integer, parameter :: cctki_use_gl_gamma = kind(gl_gamma)
  REAL*8 gl_k
  integer, parameter :: cctki_use_gl_k = kind(gl_k)
  REAL*8 hybrid_gamma (10)
  integer, parameter :: cctki_use_hybrid_gamma = kind(hybrid_gamma)
  REAL*8 hybrid_gamma1
  integer, parameter :: cctki_use_hybrid_gamma1 = kind(hybrid_gamma1)
  REAL*8 hybrid_gamma2
  integer, parameter :: cctki_use_hybrid_gamma2 = kind(hybrid_gamma2)
  REAL*8 hybrid_gamma_th
  integer, parameter :: cctki_use_hybrid_gamma_th = kind(hybrid_gamma_th)
  REAL*8 hybrid_k0
  integer, parameter :: cctki_use_hybrid_k0 = kind(hybrid_k0)
  REAL*8 hybrid_k1
  integer, parameter :: cctki_use_hybrid_k1 = kind(hybrid_k1)
  REAL*8 hybrid_rho (9)
  integer, parameter :: cctki_use_hybrid_rho = kind(hybrid_rho)
  REAL*8 hybrid_rho_nuc
  integer, parameter :: cctki_use_hybrid_rho_nuc = kind(hybrid_rho_nuc)
  REAL*8 poly_gamma
  integer, parameter :: cctki_use_poly_gamma = kind(poly_gamma)
  REAL*8 poly_gamma_initial
  integer, parameter :: cctki_use_poly_gamma_initial = kind(poly_gamma_initial)
  REAL*8 poly_k
  integer, parameter :: cctki_use_poly_k = kind(poly_k)
  integer*8 barotropiceos_table_name
  integer, parameter :: cctki_use_barotropiceos_table_name = kind(barotropiceos_table_name)
  integer*8 coldeos_table_name
  integer, parameter :: cctki_use_coldeos_table_name = kind(coldeos_table_name)
  integer*8 dump_nuceos_table_name
  integer, parameter :: cctki_use_dump_nuceos_table_name = kind(dump_nuceos_table_name)
  integer*8 nuceos_table_name
  integer, parameter :: cctki_use_nuceos_table_name = kind(nuceos_table_name)
  INTEGER*4 barotropiceos_read_table
  integer, parameter :: cctki_use_barotropiceos_read_table = kind(barotropiceos_read_table)
  INTEGER*4 barotropiceos_use_thermal_gamma_law
  integer, parameter :: cctki_use_barotropiceos_use_thermal_gamma_law = kind(barotropiceos_use_thermal_gamma_law)
  INTEGER*4 coldeos_read_table
  integer, parameter :: cctki_use_coldeos_read_table = kind(coldeos_read_table)
  INTEGER*4 coldeos_use_thermal_gamma_law
  integer, parameter :: cctki_use_coldeos_use_thermal_gamma_law = kind(coldeos_use_thermal_gamma_law)
  INTEGER*4 do_energy_shift
  integer, parameter :: cctki_use_do_energy_shift = kind(do_energy_shift)
  INTEGER*4 dump_nuceos_table
  integer, parameter :: cctki_use_dump_nuceos_table = kind(dump_nuceos_table)
  INTEGER*4 n_pieces
  integer, parameter :: cctki_use_n_pieces = kind(n_pieces)
  INTEGER*4 nuceos_read_table
  integer, parameter :: cctki_use_nuceos_read_table = kind(nuceos_read_table)
  INTEGER*4 read_table_on_single_process
  integer, parameter :: cctki_use_read_table_on_single_process = kind(read_table_on_single_process)
  INTEGER*4 reader_process
  integer, parameter :: cctki_use_reader_process = kind(reader_process)
  COMMON /EOS_Omnirest/barotropiceos_gammath, gl_gamma, gl_k, hybrid_gamma, hybrid_gamma1, hybrid_gamma2, hybrid_gamma_th, hybrid_k&
  &0, hybrid_k1, hybrid_rho, hybrid_rho_nuc, poly_gamma, poly_gamma_initial, poly_k, barotropiceos_table_name, coldeos_table_name, &
  &dump_nuceos_table_name, nuceos_table_name, barotropiceos_read_table, barotropiceos_use_thermal_gamma_law, coldeos_read_table, co&
  &ldeos_use_thermal_gamma_law, do_energy_shift, dump_nuceos_table, n_pieces, nuceos_read_table, read_table_on_single_process, read&
  &er_process
  REAL*8 CCTKH5
  integer, parameter :: cctki_use_CCTKH5 = kind(CCTKH5)
  REAL*8 CCTKH19
  integer, parameter :: cctki_use_CCTKH19 = kind(CCTKH19)
  REAL*8 CCTKH29
  integer, parameter :: cctki_use_CCTKH29 = kind(CCTKH29)
  REAL*8 CCTKH31
  integer, parameter :: cctki_use_CCTKH31 = kind(CCTKH31)
  REAL*8 CCTKH33
  integer, parameter :: cctki_use_CCTKH33 = kind(CCTKH33)
  REAL*8 CCTKH35
  integer, parameter :: cctki_use_CCTKH35 = kind(CCTKH35)
  REAL*8 CCTKH37
  integer, parameter :: cctki_use_CCTKH37 = kind(CCTKH37)
  REAL*8 CCTKH39
  integer, parameter :: cctki_use_CCTKH39 = kind(CCTKH39)
  REAL*8 CCTKH41
  integer, parameter :: cctki_use_CCTKH41 = kind(CCTKH41)
  REAL*8 CCTKH43
  integer, parameter :: cctki_use_CCTKH43 = kind(CCTKH43)
  REAL*8 CCTKH45
  integer, parameter :: cctki_use_CCTKH45 = kind(CCTKH45)
  integer*8 CCTKH2
  integer, parameter :: cctki_use_CCTKH2 = kind(CCTKH2)
  integer*8 CCTKH3
  integer, parameter :: cctki_use_CCTKH3 = kind(CCTKH3)
  integer*8 CCTKH6
  integer, parameter :: cctki_use_CCTKH6 = kind(CCTKH6)
  integer*8 CCTKH9
  integer, parameter :: cctki_use_CCTKH9 = kind(CCTKH9)
  integer*8 CCTKH10
  integer, parameter :: cctki_use_CCTKH10 = kind(CCTKH10)
  integer*8 CCTKH11
  integer, parameter :: cctki_use_CCTKH11 = kind(CCTKH11)
  integer*8 CCTKH15
  integer, parameter :: cctki_use_CCTKH15 = kind(CCTKH15)
  integer*8 out_dir
  integer, parameter :: cctki_use_out_dir = kind(out_dir)
  integer*8 CCTKH21
  integer, parameter :: cctki_use_CCTKH21 = kind(CCTKH21)
  integer*8 CCTKH22
  integer, parameter :: cctki_use_CCTKH22 = kind(CCTKH22)
  integer*8 CCTKH23
  integer, parameter :: cctki_use_CCTKH23 = kind(CCTKH23)
  integer*8 CCTKH25
  integer, parameter :: cctki_use_CCTKH25 = kind(CCTKH25)
  integer*8 CCTKH47
  integer, parameter :: cctki_use_CCTKH47 = kind(CCTKH47)
  integer*8 CCTKH49
  integer, parameter :: cctki_use_CCTKH49 = kind(CCTKH49)
  integer*8 CCTKH51
  integer, parameter :: cctki_use_CCTKH51 = kind(CCTKH51)
  integer*8 CCTKH53
  integer, parameter :: cctki_use_CCTKH53 = kind(CCTKH53)
  integer*8 CCTKH54
  integer, parameter :: cctki_use_CCTKH54 = kind(CCTKH54)
  integer*8 CCTKH57
  integer, parameter :: cctki_use_CCTKH57 = kind(CCTKH57)
  INTEGER*4 CCTKH0
  integer, parameter :: cctki_use_CCTKH0 = kind(CCTKH0)
  INTEGER*4 CCTKH1
  integer, parameter :: cctki_use_CCTKH1 = kind(CCTKH1)
  INTEGER*4 CCTKH4
  integer, parameter :: cctki_use_CCTKH4 = kind(CCTKH4)
  INTEGER*4 CCTKH7
  integer, parameter :: cctki_use_CCTKH7 = kind(CCTKH7)
  INTEGER*4 CCTKH8
  integer, parameter :: cctki_use_CCTKH8 = kind(CCTKH8)
  INTEGER*4 CCTKH12
  integer, parameter :: cctki_use_CCTKH12 = kind(CCTKH12)
  INTEGER*4 CCTKH13
  integer, parameter :: cctki_use_CCTKH13 = kind(CCTKH13)
  INTEGER*4 CCTKH14
  integer, parameter :: cctki_use_CCTKH14 = kind(CCTKH14)
  INTEGER*4 CCTKH16
  integer, parameter :: cctki_use_CCTKH16 = kind(CCTKH16)
  INTEGER*4 CCTKH17
  integer, parameter :: cctki_use_CCTKH17 = kind(CCTKH17)
  INTEGER*4 CCTKH18
  integer, parameter :: cctki_use_CCTKH18 = kind(CCTKH18)
  INTEGER*4 CCTKH20
  integer, parameter :: cctki_use_CCTKH20 = kind(CCTKH20)
  INTEGER*4 CCTKH24
  integer, parameter :: cctki_use_CCTKH24 = kind(CCTKH24)
  INTEGER*4 CCTKH26
  integer, parameter :: cctki_use_CCTKH26 = kind(CCTKH26)
  INTEGER*4 CCTKH27
  integer, parameter :: cctki_use_CCTKH27 = kind(CCTKH27)
  INTEGER*4 CCTKH28
  integer, parameter :: cctki_use_CCTKH28 = kind(CCTKH28)
  INTEGER*4 CCTKH30
  integer, parameter :: cctki_use_CCTKH30 = kind(CCTKH30)
  INTEGER*4 CCTKH32
  integer, parameter :: cctki_use_CCTKH32 = kind(CCTKH32)
  INTEGER*4 CCTKH34
  integer, parameter :: cctki_use_CCTKH34 = kind(CCTKH34)
  INTEGER*4 CCTKH36
  integer, parameter :: cctki_use_CCTKH36 = kind(CCTKH36)
  INTEGER*4 CCTKH38
  integer, parameter :: cctki_use_CCTKH38 = kind(CCTKH38)
  INTEGER*4 CCTKH40
  integer, parameter :: cctki_use_CCTKH40 = kind(CCTKH40)
  INTEGER*4 CCTKH42
  integer, parameter :: cctki_use_CCTKH42 = kind(CCTKH42)
  INTEGER*4 CCTKH44
  integer, parameter :: cctki_use_CCTKH44 = kind(CCTKH44)
  INTEGER*4 CCTKH46
  integer, parameter :: cctki_use_CCTKH46 = kind(CCTKH46)
  INTEGER*4 CCTKH48
  integer, parameter :: cctki_use_CCTKH48 = kind(CCTKH48)
  INTEGER*4 CCTKH50
  integer, parameter :: cctki_use_CCTKH50 = kind(CCTKH50)
  INTEGER*4 CCTKH52
  integer, parameter :: cctki_use_CCTKH52 = kind(CCTKH52)
  INTEGER*4 CCTKH55
  integer, parameter :: cctki_use_CCTKH55 = kind(CCTKH55)
  INTEGER*4 CCTKH56
  integer, parameter :: cctki_use_CCTKH56 = kind(CCTKH56)
  COMMON /IOrest/CCTKH5, CCTKH19, CCTKH29, CCTKH31, CCTKH33, CCTKH35, CCTKH37, CCTKH39, CCTKH41, CCTKH43, CCTKH45, CCTKH2, CCTKH3, &
  &CCTKH6, CCTKH9, CCTKH10, CCTKH11, CCTKH15, out_dir, CCTKH21, CCTKH22, CCTKH23, CCTKH25, CCTKH47, CCTKH49, CCTKH51, CCTKH53, CCTK&
  &H54, CCTKH57, CCTKH0, CCTKH1, CCTKH4, CCTKH7, CCTKH8, CCTKH12, CCTKH13, CCTKH14, CCTKH16, CCTKH17, CCTKH18, CCTKH20, CCTKH24, CC&
  &TKH26, CCTKH27, CCTKH28, CCTKH30, CCTKH32, CCTKH34, CCTKH36, CCTKH38, CCTKH40, CCTKH42, CCTKH44, CCTKH46, CCTKH48, CCTKH50, CCTK&
  &H52, CCTKH55, CCTKH56

  INTEGER*4, intent(in)     :: eoskey,keytemp,npoints
  INTEGER*4, intent(out)    :: keyerr(npoints)
  INTEGER*4, intent(out)    :: anyerr
  REAL*8, intent(in)    :: rf_precision
  REAL*8, intent(in)    :: rho(npoints),ye(npoints),press(npoints)
  REAL*8, intent(inout) :: eps(npoints), temp(npoints)
  REAL*8, intent(out)   :: xeps(npoints)

  
  integer        :: i,p
  character(256) :: warnstring
  
  real*8, dimension(1) :: xrho,xye,xtemp,xenr,xent
  real*8, dimension(1) :: xprs,xmunu,xcs2
  real*8, dimension(1) :: xdedt,xdpderho,xdpdrhoe

  if(keytemp.eq.1) then
     anyerr = 1
     keyerr(:) = -1
  else
     anyerr    = 0
     keyerr(:) = 0
  endif

  select case (eoskey)
     case (1)
        
        do i=1,npoints
           xeps(i) = press(i) / (poly_gamma - 1.0d0) / rho(i)
        enddo
     case (2)
        
        do i=1,npoints
           xeps(i) = press(i) / (gl_gamma - 1.0d0) / rho(i)
        enddo
     case (3)
        
        write(warnstring,*) "EOS_Omni_EpsFromPress call not supported for hybrid EOS"
        call CCTK_Error(938,"EOS_Omni_SingleVarCalls.F90","EOS_Omni",warnstring)
        STOP
     case (4)
        
        write(warnstring,*) "EOS_Omni_EpsFromPress call not supported for nuc_eos yet"
        call CCTK_Error(943,"EOS_Omni_SingleVarCalls.F90","EOS_Omni",warnstring)
        STOP
     case DEFAULT
        write(warnstring,*) "eoskey ",eoskey," not implemented!"
        call CCTK_Error(947,"EOS_Omni_SingleVarCalls.F90","EOS_Omni",warnstring)
        STOP
     end select

end subroutine EOS_Omni_EOS_eps_from_press


subroutine EOS_Omni_EOS_RhoFromPressEpsTempEnt(eoskey,&
                           ikeytemp,rf_precision,&
                           npoints,rho,eps,temp,entropy,ye,press,keyerr,anyerr)

  
  
  
  

  use EOS_Omni_Module
  implicit none
  REAL*8 barotropiceos_gammath
  integer, parameter :: cctki_use_barotropiceos_gammath = kind(barotropiceos_gammath)
  REAL*8 gl_gamma
  integer, parameter :: cctki_use_gl_gamma = kind(gl_gamma)
  REAL*8 gl_k
  integer, parameter :: cctki_use_gl_k = kind(gl_k)
  REAL*8 hybrid_gamma (10)
  integer, parameter :: cctki_use_hybrid_gamma = kind(hybrid_gamma)
  REAL*8 hybrid_gamma1
  integer, parameter :: cctki_use_hybrid_gamma1 = kind(hybrid_gamma1)
  REAL*8 hybrid_gamma2
  integer, parameter :: cctki_use_hybrid_gamma2 = kind(hybrid_gamma2)
  REAL*8 hybrid_gamma_th
  integer, parameter :: cctki_use_hybrid_gamma_th = kind(hybrid_gamma_th)
  REAL*8 hybrid_k0
  integer, parameter :: cctki_use_hybrid_k0 = kind(hybrid_k0)
  REAL*8 hybrid_k1
  integer, parameter :: cctki_use_hybrid_k1 = kind(hybrid_k1)
  REAL*8 hybrid_rho (9)
  integer, parameter :: cctki_use_hybrid_rho = kind(hybrid_rho)
  REAL*8 hybrid_rho_nuc
  integer, parameter :: cctki_use_hybrid_rho_nuc = kind(hybrid_rho_nuc)
  REAL*8 poly_gamma
  integer, parameter :: cctki_use_poly_gamma = kind(poly_gamma)
  REAL*8 poly_gamma_initial
  integer, parameter :: cctki_use_poly_gamma_initial = kind(poly_gamma_initial)
  REAL*8 poly_k
  integer, parameter :: cctki_use_poly_k = kind(poly_k)
  integer*8 barotropiceos_table_name
  integer, parameter :: cctki_use_barotropiceos_table_name = kind(barotropiceos_table_name)
  integer*8 coldeos_table_name
  integer, parameter :: cctki_use_coldeos_table_name = kind(coldeos_table_name)
  integer*8 dump_nuceos_table_name
  integer, parameter :: cctki_use_dump_nuceos_table_name = kind(dump_nuceos_table_name)
  integer*8 nuceos_table_name
  integer, parameter :: cctki_use_nuceos_table_name = kind(nuceos_table_name)
  INTEGER*4 barotropiceos_read_table
  integer, parameter :: cctki_use_barotropiceos_read_table = kind(barotropiceos_read_table)
  INTEGER*4 barotropiceos_use_thermal_gamma_law
  integer, parameter :: cctki_use_barotropiceos_use_thermal_gamma_law = kind(barotropiceos_use_thermal_gamma_law)
  INTEGER*4 coldeos_read_table
  integer, parameter :: cctki_use_coldeos_read_table = kind(coldeos_read_table)
  INTEGER*4 coldeos_use_thermal_gamma_law
  integer, parameter :: cctki_use_coldeos_use_thermal_gamma_law = kind(coldeos_use_thermal_gamma_law)
  INTEGER*4 do_energy_shift
  integer, parameter :: cctki_use_do_energy_shift = kind(do_energy_shift)
  INTEGER*4 dump_nuceos_table
  integer, parameter :: cctki_use_dump_nuceos_table = kind(dump_nuceos_table)
  INTEGER*4 n_pieces
  integer, parameter :: cctki_use_n_pieces = kind(n_pieces)
  INTEGER*4 nuceos_read_table
  integer, parameter :: cctki_use_nuceos_read_table = kind(nuceos_read_table)
  INTEGER*4 read_table_on_single_process
  integer, parameter :: cctki_use_read_table_on_single_process = kind(read_table_on_single_process)
  INTEGER*4 reader_process
  integer, parameter :: cctki_use_reader_process = kind(reader_process)
  COMMON /EOS_Omnirest/barotropiceos_gammath, gl_gamma, gl_k, hybrid_gamma, hybrid_gamma1, hybrid_gamma2, hybrid_gamma_th, hybrid_k&
  &0, hybrid_k1, hybrid_rho, hybrid_rho_nuc, poly_gamma, poly_gamma_initial, poly_k, barotropiceos_table_name, coldeos_table_name, &
  &dump_nuceos_table_name, nuceos_table_name, barotropiceos_read_table, barotropiceos_use_thermal_gamma_law, coldeos_read_table, co&
  &ldeos_use_thermal_gamma_law, do_energy_shift, dump_nuceos_table, n_pieces, nuceos_read_table, read_table_on_single_process, read&
  &er_process
  REAL*8 CCTKH5
  integer, parameter :: cctki_use_CCTKH5 = kind(CCTKH5)
  REAL*8 CCTKH19
  integer, parameter :: cctki_use_CCTKH19 = kind(CCTKH19)
  REAL*8 CCTKH29
  integer, parameter :: cctki_use_CCTKH29 = kind(CCTKH29)
  REAL*8 CCTKH31
  integer, parameter :: cctki_use_CCTKH31 = kind(CCTKH31)
  REAL*8 CCTKH33
  integer, parameter :: cctki_use_CCTKH33 = kind(CCTKH33)
  REAL*8 CCTKH35
  integer, parameter :: cctki_use_CCTKH35 = kind(CCTKH35)
  REAL*8 CCTKH37
  integer, parameter :: cctki_use_CCTKH37 = kind(CCTKH37)
  REAL*8 CCTKH39
  integer, parameter :: cctki_use_CCTKH39 = kind(CCTKH39)
  REAL*8 CCTKH41
  integer, parameter :: cctki_use_CCTKH41 = kind(CCTKH41)
  REAL*8 CCTKH43
  integer, parameter :: cctki_use_CCTKH43 = kind(CCTKH43)
  REAL*8 CCTKH45
  integer, parameter :: cctki_use_CCTKH45 = kind(CCTKH45)
  integer*8 CCTKH2
  integer, parameter :: cctki_use_CCTKH2 = kind(CCTKH2)
  integer*8 CCTKH3
  integer, parameter :: cctki_use_CCTKH3 = kind(CCTKH3)
  integer*8 CCTKH6
  integer, parameter :: cctki_use_CCTKH6 = kind(CCTKH6)
  integer*8 CCTKH9
  integer, parameter :: cctki_use_CCTKH9 = kind(CCTKH9)
  integer*8 CCTKH10
  integer, parameter :: cctki_use_CCTKH10 = kind(CCTKH10)
  integer*8 CCTKH11
  integer, parameter :: cctki_use_CCTKH11 = kind(CCTKH11)
  integer*8 CCTKH15
  integer, parameter :: cctki_use_CCTKH15 = kind(CCTKH15)
  integer*8 out_dir
  integer, parameter :: cctki_use_out_dir = kind(out_dir)
  integer*8 CCTKH21
  integer, parameter :: cctki_use_CCTKH21 = kind(CCTKH21)
  integer*8 CCTKH22
  integer, parameter :: cctki_use_CCTKH22 = kind(CCTKH22)
  integer*8 CCTKH23
  integer, parameter :: cctki_use_CCTKH23 = kind(CCTKH23)
  integer*8 CCTKH25
  integer, parameter :: cctki_use_CCTKH25 = kind(CCTKH25)
  integer*8 CCTKH47
  integer, parameter :: cctki_use_CCTKH47 = kind(CCTKH47)
  integer*8 CCTKH49
  integer, parameter :: cctki_use_CCTKH49 = kind(CCTKH49)
  integer*8 CCTKH51
  integer, parameter :: cctki_use_CCTKH51 = kind(CCTKH51)
  integer*8 CCTKH53
  integer, parameter :: cctki_use_CCTKH53 = kind(CCTKH53)
  integer*8 CCTKH54
  integer, parameter :: cctki_use_CCTKH54 = kind(CCTKH54)
  integer*8 CCTKH57
  integer, parameter :: cctki_use_CCTKH57 = kind(CCTKH57)
  INTEGER*4 CCTKH0
  integer, parameter :: cctki_use_CCTKH0 = kind(CCTKH0)
  INTEGER*4 CCTKH1
  integer, parameter :: cctki_use_CCTKH1 = kind(CCTKH1)
  INTEGER*4 CCTKH4
  integer, parameter :: cctki_use_CCTKH4 = kind(CCTKH4)
  INTEGER*4 CCTKH7
  integer, parameter :: cctki_use_CCTKH7 = kind(CCTKH7)
  INTEGER*4 CCTKH8
  integer, parameter :: cctki_use_CCTKH8 = kind(CCTKH8)
  INTEGER*4 CCTKH12
  integer, parameter :: cctki_use_CCTKH12 = kind(CCTKH12)
  INTEGER*4 CCTKH13
  integer, parameter :: cctki_use_CCTKH13 = kind(CCTKH13)
  INTEGER*4 CCTKH14
  integer, parameter :: cctki_use_CCTKH14 = kind(CCTKH14)
  INTEGER*4 CCTKH16
  integer, parameter :: cctki_use_CCTKH16 = kind(CCTKH16)
  INTEGER*4 CCTKH17
  integer, parameter :: cctki_use_CCTKH17 = kind(CCTKH17)
  INTEGER*4 CCTKH18
  integer, parameter :: cctki_use_CCTKH18 = kind(CCTKH18)
  INTEGER*4 CCTKH20
  integer, parameter :: cctki_use_CCTKH20 = kind(CCTKH20)
  INTEGER*4 CCTKH24
  integer, parameter :: cctki_use_CCTKH24 = kind(CCTKH24)
  INTEGER*4 CCTKH26
  integer, parameter :: cctki_use_CCTKH26 = kind(CCTKH26)
  INTEGER*4 CCTKH27
  integer, parameter :: cctki_use_CCTKH27 = kind(CCTKH27)
  INTEGER*4 CCTKH28
  integer, parameter :: cctki_use_CCTKH28 = kind(CCTKH28)
  INTEGER*4 CCTKH30
  integer, parameter :: cctki_use_CCTKH30 = kind(CCTKH30)
  INTEGER*4 CCTKH32
  integer, parameter :: cctki_use_CCTKH32 = kind(CCTKH32)
  INTEGER*4 CCTKH34
  integer, parameter :: cctki_use_CCTKH34 = kind(CCTKH34)
  INTEGER*4 CCTKH36
  integer, parameter :: cctki_use_CCTKH36 = kind(CCTKH36)
  INTEGER*4 CCTKH38
  integer, parameter :: cctki_use_CCTKH38 = kind(CCTKH38)
  INTEGER*4 CCTKH40
  integer, parameter :: cctki_use_CCTKH40 = kind(CCTKH40)
  INTEGER*4 CCTKH42
  integer, parameter :: cctki_use_CCTKH42 = kind(CCTKH42)
  INTEGER*4 CCTKH44
  integer, parameter :: cctki_use_CCTKH44 = kind(CCTKH44)
  INTEGER*4 CCTKH46
  integer, parameter :: cctki_use_CCTKH46 = kind(CCTKH46)
  INTEGER*4 CCTKH48
  integer, parameter :: cctki_use_CCTKH48 = kind(CCTKH48)
  INTEGER*4 CCTKH50
  integer, parameter :: cctki_use_CCTKH50 = kind(CCTKH50)
  INTEGER*4 CCTKH52
  integer, parameter :: cctki_use_CCTKH52 = kind(CCTKH52)
  INTEGER*4 CCTKH55
  integer, parameter :: cctki_use_CCTKH55 = kind(CCTKH55)
  INTEGER*4 CCTKH56
  integer, parameter :: cctki_use_CCTKH56 = kind(CCTKH56)
  COMMON /IOrest/CCTKH5, CCTKH19, CCTKH29, CCTKH31, CCTKH33, CCTKH35, CCTKH37, CCTKH39, CCTKH41, CCTKH43, CCTKH45, CCTKH2, CCTKH3, &
  &CCTKH6, CCTKH9, CCTKH10, CCTKH11, CCTKH15, out_dir, CCTKH21, CCTKH22, CCTKH23, CCTKH25, CCTKH47, CCTKH49, CCTKH51, CCTKH53, CCTK&
  &H54, CCTKH57, CCTKH0, CCTKH1, CCTKH4, CCTKH7, CCTKH8, CCTKH12, CCTKH13, CCTKH14, CCTKH16, CCTKH17, CCTKH18, CCTKH20, CCTKH24, CC&
  &TKH26, CCTKH27, CCTKH28, CCTKH30, CCTKH32, CCTKH34, CCTKH36, CCTKH38, CCTKH40, CCTKH42, CCTKH44, CCTKH46, CCTKH48, CCTKH50, CCTK&
  &H52, CCTKH55, CCTKH56

  INTEGER*4, intent(in)     :: eoskey,ikeytemp,npoints
  INTEGER*4, intent(out)    :: keyerr(npoints)
  INTEGER*4, intent(out)    :: anyerr
  REAL*8, intent(in)    :: rf_precision
  REAL*8, intent(in)    :: ye(npoints),press(npoints)
  REAL*8, intent(inout) :: rho(npoints),temp(npoints),eps(npoints)
  REAL*8, intent(inout) :: entropy(npoints)


  
  integer        :: i,p
  character(256) :: warnstring
  integer :: keytemp
  
  real*8, dimension(1) :: xrho,xye,xtemp,xenr,xent
  real*8, dimension(1) :: xprs,xmunu,xcs2
  real*8, dimension(1) :: xdedt,xdpderho,xdpdrhoe
  
  integer :: ir
  real*8  :: gamma
  
  
  logical :: cont
  integer :: counter
  real*8, dimension(1) :: rho_guess, rho_guess2
  real*8, dimension(1) :: press_guess,press_guess2, mydpdrho
  real*8  :: fac
  keytemp = ikeytemp

  anyerr    = 0
  keyerr(:) = 0

  select case (eoskey)
     case (1)
        
        do i=1,npoints
           rho(i) = (press(i) / poly_k)**(1.0/poly_gamma)
           eps(i) = press(i) / (poly_gamma - 1.0d0) / rho(i)
        enddo
     case (2)
        
        do i=1,npoints
           rho(i) = press(i) / ((gl_gamma - 1.0d0)*eps(i))
        enddo
     case (3)
        
        write(warnstring,*) "EOS_Omni_RestMassDensityFromPressEpsTemp not supported for hybrid EOS"
        call CCTK_Error(1014,"EOS_Omni_SingleVarCalls.F90","EOS_Omni",warnstring)
        STOP
     case (4)
        
        if(ikeytemp.eq.2) then
           call CCTK_Error(1019,"EOS_Omni_SingleVarCalls.F90","EOS_Omni","This function does not work yet when coming in with entro&
  &py")
           STOP
        else if(ikeytemp.eq.1) then
           keytemp = 1
        else
           call CCTK_Error(1024,"EOS_Omni_SingleVarCalls.F90","EOS_Omni","This function does not work yet when coming in with this &
  &keytemp")
           STOP
        endif
        
        call CCTK_Error(1028,"EOS_Omni_SingleVarCalls.F90","EOS_Omni","This routine does not work with the new nuc_eos_cxx [yet]")
        STOP

        keytemp = 1
        do i=1,npoints
           fac = 1.0d0
           counter = 0
           cont = .true.
           xprs(1) = press(i)
           press_guess(1) = xprs(1)
           rho_guess(1) = rho(i)
           xprs(1) = press(i)
           xtemp(1) = temp(i)
           xye(1) = ye(i)
           do while(cont)
              counter = counter + 1
              rho_guess2 = rho_guess * 1.0001d0
              call nuc_eos_m_kt1_short(1,rho_guess2,xtemp,xye,xenr,&
                   press_guess2,xent,xcs2,xdedt,xdpderho,xdpdrhoe,xmunu,&
                   keyerr(i),anyerr)
              call nuc_eos_m_kt1_short(1,rho_guess2,xtemp,xye,xenr,&
                   press_guess2,xent,xcs2,xdedt,xdpderho,xdpdrhoe,xmunu,&
                   keyerr(i),anyerr)
              mydpdrho(1) = (press_guess2(1)-press_guess(1))/(rho_guess2(1)-rho_guess(1))
              if (mydpdrho(1).lt.0.0d0) then
                 !$OMP CRITICAL
                 write(warnstring,"(A25,1P10E15.6)") "Issue with table, dpdrho.lt.0",&
                      rho_guess,xtemp,xye
                 call CCTK_Error(1056,"EOS_Omni_SingleVarCalls.F90","EOS_Omni",warnstring)
                 !$OMP END CRITICAL
                 STOP
              endif
              
              if (abs(1.0d0-press_guess(1)/xprs(1)).lt.rf_precision) then
                 cont = .false.
                 rho(i) = rho_guess(1)
                 eps(i) = xenr(1)
              else
                 if (fac*(xprs(1)-press_guess(1))/mydpdrho(1)/rho_guess(1).gt.0.1d0) then
                    rho_guess = 0.99d0*rho_guess
                 else
                    rho_guess(1) = rho_guess(1) + fac*(xprs(1)-press_guess(1))/mydpdrho(1)
                 endif
              endif

              if (counter.gt.100) then
                 fac = 0.01d0
              endif

              if (rho_guess(1).lt.1.0d3.or.counter.gt.100000) then
                 keyerr(i) = 473
                 anyerr = 1
                 return
              endif
           enddo
        enddo
        
     case (5)
        
        
        if(keytemp.ne.1) then
           call CCTK_Error(1089,"EOS_Omni_SingleVarCalls.F90","EOS_Omni","finding rho(press) for tabulated cold EOS only possible i&
  &f keytemp=1")
           STOP
        endif

        do i=1,npoints
           fac = 1.0d0
           counter = 0
           cont = .true.
           xprs(1) = press(i)
           press_guess(1) = xprs(1)
           rho_guess(1) = rho(i)
           xprs(1) = press(i)
           do while(cont)
              counter = counter + 1
              rho_guess2(1) = rho_guess(1) * 1.0001d0

              
              if(rho_guess2(1).lt.coldeos_rhomin) then
                 keyerr(i) = 104
                 anyerr = 1
              else if(rho_guess2(1).gt.coldeos_rhomax) then
                 keyerr(i) = 103
                 anyerr = 1
              else
                 xrho(1) = log10(rho_guess2(1))
                 ir = 2 + INT( (xrho(1) - coldeos_logrho(1) - 1.0d-10) * coldeos_dlrhoi )
              endif
              ir = max(2, min(ir,coldeos_nrho))
           
              gamma = (coldeos_gamma(ir) - coldeos_gamma(ir-1)) / &
                (coldeos_logrho(ir) - coldeos_logrho(ir-1)) * &
                (xrho(1) - coldeos_logrho(ir-1)) + coldeos_gamma(ir-1)

              press_guess2(1) = coldeos_kappa * rho_guess2(1)**gamma
              
              
              if(rho_guess(1).lt.coldeos_rhomin) then
                 keyerr(i) = 104
                 anyerr = 1
              else if(rho_guess(1).gt.coldeos_rhomax) then
                 keyerr(i) = 103
                 anyerr = 1
              else
                 xrho(1) = log10(rho_guess(1))
                 ir = 2 + INT( (xrho(1) - coldeos_logrho(1) - 1.0d-10) * coldeos_dlrhoi )
              endif
              ir = max(2, min(ir,coldeos_nrho))
           
              gamma = (coldeos_gamma(ir) - coldeos_gamma(ir-1)) / &
                (coldeos_logrho(ir) - coldeos_logrho(ir-1)) * &
                (xrho(1) - coldeos_logrho(ir-1)) + coldeos_gamma(ir-1)

              press_guess(1) = coldeos_kappa * rho_guess(1)**gamma
              

              
              mydpdrho(1) = (press_guess2(1)-press_guess(1))/(rho_guess2(1)-rho_guess(1))
              if (mydpdrho(1).lt.0.0d0) then
                 !$OMP CRITICAL
                 write(warnstring,"(A25,1P10E15.6)") "Issue with table, dpdrho.lt.0",&
                      rho_guess(1),rho_guess2(1)
                 call CCTK_Error(1150,"EOS_Omni_SingleVarCalls.F90","EOS_Omni",warnstring)
                 !$OMP END CRITICAL
                 STOP
              endif
              
              if (abs(1.0d0-press_guess(1)/xprs(1)).lt.rf_precision) then
                 cont = .false.
                 rho(i) = rho_guess(1)
                 eps(i) = (coldeos_eps(ir) - coldeos_eps(ir-1)) / &
                    (coldeos_logrho(ir) - coldeos_logrho(ir-1)) * &
                    (xrho(1) - coldeos_logrho(ir-1)) + coldeos_eps(ir-1)
              else
                 if (fac*(xprs(1)-press_guess(1))/mydpdrho(1)/rho_guess(1).gt.0.1d0) then
                    rho_guess(1) = 0.99d0*rho_guess(1)
                 else
                    rho_guess(1) = rho_guess(1) + fac*(xprs(1)-press_guess(1))/mydpdrho(1)
                 endif
              endif

              if (counter.gt.100) then
                 fac = 0.01d0
              endif

              if (rho_guess(1).lt.1.0d-15.or.counter.gt.100000) then
                 keyerr(i) = 473
                 anyerr = 1
                 return
              endif
           enddo

        enddo

     case (6)
        
        
        if(keytemp.ne.1) then
           call CCTK_Error(1186,"EOS_Omni_SingleVarCalls.F90","EOS_Omni","finding rho(press) for tabulated barotropic EOS only poss&
  &ible if keytemp=1")
           STOP
        endif

        do i=1,npoints
           fac = 1.0d0
           counter = 0
           cont = .true.
           xprs(1) = press(i)
           press_guess(1) = xprs(1)
           rho_guess(1) = rho(i)
           do while(cont)
              counter = counter + 1
              rho_guess2(1) = rho_guess(1) * 1.0001d0

              
              if(rho_guess2(1).lt.barotropiceos_rhomin) then
                 keyerr(i) = 104
                 anyerr = 1
              else if(rho_guess2(1).gt.barotropiceos_rhomax) then
                 keyerr(i) = 103
                 anyerr = 1
              else
                 xrho(1) = log10(rho_guess2(1))
                 ir = 2 + INT( (xrho(1) - barotropiceos_logrho(1) - 1.0d-10) * barotropiceos_dlrhoi )
              endif
              ir = max(2, min(ir,barotropiceos_nrho))
           
              xprs(1) = (barotropiceos_logpress(ir) - barotropiceos_logpress(ir-1)) / &
                   (barotropiceos_logrho(ir) - barotropiceos_logrho(ir-1)) * &
                   (xrho(1) - barotropiceos_logrho(ir-1)) + barotropiceos_logpress(ir-1)
              
              press_guess2(1) = 10.0d0**xprs(1)
              
              
              if(rho_guess(1).lt.barotropiceos_rhomin) then
                 keyerr(i) = 104
                 anyerr = 1
              else if(rho_guess(1).gt.barotropiceos_rhomax) then
                 keyerr(i) = 103
                 anyerr = 1
              else
                 xrho(1) = log10(rho_guess(1))
                 ir = 2 + INT( (xrho(1) - barotropiceos_logrho(1) - 1.0d-10) * barotropiceos_dlrhoi )
              endif
              ir = max(2, min(ir,barotropiceos_nrho))
           
              xprs(1) = (barotropiceos_logpress(ir) - barotropiceos_logpress(ir-1)) / &
                (barotropiceos_logrho(ir) - barotropiceos_logrho(ir-1)) * &
                (xrho(1) - barotropiceos_logrho(ir-1)) + barotropiceos_logpress(ir-1)

              press_guess(1) = 10.0d0**xprs(1)
              

 

              
              mydpdrho(1) = (press_guess2(1)-press_guess(1))/(rho_guess2(1)-rho_guess(1))
              if (mydpdrho(1).lt.0.0d0) then
                 !$OMP CRITICAL
                 write(warnstring,"(A25,1P10E15.6)") "Issue with table, dpdrho.lt.0",&
                      rho_guess(1),rho_guess2(1)
                 call CCTK_Error(1248,"EOS_Omni_SingleVarCalls.F90","EOS_Omni",warnstring)
                 !$OMP END CRITICAL
                 STOP
              endif
              
              if (abs(1.0d0-press_guess(1)/press(i)).lt.rf_precision) then
                 cont = .false.
                 rho(i) = rho_guess(1)
                 xenr(1) = (barotropiceos_logeps(ir) - barotropiceos_logeps(ir-1)) / &
                      (barotropiceos_logrho(ir) - barotropiceos_logrho(ir-1)) * &
                      (xrho(1) - barotropiceos_logrho(ir-1)) + barotropiceos_logeps(ir-1)
                 eps(i) = 10.0d0**xenr(1) - barotropiceos_energyshift
              else
                 if (fac*(press(i)-press_guess(1))/mydpdrho(1)/rho_guess(1).gt.0.1d0) then
                    rho_guess(1) = 0.99d0*rho_guess(1)
                 else
                    rho_guess(1) = rho_guess(1) + fac*(press(i)-press_guess(1))/mydpdrho(1)
                 endif
              endif

              if (counter.gt.100) then
                 fac = 0.01d0
              endif

              if (rho_guess(1).lt.1.0d-15.or.counter.gt.100000) then





                 keyerr(i) = 473
                 anyerr = 1
                 return
              endif
           enddo

        enddo

     case DEFAULT
        write(warnstring,*) "eoskey ",eoskey," not implemented!"
        call CCTK_Error(1288,"EOS_Omni_SingleVarCalls.F90","EOS_Omni",warnstring)
        STOP
     end select

end subroutine EOS_Omni_EOS_RhoFromPressEpsTempEnt


subroutine EOS_Omni_EOS_PressEpsTempYe_from_Rho(eoskey,keytemp,rf_precision,npoints,&
                              rho,eps,temp,ye,press,keyerr,anyerr)

  use EOS_Omni_Module
  implicit none
  REAL*8 barotropiceos_gammath
  integer, parameter :: cctki_use_barotropiceos_gammath = kind(barotropiceos_gammath)
  REAL*8 gl_gamma
  integer, parameter :: cctki_use_gl_gamma = kind(gl_gamma)
  REAL*8 gl_k
  integer, parameter :: cctki_use_gl_k = kind(gl_k)
  REAL*8 hybrid_gamma (10)
  integer, parameter :: cctki_use_hybrid_gamma = kind(hybrid_gamma)
  REAL*8 hybrid_gamma1
  integer, parameter :: cctki_use_hybrid_gamma1 = kind(hybrid_gamma1)
  REAL*8 hybrid_gamma2
  integer, parameter :: cctki_use_hybrid_gamma2 = kind(hybrid_gamma2)
  REAL*8 hybrid_gamma_th
  integer, parameter :: cctki_use_hybrid_gamma_th = kind(hybrid_gamma_th)
  REAL*8 hybrid_k0
  integer, parameter :: cctki_use_hybrid_k0 = kind(hybrid_k0)
  REAL*8 hybrid_k1
  integer, parameter :: cctki_use_hybrid_k1 = kind(hybrid_k1)
  REAL*8 hybrid_rho (9)
  integer, parameter :: cctki_use_hybrid_rho = kind(hybrid_rho)
  REAL*8 hybrid_rho_nuc
  integer, parameter :: cctki_use_hybrid_rho_nuc = kind(hybrid_rho_nuc)
  REAL*8 poly_gamma
  integer, parameter :: cctki_use_poly_gamma = kind(poly_gamma)
  REAL*8 poly_gamma_initial
  integer, parameter :: cctki_use_poly_gamma_initial = kind(poly_gamma_initial)
  REAL*8 poly_k
  integer, parameter :: cctki_use_poly_k = kind(poly_k)
  integer*8 barotropiceos_table_name
  integer, parameter :: cctki_use_barotropiceos_table_name = kind(barotropiceos_table_name)
  integer*8 coldeos_table_name
  integer, parameter :: cctki_use_coldeos_table_name = kind(coldeos_table_name)
  integer*8 dump_nuceos_table_name
  integer, parameter :: cctki_use_dump_nuceos_table_name = kind(dump_nuceos_table_name)
  integer*8 nuceos_table_name
  integer, parameter :: cctki_use_nuceos_table_name = kind(nuceos_table_name)
  INTEGER*4 barotropiceos_read_table
  integer, parameter :: cctki_use_barotropiceos_read_table = kind(barotropiceos_read_table)
  INTEGER*4 barotropiceos_use_thermal_gamma_law
  integer, parameter :: cctki_use_barotropiceos_use_thermal_gamma_law = kind(barotropiceos_use_thermal_gamma_law)
  INTEGER*4 coldeos_read_table
  integer, parameter :: cctki_use_coldeos_read_table = kind(coldeos_read_table)
  INTEGER*4 coldeos_use_thermal_gamma_law
  integer, parameter :: cctki_use_coldeos_use_thermal_gamma_law = kind(coldeos_use_thermal_gamma_law)
  INTEGER*4 do_energy_shift
  integer, parameter :: cctki_use_do_energy_shift = kind(do_energy_shift)
  INTEGER*4 dump_nuceos_table
  integer, parameter :: cctki_use_dump_nuceos_table = kind(dump_nuceos_table)
  INTEGER*4 n_pieces
  integer, parameter :: cctki_use_n_pieces = kind(n_pieces)
  INTEGER*4 nuceos_read_table
  integer, parameter :: cctki_use_nuceos_read_table = kind(nuceos_read_table)
  INTEGER*4 read_table_on_single_process
  integer, parameter :: cctki_use_read_table_on_single_process = kind(read_table_on_single_process)
  INTEGER*4 reader_process
  integer, parameter :: cctki_use_reader_process = kind(reader_process)
  COMMON /EOS_Omnirest/barotropiceos_gammath, gl_gamma, gl_k, hybrid_gamma, hybrid_gamma1, hybrid_gamma2, hybrid_gamma_th, hybrid_k&
  &0, hybrid_k1, hybrid_rho, hybrid_rho_nuc, poly_gamma, poly_gamma_initial, poly_k, barotropiceos_table_name, coldeos_table_name, &
  &dump_nuceos_table_name, nuceos_table_name, barotropiceos_read_table, barotropiceos_use_thermal_gamma_law, coldeos_read_table, co&
  &ldeos_use_thermal_gamma_law, do_energy_shift, dump_nuceos_table, n_pieces, nuceos_read_table, read_table_on_single_process, read&
  &er_process
  REAL*8 CCTKH5
  integer, parameter :: cctki_use_CCTKH5 = kind(CCTKH5)
  REAL*8 CCTKH19
  integer, parameter :: cctki_use_CCTKH19 = kind(CCTKH19)
  REAL*8 CCTKH29
  integer, parameter :: cctki_use_CCTKH29 = kind(CCTKH29)
  REAL*8 CCTKH31
  integer, parameter :: cctki_use_CCTKH31 = kind(CCTKH31)
  REAL*8 CCTKH33
  integer, parameter :: cctki_use_CCTKH33 = kind(CCTKH33)
  REAL*8 CCTKH35
  integer, parameter :: cctki_use_CCTKH35 = kind(CCTKH35)
  REAL*8 CCTKH37
  integer, parameter :: cctki_use_CCTKH37 = kind(CCTKH37)
  REAL*8 CCTKH39
  integer, parameter :: cctki_use_CCTKH39 = kind(CCTKH39)
  REAL*8 CCTKH41
  integer, parameter :: cctki_use_CCTKH41 = kind(CCTKH41)
  REAL*8 CCTKH43
  integer, parameter :: cctki_use_CCTKH43 = kind(CCTKH43)
  REAL*8 CCTKH45
  integer, parameter :: cctki_use_CCTKH45 = kind(CCTKH45)
  integer*8 CCTKH2
  integer, parameter :: cctki_use_CCTKH2 = kind(CCTKH2)
  integer*8 CCTKH3
  integer, parameter :: cctki_use_CCTKH3 = kind(CCTKH3)
  integer*8 CCTKH6
  integer, parameter :: cctki_use_CCTKH6 = kind(CCTKH6)
  integer*8 CCTKH9
  integer, parameter :: cctki_use_CCTKH9 = kind(CCTKH9)
  integer*8 CCTKH10
  integer, parameter :: cctki_use_CCTKH10 = kind(CCTKH10)
  integer*8 CCTKH11
  integer, parameter :: cctki_use_CCTKH11 = kind(CCTKH11)
  integer*8 CCTKH15
  integer, parameter :: cctki_use_CCTKH15 = kind(CCTKH15)
  integer*8 out_dir
  integer, parameter :: cctki_use_out_dir = kind(out_dir)
  integer*8 CCTKH21
  integer, parameter :: cctki_use_CCTKH21 = kind(CCTKH21)
  integer*8 CCTKH22
  integer, parameter :: cctki_use_CCTKH22 = kind(CCTKH22)
  integer*8 CCTKH23
  integer, parameter :: cctki_use_CCTKH23 = kind(CCTKH23)
  integer*8 CCTKH25
  integer, parameter :: cctki_use_CCTKH25 = kind(CCTKH25)
  integer*8 CCTKH47
  integer, parameter :: cctki_use_CCTKH47 = kind(CCTKH47)
  integer*8 CCTKH49
  integer, parameter :: cctki_use_CCTKH49 = kind(CCTKH49)
  integer*8 CCTKH51
  integer, parameter :: cctki_use_CCTKH51 = kind(CCTKH51)
  integer*8 CCTKH53
  integer, parameter :: cctki_use_CCTKH53 = kind(CCTKH53)
  integer*8 CCTKH54
  integer, parameter :: cctki_use_CCTKH54 = kind(CCTKH54)
  integer*8 CCTKH57
  integer, parameter :: cctki_use_CCTKH57 = kind(CCTKH57)
  INTEGER*4 CCTKH0
  integer, parameter :: cctki_use_CCTKH0 = kind(CCTKH0)
  INTEGER*4 CCTKH1
  integer, parameter :: cctki_use_CCTKH1 = kind(CCTKH1)
  INTEGER*4 CCTKH4
  integer, parameter :: cctki_use_CCTKH4 = kind(CCTKH4)
  INTEGER*4 CCTKH7
  integer, parameter :: cctki_use_CCTKH7 = kind(CCTKH7)
  INTEGER*4 CCTKH8
  integer, parameter :: cctki_use_CCTKH8 = kind(CCTKH8)
  INTEGER*4 CCTKH12
  integer, parameter :: cctki_use_CCTKH12 = kind(CCTKH12)
  INTEGER*4 CCTKH13
  integer, parameter :: cctki_use_CCTKH13 = kind(CCTKH13)
  INTEGER*4 CCTKH14
  integer, parameter :: cctki_use_CCTKH14 = kind(CCTKH14)
  INTEGER*4 CCTKH16
  integer, parameter :: cctki_use_CCTKH16 = kind(CCTKH16)
  INTEGER*4 CCTKH17
  integer, parameter :: cctki_use_CCTKH17 = kind(CCTKH17)
  INTEGER*4 CCTKH18
  integer, parameter :: cctki_use_CCTKH18 = kind(CCTKH18)
  INTEGER*4 CCTKH20
  integer, parameter :: cctki_use_CCTKH20 = kind(CCTKH20)
  INTEGER*4 CCTKH24
  integer, parameter :: cctki_use_CCTKH24 = kind(CCTKH24)
  INTEGER*4 CCTKH26
  integer, parameter :: cctki_use_CCTKH26 = kind(CCTKH26)
  INTEGER*4 CCTKH27
  integer, parameter :: cctki_use_CCTKH27 = kind(CCTKH27)
  INTEGER*4 CCTKH28
  integer, parameter :: cctki_use_CCTKH28 = kind(CCTKH28)
  INTEGER*4 CCTKH30
  integer, parameter :: cctki_use_CCTKH30 = kind(CCTKH30)
  INTEGER*4 CCTKH32
  integer, parameter :: cctki_use_CCTKH32 = kind(CCTKH32)
  INTEGER*4 CCTKH34
  integer, parameter :: cctki_use_CCTKH34 = kind(CCTKH34)
  INTEGER*4 CCTKH36
  integer, parameter :: cctki_use_CCTKH36 = kind(CCTKH36)
  INTEGER*4 CCTKH38
  integer, parameter :: cctki_use_CCTKH38 = kind(CCTKH38)
  INTEGER*4 CCTKH40
  integer, parameter :: cctki_use_CCTKH40 = kind(CCTKH40)
  INTEGER*4 CCTKH42
  integer, parameter :: cctki_use_CCTKH42 = kind(CCTKH42)
  INTEGER*4 CCTKH44
  integer, parameter :: cctki_use_CCTKH44 = kind(CCTKH44)
  INTEGER*4 CCTKH46
  integer, parameter :: cctki_use_CCTKH46 = kind(CCTKH46)
  INTEGER*4 CCTKH48
  integer, parameter :: cctki_use_CCTKH48 = kind(CCTKH48)
  INTEGER*4 CCTKH50
  integer, parameter :: cctki_use_CCTKH50 = kind(CCTKH50)
  INTEGER*4 CCTKH52
  integer, parameter :: cctki_use_CCTKH52 = kind(CCTKH52)
  INTEGER*4 CCTKH55
  integer, parameter :: cctki_use_CCTKH55 = kind(CCTKH55)
  INTEGER*4 CCTKH56
  integer, parameter :: cctki_use_CCTKH56 = kind(CCTKH56)
  COMMON /IOrest/CCTKH5, CCTKH19, CCTKH29, CCTKH31, CCTKH33, CCTKH35, CCTKH37, CCTKH39, CCTKH41, CCTKH43, CCTKH45, CCTKH2, CCTKH3, &
  &CCTKH6, CCTKH9, CCTKH10, CCTKH11, CCTKH15, out_dir, CCTKH21, CCTKH22, CCTKH23, CCTKH25, CCTKH47, CCTKH49, CCTKH51, CCTKH53, CCTK&
  &H54, CCTKH57, CCTKH0, CCTKH1, CCTKH4, CCTKH7, CCTKH8, CCTKH12, CCTKH13, CCTKH14, CCTKH16, CCTKH17, CCTKH18, CCTKH20, CCTKH24, CC&
  &TKH26, CCTKH27, CCTKH28, CCTKH30, CCTKH32, CCTKH34, CCTKH36, CCTKH38, CCTKH40, CCTKH42, CCTKH44, CCTKH46, CCTKH48, CCTKH50, CCTK&
  &H52, CCTKH55, CCTKH56

  INTEGER*4, intent(in)     :: eoskey,keytemp,npoints
  INTEGER*4, intent(out)    :: keyerr(npoints)
  INTEGER*4, intent(out)    :: anyerr
  REAL*8, intent(in)    :: rf_precision
  REAL*8, intent(in)    :: rho(npoints)
  REAL*8, intent(out)   :: eps(npoints), ye(npoints) 
  REAL*8, intent(out)   :: temp(npoints),press(npoints)

  
  integer          :: i,p
  character(256)   :: warnstring
  
  real*8, dimension(1):: xrho,xye,xtemp,xenr
  real*8, dimension(1):: xprs
  integer :: ir
  real*8 :: press_cold, press_th
  real*8 :: eps_cold, eps_th

  anyerr    = 0
  keyerr(:) = 0

  select case (eoskey)
     case (6)
        
        do i=1,npoints
           if(rho(i).lt.barotropiceos_rhomin) then
              press(i) = barotropiceos_low_kappa * rho(i)**barotropiceos_low_gamma
              eps(i) = press(i) / (barotropiceos_low_gamma - 1.0) / rho(i) 
              cycle
           else if(rho(i).gt.barotropiceos_rhomax) then
              keyerr(i) = 103
              anyerr = 1
           else
              xrho(1) = log10(rho(i))
              ir = 2 + &
                   INT( (xrho(1) - barotropiceos_logrho(1) - 1.0d-10) &
                   * barotropiceos_dlrhoi )
           endif
           ir = max(2, min(ir,barotropiceos_nrho))

           xprs(1) = (barotropiceos_logpress(ir) - barotropiceos_logpress(ir-1)) / &
                (barotropiceos_logrho(ir) - barotropiceos_logrho(ir-1)) * &
                (xrho(1) - barotropiceos_logrho(ir-1)) + barotropiceos_logpress(ir-1)

           xenr(1) = (barotropiceos_logeps(ir) - barotropiceos_logeps(ir-1)) / &
                (barotropiceos_logrho(ir) - barotropiceos_logrho(ir-1)) * &
                (xrho(1) - barotropiceos_logrho(ir-1)) + barotropiceos_logeps(ir-1)

           xtemp(1) = (barotropiceos_temp(ir) - barotropiceos_temp(ir-1)) / &
                (barotropiceos_logrho(ir) - barotropiceos_logrho(ir-1)) * &
                (xrho(1) - barotropiceos_logrho(ir-1)) + barotropiceos_temp(ir-1)

           xye(1) = (barotropiceos_ye(ir) - barotropiceos_ye(ir-1)) / &
                (barotropiceos_logrho(ir) - barotropiceos_logrho(ir-1)) * &
                (xrho(1) - barotropiceos_logrho(ir-1)) + barotropiceos_ye(ir-1)

           press_cold = 10.0**xprs(1)
           eps_cold = 10.0**xenr(1) - barotropiceos_energyshift

           if(keytemp.eq.0) then
              eps_th = max(0.0d0,eps(i) - eps_cold)
           else if (keytemp.eq.1) then
              eps_th = 0.0d0
              eps(i) = eps_cold
           endif
           press_th = coldeos_thfac*(barotropiceos_gammath - 1.0d0)*rho(i)*eps_th
           press(i) = press_cold + press_th

           temp(i) = xtemp(1)
           ye(i) = xye(1)

        enddo

     case DEFAULT
        write(warnstring,*) "eoskey ",eoskey," not implemented for EOS_Omni_EOS_PressEpsTempYe_from_Rho!"
        call CCTK_Error(1377,"EOS_Omni_SingleVarCalls.F90","EOS_Omni",warnstring)
        STOP
     end select

   end subroutine EOS_Omni_EOS_PressEpsTempYe_from_Rho
