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