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

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