SUBROUTINE POIPLT(X,N,ALAMBA)
C
C     PURPOSE--THIS SUBROUTINE GENERATES A POISSON
C              PROBABILITY PLOT
C              (WITH SINGLE PRECISION
C              TAIL LENGTH PARAMETER = ALAMBA).
C              THE PROTOTYPE POISSON DISTRIBUTION USED
C              HEREIN HAS MEAN = ALAMBA 
C              AND STANDARD DEVIATION = SQRT(ALAMBA).
C              THIS DISTRIBUTION IS DEFINED FOR
C              ALL DISCRETE NON-NEGATIVE INTEGER  X--X = 0, 1, 2, ... .
C              THIS DISTRIBUTION HAS THE PROBABILITY FUNCTION
C              F(X) = EXP(-ALAMBA) * ALAMBA**X / X!.
C              THE POISSON DISTRIBUTION IS THE
C              DISTRIBUTION OF THE NUMBER OF EVENTS
C              IN THE INTERVAL (0,ALAMBA) WHEN
C              THE WAITING TIME BETWEEN EVENTS
C              IS EXPONENTIALLY DISTRIBUTED
C              WITH MEAN = 1 AND STANDARD DEVIATION = 1.
C              THE PROTOTYPE DISTRIBUTION RESTRICTIONS OF
C              DISCRETENESS AND NON-NEGATIVENESS
C              MENTIONED ABOVE DO NOT CARRY OVER TO THE
C              INPUT VECTOR X OF OBSERVATIONS TO BE ANALYZED.
C              THE INPUT OBSERVATIONS IN X MAY BE DISCRETE, CONTINUOUS,
C              NON-NEGATIVE, OR NEGATIVE.
C              AS USED HEREIN, A PROBABILITY PLOT FOR A DISTRIBUTION
C              IS A PLOT OF THE ORDERED OBSERVATIONS VERSUS 
C              THE ORDER STATISTIC MEDIANS FOR THAT DISTRIBUTION.
C              THE POISSON PROBABILITY PLOT IS USEFUL IN
C              GRAPHICALLY TESTING THE COMPOSITE (THAT IS,
C              LOCATION AND SCALE PARAMETERS NEED NOT BE SPECIFIED)
C              HYPOTHESIS THAT THE UNDERLYING DISTRIBUTION
C              FROM WHICH THE DATA HAVE BEEN RANDOMLY DRAWN 
C              IS THE POISSON DISTRIBUTION
C              WITH TAIL LENGTH PARAMETER VALUE = ALAMBA.
C              IF THE HYPOTHESIS IS TRUE, THE PROBABILITY PLOT
C              SHOULD BE NEAR-LINEAR.
C              A MEASURE OF SUCH LINEARITY IS GIVEN BY THE
C              CALCULATED PROBABILITY PLOT CORRELATION COEFFICIENT.
C     INPUT  ARGUMENTS--X      = THE SINGLE PRECISION VECTOR OF
C                                (UNSORTED OR SORTED) OBSERVATIONS.
C                     --N      = THE INTEGER NUMBER OF OBSERVATIONS
C                                IN THE VECTOR X. 
C                     --ALAMBA = THE SINGLE PRECISION VALUE OF THE
C                                TAIL LENGTH PARAMETER.
C                                ALAMBA SHOULD BE POSITIVE. 
C     OUTPUT--A ONE-PAGE POISSON PROBABILITY PLOT.
C     PRINTING--YES.
C     RESTRICTIONS--THE MAXIMUM ALLOWABLE VALUE OF N
C                   FOR THIS SUBROUTINE IS 5000.
C                 --ALAMBA SHOULD BE POSITIVE.
C     OTHER DATAPAC   SUBROUTINES NEEDED--SORT, UNIMED, PLOT,
C                                         CHSCDF, NORPPF.
C     FORTRAN LIBRARY SUBROUTINES NEEDED--SQRT.
C     MODE OF INTERNAL OPERATIONS--SINGLE PRECISION.
C     LANGUAGE--ANSI FORTRAN. 
C     COMMENT--FOR LARGE VALUES OF ALAMBA (IN EXCESS OF 500.)
C              THIS SUBROUTINE USES THE NORMAL APPROXIMATION TO
C              THE POISSON.  THIS IS DONE TO SAVE EXECUTION TIME
C              WHICH INCREASES AS A FUNCTION OF ALAMBA AND WOULD
C              BE EXCESSIVE FOR LARGE VALUES OF ALAMBA.
C     REFERENCES--FILLIBEN, 'TECHNIQUES FOR TAIL LENGTH ANALYSIS',
C                 PROCEEDINGS OF THE EIGHTEENTH CONFERENCE
C                 ON THE DESIGN OF EXPERIMENTS IN ARMY RESEARCH
C                 DEVELOPMENT AND TESTING (ABERDEEN, MARYLAND,
C                 OCTOBER, 1972), PAGES 425-450.
C               --HAHN AND SHAPIRO, STATISTICAL METHODS IN ENGINEERING,
C                 1967, PAGES 260-308.
C               --JOHNSON AND KOTZ, DISCRETE
C                 DISTRIBUTIONS, 1969, PAGES 87-121.
C     WRITTEN BY--JAMES J. FILLIBEN
C                 STATISTICAL ENGINEERING LABORATORY (205.03)
C                 NATIONAL BUREAU OF STANDARDS
C                 WASHINGTON, D. C. 20234
C                 PHONE:  301-921-2315
C     ORIGINAL VERSION--NOVEMBER  1974. 
C     UPDATED         --AUGUST    1975. 
C     UPDATED         --SEPTEMBER 1975. 
C     UPDATED         --NOVEMBER  1975. 
C     UPDATED         --FEBRUARY  1976. 
C
C---------------------------------------------------------------------
C
      DIMENSION X(1)
      DIMENSION Y(5000),W(5000)
      DIMENSION Z(5000)
      COMMON /BLOCK2/ WS(15000)
      EQUIVALENCE (Y(1),WS(1)),(W(1),WS(5001))
      EQUIVALENCE (Z(1),WS(10001))
C
      IPR=6
      IUPPER=5000
C
C     CHECK THE INPUT ARGUMENTS FOR ERRORS
C
      IF(N.LT.1.OR.N.GT.IUPPER)GOTO50
      IF(N.EQ.1)GOTO55
      IF(ALAMBA.LE.0.0)GOTO60 
      HOLD=X(1)
      DO65I=2,N
      IF(X(I).NE.HOLD)GOTO90
   65 CONTINUE
      WRITE(IPR, 9)HOLD
      RETURN
   50 WRITE(IPR,17)IUPPER
      WRITE(IPR,47)N
      RETURN
   55 WRITE(IPR,18) 
      RETURN
   60 WRITE(IPR,25) 
      WRITE(IPR,46)ALAMBA
      RETURN
   90 CONTINUE
    9 FORMAT(1H ,109H***** NON-FATAL DIAGNOSTIC--THE FIRST  INPUT ARGUME
     1NT (A VECTOR) TO THE POIPLT SUBROUTINE HAS ALL ELEMENTS = ,E15.8,6
     1H *****)
   17 FORMAT(1H , 98H***** FATAL ERROR--THE SECOND INPUT ARGUMENT TO THE
     1 POIPLT SUBROUTINE IS OUTSIDE THE ALLOWABLE (1,,I6,16H) INTERVAL *
     1****)
   18 FORMAT(1H ,100H***** NON-FATAL DIAGNOSTIC--THE SECOND INPUT ARGUME
     1NT TO THE POIPLT SUBROUTINE HAS THE VALUE 1 *****)
   25 FORMAT(1H , 91H***** FATAL ERROR--THE THIRD  INPUT ARGUMENT TO THE
     1 POIPLT SUBROUTINE IS NON-POSITIVE *****)
   46 FORMAT(1H , 35H***** THE VALUE OF THE ARGUMENT IS ,E15.8,6H *****)
   47 FORMAT(1H , 35H***** THE VALUE OF THE ARGUMENT IS ,I8   ,6H *****)
C
C-----START POINT-----------------------------------------------------
C
      AN=N
      CUTOFF=500.0
C
C     SORT THE DATA 
C
      CALL SORT(X,N,Y)
C
C     GENERATE UNIFORM ORDER STATISTIC MEDIANS
C
      CALL UNIMED(N,W)
C
C     COMPUTE POISSON ORDER STATISTIC MEDIANS.
C     IF THE INPUT ALAMBA VALUE IS LARGE (IN EXCESS OF
C     CUTOFF VALUE OF 500.0), THEN USE THE NORMAL APPROXIMATION
C     TO THE POISSON.
C
      IF(ALAMBA.LE.CUTOFF)GOTO150
      SQALAM=SQRT(ALAMBA)
      DO170I=1,N
      CALL NORPPF(W(I),W(I))
      W(I)=ALAMBA+W(I)*SQALAM 
  170 CONTINUE
      GOTO1550
  150 CONTINUE
C
C     DETERMINE WHICH UNIFORM ORDER STATISTIC MEDIAN IS ASSOCIATED WITH
C     THE CLOSEST INTEGER TO ALAMBA.
C
      DO100I=1,N
      Z(I)=-1.0
  100 CONTINUE
C
      ILAMBA=ALAMBA+0.5
      ARG1=2.0*ALAMBA
      IARG2=2*(ILAMBA+1)
      CALL CHSCDF(ARG1,IARG2,CDF)
      CDF=1.0-CDF
      DO200J=1,N
      IF(W(J).GT.CDF)GOTO250
  200 CONTINUE
  250 JM1=J-1
      Z(JM1)=ILAMBA 
C
C     FILL IN THE POISSON ORDER STATISTIC MEDIANS BELOW ALAMBA
C
      IMAX=6.0*SQRT(ALAMBA)
      DO500I=1,IMAX 
      K=ILAMBA-I
      IF(K.LT.0)GOTO750
      IARG2=2*(K+1) 
      CALL CHSCDF(ARG1,IARG2,CDF)
      CDF=1.0-CDF
      DO600J=1,N
      IF(W(J).GT.CDF)GOTO650
  600 CONTINUE
  650 JM1=J-1
      IF(JM1.LE.0)GOTO750
      IF(Z(JM1).LT.-0.5)Z(JM1)=K
  500 CONTINUE
C
C     FILL IN THE POISSON ORDER STATISTIC MEDIANS ABOVE ALAMBA
C
  750 DO800I=1,IMAX 
      K=ILAMBA+I
      IARG2=2*(K+1) 
      CALL CHSCDF(ARG1,IARG2,CDF)
      CDF=1.0-CDF
      DO900J=1,N
      IF(W(J).GT.CDF)GOTO950
  900 CONTINUE
      Z(N)=K
      GOTO1050
  950 JM1=J-1
      IF(Z(JM1).LT.-0.5)Z(JM1)=K
  800 CONTINUE
C
C     FILL IN THE EMPTY HOLES IN THE POISSON ORDER STATISTIC MEDIAN
C     Z MATRIX WITH THE PROPER VALUES.
C     THEN FOR SAKE OF CONSISTENCY WITH OTHER DATAPAC
C     PROBABILITY PLOT SUBROUTINES, COPY THE Z VECTOR
C     INTO THE W VECTOR.
C
 1050 HOLD=Z(N)
      DO1200IREV=1,N
      I=N-IREV+1
      IF(Z(I).GE.-0.5)HOLD=Z(I)
      IF(Z(I).LT.-0.5)Z(I)=HOLD
 1200 CONTINUE
      DO1300I=1,N
      W(I)=Z(I)
 1300 CONTINUE
C
C     PLOT THE ORDERED OBSERVATIONS VERSUS ORDER STATISTICS MEDIANS.
C     WRITE OUT THE SAMPLE SIZE.
C
 1550 CALL PLOT(Y,W,N)
      WRITE(IPR,2105)ALAMBA,N 
C
C     COMPUTE THE PROBABILITY PLOT CORRELATION COEFFICIENT. 
C     COMPUTE LOCATION AND SCALE ESTIMATES
C     FROM THE INTERCEPT AND SLOPE OF THE PROBABILITY PLOT. 
C     THEN WRITE THEM OUT.
C
      SUM1=0.0
      SUM2=0.0
      DO2200I=1,N
      SUM1=SUM1+Y(I)
      SUM2=SUM2+W(I)
 2200 CONTINUE
      YBAR=SUM1/AN
      WBAR=SUM2/AN
      SUM1=0.0
      SUM2=0.0
      SUM3=0.0
      DO2300I=1,N
      SUM1=SUM1+(Y(I)-YBAR)*(Y(I)-YBAR) 
      SUM2=SUM2+(Y(I)-YBAR)*(W(I)-WBAR) 
      SUM3=SUM3+(W(I)-WBAR)*(W(I)-WBAR) 
 2300 CONTINUE
      CC=SUM2/SQRT(SUM3*SUM1) 
      YSLOPE=SUM2/SUM3
      YINT=YBAR-YSLOPE*WBAR
      WRITE(IPR,2305)CC,YINT,YSLOPE
C
 2105 FORMAT(1H ,42HPOISSON PROBABILITY PLOT WITH PARAMETER = ,9X,
     1E17.10,1X,8X,11X,20HTHE SAMPLE SIZE N = ,I7)
 2305 FORMAT(1H ,43HPROBABILITY PLOT CORRELATION COEFFICIENT = ,F8.5,5X,
     122HESTIMATED INTERCEPT = ,E15.8,3X,18HESTIMATED SLOPE = ,E15.8) 
C
      RETURN
      END