Debian Codegraph @

gui/XAlice/libsrc/gcf.c

raw
1 /* @(#)gcf.c 19.1 (ES0-DMD) 02/25/03 13:43:12 */
2 /*===========================================================================
3 Copyright (C) 1995 European Southern Observatory (ESO)
4
5 This program is free software; you can redistribute it and/or
6 modify it under the terms of the GNU General Public License as
7 published by the Free Software Foundation; either version 2 of
8 the License, or (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public
16 License along with this program; if not, write to the Free
17 Software Foundation, Inc., 675 Massachusetss Ave, Cambridge,
18 MA 02139, USA.
19
20 Corresponding concerning ESO-MIDAS should be addressed as follows:
21 Internet e-mail: [email protected]
22 Postal address: European Southern Observatory
23 Data Management Division
24 Karl-Schwarzschild-Strasse 2
25 D 85748 Garching bei Muenchen
26 GERMANY
27 ===========================================================================*/
28
29 /* @(#)gcf.c 19.1 (ESO) 02/25/03 13:43:12 */
30
31 #include <math.h>
32
33 #define ITMAX 100
34 #define EPS 3.0e-7
35
36 void gcf(gammcf,a,x,gln)
37 double a,*gammcf,*gln;
38 float x;
39 {
40 int n;
41 double gold=0.0,g,fac=1.0,b1=1.0;
42 double b0=0.0,anf,ana,an,a1,a0=1.0;
43 double gammln();
44 void nrerror();
45
46 *gln=gammln(a);
47 a1=x;
48 for (n=1;n<=ITMAX;n++) {
49 an=(double) n;
50 ana=an-a;
51 a0=(a1+a0*ana)*fac;
52 b0=(b1+b0*ana)*fac;
53 anf=an*fac;
54 a1=(double)x*a0+anf*a1;
55 b1=(double)x*b0+anf*b1;
56 if (a1) {
57 fac=1.0/a1;
58 g=b1*fac;
59 if (fabs((g-gold)/g) < EPS) {
60 *gammcf=exp(-x+a*log(x)-(*gln))*g;
61 return;
62 }
63 gold=g;
64 }
65 }
66 nrerror("a too large, ITMAX too small in routine GCF");
67 }
68
69 #undef ITMAX
70 #undef EPS