238
239
240
241
242
243
244 CHARACTER DIAG, NORMIN, TRANS, UPLO
245 INTEGER INFO, LDA, N
246 DOUBLE PRECISION SCALE
247
248
249 DOUBLE PRECISION CNORM( * )
250 COMPLEX*16 A( LDA, * ), X( * )
251
252
253
254
255
256 DOUBLE PRECISION ZERO, HALF, ONE, TWO
257 parameter( zero = 0.0d+0, half = 0.5d+0, one = 1.0d+0,
258 $ two = 2.0d+0 )
259
260
261 LOGICAL NOTRAN, NOUNIT, UPPER
262 INTEGER I, IMAX, J, JFIRST, JINC, JLAST
263 DOUBLE PRECISION BIGNUM, GROW, REC, SMLNUM, TJJ, TMAX, TSCAL,
264 $ XBND, XJ, XMAX
265 COMPLEX*16 CSUMJ, TJJS, USCAL, ZDUM
266
267
268 LOGICAL LSAME
269 INTEGER IDAMAX, IZAMAX
270 DOUBLE PRECISION DLAMCH, DZASUM
271 COMPLEX*16 ZDOTC, ZDOTU, ZLADIV
275
276
278
279
280 INTRINSIC abs, dble, dcmplx, dconjg, dimag, max, min
281
282
283 DOUBLE PRECISION CABS1, CABS2
284
285
286 cabs1( zdum ) = abs( dble( zdum ) ) + abs( dimag( zdum ) )
287 cabs2( zdum ) = abs( dble( zdum ) / 2.d0 ) +
288 $ abs( dimag( zdum ) / 2.d0 )
289
290
291
292 info = 0
293 upper =
lsame( uplo,
'U' )
294 notran =
lsame( trans,
'N' )
295 nounit =
lsame( diag,
'N' )
296
297
298
299 IF( .NOT.upper .AND. .NOT.
lsame( uplo,
'L' ) )
THEN
300 info = -1
301 ELSE IF( .NOT.notran .AND. .NOT.
lsame( trans,
'T' ) .AND. .NOT.
302 $
lsame( trans,
'C' ) )
THEN
303 info = -2
304 ELSE IF( .NOT.nounit .AND. .NOT.
lsame( diag,
'U' ) )
THEN
305 info = -3
306 ELSE IF( .NOT.
lsame( normin,
'Y' ) .AND. .NOT.
307 $
lsame( normin,
'N' ) )
THEN
308 info = -4
309 ELSE IF( n.LT.0 ) THEN
310 info = -5
311 ELSE IF( lda.LT.max( 1, n ) ) THEN
312 info = -7
313 END IF
314 IF( info.NE.0 ) THEN
315 CALL xerbla(
'ZLATRS', -info )
316 RETURN
317 END IF
318
319
320
321 scale = one
322 IF( n.EQ.0 )
323 $ RETURN
324
325
326
327 smlnum =
dlamch(
'Safe minimum' ) /
dlamch(
'Precision' )
328 bignum = one / smlnum
329
330 IF(
lsame( normin,
'N' ) )
THEN
331
332
333
334 IF( upper ) THEN
335
336
337
338 DO 10 j = 1, n
339 cnorm( j ) =
dzasum( j-1, a( 1, j ), 1 )
340 10 CONTINUE
341 ELSE
342
343
344
345 DO 20 j = 1, n - 1
346 cnorm( j ) =
dzasum( n-j, a( j+1, j ), 1 )
347 20 CONTINUE
348 cnorm( n ) = zero
349 END IF
350 END IF
351
352
353
354
355 imax =
idamax( n, cnorm, 1 )
356 tmax = cnorm( imax )
357 IF( tmax.LE.bignum*half ) THEN
358 tscal = one
359 ELSE
360
361
362
363
364 IF ( tmax.LE.
dlamch(
'Overflow') )
THEN
365
366 tscal = half / ( smlnum*tmax )
367 CALL dscal( n, tscal, cnorm, 1 )
368 ELSE
369
370
371
372
373
374 tmax = zero
375 IF( upper ) THEN
376
377
378
379 DO j = 2, n
380 DO i = 1, j - 1
381 tmax = max( tmax, abs( dble( a( i, j ) ) ),
382 $ abs( dimag(a( i, j ) ) ) )
383 END DO
384 END DO
385 ELSE
386
387
388
389 DO j = 1, n - 1
390 DO i = j + 1, n
391 tmax = max( tmax, abs( dble( a( i, j ) ) ),
392 $ abs( dimag(a( i, j ) ) ) )
393 END DO
394 END DO
395 END IF
396
397 IF( tmax.LE.
dlamch(
'Overflow') )
THEN
398 tscal = one / ( smlnum*tmax )
399 DO j = 1, n
400 IF( cnorm( j ).LE.
dlamch(
'Overflow') )
THEN
401 cnorm( j ) = cnorm( j )*tscal
402 ELSE
403
404
405 tscal = two * tscal
406 cnorm( j ) = zero
407 IF( upper ) THEN
408 DO i = 1, j - 1
409 cnorm( j ) = cnorm( j ) +
410 $ tscal * cabs2( a( i, j ) )
411 END DO
412 ELSE
413 DO i = j + 1, n
414 cnorm( j ) = cnorm( j ) +
415 $ tscal * cabs2( a( i, j ) )
416 END DO
417 END IF
418 tscal = tscal * half
419 END IF
420 END DO
421 ELSE
422
423
424 CALL ztrsv( uplo, trans, diag, n, a, lda, x, 1 )
425 RETURN
426 END IF
427 END IF
428 END IF
429
430
431
432
433 xmax = zero
434 DO 30 j = 1, n
435 xmax = max( xmax, cabs2( x( j ) ) )
436 30 CONTINUE
437 xbnd = xmax
438
439 IF( notran ) THEN
440
441
442
443 IF( upper ) THEN
444 jfirst = n
445 jlast = 1
446 jinc = -1
447 ELSE
448 jfirst = 1
449 jlast = n
450 jinc = 1
451 END IF
452
453 IF( tscal.NE.one ) THEN
454 grow = zero
455 GO TO 60
456 END IF
457
458 IF( nounit ) THEN
459
460
461
462
463
464
465 grow = half / max( xbnd, smlnum )
466 xbnd = grow
467 DO 40 j = jfirst, jlast, jinc
468
469
470
471 IF( grow.LE.smlnum )
472 $ GO TO 60
473
474 tjjs = a( j, j )
475 tjj = cabs1( tjjs )
476
477 IF( tjj.GE.smlnum ) THEN
478
479
480
481 xbnd = min( xbnd, min( one, tjj )*grow )
482 ELSE
483
484
485
486 xbnd = zero
487 END IF
488
489 IF( tjj+cnorm( j ).GE.smlnum ) THEN
490
491
492
493 grow = grow*( tjj / ( tjj+cnorm( j ) ) )
494 ELSE
495
496
497
498 grow = zero
499 END IF
500 40 CONTINUE
501 grow = xbnd
502 ELSE
503
504
505
506
507
508 grow = min( one, half / max( xbnd, smlnum ) )
509 DO 50 j = jfirst, jlast, jinc
510
511
512
513 IF( grow.LE.smlnum )
514 $ GO TO 60
515
516
517
518 grow = grow*( one / ( one+cnorm( j ) ) )
519 50 CONTINUE
520 END IF
521 60 CONTINUE
522
523 ELSE
524
525
526
527 IF( upper ) THEN
528 jfirst = 1
529 jlast = n
530 jinc = 1
531 ELSE
532 jfirst = n
533 jlast = 1
534 jinc = -1
535 END IF
536
537 IF( tscal.NE.one ) THEN
538 grow = zero
539 GO TO 90
540 END IF
541
542 IF( nounit ) THEN
543
544
545
546
547
548
549 grow = half / max( xbnd, smlnum )
550 xbnd = grow
551 DO 70 j = jfirst, jlast, jinc
552
553
554
555 IF( grow.LE.smlnum )
556 $ GO TO 90
557
558
559
560 xj = one + cnorm( j )
561 grow = min( grow, xbnd / xj )
562
563 tjjs = a( j, j )
564 tjj = cabs1( tjjs )
565
566 IF( tjj.GE.smlnum ) THEN
567
568
569
570 IF( xj.GT.tjj )
571 $ xbnd = xbnd*( tjj / xj )
572 ELSE
573
574
575
576 xbnd = zero
577 END IF
578 70 CONTINUE
579 grow = min( grow, xbnd )
580 ELSE
581
582
583
584
585
586 grow = min( one, half / max( xbnd, smlnum ) )
587 DO 80 j = jfirst, jlast, jinc
588
589
590
591 IF( grow.LE.smlnum )
592 $ GO TO 90
593
594
595
596 xj = one + cnorm( j )
597 grow = grow / xj
598 80 CONTINUE
599 END IF
600 90 CONTINUE
601 END IF
602
603 IF( ( grow*tscal ).GT.smlnum ) THEN
604
605
606
607
608 CALL ztrsv( uplo, trans, diag, n, a, lda, x, 1 )
609 ELSE
610
611
612
613 IF( xmax.GT.bignum*half ) THEN
614
615
616
617
618 scale = ( bignum*half ) / xmax
619 CALL zdscal( n, scale, x, 1 )
620 xmax = bignum
621 ELSE
622 xmax = xmax*two
623 END IF
624
625 IF( notran ) THEN
626
627
628
629 DO 120 j = jfirst, jlast, jinc
630
631
632
633 xj = cabs1( x( j ) )
634 IF( nounit ) THEN
635 tjjs = a( j, j )*tscal
636 ELSE
637 tjjs = tscal
638 IF( tscal.EQ.one )
639 $ GO TO 110
640 END IF
641 tjj = cabs1( tjjs )
642 IF( tjj.GT.smlnum ) THEN
643
644
645
646 IF( tjj.LT.one ) THEN
647 IF( xj.GT.tjj*bignum ) THEN
648
649
650
651 rec = one / xj
652 CALL zdscal( n, rec, x, 1 )
653 scale = scale*rec
654 xmax = xmax*rec
655 END IF
656 END IF
657 x( j ) =
zladiv( x( j ), tjjs )
658 xj = cabs1( x( j ) )
659 ELSE IF( tjj.GT.zero ) THEN
660
661
662
663 IF( xj.GT.tjj*bignum ) THEN
664
665
666
667
668 rec = ( tjj*bignum ) / xj
669 IF( cnorm( j ).GT.one ) THEN
670
671
672
673
674 rec = rec / cnorm( j )
675 END IF
676 CALL zdscal( n, rec, x, 1 )
677 scale = scale*rec
678 xmax = xmax*rec
679 END IF
680 x( j ) =
zladiv( x( j ), tjjs )
681 xj = cabs1( x( j ) )
682 ELSE
683
684
685
686
687 DO 100 i = 1, n
688 x( i ) = zero
689 100 CONTINUE
690 x( j ) = one
691 xj = one
692 scale = zero
693 xmax = zero
694 END IF
695 110 CONTINUE
696
697
698
699
700 IF( xj.GT.one ) THEN
701 rec = one / xj
702 IF( cnorm( j ).GT.( bignum-xmax )*rec ) THEN
703
704
705
706 rec = rec*half
707 CALL zdscal( n, rec, x, 1 )
708 scale = scale*rec
709 END IF
710 ELSE IF( xj*cnorm( j ).GT.( bignum-xmax ) ) THEN
711
712
713
714 CALL zdscal( n, half, x, 1 )
715 scale = scale*half
716 END IF
717
718 IF( upper ) THEN
719 IF( j.GT.1 ) THEN
720
721
722
723
724 CALL zaxpy( j-1, -x( j )*tscal, a( 1, j ), 1, x,
725 $ 1 )
727 xmax = cabs1( x( i ) )
728 END IF
729 ELSE
730 IF( j.LT.n ) THEN
731
732
733
734
735 CALL zaxpy( n-j, -x( j )*tscal, a( j+1, j ), 1,
736 $ x( j+1 ), 1 )
737 i = j +
izamax( n-j, x( j+1 ), 1 )
738 xmax = cabs1( x( i ) )
739 END IF
740 END IF
741 120 CONTINUE
742
743 ELSE IF(
lsame( trans,
'T' ) )
THEN
744
745
746
747 DO 170 j = jfirst, jlast, jinc
748
749
750
751
752 xj = cabs1( x( j ) )
753 uscal = tscal
754 rec = one / max( xmax, one )
755 IF( cnorm( j ).GT.( bignum-xj )*rec ) THEN
756
757
758
759 rec = rec*half
760 IF( nounit ) THEN
761 tjjs = a( j, j )*tscal
762 ELSE
763 tjjs = tscal
764 END IF
765 tjj = cabs1( tjjs )
766 IF( tjj.GT.one ) THEN
767
768
769
770 rec = min( one, rec*tjj )
771 uscal =
zladiv( uscal, tjjs )
772 END IF
773 IF( rec.LT.one ) THEN
774 CALL zdscal( n, rec, x, 1 )
775 scale = scale*rec
776 xmax = xmax*rec
777 END IF
778 END IF
779
780 csumj = zero
781 IF( uscal.EQ.dcmplx( one ) ) THEN
782
783
784
785
786 IF( upper ) THEN
787 csumj =
zdotu( j-1, a( 1, j ), 1, x, 1 )
788 ELSE IF( j.LT.n ) THEN
789 csumj =
zdotu( n-j, a( j+1, j ), 1, x( j+1 ),
790 $ 1 )
791 END IF
792 ELSE
793
794
795
796 IF( upper ) THEN
797 DO 130 i = 1, j - 1
798 csumj = csumj + ( a( i, j )*uscal )*x( i )
799 130 CONTINUE
800 ELSE IF( j.LT.n ) THEN
801 DO 140 i = j + 1, n
802 csumj = csumj + ( a( i, j )*uscal )*x( i )
803 140 CONTINUE
804 END IF
805 END IF
806
807 IF( uscal.EQ.dcmplx( tscal ) ) THEN
808
809
810
811
812 x( j ) = x( j ) - csumj
813 xj = cabs1( x( j ) )
814 IF( nounit ) THEN
815 tjjs = a( j, j )*tscal
816 ELSE
817 tjjs = tscal
818 IF( tscal.EQ.one )
819 $ GO TO 160
820 END IF
821
822
823
824 tjj = cabs1( tjjs )
825 IF( tjj.GT.smlnum ) THEN
826
827
828
829 IF( tjj.LT.one ) THEN
830 IF( xj.GT.tjj*bignum ) THEN
831
832
833
834 rec = one / xj
835 CALL zdscal( n, rec, x, 1 )
836 scale = scale*rec
837 xmax = xmax*rec
838 END IF
839 END IF
840 x( j ) =
zladiv( x( j ), tjjs )
841 ELSE IF( tjj.GT.zero ) THEN
842
843
844
845 IF( xj.GT.tjj*bignum ) THEN
846
847
848
849 rec = ( tjj*bignum ) / xj
850 CALL zdscal( n, rec, x, 1 )
851 scale = scale*rec
852 xmax = xmax*rec
853 END IF
854 x( j ) =
zladiv( x( j ), tjjs )
855 ELSE
856
857
858
859
860 DO 150 i = 1, n
861 x( i ) = zero
862 150 CONTINUE
863 x( j ) = one
864 scale = zero
865 xmax = zero
866 END IF
867 160 CONTINUE
868 ELSE
869
870
871
872
873 x( j ) =
zladiv( x( j ), tjjs ) - csumj
874 END IF
875 xmax = max( xmax, cabs1( x( j ) ) )
876 170 CONTINUE
877
878 ELSE
879
880
881
882 DO 220 j = jfirst, jlast, jinc
883
884
885
886
887 xj = cabs1( x( j ) )
888 uscal = tscal
889 rec = one / max( xmax, one )
890 IF( cnorm( j ).GT.( bignum-xj )*rec ) THEN
891
892
893
894 rec = rec*half
895 IF( nounit ) THEN
896 tjjs = dconjg( a( j, j ) )*tscal
897 ELSE
898 tjjs = tscal
899 END IF
900 tjj = cabs1( tjjs )
901 IF( tjj.GT.one ) THEN
902
903
904
905 rec = min( one, rec*tjj )
906 uscal =
zladiv( uscal, tjjs )
907 END IF
908 IF( rec.LT.one ) THEN
909 CALL zdscal( n, rec, x, 1 )
910 scale = scale*rec
911 xmax = xmax*rec
912 END IF
913 END IF
914
915 csumj = zero
916 IF( uscal.EQ.dcmplx( one ) ) THEN
917
918
919
920
921 IF( upper ) THEN
922 csumj =
zdotc( j-1, a( 1, j ), 1, x, 1 )
923 ELSE IF( j.LT.n ) THEN
924 csumj =
zdotc( n-j, a( j+1, j ), 1, x( j+1 ),
925 $ 1 )
926 END IF
927 ELSE
928
929
930
931 IF( upper ) THEN
932 DO 180 i = 1, j - 1
933 csumj = csumj + ( dconjg( a( i, j ) )*uscal )*
934 $ x( i )
935 180 CONTINUE
936 ELSE IF( j.LT.n ) THEN
937 DO 190 i = j + 1, n
938 csumj = csumj + ( dconjg( a( i, j ) )*uscal )*
939 $ x( i )
940 190 CONTINUE
941 END IF
942 END IF
943
944 IF( uscal.EQ.dcmplx( tscal ) ) THEN
945
946
947
948
949 x( j ) = x( j ) - csumj
950 xj = cabs1( x( j ) )
951 IF( nounit ) THEN
952 tjjs = dconjg( a( j, j ) )*tscal
953 ELSE
954 tjjs = tscal
955 IF( tscal.EQ.one )
956 $ GO TO 210
957 END IF
958
959
960
961 tjj = cabs1( tjjs )
962 IF( tjj.GT.smlnum ) THEN
963
964
965
966 IF( tjj.LT.one ) THEN
967 IF( xj.GT.tjj*bignum ) THEN
968
969
970
971 rec = one / xj
972 CALL zdscal( n, rec, x, 1 )
973 scale = scale*rec
974 xmax = xmax*rec
975 END IF
976 END IF
977 x( j ) =
zladiv( x( j ), tjjs )
978 ELSE IF( tjj.GT.zero ) THEN
979
980
981
982 IF( xj.GT.tjj*bignum ) THEN
983
984
985
986 rec = ( tjj*bignum ) / xj
987 CALL zdscal( n, rec, x, 1 )
988 scale = scale*rec
989 xmax = xmax*rec
990 END IF
991 x( j ) =
zladiv( x( j ), tjjs )
992 ELSE
993
994
995
996
997 DO 200 i = 1, n
998 x( i ) = zero
999 200 CONTINUE
1000 x( j ) = one
1001 scale = zero
1002 xmax = zero
1003 END IF
1004 210 CONTINUE
1005 ELSE
1006
1007
1008
1009
1010 x( j ) =
zladiv( x( j ), tjjs ) - csumj
1011 END IF
1012 xmax = max( xmax, cabs1( x( j ) ) )
1013 220 CONTINUE
1014 END IF
1015 scale = scale / tscal
1016 END IF
1017
1018
1019
1020 IF( tscal.NE.one ) THEN
1021 CALL dscal( n, one / tscal, cnorm, 1 )
1022 END IF
1023
1024 RETURN
1025
1026
1027
subroutine xerbla(srname, info)
double precision function dzasum(n, zx, incx)
DZASUM
subroutine zaxpy(n, za, zx, incx, zy, incy)
ZAXPY
complex *16 function zdotc(n, zx, incx, zy, incy)
ZDOTC
complex *16 function zdotu(n, zx, incx, zy, incy)
ZDOTU
integer function idamax(n, dx, incx)
IDAMAX
integer function izamax(n, zx, incx)
IZAMAX
complex *16 function zladiv(x, y)
ZLADIV performs complex division in real arithmetic, avoiding unnecessary overflow.
double precision function dlamch(cmach)
DLAMCH
logical function lsame(ca, cb)
LSAME
subroutine dscal(n, da, dx, incx)
DSCAL
subroutine zdscal(n, da, zx, incx)
ZDSCAL
subroutine ztrsv(uplo, trans, diag, n, a, lda, x, incx)
ZTRSV