    Program f07crfe

!     F07CRF Example Program Text

!     Mark 24 Release. NAG Copyright 2012.

!     .. 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
