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