      FUNCTION CVTD(P,DF)
C
C     * CVTD RETURNS P UPPER TAIL CRITICAL VALUE OF THE 
C     * STUDENT T-DISTRIBUTION WITH DF DEGREES OF FREEDOM.
C
C     * 7/APR 1999
C
C     * AUTHOR: SLAVA KHARIN
C     * (BISECTION METHOD)
C--------------------------------------------------------------------
C
      IMPLICIT REAL (A-H,O-Z),
     +INTEGER (I-N)
      DATA MAXIT/100/,EPS/1.E-6/
C--------------------------------------------------------------------
      PP=P
      IF (P.LT.0.5E0)PP=1.E0-P
      T1=0.E0
      T2=1.E+3
      P1=1.E0-0.5E0*BETAI1(0.5E0*DF,0.5E0,DF/(DF+T1*T1))
      P2=1.E0-0.5E0*BETAI1(0.5E0*DF,0.5E0,DF/(DF+T2*T2))
      IF ((P1-PP)*(P2-PP).GT.0.E0) THEN
         WRITE(6,'(A)')
     1        ' *** ERROR IN CVTD: ROOT MUST BE BRACKETED.'
         CALL                                      XIT('CVTD',-1)
      ENDIF
      DO IT=1,MAXIT
         T=0.5E0*(T1+T2)
         P1=1.E0-0.5E0*BETAI1(0.5E0*DF,0.5E0,DF/(DF+T*T))
         IF (P1.GT.PP) THEN
            T2=T
         ELSE
            T1=T
         ENDIF
         IF (T2-T1.LT.EPS) GOTO 100
      ENDDO
C
      WRITE(6,'(A)')
     1     ' *** ERROR IN CVTD: TOO MANY BISECTIONS.'
      CALL                                         XIT('CVTD',-2)
C
 100  CONTINUE
      CVTD=T
      IF (P.LT.0.5E0)CVTD=-T
      RETURN
      END
