!.....EOS module for the Hempel and Schaffner-Bielich EOS v1.03 in the
!.....extended format, which includes electrons, positrons and photons.
!.....RMF Parameterization: ASB
!.....Nuclear mass table: FRDM
      module asb_frdm_eos_module

      implicit none

!.....t_entries: number of temperature entries
!.....y_entries: number of electron fraction entries, not counting ye=0
!.....nb_entries: number of nb entries
!.....entries: number of EOS entries per grid-point
!.....eos(i,j,k,l): EOS array
!.....i=1, ..., t_entries: temperature index
!.....j=0, ..., y_entries: electron fraction index
!.....k=1, ..., nb_entries: baryon number density index
!.....l=1, ..., entries: EOS entry index

!.....brief list of the entries:
!.....==========================
!.....1	baryon number density: nb [fm^-3]
!.....2	total proton fraction: yp (=ye)
!.....3	internal energy per baryon e/nb: [MeV]
!.....4	pressure p: [MeV/fm^3]
!.....5	entropy per baryon: s/nb
!.....6	neutron chemical potential wrt m_n: mu_n-m_n [MeV]
!.....7	proton chemical potential wrt m_n: mu_p-m_p [MeV]
!.....8	electron chemical potential wrt m_e: mu_e_m_e [MeV]
!.....9	free energy per baryon: f/nb [MeV]
!.....10	unbound neutron mass fraction: X_n
!.....11	unbound proton mass fraction: X_p
!.....12	deuteron mass fraction: X_d
!.....13	triton mass fraction: X_t
!.....14	helion mass fraction: X_h
!.....15	alpha mass fraction: X_alpha
!.....16	heavy nuclei mass fraction: X_A
!.....17	averaged mass number of heavy nuclei: <A>
!.....18	averaged charge number of heavy nuclei: <Z>

!.....t: temperature array [MeV]
!.....y: nominal electron fraction array
!.....nb: nominal baryon number density array [fm^-3]
      integer, parameter :: t_entries = 81
      integer, parameter :: y_entries = 60
      integer, parameter :: nb_entries = 326
      integer, parameter :: entries = 18
      double precision, 
     & dimension(t_entries,0:y_entries,nb_entries,entries) :: eos
      double precision, dimension(t_entries) :: t
      double precision, dimension(0:y_entries) :: y
      double precision, dimension(nb_entries) :: nb

      contains

!.....This subroutine reads in the binary EOS table (generated with
!.....ifort on a 64 bit machine) and calculates the temperature,
!.....nominal electron fraction and nominal baryon number density arrays
        subroutine eos_readin

        implicit none
!.....define the constants of the t, y, and nb array
        double precision, parameter :: nbin = 1.0d-12
        double precision, parameter :: tin = 0.1d0
        double precision, parameter :: yin = 0.0d0
        double precision, parameter :: dnb = 0.04d0
        double precision, parameter :: dt = 0.04d0
        double precision, parameter :: dy = 0.01d0
        integer :: i, j, k

        open(10,file='asb_frdm_eos_v1.03.bin',form='unformatted',
     & status='old')
        read(10)eos
        close(10)

!.....calculate the temperature array
        do i=1,t_entries
          t(i)=tin*10.0d0**(dble(i-1)*dt)
        end do
!.....calculate the electron fraction array
        do j=0,y_entries
          y(j)=yin+dble(j)*dy
        end do
!.....calculate the baryon number density array
        do k=1,nb_entries
          nb(k)=nbin*10.0d0**(dble(k-1)*dnb)
        end do

        return
        end subroutine eos_readin

      end module asb_frdm_eos_module
