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 40 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566
  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 DLASD4 computes the square root of the i-th updated eigenvalue of a positive symmetric rank-one
  380. modification to a positive diagonal matrix. Used by dbdsdc. */
  381. /* =========== DOCUMENTATION =========== */
  382. /* Online html documentation available at */
  383. /* http://www.netlib.org/lapack/explore-html/ */
  384. /* > \htmlonly */
  385. /* > Download DLASD4 + dependencies */
  386. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/dlasd4.
  387. f"> */
  388. /* > [TGZ]</a> */
  389. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/dlasd4.
  390. f"> */
  391. /* > [ZIP]</a> */
  392. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/dlasd4.
  393. f"> */
  394. /* > [TXT]</a> */
  395. /* > \endhtmlonly */
  396. /* Definition: */
  397. /* =========== */
  398. /* SUBROUTINE DLASD4( N, I, D, Z, DELTA, RHO, SIGMA, WORK, INFO ) */
  399. /* INTEGER I, INFO, N */
  400. /* DOUBLE PRECISION RHO, SIGMA */
  401. /* DOUBLE PRECISION D( * ), DELTA( * ), WORK( * ), Z( * ) */
  402. /* > \par Purpose: */
  403. /* ============= */
  404. /* > */
  405. /* > \verbatim */
  406. /* > */
  407. /* > This subroutine computes the square root of the I-th updated */
  408. /* > eigenvalue of a positive symmetric rank-one modification to */
  409. /* > a positive diagonal matrix whose entries are given as the squares */
  410. /* > of the corresponding entries in the array d, and that */
  411. /* > */
  412. /* > 0 <= D(i) < D(j) for i < j */
  413. /* > */
  414. /* > and that RHO > 0. This is arranged by the calling routine, and is */
  415. /* > no loss in generality. The rank-one modified system is thus */
  416. /* > */
  417. /* > diag( D ) * diag( D ) + RHO * Z * Z_transpose. */
  418. /* > */
  419. /* > where we assume the Euclidean norm of Z is 1. */
  420. /* > */
  421. /* > The method consists of approximating the rational functions in the */
  422. /* > secular equation by simpler interpolating rational functions. */
  423. /* > \endverbatim */
  424. /* Arguments: */
  425. /* ========== */
  426. /* > \param[in] N */
  427. /* > \verbatim */
  428. /* > N is INTEGER */
  429. /* > The length of all arrays. */
  430. /* > \endverbatim */
  431. /* > */
  432. /* > \param[in] I */
  433. /* > \verbatim */
  434. /* > I is INTEGER */
  435. /* > The index of the eigenvalue to be computed. 1 <= I <= N. */
  436. /* > \endverbatim */
  437. /* > */
  438. /* > \param[in] D */
  439. /* > \verbatim */
  440. /* > D is DOUBLE PRECISION array, dimension ( N ) */
  441. /* > The original eigenvalues. It is assumed that they are in */
  442. /* > order, 0 <= D(I) < D(J) for I < J. */
  443. /* > \endverbatim */
  444. /* > */
  445. /* > \param[in] Z */
  446. /* > \verbatim */
  447. /* > Z is DOUBLE PRECISION array, dimension ( N ) */
  448. /* > The components of the updating vector. */
  449. /* > \endverbatim */
  450. /* > */
  451. /* > \param[out] DELTA */
  452. /* > \verbatim */
  453. /* > DELTA is DOUBLE PRECISION array, dimension ( N ) */
  454. /* > If N .ne. 1, DELTA contains (D(j) - sigma_I) in its j-th */
  455. /* > component. If N = 1, then DELTA(1) = 1. The vector DELTA */
  456. /* > contains the information necessary to construct the */
  457. /* > (singular) eigenvectors. */
  458. /* > \endverbatim */
  459. /* > */
  460. /* > \param[in] RHO */
  461. /* > \verbatim */
  462. /* > RHO is DOUBLE PRECISION */
  463. /* > The scalar in the symmetric updating formula. */
  464. /* > \endverbatim */
  465. /* > */
  466. /* > \param[out] SIGMA */
  467. /* > \verbatim */
  468. /* > SIGMA is DOUBLE PRECISION */
  469. /* > The computed sigma_I, the I-th updated eigenvalue. */
  470. /* > \endverbatim */
  471. /* > */
  472. /* > \param[out] WORK */
  473. /* > \verbatim */
  474. /* > WORK is DOUBLE PRECISION array, dimension ( N ) */
  475. /* > If N .ne. 1, WORK contains (D(j) + sigma_I) in its j-th */
  476. /* > component. If N = 1, then WORK( 1 ) = 1. */
  477. /* > \endverbatim */
  478. /* > */
  479. /* > \param[out] INFO */
  480. /* > \verbatim */
  481. /* > INFO is INTEGER */
  482. /* > = 0: successful exit */
  483. /* > > 0: if INFO = 1, the updating process failed. */
  484. /* > \endverbatim */
  485. /* > \par Internal Parameters: */
  486. /* ========================= */
  487. /* > */
  488. /* > \verbatim */
  489. /* > Logical variable ORGATI (origin-at-i?) is used for distinguishing */
  490. /* > whether D(i) or D(i+1) is treated as the origin. */
  491. /* > */
  492. /* > ORGATI = .true. origin at i */
  493. /* > ORGATI = .false. origin at i+1 */
  494. /* > */
  495. /* > Logical variable SWTCH3 (switch-for-3-poles?) is for noting */
  496. /* > if we are working with THREE poles! */
  497. /* > */
  498. /* > MAXIT is the maximum number of iterations allowed for each */
  499. /* > eigenvalue. */
  500. /* > \endverbatim */
  501. /* Authors: */
  502. /* ======== */
  503. /* > \author Univ. of Tennessee */
  504. /* > \author Univ. of California Berkeley */
  505. /* > \author Univ. of Colorado Denver */
  506. /* > \author NAG Ltd. */
  507. /* > \date December 2016 */
  508. /* > \ingroup OTHERauxiliary */
  509. /* > \par Contributors: */
  510. /* ================== */
  511. /* > */
  512. /* > Ren-Cang Li, Computer Science Division, University of California */
  513. /* > at Berkeley, USA */
  514. /* > */
  515. /* ===================================================================== */
  516. /* Subroutine */ int dlasd4_(integer *n, integer *i__, doublereal *d__,
  517. doublereal *z__, doublereal *delta, doublereal *rho, doublereal *
  518. sigma, doublereal *work, integer *info)
  519. {
  520. /* System generated locals */
  521. integer i__1;
  522. doublereal d__1;
  523. /* Local variables */
  524. doublereal dphi, sglb, dpsi, sgub;
  525. integer iter;
  526. doublereal temp, prew, temp1, temp2, a, b, c__;
  527. integer j;
  528. doublereal w, dtiim, delsq, dtiip;
  529. integer niter;
  530. doublereal dtisq;
  531. logical swtch;
  532. doublereal dtnsq;
  533. extern /* Subroutine */ int dlaed6_(integer *, logical *, doublereal *,
  534. doublereal *, doublereal *, doublereal *, doublereal *, integer *)
  535. , dlasd5_(integer *, doublereal *, doublereal *, doublereal *,
  536. doublereal *, doublereal *, doublereal *);
  537. doublereal delsq2, dd[3], dtnsq1;
  538. logical swtch3;
  539. integer ii;
  540. extern doublereal dlamch_(char *);
  541. doublereal dw, zz[3];
  542. logical orgati;
  543. doublereal erretm, dtipsq, rhoinv;
  544. integer ip1;
  545. doublereal sq2, eta, phi, eps, tau, psi;
  546. logical geomavg;
  547. integer iim1, iip1;
  548. doublereal tau2;
  549. /* -- LAPACK auxiliary routine (version 3.7.0) -- */
  550. /* -- LAPACK is a software package provided by Univ. of Tennessee, -- */
  551. /* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- */
  552. /* December 2016 */
  553. /* ===================================================================== */
  554. /* Since this routine is called in an inner loop, we do no argument */
  555. /* checking. */
  556. /* Quick return for N=1 and 2. */
  557. /* Parameter adjustments */
  558. --work;
  559. --delta;
  560. --z__;
  561. --d__;
  562. /* Function Body */
  563. *info = 0;
  564. if (*n == 1) {
  565. /* Presumably, I=1 upon entry */
  566. *sigma = sqrt(d__[1] * d__[1] + *rho * z__[1] * z__[1]);
  567. delta[1] = 1.;
  568. work[1] = 1.;
  569. return 0;
  570. }
  571. if (*n == 2) {
  572. dlasd5_(i__, &d__[1], &z__[1], &delta[1], rho, sigma, &work[1]);
  573. return 0;
  574. }
  575. /* Compute machine epsilon */
  576. eps = dlamch_("Epsilon");
  577. rhoinv = 1. / *rho;
  578. tau2 = 0.;
  579. /* The case I = N */
  580. if (*i__ == *n) {
  581. /* Initialize some basic variables */
  582. ii = *n - 1;
  583. niter = 1;
  584. /* Calculate initial guess */
  585. temp = *rho / 2.;
  586. /* If ||Z||_2 is not one, then TEMP should be set to */
  587. /* RHO * ||Z||_2^2 / TWO */
  588. temp1 = temp / (d__[*n] + sqrt(d__[*n] * d__[*n] + temp));
  589. i__1 = *n;
  590. for (j = 1; j <= i__1; ++j) {
  591. work[j] = d__[j] + d__[*n] + temp1;
  592. delta[j] = d__[j] - d__[*n] - temp1;
  593. /* L10: */
  594. }
  595. psi = 0.;
  596. i__1 = *n - 2;
  597. for (j = 1; j <= i__1; ++j) {
  598. psi += z__[j] * z__[j] / (delta[j] * work[j]);
  599. /* L20: */
  600. }
  601. c__ = rhoinv + psi;
  602. w = c__ + z__[ii] * z__[ii] / (delta[ii] * work[ii]) + z__[*n] * z__[*
  603. n] / (delta[*n] * work[*n]);
  604. if (w <= 0.) {
  605. temp1 = sqrt(d__[*n] * d__[*n] + *rho);
  606. temp = z__[*n - 1] * z__[*n - 1] / ((d__[*n - 1] + temp1) * (d__[*
  607. n] - d__[*n - 1] + *rho / (d__[*n] + temp1))) + z__[*n] *
  608. z__[*n] / *rho;
  609. /* The following TAU2 is to approximate */
  610. /* SIGMA_n^2 - D( N )*D( N ) */
  611. if (c__ <= temp) {
  612. tau = *rho;
  613. } else {
  614. delsq = (d__[*n] - d__[*n - 1]) * (d__[*n] + d__[*n - 1]);
  615. a = -c__ * delsq + z__[*n - 1] * z__[*n - 1] + z__[*n] * z__[*
  616. n];
  617. b = z__[*n] * z__[*n] * delsq;
  618. if (a < 0.) {
  619. tau2 = b * 2. / (sqrt(a * a + b * 4. * c__) - a);
  620. } else {
  621. tau2 = (a + sqrt(a * a + b * 4. * c__)) / (c__ * 2.);
  622. }
  623. tau = tau2 / (d__[*n] + sqrt(d__[*n] * d__[*n] + tau2));
  624. }
  625. /* It can be proved that */
  626. /* D(N)^2+RHO/2 <= SIGMA_n^2 < D(N)^2+TAU2 <= D(N)^2+RHO */
  627. } else {
  628. delsq = (d__[*n] - d__[*n - 1]) * (d__[*n] + d__[*n - 1]);
  629. a = -c__ * delsq + z__[*n - 1] * z__[*n - 1] + z__[*n] * z__[*n];
  630. b = z__[*n] * z__[*n] * delsq;
  631. /* The following TAU2 is to approximate */
  632. /* SIGMA_n^2 - D( N )*D( N ) */
  633. if (a < 0.) {
  634. tau2 = b * 2. / (sqrt(a * a + b * 4. * c__) - a);
  635. } else {
  636. tau2 = (a + sqrt(a * a + b * 4. * c__)) / (c__ * 2.);
  637. }
  638. tau = tau2 / (d__[*n] + sqrt(d__[*n] * d__[*n] + tau2));
  639. /* It can be proved that */
  640. /* D(N)^2 < D(N)^2+TAU2 < SIGMA(N)^2 < D(N)^2+RHO/2 */
  641. }
  642. /* The following TAU is to approximate SIGMA_n - D( N ) */
  643. /* TAU = TAU2 / ( D( N )+SQRT( D( N )*D( N )+TAU2 ) ) */
  644. *sigma = d__[*n] + tau;
  645. i__1 = *n;
  646. for (j = 1; j <= i__1; ++j) {
  647. delta[j] = d__[j] - d__[*n] - tau;
  648. work[j] = d__[j] + d__[*n] + tau;
  649. /* L30: */
  650. }
  651. /* Evaluate PSI and the derivative DPSI */
  652. dpsi = 0.;
  653. psi = 0.;
  654. erretm = 0.;
  655. i__1 = ii;
  656. for (j = 1; j <= i__1; ++j) {
  657. temp = z__[j] / (delta[j] * work[j]);
  658. psi += z__[j] * temp;
  659. dpsi += temp * temp;
  660. erretm += psi;
  661. /* L40: */
  662. }
  663. erretm = abs(erretm);
  664. /* Evaluate PHI and the derivative DPHI */
  665. temp = z__[*n] / (delta[*n] * work[*n]);
  666. phi = z__[*n] * temp;
  667. dphi = temp * temp;
  668. erretm = (-phi - psi) * 8. + erretm - phi + rhoinv;
  669. /* $ + ABS( TAU2 )*( DPSI+DPHI ) */
  670. w = rhoinv + phi + psi;
  671. /* Test for convergence */
  672. if (abs(w) <= eps * erretm) {
  673. goto L240;
  674. }
  675. /* Calculate the new step */
  676. ++niter;
  677. dtnsq1 = work[*n - 1] * delta[*n - 1];
  678. dtnsq = work[*n] * delta[*n];
  679. c__ = w - dtnsq1 * dpsi - dtnsq * dphi;
  680. a = (dtnsq + dtnsq1) * w - dtnsq * dtnsq1 * (dpsi + dphi);
  681. b = dtnsq * dtnsq1 * w;
  682. if (c__ < 0.) {
  683. c__ = abs(c__);
  684. }
  685. if (c__ == 0.) {
  686. eta = *rho - *sigma * *sigma;
  687. } else if (a >= 0.) {
  688. eta = (a + sqrt((d__1 = a * a - b * 4. * c__, abs(d__1)))) / (c__
  689. * 2.);
  690. } else {
  691. eta = b * 2. / (a - sqrt((d__1 = a * a - b * 4. * c__, abs(d__1)))
  692. );
  693. }
  694. /* Note, eta should be positive if w is negative, and */
  695. /* eta should be negative otherwise. However, */
  696. /* if for some reason caused by roundoff, eta*w > 0, */
  697. /* we simply use one Newton step instead. This way */
  698. /* will guarantee eta*w < 0. */
  699. if (w * eta > 0.) {
  700. eta = -w / (dpsi + dphi);
  701. }
  702. temp = eta - dtnsq;
  703. if (temp > *rho) {
  704. eta = *rho + dtnsq;
  705. }
  706. eta /= *sigma + sqrt(eta + *sigma * *sigma);
  707. tau += eta;
  708. *sigma += eta;
  709. i__1 = *n;
  710. for (j = 1; j <= i__1; ++j) {
  711. delta[j] -= eta;
  712. work[j] += eta;
  713. /* L50: */
  714. }
  715. /* Evaluate PSI and the derivative DPSI */
  716. dpsi = 0.;
  717. psi = 0.;
  718. erretm = 0.;
  719. i__1 = ii;
  720. for (j = 1; j <= i__1; ++j) {
  721. temp = z__[j] / (work[j] * delta[j]);
  722. psi += z__[j] * temp;
  723. dpsi += temp * temp;
  724. erretm += psi;
  725. /* L60: */
  726. }
  727. erretm = abs(erretm);
  728. /* Evaluate PHI and the derivative DPHI */
  729. tau2 = work[*n] * delta[*n];
  730. temp = z__[*n] / tau2;
  731. phi = z__[*n] * temp;
  732. dphi = temp * temp;
  733. erretm = (-phi - psi) * 8. + erretm - phi + rhoinv;
  734. /* $ + ABS( TAU2 )*( DPSI+DPHI ) */
  735. w = rhoinv + phi + psi;
  736. /* Main loop to update the values of the array DELTA */
  737. iter = niter + 1;
  738. for (niter = iter; niter <= 400; ++niter) {
  739. /* Test for convergence */
  740. if (abs(w) <= eps * erretm) {
  741. goto L240;
  742. }
  743. /* Calculate the new step */
  744. dtnsq1 = work[*n - 1] * delta[*n - 1];
  745. dtnsq = work[*n] * delta[*n];
  746. c__ = w - dtnsq1 * dpsi - dtnsq * dphi;
  747. a = (dtnsq + dtnsq1) * w - dtnsq1 * dtnsq * (dpsi + dphi);
  748. b = dtnsq1 * dtnsq * w;
  749. if (a >= 0.) {
  750. eta = (a + sqrt((d__1 = a * a - b * 4. * c__, abs(d__1)))) / (
  751. c__ * 2.);
  752. } else {
  753. eta = b * 2. / (a - sqrt((d__1 = a * a - b * 4. * c__, abs(
  754. d__1))));
  755. }
  756. /* Note, eta should be positive if w is negative, and */
  757. /* eta should be negative otherwise. However, */
  758. /* if for some reason caused by roundoff, eta*w > 0, */
  759. /* we simply use one Newton step instead. This way */
  760. /* will guarantee eta*w < 0. */
  761. if (w * eta > 0.) {
  762. eta = -w / (dpsi + dphi);
  763. }
  764. temp = eta - dtnsq;
  765. if (temp <= 0.) {
  766. eta /= 2.;
  767. }
  768. eta /= *sigma + sqrt(eta + *sigma * *sigma);
  769. tau += eta;
  770. *sigma += eta;
  771. i__1 = *n;
  772. for (j = 1; j <= i__1; ++j) {
  773. delta[j] -= eta;
  774. work[j] += eta;
  775. /* L70: */
  776. }
  777. /* Evaluate PSI and the derivative DPSI */
  778. dpsi = 0.;
  779. psi = 0.;
  780. erretm = 0.;
  781. i__1 = ii;
  782. for (j = 1; j <= i__1; ++j) {
  783. temp = z__[j] / (work[j] * delta[j]);
  784. psi += z__[j] * temp;
  785. dpsi += temp * temp;
  786. erretm += psi;
  787. /* L80: */
  788. }
  789. erretm = abs(erretm);
  790. /* Evaluate PHI and the derivative DPHI */
  791. tau2 = work[*n] * delta[*n];
  792. temp = z__[*n] / tau2;
  793. phi = z__[*n] * temp;
  794. dphi = temp * temp;
  795. erretm = (-phi - psi) * 8. + erretm - phi + rhoinv;
  796. /* $ + ABS( TAU2 )*( DPSI+DPHI ) */
  797. w = rhoinv + phi + psi;
  798. /* L90: */
  799. }
  800. /* Return with INFO = 1, NITER = MAXIT and not converged */
  801. *info = 1;
  802. goto L240;
  803. /* End for the case I = N */
  804. } else {
  805. /* The case for I < N */
  806. niter = 1;
  807. ip1 = *i__ + 1;
  808. /* Calculate initial guess */
  809. delsq = (d__[ip1] - d__[*i__]) * (d__[ip1] + d__[*i__]);
  810. delsq2 = delsq / 2.;
  811. sq2 = sqrt((d__[*i__] * d__[*i__] + d__[ip1] * d__[ip1]) / 2.);
  812. temp = delsq2 / (d__[*i__] + sq2);
  813. i__1 = *n;
  814. for (j = 1; j <= i__1; ++j) {
  815. work[j] = d__[j] + d__[*i__] + temp;
  816. delta[j] = d__[j] - d__[*i__] - temp;
  817. /* L100: */
  818. }
  819. psi = 0.;
  820. i__1 = *i__ - 1;
  821. for (j = 1; j <= i__1; ++j) {
  822. psi += z__[j] * z__[j] / (work[j] * delta[j]);
  823. /* L110: */
  824. }
  825. phi = 0.;
  826. i__1 = *i__ + 2;
  827. for (j = *n; j >= i__1; --j) {
  828. phi += z__[j] * z__[j] / (work[j] * delta[j]);
  829. /* L120: */
  830. }
  831. c__ = rhoinv + psi + phi;
  832. w = c__ + z__[*i__] * z__[*i__] / (work[*i__] * delta[*i__]) + z__[
  833. ip1] * z__[ip1] / (work[ip1] * delta[ip1]);
  834. geomavg = FALSE_;
  835. if (w > 0.) {
  836. /* d(i)^2 < the ith sigma^2 < (d(i)^2+d(i+1)^2)/2 */
  837. /* We choose d(i) as origin. */
  838. orgati = TRUE_;
  839. ii = *i__;
  840. sglb = 0.;
  841. sgub = delsq2 / (d__[*i__] + sq2);
  842. a = c__ * delsq + z__[*i__] * z__[*i__] + z__[ip1] * z__[ip1];
  843. b = z__[*i__] * z__[*i__] * delsq;
  844. if (a > 0.) {
  845. tau2 = b * 2. / (a + sqrt((d__1 = a * a - b * 4. * c__, abs(
  846. d__1))));
  847. } else {
  848. tau2 = (a - sqrt((d__1 = a * a - b * 4. * c__, abs(d__1)))) /
  849. (c__ * 2.);
  850. }
  851. /* TAU2 now is an estimation of SIGMA^2 - D( I )^2. The */
  852. /* following, however, is the corresponding estimation of */
  853. /* SIGMA - D( I ). */
  854. tau = tau2 / (d__[*i__] + sqrt(d__[*i__] * d__[*i__] + tau2));
  855. temp = sqrt(eps);
  856. if (d__[*i__] <= temp * d__[ip1] && (d__1 = z__[*i__], abs(d__1))
  857. <= temp && d__[*i__] > 0.) {
  858. /* Computing MIN */
  859. d__1 = d__[*i__] * 10.;
  860. tau = f2cmin(d__1,sgub);
  861. geomavg = TRUE_;
  862. }
  863. } else {
  864. /* (d(i)^2+d(i+1)^2)/2 <= the ith sigma^2 < d(i+1)^2/2 */
  865. /* We choose d(i+1) as origin. */
  866. orgati = FALSE_;
  867. ii = ip1;
  868. sglb = -delsq2 / (d__[ii] + sq2);
  869. sgub = 0.;
  870. a = c__ * delsq - z__[*i__] * z__[*i__] - z__[ip1] * z__[ip1];
  871. b = z__[ip1] * z__[ip1] * delsq;
  872. if (a < 0.) {
  873. tau2 = b * 2. / (a - sqrt((d__1 = a * a + b * 4. * c__, abs(
  874. d__1))));
  875. } else {
  876. tau2 = -(a + sqrt((d__1 = a * a + b * 4. * c__, abs(d__1)))) /
  877. (c__ * 2.);
  878. }
  879. /* TAU2 now is an estimation of SIGMA^2 - D( IP1 )^2. The */
  880. /* following, however, is the corresponding estimation of */
  881. /* SIGMA - D( IP1 ). */
  882. tau = tau2 / (d__[ip1] + sqrt((d__1 = d__[ip1] * d__[ip1] + tau2,
  883. abs(d__1))));
  884. }
  885. *sigma = d__[ii] + tau;
  886. i__1 = *n;
  887. for (j = 1; j <= i__1; ++j) {
  888. work[j] = d__[j] + d__[ii] + tau;
  889. delta[j] = d__[j] - d__[ii] - tau;
  890. /* L130: */
  891. }
  892. iim1 = ii - 1;
  893. iip1 = ii + 1;
  894. /* Evaluate PSI and the derivative DPSI */
  895. dpsi = 0.;
  896. psi = 0.;
  897. erretm = 0.;
  898. i__1 = iim1;
  899. for (j = 1; j <= i__1; ++j) {
  900. temp = z__[j] / (work[j] * delta[j]);
  901. psi += z__[j] * temp;
  902. dpsi += temp * temp;
  903. erretm += psi;
  904. /* L150: */
  905. }
  906. erretm = abs(erretm);
  907. /* Evaluate PHI and the derivative DPHI */
  908. dphi = 0.;
  909. phi = 0.;
  910. i__1 = iip1;
  911. for (j = *n; j >= i__1; --j) {
  912. temp = z__[j] / (work[j] * delta[j]);
  913. phi += z__[j] * temp;
  914. dphi += temp * temp;
  915. erretm += phi;
  916. /* L160: */
  917. }
  918. w = rhoinv + phi + psi;
  919. /* W is the value of the secular function with */
  920. /* its ii-th element removed. */
  921. swtch3 = FALSE_;
  922. if (orgati) {
  923. if (w < 0.) {
  924. swtch3 = TRUE_;
  925. }
  926. } else {
  927. if (w > 0.) {
  928. swtch3 = TRUE_;
  929. }
  930. }
  931. if (ii == 1 || ii == *n) {
  932. swtch3 = FALSE_;
  933. }
  934. temp = z__[ii] / (work[ii] * delta[ii]);
  935. dw = dpsi + dphi + temp * temp;
  936. temp = z__[ii] * temp;
  937. w += temp;
  938. erretm = (phi - psi) * 8. + erretm + rhoinv * 2. + abs(temp) * 3.;
  939. /* $ + ABS( TAU2 )*DW */
  940. /* Test for convergence */
  941. if (abs(w) <= eps * erretm) {
  942. goto L240;
  943. }
  944. if (w <= 0.) {
  945. sglb = f2cmax(sglb,tau);
  946. } else {
  947. sgub = f2cmin(sgub,tau);
  948. }
  949. /* Calculate the new step */
  950. ++niter;
  951. if (! swtch3) {
  952. dtipsq = work[ip1] * delta[ip1];
  953. dtisq = work[*i__] * delta[*i__];
  954. if (orgati) {
  955. /* Computing 2nd power */
  956. d__1 = z__[*i__] / dtisq;
  957. c__ = w - dtipsq * dw + delsq * (d__1 * d__1);
  958. } else {
  959. /* Computing 2nd power */
  960. d__1 = z__[ip1] / dtipsq;
  961. c__ = w - dtisq * dw - delsq * (d__1 * d__1);
  962. }
  963. a = (dtipsq + dtisq) * w - dtipsq * dtisq * dw;
  964. b = dtipsq * dtisq * w;
  965. if (c__ == 0.) {
  966. if (a == 0.) {
  967. if (orgati) {
  968. a = z__[*i__] * z__[*i__] + dtipsq * dtipsq * (dpsi +
  969. dphi);
  970. } else {
  971. a = z__[ip1] * z__[ip1] + dtisq * dtisq * (dpsi +
  972. dphi);
  973. }
  974. }
  975. eta = b / a;
  976. } else if (a <= 0.) {
  977. eta = (a - sqrt((d__1 = a * a - b * 4. * c__, abs(d__1)))) / (
  978. c__ * 2.);
  979. } else {
  980. eta = b * 2. / (a + sqrt((d__1 = a * a - b * 4. * c__, abs(
  981. d__1))));
  982. }
  983. } else {
  984. /* Interpolation using THREE most relevant poles */
  985. dtiim = work[iim1] * delta[iim1];
  986. dtiip = work[iip1] * delta[iip1];
  987. temp = rhoinv + psi + phi;
  988. if (orgati) {
  989. temp1 = z__[iim1] / dtiim;
  990. temp1 *= temp1;
  991. c__ = temp - dtiip * (dpsi + dphi) - (d__[iim1] - d__[iip1]) *
  992. (d__[iim1] + d__[iip1]) * temp1;
  993. zz[0] = z__[iim1] * z__[iim1];
  994. if (dpsi < temp1) {
  995. zz[2] = dtiip * dtiip * dphi;
  996. } else {
  997. zz[2] = dtiip * dtiip * (dpsi - temp1 + dphi);
  998. }
  999. } else {
  1000. temp1 = z__[iip1] / dtiip;
  1001. temp1 *= temp1;
  1002. c__ = temp - dtiim * (dpsi + dphi) - (d__[iip1] - d__[iim1]) *
  1003. (d__[iim1] + d__[iip1]) * temp1;
  1004. if (dphi < temp1) {
  1005. zz[0] = dtiim * dtiim * dpsi;
  1006. } else {
  1007. zz[0] = dtiim * dtiim * (dpsi + (dphi - temp1));
  1008. }
  1009. zz[2] = z__[iip1] * z__[iip1];
  1010. }
  1011. zz[1] = z__[ii] * z__[ii];
  1012. dd[0] = dtiim;
  1013. dd[1] = delta[ii] * work[ii];
  1014. dd[2] = dtiip;
  1015. dlaed6_(&niter, &orgati, &c__, dd, zz, &w, &eta, info);
  1016. if (*info != 0) {
  1017. /* If INFO is not 0, i.e., DLAED6 failed, switch back */
  1018. /* to 2 pole interpolation. */
  1019. swtch3 = FALSE_;
  1020. *info = 0;
  1021. dtipsq = work[ip1] * delta[ip1];
  1022. dtisq = work[*i__] * delta[*i__];
  1023. if (orgati) {
  1024. /* Computing 2nd power */
  1025. d__1 = z__[*i__] / dtisq;
  1026. c__ = w - dtipsq * dw + delsq * (d__1 * d__1);
  1027. } else {
  1028. /* Computing 2nd power */
  1029. d__1 = z__[ip1] / dtipsq;
  1030. c__ = w - dtisq * dw - delsq * (d__1 * d__1);
  1031. }
  1032. a = (dtipsq + dtisq) * w - dtipsq * dtisq * dw;
  1033. b = dtipsq * dtisq * w;
  1034. if (c__ == 0.) {
  1035. if (a == 0.) {
  1036. if (orgati) {
  1037. a = z__[*i__] * z__[*i__] + dtipsq * dtipsq * (
  1038. dpsi + dphi);
  1039. } else {
  1040. a = z__[ip1] * z__[ip1] + dtisq * dtisq * (dpsi +
  1041. dphi);
  1042. }
  1043. }
  1044. eta = b / a;
  1045. } else if (a <= 0.) {
  1046. eta = (a - sqrt((d__1 = a * a - b * 4. * c__, abs(d__1))))
  1047. / (c__ * 2.);
  1048. } else {
  1049. eta = b * 2. / (a + sqrt((d__1 = a * a - b * 4. * c__,
  1050. abs(d__1))));
  1051. }
  1052. }
  1053. }
  1054. /* Note, eta should be positive if w is negative, and */
  1055. /* eta should be negative otherwise. However, */
  1056. /* if for some reason caused by roundoff, eta*w > 0, */
  1057. /* we simply use one Newton step instead. This way */
  1058. /* will guarantee eta*w < 0. */
  1059. if (w * eta >= 0.) {
  1060. eta = -w / dw;
  1061. }
  1062. eta /= *sigma + sqrt(*sigma * *sigma + eta);
  1063. temp = tau + eta;
  1064. if (temp > sgub || temp < sglb) {
  1065. if (w < 0.) {
  1066. eta = (sgub - tau) / 2.;
  1067. } else {
  1068. eta = (sglb - tau) / 2.;
  1069. }
  1070. if (geomavg) {
  1071. if (w < 0.) {
  1072. if (tau > 0.) {
  1073. eta = sqrt(sgub * tau) - tau;
  1074. }
  1075. } else {
  1076. if (sglb > 0.) {
  1077. eta = sqrt(sglb * tau) - tau;
  1078. }
  1079. }
  1080. }
  1081. }
  1082. prew = w;
  1083. tau += eta;
  1084. *sigma += eta;
  1085. i__1 = *n;
  1086. for (j = 1; j <= i__1; ++j) {
  1087. work[j] += eta;
  1088. delta[j] -= eta;
  1089. /* L170: */
  1090. }
  1091. /* Evaluate PSI and the derivative DPSI */
  1092. dpsi = 0.;
  1093. psi = 0.;
  1094. erretm = 0.;
  1095. i__1 = iim1;
  1096. for (j = 1; j <= i__1; ++j) {
  1097. temp = z__[j] / (work[j] * delta[j]);
  1098. psi += z__[j] * temp;
  1099. dpsi += temp * temp;
  1100. erretm += psi;
  1101. /* L180: */
  1102. }
  1103. erretm = abs(erretm);
  1104. /* Evaluate PHI and the derivative DPHI */
  1105. dphi = 0.;
  1106. phi = 0.;
  1107. i__1 = iip1;
  1108. for (j = *n; j >= i__1; --j) {
  1109. temp = z__[j] / (work[j] * delta[j]);
  1110. phi += z__[j] * temp;
  1111. dphi += temp * temp;
  1112. erretm += phi;
  1113. /* L190: */
  1114. }
  1115. tau2 = work[ii] * delta[ii];
  1116. temp = z__[ii] / tau2;
  1117. dw = dpsi + dphi + temp * temp;
  1118. temp = z__[ii] * temp;
  1119. w = rhoinv + phi + psi + temp;
  1120. erretm = (phi - psi) * 8. + erretm + rhoinv * 2. + abs(temp) * 3.;
  1121. /* $ + ABS( TAU2 )*DW */
  1122. swtch = FALSE_;
  1123. if (orgati) {
  1124. if (-w > abs(prew) / 10.) {
  1125. swtch = TRUE_;
  1126. }
  1127. } else {
  1128. if (w > abs(prew) / 10.) {
  1129. swtch = TRUE_;
  1130. }
  1131. }
  1132. /* Main loop to update the values of the array DELTA and WORK */
  1133. iter = niter + 1;
  1134. for (niter = iter; niter <= 400; ++niter) {
  1135. /* Test for convergence */
  1136. if (abs(w) <= eps * erretm) {
  1137. /* $ .OR. (SGUB-SGLB).LE.EIGHT*ABS(SGUB+SGLB) ) THEN */
  1138. goto L240;
  1139. }
  1140. if (w <= 0.) {
  1141. sglb = f2cmax(sglb,tau);
  1142. } else {
  1143. sgub = f2cmin(sgub,tau);
  1144. }
  1145. /* Calculate the new step */
  1146. if (! swtch3) {
  1147. dtipsq = work[ip1] * delta[ip1];
  1148. dtisq = work[*i__] * delta[*i__];
  1149. if (! swtch) {
  1150. if (orgati) {
  1151. /* Computing 2nd power */
  1152. d__1 = z__[*i__] / dtisq;
  1153. c__ = w - dtipsq * dw + delsq * (d__1 * d__1);
  1154. } else {
  1155. /* Computing 2nd power */
  1156. d__1 = z__[ip1] / dtipsq;
  1157. c__ = w - dtisq * dw - delsq * (d__1 * d__1);
  1158. }
  1159. } else {
  1160. temp = z__[ii] / (work[ii] * delta[ii]);
  1161. if (orgati) {
  1162. dpsi += temp * temp;
  1163. } else {
  1164. dphi += temp * temp;
  1165. }
  1166. c__ = w - dtisq * dpsi - dtipsq * dphi;
  1167. }
  1168. a = (dtipsq + dtisq) * w - dtipsq * dtisq * dw;
  1169. b = dtipsq * dtisq * w;
  1170. if (c__ == 0.) {
  1171. if (a == 0.) {
  1172. if (! swtch) {
  1173. if (orgati) {
  1174. a = z__[*i__] * z__[*i__] + dtipsq * dtipsq *
  1175. (dpsi + dphi);
  1176. } else {
  1177. a = z__[ip1] * z__[ip1] + dtisq * dtisq * (
  1178. dpsi + dphi);
  1179. }
  1180. } else {
  1181. a = dtisq * dtisq * dpsi + dtipsq * dtipsq * dphi;
  1182. }
  1183. }
  1184. eta = b / a;
  1185. } else if (a <= 0.) {
  1186. eta = (a - sqrt((d__1 = a * a - b * 4. * c__, abs(d__1))))
  1187. / (c__ * 2.);
  1188. } else {
  1189. eta = b * 2. / (a + sqrt((d__1 = a * a - b * 4. * c__,
  1190. abs(d__1))));
  1191. }
  1192. } else {
  1193. /* Interpolation using THREE most relevant poles */
  1194. dtiim = work[iim1] * delta[iim1];
  1195. dtiip = work[iip1] * delta[iip1];
  1196. temp = rhoinv + psi + phi;
  1197. if (swtch) {
  1198. c__ = temp - dtiim * dpsi - dtiip * dphi;
  1199. zz[0] = dtiim * dtiim * dpsi;
  1200. zz[2] = dtiip * dtiip * dphi;
  1201. } else {
  1202. if (orgati) {
  1203. temp1 = z__[iim1] / dtiim;
  1204. temp1 *= temp1;
  1205. temp2 = (d__[iim1] - d__[iip1]) * (d__[iim1] + d__[
  1206. iip1]) * temp1;
  1207. c__ = temp - dtiip * (dpsi + dphi) - temp2;
  1208. zz[0] = z__[iim1] * z__[iim1];
  1209. if (dpsi < temp1) {
  1210. zz[2] = dtiip * dtiip * dphi;
  1211. } else {
  1212. zz[2] = dtiip * dtiip * (dpsi - temp1 + dphi);
  1213. }
  1214. } else {
  1215. temp1 = z__[iip1] / dtiip;
  1216. temp1 *= temp1;
  1217. temp2 = (d__[iip1] - d__[iim1]) * (d__[iim1] + d__[
  1218. iip1]) * temp1;
  1219. c__ = temp - dtiim * (dpsi + dphi) - temp2;
  1220. if (dphi < temp1) {
  1221. zz[0] = dtiim * dtiim * dpsi;
  1222. } else {
  1223. zz[0] = dtiim * dtiim * (dpsi + (dphi - temp1));
  1224. }
  1225. zz[2] = z__[iip1] * z__[iip1];
  1226. }
  1227. }
  1228. dd[0] = dtiim;
  1229. dd[1] = delta[ii] * work[ii];
  1230. dd[2] = dtiip;
  1231. dlaed6_(&niter, &orgati, &c__, dd, zz, &w, &eta, info);
  1232. if (*info != 0) {
  1233. /* If INFO is not 0, i.e., DLAED6 failed, switch */
  1234. /* back to two pole interpolation */
  1235. swtch3 = FALSE_;
  1236. *info = 0;
  1237. dtipsq = work[ip1] * delta[ip1];
  1238. dtisq = work[*i__] * delta[*i__];
  1239. if (! swtch) {
  1240. if (orgati) {
  1241. /* Computing 2nd power */
  1242. d__1 = z__[*i__] / dtisq;
  1243. c__ = w - dtipsq * dw + delsq * (d__1 * d__1);
  1244. } else {
  1245. /* Computing 2nd power */
  1246. d__1 = z__[ip1] / dtipsq;
  1247. c__ = w - dtisq * dw - delsq * (d__1 * d__1);
  1248. }
  1249. } else {
  1250. temp = z__[ii] / (work[ii] * delta[ii]);
  1251. if (orgati) {
  1252. dpsi += temp * temp;
  1253. } else {
  1254. dphi += temp * temp;
  1255. }
  1256. c__ = w - dtisq * dpsi - dtipsq * dphi;
  1257. }
  1258. a = (dtipsq + dtisq) * w - dtipsq * dtisq * dw;
  1259. b = dtipsq * dtisq * w;
  1260. if (c__ == 0.) {
  1261. if (a == 0.) {
  1262. if (! swtch) {
  1263. if (orgati) {
  1264. a = z__[*i__] * z__[*i__] + dtipsq *
  1265. dtipsq * (dpsi + dphi);
  1266. } else {
  1267. a = z__[ip1] * z__[ip1] + dtisq * dtisq *
  1268. (dpsi + dphi);
  1269. }
  1270. } else {
  1271. a = dtisq * dtisq * dpsi + dtipsq * dtipsq *
  1272. dphi;
  1273. }
  1274. }
  1275. eta = b / a;
  1276. } else if (a <= 0.) {
  1277. eta = (a - sqrt((d__1 = a * a - b * 4. * c__, abs(
  1278. d__1)))) / (c__ * 2.);
  1279. } else {
  1280. eta = b * 2. / (a + sqrt((d__1 = a * a - b * 4. * c__,
  1281. abs(d__1))));
  1282. }
  1283. }
  1284. }
  1285. /* Note, eta should be positive if w is negative, and */
  1286. /* eta should be negative otherwise. However, */
  1287. /* if for some reason caused by roundoff, eta*w > 0, */
  1288. /* we simply use one Newton step instead. This way */
  1289. /* will guarantee eta*w < 0. */
  1290. if (w * eta >= 0.) {
  1291. eta = -w / dw;
  1292. }
  1293. eta /= *sigma + sqrt(*sigma * *sigma + eta);
  1294. temp = tau + eta;
  1295. if (temp > sgub || temp < sglb) {
  1296. if (w < 0.) {
  1297. eta = (sgub - tau) / 2.;
  1298. } else {
  1299. eta = (sglb - tau) / 2.;
  1300. }
  1301. if (geomavg) {
  1302. if (w < 0.) {
  1303. if (tau > 0.) {
  1304. eta = sqrt(sgub * tau) - tau;
  1305. }
  1306. } else {
  1307. if (sglb > 0.) {
  1308. eta = sqrt(sglb * tau) - tau;
  1309. }
  1310. }
  1311. }
  1312. }
  1313. prew = w;
  1314. tau += eta;
  1315. *sigma += eta;
  1316. i__1 = *n;
  1317. for (j = 1; j <= i__1; ++j) {
  1318. work[j] += eta;
  1319. delta[j] -= eta;
  1320. /* L200: */
  1321. }
  1322. /* Evaluate PSI and the derivative DPSI */
  1323. dpsi = 0.;
  1324. psi = 0.;
  1325. erretm = 0.;
  1326. i__1 = iim1;
  1327. for (j = 1; j <= i__1; ++j) {
  1328. temp = z__[j] / (work[j] * delta[j]);
  1329. psi += z__[j] * temp;
  1330. dpsi += temp * temp;
  1331. erretm += psi;
  1332. /* L210: */
  1333. }
  1334. erretm = abs(erretm);
  1335. /* Evaluate PHI and the derivative DPHI */
  1336. dphi = 0.;
  1337. phi = 0.;
  1338. i__1 = iip1;
  1339. for (j = *n; j >= i__1; --j) {
  1340. temp = z__[j] / (work[j] * delta[j]);
  1341. phi += z__[j] * temp;
  1342. dphi += temp * temp;
  1343. erretm += phi;
  1344. /* L220: */
  1345. }
  1346. tau2 = work[ii] * delta[ii];
  1347. temp = z__[ii] / tau2;
  1348. dw = dpsi + dphi + temp * temp;
  1349. temp = z__[ii] * temp;
  1350. w = rhoinv + phi + psi + temp;
  1351. erretm = (phi - psi) * 8. + erretm + rhoinv * 2. + abs(temp) * 3.;
  1352. /* $ + ABS( TAU2 )*DW */
  1353. if (w * prew > 0. && abs(w) > abs(prew) / 10.) {
  1354. swtch = ! swtch;
  1355. }
  1356. /* L230: */
  1357. }
  1358. /* Return with INFO = 1, NITER = MAXIT and not converged */
  1359. *info = 1;
  1360. }
  1361. L240:
  1362. return 0;
  1363. /* End of DLASD4 */
  1364. } /* dlasd4_ */