00001 SUBROUTINE DLAED2( K, N, N1, D, Q, LDQ, INDXQ, RHO, Z, DLAMDA, W,
00002 $ Q2, INDX, INDXC, INDXP, COLTYP, INFO )
00003
00004
00005
00006
00007
00008
00009
00010 INTEGER INFO, K, LDQ, N, N1
00011 DOUBLE PRECISION RHO
00012
00013
00014 INTEGER COLTYP( * ), INDX( * ), INDXC( * ), INDXP( * ),
00015 $ INDXQ( * )
00016 DOUBLE PRECISION D( * ), DLAMDA( * ), Q( LDQ, * ), Q2( * ),
00017 $ W( * ), Z( * )
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 DOUBLE PRECISION MONE, ZERO, ONE, TWO, EIGHT
00134 PARAMETER ( MONE = -1.0D0, ZERO = 0.0D0, ONE = 1.0D0,
00135 $ TWO = 2.0D0, EIGHT = 8.0D0 )
00136
00137
00138 INTEGER CTOT( 4 ), PSM( 4 )
00139
00140
00141 INTEGER CT, I, IMAX, IQ1, IQ2, J, JMAX, JS, K2, N1P1,
00142 $ N2, NJ, PJ
00143 DOUBLE PRECISION C, EPS, S, T, TAU, TOL
00144
00145
00146 INTEGER IDAMAX
00147 DOUBLE PRECISION DLAMCH, DLAPY2
00148 EXTERNAL IDAMAX, DLAMCH, DLAPY2
00149
00150
00151 EXTERNAL DCOPY, DLACPY, DLAMRG, DROT, DSCAL, XERBLA
00152
00153
00154 INTRINSIC ABS, MAX, MIN, SQRT
00155
00156
00157
00158
00159
00160 INFO = 0
00161
00162 IF( N.LT.0 ) THEN
00163 INFO = -2
00164 ELSE IF( LDQ.LT.MAX( 1, N ) ) THEN
00165 INFO = -6
00166 ELSE IF( MIN( 1, ( N / 2 ) ).GT.N1 .OR. ( N / 2 ).LT.N1 ) THEN
00167 INFO = -3
00168 END IF
00169 IF( INFO.NE.0 ) THEN
00170 CALL XERBLA( 'DLAED2', -INFO )
00171 RETURN
00172 END IF
00173
00174
00175
00176 IF( N.EQ.0 )
00177 $ RETURN
00178
00179 N2 = N - N1
00180 N1P1 = N1 + 1
00181
00182 IF( RHO.LT.ZERO ) THEN
00183 CALL DSCAL( N2, MONE, Z( N1P1 ), 1 )
00184 END IF
00185
00186
00187
00188
00189 T = ONE / SQRT( TWO )
00190 CALL DSCAL( N, T, Z, 1 )
00191
00192
00193
00194 RHO = ABS( TWO*RHO )
00195
00196
00197
00198 DO 10 I = N1P1, N
00199 INDXQ( I ) = INDXQ( I ) + N1
00200 10 CONTINUE
00201
00202
00203
00204 DO 20 I = 1, N
00205 DLAMDA( I ) = D( INDXQ( I ) )
00206 20 CONTINUE
00207 CALL DLAMRG( N1, N2, DLAMDA, 1, 1, INDXC )
00208 DO 30 I = 1, N
00209 INDX( I ) = INDXQ( INDXC( I ) )
00210 30 CONTINUE
00211
00212
00213
00214 IMAX = IDAMAX( N, Z, 1 )
00215 JMAX = IDAMAX( N, D, 1 )
00216 EPS = DLAMCH( 'Epsilon' )
00217 TOL = EIGHT*EPS*MAX( ABS( D( JMAX ) ), ABS( Z( IMAX ) ) )
00218
00219
00220
00221
00222
00223 IF( RHO*ABS( Z( IMAX ) ).LE.TOL ) THEN
00224 K = 0
00225 IQ2 = 1
00226 DO 40 J = 1, N
00227 I = INDX( J )
00228 CALL DCOPY( N, Q( 1, I ), 1, Q2( IQ2 ), 1 )
00229 DLAMDA( J ) = D( I )
00230 IQ2 = IQ2 + N
00231 40 CONTINUE
00232 CALL DLACPY( 'A', N, N, Q2, N, Q, LDQ )
00233 CALL DCOPY( N, DLAMDA, 1, D, 1 )
00234 GO TO 190
00235 END IF
00236
00237
00238
00239
00240
00241
00242
00243 DO 50 I = 1, N1
00244 COLTYP( I ) = 1
00245 50 CONTINUE
00246 DO 60 I = N1P1, N
00247 COLTYP( I ) = 3
00248 60 CONTINUE
00249
00250
00251 K = 0
00252 K2 = N + 1
00253 DO 70 J = 1, N
00254 NJ = INDX( J )
00255 IF( RHO*ABS( Z( NJ ) ).LE.TOL ) THEN
00256
00257
00258
00259 K2 = K2 - 1
00260 COLTYP( NJ ) = 4
00261 INDXP( K2 ) = NJ
00262 IF( J.EQ.N )
00263 $ GO TO 100
00264 ELSE
00265 PJ = NJ
00266 GO TO 80
00267 END IF
00268 70 CONTINUE
00269 80 CONTINUE
00270 J = J + 1
00271 NJ = INDX( J )
00272 IF( J.GT.N )
00273 $ GO TO 100
00274 IF( RHO*ABS( Z( NJ ) ).LE.TOL ) THEN
00275
00276
00277
00278 K2 = K2 - 1
00279 COLTYP( NJ ) = 4
00280 INDXP( K2 ) = NJ
00281 ELSE
00282
00283
00284
00285 S = Z( PJ )
00286 C = Z( NJ )
00287
00288
00289
00290
00291 TAU = DLAPY2( C, S )
00292 T = D( NJ ) - D( PJ )
00293 C = C / TAU
00294 S = -S / TAU
00295 IF( ABS( T*C*S ).LE.TOL ) THEN
00296
00297
00298
00299 Z( NJ ) = TAU
00300 Z( PJ ) = ZERO
00301 IF( COLTYP( NJ ).NE.COLTYP( PJ ) )
00302 $ COLTYP( NJ ) = 2
00303 COLTYP( PJ ) = 4
00304 CALL DROT( N, Q( 1, PJ ), 1, Q( 1, NJ ), 1, C, S )
00305 T = D( PJ )*C**2 + D( NJ )*S**2
00306 D( NJ ) = D( PJ )*S**2 + D( NJ )*C**2
00307 D( PJ ) = T
00308 K2 = K2 - 1
00309 I = 1
00310 90 CONTINUE
00311 IF( K2+I.LE.N ) THEN
00312 IF( D( PJ ).LT.D( INDXP( K2+I ) ) ) THEN
00313 INDXP( K2+I-1 ) = INDXP( K2+I )
00314 INDXP( K2+I ) = PJ
00315 I = I + 1
00316 GO TO 90
00317 ELSE
00318 INDXP( K2+I-1 ) = PJ
00319 END IF
00320 ELSE
00321 INDXP( K2+I-1 ) = PJ
00322 END IF
00323 PJ = NJ
00324 ELSE
00325 K = K + 1
00326 DLAMDA( K ) = D( PJ )
00327 W( K ) = Z( PJ )
00328 INDXP( K ) = PJ
00329 PJ = NJ
00330 END IF
00331 END IF
00332 GO TO 80
00333 100 CONTINUE
00334
00335
00336
00337 K = K + 1
00338 DLAMDA( K ) = D( PJ )
00339 W( K ) = Z( PJ )
00340 INDXP( K ) = PJ
00341
00342
00343
00344
00345
00346
00347 DO 110 J = 1, 4
00348 CTOT( J ) = 0
00349 110 CONTINUE
00350 DO 120 J = 1, N
00351 CT = COLTYP( J )
00352 CTOT( CT ) = CTOT( CT ) + 1
00353 120 CONTINUE
00354
00355
00356
00357 PSM( 1 ) = 1
00358 PSM( 2 ) = 1 + CTOT( 1 )
00359 PSM( 3 ) = PSM( 2 ) + CTOT( 2 )
00360 PSM( 4 ) = PSM( 3 ) + CTOT( 3 )
00361 K = N - CTOT( 4 )
00362
00363
00364
00365
00366
00367 DO 130 J = 1, N
00368 JS = INDXP( J )
00369 CT = COLTYP( JS )
00370 INDX( PSM( CT ) ) = JS
00371 INDXC( PSM( CT ) ) = J
00372 PSM( CT ) = PSM( CT ) + 1
00373 130 CONTINUE
00374
00375
00376
00377
00378
00379
00380 I = 1
00381 IQ1 = 1
00382 IQ2 = 1 + ( CTOT( 1 )+CTOT( 2 ) )*N1
00383 DO 140 J = 1, CTOT( 1 )
00384 JS = INDX( I )
00385 CALL DCOPY( N1, Q( 1, JS ), 1, Q2( IQ1 ), 1 )
00386 Z( I ) = D( JS )
00387 I = I + 1
00388 IQ1 = IQ1 + N1
00389 140 CONTINUE
00390
00391 DO 150 J = 1, CTOT( 2 )
00392 JS = INDX( I )
00393 CALL DCOPY( N1, Q( 1, JS ), 1, Q2( IQ1 ), 1 )
00394 CALL DCOPY( N2, Q( N1+1, JS ), 1, Q2( IQ2 ), 1 )
00395 Z( I ) = D( JS )
00396 I = I + 1
00397 IQ1 = IQ1 + N1
00398 IQ2 = IQ2 + N2
00399 150 CONTINUE
00400
00401 DO 160 J = 1, CTOT( 3 )
00402 JS = INDX( I )
00403 CALL DCOPY( N2, Q( N1+1, JS ), 1, Q2( IQ2 ), 1 )
00404 Z( I ) = D( JS )
00405 I = I + 1
00406 IQ2 = IQ2 + N2
00407 160 CONTINUE
00408
00409 IQ1 = IQ2
00410 DO 170 J = 1, CTOT( 4 )
00411 JS = INDX( I )
00412 CALL DCOPY( N, Q( 1, JS ), 1, Q2( IQ2 ), 1 )
00413 IQ2 = IQ2 + N
00414 Z( I ) = D( JS )
00415 I = I + 1
00416 170 CONTINUE
00417
00418
00419
00420
00421 CALL DLACPY( 'A', N, CTOT( 4 ), Q2( IQ1 ), N, Q( 1, K+1 ), LDQ )
00422 CALL DCOPY( N-K, Z( K+1 ), 1, D( K+1 ), 1 )
00423
00424
00425
00426 DO 180 J = 1, 4
00427 COLTYP( J ) = CTOT( J )
00428 180 CONTINUE
00429
00430 190 CONTINUE
00431 RETURN
00432
00433
00434
00435 END