    PROGRAM f07crfe

!      F07CRF Example Program Text

!      Mark 23 Release. NAG Copyright 2011.

!      .. Use Statements ..
       USE nag_library, ONLY : nag_wp, zgttrf
!      .. Implicit None Statement ..
       IMPLICIT NONE
!      .. Parameters ..
       INTEGER, PARAMETER              :: nin = 5, nout = 6
!      .. Local Scalars ..
       INTEGER                         :: info, n
!      .. Local Arrays ..
       COMPLEX (KIND=nag_wp), ALLOCATABLE :: d(:), dl(:), du(:), du2(:)
       INTEGER, ALLOCATABLE            :: ipiv(:)
!      .. Executable Statements ..
       WRITE (nout,*) 'F07CRF Example Program Results'
       WRITE (nout,*)
!      Skip heading in data file
       READ (nin,*)
       READ (nin,*) n

       ALLOCATE (d(n),dl(n-1),du(n-1),du2(n-2),ipiv(n))

!      Read the tridiagonal matrix A from data file

       READ (nin,*) du(1:n-1)
       READ (nin,*) d(1:n)
       READ (nin,*) dl(1:n-1)

!      Factorize the tridiagonal matrix A
!      The NAG name equivalent of zgttrf is f07crf
       CALL zgttrf(n,dl,d,du,du2,ipiv,info)

       IF (info>0) THEN
          WRITE (nout,99999) 'The (', info, ',', info, ')', &
             ' element of the factor U is zero'
       END IF

!      Print details of the factorization

       WRITE (nout,*) 'Details of factorization'
       WRITE (nout,*)
       WRITE (nout,*) ' Second super-diagonal of U'
       WRITE (nout,99998) du2(1:n-2)
       WRITE (nout,*)
       WRITE (nout,*) ' First super-diagonal of U'
       WRITE (nout,99998) du(1:n-1)
       WRITE (nout,*)
       WRITE (nout,*) ' Main diagonal of U'
       WRITE (nout,99998) d(1:n)
       WRITE (nout,*)
       WRITE (nout,*) ' Multipliers'
       WRITE (nout,99998) dl(1:n-1)
       WRITE (nout,*)
       WRITE (nout,*) ' Vector of interchanges'
       WRITE (nout,99997) ipiv(1:n)

99999  FORMAT (1X,A,I3,A,I3,A,A)
99998  FORMAT (4(' (',F8.4,',',F8.4,')':))
99997  FORMAT (1X,5I7)
    END PROGRAM f07crfe
