C--------------------------------------------------C
C     PVMCAV.F COMPUTES MATRIX OF P-VALUES         C
C       FOR MCA INFERENCE                          C
C       WITH 1 OR 2 FACTORS                        C
C     Last revision:: 3/4/94 by jch                C
C--------------------------------------------------C
      SUBROUTINE PVMCAV(K,FACT1,DNU,D,PVAL)
C     PARAMETER(KM1=K-1)
      IMPLICIT DOUBLEPRECISION (A-H,O-Z)
C6    IMPLICIT REAL*8 (A-H,O-Z)
      EXTERNAL GLV,GHA1
      DIMENSION D(K,K),PVAL(K,K)
      DIMENSION FACT1(K),FACT2(100)
c
c     actually fact(k-1)
c
      DIMENSION A(100),B(100),C(100)
      DIMENSION PH(48),WH(48),WHLN(48),ZH(48)
      DIMENSION PL(48),WL(48)
      DIMENSION AH(7),BH(12)
      COMMON/LIST2/A,B,C
      COMMON/LIST5/DINFNU
      COMMON/LIST6/PH,WH,ZH,WHLN
      COMMON/LIST7/PL,WL
      COMMON/LIST8/ZERO,ZSR,ZLOG,ZLN
      COMMON/LIST9/SR2,PI,SRPI,PIB2
      COMMON/LIST10/IIN,IOUT,IOUTI
      COMMON/LIST12/AH,BH
C     ----------------------------------
C     INITIALIZE COMMONLY USED CONSTANTS
C     ----------------------------------
      CALL COMMGQ
      IMC=12
      IFACT=1
C
C     -----------------------
C     INITIALIZE CORRELATIONS
C     -----------------------
      KM1 = K-1
      DO 10 J=1,KM1
C       ----------------------
C       A = FACTOR PATTERN
C       C = 1/SQRT(UNIQUENESS)
C       ----------------------
        A(J)=1.0D0/DSQRT(2.0D0)
        IF (IFACT.EQ.2) GOTO 5
        C(J)=1.0D0/DSQRT(1.0D0-A(J)*A(J))
        GOTO 10
    5   B(J)=FACT2(J)
        C(J)=1.0D0/DSQRT(1.0D0-A(J)*A(J)-B(J)*B(J))
   10 CONTINUE
C
C     ----------------
C     COMPUTE P-VALUES
C     ----------------
      DO 1000,I=1,K-1
         DO 1010,J=I+1,K
            PVAL(I,J)=1.0D0-GLV(GHA1,IMC,K,D(I,J),DNU,-1.0D0)
 1010   CONTINUE
 1000 CONTINUE
      RETURN
      END
