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