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.

slasd4.c 40 kB

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