001:       SUBROUTINE CLA_GBRFSX_EXTENDED ( PREC_TYPE, TRANS_TYPE, N, KL, KU,
002:      $                                NRHS, AB, LDAB, AFB, LDAFB, IPIV,
003:      $                                COLEQU, C, B, LDB, Y, LDY,
004:      $                                BERR_OUT, N_NORMS, ERR_BNDS_NORM,
005:      $                                ERR_BNDS_COMP, RES, AYB, DY,
006:      $                                Y_TAIL, RCOND, ITHRESH, RTHRESH,
007:      $                                DZ_UB, IGNORE_CWISE, INFO )
008: *
009: *     -- LAPACK routine (version 3.2.1)                                 --
010: *     -- Contributed by James Demmel, Deaglan Halligan, Yozo Hida and --
011: *     -- Jason Riedy of Univ. of California Berkeley.                 --
012: *     -- April 2009                                                   --
013: *
014: *     -- LAPACK is a software package provided by Univ. of Tennessee, --
015: *     -- Univ. of California Berkeley and NAG Ltd.                    --
016: *
017:       IMPLICIT NONE
018: *     ..
019: *     .. Scalar Arguments ..
020:       INTEGER            INFO, LDAB, LDAFB, LDB, LDY, N, KL, KU, NRHS,
021:      $                   PREC_TYPE, TRANS_TYPE, N_NORMS, ITHRESH
022:       LOGICAL            COLEQU, IGNORE_CWISE
023:       REAL               RTHRESH, DZ_UB
024: *     ..
025: *     .. Array Arguments ..
026:       INTEGER            IPIV( * )
027:       COMPLEX            AB( LDAB, * ), AFB( LDAFB, * ), B( LDB, * ),
028:      $                   Y( LDY, * ), RES( * ), DY( * ), Y_TAIL( * )
029:       REAL               C( * ), AYB(*), RCOND, BERR_OUT( * ),
030:      $                   ERR_BNDS_NORM( NRHS, * ),
031:      $                   ERR_BNDS_COMP( NRHS, * )
032: *     ..
033: *
034: *  Purpose
035: *  =======
036: *
037: *  CLA_GBRFSX_EXTENDED improves the computed solution to a system of
038: *  linear equations by performing extra-precise iterative refinement
039: *  and provides error bounds and backward error estimates for the solution.
040: *  This subroutine is called by CGBRFSX to perform iterative refinement.
041: *  In addition to normwise error bound, the code provides maximum
042: *  componentwise error bound if possible. See comments for ERR_BNDS_NORM
043: *  and ERR_BNDS_COMP for details of the error bounds. Note that this
044: *  subroutine is only resonsible for setting the second fields of
045: *  ERR_BNDS_NORM and ERR_BNDS_COMP.
046: *
047: *  Arguments
048: *  =========
049: *
050: *     PREC_TYPE      (input) INTEGER
051: *     Specifies the intermediate precision to be used in refinement.
052: *     The value is defined by ILAPREC(P) where P is a CHARACTER and
053: *     P    = 'S':  Single
054: *          = 'D':  Double
055: *          = 'I':  Indigenous
056: *          = 'X', 'E':  Extra
057: *
058: *     TRANS_TYPE     (input) INTEGER
059: *     Specifies the transposition operation on A.
060: *     The value is defined by ILATRANS(T) where T is a CHARACTER and
061: *     T    = 'N':  No transpose
062: *          = 'T':  Transpose
063: *          = 'C':  Conjugate transpose
064: *
065: *     N              (input) INTEGER
066: *     The number of linear equations, i.e., the order of the
067: *     matrix A.  N >= 0.
068: *
069: *     KL             (input) INTEGER
070: *     The number of subdiagonals within the band of A.  KL >= 0.
071: *
072: *     KU             (input) INTEGER
073: *     The number of superdiagonals within the band of A.  KU >= 0
074: *
075: *     NRHS           (input) INTEGER
076: *     The number of right-hand-sides, i.e., the number of columns of the
077: *     matrix B.
078: *
079: *     AB             (input) COMPLEX array, dimension (LDA,N)
080: *     On entry, the N-by-N matrix A.
081: *
082: *     LDAB           (input) INTEGER
083: *     The leading dimension of the array A.  LDA >= max(1,N).
084: *
085: *     AFB            (input) COMPLEX array, dimension (LDAF,N)
086: *     The factors L and U from the factorization
087: *     A = P*L*U as computed by CGBTRF.
088: *
089: *     LDAFB          (input) INTEGER
090: *     The leading dimension of the array AF.  LDAF >= max(1,N).
091: *
092: *     IPIV           (input) INTEGER array, dimension (N)
093: *     The pivot indices from the factorization A = P*L*U
094: *     as computed by CGBTRF; row i of the matrix was interchanged
095: *     with row IPIV(i).
096: *
097: *     COLEQU         (input) LOGICAL
098: *     If .TRUE. then column equilibration was done to A before calling
099: *     this routine. This is needed to compute the solution and error
100: *     bounds correctly.
101: *
102: *     C              (input) REAL array, dimension (N)
103: *     The column scale factors for A. If COLEQU = .FALSE., C
104: *     is not accessed. If C is input, each element of C should be a power
105: *     of the radix to ensure a reliable solution and error estimates.
106: *     Scaling by powers of the radix does not cause rounding errors unless
107: *     the result underflows or overflows. Rounding errors during scaling
108: *     lead to refining with a matrix that is not equivalent to the
109: *     input matrix, producing error estimates that may not be
110: *     reliable.
111: *
112: *     B              (input) COMPLEX 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: *     Y              (input/output) COMPLEX array, dimension (LDY,NRHS)
119: *     On entry, the solution matrix X, as computed by CGBTRS.
120: *     On exit, the improved solution matrix Y.
121: *
122: *     LDY            (input) INTEGER
123: *     The leading dimension of the array Y.  LDY >= max(1,N).
124: *
125: *     BERR_OUT       (output) REAL array, dimension (NRHS)
126: *     On exit, BERR_OUT(j) contains the componentwise relative backward
127: *     error for right-hand-side j from the formula
128: *         max(i) ( abs(RES(i)) / ( abs(op(A_s))*abs(Y) + abs(B_s) )(i) )
129: *     where abs(Z) is the componentwise absolute value of the matrix
130: *     or vector Z. This is computed by CLA_LIN_BERR.
131: *
132: *     N_NORMS        (input) INTEGER
133: *     Determines which error bounds to return (see ERR_BNDS_NORM
134: *     and ERR_BNDS_COMP).
135: *     If N_NORMS >= 1 return normwise error bounds.
136: *     If N_NORMS >= 2 return componentwise error bounds.
137: *
138: *     ERR_BNDS_NORM  (input/output) REAL array, dimension
139: *                    (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) * slamch('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) * slamch('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) * slamch('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: *     This subroutine is only responsible for setting the second field
178: *     above.
179: *     See Lapack Working Note 165 for further details and extra
180: *     cautions.
181: *
182: *     ERR_BNDS_COMP  (input/output) REAL array, dimension
183: *                    (NRHS, N_ERR_BNDS)
184: *     For each right-hand side, this array contains information about
185: *     various error bounds and condition numbers corresponding to the
186: *     componentwise relative error, which is defined as follows:
187: *
188: *     Componentwise relative error in the ith solution vector:
189: *                    abs(XTRUE(j,i) - X(j,i))
190: *             max_j ----------------------
191: *                         abs(X(j,i))
192: *
193: *     The array is indexed by the right-hand side i (on which the
194: *     componentwise relative error depends), and the type of error
195: *     information as described below. There currently are up to three
196: *     pieces of information returned for each right-hand side. If
197: *     componentwise accuracy is not requested (PARAMS(3) = 0.0), then
198: *     ERR_BNDS_COMP is not accessed.  If N_ERR_BNDS .LT. 3, then at most
199: *     the first (:,N_ERR_BNDS) entries are returned.
200: *
201: *     The first index in ERR_BNDS_COMP(i,:) corresponds to the ith
202: *     right-hand side.
203: *
204: *     The second index in ERR_BNDS_COMP(:,err) contains the following
205: *     three fields:
206: *     err = 1 "Trust/don't trust" boolean. Trust the answer if the
207: *              reciprocal condition number is less than the threshold
208: *              sqrt(n) * slamch('Epsilon').
209: *
210: *     err = 2 "Guaranteed" error bound: The estimated forward error,
211: *              almost certainly within a factor of 10 of the true error
212: *              so long as the next entry is greater than the threshold
213: *              sqrt(n) * slamch('Epsilon'). This error bound should only
214: *              be trusted if the previous boolean is true.
215: *
216: *     err = 3  Reciprocal condition number: Estimated componentwise
217: *              reciprocal condition number.  Compared with the threshold
218: *              sqrt(n) * slamch('Epsilon') to determine if the error
219: *              estimate is "guaranteed". These reciprocal condition
220: *              numbers are 1 / (norm(Z^{-1},inf) * norm(Z,inf)) for some
221: *              appropriately scaled matrix Z.
222: *              Let Z = S*(A*diag(x)), where x is the solution for the
223: *              current right-hand side and S scales each row of
224: *              A*diag(x) by a power of the radix so all absolute row
225: *              sums of Z are approximately 1.
226: *
227: *     This subroutine is only responsible for setting the second field
228: *     above.
229: *     See Lapack Working Note 165 for further details and extra
230: *     cautions.
231: *
232: *     RES            (input) COMPLEX array, dimension (N)
233: *     Workspace to hold the intermediate residual.
234: *
235: *     AYB            (input) REAL array, dimension (N)
236: *     Workspace.
237: *
238: *     DY             (input) COMPLEX array, dimension (N)
239: *     Workspace to hold the intermediate solution.
240: *
241: *     Y_TAIL         (input) COMPLEX array, dimension (N)
242: *     Workspace to hold the trailing bits of the intermediate solution.
243: *
244: *     RCOND          (input) REAL
245: *     Reciprocal scaled condition number.  This is an estimate of the
246: *     reciprocal Skeel condition number of the matrix A after
247: *     equilibration (if done).  If this is less than the machine
248: *     precision (in particular, if it is zero), the matrix is singular
249: *     to working precision.  Note that the error may still be small even
250: *     if this number is very small and the matrix appears ill-
251: *     conditioned.
252: *
253: *     ITHRESH        (input) INTEGER
254: *     The maximum number of residual computations allowed for
255: *     refinement. The default is 10. For 'aggressive' set to 100 to
256: *     permit convergence using approximate factorizations or
257: *     factorizations other than LU. If the factorization uses a
258: *     technique other than Gaussian elimination, the guarantees in
259: *     ERR_BNDS_NORM and ERR_BNDS_COMP may no longer be trustworthy.
260: *
261: *     RTHRESH        (input) REAL
262: *     Determines when to stop refinement if the error estimate stops
263: *     decreasing. Refinement will stop when the next solution no longer
264: *     satisfies norm(dx_{i+1}) < RTHRESH * norm(dx_i) where norm(Z) is
265: *     the infinity norm of Z. RTHRESH satisfies 0 < RTHRESH <= 1. The
266: *     default value is 0.5. For 'aggressive' set to 0.9 to permit
267: *     convergence on extremely ill-conditioned matrices. See LAWN 165
268: *     for more details.
269: *
270: *     DZ_UB          (input) REAL
271: *     Determines when to start considering componentwise convergence.
272: *     Componentwise convergence is only considered after each component
273: *     of the solution Y is stable, which we definte as the relative
274: *     change in each component being less than DZ_UB. The default value
275: *     is 0.25, requiring the first bit to be stable. See LAWN 165 for
276: *     more details.
277: *
278: *     IGNORE_CWISE   (input) LOGICAL
279: *     If .TRUE. then ignore componentwise convergence. Default value
280: *     is .FALSE..
281: *
282: *     INFO           (output) INTEGER
283: *       = 0:  Successful exit.
284: *       < 0:  if INFO = -i, the ith argument to CGBTRS had an illegal
285: *             value
286: *
287: *  =====================================================================
288: *
289: *     .. Local Scalars ..
290:       CHARACTER          TRANS
291:       INTEGER            CNT, I, J, M, X_STATE, Z_STATE, Y_PREC_STATE
292:       REAL               YK, DYK, YMIN, NORMY, NORMX, NORMDX, DXRAT,
293:      $                   DZRAT, PREVNORMDX, PREV_DZ_Z, DXRATMAX,
294:      $                   DZRATMAX, DX_X, DZ_Z, FINAL_DX_X, FINAL_DZ_Z,
295:      $                   EPS, HUGEVAL, INCR_THRESH
296:       LOGICAL            INCR_PREC
297:       COMPLEX            ZDUM
298: *     ..
299: *     .. Parameters ..
300:       INTEGER            UNSTABLE_STATE, WORKING_STATE, CONV_STATE,
301:      $                   NOPROG_STATE, BASE_RESIDUAL, EXTRA_RESIDUAL,
302:      $                   EXTRA_Y
303:       PARAMETER          ( UNSTABLE_STATE = 0, WORKING_STATE = 1,
304:      $                   CONV_STATE = 2, NOPROG_STATE = 3 )
305:       PARAMETER          ( BASE_RESIDUAL = 0, EXTRA_RESIDUAL = 1,
306:      $                   EXTRA_Y = 2 )
307:       INTEGER            FINAL_NRM_ERR_I, FINAL_CMP_ERR_I, BERR_I
308:       INTEGER            RCOND_I, NRM_RCOND_I, NRM_ERR_I, CMP_RCOND_I
309:       INTEGER            CMP_ERR_I, PIV_GROWTH_I
310:       PARAMETER          ( FINAL_NRM_ERR_I = 1, FINAL_CMP_ERR_I = 2,
311:      $                   BERR_I = 3 )
312:       PARAMETER          ( RCOND_I = 4, NRM_RCOND_I = 5, NRM_ERR_I = 6 )
313:       PARAMETER          ( CMP_RCOND_I = 7, CMP_ERR_I = 8,
314:      $                   PIV_GROWTH_I = 9 )
315:       INTEGER            LA_LINRX_ITREF_I, LA_LINRX_ITHRESH_I,
316:      $                   LA_LINRX_CWISE_I
317:       PARAMETER          ( LA_LINRX_ITREF_I = 1,
318:      $                   LA_LINRX_ITHRESH_I = 2 )
319:       PARAMETER          ( LA_LINRX_CWISE_I = 3 )
320:       INTEGER            LA_LINRX_TRUST_I, LA_LINRX_ERR_I,
321:      $                   LA_LINRX_RCOND_I
322:       PARAMETER          ( LA_LINRX_TRUST_I = 1, LA_LINRX_ERR_I = 2 )
323:       PARAMETER          ( LA_LINRX_RCOND_I = 3 )
324: *     ..
325: *     .. External Subroutines ..
326:       EXTERNAL           CAXPY, CCOPY, CGBTRS, CGBMV, BLAS_CGBMV_X,
327:      $                   BLAS_CGBMV2_X, CLA_GBAMV, CLA_WWADDW, SLAMCH,
328:      $                   CHLA_TRANSTYPE, CLA_LIN_BERR
329:       REAL               SLAMCH
330:       CHARACTER          CHLA_TRANSTYPE
331: *     ..
332: *     .. Intrinsic Functions..
333:       INTRINSIC          ABS, MAX, MIN
334: *     ..
335: *     .. Statement Functions ..
336:       REAL               CABS1
337: *     ..
338: *     .. Statement Function Definitions ..
339:       CABS1( ZDUM ) = ABS( REAL( ZDUM ) ) + ABS( AIMAG( ZDUM ) )
340: *     ..
341: *     .. Executable Statements ..
342: *
343:       IF (INFO.NE.0) RETURN
344:       TRANS = CHLA_TRANSTYPE(TRANS_TYPE)
345:       EPS = SLAMCH( 'Epsilon' )
346:       HUGEVAL = SLAMCH( 'Overflow' )
347: *     Force HUGEVAL to Inf
348:       HUGEVAL = HUGEVAL * HUGEVAL
349: *     Using HUGEVAL may lead to spurious underflows.
350:       INCR_THRESH = REAL( N ) * EPS
351:       M = KL+KU+1
352: 
353:       DO J = 1, NRHS
354:          Y_PREC_STATE = EXTRA_RESIDUAL
355:          IF ( Y_PREC_STATE .EQ. EXTRA_Y ) then
356:             DO I = 1, N
357:                Y_TAIL( I ) = 0.0
358:             END DO
359:          END IF
360: 
361:          DXRAT = 0.0E+0
362:          DXRATMAX = 0.0E+0
363:          DZRAT = 0.0E+0
364:          DZRATMAX = 0.0E+0
365:          FINAL_DX_X = HUGEVAL
366:          FINAL_DZ_Z = HUGEVAL
367:          PREVNORMDX = HUGEVAL
368:          PREV_DZ_Z = HUGEVAL
369:          DZ_Z = HUGEVAL
370:          DX_X = HUGEVAL
371: 
372:          X_STATE = WORKING_STATE
373:          Z_STATE = UNSTABLE_STATE
374:          INCR_PREC = .FALSE.
375: 
376:          DO CNT = 1, ITHRESH
377: *
378: *        Compute residual RES = B_s - op(A_s) * Y,
379: *            op(A) = A, A**T, or A**H depending on TRANS (and type).
380: *
381:             CALL CCOPY( N, B( 1, J ), 1, RES, 1 )
382:             IF ( Y_PREC_STATE .EQ. BASE_RESIDUAL ) THEN
383:                CALL CGBMV( TRANS, M, N, KL, KU, (-1.0E+0,0.0E+0), AB,
384:      $              LDAB, Y( 1, J ), 1, (1.0E+0,0.0E+0), RES, 1 )
385:             ELSE IF ( Y_PREC_STATE .EQ. EXTRA_RESIDUAL ) THEN
386:                CALL BLAS_CGBMV_X( TRANS_TYPE, N, N, KL, KU,
387:      $              (-1.0E+0,0.0E+0), AB, LDAB, Y( 1, J ), 1,
388:      $              (1.0E+0,0.0E+0), RES, 1, PREC_TYPE )
389:             ELSE
390:                CALL BLAS_CGBMV2_X( TRANS_TYPE, N, N, KL, KU,
391:      $              (-1.0E+0,0.0E+0), AB, LDAB, Y( 1, J ), Y_TAIL, 1,
392:      $              (1.0E+0,0.0E+0), RES, 1, PREC_TYPE )
393:             END IF
394: 
395: !        XXX: RES is no longer needed.
396:             CALL CCOPY( N, RES, 1, DY, 1 )
397:             CALL CGBTRS( TRANS, N, KL, KU, 1, AFB, LDAFB, IPIV, DY, N,
398:      $           INFO )
399: *
400: *         Calculate relative changes DX_X, DZ_Z and ratios DXRAT, DZRAT.
401: *
402:             NORMX = 0.0E+0
403:             NORMY = 0.0E+0
404:             NORMDX = 0.0E+0
405:             DZ_Z = 0.0E+0
406:             YMIN = HUGEVAL
407: 
408:             DO I = 1, N
409:                YK = CABS1( Y( I, J ) )
410:                DYK = CABS1( DY( I ) )
411: 
412:                IF (YK .NE. 0.0) THEN
413:                   DZ_Z = MAX( DZ_Z, DYK / YK )
414:                ELSE IF ( DYK .NE. 0.0 ) THEN
415:                   DZ_Z = HUGEVAL
416:                END IF
417: 
418:                YMIN = MIN( YMIN, YK )
419: 
420:                NORMY = MAX( NORMY, YK )
421: 
422:                IF ( COLEQU ) THEN
423:                   NORMX = MAX( NORMX, YK * C( I ) )
424:                   NORMDX = MAX(NORMDX, DYK * C(I))
425:                ELSE
426:                   NORMX = NORMY
427:                   NORMDX = MAX( NORMDX, DYK )
428:                END IF
429:             END DO
430: 
431:             IF ( NORMX .NE. 0.0 ) THEN
432:                DX_X = NORMDX / NORMX
433:             ELSE IF ( NORMDX .EQ. 0.0 ) THEN
434:                DX_X = 0.0
435:             ELSE
436:                DX_X = HUGEVAL
437:             END IF
438: 
439:             DXRAT = NORMDX / PREVNORMDX
440:             DZRAT = DZ_Z / PREV_DZ_Z
441: *
442: *         Check termination criteria.
443: *
444:             IF (.NOT.IGNORE_CWISE
445:      $           .AND. YMIN*RCOND .LT. INCR_THRESH*NORMY
446:      $           .AND. Y_PREC_STATE .LT. EXTRA_Y )
447:      $           INCR_PREC = .TRUE.
448: 
449:             IF ( X_STATE .EQ. NOPROG_STATE .AND. DXRAT .LE. RTHRESH )
450:      $           X_STATE = WORKING_STATE
451:             IF ( X_STATE .EQ. WORKING_STATE ) THEN
452:                IF ( DX_X .LE. EPS ) THEN
453:                   X_STATE = CONV_STATE
454:                ELSE IF ( DXRAT .GT. RTHRESH ) THEN
455:                   IF ( Y_PREC_STATE .NE. EXTRA_Y ) THEN
456:                      INCR_PREC = .TRUE.
457:                   ELSE
458:                      X_STATE = NOPROG_STATE
459:                   END IF
460:                ELSE
461:                   IF ( DXRAT .GT. DXRATMAX ) DXRATMAX = DXRAT
462:                END IF
463:                IF ( X_STATE .GT. WORKING_STATE ) FINAL_DX_X = DX_X
464:             END IF
465: 
466:             IF ( Z_STATE .EQ. UNSTABLE_STATE .AND. DZ_Z .LE. DZ_UB )
467:      $           Z_STATE = WORKING_STATE
468:             IF ( Z_STATE .EQ. NOPROG_STATE .AND. DZRAT .LE. RTHRESH )
469:      $           Z_STATE = WORKING_STATE
470:             IF ( Z_STATE .EQ. WORKING_STATE ) THEN
471:                IF ( DZ_Z .LE. EPS ) THEN
472:                   Z_STATE = CONV_STATE
473:                ELSE IF ( DZ_Z .GT. DZ_UB ) THEN
474:                   Z_STATE = UNSTABLE_STATE
475:                   DZRATMAX = 0.0
476:                   FINAL_DZ_Z = HUGEVAL
477:                ELSE IF ( DZRAT .GT. RTHRESH ) THEN
478:                   IF ( Y_PREC_STATE .NE. EXTRA_Y ) THEN
479:                      INCR_PREC = .TRUE.
480:                   ELSE
481:                      Z_STATE = NOPROG_STATE
482:                   END IF
483:                ELSE
484:                   IF ( DZRAT .GT. DZRATMAX ) DZRATMAX = DZRAT
485:                END IF
486:                IF ( Z_STATE .GT. WORKING_STATE ) FINAL_DZ_Z = DZ_Z
487:             END IF
488: *
489: *           Exit if both normwise and componentwise stopped working,
490: *           but if componentwise is unstable, let it go at least two
491: *           iterations.
492: *
493:             IF ( X_STATE.NE.WORKING_STATE ) THEN
494:                IF ( IGNORE_CWISE ) GOTO 666
495:                IF ( Z_STATE.EQ.NOPROG_STATE .OR. Z_STATE.EQ.CONV_STATE )
496:      $              GOTO 666
497:                IF ( Z_STATE.EQ.UNSTABLE_STATE .AND. CNT.GT.1 ) GOTO 666
498:             END IF
499: 
500:             IF ( INCR_PREC ) THEN
501:                INCR_PREC = .FALSE.
502:                Y_PREC_STATE = Y_PREC_STATE + 1
503:                DO I = 1, N
504:                   Y_TAIL( I ) = 0.0
505:                END DO
506:             END IF
507: 
508:             PREVNORMDX = NORMDX
509:             PREV_DZ_Z = DZ_Z
510: *
511: *           Update soluton.
512: *
513:             IF ( Y_PREC_STATE .LT. EXTRA_Y ) THEN
514:                CALL CAXPY( N, (1.0E+0,0.0E+0), DY, 1, Y(1,J), 1 )
515:             ELSE
516:                CALL CLA_WWADDW( N, Y(1,J), Y_TAIL, DY )
517:             END IF
518: 
519:          END DO
520: *        Target of "IF (Z_STOP .AND. X_STOP)".  Sun's f77 won't EXIT.
521:  666     CONTINUE
522: *
523: *     Set final_* when cnt hits ithresh.
524: *
525:          IF ( X_STATE .EQ. WORKING_STATE ) FINAL_DX_X = DX_X
526:          IF ( Z_STATE .EQ. WORKING_STATE ) FINAL_DZ_Z = DZ_Z
527: *
528: *     Compute error bounds.
529: *
530:          IF ( N_NORMS .GE. 1 ) THEN
531:             ERR_BNDS_NORM( J, LA_LINRX_ERR_I ) =
532:      $           FINAL_DX_X / (1 - DXRATMAX)
533:          END IF
534:          IF ( N_NORMS .GE. 2 ) THEN
535:             ERR_BNDS_COMP( J, LA_LINRX_ERR_I ) =
536:      $           FINAL_DZ_Z / (1 - DZRATMAX)
537:          END IF
538: *
539: *     Compute componentwise relative backward error from formula
540: *         max(i) ( abs(R(i)) / ( abs(op(A_s))*abs(Y) + abs(B_s) )(i) )
541: *     where abs(Z) is the componentwise absolute value of the matrix
542: *     or vector Z.
543: *
544: *        Compute residual RES = B_s - op(A_s) * Y,
545: *            op(A) = A, A**T, or A**H depending on TRANS (and type).
546: *
547:          CALL CCOPY( N, B( 1, J ), 1, RES, 1 )
548:          CALL CGBMV( TRANS, N, N, KL, KU, (-1.0E+0,0.0E+0), AB, LDAB,
549:      $        Y(1,J), 1, (1.0E+0,0.0E+0), RES, 1 )
550: 
551:          DO I = 1, N
552:             AYB( I ) = CABS1( B( I, J ) )
553:          END DO
554: *
555: *     Compute abs(op(A_s))*abs(Y) + abs(B_s).
556: *
557:         CALL CLA_GBAMV( TRANS_TYPE, N, N, KL, KU, 1.0E+0,
558:      $        AB, LDAB, Y(1, J), 1, 1.0E+0, AYB, 1 )
559: 
560:          CALL CLA_LIN_BERR( N, N, 1, RES, AYB, BERR_OUT( J ) )
561: *
562: *     End of loop for each RHS.
563: *
564:       END DO
565: *
566:       RETURN
567:       END
568: