126
127
128
129
130
131
132 CHARACTER UPLO
133 INTEGER INFO, LDA, N
134
135
136 INTEGER IPIV( * )
137 COMPLEX*16 A( LDA, * ), WORK( * )
138
139
140
141
142
143 DOUBLE PRECISION ONE
144 COMPLEX*16 CONE, CZERO
145 parameter( one = 1.0d+0, cone = ( 1.0d+0, 0.0d+0 ),
146 $ czero = ( 0.0d+0, 0.0d+0 ) )
147
148
149 LOGICAL UPPER
150 INTEGER J, K, KP, KSTEP
151 DOUBLE PRECISION AK, AKP1, D, T
152 COMPLEX*16 AKKP1, TEMP
153
154
155 LOGICAL LSAME
156 COMPLEX*16 ZDOTC
158
159
161
162
163 INTRINSIC abs, dconjg, max, dble
164
165
166
167
168
169 info = 0
170 upper =
lsame( uplo,
'U' )
171 IF( .NOT.upper .AND. .NOT.
lsame( uplo,
'L' ) )
THEN
172 info = -1
173 ELSE IF( n.LT.0 ) THEN
174 info = -2
175 ELSE IF( lda.LT.max( 1, n ) ) THEN
176 info = -4
177 END IF
178 IF( info.NE.0 ) THEN
179 CALL xerbla(
'ZHETRI_ROOK', -info )
180 RETURN
181 END IF
182
183
184
185 IF( n.EQ.0 )
186 $ RETURN
187
188
189
190 IF( upper ) THEN
191
192
193
194 DO 10 info = n, 1, -1
195 IF( ipiv( info ).GT.0 .AND. a( info, info ).EQ.czero )
196 $ RETURN
197 10 CONTINUE
198 ELSE
199
200
201
202 DO 20 info = 1, n
203 IF( ipiv( info ).GT.0 .AND. a( info, info ).EQ.czero )
204 $ RETURN
205 20 CONTINUE
206 END IF
207 info = 0
208
209 IF( upper ) THEN
210
211
212
213
214
215
216 k = 1
217 30 CONTINUE
218
219
220
221 IF( k.GT.n )
222 $ GO TO 70
223
224 IF( ipiv( k ).GT.0 ) THEN
225
226
227
228
229
230 a( k, k ) = one / dble( a( k, k ) )
231
232
233
234 IF( k.GT.1 ) THEN
235 CALL zcopy( k-1, a( 1, k ), 1, work, 1 )
236 CALL zhemv( uplo, k-1, -cone, a, lda, work, 1, czero,
237 $ a( 1, k ), 1 )
238 a( k, k ) = a( k, k ) - dble(
zdotc( k-1, work, 1,
239 $ a( 1,
240 $ k ), 1 ) )
241 END IF
242 kstep = 1
243 ELSE
244
245
246
247
248
249 t = abs( a( k, k+1 ) )
250 ak = dble( a( k, k ) ) / t
251 akp1 = dble( a( k+1, k+1 ) ) / t
252 akkp1 = a( k, k+1 ) / t
253 d = t*( ak*akp1-one )
254 a( k, k ) = akp1 / d
255 a( k+1, k+1 ) = ak / d
256 a( k, k+1 ) = -akkp1 / d
257
258
259
260 IF( k.GT.1 ) THEN
261 CALL zcopy( k-1, a( 1, k ), 1, work, 1 )
262 CALL zhemv( uplo, k-1, -cone, a, lda, work, 1, czero,
263 $ a( 1, k ), 1 )
264 a( k, k ) = a( k, k ) - dble(
zdotc( k-1, work, 1,
265 $ a( 1,
266 $ k ), 1 ) )
267 a( k, k+1 ) = a( k, k+1 ) -
268 $
zdotc( k-1, a( 1, k ), 1, a( 1, k+1 ),
269 $ 1 )
270 CALL zcopy( k-1, a( 1, k+1 ), 1, work, 1 )
271 CALL zhemv( uplo, k-1, -cone, a, lda, work, 1, czero,
272 $ a( 1, k+1 ), 1 )
273 a( k+1, k+1 ) = a( k+1, k+1 ) -
274 $ dble(
zdotc( k-1, work, 1, a( 1,
275 $ k+1 ),
276 $ 1 ) )
277 END IF
278 kstep = 2
279 END IF
280
281 IF( kstep.EQ.1 ) THEN
282
283
284
285
286 kp = ipiv( k )
287 IF( kp.NE.k ) THEN
288
289 IF( kp.GT.1 )
290 $
CALL zswap( kp-1, a( 1, k ), 1, a( 1, kp ), 1 )
291
292 DO 40 j = kp + 1, k - 1
293 temp = dconjg( a( j, k ) )
294 a( j, k ) = dconjg( a( kp, j ) )
295 a( kp, j ) = temp
296 40 CONTINUE
297
298 a( kp, k ) = dconjg( a( kp, k ) )
299
300 temp = a( k, k )
301 a( k, k ) = a( kp, kp )
302 a( kp, kp ) = temp
303 END IF
304 ELSE
305
306
307
308
309
310
311 kp = -ipiv( k )
312 IF( kp.NE.k ) THEN
313
314 IF( kp.GT.1 )
315 $
CALL zswap( kp-1, a( 1, k ), 1, a( 1, kp ), 1 )
316
317 DO 50 j = kp + 1, k - 1
318 temp = dconjg( a( j, k ) )
319 a( j, k ) = dconjg( a( kp, j ) )
320 a( kp, j ) = temp
321 50 CONTINUE
322
323 a( kp, k ) = dconjg( a( kp, k ) )
324
325 temp = a( k, k )
326 a( k, k ) = a( kp, kp )
327 a( kp, kp ) = temp
328
329 temp = a( k, k+1 )
330 a( k, k+1 ) = a( kp, k+1 )
331 a( kp, k+1 ) = temp
332 END IF
333
334
335
336 k = k + 1
337 kp = -ipiv( k )
338 IF( kp.NE.k ) THEN
339
340 IF( kp.GT.1 )
341 $
CALL zswap( kp-1, a( 1, k ), 1, a( 1, kp ), 1 )
342
343 DO 60 j = kp + 1, k - 1
344 temp = dconjg( a( j, k ) )
345 a( j, k ) = dconjg( a( kp, j ) )
346 a( kp, j ) = temp
347 60 CONTINUE
348
349 a( kp, k ) = dconjg( a( kp, k ) )
350
351 temp = a( k, k )
352 a( k, k ) = a( kp, kp )
353 a( kp, kp ) = temp
354 END IF
355 END IF
356
357 k = k + 1
358 GO TO 30
359 70 CONTINUE
360
361 ELSE
362
363
364
365
366
367
368 k = n
369 80 CONTINUE
370
371
372
373 IF( k.LT.1 )
374 $ GO TO 120
375
376 IF( ipiv( k ).GT.0 ) THEN
377
378
379
380
381
382 a( k, k ) = one / dble( a( k, k ) )
383
384
385
386 IF( k.LT.n ) THEN
387 CALL zcopy( n-k, a( k+1, k ), 1, work, 1 )
388 CALL zhemv( uplo, n-k, -cone, a( k+1, k+1 ), lda,
389 $ work,
390 $ 1, czero, a( k+1, k ), 1 )
391 a( k, k ) = a( k, k ) - dble(
zdotc( n-k, work, 1,
392 $ a( k+1, k ), 1 ) )
393 END IF
394 kstep = 1
395 ELSE
396
397
398
399
400
401 t = abs( a( k, k-1 ) )
402 ak = dble( a( k-1, k-1 ) ) / t
403 akp1 = dble( a( k, k ) ) / t
404 akkp1 = a( k, k-1 ) / t
405 d = t*( ak*akp1-one )
406 a( k-1, k-1 ) = akp1 / d
407 a( k, k ) = ak / d
408 a( k, k-1 ) = -akkp1 / d
409
410
411
412 IF( k.LT.n ) THEN
413 CALL zcopy( n-k, a( k+1, k ), 1, work, 1 )
414 CALL zhemv( uplo, n-k, -cone, a( k+1, k+1 ), lda,
415 $ work,
416 $ 1, czero, a( k+1, k ), 1 )
417 a( k, k ) = a( k, k ) - dble(
zdotc( n-k, work, 1,
418 $ a( k+1, k ), 1 ) )
419 a( k, k-1 ) = a( k, k-1 ) -
420 $
zdotc( n-k, a( k+1, k ), 1, a( k+1,
421 $ k-1 ),
422 $ 1 )
423 CALL zcopy( n-k, a( k+1, k-1 ), 1, work, 1 )
424 CALL zhemv( uplo, n-k, -cone, a( k+1, k+1 ), lda,
425 $ work,
426 $ 1, czero, a( k+1, k-1 ), 1 )
427 a( k-1, k-1 ) = a( k-1, k-1 ) -
428 $ dble(
zdotc( n-k, work, 1, a( k+1,
429 $ k-1 ),
430 $ 1 ) )
431 END IF
432 kstep = 2
433 END IF
434
435 IF( kstep.EQ.1 ) THEN
436
437
438
439
440 kp = ipiv( k )
441 IF( kp.NE.k ) THEN
442
443 IF( kp.LT.n )
444 $
CALL zswap( n-kp, a( kp+1, k ), 1, a( kp+1, kp ),
445 $ 1 )
446
447 DO 90 j = k + 1, kp - 1
448 temp = dconjg( a( j, k ) )
449 a( j, k ) = dconjg( a( kp, j ) )
450 a( kp, j ) = temp
451 90 CONTINUE
452
453 a( kp, k ) = dconjg( a( kp, k ) )
454
455 temp = a( k, k )
456 a( k, k ) = a( kp, kp )
457 a( kp, kp ) = temp
458 END IF
459 ELSE
460
461
462
463
464
465
466 kp = -ipiv( k )
467 IF( kp.NE.k ) THEN
468
469 IF( kp.LT.n )
470 $
CALL zswap( n-kp, a( kp+1, k ), 1, a( kp+1, kp ),
471 $ 1 )
472
473 DO 100 j = k + 1, kp - 1
474 temp = dconjg( a( j, k ) )
475 a( j, k ) = dconjg( a( kp, j ) )
476 a( kp, j ) = temp
477 100 CONTINUE
478
479 a( kp, k ) = dconjg( a( kp, k ) )
480
481 temp = a( k, k )
482 a( k, k ) = a( kp, kp )
483 a( kp, kp ) = temp
484
485 temp = a( k, k-1 )
486 a( k, k-1 ) = a( kp, k-1 )
487 a( kp, k-1 ) = temp
488 END IF
489
490
491
492 k = k - 1
493 kp = -ipiv( k )
494 IF( kp.NE.k ) THEN
495
496 IF( kp.LT.n )
497 $
CALL zswap( n-kp, a( kp+1, k ), 1, a( kp+1, kp ),
498 $ 1 )
499
500 DO 110 j = k + 1, kp - 1
501 temp = dconjg( a( j, k ) )
502 a( j, k ) = dconjg( a( kp, j ) )
503 a( kp, j ) = temp
504 110 CONTINUE
505
506 a( kp, k ) = dconjg( a( kp, k ) )
507
508 temp = a( k, k )
509 a( k, k ) = a( kp, kp )
510 a( kp, kp ) = temp
511 END IF
512 END IF
513
514 k = k - 1
515 GO TO 80
516 120 CONTINUE
517 END IF
518
519 RETURN
520
521
522
subroutine xerbla(srname, info)
subroutine zcopy(n, zx, incx, zy, incy)
ZCOPY
complex *16 function zdotc(n, zx, incx, zy, incy)
ZDOTC
subroutine zhemv(uplo, n, alpha, a, lda, x, incx, beta, y, incy)
ZHEMV
logical function lsame(ca, cb)
LSAME
subroutine zswap(n, zx, incx, zy, incy)
ZSWAP