c
c
c*****************************************************************************
c*                                                                           *
c*  Copyright Compaq Computer Corporation 1999.         All rights reserved. *
c*                                                                           *
c*****************************************************************************
c
c
c
C
C
C
      PROGRAM EXAMPLE_LAPACK_1
C

C
C
C ***** TO DEMONSTRATE THE USE OF THE LAPACK LINEAR SYSTEM SOLVER.
C
C ***** THIS PROGRAM ILLUSTRATES THE FOLLOWING:
C
C       (1) USE OF THE FACTOR AND SOLVE ROUTINES TO SOLVE THE TEST 
C           PROBLEM STORED AS A SYMMETRIC BANDED MATRIX.
C       (2) USE OF THE CONDITION NUMBER ESTIMATOR ROUTINE TO OBTAIN 
C           THE CONDITION NUMBER OF THE MATRIX.
C       (3) USE OF THE LAPACK NORM EVALUATION ROUTINE.
C       (4) USE OF THE BLAS2 MATRIX-VECTOR MULTIPLY ROUTINE.
C
C
C ***** THE TEST PROBLEM USED IS SAME AS THE TEST PROBLEM USED IN 
C       THE CXML SPARSE SOLVERS.
C
C ***** SAMPLE OUTPUT FOLLOWS:
C
C   ILLUSTRATING THE USE OF LAPACK LINEAR SYSTEM SOLVERS
C   TEST MATRIX STORED IN A SYMMETRIC BANDED FORM
C      ORDER OF THE MATRIX:  100
C      TRUE SOLUTION     SOLUTION FROM LAPACK     ABS. DIFFERENCE
C       0.10000000E+01      0.10000000E+01      0.22204460E-15
C       0.10000000E+01      0.10000000E+01      0.22204460E-15
C       0.10000000E+01      0.10000000E+01      0.22204460E-15
C       0.10000000E+01      0.10000000E+01      0.22204460E-15
C       0.10000000E+01      0.10000000E+01      0.44408921E-15
C                                  .
C                                  .
C                                  .
C                       (EDITED FOR BREVITY)
C                                  .
C                                  .
C                                  .
C       0.10000000E+01      0.10000000E+01      0.11102230E-15
C       0.10000000E+01      0.10000000E+01      0.22204460E-15
C       0.10000000E+01      0.10000000E+01      0.11102230E-15
C       0.10000000E+01      0.10000000E+01      0.11102230E-15
C      MAXIMUM ERROR IN SOLUTION:  0.13322676E-14
C      1-NORM OF THE MATRIX: 0.80000000E+01
C      RECIPROCAL OF CONDITION NUMBER ESTIMATE: 0.14313652E-01
C
C
C
C
C
C      IMPLICIT REAL*8 (A-H, O-Z)

      PARAMETER (NMAX = 100)
      PARAMETER (NMAX_BAND = 12)
C
      REAL*8 ABND(NMAX_BAND, NMAX), XO(NMAX), BX(NMAX, 2),
     $       RWORK(3*NMAX), TEMP
      REAL*8 ANORM, DLANSB
      REAL*8 RCOND
C
      INTEGER IWORK(NMAX), I, NX, NY, NXNY, IDUM
C
C ***** SETUP OUTPUT FILE
C
      IOUNIT = 7
      OPEN (UNIT=IOUNIT, FILE='OUTPUT.DATA', STATUS='UNKNOWN')
      REWIND IOUNIT
C
      WRITE (IOUNIT, 101)
C
C ***** SET UP THE PROBLEM SIZE
C
      NX = 10
      NY = 10
      NXNY = NX*NY
      WRITE (IOUNIT, 102) NXNY
C 
C ***** GENERATE THE MATRIX AND STORE THE UPPER TRIANGULAR PART IN 
C       THE LAPACK BANDED FORM.
C
      IBW = NX+1
      DO J = 1, NXNY
          DO I = 1, IBW
              ABND(I,J) = 0.0D0
          END DO
      END DO
C
      DO J = 1, NXNY
          ABND(IBW,J) = 4.0D0
      END DO
C
      DO J = 1, NY
          DO I = 2, NX
              K = (J-1) * NX + I
              ABND(IBW-1,K) = -1.0D0
          END DO
      END DO
C
      DO J = IBW, NXNY
          ABND(1,J) = -1.0D0
      END DO
C
C ***** GENERATE XO, THE TRUE SOLUTION
C
      DO I = 1, NXNY
          XO(I) = 1.0D0
      END DO
C
C ***** OBTAIN THE CORRESPONDING RIGHT HAND SIDE (IN BX), USING THE
C       BLAS 2 ROUTINE FOR SYMMETRIC BANDED MATRIX-VECTOR MULTIPLY.
C
      CALL DSBMV ('U', NXNY, NX, 1.0D0, ABND, NMAX_BAND, XO, 1, 0.0D0,
     $            BX, 1)
C
C ***** FIRST DETERMINE THE 1-NORM OF THE MATRIX. THE FACTORIZATION 
C         ROUTINE OVERWRITES THE MATRIX BY THE CHOLESKY FACTORS.
C
      ANORM = DLANSB ('O', 'U', NXNY, NX, ABND, NMAX_BAND, RWORK)
C
C ***** CALL THE ROUTINE FOR FACTORIZATION. THE MATRIX IS SYMMETRIC,
C       POSITIVE DEFINITE; THEREFORE NO PIVOTING IS REQUIRED.
C
      CALL DPBTRF ( 'U', NXNY, NX, ABND, NMAX_BAND, INFO)
C
C ***** CHECK THAT FACTORIZATION COMPLETED WITHOUT ERROR
C
      IF (INFO.NE.0) THEN
          WRITE (IOUNIT, 103) INFO
          GO TO 999
      END IF
C
C ***** CALL THE ROUTINE FOR SOLUTION (SINGLE RIGHT HAND SIDE). 
C
      NBX = 1
      CALL DPBTRS ( 'U', NXNY, NX, NBX, ABND, NMAX_BAND, 
     $              BX, NMAX, INFO)
C
C ***** CHECK THAT THE SOLUTION COMPLETED WITHOUT ERROR
C
      IF (INFO.NE.0) THEN
          WRITE (IOUNIT, 104) INFO
          GO TO 999
      END IF
C
C ***** PRINT OUT THE SOLUTION
C
      WRITE (IOUNIT, 105)
      WRITE (IOUNIT, 106) (XO(I),BX(I,1),ABS(XO(I)-BX(I,1)),I=1,NXNY)
C
C ***** FIND MAX ERROR IN SOLUTION
C
      TEMP = ABS(XO(1) - BX(1,1))
      DO I = 2, NXNY
         TEMP = MAX( TEMP, ABS(XO(I) - BX(I,1)) )
      END DO
      WRITE (IOUNIT, 107) TEMP
C
C ***** DETERMINE THE RECIPROCAL OF THE CONDITION NUMBER ESTIMATE OF
C       THE MATRIX. 
C
      CALL DPBCON ('U', NXNY, NX, ABND, NMAX_BAND, ANORM, RCOND, 
     $              RWORK, IWORK, INFO)
C
C ***** CHECK THAT THE CONDITION ESTIMATION COMPLETED WITHOUT ERROR
C
      IF (INFO.NE.0) THEN
          WRITE (IOUNIT, 108) INFO
          GO TO 999
      END IF
C
      WRITE (IOUNIT, 109) ANORM, RCOND
C
  999 CONTINUE
C
  101 FORMAT (/,2X, 'ILLUSTRATING THE USE OF LAPACK LINEAR SYSTEM',
     $              ' SOLVERS',
     $        /,2X, 'TEST MATRIX STORED IN A SYMMETRIC BANDED FORM',/)
  102 FORMAT (/,5X, 'ORDER OF THE MATRIX:',I5)
  103 FORMAT (/,5X, 'ERROR IN THE FACTORIZATION ROUTINE. INFO:',I10)
  104 FORMAT (/,5X, 'ERROR IN THE SOLUTION ROUTINE. INFO:',I10)
  105 FORMAT (/,5X, 'TRUE SOLUTION',5X,'SOLUTION FROM LAPACK',
     $          5X, 'ABS. DIFFERENCE'/)
  106 FORMAT (/,3(5X,E15.8))
  107 FORMAT (/,5X, 'MAXIMUM ERROR IN SOLUTION: ', E15.8,/)
  108 FORMAT (/,5X, 'ERROR IN THE CONDITION ESTIMATION ROUTINE. INFO:',
     $               I10)
  109 FORMAT (/,5X, '1-NORM OF THE MATRIX:',E15.8,
     $        /,5X, 'RECIPROCAL OF CONDITION NUMBER ESTIMATE:',E15.8)
C
      STOP
      END
