      PROGRAM TEMP
      IMPLICIT NONE
      REAL      MEAN(0:20,0:20,0:7), SIGMA(0:20,0:20,0:7)
      INTEGER   HISTO(0:20,0:20,0:7,-100:100)
      REAL      LEAK(0:20,0:20,0:7)
      INTEGER   I, J, TOTAL, RATIO2, RATIO1
      INTEGER   ANAL_1, DIGI_1, ANAL_2,
     &          DIGI_2, ANAL_SUM, DIGI_SUM, SUM_DIGI
      PARAMETER ( ANAL_1=1, ANAL_2=2, ANAL_SUM=3,
     &          DIGI_1=4, DIGI_2=5, DIGI_SUM=6, SUM_DIGI=7 )
      REAL      NORM_1, NORM_2
      REAL      PICK_1, PICK_2
      INTEGER   DIGITIZED_PICK_1, DIGITIZED_PICK_2, DIGITIZED_SUM

      TOTAL = 10000


      DO I = 0 , 7
        DO RATIO1 = 0 , 20
          DO RATIO2 = 0 , 20
            SIGMA (RATIO1,RATIO2,I) = 0
            MEAN (RATIO1,RATIO2,I) = 0
            DO J = -10 , 10
              HISTO (RATIO1,RATIO2,I,J) = 0
            ENDDO
          ENDDO
        ENDDO
      ENDDO


      DO I = 1 , TOTAL

        CALL RANNOR ( NORM_1, NORM_2 )

        DO RATIO1  =  0 , 20

          PICK_1 = NORM_1 * (RATIO1/10.0)
          DIGITIZED_PICK_1 = NINT ( PICK_1 )

          DO RATIO2  =  0 , 20

            PICK_2 = NORM_2 * (RATIO2/10.0)
            DIGITIZED_PICK_2 = NINT ( PICK_2 )
            DIGITIZED_SUM = NINT ( (PICK_1 + PICK_2) / 2.0 )

            IF ( ABS(DIGITIZED_SUM) .LE. 100 ) 
     &        HISTO ( RATIO1, RATIO2, DIGI_SUM, DIGITIZED_SUM ) =
     &        HISTO ( RATIO1, RATIO2, DIGI_SUM, DIGITIZED_SUM ) + 1

            IF ( ABS((DIGITIZED_PICK_1+DIGITIZED_PICK_2)/2)  .LE. 100 ) 
     &        HISTO ( RATIO1, RATIO2, DIGI_1,
     &        (DIGITIZED_PICK_1+DIGITIZED_PICK_2)/2 ) =
     &        HISTO ( RATIO1, RATIO2, DIGI_1,
     &        (DIGITIZED_PICK_1+DIGITIZED_PICK_2)/2 ) + 1


            MEAN(RATIO1,RATIO2,ANAL_SUM) = MEAN(RATIO1,RATIO2,ANAL_SUM)
     &                               + ( (PICK_1 + PICK_2) / 2.0 )
            SIGMA(RATIO1,RATIO2,ANAL_SUM) =SIGMA(RATIO1,RATIO2,ANAL_SUM)
     &                                + ( (PICK_1 + PICK_2) / 2.0 ) **2

            MEAN(RATIO1,RATIO2,DIGI_SUM) = MEAN(RATIO1,RATIO2,DIGI_SUM)
     &                             + FLOAT(DIGITIZED_SUM)
            SIGMA(RATIO1,RATIO2,DIGI_SUM) =SIGMA(RATIO1,RATIO2,DIGI_SUM)
     &                          + FLOAT(DIGITIZED_SUM)**2

            MEAN(RATIO1,RATIO2,DIGI_1) = MEAN(RATIO1,RATIO2,DIGI_1)
     &               + FLOAT((DIGITIZED_PICK_1+DIGITIZED_PICK_2)/2)
            SIGMA(RATIO1,RATIO2,DIGI_1) = SIGMA(RATIO1,RATIO2,DIGI_1)
     &               + FLOAT((DIGITIZED_PICK_1+DIGITIZED_PICK_2)/2)**2

          ENDDO

        ENDDO

      ENDDO


      DO RATIO1 = 0 , 20
        DO RATIO2  =  0 , 20

          DO I = 1 , 7
            MEAN (RATIO1,RATIO2,I) = MEAN (RATIO1,RATIO2,I)
     &                           / FLOAT(TOTAL)
            SIGMA (RATIO1,RATIO2,I) = SIGMA (RATIO1,RATIO2,I)
     &                           / FLOAT(TOTAL)
            SIGMA (RATIO1,RATIO2,I) = SIGMA (RATIO1,RATIO2,I)
     &                            - MEAN (RATIO1,RATIO2,I) **2
            SIGMA (RATIO1,RATIO2,I) = SQRT(SIGMA (RATIO1,RATIO2,I) )
          ENDDO

          DO J =  NINT(2.5*SIGMA(RATIO1,RATIO2,ANAL_SUM)), 100
            LEAK(RATIO1,RATIO2,DIGI_SUM) = LEAK(RATIO1,RATIO2,DIGI_SUM) 
     &        + HISTO ( RATIO1, RATIO2, DIGI_SUM, J ) 
            LEAK(RATIO1,RATIO2,DIGI_1) = LEAK(RATIO1,RATIO2,DIGI_1) 
     &        + HISTO ( RATIO1, RATIO2, DIGI_1, J ) 
          ENDDO

            LEAK(RATIO1,RATIO2,DIGI_SUM) = 
     &        100.0 * LEAK(RATIO1,RATIO2,DIGI_SUM) / TOTAL 
            LEAK(RATIO1,RATIO2,DIGI_1) = 
     &        100.0 * LEAK(RATIO1,RATIO2,DIGI_1) / TOTAL 

          WRITE ( 6, 2000, ERR=90 ) (RATIO1/10.0), (RATIO2/10.0),
     &                              SIGMA(RATIO1,RATIO2,ANAL_SUM),
     &                       NINT(2.5*SIGMA(RATIO1,RATIO2,ANAL_SUM)),
     &                       SIGMA (RATIO1,RATIO2,DIGI_SUM),
     &                       LEAK (RATIO1,RATIO2,DIGI_SUM),
     &                       SIGMA (RATIO1,RATIO2,DIGI_1),
     &                       LEAK (RATIO1,RATIO2,DIGI_1)

 2000     FORMAT ( ' ', 3F5.2, I3, 10F8.3 )
   90     CONTINUE
        ENDDO
      ENDDO

      END
