001:       SUBROUTINE CGBRFSX( TRANS, EQUED, N, KL, KU, NRHS, AB, LDAB, AFB,
002:      $                    LDAFB, IPIV, R, C, B, LDB, X, LDX, RCOND,
003:      $                    BERR, N_ERR_BNDS, ERR_BNDS_NORM,
004:      $                    ERR_BNDS_COMP, NPARAMS, PARAMS, WORK, RWORK,
005:      $                    INFO )
006: *
007: *     -- LAPACK routine (version 3.2)                                 --
008: *     -- Contributed by James Demmel, Deaglan Halligan, Yozo Hida and --
009: *     -- Jason Riedy of Univ. of California Berkeley.                 --
010: *     -- November 2008                                                --
011: *
012: *     -- LAPACK is a software package provided by Univ. of Tennessee, --
013: *     -- Univ. of California Berkeley and NAG Ltd.                    --
014: *
015:       IMPLICIT NONE
016: *     ..
017: *     .. Scalar Arguments ..
018:       CHARACTER          TRANS, EQUED
019:       INTEGER            INFO, LDAB, LDAFB, LDB, LDX, N, KL, KU, NRHS,
020:      $                   NPARAMS, N_ERR_BNDS
021:       REAL               RCOND
022: *     ..
023: *     .. Array Arguments ..
024:       INTEGER            IPIV( * )
025:       COMPLEX            AB( LDAB, * ), AFB( LDAFB, * ), B( LDB, * ),
026:      $                   X( LDX , * ),WORK( * )
027:       REAL               R( * ), C( * ), PARAMS( * ), BERR( * ),
028:      $                   ERR_BNDS_NORM( NRHS, * ),
029:      $                   ERR_BNDS_COMP( NRHS, * ), RWORK( * )
030: *     ..
031: *
032: *     Purpose
033: *     =======
034: *
035: *     CGBRFSX improves the computed solution to a system of linear
036: *     equations and provides error bounds and backward error estimates
037: *     for the solution.  In addition to normwise error bound, the code
038: *     provides maximum componentwise error bound if possible.  See
039: *     comments for ERR_BNDS_N and ERR_BNDS_C for details of the error
040: *     bounds.
041: *
042: *     The original system of linear equations may have been equilibrated
043: *     before calling this routine, as described by arguments EQUED, R
044: *     and C below. In this case, the solution and error bounds returned
045: *     are for the original unequilibrated system.
046: *
047: *     Arguments
048: *     =========
049: *
050: *     Some optional parameters are bundled in the PARAMS array.  These
051: *     settings determine how refinement is performed, but often the
052: *     defaults are acceptable.  If the defaults are acceptable, users
053: *     can pass NPARAMS = 0 which prevents the source code from accessing
054: *     the PARAMS argument.
055: *
056: *     TRANS   (input) CHARACTER*1
057: *     Specifies the form of the system of equations:
058: *       = 'N':  A * X = B     (No transpose)
059: *       = 'T':  A**T * X = B  (Transpose)
060: *       = 'C':  A**H * X = B  (Conjugate transpose = Transpose)
061: *
062: *     EQUED   (input) CHARACTER*1
063: *     Specifies the form of equilibration that was done to A
064: *     before calling this routine. This is needed to compute
065: *     the solution and error bounds correctly.
066: *       = 'N':  No equilibration
067: *       = 'R':  Row equilibration, i.e., A has been premultiplied by
068: *               diag(R).
069: *       = 'C':  Column equilibration, i.e., A has been postmultiplied
070: *               by diag(C).
071: *       = 'B':  Both row and column equilibration, i.e., A has been
072: *               replaced by diag(R) * A * diag(C).
073: *               The right hand side B has been changed accordingly.
074: *
075: *     N       (input) INTEGER
076: *     The order of the matrix A.  N >= 0.
077: *
078: *     KL      (input) INTEGER
079: *     The number of subdiagonals within the band of A.  KL >= 0.
080: *
081: *     KU      (input) INTEGER
082: *     The number of superdiagonals within the band of A.  KU >= 0.
083: *
084: *     NRHS    (input) INTEGER
085: *     The number of right hand sides, i.e., the number of columns
086: *     of the matrices B and X.  NRHS >= 0.
087: *
088: *     AB      (input) DOUBLE PRECISION array, dimension (LDAB,N)
089: *     The original band matrix A, stored in rows 1 to KL+KU+1.
090: *     The j-th column of A is stored in the j-th column of the
091: *     array AB as follows:
092: *     AB(ku+1+i-j,j) = A(i,j) for max(1,j-ku)<=i<=min(n,j+kl).
093: *
094: *     LDAB    (input) INTEGER
095: *     The leading dimension of the array AB.  LDAB >= KL+KU+1.
096: *
097: *     AFB     (input) DOUBLE PRECISION array, dimension (LDAFB,N)
098: *     Details of the LU factorization of the band matrix A, as
099: *     computed by DGBTRF.  U is stored as an upper triangular band
100: *     matrix with KL+KU superdiagonals in rows 1 to KL+KU+1, and
101: *     the multipliers used during the factorization are stored in
102: *     rows KL+KU+2 to 2*KL+KU+1.
103: *
104: *     LDAFB   (input) INTEGER
105: *     The leading dimension of the array AFB.  LDAFB >= 2*KL*KU+1.
106: *
107: *     IPIV    (input) INTEGER array, dimension (N)
108: *     The pivot indices from SGETRF; for 1<=i<=N, row i of the
109: *     matrix was interchanged with row IPIV(i).
110: *
111: *     R       (input or output) REAL array, dimension (N)
112: *     The row scale factors for A.  If EQUED = 'R' or 'B', A is
113: *     multiplied on the left by diag(R); if EQUED = 'N' or 'C', R
114: *     is not accessed.  R is an input argument if FACT = 'F';
115: *     otherwise, R is an output argument.  If FACT = 'F' and
116: *     EQUED = 'R' or 'B', each element of R must be positive.
117: *     If R is output, each element of R is a power of the radix.
118: *     If R is input, each element of R should be a power of the radix
119: *     to ensure a reliable solution and error estimates. Scaling by
120: *     powers of the radix does not cause rounding errors unless the
121: *     result underflows or overflows. Rounding errors during scaling
122: *     lead to refining with a matrix that is not equivalent to the
123: *     input matrix, producing error estimates that may not be
124: *     reliable.
125: *
126: *     C       (input or output) REAL array, dimension (N)
127: *     The column scale factors for A.  If EQUED = 'C' or 'B', A is
128: *     multiplied on the right by diag(C); if EQUED = 'N' or 'R', C
129: *     is not accessed.  C is an input argument if FACT = 'F';
130: *     otherwise, C is an output argument.  If FACT = 'F' and
131: *     EQUED = 'C' or 'B', each element of C must be positive.
132: *     If C is output, each element of C is a power of the radix.
133: *     If C is input, each element of C should be a power of the radix
134: *     to ensure a reliable solution and error estimates. Scaling by
135: *     powers of the radix does not cause rounding errors unless the
136: *     result underflows or overflows. Rounding errors during scaling
137: *     lead to refining with a matrix that is not equivalent to the
138: *     input matrix, producing error estimates that may not be
139: *     reliable.
140: *
141: *     B       (input) REAL array, dimension (LDB,NRHS)
142: *     The right hand side matrix B.
143: *
144: *     LDB     (input) INTEGER
145: *     The leading dimension of the array B.  LDB >= max(1,N).
146: *
147: *     X       (input/output) REAL array, dimension (LDX,NRHS)
148: *     On entry, the solution matrix X, as computed by SGETRS.
149: *     On exit, the improved solution matrix X.
150: *
151: *     LDX     (input) INTEGER
152: *     The leading dimension of the array X.  LDX >= max(1,N).
153: *
154: *     RCOND   (output) REAL
155: *     Reciprocal scaled condition number.  This is an estimate of the
156: *     reciprocal Skeel condition number of the matrix A after
157: *     equilibration (if done).  If this is less than the machine
158: *     precision (in particular, if it is zero), the matrix is singular
159: *     to working precision.  Note that the error may still be small even
160: *     if this number is very small and the matrix appears ill-
161: *     conditioned.
162: *
163: *     BERR    (output) REAL array, dimension (NRHS)
164: *     Componentwise relative backward error.  This is the
165: *     componentwise relative backward error of each solution vector X(j)
166: *     (i.e., the smallest relative change in any element of A or B that
167: *     makes X(j) an exact solution).
168: *
169: *     N_ERR_BNDS (input) INTEGER
170: *     Number of error bounds to return for each right hand side
171: *     and each type (normwise or componentwise).  See ERR_BNDS_NORM and
172: *     ERR_BNDS_COMP below.
173: *
174: *     ERR_BNDS_NORM  (output) REAL array, dimension (NRHS, N_ERR_BNDS)
175: *     For each right-hand side, this array contains information about
176: *     various error bounds and condition numbers corresponding to the
177: *     normwise relative error, which is defined as follows:
178: *
179: *     Normwise relative error in the ith solution vector:
180: *             max_j (abs(XTRUE(j,i) - X(j,i)))
181: *            ------------------------------
182: *                  max_j abs(X(j,i))
183: *
184: *     The array is indexed by the type of error information as described
185: *     below. There currently are up to three pieces of information
186: *     returned.
187: *
188: *     The first index in ERR_BNDS_NORM(i,:) corresponds to the ith
189: *     right-hand side.
190: *
191: *     The second index in ERR_BNDS_NORM(:,err) contains the following
192: *     three fields:
193: *     err = 1 "Trust/don't trust" boolean. Trust the answer if the
194: *              reciprocal condition number is less than the threshold
195: *              sqrt(n) * slamch('Epsilon').
196: *
197: *     err = 2 "Guaranteed" error bound: The estimated forward error,
198: *              almost certainly within a factor of 10 of the true error
199: *              so long as the next entry is greater than the threshold
200: *              sqrt(n) * slamch('Epsilon'). This error bound should only
201: *              be trusted if the previous boolean is true.
202: *
203: *     err = 3  Reciprocal condition number: Estimated normwise
204: *              reciprocal condition number.  Compared with the threshold
205: *              sqrt(n) * slamch('Epsilon') to determine if the error
206: *              estimate is "guaranteed". These reciprocal condition
207: *              numbers are 1 / (norm(Z^{-1},inf) * norm(Z,inf)) for some
208: *              appropriately scaled matrix Z.
209: *              Let Z = S*A, where S scales each row by a power of the
210: *              radix so all absolute row sums of Z are approximately 1.
211: *
212: *     See Lapack Working Note 165 for further details and extra
213: *     cautions.
214: *
215: *     ERR_BNDS_COMP  (output) REAL array, dimension (NRHS, N_ERR_BNDS)
216: *     For each right-hand side, this array contains information about
217: *     various error bounds and condition numbers corresponding to the
218: *     componentwise relative error, which is defined as follows:
219: *
220: *     Componentwise relative error in the ith solution vector:
221: *                    abs(XTRUE(j,i) - X(j,i))
222: *             max_j ----------------------
223: *                         abs(X(j,i))
224: *
225: *     The array is indexed by the right-hand side i (on which the
226: *     componentwise relative error depends), and the type of error
227: *     information as described below. There currently are up to three
228: *     pieces of information returned for each right-hand side. If
229: *     componentwise accuracy is not requested (PARAMS(3) = 0.0), then
230: *     ERR_BNDS_COMP is not accessed.  If N_ERR_BNDS .LT. 3, then at most
231: *     the first (:,N_ERR_BNDS) entries are returned.
232: *
233: *     The first index in ERR_BNDS_COMP(i,:) corresponds to the ith
234: *     right-hand side.
235: *
236: *     The second index in ERR_BNDS_COMP(:,err) contains the following
237: *     three fields:
238: *     err = 1 "Trust/don't trust" boolean. Trust the answer if the
239: *              reciprocal condition number is less than the threshold
240: *              sqrt(n) * slamch('Epsilon').
241: *
242: *     err = 2 "Guaranteed" error bound: The estimated forward error,
243: *              almost certainly within a factor of 10 of the true error
244: *              so long as the next entry is greater than the threshold
245: *              sqrt(n) * slamch('Epsilon'). This error bound should only
246: *              be trusted if the previous boolean is true.
247: *
248: *     err = 3  Reciprocal condition number: Estimated componentwise
249: *              reciprocal condition number.  Compared with the threshold
250: *              sqrt(n) * slamch('Epsilon') to determine if the error
251: *              estimate is "guaranteed". These reciprocal condition
252: *              numbers are 1 / (norm(Z^{-1},inf) * norm(Z,inf)) for some
253: *              appropriately scaled matrix Z.
254: *              Let Z = S*(A*diag(x)), where x is the solution for the
255: *              current right-hand side and S scales each row of
256: *              A*diag(x) by a power of the radix so all absolute row
257: *              sums of Z are approximately 1.
258: *
259: *     See Lapack Working Note 165 for further details and extra
260: *     cautions.
261: *
262: *     NPARAMS (input) INTEGER
263: *     Specifies the number of parameters set in PARAMS.  If .LE. 0, the
264: *     PARAMS array is never referenced and default values are used.
265: *
266: *     PARAMS  (input / output) REAL array, dimension NPARAMS
267: *     Specifies algorithm parameters.  If an entry is .LT. 0.0, then
268: *     that entry will be filled with default value used for that
269: *     parameter.  Only positions up to NPARAMS are accessed; defaults
270: *     are used for higher-numbered parameters.
271: *
272: *       PARAMS(LA_LINRX_ITREF_I = 1) : Whether to perform iterative
273: *            refinement or not.
274: *         Default: 1.0
275: *            = 0.0 : No refinement is performed, and no error bounds are
276: *                    computed.
277: *            = 1.0 : Use the double-precision refinement algorithm,
278: *                    possibly with doubled-single computations if the
279: *                    compilation environment does not support DOUBLE
280: *                    PRECISION.
281: *              (other values are reserved for future use)
282: *
283: *       PARAMS(LA_LINRX_ITHRESH_I = 2) : Maximum number of residual
284: *            computations allowed for refinement.
285: *         Default: 10
286: *         Aggressive: Set to 100 to permit convergence using approximate
287: *                     factorizations or factorizations other than LU. If
288: *                     the factorization uses a technique other than
289: *                     Gaussian elimination, the guarantees in
290: *                     err_bnds_norm and err_bnds_comp may no longer be
291: *                     trustworthy.
292: *
293: *       PARAMS(LA_LINRX_CWISE_I = 3) : Flag determining if the code
294: *            will attempt to find a solution with small componentwise
295: *            relative error in the double-precision algorithm.  Positive
296: *            is true, 0.0 is false.
297: *         Default: 1.0 (attempt componentwise convergence)
298: *
299: *     WORK    (workspace) REAL array, dimension (4*N)
300: *
301: *     IWORK   (workspace) INTEGER array, dimension (N)
302: *
303: *     INFO    (output) INTEGER
304: *       = 0:  Successful exit. The solution to every right-hand side is
305: *         guaranteed.
306: *       < 0:  If INFO = -i, the i-th argument had an illegal value
307: *       > 0 and <= N:  U(INFO,INFO) is exactly zero.  The factorization
308: *         has been completed, but the factor U is exactly singular, so
309: *         the solution and error bounds could not be computed. RCOND = 0
310: *         is returned.
311: *       = N+J: The solution corresponding to the Jth right-hand side is
312: *         not guaranteed. The solutions corresponding to other right-
313: *         hand sides K with K > J may not be guaranteed as well, but
314: *         only the first such right-hand side is reported. If a small
315: *         componentwise error is not requested (PARAMS(3) = 0.0) then
316: *         the Jth right-hand side is the first with a normwise error
317: *         bound that is not guaranteed (the smallest J such
318: *         that ERR_BNDS_NORM(J,1) = 0.0). By default (PARAMS(3) = 1.0)
319: *         the Jth right-hand side is the first with either a normwise or
320: *         componentwise error bound that is not guaranteed (the smallest
321: *         J such that either ERR_BNDS_NORM(J,1) = 0.0 or
322: *         ERR_BNDS_COMP(J,1) = 0.0). See the definition of
323: *         ERR_BNDS_NORM(:,1) and ERR_BNDS_COMP(:,1). To get information
324: *         about all of the right-hand sides check ERR_BNDS_NORM or
325: *         ERR_BNDS_COMP.
326: *
327: *     ==================================================================
328: *
329: *     .. Parameters ..
330:       REAL               ZERO, ONE
331:       PARAMETER          ( ZERO = 0.0E+0, ONE = 1.0E+0 )
332:       REAL               ITREF_DEFAULT, ITHRESH_DEFAULT,
333:      $                   COMPONENTWISE_DEFAULT
334:       REAL               RTHRESH_DEFAULT, DZTHRESH_DEFAULT
335:       PARAMETER          ( ITREF_DEFAULT = 1.0 )
336:       PARAMETER          ( ITHRESH_DEFAULT = 10.0 )
337:       PARAMETER          ( COMPONENTWISE_DEFAULT = 1.0 )
338:       PARAMETER          ( RTHRESH_DEFAULT = 0.5 )
339:       PARAMETER          ( DZTHRESH_DEFAULT = 0.25 )
340:       INTEGER            LA_LINRX_ITREF_I, LA_LINRX_ITHRESH_I,
341:      $                   LA_LINRX_CWISE_I
342:       PARAMETER          ( LA_LINRX_ITREF_I = 1,
343:      $                   LA_LINRX_ITHRESH_I = 2 )
344:       PARAMETER          ( LA_LINRX_CWISE_I = 3 )
345:       INTEGER            LA_LINRX_TRUST_I, LA_LINRX_ERR_I,
346:      $                   LA_LINRX_RCOND_I
347:       PARAMETER          ( LA_LINRX_TRUST_I = 1, LA_LINRX_ERR_I = 2 )
348:       PARAMETER          ( LA_LINRX_RCOND_I = 3 )
349:       INTEGER            LA_LINRX_MAX_N_ERRS
350:       PARAMETER          ( LA_LINRX_MAX_N_ERRS = 3 )
351: *     ..
352: *     .. Local Scalars ..
353:       CHARACTER(1)       NORM
354:       LOGICAL            ROWEQU, COLEQU, NOTRAN, IGNORE_CWISE
355:       INTEGER            J, TRANS_TYPE, PREC_TYPE, REF_TYPE, N_NORMS,
356:      $                   ITHRESH
357:       REAL               ANORM, RCOND_TMP, ILLRCOND_THRESH, ERR_LBND,
358:      $                   CWISE_WRONG, RTHRESH, UNSTABLE_THRESH
359: *     ..
360: *     .. External Subroutines ..
361:       EXTERNAL           XERBLA, CGBCON, CLA_GBRFSX_EXTENDED
362: *     ..
363: *     .. Intrinsic Functions ..
364:       INTRINSIC          MAX, SQRT
365: *     ..
366: *     .. External Functions ..
367:       EXTERNAL           LSAME, BLAS_FPINFO_X, ILATRANS, ILAPREC
368:       EXTERNAL           SLAMCH, CLANGB, CLA_GBRCOND_X, CLA_GBRCOND_C
369:       REAL               SLAMCH, CLANGB, CLA_GBRCOND_X, CLA_GBRCOND_C
370:       LOGICAL            LSAME
371:       INTEGER            BLAS_FPINFO_X
372:       INTEGER            ILATRANS, ILAPREC
373: *     ..
374: *     .. Executable Statements ..
375: *
376: *     Check the input parameters.
377: *
378:       INFO = 0
379:       TRANS_TYPE = ILATRANS( TRANS )
380:       REF_TYPE = INT( ITREF_DEFAULT )
381:       IF ( NPARAMS .GE. LA_LINRX_ITREF_I ) THEN
382:          IF ( PARAMS( LA_LINRX_ITREF_I ) .LT. 0.0 ) THEN
383:             PARAMS( LA_LINRX_ITREF_I ) = ITREF_DEFAULT
384:          ELSE
385:             REF_TYPE = PARAMS( LA_LINRX_ITREF_I )
386:          END IF
387:       END IF
388: *
389: *     Set default parameters.
390: *
391:       ILLRCOND_THRESH = REAL( N ) * SLAMCH( 'Epsilon' )
392:       ITHRESH = INT( ITHRESH_DEFAULT )
393:       RTHRESH = RTHRESH_DEFAULT
394:       UNSTABLE_THRESH = DZTHRESH_DEFAULT
395:       IGNORE_CWISE = COMPONENTWISE_DEFAULT .EQ. 0.0
396: *
397:       IF ( NPARAMS.GE.LA_LINRX_ITHRESH_I ) THEN
398:          IF ( PARAMS( LA_LINRX_ITHRESH_I ).LT.0.0 ) THEN
399:             PARAMS( LA_LINRX_ITHRESH_I ) = ITHRESH
400:          ELSE
401:             ITHRESH = INT( PARAMS( LA_LINRX_ITHRESH_I ) )
402:          END IF
403:       END IF
404:       IF ( NPARAMS.GE.LA_LINRX_CWISE_I ) THEN
405:          IF ( PARAMS( LA_LINRX_CWISE_I ).LT.0.0 ) THEN
406:             IF ( IGNORE_CWISE ) THEN
407:                PARAMS( LA_LINRX_CWISE_I ) = 0.0
408:             ELSE
409:                PARAMS( LA_LINRX_CWISE_I ) = 1.0
410:             END IF
411:          ELSE
412:             IGNORE_CWISE = PARAMS( LA_LINRX_CWISE_I ) .EQ. 0.0
413:          END IF
414:       END IF
415:       IF ( REF_TYPE .EQ. 0 .OR. N_ERR_BNDS .EQ. 0 ) THEN
416:          N_NORMS = 0
417:       ELSE IF ( IGNORE_CWISE ) THEN
418:          N_NORMS = 1
419:       ELSE
420:          N_NORMS = 2
421:       END IF
422: *
423:       NOTRAN = LSAME( TRANS, 'N' )
424:       ROWEQU = LSAME( EQUED, 'R' ) .OR. LSAME( EQUED, 'B' )
425:       COLEQU = LSAME( EQUED, 'C' ) .OR. LSAME( EQUED, 'B' )
426: *
427: *     Test input parameters.
428: *
429:       IF( TRANS_TYPE.EQ.-1 ) THEN
430:         INFO = -1
431:       ELSE IF( .NOT.ROWEQU .AND. .NOT.COLEQU .AND.
432:      $         .NOT.LSAME( EQUED, 'N' ) ) THEN
433:         INFO = -2
434:       ELSE IF( N.LT.0 ) THEN
435:         INFO = -3
436:       ELSE IF( KL.LT.0 ) THEN
437:         INFO = -4
438:       ELSE IF( KU.LT.0 ) THEN
439:         INFO = -5
440:       ELSE IF( NRHS.LT.0 ) THEN
441:         INFO = -6
442:       ELSE IF( LDAB.LT.KL+KU+1 ) THEN
443:         INFO = -8
444:       ELSE IF( LDAFB.LT.2*KL+KU+1 ) THEN
445:         INFO = -10
446:       ELSE IF( LDB.LT.MAX( 1, N ) ) THEN
447:         INFO = -13
448:       ELSE IF( LDX.LT.MAX( 1, N ) ) THEN
449:         INFO = -15
450:       END IF
451:       IF( INFO.NE.0 ) THEN
452:         CALL XERBLA( 'CGBRFSX', -INFO )
453:         RETURN
454:       END IF
455: *
456: *     Quick return if possible.
457: *
458:       IF( N.EQ.0 .OR. NRHS.EQ.0 ) THEN
459:          RCOND = 1.0
460:          DO J = 1, NRHS
461:             BERR( J ) = 0.0
462:             IF ( N_ERR_BNDS .GE. 1 ) THEN
463:                ERR_BNDS_NORM( J, LA_LINRX_TRUST_I ) = 1.0
464:                ERR_BNDS_COMP( J, LA_LINRX_TRUST_I ) = 1.0
465:             ELSE IF ( N_ERR_BNDS .GE. 2 ) THEN
466:                ERR_BNDS_NORM( J, LA_LINRX_ERR_I ) = 0.0
467:                ERR_BNDS_COMP( J, LA_LINRX_ERR_I ) = 0.0
468:             ELSE IF ( N_ERR_BNDS .GE. 3 ) THEN
469:                ERR_BNDS_NORM( J, LA_LINRX_RCOND_I ) = 1.0
470:                ERR_BNDS_COMP( J, LA_LINRX_RCOND_I ) = 1.0
471:             END IF
472:          END DO
473:          RETURN
474:       END IF
475: *
476: *     Default to failure.
477: *
478:       RCOND = 0.0
479:       DO J = 1, NRHS
480:          BERR( J ) = 1.0
481:          IF ( N_ERR_BNDS .GE. 1 ) THEN
482:             ERR_BNDS_NORM( J, LA_LINRX_TRUST_I ) = 1.0
483:             ERR_BNDS_COMP( J, LA_LINRX_TRUST_I ) = 1.0
484:          ELSE IF ( N_ERR_BNDS .GE. 2 ) THEN
485:             ERR_BNDS_NORM( J, LA_LINRX_ERR_I ) = 1.0
486:             ERR_BNDS_COMP( J, LA_LINRX_ERR_I ) = 1.0
487:          ELSE IF ( N_ERR_BNDS .GE. 3 ) THEN
488:             ERR_BNDS_NORM( J, LA_LINRX_RCOND_I ) = 0.0
489:             ERR_BNDS_COMP( J, LA_LINRX_RCOND_I ) = 0.0
490:          END IF
491:       END DO
492: *
493: *     Compute the norm of A and the reciprocal of the condition
494: *     number of A.
495: *
496:       IF( NOTRAN ) THEN
497:          NORM = 'I'
498:       ELSE
499:          NORM = '1'
500:       END IF
501:       ANORM = CLANGB( NORM, N, KL, KU, AB, LDAB, WORK )
502:       CALL CGBCON( NORM, N, KL, KU, AFB, LDAFB, IPIV, ANORM, RCOND,
503:      $     WORK, RWORK, INFO )
504: *
505: *     Perform refinement on each right-hand side
506: *
507:       IF ( REF_TYPE .NE. 0 ) THEN
508: 
509:          PREC_TYPE = ILAPREC( 'D' )
510: 
511:          IF ( NOTRAN ) THEN
512:             CALL CLA_GBRFSX_EXTENDED( PREC_TYPE, TRANS_TYPE,  N, KL, KU,
513:      $           NRHS, AB, LDAB, AFB, LDAFB, IPIV, COLEQU, C, B,
514:      $           LDB, X, LDX, BERR, N_NORMS, ERR_BNDS_NORM,
515:      $           ERR_BNDS_COMP, WORK(N+1), RWORK, WORK(1), RWORK, RCOND,
516:      $           ITHRESH, RTHRESH, UNSTABLE_THRESH, IGNORE_CWISE,
517:      $           INFO )
518:          ELSE
519:             CALL CLA_GBRFSX_EXTENDED( PREC_TYPE, TRANS_TYPE,  N, KL, KU,
520:      $           NRHS, AB, LDAB, AFB, LDAFB, IPIV, ROWEQU, C, B,
521:      $           LDB, X, LDX, BERR, N_NORMS, ERR_BNDS_NORM,
522:      $           ERR_BNDS_COMP, WORK(N+1), RWORK, WORK(1), RWORK, RCOND,
523:      $           ITHRESH, RTHRESH, UNSTABLE_THRESH, IGNORE_CWISE,
524:      $           INFO )
525:          END IF
526:       END IF
527: 
528:       ERR_LBND = MAX( 10.0, SQRT( REAL( N ) ) ) * SLAMCH( 'Epsilon' )
529:       IF (N_ERR_BNDS .GE. 1 .AND. N_NORMS .GE. 1) THEN
530: *
531: *     Compute scaled normwise condition number cond(A*C).
532: *
533:          IF ( COLEQU .AND. NOTRAN ) THEN
534:             RCOND_TMP = CLA_GBRCOND_C( TRANS, N, KL, KU, AB, LDAB, AFB,
535:      $           LDAFB, IPIV, C, .TRUE., INFO, WORK, RWORK )
536:          ELSE IF ( ROWEQU .AND. .NOT. NOTRAN ) THEN
537:             RCOND_TMP = CLA_GBRCOND_C( TRANS, N, KL, KU, AB, LDAB, AFB,
538:      $           LDAFB, IPIV, R, .TRUE., INFO, WORK, RWORK )
539:          ELSE
540:             RCOND_TMP = CLA_GBRCOND_C( TRANS, N, KL, KU, AB, LDAB, AFB,
541:      $           LDAFB, IPIV, C, .FALSE., INFO, WORK, RWORK )
542:          END IF
543:          DO J = 1, NRHS
544: *
545: *     Cap the error at 1.0.
546: *
547:             IF ( N_ERR_BNDS .GE. LA_LINRX_ERR_I
548:      $           .AND. ERR_BNDS_NORM( J, LA_LINRX_ERR_I ) .GT. 1.0)
549:      $           ERR_BNDS_NORM( J, LA_LINRX_ERR_I ) = 1.0
550: *
551: *     Threshold the error (see LAWN).
552: *
553:             IF ( RCOND_TMP .LT. ILLRCOND_THRESH ) THEN
554:                ERR_BNDS_NORM( J, LA_LINRX_ERR_I ) = 1.0
555:                ERR_BNDS_NORM( J, LA_LINRX_TRUST_I ) = 0.0
556:                IF ( INFO .LE. N ) INFO = N + J
557:             ELSE IF ( ERR_BNDS_NORM( J, LA_LINRX_ERR_I ) .LT. ERR_LBND )
558:      $              THEN
559:                ERR_BNDS_NORM( J, LA_LINRX_ERR_I ) = ERR_LBND
560:                ERR_BNDS_NORM( J, LA_LINRX_TRUST_I ) = 1.0
561:             END IF
562: *
563: *     Save the condition number.
564: *
565:             IF ( N_ERR_BNDS .GE. LA_LINRX_RCOND_I ) THEN
566:                ERR_BNDS_NORM( J, LA_LINRX_RCOND_I ) = RCOND_TMP
567:             END IF
568: 
569:          END DO
570:       END IF
571: 
572:       IF (N_ERR_BNDS .GE. 1 .AND. N_NORMS .GE. 2) THEN
573: *
574: *     Compute componentwise condition number cond(A*diag(Y(:,J))) for
575: *     each right-hand side using the current solution as an estimate of
576: *     the true solution.  If the componentwise error estimate is too
577: *     large, then the solution is a lousy estimate of truth and the
578: *     estimated RCOND may be too optimistic.  To avoid misleading users,
579: *     the inverse condition number is set to 0.0 when the estimated
580: *     cwise error is at least CWISE_WRONG.
581: *
582:          CWISE_WRONG = SQRT( SLAMCH( 'Epsilon' ) )
583:          DO J = 1, NRHS
584:             IF (ERR_BNDS_COMP( J, LA_LINRX_ERR_I ) .LT. CWISE_WRONG )
585:      $     THEN
586:                RCOND_TMP = CLA_GBRCOND_X( TRANS, N, KL, KU, AB, LDAB,
587:      $              AFB, LDAFB, IPIV, X( 1, J ), INFO, WORK, RWORK )
588:             ELSE
589:                RCOND_TMP = 0.0
590:             END IF
591: *
592: *     Cap the error at 1.0.
593: *
594:             IF ( N_ERR_BNDS .GE. LA_LINRX_ERR_I
595:      $           .AND. ERR_BNDS_COMP( J, LA_LINRX_ERR_I ) .GT. 1.0 )
596:      $           ERR_BNDS_COMP( J, LA_LINRX_ERR_I ) = 1.0
597: *
598: *     Threshold the error (see LAWN).
599: *
600:             IF ( RCOND_TMP .LT. ILLRCOND_THRESH ) THEN
601:                ERR_BNDS_COMP( J, LA_LINRX_ERR_I ) = 1.0
602:                ERR_BNDS_COMP( J, LA_LINRX_TRUST_I ) = 0.0
603:                IF ( PARAMS( LA_LINRX_CWISE_I ) .EQ. 1.0
604:      $              .AND. INFO.LT.N + J ) INFO = N + J
605:             ELSE IF ( ERR_BNDS_COMP( J, LA_LINRX_ERR_I )
606:      $              .LT. ERR_LBND ) THEN
607:                ERR_BNDS_COMP( J, LA_LINRX_ERR_I ) = ERR_LBND
608:                ERR_BNDS_COMP( J, LA_LINRX_TRUST_I ) = 1.0
609:             END IF
610: *
611: *     Save the condition number.
612: *
613:             IF ( N_ERR_BNDS .GE. LA_LINRX_RCOND_I ) THEN
614:                ERR_BNDS_COMP( J, LA_LINRX_RCOND_I ) = RCOND_TMP
615:             END IF
616: 
617:          END DO
618:       END IF
619: *
620:       RETURN
621: *
622: *     End of CGBRFSX
623: *
624:       END
625: