00001 SUBROUTINE ZGTRFS( TRANS, N, NRHS, DL, D, DU, DLF, DF, DUF, DU2,
00002 $ IPIV, B, LDB, X, LDX, FERR, BERR, WORK, RWORK,
00003 $ INFO )
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013 CHARACTER TRANS
00014 INTEGER INFO, LDB, LDX, N, NRHS
00015
00016
00017 INTEGER IPIV( * )
00018 DOUBLE PRECISION BERR( * ), FERR( * ), RWORK( * )
00019 COMPLEX*16 B( LDB, * ), D( * ), DF( * ), DL( * ),
00020 $ DLF( * ), DU( * ), DU2( * ), DUF( * ),
00021 $ WORK( * ), X( LDX, * )
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
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120 INTEGER ITMAX
00121 PARAMETER ( ITMAX = 5 )
00122 DOUBLE PRECISION ZERO, ONE
00123 PARAMETER ( ZERO = 0.0D+0, ONE = 1.0D+0 )
00124 DOUBLE PRECISION TWO
00125 PARAMETER ( TWO = 2.0D+0 )
00126 DOUBLE PRECISION THREE
00127 PARAMETER ( THREE = 3.0D+0 )
00128
00129
00130 LOGICAL NOTRAN
00131 CHARACTER TRANSN, TRANST
00132 INTEGER COUNT, I, J, KASE, NZ
00133 DOUBLE PRECISION EPS, LSTRES, S, SAFE1, SAFE2, SAFMIN
00134 COMPLEX*16 ZDUM
00135
00136
00137 INTEGER ISAVE( 3 )
00138
00139
00140 EXTERNAL XERBLA, ZAXPY, ZCOPY, ZGTTRS, ZLACN2, ZLAGTM
00141
00142
00143 INTRINSIC ABS, DBLE, DCMPLX, DIMAG, MAX
00144
00145
00146 LOGICAL LSAME
00147 DOUBLE PRECISION DLAMCH
00148 EXTERNAL LSAME, DLAMCH
00149
00150
00151 DOUBLE PRECISION CABS1
00152
00153
00154 CABS1( ZDUM ) = ABS( DBLE( ZDUM ) ) + ABS( DIMAG( ZDUM ) )
00155
00156
00157
00158
00159
00160 INFO = 0
00161 NOTRAN = LSAME( TRANS, 'N' )
00162 IF( .NOT.NOTRAN .AND. .NOT.LSAME( TRANS, 'T' ) .AND. .NOT.
00163 $ LSAME( TRANS, 'C' ) ) THEN
00164 INFO = -1
00165 ELSE IF( N.LT.0 ) THEN
00166 INFO = -2
00167 ELSE IF( NRHS.LT.0 ) THEN
00168 INFO = -3
00169 ELSE IF( LDB.LT.MAX( 1, N ) ) THEN
00170 INFO = -13
00171 ELSE IF( LDX.LT.MAX( 1, N ) ) THEN
00172 INFO = -15
00173 END IF
00174 IF( INFO.NE.0 ) THEN
00175 CALL XERBLA( 'ZGTRFS', -INFO )
00176 RETURN
00177 END IF
00178
00179
00180
00181 IF( N.EQ.0 .OR. NRHS.EQ.0 ) THEN
00182 DO 10 J = 1, NRHS
00183 FERR( J ) = ZERO
00184 BERR( J ) = ZERO
00185 10 CONTINUE
00186 RETURN
00187 END IF
00188
00189 IF( NOTRAN ) THEN
00190 TRANSN = 'N'
00191 TRANST = 'C'
00192 ELSE
00193 TRANSN = 'C'
00194 TRANST = 'N'
00195 END IF
00196
00197
00198
00199 NZ = 4
00200 EPS = DLAMCH( 'Epsilon' )
00201 SAFMIN = DLAMCH( 'Safe minimum' )
00202 SAFE1 = NZ*SAFMIN
00203 SAFE2 = SAFE1 / EPS
00204
00205
00206
00207 DO 110 J = 1, NRHS
00208
00209 COUNT = 1
00210 LSTRES = THREE
00211 20 CONTINUE
00212
00213
00214
00215
00216
00217
00218 CALL ZCOPY( N, B( 1, J ), 1, WORK, 1 )
00219 CALL ZLAGTM( TRANS, N, 1, -ONE, DL, D, DU, X( 1, J ), LDX, ONE,
00220 $ WORK, N )
00221
00222
00223
00224
00225 IF( NOTRAN ) THEN
00226 IF( N.EQ.1 ) THEN
00227 RWORK( 1 ) = CABS1( B( 1, J ) ) +
00228 $ CABS1( D( 1 ) )*CABS1( X( 1, J ) )
00229 ELSE
00230 RWORK( 1 ) = CABS1( B( 1, J ) ) +
00231 $ CABS1( D( 1 ) )*CABS1( X( 1, J ) ) +
00232 $ CABS1( DU( 1 ) )*CABS1( X( 2, J ) )
00233 DO 30 I = 2, N - 1
00234 RWORK( I ) = CABS1( B( I, J ) ) +
00235 $ CABS1( DL( I-1 ) )*CABS1( X( I-1, J ) ) +
00236 $ CABS1( D( I ) )*CABS1( X( I, J ) ) +
00237 $ CABS1( DU( I ) )*CABS1( X( I+1, J ) )
00238 30 CONTINUE
00239 RWORK( N ) = CABS1( B( N, J ) ) +
00240 $ CABS1( DL( N-1 ) )*CABS1( X( N-1, J ) ) +
00241 $ CABS1( D( N ) )*CABS1( X( N, J ) )
00242 END IF
00243 ELSE
00244 IF( N.EQ.1 ) THEN
00245 RWORK( 1 ) = CABS1( B( 1, J ) ) +
00246 $ CABS1( D( 1 ) )*CABS1( X( 1, J ) )
00247 ELSE
00248 RWORK( 1 ) = CABS1( B( 1, J ) ) +
00249 $ CABS1( D( 1 ) )*CABS1( X( 1, J ) ) +
00250 $ CABS1( DL( 1 ) )*CABS1( X( 2, J ) )
00251 DO 40 I = 2, N - 1
00252 RWORK( I ) = CABS1( B( I, J ) ) +
00253 $ CABS1( DU( I-1 ) )*CABS1( X( I-1, J ) ) +
00254 $ CABS1( D( I ) )*CABS1( X( I, J ) ) +
00255 $ CABS1( DL( I ) )*CABS1( X( I+1, J ) )
00256 40 CONTINUE
00257 RWORK( N ) = CABS1( B( N, J ) ) +
00258 $ CABS1( DU( N-1 ) )*CABS1( X( N-1, J ) ) +
00259 $ CABS1( D( N ) )*CABS1( X( N, J ) )
00260 END IF
00261 END IF
00262
00263
00264
00265
00266
00267
00268
00269
00270
00271
00272 S = ZERO
00273 DO 50 I = 1, N
00274 IF( RWORK( I ).GT.SAFE2 ) THEN
00275 S = MAX( S, CABS1( WORK( I ) ) / RWORK( I ) )
00276 ELSE
00277 S = MAX( S, ( CABS1( WORK( I ) )+SAFE1 ) /
00278 $ ( RWORK( I )+SAFE1 ) )
00279 END IF
00280 50 CONTINUE
00281 BERR( J ) = S
00282
00283
00284
00285
00286
00287
00288
00289 IF( BERR( J ).GT.EPS .AND. TWO*BERR( J ).LE.LSTRES .AND.
00290 $ COUNT.LE.ITMAX ) THEN
00291
00292
00293
00294 CALL ZGTTRS( TRANS, N, 1, DLF, DF, DUF, DU2, IPIV, WORK, N,
00295 $ INFO )
00296 CALL ZAXPY( N, DCMPLX( ONE ), WORK, 1, X( 1, J ), 1 )
00297 LSTRES = BERR( J )
00298 COUNT = COUNT + 1
00299 GO TO 20
00300 END IF
00301
00302
00303
00304
00305
00306
00307
00308
00309
00310
00311
00312
00313
00314
00315
00316
00317
00318
00319
00320
00321
00322
00323
00324 DO 60 I = 1, N
00325 IF( RWORK( I ).GT.SAFE2 ) THEN
00326 RWORK( I ) = CABS1( WORK( I ) ) + NZ*EPS*RWORK( I )
00327 ELSE
00328 RWORK( I ) = CABS1( WORK( I ) ) + NZ*EPS*RWORK( I ) +
00329 $ SAFE1
00330 END IF
00331 60 CONTINUE
00332
00333 KASE = 0
00334 70 CONTINUE
00335 CALL ZLACN2( N, WORK( N+1 ), WORK, FERR( J ), KASE, ISAVE )
00336 IF( KASE.NE.0 ) THEN
00337 IF( KASE.EQ.1 ) THEN
00338
00339
00340
00341 CALL ZGTTRS( TRANST, N, 1, DLF, DF, DUF, DU2, IPIV, WORK,
00342 $ N, INFO )
00343 DO 80 I = 1, N
00344 WORK( I ) = RWORK( I )*WORK( I )
00345 80 CONTINUE
00346 ELSE
00347
00348
00349
00350 DO 90 I = 1, N
00351 WORK( I ) = RWORK( I )*WORK( I )
00352 90 CONTINUE
00353 CALL ZGTTRS( TRANSN, N, 1, DLF, DF, DUF, DU2, IPIV, WORK,
00354 $ N, INFO )
00355 END IF
00356 GO TO 70
00357 END IF
00358
00359
00360
00361 LSTRES = ZERO
00362 DO 100 I = 1, N
00363 LSTRES = MAX( LSTRES, CABS1( X( I, J ) ) )
00364 100 CONTINUE
00365 IF( LSTRES.NE.ZERO )
00366 $ FERR( J ) = FERR( J ) / LSTRES
00367
00368 110 CONTINUE
00369
00370 RETURN
00371
00372
00373
00374 END