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 blasint logical;
  52. typedef char logical1;
  53. typedef char integer1;
  54. #define TRUE_ (1)
  55. #define FALSE_ (0)
  56. /* Extern is for use with -E */
  57. #ifndef Extern
  58. #define Extern extern
  59. #endif
  60. /* I/O stuff */
  61. typedef int flag;
  62. typedef int ftnlen;
  63. typedef int ftnint;
  64. /*external read, write*/
  65. typedef struct
  66. { flag cierr;
  67. ftnint ciunit;
  68. flag ciend;
  69. char *cifmt;
  70. ftnint cirec;
  71. } cilist;
  72. /*internal read, write*/
  73. typedef struct
  74. { flag icierr;
  75. char *iciunit;
  76. flag iciend;
  77. char *icifmt;
  78. ftnint icirlen;
  79. ftnint icirnum;
  80. } icilist;
  81. /*open*/
  82. typedef struct
  83. { flag oerr;
  84. ftnint ounit;
  85. char *ofnm;
  86. ftnlen ofnmlen;
  87. char *osta;
  88. char *oacc;
  89. char *ofm;
  90. ftnint orl;
  91. char *oblnk;
  92. } olist;
  93. /*close*/
  94. typedef struct
  95. { flag cerr;
  96. ftnint cunit;
  97. char *csta;
  98. } cllist;
  99. /*rewind, backspace, endfile*/
  100. typedef struct
  101. { flag aerr;
  102. ftnint aunit;
  103. } alist;
  104. /* inquire */
  105. typedef struct
  106. { flag inerr;
  107. ftnint inunit;
  108. char *infile;
  109. ftnlen infilen;
  110. ftnint *inex; /*parameters in standard's order*/
  111. ftnint *inopen;
  112. ftnint *innum;
  113. ftnint *innamed;
  114. char *inname;
  115. ftnlen innamlen;
  116. char *inacc;
  117. ftnlen inacclen;
  118. char *inseq;
  119. ftnlen inseqlen;
  120. char *indir;
  121. ftnlen indirlen;
  122. char *infmt;
  123. ftnlen infmtlen;
  124. char *inform;
  125. ftnint informlen;
  126. char *inunf;
  127. ftnlen inunflen;
  128. ftnint *inrecl;
  129. ftnint *innrec;
  130. char *inblank;
  131. ftnlen inblanklen;
  132. } inlist;
  133. #define VOID void
  134. union Multitype { /* for multiple entry points */
  135. integer1 g;
  136. shortint h;
  137. integer i;
  138. /* longint j; */
  139. real r;
  140. doublereal d;
  141. complex c;
  142. doublecomplex z;
  143. };
  144. typedef union Multitype Multitype;
  145. struct Vardesc { /* for Namelist */
  146. char *name;
  147. char *addr;
  148. ftnlen *dims;
  149. int type;
  150. };
  151. typedef struct Vardesc Vardesc;
  152. struct Namelist {
  153. char *name;
  154. Vardesc **vars;
  155. int nvars;
  156. };
  157. typedef struct Namelist Namelist;
  158. #define abs(x) ((x) >= 0 ? (x) : -(x))
  159. #define dabs(x) (fabs(x))
  160. #define f2cmin(a,b) ((a) <= (b) ? (a) : (b))
  161. #define f2cmax(a,b) ((a) >= (b) ? (a) : (b))
  162. #define dmin(a,b) (f2cmin(a,b))
  163. #define dmax(a,b) (f2cmax(a,b))
  164. #define bit_test(a,b) ((a) >> (b) & 1)
  165. #define bit_clear(a,b) ((a) & ~((uinteger)1 << (b)))
  166. #define bit_set(a,b) ((a) | ((uinteger)1 << (b)))
  167. #define abort_() { sig_die("Fortran abort routine called", 1); }
  168. #define c_abs(z) (cabsf(Cf(z)))
  169. #define c_cos(R,Z) { pCf(R)=ccos(Cf(Z)); }
  170. #ifdef _MSC_VER
  171. #define c_div(c, a, b) {Cf(c)._Val[0] = (Cf(a)._Val[0]/Cf(b)._Val[0]); Cf(c)._Val[1]=(Cf(a)._Val[1]/Cf(b)._Val[1]);}
  172. #define z_div(c, a, b) {Cd(c)._Val[0] = (Cd(a)._Val[0]/Cd(b)._Val[0]); Cd(c)._Val[1]=(Cd(a)._Val[1]/df(b)._Val[1]);}
  173. #else
  174. #define c_div(c, a, b) {pCf(c) = Cf(a)/Cf(b);}
  175. #define z_div(c, a, b) {pCd(c) = Cd(a)/Cd(b);}
  176. #endif
  177. #define c_exp(R, Z) {pCf(R) = cexpf(Cf(Z));}
  178. #define c_log(R, Z) {pCf(R) = clogf(Cf(Z));}
  179. #define c_sin(R, Z) {pCf(R) = csinf(Cf(Z));}
  180. //#define c_sqrt(R, Z) {*(R) = csqrtf(Cf(Z));}
  181. #define c_sqrt(R, Z) {pCf(R) = csqrtf(Cf(Z));}
  182. #define d_abs(x) (fabs(*(x)))
  183. #define d_acos(x) (acos(*(x)))
  184. #define d_asin(x) (asin(*(x)))
  185. #define d_atan(x) (atan(*(x)))
  186. #define d_atn2(x, y) (atan2(*(x),*(y)))
  187. #define d_cnjg(R, Z) { pCd(R) = conj(Cd(Z)); }
  188. #define r_cnjg(R, Z) { pCf(R) = conjf(Cf(Z)); }
  189. #define d_cos(x) (cos(*(x)))
  190. #define d_cosh(x) (cosh(*(x)))
  191. #define d_dim(__a, __b) ( *(__a) > *(__b) ? *(__a) - *(__b) : 0.0 )
  192. #define d_exp(x) (exp(*(x)))
  193. #define d_imag(z) (cimag(Cd(z)))
  194. #define r_imag(z) (cimagf(Cf(z)))
  195. #define d_int(__x) (*(__x)>0 ? floor(*(__x)) : -floor(- *(__x)))
  196. #define r_int(__x) (*(__x)>0 ? floor(*(__x)) : -floor(- *(__x)))
  197. #define d_lg10(x) ( 0.43429448190325182765 * log(*(x)) )
  198. #define r_lg10(x) ( 0.43429448190325182765 * log(*(x)) )
  199. #define d_log(x) (log(*(x)))
  200. #define d_mod(x, y) (fmod(*(x), *(y)))
  201. #define u_nint(__x) ((__x)>=0 ? floor((__x) + .5) : -floor(.5 - (__x)))
  202. #define d_nint(x) u_nint(*(x))
  203. #define u_sign(__a,__b) ((__b) >= 0 ? ((__a) >= 0 ? (__a) : -(__a)) : -((__a) >= 0 ? (__a) : -(__a)))
  204. #define d_sign(a,b) u_sign(*(a),*(b))
  205. #define r_sign(a,b) u_sign(*(a),*(b))
  206. #define d_sin(x) (sin(*(x)))
  207. #define d_sinh(x) (sinh(*(x)))
  208. #define d_sqrt(x) (sqrt(*(x)))
  209. #define d_tan(x) (tan(*(x)))
  210. #define d_tanh(x) (tanh(*(x)))
  211. #define i_abs(x) abs(*(x))
  212. #define i_dnnt(x) ((integer)u_nint(*(x)))
  213. #define i_len(s, n) (n)
  214. #define i_nint(x) ((integer)u_nint(*(x)))
  215. #define i_sign(a,b) ((integer)u_sign((integer)*(a),(integer)*(b)))
  216. #define pow_dd(ap, bp) ( pow(*(ap), *(bp)))
  217. #define pow_si(B,E) spow_ui(*(B),*(E))
  218. #define pow_ri(B,E) spow_ui(*(B),*(E))
  219. #define pow_di(B,E) dpow_ui(*(B),*(E))
  220. #define pow_zi(p, a, b) {pCd(p) = zpow_ui(Cd(a), *(b));}
  221. #define pow_ci(p, a, b) {pCf(p) = cpow_ui(Cf(a), *(b));}
  222. #define pow_zz(R,A,B) {pCd(R) = cpow(Cd(A),*(B));}
  223. #define s_cat(lpp, rpp, rnp, np, llp) { ftnlen i, nc, ll; char *f__rp, *lp; ll = (llp); lp = (lpp); for(i=0; i < (int)*(np); ++i) { nc = ll; if((rnp)[i] < nc) nc = (rnp)[i]; ll -= nc; f__rp = (rpp)[i]; while(--nc >= 0) *lp++ = *(f__rp)++; } while(--ll >= 0) *lp++ = ' '; }
  224. #define s_cmp(a,b,c,d) ((integer)strncmp((a),(b),f2cmin((c),(d))))
  225. #define s_copy(A,B,C,D) { int __i,__m; for (__i=0, __m=f2cmin((C),(D)); __i<__m && (B)[__i] != 0; ++__i) (A)[__i] = (B)[__i]; }
  226. #define sig_die(s, kill) { exit(1); }
  227. #define s_stop(s, n) {exit(0);}
  228. static char junk[] = "\n@(#)LIBF77 VERSION 19990503\n";
  229. #define z_abs(z) (cabs(Cd(z)))
  230. #define z_exp(R, Z) {pCd(R) = cexp(Cd(Z));}
  231. #define z_sqrt(R, Z) {pCd(R) = csqrt(Cd(Z));}
  232. #define myexit_() break;
  233. #define mycycle() continue;
  234. #define myceiling(w) {ceil(w)}
  235. #define myhuge(w) {HUGE_VAL}
  236. //#define mymaxloc_(w,s,e,n) {if (sizeof(*(w)) == sizeof(double)) dmaxloc_((w),*(s),*(e),n); else dmaxloc_((w),*(s),*(e),n);}
  237. #define mymaxloc(w,s,e,n) {dmaxloc_(w,*(s),*(e),n)}
  238. /* procedure parameter types for -A and -C++ */
  239. #ifdef __cplusplus
  240. typedef logical (*L_fp)(...);
  241. #else
  242. typedef logical (*L_fp)();
  243. #endif
  244. static float spow_ui(float x, integer n) {
  245. float pow=1.0; unsigned long int u;
  246. if(n != 0) {
  247. if(n < 0) n = -n, x = 1/x;
  248. for(u = n; ; ) {
  249. if(u & 01) pow *= x;
  250. if(u >>= 1) x *= x;
  251. else break;
  252. }
  253. }
  254. return pow;
  255. }
  256. static double dpow_ui(double x, integer n) {
  257. double pow=1.0; unsigned long int u;
  258. if(n != 0) {
  259. if(n < 0) n = -n, x = 1/x;
  260. for(u = n; ; ) {
  261. if(u & 01) pow *= x;
  262. if(u >>= 1) x *= x;
  263. else break;
  264. }
  265. }
  266. return pow;
  267. }
  268. #ifdef _MSC_VER
  269. static _Fcomplex cpow_ui(complex x, integer n) {
  270. complex pow={1.0,0.0}; unsigned long int u;
  271. if(n != 0) {
  272. if(n < 0) n = -n, x.r = 1/x.r, x.i=1/x.i;
  273. for(u = n; ; ) {
  274. if(u & 01) pow.r *= x.r, pow.i *= x.i;
  275. if(u >>= 1) x.r *= x.r, x.i *= x.i;
  276. else break;
  277. }
  278. }
  279. _Fcomplex p={pow.r, pow.i};
  280. return p;
  281. }
  282. #else
  283. static _Complex float cpow_ui(_Complex float x, integer n) {
  284. _Complex float pow=1.0; unsigned long int u;
  285. if(n != 0) {
  286. if(n < 0) n = -n, x = 1/x;
  287. for(u = n; ; ) {
  288. if(u & 01) pow *= x;
  289. if(u >>= 1) x *= x;
  290. else break;
  291. }
  292. }
  293. return pow;
  294. }
  295. #endif
  296. #ifdef _MSC_VER
  297. static _Dcomplex zpow_ui(_Dcomplex x, integer n) {
  298. _Dcomplex pow={1.0,0.0}; unsigned long int u;
  299. if(n != 0) {
  300. if(n < 0) n = -n, x._Val[0] = 1/x._Val[0], x._Val[1] =1/x._Val[1];
  301. for(u = n; ; ) {
  302. if(u & 01) pow._Val[0] *= x._Val[0], pow._Val[1] *= x._Val[1];
  303. if(u >>= 1) x._Val[0] *= x._Val[0], x._Val[1] *= x._Val[1];
  304. else break;
  305. }
  306. }
  307. _Dcomplex p = {pow._Val[0], pow._Val[1]};
  308. return p;
  309. }
  310. #else
  311. static _Complex double zpow_ui(_Complex double x, integer n) {
  312. _Complex double pow=1.0; unsigned long int u;
  313. if(n != 0) {
  314. if(n < 0) n = -n, x = 1/x;
  315. for(u = n; ; ) {
  316. if(u & 01) pow *= x;
  317. if(u >>= 1) x *= x;
  318. else break;
  319. }
  320. }
  321. return pow;
  322. }
  323. #endif
  324. static integer pow_ii(integer x, integer n) {
  325. integer pow; unsigned long int u;
  326. if (n <= 0) {
  327. if (n == 0 || x == 1) pow = 1;
  328. else if (x != -1) pow = x == 0 ? 1/x : 0;
  329. else n = -n;
  330. }
  331. if ((n > 0) || !(n == 0 || x == 1 || x != -1)) {
  332. u = n;
  333. for(pow = 1; ; ) {
  334. if(u & 01) pow *= x;
  335. if(u >>= 1) x *= x;
  336. else break;
  337. }
  338. }
  339. return pow;
  340. }
  341. static integer dmaxloc_(double *w, integer s, integer e, integer *n)
  342. {
  343. double m; integer i, mi;
  344. for(m=w[s-1], mi=s, i=s+1; i<=e; i++)
  345. if (w[i-1]>m) mi=i ,m=w[i-1];
  346. return mi-s+1;
  347. }
  348. static integer smaxloc_(float *w, integer s, integer e, integer *n)
  349. {
  350. float m; integer i, mi;
  351. for(m=w[s-1], mi=s, i=s+1; i<=e; i++)
  352. if (w[i-1]>m) mi=i ,m=w[i-1];
  353. return mi-s+1;
  354. }
  355. static inline void cdotc_(complex *z, integer *n_, complex *x, integer *incx_, complex *y, integer *incy_) {
  356. integer n = *n_, incx = *incx_, incy = *incy_, i;
  357. #ifdef _MSC_VER
  358. _Fcomplex zdotc = {0.0, 0.0};
  359. if (incx == 1 && incy == 1) {
  360. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  361. zdotc._Val[0] += conjf(Cf(&x[i]))._Val[0] * Cf(&y[i])._Val[0];
  362. zdotc._Val[1] += conjf(Cf(&x[i]))._Val[1] * Cf(&y[i])._Val[1];
  363. }
  364. } else {
  365. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  366. zdotc._Val[0] += conjf(Cf(&x[i*incx]))._Val[0] * Cf(&y[i*incy])._Val[0];
  367. zdotc._Val[1] += conjf(Cf(&x[i*incx]))._Val[1] * Cf(&y[i*incy])._Val[1];
  368. }
  369. }
  370. pCf(z) = zdotc;
  371. }
  372. #else
  373. _Complex float zdotc = 0.0;
  374. if (incx == 1 && incy == 1) {
  375. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  376. zdotc += conjf(Cf(&x[i])) * Cf(&y[i]);
  377. }
  378. } else {
  379. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  380. zdotc += conjf(Cf(&x[i*incx])) * Cf(&y[i*incy]);
  381. }
  382. }
  383. pCf(z) = zdotc;
  384. }
  385. #endif
  386. static inline void zdotc_(doublecomplex *z, integer *n_, doublecomplex *x, integer *incx_, doublecomplex *y, integer *incy_) {
  387. integer n = *n_, incx = *incx_, incy = *incy_, i;
  388. #ifdef _MSC_VER
  389. _Dcomplex zdotc = {0.0, 0.0};
  390. if (incx == 1 && incy == 1) {
  391. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  392. zdotc._Val[0] += conj(Cd(&x[i]))._Val[0] * Cd(&y[i])._Val[0];
  393. zdotc._Val[1] += conj(Cd(&x[i]))._Val[1] * Cd(&y[i])._Val[1];
  394. }
  395. } else {
  396. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  397. zdotc._Val[0] += conj(Cd(&x[i*incx]))._Val[0] * Cd(&y[i*incy])._Val[0];
  398. zdotc._Val[1] += conj(Cd(&x[i*incx]))._Val[1] * Cd(&y[i*incy])._Val[1];
  399. }
  400. }
  401. pCd(z) = zdotc;
  402. }
  403. #else
  404. _Complex double zdotc = 0.0;
  405. if (incx == 1 && incy == 1) {
  406. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  407. zdotc += conj(Cd(&x[i])) * Cd(&y[i]);
  408. }
  409. } else {
  410. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  411. zdotc += conj(Cd(&x[i*incx])) * Cd(&y[i*incy]);
  412. }
  413. }
  414. pCd(z) = zdotc;
  415. }
  416. #endif
  417. static inline void cdotu_(complex *z, integer *n_, complex *x, integer *incx_, complex *y, integer *incy_) {
  418. integer n = *n_, incx = *incx_, incy = *incy_, i;
  419. #ifdef _MSC_VER
  420. _Fcomplex zdotc = {0.0, 0.0};
  421. if (incx == 1 && incy == 1) {
  422. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  423. zdotc._Val[0] += Cf(&x[i])._Val[0] * Cf(&y[i])._Val[0];
  424. zdotc._Val[1] += Cf(&x[i])._Val[1] * Cf(&y[i])._Val[1];
  425. }
  426. } else {
  427. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  428. zdotc._Val[0] += Cf(&x[i*incx])._Val[0] * Cf(&y[i*incy])._Val[0];
  429. zdotc._Val[1] += Cf(&x[i*incx])._Val[1] * Cf(&y[i*incy])._Val[1];
  430. }
  431. }
  432. pCf(z) = zdotc;
  433. }
  434. #else
  435. _Complex float zdotc = 0.0;
  436. if (incx == 1 && incy == 1) {
  437. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  438. zdotc += Cf(&x[i]) * Cf(&y[i]);
  439. }
  440. } else {
  441. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  442. zdotc += Cf(&x[i*incx]) * Cf(&y[i*incy]);
  443. }
  444. }
  445. pCf(z) = zdotc;
  446. }
  447. #endif
  448. static inline void zdotu_(doublecomplex *z, integer *n_, doublecomplex *x, integer *incx_, doublecomplex *y, integer *incy_) {
  449. integer n = *n_, incx = *incx_, incy = *incy_, i;
  450. #ifdef _MSC_VER
  451. _Dcomplex zdotc = {0.0, 0.0};
  452. if (incx == 1 && incy == 1) {
  453. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  454. zdotc._Val[0] += Cd(&x[i])._Val[0] * Cd(&y[i])._Val[0];
  455. zdotc._Val[1] += Cd(&x[i])._Val[1] * Cd(&y[i])._Val[1];
  456. }
  457. } else {
  458. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  459. zdotc._Val[0] += Cd(&x[i*incx])._Val[0] * Cd(&y[i*incy])._Val[0];
  460. zdotc._Val[1] += Cd(&x[i*incx])._Val[1] * Cd(&y[i*incy])._Val[1];
  461. }
  462. }
  463. pCd(z) = zdotc;
  464. }
  465. #else
  466. _Complex double zdotc = 0.0;
  467. if (incx == 1 && incy == 1) {
  468. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  469. zdotc += Cd(&x[i]) * Cd(&y[i]);
  470. }
  471. } else {
  472. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  473. zdotc += Cd(&x[i*incx]) * Cd(&y[i*incy]);
  474. }
  475. }
  476. pCd(z) = zdotc;
  477. }
  478. #endif
  479. /* -- translated by f2c (version 20000121).
  480. You must link the resulting object file with the libraries:
  481. -lf2c -lm (in that order)
  482. */
  483. /* Table of constant values */
  484. static doublereal c_b10 = 1.;
  485. static doublereal c_b14 = -.125;
  486. static integer c__1 = 1;
  487. static doublereal c_b19 = 0.;
  488. static integer c__2 = 2;
  489. /* > \brief \b DBDSVDX */
  490. /* =========== DOCUMENTATION =========== */
  491. /* Online html documentation available at */
  492. /* http://www.netlib.org/lapack/explore-html/ */
  493. /* > \htmlonly */
  494. /* > Download DBDSVDX + dependencies */
  495. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/dbdsvdx
  496. .f"> */
  497. /* > [TGZ]</a> */
  498. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/dbdsvdx
  499. .f"> */
  500. /* > [ZIP]</a> */
  501. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/dbdsvdx
  502. .f"> */
  503. /* > [TXT]</a> */
  504. /* > \endhtmlonly */
  505. /* Definition: */
  506. /* =========== */
  507. /* SUBROUTINE DBDSVDX( UPLO, JOBZ, RANGE, N, D, E, VL, VU, IL, IU, */
  508. /* $ NS, S, Z, LDZ, WORK, IWORK, INFO ) */
  509. /* CHARACTER JOBZ, RANGE, UPLO */
  510. /* INTEGER IL, INFO, IU, LDZ, N, NS */
  511. /* DOUBLE PRECISION VL, VU */
  512. /* INTEGER IWORK( * ) */
  513. /* DOUBLE PRECISION D( * ), E( * ), S( * ), WORK( * ), */
  514. /* Z( LDZ, * ) */
  515. /* > \par Purpose: */
  516. /* ============= */
  517. /* > */
  518. /* > \verbatim */
  519. /* > */
  520. /* > DBDSVDX computes the singular value decomposition (SVD) of a real */
  521. /* > N-by-N (upper or lower) bidiagonal matrix B, B = U * S * VT, */
  522. /* > where S is a diagonal matrix with non-negative diagonal elements */
  523. /* > (the singular values of B), and U and VT are orthogonal matrices */
  524. /* > of left and right singular vectors, respectively. */
  525. /* > */
  526. /* > Given an upper bidiagonal B with diagonal D = [ d_1 d_2 ... d_N ] */
  527. /* > and superdiagonal E = [ e_1 e_2 ... e_N-1 ], DBDSVDX computes the */
  528. /* > singular value decompositon of B through the eigenvalues and */
  529. /* > eigenvectors of the N*2-by-N*2 tridiagonal matrix */
  530. /* > */
  531. /* > | 0 d_1 | */
  532. /* > | d_1 0 e_1 | */
  533. /* > TGK = | e_1 0 d_2 | */
  534. /* > | d_2 . . | */
  535. /* > | . . . | */
  536. /* > */
  537. /* > If (s,u,v) is a singular triplet of B with ||u|| = ||v|| = 1, then */
  538. /* > (+/-s,q), ||q|| = 1, are eigenpairs of TGK, with q = P * ( u' +/-v' ) / */
  539. /* > sqrt(2) = ( v_1 u_1 v_2 u_2 ... v_n u_n ) / sqrt(2), and */
  540. /* > P = [ e_{n+1} e_{1} e_{n+2} e_{2} ... ]. */
  541. /* > */
  542. /* > Given a TGK matrix, one can either a) compute -s,-v and change signs */
  543. /* > so that the singular values (and corresponding vectors) are already in */
  544. /* > descending order (as in DGESVD/DGESDD) or b) compute s,v and reorder */
  545. /* > the values (and corresponding vectors). DBDSVDX implements a) by */
  546. /* > calling DSTEVX (bisection plus inverse iteration, to be replaced */
  547. /* > with a version of the Multiple Relative Robust Representation */
  548. /* > algorithm. (See P. Willems and B. Lang, A framework for the MR^3 */
  549. /* > algorithm: theory and implementation, SIAM J. Sci. Comput., */
  550. /* > 35:740-766, 2013.) */
  551. /* > \endverbatim */
  552. /* Arguments: */
  553. /* ========== */
  554. /* > \param[in] UPLO */
  555. /* > \verbatim */
  556. /* > UPLO is CHARACTER*1 */
  557. /* > = 'U': B is upper bidiagonal; */
  558. /* > = 'L': B is lower bidiagonal. */
  559. /* > \endverbatim */
  560. /* > */
  561. /* > \param[in] JOBZ */
  562. /* > \verbatim */
  563. /* > JOBZ is CHARACTER*1 */
  564. /* > = 'N': Compute singular values only; */
  565. /* > = 'V': Compute singular values and singular vectors. */
  566. /* > \endverbatim */
  567. /* > */
  568. /* > \param[in] RANGE */
  569. /* > \verbatim */
  570. /* > RANGE is CHARACTER*1 */
  571. /* > = 'A': all singular values will be found. */
  572. /* > = 'V': all singular values in the half-open interval [VL,VU) */
  573. /* > will be found. */
  574. /* > = 'I': the IL-th through IU-th singular values will be found. */
  575. /* > \endverbatim */
  576. /* > */
  577. /* > \param[in] N */
  578. /* > \verbatim */
  579. /* > N is INTEGER */
  580. /* > The order of the bidiagonal matrix. N >= 0. */
  581. /* > \endverbatim */
  582. /* > */
  583. /* > \param[in] D */
  584. /* > \verbatim */
  585. /* > D is DOUBLE PRECISION array, dimension (N) */
  586. /* > The n diagonal elements of the bidiagonal matrix B. */
  587. /* > \endverbatim */
  588. /* > */
  589. /* > \param[in] E */
  590. /* > \verbatim */
  591. /* > E is DOUBLE PRECISION array, dimension (f2cmax(1,N-1)) */
  592. /* > The (n-1) superdiagonal elements of the bidiagonal matrix */
  593. /* > B in elements 1 to N-1. */
  594. /* > \endverbatim */
  595. /* > */
  596. /* > \param[in] VL */
  597. /* > \verbatim */
  598. /* > VL is DOUBLE PRECISION */
  599. /* > If RANGE='V', the lower bound of the interval to */
  600. /* > be searched for singular values. VU > VL. */
  601. /* > Not referenced if RANGE = 'A' or 'I'. */
  602. /* > \endverbatim */
  603. /* > */
  604. /* > \param[in] VU */
  605. /* > \verbatim */
  606. /* > VU is DOUBLE PRECISION */
  607. /* > If RANGE='V', the upper bound of the interval to */
  608. /* > be searched for singular values. VU > VL. */
  609. /* > Not referenced if RANGE = 'A' or 'I'. */
  610. /* > \endverbatim */
  611. /* > */
  612. /* > \param[in] IL */
  613. /* > \verbatim */
  614. /* > IL is INTEGER */
  615. /* > If RANGE='I', the index of the */
  616. /* > smallest singular value to be returned. */
  617. /* > 1 <= IL <= IU <= f2cmin(M,N), if f2cmin(M,N) > 0. */
  618. /* > Not referenced if RANGE = 'A' or 'V'. */
  619. /* > \endverbatim */
  620. /* > */
  621. /* > \param[in] IU */
  622. /* > \verbatim */
  623. /* > IU is INTEGER */
  624. /* > If RANGE='I', the index of the */
  625. /* > largest singular value to be returned. */
  626. /* > 1 <= IL <= IU <= f2cmin(M,N), if f2cmin(M,N) > 0. */
  627. /* > Not referenced if RANGE = 'A' or 'V'. */
  628. /* > \endverbatim */
  629. /* > */
  630. /* > \param[out] NS */
  631. /* > \verbatim */
  632. /* > NS is INTEGER */
  633. /* > The total number of singular values found. 0 <= NS <= N. */
  634. /* > If RANGE = 'A', NS = N, and if RANGE = 'I', NS = IU-IL+1. */
  635. /* > \endverbatim */
  636. /* > */
  637. /* > \param[out] S */
  638. /* > \verbatim */
  639. /* > S is DOUBLE PRECISION array, dimension (N) */
  640. /* > The first NS elements contain the selected singular values in */
  641. /* > ascending order. */
  642. /* > \endverbatim */
  643. /* > */
  644. /* > \param[out] Z */
  645. /* > \verbatim */
  646. /* > Z is DOUBLE PRECISION array, dimension (2*N,K) */
  647. /* > If JOBZ = 'V', then if INFO = 0 the first NS columns of Z */
  648. /* > contain the singular vectors of the matrix B corresponding to */
  649. /* > the selected singular values, with U in rows 1 to N and V */
  650. /* > in rows N+1 to N*2, i.e. */
  651. /* > Z = [ U ] */
  652. /* > [ V ] */
  653. /* > If JOBZ = 'N', then Z is not referenced. */
  654. /* > Note: The user must ensure that at least K = NS+1 columns are */
  655. /* > supplied in the array Z; if RANGE = 'V', the exact value of */
  656. /* > NS is not known in advance and an upper bound must be used. */
  657. /* > \endverbatim */
  658. /* > */
  659. /* > \param[in] LDZ */
  660. /* > \verbatim */
  661. /* > LDZ is INTEGER */
  662. /* > The leading dimension of the array Z. LDZ >= 1, and if */
  663. /* > JOBZ = 'V', LDZ >= f2cmax(2,N*2). */
  664. /* > \endverbatim */
  665. /* > */
  666. /* > \param[out] WORK */
  667. /* > \verbatim */
  668. /* > WORK is DOUBLE PRECISION array, dimension (14*N) */
  669. /* > \endverbatim */
  670. /* > */
  671. /* > \param[out] IWORK */
  672. /* > \verbatim */
  673. /* > IWORK is INTEGER array, dimension (12*N) */
  674. /* > If JOBZ = 'V', then if INFO = 0, the first NS elements of */
  675. /* > IWORK are zero. If INFO > 0, then IWORK contains the indices */
  676. /* > of the eigenvectors that failed to converge in DSTEVX. */
  677. /* > \endverbatim */
  678. /* > */
  679. /* > \param[out] INFO */
  680. /* > \verbatim */
  681. /* > INFO is INTEGER */
  682. /* > = 0: successful exit */
  683. /* > < 0: if INFO = -i, the i-th argument had an illegal value */
  684. /* > > 0: if INFO = i, then i eigenvectors failed to converge */
  685. /* > in DSTEVX. The indices of the eigenvectors */
  686. /* > (as returned by DSTEVX) are stored in the */
  687. /* > array IWORK. */
  688. /* > if INFO = N*2 + 1, an internal error occurred. */
  689. /* > \endverbatim */
  690. /* Authors: */
  691. /* ======== */
  692. /* > \author Univ. of Tennessee */
  693. /* > \author Univ. of California Berkeley */
  694. /* > \author Univ. of Colorado Denver */
  695. /* > \author NAG Ltd. */
  696. /* > \date June 2016 */
  697. /* > \ingroup doubleOTHEReigen */
  698. /* ===================================================================== */
  699. /* Subroutine */ void dbdsvdx_(char *uplo, char *jobz, char *range, integer *n,
  700. doublereal *d__, doublereal *e, doublereal *vl, doublereal *vu,
  701. integer *il, integer *iu, integer *ns, doublereal *s, doublereal *z__,
  702. integer *ldz, doublereal *work, integer *iwork, integer *info)
  703. {
  704. /* System generated locals */
  705. integer z_dim1, z_offset, i__1, i__2, i__3, i__4, i__5;
  706. doublereal d__1, d__2, d__3, d__4;
  707. /* Local variables */
  708. doublereal emin;
  709. extern doublereal ddot_(integer *, doublereal *, integer *, doublereal *,
  710. integer *);
  711. integer ntgk;
  712. doublereal smin, smax, nrmu, nrmv;
  713. extern doublereal dnrm2_(integer *, doublereal *, integer *);
  714. logical sveq0;
  715. integer i__, idbeg, j, k;
  716. doublereal sqrt2;
  717. integer idend;
  718. extern /* Subroutine */ void dscal_(integer *, doublereal *, doublereal *,
  719. integer *);
  720. integer isbeg;
  721. extern logical lsame_(char *, char *);
  722. integer idtgk, ietgk, iltgk, itemp;
  723. extern /* Subroutine */ void dcopy_(integer *, doublereal *, integer *,
  724. doublereal *, integer *);
  725. integer icolz;
  726. logical allsv;
  727. integer idptr;
  728. logical indsv;
  729. integer ieptr, iutgk;
  730. extern /* Subroutine */ void daxpy_(integer *, doublereal *, doublereal *,
  731. integer *, doublereal *, integer *);
  732. doublereal vltgk;
  733. logical lower;
  734. extern /* Subroutine */ void dswap_(integer *, doublereal *, integer *,
  735. doublereal *, integer *);
  736. doublereal zjtji;
  737. logical split, valsv;
  738. integer isplt;
  739. doublereal ortol, vutgk;
  740. logical wantz;
  741. char rngvx[1];
  742. integer irowu, irowv, irowz;
  743. extern doublereal dlamch_(char *);
  744. integer iifail;
  745. doublereal mu;
  746. extern integer idamax_(integer *, doublereal *, integer *);
  747. extern /* Subroutine */ void dlaset_(char *, integer *, integer *,
  748. doublereal *, doublereal *, doublereal *, integer *);
  749. extern int xerbla_(char *, integer *, ftnlen);
  750. doublereal abstol, thresh;
  751. integer iiwork;
  752. extern /* Subroutine */ void dstevx_(char *, char *, integer *, doublereal
  753. *, doublereal *, doublereal *, doublereal *, integer *, integer *,
  754. doublereal *, integer *, doublereal *, doublereal *, integer *,
  755. doublereal *, integer *, integer *, integer *),
  756. mecago_();
  757. doublereal eps;
  758. integer nsl;
  759. doublereal tol, ulp;
  760. integer nru, nrv;
  761. /* -- LAPACK driver routine (version 3.8.0) -- */
  762. /* -- LAPACK is a software package provided by Univ. of Tennessee, -- */
  763. /* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- */
  764. /* November 2017 */
  765. /* ===================================================================== */
  766. /* Test the input parameters. */
  767. /* Parameter adjustments */
  768. --d__;
  769. --e;
  770. --s;
  771. z_dim1 = *ldz;
  772. z_offset = 1 + z_dim1 * 1;
  773. z__ -= z_offset;
  774. --work;
  775. --iwork;
  776. /* Function Body */
  777. allsv = lsame_(range, "A");
  778. valsv = lsame_(range, "V");
  779. indsv = lsame_(range, "I");
  780. wantz = lsame_(jobz, "V");
  781. lower = lsame_(uplo, "L");
  782. *info = 0;
  783. if (! lsame_(uplo, "U") && ! lower) {
  784. *info = -1;
  785. } else if (! (wantz || lsame_(jobz, "N"))) {
  786. *info = -2;
  787. } else if (! (allsv || valsv || indsv)) {
  788. *info = -3;
  789. } else if (*n < 0) {
  790. *info = -4;
  791. } else if (*n > 0) {
  792. if (valsv) {
  793. if (*vl < 0.) {
  794. *info = -7;
  795. } else if (*vu <= *vl) {
  796. *info = -8;
  797. }
  798. } else if (indsv) {
  799. if (*il < 1 || *il > f2cmax(1,*n)) {
  800. *info = -9;
  801. } else if (*iu < f2cmin(*n,*il) || *iu > *n) {
  802. *info = -10;
  803. }
  804. }
  805. }
  806. if (*info == 0) {
  807. if (*ldz < 1 || wantz && *ldz < *n << 1) {
  808. *info = -14;
  809. }
  810. }
  811. if (*info != 0) {
  812. i__1 = -(*info);
  813. xerbla_("DBDSVDX", &i__1, (ftnlen)7);
  814. return;
  815. }
  816. /* Quick return if possible (N.LE.1) */
  817. *ns = 0;
  818. if (*n == 0) {
  819. return;
  820. }
  821. if (*n == 1) {
  822. if (allsv || indsv) {
  823. *ns = 1;
  824. s[1] = abs(d__[1]);
  825. } else {
  826. if (*vl < abs(d__[1]) && *vu >= abs(d__[1])) {
  827. *ns = 1;
  828. s[1] = abs(d__[1]);
  829. }
  830. }
  831. if (wantz) {
  832. z__[z_dim1 + 1] = d_sign(&c_b10, &d__[1]);
  833. z__[z_dim1 + 2] = 1.;
  834. }
  835. return;
  836. }
  837. abstol = dlamch_("Safe Minimum") * 2;
  838. ulp = dlamch_("Precision");
  839. eps = dlamch_("Epsilon");
  840. sqrt2 = sqrt(2.);
  841. ortol = sqrt(ulp);
  842. /* Criterion for splitting is taken from DBDSQR when singular */
  843. /* values are computed to relative accuracy TOL. (See J. Demmel and */
  844. /* W. Kahan, Accurate singular values of bidiagonal matrices, SIAM */
  845. /* J. Sci. and Stat. Comput., 11:873–912, 1990.) */
  846. /* Computing MAX */
  847. /* Computing MIN */
  848. d__3 = 100., d__4 = pow_dd(&eps, &c_b14);
  849. d__1 = 10., d__2 = f2cmin(d__3,d__4);
  850. tol = f2cmax(d__1,d__2) * eps;
  851. /* Compute approximate maximum, minimum singular values. */
  852. i__ = idamax_(n, &d__[1], &c__1);
  853. smax = (d__1 = d__[i__], abs(d__1));
  854. i__1 = *n - 1;
  855. i__ = idamax_(&i__1, &e[1], &c__1);
  856. /* Computing MAX */
  857. d__2 = smax, d__3 = (d__1 = e[i__], abs(d__1));
  858. smax = f2cmax(d__2,d__3);
  859. /* Compute threshold for neglecting D's and E's. */
  860. smin = abs(d__[1]);
  861. if (smin != 0.) {
  862. mu = smin;
  863. i__1 = *n;
  864. for (i__ = 2; i__ <= i__1; ++i__) {
  865. mu = (d__2 = d__[i__], abs(d__2)) * (mu / (mu + (d__1 = e[i__ - 1]
  866. , abs(d__1))));
  867. smin = f2cmin(smin,mu);
  868. if (smin == 0.) {
  869. myexit_();
  870. }
  871. }
  872. }
  873. smin /= sqrt((doublereal) (*n));
  874. thresh = tol * smin;
  875. /* Check for zeros in D and E (splits), i.e. submatrices. */
  876. i__1 = *n - 1;
  877. for (i__ = 1; i__ <= i__1; ++i__) {
  878. if ((d__1 = d__[i__], abs(d__1)) <= thresh) {
  879. d__[i__] = 0.;
  880. }
  881. if ((d__1 = e[i__], abs(d__1)) <= thresh) {
  882. e[i__] = 0.;
  883. }
  884. }
  885. if ((d__1 = d__[*n], abs(d__1)) <= thresh) {
  886. d__[*n] = 0.;
  887. }
  888. /* Pointers for arrays used by DSTEVX. */
  889. idtgk = 1;
  890. ietgk = idtgk + (*n << 1);
  891. itemp = ietgk + (*n << 1);
  892. iifail = 1;
  893. iiwork = iifail + (*n << 1);
  894. /* Set RNGVX, which corresponds to RANGE for DSTEVX in TGK mode. */
  895. /* VL,VU or IL,IU are redefined to conform to implementation a) */
  896. /* described in the leading comments. */
  897. iltgk = 0;
  898. iutgk = 0;
  899. vltgk = 0.;
  900. vutgk = 0.;
  901. if (allsv) {
  902. /* All singular values will be found. We aim at -s (see */
  903. /* leading comments) with RNGVX = 'I'. IL and IU are set */
  904. /* later (as ILTGK and IUTGK) according to the dimension */
  905. /* of the active submatrix. */
  906. *(unsigned char *)rngvx = 'I';
  907. if (wantz) {
  908. i__1 = *n << 1;
  909. i__2 = *n + 1;
  910. dlaset_("F", &i__1, &i__2, &c_b19, &c_b19, &z__[z_offset], ldz);
  911. }
  912. } else if (valsv) {
  913. /* Find singular values in a half-open interval. We aim */
  914. /* at -s (see leading comments) and we swap VL and VU */
  915. /* (as VUTGK and VLTGK), changing their signs. */
  916. *(unsigned char *)rngvx = 'V';
  917. vltgk = -(*vu);
  918. vutgk = -(*vl);
  919. i__1 = idtgk + (*n << 1) - 1;
  920. for (i__ = idtgk; i__ <= i__1; ++i__) {
  921. work[i__] = 0.;
  922. }
  923. /* WORK( IDTGK:IDTGK+2*N-1 ) = ZERO */
  924. dcopy_(n, &d__[1], &c__1, &work[ietgk], &c__2);
  925. i__1 = *n - 1;
  926. dcopy_(&i__1, &e[1], &c__1, &work[ietgk + 1], &c__2);
  927. i__1 = *n << 1;
  928. dstevx_("N", "V", &i__1, &work[idtgk], &work[ietgk], &vltgk, &vutgk, &
  929. iltgk, &iltgk, &abstol, ns, &s[1], &z__[z_offset], ldz, &work[
  930. itemp], &iwork[iiwork], &iwork[iifail], info);
  931. if (*ns == 0) {
  932. return;
  933. } else {
  934. if (wantz) {
  935. i__1 = *n << 1;
  936. dlaset_("F", &i__1, ns, &c_b19, &c_b19, &z__[z_offset], ldz);
  937. }
  938. }
  939. } else if (indsv) {
  940. /* Find the IL-th through the IU-th singular values. We aim */
  941. /* at -s (see leading comments) and indices are mapped into */
  942. /* values, therefore mimicking DSTEBZ, where */
  943. /* GL = GL - FUDGE*TNORM*ULP*N - FUDGE*TWO*PIVMIN */
  944. /* GU = GU + FUDGE*TNORM*ULP*N + FUDGE*PIVMIN */
  945. iltgk = *il;
  946. iutgk = *iu;
  947. *(unsigned char *)rngvx = 'V';
  948. i__1 = idtgk + (*n << 1) - 1;
  949. for (i__ = idtgk; i__ <= i__1; ++i__) {
  950. work[i__] = 0.;
  951. }
  952. /* WORK( IDTGK:IDTGK+2*N-1 ) = ZERO */
  953. dcopy_(n, &d__[1], &c__1, &work[ietgk], &c__2);
  954. i__1 = *n - 1;
  955. dcopy_(&i__1, &e[1], &c__1, &work[ietgk + 1], &c__2);
  956. i__1 = *n << 1;
  957. dstevx_("N", "I", &i__1, &work[idtgk], &work[ietgk], &vltgk, &vltgk, &
  958. iltgk, &iltgk, &abstol, ns, &s[1], &z__[z_offset], ldz, &work[
  959. itemp], &iwork[iiwork], &iwork[iifail], info);
  960. vltgk = s[1] - smax * 2. * ulp * *n;
  961. i__1 = idtgk + (*n << 1) - 1;
  962. for (i__ = idtgk; i__ <= i__1; ++i__) {
  963. work[i__] = 0.;
  964. }
  965. /* WORK( IDTGK:IDTGK+2*N-1 ) = ZERO */
  966. dcopy_(n, &d__[1], &c__1, &work[ietgk], &c__2);
  967. i__1 = *n - 1;
  968. dcopy_(&i__1, &e[1], &c__1, &work[ietgk + 1], &c__2);
  969. i__1 = *n << 1;
  970. dstevx_("N", "I", &i__1, &work[idtgk], &work[ietgk], &vutgk, &vutgk, &
  971. iutgk, &iutgk, &abstol, ns, &s[1], &z__[z_offset], ldz, &work[
  972. itemp], &iwork[iiwork], &iwork[iifail], info);
  973. vutgk = s[1] + smax * 2. * ulp * *n;
  974. vutgk = f2cmin(vutgk,0.);
  975. /* If VLTGK=VUTGK, DSTEVX returns an error message, */
  976. /* so if needed we change VUTGK slightly. */
  977. if (vltgk == vutgk) {
  978. vltgk -= tol;
  979. }
  980. if (wantz) {
  981. i__1 = *n << 1;
  982. i__2 = *iu - *il + 1;
  983. dlaset_("F", &i__1, &i__2, &c_b19, &c_b19, &z__[z_offset], ldz);
  984. }
  985. }
  986. /* Initialize variables and pointers for S, Z, and WORK. */
  987. /* NRU, NRV: number of rows in U and V for the active submatrix */
  988. /* IDBEG, ISBEG: offsets for the entries of D and S */
  989. /* IROWZ, ICOLZ: offsets for the rows and columns of Z */
  990. /* IROWU, IROWV: offsets for the rows of U and V */
  991. *ns = 0;
  992. nru = 0;
  993. nrv = 0;
  994. idbeg = 1;
  995. isbeg = 1;
  996. irowz = 1;
  997. icolz = 1;
  998. irowu = 2;
  999. irowv = 1;
  1000. split = FALSE_;
  1001. sveq0 = FALSE_;
  1002. /* Form the tridiagonal TGK matrix. */
  1003. i__1 = *n;
  1004. for (i__ = 1; i__ <= i__1; ++i__) {
  1005. s[i__] = 0.;
  1006. }
  1007. /* S( 1:N ) = ZERO */
  1008. work[ietgk + (*n << 1) - 1] = 0.;
  1009. i__1 = idtgk + (*n << 1) - 1;
  1010. for (i__ = idtgk; i__ <= i__1; ++i__) {
  1011. work[i__] = 0.;
  1012. }
  1013. /* WORK( IDTGK:IDTGK+2*N-1 ) = ZERO */
  1014. dcopy_(n, &d__[1], &c__1, &work[ietgk], &c__2);
  1015. i__1 = *n - 1;
  1016. dcopy_(&i__1, &e[1], &c__1, &work[ietgk + 1], &c__2);
  1017. /* Check for splits in two levels, outer level */
  1018. /* in E and inner level in D. */
  1019. i__1 = *n << 1;
  1020. for (ieptr = 2; ieptr <= i__1; ieptr += 2) {
  1021. if (work[ietgk + ieptr - 1] == 0.) {
  1022. /* Split in E (this piece of B is square) or bottom */
  1023. /* of the (input bidiagonal) matrix. */
  1024. isplt = idbeg;
  1025. idend = ieptr - 1;
  1026. i__2 = idend;
  1027. for (idptr = idbeg; idptr <= i__2; idptr += 2) {
  1028. if (work[ietgk + idptr - 1] == 0.) {
  1029. /* Split in D (rectangular submatrix). Set the number */
  1030. /* of rows in U and V (NRU and NRV) accordingly. */
  1031. if (idptr == idbeg) {
  1032. /* D=0 at the top. */
  1033. sveq0 = TRUE_;
  1034. if (idbeg == idend) {
  1035. nru = 1;
  1036. nrv = 1;
  1037. }
  1038. } else if (idptr == idend) {
  1039. /* D=0 at the bottom. */
  1040. sveq0 = TRUE_;
  1041. nru = (idend - isplt) / 2 + 1;
  1042. nrv = nru;
  1043. if (isplt != idbeg) {
  1044. ++nru;
  1045. }
  1046. } else {
  1047. if (isplt == idbeg) {
  1048. /* Split: top rectangular submatrix. */
  1049. nru = (idptr - idbeg) / 2;
  1050. nrv = nru + 1;
  1051. } else {
  1052. /* Split: middle square submatrix. */
  1053. nru = (idptr - isplt) / 2 + 1;
  1054. nrv = nru;
  1055. }
  1056. }
  1057. } else if (idptr == idend) {
  1058. /* Last entry of D in the active submatrix. */
  1059. if (isplt == idbeg) {
  1060. /* No split (trivial case). */
  1061. nru = (idend - idbeg) / 2 + 1;
  1062. nrv = nru;
  1063. } else {
  1064. /* Split: bottom rectangular submatrix. */
  1065. nrv = (idend - isplt) / 2 + 1;
  1066. nru = nrv + 1;
  1067. }
  1068. }
  1069. ntgk = nru + nrv;
  1070. if (ntgk > 0) {
  1071. /* Compute eigenvalues/vectors of the active */
  1072. /* submatrix according to RANGE: */
  1073. /* if RANGE='A' (ALLSV) then RNGVX = 'I' */
  1074. /* if RANGE='V' (VALSV) then RNGVX = 'V' */
  1075. /* if RANGE='I' (INDSV) then RNGVX = 'V' */
  1076. iltgk = 1;
  1077. iutgk = ntgk / 2;
  1078. if (allsv || vutgk == 0.) {
  1079. if (sveq0 || smin < eps || ntgk % 2 > 0) {
  1080. /* Special case: eigenvalue equal to zero or very */
  1081. /* small, additional eigenvector is needed. */
  1082. ++iutgk;
  1083. }
  1084. }
  1085. /* Workspace needed by DSTEVX: */
  1086. /* WORK( ITEMP: ): 2*5*NTGK */
  1087. /* IWORK( 1: ): 2*6*NTGK */
  1088. dstevx_(jobz, rngvx, &ntgk, &work[idtgk + isplt - 1], &
  1089. work[ietgk + isplt - 1], &vltgk, &vutgk, &iltgk, &
  1090. iutgk, &abstol, &nsl, &s[isbeg], &z__[irowz +
  1091. icolz * z_dim1], ldz, &work[itemp], &iwork[iiwork]
  1092. , &iwork[iifail], info);
  1093. if (*info != 0) {
  1094. /* Exit with the error code from DSTEVX. */
  1095. return;
  1096. }
  1097. emin = (d__1 = s[isbeg], abs(d__1));
  1098. i__3 = isbeg + nsl - 1;
  1099. for (i__ = isbeg; i__ <= i__3; ++i__) {
  1100. if ((d__1 = s[i__], abs(d__1)) > emin) {
  1101. emin = s[i__];
  1102. }
  1103. }
  1104. /* EMIN = ABS( MAXVAL( S( ISBEG:ISBEG+NSL-1 ) ) ) */
  1105. if (nsl > 0 && wantz) {
  1106. /* Normalize u=Z([2,4,...],:) and v=Z([1,3,...],:), */
  1107. /* changing the sign of v as discussed in the leading */
  1108. /* comments. The norms of u and v may be (slightly) */
  1109. /* different from 1/sqrt(2) if the corresponding */
  1110. /* eigenvalues are very small or too close. We check */
  1111. /* those norms and, if needed, reorthogonalize the */
  1112. /* vectors. */
  1113. if (nsl > 1 && vutgk == 0. && ntgk % 2 == 0 && emin ==
  1114. 0. && ! split) {
  1115. /* D=0 at the top or bottom of the active submatrix: */
  1116. /* one eigenvalue is equal to zero; concatenate the */
  1117. /* eigenvectors corresponding to the two smallest */
  1118. /* eigenvalues. */
  1119. i__3 = irowz + ntgk - 1;
  1120. for (i__ = irowz; i__ <= i__3; ++i__) {
  1121. z__[i__ + (icolz + nsl - 2) * z_dim1] += z__[
  1122. i__ + (icolz + nsl - 1) * z_dim1];
  1123. z__[i__ + (icolz + nsl - 1) * z_dim1] = 0.;
  1124. }
  1125. /* Z( IROWZ:IROWZ+NTGK-1,ICOLZ+NSL-2 ) = */
  1126. /* $ Z( IROWZ:IROWZ+NTGK-1,ICOLZ+NSL-2 ) + */
  1127. /* $ Z( IROWZ:IROWZ+NTGK-1,ICOLZ+NSL-1 ) */
  1128. /* Z( IROWZ:IROWZ+NTGK-1,ICOLZ+NSL-1 ) = */
  1129. /* $ ZERO */
  1130. /* IF( IUTGK*2.GT.NTGK ) THEN */
  1131. /* Eigenvalue equal to zero or very small. */
  1132. /* NSL = NSL - 1 */
  1133. /* END IF */
  1134. }
  1135. /* Computing MIN */
  1136. i__4 = nsl - 1, i__5 = nru - 1;
  1137. i__3 = f2cmin(i__4,i__5);
  1138. for (i__ = 0; i__ <= i__3; ++i__) {
  1139. nrmu = dnrm2_(&nru, &z__[irowu + (icolz + i__) *
  1140. z_dim1], &c__2);
  1141. if (nrmu == 0.) {
  1142. *info = (*n << 1) + 1;
  1143. return;
  1144. }
  1145. d__1 = 1. / nrmu;
  1146. dscal_(&nru, &d__1, &z__[irowu + (icolz + i__) *
  1147. z_dim1], &c__2);
  1148. if (nrmu != 1. && (d__1 = nrmu - ortol, abs(d__1))
  1149. * sqrt2 > 1.) {
  1150. i__4 = i__ - 1;
  1151. for (j = 0; j <= i__4; ++j) {
  1152. zjtji = -ddot_(&nru, &z__[irowu + (icolz
  1153. + j) * z_dim1], &c__2, &z__[irowu
  1154. + (icolz + i__) * z_dim1], &c__2);
  1155. daxpy_(&nru, &zjtji, &z__[irowu + (icolz
  1156. + j) * z_dim1], &c__2, &z__[irowu
  1157. + (icolz + i__) * z_dim1], &c__2);
  1158. }
  1159. nrmu = dnrm2_(&nru, &z__[irowu + (icolz + i__)
  1160. * z_dim1], &c__2);
  1161. d__1 = 1. / nrmu;
  1162. dscal_(&nru, &d__1, &z__[irowu + (icolz + i__)
  1163. * z_dim1], &c__2);
  1164. }
  1165. }
  1166. /* Computing MIN */
  1167. i__4 = nsl - 1, i__5 = nrv - 1;
  1168. i__3 = f2cmin(i__4,i__5);
  1169. for (i__ = 0; i__ <= i__3; ++i__) {
  1170. nrmv = dnrm2_(&nrv, &z__[irowv + (icolz + i__) *
  1171. z_dim1], &c__2);
  1172. if (nrmv == 0.) {
  1173. *info = (*n << 1) + 1;
  1174. return;
  1175. }
  1176. d__1 = -1. / nrmv;
  1177. dscal_(&nrv, &d__1, &z__[irowv + (icolz + i__) *
  1178. z_dim1], &c__2);
  1179. if (nrmv != 1. && (d__1 = nrmv - ortol, abs(d__1))
  1180. * sqrt2 > 1.) {
  1181. i__4 = i__ - 1;
  1182. for (j = 0; j <= i__4; ++j) {
  1183. zjtji = -ddot_(&nrv, &z__[irowv + (icolz
  1184. + j) * z_dim1], &c__2, &z__[irowv
  1185. + (icolz + i__) * z_dim1], &c__2);
  1186. daxpy_(&nru, &zjtji, &z__[irowv + (icolz
  1187. + j) * z_dim1], &c__2, &z__[irowv
  1188. + (icolz + i__) * z_dim1], &c__2);
  1189. }
  1190. nrmv = dnrm2_(&nrv, &z__[irowv + (icolz + i__)
  1191. * z_dim1], &c__2);
  1192. d__1 = 1. / nrmv;
  1193. dscal_(&nrv, &d__1, &z__[irowv + (icolz + i__)
  1194. * z_dim1], &c__2);
  1195. }
  1196. }
  1197. if (vutgk == 0. && idptr < idend && ntgk % 2 > 0) {
  1198. /* D=0 in the middle of the active submatrix (one */
  1199. /* eigenvalue is equal to zero): save the corresponding */
  1200. /* eigenvector for later use (when bottom of the */
  1201. /* active submatrix is reached). */
  1202. split = TRUE_;
  1203. i__3 = irowz + ntgk - 1;
  1204. for (i__ = irowz; i__ <= i__3; ++i__) {
  1205. z__[i__ + (*n + 1) * z_dim1] = z__[i__ + (*ns
  1206. + nsl) * z_dim1];
  1207. z__[i__ + (*ns + nsl) * z_dim1] = 0.;
  1208. }
  1209. /* Z( IROWZ:IROWZ+NTGK-1,N+1 ) = */
  1210. /* $ Z( IROWZ:IROWZ+NTGK-1,NS+NSL ) */
  1211. /* Z( IROWZ:IROWZ+NTGK-1,NS+NSL ) = */
  1212. /* $ ZERO */
  1213. }
  1214. }
  1215. /* ** WANTZ **! */
  1216. nsl = f2cmin(nsl,nru);
  1217. sveq0 = FALSE_;
  1218. /* Absolute values of the eigenvalues of TGK. */
  1219. i__3 = nsl - 1;
  1220. for (i__ = 0; i__ <= i__3; ++i__) {
  1221. s[isbeg + i__] = (d__1 = s[isbeg + i__], abs(d__1));
  1222. }
  1223. /* Update pointers for TGK, S and Z. */
  1224. isbeg += nsl;
  1225. irowz += ntgk;
  1226. icolz += nsl;
  1227. irowu = irowz;
  1228. irowv = irowz + 1;
  1229. isplt = idptr + 1;
  1230. *ns += nsl;
  1231. nru = 0;
  1232. nrv = 0;
  1233. }
  1234. /* ** NTGK.GT.0 **! */
  1235. if (irowz < *n << 1 && wantz) {
  1236. i__3 = irowz - 1;
  1237. for (i__ = 1; i__ <= i__3; ++i__) {
  1238. z__[i__ + icolz * z_dim1] = 0.;
  1239. }
  1240. /* Z( 1:IROWZ-1, ICOLZ ) = ZERO */
  1241. }
  1242. }
  1243. /* ** IDPTR loop **! */
  1244. if (split && wantz) {
  1245. /* Bring back eigenvector corresponding */
  1246. /* to eigenvalue equal to zero. */
  1247. i__2 = idend - ntgk + 1;
  1248. for (i__ = idbeg; i__ <= i__2; ++i__) {
  1249. z__[i__ + (isbeg - 1) * z_dim1] += z__[i__ + (*n + 1) *
  1250. z_dim1];
  1251. z__[i__ + (*n + 1) * z_dim1] = 0.;
  1252. }
  1253. /* Z( IDBEG:IDEND-NTGK+1,ISBEG-1 ) = */
  1254. /* $ Z( IDBEG:IDEND-NTGK+1,ISBEG-1 ) + */
  1255. /* $ Z( IDBEG:IDEND-NTGK+1,N+1 ) */
  1256. /* Z( IDBEG:IDEND-NTGK+1,N+1 ) = 0 */
  1257. }
  1258. --irowv;
  1259. ++irowu;
  1260. idbeg = ieptr + 1;
  1261. sveq0 = FALSE_;
  1262. split = FALSE_;
  1263. }
  1264. /* ** Check for split in E **! */
  1265. }
  1266. /* Sort the singular values into decreasing order (insertion sort on */
  1267. /* singular values, but only one transposition per singular vector) */
  1268. /* ** IEPTR loop **! */
  1269. i__1 = *ns - 1;
  1270. for (i__ = 1; i__ <= i__1; ++i__) {
  1271. k = 1;
  1272. smin = s[1];
  1273. i__2 = *ns + 1 - i__;
  1274. for (j = 2; j <= i__2; ++j) {
  1275. if (s[j] <= smin) {
  1276. k = j;
  1277. smin = s[j];
  1278. }
  1279. }
  1280. if (k != *ns + 1 - i__) {
  1281. s[k] = s[*ns + 1 - i__];
  1282. s[*ns + 1 - i__] = smin;
  1283. if (wantz) {
  1284. i__2 = *n << 1;
  1285. dswap_(&i__2, &z__[k * z_dim1 + 1], &c__1, &z__[(*ns + 1 -
  1286. i__) * z_dim1 + 1], &c__1);
  1287. }
  1288. }
  1289. }
  1290. /* If RANGE=I, check for singular values/vectors to be discarded. */
  1291. if (indsv) {
  1292. k = *iu - *il + 1;
  1293. if (k < *ns) {
  1294. i__1 = *ns;
  1295. for (i__ = k + 1; i__ <= i__1; ++i__) {
  1296. s[i__] = 0.;
  1297. }
  1298. /* S( K+1:NS ) = ZERO */
  1299. if (wantz) {
  1300. i__1 = *n << 1;
  1301. for (i__ = 1; i__ <= i__1; ++i__) {
  1302. i__2 = *ns;
  1303. for (j = k + 1; j <= i__2; ++j) {
  1304. z__[i__ + j * z_dim1] = 0.;
  1305. }
  1306. }
  1307. /* Z( 1:N*2,K+1:NS ) = ZERO */
  1308. }
  1309. *ns = k;
  1310. }
  1311. }
  1312. /* Reorder Z: U = Z( 1:N,1:NS ), V = Z( N+1:N*2,1:NS ). */
  1313. /* If B is a lower diagonal, swap U and V. */
  1314. if (wantz) {
  1315. i__1 = *ns;
  1316. for (i__ = 1; i__ <= i__1; ++i__) {
  1317. i__2 = *n << 1;
  1318. dcopy_(&i__2, &z__[i__ * z_dim1 + 1], &c__1, &work[1], &c__1);
  1319. if (lower) {
  1320. dcopy_(n, &work[2], &c__2, &z__[*n + 1 + i__ * z_dim1], &c__1)
  1321. ;
  1322. dcopy_(n, &work[1], &c__2, &z__[i__ * z_dim1 + 1], &c__1);
  1323. } else {
  1324. dcopy_(n, &work[2], &c__2, &z__[i__ * z_dim1 + 1], &c__1);
  1325. dcopy_(n, &work[1], &c__2, &z__[*n + 1 + i__ * z_dim1], &c__1)
  1326. ;
  1327. }
  1328. }
  1329. }
  1330. return;
  1331. /* End of DBDSVDX */
  1332. } /* dbdsvdx_ */