      SUBROUTINE SAMPP(X,N,P,IWRITE,PP) 
C
C     PURPOSE--THIS SUBROUTINE COMPUTES THE
C              SAMPLE 100P PERCENT POINT
C              (WHERE P IS BETWEEN 0.0 AND 1.0, EXCLUSIVELY)
C              OF THE DATA IN THE INPUT VECTOR X. 
C              THE SAMPLE 100P PERCENT POINT =  IS THAT POINT IN WHICH
C              100P PERCENT OF THE DATA IN THE SAMPLE IS BELOW.
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                     --P      = THE SINGLE PRECISION FRACTION VALUE
C                                (BETWEEN 0.0 AND 1.0, EXCLUSIVELY)
C                                WHICH DEFINES THE DESIRED PERCENT
C                                POINT TO BE COMPUTED.
C                     --IWRITE = AN INTEGER FLAG CODE WHICH 
C                                (IF SET TO 0) WILL SUPPRESS
C                                THE PRINTING OF THE
C                                SAMPLE 100P PERCENT POINT
C                                AS IT IS COMPUTED;
C                                OR (IF SET TO SOME INTEGER 
C                                VALUE NOT EQUAL TO 0),
C                                LIKE, SAY, 1) WILL CAUSE
C                                THE PRINTING OF THE
C                                SAMPLE 100P PERCENT POINT
C                                AT THE TIME IT IS COMPUTED.
C     OUTPUT ARGUMENTS--PP     = THE SINGLE PRECISION VALUE OF THE
C                                COMPUTED SAMPLE 100P PERCENT POINT.
C     OUTPUT--THE COMPUTED SINGLE PRECISION VALUE OF THE
C             SAMPLE 100P PERCENT POINT.
C     PRINTING--NONE, UNLESS IWRITE HAS BEEN SET TO A NON-ZERO
C               INTEGER, OR UNLESS AN INPUT ARGUMENT ERROR
C               CONDITION EXISTS.
C     RESTRICTIONS--THE MAXIMUM ALLOWABLE VALUE OF N
C                   FOR THIS SUBROUTINE IS 15000. 
C                 --THE INPUT ARGUMENTS N AND P SHOULD BE SUCH THAT
C                   THE PRODUCT OF N+1 AND P IS NOT SMALLER THAN 1 NOR
C                   LARGER THAN N.  THIS RESTRICTION IS DUE TO THE
C                   INTRINSIC DIFFICULTY OF ESTIMATING
C                   SAMPLE PERCENT POINTS SMALLER THAN THE OBSERVED
C                   SAMPLE MINIMUM OR LARGER THAN THE OBSERVED
C                   SAMPLE MAXIMUM.
C                   IF (N+1)P IS SMALLER THAN 1, AN ERROR MESSAGE WILL
C                   BE PRINTED OUT AND PP WILL BE SET TO -999999999.0 
C                   IF(N+1)P IS LARGER THAN N, AN ERROR MESSAGE WILL
C                   BE PRINTED OUT AND PP WILL BE SET TO 999999999.0. 
C     OTHER DATAPAC   SUBROUTINES NEEDED--SORT.
C     FORTRAN LIBRARY SUBROUTINES NEEDED--NONE.
C     MODE OF INTERNAL OPERATIONS--SINGLE PRECISION.
C     LANGUAGE--ANSI FORTRAN. 
C     REFERENCES--KENDALL AND STUART, THE ADVANCED THEORY OF
C                 STATISTICS, VOLUME 1, EDITION 2, 1963, PAGES 236-239,
C                 243.
C               --MOOD AND GRABLE, 'INTRODUCTION TO THE THEORY
C                 OF STATISTICS, EDITION 2, 1963, PAGES 406-407.
C               --SNEDECOR AND COCHRAN, STATISTICAL METHODS,
C                 EDITION 6, 1967, PAGE 125.
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--DECEMBER  1974. 
C     UPDATED         --SEPTEMBER 1975. 
C     UPDATED         --NOVEMBER  1975. 
C     UPDATED         --FEBRUARY  1976. 
C
C---------------------------------------------------------------------
C
      DIMENSION X(1)
      DIMENSION Y(15000)
      COMMON /BLOCK2/ WS(15000)
      EQUIVALENCE (Y(1),WS(1))
C
      IPR=6
      IUPPER=15000
C
C     CHECK THE INPUT ARGUMENTS FOR ERRORS
C
      AN=N
      ANP1=N+1
      AJ=P*ANP1
      J=AJ
      JP1=J+1
      IF(N.LT.1.OR.N.GT.IUPPER)GOTO50
      IF(N.EQ.1)GOTO55
      IF(J.LT.1)GOTO60
      IF(JP1.GT.N)GOTO65
      HOLD=X(1)
      DO70I=2,N
      IF(X(I).NE.HOLD)GOTO90
   70 CONTINUE
      WRITE(IPR, 9)HOLD
      GOTO90
   50 WRITE(IPR,17)IUPPER
      WRITE(IPR,47)N
      RETURN
   55 WRITE(IPR,18) 
      PP=X(1)
      RETURN
   60 WRITE(IPR,48) 
      WRITE(IPR,51)N,P
      PP=-999999999.0
      RETURN
   65 WRITE(IPR,49) 
      WRITE(IPR,51)N,P
      PP=999999999.0
      RETURN
   90 CONTINUE
    9 FORMAT(1H ,108H***** NON-FATAL DIAGNOSTIC--THE FIRST  INPUT ARGUME
     1NT (A VECTOR) TO THE SAMPP  SUBROUTINE HAS ALL ELEMENTS = ,E15.8,6
     1H *****)
   17 FORMAT(1H , 98H***** FATAL ERROR--THE SECOND INPUT ARGUMENT TO THE
     1 SAMPP  SUBROUTINE IS OUTSIDE THE ALLOWABLE (1,,I6,16H) INTERVAL *
     1****)
   18 FORMAT(1H ,100H***** NON-FATAL DIAGNOSTIC--THE SECOND INPUT ARGUME
     1NT TO THE SAMPP  SUBROUTINE HAS THE VALUE 1 *****)
   47 FORMAT(1H , 35H***** THE VALUE OF THE ARGUMENT IS ,I8   ,6H *****)
   48 FORMAT(1H ,48HTHE THIRD INPUT ARGUMENT IS SMALLER THAN 1/(N+1), 
     1 32H = 1/(SECOND INPUT ARGUMENT + 1))
   49 FORMAT(1H ,47HTHE THIRD INPUT ARGUMENT IS LARGER THAN N/(N+1),
     1 54H = (SECOND INPUT ARGUMENT)/(SECOND INPUT ARGUMENT + 1))
   51 FORMAT(1H ,46H*****THE VALUE OF THE SECOND INPUT ARGUMENT = ,I8,
     142H  THE VALUE OF THE THIRD INPUT ARGUMENT = ,E20.10,5H*****)
C
C-----START POINT-----------------------------------------------------
C
      CALL SORT(X,N,Y)
C
      AJINT=J
      W=1.0-(AJ-AJINT)
      PP=W*Y(J)+(1.0-W)*Y(JP1)
C
      HUNP=100.0*P
      IF(IWRITE.EQ.0)RETURN
      WRITE(IPR,205)HUNP,N,PP 
  205 FORMAT(1H ,14HTHE EMPIRICAL ,F9.5,22H PERCENT POINT OF THE ,
     1  I6,17H OBSERVATIONS IS ,F16.7)
C
      RETURN
      END 
