    PROGRAM f07cnfe

!      F07CNF Example Program Text

!      Mark 23 Release. NAG Copyright 2011.

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

       ALLOCATE (b(n),d(n),dl(n-1),du(n-1))

!      Read the tridiagonal matrix A and the right hand side B from
!      data file

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

!      Solve the equations Ax = b for x
!      The NAG name equivalent of zgtsv is f07cnf
       CALL zgtsv(n,1,dl,d,du,b,n,info)

       IF (info==0) THEN

!         Print solution

          WRITE (nout,*) 'Solution'
          WRITE (nout,99999) b(1:n)

       ELSE
          WRITE (nout,99998) 'The (', info, ',', info, ')', &
             ' element of the factor U is zero'
       END IF

99999  FORMAT (4(' (',F8.4,',',F8.4,')':))
99998  FORMAT (1X,A,I3,A,I3,A,A)
    END PROGRAM f07cnfe
