You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

dlasd4.c 39 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545
  1. /* f2c.h -- Standard Fortran to C header file */
  2. /** barf [ba:rf] 2. "He suggested using FORTRAN, and everybody barfed."
  3. - From The Shogakukan DICTIONARY OF NEW ENGLISH (Second edition) */
  4. #ifndef F2C_INCLUDE
  5. #define F2C_INCLUDE
  6. #include <math.h>
  7. #include <stdlib.h>
  8. #include <string.h>
  9. #include <stdio.h>
  10. #include <complex.h>
  11. #ifdef complex
  12. #undef complex
  13. #endif
  14. #ifdef I
  15. #undef I
  16. #endif
  17. typedef int integer;
  18. typedef unsigned int uinteger;
  19. typedef char *address;
  20. typedef short int shortint;
  21. typedef float real;
  22. typedef double doublereal;
  23. typedef struct { real r, i; } complex;
  24. typedef struct { doublereal r, i; } doublecomplex;
  25. static inline _Complex float Cf(complex *z) {return z->r + z->i*_Complex_I;}
  26. static inline _Complex double Cd(doublecomplex *z) {return z->r + z->i*_Complex_I;}
  27. static inline _Complex float * _pCf(complex *z) {return (_Complex float*)z;}
  28. static inline _Complex double * _pCd(doublecomplex *z) {return (_Complex double*)z;}
  29. #define pCf(z) (*_pCf(z))
  30. #define pCd(z) (*_pCd(z))
  31. typedef int logical;
  32. typedef short int shortlogical;
  33. typedef char logical1;
  34. typedef char integer1;
  35. #define TRUE_ (1)
  36. #define FALSE_ (0)
  37. /* Extern is for use with -E */
  38. #ifndef Extern
  39. #define Extern extern
  40. #endif
  41. /* I/O stuff */
  42. typedef int flag;
  43. typedef int ftnlen;
  44. typedef int ftnint;
  45. /*external read, write*/
  46. typedef struct
  47. { flag cierr;
  48. ftnint ciunit;
  49. flag ciend;
  50. char *cifmt;
  51. ftnint cirec;
  52. } cilist;
  53. /*internal read, write*/
  54. typedef struct
  55. { flag icierr;
  56. char *iciunit;
  57. flag iciend;
  58. char *icifmt;
  59. ftnint icirlen;
  60. ftnint icirnum;
  61. } icilist;
  62. /*open*/
  63. typedef struct
  64. { flag oerr;
  65. ftnint ounit;
  66. char *ofnm;
  67. ftnlen ofnmlen;
  68. char *osta;
  69. char *oacc;
  70. char *ofm;
  71. ftnint orl;
  72. char *oblnk;
  73. } olist;
  74. /*close*/
  75. typedef struct
  76. { flag cerr;
  77. ftnint cunit;
  78. char *csta;
  79. } cllist;
  80. /*rewind, backspace, endfile*/
  81. typedef struct
  82. { flag aerr;
  83. ftnint aunit;
  84. } alist;
  85. /* inquire */
  86. typedef struct
  87. { flag inerr;
  88. ftnint inunit;
  89. char *infile;
  90. ftnlen infilen;
  91. ftnint *inex; /*parameters in standard's order*/
  92. ftnint *inopen;
  93. ftnint *innum;
  94. ftnint *innamed;
  95. char *inname;
  96. ftnlen innamlen;
  97. char *inacc;
  98. ftnlen inacclen;
  99. char *inseq;
  100. ftnlen inseqlen;
  101. char *indir;
  102. ftnlen indirlen;
  103. char *infmt;
  104. ftnlen infmtlen;
  105. char *inform;
  106. ftnint informlen;
  107. char *inunf;
  108. ftnlen inunflen;
  109. ftnint *inrecl;
  110. ftnint *innrec;
  111. char *inblank;
  112. ftnlen inblanklen;
  113. } inlist;
  114. #define VOID void
  115. union Multitype { /* for multiple entry points */
  116. integer1 g;
  117. shortint h;
  118. integer i;
  119. /* longint j; */
  120. real r;
  121. doublereal d;
  122. complex c;
  123. doublecomplex z;
  124. };
  125. typedef union Multitype Multitype;
  126. struct Vardesc { /* for Namelist */
  127. char *name;
  128. char *addr;
  129. ftnlen *dims;
  130. int type;
  131. };
  132. typedef struct Vardesc Vardesc;
  133. struct Namelist {
  134. char *name;
  135. Vardesc **vars;
  136. int nvars;
  137. };
  138. typedef struct Namelist Namelist;
  139. #define abs(x) ((x) >= 0 ? (x) : -(x))
  140. #define dabs(x) (fabs(x))
  141. #define f2cmin(a,b) ((a) <= (b) ? (a) : (b))
  142. #define f2cmax(a,b) ((a) >= (b) ? (a) : (b))
  143. #define dmin(a,b) (f2cmin(a,b))
  144. #define dmax(a,b) (f2cmax(a,b))
  145. #define bit_test(a,b) ((a) >> (b) & 1)
  146. #define bit_clear(a,b) ((a) & ~((uinteger)1 << (b)))
  147. #define bit_set(a,b) ((a) | ((uinteger)1 << (b)))
  148. #define abort_() { sig_die("Fortran abort routine called", 1); }
  149. #define c_abs(z) (cabsf(Cf(z)))
  150. #define c_cos(R,Z) { pCf(R)=ccos(Cf(Z)); }
  151. #define c_div(c, a, b) {pCf(c) = Cf(a)/Cf(b);}
  152. #define z_div(c, a, b) {pCd(c) = Cd(a)/Cd(b);}
  153. #define c_exp(R, Z) {pCf(R) = cexpf(Cf(Z));}
  154. #define c_log(R, Z) {pCf(R) = clogf(Cf(Z));}
  155. #define c_sin(R, Z) {pCf(R) = csinf(Cf(Z));}
  156. //#define c_sqrt(R, Z) {*(R) = csqrtf(Cf(Z));}
  157. #define c_sqrt(R, Z) {pCf(R) = csqrtf(Cf(Z));}
  158. #define d_abs(x) (fabs(*(x)))
  159. #define d_acos(x) (acos(*(x)))
  160. #define d_asin(x) (asin(*(x)))
  161. #define d_atan(x) (atan(*(x)))
  162. #define d_atn2(x, y) (atan2(*(x),*(y)))
  163. #define d_cnjg(R, Z) { pCd(R) = conj(Cd(Z)); }
  164. #define r_cnjg(R, Z) { pCf(R) = conj(Cf(Z)); }
  165. #define d_cos(x) (cos(*(x)))
  166. #define d_cosh(x) (cosh(*(x)))
  167. #define d_dim(__a, __b) ( *(__a) > *(__b) ? *(__a) - *(__b) : 0.0 )
  168. #define d_exp(x) (exp(*(x)))
  169. #define d_imag(z) (cimag(Cd(z)))
  170. #define r_imag(z) (cimag(Cf(z)))
  171. #define d_int(__x) (*(__x)>0 ? floor(*(__x)) : -floor(- *(__x)))
  172. #define r_int(__x) (*(__x)>0 ? floor(*(__x)) : -floor(- *(__x)))
  173. #define d_lg10(x) ( 0.43429448190325182765 * log(*(x)) )
  174. #define r_lg10(x) ( 0.43429448190325182765 * log(*(x)) )
  175. #define d_log(x) (log(*(x)))
  176. #define d_mod(x, y) (fmod(*(x), *(y)))
  177. #define u_nint(__x) ((__x)>=0 ? floor((__x) + .5) : -floor(.5 - (__x)))
  178. #define d_nint(x) u_nint(*(x))
  179. #define u_sign(__a,__b) ((__b) >= 0 ? ((__a) >= 0 ? (__a) : -(__a)) : -((__a) >= 0 ? (__a) : -(__a)))
  180. #define d_sign(a,b) u_sign(*(a),*(b))
  181. #define r_sign(a,b) u_sign(*(a),*(b))
  182. #define d_sin(x) (sin(*(x)))
  183. #define d_sinh(x) (sinh(*(x)))
  184. #define d_sqrt(x) (sqrt(*(x)))
  185. #define d_tan(x) (tan(*(x)))
  186. #define d_tanh(x) (tanh(*(x)))
  187. #define i_abs(x) abs(*(x))
  188. #define i_dnnt(x) ((integer)u_nint(*(x)))
  189. #define i_len(s, n) (n)
  190. #define i_nint(x) ((integer)u_nint(*(x)))
  191. #define i_sign(a,b) ((integer)u_sign((integer)*(a),(integer)*(b)))
  192. #define pow_dd(ap, bp) ( pow(*(ap), *(bp)))
  193. #define pow_si(B,E) spow_ui(*(B),*(E))
  194. #define pow_ri(B,E) spow_ui(*(B),*(E))
  195. #define pow_di(B,E) dpow_ui(*(B),*(E))
  196. #define pow_zi(p, a, b) {pCd(p) = zpow_ui(Cd(a), *(b));}
  197. #define pow_ci(p, a, b) {pCf(p) = cpow_ui(Cf(a), *(b));}
  198. #define pow_zz(R,A,B) {pCd(R) = cpow(Cd(A),*(B));}
  199. #define s_cat(lpp, rpp, rnp, np, llp) { ftnlen i, nc, ll; char *f__rp, *lp; ll = (llp); lp = (lpp); for(i=0; i < (int)*(np); ++i) { nc = ll; if((rnp)[i] < nc) nc = (rnp)[i]; ll -= nc; f__rp = (rpp)[i]; while(--nc >= 0) *lp++ = *(f__rp)++; } while(--ll >= 0) *lp++ = ' '; }
  200. #define s_cmp(a,b,c,d) ((integer)strncmp((a),(b),f2cmin((c),(d))))
  201. #define s_copy(A,B,C,D) { int __i,__m; for (__i=0, __m=f2cmin((C),(D)); __i<__m && (B)[__i] != 0; ++__i) (A)[__i] = (B)[__i]; }
  202. #define sig_die(s, kill) { exit(1); }
  203. #define s_stop(s, n) {exit(0);}
  204. static char junk[] = "\n@(#)LIBF77 VERSION 19990503\n";
  205. #define z_abs(z) (cabs(Cd(z)))
  206. #define z_exp(R, Z) {pCd(R) = cexp(Cd(Z));}
  207. #define z_sqrt(R, Z) {pCd(R) = csqrt(Cd(Z));}
  208. #define myexit_() break;
  209. #define mycycle() continue;
  210. #define myceiling(w) {ceil(w)}
  211. #define myhuge(w) {HUGE_VAL}
  212. //#define mymaxloc_(w,s,e,n) {if (sizeof(*(w)) == sizeof(double)) dmaxloc_((w),*(s),*(e),n); else dmaxloc_((w),*(s),*(e),n);}
  213. #define mymaxloc(w,s,e,n) {dmaxloc_(w,*(s),*(e),n)}
  214. /* procedure parameter types for -A and -C++ */
  215. #define F2C_proc_par_types 1
  216. #ifdef __cplusplus
  217. typedef logical (*L_fp)(...);
  218. #else
  219. typedef logical (*L_fp)();
  220. #endif
  221. static float spow_ui(float x, integer n) {
  222. float pow=1.0; unsigned long int u;
  223. if(n != 0) {
  224. if(n < 0) n = -n, x = 1/x;
  225. for(u = n; ; ) {
  226. if(u & 01) pow *= x;
  227. if(u >>= 1) x *= x;
  228. else break;
  229. }
  230. }
  231. return pow;
  232. }
  233. static double dpow_ui(double x, integer n) {
  234. double pow=1.0; unsigned long int u;
  235. if(n != 0) {
  236. if(n < 0) n = -n, x = 1/x;
  237. for(u = n; ; ) {
  238. if(u & 01) pow *= x;
  239. if(u >>= 1) x *= x;
  240. else break;
  241. }
  242. }
  243. return pow;
  244. }
  245. static _Complex float cpow_ui(_Complex float x, integer n) {
  246. _Complex float pow=1.0; unsigned long int u;
  247. if(n != 0) {
  248. if(n < 0) n = -n, x = 1/x;
  249. for(u = n; ; ) {
  250. if(u & 01) pow *= x;
  251. if(u >>= 1) x *= x;
  252. else break;
  253. }
  254. }
  255. return pow;
  256. }
  257. static _Complex double zpow_ui(_Complex double x, integer n) {
  258. _Complex double pow=1.0; unsigned long int u;
  259. if(n != 0) {
  260. if(n < 0) n = -n, x = 1/x;
  261. for(u = n; ; ) {
  262. if(u & 01) pow *= x;
  263. if(u >>= 1) x *= x;
  264. else break;
  265. }
  266. }
  267. return pow;
  268. }
  269. static integer pow_ii(integer x, integer n) {
  270. integer pow; unsigned long int u;
  271. if (n <= 0) {
  272. if (n == 0 || x == 1) pow = 1;
  273. else if (x != -1) pow = x == 0 ? 1/x : 0;
  274. else n = -n;
  275. }
  276. if ((n > 0) || !(n == 0 || x == 1 || x != -1)) {
  277. u = n;
  278. for(pow = 1; ; ) {
  279. if(u & 01) pow *= x;
  280. if(u >>= 1) x *= x;
  281. else break;
  282. }
  283. }
  284. return pow;
  285. }
  286. static integer dmaxloc_(double *w, integer s, integer e, integer *n)
  287. {
  288. double m; integer i, mi;
  289. for(m=w[s-1], mi=s, i=s+1; i<=e; i++)
  290. if (w[i-1]>m) mi=i ,m=w[i-1];
  291. return mi-s+1;
  292. }
  293. static integer smaxloc_(float *w, integer s, integer e, integer *n)
  294. {
  295. float m; integer i, mi;
  296. for(m=w[s-1], mi=s, i=s+1; i<=e; i++)
  297. if (w[i-1]>m) mi=i ,m=w[i-1];
  298. return mi-s+1;
  299. }
  300. static inline void cdotc_(complex *z, integer *n_, complex *x, integer *incx_, complex *y, integer *incy_) {
  301. integer n = *n_, incx = *incx_, incy = *incy_, i;
  302. _Complex float zdotc = 0.0;
  303. if (incx == 1 && incy == 1) {
  304. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  305. zdotc += conjf(Cf(&x[i])) * Cf(&y[i]);
  306. }
  307. } else {
  308. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  309. zdotc += conjf(Cf(&x[i*incx])) * Cf(&y[i*incy]);
  310. }
  311. }
  312. pCf(z) = zdotc;
  313. }
  314. static inline void zdotc_(doublecomplex *z, integer *n_, doublecomplex *x, integer *incx_, doublecomplex *y, integer *incy_) {
  315. integer n = *n_, incx = *incx_, incy = *incy_, i;
  316. _Complex double zdotc = 0.0;
  317. if (incx == 1 && incy == 1) {
  318. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  319. zdotc += conj(Cd(&x[i])) * Cd(&y[i]);
  320. }
  321. } else {
  322. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  323. zdotc += conj(Cd(&x[i*incx])) * Cd(&y[i*incy]);
  324. }
  325. }
  326. pCd(z) = zdotc;
  327. }
  328. static inline void cdotu_(complex *z, integer *n_, complex *x, integer *incx_, complex *y, integer *incy_) {
  329. integer n = *n_, incx = *incx_, incy = *incy_, i;
  330. _Complex float zdotc = 0.0;
  331. if (incx == 1 && incy == 1) {
  332. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  333. zdotc += Cf(&x[i]) * Cf(&y[i]);
  334. }
  335. } else {
  336. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  337. zdotc += Cf(&x[i*incx]) * Cf(&y[i*incy]);
  338. }
  339. }
  340. pCf(z) = zdotc;
  341. }
  342. static inline void zdotu_(doublecomplex *z, integer *n_, doublecomplex *x, integer *incx_, doublecomplex *y, integer *incy_) {
  343. integer n = *n_, incx = *incx_, incy = *incy_, i;
  344. _Complex double zdotc = 0.0;
  345. if (incx == 1 && incy == 1) {
  346. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  347. zdotc += Cd(&x[i]) * Cd(&y[i]);
  348. }
  349. } else {
  350. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  351. zdotc += Cd(&x[i*incx]) * Cd(&y[i*incy]);
  352. }
  353. }
  354. pCd(z) = zdotc;
  355. }
  356. #endif
  357. /* -- translated by f2c (version 20000121).
  358. You must link the resulting object file with the libraries:
  359. -lf2c -lm (in that order)
  360. */
  361. /* > \brief \b DLASD4 computes the square root of the i-th updated eigenvalue of a positive symmetric rank-one
  362. modification to a positive diagonal matrix. Used by dbdsdc. */
  363. /* =========== DOCUMENTATION =========== */
  364. /* Online html documentation available at */
  365. /* http://www.netlib.org/lapack/explore-html/ */
  366. /* > \htmlonly */
  367. /* > Download DLASD4 + dependencies */
  368. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/dlasd4.
  369. f"> */
  370. /* > [TGZ]</a> */
  371. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/dlasd4.
  372. f"> */
  373. /* > [ZIP]</a> */
  374. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/dlasd4.
  375. f"> */
  376. /* > [TXT]</a> */
  377. /* > \endhtmlonly */
  378. /* Definition: */
  379. /* =========== */
  380. /* SUBROUTINE DLASD4( N, I, D, Z, DELTA, RHO, SIGMA, WORK, INFO ) */
  381. /* INTEGER I, INFO, N */
  382. /* DOUBLE PRECISION RHO, SIGMA */
  383. /* DOUBLE PRECISION D( * ), DELTA( * ), WORK( * ), Z( * ) */
  384. /* > \par Purpose: */
  385. /* ============= */
  386. /* > */
  387. /* > \verbatim */
  388. /* > */
  389. /* > This subroutine computes the square root of the I-th updated */
  390. /* > eigenvalue of a positive symmetric rank-one modification to */
  391. /* > a positive diagonal matrix whose entries are given as the squares */
  392. /* > of the corresponding entries in the array d, and that */
  393. /* > */
  394. /* > 0 <= D(i) < D(j) for i < j */
  395. /* > */
  396. /* > and that RHO > 0. This is arranged by the calling routine, and is */
  397. /* > no loss in generality. The rank-one modified system is thus */
  398. /* > */
  399. /* > diag( D ) * diag( D ) + RHO * Z * Z_transpose. */
  400. /* > */
  401. /* > where we assume the Euclidean norm of Z is 1. */
  402. /* > */
  403. /* > The method consists of approximating the rational functions in the */
  404. /* > secular equation by simpler interpolating rational functions. */
  405. /* > \endverbatim */
  406. /* Arguments: */
  407. /* ========== */
  408. /* > \param[in] N */
  409. /* > \verbatim */
  410. /* > N is INTEGER */
  411. /* > The length of all arrays. */
  412. /* > \endverbatim */
  413. /* > */
  414. /* > \param[in] I */
  415. /* > \verbatim */
  416. /* > I is INTEGER */
  417. /* > The index of the eigenvalue to be computed. 1 <= I <= N. */
  418. /* > \endverbatim */
  419. /* > */
  420. /* > \param[in] D */
  421. /* > \verbatim */
  422. /* > D is DOUBLE PRECISION array, dimension ( N ) */
  423. /* > The original eigenvalues. It is assumed that they are in */
  424. /* > order, 0 <= D(I) < D(J) for I < J. */
  425. /* > \endverbatim */
  426. /* > */
  427. /* > \param[in] Z */
  428. /* > \verbatim */
  429. /* > Z is DOUBLE PRECISION array, dimension ( N ) */
  430. /* > The components of the updating vector. */
  431. /* > \endverbatim */
  432. /* > */
  433. /* > \param[out] DELTA */
  434. /* > \verbatim */
  435. /* > DELTA is DOUBLE PRECISION array, dimension ( N ) */
  436. /* > If N .ne. 1, DELTA contains (D(j) - sigma_I) in its j-th */
  437. /* > component. If N = 1, then DELTA(1) = 1. The vector DELTA */
  438. /* > contains the information necessary to construct the */
  439. /* > (singular) eigenvectors. */
  440. /* > \endverbatim */
  441. /* > */
  442. /* > \param[in] RHO */
  443. /* > \verbatim */
  444. /* > RHO is DOUBLE PRECISION */
  445. /* > The scalar in the symmetric updating formula. */
  446. /* > \endverbatim */
  447. /* > */
  448. /* > \param[out] SIGMA */
  449. /* > \verbatim */
  450. /* > SIGMA is DOUBLE PRECISION */
  451. /* > The computed sigma_I, the I-th updated eigenvalue. */
  452. /* > \endverbatim */
  453. /* > */
  454. /* > \param[out] WORK */
  455. /* > \verbatim */
  456. /* > WORK is DOUBLE PRECISION array, dimension ( N ) */
  457. /* > If N .ne. 1, WORK contains (D(j) + sigma_I) in its j-th */
  458. /* > component. If N = 1, then WORK( 1 ) = 1. */
  459. /* > \endverbatim */
  460. /* > */
  461. /* > \param[out] INFO */
  462. /* > \verbatim */
  463. /* > INFO is INTEGER */
  464. /* > = 0: successful exit */
  465. /* > > 0: if INFO = 1, the updating process failed. */
  466. /* > \endverbatim */
  467. /* > \par Internal Parameters: */
  468. /* ========================= */
  469. /* > */
  470. /* > \verbatim */
  471. /* > Logical variable ORGATI (origin-at-i?) is used for distinguishing */
  472. /* > whether D(i) or D(i+1) is treated as the origin. */
  473. /* > */
  474. /* > ORGATI = .true. origin at i */
  475. /* > ORGATI = .false. origin at i+1 */
  476. /* > */
  477. /* > Logical variable SWTCH3 (switch-for-3-poles?) is for noting */
  478. /* > if we are working with THREE poles! */
  479. /* > */
  480. /* > MAXIT is the maximum number of iterations allowed for each */
  481. /* > eigenvalue. */
  482. /* > \endverbatim */
  483. /* Authors: */
  484. /* ======== */
  485. /* > \author Univ. of Tennessee */
  486. /* > \author Univ. of California Berkeley */
  487. /* > \author Univ. of Colorado Denver */
  488. /* > \author NAG Ltd. */
  489. /* > \date December 2016 */
  490. /* > \ingroup OTHERauxiliary */
  491. /* > \par Contributors: */
  492. /* ================== */
  493. /* > */
  494. /* > Ren-Cang Li, Computer Science Division, University of California */
  495. /* > at Berkeley, USA */
  496. /* > */
  497. /* ===================================================================== */
  498. /* Subroutine */ int dlasd4_(integer *n, integer *i__, doublereal *d__,
  499. doublereal *z__, doublereal *delta, doublereal *rho, doublereal *
  500. sigma, doublereal *work, integer *info)
  501. {
  502. /* System generated locals */
  503. integer i__1;
  504. doublereal d__1;
  505. /* Local variables */
  506. doublereal dphi, sglb, dpsi, sgub;
  507. integer iter;
  508. doublereal temp, prew, temp1, temp2, a, b, c__;
  509. integer j;
  510. doublereal w, dtiim, delsq, dtiip;
  511. integer niter;
  512. doublereal dtisq;
  513. logical swtch;
  514. doublereal dtnsq;
  515. extern /* Subroutine */ int dlaed6_(integer *, logical *, doublereal *,
  516. doublereal *, doublereal *, doublereal *, doublereal *, integer *)
  517. , dlasd5_(integer *, doublereal *, doublereal *, doublereal *,
  518. doublereal *, doublereal *, doublereal *);
  519. doublereal delsq2, dd[3], dtnsq1;
  520. logical swtch3;
  521. integer ii;
  522. extern doublereal dlamch_(char *);
  523. doublereal dw, zz[3];
  524. logical orgati;
  525. doublereal erretm, dtipsq, rhoinv;
  526. integer ip1;
  527. doublereal sq2, eta, phi, eps, tau, psi;
  528. logical geomavg;
  529. integer iim1, iip1;
  530. doublereal tau2;
  531. /* -- LAPACK auxiliary routine (version 3.7.0) -- */
  532. /* -- LAPACK is a software package provided by Univ. of Tennessee, -- */
  533. /* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- */
  534. /* December 2016 */
  535. /* ===================================================================== */
  536. /* Since this routine is called in an inner loop, we do no argument */
  537. /* checking. */
  538. /* Quick return for N=1 and 2. */
  539. /* Parameter adjustments */
  540. --work;
  541. --delta;
  542. --z__;
  543. --d__;
  544. /* Function Body */
  545. *info = 0;
  546. if (*n == 1) {
  547. /* Presumably, I=1 upon entry */
  548. *sigma = sqrt(d__[1] * d__[1] + *rho * z__[1] * z__[1]);
  549. delta[1] = 1.;
  550. work[1] = 1.;
  551. return 0;
  552. }
  553. if (*n == 2) {
  554. dlasd5_(i__, &d__[1], &z__[1], &delta[1], rho, sigma, &work[1]);
  555. return 0;
  556. }
  557. /* Compute machine epsilon */
  558. eps = dlamch_("Epsilon");
  559. rhoinv = 1. / *rho;
  560. tau2 = 0.;
  561. /* The case I = N */
  562. if (*i__ == *n) {
  563. /* Initialize some basic variables */
  564. ii = *n - 1;
  565. niter = 1;
  566. /* Calculate initial guess */
  567. temp = *rho / 2.;
  568. /* If ||Z||_2 is not one, then TEMP should be set to */
  569. /* RHO * ||Z||_2^2 / TWO */
  570. temp1 = temp / (d__[*n] + sqrt(d__[*n] * d__[*n] + temp));
  571. i__1 = *n;
  572. for (j = 1; j <= i__1; ++j) {
  573. work[j] = d__[j] + d__[*n] + temp1;
  574. delta[j] = d__[j] - d__[*n] - temp1;
  575. /* L10: */
  576. }
  577. psi = 0.;
  578. i__1 = *n - 2;
  579. for (j = 1; j <= i__1; ++j) {
  580. psi += z__[j] * z__[j] / (delta[j] * work[j]);
  581. /* L20: */
  582. }
  583. c__ = rhoinv + psi;
  584. w = c__ + z__[ii] * z__[ii] / (delta[ii] * work[ii]) + z__[*n] * z__[*
  585. n] / (delta[*n] * work[*n]);
  586. if (w <= 0.) {
  587. temp1 = sqrt(d__[*n] * d__[*n] + *rho);
  588. temp = z__[*n - 1] * z__[*n - 1] / ((d__[*n - 1] + temp1) * (d__[*
  589. n] - d__[*n - 1] + *rho / (d__[*n] + temp1))) + z__[*n] *
  590. z__[*n] / *rho;
  591. /* The following TAU2 is to approximate */
  592. /* SIGMA_n^2 - D( N )*D( N ) */
  593. if (c__ <= temp) {
  594. tau = *rho;
  595. } else {
  596. delsq = (d__[*n] - d__[*n - 1]) * (d__[*n] + d__[*n - 1]);
  597. a = -c__ * delsq + z__[*n - 1] * z__[*n - 1] + z__[*n] * z__[*
  598. n];
  599. b = z__[*n] * z__[*n] * delsq;
  600. if (a < 0.) {
  601. tau2 = b * 2. / (sqrt(a * a + b * 4. * c__) - a);
  602. } else {
  603. tau2 = (a + sqrt(a * a + b * 4. * c__)) / (c__ * 2.);
  604. }
  605. tau = tau2 / (d__[*n] + sqrt(d__[*n] * d__[*n] + tau2));
  606. }
  607. /* It can be proved that */
  608. /* D(N)^2+RHO/2 <= SIGMA_n^2 < D(N)^2+TAU2 <= D(N)^2+RHO */
  609. } else {
  610. delsq = (d__[*n] - d__[*n - 1]) * (d__[*n] + d__[*n - 1]);
  611. a = -c__ * delsq + z__[*n - 1] * z__[*n - 1] + z__[*n] * z__[*n];
  612. b = z__[*n] * z__[*n] * delsq;
  613. /* The following TAU2 is to approximate */
  614. /* SIGMA_n^2 - D( N )*D( N ) */
  615. if (a < 0.) {
  616. tau2 = b * 2. / (sqrt(a * a + b * 4. * c__) - a);
  617. } else {
  618. tau2 = (a + sqrt(a * a + b * 4. * c__)) / (c__ * 2.);
  619. }
  620. tau = tau2 / (d__[*n] + sqrt(d__[*n] * d__[*n] + tau2));
  621. /* It can be proved that */
  622. /* D(N)^2 < D(N)^2+TAU2 < SIGMA(N)^2 < D(N)^2+RHO/2 */
  623. }
  624. /* The following TAU is to approximate SIGMA_n - D( N ) */
  625. /* TAU = TAU2 / ( D( N )+SQRT( D( N )*D( N )+TAU2 ) ) */
  626. *sigma = d__[*n] + tau;
  627. i__1 = *n;
  628. for (j = 1; j <= i__1; ++j) {
  629. delta[j] = d__[j] - d__[*n] - tau;
  630. work[j] = d__[j] + d__[*n] + tau;
  631. /* L30: */
  632. }
  633. /* Evaluate PSI and the derivative DPSI */
  634. dpsi = 0.;
  635. psi = 0.;
  636. erretm = 0.;
  637. i__1 = ii;
  638. for (j = 1; j <= i__1; ++j) {
  639. temp = z__[j] / (delta[j] * work[j]);
  640. psi += z__[j] * temp;
  641. dpsi += temp * temp;
  642. erretm += psi;
  643. /* L40: */
  644. }
  645. erretm = abs(erretm);
  646. /* Evaluate PHI and the derivative DPHI */
  647. temp = z__[*n] / (delta[*n] * work[*n]);
  648. phi = z__[*n] * temp;
  649. dphi = temp * temp;
  650. erretm = (-phi - psi) * 8. + erretm - phi + rhoinv;
  651. /* $ + ABS( TAU2 )*( DPSI+DPHI ) */
  652. w = rhoinv + phi + psi;
  653. /* Test for convergence */
  654. if (abs(w) <= eps * erretm) {
  655. goto L240;
  656. }
  657. /* Calculate the new step */
  658. ++niter;
  659. dtnsq1 = work[*n - 1] * delta[*n - 1];
  660. dtnsq = work[*n] * delta[*n];
  661. c__ = w - dtnsq1 * dpsi - dtnsq * dphi;
  662. a = (dtnsq + dtnsq1) * w - dtnsq * dtnsq1 * (dpsi + dphi);
  663. b = dtnsq * dtnsq1 * w;
  664. if (c__ < 0.) {
  665. c__ = abs(c__);
  666. }
  667. if (c__ == 0.) {
  668. eta = *rho - *sigma * *sigma;
  669. } else if (a >= 0.) {
  670. eta = (a + sqrt((d__1 = a * a - b * 4. * c__, abs(d__1)))) / (c__
  671. * 2.);
  672. } else {
  673. eta = b * 2. / (a - sqrt((d__1 = a * a - b * 4. * c__, abs(d__1)))
  674. );
  675. }
  676. /* Note, eta should be positive if w is negative, and */
  677. /* eta should be negative otherwise. However, */
  678. /* if for some reason caused by roundoff, eta*w > 0, */
  679. /* we simply use one Newton step instead. This way */
  680. /* will guarantee eta*w < 0. */
  681. if (w * eta > 0.) {
  682. eta = -w / (dpsi + dphi);
  683. }
  684. temp = eta - dtnsq;
  685. if (temp > *rho) {
  686. eta = *rho + dtnsq;
  687. }
  688. eta /= *sigma + sqrt(eta + *sigma * *sigma);
  689. tau += eta;
  690. *sigma += eta;
  691. i__1 = *n;
  692. for (j = 1; j <= i__1; ++j) {
  693. delta[j] -= eta;
  694. work[j] += eta;
  695. /* L50: */
  696. }
  697. /* Evaluate PSI and the derivative DPSI */
  698. dpsi = 0.;
  699. psi = 0.;
  700. erretm = 0.;
  701. i__1 = ii;
  702. for (j = 1; j <= i__1; ++j) {
  703. temp = z__[j] / (work[j] * delta[j]);
  704. psi += z__[j] * temp;
  705. dpsi += temp * temp;
  706. erretm += psi;
  707. /* L60: */
  708. }
  709. erretm = abs(erretm);
  710. /* Evaluate PHI and the derivative DPHI */
  711. tau2 = work[*n] * delta[*n];
  712. temp = z__[*n] / tau2;
  713. phi = z__[*n] * temp;
  714. dphi = temp * temp;
  715. erretm = (-phi - psi) * 8. + erretm - phi + rhoinv;
  716. /* $ + ABS( TAU2 )*( DPSI+DPHI ) */
  717. w = rhoinv + phi + psi;
  718. /* Main loop to update the values of the array DELTA */
  719. iter = niter + 1;
  720. for (niter = iter; niter <= 400; ++niter) {
  721. /* Test for convergence */
  722. if (abs(w) <= eps * erretm) {
  723. goto L240;
  724. }
  725. /* Calculate the new step */
  726. dtnsq1 = work[*n - 1] * delta[*n - 1];
  727. dtnsq = work[*n] * delta[*n];
  728. c__ = w - dtnsq1 * dpsi - dtnsq * dphi;
  729. a = (dtnsq + dtnsq1) * w - dtnsq1 * dtnsq * (dpsi + dphi);
  730. b = dtnsq1 * dtnsq * w;
  731. if (a >= 0.) {
  732. eta = (a + sqrt((d__1 = a * a - b * 4. * c__, abs(d__1)))) / (
  733. c__ * 2.);
  734. } else {
  735. eta = b * 2. / (a - sqrt((d__1 = a * a - b * 4. * c__, abs(
  736. d__1))));
  737. }
  738. /* Note, eta should be positive if w is negative, and */
  739. /* eta should be negative otherwise. However, */
  740. /* if for some reason caused by roundoff, eta*w > 0, */
  741. /* we simply use one Newton step instead. This way */
  742. /* will guarantee eta*w < 0. */
  743. if (w * eta > 0.) {
  744. eta = -w / (dpsi + dphi);
  745. }
  746. temp = eta - dtnsq;
  747. if (temp <= 0.) {
  748. eta /= 2.;
  749. }
  750. eta /= *sigma + sqrt(eta + *sigma * *sigma);
  751. tau += eta;
  752. *sigma += eta;
  753. i__1 = *n;
  754. for (j = 1; j <= i__1; ++j) {
  755. delta[j] -= eta;
  756. work[j] += eta;
  757. /* L70: */
  758. }
  759. /* Evaluate PSI and the derivative DPSI */
  760. dpsi = 0.;
  761. psi = 0.;
  762. erretm = 0.;
  763. i__1 = ii;
  764. for (j = 1; j <= i__1; ++j) {
  765. temp = z__[j] / (work[j] * delta[j]);
  766. psi += z__[j] * temp;
  767. dpsi += temp * temp;
  768. erretm += psi;
  769. /* L80: */
  770. }
  771. erretm = abs(erretm);
  772. /* Evaluate PHI and the derivative DPHI */
  773. tau2 = work[*n] * delta[*n];
  774. temp = z__[*n] / tau2;
  775. phi = z__[*n] * temp;
  776. dphi = temp * temp;
  777. erretm = (-phi - psi) * 8. + erretm - phi + rhoinv;
  778. /* $ + ABS( TAU2 )*( DPSI+DPHI ) */
  779. w = rhoinv + phi + psi;
  780. /* L90: */
  781. }
  782. /* Return with INFO = 1, NITER = MAXIT and not converged */
  783. *info = 1;
  784. goto L240;
  785. /* End for the case I = N */
  786. } else {
  787. /* The case for I < N */
  788. niter = 1;
  789. ip1 = *i__ + 1;
  790. /* Calculate initial guess */
  791. delsq = (d__[ip1] - d__[*i__]) * (d__[ip1] + d__[*i__]);
  792. delsq2 = delsq / 2.;
  793. sq2 = sqrt((d__[*i__] * d__[*i__] + d__[ip1] * d__[ip1]) / 2.);
  794. temp = delsq2 / (d__[*i__] + sq2);
  795. i__1 = *n;
  796. for (j = 1; j <= i__1; ++j) {
  797. work[j] = d__[j] + d__[*i__] + temp;
  798. delta[j] = d__[j] - d__[*i__] - temp;
  799. /* L100: */
  800. }
  801. psi = 0.;
  802. i__1 = *i__ - 1;
  803. for (j = 1; j <= i__1; ++j) {
  804. psi += z__[j] * z__[j] / (work[j] * delta[j]);
  805. /* L110: */
  806. }
  807. phi = 0.;
  808. i__1 = *i__ + 2;
  809. for (j = *n; j >= i__1; --j) {
  810. phi += z__[j] * z__[j] / (work[j] * delta[j]);
  811. /* L120: */
  812. }
  813. c__ = rhoinv + psi + phi;
  814. w = c__ + z__[*i__] * z__[*i__] / (work[*i__] * delta[*i__]) + z__[
  815. ip1] * z__[ip1] / (work[ip1] * delta[ip1]);
  816. geomavg = FALSE_;
  817. if (w > 0.) {
  818. /* d(i)^2 < the ith sigma^2 < (d(i)^2+d(i+1)^2)/2 */
  819. /* We choose d(i) as origin. */
  820. orgati = TRUE_;
  821. ii = *i__;
  822. sglb = 0.;
  823. sgub = delsq2 / (d__[*i__] + sq2);
  824. a = c__ * delsq + z__[*i__] * z__[*i__] + z__[ip1] * z__[ip1];
  825. b = z__[*i__] * z__[*i__] * delsq;
  826. if (a > 0.) {
  827. tau2 = b * 2. / (a + sqrt((d__1 = a * a - b * 4. * c__, abs(
  828. d__1))));
  829. } else {
  830. tau2 = (a - sqrt((d__1 = a * a - b * 4. * c__, abs(d__1)))) /
  831. (c__ * 2.);
  832. }
  833. /* TAU2 now is an estimation of SIGMA^2 - D( I )^2. The */
  834. /* following, however, is the corresponding estimation of */
  835. /* SIGMA - D( I ). */
  836. tau = tau2 / (d__[*i__] + sqrt(d__[*i__] * d__[*i__] + tau2));
  837. temp = sqrt(eps);
  838. if (d__[*i__] <= temp * d__[ip1] && (d__1 = z__[*i__], abs(d__1))
  839. <= temp && d__[*i__] > 0.) {
  840. /* Computing MIN */
  841. d__1 = d__[*i__] * 10.;
  842. tau = f2cmin(d__1,sgub);
  843. geomavg = TRUE_;
  844. }
  845. } else {
  846. /* (d(i)^2+d(i+1)^2)/2 <= the ith sigma^2 < d(i+1)^2/2 */
  847. /* We choose d(i+1) as origin. */
  848. orgati = FALSE_;
  849. ii = ip1;
  850. sglb = -delsq2 / (d__[ii] + sq2);
  851. sgub = 0.;
  852. a = c__ * delsq - z__[*i__] * z__[*i__] - z__[ip1] * z__[ip1];
  853. b = z__[ip1] * z__[ip1] * delsq;
  854. if (a < 0.) {
  855. tau2 = b * 2. / (a - sqrt((d__1 = a * a + b * 4. * c__, abs(
  856. d__1))));
  857. } else {
  858. tau2 = -(a + sqrt((d__1 = a * a + b * 4. * c__, abs(d__1)))) /
  859. (c__ * 2.);
  860. }
  861. /* TAU2 now is an estimation of SIGMA^2 - D( IP1 )^2. The */
  862. /* following, however, is the corresponding estimation of */
  863. /* SIGMA - D( IP1 ). */
  864. tau = tau2 / (d__[ip1] + sqrt((d__1 = d__[ip1] * d__[ip1] + tau2,
  865. abs(d__1))));
  866. }
  867. *sigma = d__[ii] + tau;
  868. i__1 = *n;
  869. for (j = 1; j <= i__1; ++j) {
  870. work[j] = d__[j] + d__[ii] + tau;
  871. delta[j] = d__[j] - d__[ii] - tau;
  872. /* L130: */
  873. }
  874. iim1 = ii - 1;
  875. iip1 = ii + 1;
  876. /* Evaluate PSI and the derivative DPSI */
  877. dpsi = 0.;
  878. psi = 0.;
  879. erretm = 0.;
  880. i__1 = iim1;
  881. for (j = 1; j <= i__1; ++j) {
  882. temp = z__[j] / (work[j] * delta[j]);
  883. psi += z__[j] * temp;
  884. dpsi += temp * temp;
  885. erretm += psi;
  886. /* L150: */
  887. }
  888. erretm = abs(erretm);
  889. /* Evaluate PHI and the derivative DPHI */
  890. dphi = 0.;
  891. phi = 0.;
  892. i__1 = iip1;
  893. for (j = *n; j >= i__1; --j) {
  894. temp = z__[j] / (work[j] * delta[j]);
  895. phi += z__[j] * temp;
  896. dphi += temp * temp;
  897. erretm += phi;
  898. /* L160: */
  899. }
  900. w = rhoinv + phi + psi;
  901. /* W is the value of the secular function with */
  902. /* its ii-th element removed. */
  903. swtch3 = FALSE_;
  904. if (orgati) {
  905. if (w < 0.) {
  906. swtch3 = TRUE_;
  907. }
  908. } else {
  909. if (w > 0.) {
  910. swtch3 = TRUE_;
  911. }
  912. }
  913. if (ii == 1 || ii == *n) {
  914. swtch3 = FALSE_;
  915. }
  916. temp = z__[ii] / (work[ii] * delta[ii]);
  917. dw = dpsi + dphi + temp * temp;
  918. temp = z__[ii] * temp;
  919. w += temp;
  920. erretm = (phi - psi) * 8. + erretm + rhoinv * 2. + abs(temp) * 3.;
  921. /* $ + ABS( TAU2 )*DW */
  922. /* Test for convergence */
  923. if (abs(w) <= eps * erretm) {
  924. goto L240;
  925. }
  926. if (w <= 0.) {
  927. sglb = f2cmax(sglb,tau);
  928. } else {
  929. sgub = f2cmin(sgub,tau);
  930. }
  931. /* Calculate the new step */
  932. ++niter;
  933. if (! swtch3) {
  934. dtipsq = work[ip1] * delta[ip1];
  935. dtisq = work[*i__] * delta[*i__];
  936. if (orgati) {
  937. /* Computing 2nd power */
  938. d__1 = z__[*i__] / dtisq;
  939. c__ = w - dtipsq * dw + delsq * (d__1 * d__1);
  940. } else {
  941. /* Computing 2nd power */
  942. d__1 = z__[ip1] / dtipsq;
  943. c__ = w - dtisq * dw - delsq * (d__1 * d__1);
  944. }
  945. a = (dtipsq + dtisq) * w - dtipsq * dtisq * dw;
  946. b = dtipsq * dtisq * w;
  947. if (c__ == 0.) {
  948. if (a == 0.) {
  949. if (orgati) {
  950. a = z__[*i__] * z__[*i__] + dtipsq * dtipsq * (dpsi +
  951. dphi);
  952. } else {
  953. a = z__[ip1] * z__[ip1] + dtisq * dtisq * (dpsi +
  954. dphi);
  955. }
  956. }
  957. eta = b / a;
  958. } else if (a <= 0.) {
  959. eta = (a - sqrt((d__1 = a * a - b * 4. * c__, abs(d__1)))) / (
  960. c__ * 2.);
  961. } else {
  962. eta = b * 2. / (a + sqrt((d__1 = a * a - b * 4. * c__, abs(
  963. d__1))));
  964. }
  965. } else {
  966. /* Interpolation using THREE most relevant poles */
  967. dtiim = work[iim1] * delta[iim1];
  968. dtiip = work[iip1] * delta[iip1];
  969. temp = rhoinv + psi + phi;
  970. if (orgati) {
  971. temp1 = z__[iim1] / dtiim;
  972. temp1 *= temp1;
  973. c__ = temp - dtiip * (dpsi + dphi) - (d__[iim1] - d__[iip1]) *
  974. (d__[iim1] + d__[iip1]) * temp1;
  975. zz[0] = z__[iim1] * z__[iim1];
  976. if (dpsi < temp1) {
  977. zz[2] = dtiip * dtiip * dphi;
  978. } else {
  979. zz[2] = dtiip * dtiip * (dpsi - temp1 + dphi);
  980. }
  981. } else {
  982. temp1 = z__[iip1] / dtiip;
  983. temp1 *= temp1;
  984. c__ = temp - dtiim * (dpsi + dphi) - (d__[iip1] - d__[iim1]) *
  985. (d__[iim1] + d__[iip1]) * temp1;
  986. if (dphi < temp1) {
  987. zz[0] = dtiim * dtiim * dpsi;
  988. } else {
  989. zz[0] = dtiim * dtiim * (dpsi + (dphi - temp1));
  990. }
  991. zz[2] = z__[iip1] * z__[iip1];
  992. }
  993. zz[1] = z__[ii] * z__[ii];
  994. dd[0] = dtiim;
  995. dd[1] = delta[ii] * work[ii];
  996. dd[2] = dtiip;
  997. dlaed6_(&niter, &orgati, &c__, dd, zz, &w, &eta, info);
  998. if (*info != 0) {
  999. /* If INFO is not 0, i.e., DLAED6 failed, switch back */
  1000. /* to 2 pole interpolation. */
  1001. swtch3 = FALSE_;
  1002. *info = 0;
  1003. dtipsq = work[ip1] * delta[ip1];
  1004. dtisq = work[*i__] * delta[*i__];
  1005. if (orgati) {
  1006. /* Computing 2nd power */
  1007. d__1 = z__[*i__] / dtisq;
  1008. c__ = w - dtipsq * dw + delsq * (d__1 * d__1);
  1009. } else {
  1010. /* Computing 2nd power */
  1011. d__1 = z__[ip1] / dtipsq;
  1012. c__ = w - dtisq * dw - delsq * (d__1 * d__1);
  1013. }
  1014. a = (dtipsq + dtisq) * w - dtipsq * dtisq * dw;
  1015. b = dtipsq * dtisq * w;
  1016. if (c__ == 0.) {
  1017. if (a == 0.) {
  1018. if (orgati) {
  1019. a = z__[*i__] * z__[*i__] + dtipsq * dtipsq * (
  1020. dpsi + dphi);
  1021. } else {
  1022. a = z__[ip1] * z__[ip1] + dtisq * dtisq * (dpsi +
  1023. dphi);
  1024. }
  1025. }
  1026. eta = b / a;
  1027. } else if (a <= 0.) {
  1028. eta = (a - sqrt((d__1 = a * a - b * 4. * c__, abs(d__1))))
  1029. / (c__ * 2.);
  1030. } else {
  1031. eta = b * 2. / (a + sqrt((d__1 = a * a - b * 4. * c__,
  1032. abs(d__1))));
  1033. }
  1034. }
  1035. }
  1036. /* Note, eta should be positive if w is negative, and */
  1037. /* eta should be negative otherwise. However, */
  1038. /* if for some reason caused by roundoff, eta*w > 0, */
  1039. /* we simply use one Newton step instead. This way */
  1040. /* will guarantee eta*w < 0. */
  1041. if (w * eta >= 0.) {
  1042. eta = -w / dw;
  1043. }
  1044. eta /= *sigma + sqrt(*sigma * *sigma + eta);
  1045. temp = tau + eta;
  1046. if (temp > sgub || temp < sglb) {
  1047. if (w < 0.) {
  1048. eta = (sgub - tau) / 2.;
  1049. } else {
  1050. eta = (sglb - tau) / 2.;
  1051. }
  1052. if (geomavg) {
  1053. if (w < 0.) {
  1054. if (tau > 0.) {
  1055. eta = sqrt(sgub * tau) - tau;
  1056. }
  1057. } else {
  1058. if (sglb > 0.) {
  1059. eta = sqrt(sglb * tau) - tau;
  1060. }
  1061. }
  1062. }
  1063. }
  1064. prew = w;
  1065. tau += eta;
  1066. *sigma += eta;
  1067. i__1 = *n;
  1068. for (j = 1; j <= i__1; ++j) {
  1069. work[j] += eta;
  1070. delta[j] -= eta;
  1071. /* L170: */
  1072. }
  1073. /* Evaluate PSI and the derivative DPSI */
  1074. dpsi = 0.;
  1075. psi = 0.;
  1076. erretm = 0.;
  1077. i__1 = iim1;
  1078. for (j = 1; j <= i__1; ++j) {
  1079. temp = z__[j] / (work[j] * delta[j]);
  1080. psi += z__[j] * temp;
  1081. dpsi += temp * temp;
  1082. erretm += psi;
  1083. /* L180: */
  1084. }
  1085. erretm = abs(erretm);
  1086. /* Evaluate PHI and the derivative DPHI */
  1087. dphi = 0.;
  1088. phi = 0.;
  1089. i__1 = iip1;
  1090. for (j = *n; j >= i__1; --j) {
  1091. temp = z__[j] / (work[j] * delta[j]);
  1092. phi += z__[j] * temp;
  1093. dphi += temp * temp;
  1094. erretm += phi;
  1095. /* L190: */
  1096. }
  1097. tau2 = work[ii] * delta[ii];
  1098. temp = z__[ii] / tau2;
  1099. dw = dpsi + dphi + temp * temp;
  1100. temp = z__[ii] * temp;
  1101. w = rhoinv + phi + psi + temp;
  1102. erretm = (phi - psi) * 8. + erretm + rhoinv * 2. + abs(temp) * 3.;
  1103. /* $ + ABS( TAU2 )*DW */
  1104. swtch = FALSE_;
  1105. if (orgati) {
  1106. if (-w > abs(prew) / 10.) {
  1107. swtch = TRUE_;
  1108. }
  1109. } else {
  1110. if (w > abs(prew) / 10.) {
  1111. swtch = TRUE_;
  1112. }
  1113. }
  1114. /* Main loop to update the values of the array DELTA and WORK */
  1115. iter = niter + 1;
  1116. for (niter = iter; niter <= 400; ++niter) {
  1117. /* Test for convergence */
  1118. if (abs(w) <= eps * erretm) {
  1119. /* $ .OR. (SGUB-SGLB).LE.EIGHT*ABS(SGUB+SGLB) ) THEN */
  1120. goto L240;
  1121. }
  1122. if (w <= 0.) {
  1123. sglb = f2cmax(sglb,tau);
  1124. } else {
  1125. sgub = f2cmin(sgub,tau);
  1126. }
  1127. /* Calculate the new step */
  1128. if (! swtch3) {
  1129. dtipsq = work[ip1] * delta[ip1];
  1130. dtisq = work[*i__] * delta[*i__];
  1131. if (! swtch) {
  1132. if (orgati) {
  1133. /* Computing 2nd power */
  1134. d__1 = z__[*i__] / dtisq;
  1135. c__ = w - dtipsq * dw + delsq * (d__1 * d__1);
  1136. } else {
  1137. /* Computing 2nd power */
  1138. d__1 = z__[ip1] / dtipsq;
  1139. c__ = w - dtisq * dw - delsq * (d__1 * d__1);
  1140. }
  1141. } else {
  1142. temp = z__[ii] / (work[ii] * delta[ii]);
  1143. if (orgati) {
  1144. dpsi += temp * temp;
  1145. } else {
  1146. dphi += temp * temp;
  1147. }
  1148. c__ = w - dtisq * dpsi - dtipsq * dphi;
  1149. }
  1150. a = (dtipsq + dtisq) * w - dtipsq * dtisq * dw;
  1151. b = dtipsq * dtisq * w;
  1152. if (c__ == 0.) {
  1153. if (a == 0.) {
  1154. if (! swtch) {
  1155. if (orgati) {
  1156. a = z__[*i__] * z__[*i__] + dtipsq * dtipsq *
  1157. (dpsi + dphi);
  1158. } else {
  1159. a = z__[ip1] * z__[ip1] + dtisq * dtisq * (
  1160. dpsi + dphi);
  1161. }
  1162. } else {
  1163. a = dtisq * dtisq * dpsi + dtipsq * dtipsq * dphi;
  1164. }
  1165. }
  1166. eta = b / a;
  1167. } else if (a <= 0.) {
  1168. eta = (a - sqrt((d__1 = a * a - b * 4. * c__, abs(d__1))))
  1169. / (c__ * 2.);
  1170. } else {
  1171. eta = b * 2. / (a + sqrt((d__1 = a * a - b * 4. * c__,
  1172. abs(d__1))));
  1173. }
  1174. } else {
  1175. /* Interpolation using THREE most relevant poles */
  1176. dtiim = work[iim1] * delta[iim1];
  1177. dtiip = work[iip1] * delta[iip1];
  1178. temp = rhoinv + psi + phi;
  1179. if (swtch) {
  1180. c__ = temp - dtiim * dpsi - dtiip * dphi;
  1181. zz[0] = dtiim * dtiim * dpsi;
  1182. zz[2] = dtiip * dtiip * dphi;
  1183. } else {
  1184. if (orgati) {
  1185. temp1 = z__[iim1] / dtiim;
  1186. temp1 *= temp1;
  1187. temp2 = (d__[iim1] - d__[iip1]) * (d__[iim1] + d__[
  1188. iip1]) * temp1;
  1189. c__ = temp - dtiip * (dpsi + dphi) - temp2;
  1190. zz[0] = z__[iim1] * z__[iim1];
  1191. if (dpsi < temp1) {
  1192. zz[2] = dtiip * dtiip * dphi;
  1193. } else {
  1194. zz[2] = dtiip * dtiip * (dpsi - temp1 + dphi);
  1195. }
  1196. } else {
  1197. temp1 = z__[iip1] / dtiip;
  1198. temp1 *= temp1;
  1199. temp2 = (d__[iip1] - d__[iim1]) * (d__[iim1] + d__[
  1200. iip1]) * temp1;
  1201. c__ = temp - dtiim * (dpsi + dphi) - temp2;
  1202. if (dphi < temp1) {
  1203. zz[0] = dtiim * dtiim * dpsi;
  1204. } else {
  1205. zz[0] = dtiim * dtiim * (dpsi + (dphi - temp1));
  1206. }
  1207. zz[2] = z__[iip1] * z__[iip1];
  1208. }
  1209. }
  1210. dd[0] = dtiim;
  1211. dd[1] = delta[ii] * work[ii];
  1212. dd[2] = dtiip;
  1213. dlaed6_(&niter, &orgati, &c__, dd, zz, &w, &eta, info);
  1214. if (*info != 0) {
  1215. /* If INFO is not 0, i.e., DLAED6 failed, switch */
  1216. /* back to two pole interpolation */
  1217. swtch3 = FALSE_;
  1218. *info = 0;
  1219. dtipsq = work[ip1] * delta[ip1];
  1220. dtisq = work[*i__] * delta[*i__];
  1221. if (! swtch) {
  1222. if (orgati) {
  1223. /* Computing 2nd power */
  1224. d__1 = z__[*i__] / dtisq;
  1225. c__ = w - dtipsq * dw + delsq * (d__1 * d__1);
  1226. } else {
  1227. /* Computing 2nd power */
  1228. d__1 = z__[ip1] / dtipsq;
  1229. c__ = w - dtisq * dw - delsq * (d__1 * d__1);
  1230. }
  1231. } else {
  1232. temp = z__[ii] / (work[ii] * delta[ii]);
  1233. if (orgati) {
  1234. dpsi += temp * temp;
  1235. } else {
  1236. dphi += temp * temp;
  1237. }
  1238. c__ = w - dtisq * dpsi - dtipsq * dphi;
  1239. }
  1240. a = (dtipsq + dtisq) * w - dtipsq * dtisq * dw;
  1241. b = dtipsq * dtisq * w;
  1242. if (c__ == 0.) {
  1243. if (a == 0.) {
  1244. if (! swtch) {
  1245. if (orgati) {
  1246. a = z__[*i__] * z__[*i__] + dtipsq *
  1247. dtipsq * (dpsi + dphi);
  1248. } else {
  1249. a = z__[ip1] * z__[ip1] + dtisq * dtisq *
  1250. (dpsi + dphi);
  1251. }
  1252. } else {
  1253. a = dtisq * dtisq * dpsi + dtipsq * dtipsq *
  1254. dphi;
  1255. }
  1256. }
  1257. eta = b / a;
  1258. } else if (a <= 0.) {
  1259. eta = (a - sqrt((d__1 = a * a - b * 4. * c__, abs(
  1260. d__1)))) / (c__ * 2.);
  1261. } else {
  1262. eta = b * 2. / (a + sqrt((d__1 = a * a - b * 4. * c__,
  1263. abs(d__1))));
  1264. }
  1265. }
  1266. }
  1267. /* Note, eta should be positive if w is negative, and */
  1268. /* eta should be negative otherwise. However, */
  1269. /* if for some reason caused by roundoff, eta*w > 0, */
  1270. /* we simply use one Newton step instead. This way */
  1271. /* will guarantee eta*w < 0. */
  1272. if (w * eta >= 0.) {
  1273. eta = -w / dw;
  1274. }
  1275. eta /= *sigma + sqrt(*sigma * *sigma + eta);
  1276. temp = tau + eta;
  1277. if (temp > sgub || temp < sglb) {
  1278. if (w < 0.) {
  1279. eta = (sgub - tau) / 2.;
  1280. } else {
  1281. eta = (sglb - tau) / 2.;
  1282. }
  1283. if (geomavg) {
  1284. if (w < 0.) {
  1285. if (tau > 0.) {
  1286. eta = sqrt(sgub * tau) - tau;
  1287. }
  1288. } else {
  1289. if (sglb > 0.) {
  1290. eta = sqrt(sglb * tau) - tau;
  1291. }
  1292. }
  1293. }
  1294. }
  1295. prew = w;
  1296. tau += eta;
  1297. *sigma += eta;
  1298. i__1 = *n;
  1299. for (j = 1; j <= i__1; ++j) {
  1300. work[j] += eta;
  1301. delta[j] -= eta;
  1302. /* L200: */
  1303. }
  1304. /* Evaluate PSI and the derivative DPSI */
  1305. dpsi = 0.;
  1306. psi = 0.;
  1307. erretm = 0.;
  1308. i__1 = iim1;
  1309. for (j = 1; j <= i__1; ++j) {
  1310. temp = z__[j] / (work[j] * delta[j]);
  1311. psi += z__[j] * temp;
  1312. dpsi += temp * temp;
  1313. erretm += psi;
  1314. /* L210: */
  1315. }
  1316. erretm = abs(erretm);
  1317. /* Evaluate PHI and the derivative DPHI */
  1318. dphi = 0.;
  1319. phi = 0.;
  1320. i__1 = iip1;
  1321. for (j = *n; j >= i__1; --j) {
  1322. temp = z__[j] / (work[j] * delta[j]);
  1323. phi += z__[j] * temp;
  1324. dphi += temp * temp;
  1325. erretm += phi;
  1326. /* L220: */
  1327. }
  1328. tau2 = work[ii] * delta[ii];
  1329. temp = z__[ii] / tau2;
  1330. dw = dpsi + dphi + temp * temp;
  1331. temp = z__[ii] * temp;
  1332. w = rhoinv + phi + psi + temp;
  1333. erretm = (phi - psi) * 8. + erretm + rhoinv * 2. + abs(temp) * 3.;
  1334. /* $ + ABS( TAU2 )*DW */
  1335. if (w * prew > 0. && abs(w) > abs(prew) / 10.) {
  1336. swtch = ! swtch;
  1337. }
  1338. /* L230: */
  1339. }
  1340. /* Return with INFO = 1, NITER = MAXIT and not converged */
  1341. *info = 1;
  1342. }
  1343. L240:
  1344. return 0;
  1345. /* End of DLASD4 */
  1346. } /* dlasd4_ */