    PROGRAM f06wcfe

!      F06WCF Example Program Text

!      Mark 23 Release. NAG Copyright 2011.

!      .. Use Statements ..
       USE nag_library, ONLY : dsfrk, dtfttr, dtrttf, nag_wp, x04caf
!      .. Implicit None Statement ..
       IMPLICIT NONE
!      .. Parameters ..
       INTEGER, PARAMETER              :: nin = 5, nout = 6
!      .. Local Scalars ..
       REAL (KIND=nag_wp)              :: alpha, beta
       INTEGER                         :: i, ifail, info, k, lda, n
       CHARACTER (1)                   :: trans, transr, uplo
!      .. Local Arrays ..
       REAL (KIND=nag_wp), ALLOCATABLE :: a(:,:), c(:,:), cf(:)
!      .. Executable Statements ..
       WRITE (nout,*) 'F06WCF Example Program Results'

!      Skip heading in data file
       READ (nin,*)

       READ (nin,*) n, k, uplo, transr, alpha, beta, trans

       lda = n
       ALLOCATE (c(lda,n),cf((n*(n+1))/2),a(lda,k))

!      Read upper or lower triangle of matrix C from data file

       IF (uplo=='L' .OR. uplo=='l') THEN
          DO i = 1, n
             READ (nin,*) c(i,1:i)
          END DO
       ELSE
          DO i = 1, n
             READ (nin,*) c(i,i:n)
          END DO
       END IF

!      Read matrix A from data file       

       READ (nin,*) (a(i,1:k),i=1,n)

!      Convert C to rectangular full packed storage in CF

!      The NAG name equivalent of dtrttf is f01vef
       CALL dtrttf(transr,uplo,n,c,lda,cf,info)

       WRITE (nout,*)
       FLUSH (nout)

!      Perform the rank-k update

!      The NAG name equivalent of dsfrk is f06wcf
       CALL dsfrk(transr,uplo,trans,n,k,alpha,a,lda,beta,cf)

!      Convert CF back from rectangular full packed to standard format in C  

!      The NAG name equivalent of dtfttr is f01vgf
       CALL dtfttr(transr,uplo,n,cf,c,lda,info)

!      Print out the result, stored in the lower triangle of matrix C

       CALL x04caf('Lower','N',n,n,c,lda,'The Solution',ifail)

    END PROGRAM f06wcfe
