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.

dbdsvdx.c 44 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473
  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. /* Table of constant values */
  486. static doublereal c_b10 = 1.;
  487. static doublereal c_b14 = -.125;
  488. static integer c__1 = 1;
  489. static doublereal c_b19 = 0.;
  490. static integer c__2 = 2;
  491. /* > \brief \b DBDSVDX */
  492. /* =========== DOCUMENTATION =========== */
  493. /* Online html documentation available at */
  494. /* http://www.netlib.org/lapack/explore-html/ */
  495. /* > \htmlonly */
  496. /* > Download DBDSVDX + dependencies */
  497. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/dbdsvdx
  498. .f"> */
  499. /* > [TGZ]</a> */
  500. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/dbdsvdx
  501. .f"> */
  502. /* > [ZIP]</a> */
  503. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/dbdsvdx
  504. .f"> */
  505. /* > [TXT]</a> */
  506. /* > \endhtmlonly */
  507. /* Definition: */
  508. /* =========== */
  509. /* SUBROUTINE DBDSVDX( UPLO, JOBZ, RANGE, N, D, E, VL, VU, IL, IU, */
  510. /* $ NS, S, Z, LDZ, WORK, IWORK, INFO ) */
  511. /* CHARACTER JOBZ, RANGE, UPLO */
  512. /* INTEGER IL, INFO, IU, LDZ, N, NS */
  513. /* DOUBLE PRECISION VL, VU */
  514. /* INTEGER IWORK( * ) */
  515. /* DOUBLE PRECISION D( * ), E( * ), S( * ), WORK( * ), */
  516. /* Z( LDZ, * ) */
  517. /* > \par Purpose: */
  518. /* ============= */
  519. /* > */
  520. /* > \verbatim */
  521. /* > */
  522. /* > DBDSVDX computes the singular value decomposition (SVD) of a real */
  523. /* > N-by-N (upper or lower) bidiagonal matrix B, B = U * S * VT, */
  524. /* > where S is a diagonal matrix with non-negative diagonal elements */
  525. /* > (the singular values of B), and U and VT are orthogonal matrices */
  526. /* > of left and right singular vectors, respectively. */
  527. /* > */
  528. /* > Given an upper bidiagonal B with diagonal D = [ d_1 d_2 ... d_N ] */
  529. /* > and superdiagonal E = [ e_1 e_2 ... e_N-1 ], DBDSVDX computes the */
  530. /* > singular value decompositon of B through the eigenvalues and */
  531. /* > eigenvectors of the N*2-by-N*2 tridiagonal matrix */
  532. /* > */
  533. /* > | 0 d_1 | */
  534. /* > | d_1 0 e_1 | */
  535. /* > TGK = | e_1 0 d_2 | */
  536. /* > | d_2 . . | */
  537. /* > | . . . | */
  538. /* > */
  539. /* > If (s,u,v) is a singular triplet of B with ||u|| = ||v|| = 1, then */
  540. /* > (+/-s,q), ||q|| = 1, are eigenpairs of TGK, with q = P * ( u' +/-v' ) / */
  541. /* > sqrt(2) = ( v_1 u_1 v_2 u_2 ... v_n u_n ) / sqrt(2), and */
  542. /* > P = [ e_{n+1} e_{1} e_{n+2} e_{2} ... ]. */
  543. /* > */
  544. /* > Given a TGK matrix, one can either a) compute -s,-v and change signs */
  545. /* > so that the singular values (and corresponding vectors) are already in */
  546. /* > descending order (as in DGESVD/DGESDD) or b) compute s,v and reorder */
  547. /* > the values (and corresponding vectors). DBDSVDX implements a) by */
  548. /* > calling DSTEVX (bisection plus inverse iteration, to be replaced */
  549. /* > with a version of the Multiple Relative Robust Representation */
  550. /* > algorithm. (See P. Willems and B. Lang, A framework for the MR^3 */
  551. /* > algorithm: theory and implementation, SIAM J. Sci. Comput., */
  552. /* > 35:740-766, 2013.) */
  553. /* > \endverbatim */
  554. /* Arguments: */
  555. /* ========== */
  556. /* > \param[in] UPLO */
  557. /* > \verbatim */
  558. /* > UPLO is CHARACTER*1 */
  559. /* > = 'U': B is upper bidiagonal; */
  560. /* > = 'L': B is lower bidiagonal. */
  561. /* > \endverbatim */
  562. /* > */
  563. /* > \param[in] JOBZ */
  564. /* > \verbatim */
  565. /* > JOBZ is CHARACTER*1 */
  566. /* > = 'N': Compute singular values only; */
  567. /* > = 'V': Compute singular values and singular vectors. */
  568. /* > \endverbatim */
  569. /* > */
  570. /* > \param[in] RANGE */
  571. /* > \verbatim */
  572. /* > RANGE is CHARACTER*1 */
  573. /* > = 'A': all singular values will be found. */
  574. /* > = 'V': all singular values in the half-open interval [VL,VU) */
  575. /* > will be found. */
  576. /* > = 'I': the IL-th through IU-th singular values will be found. */
  577. /* > \endverbatim */
  578. /* > */
  579. /* > \param[in] N */
  580. /* > \verbatim */
  581. /* > N is INTEGER */
  582. /* > The order of the bidiagonal matrix. N >= 0. */
  583. /* > \endverbatim */
  584. /* > */
  585. /* > \param[in] D */
  586. /* > \verbatim */
  587. /* > D is DOUBLE PRECISION array, dimension (N) */
  588. /* > The n diagonal elements of the bidiagonal matrix B. */
  589. /* > \endverbatim */
  590. /* > */
  591. /* > \param[in] E */
  592. /* > \verbatim */
  593. /* > E is DOUBLE PRECISION array, dimension (f2cmax(1,N-1)) */
  594. /* > The (n-1) superdiagonal elements of the bidiagonal matrix */
  595. /* > B in elements 1 to N-1. */
  596. /* > \endverbatim */
  597. /* > */
  598. /* > \param[in] VL */
  599. /* > \verbatim */
  600. /* > VL is DOUBLE PRECISION */
  601. /* > If RANGE='V', the lower bound of the interval to */
  602. /* > be searched for singular values. VU > VL. */
  603. /* > Not referenced if RANGE = 'A' or 'I'. */
  604. /* > \endverbatim */
  605. /* > */
  606. /* > \param[in] VU */
  607. /* > \verbatim */
  608. /* > VU is DOUBLE PRECISION */
  609. /* > If RANGE='V', the upper bound of the interval to */
  610. /* > be searched for singular values. VU > VL. */
  611. /* > Not referenced if RANGE = 'A' or 'I'. */
  612. /* > \endverbatim */
  613. /* > */
  614. /* > \param[in] IL */
  615. /* > \verbatim */
  616. /* > IL is INTEGER */
  617. /* > If RANGE='I', the index of the */
  618. /* > smallest singular value to be returned. */
  619. /* > 1 <= IL <= IU <= f2cmin(M,N), if f2cmin(M,N) > 0. */
  620. /* > Not referenced if RANGE = 'A' or 'V'. */
  621. /* > \endverbatim */
  622. /* > */
  623. /* > \param[in] IU */
  624. /* > \verbatim */
  625. /* > IU is INTEGER */
  626. /* > If RANGE='I', the index of the */
  627. /* > largest singular value to be returned. */
  628. /* > 1 <= IL <= IU <= f2cmin(M,N), if f2cmin(M,N) > 0. */
  629. /* > Not referenced if RANGE = 'A' or 'V'. */
  630. /* > \endverbatim */
  631. /* > */
  632. /* > \param[out] NS */
  633. /* > \verbatim */
  634. /* > NS is INTEGER */
  635. /* > The total number of singular values found. 0 <= NS <= N. */
  636. /* > If RANGE = 'A', NS = N, and if RANGE = 'I', NS = IU-IL+1. */
  637. /* > \endverbatim */
  638. /* > */
  639. /* > \param[out] S */
  640. /* > \verbatim */
  641. /* > S is DOUBLE PRECISION array, dimension (N) */
  642. /* > The first NS elements contain the selected singular values in */
  643. /* > ascending order. */
  644. /* > \endverbatim */
  645. /* > */
  646. /* > \param[out] Z */
  647. /* > \verbatim */
  648. /* > Z is DOUBLE PRECISION array, dimension (2*N,K) */
  649. /* > If JOBZ = 'V', then if INFO = 0 the first NS columns of Z */
  650. /* > contain the singular vectors of the matrix B corresponding to */
  651. /* > the selected singular values, with U in rows 1 to N and V */
  652. /* > in rows N+1 to N*2, i.e. */
  653. /* > Z = [ U ] */
  654. /* > [ V ] */
  655. /* > If JOBZ = 'N', then Z is not referenced. */
  656. /* > Note: The user must ensure that at least K = NS+1 columns are */
  657. /* > supplied in the array Z; if RANGE = 'V', the exact value of */
  658. /* > NS is not known in advance and an upper bound must be used. */
  659. /* > \endverbatim */
  660. /* > */
  661. /* > \param[in] LDZ */
  662. /* > \verbatim */
  663. /* > LDZ is INTEGER */
  664. /* > The leading dimension of the array Z. LDZ >= 1, and if */
  665. /* > JOBZ = 'V', LDZ >= f2cmax(2,N*2). */
  666. /* > \endverbatim */
  667. /* > */
  668. /* > \param[out] WORK */
  669. /* > \verbatim */
  670. /* > WORK is DOUBLE PRECISION array, dimension (14*N) */
  671. /* > \endverbatim */
  672. /* > */
  673. /* > \param[out] IWORK */
  674. /* > \verbatim */
  675. /* > IWORK is INTEGER array, dimension (12*N) */
  676. /* > If JOBZ = 'V', then if INFO = 0, the first NS elements of */
  677. /* > IWORK are zero. If INFO > 0, then IWORK contains the indices */
  678. /* > of the eigenvectors that failed to converge in DSTEVX. */
  679. /* > \endverbatim */
  680. /* > */
  681. /* > \param[out] INFO */
  682. /* > \verbatim */
  683. /* > INFO is INTEGER */
  684. /* > = 0: successful exit */
  685. /* > < 0: if INFO = -i, the i-th argument had an illegal value */
  686. /* > > 0: if INFO = i, then i eigenvectors failed to converge */
  687. /* > in DSTEVX. The indices of the eigenvectors */
  688. /* > (as returned by DSTEVX) are stored in the */
  689. /* > array IWORK. */
  690. /* > if INFO = N*2 + 1, an internal error occurred. */
  691. /* > \endverbatim */
  692. /* Authors: */
  693. /* ======== */
  694. /* > \author Univ. of Tennessee */
  695. /* > \author Univ. of California Berkeley */
  696. /* > \author Univ. of Colorado Denver */
  697. /* > \author NAG Ltd. */
  698. /* > \date June 2016 */
  699. /* > \ingroup doubleOTHEReigen */
  700. /* ===================================================================== */
  701. /* Subroutine */ int dbdsvdx_(char *uplo, char *jobz, char *range, integer *n,
  702. doublereal *d__, doublereal *e, doublereal *vl, doublereal *vu,
  703. integer *il, integer *iu, integer *ns, doublereal *s, doublereal *z__,
  704. integer *ldz, doublereal *work, integer *iwork, integer *info)
  705. {
  706. /* System generated locals */
  707. integer z_dim1, z_offset, i__1, i__2, i__3, i__4, i__5;
  708. doublereal d__1, d__2, d__3, d__4;
  709. /* Local variables */
  710. doublereal emin;
  711. extern doublereal ddot_(integer *, doublereal *, integer *, doublereal *,
  712. integer *);
  713. integer ntgk;
  714. doublereal smin, smax, nrmu, nrmv;
  715. extern doublereal dnrm2_(integer *, doublereal *, integer *);
  716. logical sveq0;
  717. integer i__, idbeg, j, k;
  718. doublereal sqrt2;
  719. integer idend;
  720. extern /* Subroutine */ int dscal_(integer *, doublereal *, doublereal *,
  721. integer *);
  722. integer isbeg;
  723. extern logical lsame_(char *, char *);
  724. integer idtgk, ietgk, iltgk, itemp;
  725. extern /* Subroutine */ int dcopy_(integer *, doublereal *, integer *,
  726. doublereal *, integer *);
  727. integer icolz;
  728. logical allsv;
  729. integer idptr;
  730. logical indsv;
  731. integer ieptr, iutgk;
  732. extern /* Subroutine */ int daxpy_(integer *, doublereal *, doublereal *,
  733. integer *, doublereal *, integer *);
  734. doublereal vltgk;
  735. logical lower;
  736. extern /* Subroutine */ int dswap_(integer *, doublereal *, integer *,
  737. doublereal *, integer *);
  738. doublereal zjtji;
  739. logical split, valsv;
  740. integer isplt;
  741. doublereal ortol, vutgk;
  742. logical wantz;
  743. char rngvx[1];
  744. integer irowu, irowv, irowz;
  745. extern doublereal dlamch_(char *);
  746. integer iifail;
  747. doublereal mu;
  748. extern integer idamax_(integer *, doublereal *, integer *);
  749. extern /* Subroutine */ int dlaset_(char *, integer *, integer *,
  750. doublereal *, doublereal *, doublereal *, integer *),
  751. xerbla_(char *, integer *, ftnlen);
  752. doublereal abstol, thresh;
  753. integer iiwork;
  754. extern /* Subroutine */ int dstevx_(char *, char *, integer *, doublereal
  755. *, doublereal *, doublereal *, doublereal *, integer *, integer *,
  756. doublereal *, integer *, doublereal *, doublereal *, integer *,
  757. doublereal *, integer *, integer *, integer *),
  758. mecago_();
  759. doublereal eps;
  760. integer nsl;
  761. doublereal tol, ulp;
  762. integer nru, nrv;
  763. /* -- LAPACK driver routine (version 3.8.0) -- */
  764. /* -- LAPACK is a software package provided by Univ. of Tennessee, -- */
  765. /* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- */
  766. /* November 2017 */
  767. /* ===================================================================== */
  768. /* Test the input parameters. */
  769. /* Parameter adjustments */
  770. --d__;
  771. --e;
  772. --s;
  773. z_dim1 = *ldz;
  774. z_offset = 1 + z_dim1 * 1;
  775. z__ -= z_offset;
  776. --work;
  777. --iwork;
  778. /* Function Body */
  779. allsv = lsame_(range, "A");
  780. valsv = lsame_(range, "V");
  781. indsv = lsame_(range, "I");
  782. wantz = lsame_(jobz, "V");
  783. lower = lsame_(uplo, "L");
  784. *info = 0;
  785. if (! lsame_(uplo, "U") && ! lower) {
  786. *info = -1;
  787. } else if (! (wantz || lsame_(jobz, "N"))) {
  788. *info = -2;
  789. } else if (! (allsv || valsv || indsv)) {
  790. *info = -3;
  791. } else if (*n < 0) {
  792. *info = -4;
  793. } else if (*n > 0) {
  794. if (valsv) {
  795. if (*vl < 0.) {
  796. *info = -7;
  797. } else if (*vu <= *vl) {
  798. *info = -8;
  799. }
  800. } else if (indsv) {
  801. if (*il < 1 || *il > f2cmax(1,*n)) {
  802. *info = -9;
  803. } else if (*iu < f2cmin(*n,*il) || *iu > *n) {
  804. *info = -10;
  805. }
  806. }
  807. }
  808. if (*info == 0) {
  809. if (*ldz < 1 || wantz && *ldz < *n << 1) {
  810. *info = -14;
  811. }
  812. }
  813. if (*info != 0) {
  814. i__1 = -(*info);
  815. xerbla_("DBDSVDX", &i__1, (ftnlen)7);
  816. return 0;
  817. }
  818. /* Quick return if possible (N.LE.1) */
  819. *ns = 0;
  820. if (*n == 0) {
  821. return 0;
  822. }
  823. if (*n == 1) {
  824. if (allsv || indsv) {
  825. *ns = 1;
  826. s[1] = abs(d__[1]);
  827. } else {
  828. if (*vl < abs(d__[1]) && *vu >= abs(d__[1])) {
  829. *ns = 1;
  830. s[1] = abs(d__[1]);
  831. }
  832. }
  833. if (wantz) {
  834. z__[z_dim1 + 1] = d_sign(&c_b10, &d__[1]);
  835. z__[z_dim1 + 2] = 1.;
  836. }
  837. return 0;
  838. }
  839. abstol = dlamch_("Safe Minimum") * 2;
  840. ulp = dlamch_("Precision");
  841. eps = dlamch_("Epsilon");
  842. sqrt2 = sqrt(2.);
  843. ortol = sqrt(ulp);
  844. /* Criterion for splitting is taken from DBDSQR when singular */
  845. /* values are computed to relative accuracy TOL. (See J. Demmel and */
  846. /* W. Kahan, Accurate singular values of bidiagonal matrices, SIAM */
  847. /* J. Sci. and Stat. Comput., 11:873–912, 1990.) */
  848. /* Computing MAX */
  849. /* Computing MIN */
  850. d__3 = 100., d__4 = pow_dd(&eps, &c_b14);
  851. d__1 = 10., d__2 = f2cmin(d__3,d__4);
  852. tol = f2cmax(d__1,d__2) * eps;
  853. /* Compute approximate maximum, minimum singular values. */
  854. i__ = idamax_(n, &d__[1], &c__1);
  855. smax = (d__1 = d__[i__], abs(d__1));
  856. i__1 = *n - 1;
  857. i__ = idamax_(&i__1, &e[1], &c__1);
  858. /* Computing MAX */
  859. d__2 = smax, d__3 = (d__1 = e[i__], abs(d__1));
  860. smax = f2cmax(d__2,d__3);
  861. /* Compute threshold for neglecting D's and E's. */
  862. smin = abs(d__[1]);
  863. if (smin != 0.) {
  864. mu = smin;
  865. i__1 = *n;
  866. for (i__ = 2; i__ <= i__1; ++i__) {
  867. mu = (d__2 = d__[i__], abs(d__2)) * (mu / (mu + (d__1 = e[i__ - 1]
  868. , abs(d__1))));
  869. smin = f2cmin(smin,mu);
  870. if (smin == 0.) {
  871. myexit_();
  872. }
  873. }
  874. }
  875. smin /= sqrt((doublereal) (*n));
  876. thresh = tol * smin;
  877. /* Check for zeros in D and E (splits), i.e. submatrices. */
  878. i__1 = *n - 1;
  879. for (i__ = 1; i__ <= i__1; ++i__) {
  880. if ((d__1 = d__[i__], abs(d__1)) <= thresh) {
  881. d__[i__] = 0.;
  882. }
  883. if ((d__1 = e[i__], abs(d__1)) <= thresh) {
  884. e[i__] = 0.;
  885. }
  886. }
  887. if ((d__1 = d__[*n], abs(d__1)) <= thresh) {
  888. d__[*n] = 0.;
  889. }
  890. /* Pointers for arrays used by DSTEVX. */
  891. idtgk = 1;
  892. ietgk = idtgk + (*n << 1);
  893. itemp = ietgk + (*n << 1);
  894. iifail = 1;
  895. iiwork = iifail + (*n << 1);
  896. /* Set RNGVX, which corresponds to RANGE for DSTEVX in TGK mode. */
  897. /* VL,VU or IL,IU are redefined to conform to implementation a) */
  898. /* described in the leading comments. */
  899. iltgk = 0;
  900. iutgk = 0;
  901. vltgk = 0.;
  902. vutgk = 0.;
  903. if (allsv) {
  904. /* All singular values will be found. We aim at -s (see */
  905. /* leading comments) with RNGVX = 'I'. IL and IU are set */
  906. /* later (as ILTGK and IUTGK) according to the dimension */
  907. /* of the active submatrix. */
  908. *(unsigned char *)rngvx = 'I';
  909. if (wantz) {
  910. i__1 = *n << 1;
  911. i__2 = *n + 1;
  912. dlaset_("F", &i__1, &i__2, &c_b19, &c_b19, &z__[z_offset], ldz);
  913. }
  914. } else if (valsv) {
  915. /* Find singular values in a half-open interval. We aim */
  916. /* at -s (see leading comments) and we swap VL and VU */
  917. /* (as VUTGK and VLTGK), changing their signs. */
  918. *(unsigned char *)rngvx = 'V';
  919. vltgk = -(*vu);
  920. vutgk = -(*vl);
  921. i__1 = idtgk + (*n << 1) - 1;
  922. for (i__ = idtgk; i__ <= i__1; ++i__) {
  923. work[i__] = 0.;
  924. }
  925. /* WORK( IDTGK:IDTGK+2*N-1 ) = ZERO */
  926. dcopy_(n, &d__[1], &c__1, &work[ietgk], &c__2);
  927. i__1 = *n - 1;
  928. dcopy_(&i__1, &e[1], &c__1, &work[ietgk + 1], &c__2);
  929. i__1 = *n << 1;
  930. dstevx_("N", "V", &i__1, &work[idtgk], &work[ietgk], &vltgk, &vutgk, &
  931. iltgk, &iltgk, &abstol, ns, &s[1], &z__[z_offset], ldz, &work[
  932. itemp], &iwork[iiwork], &iwork[iifail], info);
  933. if (*ns == 0) {
  934. return 0;
  935. } else {
  936. if (wantz) {
  937. i__1 = *n << 1;
  938. dlaset_("F", &i__1, ns, &c_b19, &c_b19, &z__[z_offset], ldz);
  939. }
  940. }
  941. } else if (indsv) {
  942. /* Find the IL-th through the IU-th singular values. We aim */
  943. /* at -s (see leading comments) and indices are mapped into */
  944. /* values, therefore mimicking DSTEBZ, where */
  945. /* GL = GL - FUDGE*TNORM*ULP*N - FUDGE*TWO*PIVMIN */
  946. /* GU = GU + FUDGE*TNORM*ULP*N + FUDGE*PIVMIN */
  947. iltgk = *il;
  948. iutgk = *iu;
  949. *(unsigned char *)rngvx = 'V';
  950. i__1 = idtgk + (*n << 1) - 1;
  951. for (i__ = idtgk; i__ <= i__1; ++i__) {
  952. work[i__] = 0.;
  953. }
  954. /* WORK( IDTGK:IDTGK+2*N-1 ) = ZERO */
  955. dcopy_(n, &d__[1], &c__1, &work[ietgk], &c__2);
  956. i__1 = *n - 1;
  957. dcopy_(&i__1, &e[1], &c__1, &work[ietgk + 1], &c__2);
  958. i__1 = *n << 1;
  959. dstevx_("N", "I", &i__1, &work[idtgk], &work[ietgk], &vltgk, &vltgk, &
  960. iltgk, &iltgk, &abstol, ns, &s[1], &z__[z_offset], ldz, &work[
  961. itemp], &iwork[iiwork], &iwork[iifail], info);
  962. vltgk = s[1] - smax * 2. * ulp * *n;
  963. i__1 = idtgk + (*n << 1) - 1;
  964. for (i__ = idtgk; i__ <= i__1; ++i__) {
  965. work[i__] = 0.;
  966. }
  967. /* WORK( IDTGK:IDTGK+2*N-1 ) = ZERO */
  968. dcopy_(n, &d__[1], &c__1, &work[ietgk], &c__2);
  969. i__1 = *n - 1;
  970. dcopy_(&i__1, &e[1], &c__1, &work[ietgk + 1], &c__2);
  971. i__1 = *n << 1;
  972. dstevx_("N", "I", &i__1, &work[idtgk], &work[ietgk], &vutgk, &vutgk, &
  973. iutgk, &iutgk, &abstol, ns, &s[1], &z__[z_offset], ldz, &work[
  974. itemp], &iwork[iiwork], &iwork[iifail], info);
  975. vutgk = s[1] + smax * 2. * ulp * *n;
  976. vutgk = f2cmin(vutgk,0.);
  977. /* If VLTGK=VUTGK, DSTEVX returns an error message, */
  978. /* so if needed we change VUTGK slightly. */
  979. if (vltgk == vutgk) {
  980. vltgk -= tol;
  981. }
  982. if (wantz) {
  983. i__1 = *n << 1;
  984. i__2 = *iu - *il + 1;
  985. dlaset_("F", &i__1, &i__2, &c_b19, &c_b19, &z__[z_offset], ldz);
  986. }
  987. }
  988. /* Initialize variables and pointers for S, Z, and WORK. */
  989. /* NRU, NRV: number of rows in U and V for the active submatrix */
  990. /* IDBEG, ISBEG: offsets for the entries of D and S */
  991. /* IROWZ, ICOLZ: offsets for the rows and columns of Z */
  992. /* IROWU, IROWV: offsets for the rows of U and V */
  993. *ns = 0;
  994. nru = 0;
  995. nrv = 0;
  996. idbeg = 1;
  997. isbeg = 1;
  998. irowz = 1;
  999. icolz = 1;
  1000. irowu = 2;
  1001. irowv = 1;
  1002. split = FALSE_;
  1003. sveq0 = FALSE_;
  1004. /* Form the tridiagonal TGK matrix. */
  1005. i__1 = *n;
  1006. for (i__ = 1; i__ <= i__1; ++i__) {
  1007. s[i__] = 0.;
  1008. }
  1009. /* S( 1:N ) = ZERO */
  1010. work[ietgk + (*n << 1) - 1] = 0.;
  1011. i__1 = idtgk + (*n << 1) - 1;
  1012. for (i__ = idtgk; i__ <= i__1; ++i__) {
  1013. work[i__] = 0.;
  1014. }
  1015. /* WORK( IDTGK:IDTGK+2*N-1 ) = ZERO */
  1016. dcopy_(n, &d__[1], &c__1, &work[ietgk], &c__2);
  1017. i__1 = *n - 1;
  1018. dcopy_(&i__1, &e[1], &c__1, &work[ietgk + 1], &c__2);
  1019. /* Check for splits in two levels, outer level */
  1020. /* in E and inner level in D. */
  1021. i__1 = *n << 1;
  1022. for (ieptr = 2; ieptr <= i__1; ieptr += 2) {
  1023. if (work[ietgk + ieptr - 1] == 0.) {
  1024. /* Split in E (this piece of B is square) or bottom */
  1025. /* of the (input bidiagonal) matrix. */
  1026. isplt = idbeg;
  1027. idend = ieptr - 1;
  1028. i__2 = idend;
  1029. for (idptr = idbeg; idptr <= i__2; idptr += 2) {
  1030. if (work[ietgk + idptr - 1] == 0.) {
  1031. /* Split in D (rectangular submatrix). Set the number */
  1032. /* of rows in U and V (NRU and NRV) accordingly. */
  1033. if (idptr == idbeg) {
  1034. /* D=0 at the top. */
  1035. sveq0 = TRUE_;
  1036. if (idbeg == idend) {
  1037. nru = 1;
  1038. nrv = 1;
  1039. }
  1040. } else if (idptr == idend) {
  1041. /* D=0 at the bottom. */
  1042. sveq0 = TRUE_;
  1043. nru = (idend - isplt) / 2 + 1;
  1044. nrv = nru;
  1045. if (isplt != idbeg) {
  1046. ++nru;
  1047. }
  1048. } else {
  1049. if (isplt == idbeg) {
  1050. /* Split: top rectangular submatrix. */
  1051. nru = (idptr - idbeg) / 2;
  1052. nrv = nru + 1;
  1053. } else {
  1054. /* Split: middle square submatrix. */
  1055. nru = (idptr - isplt) / 2 + 1;
  1056. nrv = nru;
  1057. }
  1058. }
  1059. } else if (idptr == idend) {
  1060. /* Last entry of D in the active submatrix. */
  1061. if (isplt == idbeg) {
  1062. /* No split (trivial case). */
  1063. nru = (idend - idbeg) / 2 + 1;
  1064. nrv = nru;
  1065. } else {
  1066. /* Split: bottom rectangular submatrix. */
  1067. nrv = (idend - isplt) / 2 + 1;
  1068. nru = nrv + 1;
  1069. }
  1070. }
  1071. ntgk = nru + nrv;
  1072. if (ntgk > 0) {
  1073. /* Compute eigenvalues/vectors of the active */
  1074. /* submatrix according to RANGE: */
  1075. /* if RANGE='A' (ALLSV) then RNGVX = 'I' */
  1076. /* if RANGE='V' (VALSV) then RNGVX = 'V' */
  1077. /* if RANGE='I' (INDSV) then RNGVX = 'V' */
  1078. iltgk = 1;
  1079. iutgk = ntgk / 2;
  1080. if (allsv || vutgk == 0.) {
  1081. if (sveq0 || smin < eps || ntgk % 2 > 0) {
  1082. /* Special case: eigenvalue equal to zero or very */
  1083. /* small, additional eigenvector is needed. */
  1084. ++iutgk;
  1085. }
  1086. }
  1087. /* Workspace needed by DSTEVX: */
  1088. /* WORK( ITEMP: ): 2*5*NTGK */
  1089. /* IWORK( 1: ): 2*6*NTGK */
  1090. dstevx_(jobz, rngvx, &ntgk, &work[idtgk + isplt - 1], &
  1091. work[ietgk + isplt - 1], &vltgk, &vutgk, &iltgk, &
  1092. iutgk, &abstol, &nsl, &s[isbeg], &z__[irowz +
  1093. icolz * z_dim1], ldz, &work[itemp], &iwork[iiwork]
  1094. , &iwork[iifail], info);
  1095. if (*info != 0) {
  1096. /* Exit with the error code from DSTEVX. */
  1097. return 0;
  1098. }
  1099. emin = (d__1 = s[isbeg], abs(d__1));
  1100. i__3 = isbeg + nsl - 1;
  1101. for (i__ = isbeg; i__ <= i__3; ++i__) {
  1102. if ((d__1 = s[i__], abs(d__1)) > emin) {
  1103. emin = s[i__];
  1104. }
  1105. }
  1106. /* EMIN = ABS( MAXVAL( S( ISBEG:ISBEG+NSL-1 ) ) ) */
  1107. if (nsl > 0 && wantz) {
  1108. /* Normalize u=Z([2,4,...],:) and v=Z([1,3,...],:), */
  1109. /* changing the sign of v as discussed in the leading */
  1110. /* comments. The norms of u and v may be (slightly) */
  1111. /* different from 1/sqrt(2) if the corresponding */
  1112. /* eigenvalues are very small or too close. We check */
  1113. /* those norms and, if needed, reorthogonalize the */
  1114. /* vectors. */
  1115. if (nsl > 1 && vutgk == 0. && ntgk % 2 == 0 && emin ==
  1116. 0. && ! split) {
  1117. /* D=0 at the top or bottom of the active submatrix: */
  1118. /* one eigenvalue is equal to zero; concatenate the */
  1119. /* eigenvectors corresponding to the two smallest */
  1120. /* eigenvalues. */
  1121. i__3 = irowz + ntgk - 1;
  1122. for (i__ = irowz; i__ <= i__3; ++i__) {
  1123. z__[i__ + (icolz + nsl - 2) * z_dim1] += z__[
  1124. i__ + (icolz + nsl - 1) * z_dim1];
  1125. z__[i__ + (icolz + nsl - 1) * z_dim1] = 0.;
  1126. }
  1127. /* Z( IROWZ:IROWZ+NTGK-1,ICOLZ+NSL-2 ) = */
  1128. /* $ Z( IROWZ:IROWZ+NTGK-1,ICOLZ+NSL-2 ) + */
  1129. /* $ Z( IROWZ:IROWZ+NTGK-1,ICOLZ+NSL-1 ) */
  1130. /* Z( IROWZ:IROWZ+NTGK-1,ICOLZ+NSL-1 ) = */
  1131. /* $ ZERO */
  1132. /* IF( IUTGK*2.GT.NTGK ) THEN */
  1133. /* Eigenvalue equal to zero or very small. */
  1134. /* NSL = NSL - 1 */
  1135. /* END IF */
  1136. }
  1137. /* Computing MIN */
  1138. i__4 = nsl - 1, i__5 = nru - 1;
  1139. i__3 = f2cmin(i__4,i__5);
  1140. for (i__ = 0; i__ <= i__3; ++i__) {
  1141. nrmu = dnrm2_(&nru, &z__[irowu + (icolz + i__) *
  1142. z_dim1], &c__2);
  1143. if (nrmu == 0.) {
  1144. *info = (*n << 1) + 1;
  1145. return 0;
  1146. }
  1147. d__1 = 1. / nrmu;
  1148. dscal_(&nru, &d__1, &z__[irowu + (icolz + i__) *
  1149. z_dim1], &c__2);
  1150. if (nrmu != 1. && (d__1 = nrmu - ortol, abs(d__1))
  1151. * sqrt2 > 1.) {
  1152. i__4 = i__ - 1;
  1153. for (j = 0; j <= i__4; ++j) {
  1154. zjtji = -ddot_(&nru, &z__[irowu + (icolz
  1155. + j) * z_dim1], &c__2, &z__[irowu
  1156. + (icolz + i__) * z_dim1], &c__2);
  1157. daxpy_(&nru, &zjtji, &z__[irowu + (icolz
  1158. + j) * z_dim1], &c__2, &z__[irowu
  1159. + (icolz + i__) * z_dim1], &c__2);
  1160. }
  1161. nrmu = dnrm2_(&nru, &z__[irowu + (icolz + i__)
  1162. * z_dim1], &c__2);
  1163. d__1 = 1. / nrmu;
  1164. dscal_(&nru, &d__1, &z__[irowu + (icolz + i__)
  1165. * z_dim1], &c__2);
  1166. }
  1167. }
  1168. /* Computing MIN */
  1169. i__4 = nsl - 1, i__5 = nrv - 1;
  1170. i__3 = f2cmin(i__4,i__5);
  1171. for (i__ = 0; i__ <= i__3; ++i__) {
  1172. nrmv = dnrm2_(&nrv, &z__[irowv + (icolz + i__) *
  1173. z_dim1], &c__2);
  1174. if (nrmv == 0.) {
  1175. *info = (*n << 1) + 1;
  1176. return 0;
  1177. }
  1178. d__1 = -1. / nrmv;
  1179. dscal_(&nrv, &d__1, &z__[irowv + (icolz + i__) *
  1180. z_dim1], &c__2);
  1181. if (nrmv != 1. && (d__1 = nrmv - ortol, abs(d__1))
  1182. * sqrt2 > 1.) {
  1183. i__4 = i__ - 1;
  1184. for (j = 0; j <= i__4; ++j) {
  1185. zjtji = -ddot_(&nrv, &z__[irowv + (icolz
  1186. + j) * z_dim1], &c__2, &z__[irowv
  1187. + (icolz + i__) * z_dim1], &c__2);
  1188. daxpy_(&nru, &zjtji, &z__[irowv + (icolz
  1189. + j) * z_dim1], &c__2, &z__[irowv
  1190. + (icolz + i__) * z_dim1], &c__2);
  1191. }
  1192. nrmv = dnrm2_(&nrv, &z__[irowv + (icolz + i__)
  1193. * z_dim1], &c__2);
  1194. d__1 = 1. / nrmv;
  1195. dscal_(&nrv, &d__1, &z__[irowv + (icolz + i__)
  1196. * z_dim1], &c__2);
  1197. }
  1198. }
  1199. if (vutgk == 0. && idptr < idend && ntgk % 2 > 0) {
  1200. /* D=0 in the middle of the active submatrix (one */
  1201. /* eigenvalue is equal to zero): save the corresponding */
  1202. /* eigenvector for later use (when bottom of the */
  1203. /* active submatrix is reached). */
  1204. split = TRUE_;
  1205. i__3 = irowz + ntgk - 1;
  1206. for (i__ = irowz; i__ <= i__3; ++i__) {
  1207. z__[i__ + (*n + 1) * z_dim1] = z__[i__ + (*ns
  1208. + nsl) * z_dim1];
  1209. z__[i__ + (*ns + nsl) * z_dim1] = 0.;
  1210. }
  1211. /* Z( IROWZ:IROWZ+NTGK-1,N+1 ) = */
  1212. /* $ Z( IROWZ:IROWZ+NTGK-1,NS+NSL ) */
  1213. /* Z( IROWZ:IROWZ+NTGK-1,NS+NSL ) = */
  1214. /* $ ZERO */
  1215. }
  1216. }
  1217. /* ** WANTZ **! */
  1218. nsl = f2cmin(nsl,nru);
  1219. sveq0 = FALSE_;
  1220. /* Absolute values of the eigenvalues of TGK. */
  1221. i__3 = nsl - 1;
  1222. for (i__ = 0; i__ <= i__3; ++i__) {
  1223. s[isbeg + i__] = (d__1 = s[isbeg + i__], abs(d__1));
  1224. }
  1225. /* Update pointers for TGK, S and Z. */
  1226. isbeg += nsl;
  1227. irowz += ntgk;
  1228. icolz += nsl;
  1229. irowu = irowz;
  1230. irowv = irowz + 1;
  1231. isplt = idptr + 1;
  1232. *ns += nsl;
  1233. nru = 0;
  1234. nrv = 0;
  1235. }
  1236. /* ** NTGK.GT.0 **! */
  1237. if (irowz < *n << 1 && wantz) {
  1238. i__3 = irowz - 1;
  1239. for (i__ = 1; i__ <= i__3; ++i__) {
  1240. z__[i__ + icolz * z_dim1] = 0.;
  1241. }
  1242. /* Z( 1:IROWZ-1, ICOLZ ) = ZERO */
  1243. }
  1244. }
  1245. /* ** IDPTR loop **! */
  1246. if (split && wantz) {
  1247. /* Bring back eigenvector corresponding */
  1248. /* to eigenvalue equal to zero. */
  1249. i__2 = idend - ntgk + 1;
  1250. for (i__ = idbeg; i__ <= i__2; ++i__) {
  1251. z__[i__ + (isbeg - 1) * z_dim1] += z__[i__ + (*n + 1) *
  1252. z_dim1];
  1253. z__[i__ + (*n + 1) * z_dim1] = 0.;
  1254. }
  1255. /* Z( IDBEG:IDEND-NTGK+1,ISBEG-1 ) = */
  1256. /* $ Z( IDBEG:IDEND-NTGK+1,ISBEG-1 ) + */
  1257. /* $ Z( IDBEG:IDEND-NTGK+1,N+1 ) */
  1258. /* Z( IDBEG:IDEND-NTGK+1,N+1 ) = 0 */
  1259. }
  1260. --irowv;
  1261. ++irowu;
  1262. idbeg = ieptr + 1;
  1263. sveq0 = FALSE_;
  1264. split = FALSE_;
  1265. }
  1266. /* ** Check for split in E **! */
  1267. }
  1268. /* Sort the singular values into decreasing order (insertion sort on */
  1269. /* singular values, but only one transposition per singular vector) */
  1270. /* ** IEPTR loop **! */
  1271. i__1 = *ns - 1;
  1272. for (i__ = 1; i__ <= i__1; ++i__) {
  1273. k = 1;
  1274. smin = s[1];
  1275. i__2 = *ns + 1 - i__;
  1276. for (j = 2; j <= i__2; ++j) {
  1277. if (s[j] <= smin) {
  1278. k = j;
  1279. smin = s[j];
  1280. }
  1281. }
  1282. if (k != *ns + 1 - i__) {
  1283. s[k] = s[*ns + 1 - i__];
  1284. s[*ns + 1 - i__] = smin;
  1285. if (wantz) {
  1286. i__2 = *n << 1;
  1287. dswap_(&i__2, &z__[k * z_dim1 + 1], &c__1, &z__[(*ns + 1 -
  1288. i__) * z_dim1 + 1], &c__1);
  1289. }
  1290. }
  1291. }
  1292. /* If RANGE=I, check for singular values/vectors to be discarded. */
  1293. if (indsv) {
  1294. k = *iu - *il + 1;
  1295. if (k < *ns) {
  1296. i__1 = *ns;
  1297. for (i__ = k + 1; i__ <= i__1; ++i__) {
  1298. s[i__] = 0.;
  1299. }
  1300. /* S( K+1:NS ) = ZERO */
  1301. if (wantz) {
  1302. i__1 = *n << 1;
  1303. for (i__ = 1; i__ <= i__1; ++i__) {
  1304. i__2 = *ns;
  1305. for (j = k + 1; j <= i__2; ++j) {
  1306. z__[i__ + j * z_dim1] = 0.;
  1307. }
  1308. }
  1309. /* Z( 1:N*2,K+1:NS ) = ZERO */
  1310. }
  1311. *ns = k;
  1312. }
  1313. }
  1314. /* Reorder Z: U = Z( 1:N,1:NS ), V = Z( N+1:N*2,1:NS ). */
  1315. /* If B is a lower diagonal, swap U and V. */
  1316. if (wantz) {
  1317. i__1 = *ns;
  1318. for (i__ = 1; i__ <= i__1; ++i__) {
  1319. i__2 = *n << 1;
  1320. dcopy_(&i__2, &z__[i__ * z_dim1 + 1], &c__1, &work[1], &c__1);
  1321. if (lower) {
  1322. dcopy_(n, &work[2], &c__2, &z__[*n + 1 + i__ * z_dim1], &c__1)
  1323. ;
  1324. dcopy_(n, &work[1], &c__2, &z__[i__ * z_dim1 + 1], &c__1);
  1325. } else {
  1326. dcopy_(n, &work[2], &c__2, &z__[i__ * z_dim1 + 1], &c__1);
  1327. dcopy_(n, &work[1], &c__2, &z__[*n + 1 + i__ * z_dim1], &c__1)
  1328. ;
  1329. }
  1330. }
  1331. }
  1332. return 0;
  1333. /* End of DBDSVDX */
  1334. } /* dbdsvdx_ */