00001 SUBROUTINE ZHETRI( UPLO, N, A, LDA, IPIV, WORK, INFO )
00002
00003
00004
00005
00006
00007
00008
00009 CHARACTER UPLO
00010 INTEGER INFO, LDA, N
00011
00012
00013 INTEGER IPIV( * )
00014 COMPLEX*16 A( LDA, * ), WORK( * )
00015
00016
00017
00018
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 DOUBLE PRECISION ONE
00066 COMPLEX*16 CONE, ZERO
00067 PARAMETER ( ONE = 1.0D+0, CONE = ( 1.0D+0, 0.0D+0 ),
00068 $ ZERO = ( 0.0D+0, 0.0D+0 ) )
00069
00070
00071 LOGICAL UPPER
00072 INTEGER J, K, KP, KSTEP
00073 DOUBLE PRECISION AK, AKP1, D, T
00074 COMPLEX*16 AKKP1, TEMP
00075
00076
00077 LOGICAL LSAME
00078 COMPLEX*16 ZDOTC
00079 EXTERNAL LSAME, ZDOTC
00080
00081
00082 EXTERNAL XERBLA, ZCOPY, ZHEMV, ZSWAP
00083
00084
00085 INTRINSIC ABS, DBLE, DCONJG, MAX
00086
00087
00088
00089
00090
00091 INFO = 0
00092 UPPER = LSAME( UPLO, 'U' )
00093 IF( .NOT.UPPER .AND. .NOT.LSAME( UPLO, 'L' ) ) THEN
00094 INFO = -1
00095 ELSE IF( N.LT.0 ) THEN
00096 INFO = -2
00097 ELSE IF( LDA.LT.MAX( 1, N ) ) THEN
00098 INFO = -4
00099 END IF
00100 IF( INFO.NE.0 ) THEN
00101 CALL XERBLA( 'ZHETRI', -INFO )
00102 RETURN
00103 END IF
00104
00105
00106
00107 IF( N.EQ.0 )
00108 $ RETURN
00109
00110
00111
00112 IF( UPPER ) THEN
00113
00114
00115
00116 DO 10 INFO = N, 1, -1
00117 IF( IPIV( INFO ).GT.0 .AND. A( INFO, INFO ).EQ.ZERO )
00118 $ RETURN
00119 10 CONTINUE
00120 ELSE
00121
00122
00123
00124 DO 20 INFO = 1, N
00125 IF( IPIV( INFO ).GT.0 .AND. A( INFO, INFO ).EQ.ZERO )
00126 $ RETURN
00127 20 CONTINUE
00128 END IF
00129 INFO = 0
00130
00131 IF( UPPER ) THEN
00132
00133
00134
00135
00136
00137
00138 K = 1
00139 30 CONTINUE
00140
00141
00142
00143 IF( K.GT.N )
00144 $ GO TO 50
00145
00146 IF( IPIV( K ).GT.0 ) THEN
00147
00148
00149
00150
00151
00152 A( K, K ) = ONE / DBLE( A( K, K ) )
00153
00154
00155
00156 IF( K.GT.1 ) THEN
00157 CALL ZCOPY( K-1, A( 1, K ), 1, WORK, 1 )
00158 CALL ZHEMV( UPLO, K-1, -CONE, A, LDA, WORK, 1, ZERO,
00159 $ A( 1, K ), 1 )
00160 A( K, K ) = A( K, K ) - DBLE( ZDOTC( K-1, WORK, 1, A( 1,
00161 $ K ), 1 ) )
00162 END IF
00163 KSTEP = 1
00164 ELSE
00165
00166
00167
00168
00169
00170 T = ABS( A( K, K+1 ) )
00171 AK = DBLE( A( K, K ) ) / T
00172 AKP1 = DBLE( A( K+1, K+1 ) ) / T
00173 AKKP1 = A( K, K+1 ) / T
00174 D = T*( AK*AKP1-ONE )
00175 A( K, K ) = AKP1 / D
00176 A( K+1, K+1 ) = AK / D
00177 A( K, K+1 ) = -AKKP1 / D
00178
00179
00180
00181 IF( K.GT.1 ) THEN
00182 CALL ZCOPY( K-1, A( 1, K ), 1, WORK, 1 )
00183 CALL ZHEMV( UPLO, K-1, -CONE, A, LDA, WORK, 1, ZERO,
00184 $ A( 1, K ), 1 )
00185 A( K, K ) = A( K, K ) - DBLE( ZDOTC( K-1, WORK, 1, A( 1,
00186 $ K ), 1 ) )
00187 A( K, K+1 ) = A( K, K+1 ) -
00188 $ ZDOTC( K-1, A( 1, K ), 1, A( 1, K+1 ), 1 )
00189 CALL ZCOPY( K-1, A( 1, K+1 ), 1, WORK, 1 )
00190 CALL ZHEMV( UPLO, K-1, -CONE, A, LDA, WORK, 1, ZERO,
00191 $ A( 1, K+1 ), 1 )
00192 A( K+1, K+1 ) = A( K+1, K+1 ) -
00193 $ DBLE( ZDOTC( K-1, WORK, 1, A( 1, K+1 ),
00194 $ 1 ) )
00195 END IF
00196 KSTEP = 2
00197 END IF
00198
00199 KP = ABS( IPIV( K ) )
00200 IF( KP.NE.K ) THEN
00201
00202
00203
00204
00205 CALL ZSWAP( KP-1, A( 1, K ), 1, A( 1, KP ), 1 )
00206 DO 40 J = KP + 1, K - 1
00207 TEMP = DCONJG( A( J, K ) )
00208 A( J, K ) = DCONJG( A( KP, J ) )
00209 A( KP, J ) = TEMP
00210 40 CONTINUE
00211 A( KP, K ) = DCONJG( A( KP, K ) )
00212 TEMP = A( K, K )
00213 A( K, K ) = A( KP, KP )
00214 A( KP, KP ) = TEMP
00215 IF( KSTEP.EQ.2 ) THEN
00216 TEMP = A( K, K+1 )
00217 A( K, K+1 ) = A( KP, K+1 )
00218 A( KP, K+1 ) = TEMP
00219 END IF
00220 END IF
00221
00222 K = K + KSTEP
00223 GO TO 30
00224 50 CONTINUE
00225
00226 ELSE
00227
00228
00229
00230
00231
00232
00233 K = N
00234 60 CONTINUE
00235
00236
00237
00238 IF( K.LT.1 )
00239 $ GO TO 80
00240
00241 IF( IPIV( K ).GT.0 ) THEN
00242
00243
00244
00245
00246
00247 A( K, K ) = ONE / DBLE( A( K, K ) )
00248
00249
00250
00251 IF( K.LT.N ) THEN
00252 CALL ZCOPY( N-K, A( K+1, K ), 1, WORK, 1 )
00253 CALL ZHEMV( UPLO, N-K, -CONE, A( K+1, K+1 ), LDA, WORK,
00254 $ 1, ZERO, A( K+1, K ), 1 )
00255 A( K, K ) = A( K, K ) - DBLE( ZDOTC( N-K, WORK, 1,
00256 $ A( K+1, K ), 1 ) )
00257 END IF
00258 KSTEP = 1
00259 ELSE
00260
00261
00262
00263
00264
00265 T = ABS( A( K, K-1 ) )
00266 AK = DBLE( A( K-1, K-1 ) ) / T
00267 AKP1 = DBLE( A( K, K ) ) / T
00268 AKKP1 = A( K, K-1 ) / T
00269 D = T*( AK*AKP1-ONE )
00270 A( K-1, K-1 ) = AKP1 / D
00271 A( K, K ) = AK / D
00272 A( K, K-1 ) = -AKKP1 / D
00273
00274
00275
00276 IF( K.LT.N ) THEN
00277 CALL ZCOPY( N-K, A( K+1, K ), 1, WORK, 1 )
00278 CALL ZHEMV( UPLO, N-K, -CONE, A( K+1, K+1 ), LDA, WORK,
00279 $ 1, ZERO, A( K+1, K ), 1 )
00280 A( K, K ) = A( K, K ) - DBLE( ZDOTC( N-K, WORK, 1,
00281 $ A( K+1, K ), 1 ) )
00282 A( K, K-1 ) = A( K, K-1 ) -
00283 $ ZDOTC( N-K, A( K+1, K ), 1, A( K+1, K-1 ),
00284 $ 1 )
00285 CALL ZCOPY( N-K, A( K+1, K-1 ), 1, WORK, 1 )
00286 CALL ZHEMV( UPLO, N-K, -CONE, A( K+1, K+1 ), LDA, WORK,
00287 $ 1, ZERO, A( K+1, K-1 ), 1 )
00288 A( K-1, K-1 ) = A( K-1, K-1 ) -
00289 $ DBLE( ZDOTC( N-K, WORK, 1, A( K+1, K-1 ),
00290 $ 1 ) )
00291 END IF
00292 KSTEP = 2
00293 END IF
00294
00295 KP = ABS( IPIV( K ) )
00296 IF( KP.NE.K ) THEN
00297
00298
00299
00300
00301 IF( KP.LT.N )
00302 $ CALL ZSWAP( N-KP, A( KP+1, K ), 1, A( KP+1, KP ), 1 )
00303 DO 70 J = K + 1, KP - 1
00304 TEMP = DCONJG( A( J, K ) )
00305 A( J, K ) = DCONJG( A( KP, J ) )
00306 A( KP, J ) = TEMP
00307 70 CONTINUE
00308 A( KP, K ) = DCONJG( A( KP, K ) )
00309 TEMP = A( K, K )
00310 A( K, K ) = A( KP, KP )
00311 A( KP, KP ) = TEMP
00312 IF( KSTEP.EQ.2 ) THEN
00313 TEMP = A( K, K-1 )
00314 A( K, K-1 ) = A( KP, K-1 )
00315 A( KP, K-1 ) = TEMP
00316 END IF
00317 END IF
00318
00319 K = K - KSTEP
00320 GO TO 60
00321 80 CONTINUE
00322 END IF
00323
00324 RETURN
00325
00326
00327
00328 END