| 1 |
/* |
| 2 |
* Copyright(C) 1999-2020 National Technology & Engineering Solutions |
| 3 |
* of Sandia, LLC (NTESS). Under the terms of Contract DE-NA0003525 with |
| 4 |
* NTESS, the U.S. Government retains certain rights in this software. |
| 5 |
* |
| 6 |
* See packages/seacas/LICENSE for details |
| 7 |
*/ |
| 8 |
/* tinvit.f -- translated by f2c (version of 16 May 1991 13:06:06). |
| 9 |
*/ |
| 10 |
|
| 11 |
#include <float.h> |
| 12 |
#include <math.h> |
| 13 |
|
| 14 |
int tinvit(long int *nm, long int *n, double *d, double *e, double *e2, long int *m, double *w, |
| 15 |
long int *ind, double *z, long int *ierr, double *rv1, double *rv2, double *rv3, |
| 16 |
double *rv4, double *rv6) |
| 17 |
{ |
| 18 |
/* System generated locals */ |
| 19 |
long int z_dim1, z_offset, i__1, i__2, i__3; |
| 20 |
double d__1, d__2, d__3, d__4; |
| 21 |
|
| 22 |
/* Local variables */ |
| 23 |
static double norm; |
| 24 |
static long int i, j, p, q, r, s; |
| 25 |
static double u, v, order; |
| 26 |
static long int group; |
| 27 |
static double x0, x1; |
| 28 |
static long int ii, jj, ip; |
| 29 |
static double uk, xu; |
| 30 |
static long int tag, its; |
| 31 |
static double eps2, eps3, eps4; |
| 32 |
|
| 33 |
/* this subroutine is a translation of the inverse iteration tech- */ |
| 34 |
/* nique in the algol procedure tristurm by peters and wilkinson. */ |
| 35 |
/* handbook for auto. comp., vol.ii-linear algebra, 418-439(1971). */ |
| 36 |
|
| 37 |
/* this subroutine finds those eigenvectors of a tridiagonal */ |
| 38 |
/* symmetric matrix corresponding to specified eigenvalues, */ |
| 39 |
/* using inverse iteration. */ |
| 40 |
|
| 41 |
/* on input */ |
| 42 |
|
| 43 |
/* nm must be set to the row dimension of two-dimensional */ |
| 44 |
/* array parameters as declared in the calling program */ |
| 45 |
/* dimension statement. */ |
| 46 |
|
| 47 |
/* n is the order of the matrix. */ |
| 48 |
|
| 49 |
/* d contains the diagonal elements of the input matrix. */ |
| 50 |
|
| 51 |
/* e contains the subdiagonal elements of the input matrix */ |
| 52 |
/* in its last n-1 positions. e(1) is arbitrary. */ |
| 53 |
|
| 54 |
/* e2 contains the squares of the corresponding elements of e, */ |
| 55 |
/* with zeros corresponding to negligible elements of e. */ |
| 56 |
/* e(i) is considered negligible if it is not larger than */ |
| 57 |
/* the product of the relative machine precision and the sum */ |
| 58 |
/* of the magnitudes of d(i) and d(i-1). e2(1) must contain */ |
| 59 |
/* 0.0d0 if the eigenvalues are in ascending order, or 2.0d0 */ |
| 60 |
/* if the eigenvalues are in descending order. if bisect, */ |
| 61 |
/* tridib, or imtqlv has been used to find the eigenvalues, */ |
| 62 |
/* their output e2 array is exactly what is expected here. */ |
| 63 |
|
| 64 |
/* m is the number of specified eigenvalues. */ |
| 65 |
|
| 66 |
/* w contains the m eigenvalues in ascending or descending order. |
| 67 |
*/ |
| 68 |
|
| 69 |
/* ind contains in its first m positions the submatrix indices */ |
| 70 |
/* associated with the corresponding eigenvalues in w -- */ |
| 71 |
/* 1 for eigenvalues belonging to the first submatrix from */ |
| 72 |
/* the top, 2 for those belonging to the second submatrix, etc. |
| 73 |
*/ |
| 74 |
|
| 75 |
/* on output */ |
| 76 |
|
| 77 |
/* all input arrays are unaltered. */ |
| 78 |
|
| 79 |
/* z contains the associated set of orthonormal eigenvectors. */ |
| 80 |
/* any vector which fails to converge is set to zero. */ |
| 81 |
|
| 82 |
/* ierr is set to */ |
| 83 |
/* zero for normal return, */ |
| 84 |
/* -r if the eigenvector corresponding to the r-th */ |
| 85 |
/* eigenvalue fails to converge in 5 iterations. */ |
| 86 |
|
| 87 |
/* rv1, rv2, rv3, rv4, and rv6 are temporary storage arrays. */ |
| 88 |
|
| 89 |
/* calls hypot for dsqrt(a*a + b*b) . */ |
| 90 |
|
| 91 |
/* questions and comments should be directed to burton s. garbow, */ |
| 92 |
/* mathematics and computer science div, argonne national laboratory |
| 93 |
*/ |
| 94 |
|
| 95 |
/* this version dated august 1983. */ |
| 96 |
|
| 97 |
/* ------------------------------------------------------------------ |
| 98 |
*/ |
| 99 |
|
| 100 |
/* Parameter adjustments */ |
| 101 |
--rv6; |
| 102 |
--rv4; |
| 103 |
--rv3; |
| 104 |
--rv2; |
| 105 |
--rv1; |
| 106 |
z_dim1 = *nm; |
| 107 |
z_offset = z_dim1 + 1; |
| 108 |
z -= z_offset; |
| 109 |
--ind; |
| 110 |
--w; |
| 111 |
--e2; |
| 112 |
--e; |
| 113 |
--d; |
| 114 |
|
| 115 |
/* Function Body */ |
| 116 |
*ierr = 0; |
| 117 |
if (*m == 0) { |
| 118 |
goto L1001; |
| 119 |
} |
| 120 |
tag = 0; |
| 121 |
order = 1. - e2[1]; |
| 122 |
q = 0; |
| 123 |
/* .......... establish and process next submatrix .......... */ |
| 124 |
L100: |
| 125 |
p = q + 1; |
| 126 |
|
| 127 |
i__1 = *n; |
| 128 |
for (q = p; q <= i__1; ++q) { |
| 129 |
if (q == *n) { |
| 130 |
goto L140; |
| 131 |
} |
| 132 |
if (e2[q + 1] == 0.) { |
| 133 |
goto L140; |
| 134 |
} |
| 135 |
/* L120: */ |
| 136 |
} |
| 137 |
/* .......... find vectors by inverse iteration .......... */ |
| 138 |
L140: |
| 139 |
++tag; |
| 140 |
s = 0; |
| 141 |
|
| 142 |
i__1 = *m; |
| 143 |
for (r = 1; r <= i__1; ++r) { |
| 144 |
if (ind[r] != tag) { |
| 145 |
goto L920; |
| 146 |
} |
| 147 |
its = 1; |
| 148 |
x1 = w[r]; |
| 149 |
if (s != 0) { |
| 150 |
goto L510; |
| 151 |
} |
| 152 |
/* .......... check for isolated root .......... */ |
| 153 |
xu = 1.; |
| 154 |
if (p != q) { |
| 155 |
goto L490; |
| 156 |
} |
| 157 |
rv6[p] = 1.; |
| 158 |
goto L870; |
| 159 |
L490: |
| 160 |
norm = (d__1 = d[p], fabs(d__1)); |
| 161 |
ip = p + 1; |
| 162 |
|
| 163 |
i__2 = q; |
| 164 |
for (i = ip; i <= i__2; ++i) { |
| 165 |
/* L500: */ |
| 166 |
/* Computing MAX */ |
| 167 |
d__3 = norm, d__4 = (d__1 = d[i], fabs(d__1)) + (d__2 = e[i], fabs(d__2)); |
| 168 |
norm = d__3 > d__4 ? d__3 : d__4; |
| 169 |
} |
| 170 |
/* .......... eps2 is the criterion for grouping, */ |
| 171 |
/* eps3 replaces zero pivots and equal */ |
| 172 |
/* roots are modified by eps3, */ |
| 173 |
/* eps4 is taken very small to avoid overflow ......... |
| 174 |
. */ |
| 175 |
eps2 = norm * .001; |
| 176 |
eps3 = DBL_EPSILON * fabs(norm); |
| 177 |
uk = (double)(q - p + 1); |
| 178 |
eps4 = uk * eps3; |
| 179 |
uk = eps4 / sqrt(uk); |
| 180 |
s = p; |
| 181 |
L505: |
| 182 |
group = 0; |
| 183 |
goto L520; |
| 184 |
/* .......... look for close or coincident roots .......... */ |
| 185 |
L510: |
| 186 |
if ((d__1 = x1 - x0, fabs(d__1)) >= eps2) { |
| 187 |
goto L505; |
| 188 |
} |
| 189 |
++group; |
| 190 |
if (order * (x1 - x0) <= 0.) { |
| 191 |
x1 = x0 + order * eps3; |
| 192 |
} |
| 193 |
/* .......... elimination with interchanges and */ |
| 194 |
/* initialization of vector .......... */ |
| 195 |
L520: |
| 196 |
v = 0.; |
| 197 |
|
| 198 |
i__2 = q; |
| 199 |
for (i = p; i <= i__2; ++i) { |
| 200 |
rv6[i] = uk; |
| 201 |
if (i == p) { |
| 202 |
goto L560; |
| 203 |
} |
| 204 |
if ((d__1 = e[i], fabs(d__1)) < fabs(u)) { |
| 205 |
goto L540; |
| 206 |
} |
| 207 |
/* .......... warning -- a divide check may occur here if */ |
| 208 |
/* e2 array has not been specified correctly ...... |
| 209 |
.... */ |
| 210 |
xu = u / e[i]; |
| 211 |
rv4[i] = xu; |
| 212 |
rv1[i - 1] = e[i]; |
| 213 |
rv2[i - 1] = d[i] - x1; |
| 214 |
rv3[i - 1] = 0.; |
| 215 |
if (i != q) { |
| 216 |
rv3[i - 1] = e[i + 1]; |
| 217 |
} |
| 218 |
u = v - xu * rv2[i - 1]; |
| 219 |
v = -xu * rv3[i - 1]; |
| 220 |
goto L580; |
| 221 |
L540: |
| 222 |
xu = e[i] / u; |
| 223 |
rv4[i] = xu; |
| 224 |
rv1[i - 1] = u; |
| 225 |
rv2[i - 1] = v; |
| 226 |
rv3[i - 1] = 0.; |
| 227 |
L560: |
| 228 |
u = d[i] - x1 - xu * v; |
| 229 |
if (i != q) { |
| 230 |
v = e[i + 1]; |
| 231 |
} |
| 232 |
L580:; |
| 233 |
} |
| 234 |
|
| 235 |
if (u == 0.) { |
| 236 |
u = eps3; |
| 237 |
} |
| 238 |
rv1[q] = u; |
| 239 |
rv2[q] = 0.; |
| 240 |
rv3[q] = 0.; |
| 241 |
/* .......... back substitution */ |
| 242 |
/* for i=q step -1 until p do -- .......... */ |
| 243 |
L600: |
| 244 |
i__2 = q; |
| 245 |
for (ii = p; ii <= i__2; ++ii) { |
| 246 |
i = p + q - ii; |
| 247 |
rv6[i] = (rv6[i] - u * rv2[i] - v * rv3[i]) / rv1[i]; |
| 248 |
v = u; |
| 249 |
u = rv6[i]; |
| 250 |
/* L620: */ |
| 251 |
} |
| 252 |
/* .......... orthogonalize with respect to previous */ |
| 253 |
/* members of group .......... */ |
| 254 |
if (group == 0) { |
| 255 |
goto L700; |
| 256 |
} |
| 257 |
j = r; |
| 258 |
|
| 259 |
i__2 = group; |
| 260 |
for (jj = 1; jj <= i__2; ++jj) { |
| 261 |
L630: |
| 262 |
--j; |
| 263 |
if (ind[j] != tag) { |
| 264 |
goto L630; |
| 265 |
} |
| 266 |
xu = 0.; |
| 267 |
|
| 268 |
i__3 = q; |
| 269 |
for (i = p; i <= i__3; ++i) { |
| 270 |
/* L640: */ |
| 271 |
xu += rv6[i] * z[i + j * z_dim1]; |
| 272 |
} |
| 273 |
|
| 274 |
i__3 = q; |
| 275 |
for (i = p; i <= i__3; ++i) { |
| 276 |
/* L660: */ |
| 277 |
rv6[i] -= xu * z[i + j * z_dim1]; |
| 278 |
} |
| 279 |
|
| 280 |
/* L680: */ |
| 281 |
} |
| 282 |
|
| 283 |
L700: |
| 284 |
norm = 0.; |
| 285 |
|
| 286 |
i__2 = q; |
| 287 |
for (i = p; i <= i__2; ++i) { |
| 288 |
/* L720: */ |
| 289 |
norm += (d__1 = rv6[i], fabs(d__1)); |
| 290 |
} |
| 291 |
|
| 292 |
if (norm >= 1.) { |
| 293 |
goto L840; |
| 294 |
} |
| 295 |
/* .......... forward substitution .......... */ |
| 296 |
if (its == 5) { |
| 297 |
goto L830; |
| 298 |
} |
| 299 |
if (norm != 0.) { |
| 300 |
goto L740; |
| 301 |
} |
| 302 |
rv6[s] = eps4; |
| 303 |
++s; |
| 304 |
if (s > q) { |
| 305 |
s = p; |
| 306 |
} |
| 307 |
goto L780; |
| 308 |
L740: |
| 309 |
xu = eps4 / norm; |
| 310 |
|
| 311 |
i__2 = q; |
| 312 |
for (i = p; i <= i__2; ++i) { |
| 313 |
/* L760: */ |
| 314 |
rv6[i] *= xu; |
| 315 |
} |
| 316 |
/* .......... elimination operations on next vector */ |
| 317 |
/* iterate .......... */ |
| 318 |
L780: |
| 319 |
i__2 = q; |
| 320 |
for (i = ip; i <= i__2; ++i) { |
| 321 |
u = rv6[i]; |
| 322 |
/* .......... if rv1(i-1) .eq. e(i), a row interchange */ |
| 323 |
/* was performed earlier in the */ |
| 324 |
/* triangularization process .......... */ |
| 325 |
if (rv1[i - 1] != e[i]) { |
| 326 |
goto L800; |
| 327 |
} |
| 328 |
u = rv6[i - 1]; |
| 329 |
rv6[i - 1] = rv6[i]; |
| 330 |
L800: |
| 331 |
rv6[i] = u - rv4[i] * rv6[i - 1]; |
| 332 |
/* L820: */ |
| 333 |
} |
| 334 |
|
| 335 |
++its; |
| 336 |
goto L600; |
| 337 |
/* .......... set error -- non-converged eigenvector .......... */ |
| 338 |
|
| 339 |
L830: |
| 340 |
*ierr = -r; |
| 341 |
xu = 0.; |
| 342 |
goto L870; |
| 343 |
/* .......... normalize so that sum of squares is */ |
| 344 |
/* 1 and expand to full order .......... */ |
| 345 |
L840: |
| 346 |
u = 0.; |
| 347 |
|
| 348 |
i__2 = q; |
| 349 |
for (i = p; i <= i__2; ++i) { |
| 350 |
/* L860: */ |
| 351 |
u = hypot(u, rv6[i]); |
| 352 |
} |
| 353 |
|
| 354 |
xu = 1. / u; |
| 355 |
|
| 356 |
L870: |
| 357 |
i__2 = *n; |
| 358 |
for (i = 1; i <= i__2; ++i) { |
| 359 |
/* L880: */ |
| 360 |
z[i + r * z_dim1] = 0.; |
| 361 |
} |
| 362 |
|
| 363 |
i__2 = q; |
| 364 |
for (i = p; i <= i__2; ++i) { |
| 365 |
/* L900: */ |
| 366 |
z[i + r * z_dim1] = rv6[i] * xu; |
| 367 |
} |
| 368 |
|
| 369 |
x0 = x1; |
| 370 |
L920:; |
| 371 |
} |
| 372 |
|
| 373 |
if (q < *n) { |
| 374 |
goto L100; |
| 375 |
} |
| 376 |
L1001: |
| 377 |
return 0; |
| 378 |
} /* tinvit_ */ |