SUBROUTINE DISCR3(X,N,NUMCLA,Y)
C
C     PURPOSE--THIS SUBROUTINE 'DISCRETIZES' THE DATA
C              ON THE SINGLE PRECISION VECTOR X
C              INTO NUMCLA CLASSES.
C              ALL VALUES IN THE VECTOR X WITHIN A GIVEN CLASS
C              WILL BE MAPPED INTO THE CLASS NUMBER
C              (1, 2, ... , NUMCLA).
C              THUS ALL THE ELEMENTS IN THE LOWERMOST CLASS 
C              WILL BE MAPPED INTO THE VALUE 1.0; 
C              ALL THE ELEMENTS OF X IN THE NEXT HIGHER CLASS
C              WILL BE MAPPED INTO 2.0; 
C              ETC. 
C              THE SAMPLE MINIMUM AND SAMPLE MAXIMUM
C              ARE AUTOMATICALLY COMPUTED INTERNALLY
C              AND THE CLASS WIDTH (XDEL) IS COMPUTED AS
C              THE (SAMPLE MAX - SAMPLE MIN)/NUMCLA.
C              THE FIRST CLASS INTERVAL IS FROM
C              THE SAMPLE MIN TO THE SAMPLE MIN + XDEL;
C              THE SECOND CLASS INTERVAL IS FROM
C              THE SAMPLE MIN + XDEL TO 
C              THE SAMPLE MIN + 2*XDEL; 
C              ...; 
C              THE LAST CLASS INTERVAL IS FROM
C              THE SAMPLE MAX - XDEL TO THE SAMPLE MAX.
C              THE USE OF THIS SUBROUTINE
C              (AND THE DISCRE AND DISCR2 SUBROUTINES)
C              GIVES THE DATA ANALYST THE CAPABILITY OF
C              CONSTRUCTING A DISCRETE VARIATE FROM
C              A CONTINUOUS ONE.
C              THE RESULTING DISCRETE VARIATE MIGHT THEN
C              (FOR EXAMPLE) BE ANALYZED IN ITSELF FOR
C              GROSS STRUCTURE, OR FOR ADHERENCE TO SOME
C              THEROETICAL DISCRETE PROBABILITY MODEL,
C              OR THE DISCRETE VARIATE MIGHT BE USED
C              AS A SUBSET DEFINITION VECTOR FOR SOME
C              OTHER VARIATE. 
C              THIS DISCR3 SUBROUTINE IS PARTICULARLY
C              SUITED TO THIS LAST PURPOSE INASMUCH
C              AS IT OUTPUT'S 1'S, 2'S, ETC.
C              RATHER THAN MIDPOINTS.
C     INPUT  ARGUMENTS--X      = THE SINGLE PRECISION VECTOR OF
C                                (UNSORTED OR SORTED) OBSERVATIONS.
C                                TO BE DISCRETIZED.
C                     --N      = THE INTEGER NUMBER OF OBSERVATIONS
C                                IN THE VECTOR X. 
C                     --NUMLEV = THE INTEGER NUMBER OF CLASSES
C                                DESIRED IN THE DISCRETIZATION.
C     OUTPUT ARGUMENTS--Y      = THE SINGLE PRECISION VECTOR OF
C                                DISCRETIZED VALUES CORRESPONDING TO
C                                THE CONTINUOUS VALUES IN THE VECTOR X.
C                                THERE WILL RESULT N SUCH DISCRETIZED 
C                                VALUES.
C     OUTPUT--THE SINGLE PRECISION VECTOR Y
C             WHICH CONTAINS N DISCRETIZED VALUES 
C             CORRESPONDING TO THE N
C             CONTINUOUS VALUES IN THE
C             INPUT VECTOR X. 
C             ALSO, (NUMCLA+5) LINES OF SUMMARY INFORMATION 
C             WILL BE GENERATED INDICATING
C             1) WHAT THE SAMPLE SIZE IS (N);
C             2) WHAT THE NUMBER OF CLASSES IS (NUMCLA).
C             3) WHAT THE CLASS BOUNDARIES AND
C                THE NUMBER OF OBSERVATIONS
C                FALLING IN EACH CLASS ARE.
C     PRINTING--YES 
C     RESTRICTIONS--THERE IS NO RESTRICTION ON THE MAXIMUM VALUE
C                   OF N FOR THIS SUBROUTINE.
C                 --NUMCLA SHOULD BE POSITIVE AND NOT EXCEED 1000
C     OTHER DATAPAC   SUBROUTINES NEEDED--NONE.
C     FORTRAN LIBRARY SUBROUTINES NEEDED--NONE.
C     MODE OF INTERNAL OPERATIONS--SINGLE PRECISION.
C     LANGUAGE--ANSI FORTRAN. 
C     COMMENT--THIS SUBROUTINE DIFFERS FROM THE DISCR2
C              SUBROUTINE INASMUCH AS THIS SUBROUTINE
C              PERFORMS ITS DISCRETIZATION BY OUTPUTING
C              CLASS NUMBERS (1, 2,, ..., NUMCLA);
C              WHEREAS THE DISCR2 SUBROUTINE
C              OUTPUTS CLASS MIDPOINTS. 
C     COMMENT--THE INPUT VECTOR X REMAINS UNALTERED.
C     COMMENT--IN THE MAIN (CALLING) ROUTINE, IT IS
C              PERMISSABLE (IF THE ANALYST SO DESIRES)
C              TO USE THE SAME VARIABLE NAME
C              IN THE FOURTH ARGUMENT AS USED IN THE FIRST
C              ARGUMENT IN THE CALLING SEQUENCE TO THIS
C              DISCR3 SUBROUTINE--NO CONFLICT WILL RESULT
C              IN THE INTERNAL OPERATION OF THE     DISCR3
C              SUBROUTINE.  FOR EXAMPLE, IT IS PERMISSIBLE
C              TO HAVE        CALL DISCR3(X,N,10,X)
C              IN WHICH THE VARIABLE NAME      X    IS USED 
C              AS BOTH THE FIRST AND FOURTH ARGUMENTS.
C     REFERENCES--NONE.
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         --APRIL     1975. 
C     UPDATED         --NOVEMBER  1975. 
C
C---------------------------------------------------------------------
C
      DIMENSION X(1),Y(1)
      DIMENSION ICOUNT(1000)
C
      IPR=6
      IUPNCL=1000
C
C     CHECK THE INPUT ARGUMENTS FOR ERRORS
C
      IF(N.LT.1)GOTO50
      IF(N.EQ.1)GOTO55
      IF(NUMCLA.LT.1.OR.NUMCLA.GT.IUPNCL)GOTO70
      IF(NUMCLA.EQ.1)GOTO80
      HOLD=X(1)
      DO60I=2,N
      IF(X(I).NE.HOLD)GOTO90
   60 CONTINUE
      WRITE(IPR, 9)HOLD
      DO65I=1,N
      Y(I)=X(I)
   65 CONTINUE
      RETURN
   50 WRITE(IPR,15) 
      WRITE(IPR,47)N
      RETURN
   55 WRITE(IPR,18) 
      Y(1)=X(1)
      RETURN
   70 WRITE(IPR,27)IUPNCL
      WRITE(IPR,47)NUMCLA
      DO71I=1,N
      Y(I)=0.0
   71 CONTINUE
      RETURN
   80 WRITE(IPR,28) 
   90 CONTINUE
    9 FORMAT(1H ,108H***** NON-FATAL DIAGNOSTIC--THE FIRST  INPUT ARGUME
     1NT (A VECTOR) TO THE DISCR3 SUBROUTINE HAS ALL ELEMENTS = ,E15.8,6
     1H *****)
   15 FORMAT(1H , 91H***** FATAL ERROR--THE SECOND INPUT ARGUMENT TO THE
     1 DISCR3 SUBROUTINE IS NON-POSITIVE *****)
   18 FORMAT(1H ,100H***** NON-FATAL DIAGNOSTIC--THE SECOND INPUT ARGUME
     1NT TO THE DISCR3 SUBROUTINE HAS THE VALUE 1 *****)
   27 FORMAT(1H , 98H***** FATAL ERROR--THE THIRD  INPUT ARGUMENT TO THE
     1 DISCR3 SUBROUTINE IS OUTSIDE THE ALLOWABLE (1,,I6,16H) INTERVAL *
     1****)
   28 FORMAT(1H ,100H***** NON-FATAL DIAGNOSTIC--THE THIRD  INPUT ARGUME
     1NT TO THE DISCR3 SUBROUTINE HAS THE VALUE 1 *****)
   47 FORMAT(1H , 35H***** THE VALUE OF THE ARGUMENT IS ,I8   ,6H *****)
C
C-----START POINT-----------------------------------------------------
C
      ANUML=NUMCLA
C
C     ZERO OUT THE COUNT VECTOR (ICOUNT)
C
      DO100I=1,NUMCLA
      ICOUNT(I)=0
  100 CONTINUE
C
C     COMPUTE THE SAMPLE MINIMUM AND MAXIMUM,
C     THEN COMPUTE THE CLASS WIDTH.
C
      XMIN=X(1)
      XMAX=X(1)
      DO200I=1,N
      IF(X(I).LT.XMIN)XMIN=X(I)
      IF(X(I).GT.XMAX)XMAX=X(I)
  200 CONTINUE
      XDEL=(XMAX-XMIN)/ANUML
C
C     PERFORM THE DISCRETIZING TRANSFORMATION.
C     ALSO, KEEP A FREQUENCY COUNT FOR EACH CLASS.
C
      DO400I=1,N
      P=(X(I)-XMIN)/(XMAX-XMIN)
      P=P*ANUML+1.0 
      IP=P
      IF(IP.LT.1)IP=1
      IF(IP.GT.NUMCLA)IP=NUMCLA
      Y(I)=IP
      ICOUNT(IP)=ICOUNT(IP)+1 
  400 CONTINUE
C
C     COMPUTE CLASS LIMITS AND WRITE OUT SUMMARY INFORMATION.
C
      WRITE(IPR,999)
      WRITE(IPR,501)
      WRITE(IPR,999)
      WRITE(IPR,502)N
      WRITE(IPR,508)NUMCLA
      WRITE(IPR,503)XMIN
      WRITE(IPR,504)XDEL
      WRITE(IPR,505)XMAX
      WRITE(IPR,999)
      WRITE(IPR,510)
      WRITE(IPR,997)
      DO500I=1,NUMCLA
      AI=I
      CMIN=XMIN+(AI-1.0)*XDEL 
      CMAX=XMIN+AI*XDEL
      WRITE(IPR,520)I,CMIN,CMAX,ICOUNT(I)
  500 CONTINUE
C
  501 FORMAT(1H ,35HOUTPUT FROM THE DISCR3 SUBROUTINE--)
  502 FORMAT(1H ,7X,36HNUMBER OF OBSERVATIONS            = ,I8)
  503 FORMAT(1H ,7X,36HCOMPUTED  LOWER BOUND OF INTERVAL = ,F15.7)
  504 FORMAT(1H ,7X,36HCOMPUTED  CLASS WIDTH             = ,F15.7)
  505 FORMAT(1H ,7X,36HCOMPUTED  UPPER BOUND OF INTERVAL = ,F15.7)
  508 FORMAT(1H ,7X,36HSPECIFIED NUMBER OF LEVELS        = ,I8)
  510 FORMAT(1H ,49H       LEVEL     MINIMUM       MAXIMUM      COUNT)
  520 FORMAT(1H ,4X,I6,2X,2F14.7,I8)
  997 FORMAT(1H ,49H       ------------------------------------------)
  999 FORMAT(1H )
C
      RETURN
      END