1       SUBROUTINE STBT03( UPLO, TRANS, DIAG, N, KD, NRHS, AB, LDAB,
  2      $                   SCALE, CNORM, TSCAL, X, LDX, B, LDB, WORK,
  3      $                   RESID )
  4 *
  5 *  -- LAPACK test routine (version 3.1) --
  6 *     Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd..
  7 *     November 2006
  8 *
  9 *     .. Scalar Arguments ..
 10       CHARACTER          DIAG, TRANS, UPLO
 11       INTEGER            KD, LDAB, LDB, LDX, N, NRHS
 12       REAL               RESID, SCALE, TSCAL
 13 *     ..
 14 *     .. Array Arguments ..
 15       REAL               AB( LDAB, * ), B( LDB, * ), CNORM( * ),
 16      $                   WORK( * ), X( LDX, * )
 17 *     ..
 18 *
 19 *  Purpose
 20 *  =======
 21 *
 22 *  STBT03 computes the residual for the solution to a scaled triangular
 23 *  system of equations  A*x = s*b  or  A'*x = s*b  when A is a
 24 *  triangular band matrix. Here A' is the transpose of A, s is a scalar,
 25 *  and x and b are N by NRHS matrices.  The test ratio is the maximum
 26 *  over the number of right hand sides of
 27 *     norm(s*b - op(A)*x) / ( norm(op(A)) * norm(x) * EPS ),
 28 *  where op(A) denotes A or A' and EPS is the machine epsilon.
 29 *
 30 *  Arguments
 31 *  =========
 32 *
 33 *  UPLO    (input) CHARACTER*1
 34 *          Specifies whether the matrix A is upper or lower triangular.
 35 *          = 'U':  Upper triangular
 36 *          = 'L':  Lower triangular
 37 *
 38 *  TRANS   (input) CHARACTER*1
 39 *          Specifies the operation applied to A.
 40 *          = 'N':  A *x = b  (No transpose)
 41 *          = 'T':  A'*x = b  (Transpose)
 42 *          = 'C':  A'*x = b  (Conjugate transpose = Transpose)
 43 *
 44 *  DIAG    (input) CHARACTER*1
 45 *          Specifies whether or not the matrix A is unit triangular.
 46 *          = 'N':  Non-unit triangular
 47 *          = 'U':  Unit triangular
 48 *
 49 *  N       (input) INTEGER
 50 *          The order of the matrix A.  N >= 0.
 51 *
 52 *  KD      (input) INTEGER
 53 *          The number of superdiagonals or subdiagonals of the
 54 *          triangular band matrix A.  KD >= 0.
 55 *
 56 *  NRHS    (input) INTEGER
 57 *          The number of right hand sides, i.e., the number of columns
 58 *          of the matrices X and B.  NRHS >= 0.
 59 *
 60 *  AB      (input) REAL array, dimension (LDAB,N)
 61 *          The upper or lower triangular band matrix A, stored in the
 62 *          first kd+1 rows of the array. The j-th column of A is stored
 63 *          in the j-th column of the array AB as follows:
 64 *          if UPLO = 'U', AB(kd+1+i-j,j) = A(i,j) for max(1,j-kd)<=i<=j;
 65 *          if UPLO = 'L', AB(1+i-j,j)    = A(i,j) for j<=i<=min(n,j+kd).
 66 *
 67 *  LDAB    (input) INTEGER
 68 *          The leading dimension of the array AB.  LDAB >= KD+1.
 69 *
 70 *  SCALE   (input) REAL
 71 *          The scaling factor s used in solving the triangular system.
 72 *
 73 *  CNORM   (input) REAL array, dimension (N)
 74 *          The 1-norms of the columns of A, not counting the diagonal.
 75 *
 76 *  TSCAL   (input) REAL
 77 *          The scaling factor used in computing the 1-norms in CNORM.
 78 *          CNORM actually contains the column norms of TSCAL*A.
 79 *
 80 *  X       (input) REAL array, dimension (LDX,NRHS)
 81 *          The computed solution vectors for the system of linear
 82 *          equations.
 83 *
 84 *  LDX     (input) INTEGER
 85 *          The leading dimension of the array X.  LDX >= max(1,N).
 86 *
 87 *  B       (input) REAL array, dimension (LDB,NRHS)
 88 *          The right hand side vectors for the system of linear
 89 *          equations.
 90 *
 91 *  LDB     (input) INTEGER
 92 *          The leading dimension of the array B.  LDB >= max(1,N).
 93 *
 94 *  WORK    (workspace) REAL array, dimension (N)
 95 *
 96 *  RESID   (output) REAL
 97 *          The maximum over the number of right hand sides of
 98 *          norm(op(A)*x - s*b) / ( norm(op(A)) * norm(x) * EPS ).
 99 *
100 *  =====================================================================
101 *
102 *     .. Parameters ..
103       REAL               ONE, ZERO
104       PARAMETER          ( ONE = 1.0E+0, ZERO = 0.0E+0 )
105 *     ..
106 *     .. Local Scalars ..
107       INTEGER            IX, J
108       REAL               BIGNUM, EPS, ERR, SMLNUM, TNORM, XNORM, XSCAL
109 *     ..
110 *     .. External Functions ..
111       LOGICAL            LSAME
112       INTEGER            ISAMAX
113       REAL               SLAMCH
114       EXTERNAL           LSAME, ISAMAX, SLAMCH
115 *     ..
116 *     .. External Subroutines ..
117       EXTERNAL           SAXPY, SCOPY, SLABAD, SSCAL, STBMV
118 *     ..
119 *     .. Intrinsic Functions ..
120       INTRINSIC          ABSMAX, REAL
121 *     ..
122 *     .. Executable Statements ..
123 *
124 *     Quick exit if N = 0
125 *
126       IF( N.LE.0 .OR. NRHS.LE.0 ) THEN
127          RESID = ZERO
128          RETURN
129       END IF
130       EPS = SLAMCH( 'Epsilon' )
131       SMLNUM = SLAMCH( 'Safe minimum' )
132       BIGNUM = ONE / SMLNUM
133       CALL SLABAD( SMLNUM, BIGNUM )
134 *
135 *     Compute the norm of the triangular matrix A using the column
136 *     norms already computed by SLATBS.
137 *
138       TNORM = ZERO
139       IF( LSAME( DIAG, 'N' ) ) THEN
140          IF( LSAME( UPLO, 'U' ) ) THEN
141             DO 10 J = 1, N
142                TNORM = MAX( TNORM, TSCAL*ABS( AB( KD+1, J ) )+
143      $                 CNORM( J ) )
144    10       CONTINUE
145          ELSE
146             DO 20 J = 1, N
147                TNORM = MAX( TNORM, TSCAL*ABS( AB( 1, J ) )+CNORM( J ) )
148    20       CONTINUE
149          END IF
150       ELSE
151          DO 30 J = 1, N
152             TNORM = MAX( TNORM, TSCAL+CNORM( J ) )
153    30    CONTINUE
154       END IF
155 *
156 *     Compute the maximum over the number of right hand sides of
157 *        norm(op(A)*x - s*b) / ( norm(op(A)) * norm(x) * EPS ).
158 *
159       RESID = ZERO
160       DO 40 J = 1, NRHS
161          CALL SCOPY( N, X( 1, J ), 1, WORK, 1 )
162          IX = ISAMAX( N, WORK, 1 )
163          XNORM = MAX( ONE, ABS( X( IX, J ) ) )
164          XSCAL = ( ONE / XNORM ) / REAL( KD+1 )
165          CALL SSCAL( N, XSCAL, WORK, 1 )
166          CALL STBMV( UPLO, TRANS, DIAG, N, KD, AB, LDAB, WORK, 1 )
167          CALL SAXPY( N, -SCALE*XSCAL, B( 1, J ), 1, WORK, 1 )
168          IX = ISAMAX( N, WORK, 1 )
169          ERR = TSCAL*ABS( WORK( IX ) )
170          IX = ISAMAX( N, X( 1, J ), 1 )
171          XNORM = ABS( X( IX, J ) )
172          IF( ERR*SMLNUM.LE.XNORM ) THEN
173             IF( XNORM.GT.ZERO )
174      $         ERR = ERR / XNORM
175          ELSE
176             IF( ERR.GT.ZERO )
177      $         ERR = ONE / EPS
178          END IF
179          IF( ERR*SMLNUM.LE.TNORM ) THEN
180             IF( TNORM.GT.ZERO )
181      $         ERR = ERR / TNORM
182          ELSE
183             IF( ERR.GT.ZERO )
184      $         ERR = ONE / EPS
185          END IF
186          RESID = MAX( RESID, ERR )
187    40 CONTINUE
188 *
189       RETURN
190 *
191 *     End of STBT03
192 *
193       END