1       SUBROUTINE CGBT05( TRANS, N, KL, KU, NRHS, AB, LDAB, B, LDB, X,
  2      $                   LDX, XACT, LDXACT, FERR, BERR, RESLTS )
  3 *
  4 *  -- LAPACK test routine (version 3.1) --
  5 *     Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd..
  6 *     November 2006
  7 *
  8 *     .. Scalar Arguments ..
  9       CHARACTER          TRANS
 10       INTEGER            KL, KU, LDAB, LDB, LDX, LDXACT, N, NRHS
 11 *     ..
 12 *     .. Array Arguments ..
 13       REAL               BERR( * ), FERR( * ), RESLTS( * )
 14       COMPLEX            AB( LDAB, * ), B( LDB, * ), X( LDX, * ),
 15      $                   XACT( LDXACT, * )
 16 *     ..
 17 *
 18 *  Purpose
 19 *  =======
 20 *
 21 *  CGBT05 tests the error bounds from iterative refinement for the
 22 *  computed solution to a system of equations op(A)*X = B, where A is a
 23 *  general band matrix of order n with kl subdiagonals and ku
 24 *  superdiagonals and op(A) = A or A**T, depending on TRANS.
 25 *
 26 *  RESLTS(1) = test of the error bound
 27 *            = norm(X - XACT) / ( norm(X) * FERR )
 28 *
 29 *  A large value is returned if this ratio is not less than one.
 30 *
 31 *  RESLTS(2) = residual from the iterative refinement routine
 32 *            = the maximum of BERR / ( NZ*EPS + (*) ), where
 33 *              (*) = NZ*UNFL / (min_i (abs(op(A))*abs(X) +abs(b))_i )
 34 *              and NZ = max. number of nonzeros in any row of A, plus 1
 35 *
 36 *  Arguments
 37 *  =========
 38 *
 39 *  TRANS   (input) CHARACTER*1
 40 *          Specifies the form of the system of equations.
 41 *          = 'N':  A * X = B     (No transpose)
 42 *          = 'T':  A**T * X = B  (Transpose)
 43 *          = 'C':  A**H * X = B  (Conjugate transpose = Transpose)
 44 *
 45 *  N       (input) INTEGER
 46 *          The number of rows of the matrices X, B, and XACT, and the
 47 *          order of the matrix A.  N >= 0.
 48 *
 49 *  KL      (input) INTEGER
 50 *          The number of subdiagonals within the band of A.  KL >= 0.
 51 *
 52 *  KU      (input) INTEGER
 53 *          The number of superdiagonals within the band of A.  KU >= 0.
 54 *
 55 *  NRHS    (input) INTEGER
 56 *          The number of columns of the matrices X, B, and XACT.
 57 *          NRHS >= 0.
 58 *
 59 *  AB      (input) COMPLEX array, dimension (LDAB,N)
 60 *          The original band matrix A, stored in rows 1 to KL+KU+1.
 61 *          The j-th column of A is stored in the j-th column of the
 62 *          array AB as follows:
 63 *          AB(ku+1+i-j,j) = A(i,j) for max(1,j-ku)<=i<=min(n,j+kl).
 64 *
 65 *  LDAB    (input) INTEGER
 66 *          The leading dimension of the array AB.  LDAB >= KL+KU+1.
 67 *
 68 *  B       (input) COMPLEX array, dimension (LDB,NRHS)
 69 *          The right hand side vectors for the system of linear
 70 *          equations.
 71 *
 72 *  LDB     (input) INTEGER
 73 *          The leading dimension of the array B.  LDB >= max(1,N).
 74 *
 75 *  X       (input) COMPLEX array, dimension (LDX,NRHS)
 76 *          The computed solution vectors.  Each vector is stored as a
 77 *          column of the matrix X.
 78 *
 79 *  LDX     (input) INTEGER
 80 *          The leading dimension of the array X.  LDX >= max(1,N).
 81 *
 82 *  XACT    (input) COMPLEX array, dimension (LDX,NRHS)
 83 *          The exact solution vectors.  Each vector is stored as a
 84 *          column of the matrix XACT.
 85 *
 86 *  LDXACT  (input) INTEGER
 87 *          The leading dimension of the array XACT.  LDXACT >= max(1,N).
 88 *
 89 *  FERR    (input) REAL array, dimension (NRHS)
 90 *          The estimated forward error bounds for each solution vector
 91 *          X.  If XTRUE is the true solution, FERR bounds the magnitude
 92 *          of the largest entry in (X - XTRUE) divided by the magnitude
 93 *          of the largest entry in X.
 94 *
 95 *  BERR    (input) REAL array, dimension (NRHS)
 96 *          The componentwise relative backward error of each solution
 97 *          vector (i.e., the smallest relative change in any entry of A
 98 *          or B that makes X an exact solution).
 99 *
100 *  RESLTS  (output) REAL array, dimension (2)
101 *          The maximum over the NRHS solution vectors of the ratios:
102 *          RESLTS(1) = norm(X - XACT) / ( norm(X) * FERR )
103 *          RESLTS(2) = BERR / ( NZ*EPS + (*) )
104 *
105 *  =====================================================================
106 *
107 *     .. Parameters ..
108       REAL               ZERO, ONE
109       PARAMETER          ( ZERO = 0.0E+0, ONE = 1.0E+0 )
110 *     ..
111 *     .. Local Scalars ..
112       LOGICAL            NOTRAN
113       INTEGER            I, IMAX, J, K, NZ
114       REAL               AXBI, DIFF, EPS, ERRBND, OVFL, TMP, UNFL, XNORM
115       COMPLEX            ZDUM
116 *     ..
117 *     .. External Functions ..
118       LOGICAL            LSAME
119       INTEGER            ICAMAX
120       REAL               SLAMCH
121       EXTERNAL           LSAME, ICAMAX, SLAMCH
122 *     ..
123 *     .. Intrinsic Functions ..
124       INTRINSIC          ABSAIMAGMAXMIN, REAL
125 *     ..
126 *     .. Statement Functions ..
127       REAL               CABS1
128 *     ..
129 *     .. Statement Function definitions ..
130       CABS1( ZDUM ) = ABSREAL( ZDUM ) ) + ABSAIMAG( ZDUM ) )
131 *     ..
132 *     .. Executable Statements ..
133 *
134 *     Quick exit if N = 0 or NRHS = 0.
135 *
136       IF( N.LE.0 .OR. NRHS.LE.0 ) THEN
137          RESLTS( 1 ) = ZERO
138          RESLTS( 2 ) = ZERO
139          RETURN
140       END IF
141 *
142       EPS = SLAMCH( 'Epsilon' )
143       UNFL = SLAMCH( 'Safe minimum' )
144       OVFL = ONE / UNFL
145       NOTRAN = LSAME( TRANS, 'N' )
146       NZ = MIN( KL+KU+2, N+1 )
147 *
148 *     Test 1:  Compute the maximum of
149 *        norm(X - XACT) / ( norm(X) * FERR )
150 *     over all the vectors X and XACT using the infinity-norm.
151 *
152       ERRBND = ZERO
153       DO 30 J = 1, NRHS
154          IMAX = ICAMAX( N, X( 1, J ), 1 )
155          XNORM = MAX( CABS1( X( IMAX, J ) ), UNFL )
156          DIFF = ZERO
157          DO 10 I = 1, N
158             DIFF = MAX( DIFF, CABS1( X( I, J )-XACT( I, J ) ) )
159    10    CONTINUE
160 *
161          IF( XNORM.GT.ONE ) THEN
162             GO TO 20
163          ELSE IF( DIFF.LE.OVFL*XNORM ) THEN
164             GO TO 20
165          ELSE
166             ERRBND = ONE / EPS
167             GO TO 30
168          END IF
169 *
170    20    CONTINUE
171          IF( DIFF / XNORM.LE.FERR( J ) ) THEN
172             ERRBND = MAX( ERRBND, ( DIFF / XNORM ) / FERR( J ) )
173          ELSE
174             ERRBND = ONE / EPS
175          END IF
176    30 CONTINUE
177       RESLTS( 1 ) = ERRBND
178 *
179 *     Test 2:  Compute the maximum of BERR / ( NZ*EPS + (*) ), where
180 *     (*) = NZ*UNFL / (min_i (abs(op(A))*abs(X) +abs(b))_i )
181 *
182       DO 70 K = 1, NRHS
183          DO 60 I = 1, N
184             TMP = CABS1( B( I, K ) )
185             IF( NOTRAN ) THEN
186                DO 40 J = MAX( I-KL, 1 ), MIN( I+KU, N )
187                   TMP = TMP + CABS1( AB( KU+1+I-J, J ) )*
188      $                  CABS1( X( J, K ) )
189    40          CONTINUE
190             ELSE
191                DO 50 J = MAX( I-KU, 1 ), MIN( I+KL, N )
192                   TMP = TMP + CABS1( AB( KU+1+J-I, I ) )*
193      $                  CABS1( X( J, K ) )
194    50          CONTINUE
195             END IF
196             IF( I.EQ.1 ) THEN
197                AXBI = TMP
198             ELSE
199                AXBI = MIN( AXBI, TMP )
200             END IF
201    60    CONTINUE
202          TMP = BERR( K ) / ( NZ*EPS+NZ*UNFL / MAX( AXBI, NZ*UNFL ) )
203          IF( K.EQ.1 ) THEN
204             RESLTS( 2 ) = TMP
205          ELSE
206             RESLTS( 2 ) = MAX( RESLTS( 2 ), TMP )
207          END IF
208    70 CONTINUE
209 *
210       RETURN
211 *
212 *     End of CGBT05
213 *
214       END