      SUBROUTINE HTEST(P,NWDS,ALPHA,IKIND,K,D)
C 
C     * F. MAJAESS -- SEPT. 30, 1987 (IN COMPUTING THE FIELDS OF
C     *                              TRANSFORMED SIGNIFICANCE LEVELS K, 
C     *                              USE LOG BASE 5 INSTEAD OF LOG BASE 
C     *                              2. I.E USE P=ALPHA/5**(K-1) INSTEAD
C     *                              OF P=ALPHA/2**(K-1)).
C     * F. ZWIERS  -- NOV.  27, 1984
C     * 
C     * THIS SUBROUTINE CONDUCTS A TEST OF HYPOTHESIS BY EXAMINING
C     * P-VALUES. 
C     * 
C     * 
C     * INPUT:  
C     *    P    : ARRAY OF P-VALUES.
C     * 
C     *    NWDS : LENGTH OF ARRAY P.
C     * 
C     *    ALPHA: THE SIGNIFICANCE LEVEL OF THE TEST. 
C     * 
C     *    IKIND=-1 REJECT THE NULL HYPOTHESIS IF P > 1 - ALPHA 
C     *             (IE - CONDUCT A ONE TAILED TEST AND REJECT IF 
C     *                   THE TEST STATISTIC IS UNUSUALLY SMALL). 
C     *         = 0 INDICATES A TWO TAILED TEST (REJECT IF
C     *             P > 1 - ALPHA/2   OR IF  P < ALPHA/2) 
C     *             (IE - REJECT IF THE TEST STATISTIC IS 
C     *                   UNUSUALLY SMALL OR LARGE).
C     *         = 1 REJECT THE NULL HYPOTHESIS IF P < ALPHA 
C     *             (IE - CONDUCT A ONE TAILED TEST AND REJECT IF 
C     *                   THE TEST STATISTIC IS UNUSUALLY LARGE). 
C     * 
C     * 
C     * OUTPUT: 
C     *    K    : REAL ARRAY OF TRANSFORMED SIGNIFICANCE LEVELS.
C     *           THE K-VALUES ARE LOG TO BASE 5 OF ALPHA DEVIDED BY
C     *           THE SIGNIFICANCE OF THE OBSERVED STATISTIC. THUS A
C     *           K-VALUE OF 1 INDICATES THAT THE OBSERVED STATISTIC
C     *           IS JUST SIGNIFICANT AT THE ALPHA SIGNIFICANCE LEVEL.
C     *           IN GENERAL K-VALUE INDICATES THAT THE OBSERVED
C     *           STATISTIC WOULD BE SIGNIFICANT AT THE 
C     *                          ALPHA/5**(K-1) 
C     *           SIGNFICANCE LEVEL.
C     *           IF PLOTTED WITH UNIT CONTOUR INTERVALS, SUCCESSIVE
C     *           CONTOURS WILL ENCLOSE REGIONS WHERE LOCALLY IT IS 
C     *           FIVE TIMES AS UNLIKELY THAT VALUES OF THE OBSERVED
C     *           STATISTICS ARE CONSISTENT WITH THE NULL HYPOTHESIS
C     *           THAN IN REGIONS OUTSIDE THE NEXT LOWER CONTOUR. 
C     * 
C     *    D    : ARRAY CONSISTING OF 0'S (HYPOTHESIS ACCEPTED) 
C     *           AND 1'S (HYPOTHESIS REJECTED).
C     * 
C 
      IMPLICIT REAL (A-H,O-Z),
     +INTEGER (I-N)
      REAL LN5,LNABS5,P(1),ALPHA,K(1),D(1)
      INTEGER IKIND 
      DATA EPS/1.E-12/
C 
C---------------------------------------------------------------------------- 
C 
      LN5=LOG(5.0E0) 
      LNABS5=LOG(ALPHA)/LN5
C 
C     * CONVERT THE P-VALUES TO SIGNFICANCE LEVELS AND STORE THEM 
C     * IN ARRAY D WHICH IS USED TEMPORARILY AS A WORKING ARRAY.
C 
      IF(IKIND.EQ.-1)THEN 
         DO 10 I=1,NWDS 
            D(I)=1.0E0-P(I) 
  10     CONTINUE 
      ELSEIF(IKIND.EQ.0)THEN
         DO 20 I=1,NWDS 
            D(I)=2.0E0*MIN(P(I),1.0E0-P(I)) 
  20     CONTINUE 
        ELSE
         DO 30 I=1,NWDS 
            D(I)=P(I) 
  30     CONTINUE 
      ENDIF 
C 
C     * BEFORE COMPUTING THE K-VALUES, MAKE SURE THE SIGNIFICANCE LEVEL 
C     * IS NOT ZERO. (BECAUSE WE PLAN TO TAKE LOGS).
C 
      DO 40 I=1,NWDS
         D(I)=MAX(D(I),EPS) 
 40   CONTINUE
C 
C     * COMPUTE THE TRANSFORMED SIGNIFICANCE LEVELS.(K-VALUES). 
C 
      DO 50 I=1,NWDS
         K(I)=LNABS5-LOG(D(I))/LN5+1.0E0 
 50   CONTINUE
C 
C     * MAKE DECISION ABOUT WHETHER OR NOT TO REJECT. 
C     * (I.E. COMPUTE D-VALUES).
C 
      DO 60 I=1,NWDS
         D(I)=0.0E0 
 60   CONTINUE
      DO 70 I=1,NWDS
         D(I)=MERGE(1.0E0,0.0E0,K(I).GE.1.0E0) 
 70   CONTINUE
C 
      RETURN
      END 
