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