    Program f06wbfe

!     F06WBF Example Program Text

!     Mark 24 Release. NAG Copyright 2012.

!     .. Use Statements ..
      Use nag_library, Only: dtfsm, dtrttf, nag_wp, x04caf
!     .. Implicit None Statement ..
      Implicit None
!     .. Parameters ..
      Integer, Parameter               :: nin = 5, nout = 6
!     .. Local Scalars ..
      Real (Kind=nag_wp)               :: alpha
      Integer                          :: i, ifail, info, lda, ldb, m, n
      Character (1)                    :: side, trans, transr, uplo
!     .. Local Arrays ..
      Real (Kind=nag_wp), Allocatable  :: a(:,:), af(:), b(:,:), work(:)
!     .. Executable Statements ..
      Write (nout,*) 'F06WBF 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 dtrttf is f01vef
      Call dtrttf(transr,uplo,m,a,lda,af,info)

      Write (nout,*)
      Flush (nout)

!     Perform the matrix-matrix operation

!     The NAG name equivalent of dtfsm is f06wbf
      Call dtfsm(transr,side,uplo,trans,'N',m,n,alpha,af,b,ldb)

!     Print the result

      ifail = 0
      Call x04caf('General',' ',m,n,b,ldb,'The Solution',ifail)

    End Program f06wbfe
