001:       SUBROUTINE SGBRFSX( 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, IWORK,
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( * ), IWORK( * )
025:       REAL               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, * )
030: *     ..
031: *
032: *     Purpose
033: *     =======
034: *
035: *     SGBRFSX 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
355:       INTEGER            J, TRANS_TYPE, PREC_TYPE, REF_TYPE
356:       INTEGER            N_NORMS
357:       REAL               ANORM, RCOND_TMP
358:       REAL               ILLRCOND_THRESH, ERR_LBND, CWISE_WRONG
359:       LOGICAL            IGNORE_CWISE
360:       INTEGER            ITHRESH
361:       REAL               RTHRESH, UNSTABLE_THRESH
362: *     ..
363: *     .. External Subroutines ..
364:       EXTERNAL           XERBLA, SGBCON
365:       EXTERNAL           SLA_GBRFSX_EXTENDED
366: *     ..
367: *     .. Intrinsic Functions ..
368:       INTRINSIC          MAX, SQRT
369: *     ..
370: *     .. External Functions ..
371:       EXTERNAL           LSAME, BLAS_FPINFO_X, ILATRANS, ILAPREC
372:       EXTERNAL           SLAMCH, SLANGB, SLA_GBRCOND
373:       REAL               SLAMCH, SLANGB, SLA_GBRCOND
374:       LOGICAL            LSAME
375:       INTEGER            BLAS_FPINFO_X
376:       INTEGER            ILATRANS, ILAPREC
377: *     ..
378: *     .. Executable Statements ..
379: *
380: *     Check the input parameters.
381: *
382:       INFO = 0
383:       TRANS_TYPE = ILATRANS( TRANS )
384:       REF_TYPE = INT( ITREF_DEFAULT )
385:       IF ( NPARAMS .GE. LA_LINRX_ITREF_I ) THEN
386:          IF ( PARAMS( LA_LINRX_ITREF_I ) .LT. 0.0 ) THEN
387:             PARAMS( LA_LINRX_ITREF_I ) = ITREF_DEFAULT
388:          ELSE
389:             REF_TYPE = PARAMS( LA_LINRX_ITREF_I )
390:          END IF
391:       END IF
392: *
393: *     Set default parameters.
394: *
395:       ILLRCOND_THRESH = REAL( N ) * SLAMCH( 'Epsilon' )
396:       ITHRESH = INT( ITHRESH_DEFAULT )
397:       RTHRESH = RTHRESH_DEFAULT
398:       UNSTABLE_THRESH = DZTHRESH_DEFAULT
399:       IGNORE_CWISE = COMPONENTWISE_DEFAULT .EQ. 0.0
400: *
401:       IF ( NPARAMS.GE.LA_LINRX_ITHRESH_I ) THEN
402:          IF ( PARAMS( LA_LINRX_ITHRESH_I ).LT.0.0 ) THEN
403:             PARAMS( LA_LINRX_ITHRESH_I ) = ITHRESH
404:          ELSE
405:             ITHRESH = INT( PARAMS( LA_LINRX_ITHRESH_I ) )
406:          END IF
407:       END IF
408:       IF ( NPARAMS.GE.LA_LINRX_CWISE_I ) THEN
409:          IF ( PARAMS( LA_LINRX_CWISE_I ).LT.0.0 ) THEN
410:             IF ( IGNORE_CWISE ) THEN
411:                PARAMS( LA_LINRX_CWISE_I ) = 0.0
412:             ELSE
413:                PARAMS( LA_LINRX_CWISE_I ) = 1.0
414:             END IF
415:          ELSE
416:             IGNORE_CWISE = PARAMS( LA_LINRX_CWISE_I ) .EQ. 0.0
417:          END IF
418:       END IF
419:       IF ( REF_TYPE .EQ. 0 .OR. N_ERR_BNDS .EQ. 0 ) THEN
420:          N_NORMS = 0
421:       ELSE IF ( IGNORE_CWISE ) THEN
422:          N_NORMS = 1
423:       ELSE
424:          N_NORMS = 2
425:       END IF
426: *
427:       NOTRAN = LSAME( TRANS, 'N' )
428:       ROWEQU = LSAME( EQUED, 'R' ) .OR. LSAME( EQUED, 'B' )
429:       COLEQU = LSAME( EQUED, 'C' ) .OR. LSAME( EQUED, 'B' )
430: *
431: *     Test input parameters.
432: *
433:       IF( TRANS_TYPE.EQ.-1 ) THEN
434:         INFO = -1
435:       ELSE IF( .NOT.ROWEQU .AND. .NOT.COLEQU .AND.
436:      $         .NOT.LSAME( EQUED, 'N' ) ) THEN
437:         INFO = -2
438:       ELSE IF( N.LT.0 ) THEN
439:         INFO = -3
440:       ELSE IF( KL.LT.0 ) THEN
441:         INFO = -4
442:       ELSE IF( KU.LT.0 ) THEN
443:         INFO = -5
444:       ELSE IF( NRHS.LT.0 ) THEN
445:         INFO = -6
446:       ELSE IF( LDAB.LT.KL+KU+1 ) THEN
447:         INFO = -8
448:       ELSE IF( LDAFB.LT.2*KL+KU+1 ) THEN
449:         INFO = -10
450:       ELSE IF( LDB.LT.MAX( 1, N ) ) THEN
451:         INFO = -13
452:       ELSE IF( LDX.LT.MAX( 1, N ) ) THEN
453:         INFO = -15
454:       END IF
455:       IF( INFO.NE.0 ) THEN
456:         CALL XERBLA( 'SGBRFSX', -INFO )
457:         RETURN
458:       END IF
459: *
460: *     Quick return if possible.
461: *
462:       IF( N.EQ.0 .OR. NRHS.EQ.0 ) THEN
463:          RCOND = 1.0
464:          DO J = 1, NRHS
465:             BERR( J ) = 0.0
466:             IF ( N_ERR_BNDS .GE. 1 ) THEN
467:                ERR_BNDS_NORM( J, LA_LINRX_TRUST_I ) = 1.0
468:                ERR_BNDS_COMP( J, LA_LINRX_TRUST_I ) = 1.0
469:             ELSE IF ( N_ERR_BNDS .GE. 2 ) THEN
470:                ERR_BNDS_NORM( J, LA_LINRX_ERR_I ) = 0.0
471:                ERR_BNDS_COMP( J, LA_LINRX_ERR_I ) = 0.0
472:             ELSE IF ( N_ERR_BNDS .GE. 3 ) THEN
473:                ERR_BNDS_NORM( J, LA_LINRX_RCOND_I ) = 1.0
474:                ERR_BNDS_COMP( J, LA_LINRX_RCOND_I ) = 1.0
475:             END IF
476:          END DO
477:          RETURN
478:       END IF
479: *
480: *     Default to failure.
481: *
482:       RCOND = 0.0
483:       DO J = 1, NRHS
484:          BERR( J ) = 1.0
485:          IF ( N_ERR_BNDS .GE. 1 ) THEN
486:             ERR_BNDS_NORM( J, LA_LINRX_TRUST_I ) = 1.0
487:             ERR_BNDS_COMP( J, LA_LINRX_TRUST_I ) = 1.0
488:          ELSE IF ( N_ERR_BNDS .GE. 2 ) THEN
489:             ERR_BNDS_NORM( J, LA_LINRX_ERR_I ) = 1.0
490:             ERR_BNDS_COMP( J, LA_LINRX_ERR_I ) = 1.0
491:          ELSE IF ( N_ERR_BNDS .GE. 3 ) THEN
492:             ERR_BNDS_NORM( J, LA_LINRX_RCOND_I ) = 0.0
493:             ERR_BNDS_COMP( J, LA_LINRX_RCOND_I ) = 0.0
494:          END IF
495:       END DO
496: *
497: *     Compute the norm of A and the reciprocal of the condition
498: *     number of A.
499: *
500:       IF( NOTRAN ) THEN
501:          NORM = 'I'
502:       ELSE
503:          NORM = '1'
504:       END IF
505:       ANORM = SLANGB( NORM, N, KL, KU, AB, LDAB, WORK )
506:       CALL SGBCON( NORM, N, KL, KU, AFB, LDAFB, IPIV, ANORM, RCOND,
507:      $     WORK, IWORK, INFO )
508: *
509: *     Perform refinement on each right-hand side
510: *
511:       IF (REF_TYPE .NE. 0) THEN
512: 
513:          PREC_TYPE = ILAPREC( 'D' )
514: 
515:          IF ( NOTRAN ) THEN
516:             CALL SLA_GBRFSX_EXTENDED( PREC_TYPE, TRANS_TYPE,  N, KL, KU,
517:      $           NRHS, AB, LDAB, AFB, LDAFB, IPIV, COLEQU, C, B,
518:      $           LDB, X, LDX, BERR, N_NORMS, ERR_BNDS_NORM,
519:      $           ERR_BNDS_COMP, WORK( N+1 ), WORK( 1 ), WORK( 2*N+1 ),
520:      $           WORK( 1 ), RCOND, ITHRESH, RTHRESH, UNSTABLE_THRESH,
521:      $           IGNORE_CWISE, INFO )
522:          ELSE
523:             CALL SLA_GBRFSX_EXTENDED( PREC_TYPE, TRANS_TYPE,  N, KL, KU,
524:      $           NRHS, AB, LDAB, AFB, LDAFB, IPIV, ROWEQU, C, B,
525:      $           LDB, X, LDX, BERR, N_NORMS, ERR_BNDS_NORM,
526:      $           ERR_BNDS_COMP, WORK( N+1 ), WORK( 1 ), WORK( 2*N+1 ),
527:      $           WORK( 1 ), RCOND, ITHRESH, RTHRESH, UNSTABLE_THRESH,
528:      $           IGNORE_CWISE, INFO )
529:          END IF
530:       END IF
531: 
532:       ERR_LBND = MAX( 10.0, SQRT( REAL( N ) ) ) * SLAMCH( 'Epsilon' )
533:       IF ( N_ERR_BNDS .GE. 1 .AND. N_NORMS .GE. 1 ) THEN
534: *
535: *     Compute scaled normwise condition number cond(A*C).
536: *
537:          IF ( COLEQU .AND. NOTRAN ) THEN
538:             RCOND_TMP = SLA_GBRCOND( TRANS, N, KL, KU, AB, LDAB, AFB,
539:      $           LDAFB, IPIV, -1, C, INFO, WORK, IWORK )
540:          ELSE IF ( ROWEQU .AND. .NOT. NOTRAN ) THEN
541:             RCOND_TMP = SLA_GBRCOND( TRANS, N, KL, KU, AB, LDAB, AFB,
542:      $           LDAFB, IPIV, -1, R, INFO, WORK, IWORK )
543:          ELSE
544:             RCOND_TMP = SLA_GBRCOND( TRANS, N, KL, KU, AB, LDAB, AFB,
545:      $           LDAFB, IPIV, 0, R, INFO, WORK, IWORK )
546:          END IF
547:          DO J = 1, NRHS
548: *
549: *     Cap the error at 1.0.
550: *
551:             IF ( N_ERR_BNDS .GE. LA_LINRX_ERR_I
552:      $           .AND. ERR_BNDS_NORM( J, LA_LINRX_ERR_I ) .GT. 1.0 )
553:      $           ERR_BNDS_NORM( J, LA_LINRX_ERR_I ) = 1.0
554: *
555: *     Threshold the error (see LAWN).
556: *
557:             IF ( RCOND_TMP .LT. ILLRCOND_THRESH ) THEN
558:                ERR_BNDS_NORM( J, LA_LINRX_ERR_I ) = 1.0
559:                ERR_BNDS_NORM( J, LA_LINRX_TRUST_I ) = 0.0
560:                IF ( INFO .LE. N ) INFO = N + J
561:             ELSE IF ( ERR_BNDS_NORM( J, LA_LINRX_ERR_I ) .LT. ERR_LBND )
562:      $     THEN
563:                ERR_BNDS_NORM( J, LA_LINRX_ERR_I ) = ERR_LBND
564:                ERR_BNDS_NORM( J, LA_LINRX_TRUST_I ) = 1.0
565:             END IF
566: *
567: *     Save the condition number.
568: *
569:             IF ( N_ERR_BNDS .GE. LA_LINRX_RCOND_I ) THEN
570:                ERR_BNDS_NORM( J, LA_LINRX_RCOND_I ) = RCOND_TMP
571:             END IF
572: 
573:          END DO
574:       END IF
575: 
576:       IF (N_ERR_BNDS .GE. 1 .AND. N_NORMS .GE. 2) THEN
577: *
578: *     Compute componentwise condition number cond(A*diag(Y(:,J))) for
579: *     each right-hand side using the current solution as an estimate of
580: *     the true solution.  If the componentwise error estimate is too
581: *     large, then the solution is a lousy estimate of truth and the
582: *     estimated RCOND may be too optimistic.  To avoid misleading users,
583: *     the inverse condition number is set to 0.0 when the estimated
584: *     cwise error is at least CWISE_WRONG.
585: *
586:          CWISE_WRONG = SQRT( SLAMCH( 'Epsilon' ) )
587:          DO J = 1, NRHS
588:             IF ( ERR_BNDS_COMP( J, LA_LINRX_ERR_I ) .LT. CWISE_WRONG )
589:      $     THEN
590:                RCOND_TMP = SLA_GBRCOND( TRANS, N, KL, KU, AB, LDAB, AFB,
591:      $              LDAFB, IPIV, 1, X( 1, J ), INFO, WORK, IWORK )
592:             ELSE
593:                RCOND_TMP = 0.0
594:             END IF
595: *
596: *     Cap the error at 1.0.
597: *
598:             IF ( N_ERR_BNDS .GE. LA_LINRX_ERR_I
599:      $           .AND. ERR_BNDS_COMP( J, LA_LINRX_ERR_I ) .GT. 1.0 )
600:      $           ERR_BNDS_COMP( J, LA_LINRX_ERR_I ) = 1.0
601: *
602: *     Threshold the error (see LAWN).
603: *
604:             IF ( RCOND_TMP .LT. ILLRCOND_THRESH ) THEN
605:                ERR_BNDS_COMP( J, LA_LINRX_ERR_I ) = 1.0
606:                ERR_BNDS_COMP( J, LA_LINRX_TRUST_I ) = 0.0
607:                IF ( PARAMS( LA_LINRX_CWISE_I ) .EQ. 1.0
608:      $              .AND. INFO.LT.N + J ) INFO = N + J
609:             ELSE IF ( ERR_BNDS_COMP( J, LA_LINRX_ERR_I )
610:      $              .LT. ERR_LBND ) THEN
611:                ERR_BNDS_COMP( J, LA_LINRX_ERR_I ) = ERR_LBND
612:                ERR_BNDS_COMP( J, LA_LINRX_TRUST_I ) = 1.0
613:             END IF
614: *
615: *     Save the condition number.
616: *
617:             IF ( N_ERR_BNDS .GE. LA_LINRX_RCOND_I ) THEN
618:                ERR_BNDS_COMP( J, LA_LINRX_RCOND_I ) = RCOND_TMP
619:             END IF
620: 
621:          END DO
622:       END IF
623: *
624:       RETURN
625: *
626: *     End of SGBRFSX
627: *
628:       END
629: