PHYEX 0.9.5
PHYsique EXternalisée
Loading...
Searching...
No Matches
gamma_inc.F90
Go to the documentation of this file.
1!MNH_LIC Copyright 1995-2019 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 FUNCTION gamma_inc(PA,PX) RESULT(PGAMMA_INC)
6 USE yomhook , ONLY : lhook, dr_hook, jphook
7! #############################################
8!
9!
10!!**** *GAMMA_INC * - Generalized gamma function
11!!
12!!
13!! PURPOSE
14!! -------
15! The purpose of this function is to compute the generalized
16!! incomplete Gamma function of its argument.
17!!
18!! /X
19!! 1 |
20!! GAMMA_INC(A,X)= -------- | Z**(A-1) EXP(-Z) dZ
21!! GAMMA(A) |
22!! /0
23!!
24!!** METHOD
25!! ------
26!!
27!! EXTERNAL
28!! --------
29!! NONE
30!!
31!! IMPLICIT ARGUMENTS
32!! ------------------
33!! gamma.h : computation of the Gamma function (GAMMA)
34!!
35!! REFERENCE
36!! ---------
37!! Press, Teukolsky, Vetterling and Flannery: Numerical Recipes, 209-213
38!!
39!!
40!! AUTHOR
41!! ------
42!! Jean-Pierre Pinty *LA/OMP*
43!!
44!! MODIFICATIONS
45!! -------------
46!! Original 7/12/95
47! P. Wautelet 10/04/2019: replace ABORT and STOP calls by Print_msg
48! P. Wautelet 26/04/2019: replace non-standard FLOAT function by REAL function
49!
50!* 0. DECLARATIONS
51! ------------
52!
53USE mode_msg, ONLY: print_msg
54!
55USE modd_io, ONLY:nverb_fatal
56!
57IMPLICIT NONE
58!
59!* 0.1 declarations of arguments and result
60!
61REAL, INTENT(IN) :: pa
62REAL, INTENT(IN) :: px
63REAL :: pgamma_inc
64!
65!* 0.2 declarations of local variables
66!
67INTEGER :: jn
68INTEGER :: itmax=100
69REAL :: zeps=3.e-7
70REAL :: zfpmin=1.e-30
71REAL :: zap,zdel,zsum
72REAL :: zan,zb,zc,zd,zh
73!
74REAL(kind=jphook) :: zhook_handle
75IF (lhook) CALL dr_hook('GAMMA_INC',0,zhook_handle)
76IF(px<0.0 .OR. pa<=0.0) THEN
77 CALL print_msg(nverb_fatal, 'GEN', 'GAMMA_INC', .OR.'invalid arguments: PX<0.0 PA<=0.0')
78END IF
79!
80IF( (px.LT.pa+1.0) ) THEN
81 zap = pa
82 zsum = 1.0/pa
83 zdel = zsum
84 jn = 1
85!
86 loop_series: DO
87 zap = zap +1.0
88 zdel = zdel*px/zap
89 zsum = zsum + zdel
90 IF( abs(zdel).LT.abs(zsum)*zeps ) EXIT loop_series
91 jn = jn + 1
92 IF( jn.GT.itmax ) THEN
93 CALL print_msg(nverb_fatal, 'GEN', 'GAMMA_INC', 'PA argument is too large or ITMAX is too small, &
94 &the incomplete GAMMA_INC function cannot be evaluated correctly &
95 &by the series method')
96 END IF
97 END DO loop_series
98 pgamma_inc = zsum * exp( -px+pa*log(px)-log(gamma(pa)) )
99!
100 ELSE
101!
102 zb = px + 1.0 - pa
103 zc = 1.0/tiny(px)
104 zd = 1.0/zb
105 zh = zd
106 jn = 1
107!
108 loop_fraction: DO
109 zan = -real(jn)*(real(jn)-pa)
110 zb = zb + 2.0
111 zd = zan*zd + zb
112 IF( abs(zd).LT.tiny(px) ) THEN
113 zd = zfpmin
114 END IF
115 zc = zb + zan/zc
116 IF( abs(zc).LT.tiny(px) ) THEN
117 zc = zfpmin
118 END IF
119 zd = 1.0/zd
120 zdel = zd*zc
121 zh = zh*zdel
122 IF( abs(zdel-1.0).LT.zeps ) EXIT loop_fraction
123 jn = jn + 1
124 IF( jn.GT.itmax ) THEN
125 CALL print_msg(nverb_fatal, 'GEN', 'GAMMA_INC', 'PA argument is too large or ITMAX is too small, &
126 &the incomplete GAMMA_INC function cannot be evaluated correctly &
127 &by the continuous fraction method')
128 END IF
129 END DO loop_fraction
130 pgamma_inc = 1.0 - zh*exp( -px+pa*log(px)-log(gamma(pa)) )
131!
132END IF
133!
134IF (lhook) CALL dr_hook('GAMMA_INC',1,zhook_handle)
135RETURN
136!
137CONTAINS
138include "gamma.h"
139END FUNCTION gamma_inc
elemental real function gamma(px)
Definition gamma.h:14
real function gamma_inc(pa, px)
Definition gamma_inc.F90:6
integer, parameter nverb_fatal
Definition modd_io.F90:6