The TELEMAC-MASCARET system
trunk
sources
utils
bief
bief_gcf.f
Go to the documentation of this file.
1
! *******************
2
SUBROUTINE
bief_gcf
3
! *******************
4
!
5
&(gammcf,a,x,gln)
6
!
7
!***********************************************************************
8
! BIEF V6P3 07/03/2013
9
!***********************************************************************
10
!
11
!brief Returns the incomplete gamma function Q(a,x) evaluated by its
12
!+ continued fraction representation as GAMMCF. Also returns
13
!+ gamma (a) as GLN. From 'Numerical Recipes' Chapter 6.2
14
!
15
!history D J Evans-Roberts (HRW)
16
!+ 23/11/1993
17
!+ V6P3
18
!+ First version sent by Michiel Knaapen (HRW) on 07/03/2013.
19
!
20
!~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
21
!| A |-->| PARAMETER
22
!| GAMMCF |<->| Incomplete gamma function Q(a,x)
23
!| GLN |<->| gamma(a)
24
!| X |-->| OPERAND
25
!~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
26
!
27
! USE BIEF
28
!
29
USE
declarations_special
30
IMPLICIT NONE
31
!
32
!+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
33
!
34
DOUBLE PRECISION
,
INTENT(IN)
:: A,X
35
DOUBLE PRECISION
,
INTENT(INOUT)
:: GAMMCF,GLN
36
!
37
!+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
38
!
39
INTEGER
:: N
40
DOUBLE PRECISION
GOLD,A0,A1,B0,B1,FAC,AN,ANA,ANF,G
41
!
42
INTEGER
,
PARAMETER
:: ITMAX = 100
43
DOUBLE PRECISION
:: EPS = 3.e-7
44
!
45
DOUBLE PRECISION
BIEF_GAMMLN
46
EXTERNAL
bief_gammln
47
!
48
INTRINSIC
exp,log,float,abs
49
!
50
!-----------------------------------------------------------------------
51
!
52
gln = bief_gammln(a)
53
! This is the previous value, tested against for convergence.
54
gold = 0.d0
55
a0 = 1.d0
56
! We are here setting up the A's and B's of equation (5.2.4) for
57
! evaluating the continued fraction.
58
a1 = x
59
b0 = 0.d0
60
b1 = 1.d0
61
! FAC is the renormalization factor for preventing overflow of the
62
! partial numerators and denominators.
63
fac = 1.d0
64
DO
n = 1,itmax
65
an = float(n)
66
ana = an - a
67
! One step of the recurrence (5.2.5).
68
a0 = (a1+a0*ana)*fac
69
b0 = (b1+b0*ana)*fac
70
anf = an*fac
71
! The next step of the recurrence (5.2.5).
72
a1 = x*a0 + anf*a1
73
b1 = x*b0 + anf*b1
74
! Shall we renormalize?
75
IF
(a1.NE.0.d0)
THEN
76
! Yes. Set FAC so it happens.
77
fac = 1.d0/a1
78
! New value of answer.
79
g = b1*fac
80
! Converged? If so, exit.
81
IF
(abs((g-gold)/g).LT.eps)
GO TO
110
82
! If not, save value.
83
gold = g
84
ENDIF
85
ENDDO
86
WRITE
(
lu
,*)
'BIEF_GCF: FATAL ERROR'
87
CALL
plante(1)
88
stop
89
110
CONTINUE
90
!
91
gammcf = exp(-x+a*log(x)-gln)*g
92
!
93
!-----------------------------------------------------------------------
94
!
95
RETURN
96
END
declarations_special
Definition:
declarations_special.F:3
declarations_special::lu
integer lu
Definition:
declarations_special.F:45
bief_gcf
subroutine bief_gcf(GAMMCF, A, X, GLN)
Definition:
bief_gcf.f:7