1
SUBROUTINE cdfpoi(which,p,q,s,xlam,status,bound)
2
C**********************************************************************
4
C SUBROUTINE CDFPOI( WHICH, P, Q, S, XLAM, STATUS, BOUND )
5
C Cumulative Distribution Function
12
C Calculates any one parameter of the Poisson
13
C distribution given values for the others.
19
C WHICH --> Integer indicating which argument
20
C value is to be calculated from the others.
22
C iwhich = 1 : Calculate P and Q from S and XLAM
23
C iwhich = 2 : Calculate A from P,Q and XLAM
24
C iwhich = 3 : Calculate XLAM from P,Q and S
27
C P <--> The cumulation from 0 to S of the poisson density.
32
C Input range: (0, 1].
36
C S <--> Upper limit of cumulation of the Poisson.
37
C Input range: [0, +infinity).
38
C Search range: [0,1E300]
41
C XLAM <--> Mean of the Poisson distribution.
42
C Input range: [0, +infinity).
43
C Search range: [0,1E300]
44
C DOUBLE PRECISION XLAM
46
C STATUS <-- 0 if calculation completed correctly
47
C -I if input parameter number I is out of range
48
C 1 if answer appears to be lower than lowest
50
C 2 if answer appears to be higher than greatest
55
C BOUND <-- Undefined if STATUS is 0
57
C Bound exceeded by parameter number I if STATUS
60
C Lower search bound if STATUS is 1.
62
C Upper search bound if STATUS is 2.
68
C Formula 26.4.21 of Abramowitz and Stegun, Handbook of
69
C Mathematical Functions (1966) is used to reduce the computation
70
C of the cumulative distribution function to that of computing a
71
C chi-square, hence an incomplete gamma function.
73
C Cumulative distribution function (P) is calculated directly.
74
C Computation of other parameters involve a seach for a value that
75
C produces the desired value of P. The search relies on the
76
C monotinicity of P with the other parameter.
79
C**********************************************************************
82
PARAMETER (tol=1.0D-8)
84
PARAMETER (atol=1.0D-50)
86
PARAMETER (inf=1.0D300)
88
C .. Scalar Arguments ..
89
DOUBLE PRECISION bound,p,q,s,xlam
93
DOUBLE PRECISION fx,cum,ccum,pq
94
LOGICAL qhi,qleft,qporq
96
C .. External Functions ..
97
DOUBLE PRECISION spmpar
100
C .. External Subroutines ..
101
EXTERNAL dinvr,dstinv,cumpoi
103
C .. Executable Statements ..
107
IF (.NOT. ((which.LT.1).OR. (which.GT.3))) GO TO 30
108
IF (.NOT. (which.LT.1)) GO TO 10
116
30 IF (which.EQ.1) GO TO 70
120
IF (.NOT. ((p.LT.0.0D0).OR. (p.GT.1.0D0))) GO TO 60
121
IF (.NOT. (p.LT.0.0D0)) GO TO 40
130
70 IF (which.EQ.1) GO TO 110
134
IF (.NOT. ((q.LE.0.0D0).OR. (q.GT.1.0D0))) GO TO 100
135
IF (.NOT. (q.LE.0.0D0)) GO TO 80
144
110 IF (which.EQ.2) GO TO 130
148
IF (.NOT. (s.LT.0.0D0)) GO TO 120
154
130 IF (which.EQ.3) GO TO 150
158
IF (.NOT. (xlam.LT.0.0D0)) GO TO 140
164
150 IF (which.EQ.1) GO TO 190
169
IF (.NOT. (abs(((pq)-0.5D0)-0.5D0).GT.
170
+ (3.0D0*spmpar(1)))) GO TO 180
171
IF (.NOT. (pq.LT.0.0D0)) GO TO 160
180
190 IF (.NOT. (which.EQ.1)) qporq = p .LE. q
182
C Select the minimum of P or Q
187
IF ((1).EQ. (which)) THEN
191
CALL cumpoi(s,xlam,p,q)
194
ELSE IF ((2).EQ. (which)) THEN
199
CALL dstinv(0.0D0,inf,0.5D0,0.5D0,5.0D0,atol,tol)
201
CALL dinvr(status,s,fx,qleft,qhi)
202
200 IF (.NOT. (status.EQ.1)) GO TO 230
203
CALL cumpoi(s,xlam,cum,ccum)
204
IF (.NOT. (qporq)) GO TO 210
209
220 CALL dinvr(status,s,fx,qleft,qhi)
212
230 IF (.NOT. (status.EQ.-1)) GO TO 260
213
IF (.NOT. (qleft)) GO TO 240
223
ELSE IF ((3).EQ. (which)) THEN
228
CALL dstinv(0.0D0,inf,0.5D0,0.5D0,5.0D0,atol,tol)
230
CALL dinvr(status,xlam,fx,qleft,qhi)
231
270 IF (.NOT. (status.EQ.1)) GO TO 300
232
CALL cumpoi(s,xlam,cum,ccum)
233
IF (.NOT. (qporq)) GO TO 280
238
290 CALL dinvr(status,xlam,fx,qleft,qhi)
241
300 IF (.NOT. (status.EQ.-1)) GO TO 330
242
IF (.NOT. (qleft)) GO TO 310