00001 SUBROUTINE CLATRS( UPLO, TRANS, DIAG, NORMIN, N, A, LDA, X, SCALE,
00002 $ CNORM, INFO )
00003
00004
00005
00006
00007
00008
00009
00010 CHARACTER DIAG, NORMIN, TRANS, UPLO
00011 INTEGER INFO, LDA, N
00012 REAL SCALE
00013
00014
00015 REAL CNORM( * )
00016 COMPLEX A( LDA, * ), X( * )
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
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174 REAL ZERO, HALF, ONE, TWO
00175 PARAMETER ( ZERO = 0.0E+0, HALF = 0.5E+0, ONE = 1.0E+0,
00176 $ TWO = 2.0E+0 )
00177
00178
00179 LOGICAL NOTRAN, NOUNIT, UPPER
00180 INTEGER I, IMAX, J, JFIRST, JINC, JLAST
00181 REAL BIGNUM, GROW, REC, SMLNUM, TJJ, TMAX, TSCAL,
00182 $ XBND, XJ, XMAX
00183 COMPLEX CSUMJ, TJJS, USCAL, ZDUM
00184
00185
00186 LOGICAL LSAME
00187 INTEGER ICAMAX, ISAMAX
00188 REAL SCASUM, SLAMCH
00189 COMPLEX CDOTC, CDOTU, CLADIV
00190 EXTERNAL LSAME, ICAMAX, ISAMAX, SCASUM, SLAMCH, CDOTC,
00191 $ CDOTU, CLADIV
00192
00193
00194 EXTERNAL CAXPY, CSSCAL, CTRSV, SLABAD, SSCAL, XERBLA
00195
00196
00197 INTRINSIC ABS, AIMAG, CMPLX, CONJG, MAX, MIN, REAL
00198
00199
00200 REAL CABS1, CABS2
00201
00202
00203 CABS1( ZDUM ) = ABS( REAL( ZDUM ) ) + ABS( AIMAG( ZDUM ) )
00204 CABS2( ZDUM ) = ABS( REAL( ZDUM ) / 2. ) +
00205 $ ABS( AIMAG( ZDUM ) / 2. )
00206
00207
00208
00209 INFO = 0
00210 UPPER = LSAME( UPLO, 'U' )
00211 NOTRAN = LSAME( TRANS, 'N' )
00212 NOUNIT = LSAME( DIAG, 'N' )
00213
00214
00215
00216 IF( .NOT.UPPER .AND. .NOT.LSAME( UPLO, 'L' ) ) THEN
00217 INFO = -1
00218 ELSE IF( .NOT.NOTRAN .AND. .NOT.LSAME( TRANS, 'T' ) .AND. .NOT.
00219 $ LSAME( TRANS, 'C' ) ) THEN
00220 INFO = -2
00221 ELSE IF( .NOT.NOUNIT .AND. .NOT.LSAME( DIAG, 'U' ) ) THEN
00222 INFO = -3
00223 ELSE IF( .NOT.LSAME( NORMIN, 'Y' ) .AND. .NOT.
00224 $ LSAME( NORMIN, 'N' ) ) THEN
00225 INFO = -4
00226 ELSE IF( N.LT.0 ) THEN
00227 INFO = -5
00228 ELSE IF( LDA.LT.MAX( 1, N ) ) THEN
00229 INFO = -7
00230 END IF
00231 IF( INFO.NE.0 ) THEN
00232 CALL XERBLA( 'CLATRS', -INFO )
00233 RETURN
00234 END IF
00235
00236
00237
00238 IF( N.EQ.0 )
00239 $ RETURN
00240
00241
00242
00243 SMLNUM = SLAMCH( 'Safe minimum' )
00244 BIGNUM = ONE / SMLNUM
00245 CALL SLABAD( SMLNUM, BIGNUM )
00246 SMLNUM = SMLNUM / SLAMCH( 'Precision' )
00247 BIGNUM = ONE / SMLNUM
00248 SCALE = ONE
00249
00250 IF( LSAME( NORMIN, 'N' ) ) THEN
00251
00252
00253
00254 IF( UPPER ) THEN
00255
00256
00257
00258 DO 10 J = 1, N
00259 CNORM( J ) = SCASUM( J-1, A( 1, J ), 1 )
00260 10 CONTINUE
00261 ELSE
00262
00263
00264
00265 DO 20 J = 1, N - 1
00266 CNORM( J ) = SCASUM( N-J, A( J+1, J ), 1 )
00267 20 CONTINUE
00268 CNORM( N ) = ZERO
00269 END IF
00270 END IF
00271
00272
00273
00274
00275 IMAX = ISAMAX( N, CNORM, 1 )
00276 TMAX = CNORM( IMAX )
00277 IF( TMAX.LE.BIGNUM*HALF ) THEN
00278 TSCAL = ONE
00279 ELSE
00280 TSCAL = HALF / ( SMLNUM*TMAX )
00281 CALL SSCAL( N, TSCAL, CNORM, 1 )
00282 END IF
00283
00284
00285
00286
00287 XMAX = ZERO
00288 DO 30 J = 1, N
00289 XMAX = MAX( XMAX, CABS2( X( J ) ) )
00290 30 CONTINUE
00291 XBND = XMAX
00292
00293 IF( NOTRAN ) THEN
00294
00295
00296
00297 IF( UPPER ) THEN
00298 JFIRST = N
00299 JLAST = 1
00300 JINC = -1
00301 ELSE
00302 JFIRST = 1
00303 JLAST = N
00304 JINC = 1
00305 END IF
00306
00307 IF( TSCAL.NE.ONE ) THEN
00308 GROW = ZERO
00309 GO TO 60
00310 END IF
00311
00312 IF( NOUNIT ) THEN
00313
00314
00315
00316
00317
00318
00319 GROW = HALF / MAX( XBND, SMLNUM )
00320 XBND = GROW
00321 DO 40 J = JFIRST, JLAST, JINC
00322
00323
00324
00325 IF( GROW.LE.SMLNUM )
00326 $ GO TO 60
00327
00328 TJJS = A( J, J )
00329 TJJ = CABS1( TJJS )
00330
00331 IF( TJJ.GE.SMLNUM ) THEN
00332
00333
00334
00335 XBND = MIN( XBND, MIN( ONE, TJJ )*GROW )
00336 ELSE
00337
00338
00339
00340 XBND = ZERO
00341 END IF
00342
00343 IF( TJJ+CNORM( J ).GE.SMLNUM ) THEN
00344
00345
00346
00347 GROW = GROW*( TJJ / ( TJJ+CNORM( J ) ) )
00348 ELSE
00349
00350
00351
00352 GROW = ZERO
00353 END IF
00354 40 CONTINUE
00355 GROW = XBND
00356 ELSE
00357
00358
00359
00360
00361
00362 GROW = MIN( ONE, HALF / MAX( XBND, SMLNUM ) )
00363 DO 50 J = JFIRST, JLAST, JINC
00364
00365
00366
00367 IF( GROW.LE.SMLNUM )
00368 $ GO TO 60
00369
00370
00371
00372 GROW = GROW*( ONE / ( ONE+CNORM( J ) ) )
00373 50 CONTINUE
00374 END IF
00375 60 CONTINUE
00376
00377 ELSE
00378
00379
00380
00381 IF( UPPER ) THEN
00382 JFIRST = 1
00383 JLAST = N
00384 JINC = 1
00385 ELSE
00386 JFIRST = N
00387 JLAST = 1
00388 JINC = -1
00389 END IF
00390
00391 IF( TSCAL.NE.ONE ) THEN
00392 GROW = ZERO
00393 GO TO 90
00394 END IF
00395
00396 IF( NOUNIT ) THEN
00397
00398
00399
00400
00401
00402
00403 GROW = HALF / MAX( XBND, SMLNUM )
00404 XBND = GROW
00405 DO 70 J = JFIRST, JLAST, JINC
00406
00407
00408
00409 IF( GROW.LE.SMLNUM )
00410 $ GO TO 90
00411
00412
00413
00414 XJ = ONE + CNORM( J )
00415 GROW = MIN( GROW, XBND / XJ )
00416
00417 TJJS = A( J, J )
00418 TJJ = CABS1( TJJS )
00419
00420 IF( TJJ.GE.SMLNUM ) THEN
00421
00422
00423
00424 IF( XJ.GT.TJJ )
00425 $ XBND = XBND*( TJJ / XJ )
00426 ELSE
00427
00428
00429
00430 XBND = ZERO
00431 END IF
00432 70 CONTINUE
00433 GROW = MIN( GROW, XBND )
00434 ELSE
00435
00436
00437
00438
00439
00440 GROW = MIN( ONE, HALF / MAX( XBND, SMLNUM ) )
00441 DO 80 J = JFIRST, JLAST, JINC
00442
00443
00444
00445 IF( GROW.LE.SMLNUM )
00446 $ GO TO 90
00447
00448
00449
00450 XJ = ONE + CNORM( J )
00451 GROW = GROW / XJ
00452 80 CONTINUE
00453 END IF
00454 90 CONTINUE
00455 END IF
00456
00457 IF( ( GROW*TSCAL ).GT.SMLNUM ) THEN
00458
00459
00460
00461
00462 CALL CTRSV( UPLO, TRANS, DIAG, N, A, LDA, X, 1 )
00463 ELSE
00464
00465
00466
00467 IF( XMAX.GT.BIGNUM*HALF ) THEN
00468
00469
00470
00471
00472 SCALE = ( BIGNUM*HALF ) / XMAX
00473 CALL CSSCAL( N, SCALE, X, 1 )
00474 XMAX = BIGNUM
00475 ELSE
00476 XMAX = XMAX*TWO
00477 END IF
00478
00479 IF( NOTRAN ) THEN
00480
00481
00482
00483 DO 110 J = JFIRST, JLAST, JINC
00484
00485
00486
00487 XJ = CABS1( X( J ) )
00488 IF( NOUNIT ) THEN
00489 TJJS = A( J, J )*TSCAL
00490 ELSE
00491 TJJS = TSCAL
00492 IF( TSCAL.EQ.ONE )
00493 $ GO TO 105
00494 END IF
00495 TJJ = CABS1( TJJS )
00496 IF( TJJ.GT.SMLNUM ) THEN
00497
00498
00499
00500 IF( TJJ.LT.ONE ) THEN
00501 IF( XJ.GT.TJJ*BIGNUM ) THEN
00502
00503
00504
00505 REC = ONE / XJ
00506 CALL CSSCAL( N, REC, X, 1 )
00507 SCALE = SCALE*REC
00508 XMAX = XMAX*REC
00509 END IF
00510 END IF
00511 X( J ) = CLADIV( X( J ), TJJS )
00512 XJ = CABS1( X( J ) )
00513 ELSE IF( TJJ.GT.ZERO ) THEN
00514
00515
00516
00517 IF( XJ.GT.TJJ*BIGNUM ) THEN
00518
00519
00520
00521
00522 REC = ( TJJ*BIGNUM ) / XJ
00523 IF( CNORM( J ).GT.ONE ) THEN
00524
00525
00526
00527
00528 REC = REC / CNORM( J )
00529 END IF
00530 CALL CSSCAL( N, REC, X, 1 )
00531 SCALE = SCALE*REC
00532 XMAX = XMAX*REC
00533 END IF
00534 X( J ) = CLADIV( X( J ), TJJS )
00535 XJ = CABS1( X( J ) )
00536 ELSE
00537
00538
00539
00540
00541 DO 100 I = 1, N
00542 X( I ) = ZERO
00543 100 CONTINUE
00544 X( J ) = ONE
00545 XJ = ONE
00546 SCALE = ZERO
00547 XMAX = ZERO
00548 END IF
00549 105 CONTINUE
00550
00551
00552
00553
00554 IF( XJ.GT.ONE ) THEN
00555 REC = ONE / XJ
00556 IF( CNORM( J ).GT.( BIGNUM-XMAX )*REC ) THEN
00557
00558
00559
00560 REC = REC*HALF
00561 CALL CSSCAL( N, REC, X, 1 )
00562 SCALE = SCALE*REC
00563 END IF
00564 ELSE IF( XJ*CNORM( J ).GT.( BIGNUM-XMAX ) ) THEN
00565
00566
00567
00568 CALL CSSCAL( N, HALF, X, 1 )
00569 SCALE = SCALE*HALF
00570 END IF
00571
00572 IF( UPPER ) THEN
00573 IF( J.GT.1 ) THEN
00574
00575
00576
00577
00578 CALL CAXPY( J-1, -X( J )*TSCAL, A( 1, J ), 1, X,
00579 $ 1 )
00580 I = ICAMAX( J-1, X, 1 )
00581 XMAX = CABS1( X( I ) )
00582 END IF
00583 ELSE
00584 IF( J.LT.N ) THEN
00585
00586
00587
00588
00589 CALL CAXPY( N-J, -X( J )*TSCAL, A( J+1, J ), 1,
00590 $ X( J+1 ), 1 )
00591 I = J + ICAMAX( N-J, X( J+1 ), 1 )
00592 XMAX = CABS1( X( I ) )
00593 END IF
00594 END IF
00595 110 CONTINUE
00596
00597 ELSE IF( LSAME( TRANS, 'T' ) ) THEN
00598
00599
00600
00601 DO 150 J = JFIRST, JLAST, JINC
00602
00603
00604
00605
00606 XJ = CABS1( X( J ) )
00607 USCAL = TSCAL
00608 REC = ONE / MAX( XMAX, ONE )
00609 IF( CNORM( J ).GT.( BIGNUM-XJ )*REC ) THEN
00610
00611
00612
00613 REC = REC*HALF
00614 IF( NOUNIT ) THEN
00615 TJJS = A( J, J )*TSCAL
00616 ELSE
00617 TJJS = TSCAL
00618 END IF
00619 TJJ = CABS1( TJJS )
00620 IF( TJJ.GT.ONE ) THEN
00621
00622
00623
00624 REC = MIN( ONE, REC*TJJ )
00625 USCAL = CLADIV( USCAL, TJJS )
00626 END IF
00627 IF( REC.LT.ONE ) THEN
00628 CALL CSSCAL( N, REC, X, 1 )
00629 SCALE = SCALE*REC
00630 XMAX = XMAX*REC
00631 END IF
00632 END IF
00633
00634 CSUMJ = ZERO
00635 IF( USCAL.EQ.CMPLX( ONE ) ) THEN
00636
00637
00638
00639
00640 IF( UPPER ) THEN
00641 CSUMJ = CDOTU( J-1, A( 1, J ), 1, X, 1 )
00642 ELSE IF( J.LT.N ) THEN
00643 CSUMJ = CDOTU( N-J, A( J+1, J ), 1, X( J+1 ), 1 )
00644 END IF
00645 ELSE
00646
00647
00648
00649 IF( UPPER ) THEN
00650 DO 120 I = 1, J - 1
00651 CSUMJ = CSUMJ + ( A( I, J )*USCAL )*X( I )
00652 120 CONTINUE
00653 ELSE IF( J.LT.N ) THEN
00654 DO 130 I = J + 1, N
00655 CSUMJ = CSUMJ + ( A( I, J )*USCAL )*X( I )
00656 130 CONTINUE
00657 END IF
00658 END IF
00659
00660 IF( USCAL.EQ.CMPLX( TSCAL ) ) THEN
00661
00662
00663
00664
00665 X( J ) = X( J ) - CSUMJ
00666 XJ = CABS1( X( J ) )
00667 IF( NOUNIT ) THEN
00668 TJJS = A( J, J )*TSCAL
00669 ELSE
00670 TJJS = TSCAL
00671 IF( TSCAL.EQ.ONE )
00672 $ GO TO 145
00673 END IF
00674
00675
00676
00677 TJJ = CABS1( TJJS )
00678 IF( TJJ.GT.SMLNUM ) THEN
00679
00680
00681
00682 IF( TJJ.LT.ONE ) THEN
00683 IF( XJ.GT.TJJ*BIGNUM ) THEN
00684
00685
00686
00687 REC = ONE / XJ
00688 CALL CSSCAL( N, REC, X, 1 )
00689 SCALE = SCALE*REC
00690 XMAX = XMAX*REC
00691 END IF
00692 END IF
00693 X( J ) = CLADIV( X( J ), TJJS )
00694 ELSE IF( TJJ.GT.ZERO ) THEN
00695
00696
00697
00698 IF( XJ.GT.TJJ*BIGNUM ) THEN
00699
00700
00701
00702 REC = ( TJJ*BIGNUM ) / XJ
00703 CALL CSSCAL( N, REC, X, 1 )
00704 SCALE = SCALE*REC
00705 XMAX = XMAX*REC
00706 END IF
00707 X( J ) = CLADIV( X( J ), TJJS )
00708 ELSE
00709
00710
00711
00712
00713 DO 140 I = 1, N
00714 X( I ) = ZERO
00715 140 CONTINUE
00716 X( J ) = ONE
00717 SCALE = ZERO
00718 XMAX = ZERO
00719 END IF
00720 145 CONTINUE
00721 ELSE
00722
00723
00724
00725
00726 X( J ) = CLADIV( X( J ), TJJS ) - CSUMJ
00727 END IF
00728 XMAX = MAX( XMAX, CABS1( X( J ) ) )
00729 150 CONTINUE
00730
00731 ELSE
00732
00733
00734
00735 DO 190 J = JFIRST, JLAST, JINC
00736
00737
00738
00739
00740 XJ = CABS1( X( J ) )
00741 USCAL = TSCAL
00742 REC = ONE / MAX( XMAX, ONE )
00743 IF( CNORM( J ).GT.( BIGNUM-XJ )*REC ) THEN
00744
00745
00746
00747 REC = REC*HALF
00748 IF( NOUNIT ) THEN
00749 TJJS = CONJG( A( J, J ) )*TSCAL
00750 ELSE
00751 TJJS = TSCAL
00752 END IF
00753 TJJ = CABS1( TJJS )
00754 IF( TJJ.GT.ONE ) THEN
00755
00756
00757
00758 REC = MIN( ONE, REC*TJJ )
00759 USCAL = CLADIV( USCAL, TJJS )
00760 END IF
00761 IF( REC.LT.ONE ) THEN
00762 CALL CSSCAL( N, REC, X, 1 )
00763 SCALE = SCALE*REC
00764 XMAX = XMAX*REC
00765 END IF
00766 END IF
00767
00768 CSUMJ = ZERO
00769 IF( USCAL.EQ.CMPLX( ONE ) ) THEN
00770
00771
00772
00773
00774 IF( UPPER ) THEN
00775 CSUMJ = CDOTC( J-1, A( 1, J ), 1, X, 1 )
00776 ELSE IF( J.LT.N ) THEN
00777 CSUMJ = CDOTC( N-J, A( J+1, J ), 1, X( J+1 ), 1 )
00778 END IF
00779 ELSE
00780
00781
00782
00783 IF( UPPER ) THEN
00784 DO 160 I = 1, J - 1
00785 CSUMJ = CSUMJ + ( CONJG( A( I, J ) )*USCAL )*
00786 $ X( I )
00787 160 CONTINUE
00788 ELSE IF( J.LT.N ) THEN
00789 DO 170 I = J + 1, N
00790 CSUMJ = CSUMJ + ( CONJG( A( I, J ) )*USCAL )*
00791 $ X( I )
00792 170 CONTINUE
00793 END IF
00794 END IF
00795
00796 IF( USCAL.EQ.CMPLX( TSCAL ) ) THEN
00797
00798
00799
00800
00801 X( J ) = X( J ) - CSUMJ
00802 XJ = CABS1( X( J ) )
00803 IF( NOUNIT ) THEN
00804 TJJS = CONJG( A( J, J ) )*TSCAL
00805 ELSE
00806 TJJS = TSCAL
00807 IF( TSCAL.EQ.ONE )
00808 $ GO TO 185
00809 END IF
00810
00811
00812
00813 TJJ = CABS1( TJJS )
00814 IF( TJJ.GT.SMLNUM ) THEN
00815
00816
00817
00818 IF( TJJ.LT.ONE ) THEN
00819 IF( XJ.GT.TJJ*BIGNUM ) THEN
00820
00821
00822
00823 REC = ONE / XJ
00824 CALL CSSCAL( N, REC, X, 1 )
00825 SCALE = SCALE*REC
00826 XMAX = XMAX*REC
00827 END IF
00828 END IF
00829 X( J ) = CLADIV( X( J ), TJJS )
00830 ELSE IF( TJJ.GT.ZERO ) THEN
00831
00832
00833
00834 IF( XJ.GT.TJJ*BIGNUM ) THEN
00835
00836
00837
00838 REC = ( TJJ*BIGNUM ) / XJ
00839 CALL CSSCAL( N, REC, X, 1 )
00840 SCALE = SCALE*REC
00841 XMAX = XMAX*REC
00842 END IF
00843 X( J ) = CLADIV( X( J ), TJJS )
00844 ELSE
00845
00846
00847
00848
00849 DO 180 I = 1, N
00850 X( I ) = ZERO
00851 180 CONTINUE
00852 X( J ) = ONE
00853 SCALE = ZERO
00854 XMAX = ZERO
00855 END IF
00856 185 CONTINUE
00857 ELSE
00858
00859
00860
00861
00862 X( J ) = CLADIV( X( J ), TJJS ) - CSUMJ
00863 END IF
00864 XMAX = MAX( XMAX, CABS1( X( J ) ) )
00865 190 CONTINUE
00866 END IF
00867 SCALE = SCALE / TSCAL
00868 END IF
00869
00870
00871
00872 IF( TSCAL.NE.ONE ) THEN
00873 CALL SSCAL( N, ONE / TSCAL, CNORM, 1 )
00874 END IF
00875
00876 RETURN
00877
00878
00879
00880 END