116 lines
2.8 KiB
Fortran
116 lines
2.8 KiB
Fortran
module moduleTableTtoZ
|
|
use constantParameters, only: dp
|
|
|
|
type:: tableTtoZ
|
|
real(dp):: Z_min, Z_max
|
|
real(dp):: Temp_min, Temp_max
|
|
real(dp), allocatable, dimension(:):: Temp
|
|
real(dp), allocatable, dimension(:):: Z
|
|
real(dp), allocatable, dimension(:):: Z_k
|
|
contains
|
|
procedure, pass:: init => initTableTtoZ
|
|
procedure, pass:: get => getValueTableTtoZ
|
|
|
|
end type tableTtoZ
|
|
|
|
contains
|
|
subroutine initTableTtoZ(self, tableFile)
|
|
use constantParameters, only: eV_to_K
|
|
use referenceValues, only: Temp_ref
|
|
implicit none
|
|
|
|
class(tableTtoZ), intent(inout):: self
|
|
character(:), allocatable, intent(in):: tableFile
|
|
character(100):: dummy
|
|
integer:: amount
|
|
integer:: i
|
|
integer:: stat
|
|
integer:: id = 20
|
|
|
|
open(id, file = tableFile)
|
|
amount = -1 ! Remove header
|
|
do
|
|
read(id, '(A)', iostat = stat) dummy
|
|
!If EOF or error, exit file
|
|
if (stat /= 0) EXIT
|
|
! !Skip comment
|
|
! if (index(dummy,'#') /= 0) CYCLE
|
|
!Add row
|
|
amount = amount + 1
|
|
|
|
end do
|
|
|
|
!Go bback to initial point
|
|
rewind(id)
|
|
|
|
!Allocate table arrays
|
|
allocate(self%Temp(1:amount))
|
|
allocate(self%Z(1:amount))
|
|
allocate(self%Z_k(1:amount))
|
|
self%Temp = 0.0_dp
|
|
self%Z = 0.0_dp
|
|
self%Z_k = 0.0_dp
|
|
|
|
i = 0
|
|
read(id, *) ! Skip header
|
|
do
|
|
read(id, '(A)', iostat = stat) dummy
|
|
!TOdo: Make this a function
|
|
if (stat /= 0) EXIT
|
|
!Add data
|
|
!TODO: substitute with extracting information from dummy
|
|
backspace(id)
|
|
i = i + 1
|
|
read(id, *) self%Temp(i), self%Z(i)
|
|
|
|
end do
|
|
self%Temp = self%Temp * eV_to_K / Temp_ref
|
|
|
|
close(id)
|
|
|
|
self%Temp_min = self%Temp(1)
|
|
self%Temp_max = self%Temp(amount)
|
|
self%Z_min = self%Z(1)
|
|
self%Z_max = self%Z(amount)
|
|
|
|
do i = 1, amount - 1
|
|
self%Z_k(i) = ( self%Z(i+1) - self%Z(i))/(self%Temp(i+1) - self%Temp(i))
|
|
|
|
end do
|
|
|
|
end subroutine initTableTtoZ
|
|
|
|
subroutine getValueTableTtoZ(self, Temp, Z)
|
|
implicit none
|
|
|
|
class(tableTtoZ), intent(in):: self
|
|
real(dp), intent(in):: Temp
|
|
real(dp), intent(out):: Z
|
|
real(dp):: delta_Temp
|
|
integer:: i
|
|
|
|
if (Temp <= self%Temp_min) THEN
|
|
Z = self%Z_min
|
|
|
|
elseif (Temp >= self%Temp_max) THEN
|
|
Z = self%Z_max
|
|
|
|
else
|
|
i = minloc(abs(Temp - self%Temp), 1)
|
|
delta_Temp = Temp - self%Temp(i)
|
|
if (delta_Temp < 0 ) THEN
|
|
i = i - 1
|
|
delta_Temp = Temp - self%Temp(i)
|
|
|
|
end if
|
|
|
|
Z = self%Z(i) + self%Z_k(i)*delta_Temp
|
|
|
|
end if
|
|
|
|
end subroutine getValueTableTtoZ
|
|
|
|
|
|
|
|
end module moduleTableTtoZ
|
|
|