SCALE-RM
scale_specfunc.F90
Go to the documentation of this file.
1 !-------------------------------------------------------------------------------
13 #include "scalelib.h"
15  !-----------------------------------------------------------------------------
16  !
17  !++ used modules
18  !
19  use scale_precision
20  use scale_io
21  use scale_prof
22  !-----------------------------------------------------------------------------
23  implicit none
24  private
25  !-----------------------------------------------------------------------------
26  !
27  !++ Public procedure
28  !
29  public :: sf_gamma
30 
31  !-----------------------------------------------------------------------------
32  !
33  !++ Public parameters & variables
34  !
35  !-----------------------------------------------------------------------------
36  !
37  !++ Private procedure
38  !
39  !-----------------------------------------------------------------------------
40  !
41  !++ Private parameters & variables
42  !
43  !-----------------------------------------------------------------------------
44 contains
45  !-----------------------------------------------------------------------------
47  ! Lanczos approximation
48  ! g = 7.0, N = 8
49  function sf_gamma(x)
50  implicit none
51 
52  real(rp), intent(in) :: x
53  real(rp) :: sf_gamma
54 
55  real(dp), parameter :: lrtp = 0.9189385332046727_dp ! log(sqrt(2*PI))
56  real(dp) :: ag, dx, work
57  !---------------------------------------------------------------------------
58 
59  dx = real(x-1.0_rp, kind=dp)
60 
61  ag = 0.999999999999809932276847004735_dp &
62  + 676.520368121885098567009190444_dp / ( dx + 1.0_dp ) &
63  - 1259.13921672240287047156078755_dp / ( dx + 2.0_dp ) &
64  + 771.323428777653078848652825889_dp / ( dx + 3.0_dp ) &
65  - 176.615029162140599065845513540_dp / ( dx + 4.0_dp ) &
66  + 12.5073432786869048144589368533_dp / ( dx + 5.0_dp ) &
67  - 0.138571095265720116895547069851_dp / ( dx + 6.0_dp ) &
68  + 9.98436957801957085956266899569e-6_dp / ( dx + 7.0_dp ) &
69  + 1.50563273514931155833835577539e-7_dp / ( dx + 8.0_dp )
70 
71  work = exp( lrtp + (dx+0.5_dp)*log(dx+7.5_dp) - (dx+7.5_dp) + log(ag) )
72  sf_gamma = real(work, kind=rp)
73 
74  return
75  end function sf_gamma
76 
77 end module scale_specfunc
scale_precision
module PRECISION
Definition: scale_precision.F90:14
scale_precision::rp
integer, parameter, public rp
Definition: scale_precision.F90:41
scale_io
module STDIO
Definition: scale_io.F90:10
scale_prof
module profiler
Definition: scale_prof.F90:11
scale_precision::dp
integer, parameter, public dp
Definition: scale_precision.F90:32
scale_specfunc
module SPECFUNC
Definition: scale_specfunc.F90:14
scale_specfunc::sf_gamma
real(rp) function, public sf_gamma(x)
Gamma function.
Definition: scale_specfunc.F90:50