@extract -b incpath.inc
@extract -b @(incd)/type.inc type=@(@type)
@ROUT gtsv
PROGRAM LA_@(pre)GTSV_ET_EXAMPLE
@extract -b @(incd)/header.inc -case0
!  .. Use Statements
   USE LA_PRECISION, ONLY: WP => @(upr)P
   USE F90_LAPACK, ONLY: LA_GTSV
!  .. Implicit Statement ..
   IMPLICIT NONE
!  .. Parameters ..
 @type sreal dreal
      CHARACTER(LEN=*), PARAMETER :: FMT = '(8(1X,F10.3))'
 @type scplx dcplx
      CHARACTER(LEN=*), PARAMETER :: FMT =                              &
     &                   '(4(1X,1H(,F7.3,1H,,F7.3,1H):))'
 @type !
   INTEGER, PARAMETER :: NIN=5, NOUT=6
!  .. Local Scalars ..
   INTEGER :: I, J, IFAIL, N, NRHS
!  .. Local Arrays ..
   REAL(WP), ALLOCATABLE :: DDL(:), DD(:), DDU(:), BB(:,:)
   @(type)(WP), ALLOCATABLE :: DL(:), D(:), DU(:), B(:,:)
!  .. Executable Statements ..
   WRITE (NOUT,*) '@(pre)GTSV ET_Example Program Results.'
   READ ( NIN, * )   ! Skip heading in data file
   READ ( NIN, * ) N, NRHS
   PRINT *, 'N = ', N, ' NRHS = ', NRHS
   ALLOCATE ( DL(N-1), DDL(N-1), D(N), DD(N), DU(N-1), DDU(N-1), B(N,NRHS), BB(N,NRHS) )
!
        READ (NIN, *) DDU(:), DD(:), DDL(:)
        
      BB(1,:) = DD(1) + DDU(1)
!     BB(2:N-1,:) = DDL(1:N-2) + DD(2:N-1) + DDU(2:N-1)
      DO I = 2, N-1
         BB(I,:) = DDL(I-1) + DD(I) + DDU(I)
      ENDDO
      BB(N,:) = DDL(N-1) + DD(N-1)
      DO I = 1, NRHS
         BB(:,I) = BB(:,I)*I
      ENDDO
!
   DL = DDL; D = DD; DU = DDU; B = BB
      WRITE(NOUT,*) 'The matrix A:'
      WRITE (NOUT,*) 'DU '; WRITE (NOUT,FMT) DU
      WRITE (NOUT,*) 'D  '; WRITE (NOUT,FMT) D
      WRITE (NOUT,*) 'DL '; WRITE (NOUT,FMT) DL
      WRITE(NOUT,*) 'The RHS matrix B:'
      DO J = 1, NRHS
        WRITE (NOUT,*) 'RHS', J; WRITE (NOUT,FMT) B(:,J)
      ENDDO
!
   WRITE ( NOUT, * )'---------------------------------------------------------'
   WRITE ( NOUT, * )
   WRITE ( NOUT, * )'Details of LA_@(pre)GTSV LAPACK Subroutine Results.'
!
   WRITE(NOUT,*)
   WRITE(NOUT,*) ' CALL LA_GTSV(DL, D, DU, B )'
   DL = DDL; D = DD; DU = DDU; B = BB
   CALL LA_GTSV(DL, D, DU, B )
   WRITE(NOUT,*)'   B - the solution vectors computed by LA_GTSV:'
   DO J = 1, NRHS; WRITE (NOUT,FMT) B(:,J); END DO
!
   WRITE(NOUT,*)
   WRITE(NOUT,*) 'CALL LA_GTSV(DL, D, DU, B(1:N,1)'
   DL = DDL; D = DD; DU = DDU; B = BB
   CALL LA_GTSV(DL, D, DU, B(1:N,1) )
   WRITE(NOUT,*)'   B - the solution vectors computed by LA_GTSV:'
   WRITE (NOUT,FMT) B(:,1)
! 
   WRITE(NOUT,*)
   WRITE(NOUT,*) 'CALL LA_GTSV(DL, D, DU, B, INFO=IFAIL )'
   DL = DDL; D = DD; DU = DDU; B = BB
   CALL LA_GTSV(DL, D, DU, B, INFO=IFAIL )
   WRITE(NOUT,*)'   B - the solution vectors computed by LA_GTSV:'
   DO J = 1, NRHS; WRITE (NOUT,FMT) B(:,J); END DO
! 
   WRITE(NOUT,*)
   WRITE(NOUT,*) ' CALL LA_GTSV(DL, D, DU, B(1:N,1), IFAIL )'
   DL = DDL; D = DD; DU = DDU; B = BB
   CALL LA_GTSV(DL, D, DU, B(1:N,1), IFAIL )
   WRITE(NOUT,*)'   B - the solution vectors computed by LA_GTSV:'
   WRITE (NOUT,FMT) B(1:N,1)
!
END PROGRAM LA_@(pre)GTSV_ET_EXAMPLE
