The TELEMAC-MASCARET system  trunk
bief_gser.f
Go to the documentation of this file.
1 ! ********************
2  SUBROUTINE bief_gser
3 ! ********************
4 !
5  &(gamser,a,x,gln)
6 !
7 !***********************************************************************
8 ! BIEF V6P3 07/03/2013
9 !***********************************************************************
10 !
11 !brief Returns the incomplete gamma function P(a,x) evaluated by its
12 !+ series representation as GAMSER. Also returns ln gamma(a) as
13 !+ GLN. From 'Numerical Recipes' Chapter 6.2 This routine is only
14 !+ valid for X.GE.0 Negative X cannot occur when calling from ERF
15 !+ or ERFC via GAMMP or GAMMQ
16 !
17 !history D J Evans-Roberts (HRW)
18 !+ 23/11/1993
19 !+ V6P3
20 !+ First version sent by Michiel Knaapen (HRW) on 07/03/2013.
21 !
22 !~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
23 !| A |-->| PARAMETER
24 !| GAMSER |<->| Incomplete gamma function P(a,x)
25 !| GLN |<->| gamma(a)
26 !| X |-->| OPERAND
27 !| IFAIL |<->| ERROR TAG: 1 IS OK, 0 IS ERROR
28 !~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
29 !
30 ! USE BIEF
31 !
33  IMPLICIT NONE
34 !
35 !+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
36 !
37  DOUBLE PRECISION, INTENT(IN) :: X,A
38  DOUBLE PRECISION, INTENT(INOUT) :: GAMSER,GLN
39 !
40 !+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
41 !
42  INTEGER :: N
43  DOUBLE PRECISION :: AP,SOMME,DEL
44 !
45  INTEGER, PARAMETER :: ITMAX = 100
46  DOUBLE PRECISION :: EPS = 3.d-7
47 !
48  DOUBLE PRECISION BIEF_GAMMLN
49  EXTERNAL bief_gammln
50 !
51  INTRINSIC abs,exp,log
52 !
53 !-----------------------------------------------------------------------
54 !
55  gln = bief_gammln(a)
56 !
57  IF(x.LT.0.d0) THEN
58 ! Cannot occur when used by ERF or ERFC
59  WRITE(lu,*) 'BIEF_GSER: UNEXPECTED NEGATIVE X'
60  CALL plante(1)
61  stop
62  ELSEIF(x.EQ.0.d0) THEN
63  gamser = 0.d0
64  ELSE
65  ap = a
66  somme = 1.d0/a
67  del = somme
68  DO n = 1,itmax
69  ap = ap + 1.d0
70  del = del*x/ap
71  somme = somme + del
72  IF(abs(del).LT.abs(somme)*eps) GO TO 110
73  ENDDO
74  WRITE(lu,*) 'BIEF_GSER: MAXIMUM OF ITERATIONS REACHED:',itmax
75  CALL plante(1)
76  stop
77 110 CONTINUE
78  gamser = somme*exp(-x+a*log(x)-gln)
79  ENDIF
80 !
81 !-----------------------------------------------------------------------
82 !
83  RETURN
84  END
subroutine bief_gser(GAMSER, A, X, GLN)
Definition: bief_gser.f:7