    PROGRAM f07wrfe

!      F07WRF Example Program Text

!      Mark 23 Release. NAG Copyright 2011.

!      .. Use Statements ..
       USE nag_library, ONLY : nag_wp, x04dbf, zpftrf, ztfttr
!      .. Implicit None Statement ..
       IMPLICIT NONE
!      .. Parameters ..
       INTEGER, PARAMETER              :: nin = 5, nout = 6
!      .. Local Scalars ..
       INTEGER                         :: ifail, info, ldf, lena, n
       CHARACTER (1)                   :: transr, uplo
!      .. Local Arrays ..
       COMPLEX (KIND=nag_wp), ALLOCATABLE :: a(:), f(:,:)
       CHARACTER (1)                   :: clabs(1), rlabs(1)
!      .. Executable Statements ..
       WRITE (nout,*) 'F07WRF Example Program Results'
!      Skip heading in data file
       READ (nin,*)
       READ (nin,*) n, uplo, transr

       lena = n*(n+1)/2
       ldf = n
       ALLOCATE (a(lena),f(ldf,n))

!      Read A from data file
       READ (nin,*) a(1:lena)

!      Factorize A
!      The NAG name equivalent of zpftrf is f07wrf
       CALL zpftrf(transr,uplo,n,a,info)

       WRITE (nout,*)
       FLUSH (nout)
       IF (info==0) THEN

!         Convert and print factor
!         The NAG name equivalent of ztfttr is f01vhf
          CALL ztfttr(transr,uplo,n,a,f,ldf,info)
          ifail = 0
          CALL x04dbf(uplo,'Nonunit',n,n,f,ldf,'Bracketed','F7.4','Factor', &
             'Integer',rlabs,'Integer',clabs,80,0,ifail)

       ELSE
          WRITE (nout,*) 'A is not positive definite'
       END IF

    END PROGRAM f07wrfe
