    PROGRAM g01dcfe

!      G01DCF Example Program Text

!      Mark 23 Release. NAG Copyright 2011.

!      .. Use Statements ..
       USE nag_library, ONLY : g01daf, g01dcf, nag_wp
!      .. Implicit None Statement ..
       IMPLICIT NONE
!      .. Parameters ..
       INTEGER, PARAMETER              :: nout = 6
!      .. Local Scalars ..
       REAL (KIND=nag_wp)              :: errest, etol, exp1, exp2, sumssq
       INTEGER                         :: i, ifail, iw, j, k, lvec, n
!      .. Local Arrays ..
       REAL (KIND=nag_wp), ALLOCATABLE :: pp(:), vec(:), work(:)
!      .. Executable Statements ..
       WRITE (nout,*) 'G01DCF Example Program Results'
       WRITE (nout,*)

!      Set the problem size
       n = 6
       etol = 0.0001E0_nag_wp

       lvec = n*(n+1)/2
       iw = 3*n/2
       ALLOCATE (pp(n),work(iw),vec(lvec))

!      Compute normal scores
       ifail = 0
       CALL g01daf(n,pp,etol,errest,work,iw,ifail)

       exp1 = pp(n)
       exp2 = pp(n-1)
       sumssq = 0.0E0_nag_wp
       DO i = 1, n
          sumssq = sumssq + pp(i)*pp(i)
       END DO

!      Compute approximate variance-covariance matrix
       ifail = 0
       CALL g01dcf(n,exp1,exp2,sumssq,vec,ifail)

!      Display results
       WRITE (nout,99999) 'Sample size = ', n
       WRITE (nout,*) 'Variance-covariance matrix'
       k = 1
       DO j = 1, n
          WRITE (nout,99998) vec(k:(k+j-1))
          k = k + j
       END DO

99999  FORMAT (1X,A,I2)
99998  FORMAT (1X,6F8.4)
    END PROGRAM g01dcfe
