192
193
194
195
196
197
198 CHARACTER UPLO
199 INTEGER INFO, LDA, N
200
201
202 INTEGER IPIV( * )
203 COMPLEX*16 A( LDA, * )
204
205
206
207
208
209 DOUBLE PRECISION ZERO, ONE
210 parameter( zero = 0.0d+0, one = 1.0d+0 )
211 DOUBLE PRECISION EIGHT, SEVTEN
212 parameter( eight = 8.0d+0, sevten = 17.0d+0 )
213
214
215 LOGICAL DONE, UPPER
216 INTEGER I, II, IMAX, ITEMP, J, JMAX, K, KK, KP, KSTEP,
217 $ P
218 DOUBLE PRECISION ABSAKK, ALPHA, COLMAX, D, D11, D22, R1, DTEMP,
219 $ ROWMAX, TT, SFMIN
220 COMPLEX*16 D12, D21, T, WK, WKM1, WKP1, Z
221
222
223
224 LOGICAL LSAME
225 INTEGER IZAMAX
226 DOUBLE PRECISION DLAMCH, DLAPY2
228
229
231
232
233 INTRINSIC abs, dble, dcmplx, dconjg, dimag, max, sqrt
234
235
236 DOUBLE PRECISION CABS1
237
238
239 cabs1( z ) = abs( dble( z ) ) + abs( dimag( z ) )
240
241
242
243
244
245 info = 0
246 upper =
lsame( uplo,
'U' )
247 IF( .NOT.upper .AND. .NOT.
lsame( uplo,
'L' ) )
THEN
248 info = -1
249 ELSE IF( n.LT.0 ) THEN
250 info = -2
251 ELSE IF( lda.LT.max( 1, n ) ) THEN
252 info = -4
253 END IF
254 IF( info.NE.0 ) THEN
255 CALL xerbla(
'ZHETF2_ROOK', -info )
256 RETURN
257 END IF
258
259
260
261 alpha = ( one+sqrt( sevten ) ) / eight
262
263
264
266
267 IF( upper ) THEN
268
269
270
271
272
273
274 k = n
275 10 CONTINUE
276
277
278
279 IF( k.LT.1 )
280 $ GO TO 70
281 kstep = 1
282 p = k
283
284
285
286
287 absakk = abs( dble( a( k, k ) ) )
288
289
290
291
292
293 IF( k.GT.1 ) THEN
294 imax =
izamax( k-1, a( 1, k ), 1 )
295 colmax = cabs1( a( imax, k ) )
296 ELSE
297 colmax = zero
298 END IF
299
300 IF( ( max( absakk, colmax ).EQ.zero ) ) THEN
301
302
303
304 IF( info.EQ.0 )
305 $ info = k
306 kp = k
307 a( k, k ) = dble( a( k, k ) )
308 ELSE
309
310
311
312
313
314
315
316
317
318 IF( .NOT.( absakk.LT.alpha*colmax ) ) THEN
319
320
321
322 kp = k
323
324 ELSE
325
326 done = .false.
327
328
329
330 12 CONTINUE
331
332
333
334
335
336
337
338
339 IF( imax.NE.k ) THEN
340 jmax = imax +
izamax( k-imax, a( imax, imax+1 ),
341 $ lda )
342 rowmax = cabs1( a( imax, jmax ) )
343 ELSE
344 rowmax = zero
345 END IF
346
347 IF( imax.GT.1 ) THEN
348 itemp =
izamax( imax-1, a( 1, imax ), 1 )
349 dtemp = cabs1( a( itemp, imax ) )
350 IF( dtemp.GT.rowmax ) THEN
351 rowmax = dtemp
352 jmax = itemp
353 END IF
354 END IF
355
356
357
358
359
360
361 IF( .NOT.( abs( dble( a( imax, imax ) ) )
362 $ .LT.alpha*rowmax ) ) THEN
363
364
365
366
367 kp = imax
368 done = .true.
369
370
371
372
373
374 ELSE IF( ( p.EQ.jmax ) .OR. ( rowmax.LE.colmax ) )
375 $ THEN
376
377
378
379
380 kp = imax
381 kstep = 2
382 done = .true.
383
384
385 ELSE
386
387
388
389 p = imax
390 colmax = rowmax
391 imax = jmax
392 END IF
393
394
395
396 IF( .NOT.done ) GOTO 12
397
398 END IF
399
400
401
402
403
404
405
406 kk = k - kstep + 1
407
408
409
410
411 IF( ( kstep.EQ.2 ) .AND. ( p.NE.k ) ) THEN
412
413 IF( p.GT.1 )
414 $
CALL zswap( p-1, a( 1, k ), 1, a( 1, p ), 1 )
415
416 DO 14 j = p + 1, k - 1
417 t = dconjg( a( j, k ) )
418 a( j, k ) = dconjg( a( p, j ) )
419 a( p, j ) = t
420 14 CONTINUE
421
422 a( p, k ) = dconjg( a( p, k ) )
423
424 r1 = dble( a( k, k ) )
425 a( k, k ) = dble( a( p, p ) )
426 a( p, p ) = r1
427 END IF
428
429
430
431
432 IF( kp.NE.kk ) THEN
433
434 IF( kp.GT.1 )
435 $
CALL zswap( kp-1, a( 1, kk ), 1, a( 1, kp ), 1 )
436
437 DO 15 j = kp + 1, kk - 1
438 t = dconjg( a( j, kk ) )
439 a( j, kk ) = dconjg( a( kp, j ) )
440 a( kp, j ) = t
441 15 CONTINUE
442
443 a( kp, kk ) = dconjg( a( kp, kk ) )
444
445 r1 = dble( a( kk, kk ) )
446 a( kk, kk ) = dble( a( kp, kp ) )
447 a( kp, kp ) = r1
448
449 IF( kstep.EQ.2 ) THEN
450
451 a( k, k ) = dble( a( k, k ) )
452
453 t = a( k-1, k )
454 a( k-1, k ) = a( kp, k )
455 a( kp, k ) = t
456 END IF
457 ELSE
458
459 a( k, k ) = dble( a( k, k ) )
460 IF( kstep.EQ.2 )
461 $ a( k-1, k-1 ) = dble( a( k-1, k-1 ) )
462 END IF
463
464
465
466 IF( kstep.EQ.1 ) THEN
467
468
469
470
471
472
473
474 IF( k.GT.1 ) THEN
475
476
477
478
479 IF( abs( dble( a( k, k ) ) ).GE.sfmin ) THEN
480
481
482
483
484
485 d11 = one / dble( a( k, k ) )
486 CALL zher( uplo, k-1, -d11, a( 1, k ), 1, a,
487 $ lda )
488
489
490
491 CALL zdscal( k-1, d11, a( 1, k ), 1 )
492 ELSE
493
494
495
496 d11 = dble( a( k, k ) )
497 DO 16 ii = 1, k - 1
498 a( ii, k ) = a( ii, k ) / d11
499 16 CONTINUE
500
501
502
503
504
505
506 CALL zher( uplo, k-1, -d11, a( 1, k ), 1, a,
507 $ lda )
508 END IF
509 END IF
510
511 ELSE
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527 IF( k.GT.2 ) THEN
528
529 d =
dlapy2( dble( a( k-1, k ) ),
530 $ dimag( a( k-1, k ) ) )
531 d11 = dble( a( k, k ) / d )
532 d22 = dble( a( k-1, k-1 ) / d )
533 d12 = a( k-1, k ) / d
534 tt = one / ( d11*d22-one )
535
536 DO 30 j = k - 2, 1, -1
537
538
539
540 wkm1 = tt*( d11*a( j, k-1 )-dconjg( d12 )*
541 $ a( j, k ) )
542 wk = tt*( d22*a( j, k )-d12*a( j, k-1 ) )
543
544
545
546 DO 20 i = j, 1, -1
547 a( i, j ) = a( i, j ) -
548 $ ( a( i, k ) / d )*dconjg( wk ) -
549 $ ( a( i, k-1 ) / d )*dconjg( wkm1 )
550 20 CONTINUE
551
552
553
554 a( j, k ) = wk / d
555 a( j, k-1 ) = wkm1 / d
556
557 a( j, j ) = dcmplx( dble( a( j, j ) ), zero )
558
559 30 CONTINUE
560
561 END IF
562
563 END IF
564
565 END IF
566
567
568
569 IF( kstep.EQ.1 ) THEN
570 ipiv( k ) = kp
571 ELSE
572 ipiv( k ) = -p
573 ipiv( k-1 ) = -kp
574 END IF
575
576
577
578 k = k - kstep
579 GO TO 10
580
581 ELSE
582
583
584
585
586
587
588 k = 1
589 40 CONTINUE
590
591
592
593 IF( k.GT.n )
594 $ GO TO 70
595 kstep = 1
596 p = k
597
598
599
600
601 absakk = abs( dble( a( k, k ) ) )
602
603
604
605
606
607 IF( k.LT.n ) THEN
608 imax = k +
izamax( n-k, a( k+1, k ), 1 )
609 colmax = cabs1( a( imax, k ) )
610 ELSE
611 colmax = zero
612 END IF
613
614 IF( max( absakk, colmax ).EQ.zero ) THEN
615
616
617
618 IF( info.EQ.0 )
619 $ info = k
620 kp = k
621 a( k, k ) = dble( a( k, k ) )
622 ELSE
623
624
625
626
627
628
629
630
631
632 IF( .NOT.( absakk.LT.alpha*colmax ) ) THEN
633
634
635
636 kp = k
637
638 ELSE
639
640 done = .false.
641
642
643
644 42 CONTINUE
645
646
647
648
649
650
651
652
653 IF( imax.NE.k ) THEN
654 jmax = k - 1 +
izamax( imax-k, a( imax, k ),
655 $ lda )
656 rowmax = cabs1( a( imax, jmax ) )
657 ELSE
658 rowmax = zero
659 END IF
660
661 IF( imax.LT.n ) THEN
662 itemp = imax +
izamax( n-imax, a( imax+1,
663 $ imax ),
664 $ 1 )
665 dtemp = cabs1( a( itemp, imax ) )
666 IF( dtemp.GT.rowmax ) THEN
667 rowmax = dtemp
668 jmax = itemp
669 END IF
670 END IF
671
672
673
674
675
676
677 IF( .NOT.( abs( dble( a( imax, imax ) ) )
678 $ .LT.alpha*rowmax ) ) THEN
679
680
681
682
683 kp = imax
684 done = .true.
685
686
687
688
689
690 ELSE IF( ( p.EQ.jmax ) .OR. ( rowmax.LE.colmax ) )
691 $ THEN
692
693
694
695
696 kp = imax
697 kstep = 2
698 done = .true.
699
700
701 ELSE
702
703
704
705 p = imax
706 colmax = rowmax
707 imax = jmax
708 END IF
709
710
711
712
713 IF( .NOT.done ) GOTO 42
714
715 END IF
716
717
718
719
720
721
722
723 kk = k + kstep - 1
724
725
726
727
728 IF( ( kstep.EQ.2 ) .AND. ( p.NE.k ) ) THEN
729
730 IF( p.LT.n )
731 $
CALL zswap( n-p, a( p+1, k ), 1, a( p+1, p ), 1 )
732
733 DO 44 j = k + 1, p - 1
734 t = dconjg( a( j, k ) )
735 a( j, k ) = dconjg( a( p, j ) )
736 a( p, j ) = t
737 44 CONTINUE
738
739 a( p, k ) = dconjg( a( p, k ) )
740
741 r1 = dble( a( k, k ) )
742 a( k, k ) = dble( a( p, p ) )
743 a( p, p ) = r1
744 END IF
745
746
747
748
749 IF( kp.NE.kk ) THEN
750
751 IF( kp.LT.n )
752 $
CALL zswap( n-kp, a( kp+1, kk ), 1, a( kp+1, kp ),
753 $ 1 )
754
755 DO 45 j = kk + 1, kp - 1
756 t = dconjg( a( j, kk ) )
757 a( j, kk ) = dconjg( a( kp, j ) )
758 a( kp, j ) = t
759 45 CONTINUE
760
761 a( kp, kk ) = dconjg( a( kp, kk ) )
762
763 r1 = dble( a( kk, kk ) )
764 a( kk, kk ) = dble( a( kp, kp ) )
765 a( kp, kp ) = r1
766
767 IF( kstep.EQ.2 ) THEN
768
769 a( k, k ) = dble( a( k, k ) )
770
771 t = a( k+1, k )
772 a( k+1, k ) = a( kp, k )
773 a( kp, k ) = t
774 END IF
775 ELSE
776
777 a( k, k ) = dble( a( k, k ) )
778 IF( kstep.EQ.2 )
779 $ a( k+1, k+1 ) = dble( a( k+1, k+1 ) )
780 END IF
781
782
783
784 IF( kstep.EQ.1 ) THEN
785
786
787
788
789
790
791
792 IF( k.LT.n ) THEN
793
794
795
796
797
798
799 IF( abs( dble( a( k, k ) ) ).GE.sfmin ) THEN
800
801
802
803
804
805 d11 = one / dble( a( k, k ) )
806 CALL zher( uplo, n-k, -d11, a( k+1, k ), 1,
807 $ a( k+1, k+1 ), lda )
808
809
810
811 CALL zdscal( n-k, d11, a( k+1, k ), 1 )
812 ELSE
813
814
815
816 d11 = dble( a( k, k ) )
817 DO 46 ii = k + 1, n
818 a( ii, k ) = a( ii, k ) / d11
819 46 CONTINUE
820
821
822
823
824
825
826 CALL zher( uplo, n-k, -d11, a( k+1, k ), 1,
827 $ a( k+1, k+1 ), lda )
828 END IF
829 END IF
830
831 ELSE
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848 IF( k.LT.n-1 ) THEN
849
850 d =
dlapy2( dble( a( k+1, k ) ),
851 $ dimag( a( k+1, k ) ) )
852 d11 = dble( a( k+1, k+1 ) ) / d
853 d22 = dble( a( k, k ) ) / d
854 d21 = a( k+1, k ) / d
855 tt = one / ( d11*d22-one )
856
857 DO 60 j = k + 2, n
858
859
860
861 wk = tt*( d11*a( j, k )-d21*a( j, k+1 ) )
862 wkp1 = tt*( d22*a( j, k+1 )-dconjg( d21 )*
863 $ a( j, k ) )
864
865
866
867 DO 50 i = j, n
868 a( i, j ) = a( i, j ) -
869 $ ( a( i, k ) / d )*dconjg( wk ) -
870 $ ( a( i, k+1 ) / d )*dconjg( wkp1 )
871 50 CONTINUE
872
873
874
875 a( j, k ) = wk / d
876 a( j, k+1 ) = wkp1 / d
877
878 a( j, j ) = dcmplx( dble( a( j, j ) ), zero )
879
880 60 CONTINUE
881
882 END IF
883
884 END IF
885
886 END IF
887
888
889
890 IF( kstep.EQ.1 ) THEN
891 ipiv( k ) = kp
892 ELSE
893 ipiv( k ) = -p
894 ipiv( k+1 ) = -kp
895 END IF
896
897
898
899 k = k + kstep
900 GO TO 40
901
902 END IF
903
904 70 CONTINUE
905
906 RETURN
907
908
909
subroutine xerbla(srname, info)
subroutine zher(uplo, n, alpha, x, incx, a, lda)
ZHER
integer function izamax(n, zx, incx)
IZAMAX
double precision function dlamch(cmach)
DLAMCH
double precision function dlapy2(x, y)
DLAPY2 returns sqrt(x2+y2).
logical function lsame(ca, cb)
LSAME
subroutine zdscal(n, da, zx, incx)
ZDSCAL
subroutine zswap(n, zx, incx, zy, incy)
ZSWAP