zstein.c
Go to the documentation of this file.
00001 /* zstein.f -- translated by f2c (version 20061008).
00002    You must link the resulting object file with libf2c:
00003         on Microsoft Windows system, link with libf2c.lib;
00004         on Linux or Unix systems, link with .../path/to/libf2c.a -lm
00005         or, if you install libf2c.a in a standard place, with -lf2c -lm
00006         -- in that order, at the end of the command line, as in
00007                 cc *.o -lf2c -lm
00008         Source for libf2c is in /netlib/f2c/libf2c.zip, e.g.,
00009 
00010                 http://www.netlib.org/f2c/libf2c.zip
00011 */
00012 
00013 #include "f2c.h"
00014 #include "blaswrap.h"
00015 
00016 /* Table of constant values */
00017 
00018 static integer c__2 = 2;
00019 static integer c__1 = 1;
00020 static integer c_n1 = -1;
00021 
00022 /* Subroutine */ 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     /* System generated locals */
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     /* Builtin functions */
00033     double sqrt(doublereal);
00034 
00035     /* Local variables */
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 /* Subroutine */ int dscal_(integer *, doublereal *, doublereal *, 
00043             integer *);
00044     integer iseed[4], gpind, iinfo;
00045     extern doublereal dasum_(integer *, doublereal *, integer *);
00046     extern /* Subroutine */ 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 /* Subroutine */ int dlagtf_(integer *, doublereal *, doublereal *, 
00052              doublereal *, doublereal *, doublereal *, doublereal *, integer *
00053 , integer *);
00054     extern integer idamax_(integer *, doublereal *, integer *);
00055     extern /* Subroutine */ int xerbla_(char *, integer *), dlagts_(
00056             integer *, integer *, doublereal *, doublereal *, doublereal *, 
00057             doublereal *, integer *, doublereal *, doublereal *, integer *);
00058     integer nrmchk;
00059     extern /* Subroutine */ int dlarnv_(integer *, integer *, integer *, 
00060             doublereal *);
00061     integer blksiz;
00062     doublereal onenrm, dtpcrt, pertol;
00063 
00064 
00065 /*  -- LAPACK routine (version 3.2) -- */
00066 /*     Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
00067 /*     November 2006 */
00068 
00069 /*     .. Scalar Arguments .. */
00070 /*     .. */
00071 /*     .. Array Arguments .. */
00072 /*     .. */
00073 
00074 /*  Purpose */
00075 /*  ======= */
00076 
00077 /*  ZSTEIN computes the eigenvectors of a real symmetric tridiagonal */
00078 /*  matrix T corresponding to specified eigenvalues, using inverse */
00079 /*  iteration. */
00080 
00081 /*  The maximum number of iterations allowed for each eigenvector is */
00082 /*  specified by an internal parameter MAXITS (currently set to 5). */
00083 
00084 /*  Although the eigenvectors are real, they are stored in a complex */
00085 /*  array, which may be passed to ZUNMTR or ZUPMTR for back */
00086 /*  transformation to the eigenvectors of a complex Hermitian matrix */
00087 /*  which was reduced to tridiagonal form. */
00088 
00089 
00090 /*  Arguments */
00091 /*  ========= */
00092 
00093 /*  N       (input) INTEGER */
00094 /*          The order of the matrix.  N >= 0. */
00095 
00096 /*  D       (input) DOUBLE PRECISION array, dimension (N) */
00097 /*          The n diagonal elements of the tridiagonal matrix T. */
00098 
00099 /*  E       (input) DOUBLE PRECISION array, dimension (N-1) */
00100 /*          The (n-1) subdiagonal elements of the tridiagonal matrix */
00101 /*          T, stored in elements 1 to N-1. */
00102 
00103 /*  M       (input) INTEGER */
00104 /*          The number of eigenvectors to be found.  0 <= M <= N. */
00105 
00106 /*  W       (input) DOUBLE PRECISION array, dimension (N) */
00107 /*          The first M elements of W contain the eigenvalues for */
00108 /*          which eigenvectors are to be computed.  The eigenvalues */
00109 /*          should be grouped by split-off block and ordered from */
00110 /*          smallest to largest within the block.  ( The output array */
00111 /*          W from DSTEBZ with ORDER = 'B' is expected here. ) */
00112 
00113 /*  IBLOCK  (input) INTEGER array, dimension (N) */
00114 /*          The submatrix indices associated with the corresponding */
00115 /*          eigenvalues in W; IBLOCK(i)=1 if eigenvalue W(i) belongs to */
00116 /*          the first submatrix from the top, =2 if W(i) belongs to */
00117 /*          the second submatrix, etc.  ( The output array IBLOCK */
00118 /*          from DSTEBZ is expected here. ) */
00119 
00120 /*  ISPLIT  (input) INTEGER array, dimension (N) */
00121 /*          The splitting points, at which T breaks up into submatrices. */
00122 /*          The first submatrix consists of rows/columns 1 to */
00123 /*          ISPLIT( 1 ), the second of rows/columns ISPLIT( 1 )+1 */
00124 /*          through ISPLIT( 2 ), etc. */
00125 /*          ( The output array ISPLIT from DSTEBZ is expected here. ) */
00126 
00127 /*  Z       (output) COMPLEX*16 array, dimension (LDZ, M) */
00128 /*          The computed eigenvectors.  The eigenvector associated */
00129 /*          with the eigenvalue W(i) is stored in the i-th column of */
00130 /*          Z.  Any vector which fails to converge is set to its current */
00131 /*          iterate after MAXITS iterations. */
00132 /*          The imaginary parts of the eigenvectors are set to zero. */
00133 
00134 /*  LDZ     (input) INTEGER */
00135 /*          The leading dimension of the array Z.  LDZ >= max(1,N). */
00136 
00137 /*  WORK    (workspace) DOUBLE PRECISION array, dimension (5*N) */
00138 
00139 /*  IWORK   (workspace) INTEGER array, dimension (N) */
00140 
00141 /*  IFAIL   (output) INTEGER array, dimension (M) */
00142 /*          On normal exit, all elements of IFAIL are zero. */
00143 /*          If one or more eigenvectors fail to converge after */
00144 /*          MAXITS iterations, then their indices are stored in */
00145 /*          array IFAIL. */
00146 
00147 /*  INFO    (output) INTEGER */
00148 /*          = 0: successful exit */
00149 /*          < 0: if INFO = -i, the i-th argument had an illegal value */
00150 /*          > 0: if INFO = i, then i eigenvectors failed to converge */
00151 /*               in MAXITS iterations.  Their indices are stored in */
00152 /*               array IFAIL. */
00153 
00154 /*  Internal Parameters */
00155 /*  =================== */
00156 
00157 /*  MAXITS  INTEGER, default = 5 */
00158 /*          The maximum number of iterations performed. */
00159 
00160 /*  EXTRA   INTEGER, default = 2 */
00161 /*          The number of iterations performed after norm growth */
00162 /*          criterion is satisfied, should be at least 1. */
00163 
00164 /* ===================================================================== */
00165 
00166 /*     .. Parameters .. */
00167 /*     .. */
00168 /*     .. Local Scalars .. */
00169 /*     .. */
00170 /*     .. Local Arrays .. */
00171 /*     .. */
00172 /*     .. External Functions .. */
00173 /*     .. */
00174 /*     .. External Subroutines .. */
00175 /*     .. */
00176 /*     .. Intrinsic Functions .. */
00177 /*     .. */
00178 /*     .. Executable Statements .. */
00179 
00180 /*     Test the input parameters. */
00181 
00182     /* Parameter adjustments */
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     /* Function Body */
00196     *info = 0;
00197     i__1 = *m;
00198     for (i__ = 1; i__ <= i__1; ++i__) {
00199         ifail[i__] = 0;
00200 /* L10: */
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 /* L20: */
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 /*     Quick return if possible */
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 /*     Get machine constants. */
00243 
00244     eps = dlamch_("Precision");
00245 
00246 /*     Initialize seed for random number generator DLARNV. */
00247 
00248     for (i__ = 1; i__ <= 4; ++i__) {
00249         iseed[i__ - 1] = 1;
00250 /* L40: */
00251     }
00252 
00253 /*     Initialize pointers. */
00254 
00255     indrv1 = 0;
00256     indrv2 = indrv1 + *n;
00257     indrv3 = indrv2 + *n;
00258     indrv4 = indrv3 + *n;
00259     indrv5 = indrv4 + *n;
00260 
00261 /*     Compute eigenvectors of matrix blocks. */
00262 
00263     j1 = 1;
00264     i__1 = iblock[*m];
00265     for (nblk = 1; nblk <= i__1; ++nblk) {
00266 
00267 /*        Find starting and ending indices of block nblk. */
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 /*        Compute reorthogonalization criterion and stopping criterion. */
00282 
00283         onenrm = (d__1 = d__[b1], abs(d__1)) + (d__2 = e[b1], abs(d__2));
00284 /* Computing MAX */
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 /* Computing MAX */
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 /* L50: */
00295         }
00296         ortol = onenrm * .001;
00297 
00298         dtpcrt = sqrt(.1 / blksiz);
00299 
00300 /*        Loop through eigenvalues of block nblk. */
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 /*           Skip all the work if the block size is one. */
00314 
00315             if (blksiz == 1) {
00316                 work[indrv1 + 1] = 1.;
00317                 goto L140;
00318             }
00319 
00320 /*           If eigenvalues j and j-1 are too close, add a relatively */
00321 /*           small perturbation. */
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 /*           Get random starting vector. */
00336 
00337             dlarnv_(&c__2, iseed, &blksiz, &work[indrv1 + 1]);
00338 
00339 /*           Copy the matrix T so it won't be destroyed in factorization. */
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 /*           Compute LU factors with partial pivoting  ( PT = LU ) */
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 /*           Update iteration count. */
00354 
00355 L70:
00356             ++its;
00357             if (its > 5) {
00358                 goto L120;
00359             }
00360 
00361 /*           Normalize and scale the righthand side vector Pb. */
00362 
00363 /* Computing MAX */
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 /*           Solve the system LU = Pb. */
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 /*           Reorthogonalize by modified Gram-Schmidt if eigenvalues are */
00376 /*           close enough. */
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 /* L80: */
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 /* L90: */
00399                     }
00400 /* L100: */
00401                 }
00402             }
00403 
00404 /*           Check the infinity norm of the iterate. */
00405 
00406 L110:
00407             jmax = idamax_(&blksiz, &work[indrv1 + 1], &c__1);
00408             nrm = (d__1 = work[indrv1 + jmax], abs(d__1));
00409 
00410 /*           Continue for additional iterations after norm reaches */
00411 /*           stopping criterion. */
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 /*           If stopping criterion was not satisfied, update info and */
00424 /*           store eigenvector number in array ifail. */
00425 
00426 L120:
00427             ++(*info);
00428             ifail[*info] = j;
00429 
00430 /*           Accept iterate as jth eigenvector. */
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 /* L150: */
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 /* L160: */
00453             }
00454 
00455 /*           Save the shift to check eigenvalue spacing at next */
00456 /*           iteration. */
00457 
00458             xjm = xj;
00459 
00460 /* L170: */
00461         }
00462 L180:
00463         ;
00464     }
00465 
00466     return 0;
00467 
00468 /*     End of ZSTEIN */
00469 
00470 } /* zstein_ */


swiftnav
Author(s):
autogenerated on Sat Jun 8 2019 18:56:43