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__2 = 2;
00019 static integer c__1 = 1;
00020 static integer c_n1 = -1;
00021
00022 int dstein_(integer *n, doublereal *d__, doublereal *e,
00023 integer *m, doublereal *w, integer *iblock, integer *isplit,
00024 doublereal *z__, integer *ldz, doublereal *work, integer *iwork,
00025 integer *ifail, integer *info)
00026 {
00027
00028 integer z_dim1, z_offset, i__1, i__2, i__3;
00029 doublereal d__1, d__2, d__3, d__4, d__5;
00030
00031
00032 double sqrt(doublereal);
00033
00034
00035 integer i__, j, b1, j1, bn;
00036 doublereal xj, scl, eps, sep, nrm, tol;
00037 integer its;
00038 doublereal xjm, ztr, eps1;
00039 integer jblk, nblk;
00040 extern doublereal ddot_(integer *, doublereal *, integer *, doublereal *,
00041 integer *);
00042 integer jmax;
00043 extern doublereal dnrm2_(integer *, doublereal *, integer *);
00044 extern int dscal_(integer *, doublereal *, doublereal *,
00045 integer *);
00046 integer iseed[4], gpind, iinfo;
00047 extern doublereal dasum_(integer *, doublereal *, integer *);
00048 extern int dcopy_(integer *, doublereal *, integer *,
00049 doublereal *, integer *), daxpy_(integer *, doublereal *,
00050 doublereal *, integer *, doublereal *, integer *);
00051 doublereal ortol;
00052 integer indrv1, indrv2, indrv3, indrv4, indrv5;
00053 extern doublereal dlamch_(char *);
00054 extern int dlagtf_(integer *, doublereal *, doublereal *,
00055 doublereal *, doublereal *, doublereal *, doublereal *, integer *
00056 , integer *);
00057 extern integer idamax_(integer *, doublereal *, integer *);
00058 extern int xerbla_(char *, integer *), dlagts_(
00059 integer *, integer *, doublereal *, doublereal *, doublereal *,
00060 doublereal *, integer *, doublereal *, doublereal *, integer *);
00061 integer nrmchk;
00062 extern int dlarnv_(integer *, integer *, integer *,
00063 doublereal *);
00064 integer blksiz;
00065 doublereal onenrm, dtpcrt, pertol;
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 --d__;
00180 --e;
00181 --w;
00182 --iblock;
00183 --isplit;
00184 z_dim1 = *ldz;
00185 z_offset = 1 + z_dim1;
00186 z__ -= z_offset;
00187 --work;
00188 --iwork;
00189 --ifail;
00190
00191
00192 *info = 0;
00193 i__1 = *m;
00194 for (i__ = 1; i__ <= i__1; ++i__) {
00195 ifail[i__] = 0;
00196
00197 }
00198
00199 if (*n < 0) {
00200 *info = -1;
00201 } else if (*m < 0 || *m > *n) {
00202 *info = -4;
00203 } else if (*ldz < max(1,*n)) {
00204 *info = -9;
00205 } else {
00206 i__1 = *m;
00207 for (j = 2; j <= i__1; ++j) {
00208 if (iblock[j] < iblock[j - 1]) {
00209 *info = -6;
00210 goto L30;
00211 }
00212 if (iblock[j] == iblock[j - 1] && w[j] < w[j - 1]) {
00213 *info = -5;
00214 goto L30;
00215 }
00216
00217 }
00218 L30:
00219 ;
00220 }
00221
00222 if (*info != 0) {
00223 i__1 = -(*info);
00224 xerbla_("DSTEIN", &i__1);
00225 return 0;
00226 }
00227
00228
00229
00230 if (*n == 0 || *m == 0) {
00231 return 0;
00232 } else if (*n == 1) {
00233 z__[z_dim1 + 1] = 1.;
00234 return 0;
00235 }
00236
00237
00238
00239 eps = dlamch_("Precision");
00240
00241
00242
00243 for (i__ = 1; i__ <= 4; ++i__) {
00244 iseed[i__ - 1] = 1;
00245
00246 }
00247
00248
00249
00250 indrv1 = 0;
00251 indrv2 = indrv1 + *n;
00252 indrv3 = indrv2 + *n;
00253 indrv4 = indrv3 + *n;
00254 indrv5 = indrv4 + *n;
00255
00256
00257
00258 j1 = 1;
00259 i__1 = iblock[*m];
00260 for (nblk = 1; nblk <= i__1; ++nblk) {
00261
00262
00263
00264 if (nblk == 1) {
00265 b1 = 1;
00266 } else {
00267 b1 = isplit[nblk - 1] + 1;
00268 }
00269 bn = isplit[nblk];
00270 blksiz = bn - b1 + 1;
00271 if (blksiz == 1) {
00272 goto L60;
00273 }
00274 gpind = b1;
00275
00276
00277
00278 onenrm = (d__1 = d__[b1], abs(d__1)) + (d__2 = e[b1], abs(d__2));
00279
00280 d__3 = onenrm, d__4 = (d__1 = d__[bn], abs(d__1)) + (d__2 = e[bn - 1],
00281 abs(d__2));
00282 onenrm = max(d__3,d__4);
00283 i__2 = bn - 1;
00284 for (i__ = b1 + 1; i__ <= i__2; ++i__) {
00285
00286 d__4 = onenrm, d__5 = (d__1 = d__[i__], abs(d__1)) + (d__2 = e[
00287 i__ - 1], abs(d__2)) + (d__3 = e[i__], abs(d__3));
00288 onenrm = max(d__4,d__5);
00289
00290 }
00291 ortol = onenrm * .001;
00292
00293 dtpcrt = sqrt(.1 / blksiz);
00294
00295
00296
00297 L60:
00298 jblk = 0;
00299 i__2 = *m;
00300 for (j = j1; j <= i__2; ++j) {
00301 if (iblock[j] != nblk) {
00302 j1 = j;
00303 goto L160;
00304 }
00305 ++jblk;
00306 xj = w[j];
00307
00308
00309
00310 if (blksiz == 1) {
00311 work[indrv1 + 1] = 1.;
00312 goto L120;
00313 }
00314
00315
00316
00317
00318 if (jblk > 1) {
00319 eps1 = (d__1 = eps * xj, abs(d__1));
00320 pertol = eps1 * 10.;
00321 sep = xj - xjm;
00322 if (sep < pertol) {
00323 xj = xjm + pertol;
00324 }
00325 }
00326
00327 its = 0;
00328 nrmchk = 0;
00329
00330
00331
00332 dlarnv_(&c__2, iseed, &blksiz, &work[indrv1 + 1]);
00333
00334
00335
00336 dcopy_(&blksiz, &d__[b1], &c__1, &work[indrv4 + 1], &c__1);
00337 i__3 = blksiz - 1;
00338 dcopy_(&i__3, &e[b1], &c__1, &work[indrv2 + 2], &c__1);
00339 i__3 = blksiz - 1;
00340 dcopy_(&i__3, &e[b1], &c__1, &work[indrv3 + 1], &c__1);
00341
00342
00343
00344 tol = 0.;
00345 dlagtf_(&blksiz, &work[indrv4 + 1], &xj, &work[indrv2 + 2], &work[
00346 indrv3 + 1], &tol, &work[indrv5 + 1], &iwork[1], &iinfo);
00347
00348
00349
00350 L70:
00351 ++its;
00352 if (its > 5) {
00353 goto L100;
00354 }
00355
00356
00357
00358
00359 d__2 = eps, d__3 = (d__1 = work[indrv4 + blksiz], abs(d__1));
00360 scl = blksiz * onenrm * max(d__2,d__3) / dasum_(&blksiz, &work[
00361 indrv1 + 1], &c__1);
00362 dscal_(&blksiz, &scl, &work[indrv1 + 1], &c__1);
00363
00364
00365
00366 dlagts_(&c_n1, &blksiz, &work[indrv4 + 1], &work[indrv2 + 2], &
00367 work[indrv3 + 1], &work[indrv5 + 1], &iwork[1], &work[
00368 indrv1 + 1], &tol, &iinfo);
00369
00370
00371
00372
00373 if (jblk == 1) {
00374 goto L90;
00375 }
00376 if ((d__1 = xj - xjm, abs(d__1)) > ortol) {
00377 gpind = j;
00378 }
00379 if (gpind != j) {
00380 i__3 = j - 1;
00381 for (i__ = gpind; i__ <= i__3; ++i__) {
00382 ztr = -ddot_(&blksiz, &work[indrv1 + 1], &c__1, &z__[b1 +
00383 i__ * z_dim1], &c__1);
00384 daxpy_(&blksiz, &ztr, &z__[b1 + i__ * z_dim1], &c__1, &
00385 work[indrv1 + 1], &c__1);
00386
00387 }
00388 }
00389
00390
00391
00392 L90:
00393 jmax = idamax_(&blksiz, &work[indrv1 + 1], &c__1);
00394 nrm = (d__1 = work[indrv1 + jmax], abs(d__1));
00395
00396
00397
00398
00399 if (nrm < dtpcrt) {
00400 goto L70;
00401 }
00402 ++nrmchk;
00403 if (nrmchk < 3) {
00404 goto L70;
00405 }
00406
00407 goto L110;
00408
00409
00410
00411
00412 L100:
00413 ++(*info);
00414 ifail[*info] = j;
00415
00416
00417
00418 L110:
00419 scl = 1. / dnrm2_(&blksiz, &work[indrv1 + 1], &c__1);
00420 jmax = idamax_(&blksiz, &work[indrv1 + 1], &c__1);
00421 if (work[indrv1 + jmax] < 0.) {
00422 scl = -scl;
00423 }
00424 dscal_(&blksiz, &scl, &work[indrv1 + 1], &c__1);
00425 L120:
00426 i__3 = *n;
00427 for (i__ = 1; i__ <= i__3; ++i__) {
00428 z__[i__ + j * z_dim1] = 0.;
00429
00430 }
00431 i__3 = blksiz;
00432 for (i__ = 1; i__ <= i__3; ++i__) {
00433 z__[b1 + i__ - 1 + j * z_dim1] = work[indrv1 + i__];
00434
00435 }
00436
00437
00438
00439
00440 xjm = xj;
00441
00442
00443 }
00444 L160:
00445 ;
00446 }
00447
00448 return 0;
00449
00450
00451
00452 }