@extract -b incpath.inc
@extract -b @(incd)/type.inc type=@(@type)
@ROUT ptsv
PROGRAM LA_@(pre)PTSV_ET_EXAMPLE
@extract -b @(incd)/header.inc -case0
!  .. Use Statements
   USE LA_PRECISION, ONLY: WP => @(upr)P
   USE F90_LAPACK, ONLY: LA_PTSV
!  .. Implicit Statement ..
   IMPLICIT NONE
!  .. Parameters ..
 @type sreal dreal
      CHARACTER(LEN=*), PARAMETER :: FMT = '(8(1X,F10.3))'
 @type scplx dcplx
      CHARACTER(LEN=*), PARAMETER :: FMTR = '(8(1X,F10.3))'
      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 ..
   @(type)(WP), ALLOCATABLE :: E(:), B(:,:)
   REAL(WP), ALLOCATABLE :: D(:), DD(:), EE(:), BB(:,:)
!  .. Executable Statements ..
   WRITE (NOUT,*) '@(pre)PTSV ET_Example Program Results.'
   READ ( NIN, * )   ! Skip heading in data file
   READ ( NIN, * ) N, NRHS
   PRINT *, 'N = ', N, ' NRHS = ', NRHS
   ALLOCATE ( D(N), DD(N), E(N-1), EE(N-1), B(N,NRHS), BB(N,NRHS) )
!
        READ (NIN, *) DD(:), EE(:)
        
      BB(1,:) = DD(1) + EE(1)
!     BB(2:N-1,:) = EE(1:N-2) + DD(2:N-1) + EE(2:N-1)
      DO I = 2, N-1
         BB(I,:) = EE(I-1) + DD(I) + EE(I)
      ENDDO
      BB(N,:) = EE(N-1) + DD(N)
      DO I = 1, NRHS
         BB(:,I) = BB(:,I)*I
      ENDDO
   D = DD; E = EE; B = BB
      WRITE(NOUT,*) 'The matrix A:'
 @type sreal dreal
      WRITE (NOUT,*) 'D  '; WRITE (NOUT,FMT) D
 @type scplx dcplx
      WRITE (NOUT,*) 'D  '; WRITE (NOUT,FMTR) D
 @type !
      WRITE (NOUT,*) 'EE '; WRITE (NOUT,FMT) E
      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)PTSV LAPACK Subroutine Results.'
   WRITE ( NOUT, * )
!
   WRITE(NOUT,*)
   WRITE(NOUT,*) 'CALL LA_PTSV( D, E, B )'
   D = DD; E = EE; B = BB
   IF (NRHS .GT. 1) THEN
      CALL LA_PTSV( D, E, B )
   ELSE
      CALL LA_PTSV( D, E, B(1:N,1) )
   END IF
   WRITE(NOUT,*)'   B - the solution vectors computed by LA_PTSV:'
   DO J = 1, NRHS
      WRITE (NOUT,FMT) B(:,J)
   END DO
! 
   WRITE(NOUT,*)
   WRITE(NOUT,*) 'CALL LA_PTSV( D, E, B, INFO=IFAIL)'
   D = DD; E = EE; B = BB
   CALL LA_PTSV( D, E, B, INFO=IFAIL )
   WRITE(NOUT,*)'   B - the solution vectors computed by LA_PTSV, INFO = ', IFAIL
   DO J = 1, NRHS
      WRITE (NOUT,FMT) B(:,J)
   END DO
   D = DD; E = EE; B = BB
   CALL LA_PTSV( D, E, B(1:N,1), IFAIL )
   WRITE(NOUT,*)'   B - the solution vectors computed by LA_PTSV, INFO = ', IFAIL
   WRITE (NOUT,FMT) B(1:N,1)
!
END PROGRAM LA_@(pre)PTSV_ET_EXAMPLE
