    PROGRAM f01bufe

!      F01BUF Example Program Text

!      Mark 23 Release. NAG Copyright 2011.

!      .. Use Statements ..
       USE nag_library, ONLY : f01buf, nag_wp
!      .. Implicit None Statement ..
       IMPLICIT NONE
!      .. Parameters ..
       INTEGER, PARAMETER              :: nin = 5, nout = 6
!      .. Local Scalars ..
       INTEGER                         :: i, ifail, j, k, lda, m, m1, n
!      .. Local Arrays ..
       REAL (KIND=nag_wp), ALLOCATABLE :: a(:,:), w(:)
!      .. Intrinsic Functions ..
       INTRINSIC                          max
!      .. Executable Statements ..
       WRITE (nout,*) 'F01BUF Example Program Results'
!      Skip heading in data file
       READ (nin,*)
       READ (nin,*) n, m1
       lda = m1
       ALLOCATE (a(lda,n),w(m1))
       READ (nin,*) ((a(j,i),j=max(1,m1+1-i),m1),i=1,n)
       m = m1 - 1
       k = ((n+m)/(2*m))*m

!      ifail: behaviour on error exit
!             =0 for hard exit, =1 for quiet-soft, =-1 for noisy-soft
       ifail = 0
       CALL f01buf(n,m1,k,a,lda,w,ifail)

       WRITE (nout,*)
       WRITE (nout,*) 'Computed upper triangular matrix'
       WRITE (nout,*)
       DO i = 1, n
          WRITE (nout,99999) (a(j,i),j=max(1,m1+1-i),m1)
       END DO

99999  FORMAT (1X,8F9.4)
    END PROGRAM f01bufe
