00001 SUBROUTINE CHETRI( 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 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 REAL ONE
00066 COMPLEX CONE, ZERO
00067 PARAMETER ( ONE = 1.0E+0, CONE = ( 1.0E+0, 0.0E+0 ),
00068 $ ZERO = ( 0.0E+0, 0.0E+0 ) )
00069
00070
00071 LOGICAL UPPER
00072 INTEGER J, K, KP, KSTEP
00073 REAL AK, AKP1, D, T
00074 COMPLEX AKKP1, TEMP
00075
00076
00077 LOGICAL LSAME
00078 COMPLEX CDOTC
00079 EXTERNAL LSAME, CDOTC
00080
00081
00082 EXTERNAL CCOPY, CHEMV, CSWAP, XERBLA
00083
00084
00085 INTRINSIC ABS, CONJG, MAX, REAL
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( 'CHETRI', -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 / REAL( A( K, K ) )
00153
00154
00155
00156 IF( K.GT.1 ) THEN
00157 CALL CCOPY( K-1, A( 1, K ), 1, WORK, 1 )
00158 CALL CHEMV( UPLO, K-1, -CONE, A, LDA, WORK, 1, ZERO,
00159 $ A( 1, K ), 1 )
00160 A( K, K ) = A( K, K ) - REAL( CDOTC( K-1, WORK, 1, A( 1,
$ K ), 1 ) )
00161 END IF
00162 KSTEP = 1
00163 ELSE
00164
00165
00166
00167
00168
00169 T = ABS( A( K, K+1 ) )
00170 AK = REAL( A( K, K ) ) / T
00171 AKP1 = REAL( A( K+1, K+1 ) ) / T
00172 AKKP1 = A( K, K+1 ) / T
00173 D = T*( AK*AKP1-ONE )
00174 A( K, K ) = AKP1 / D
00175 A( K+1, K+1 ) = AK / D
00176 A( K, K+1 ) = -AKKP1 / D
00177
00178
00179
00180 IF( K.GT.1 ) THEN
00181 CALL CCOPY( K-1, A( 1, K ), 1, WORK, 1 )
00182 CALL CHEMV( UPLO, K-1, -CONE, A, LDA, WORK, 1, ZERO,
00183 $ A( 1, K ), 1 )
00184 A( K, K ) = A( K, K ) - REAL( CDOTC( K-1, WORK, 1, A( 1,
$ K ), 1 ) )
00185 A( K, K+1 ) = A( K, K+1 ) -
00186 $ CDOTC( K-1, A( 1, K ), 1, A( 1, K+1 ), 1 )
00187 CALL CCOPY( K-1, A( 1, K+1 ), 1, WORK, 1 )
00188 CALL CHEMV( UPLO, K-1, -CONE, A, LDA, WORK, 1, ZERO,
00189 $ A( 1, K+1 ), 1 )
00190 A( K+1, K+1 ) = A( K+1, K+1 ) -
00191 $ REAL( CDOTC( K-1, WORK, 1, A( 1, K+1 ),
00192 $ 1 ) )
00193 END IF
00194 KSTEP = 2
00195 END IF
00196
00197 KP = ABS( IPIV( K ) )
00198 IF( KP.NE.K ) THEN
00199
00200
00201
00202
00203 CALL CSWAP( KP-1, A( 1, K ), 1, A( 1, KP ), 1 )
00204 DO 40 J = KP + 1, K - 1
00205 TEMP = CONJG( A( J, K ) )
00206 A( J, K ) = CONJG( A( KP, J ) )
00207 A( KP, J ) = TEMP
00208 40 CONTINUE
00209 A( KP, K ) = CONJG( A( KP, K ) )
00210 TEMP = A( K, K )
00211 A( K, K ) = A( KP, KP )
00212 A( KP, KP ) = TEMP
00213 IF( KSTEP.EQ.2 ) THEN
00214 TEMP = A( K, K+1 )
00215 A( K, K+1 ) = A( KP, K+1 )
00216 A( KP, K+1 ) = TEMP
00217 END IF
00218 END IF
00219
00220 K = K + KSTEP
00221 GO TO 30
00222 50 CONTINUE
00223
00224 ELSE
00225
00226
00227
00228
00229
00230
00231 K = N
00232 60 CONTINUE
00233
00234
00235
00236 IF( K.LT.1 )
00237 $ GO TO 80
00238
00239 IF( IPIV( K ).GT.0 ) THEN
00240
00241
00242
00243
00244
00245 A( K, K ) = ONE / REAL( A( K, K ) )
00246
00247
00248
00249 IF( K.LT.N ) THEN
00250 CALL CCOPY( N-K, A( K+1, K ), 1, WORK, 1 )
00251 CALL CHEMV( UPLO, N-K, -CONE, A( K+1, K+1 ), LDA, WORK,
00252 $ 1, ZERO, A( K+1, K ), 1 )
00253 A( K, K ) = A( K, K ) - REAL( CDOTC( N-K, WORK, 1,
$ A( K+1, K ), 1 ) )
00254 END IF
00255 KSTEP = 1
00256 ELSE
00257
00258
00259
00260
00261
00262 T = ABS( A( K, K-1 ) )
00263 AK = REAL( A( K-1, K-1 ) ) / T
00264 AKP1 = REAL( A( K, K ) ) / T
00265 AKKP1 = A( K, K-1 ) / T
00266 D = T*( AK*AKP1-ONE )
00267 A( K-1, K-1 ) = AKP1 / D
00268 A( K, K ) = AK / D
00269 A( K, K-1 ) = -AKKP1 / D
00270
00271
00272
00273 IF( K.LT.N ) THEN
00274 CALL CCOPY( N-K, A( K+1, K ), 1, WORK, 1 )
00275 CALL CHEMV( UPLO, N-K, -CONE, A( K+1, K+1 ), LDA, WORK,
00276 $ 1, ZERO, A( K+1, K ), 1 )
00277 A( K, K ) = A( K, K ) - REAL( CDOTC( N-K, WORK, 1,
$ A( K+1, K ), 1 ) )
00278 A( K, K-1 ) = A( K, K-1 ) -
00279 $ CDOTC( N-K, A( K+1, K ), 1, A( K+1, K-1 ),
00280 $ 1 )
00281 CALL CCOPY( N-K, A( K+1, K-1 ), 1, WORK, 1 )
00282 CALL CHEMV( UPLO, N-K, -CONE, A( K+1, K+1 ), LDA, WORK,
00283 $ 1, ZERO, A( K+1, K-1 ), 1 )
00284 A( K-1, K-1 ) = A( K-1, K-1 ) -
00285 $ REAL( CDOTC( N-K, WORK, 1, A( K+1, K-1 ),
00286 $ 1 ) )
00287 END IF
00288 KSTEP = 2
00289 END IF
00290
00291 KP = ABS( IPIV( K ) )
00292 IF( KP.NE.K ) THEN
00293
00294
00295
00296
00297 IF( KP.LT.N )
00298 $ CALL CSWAP( N-KP, A( KP+1, K ), 1, A( KP+1, KP ), 1 )
00299 DO 70 J = K + 1, KP - 1
00300 TEMP = CONJG( A( J, K ) )
00301 A( J, K ) = CONJG( A( KP, J ) )
00302 A( KP, J ) = TEMP
00303 70 CONTINUE
00304 A( KP, K ) = CONJG( A( KP, K ) )
00305 TEMP = A( K, K )
00306 A( K, K ) = A( KP, KP )
00307 A( KP, KP ) = TEMP
00308 IF( KSTEP.EQ.2 ) THEN
00309 TEMP = A( K, K-1 )
00310 A( K, K-1 ) = A( KP, K-1 )
00311 A( KP, K-1 ) = TEMP
00312 END IF
00313 END IF
00314
00315 K = K - KSTEP
00316 GO TO 60
00317 80 CONTINUE
00318 END IF
00319
00320 RETURN
00321
00322
00323
00324 END
00325