001:       SUBROUTINE DLA_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:       DOUBLE PRECISION   RTHRESH, DZ_UB
024: *     ..
025: *     .. Array Arguments ..
026:       INTEGER            IPIV( * )
027:       DOUBLE PRECISION   AB( LDAB, * ), AFB( LDAFB, * ), B( LDB, * ),
028:      $                   Y( LDY, * ), RES(*), DY(*), Y_TAIL(*)
029:       DOUBLE PRECISION   C( * ), AYB(*), RCOND, BERR_OUT(*),
030:      $                   ERR_BNDS_NORM( NRHS, * ),
031:      $                   ERR_BNDS_COMP( NRHS, * )
032: *     ..
033: *
034: *  Purpose
035: *  =======
036: * 
037: *  DLA_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 DGBRFSX 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: *     A              (input) DOUBLE PRECISION array, dimension (LDA,N)
080: *     On entry, the N-by-N matrix A.
081: *
082: *     LDA            (input) INTEGER
083: *     The leading dimension of the array A.  LDA >= max(1,N).
084: *
085: *     AF             (input) DOUBLE PRECISION array, dimension (LDAF,N)
086: *     The factors L and U from the factorization
087: *     A = P*L*U as computed by DGBTRF.
088: *
089: *     LDAF           (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 DGBTRF; 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) DOUBLE PRECISION 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) DOUBLE PRECISION 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) DOUBLE PRECISION array, dimension 
119: *                    (LDY,NRHS)
120: *     On entry, the solution matrix X, as computed by DGBTRS.
121: *     On exit, the improved solution matrix Y.
122: *
123: *     LDY            (input) INTEGER
124: *     The leading dimension of the array Y.  LDY >= max(1,N).
125: *
126: *     BERR_OUT       (output) DOUBLE PRECISION array, dimension (NRHS)
127: *     On exit, BERR_OUT(j) contains the componentwise relative backward
128: *     error for right-hand-side j from the formula
129: *         max(i) ( abs(RES(i)) / ( abs(op(A_s))*abs(Y) + abs(B_s) )(i) )
130: *     where abs(Z) is the componentwise absolute value of the matrix
131: *     or vector Z. This is computed by DLA_LIN_BERR.
132: *
133: *     N_NORMS        (input) INTEGER
134: *     Determines which error bounds to return (see ERR_BNDS_NORM
135: *     and ERR_BNDS_COMP).
136: *     If N_NORMS >= 1 return normwise error bounds.
137: *     If N_NORMS >= 2 return componentwise error bounds.
138: *
139: *     ERR_BNDS_NORM  (input/output) DOUBLE PRECISION array, dimension 
140: *                    (NRHS, N_ERR_BNDS)
141: *     For each right-hand side, this array contains information about
142: *     various error bounds and condition numbers corresponding to the
143: *     normwise relative error, which is defined as follows:
144: *
145: *     Normwise relative error in the ith solution vector:
146: *             max_j (abs(XTRUE(j,i) - X(j,i)))
147: *            ------------------------------
148: *                  max_j abs(X(j,i))
149: *
150: *     The array is indexed by the type of error information as described
151: *     below. There currently are up to three pieces of information
152: *     returned.
153: *
154: *     The first index in ERR_BNDS_NORM(i,:) corresponds to the ith
155: *     right-hand side.
156: *
157: *     The second index in ERR_BNDS_NORM(:,err) contains the following
158: *     three fields:
159: *     err = 1 "Trust/don't trust" boolean. Trust the answer if the
160: *              reciprocal condition number is less than the threshold
161: *              sqrt(n) * slamch('Epsilon').
162: *
163: *     err = 2 "Guaranteed" error bound: The estimated forward error,
164: *              almost certainly within a factor of 10 of the true error
165: *              so long as the next entry is greater than the threshold
166: *              sqrt(n) * slamch('Epsilon'). This error bound should only
167: *              be trusted if the previous boolean is true.
168: *
169: *     err = 3  Reciprocal condition number: Estimated normwise
170: *              reciprocal condition number.  Compared with the threshold
171: *              sqrt(n) * slamch('Epsilon') to determine if the error
172: *              estimate is "guaranteed". These reciprocal condition
173: *              numbers are 1 / (norm(Z^{-1},inf) * norm(Z,inf)) for some
174: *              appropriately scaled matrix Z.
175: *              Let Z = S*A, where S scales each row by a power of the
176: *              radix so all absolute row sums of Z are approximately 1.
177: *
178: *     This subroutine is only responsible for setting the second field
179: *     above.
180: *     See Lapack Working Note 165 for further details and extra
181: *     cautions.
182: *
183: *     ERR_BNDS_COMP  (input/output) DOUBLE PRECISION array, dimension 
184: *                    (NRHS, N_ERR_BNDS)
185: *     For each right-hand side, this array contains information about
186: *     various error bounds and condition numbers corresponding to the
187: *     componentwise relative error, which is defined as follows:
188: *
189: *     Componentwise relative error in the ith solution vector:
190: *                    abs(XTRUE(j,i) - X(j,i))
191: *             max_j ----------------------
192: *                         abs(X(j,i))
193: *
194: *     The array is indexed by the right-hand side i (on which the
195: *     componentwise relative error depends), and the type of error
196: *     information as described below. There currently are up to three
197: *     pieces of information returned for each right-hand side. If
198: *     componentwise accuracy is not requested (PARAMS(3) = 0.0), then
199: *     ERR_BNDS_COMP is not accessed.  If N_ERR_BNDS .LT. 3, then at most
200: *     the first (:,N_ERR_BNDS) entries are returned.
201: *
202: *     The first index in ERR_BNDS_COMP(i,:) corresponds to the ith
203: *     right-hand side.
204: *
205: *     The second index in ERR_BNDS_COMP(:,err) contains the following
206: *     three fields:
207: *     err = 1 "Trust/don't trust" boolean. Trust the answer if the
208: *              reciprocal condition number is less than the threshold
209: *              sqrt(n) * slamch('Epsilon').
210: *
211: *     err = 2 "Guaranteed" error bound: The estimated forward error,
212: *              almost certainly within a factor of 10 of the true error
213: *              so long as the next entry is greater than the threshold
214: *              sqrt(n) * slamch('Epsilon'). This error bound should only
215: *              be trusted if the previous boolean is true.
216: *
217: *     err = 3  Reciprocal condition number: Estimated componentwise
218: *              reciprocal condition number.  Compared with the threshold
219: *              sqrt(n) * slamch('Epsilon') to determine if the error
220: *              estimate is "guaranteed". These reciprocal condition
221: *              numbers are 1 / (norm(Z^{-1},inf) * norm(Z,inf)) for some
222: *              appropriately scaled matrix Z.
223: *              Let Z = S*(A*diag(x)), where x is the solution for the
224: *              current right-hand side and S scales each row of
225: *              A*diag(x) by a power of the radix so all absolute row
226: *              sums of Z are approximately 1.
227: *
228: *     This subroutine is only responsible for setting the second field
229: *     above.
230: *     See Lapack Working Note 165 for further details and extra
231: *     cautions.
232: *
233: *     RES            (input) DOUBLE PRECISION array, dimension (N)
234: *     Workspace to hold the intermediate residual.
235: *
236: *     AYB            (input) DOUBLE PRECISION array, dimension (N)
237: *     Workspace. This can be the same workspace passed for Y_TAIL.
238: *
239: *     DY             (input) DOUBLE PRECISION array, dimension (N)
240: *     Workspace to hold the intermediate solution.
241: *
242: *     Y_TAIL         (input) DOUBLE PRECISION array, dimension (N)
243: *     Workspace to hold the trailing bits of the intermediate solution.
244: *
245: *     RCOND          (input) DOUBLE PRECISION
246: *     Reciprocal scaled condition number.  This is an estimate of the
247: *     reciprocal Skeel condition number of the matrix A after
248: *     equilibration (if done).  If this is less than the machine
249: *     precision (in particular, if it is zero), the matrix is singular
250: *     to working precision.  Note that the error may still be small even
251: *     if this number is very small and the matrix appears ill-
252: *     conditioned.
253: *
254: *     ITHRESH        (input) INTEGER
255: *     The maximum number of residual computations allowed for
256: *     refinement. The default is 10. For 'aggressive' set to 100 to
257: *     permit convergence using approximate factorizations or
258: *     factorizations other than LU. If the factorization uses a
259: *     technique other than Gaussian elimination, the guarantees in
260: *     ERR_BNDS_NORM and ERR_BNDS_COMP may no longer be trustworthy.
261: *
262: *     RTHRESH        (input) DOUBLE PRECISION
263: *     Determines when to stop refinement if the error estimate stops
264: *     decreasing. Refinement will stop when the next solution no longer
265: *     satisfies norm(dx_{i+1}) < RTHRESH * norm(dx_i) where norm(Z) is
266: *     the infinity norm of Z. RTHRESH satisfies 0 < RTHRESH <= 1. The
267: *     default value is 0.5. For 'aggressive' set to 0.9 to permit
268: *     convergence on extremely ill-conditioned matrices. See LAWN 165
269: *     for more details.
270: *
271: *     DZ_UB          (input) DOUBLE PRECISION
272: *     Determines when to start considering componentwise convergence.
273: *     Componentwise convergence is only considered after each component
274: *     of the solution Y is stable, which we definte as the relative
275: *     change in each component being less than DZ_UB. The default value
276: *     is 0.25, requiring the first bit to be stable. See LAWN 165 for
277: *     more details.
278: *
279: *     IGNORE_CWISE   (input) LOGICAL
280: *     If .TRUE. then ignore componentwise convergence. Default value
281: *     is .FALSE..
282: *
283: *     INFO           (output) INTEGER
284: *       = 0:  Successful exit.
285: *       < 0:  if INFO = -i, the ith argument to DGBTRS had an illegal
286: *             value
287: *
288: *  =====================================================================
289: *
290: *     .. Local Scalars ..
291:       CHARACTER          TRANS
292:       INTEGER            CNT, I, J, M, X_STATE, Z_STATE, Y_PREC_STATE
293:       DOUBLE PRECISION   YK, DYK, YMIN, NORMY, NORMX, NORMDX, DXRAT,
294:      $                   DZRAT, PREVNORMDX, PREV_DZ_Z, DXRATMAX,
295:      $                   DZRATMAX, DX_X, DZ_Z, FINAL_DX_X, FINAL_DZ_Z,
296:      $                   EPS, HUGEVAL, INCR_THRESH
297:       LOGICAL            INCR_PREC
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           DAXPY, DCOPY, DGBTRS, DGBMV, BLAS_DGBMV_X,
327:      $                   BLAS_DGBMV2_X, DLA_GBAMV, DLA_WWADDW, DLAMCH,
328:      $                   CHLA_TRANSTYPE, DLA_LIN_BERR
329:       DOUBLE PRECISION   DLAMCH
330:       CHARACTER          CHLA_TRANSTYPE
331: *     ..
332: *     .. Intrinsic Functions ..
333:       INTRINSIC          ABS, MAX, MIN
334: *     ..
335: *     .. Executable Statements ..
336: *
337:       IF (INFO.NE.0) RETURN
338:       TRANS = CHLA_TRANSTYPE(TRANS_TYPE)
339:       EPS = DLAMCH( 'Epsilon' )
340:       HUGEVAL = DLAMCH( 'Overflow' )
341: *     Force HUGEVAL to Inf
342:       HUGEVAL = HUGEVAL * HUGEVAL
343: *     Using HUGEVAL may lead to spurious underflows.
344:       INCR_THRESH = DBLE( N ) * EPS
345:       M = KL+KU+1
346: 
347:       DO J = 1, NRHS
348:          Y_PREC_STATE = EXTRA_RESIDUAL
349:          IF ( Y_PREC_STATE .EQ. EXTRA_Y ) THEN
350:             DO I = 1, N
351:                Y_TAIL( I ) = 0.0D+0
352:             END DO
353:          END IF
354: 
355:          DXRAT = 0.0D+0
356:          DXRATMAX = 0.0D+0
357:          DZRAT = 0.0D+0
358:          DZRATMAX = 0.0D+0
359:          FINAL_DX_X = HUGEVAL
360:          FINAL_DZ_Z = HUGEVAL
361:          PREVNORMDX = HUGEVAL
362:          PREV_DZ_Z = HUGEVAL
363:          DZ_Z = HUGEVAL
364:          DX_X = HUGEVAL
365: 
366:          X_STATE = WORKING_STATE
367:          Z_STATE = UNSTABLE_STATE
368:          INCR_PREC = .FALSE.
369: 
370:          DO CNT = 1, ITHRESH
371: *
372: *        Compute residual RES = B_s - op(A_s) * Y,
373: *            op(A) = A, A**T, or A**H depending on TRANS (and type).
374: *
375:             CALL DCOPY( N, B( 1, J ), 1, RES, 1 )
376:             IF ( Y_PREC_STATE .EQ. BASE_RESIDUAL ) THEN
377:                CALL DGBMV( TRANS, M, N, KL, KU, -1.0D+0, AB, LDAB,
378:      $              Y( 1, J ), 1, 1.0D+0, RES, 1 )
379:             ELSE IF ( Y_PREC_STATE .EQ. EXTRA_RESIDUAL ) THEN
380:                CALL BLAS_DGBMV_X( TRANS_TYPE, N, N, KL, KU,
381:      $              -1.0D+0, AB, LDAB, Y( 1, J ), 1, 1.0D+0, RES, 1,
382:      $              PREC_TYPE )
383:             ELSE
384:                CALL BLAS_DGBMV2_X( TRANS_TYPE, N, N, KL, KU, -1.0D+0,
385:      $              AB, LDAB, Y( 1, J ), Y_TAIL, 1, 1.0D+0, RES, 1,
386:      $              PREC_TYPE )
387:             END IF
388: 
389: !        XXX: RES is no longer needed.
390:             CALL DCOPY( N, RES, 1, DY, 1 )
391:             CALL DGBTRS( TRANS, N, KL, KU, 1, AFB, LDAFB, IPIV, DY, N,
392:      $           INFO )
393: *
394: *         Calculate relative changes DX_X, DZ_Z and ratios DXRAT, DZRAT.
395: *
396:             NORMX = 0.0D+0
397:             NORMY = 0.0D+0
398:             NORMDX = 0.0D+0
399:             DZ_Z = 0.0D+0
400:             YMIN = HUGEVAL
401: 
402:             DO I = 1, N
403:                YK = ABS( Y( I, J ) )
404:                DYK = ABS( DY( I ) )
405: 
406:                IF ( YK .NE. 0.0D+0 ) THEN
407:                   DZ_Z = MAX( DZ_Z, DYK / YK )
408:                ELSE IF ( DYK .NE. 0.0D+0 ) THEN
409:                   DZ_Z = HUGEVAL
410:                END IF
411: 
412:                YMIN = MIN( YMIN, YK )
413: 
414:                NORMY = MAX( NORMY, YK )
415: 
416:                IF ( COLEQU ) THEN
417:                   NORMX = MAX( NORMX, YK * C( I ) )
418:                   NORMDX = MAX( NORMDX, DYK * C( I ) )
419:                ELSE
420:                   NORMX = NORMY
421:                   NORMDX = MAX( NORMDX, DYK )
422:                END IF
423:             END DO
424: 
425:             IF ( NORMX .NE. 0.0D+0 ) THEN
426:                DX_X = NORMDX / NORMX
427:             ELSE IF ( NORMDX .EQ. 0.0D+0 ) THEN
428:                DX_X = 0.0D+0
429:             ELSE
430:                DX_X = HUGEVAL
431:             END IF
432: 
433:             DXRAT = NORMDX / PREVNORMDX
434:             DZRAT = DZ_Z / PREV_DZ_Z
435: *
436: *         Check termination criteria.
437: *
438:             IF ( .NOT.IGNORE_CWISE
439:      $           .AND. YMIN*RCOND .LT. INCR_THRESH*NORMY
440:      $           .AND. Y_PREC_STATE .LT. EXTRA_Y )
441:      $           INCR_PREC = .TRUE.
442: 
443:             IF ( X_STATE .EQ. NOPROG_STATE .AND. DXRAT .LE. RTHRESH )
444:      $           X_STATE = WORKING_STATE
445:             IF ( X_STATE .EQ. WORKING_STATE ) THEN
446:                IF ( DX_X .LE. EPS ) THEN
447:                   X_STATE = CONV_STATE
448:                ELSE IF ( DXRAT .GT. RTHRESH ) THEN
449:                   IF ( Y_PREC_STATE .NE. EXTRA_Y ) THEN
450:                      INCR_PREC = .TRUE.
451:                   ELSE
452:                      X_STATE = NOPROG_STATE
453:                   END IF
454:                ELSE
455:                   IF ( DXRAT .GT. DXRATMAX ) DXRATMAX = DXRAT
456:                END IF
457:                IF ( X_STATE .GT. WORKING_STATE ) FINAL_DX_X = DX_X
458:             END IF
459: 
460:             IF ( Z_STATE .EQ. UNSTABLE_STATE .AND. DZ_Z .LE. DZ_UB )
461:      $           Z_STATE = WORKING_STATE
462:             IF ( Z_STATE .EQ. NOPROG_STATE .AND. DZRAT .LE. RTHRESH )
463:      $           Z_STATE = WORKING_STATE
464:             IF ( Z_STATE .EQ. WORKING_STATE ) THEN
465:                IF ( DZ_Z .LE. EPS ) THEN
466:                   Z_STATE = CONV_STATE
467:                ELSE IF ( DZ_Z .GT. DZ_UB ) THEN
468:                   Z_STATE = UNSTABLE_STATE
469:                   DZRATMAX = 0.0D+0
470:                   FINAL_DZ_Z = HUGEVAL
471:                ELSE IF ( DZRAT .GT. RTHRESH ) THEN
472:                   IF ( Y_PREC_STATE .NE. EXTRA_Y ) THEN
473:                      INCR_PREC = .TRUE.
474:                   ELSE
475:                      Z_STATE = NOPROG_STATE
476:                   END IF
477:                ELSE
478:                   IF ( DZRAT .GT. DZRATMAX ) DZRATMAX = DZRAT
479:                END IF
480:                IF ( Z_STATE .GT. WORKING_STATE ) FINAL_DZ_Z = DZ_Z
481:             END IF
482: *
483: *           Exit if both normwise and componentwise stopped working,
484: *           but if componentwise is unstable, let it go at least two
485: *           iterations.
486: *
487:             IF ( X_STATE.NE.WORKING_STATE ) THEN
488:                IF ( IGNORE_CWISE ) GOTO 666
489:                IF ( Z_STATE.EQ.NOPROG_STATE .OR. Z_STATE.EQ.CONV_STATE )
490:      $              GOTO 666
491:                IF ( Z_STATE.EQ.UNSTABLE_STATE .AND. CNT.GT.1 ) GOTO 666
492:             END IF
493: 
494:             IF ( INCR_PREC ) THEN
495:                INCR_PREC = .FALSE.
496:                Y_PREC_STATE = Y_PREC_STATE + 1
497:                DO I = 1, N
498:                   Y_TAIL( I ) = 0.0D+0
499:                END DO
500:             END IF
501: 
502:             PREVNORMDX = NORMDX
503:             PREV_DZ_Z = DZ_Z
504: *
505: *           Update soluton.
506: *
507:             IF (Y_PREC_STATE .LT. EXTRA_Y) THEN
508:                CALL DAXPY( N, 1.0D+0, DY, 1, Y(1,J), 1 )
509:             ELSE
510:                CALL DLA_WWADDW( N, Y(1,J), Y_TAIL, DY )
511:             END IF
512: 
513:          END DO
514: *        Target of "IF (Z_STOP .AND. X_STOP)".  Sun's f77 won't EXIT.
515:  666     CONTINUE
516: *
517: *     Set final_* when cnt hits ithresh.
518: *
519:          IF ( X_STATE .EQ. WORKING_STATE ) FINAL_DX_X = DX_X
520:          IF ( Z_STATE .EQ. WORKING_STATE ) FINAL_DZ_Z = DZ_Z
521: *
522: *     Compute error bounds.
523: *
524:          IF ( N_NORMS .GE. 1 ) THEN
525:             ERR_BNDS_NORM( J, LA_LINRX_ERR_I ) =
526:      $           FINAL_DX_X / (1 - DXRATMAX)
527:          END IF
528:          IF (N_NORMS .GE. 2) THEN
529:             ERR_BNDS_COMP( J, LA_LINRX_ERR_I ) =
530:      $           FINAL_DZ_Z / (1 - DZRATMAX)
531:          END IF
532: *
533: *     Compute componentwise relative backward error from formula
534: *         max(i) ( abs(R(i)) / ( abs(op(A_s))*abs(Y) + abs(B_s) )(i) )
535: *     where abs(Z) is the componentwise absolute value of the matrix
536: *     or vector Z.
537: *
538: *        Compute residual RES = B_s - op(A_s) * Y,
539: *            op(A) = A, A**T, or A**H depending on TRANS (and type).
540: *
541:          CALL DCOPY( N, B( 1, J ), 1, RES, 1 )
542:          CALL DGBMV(TRANS, N, N, KL, KU, -1.0D+0, AB, LDAB, Y(1,J),
543:      $        1, 1.0D+0, RES, 1 )
544: 
545:          DO I = 1, N
546:             AYB( I ) = ABS( B( I, J ) )
547:          END DO
548: *
549: *     Compute abs(op(A_s))*abs(Y) + abs(B_s).
550: *
551:         CALL DLA_GBAMV( TRANS_TYPE, N, N, KL, KU, 1.0D+0,
552:      $        AB, LDAB, Y(1, J), 1, 1.0D+0, AYB, 1 )
553: 
554:          CALL DLA_LIN_BERR( N, N, 1, RES, AYB, BERR_OUT( J ) )
555: *
556: *     End of loop for each RHS
557: *
558:       END DO
559: *
560:       RETURN
561:       END
562: