    Program f08qhfe

!     F08QHF Example Program Text

!     Mark 24 Release. NAG Copyright 2012.

!     .. Use Statements ..
      Use nag_library, Only: dtrsyl, nag_wp, x04caf
!     .. Implicit None Statement ..
      Implicit None
!     .. Parameters ..
      Integer, Parameter               :: nin = 5, nout = 6
!     .. Local Scalars ..
      Real (Kind=nag_wp)               :: scale
      Integer                          :: i, ifail, info, lda, ldb, ldc, m, n, &
                                          sign
!     .. Local Arrays ..
      Real (Kind=nag_wp), Allocatable  :: a(:,:), b(:,:), c(:,:)
!     .. Executable Statements ..
      Write (nout,*) 'F08QHF Example Program Results'
      Write (nout,*)
      Flush (nout)
!     Skip heading in data file
      Read (nin,*)
      Read (nin,*) m, n
      lda = m
      ldb = n
      ldc = m
      sign = 1
      Allocate (a(lda,m),b(ldb,n),c(ldc,n))

!     Read A, B and C from data file

      Read (nin,*)(a(i,1:m),i=1,m)
      Read (nin,*)(b(i,1:n),i=1,n)
      Read (nin,*)(c(i,1:n),i=1,m)

!     Solve the Sylvester equation A*X + X*B = C for X
!     The NAG name equivalent of dtrsyl is f08qhf
      Call dtrsyl('No transpose','No transpose',sign,m,n,a,lda,b,ldb,c,ldc, &
        scale,info)
      If (info==1) Then
        Write (nout,99999)
        Write (nout,*)
      End If

      Flush (nout)

!     Print X
!     ifail: behaviour on error exit
!             =0 for hard exit, =1 for quiet-soft, =-1 for noisy-soft
      ifail = 0
      Call x04caf('General',' ',m,n,c,ldc,'Solution Matrix',ifail)

99999 Format (/' A and B have common or very close eigenvalues.'/' Pe', &
        'rturbed values were used to solve the equations')
    End Program f08qhfe
