C--------------------------------------------------------------------C
C     FUNCTION GLV INTEGRATES WITH RESPECT TO CHI/SQRT(2) DENSITY    C
C                 USING GAUSS-LEGENDRE QUADRATURE                    C
C                                                                    C
C     FFUN = EXTERNAL FUNCTION COULD BE GH1D OR GH2D                 C
C     K    = NUMBER OF TREATMENTS (PASSED ONTO INSIDE INTEGRAL)      C
C     D    = CRITICAL VALUE       (PASSED ONTO INSIDE INTEGRAL)      C
C     DNU  = DEGREES OF FREEDOM OF S                                 C
C     SUP  = UPPER INTEGRATION LIMIT OF SQRT(NU/2)*S                 C
C            FOR POWER CALCULATIONS                                  C
C          = + INFINITY INTERNALLY IF ON INPUT SUP IS .LT. ZERO      C
C              FOR CRITICAL VALUE CALCULATIONS                       C
C     PROGRAMMER: JASON C. HSU                                       C
C     LAST REVISION: 05-18-88 BY WCS FOR VECTOR PROCESSING           C
C     AUXILIARY FUNCTION REQUIRED: GAMALN                            C
C--------------------------------------------------------------------C
      DOUBLEPRECISION FUNCTION GLV(FFUN,IMC,K,D,DNU,SUP)
      IMPLICIT DOUBLE PRECISION(A-H,O-Z)
C6    IMPLICIT REAL*8(A-H,O-Z)
      PARAMETER(PBOT=0.000005D0,PUP=0.999995D0)
      COMMON/LIST5/DINFNU
      COMMON/LIST8/ZERO,ZSR,ZLOG,ZLN
      COMMON/LIST9/SR2,PI,SRPI,PIB2
      DIMENSION PL(48),WL(48)
      COMMON/LIST7/PL,WL
      EXTERNAL FFUN
C
      RDNU=DSQRT(DNU)
C     ----------------------------------------------------------------
C     IF NU (D.F.) GREATER THAN OR EQUAL TO IFNI ASSUME S = SIGMA
C
C       NOTE:  IN THE SIGMA KNOWN (INFINITE DEGRESS OF FREEDOM) CASE,
C              THE UPPER BOUND ON S IS PLUS INFINITY, AS IT SHOULD BE,
C              BECAUSE THE POWER IS EITHER 1-ALPHA OR 0
C     ----------------------------------------------------------------
      IF (DNU.LE.DINFNU) GOTO 90
        GLV=FFUN(IMC,K,D,1.0D0)
        GOTO 110
   90 CONTINUE
      DNB2=0.50D0*DNU
      GDNB2=GAMALN(DNB2)
C     -------------------------
C     B=LOWER INTEGRATION LIMIT
C     U=UPPER INTEGRATION LIMIT
C     -------------------------
      B=DSQRT(0.50D0*PPCHI2(PBOT,DNU,IFAULT))
      IF (SUP.LT.0.0D0) GOTO 20
        U=SUP
        GOTO 30
   20 U=DSQRT(0.50D0*PPCHI2(PUP,DNU,IFAULT))
   30 WID=U-B
        HWID=0.50D0*WID
        SUM=0.0D0
          DO 10 I=1,48
            Q=HWID*(1.0D0+PL(I))+B
            S=SR2*Q/RDNU
            VGH=FFUN(IMC,K,D,S)
            GAMA=(DNU-1.0D0)*DLOG(Q)-Q*Q-GDNB2
            SUM=SUM+VGH*DEXP(GAMA)*WID*WL(I)
   10    CONTINUE
  100 GLV=SUM
  110 CONTINUE
      RETURN
      END
C
