SUBROUTINE FREQ(X,N)
C
C     PURPOSE--THIS SUBROUTINE COMPUTES THE SAMPLE FREQUENCY
C              AND SAMPLE CUMULATIVE FREQUENCY
C              FOR THE DATA IN THE INPUT VECTOR X.
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     OUTPUT--SEVERAL (FOR LARGE DATA SETS) PAGES OF AUTOMATIC
C             PRINTOUT (WITH APPROXIMATELY 55 VALUES PER PAGE)
C             CONSISTING OF AN ORDERED LISTING OF EACH DISTINCT
C             VALUE IN THE DATA SET ALONG WITH
C             THE FREQUENCY OF OCCURANCE OF THAT VALUE
C             AND THE CUMULATIVE FREQUENCY.
C     PRINTING--YES.
C     RESTRICTIONS--THE MAXIMUM ALLOWABLE VALUE OF N
C                   FOR THIS SUBROUTINE IS 15000. 
C     OTHER DATAPAC   SUBROUTINES NEEDED--SORT.
C     FORTRAN LIBRARY SUBROUTINES NEEDED--SQRT.
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, PAGE 8.
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  1972. 
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
      IF(N.LT.1.OR.N.GT.IUPPER)GOTO50
      IF(N.EQ.1)GOTO55
      HOLD=X(1)
      DO60I=2,N
      IF(X(I).NE.HOLD)GOTO90
   60 CONTINUE
      WRITE(IPR, 9)HOLD
      GOTO90
   50 WRITE(IPR,17)IUPPER
      WRITE(IPR,47)N
      RETURN
   55 WRITE(IPR,18) 
      RETURN
   90 CONTINUE
    9 FORMAT(1H ,109H***** NON-FATAL DIAGNOSTIC--THE FIRST  INPUT ARGUME
     1NT (A VECTOR) TO THE FREQ   SUBROUTINE HAS ALL ELEMENTS = ,E15.8,6
     1H *****)
   17 FORMAT(1H , 98H***** FATAL ERROR--THE SECOND INPUT ARGUMENT TO THE
     1 FREQ   SUBROUTINE IS OUTSIDE THE ALLOWABLE (1,,I6,16H) INTERVAL *
     1****)
   18 FORMAT(1H ,100H***** FATAL ERROR--         THE SECOND INPUT ARGUME
     1NT TO THE FREQ   SUBROUTINE HAS THE VALUE 1 *****)
   47 FORMAT(1H , 35H***** THE VALUE OF THE ARGUMENT IS ,I8   ,6H *****)
C
C-----START POINT-----------------------------------------------------
C
      AN=N
C
C     COMPUTE THE SAMPLE MEAN AND SAMPLE STANDARD DEVIATION 
C
      SUM=0.0
      DO100I=1,N
      SUM=SUM+X(I)
  100 CONTINUE
      XBAR=SUM/AN
      SUM=0.0
      DO200I=1,N
      SUM=SUM+(X(I)-XBAR)**2
  200 CONTINUE
      S=SQRT(SUM/(AN-1.0))
C
      WRITE(IPR,998)
      WRITE(IPR,101)
      WRITE(IPR,999)
      WRITE(IPR,102)N
      WRITE(IPR,103)XBAR
      WRITE(IPR,104)S
      WRITE(IPR,999)
      WRITE(IPR,999)
      WRITE(IPR,105)
      WRITE(IPR,106)
      WRITE(IPR,107)
      WRITE(IPR,999)
C
      CALL SORT(X,N,Y)
      NDV=0
      ICFREQ=0
      NUMSEQ=1
      NM1=N-1
      DO400I=1,NM1
      IP1=I+1
      IF(Y(I).EQ.Y(IP1))NUMSEQ=NUMSEQ+1 
      IF(Y(I).EQ.Y(IP1))GOTO400
      NDV=NDV+1
      DVALUE=Y(I)
      IFREQ=NUMSEQ
      ICFREQ=ICFREQ+IFREQ
      FRQ=IFREQ
      CFREQ=ICFREQ
      PFREQ=100.0*FRQ/AN
      PCFREQ=100.0*CFREQ/AN
      WRITE(IPR,110)NDV,DVALUE,IFREQ,PFREQ,ICFREQ,PCFREQ
      IFLAG=NDV-10*(NDV/10)
      IF(IFLAG.EQ.0)WRITE(IPR,999)
      NUMSEQ=1
  400 CONTINUE
      NDV=NDV+1
      DVALUE=Y(N)
      IFREQ=NUMSEQ
      ICFREQ=ICFREQ+IFREQ
      FRQ=IFREQ
      CFREQ=ICFREQ
      PFREQ=100.0*FRQ/AN
      PCFREQ=100.0*CFREQ/AN
      WRITE(IPR,110)NDV,DVALUE,IFREQ,PFREQ,ICFREQ,PCFREQ
      IFLAG=NDV-10*(NDV/10)
      IF(IFLAG.EQ.0)WRITE(IPR,999)
C
  101 FORMAT(1H ,18X,48HSAMPLE FREQUENCY AND SAMPLE CUMULATIVE FREQUENCY
     1)
  102 FORMAT(1H ,27X,20HTHE SAMPLE SIZE N = ,I8)
  103 FORMAT(1H ,25X,18HTHE SAMPLE MEAN = ,E15.8) 
  104 FORMAT(1H ,20X,32HTHE SAMPLE STANDARD DEVIATION = ,E15.8)
  105 FORMAT(1H , 88H    INDEX            VALUE       FREQUENCY    PERCE
     1NTAGE        CUMULATIVE    PERCENTAGE)
  106 FORMAT(1H , 88H                                              FREQU
     1ENCY         FREQUENCY     CUMULATIVE)
  107 FORMAT(1H , 88H
     1                           FREQUENCY )
  110 FORMAT(1H ,I8,4X,E17.10,3X,I8,6X,F8.4,10X,I8,6X,F8.4) 
  998 FORMAT(1H1)
  999 FORMAT(1H )
      RETURN
      END