001:       SUBROUTINE ZGBRFSX( 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.1)                                 --
008: *     -- Contributed by James Demmel, Deaglan Halligan, Yozo Hida and --
009: *     -- Jason Riedy of Univ. of California Berkeley.                 --
010: *     -- April 2009                                                   --
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:       DOUBLE PRECISION   RCOND
022: *     ..
023: *     .. Array Arguments ..
024:       INTEGER            IPIV( * )
025:       COMPLEX*16         AB( LDAB, * ), AFB( LDAFB, * ), B( LDB, * ),
026:      $                   X( LDX , * ),WORK( * )
027:       DOUBLE PRECISION   R( * ), C( * ), PARAMS( * ), BERR( * ),
028:      $                   ERR_BNDS_NORM( NRHS, * ),
029:      $                   ERR_BNDS_COMP( NRHS, * ), RWORK( * )
030: *     ..
031: *
032: *     Purpose
033: *     =======
034: *
035: *     ZGBRFSX 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_NORM and ERR_BNDS_COMP for details of the
040: *     error 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 DGETRF; for 1<=i<=N, row i of the
109: *     matrix was interchanged with row IPIV(i).
110: *
111: *     R       (input or output) DOUBLE PRECISION 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) DOUBLE PRECISION 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) DOUBLE PRECISION 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) DOUBLE PRECISION array, dimension (LDX,NRHS)
148: *     On entry, the solution matrix X, as computed by DGETRS.
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) DOUBLE PRECISION
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) DOUBLE PRECISION 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) DOUBLE PRECISION 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) * dlamch('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) * dlamch('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) * dlamch('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) DOUBLE PRECISION 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) * dlamch('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) * dlamch('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) * dlamch('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) DOUBLE PRECISION 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.0D+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) COMPLEX*16 array, dimension (2*N)
300: *
301: *     RWORK   (workspace) DOUBLE PRECISION array, dimension (2*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:       DOUBLE PRECISION   ZERO, ONE
331:       PARAMETER          ( ZERO = 0.0D+0, ONE = 1.0D+0 )
332:       DOUBLE PRECISION   ITREF_DEFAULT, ITHRESH_DEFAULT
333:       DOUBLE PRECISION   COMPONENTWISE_DEFAULT, RTHRESH_DEFAULT
334:       DOUBLE PRECISION   DZTHRESH_DEFAULT
335:       PARAMETER          ( ITREF_DEFAULT = 1.0D+0 )
336:       PARAMETER          ( ITHRESH_DEFAULT = 10.0D+0 )
337:       PARAMETER          ( COMPONENTWISE_DEFAULT = 1.0D+0 )
338:       PARAMETER          ( RTHRESH_DEFAULT = 0.5D+0 )
339:       PARAMETER          ( DZTHRESH_DEFAULT = 0.25D+0 )
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: *     ..
350: *     .. Local Scalars ..
351:       CHARACTER(1)       NORM
352:       LOGICAL            ROWEQU, COLEQU, NOTRAN, IGNORE_CWISE
353:       INTEGER            J, TRANS_TYPE, PREC_TYPE, REF_TYPE, N_NORMS,
354:      $                   ITHRESH
355:       DOUBLE PRECISION   ANORM, RCOND_TMP, ILLRCOND_THRESH, ERR_LBND,
356:      $                   CWISE_WRONG, RTHRESH, UNSTABLE_THRESH
357: *     ..
358: *     .. External Subroutines ..
359:       EXTERNAL           XERBLA, ZGBCON, ZLA_GBRFSX_EXTENDED
360: *     ..
361: *     .. Intrinsic Functions ..
362:       INTRINSIC          MAX, SQRT, TRANSFER
363: *     ..
364: *     .. External Functions ..
365:       EXTERNAL           LSAME, BLAS_FPINFO_X, ILATRANS, ILAPREC
366:       EXTERNAL           DLAMCH, ZLANGB, ZLA_GBRCOND_X, ZLA_GBRCOND_C
367:       DOUBLE PRECISION   DLAMCH, ZLANGB, ZLA_GBRCOND_X, ZLA_GBRCOND_C
368:       LOGICAL            LSAME
369:       INTEGER            BLAS_FPINFO_X
370:       INTEGER            ILATRANS, ILAPREC
371: *     ..
372: *     .. Executable Statements ..
373: *
374: *     Check the input parameters.
375: *
376:       INFO = 0
377:       TRANS_TYPE = ILATRANS( TRANS )
378:       REF_TYPE = INT( ITREF_DEFAULT )
379:       IF ( NPARAMS .GE. LA_LINRX_ITREF_I ) THEN
380:          IF ( PARAMS( LA_LINRX_ITREF_I ) .LT. 0.0D+0 ) THEN
381:             PARAMS( LA_LINRX_ITREF_I ) = ITREF_DEFAULT
382:          ELSE
383:             REF_TYPE = PARAMS( LA_LINRX_ITREF_I )
384:          END IF
385:       END IF
386: *
387: *     Set default parameters.
388: *
389:       ILLRCOND_THRESH = DBLE( N ) * DLAMCH( 'Epsilon' )
390:       ITHRESH = INT( ITHRESH_DEFAULT )
391:       RTHRESH = RTHRESH_DEFAULT
392:       UNSTABLE_THRESH = DZTHRESH_DEFAULT
393:       IGNORE_CWISE = COMPONENTWISE_DEFAULT .EQ. 0.0D+0
394: *
395:       IF ( NPARAMS.GE.LA_LINRX_ITHRESH_I ) THEN
396:          IF ( PARAMS( LA_LINRX_ITHRESH_I ).LT.0.0D+0 ) THEN
397:             PARAMS( LA_LINRX_ITHRESH_I ) = ITHRESH
398:          ELSE
399:             ITHRESH = INT( PARAMS( LA_LINRX_ITHRESH_I ) )
400:          END IF
401:       END IF
402:       IF ( NPARAMS.GE.LA_LINRX_CWISE_I ) THEN
403:          IF ( PARAMS( LA_LINRX_CWISE_I ).LT.0.0D+0 ) THEN
404:             IF ( IGNORE_CWISE ) THEN
405:                PARAMS( LA_LINRX_CWISE_I ) = 0.0D+0
406:             ELSE
407:                PARAMS( LA_LINRX_CWISE_I ) = 1.0D+0
408:             END IF
409:          ELSE
410:             IGNORE_CWISE = PARAMS( LA_LINRX_CWISE_I ) .EQ. 0.0D+0
411:          END IF
412:       END IF
413:       IF ( REF_TYPE .EQ. 0 .OR. N_ERR_BNDS .EQ. 0 ) THEN
414:          N_NORMS = 0
415:       ELSE IF ( IGNORE_CWISE ) THEN
416:          N_NORMS = 1
417:       ELSE
418:          N_NORMS = 2
419:       END IF
420: *
421:       NOTRAN = LSAME( TRANS, 'N' )
422:       ROWEQU = LSAME( EQUED, 'R' ) .OR. LSAME( EQUED, 'B' )
423:       COLEQU = LSAME( EQUED, 'C' ) .OR. LSAME( EQUED, 'B' )
424: *
425: *     Test input parameters.
426: *
427:       IF( TRANS_TYPE.EQ.-1 ) THEN
428:         INFO = -1
429:       ELSE IF( .NOT.ROWEQU .AND. .NOT.COLEQU .AND.
430:      $         .NOT.LSAME( EQUED, 'N' ) ) THEN
431:         INFO = -2
432:       ELSE IF( N.LT.0 ) THEN
433:         INFO = -3
434:       ELSE IF( KL.LT.0 ) THEN
435:         INFO = -4
436:       ELSE IF( KU.LT.0 ) THEN
437:         INFO = -5
438:       ELSE IF( NRHS.LT.0 ) THEN
439:         INFO = -6
440:       ELSE IF( LDAB.LT.KL+KU+1 ) THEN
441:         INFO = -8
442:       ELSE IF( LDAFB.LT.2*KL+KU+1 ) THEN
443:         INFO = -10
444:       ELSE IF( LDB.LT.MAX( 1, N ) ) THEN
445:         INFO = -13
446:       ELSE IF( LDX.LT.MAX( 1, N ) ) THEN
447:         INFO = -15
448:       END IF
449:       IF( INFO.NE.0 ) THEN
450:         CALL XERBLA( 'ZGBRFSX', -INFO )
451:         RETURN
452:       END IF
453: *
454: *     Quick return if possible.
455: *
456:       IF( N.EQ.0 .OR. NRHS.EQ.0 ) THEN
457:          RCOND = 1.0D+0
458:          DO J = 1, NRHS
459:             BERR( J ) = 0.0D+0
460:             IF ( N_ERR_BNDS .GE. 1 ) THEN
461:                ERR_BNDS_NORM( J, LA_LINRX_TRUST_I ) = 1.0D+0
462:                ERR_BNDS_COMP( J, LA_LINRX_TRUST_I ) = 1.0D+0
463:             ELSE IF ( N_ERR_BNDS .GE. 2 ) THEN
464:                ERR_BNDS_NORM( J, LA_LINRX_ERR_I ) = 0.0D+0
465:                ERR_BNDS_COMP( J, LA_LINRX_ERR_I ) = 0.0D+0
466:             ELSE IF ( N_ERR_BNDS .GE. 3 ) THEN
467:                ERR_BNDS_NORM( J, LA_LINRX_RCOND_I ) = 1.0D+0
468:                ERR_BNDS_COMP( J, LA_LINRX_RCOND_I ) = 1.0D+0
469:             END IF
470:          END DO
471:          RETURN
472:       END IF
473: *
474: *     Default to failure.
475: *
476:       RCOND = 0.0D+0
477:       DO J = 1, NRHS
478:          BERR( J ) = 1.0D+0
479:          IF ( N_ERR_BNDS .GE. 1 ) THEN
480:             ERR_BNDS_NORM( J, LA_LINRX_TRUST_I ) = 1.0D+0
481:             ERR_BNDS_COMP( J, LA_LINRX_TRUST_I ) = 1.0D+0
482:          ELSE IF ( N_ERR_BNDS .GE. 2 ) THEN
483:             ERR_BNDS_NORM( J, LA_LINRX_ERR_I ) = 1.0D+0
484:             ERR_BNDS_COMP( J, LA_LINRX_ERR_I ) = 1.0D+0
485:          ELSE IF ( N_ERR_BNDS .GE. 3 ) THEN
486:             ERR_BNDS_NORM( J, LA_LINRX_RCOND_I ) = 0.0D+0
487:             ERR_BNDS_COMP( J, LA_LINRX_RCOND_I ) = 0.0D+0
488:          END IF
489:       END DO
490: *
491: *     Compute the norm of A and the reciprocal of the condition
492: *     number of A.
493: *
494:       IF( NOTRAN ) THEN
495:          NORM = 'I'
496:       ELSE
497:          NORM = '1'
498:       END IF
499:       ANORM = ZLANGB( NORM, N, KL, KU, AB, LDAB, RWORK )
500:       CALL ZGBCON( NORM, N, KL, KU, AFB, LDAFB, IPIV, ANORM, RCOND,
501:      $     WORK, RWORK, INFO )
502: *
503: *     Perform refinement on each right-hand side
504: *
505:       IF ( REF_TYPE .NE. 0 ) THEN
506: 
507:          PREC_TYPE = ILAPREC( 'E' )
508: 
509:          IF ( NOTRAN ) THEN
510:             CALL ZLA_GBRFSX_EXTENDED( PREC_TYPE, TRANS_TYPE,  N, KL, KU,
511:      $           NRHS, AB, LDAB, AFB, LDAFB, IPIV, COLEQU, C, B,
512:      $           LDB, X, LDX, BERR, N_NORMS, ERR_BNDS_NORM,
513:      $           ERR_BNDS_COMP, WORK, RWORK, WORK(N+1),
514:      $           TRANSFER (RWORK(1:2*N), (/ (ZERO, ZERO) /), N),
515:      $           RCOND, ITHRESH, RTHRESH, UNSTABLE_THRESH, IGNORE_CWISE,
516:      $           INFO )
517:          ELSE
518:             CALL ZLA_GBRFSX_EXTENDED( PREC_TYPE, TRANS_TYPE,  N, KL, KU,
519:      $           NRHS, AB, LDAB, AFB, LDAFB, IPIV, ROWEQU, R, B,
520:      $           LDB, X, LDX, BERR, N_NORMS, ERR_BNDS_NORM,
521:      $           ERR_BNDS_COMP, WORK, RWORK, WORK(N+1),
522:      $           TRANSFER (RWORK(1:2*N), (/ (ZERO, ZERO) /), N),
523:      $           RCOND, ITHRESH, RTHRESH, UNSTABLE_THRESH, IGNORE_CWISE,
524:      $           INFO )
525:          END IF
526:       END IF
527: 
528:       ERR_LBND = MAX( 10.0D+0, SQRT( DBLE( N ) ) ) * DLAMCH( '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 = ZLA_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 = ZLA_GBRCOND_C( TRANS, N, KL, KU, AB, LDAB, AFB,
538:      $           LDAFB, IPIV, R, .TRUE., INFO, WORK, RWORK )
539:          ELSE
540:             RCOND_TMP = ZLA_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.0D+0)
549:      $           ERR_BNDS_NORM( J, LA_LINRX_ERR_I ) = 1.0D+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.0D+0
555:                ERR_BNDS_NORM( J, LA_LINRX_TRUST_I ) = 0.0D+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.0D+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( DLAMCH( 'Epsilon' ) )
583:          DO J = 1, NRHS
584:             IF (ERR_BNDS_COMP( J, LA_LINRX_ERR_I ) .LT. CWISE_WRONG )
585:      $     THEN
586:                RCOND_TMP = ZLA_GBRCOND_X( TRANS, N, KL, KU, AB, LDAB,
587:      $              AFB, LDAFB, IPIV, X( 1, J ), INFO, WORK, RWORK )
588:             ELSE
589:                RCOND_TMP = 0.0D+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.0D+0 )
596:      $           ERR_BNDS_COMP( J, LA_LINRX_ERR_I ) = 1.0D+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.0D+0
602:                ERR_BNDS_COMP( J, LA_LINRX_TRUST_I ) = 0.0D+0
603:                IF ( PARAMS( LA_LINRX_CWISE_I ) .EQ. 1.0D+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.0D+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 ZGBRFSX
623: *
624:       END
625: