00001 SUBROUTINE CTBRFS( UPLO, TRANS, DIAG, N, KD, NRHS, AB, LDAB, B,
00002 $ LDB, X, LDX, FERR, BERR, WORK, RWORK, INFO )
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 CHARACTER DIAG, TRANS, UPLO
00013 INTEGER INFO, KD, LDAB, LDB, LDX, N, NRHS
00014
00015
00016 REAL BERR( * ), FERR( * ), RWORK( * )
00017 COMPLEX AB( LDAB, * ), B( LDB, * ), WORK( * ),
00018 $ X( LDX, * )
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110 REAL ZERO
00111 PARAMETER ( ZERO = 0.0E+0 )
00112 COMPLEX ONE
00113 PARAMETER ( ONE = ( 1.0E+0, 0.0E+0 ) )
00114
00115
00116 LOGICAL NOTRAN, NOUNIT, UPPER
00117 CHARACTER TRANSN, TRANST
00118 INTEGER I, J, K, KASE, NZ
00119 REAL EPS, LSTRES, S, SAFE1, SAFE2, SAFMIN, XK
00120 COMPLEX ZDUM
00121
00122
00123 INTEGER ISAVE( 3 )
00124
00125
00126 EXTERNAL CAXPY, CCOPY, CLACN2, CTBMV, CTBSV, XERBLA
00127
00128
00129 INTRINSIC ABS, AIMAG, MAX, MIN, REAL
00130
00131
00132 LOGICAL LSAME
00133 REAL SLAMCH
00134 EXTERNAL LSAME, SLAMCH
00135
00136
00137 REAL CABS1
00138
00139
00140 CABS1( ZDUM ) = ABS( REAL( ZDUM ) ) + ABS( AIMAG( ZDUM ) )
00141
00142
00143
00144
00145
00146 INFO = 0
00147 UPPER = LSAME( UPLO, 'U' )
00148 NOTRAN = LSAME( TRANS, 'N' )
00149 NOUNIT = LSAME( DIAG, 'N' )
00150
00151 IF( .NOT.UPPER .AND. .NOT.LSAME( UPLO, 'L' ) ) THEN
00152 INFO = -1
00153 ELSE IF( .NOT.NOTRAN .AND. .NOT.LSAME( TRANS, 'T' ) .AND. .NOT.
00154 $ LSAME( TRANS, 'C' ) ) THEN
00155 INFO = -2
00156 ELSE IF( .NOT.NOUNIT .AND. .NOT.LSAME( DIAG, 'U' ) ) THEN
00157 INFO = -3
00158 ELSE IF( N.LT.0 ) THEN
00159 INFO = -4
00160 ELSE IF( KD.LT.0 ) THEN
00161 INFO = -5
00162 ELSE IF( NRHS.LT.0 ) THEN
00163 INFO = -6
00164 ELSE IF( LDAB.LT.KD+1 ) THEN
00165 INFO = -8
00166 ELSE IF( LDB.LT.MAX( 1, N ) ) THEN
00167 INFO = -10
00168 ELSE IF( LDX.LT.MAX( 1, N ) ) THEN
00169 INFO = -12
00170 END IF
00171 IF( INFO.NE.0 ) THEN
00172 CALL XERBLA( 'CTBRFS', -INFO )
00173 RETURN
00174 END IF
00175
00176
00177
00178 IF( N.EQ.0 .OR. NRHS.EQ.0 ) THEN
00179 DO 10 J = 1, NRHS
00180 FERR( J ) = ZERO
00181 BERR( J ) = ZERO
00182 10 CONTINUE
00183 RETURN
00184 END IF
00185
00186 IF( NOTRAN ) THEN
00187 TRANSN = 'N'
00188 TRANST = 'C'
00189 ELSE
00190 TRANSN = 'C'
00191 TRANST = 'N'
00192 END IF
00193
00194
00195
00196 NZ = KD + 2
00197 EPS = SLAMCH( 'Epsilon' )
00198 SAFMIN = SLAMCH( 'Safe minimum' )
00199 SAFE1 = NZ*SAFMIN
00200 SAFE2 = SAFE1 / EPS
00201
00202
00203
00204 DO 250 J = 1, NRHS
00205
00206
00207
00208
00209 CALL CCOPY( N, X( 1, J ), 1, WORK, 1 )
00210 CALL CTBMV( UPLO, TRANS, DIAG, N, KD, AB, LDAB, WORK, 1 )
00211 CALL CAXPY( N, -ONE, B( 1, J ), 1, WORK, 1 )
00212
00213
00214
00215
00216
00217
00218
00219
00220
00221
00222 DO 20 I = 1, N
00223 RWORK( I ) = CABS1( B( I, J ) )
00224 20 CONTINUE
00225
00226 IF( NOTRAN ) THEN
00227
00228
00229
00230 IF( UPPER ) THEN
00231 IF( NOUNIT ) THEN
00232 DO 40 K = 1, N
00233 XK = CABS1( X( K, J ) )
00234 DO 30 I = MAX( 1, K-KD ), K
00235 RWORK( I ) = RWORK( I ) +
00236 $ CABS1( AB( KD+1+I-K, K ) )*XK
00237 30 CONTINUE
00238 40 CONTINUE
00239 ELSE
00240 DO 60 K = 1, N
00241 XK = CABS1( X( K, J ) )
00242 DO 50 I = MAX( 1, K-KD ), K - 1
00243 RWORK( I ) = RWORK( I ) +
00244 $ CABS1( AB( KD+1+I-K, K ) )*XK
00245 50 CONTINUE
00246 RWORK( K ) = RWORK( K ) + XK
00247 60 CONTINUE
00248 END IF
00249 ELSE
00250 IF( NOUNIT ) THEN
00251 DO 80 K = 1, N
00252 XK = CABS1( X( K, J ) )
00253 DO 70 I = K, MIN( N, K+KD )
00254 RWORK( I ) = RWORK( I ) +
00255 $ CABS1( AB( 1+I-K, K ) )*XK
00256 70 CONTINUE
00257 80 CONTINUE
00258 ELSE
00259 DO 100 K = 1, N
00260 XK = CABS1( X( K, J ) )
00261 DO 90 I = K + 1, MIN( N, K+KD )
00262 RWORK( I ) = RWORK( I ) +
00263 $ CABS1( AB( 1+I-K, K ) )*XK
00264 90 CONTINUE
00265 RWORK( K ) = RWORK( K ) + XK
00266 100 CONTINUE
00267 END IF
00268 END IF
00269 ELSE
00270
00271
00272
00273 IF( UPPER ) THEN
00274 IF( NOUNIT ) THEN
00275 DO 120 K = 1, N
00276 S = ZERO
00277 DO 110 I = MAX( 1, K-KD ), K
00278 S = S + CABS1( AB( KD+1+I-K, K ) )*
00279 $ CABS1( X( I, J ) )
00280 110 CONTINUE
00281 RWORK( K ) = RWORK( K ) + S
00282 120 CONTINUE
00283 ELSE
00284 DO 140 K = 1, N
00285 S = CABS1( X( K, J ) )
00286 DO 130 I = MAX( 1, K-KD ), K - 1
00287 S = S + CABS1( AB( KD+1+I-K, K ) )*
00288 $ CABS1( X( I, J ) )
00289 130 CONTINUE
00290 RWORK( K ) = RWORK( K ) + S
00291 140 CONTINUE
00292 END IF
00293 ELSE
00294 IF( NOUNIT ) THEN
00295 DO 160 K = 1, N
00296 S = ZERO
00297 DO 150 I = K, MIN( N, K+KD )
00298 S = S + CABS1( AB( 1+I-K, K ) )*
00299 $ CABS1( X( I, J ) )
00300 150 CONTINUE
00301 RWORK( K ) = RWORK( K ) + S
00302 160 CONTINUE
00303 ELSE
00304 DO 180 K = 1, N
00305 S = CABS1( X( K, J ) )
00306 DO 170 I = K + 1, MIN( N, K+KD )
00307 S = S + CABS1( AB( 1+I-K, K ) )*
00308 $ CABS1( X( I, J ) )
00309 170 CONTINUE
00310 RWORK( K ) = RWORK( K ) + S
00311 180 CONTINUE
00312 END IF
00313 END IF
00314 END IF
00315 S = ZERO
00316 DO 190 I = 1, N
00317 IF( RWORK( I ).GT.SAFE2 ) THEN
00318 S = MAX( S, CABS1( WORK( I ) ) / RWORK( I ) )
00319 ELSE
00320 S = MAX( S, ( CABS1( WORK( I ) )+SAFE1 ) /
00321 $ ( RWORK( I )+SAFE1 ) )
00322 END IF
00323 190 CONTINUE
00324 BERR( J ) = S
00325
00326
00327
00328
00329
00330
00331
00332
00333
00334
00335
00336
00337
00338
00339
00340
00341
00342
00343
00344
00345
00346
00347
00348 DO 200 I = 1, N
00349 IF( RWORK( I ).GT.SAFE2 ) THEN
00350 RWORK( I ) = CABS1( WORK( I ) ) + NZ*EPS*RWORK( I )
00351 ELSE
00352 RWORK( I ) = CABS1( WORK( I ) ) + NZ*EPS*RWORK( I ) +
00353 $ SAFE1
00354 END IF
00355 200 CONTINUE
00356
00357 KASE = 0
00358 210 CONTINUE
00359 CALL CLACN2( N, WORK( N+1 ), WORK, FERR( J ), KASE, ISAVE )
00360 IF( KASE.NE.0 ) THEN
00361 IF( KASE.EQ.1 ) THEN
00362
00363
00364
00365 CALL CTBSV( UPLO, TRANST, DIAG, N, KD, AB, LDAB, WORK,
00366 $ 1 )
00367 DO 220 I = 1, N
00368 WORK( I ) = RWORK( I )*WORK( I )
00369 220 CONTINUE
00370 ELSE
00371
00372
00373
00374 DO 230 I = 1, N
00375 WORK( I ) = RWORK( I )*WORK( I )
00376 230 CONTINUE
00377 CALL CTBSV( UPLO, TRANSN, DIAG, N, KD, AB, LDAB, WORK,
00378 $ 1 )
00379 END IF
00380 GO TO 210
00381 END IF
00382
00383
00384
00385 LSTRES = ZERO
00386 DO 240 I = 1, N
00387 LSTRES = MAX( LSTRES, CABS1( X( I, J ) ) )
00388 240 CONTINUE
00389 IF( LSTRES.NE.ZERO )
00390 $ FERR( J ) = FERR( J ) / LSTRES
00391
00392 250 CONTINUE
00393
00394 RETURN
00395
00396
00397
00398 END