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