    PROGRAM f06wpfe

!      F06WPF Example Program Text

!      Mark 23 Release. NAG Copyright 2011.

!      .. Use Statements ..
       USE nag_library, ONLY : nag_wp, x04daf, ztfsm, ztrttf
!      .. Implicit None Statement ..
       IMPLICIT NONE
!      .. Parameters ..
       INTEGER, PARAMETER              :: nin = 5, nout = 6
!      .. Local Scalars ..
       COMPLEX (KIND=nag_wp)           :: alpha
       INTEGER                         :: i, ifail, info, lda, ldb, m, n
       CHARACTER (1)                   :: side, trans, transr, uplo
!      .. Local Arrays ..
       COMPLEX (KIND=nag_wp), ALLOCATABLE :: a(:,:), af(:), b(:,:), work(:)
!      .. Executable Statements ..
       WRITE (nout,*) 'F06WPF Example Program Results'

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

       READ (nin,*) m, n, uplo, transr, side, alpha, trans

       lda = m
       ldb = m
       ALLOCATE (a(lda,m),af((m*(m+1))/2),work(m),b(ldb,n))

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

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

!      Read matrix B from data file       

       READ (nin,*) (b(i,1:n),i=1,m)

!      Convert A to rectangular full packed storage in AF

!      The NAG name equivalent of ztrttf is f01vef
       CALL ztrttf(transr,uplo,m,a,lda,af,info)

       WRITE (nout,*)
       FLUSH (nout)

!      The NAG name equivalent of ztfsm is f06wpf
       CALL ztfsm(transr,side,uplo,trans,'N',m,n,alpha,af,b,ldb)
       CALL x04daf('General',' ',m,n,b,ldb,'The Solution',ifail)

    END PROGRAM f06wpfe
