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