235 IMPLICIT NONE
236
237
238
239
240
241
242 CHARACTER HOWMNY, SIDE
243 INTEGER INFO, LDT, LDVL, LDVR, LWORK, M, MM, N
244
245
246 LOGICAL SELECT( * )
247 REAL T( LDT, * ), VL( LDVL, * ), VR( LDVR, * ),
248 $ WORK( * )
249
250
251
252
253
254 REAL ZERO, ONE
255 parameter( zero = 0.0e+0, one = 1.0e+0 )
256 INTEGER NBMIN, NBMAX
257 parameter( nbmin = 8, nbmax = 128 )
258
259
260 LOGICAL ALLV, BOTHV, LEFTV, LQUERY, OVER, PAIR,
261 $ RIGHTV, SOMEV
262 INTEGER I, IERR, II, IP, IS, J, J1, J2, JNXT, K, KI,
263 $ IV, MAXWRK, NB, KI2
264 REAL BETA, BIGNUM, EMAX, OVFL, REC, REMAX, SCALE,
265 $ SMIN, SMLNUM, ULP, UNFL, VCRIT, VMAX, WI, WR,
266 $ XNORM
267
268
269 LOGICAL LSAME
270 INTEGER ISAMAX, ILAENV
271 REAL SDOT, SLAMCH
273
274
278
279
280 INTRINSIC abs, max, sqrt
281
282
283 REAL X( 2, 2 )
284 INTEGER ISCOMPLEX( NBMAX )
285
286
287
288
289
290 bothv =
lsame( side,
'B' )
291 rightv =
lsame( side,
'R' ) .OR. bothv
292 leftv =
lsame( side,
'L' ) .OR. bothv
293
294 allv =
lsame( howmny,
'A' )
295 over =
lsame( howmny,
'B' )
296 somev =
lsame( howmny,
'S' )
297
298 info = 0
299 nb =
ilaenv( 1,
'STREVC', side // howmny, n, -1, -1, -1 )
300 maxwrk = max( 1, n + 2*n*nb )
301 work( 1 ) = real( maxwrk )
302 lquery = ( lwork.EQ.-1 )
303 IF( .NOT.rightv .AND. .NOT.leftv ) THEN
304 info = -1
305 ELSE IF( .NOT.allv .AND. .NOT.over .AND. .NOT.somev ) THEN
306 info = -2
307 ELSE IF( n.LT.0 ) THEN
308 info = -4
309 ELSE IF( ldt.LT.max( 1, n ) ) THEN
310 info = -6
311 ELSE IF( ldvl.LT.1 .OR. ( leftv .AND. ldvl.LT.n ) ) THEN
312 info = -8
313 ELSE IF( ldvr.LT.1 .OR. ( rightv .AND. ldvr.LT.n ) ) THEN
314 info = -10
315 ELSE IF( lwork.LT.max( 1, 3*n ) .AND. .NOT.lquery ) THEN
316 info = -14
317 ELSE
318
319
320
321
322
323 IF( somev ) THEN
324 m = 0
325 pair = .false.
326 DO 10 j = 1, n
327 IF( pair ) THEN
328 pair = .false.
329 SELECT( j ) = .false.
330 ELSE
331 IF( j.LT.n ) THEN
332 IF( t( j+1, j ).EQ.zero ) THEN
333 IF( SELECT( j ) )
334 $ m = m + 1
335 ELSE
336 pair = .true.
337 IF( SELECT( j ) .OR. SELECT( j+1 ) ) THEN
338 SELECT( j ) = .true.
339 m = m + 2
340 END IF
341 END IF
342 ELSE
343 IF( SELECT( n ) )
344 $ m = m + 1
345 END IF
346 END IF
347 10 CONTINUE
348 ELSE
349 m = n
350 END IF
351
352 IF( mm.LT.m ) THEN
353 info = -11
354 END IF
355 END IF
356 IF( info.NE.0 ) THEN
357 CALL xerbla(
'STREVC3', -info )
358 RETURN
359 ELSE IF( lquery ) THEN
360 RETURN
361 END IF
362
363
364
365 IF( n.EQ.0 )
366 $ RETURN
367
368
369
370
371 IF( over .AND. lwork .GE. n + 2*n*nbmin ) THEN
372 nb = (lwork - n) / (2*n)
373 nb = min( nb, nbmax )
374 CALL slaset(
'F', n, 1+2*nb, zero, zero, work, n )
375 ELSE
376 nb = 1
377 END IF
378
379
380
381 unfl =
slamch(
'Safe minimum' )
382 ovfl = one / unfl
383 ulp =
slamch(
'Precision' )
384 smlnum = unfl*( real( n ) / ulp )
385 bignum = ( one-ulp ) / smlnum
386
387
388
389
390 work( 1 ) = zero
391 DO 30 j = 2, n
392 work( j ) = zero
393 DO 20 i = 1, j - 1
394 work( j ) = work( j ) + abs( t( i, j ) )
395 20 CONTINUE
396 30 CONTINUE
397
398
399
400
401
402
403
404 IF( rightv ) THEN
405
406
407
408
409
410
411
412
413
414 iv = 2
415 IF( nb.GT.2 ) THEN
416 iv = nb
417 END IF
418
419 ip = 0
420 is = m
421 DO 140 ki = n, 1, -1
422 IF( ip.EQ.-1 ) THEN
423
424
425 ip = 1
426 GO TO 140
427 ELSE IF( ki.EQ.1 ) THEN
428
429 ip = 0
430 ELSE IF( t( ki, ki-1 ).EQ.zero ) THEN
431
432 ip = 0
433 ELSE
434
435 ip = -1
436 END IF
437
438 IF( somev ) THEN
439 IF( ip.EQ.0 ) THEN
440 IF( .NOT.SELECT( ki ) )
441 $ GO TO 140
442 ELSE
443 IF( .NOT.SELECT( ki-1 ) )
444 $ GO TO 140
445 END IF
446 END IF
447
448
449
450 wr = t( ki, ki )
451 wi = zero
452 IF( ip.NE.0 )
453 $ wi = sqrt( abs( t( ki, ki-1 ) ) )*
454 $ sqrt( abs( t( ki-1, ki ) ) )
455 smin = max( ulp*( abs( wr )+abs( wi ) ), smlnum )
456
457 IF( ip.EQ.0 ) THEN
458
459
460
461
462 work( ki + iv*n ) = one
463
464
465
466 DO 50 k = 1, ki - 1
467 work( k + iv*n ) = -t( k, ki )
468 50 CONTINUE
469
470
471
472
473 jnxt = ki - 1
474 DO 60 j = ki - 1, 1, -1
475 IF( j.GT.jnxt )
476 $ GO TO 60
477 j1 = j
478 j2 = j
479 jnxt = j - 1
480 IF( j.GT.1 ) THEN
481 IF( t( j, j-1 ).NE.zero ) THEN
482 j1 = j - 1
483 jnxt = j - 2
484 END IF
485 END IF
486
487 IF( j1.EQ.j2 ) THEN
488
489
490
491 CALL slaln2( .false., 1, 1, smin, one, t( j,
492 $ j ),
493 $ ldt, one, one, work( j+iv*n ), n, wr,
494 $ zero, x, 2, scale, xnorm, ierr )
495
496
497
498
499 IF( xnorm.GT.one ) THEN
500 IF( work( j ).GT.bignum / xnorm ) THEN
501 x( 1, 1 ) = x( 1, 1 ) / xnorm
502 scale = scale / xnorm
503 END IF
504 END IF
505
506
507
508 IF( scale.NE.one )
509 $
CALL sscal( ki, scale, work( 1+iv*n ), 1 )
510 work( j+iv*n ) = x( 1, 1 )
511
512
513
514 CALL saxpy( j-1, -x( 1, 1 ), t( 1, j ), 1,
515 $ work( 1+iv*n ), 1 )
516
517 ELSE
518
519
520
521 CALL slaln2( .false., 2, 1, smin, one,
522 $ t( j-1, j-1 ), ldt, one, one,
523 $ work( j-1+iv*n ), n, wr, zero, x, 2,
524 $ scale, xnorm, ierr )
525
526
527
528
529 IF( xnorm.GT.one ) THEN
530 beta = max( work( j-1 ), work( j ) )
531 IF( beta.GT.bignum / xnorm ) THEN
532 x( 1, 1 ) = x( 1, 1 ) / xnorm
533 x( 2, 1 ) = x( 2, 1 ) / xnorm
534 scale = scale / xnorm
535 END IF
536 END IF
537
538
539
540 IF( scale.NE.one )
541 $
CALL sscal( ki, scale, work( 1+iv*n ), 1 )
542 work( j-1+iv*n ) = x( 1, 1 )
543 work( j +iv*n ) = x( 2, 1 )
544
545
546
547 CALL saxpy( j-2, -x( 1, 1 ), t( 1, j-1 ), 1,
548 $ work( 1+iv*n ), 1 )
549 CALL saxpy( j-2, -x( 2, 1 ), t( 1, j ), 1,
550 $ work( 1+iv*n ), 1 )
551 END IF
552 60 CONTINUE
553
554
555
556 IF( .NOT.over ) THEN
557
558
559 CALL scopy( ki, work( 1 + iv*n ), 1, vr( 1, is ),
560 $ 1 )
561
562 ii =
isamax( ki, vr( 1, is ), 1 )
563 remax = one / abs( vr( ii, is ) )
564 CALL sscal( ki, remax, vr( 1, is ), 1 )
565
566 DO 70 k = ki + 1, n
567 vr( k, is ) = zero
568 70 CONTINUE
569
570 ELSE IF( nb.EQ.1 ) THEN
571
572
573 IF( ki.GT.1 )
574 $
CALL sgemv(
'N', n, ki-1, one, vr, ldvr,
575 $ work( 1 + iv*n ), 1, work( ki + iv*n ),
576 $ vr( 1, ki ), 1 )
577
578 ii =
isamax( n, vr( 1, ki ), 1 )
579 remax = one / abs( vr( ii, ki ) )
580 CALL sscal( n, remax, vr( 1, ki ), 1 )
581
582 ELSE
583
584
585
586 DO k = ki + 1, n
587 work( k + iv*n ) = zero
588 END DO
589 iscomplex( iv ) = ip
590
591 END IF
592 ELSE
593
594
595
596
597
598
599
600
601 IF( abs( t( ki-1, ki ) ).GE.abs( t( ki, ki-1 ) ) ) THEN
602 work( ki-1 + (iv-1)*n ) = one
603 work( ki + (iv )*n ) = wi / t( ki-1, ki )
604 ELSE
605 work( ki-1 + (iv-1)*n ) = -wi / t( ki, ki-1 )
606 work( ki + (iv )*n ) = one
607 END IF
608 work( ki + (iv-1)*n ) = zero
609 work( ki-1 + (iv )*n ) = zero
610
611
612
613 DO 80 k = 1, ki - 2
614 work( k+(iv-1)*n ) = -work( ki-1+(iv-1)*n )*t(k,ki-1)
615 work( k+(iv )*n ) = -work( ki +(iv )*n )*t(k,ki )
616 80 CONTINUE
617
618
619
620
621 jnxt = ki - 2
622 DO 90 j = ki - 2, 1, -1
623 IF( j.GT.jnxt )
624 $ GO TO 90
625 j1 = j
626 j2 = j
627 jnxt = j - 1
628 IF( j.GT.1 ) THEN
629 IF( t( j, j-1 ).NE.zero ) THEN
630 j1 = j - 1
631 jnxt = j - 2
632 END IF
633 END IF
634
635 IF( j1.EQ.j2 ) THEN
636
637
638
639 CALL slaln2( .false., 1, 2, smin, one, t( j,
640 $ j ),
641 $ ldt, one, one, work( j+(iv-1)*n ), n,
642 $ wr, wi, x, 2, scale, xnorm, ierr )
643
644
645
646
647 IF( xnorm.GT.one ) THEN
648 IF( work( j ).GT.bignum / xnorm ) THEN
649 x( 1, 1 ) = x( 1, 1 ) / xnorm
650 x( 1, 2 ) = x( 1, 2 ) / xnorm
651 scale = scale / xnorm
652 END IF
653 END IF
654
655
656
657 IF( scale.NE.one ) THEN
658 CALL sscal( ki, scale, work( 1+(iv-1)*n ),
659 $ 1 )
660 CALL sscal( ki, scale, work( 1+(iv )*n ),
661 $ 1 )
662 END IF
663 work( j+(iv-1)*n ) = x( 1, 1 )
664 work( j+(iv )*n ) = x( 1, 2 )
665
666
667
668 CALL saxpy( j-1, -x( 1, 1 ), t( 1, j ), 1,
669 $ work( 1+(iv-1)*n ), 1 )
670 CALL saxpy( j-1, -x( 1, 2 ), t( 1, j ), 1,
671 $ work( 1+(iv )*n ), 1 )
672
673 ELSE
674
675
676
677 CALL slaln2( .false., 2, 2, smin, one,
678 $ t( j-1, j-1 ), ldt, one, one,
679 $ work( j-1+(iv-1)*n ), n, wr, wi, x, 2,
680 $ scale, xnorm, ierr )
681
682
683
684
685 IF( xnorm.GT.one ) THEN
686 beta = max( work( j-1 ), work( j ) )
687 IF( beta.GT.bignum / xnorm ) THEN
688 rec = one / xnorm
689 x( 1, 1 ) = x( 1, 1 )*rec
690 x( 1, 2 ) = x( 1, 2 )*rec
691 x( 2, 1 ) = x( 2, 1 )*rec
692 x( 2, 2 ) = x( 2, 2 )*rec
693 scale = scale*rec
694 END IF
695 END IF
696
697
698
699 IF( scale.NE.one ) THEN
700 CALL sscal( ki, scale, work( 1+(iv-1)*n ),
701 $ 1 )
702 CALL sscal( ki, scale, work( 1+(iv )*n ),
703 $ 1 )
704 END IF
705 work( j-1+(iv-1)*n ) = x( 1, 1 )
706 work( j +(iv-1)*n ) = x( 2, 1 )
707 work( j-1+(iv )*n ) = x( 1, 2 )
708 work( j +(iv )*n ) = x( 2, 2 )
709
710
711
712 CALL saxpy( j-2, -x( 1, 1 ), t( 1, j-1 ), 1,
713 $ work( 1+(iv-1)*n ), 1 )
714 CALL saxpy( j-2, -x( 2, 1 ), t( 1, j ), 1,
715 $ work( 1+(iv-1)*n ), 1 )
716 CALL saxpy( j-2, -x( 1, 2 ), t( 1, j-1 ), 1,
717 $ work( 1+(iv )*n ), 1 )
718 CALL saxpy( j-2, -x( 2, 2 ), t( 1, j ), 1,
719 $ work( 1+(iv )*n ), 1 )
720 END IF
721 90 CONTINUE
722
723
724
725 IF( .NOT.over ) THEN
726
727
728 CALL scopy( ki, work( 1+(iv-1)*n ), 1, vr(1,is-1),
729 $ 1 )
730 CALL scopy( ki, work( 1+(iv )*n ), 1, vr(1,is ),
731 $ 1 )
732
733 emax = zero
734 DO 100 k = 1, ki
735 emax = max( emax, abs( vr( k, is-1 ) )+
736 $ abs( vr( k, is ) ) )
737 100 CONTINUE
738 remax = one / emax
739 CALL sscal( ki, remax, vr( 1, is-1 ), 1 )
740 CALL sscal( ki, remax, vr( 1, is ), 1 )
741
742 DO 110 k = ki + 1, n
743 vr( k, is-1 ) = zero
744 vr( k, is ) = zero
745 110 CONTINUE
746
747 ELSE IF( nb.EQ.1 ) THEN
748
749
750 IF( ki.GT.2 ) THEN
751 CALL sgemv(
'N', n, ki-2, one, vr, ldvr,
752 $ work( 1 + (iv-1)*n ), 1,
753 $ work( ki-1 + (iv-1)*n ), vr(1,ki-1), 1)
754 CALL sgemv(
'N', n, ki-2, one, vr, ldvr,
755 $ work( 1 + (iv)*n ), 1,
756 $ work( ki + (iv)*n ), vr( 1, ki ), 1 )
757 ELSE
758 CALL sscal( n, work(ki-1+(iv-1)*n), vr(1,ki-1),
759 $ 1)
760 CALL sscal( n, work(ki +(iv )*n), vr(1,ki ),
761 $ 1)
762 END IF
763
764 emax = zero
765 DO 120 k = 1, n
766 emax = max( emax, abs( vr( k, ki-1 ) )+
767 $ abs( vr( k, ki ) ) )
768 120 CONTINUE
769 remax = one / emax
770 CALL sscal( n, remax, vr( 1, ki-1 ), 1 )
771 CALL sscal( n, remax, vr( 1, ki ), 1 )
772
773 ELSE
774
775
776
777 DO k = ki + 1, n
778 work( k + (iv-1)*n ) = zero
779 work( k + (iv )*n ) = zero
780 END DO
781 iscomplex( iv-1 ) = -ip
782 iscomplex( iv ) = ip
783 iv = iv - 1
784
785 END IF
786 END IF
787
788 IF( nb.GT.1 ) THEN
789
790
791
792 IF( ip.EQ.0 ) THEN
793 ki2 = ki
794 ELSE
795 ki2 = ki - 1
796 END IF
797
798
799
800
801 IF( (iv.LE.2) .OR. (ki2.EQ.1) ) THEN
802 CALL sgemm(
'N',
'N', n, nb-iv+1, ki2+nb-iv, one,
803 $ vr, ldvr,
804 $ work( 1 + (iv)*n ), n,
805 $ zero,
806 $ work( 1 + (nb+iv)*n ), n )
807
808 DO k = iv, nb
809 IF( iscomplex(k).EQ.0 ) THEN
810
811 ii =
isamax( n, work( 1 + (nb+k)*n ), 1 )
812 remax = one / abs( work( ii + (nb+k)*n ) )
813 ELSE IF( iscomplex(k).EQ.1 ) THEN
814
815 emax = zero
816 DO ii = 1, n
817 emax = max( emax,
818 $ abs( work( ii + (nb+k )*n ) )+
819 $ abs( work( ii + (nb+k+1)*n ) ) )
820 END DO
821 remax = one / emax
822
823
824
825 END IF
826 CALL sscal( n, remax, work( 1 + (nb+k)*n ), 1 )
827 END DO
828 CALL slacpy(
'F', n, nb-iv+1,
829 $ work( 1 + (nb+iv)*n ), n,
830 $ vr( 1, ki2 ), ldvr )
831 iv = nb
832 ELSE
833 iv = iv - 1
834 END IF
835 END IF
836
837 is = is - 1
838 IF( ip.NE.0 )
839 $ is = is - 1
840 140 CONTINUE
841 END IF
842
843 IF( leftv ) THEN
844
845
846
847
848
849
850
851
852
853 iv = 1
854 ip = 0
855 is = 1
856 DO 260 ki = 1, n
857 IF( ip.EQ.1 ) THEN
858
859
860 ip = -1
861 GO TO 260
862 ELSE IF( ki.EQ.n ) THEN
863
864 ip = 0
865 ELSE IF( t( ki+1, ki ).EQ.zero ) THEN
866
867 ip = 0
868 ELSE
869
870 ip = 1
871 END IF
872
873 IF( somev ) THEN
874 IF( .NOT.SELECT( ki ) )
875 $ GO TO 260
876 END IF
877
878
879
880 wr = t( ki, ki )
881 wi = zero
882 IF( ip.NE.0 )
883 $ wi = sqrt( abs( t( ki, ki+1 ) ) )*
884 $ sqrt( abs( t( ki+1, ki ) ) )
885 smin = max( ulp*( abs( wr )+abs( wi ) ), smlnum )
886
887 IF( ip.EQ.0 ) THEN
888
889
890
891
892 work( ki + iv*n ) = one
893
894
895
896 DO 160 k = ki + 1, n
897 work( k + iv*n ) = -t( ki, k )
898 160 CONTINUE
899
900
901
902
903 vmax = one
904 vcrit = bignum
905
906 jnxt = ki + 1
907 DO 170 j = ki + 1, n
908 IF( j.LT.jnxt )
909 $ GO TO 170
910 j1 = j
911 j2 = j
912 jnxt = j + 1
913 IF( j.LT.n ) THEN
914 IF( t( j+1, j ).NE.zero ) THEN
915 j2 = j + 1
916 jnxt = j + 2
917 END IF
918 END IF
919
920 IF( j1.EQ.j2 ) THEN
921
922
923
924
925
926
927 IF( work( j ).GT.vcrit ) THEN
928 rec = one / vmax
929 CALL sscal( n-ki+1, rec, work( ki+iv*n ), 1 )
930 vmax = one
931 vcrit = bignum
932 END IF
933
934 work( j+iv*n ) = work( j+iv*n ) -
935 $
sdot( j-ki-1, t( ki+1, j ), 1,
936 $ work( ki+1+iv*n ), 1 )
937
938
939
940 CALL slaln2( .false., 1, 1, smin, one, t( j,
941 $ j ),
942 $ ldt, one, one, work( j+iv*n ), n, wr,
943 $ zero, x, 2, scale, xnorm, ierr )
944
945
946
947 IF( scale.NE.one )
948 $
CALL sscal( n-ki+1, scale, work( ki+iv*n ),
949 $ 1 )
950 work( j+iv*n ) = x( 1, 1 )
951 vmax = max( abs( work( j+iv*n ) ), vmax )
952 vcrit = bignum / vmax
953
954 ELSE
955
956
957
958
959
960
961 beta = max( work( j ), work( j+1 ) )
962 IF( beta.GT.vcrit ) THEN
963 rec = one / vmax
964 CALL sscal( n-ki+1, rec, work( ki+iv*n ), 1 )
965 vmax = one
966 vcrit = bignum
967 END IF
968
969 work( j+iv*n ) = work( j+iv*n ) -
970 $
sdot( j-ki-1, t( ki+1, j ), 1,
971 $ work( ki+1+iv*n ), 1 )
972
973 work( j+1+iv*n ) = work( j+1+iv*n ) -
974 $
sdot( j-ki-1, t( ki+1, j+1 ),
975 $ 1,
976 $ work( ki+1+iv*n ), 1 )
977
978
979
980
981
982 CALL slaln2( .true., 2, 1, smin, one, t( j, j ),
983 $ ldt, one, one, work( j+iv*n ), n, wr,
984 $ zero, x, 2, scale, xnorm, ierr )
985
986
987
988 IF( scale.NE.one )
989 $
CALL sscal( n-ki+1, scale, work( ki+iv*n ),
990 $ 1 )
991 work( j +iv*n ) = x( 1, 1 )
992 work( j+1+iv*n ) = x( 2, 1 )
993
994 vmax = max( abs( work( j +iv*n ) ),
995 $ abs( work( j+1+iv*n ) ), vmax )
996 vcrit = bignum / vmax
997
998 END IF
999 170 CONTINUE
1000
1001
1002
1003 IF( .NOT.over ) THEN
1004
1005
1006 CALL scopy( n-ki+1, work( ki + iv*n ), 1,
1007 $ vl( ki, is ), 1 )
1008
1009 ii =
isamax( n-ki+1, vl( ki, is ), 1 ) + ki - 1
1010 remax = one / abs( vl( ii, is ) )
1011 CALL sscal( n-ki+1, remax, vl( ki, is ), 1 )
1012
1013 DO 180 k = 1, ki - 1
1014 vl( k, is ) = zero
1015 180 CONTINUE
1016
1017 ELSE IF( nb.EQ.1 ) THEN
1018
1019
1020 IF( ki.LT.n )
1021 $
CALL sgemv(
'N', n, n-ki, one,
1022 $ vl( 1, ki+1 ), ldvl,
1023 $ work( ki+1 + iv*n ), 1,
1024 $ work( ki + iv*n ), vl( 1, ki ), 1 )
1025
1026 ii =
isamax( n, vl( 1, ki ), 1 )
1027 remax = one / abs( vl( ii, ki ) )
1028 CALL sscal( n, remax, vl( 1, ki ), 1 )
1029
1030 ELSE
1031
1032
1033
1034
1035 DO k = 1, ki - 1
1036 work( k + iv*n ) = zero
1037 END DO
1038 iscomplex( iv ) = ip
1039
1040 END IF
1041 ELSE
1042
1043
1044
1045
1046
1047
1048
1049
1050 IF( abs( t( ki, ki+1 ) ).GE.abs( t( ki+1, ki ) ) ) THEN
1051 work( ki + (iv )*n ) = wi / t( ki, ki+1 )
1052 work( ki+1 + (iv+1)*n ) = one
1053 ELSE
1054 work( ki + (iv )*n ) = one
1055 work( ki+1 + (iv+1)*n ) = -wi / t( ki+1, ki )
1056 END IF
1057 work( ki+1 + (iv )*n ) = zero
1058 work( ki + (iv+1)*n ) = zero
1059
1060
1061
1062 DO 190 k = ki + 2, n
1063 work( k+(iv )*n ) = -work( ki +(iv )*n )*t(ki, k)
1064 work( k+(iv+1)*n ) = -work( ki+1+(iv+1)*n )*t(ki+1,k)
1065 190 CONTINUE
1066
1067
1068
1069
1070 vmax = one
1071 vcrit = bignum
1072
1073 jnxt = ki + 2
1074 DO 200 j = ki + 2, n
1075 IF( j.LT.jnxt )
1076 $ GO TO 200
1077 j1 = j
1078 j2 = j
1079 jnxt = j + 1
1080 IF( j.LT.n ) THEN
1081 IF( t( j+1, j ).NE.zero ) THEN
1082 j2 = j + 1
1083 jnxt = j + 2
1084 END IF
1085 END IF
1086
1087 IF( j1.EQ.j2 ) THEN
1088
1089
1090
1091
1092
1093
1094 IF( work( j ).GT.vcrit ) THEN
1095 rec = one / vmax
1096 CALL sscal( n-ki+1, rec, work(ki+(iv )*n),
1097 $ 1 )
1098 CALL sscal( n-ki+1, rec, work(ki+(iv+1)*n),
1099 $ 1 )
1100 vmax = one
1101 vcrit = bignum
1102 END IF
1103
1104 work( j+(iv )*n ) = work( j+(iv)*n ) -
1105 $
sdot( j-ki-2, t( ki+2, j ),
1106 $ 1,
1107 $ work( ki+2+(iv)*n ), 1 )
1108 work( j+(iv+1)*n ) = work( j+(iv+1)*n ) -
1109 $
sdot( j-ki-2, t( ki+2, j ),
1110 $ 1,
1111 $ work( ki+2+(iv+1)*n ), 1 )
1112
1113
1114
1115 CALL slaln2( .false., 1, 2, smin, one, t( j,
1116 $ j ),
1117 $ ldt, one, one, work( j+iv*n ), n, wr,
1118 $ -wi, x, 2, scale, xnorm, ierr )
1119
1120
1121
1122 IF( scale.NE.one ) THEN
1123 CALL sscal( n-ki+1, scale, work(ki+(iv )*n),
1124 $ 1)
1125 CALL sscal( n-ki+1, scale, work(ki+(iv+1)*n),
1126 $ 1)
1127 END IF
1128 work( j+(iv )*n ) = x( 1, 1 )
1129 work( j+(iv+1)*n ) = x( 1, 2 )
1130 vmax = max( abs( work( j+(iv )*n ) ),
1131 $ abs( work( j+(iv+1)*n ) ), vmax )
1132 vcrit = bignum / vmax
1133
1134 ELSE
1135
1136
1137
1138
1139
1140
1141 beta = max( work( j ), work( j+1 ) )
1142 IF( beta.GT.vcrit ) THEN
1143 rec = one / vmax
1144 CALL sscal( n-ki+1, rec, work(ki+(iv )*n),
1145 $ 1 )
1146 CALL sscal( n-ki+1, rec, work(ki+(iv+1)*n),
1147 $ 1 )
1148 vmax = one
1149 vcrit = bignum
1150 END IF
1151
1152 work( j +(iv )*n ) = work( j+(iv)*n ) -
1153 $
sdot( j-ki-2, t( ki+2, j ), 1,
1154 $ work( ki+2+(iv)*n ), 1 )
1155
1156 work( j +(iv+1)*n ) = work( j+(iv+1)*n ) -
1157 $
sdot( j-ki-2, t( ki+2, j ), 1,
1158 $ work( ki+2+(iv+1)*n ), 1 )
1159
1160 work( j+1+(iv )*n ) = work( j+1+(iv)*n ) -
1161 $
sdot( j-ki-2, t( ki+2, j+1 ),
1162 $ 1,
1163 $ work( ki+2+(iv)*n ), 1 )
1164
1165 work( j+1+(iv+1)*n ) = work( j+1+(iv+1)*n ) -
1166 $
sdot( j-ki-2, t( ki+2, j+1 ),
1167 $ 1,
1168 $ work( ki+2+(iv+1)*n ), 1 )
1169
1170
1171
1172
1173
1174 CALL slaln2( .true., 2, 2, smin, one, t( j, j ),
1175 $ ldt, one, one, work( j+iv*n ), n, wr,
1176 $ -wi, x, 2, scale, xnorm, ierr )
1177
1178
1179
1180 IF( scale.NE.one ) THEN
1181 CALL sscal( n-ki+1, scale, work(ki+(iv )*n),
1182 $ 1)
1183 CALL sscal( n-ki+1, scale, work(ki+(iv+1)*n),
1184 $ 1)
1185 END IF
1186 work( j +(iv )*n ) = x( 1, 1 )
1187 work( j +(iv+1)*n ) = x( 1, 2 )
1188 work( j+1+(iv )*n ) = x( 2, 1 )
1189 work( j+1+(iv+1)*n ) = x( 2, 2 )
1190 vmax = max( abs( x( 1, 1 ) ), abs( x( 1, 2 ) ),
1191 $ abs( x( 2, 1 ) ), abs( x( 2, 2 ) ),
1192 $ vmax )
1193 vcrit = bignum / vmax
1194
1195 END IF
1196 200 CONTINUE
1197
1198
1199
1200 IF( .NOT.over ) THEN
1201
1202
1203 CALL scopy( n-ki+1, work( ki + (iv )*n ), 1,
1204 $ vl( ki, is ), 1 )
1205 CALL scopy( n-ki+1, work( ki + (iv+1)*n ), 1,
1206 $ vl( ki, is+1 ), 1 )
1207
1208 emax = zero
1209 DO 220 k = ki, n
1210 emax = max( emax, abs( vl( k, is ) )+
1211 $ abs( vl( k, is+1 ) ) )
1212 220 CONTINUE
1213 remax = one / emax
1214 CALL sscal( n-ki+1, remax, vl( ki, is ), 1 )
1215 CALL sscal( n-ki+1, remax, vl( ki, is+1 ), 1 )
1216
1217 DO 230 k = 1, ki - 1
1218 vl( k, is ) = zero
1219 vl( k, is+1 ) = zero
1220 230 CONTINUE
1221
1222 ELSE IF( nb.EQ.1 ) THEN
1223
1224
1225 IF( ki.LT.n-1 ) THEN
1226 CALL sgemv(
'N', n, n-ki-1, one,
1227 $ vl( 1, ki+2 ), ldvl,
1228 $ work( ki+2 + (iv)*n ), 1,
1229 $ work( ki + (iv)*n ),
1230 $ vl( 1, ki ), 1 )
1231 CALL sgemv(
'N', n, n-ki-1, one,
1232 $ vl( 1, ki+2 ), ldvl,
1233 $ work( ki+2 + (iv+1)*n ), 1,
1234 $ work( ki+1 + (iv+1)*n ),
1235 $ vl( 1, ki+1 ), 1 )
1236 ELSE
1237 CALL sscal( n, work(ki+ (iv )*n), vl(1, ki ),
1238 $ 1)
1239 CALL sscal( n, work(ki+1+(iv+1)*n), vl(1, ki+1),
1240 $ 1)
1241 END IF
1242
1243 emax = zero
1244 DO 240 k = 1, n
1245 emax = max( emax, abs( vl( k, ki ) )+
1246 $ abs( vl( k, ki+1 ) ) )
1247 240 CONTINUE
1248 remax = one / emax
1249 CALL sscal( n, remax, vl( 1, ki ), 1 )
1250 CALL sscal( n, remax, vl( 1, ki+1 ), 1 )
1251
1252 ELSE
1253
1254
1255
1256
1257 DO k = 1, ki - 1
1258 work( k + (iv )*n ) = zero
1259 work( k + (iv+1)*n ) = zero
1260 END DO
1261 iscomplex( iv ) = ip
1262 iscomplex( iv+1 ) = -ip
1263 iv = iv + 1
1264
1265 END IF
1266 END IF
1267
1268 IF( nb.GT.1 ) THEN
1269
1270
1271
1272 IF( ip.EQ.0 ) THEN
1273 ki2 = ki
1274 ELSE
1275 ki2 = ki + 1
1276 END IF
1277
1278
1279
1280
1281 IF( (iv.GE.nb-1) .OR. (ki2.EQ.n) ) THEN
1282 CALL sgemm(
'N',
'N', n, iv, n-ki2+iv, one,
1283 $ vl( 1, ki2-iv+1 ), ldvl,
1284 $ work( ki2-iv+1 + (1)*n ), n,
1285 $ zero,
1286 $ work( 1 + (nb+1)*n ), n )
1287
1288 DO k = 1, iv
1289 IF( iscomplex(k).EQ.0) THEN
1290
1291 ii =
isamax( n, work( 1 + (nb+k)*n ), 1 )
1292 remax = one / abs( work( ii + (nb+k)*n ) )
1293 ELSE IF( iscomplex(k).EQ.1) THEN
1294
1295 emax = zero
1296 DO ii = 1, n
1297 emax = max( emax,
1298 $ abs( work( ii + (nb+k )*n ) )+
1299 $ abs( work( ii + (nb+k+1)*n ) ) )
1300 END DO
1301 remax = one / emax
1302
1303
1304
1305 END IF
1306 CALL sscal( n, remax, work( 1 + (nb+k)*n ), 1 )
1307 END DO
1309 $ work( 1 + (nb+1)*n ), n,
1310 $ vl( 1, ki2-iv+1 ), ldvl )
1311 iv = 1
1312 ELSE
1313 iv = iv + 1
1314 END IF
1315 END IF
1316
1317 is = is + 1
1318 IF( ip.NE.0 )
1319 $ is = is + 1
1320 260 CONTINUE
1321 END IF
1322
1323 RETURN
1324
1325
1326
subroutine xerbla(srname, info)
subroutine saxpy(n, sa, sx, incx, sy, incy)
SAXPY
subroutine scopy(n, sx, incx, sy, incy)
SCOPY
real function sdot(n, sx, incx, sy, incy)
SDOT
subroutine sgemm(transa, transb, m, n, k, alpha, a, lda, b, ldb, beta, c, ldc)
SGEMM
subroutine sgemv(trans, m, n, alpha, a, lda, x, incx, beta, y, incy)
SGEMV
integer function isamax(n, sx, incx)
ISAMAX
integer function ilaenv(ispec, name, opts, n1, n2, n3, n4)
ILAENV
subroutine slacpy(uplo, m, n, a, lda, b, ldb)
SLACPY copies all or part of one two-dimensional array to another.
subroutine slaln2(ltrans, na, nw, smin, ca, a, lda, d1, d2, b, ldb, wr, wi, x, ldx, scale, xnorm, info)
SLALN2 solves a 1-by-1 or 2-by-2 linear system of equations of the specified form.
real function slamch(cmach)
SLAMCH
subroutine slaset(uplo, m, n, alpha, beta, a, lda)
SLASET initializes the off-diagonal elements and the diagonal elements of a matrix to given values.
logical function lsame(ca, cb)
LSAME
subroutine sscal(n, sa, sx, incx)
SSCAL