      PROGRAM main

c*********************************************************************72
c
cc toms599_test() tests toms599().
c
c  Discussion:
c
      REAL MU
      DIMENSION VPAR4(22),VPAR5(24),SAMPLE(10000),II(5)
C
C     VPAR4 - VECTOR OF PARAMETER VALUES FOR CASE 4 : SGAMMA
C
      DATA VPAR4 /.0001,.25,.5,.75,.9999,1.,1.5,2.,
     ,3.,4.,5.,7.,10.,15.,20.,30.,50.,100.,1000.,
     ,10000.,100000.,1000000./
C
C     VPAR5 - VECTOR OF PARAMETER VALUES FOR CASE 5 : KPOISS
C
      DATA VPAR5 /.0001,1.,2.,5.,9.99,10.,
     ,12.,15.,20.,25.,30.,40.,50.,75.,100.,150.,
     ,200.,500.,1000.,2000.,5000.,1.E4,1.E5,1.E6/
C
C     II - NUMBER OF RUNS FOR EACH DISTRIBUTION
C
      DATA II /1,1,1,22,24/
C
C     FORMAT STATEMENTS
C
   1  FORMAT(' ',/,' ',/,' LISTING OF TRIAL RUNS',
     ,' FOR RANDOM NUMBER PACKAGE AHRENS/DIETER/KOHRT',
C    ,/,' ===============================',
     ,'====================================')
   2  FORMAT('   FIRST 100 SAMPLES:',/,
     ,'   ..................',/,' ',/,(5E15.6))
   3  FORMAT(' ',/,' ',/,'   TEST DATA:',
     ,'     (]BASED ON 10000 SAMPLES])',
     ,/,'   ..........',/,20X,'MEAN',11X,
     ,'STD.DEV.',7X,'SKEWNESS',
     ,7X,'EXCESS',/,' ',/,
     ,'   TRUE VALUES:',4E15.6,/,
     ,'   SAMPLE DATA:',4E15.6,/,' ')
   4  FORMAT(' ',/,' 1.)   0,1 -UNIFORM DISTRIBUTION:',
     ,/,' ********************************')
   5  FORMAT(' ',/,' 2.)  (STANDARD-) EXPONENTIAL DISTRIBUTION:',
     ,/,' ******************************************')
   6  FORMAT(' ',/,' 3.)  (STANDARD-) NORMAL DISTRIBUTION:',
     ,/,' ******************************************')
   7  FORMAT(' ',/,' 4.)  (STANDARD-) GAMMA-(A) DISTRIBUTION:',
     ,/,' ****************************************')
   8  FORMAT(' ',/,' 5.)  POISSON-(MU) DISTRIBUTION:',
     ,/,' *******************************',/,' ',
     ,/,'   (INTEGER SAMPLES ARE DISPLAYED AS REALS])',
     ,/,' ',/,' ')
   9  FORMAT(43X,'    GAMMA-(A):  A =',E13.6,
     ,/,43X,'    ----------------------------')
  10  FORMAT(43X,'POISSON-(MU):  MU =',E13.6,
     ,/,43X,'--------------------------------')
  11  FORMAT(' ',/,' ')
C
C     OUTPUT: MAIN HEADING
C
      WRITE ( *,1)
C
C     TRIAL RUNS FOR 5 DIFFERENT CASES:
C
C       NDIS=1 :   0,1 -UNIFORM DISTRIBUTION
C       NDIS=2 :  (STANDARD-) EXPONENTIAL DISTRIBUTION
C       NDIS=3 :  (STANDARD-) NORMAL DISTRIBUTION
C       NDIS=4 :  (STANDARD-) GAMMA-(A) DISTRIBUTION
C       NDIS=5 :  POISSON-(MU) DISTRIBUTION
C
      DO 27 NDIS=1,5
      NRUN=II(NDIS)
C
C     OUTPUT: CASE HEADING
C
      WRITE ( *,11)
      IF (NDIS .EQ. 1) WRITE (*,4)
      IF (NDIS .EQ. 2) WRITE (*,5)
      IF (NDIS .EQ. 3) WRITE (*,6)
      IF (NDIS .EQ. 4) WRITE (*,7)
      IF (NDIS .EQ. 5) WRITE (*,8)
C
C     EACH CASE: ONE RUN FOR EVERY PARAMETER VALUE
C
      DO 26 NPAR=1,NRUN
C
C     CASE 4 AND 5: SET PARAMETER VALUES ACCORDING TO DATA VECTOR
C
      IF (NDIS .EQ. 4) A=VPAR4(NPAR)
      IF (NDIS .EQ. 5) MU=VPAR5(NPAR)
C
C     SEED FOR UNIFORM RANDOM NUMBER GENERATOR IS INITIALIZED TO 4*0+1
C
      IR=1
C
C     EACH CASE SEPARATELY: SAMPLING AND TEST DATA
C        T2 - STANDARD DEVIATION (=SQRT(VARIANCE)),
C        T1 - MEAN,   T3 - SKEWNESS,   T4 - EXCESS.
C
      GO TO (12,14,16,18,20) , NDIS
C
C     CASE 1 :   0,1 -UNIFORM DISTRIBUTION
C
  12  DO I=1,10000
        SAMPLE(I)=SUNIF(IR)
      end do
      T1=0.5
      T2=1.0/SQRT(12.0)
      T3=0.0
      T4=-1.2
      GO TO 23
C
C     (STANDARD-) EXPONENTIAL DISTRIBUTION
C
  14  DO I=1,10000
        SAMPLE(I)=SEXPO(IR)
      end do
      T1=1.0
      T2=1.0
      T3=2.0
      T4=6.0
      GO TO 23
C
C     (STANDARD-) NORMAL DISTRIBUTION
C
  16  DO I=1,10000
        SAMPLE(I)=SNORM(IR)
      end do
      T1=0.0
      T2=1.0
      T3=0.0
      T4=0.0
      GO TO 23
C
C     (STANDARD-) GAMMA-(A) DISTRIBUTION
C
  18  DO I=1,10000
        SAMPLE(I)=SGAMMA(IR,A)
      end do
      T1=A
      T2=SQRT(A)
      T3=2.0/T2
      T4=6.0/A
      GO TO 22
C
C     POISSON-(MU) DISTRIBUTION
C
  20  DO I=1,10000
        SAMPLE(I)=FLOAT(KPOISS(IR,MU))
      end do
      T1=MU
      T2=SQRT(MU)
      T3=1.0/T2
      T4=1.0/MU
C
C     CASE 4 AND 5:  OUTPUT: PARAMETER VALUE
C
  22  IF (NPAR .NE. 1) WRITE (*,11)
      IF (NDIS .EQ. 4) WRITE (*, 9) A
      IF (NDIS .EQ. 5) WRITE (*,10) MU
C
  23  CONTINUE
C
C     OUTPUT : FIRST 100 RANDOM DEVIATES FOR EACH RUN
C              (INTEGER SAMPLES ARE DISPLAYED AS REALS])
C
      IF (NDIS .LE. 3) WRITE (*,11)
      WRITE (*,2) (SAMPLE(I),I=1,100)
C
C     EVALUATION OF SAMPLE MEAN:    E1 - (1/N)*SUM(SAMPLE(I))
C
      S1=0.0
      DO I=1,10000
        S1=S1+SAMPLE(I)
      end do
      E1=S1/10000.0
C
C     EVALUATION OF FURTHER SAMPLE ESTIMATES :
C
C     SK       - (1/N)*SUM((SAMPLE(I)-E1)**K)
C                SAMPLE CENTRAL MOMENTS  (K=2,3,4)
C                WITH RESPECT TO SAMPLE MEAN
C
C     E2       - SQRT(S2)
C                SAMPLE STANDARD DEVIATION
C                (=SQRT(SAMPLE VARIANCE))
C
C     E3       - S3/S2**(3/2)
C                SAMPLE SKEWNESS
C
C     E4       - S4/S2**2-3
C                SAMPLE EXCESS
C
      S2=0.0
      S3=0.0
      S4=0.0
C
      DO 25 I=1,10000
C
      X1=SAMPLE(I)-E1
      X2=X1*X1
      X3=X2*X1
      X4=X2*X2
C
      S2=S2+X2
      S3=S3+X3
      S4=S4+X4
C
  25  CONTINUE
C
      S2=S2/10000.0
      S3=S3/10000.0
      S4=S4/10000.0
C
      E2=SQRT(S2)
      E3=S3/SQRT(S2*S2*S2)
      E4=S4/(S2*S2)-3.0
C
C     END OF EVALUATION
C     OUTPUT: CHARACTERISTIC DATA
C
      WRITE (*,3) T1,T2,T3,T4,E1,E2,E3,E4
C
C     END OF PARAMETER LOOP
C
  26  CONTINUE
C
C     END OF DISTRIBUTION LOOP
C
  27  CONTINUE
C
C     END OF PROGRAM
C
      STOP
      END
