PHYEX 0.9.5
PHYsique EXternalisée
Loading...
Searching...
No Matches
gamma.h
Go to the documentation of this file.
1!MNH_LIC Copyright 1995-2025 CNRS, Meteo-France and Universite Paul Sabatier
2!MNH_LIC This is part of the Meso-NH software governed by the CeCILL-C licence
3!MNH_LIC version 1. See LICENSE, CeCILL-C_V1-en.txt and CeCILL-C_V1-fr.txt
4!MNH_LIC for details. version 1.
5!--------------------------------------------------------------------------
6! ******* TO BE INCLUDED IN THE *CONTAINS* OF A SUBROUTINE OR FUNCTION ******
7! => Don't use drHook !!!
8! The GAMMA function defined here hides the intrinsic function of the same name.
9! GAMMA_DBLE is the same function for double precision arguments (whatever the
10! precision of the default REAL).
11!
12! ######################################
13 ELEMENTAL FUNCTION gamma(PX) RESULT(PGAMMA)
14! ######################################
15!
16!
17!!**** *GAMMA * - Gamma function
18!!
19!!
20!! PURPOSE
21!! -------
22! The purpose of this function is to compute the Generalized gamma
23! function of its argument.
24!
25!
26!!** METHOD
27!! ------
28!!
29!! EXTERNAL
30!! --------
31!! NONE
32!!
33!! IMPLICIT ARGUMENTS
34!! ------------------
35!! None
36!!
37!! REFERENCE
38!! ---------
39!! Press, Teukolsky, Vetterling and Flannery: Numerical Recipes, 206-207
40!!
41!! AUTHOR
42!! ------
43!! Jean-Pierre Pinty *LA/OMP*
44!!
45!! MODIFICATIONS
46!! -------------
47!! Original 7/11/95
48!! C. Barthe 9/11/09 add a function for 1D arguments
49! P. Wautelet 22/06/2022: GAMMA_X0D is now declared PURE
50! S. Riette Nov 2026: elemental function in gamma.h (replaces GAMMA_X0D and GAMMA_X1D)
51!
52!* 0. DECLARATIONS
53! ------------
54!
55IMPLICIT NONE
56
57!$acc routine seq
58
59!
60!* 0.1 declarations of arguments and result
61!
62REAL, INTENT(IN) :: px
63REAL :: pgamma
64!
65!* 0.2 declarations of local variables
66!
67INTEGER :: jj ! Loop index
68REAL :: zser,zstp,ztmp,zx,zy
69REAL, DIMENSION(6), PARAMETER :: zcoef=(/76.18009172947146, &
70 &-86.50532032941677, &
71 & 24.01409824083091, &
72 & -1.231739572450155, &
73 & 0.1208650973866179E-2, &
74 & -0.5395239384953E-5/)
75real :: zpi
76!
77!-------------------------------------------------------------------------------
78!
79!* 1. SOME CONSTANTS
80! --------------
81!
82zstp = 2.5066282746310005
83!
84zpi = 3.141592654
85!
86!-------------------------------------------------------------------------------
87!
88!* 2. COMPUTE GAMMA
89! -------------
90!
91IF (px .LT. 0.) THEN
92 zx = 1. - px
93ELSE
94 zx = px
95END IF
96zy = zx
97ztmp = zx + 5.5
98ztmp = (zx + 0.5) * log(ztmp) - ztmp
99zser = 1.000000000190015
100!
101DO jj = 1, 6
102 zy = zy + 1.0
103 zser = zser + zcoef(jj) / zy
104END DO
105!
106IF (px .LT. 0.) THEN
107 pgamma = zpi / sin(zpi*px) / exp(ztmp + log(zstp*zser/zx))
108ELSE
109 pgamma = exp(ztmp + log(zstp*zser/zx))
110END IF
111!
112END FUNCTION gamma
113!
114!-------------------------------------------------------------------------------
115!
116! ######################################
117 ELEMENTAL FUNCTION gamma_dble(PX) RESULT(PGAMMA)
118! ######################################
119!
120!!**** *GAMMA_DBLE * - Gamma function for double precision arguments
121!!
122!! PURPOSE
123!! -------
124! Same computation as the GAMMA function, done in double precision whatever
125! the precision of the default REAL (the results are identical to those of
126! GAMMA when the default REAL is in double precision)
127!
128!* 0. DECLARATIONS
129! ------------
130!
131USE modd_precision, ONLY: mnhreal64
132!
133IMPLICIT NONE
134
135!$acc routine seq
136
137!
138!* 0.1 declarations of arguments and result
139!
140REAL(kind=mnhreal64), INTENT(IN) :: px
141REAL(kind=mnhreal64) :: pgamma
142!
143!* 0.2 declarations of local variables
144!
145INTEGER :: jj ! Loop index
146REAL(kind=mnhreal64) :: zser,zstp,ztmp,zx,zy
147REAL(kind=mnhreal64), DIMENSION(6), PARAMETER :: zcoef=(/76.18009172947146_mnhreal64, &
148 &-86.50532032941677_mnhreal64, &
149 & 24.01409824083091_mnhreal64, &
150 & -1.231739572450155_mnhreal64, &
151 & 0.1208650973866179e-2_mnhreal64, &
152 & -0.5395239384953e-5_mnhreal64/)
153REAL(kind=mnhreal64) :: zpi
154!
155!-------------------------------------------------------------------------------
156!
157!* 1. SOME CONSTANTS
158! --------------
159!
160zstp = 2.5066282746310005_mnhreal64
161!
162zpi = 3.141592654_mnhreal64
163!
164!-------------------------------------------------------------------------------
165!
166!* 2. COMPUTE GAMMA
167! -------------
168!
169IF (px .LT. 0._mnhreal64) THEN
170 zx = 1._mnhreal64 - px
171ELSE
172 zx = px
173END IF
174zy = zx
175ztmp = zx + 5.5_mnhreal64
176ztmp = (zx + 0.5_mnhreal64) * log(ztmp) - ztmp
177zser = 1.000000000190015_mnhreal64
178!
179DO jj = 1, 6
180 zy = zy + 1.0_mnhreal64
181 zser = zser + zcoef(jj) / zy
182END DO
183!
184IF (px .LT. 0._mnhreal64) THEN
185 pgamma = zpi / sin(zpi*px) / exp(ztmp + log(zstp*zser/zx))
186ELSE
187 pgamma = exp(ztmp + log(zstp*zser/zx))
188END IF
189!
190END FUNCTION gamma_dble
elemental real function gamma(px)
Definition gamma.h:14
elemental real(kind=mnhreal64) function gamma_dble(px)
Definition gamma.h:118
integer, parameter mnhreal64