00001 SUBROUTINE SGEJSV( JOBA, JOBU, JOBV, JOBR, JOBT, JOBP,
00002 & M, N, A, LDA, SVA, U, LDU, V, LDV,
00003 & WORK, LWORK, IWORK, INFO )
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 IMPLICIT NONE
00022 INTEGER INFO, LDA, LDU, LDV, LWORK, M, N
00023
00024
00025
00026 REAL A( LDA, * ), SVA( N ), U( LDU, * ), V( LDV, * ),
00027 & WORK( LWORK )
00028 INTEGER IWORK( * )
00029 CHARACTER*1 JOBA, JOBP, JOBR, JOBT, JOBU, JOBV
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
00175
00176
00177
00178
00179
00180
00181
00182
00183
00184
00185
00186
00187
00188
00189
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199
00200
00201
00202
00203
00204
00205
00206
00207
00208
00209
00210
00211
00212
00213
00214
00215
00216
00217
00218
00219
00220
00221
00222
00223
00224
00225
00226
00227
00228
00229
00230
00231
00232
00233
00234
00235
00236
00237
00238
00239
00240
00241
00242
00243
00244
00245
00246
00247
00248
00249
00250
00251
00252
00253
00254
00255
00256
00257
00258
00259
00260
00261
00262
00263
00264
00265
00266
00267
00268
00269
00270
00271
00272
00273
00274
00275
00276
00277
00278
00279
00280
00281
00282
00283
00284
00285
00286
00287
00288
00289
00290
00291
00292
00293
00294
00295
00296
00297
00298
00299
00300
00301
00302
00303
00304
00305
00306
00307
00308
00309
00310
00311
00312
00313
00314
00315
00316
00317
00318
00319
00320
00321
00322
00323
00324
00325
00326
00327
00328
00329
00330
00331
00332
00333
00334
00335
00336
00337
00338
00339
00340
00341
00342
00343
00344
00345
00346
00347
00348
00349
00350
00351
00352
00353
00354
00355
00356
00357
00358
00359
00360
00361
00362
00363
00364
00365
00366
00367
00368
00369
00370
00371 REAL ZERO, ONE
00372 PARAMETER ( ZERO = 0.0E0, ONE = 1.0E0 )
00373
00374
00375 REAL AAPP, AAQQ, AATMAX, AATMIN, BIG, BIG1, COND_OK,
00376 & CONDR1, CONDR2, ENTRA, ENTRAT, EPSLN, MAXPRJ, SCALEM,
00377 & SCONDA, SFMIN, SMALL, TEMP1, USCAL1, USCAL2, XSC
00378 INTEGER IERR, N1, NR, NUMRANK, p, q, WARNING
00379 LOGICAL ALMORT, DEFR, ERREST, GOSCAL, JRACC, KILL, LSVEC,
00380 & L2ABER, L2KILL, L2PERT, L2RANK, L2TRAN,
00381 & NOSCAL, ROWPIV, RSVEC, TRANSP
00382
00383
00384 INTRINSIC ABS, ALOG, AMAX1, AMIN1, FLOAT,
00385 & MAX0, MIN0, NINT, SIGN, SQRT
00386
00387
00388 REAL SLAMCH, SNRM2
00389 INTEGER ISAMAX
00390 LOGICAL LSAME
00391 EXTERNAL ISAMAX, LSAME, SLAMCH, SNRM2
00392
00393
00394 EXTERNAL SCOPY, SGELQF, SGEQP3, SGEQRF, SLACPY, SLASCL,
00395 & SLASET, SLASSQ, SLASWP, SORGQR, SORMLQ,
00396 & SORMQR, SPOCON, SSCAL, SSWAP, STRSM, XERBLA
00397
00398 EXTERNAL SGESVJ
00399
00400
00401
00402
00403 LSVEC = LSAME( JOBU, 'U' ) .OR. LSAME( JOBU, 'F' )
00404 JRACC = LSAME( JOBV, 'J' )
00405 RSVEC = LSAME( JOBV, 'V' ) .OR. JRACC
00406 ROWPIV = LSAME( JOBA, 'F' ) .OR. LSAME( JOBA, 'G' )
00407 L2RANK = LSAME( JOBA, 'R' )
00408 L2ABER = LSAME( JOBA, 'A' )
00409 ERREST = LSAME( JOBA, 'E' ) .OR. LSAME( JOBA, 'G' )
00410 L2TRAN = LSAME( JOBT, 'T' )
00411 L2KILL = LSAME( JOBR, 'R' )
00412 DEFR = LSAME( JOBR, 'N' )
00413 L2PERT = LSAME( JOBP, 'P' )
00414
00415 IF ( .NOT.(ROWPIV .OR. L2RANK .OR. L2ABER .OR.
00416 & ERREST .OR. LSAME( JOBA, 'C' ) )) THEN
00417 INFO = - 1
00418 ELSE IF ( .NOT.( LSVEC .OR. LSAME( JOBU, 'N' ) .OR.
00419 & LSAME( JOBU, 'W' )) ) THEN
00420 INFO = - 2
00421 ELSE IF ( .NOT.( RSVEC .OR. LSAME( JOBV, 'N' ) .OR.
00422 & LSAME( JOBV, 'W' )) .OR. ( JRACC .AND. (.NOT.LSVEC) ) ) THEN
00423 INFO = - 3
00424 ELSE IF ( .NOT. ( L2KILL .OR. DEFR ) ) THEN
00425 INFO = - 4
00426 ELSE IF ( .NOT. ( L2TRAN .OR. LSAME( JOBT, 'N' ) ) ) THEN
00427 INFO = - 5
00428 ELSE IF ( .NOT. ( L2PERT .OR. LSAME( JOBP, 'N' ) ) ) THEN
00429 INFO = - 6
00430 ELSE IF ( M .LT. 0 ) THEN
00431 INFO = - 7
00432 ELSE IF ( ( N .LT. 0 ) .OR. ( N .GT. M ) ) THEN
00433 INFO = - 8
00434 ELSE IF ( LDA .LT. M ) THEN
00435 INFO = - 10
00436 ELSE IF ( LSVEC .AND. ( LDU .LT. M ) ) THEN
00437 INFO = - 13
00438 ELSE IF ( RSVEC .AND. ( LDV .LT. N ) ) THEN
00439 INFO = - 14
00440 ELSE IF ( (.NOT.(LSVEC .OR. RSVEC .OR. ERREST).AND.
00441 & (LWORK .LT. MAX0(7,4*N+1,2*M+N))) .OR.
00442 & (.NOT.(LSVEC .OR. LSVEC) .AND. ERREST .AND.
00443 & (LWORK .LT. MAX0(7,4*N+N*N,2*M+N))) .OR.
00444 & (LSVEC .AND. (.NOT.RSVEC) .AND. (LWORK .LT. MAX0(7,2*N+M))) .OR.
00445 & (RSVEC .AND. (.NOT.LSVEC) .AND. (LWORK .LT. MAX0(7,2*N+M))) .OR.
00446 & (LSVEC .AND. RSVEC .AND. .NOT.JRACC .AND. (LWORK.LT.6*N+2*N*N))
00447 & .OR. (LSVEC.AND.RSVEC.AND.JRACC.AND.LWORK.LT.MAX0(7,M+3*N+N*N)))
00448 & THEN
00449 INFO = - 17
00450 ELSE
00451
00452 INFO = 0
00453 END IF
00454
00455 IF ( INFO .NE. 0 ) THEN
00456
00457 CALL XERBLA( 'SGEJSV', - INFO )
00458 END IF
00459
00460
00461
00462 IF ( ( M .EQ. 0 ) .OR. ( N .EQ. 0 ) ) RETURN
00463
00464
00465
00466 IF ( LSVEC ) THEN
00467 N1 = N
00468 IF ( LSAME( JOBU, 'F' ) ) N1 = M
00469 END IF
00470
00471
00472
00473
00474
00475 EPSLN = SLAMCH('Epsilon')
00476 SFMIN = SLAMCH('SafeMinimum')
00477 SMALL = SFMIN / EPSLN
00478 BIG = SLAMCH('O')
00479
00480
00481
00482
00483
00484
00485
00486 SCALEM = ONE / SQRT(FLOAT(M)*FLOAT(N))
00487 NOSCAL = .TRUE.
00488 GOSCAL = .TRUE.
00489 DO 1874 p = 1, N
00490 AAPP = ZERO
00491 AAQQ = ONE
00492 CALL SLASSQ( M, A(1,p), 1, AAPP, AAQQ )
00493 IF ( AAPP .GT. BIG ) THEN
00494 INFO = - 9
00495 CALL XERBLA( 'SGEJSV', -INFO )
00496 RETURN
00497 END IF
00498 AAQQ = SQRT(AAQQ)
00499 IF ( ( AAPP .LT. (BIG / AAQQ) ) .AND. NOSCAL ) THEN
00500 SVA(p) = AAPP * AAQQ
00501 ELSE
00502 NOSCAL = .FALSE.
00503 SVA(p) = AAPP * ( AAQQ * SCALEM )
00504 IF ( GOSCAL ) THEN
00505 GOSCAL = .FALSE.
00506 CALL SSCAL( p-1, SCALEM, SVA, 1 )
00507 END IF
00508 END IF
00509 1874 CONTINUE
00510
00511 IF ( NOSCAL ) SCALEM = ONE
00512
00513 AAPP = ZERO
00514 AAQQ = BIG
00515 DO 4781 p = 1, N
00516 AAPP = AMAX1( AAPP, SVA(p) )
00517 IF ( SVA(p) .NE. ZERO ) AAQQ = AMIN1( AAQQ, SVA(p) )
00518 4781 CONTINUE
00519
00520
00521
00522 IF ( AAPP .EQ. ZERO ) THEN
00523 IF ( LSVEC ) CALL SLASET( 'G', M, N1, ZERO, ONE, U, LDU )
00524 IF ( RSVEC ) CALL SLASET( 'G', N, N, ZERO, ONE, V, LDV )
00525 WORK(1) = ONE
00526 WORK(2) = ONE
00527 IF ( ERREST ) WORK(3) = ONE
00528 IF ( LSVEC .AND. RSVEC ) THEN
00529 WORK(4) = ONE
00530 WORK(5) = ONE
00531 END IF
00532 IF ( L2TRAN ) THEN
00533 WORK(6) = ZERO
00534 WORK(7) = ZERO
00535 END IF
00536 IWORK(1) = 0
00537 IWORK(2) = 0
00538 RETURN
00539 END IF
00540
00541
00542
00543
00544
00545 WARNING = 0
00546 IF ( AAQQ .LE. SFMIN ) THEN
00547 L2RANK = .TRUE.
00548 L2KILL = .TRUE.
00549 WARNING = 1
00550 END IF
00551
00552
00553
00554 IF ( N .EQ. 1 ) THEN
00555
00556 IF ( LSVEC ) THEN
00557 CALL SLASCL( 'G',0,0,SVA(1),SCALEM, M,1,A(1,1),LDA,IERR )
00558 CALL SLACPY( 'A', M, 1, A, LDA, U, LDU )
00559
00560 IF ( N1 .NE. N ) THEN
00561 CALL SGEQRF( M, N, U,LDU, WORK, WORK(N+1),LWORK-N,IERR )
00562 CALL SORGQR( M,N1,1, U,LDU,WORK,WORK(N+1),LWORK-N,IERR )
00563 CALL SCOPY( M, A(1,1), 1, U(1,1), 1 )
00564 END IF
00565 END IF
00566 IF ( RSVEC ) THEN
00567 V(1,1) = ONE
00568 END IF
00569 IF ( SVA(1) .LT. (BIG*SCALEM) ) THEN
00570 SVA(1) = SVA(1) / SCALEM
00571 SCALEM = ONE
00572 END IF
00573 WORK(1) = ONE / SCALEM
00574 WORK(2) = ONE
00575 IF ( SVA(1) .NE. ZERO ) THEN
00576 IWORK(1) = 1
00577 IF ( ( SVA(1) / SCALEM) .GE. SFMIN ) THEN
00578 IWORK(2) = 1
00579 ELSE
00580 IWORK(2) = 0
00581 END IF
00582 ELSE
00583 IWORK(1) = 0
00584 IWORK(2) = 0
00585 END IF
00586 IF ( ERREST ) WORK(3) = ONE
00587 IF ( LSVEC .AND. RSVEC ) THEN
00588 WORK(4) = ONE
00589 WORK(5) = ONE
00590 END IF
00591 IF ( L2TRAN ) THEN
00592 WORK(6) = ZERO
00593 WORK(7) = ZERO
00594 END IF
00595 RETURN
00596
00597 END IF
00598
00599 TRANSP = .FALSE.
00600 L2TRAN = L2TRAN .AND. ( M .EQ. N )
00601
00602 AATMAX = -ONE
00603 AATMIN = BIG
00604 IF ( ROWPIV .OR. L2TRAN ) THEN
00605
00606
00607
00608
00609
00610
00611 IF ( L2TRAN ) THEN
00612 DO 1950 p = 1, M
00613 XSC = ZERO
00614 TEMP1 = ONE
00615 CALL SLASSQ( N, A(p,1), LDA, XSC, TEMP1 )
00616
00617
00618 WORK(M+N+p) = XSC * SCALEM
00619 WORK(N+p) = XSC * (SCALEM*SQRT(TEMP1))
00620 AATMAX = AMAX1( AATMAX, WORK(N+p) )
00621 IF (WORK(N+p) .NE. ZERO) AATMIN = AMIN1(AATMIN,WORK(N+p))
00622 1950 CONTINUE
00623 ELSE
00624 DO 1904 p = 1, M
00625 WORK(M+N+p) = SCALEM*ABS( A(p,ISAMAX(N,A(p,1),LDA)) )
00626 AATMAX = AMAX1( AATMAX, WORK(M+N+p) )
00627 AATMIN = AMIN1( AATMIN, WORK(M+N+p) )
00628 1904 CONTINUE
00629 END IF
00630
00631 END IF
00632
00633
00634
00635
00636
00637
00638
00639
00640 ENTRA = ZERO
00641 ENTRAT = ZERO
00642 IF ( L2TRAN ) THEN
00643
00644 XSC = ZERO
00645 TEMP1 = ONE
00646 CALL SLASSQ( N, SVA, 1, XSC, TEMP1 )
00647 TEMP1 = ONE / TEMP1
00648
00649 ENTRA = ZERO
00650 DO 1113 p = 1, N
00651 BIG1 = ( ( SVA(p) / XSC )**2 ) * TEMP1
00652 IF ( BIG1 .NE. ZERO ) ENTRA = ENTRA + BIG1 * ALOG(BIG1)
00653 1113 CONTINUE
00654 ENTRA = - ENTRA / ALOG(FLOAT(N))
00655
00656
00657
00658
00659
00660
00661
00662 ENTRAT = ZERO
00663 DO 1114 p = N+1, N+M
00664 BIG1 = ( ( WORK(p) / XSC )**2 ) * TEMP1
00665 IF ( BIG1 .NE. ZERO ) ENTRAT = ENTRAT + BIG1 * ALOG(BIG1)
00666 1114 CONTINUE
00667 ENTRAT = - ENTRAT / ALOG(FLOAT(M))
00668
00669
00670
00671
00672 TRANSP = ( ENTRAT .LT. ENTRA )
00673
00674
00675
00676 IF ( TRANSP ) THEN
00677
00678
00679 DO 1115 p = 1, N - 1
00680 DO 1116 q = p + 1, N
00681 TEMP1 = A(q,p)
00682 A(q,p) = A(p,q)
00683 A(p,q) = TEMP1
00684 1116 CONTINUE
00685 1115 CONTINUE
00686 DO 1117 p = 1, N
00687 WORK(M+N+p) = SVA(p)
00688 SVA(p) = WORK(N+p)
00689 1117 CONTINUE
00690 TEMP1 = AAPP
00691 AAPP = AATMAX
00692 AATMAX = TEMP1
00693 TEMP1 = AAQQ
00694 AAQQ = AATMIN
00695 AATMIN = TEMP1
00696 KILL = LSVEC
00697 LSVEC = RSVEC
00698 RSVEC = KILL
00699 IF ( LSVEC ) N1 = N
00700
00701 ROWPIV = .TRUE.
00702 END IF
00703
00704 END IF
00705
00706
00707
00708
00709
00710
00711
00712
00713
00714
00715
00716
00717 BIG1 = SQRT( BIG )
00718 TEMP1 = SQRT( BIG / FLOAT(N) )
00719
00720 CALL SLASCL( 'G', 0, 0, AAPP, TEMP1, N, 1, SVA, N, IERR )
00721 IF ( AAQQ .GT. (AAPP * SFMIN) ) THEN
00722 AAQQ = ( AAQQ / AAPP ) * TEMP1
00723 ELSE
00724 AAQQ = ( AAQQ * TEMP1 ) / AAPP
00725 END IF
00726 TEMP1 = TEMP1 * SCALEM
00727 CALL SLASCL( 'G', 0, 0, AAPP, TEMP1, M, N, A, LDA, IERR )
00728
00729
00730
00731
00732 USCAL1 = TEMP1
00733 USCAL2 = AAPP
00734
00735 IF ( L2KILL ) THEN
00736
00737
00738
00739 XSC = SQRT( SFMIN )
00740 ELSE
00741 XSC = SMALL
00742
00743
00744
00745
00746
00747
00748
00749
00750
00751 IF ( ( AAQQ.LT.SQRT(SFMIN) ) .AND. LSVEC .AND. RSVEC ) THEN
00752 JRACC = .TRUE.
00753 END IF
00754
00755 END IF
00756 IF ( AAQQ .LT. XSC ) THEN
00757 DO 700 p = 1, N
00758 IF ( SVA(p) .LT. XSC ) THEN
00759 CALL SLASET( 'A', M, 1, ZERO, ZERO, A(1,p), LDA )
00760 SVA(p) = ZERO
00761 END IF
00762 700 CONTINUE
00763 END IF
00764
00765
00766
00767 IF ( ROWPIV ) THEN
00768
00769
00770
00771
00772
00773 DO 1952 p = 1, M - 1
00774 q = ISAMAX( M-p+1, WORK(M+N+p), 1 ) + p - 1
00775 IWORK(2*N+p) = q
00776 IF ( p .NE. q ) THEN
00777 TEMP1 = WORK(M+N+p)
00778 WORK(M+N+p) = WORK(M+N+q)
00779 WORK(M+N+q) = TEMP1
00780 END IF
00781 1952 CONTINUE
00782 CALL SLASWP( N, A, LDA, 1, M-1, IWORK(2*N+1), 1 )
00783 END IF
00784
00785
00786
00787
00788
00789
00790
00791
00792
00793
00794
00795
00796
00797
00798
00799
00800 DO 1963 p = 1, N
00801
00802 IWORK(p) = 0
00803 1963 CONTINUE
00804 CALL SGEQP3( M,N,A,LDA, IWORK,WORK, WORK(N+1),LWORK-N, IERR )
00805
00806
00807
00808
00809
00810
00811
00812
00813
00814 NR = 1
00815 IF ( L2ABER ) THEN
00816
00817
00818
00819
00820 TEMP1 = SQRT(FLOAT(N))*EPSLN
00821 DO 3001 p = 2, N
00822 IF ( ABS(A(p,p)) .GE. (TEMP1*ABS(A(1,1))) ) THEN
00823 NR = NR + 1
00824 ELSE
00825 GO TO 3002
00826 END IF
00827 3001 CONTINUE
00828 3002 CONTINUE
00829 ELSE IF ( L2RANK ) THEN
00830
00831
00832
00833 TEMP1 = SQRT(SFMIN)
00834 DO 3401 p = 2, N
00835 IF ( ( ABS(A(p,p)) .LT. (EPSLN*ABS(A(p-1,p-1))) ) .OR.
00836 & ( ABS(A(p,p)) .LT. SMALL ) .OR.
00837 & ( L2KILL .AND. (ABS(A(p,p)) .LT. TEMP1) ) ) GO TO 3402
00838 NR = NR + 1
00839 3401 CONTINUE
00840 3402 CONTINUE
00841
00842 ELSE
00843
00844
00845
00846
00847
00848
00849
00850 TEMP1 = SQRT(SFMIN)
00851 DO 3301 p = 2, N
00852 IF ( ( ABS(A(p,p)) .LT. SMALL ) .OR.
00853 & ( L2KILL .AND. (ABS(A(p,p)) .LT. TEMP1) ) ) GO TO 3302
00854 NR = NR + 1
00855 3301 CONTINUE
00856 3302 CONTINUE
00857
00858 END IF
00859
00860 ALMORT = .FALSE.
00861 IF ( NR .EQ. N ) THEN
00862 MAXPRJ = ONE
00863 DO 3051 p = 2, N
00864 TEMP1 = ABS(A(p,p)) / SVA(IWORK(p))
00865 MAXPRJ = AMIN1( MAXPRJ, TEMP1 )
00866 3051 CONTINUE
00867 IF ( MAXPRJ**2 .GE. ONE - FLOAT(N)*EPSLN ) ALMORT = .TRUE.
00868 END IF
00869
00870
00871 SCONDA = - ONE
00872 CONDR1 = - ONE
00873 CONDR2 = - ONE
00874
00875 IF ( ERREST ) THEN
00876 IF ( N .EQ. NR ) THEN
00877 IF ( RSVEC ) THEN
00878
00879 CALL SLACPY( 'U', N, N, A, LDA, V, LDV )
00880 DO 3053 p = 1, N
00881 TEMP1 = SVA(IWORK(p))
00882 CALL SSCAL( p, ONE/TEMP1, V(1,p), 1 )
00883 3053 CONTINUE
00884 CALL SPOCON( 'U', N, V, LDV, ONE, TEMP1,
00885 & WORK(N+1), IWORK(2*N+M+1), IERR )
00886 ELSE IF ( LSVEC ) THEN
00887
00888 CALL SLACPY( 'U', N, N, A, LDA, U, LDU )
00889 DO 3054 p = 1, N
00890 TEMP1 = SVA(IWORK(p))
00891 CALL SSCAL( p, ONE/TEMP1, U(1,p), 1 )
00892 3054 CONTINUE
00893 CALL SPOCON( 'U', N, U, LDU, ONE, TEMP1,
00894 & WORK(N+1), IWORK(2*N+M+1), IERR )
00895 ELSE
00896 CALL SLACPY( 'U', N, N, A, LDA, WORK(N+1), N )
00897 DO 3052 p = 1, N
00898 TEMP1 = SVA(IWORK(p))
00899 CALL SSCAL( p, ONE/TEMP1, WORK(N+(p-1)*N+1), 1 )
00900 3052 CONTINUE
00901
00902 CALL SPOCON( 'U', N, WORK(N+1), N, ONE, TEMP1,
00903 & WORK(N+N*N+1), IWORK(2*N+M+1), IERR )
00904 END IF
00905 SCONDA = ONE / SQRT(TEMP1)
00906
00907
00908 ELSE
00909 SCONDA = - ONE
00910 END IF
00911 END IF
00912
00913 L2PERT = L2PERT .AND. ( ABS( A(1,1)/A(NR,NR) ) .GT. SQRT(BIG1) )
00914
00915
00916
00917
00918 IF ( .NOT. ( RSVEC .OR. LSVEC ) ) THEN
00919
00920
00921
00922
00923 DO 1946 p = 1, MIN0( N-1, NR )
00924 CALL SCOPY( N-p, A(p,p+1), LDA, A(p+1,p), 1 )
00925 1946 CONTINUE
00926
00927
00928
00929
00930
00931
00932
00933
00934
00935
00936
00937
00938
00939 IF ( .NOT. ALMORT ) THEN
00940
00941 IF ( L2PERT ) THEN
00942
00943 XSC = EPSLN / FLOAT(N)
00944 DO 4947 q = 1, NR
00945 TEMP1 = XSC*ABS(A(q,q))
00946 DO 4949 p = 1, N
00947 IF ( ( (p.GT.q) .AND. (ABS(A(p,q)).LE.TEMP1) )
00948 & .OR. ( p .LT. q ) )
00949 & A(p,q) = SIGN( TEMP1, A(p,q) )
00950 4949 CONTINUE
00951 4947 CONTINUE
00952 ELSE
00953 CALL SLASET( 'U', NR-1,NR-1, ZERO,ZERO, A(1,2),LDA )
00954 END IF
00955
00956
00957
00958 CALL SGEQRF( N,NR, A,LDA, WORK, WORK(N+1),LWORK-N, IERR )
00959
00960
00961 DO 1948 p = 1, NR - 1
00962 CALL SCOPY( NR-p, A(p,p+1), LDA, A(p+1,p), 1 )
00963 1948 CONTINUE
00964
00965 END IF
00966
00967
00968
00969
00970
00971 IF ( L2PERT ) THEN
00972
00973 XSC = EPSLN / FLOAT(N)
00974 DO 1947 q = 1, NR
00975 TEMP1 = XSC*ABS(A(q,q))
00976 DO 1949 p = 1, NR
00977 IF ( ( (p.GT.q) .AND. (ABS(A(p,q)).LE.TEMP1) )
00978 & .OR. ( p .LT. q ) )
00979 & A(p,q) = SIGN( TEMP1, A(p,q) )
00980 1949 CONTINUE
00981 1947 CONTINUE
00982 ELSE
00983 CALL SLASET( 'U', NR-1, NR-1, ZERO, ZERO, A(1,2), LDA )
00984 END IF
00985
00986
00987
00988
00989
00990 CALL SGESVJ( 'L', 'NoU', 'NoV', NR, NR, A, LDA, SVA,
00991 & N, V, LDV, WORK, LWORK, INFO )
00992
00993 SCALEM = WORK(1)
00994 NUMRANK = NINT(WORK(2))
00995
00996
00997 ELSE IF ( RSVEC .AND. ( .NOT. LSVEC ) ) THEN
00998
00999
01000
01001 IF ( ALMORT ) THEN
01002
01003
01004 DO 1998 p = 1, NR
01005 CALL SCOPY( N-p+1, A(p,p), LDA, V(p,p), 1 )
01006 1998 CONTINUE
01007 CALL SLASET( 'Upper', NR-1, NR-1, ZERO, ZERO, V(1,2), LDV )
01008
01009 CALL SGESVJ( 'L','U','N', N, NR, V,LDV, SVA, NR, A,LDA,
01010 & WORK, LWORK, INFO )
01011 SCALEM = WORK(1)
01012 NUMRANK = NINT(WORK(2))
01013
01014 ELSE
01015
01016
01017
01018
01019 CALL SLASET( 'Lower', NR-1, NR-1, ZERO, ZERO, A(2,1), LDA )
01020 CALL SGELQF( NR, N, A, LDA, WORK, WORK(N+1), LWORK-N, IERR)
01021 CALL SLACPY( 'Lower', NR, NR, A, LDA, V, LDV )
01022 CALL SLASET( 'Upper', NR-1, NR-1, ZERO, ZERO, V(1,2), LDV )
01023 CALL SGEQRF( NR, NR, V, LDV, WORK(N+1), WORK(2*N+1),
01024 & LWORK-2*N, IERR )
01025 DO 8998 p = 1, NR
01026 CALL SCOPY( NR-p+1, V(p,p), LDV, V(p,p), 1 )
01027 8998 CONTINUE
01028 CALL SLASET( 'Upper', NR-1, NR-1, ZERO, ZERO, V(1,2), LDV )
01029
01030 CALL SGESVJ( 'Lower', 'U','N', NR, NR, V,LDV, SVA, NR, U,
01031 & LDU, WORK(N+1), LWORK, INFO )
01032 SCALEM = WORK(N+1)
01033 NUMRANK = NINT(WORK(N+2))
01034 IF ( NR .LT. N ) THEN
01035 CALL SLASET( 'A',N-NR, NR, ZERO,ZERO, V(NR+1,1), LDV )
01036 CALL SLASET( 'A',NR, N-NR, ZERO,ZERO, V(1,NR+1), LDV )
01037 CALL SLASET( 'A',N-NR,N-NR,ZERO,ONE, V(NR+1,NR+1), LDV )
01038 END IF
01039
01040 CALL SORMLQ( 'Left', 'Transpose', N, N, NR, A, LDA, WORK,
01041 & V, LDV, WORK(N+1), LWORK-N, IERR )
01042
01043 END IF
01044
01045 DO 8991 p = 1, N
01046 CALL SCOPY( N, V(p,1), LDV, A(IWORK(p),1), LDA )
01047 8991 CONTINUE
01048 CALL SLACPY( 'All', N, N, A, LDA, V, LDV )
01049
01050 IF ( TRANSP ) THEN
01051 CALL SLACPY( 'All', N, N, V, LDV, U, LDU )
01052 END IF
01053
01054 ELSE IF ( LSVEC .AND. ( .NOT. RSVEC ) ) THEN
01055
01056
01057
01058
01059
01060 DO 1965 p = 1, NR
01061 CALL SCOPY( N-p+1, A(p,p), LDA, U(p,p), 1 )
01062 1965 CONTINUE
01063 CALL SLASET( 'Upper', NR-1, NR-1, ZERO, ZERO, U(1,2), LDU )
01064
01065 CALL SGEQRF( N, NR, U, LDU, WORK(N+1), WORK(2*N+1),
01066 & LWORK-2*N, IERR )
01067
01068 DO 1967 p = 1, NR - 1
01069 CALL SCOPY( NR-p, U(p,p+1), LDU, U(p+1,p), 1 )
01070 1967 CONTINUE
01071 CALL SLASET( 'Upper', NR-1, NR-1, ZERO, ZERO, U(1,2), LDU )
01072
01073 CALL SGESVJ( 'Lower', 'U', 'N', NR,NR, U, LDU, SVA, NR, A,
01074 & LDA, WORK(N+1), LWORK-N, INFO )
01075 SCALEM = WORK(N+1)
01076 NUMRANK = NINT(WORK(N+2))
01077
01078 IF ( NR .LT. M ) THEN
01079 CALL SLASET( 'A', M-NR, NR,ZERO, ZERO, U(NR+1,1), LDU )
01080 IF ( NR .LT. N1 ) THEN
01081 CALL SLASET( 'A',NR, N1-NR, ZERO, ZERO, U(1,NR+1), LDU )
01082 CALL SLASET( 'A',M-NR,N1-NR,ZERO,ONE,U(NR+1,NR+1), LDU )
01083 END IF
01084 END IF
01085
01086 CALL SORMQR( 'Left', 'No Tr', M, N1, N, A, LDA, WORK, U,
01087 & LDU, WORK(N+1), LWORK-N, IERR )
01088
01089 IF ( ROWPIV )
01090 & CALL SLASWP( N1, U, LDU, 1, M-1, IWORK(2*N+1), -1 )
01091
01092 DO 1974 p = 1, N1
01093 XSC = ONE / SNRM2( M, U(1,p), 1 )
01094 CALL SSCAL( M, XSC, U(1,p), 1 )
01095 1974 CONTINUE
01096
01097 IF ( TRANSP ) THEN
01098 CALL SLACPY( 'All', N, N, U, LDU, V, LDV )
01099 END IF
01100
01101 ELSE
01102
01103
01104
01105 IF ( .NOT. JRACC ) THEN
01106
01107 IF ( .NOT. ALMORT ) THEN
01108
01109
01110
01111
01112
01113
01114
01115
01116 DO 1968 p = 1, NR
01117 CALL SCOPY( N-p+1, A(p,p), LDA, V(p,p), 1 )
01118 1968 CONTINUE
01119
01120
01121
01122
01123
01124
01125
01126
01127
01128
01129
01130
01131
01132 IF ( L2PERT ) THEN
01133 XSC = SQRT(SMALL)
01134 DO 2969 q = 1, NR
01135 TEMP1 = XSC*ABS( V(q,q) )
01136 DO 2968 p = 1, N
01137 IF ( ( p .GT. q ) .AND. ( ABS(V(p,q)) .LE. TEMP1 )
01138 & .OR. ( p .LT. q ) )
01139 & V(p,q) = SIGN( TEMP1, V(p,q) )
01140 IF ( p. LT. q ) V(p,q) = - V(p,q)
01141 2968 CONTINUE
01142 2969 CONTINUE
01143 ELSE
01144 CALL SLASET( 'U', NR-1, NR-1, ZERO, ZERO, V(1,2), LDV )
01145 END IF
01146
01147
01148
01149
01150
01151 CALL SLACPY( 'L', NR, NR, V, LDV, WORK(2*N+1), NR )
01152 DO 3950 p = 1, NR
01153 TEMP1 = SNRM2(NR-p+1,WORK(2*N+(p-1)*NR+p),1)
01154 CALL SSCAL(NR-p+1,ONE/TEMP1,WORK(2*N+(p-1)*NR+p),1)
01155 3950 CONTINUE
01156 CALL SPOCON('Lower',NR,WORK(2*N+1),NR,ONE,TEMP1,
01157 & WORK(2*N+NR*NR+1),IWORK(M+2*N+1),IERR)
01158 CONDR1 = ONE / SQRT(TEMP1)
01159
01160
01161
01162
01163
01164 COND_OK = SQRT(FLOAT(NR))
01165
01166
01167 IF ( CONDR1 .LT. COND_OK ) THEN
01168
01169
01170
01171
01172 CALL SGEQRF( N, NR, V, LDV, WORK(N+1), WORK(2*N+1),
01173 & LWORK-2*N, IERR )
01174
01175 IF ( L2PERT ) THEN
01176 XSC = SQRT(SMALL)/EPSLN
01177 DO 3959 p = 2, NR
01178 DO 3958 q = 1, p - 1
01179 TEMP1 = XSC * AMIN1(ABS(V(p,p)),ABS(V(q,q)))
01180 IF ( ABS(V(q,p)) .LE. TEMP1 )
01181 & V(q,p) = SIGN( TEMP1, V(q,p) )
01182 3958 CONTINUE
01183 3959 CONTINUE
01184 END IF
01185
01186 IF ( NR .NE. N )
01187
01188 & CALL SLACPY( 'A', N, NR, V, LDV, WORK(2*N+1), N )
01189
01190
01191 DO 1969 p = 1, NR - 1
01192 CALL SCOPY( NR-p, V(p,p+1), LDV, V(p+1,p), 1 )
01193 1969 CONTINUE
01194
01195 CONDR2 = CONDR1
01196
01197 ELSE
01198
01199
01200
01201
01202
01203
01204
01205
01206
01207 DO 3003 p = 1, NR
01208 IWORK(N+p) = 0
01209 3003 CONTINUE
01210 CALL SGEQP3( N, NR, V, LDV, IWORK(N+1), WORK(N+1),
01211 & WORK(2*N+1), LWORK-2*N, IERR )
01212
01213
01214 IF ( L2PERT ) THEN
01215 XSC = SQRT(SMALL)
01216 DO 3969 p = 2, NR
01217 DO 3968 q = 1, p - 1
01218 TEMP1 = XSC * AMIN1(ABS(V(p,p)),ABS(V(q,q)))
01219 IF ( ABS(V(q,p)) .LE. TEMP1 )
01220 & V(q,p) = SIGN( TEMP1, V(q,p) )
01221 3968 CONTINUE
01222 3969 CONTINUE
01223 END IF
01224
01225 CALL SLACPY( 'A', N, NR, V, LDV, WORK(2*N+1), N )
01226
01227 IF ( L2PERT ) THEN
01228 XSC = SQRT(SMALL)
01229 DO 8970 p = 2, NR
01230 DO 8971 q = 1, p - 1
01231 TEMP1 = XSC * AMIN1(ABS(V(p,p)),ABS(V(q,q)))
01232 V(p,q) = - SIGN( TEMP1, V(q,p) )
01233 8971 CONTINUE
01234 8970 CONTINUE
01235 ELSE
01236 CALL SLASET( 'L',NR-1,NR-1,ZERO,ZERO,V(2,1),LDV )
01237 END IF
01238
01239 CALL SGELQF( NR, NR, V, LDV, WORK(2*N+N*NR+1),
01240 & WORK(2*N+N*NR+NR+1), LWORK-2*N-N*NR-NR, IERR )
01241
01242 CALL SLACPY( 'L',NR,NR,V,LDV,WORK(2*N+N*NR+NR+1),NR )
01243 DO 4950 p = 1, NR
01244 TEMP1 = SNRM2( p, WORK(2*N+N*NR+NR+p), NR )
01245 CALL SSCAL( p, ONE/TEMP1, WORK(2*N+N*NR+NR+p), NR )
01246 4950 CONTINUE
01247 CALL SPOCON( 'L',NR,WORK(2*N+N*NR+NR+1),NR,ONE,TEMP1,
01248 & WORK(2*N+N*NR+NR+NR*NR+1),IWORK(M+2*N+1),IERR )
01249 CONDR2 = ONE / SQRT(TEMP1)
01250
01251 IF ( CONDR2 .GE. COND_OK ) THEN
01252
01253
01254
01255
01256 CALL SLACPY( 'U', NR, NR, V, LDV, WORK(2*N+1), N )
01257
01258
01259 END IF
01260
01261 END IF
01262
01263 IF ( L2PERT ) THEN
01264 XSC = SQRT(SMALL)
01265 DO 4968 q = 2, NR
01266 TEMP1 = XSC * V(q,q)
01267 DO 4969 p = 1, q - 1
01268
01269 V(p,q) = - SIGN( TEMP1, V(p,q) )
01270 4969 CONTINUE
01271 4968 CONTINUE
01272 ELSE
01273 CALL SLASET( 'U', NR-1,NR-1, ZERO,ZERO, V(1,2), LDV )
01274 END IF
01275
01276
01277
01278
01279
01280
01281
01282 IF ( CONDR1 .LT. COND_OK ) THEN
01283
01284 CALL SGESVJ( 'L','U','N',NR,NR,V,LDV,SVA,NR,U,
01285 & LDU,WORK(2*N+N*NR+NR+1),LWORK-2*N-N*NR-NR,INFO )
01286 SCALEM = WORK(2*N+N*NR+NR+1)
01287 NUMRANK = NINT(WORK(2*N+N*NR+NR+2))
01288 DO 3970 p = 1, NR
01289 CALL SCOPY( NR, V(1,p), 1, U(1,p), 1 )
01290 CALL SSCAL( NR, SVA(p), V(1,p), 1 )
01291 3970 CONTINUE
01292
01293
01294
01295 IF ( NR. EQ. N ) THEN
01296
01297
01298
01299
01300 CALL STRSM( 'L','U','N','N', NR,NR,ONE, A,LDA, V,LDV )
01301 ELSE
01302
01303
01304
01305
01306 CALL STRSM('L','U','T','N',NR,NR,ONE,WORK(2*N+1),
01307 & N,V,LDV)
01308 IF ( NR .LT. N ) THEN
01309 CALL SLASET('A',N-NR,NR,ZERO,ZERO,V(NR+1,1),LDV)
01310 CALL SLASET('A',NR,N-NR,ZERO,ZERO,V(1,NR+1),LDV)
01311 CALL SLASET('A',N-NR,N-NR,ZERO,ONE,V(NR+1,NR+1),LDV)
01312 END IF
01313 CALL SORMQR('L','N',N,N,NR,WORK(2*N+1),N,WORK(N+1),
01314 & V,LDV,WORK(2*N+N*NR+NR+1),LWORK-2*N-N*NR-NR,IERR)
01315 END IF
01316
01317 ELSE IF ( CONDR2 .LT. COND_OK ) THEN
01318
01319
01320
01321
01322
01323
01324
01325 CALL SGESVJ( 'L', 'U', 'N', NR, NR, V, LDV, SVA, NR, U,
01326 & LDU, WORK(2*N+N*NR+NR+1), LWORK-2*N-N*NR-NR, INFO )
01327 SCALEM = WORK(2*N+N*NR+NR+1)
01328 NUMRANK = NINT(WORK(2*N+N*NR+NR+2))
01329 DO 3870 p = 1, NR
01330 CALL SCOPY( NR, V(1,p), 1, U(1,p), 1 )
01331 CALL SSCAL( NR, SVA(p), U(1,p), 1 )
01332 3870 CONTINUE
01333 CALL STRSM('L','U','N','N',NR,NR,ONE,WORK(2*N+1),N,U,LDU)
01334
01335 DO 873 q = 1, NR
01336 DO 872 p = 1, NR
01337 WORK(2*N+N*NR+NR+IWORK(N+p)) = U(p,q)
01338 872 CONTINUE
01339 DO 874 p = 1, NR
01340 U(p,q) = WORK(2*N+N*NR+NR+p)
01341 874 CONTINUE
01342 873 CONTINUE
01343 IF ( NR .LT. N ) THEN
01344 CALL SLASET( 'A',N-NR,NR,ZERO,ZERO,V(NR+1,1),LDV )
01345 CALL SLASET( 'A',NR,N-NR,ZERO,ZERO,V(1,NR+1),LDV )
01346 CALL SLASET( 'A',N-NR,N-NR,ZERO,ONE,V(NR+1,NR+1),LDV )
01347 END IF
01348 CALL SORMQR( 'L','N',N,N,NR,WORK(2*N+1),N,WORK(N+1),
01349 & V,LDV,WORK(2*N+N*NR+NR+1),LWORK-2*N-N*NR-NR,IERR )
01350 ELSE
01351
01352
01353
01354
01355
01356
01357
01358
01359
01360
01361
01362 CALL SGESVJ( 'L', 'U', 'V', NR, NR, V, LDV, SVA, NR, U,
01363 & LDU, WORK(2*N+N*NR+NR+1), LWORK-2*N-N*NR-NR, INFO )
01364 SCALEM = WORK(2*N+N*NR+NR+1)
01365 NUMRANK = NINT(WORK(2*N+N*NR+NR+2))
01366 IF ( NR .LT. N ) THEN
01367 CALL SLASET( 'A',N-NR,NR,ZERO,ZERO,V(NR+1,1),LDV )
01368 CALL SLASET( 'A',NR,N-NR,ZERO,ZERO,V(1,NR+1),LDV )
01369 CALL SLASET( 'A',N-NR,N-NR,ZERO,ONE,V(NR+1,NR+1),LDV )
01370 END IF
01371 CALL SORMQR( 'L','N',N,N,NR,WORK(2*N+1),N,WORK(N+1),
01372 & V,LDV,WORK(2*N+N*NR+NR+1),LWORK-2*N-N*NR-NR,IERR )
01373
01374 CALL SORMLQ( 'L', 'T', NR, NR, NR, WORK(2*N+1), N,
01375 & WORK(2*N+N*NR+1), U, LDU, WORK(2*N+N*NR+NR+1),
01376 & LWORK-2*N-N*NR-NR, IERR )
01377 DO 773 q = 1, NR
01378 DO 772 p = 1, NR
01379 WORK(2*N+N*NR+NR+IWORK(N+p)) = U(p,q)
01380 772 CONTINUE
01381 DO 774 p = 1, NR
01382 U(p,q) = WORK(2*N+N*NR+NR+p)
01383 774 CONTINUE
01384 773 CONTINUE
01385
01386 END IF
01387
01388
01389
01390
01391
01392 TEMP1 = SQRT(FLOAT(N)) * EPSLN
01393 DO 1972 q = 1, N
01394 DO 972 p = 1, N
01395 WORK(2*N+N*NR+NR+IWORK(p)) = V(p,q)
01396 972 CONTINUE
01397 DO 973 p = 1, N
01398 V(p,q) = WORK(2*N+N*NR+NR+p)
01399 973 CONTINUE
01400 XSC = ONE / SNRM2( N, V(1,q), 1 )
01401 IF ( (XSC .LT. (ONE-TEMP1)) .OR. (XSC .GT. (ONE+TEMP1)) )
01402 & CALL SSCAL( N, XSC, V(1,q), 1 )
01403 1972 CONTINUE
01404
01405
01406 IF ( NR .LT. M ) THEN
01407 CALL SLASET( 'A', M-NR, NR, ZERO, ZERO, U(NR+1,1), LDU )
01408 IF ( NR .LT. N1 ) THEN
01409 CALL SLASET('A',NR,N1-NR,ZERO,ZERO,U(1,NR+1),LDU)
01410 CALL SLASET('A',M-NR,N1-NR,ZERO,ONE,U(NR+1,NR+1),LDU)
01411 END IF
01412 END IF
01413
01414
01415
01416
01417 CALL SORMQR( 'Left', 'No_Tr', M, N1, N, A, LDA, WORK, U,
01418 & LDU, WORK(N+1), LWORK-N, IERR )
01419
01420
01421 TEMP1 = SQRT(FLOAT(M)) * EPSLN
01422 DO 1973 p = 1, NR
01423 XSC = ONE / SNRM2( M, U(1,p), 1 )
01424 IF ( (XSC .LT. (ONE-TEMP1)) .OR. (XSC .GT. (ONE+TEMP1)) )
01425 & CALL SSCAL( M, XSC, U(1,p), 1 )
01426 1973 CONTINUE
01427
01428
01429
01430
01431 IF ( ROWPIV )
01432 & CALL SLASWP( N1, U, LDU, 1, M-1, IWORK(2*N+1), -1 )
01433
01434 ELSE
01435
01436
01437
01438
01439 CALL SLACPY( 'Upper', N, N, A, LDA, WORK(N+1), N )
01440 IF ( L2PERT ) THEN
01441 XSC = SQRT(SMALL)
01442 DO 5970 p = 2, N
01443 TEMP1 = XSC * WORK( N + (p-1)*N + p )
01444 DO 5971 q = 1, p - 1
01445 WORK(N+(q-1)*N+p)=-SIGN(TEMP1,WORK(N+(p-1)*N+q))
01446 5971 CONTINUE
01447 5970 CONTINUE
01448 ELSE
01449 CALL SLASET( 'Lower',N-1,N-1,ZERO,ZERO,WORK(N+2),N )
01450 END IF
01451
01452 CALL SGESVJ( 'Upper', 'U', 'N', N, N, WORK(N+1), N, SVA,
01453 & N, U, LDU, WORK(N+N*N+1), LWORK-N-N*N, INFO )
01454
01455 SCALEM = WORK(N+N*N+1)
01456 NUMRANK = NINT(WORK(N+N*N+2))
01457 DO 6970 p = 1, N
01458 CALL SCOPY( N, WORK(N+(p-1)*N+1), 1, U(1,p), 1 )
01459 CALL SSCAL( N, SVA(p), WORK(N+(p-1)*N+1), 1 )
01460 6970 CONTINUE
01461
01462 CALL STRSM( 'Left', 'Upper', 'NoTrans', 'No UD', N, N,
01463 & ONE, A, LDA, WORK(N+1), N )
01464 DO 6972 p = 1, N
01465 CALL SCOPY( N, WORK(N+p), N, V(IWORK(p),1), LDV )
01466 6972 CONTINUE
01467 TEMP1 = SQRT(FLOAT(N))*EPSLN
01468 DO 6971 p = 1, N
01469 XSC = ONE / SNRM2( N, V(1,p), 1 )
01470 IF ( (XSC .LT. (ONE-TEMP1)) .OR. (XSC .GT. (ONE+TEMP1)) )
01471 & CALL SSCAL( N, XSC, V(1,p), 1 )
01472 6971 CONTINUE
01473
01474
01475
01476 IF ( N .LT. M ) THEN
01477 CALL SLASET( 'A', M-N, N, ZERO, ZERO, U(N+1,1), LDU )
01478 IF ( N .LT. N1 ) THEN
01479 CALL SLASET( 'A',N, N1-N, ZERO, ZERO, U(1,N+1),LDU )
01480 CALL SLASET( 'A',M-N,N1-N, ZERO, ONE,U(N+1,N+1),LDU )
01481 END IF
01482 END IF
01483 CALL SORMQR( 'Left', 'No Tr', M, N1, N, A, LDA, WORK, U,
01484 & LDU, WORK(N+1), LWORK-N, IERR )
01485 TEMP1 = SQRT(FLOAT(M))*EPSLN
01486 DO 6973 p = 1, N1
01487 XSC = ONE / SNRM2( M, U(1,p), 1 )
01488 IF ( (XSC .LT. (ONE-TEMP1)) .OR. (XSC .GT. (ONE+TEMP1)) )
01489 & CALL SSCAL( M, XSC, U(1,p), 1 )
01490 6973 CONTINUE
01491
01492 IF ( ROWPIV )
01493 & CALL SLASWP( N1, U, LDU, 1, M-1, IWORK(2*N+1), -1 )
01494
01495 END IF
01496
01497
01498
01499 ELSE
01500
01501
01502
01503
01504
01505
01506
01507
01508
01509
01510
01511 DO 7968 p = 1, NR
01512 CALL SCOPY( N-p+1, A(p,p), LDA, V(p,p), 1 )
01513 7968 CONTINUE
01514
01515 IF ( L2PERT ) THEN
01516 XSC = SQRT(SMALL/EPSLN)
01517 DO 5969 q = 1, NR
01518 TEMP1 = XSC*ABS( V(q,q) )
01519 DO 5968 p = 1, N
01520 IF ( ( p .GT. q ) .AND. ( ABS(V(p,q)) .LE. TEMP1 )
01521 & .OR. ( p .LT. q ) )
01522 & V(p,q) = SIGN( TEMP1, V(p,q) )
01523 IF ( p. LT. q ) V(p,q) = - V(p,q)
01524 5968 CONTINUE
01525 5969 CONTINUE
01526 ELSE
01527 CALL SLASET( 'U', NR-1, NR-1, ZERO, ZERO, V(1,2), LDV )
01528 END IF
01529
01530 CALL SGEQRF( N, NR, V, LDV, WORK(N+1), WORK(2*N+1),
01531 & LWORK-2*N, IERR )
01532 CALL SLACPY( 'L', N, NR, V, LDV, WORK(2*N+1), N )
01533
01534 DO 7969 p = 1, NR
01535 CALL SCOPY( NR-p+1, V(p,p), LDV, U(p,p), 1 )
01536 7969 CONTINUE
01537
01538 IF ( L2PERT ) THEN
01539 XSC = SQRT(SMALL/EPSLN)
01540 DO 9970 q = 2, NR
01541 DO 9971 p = 1, q - 1
01542 TEMP1 = XSC * AMIN1(ABS(U(p,p)),ABS(U(q,q)))
01543 U(p,q) = - SIGN( TEMP1, U(q,p) )
01544 9971 CONTINUE
01545 9970 CONTINUE
01546 ELSE
01547 CALL SLASET('U', NR-1, NR-1, ZERO, ZERO, U(1,2), LDU )
01548 END IF
01549
01550 CALL SGESVJ( 'L', 'U', 'V', NR, NR, U, LDU, SVA,
01551 & N, V, LDV, WORK(2*N+N*NR+1), LWORK-2*N-N*NR, INFO )
01552 SCALEM = WORK(2*N+N*NR+1)
01553 NUMRANK = NINT(WORK(2*N+N*NR+2))
01554
01555 IF ( NR .LT. N ) THEN
01556 CALL SLASET( 'A',N-NR,NR,ZERO,ZERO,V(NR+1,1),LDV )
01557 CALL SLASET( 'A',NR,N-NR,ZERO,ZERO,V(1,NR+1),LDV )
01558 CALL SLASET( 'A',N-NR,N-NR,ZERO,ONE,V(NR+1,NR+1),LDV )
01559 END IF
01560
01561 CALL SORMQR( 'L','N',N,N,NR,WORK(2*N+1),N,WORK(N+1),
01562 & V,LDV,WORK(2*N+N*NR+NR+1),LWORK-2*N-N*NR-NR,IERR )
01563
01564
01565
01566
01567
01568 TEMP1 = SQRT(FLOAT(N)) * EPSLN
01569 DO 7972 q = 1, N
01570 DO 8972 p = 1, N
01571 WORK(2*N+N*NR+NR+IWORK(p)) = V(p,q)
01572 8972 CONTINUE
01573 DO 8973 p = 1, N
01574 V(p,q) = WORK(2*N+N*NR+NR+p)
01575 8973 CONTINUE
01576 XSC = ONE / SNRM2( N, V(1,q), 1 )
01577 IF ( (XSC .LT. (ONE-TEMP1)) .OR. (XSC .GT. (ONE+TEMP1)) )
01578 & CALL SSCAL( N, XSC, V(1,q), 1 )
01579 7972 CONTINUE
01580
01581
01582
01583
01584 IF ( NR .LT. M ) THEN
01585 CALL SLASET( 'A', M-NR, NR, ZERO, ZERO, U(NR+1,1), LDU )
01586 IF ( NR .LT. N1 ) THEN
01587 CALL SLASET( 'A',NR, N1-NR, ZERO, ZERO, U(1,NR+1),LDU )
01588 CALL SLASET( 'A',M-NR,N1-NR, ZERO, ONE,U(NR+1,NR+1),LDU )
01589 END IF
01590 END IF
01591
01592 CALL SORMQR( 'Left', 'No Tr', M, N1, N, A, LDA, WORK, U,
01593 & LDU, WORK(N+1), LWORK-N, IERR )
01594
01595 IF ( ROWPIV )
01596 & CALL SLASWP( N1, U, LDU, 1, M-1, IWORK(2*N+1), -1 )
01597
01598
01599 END IF
01600 IF ( TRANSP ) THEN
01601
01602 DO 6974 p = 1, N
01603 CALL SSWAP( N, U(1,p), 1, V(1,p), 1 )
01604 6974 CONTINUE
01605 END IF
01606
01607 END IF
01608
01609
01610
01611
01612 IF ( USCAL2 .LE. (BIG/SVA(1))*USCAL1 ) THEN
01613 CALL SLASCL( 'G', 0, 0, USCAL1, USCAL2, NR, 1, SVA, N, IERR )
01614 USCAL1 = ONE
01615 USCAL2 = ONE
01616 END IF
01617
01618 IF ( NR .LT. N ) THEN
01619 DO 3004 p = NR+1, N
01620 SVA(p) = ZERO
01621 3004 CONTINUE
01622 END IF
01623
01624 WORK(1) = USCAL2 * SCALEM
01625 WORK(2) = USCAL1
01626 IF ( ERREST ) WORK(3) = SCONDA
01627 IF ( LSVEC .AND. RSVEC ) THEN
01628 WORK(4) = CONDR1
01629 WORK(5) = CONDR2
01630 END IF
01631 IF ( L2TRAN ) THEN
01632 WORK(6) = ENTRA
01633 WORK(7) = ENTRAT
01634 END IF
01635
01636 IWORK(1) = NR
01637 IWORK(2) = NUMRANK
01638 IWORK(3) = WARNING
01639
01640 RETURN
01641
01642
01643
01644 END
01645