00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013 #include "f2c.h"
00014 #include "blaswrap.h"
00015
00016
00017
00018 static integer c__9 = 9;
00019 static integer c__0 = 0;
00020 static doublereal c_b15 = 1.;
00021 static integer c__1 = 1;
00022 static doublereal c_b29 = 0.;
00023
00024 int dbdsdc_(char *uplo, char *compq, integer *n, doublereal *
00025 d__, doublereal *e, doublereal *u, integer *ldu, doublereal *vt,
00026 integer *ldvt, doublereal *q, integer *iq, doublereal *work, integer *
00027 iwork, integer *info)
00028 {
00029
00030 integer u_dim1, u_offset, vt_dim1, vt_offset, i__1, i__2;
00031 doublereal d__1;
00032
00033
00034 double d_sign(doublereal *, doublereal *), log(doublereal);
00035
00036
00037 integer i__, j, k;
00038 doublereal p, r__;
00039 integer z__, ic, ii, kk;
00040 doublereal cs;
00041 integer is, iu;
00042 doublereal sn;
00043 integer nm1;
00044 doublereal eps;
00045 integer ivt, difl, difr, ierr, perm, mlvl, sqre;
00046 extern logical lsame_(char *, char *);
00047 extern int dlasr_(char *, char *, char *, integer *,
00048 integer *, doublereal *, doublereal *, doublereal *, integer *), dcopy_(integer *, doublereal *, integer *
00049 , doublereal *, integer *), dswap_(integer *, doublereal *,
00050 integer *, doublereal *, integer *);
00051 integer poles, iuplo, nsize, start;
00052 extern int dlasd0_(integer *, integer *, doublereal *,
00053 doublereal *, doublereal *, integer *, doublereal *, integer *,
00054 integer *, integer *, doublereal *, integer *);
00055 extern doublereal dlamch_(char *);
00056 extern int dlasda_(integer *, integer *, integer *,
00057 integer *, doublereal *, doublereal *, doublereal *, integer *,
00058 doublereal *, integer *, doublereal *, doublereal *, doublereal *,
00059 doublereal *, integer *, integer *, integer *, integer *,
00060 doublereal *, doublereal *, doublereal *, doublereal *, integer *,
00061 integer *), dlascl_(char *, integer *, integer *, doublereal *,
00062 doublereal *, integer *, integer *, doublereal *, integer *,
00063 integer *), dlasdq_(char *, integer *, integer *, integer
00064 *, integer *, integer *, doublereal *, doublereal *, doublereal *,
00065 integer *, doublereal *, integer *, doublereal *, integer *,
00066 doublereal *, integer *), dlaset_(char *, integer *,
00067 integer *, doublereal *, doublereal *, doublereal *, integer *), dlartg_(doublereal *, doublereal *, doublereal *,
00068 doublereal *, doublereal *);
00069 extern integer ilaenv_(integer *, char *, char *, integer *, integer *,
00070 integer *, integer *);
00071 extern int xerbla_(char *, integer *);
00072 integer givcol;
00073 extern doublereal dlanst_(char *, integer *, doublereal *, doublereal *);
00074 integer icompq;
00075 doublereal orgnrm;
00076 integer givnum, givptr, qstart, smlsiz, wstart, smlszp;
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 --d__;
00222 --e;
00223 u_dim1 = *ldu;
00224 u_offset = 1 + u_dim1;
00225 u -= u_offset;
00226 vt_dim1 = *ldvt;
00227 vt_offset = 1 + vt_dim1;
00228 vt -= vt_offset;
00229 --q;
00230 --iq;
00231 --work;
00232 --iwork;
00233
00234
00235 *info = 0;
00236
00237 iuplo = 0;
00238 if (lsame_(uplo, "U")) {
00239 iuplo = 1;
00240 }
00241 if (lsame_(uplo, "L")) {
00242 iuplo = 2;
00243 }
00244 if (lsame_(compq, "N")) {
00245 icompq = 0;
00246 } else if (lsame_(compq, "P")) {
00247 icompq = 1;
00248 } else if (lsame_(compq, "I")) {
00249 icompq = 2;
00250 } else {
00251 icompq = -1;
00252 }
00253 if (iuplo == 0) {
00254 *info = -1;
00255 } else if (icompq < 0) {
00256 *info = -2;
00257 } else if (*n < 0) {
00258 *info = -3;
00259 } else if (*ldu < 1 || icompq == 2 && *ldu < *n) {
00260 *info = -7;
00261 } else if (*ldvt < 1 || icompq == 2 && *ldvt < *n) {
00262 *info = -9;
00263 }
00264 if (*info != 0) {
00265 i__1 = -(*info);
00266 xerbla_("DBDSDC", &i__1);
00267 return 0;
00268 }
00269
00270
00271
00272 if (*n == 0) {
00273 return 0;
00274 }
00275 smlsiz = ilaenv_(&c__9, "DBDSDC", " ", &c__0, &c__0, &c__0, &c__0);
00276 if (*n == 1) {
00277 if (icompq == 1) {
00278 q[1] = d_sign(&c_b15, &d__[1]);
00279 q[smlsiz * *n + 1] = 1.;
00280 } else if (icompq == 2) {
00281 u[u_dim1 + 1] = d_sign(&c_b15, &d__[1]);
00282 vt[vt_dim1 + 1] = 1.;
00283 }
00284 d__[1] = abs(d__[1]);
00285 return 0;
00286 }
00287 nm1 = *n - 1;
00288
00289
00290
00291
00292 wstart = 1;
00293 qstart = 3;
00294 if (icompq == 1) {
00295 dcopy_(n, &d__[1], &c__1, &q[1], &c__1);
00296 i__1 = *n - 1;
00297 dcopy_(&i__1, &e[1], &c__1, &q[*n + 1], &c__1);
00298 }
00299 if (iuplo == 2) {
00300 qstart = 5;
00301 wstart = (*n << 1) - 1;
00302 i__1 = *n - 1;
00303 for (i__ = 1; i__ <= i__1; ++i__) {
00304 dlartg_(&d__[i__], &e[i__], &cs, &sn, &r__);
00305 d__[i__] = r__;
00306 e[i__] = sn * d__[i__ + 1];
00307 d__[i__ + 1] = cs * d__[i__ + 1];
00308 if (icompq == 1) {
00309 q[i__ + (*n << 1)] = cs;
00310 q[i__ + *n * 3] = sn;
00311 } else if (icompq == 2) {
00312 work[i__] = cs;
00313 work[nm1 + i__] = -sn;
00314 }
00315
00316 }
00317 }
00318
00319
00320
00321 if (icompq == 0) {
00322 dlasdq_("U", &c__0, n, &c__0, &c__0, &c__0, &d__[1], &e[1], &vt[
00323 vt_offset], ldvt, &u[u_offset], ldu, &u[u_offset], ldu, &work[
00324 wstart], info);
00325 goto L40;
00326 }
00327
00328
00329
00330
00331 if (*n <= smlsiz) {
00332 if (icompq == 2) {
00333 dlaset_("A", n, n, &c_b29, &c_b15, &u[u_offset], ldu);
00334 dlaset_("A", n, n, &c_b29, &c_b15, &vt[vt_offset], ldvt);
00335 dlasdq_("U", &c__0, n, n, n, &c__0, &d__[1], &e[1], &vt[vt_offset]
00336 , ldvt, &u[u_offset], ldu, &u[u_offset], ldu, &work[
00337 wstart], info);
00338 } else if (icompq == 1) {
00339 iu = 1;
00340 ivt = iu + *n;
00341 dlaset_("A", n, n, &c_b29, &c_b15, &q[iu + (qstart - 1) * *n], n);
00342 dlaset_("A", n, n, &c_b29, &c_b15, &q[ivt + (qstart - 1) * *n], n);
00343 dlasdq_("U", &c__0, n, n, n, &c__0, &d__[1], &e[1], &q[ivt + (
00344 qstart - 1) * *n], n, &q[iu + (qstart - 1) * *n], n, &q[
00345 iu + (qstart - 1) * *n], n, &work[wstart], info);
00346 }
00347 goto L40;
00348 }
00349
00350 if (icompq == 2) {
00351 dlaset_("A", n, n, &c_b29, &c_b15, &u[u_offset], ldu);
00352 dlaset_("A", n, n, &c_b29, &c_b15, &vt[vt_offset], ldvt);
00353 }
00354
00355
00356
00357 orgnrm = dlanst_("M", n, &d__[1], &e[1]);
00358 if (orgnrm == 0.) {
00359 return 0;
00360 }
00361 dlascl_("G", &c__0, &c__0, &orgnrm, &c_b15, n, &c__1, &d__[1], n, &ierr);
00362 dlascl_("G", &c__0, &c__0, &orgnrm, &c_b15, &nm1, &c__1, &e[1], &nm1, &
00363 ierr);
00364
00365 eps = dlamch_("Epsilon");
00366
00367 mlvl = (integer) (log((doublereal) (*n) / (doublereal) (smlsiz + 1)) /
00368 log(2.)) + 1;
00369 smlszp = smlsiz + 1;
00370
00371 if (icompq == 1) {
00372 iu = 1;
00373 ivt = smlsiz + 1;
00374 difl = ivt + smlszp;
00375 difr = difl + mlvl;
00376 z__ = difr + (mlvl << 1);
00377 ic = z__ + mlvl;
00378 is = ic + 1;
00379 poles = is + 1;
00380 givnum = poles + (mlvl << 1);
00381
00382 k = 1;
00383 givptr = 2;
00384 perm = 3;
00385 givcol = perm + mlvl;
00386 }
00387
00388 i__1 = *n;
00389 for (i__ = 1; i__ <= i__1; ++i__) {
00390 if ((d__1 = d__[i__], abs(d__1)) < eps) {
00391 d__[i__] = d_sign(&eps, &d__[i__]);
00392 }
00393
00394 }
00395
00396 start = 1;
00397 sqre = 0;
00398
00399 i__1 = nm1;
00400 for (i__ = 1; i__ <= i__1; ++i__) {
00401 if ((d__1 = e[i__], abs(d__1)) < eps || i__ == nm1) {
00402
00403
00404
00405
00406 if (i__ < nm1) {
00407
00408
00409
00410 nsize = i__ - start + 1;
00411 } else if ((d__1 = e[i__], abs(d__1)) >= eps) {
00412
00413
00414
00415 nsize = *n - start + 1;
00416 } else {
00417
00418
00419
00420
00421
00422 nsize = i__ - start + 1;
00423 if (icompq == 2) {
00424 u[*n + *n * u_dim1] = d_sign(&c_b15, &d__[*n]);
00425 vt[*n + *n * vt_dim1] = 1.;
00426 } else if (icompq == 1) {
00427 q[*n + (qstart - 1) * *n] = d_sign(&c_b15, &d__[*n]);
00428 q[*n + (smlsiz + qstart - 1) * *n] = 1.;
00429 }
00430 d__[*n] = (d__1 = d__[*n], abs(d__1));
00431 }
00432 if (icompq == 2) {
00433 dlasd0_(&nsize, &sqre, &d__[start], &e[start], &u[start +
00434 start * u_dim1], ldu, &vt[start + start * vt_dim1],
00435 ldvt, &smlsiz, &iwork[1], &work[wstart], info);
00436 } else {
00437 dlasda_(&icompq, &smlsiz, &nsize, &sqre, &d__[start], &e[
00438 start], &q[start + (iu + qstart - 2) * *n], n, &q[
00439 start + (ivt + qstart - 2) * *n], &iq[start + k * *n],
00440 &q[start + (difl + qstart - 2) * *n], &q[start + (
00441 difr + qstart - 2) * *n], &q[start + (z__ + qstart -
00442 2) * *n], &q[start + (poles + qstart - 2) * *n], &iq[
00443 start + givptr * *n], &iq[start + givcol * *n], n, &
00444 iq[start + perm * *n], &q[start + (givnum + qstart -
00445 2) * *n], &q[start + (ic + qstart - 2) * *n], &q[
00446 start + (is + qstart - 2) * *n], &work[wstart], &
00447 iwork[1], info);
00448 if (*info != 0) {
00449 return 0;
00450 }
00451 }
00452 start = i__ + 1;
00453 }
00454
00455 }
00456
00457
00458
00459 dlascl_("G", &c__0, &c__0, &c_b15, &orgnrm, n, &c__1, &d__[1], n, &ierr);
00460 L40:
00461
00462
00463
00464 i__1 = *n;
00465 for (ii = 2; ii <= i__1; ++ii) {
00466 i__ = ii - 1;
00467 kk = i__;
00468 p = d__[i__];
00469 i__2 = *n;
00470 for (j = ii; j <= i__2; ++j) {
00471 if (d__[j] > p) {
00472 kk = j;
00473 p = d__[j];
00474 }
00475
00476 }
00477 if (kk != i__) {
00478 d__[kk] = d__[i__];
00479 d__[i__] = p;
00480 if (icompq == 1) {
00481 iq[i__] = kk;
00482 } else if (icompq == 2) {
00483 dswap_(n, &u[i__ * u_dim1 + 1], &c__1, &u[kk * u_dim1 + 1], &
00484 c__1);
00485 dswap_(n, &vt[i__ + vt_dim1], ldvt, &vt[kk + vt_dim1], ldvt);
00486 }
00487 } else if (icompq == 1) {
00488 iq[i__] = i__;
00489 }
00490
00491 }
00492
00493
00494
00495 if (icompq == 1) {
00496 if (iuplo == 1) {
00497 iq[*n] = 1;
00498 } else {
00499 iq[*n] = 0;
00500 }
00501 }
00502
00503
00504
00505
00506 if (iuplo == 2 && icompq == 2) {
00507 dlasr_("L", "V", "B", n, n, &work[1], &work[*n], &u[u_offset], ldu);
00508 }
00509
00510 return 0;
00511
00512
00513
00514 }