@brief Extended trapezoidal rule for integrating the Gamma PDF. See Sec. 4.2 of Numerical Recipies in Fortran 77.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
real(kind=rp), | intent(in) | :: | a | |||
real(kind=rp), | intent(in) | :: | b | |||
real(kind=rp), | intent(in) | :: | k | |||
real(kind=rp), | intent(in) | :: | t |
FUNCTION IntGamma(a,b,k,t)
REAL(rp), INTENT(IN) :: a
REAL(rp), INTENT(IN) :: b
REAL(rp), INTENT(IN) :: k ! shape factor
REAL(rp), INTENT(IN) :: t ! scale factor
REAL(rp) :: IntGamma
REAL(rp) :: Iold
REAL(rp) :: Inew
REAL(rp) :: rerr
REAL(rp) :: sum_f
REAL(rp) :: h,z
INTEGER :: ii,jj,npoints
LOGICAL :: flag
h = b - a
sum_f = 0.5*(fGamma(a,k,t) + fGamma(b,k,t))
Iold = 0.0_rp
Inew = sum_f*h
ii = 1_idef
flag = .TRUE.
do while (flag)
Iold = Inew
ii = ii + 1_idef
npoints = 2_idef**(ii-2_idef)
h = 0.5_rp*(b-a)/REAL(npoints,rp)
sum_f = 0.0_rp
do jj=1_idef,npoints
z = a + h + 2.0_rp*(REAL(jj,rp) - 1.0_rp)*h
sum_f = sum_f + fGamma(z,k,t)
end do
Inew = 0.5_rp*Iold + sum_f*h
rerr = ABS((Inew - Iold)/Iold)
flag = .NOT.(rerr.LT.Tol)
end do
IntGamma = Inew
END FUNCTION IntGamma