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

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