00001 SUBROUTINE SPSTF2( UPLO, N, A, LDA, PIV, RANK, TOL, WORK, INFO )
00002
00003
00004
00005
00006
00007
00008 REAL TOL
00009 INTEGER INFO, LDA, N, RANK
00010 CHARACTER UPLO
00011
00012
00013 REAL A( LDA, * ), WORK( 2*N )
00014 INTEGER PIV( N )
00015
00016
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 REAL ONE, ZERO
00085 PARAMETER ( ONE = 1.0E+0, ZERO = 0.0E+0 )
00086
00087
00088 REAL AJJ, SSTOP, STEMP
00089 INTEGER I, ITEMP, J, PVT
00090 LOGICAL UPPER
00091
00092
00093 REAL SLAMCH
00094 LOGICAL LSAME, SISNAN
00095 EXTERNAL SLAMCH, LSAME, SISNAN
00096
00097
00098 EXTERNAL SGEMV, SSCAL, SSWAP, XERBLA
00099
00100
00101 INTRINSIC MAX, SQRT, MAXLOC
00102
00103
00104
00105
00106
00107 INFO = 0
00108 UPPER = LSAME( UPLO, 'U' )
00109 IF( .NOT.UPPER .AND. .NOT.LSAME( UPLO, 'L' ) ) THEN
00110 INFO = -1
00111 ELSE IF( N.LT.0 ) THEN
00112 INFO = -2
00113 ELSE IF( LDA.LT.MAX( 1, N ) ) THEN
00114 INFO = -4
00115 END IF
00116 IF( INFO.NE.0 ) THEN
00117 CALL XERBLA( 'SPSTF2', -INFO )
00118 RETURN
00119 END IF
00120
00121
00122
00123 IF( N.EQ.0 )
00124 $ RETURN
00125
00126
00127
00128 DO 100 I = 1, N
00129 PIV( I ) = I
00130 100 CONTINUE
00131
00132
00133
00134 PVT = 1
00135 AJJ = A( PVT, PVT )
00136 DO I = 2, N
00137 IF( A( I, I ).GT.AJJ ) THEN
00138 PVT = I
00139 AJJ = A( PVT, PVT )
00140 END IF
00141 END DO
00142 IF( AJJ.EQ.ZERO.OR.SISNAN( AJJ ) ) THEN
00143 RANK = 0
00144 INFO = 1
00145 GO TO 170
00146 END IF
00147
00148
00149
00150 IF( TOL.LT.ZERO ) THEN
00151 SSTOP = N * SLAMCH( 'Epsilon' ) * AJJ
00152 ELSE
00153 SSTOP = TOL
00154 END IF
00155
00156
00157
00158 DO 110 I = 1, N
00159 WORK( I ) = 0
00160 110 CONTINUE
00161
00162 IF( UPPER ) THEN
00163
00164
00165
00166 DO 130 J = 1, N
00167
00168
00169
00170
00171
00172 DO 120 I = J, N
00173
00174 IF( J.GT.1 ) THEN
00175 WORK( I ) = WORK( I ) + A( J-1, I )**2
00176 END IF
00177 WORK( N+I ) = A( I, I ) - WORK( I )
00178
00179 120 CONTINUE
00180
00181 IF( J.GT.1 ) THEN
00182 ITEMP = MAXLOC( WORK( (N+J):(2*N) ), 1 )
00183 PVT = ITEMP + J - 1
00184 AJJ = WORK( N+PVT )
00185 IF( AJJ.LE.SSTOP.OR.SISNAN( AJJ ) ) THEN
00186 A( J, J ) = AJJ
00187 GO TO 160
00188 END IF
00189 END IF
00190
00191 IF( J.NE.PVT ) THEN
00192
00193
00194
00195 A( PVT, PVT ) = A( J, J )
00196 CALL SSWAP( J-1, A( 1, J ), 1, A( 1, PVT ), 1 )
00197 IF( PVT.LT.N )
00198 $ CALL SSWAP( N-PVT, A( J, PVT+1 ), LDA,
00199 $ A( PVT, PVT+1 ), LDA )
00200 CALL SSWAP( PVT-J-1, A( J, J+1 ), LDA, A( J+1, PVT ), 1 )
00201
00202
00203
00204 STEMP = WORK( J )
00205 WORK( J ) = WORK( PVT )
00206 WORK( PVT ) = STEMP
00207 ITEMP = PIV( PVT )
00208 PIV( PVT ) = PIV( J )
00209 PIV( J ) = ITEMP
00210 END IF
00211
00212 AJJ = SQRT( AJJ )
00213 A( J, J ) = AJJ
00214
00215
00216
00217 IF( J.LT.N ) THEN
00218 CALL SGEMV( 'Trans', J-1, N-J, -ONE, A( 1, J+1 ), LDA,
00219 $ A( 1, J ), 1, ONE, A( J, J+1 ), LDA )
00220 CALL SSCAL( N-J, ONE / AJJ, A( J, J+1 ), LDA )
00221 END IF
00222
00223 130 CONTINUE
00224
00225 ELSE
00226
00227
00228
00229 DO 150 J = 1, N
00230
00231
00232
00233
00234
00235 DO 140 I = J, N
00236
00237 IF( J.GT.1 ) THEN
00238 WORK( I ) = WORK( I ) + A( I, J-1 )**2
00239 END IF
00240 WORK( N+I ) = A( I, I ) - WORK( I )
00241
00242 140 CONTINUE
00243
00244 IF( J.GT.1 ) THEN
00245 ITEMP = MAXLOC( WORK( (N+J):(2*N) ), 1 )
00246 PVT = ITEMP + J - 1
00247 AJJ = WORK( N+PVT )
00248 IF( AJJ.LE.SSTOP.OR.SISNAN( AJJ ) ) THEN
00249 A( J, J ) = AJJ
00250 GO TO 160
00251 END IF
00252 END IF
00253
00254 IF( J.NE.PVT ) THEN
00255
00256
00257
00258 A( PVT, PVT ) = A( J, J )
00259 CALL SSWAP( J-1, A( J, 1 ), LDA, A( PVT, 1 ), LDA )
00260 IF( PVT.LT.N )
00261 $ CALL SSWAP( N-PVT, A( PVT+1, J ), 1, A( PVT+1, PVT ),
00262 $ 1 )
00263 CALL SSWAP( PVT-J-1, A( J+1, J ), 1, A( PVT, J+1 ), LDA )
00264
00265
00266
00267 STEMP = WORK( J )
00268 WORK( J ) = WORK( PVT )
00269 WORK( PVT ) = STEMP
00270 ITEMP = PIV( PVT )
00271 PIV( PVT ) = PIV( J )
00272 PIV( J ) = ITEMP
00273 END IF
00274
00275 AJJ = SQRT( AJJ )
00276 A( J, J ) = AJJ
00277
00278
00279
00280 IF( J.LT.N ) THEN
00281 CALL SGEMV( 'No Trans', N-J, J-1, -ONE, A( J+1, 1 ), LDA,
00282 $ A( J, 1 ), LDA, ONE, A( J+1, J ), 1 )
00283 CALL SSCAL( N-J, ONE / AJJ, A( J+1, J ), 1 )
00284 END IF
00285
00286 150 CONTINUE
00287
00288 END IF
00289
00290
00291
00292 RANK = N
00293
00294 GO TO 170
00295 160 CONTINUE
00296
00297
00298
00299
00300 RANK = J - 1
00301 INFO = 1
00302
00303 170 CONTINUE
00304 RETURN
00305
00306
00307
00308 END