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.

dlaed4.c 34 kB

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