    PROGRAM f01zafe

!      F01ZAF Example Program Text

!      Mark 23 Release. NAG Copyright 2011.

!      .. Use Statements ..
       USE nag_library, ONLY : f01zaf, nag_wp, x04cbf
!      .. Implicit None Statement ..
       IMPLICIT NONE
!      .. Parameters ..
       INTEGER, PARAMETER              :: nin = 5, nout = 6
!      .. Local Scalars ..
       INTEGER                         :: i, ifail, lb, lda, lenb, n
       CHARACTER (1)                   :: diag, uplo
!      .. Local Arrays ..
       REAL (KIND=nag_wp), ALLOCATABLE :: a(:,:), b(:)
       CHARACTER (1)                   :: clabs(1), rlabs(1)
!      .. Executable Statements ..
       WRITE (nout,*) 'F01ZAF Example Program Results'
!      Skip heading in data file
       READ (nin,*)
       WRITE (nout,*)
       FLUSH (nout)
       READ (nin,*) n, uplo, diag
       lda = n
       lenb = (n*(n+1))/2
       ALLOCATE (a(lda,n),b(lenb))
!      Read a triangular matrix of order n
       DO i = 1, n
          READ (nin,*) a(i,1:n)
       END DO

!      ifail: behaviour on error exit
!             =0 for hard exit, =1 for quiet-soft, =-1 for noisy-soft
       ifail = 0
!      Print the unpacked matrix
       CALL x04cbf(uplo,diag,n,n,a,lda,'F5.2','Unpacked Matrix A:','I',rlabs, &
          'I',clabs,80,0,ifail)

       WRITE (nout,*)
       FLUSH (nout)

!      Convert to packed vector form
       ifail = 0
       CALL f01zaf('Pack',uplo,diag,n,a,lda,b,ifail)

       lb = n*(n+1)/2

!      Print the packed vector
       ifail = 0
       CALL x04cbf('G','X',lb,1,b,lb,'F5.2','Packed Vector B:','I',rlabs,'N', &
          clabs,80,0,ifail)

    END PROGRAM f01zafe
