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.

dbbcsd.c 54 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800
  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 = -.125;
  485. static doublereal c_b35 = -1.;
  486. static integer c__1 = 1;
  487. /* > \brief \b DBBCSD */
  488. /* =========== DOCUMENTATION =========== */
  489. /* Online html documentation available at */
  490. /* http://www.netlib.org/lapack/explore-html/ */
  491. /* > \htmlonly */
  492. /* > Download DBBCSD + dependencies */
  493. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/dbbcsd.
  494. f"> */
  495. /* > [TGZ]</a> */
  496. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/dbbcsd.
  497. f"> */
  498. /* > [ZIP]</a> */
  499. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/dbbcsd.
  500. f"> */
  501. /* > [TXT]</a> */
  502. /* > \endhtmlonly */
  503. /* Definition: */
  504. /* =========== */
  505. /* SUBROUTINE DBBCSD( JOBU1, JOBU2, JOBV1T, JOBV2T, TRANS, M, P, Q, */
  506. /* THETA, PHI, U1, LDU1, U2, LDU2, V1T, LDV1T, */
  507. /* V2T, LDV2T, B11D, B11E, B12D, B12E, B21D, B21E, */
  508. /* B22D, B22E, WORK, LWORK, INFO ) */
  509. /* CHARACTER JOBU1, JOBU2, JOBV1T, JOBV2T, TRANS */
  510. /* INTEGER INFO, LDU1, LDU2, LDV1T, LDV2T, LWORK, M, P, Q */
  511. /* DOUBLE PRECISION B11D( * ), B11E( * ), B12D( * ), B12E( * ), */
  512. /* $ B21D( * ), B21E( * ), B22D( * ), B22E( * ), */
  513. /* $ PHI( * ), THETA( * ), WORK( * ) */
  514. /* DOUBLE PRECISION U1( LDU1, * ), U2( LDU2, * ), V1T( LDV1T, * ), */
  515. /* $ V2T( LDV2T, * ) */
  516. /* > \par Purpose: */
  517. /* ============= */
  518. /* > */
  519. /* > \verbatim */
  520. /* > */
  521. /* > DBBCSD computes the CS decomposition of an orthogonal matrix in */
  522. /* > bidiagonal-block form, */
  523. /* > */
  524. /* > */
  525. /* > [ B11 | B12 0 0 ] */
  526. /* > [ 0 | 0 -I 0 ] */
  527. /* > X = [----------------] */
  528. /* > [ B21 | B22 0 0 ] */
  529. /* > [ 0 | 0 0 I ] */
  530. /* > */
  531. /* > [ C | -S 0 0 ] */
  532. /* > [ U1 | ] [ 0 | 0 -I 0 ] [ V1 | ]**T */
  533. /* > = [---------] [---------------] [---------] . */
  534. /* > [ | U2 ] [ S | C 0 0 ] [ | V2 ] */
  535. /* > [ 0 | 0 0 I ] */
  536. /* > */
  537. /* > X is M-by-M, its top-left block is P-by-Q, and Q must be no larger */
  538. /* > than P, M-P, or M-Q. (If Q is not the smallest index, then X must be */
  539. /* > transposed and/or permuted. This can be done in constant time using */
  540. /* > the TRANS and SIGNS options. See DORCSD for details.) */
  541. /* > */
  542. /* > The bidiagonal matrices B11, B12, B21, and B22 are represented */
  543. /* > implicitly by angles THETA(1:Q) and PHI(1:Q-1). */
  544. /* > */
  545. /* > The orthogonal matrices U1, U2, V1T, and V2T are input/output. */
  546. /* > The input matrices are pre- or post-multiplied by the appropriate */
  547. /* > singular vector matrices. */
  548. /* > \endverbatim */
  549. /* Arguments: */
  550. /* ========== */
  551. /* > \param[in] JOBU1 */
  552. /* > \verbatim */
  553. /* > JOBU1 is CHARACTER */
  554. /* > = 'Y': U1 is updated; */
  555. /* > otherwise: U1 is not updated. */
  556. /* > \endverbatim */
  557. /* > */
  558. /* > \param[in] JOBU2 */
  559. /* > \verbatim */
  560. /* > JOBU2 is CHARACTER */
  561. /* > = 'Y': U2 is updated; */
  562. /* > otherwise: U2 is not updated. */
  563. /* > \endverbatim */
  564. /* > */
  565. /* > \param[in] JOBV1T */
  566. /* > \verbatim */
  567. /* > JOBV1T is CHARACTER */
  568. /* > = 'Y': V1T is updated; */
  569. /* > otherwise: V1T is not updated. */
  570. /* > \endverbatim */
  571. /* > */
  572. /* > \param[in] JOBV2T */
  573. /* > \verbatim */
  574. /* > JOBV2T is CHARACTER */
  575. /* > = 'Y': V2T is updated; */
  576. /* > otherwise: V2T is not updated. */
  577. /* > \endverbatim */
  578. /* > */
  579. /* > \param[in] TRANS */
  580. /* > \verbatim */
  581. /* > TRANS is CHARACTER */
  582. /* > = 'T': X, U1, U2, V1T, and V2T are stored in row-major */
  583. /* > order; */
  584. /* > otherwise: X, U1, U2, V1T, and V2T are stored in column- */
  585. /* > major order. */
  586. /* > \endverbatim */
  587. /* > */
  588. /* > \param[in] M */
  589. /* > \verbatim */
  590. /* > M is INTEGER */
  591. /* > The number of rows and columns in X, the orthogonal matrix in */
  592. /* > bidiagonal-block form. */
  593. /* > \endverbatim */
  594. /* > */
  595. /* > \param[in] P */
  596. /* > \verbatim */
  597. /* > P is INTEGER */
  598. /* > The number of rows in the top-left block of X. 0 <= P <= M. */
  599. /* > \endverbatim */
  600. /* > */
  601. /* > \param[in] Q */
  602. /* > \verbatim */
  603. /* > Q is INTEGER */
  604. /* > The number of columns in the top-left block of X. */
  605. /* > 0 <= Q <= MIN(P,M-P,M-Q). */
  606. /* > \endverbatim */
  607. /* > */
  608. /* > \param[in,out] THETA */
  609. /* > \verbatim */
  610. /* > THETA is DOUBLE PRECISION array, dimension (Q) */
  611. /* > On entry, the angles THETA(1),...,THETA(Q) that, along with */
  612. /* > PHI(1), ...,PHI(Q-1), define the matrix in bidiagonal-block */
  613. /* > form. On exit, the angles whose cosines and sines define the */
  614. /* > diagonal blocks in the CS decomposition. */
  615. /* > \endverbatim */
  616. /* > */
  617. /* > \param[in,out] PHI */
  618. /* > \verbatim */
  619. /* > PHI is DOUBLE PRECISION array, dimension (Q-1) */
  620. /* > The angles PHI(1),...,PHI(Q-1) that, along with THETA(1),..., */
  621. /* > THETA(Q), define the matrix in bidiagonal-block form. */
  622. /* > \endverbatim */
  623. /* > */
  624. /* > \param[in,out] U1 */
  625. /* > \verbatim */
  626. /* > U1 is DOUBLE PRECISION array, dimension (LDU1,P) */
  627. /* > On entry, a P-by-P matrix. On exit, U1 is postmultiplied */
  628. /* > by the left singular vector matrix common to [ B11 ; 0 ] and */
  629. /* > [ B12 0 0 ; 0 -I 0 0 ]. */
  630. /* > \endverbatim */
  631. /* > */
  632. /* > \param[in] LDU1 */
  633. /* > \verbatim */
  634. /* > LDU1 is INTEGER */
  635. /* > The leading dimension of the array U1, LDU1 >= MAX(1,P). */
  636. /* > \endverbatim */
  637. /* > */
  638. /* > \param[in,out] U2 */
  639. /* > \verbatim */
  640. /* > U2 is DOUBLE PRECISION array, dimension (LDU2,M-P) */
  641. /* > On entry, an (M-P)-by-(M-P) matrix. On exit, U2 is */
  642. /* > postmultiplied by the left singular vector matrix common to */
  643. /* > [ B21 ; 0 ] and [ B22 0 0 ; 0 0 I ]. */
  644. /* > \endverbatim */
  645. /* > */
  646. /* > \param[in] LDU2 */
  647. /* > \verbatim */
  648. /* > LDU2 is INTEGER */
  649. /* > The leading dimension of the array U2, LDU2 >= MAX(1,M-P). */
  650. /* > \endverbatim */
  651. /* > */
  652. /* > \param[in,out] V1T */
  653. /* > \verbatim */
  654. /* > V1T is DOUBLE PRECISION array, dimension (LDV1T,Q) */
  655. /* > On entry, a Q-by-Q matrix. On exit, V1T is premultiplied */
  656. /* > by the transpose of the right singular vector */
  657. /* > matrix common to [ B11 ; 0 ] and [ B21 ; 0 ]. */
  658. /* > \endverbatim */
  659. /* > */
  660. /* > \param[in] LDV1T */
  661. /* > \verbatim */
  662. /* > LDV1T is INTEGER */
  663. /* > The leading dimension of the array V1T, LDV1T >= MAX(1,Q). */
  664. /* > \endverbatim */
  665. /* > */
  666. /* > \param[in,out] V2T */
  667. /* > \verbatim */
  668. /* > V2T is DOUBLE PRECISION array, dimension (LDV2T,M-Q) */
  669. /* > On entry, an (M-Q)-by-(M-Q) matrix. On exit, V2T is */
  670. /* > premultiplied by the transpose of the right */
  671. /* > singular vector matrix common to [ B12 0 0 ; 0 -I 0 ] and */
  672. /* > [ B22 0 0 ; 0 0 I ]. */
  673. /* > \endverbatim */
  674. /* > */
  675. /* > \param[in] LDV2T */
  676. /* > \verbatim */
  677. /* > LDV2T is INTEGER */
  678. /* > The leading dimension of the array V2T, LDV2T >= MAX(1,M-Q). */
  679. /* > \endverbatim */
  680. /* > */
  681. /* > \param[out] B11D */
  682. /* > \verbatim */
  683. /* > B11D is DOUBLE PRECISION array, dimension (Q) */
  684. /* > When DBBCSD converges, B11D contains the cosines of THETA(1), */
  685. /* > ..., THETA(Q). If DBBCSD fails to converge, then B11D */
  686. /* > contains the diagonal of the partially reduced top-left */
  687. /* > block. */
  688. /* > \endverbatim */
  689. /* > */
  690. /* > \param[out] B11E */
  691. /* > \verbatim */
  692. /* > B11E is DOUBLE PRECISION array, dimension (Q-1) */
  693. /* > When DBBCSD converges, B11E contains zeros. If DBBCSD fails */
  694. /* > to converge, then B11E contains the superdiagonal of the */
  695. /* > partially reduced top-left block. */
  696. /* > \endverbatim */
  697. /* > */
  698. /* > \param[out] B12D */
  699. /* > \verbatim */
  700. /* > B12D is DOUBLE PRECISION array, dimension (Q) */
  701. /* > When DBBCSD converges, B12D contains the negative sines of */
  702. /* > THETA(1), ..., THETA(Q). If DBBCSD fails to converge, then */
  703. /* > B12D contains the diagonal of the partially reduced top-right */
  704. /* > block. */
  705. /* > \endverbatim */
  706. /* > */
  707. /* > \param[out] B12E */
  708. /* > \verbatim */
  709. /* > B12E is DOUBLE PRECISION array, dimension (Q-1) */
  710. /* > When DBBCSD converges, B12E contains zeros. If DBBCSD fails */
  711. /* > to converge, then B12E contains the subdiagonal of the */
  712. /* > partially reduced top-right block. */
  713. /* > \endverbatim */
  714. /* > */
  715. /* > \param[out] B21D */
  716. /* > \verbatim */
  717. /* > B21D is DOUBLE PRECISION array, dimension (Q) */
  718. /* > When DBBCSD converges, B21D contains the negative sines of */
  719. /* > THETA(1), ..., THETA(Q). If DBBCSD fails to converge, then */
  720. /* > B21D contains the diagonal of the partially reduced bottom-left */
  721. /* > block. */
  722. /* > \endverbatim */
  723. /* > */
  724. /* > \param[out] B21E */
  725. /* > \verbatim */
  726. /* > B21E is DOUBLE PRECISION array, dimension (Q-1) */
  727. /* > When DBBCSD converges, B21E contains zeros. If DBBCSD fails */
  728. /* > to converge, then B21E contains the subdiagonal of the */
  729. /* > partially reduced bottom-left block. */
  730. /* > \endverbatim */
  731. /* > */
  732. /* > \param[out] B22D */
  733. /* > \verbatim */
  734. /* > B22D is DOUBLE PRECISION array, dimension (Q) */
  735. /* > When DBBCSD converges, B22D contains the negative sines of */
  736. /* > THETA(1), ..., THETA(Q). If DBBCSD fails to converge, then */
  737. /* > B22D contains the diagonal of the partially reduced bottom-right */
  738. /* > block. */
  739. /* > \endverbatim */
  740. /* > */
  741. /* > \param[out] B22E */
  742. /* > \verbatim */
  743. /* > B22E is DOUBLE PRECISION array, dimension (Q-1) */
  744. /* > When DBBCSD converges, B22E contains zeros. If DBBCSD fails */
  745. /* > to converge, then B22E contains the subdiagonal of the */
  746. /* > partially reduced bottom-right block. */
  747. /* > \endverbatim */
  748. /* > */
  749. /* > \param[out] WORK */
  750. /* > \verbatim */
  751. /* > WORK is DOUBLE PRECISION array, dimension (MAX(1,LWORK)) */
  752. /* > On exit, if INFO = 0, WORK(1) returns the optimal LWORK. */
  753. /* > \endverbatim */
  754. /* > */
  755. /* > \param[in] LWORK */
  756. /* > \verbatim */
  757. /* > LWORK is INTEGER */
  758. /* > The dimension of the array WORK. LWORK >= MAX(1,8*Q). */
  759. /* > */
  760. /* > If LWORK = -1, then a workspace query is assumed; the */
  761. /* > routine only calculates the optimal size of the WORK array, */
  762. /* > returns this value as the first entry of the work array, and */
  763. /* > no error message related to LWORK is issued by XERBLA. */
  764. /* > \endverbatim */
  765. /* > */
  766. /* > \param[out] INFO */
  767. /* > \verbatim */
  768. /* > INFO is INTEGER */
  769. /* > = 0: successful exit. */
  770. /* > < 0: if INFO = -i, the i-th argument had an illegal value. */
  771. /* > > 0: if DBBCSD did not converge, INFO specifies the number */
  772. /* > of nonzero entries in PHI, and B11D, B11E, etc., */
  773. /* > contain the partially reduced matrix. */
  774. /* > \endverbatim */
  775. /* > \par Internal Parameters: */
  776. /* ========================= */
  777. /* > */
  778. /* > \verbatim */
  779. /* > TOLMUL DOUBLE PRECISION, default = MAX(10,MIN(100,EPS**(-1/8))) */
  780. /* > TOLMUL controls the convergence criterion of the QR loop. */
  781. /* > Angles THETA(i), PHI(i) are rounded to 0 or PI/2 when they */
  782. /* > are within TOLMUL*EPS of either bound. */
  783. /* > \endverbatim */
  784. /* > \par References: */
  785. /* ================ */
  786. /* > */
  787. /* > [1] Brian D. Sutton. Computing the complete CS decomposition. Numer. */
  788. /* > Algorithms, 50(1):33-65, 2009. */
  789. /* Authors: */
  790. /* ======== */
  791. /* > \author Univ. of Tennessee */
  792. /* > \author Univ. of California Berkeley */
  793. /* > \author Univ. of Colorado Denver */
  794. /* > \author NAG Ltd. */
  795. /* > \date June 2016 */
  796. /* > \ingroup doubleOTHERcomputational */
  797. /* ===================================================================== */
  798. /* Subroutine */ void dbbcsd_(char *jobu1, char *jobu2, char *jobv1t, char *
  799. jobv2t, char *trans, integer *m, integer *p, integer *q, doublereal *
  800. theta, doublereal *phi, doublereal *u1, integer *ldu1, doublereal *u2,
  801. integer *ldu2, doublereal *v1t, integer *ldv1t, doublereal *v2t,
  802. integer *ldv2t, doublereal *b11d, doublereal *b11e, doublereal *b12d,
  803. doublereal *b12e, doublereal *b21d, doublereal *b21e, doublereal *
  804. b22d, doublereal *b22e, doublereal *work, integer *lwork, integer *
  805. info)
  806. {
  807. /* System generated locals */
  808. integer u1_dim1, u1_offset, u2_dim1, u2_offset, v1t_dim1, v1t_offset,
  809. v2t_dim1, v2t_offset, i__1, i__2;
  810. doublereal d__1, d__2, d__3, d__4;
  811. /* Local variables */
  812. integer imin, mini, imax, iter;
  813. doublereal unfl, temp;
  814. logical colmajor;
  815. doublereal thetamin, thetamax;
  816. logical restart11, restart12, restart21, restart22;
  817. extern /* Subroutine */ void dlas2_(doublereal *, doublereal *, doublereal
  818. *, doublereal *, doublereal *);
  819. integer lworkmin, iu1cs, iu2cs, iu1sn, iu2sn, lworkopt, i__, j;
  820. doublereal r__;
  821. extern /* Subroutine */ void dscal_(integer *, doublereal *, doublereal *,
  822. integer *);
  823. extern logical lsame_(char *, char *);
  824. extern /* Subroutine */ void dlasr_(char *, char *, char *, integer *,
  825. integer *, doublereal *, doublereal *, doublereal *, integer *), dswap_(integer *, doublereal *, integer *
  826. , doublereal *, integer *);
  827. integer maxit;
  828. doublereal dummy, x1, x2, y1, y2;
  829. integer iv1tcs, iv2tcs;
  830. logical wantu1, wantu2;
  831. integer iv1tsn, iv2tsn;
  832. extern doublereal dlamch_(char *);
  833. doublereal mu, nu, sigma11, sigma21;
  834. extern /* Subroutine */ int xerbla_(char *, integer *, ftnlen);
  835. doublereal thresh, tolmul;
  836. extern /* Subroutine */ void mecago_();
  837. logical lquery;
  838. doublereal b11bulge;
  839. logical wantv1t, wantv2t;
  840. doublereal b12bulge, b21bulge, b22bulge, eps, tol;
  841. extern /* Subroutine */ void dlartgp_(doublereal *, doublereal *,
  842. doublereal *, doublereal *, doublereal *), dlartgs_(doublereal *,
  843. doublereal *, doublereal *, doublereal *, doublereal *);
  844. /* -- LAPACK computational routine (version 3.7.1) -- */
  845. /* -- LAPACK is a software package provided by Univ. of Tennessee, -- */
  846. /* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- */
  847. /* June 2016 */
  848. /* =================================================================== */
  849. /* Test input arguments */
  850. /* Parameter adjustments */
  851. --theta;
  852. --phi;
  853. u1_dim1 = *ldu1;
  854. u1_offset = 1 + u1_dim1 * 1;
  855. u1 -= u1_offset;
  856. u2_dim1 = *ldu2;
  857. u2_offset = 1 + u2_dim1 * 1;
  858. u2 -= u2_offset;
  859. v1t_dim1 = *ldv1t;
  860. v1t_offset = 1 + v1t_dim1 * 1;
  861. v1t -= v1t_offset;
  862. v2t_dim1 = *ldv2t;
  863. v2t_offset = 1 + v2t_dim1 * 1;
  864. v2t -= v2t_offset;
  865. --b11d;
  866. --b11e;
  867. --b12d;
  868. --b12e;
  869. --b21d;
  870. --b21e;
  871. --b22d;
  872. --b22e;
  873. --work;
  874. /* Function Body */
  875. *info = 0;
  876. lquery = *lwork == -1;
  877. wantu1 = lsame_(jobu1, "Y");
  878. wantu2 = lsame_(jobu2, "Y");
  879. wantv1t = lsame_(jobv1t, "Y");
  880. wantv2t = lsame_(jobv2t, "Y");
  881. colmajor = ! lsame_(trans, "T");
  882. if (*m < 0) {
  883. *info = -6;
  884. } else if (*p < 0 || *p > *m) {
  885. *info = -7;
  886. } else if (*q < 0 || *q > *m) {
  887. *info = -8;
  888. } else if (*q > *p || *q > *m - *p || *q > *m - *q) {
  889. *info = -8;
  890. } else if (wantu1 && *ldu1 < *p) {
  891. *info = -12;
  892. } else if (wantu2 && *ldu2 < *m - *p) {
  893. *info = -14;
  894. } else if (wantv1t && *ldv1t < *q) {
  895. *info = -16;
  896. } else if (wantv2t && *ldv2t < *m - *q) {
  897. *info = -18;
  898. }
  899. /* Quick return if Q = 0 */
  900. if (*info == 0 && *q == 0) {
  901. lworkmin = 1;
  902. work[1] = (doublereal) lworkmin;
  903. return;
  904. }
  905. /* Compute workspace */
  906. if (*info == 0) {
  907. iu1cs = 1;
  908. iu1sn = iu1cs + *q;
  909. iu2cs = iu1sn + *q;
  910. iu2sn = iu2cs + *q;
  911. iv1tcs = iu2sn + *q;
  912. iv1tsn = iv1tcs + *q;
  913. iv2tcs = iv1tsn + *q;
  914. iv2tsn = iv2tcs + *q;
  915. lworkopt = iv2tsn + *q - 1;
  916. lworkmin = lworkopt;
  917. work[1] = (doublereal) lworkopt;
  918. if (*lwork < lworkmin && ! lquery) {
  919. *info = -28;
  920. }
  921. }
  922. if (*info != 0) {
  923. i__1 = -(*info);
  924. xerbla_("DBBCSD", &i__1, (ftnlen)6);
  925. return;
  926. } else if (lquery) {
  927. return;
  928. }
  929. /* Get machine constants */
  930. eps = dlamch_("Epsilon");
  931. unfl = dlamch_("Safe minimum");
  932. /* Computing MAX */
  933. /* Computing MIN */
  934. d__3 = 100., d__4 = pow_dd(&eps, &c_b10);
  935. d__1 = 10., d__2 = f2cmin(d__3,d__4);
  936. tolmul = f2cmax(d__1,d__2);
  937. tol = tolmul * eps;
  938. /* Computing MAX */
  939. d__1 = tol, d__2 = *q * 6 * *q * unfl;
  940. thresh = f2cmax(d__1,d__2);
  941. /* Test for negligible sines or cosines */
  942. i__1 = *q;
  943. for (i__ = 1; i__ <= i__1; ++i__) {
  944. if (theta[i__] < thresh) {
  945. theta[i__] = 0.;
  946. } else if (theta[i__] > 1.57079632679489662 - thresh) {
  947. theta[i__] = 1.57079632679489662;
  948. }
  949. }
  950. i__1 = *q - 1;
  951. for (i__ = 1; i__ <= i__1; ++i__) {
  952. if (phi[i__] < thresh) {
  953. phi[i__] = 0.;
  954. } else if (phi[i__] > 1.57079632679489662 - thresh) {
  955. phi[i__] = 1.57079632679489662;
  956. }
  957. }
  958. /* Initial deflation */
  959. imax = *q;
  960. while(imax > 1) {
  961. if (phi[imax - 1] != 0.) {
  962. myexit_();
  963. }
  964. --imax;
  965. }
  966. imin = imax - 1;
  967. if (imin > 1) {
  968. while(phi[imin - 1] != 0.) {
  969. --imin;
  970. if (imin <= 1) {
  971. myexit_();
  972. }
  973. }
  974. }
  975. /* Initialize iteration counter */
  976. maxit = *q * 6 * *q;
  977. iter = 0;
  978. /* Begin main iteration loop */
  979. while(imax > 1) {
  980. /* Compute the matrix entries */
  981. b11d[imin] = cos(theta[imin]);
  982. b21d[imin] = -sin(theta[imin]);
  983. i__1 = imax - 1;
  984. for (i__ = imin; i__ <= i__1; ++i__) {
  985. b11e[i__] = -sin(theta[i__]) * sin(phi[i__]);
  986. b11d[i__ + 1] = cos(theta[i__ + 1]) * cos(phi[i__]);
  987. b12d[i__] = sin(theta[i__]) * cos(phi[i__]);
  988. b12e[i__] = cos(theta[i__ + 1]) * sin(phi[i__]);
  989. b21e[i__] = -cos(theta[i__]) * sin(phi[i__]);
  990. b21d[i__ + 1] = -sin(theta[i__ + 1]) * cos(phi[i__]);
  991. b22d[i__] = cos(theta[i__]) * cos(phi[i__]);
  992. b22e[i__] = -sin(theta[i__ + 1]) * sin(phi[i__]);
  993. }
  994. b12d[imax] = sin(theta[imax]);
  995. b22d[imax] = cos(theta[imax]);
  996. /* Abort if not converging; otherwise, increment ITER */
  997. if (iter > maxit) {
  998. *info = 0;
  999. i__1 = *q;
  1000. for (i__ = 1; i__ <= i__1; ++i__) {
  1001. if (phi[i__] != 0.) {
  1002. ++(*info);
  1003. }
  1004. }
  1005. return;
  1006. }
  1007. iter = iter + imax - imin;
  1008. /* Compute shifts */
  1009. thetamax = theta[imin];
  1010. thetamin = theta[imin];
  1011. i__1 = imax;
  1012. for (i__ = imin + 1; i__ <= i__1; ++i__) {
  1013. if (theta[i__] > thetamax) {
  1014. thetamax = theta[i__];
  1015. }
  1016. if (theta[i__] < thetamin) {
  1017. thetamin = theta[i__];
  1018. }
  1019. }
  1020. if (thetamax > 1.57079632679489662 - thresh) {
  1021. /* Zero on diagonals of B11 and B22; induce deflation with a */
  1022. /* zero shift */
  1023. mu = 0.;
  1024. nu = 1.;
  1025. } else if (thetamin < thresh) {
  1026. /* Zero on diagonals of B12 and B22; induce deflation with a */
  1027. /* zero shift */
  1028. mu = 1.;
  1029. nu = 0.;
  1030. } else {
  1031. /* Compute shifts for B11 and B21 and use the lesser */
  1032. dlas2_(&b11d[imax - 1], &b11e[imax - 1], &b11d[imax], &sigma11, &
  1033. dummy);
  1034. dlas2_(&b21d[imax - 1], &b21e[imax - 1], &b21d[imax], &sigma21, &
  1035. dummy);
  1036. if (sigma11 <= sigma21) {
  1037. mu = sigma11;
  1038. /* Computing 2nd power */
  1039. d__1 = mu;
  1040. nu = sqrt(1. - d__1 * d__1);
  1041. if (mu < thresh) {
  1042. mu = 0.;
  1043. nu = 1.;
  1044. }
  1045. } else {
  1046. nu = sigma21;
  1047. /* Computing 2nd power */
  1048. d__1 = nu;
  1049. mu = sqrt(1.f - d__1 * d__1);
  1050. if (nu < thresh) {
  1051. mu = 1.;
  1052. nu = 0.;
  1053. }
  1054. }
  1055. }
  1056. /* Rotate to produce bulges in B11 and B21 */
  1057. if (mu <= nu) {
  1058. dlartgs_(&b11d[imin], &b11e[imin], &mu, &work[iv1tcs + imin - 1],
  1059. &work[iv1tsn + imin - 1]);
  1060. } else {
  1061. dlartgs_(&b21d[imin], &b21e[imin], &nu, &work[iv1tcs + imin - 1],
  1062. &work[iv1tsn + imin - 1]);
  1063. }
  1064. temp = work[iv1tcs + imin - 1] * b11d[imin] + work[iv1tsn + imin - 1]
  1065. * b11e[imin];
  1066. b11e[imin] = work[iv1tcs + imin - 1] * b11e[imin] - work[iv1tsn +
  1067. imin - 1] * b11d[imin];
  1068. b11d[imin] = temp;
  1069. b11bulge = work[iv1tsn + imin - 1] * b11d[imin + 1];
  1070. b11d[imin + 1] = work[iv1tcs + imin - 1] * b11d[imin + 1];
  1071. temp = work[iv1tcs + imin - 1] * b21d[imin] + work[iv1tsn + imin - 1]
  1072. * b21e[imin];
  1073. b21e[imin] = work[iv1tcs + imin - 1] * b21e[imin] - work[iv1tsn +
  1074. imin - 1] * b21d[imin];
  1075. b21d[imin] = temp;
  1076. b21bulge = work[iv1tsn + imin - 1] * b21d[imin + 1];
  1077. b21d[imin + 1] = work[iv1tcs + imin - 1] * b21d[imin + 1];
  1078. /* Compute THETA(IMIN) */
  1079. /* Computing 2nd power */
  1080. d__1 = b21d[imin];
  1081. /* Computing 2nd power */
  1082. d__2 = b21bulge;
  1083. /* Computing 2nd power */
  1084. d__3 = b11d[imin];
  1085. /* Computing 2nd power */
  1086. d__4 = b11bulge;
  1087. theta[imin] = atan2(sqrt(d__1 * d__1 + d__2 * d__2), sqrt(d__3 * d__3
  1088. + d__4 * d__4));
  1089. /* Chase the bulges in B11(IMIN+1,IMIN) and B21(IMIN+1,IMIN) */
  1090. /* Computing 2nd power */
  1091. d__1 = b11d[imin];
  1092. /* Computing 2nd power */
  1093. d__2 = b11bulge;
  1094. /* Computing 2nd power */
  1095. d__3 = thresh;
  1096. if (d__1 * d__1 + d__2 * d__2 > d__3 * d__3) {
  1097. dlartgp_(&b11bulge, &b11d[imin], &work[iu1sn + imin - 1], &work[
  1098. iu1cs + imin - 1], &r__);
  1099. } else if (mu <= nu) {
  1100. dlartgs_(&b11e[imin], &b11d[imin + 1], &mu, &work[iu1cs + imin -
  1101. 1], &work[iu1sn + imin - 1]);
  1102. } else {
  1103. dlartgs_(&b12d[imin], &b12e[imin], &nu, &work[iu1cs + imin - 1], &
  1104. work[iu1sn + imin - 1]);
  1105. }
  1106. /* Computing 2nd power */
  1107. d__1 = b21d[imin];
  1108. /* Computing 2nd power */
  1109. d__2 = b21bulge;
  1110. /* Computing 2nd power */
  1111. d__3 = thresh;
  1112. if (d__1 * d__1 + d__2 * d__2 > d__3 * d__3) {
  1113. dlartgp_(&b21bulge, &b21d[imin], &work[iu2sn + imin - 1], &work[
  1114. iu2cs + imin - 1], &r__);
  1115. } else if (nu < mu) {
  1116. dlartgs_(&b21e[imin], &b21d[imin + 1], &nu, &work[iu2cs + imin -
  1117. 1], &work[iu2sn + imin - 1]);
  1118. } else {
  1119. dlartgs_(&b22d[imin], &b22e[imin], &mu, &work[iu2cs + imin - 1], &
  1120. work[iu2sn + imin - 1]);
  1121. }
  1122. work[iu2cs + imin - 1] = -work[iu2cs + imin - 1];
  1123. work[iu2sn + imin - 1] = -work[iu2sn + imin - 1];
  1124. temp = work[iu1cs + imin - 1] * b11e[imin] + work[iu1sn + imin - 1] *
  1125. b11d[imin + 1];
  1126. b11d[imin + 1] = work[iu1cs + imin - 1] * b11d[imin + 1] - work[iu1sn
  1127. + imin - 1] * b11e[imin];
  1128. b11e[imin] = temp;
  1129. if (imax > imin + 1) {
  1130. b11bulge = work[iu1sn + imin - 1] * b11e[imin + 1];
  1131. b11e[imin + 1] = work[iu1cs + imin - 1] * b11e[imin + 1];
  1132. }
  1133. temp = work[iu1cs + imin - 1] * b12d[imin] + work[iu1sn + imin - 1] *
  1134. b12e[imin];
  1135. b12e[imin] = work[iu1cs + imin - 1] * b12e[imin] - work[iu1sn + imin
  1136. - 1] * b12d[imin];
  1137. b12d[imin] = temp;
  1138. b12bulge = work[iu1sn + imin - 1] * b12d[imin + 1];
  1139. b12d[imin + 1] = work[iu1cs + imin - 1] * b12d[imin + 1];
  1140. temp = work[iu2cs + imin - 1] * b21e[imin] + work[iu2sn + imin - 1] *
  1141. b21d[imin + 1];
  1142. b21d[imin + 1] = work[iu2cs + imin - 1] * b21d[imin + 1] - work[iu2sn
  1143. + imin - 1] * b21e[imin];
  1144. b21e[imin] = temp;
  1145. if (imax > imin + 1) {
  1146. b21bulge = work[iu2sn + imin - 1] * b21e[imin + 1];
  1147. b21e[imin + 1] = work[iu2cs + imin - 1] * b21e[imin + 1];
  1148. }
  1149. temp = work[iu2cs + imin - 1] * b22d[imin] + work[iu2sn + imin - 1] *
  1150. b22e[imin];
  1151. b22e[imin] = work[iu2cs + imin - 1] * b22e[imin] - work[iu2sn + imin
  1152. - 1] * b22d[imin];
  1153. b22d[imin] = temp;
  1154. b22bulge = work[iu2sn + imin - 1] * b22d[imin + 1];
  1155. b22d[imin + 1] = work[iu2cs + imin - 1] * b22d[imin + 1];
  1156. /* Inner loop: chase bulges from B11(IMIN,IMIN+2), */
  1157. /* B12(IMIN,IMIN+1), B21(IMIN,IMIN+2), and B22(IMIN,IMIN+1) to */
  1158. /* bottom-right */
  1159. i__1 = imax - 1;
  1160. for (i__ = imin + 1; i__ <= i__1; ++i__) {
  1161. /* Compute PHI(I-1) */
  1162. x1 = sin(theta[i__ - 1]) * b11e[i__ - 1] + cos(theta[i__ - 1]) *
  1163. b21e[i__ - 1];
  1164. x2 = sin(theta[i__ - 1]) * b11bulge + cos(theta[i__ - 1]) *
  1165. b21bulge;
  1166. y1 = sin(theta[i__ - 1]) * b12d[i__ - 1] + cos(theta[i__ - 1]) *
  1167. b22d[i__ - 1];
  1168. y2 = sin(theta[i__ - 1]) * b12bulge + cos(theta[i__ - 1]) *
  1169. b22bulge;
  1170. /* Computing 2nd power */
  1171. d__1 = x1;
  1172. /* Computing 2nd power */
  1173. d__2 = x2;
  1174. /* Computing 2nd power */
  1175. d__3 = y1;
  1176. /* Computing 2nd power */
  1177. d__4 = y2;
  1178. phi[i__ - 1] = atan2(sqrt(d__1 * d__1 + d__2 * d__2), sqrt(d__3 *
  1179. d__3 + d__4 * d__4));
  1180. /* Determine if there are bulges to chase or if a new direct */
  1181. /* summand has been reached */
  1182. /* Computing 2nd power */
  1183. d__1 = b11e[i__ - 1];
  1184. /* Computing 2nd power */
  1185. d__2 = b11bulge;
  1186. /* Computing 2nd power */
  1187. d__3 = thresh;
  1188. restart11 = d__1 * d__1 + d__2 * d__2 <= d__3 * d__3;
  1189. /* Computing 2nd power */
  1190. d__1 = b21e[i__ - 1];
  1191. /* Computing 2nd power */
  1192. d__2 = b21bulge;
  1193. /* Computing 2nd power */
  1194. d__3 = thresh;
  1195. restart21 = d__1 * d__1 + d__2 * d__2 <= d__3 * d__3;
  1196. /* Computing 2nd power */
  1197. d__1 = b12d[i__ - 1];
  1198. /* Computing 2nd power */
  1199. d__2 = b12bulge;
  1200. /* Computing 2nd power */
  1201. d__3 = thresh;
  1202. restart12 = d__1 * d__1 + d__2 * d__2 <= d__3 * d__3;
  1203. /* Computing 2nd power */
  1204. d__1 = b22d[i__ - 1];
  1205. /* Computing 2nd power */
  1206. d__2 = b22bulge;
  1207. /* Computing 2nd power */
  1208. d__3 = thresh;
  1209. restart22 = d__1 * d__1 + d__2 * d__2 <= d__3 * d__3;
  1210. /* If possible, chase bulges from B11(I-1,I+1), B12(I-1,I), */
  1211. /* B21(I-1,I+1), and B22(I-1,I). If necessary, restart bulge- */
  1212. /* chasing by applying the original shift again. */
  1213. if (! restart11 && ! restart21) {
  1214. dlartgp_(&x2, &x1, &work[iv1tsn + i__ - 1], &work[iv1tcs +
  1215. i__ - 1], &r__);
  1216. } else if (! restart11 && restart21) {
  1217. dlartgp_(&b11bulge, &b11e[i__ - 1], &work[iv1tsn + i__ - 1], &
  1218. work[iv1tcs + i__ - 1], &r__);
  1219. } else if (restart11 && ! restart21) {
  1220. dlartgp_(&b21bulge, &b21e[i__ - 1], &work[iv1tsn + i__ - 1], &
  1221. work[iv1tcs + i__ - 1], &r__);
  1222. } else if (mu <= nu) {
  1223. dlartgs_(&b11d[i__], &b11e[i__], &mu, &work[iv1tcs + i__ - 1],
  1224. &work[iv1tsn + i__ - 1]);
  1225. } else {
  1226. dlartgs_(&b21d[i__], &b21e[i__], &nu, &work[iv1tcs + i__ - 1],
  1227. &work[iv1tsn + i__ - 1]);
  1228. }
  1229. work[iv1tcs + i__ - 1] = -work[iv1tcs + i__ - 1];
  1230. work[iv1tsn + i__ - 1] = -work[iv1tsn + i__ - 1];
  1231. if (! restart12 && ! restart22) {
  1232. dlartgp_(&y2, &y1, &work[iv2tsn + i__ - 2], &work[iv2tcs +
  1233. i__ - 2], &r__);
  1234. } else if (! restart12 && restart22) {
  1235. dlartgp_(&b12bulge, &b12d[i__ - 1], &work[iv2tsn + i__ - 2], &
  1236. work[iv2tcs + i__ - 2], &r__);
  1237. } else if (restart12 && ! restart22) {
  1238. dlartgp_(&b22bulge, &b22d[i__ - 1], &work[iv2tsn + i__ - 2], &
  1239. work[iv2tcs + i__ - 2], &r__);
  1240. } else if (nu < mu) {
  1241. dlartgs_(&b12e[i__ - 1], &b12d[i__], &nu, &work[iv2tcs + i__
  1242. - 2], &work[iv2tsn + i__ - 2]);
  1243. } else {
  1244. dlartgs_(&b22e[i__ - 1], &b22d[i__], &mu, &work[iv2tcs + i__
  1245. - 2], &work[iv2tsn + i__ - 2]);
  1246. }
  1247. temp = work[iv1tcs + i__ - 1] * b11d[i__] + work[iv1tsn + i__ - 1]
  1248. * b11e[i__];
  1249. b11e[i__] = work[iv1tcs + i__ - 1] * b11e[i__] - work[iv1tsn +
  1250. i__ - 1] * b11d[i__];
  1251. b11d[i__] = temp;
  1252. b11bulge = work[iv1tsn + i__ - 1] * b11d[i__ + 1];
  1253. b11d[i__ + 1] = work[iv1tcs + i__ - 1] * b11d[i__ + 1];
  1254. temp = work[iv1tcs + i__ - 1] * b21d[i__] + work[iv1tsn + i__ - 1]
  1255. * b21e[i__];
  1256. b21e[i__] = work[iv1tcs + i__ - 1] * b21e[i__] - work[iv1tsn +
  1257. i__ - 1] * b21d[i__];
  1258. b21d[i__] = temp;
  1259. b21bulge = work[iv1tsn + i__ - 1] * b21d[i__ + 1];
  1260. b21d[i__ + 1] = work[iv1tcs + i__ - 1] * b21d[i__ + 1];
  1261. temp = work[iv2tcs + i__ - 2] * b12e[i__ - 1] + work[iv2tsn + i__
  1262. - 2] * b12d[i__];
  1263. b12d[i__] = work[iv2tcs + i__ - 2] * b12d[i__] - work[iv2tsn +
  1264. i__ - 2] * b12e[i__ - 1];
  1265. b12e[i__ - 1] = temp;
  1266. b12bulge = work[iv2tsn + i__ - 2] * b12e[i__];
  1267. b12e[i__] = work[iv2tcs + i__ - 2] * b12e[i__];
  1268. temp = work[iv2tcs + i__ - 2] * b22e[i__ - 1] + work[iv2tsn + i__
  1269. - 2] * b22d[i__];
  1270. b22d[i__] = work[iv2tcs + i__ - 2] * b22d[i__] - work[iv2tsn +
  1271. i__ - 2] * b22e[i__ - 1];
  1272. b22e[i__ - 1] = temp;
  1273. b22bulge = work[iv2tsn + i__ - 2] * b22e[i__];
  1274. b22e[i__] = work[iv2tcs + i__ - 2] * b22e[i__];
  1275. /* Compute THETA(I) */
  1276. x1 = cos(phi[i__ - 1]) * b11d[i__] + sin(phi[i__ - 1]) * b12e[i__
  1277. - 1];
  1278. x2 = cos(phi[i__ - 1]) * b11bulge + sin(phi[i__ - 1]) * b12bulge;
  1279. y1 = cos(phi[i__ - 1]) * b21d[i__] + sin(phi[i__ - 1]) * b22e[i__
  1280. - 1];
  1281. y2 = cos(phi[i__ - 1]) * b21bulge + sin(phi[i__ - 1]) * b22bulge;
  1282. /* Computing 2nd power */
  1283. d__1 = y1;
  1284. /* Computing 2nd power */
  1285. d__2 = y2;
  1286. /* Computing 2nd power */
  1287. d__3 = x1;
  1288. /* Computing 2nd power */
  1289. d__4 = x2;
  1290. theta[i__] = atan2(sqrt(d__1 * d__1 + d__2 * d__2), sqrt(d__3 *
  1291. d__3 + d__4 * d__4));
  1292. /* Determine if there are bulges to chase or if a new direct */
  1293. /* summand has been reached */
  1294. /* Computing 2nd power */
  1295. d__1 = b11d[i__];
  1296. /* Computing 2nd power */
  1297. d__2 = b11bulge;
  1298. /* Computing 2nd power */
  1299. d__3 = thresh;
  1300. restart11 = d__1 * d__1 + d__2 * d__2 <= d__3 * d__3;
  1301. /* Computing 2nd power */
  1302. d__1 = b12e[i__ - 1];
  1303. /* Computing 2nd power */
  1304. d__2 = b12bulge;
  1305. /* Computing 2nd power */
  1306. d__3 = thresh;
  1307. restart12 = d__1 * d__1 + d__2 * d__2 <= d__3 * d__3;
  1308. /* Computing 2nd power */
  1309. d__1 = b21d[i__];
  1310. /* Computing 2nd power */
  1311. d__2 = b21bulge;
  1312. /* Computing 2nd power */
  1313. d__3 = thresh;
  1314. restart21 = d__1 * d__1 + d__2 * d__2 <= d__3 * d__3;
  1315. /* Computing 2nd power */
  1316. d__1 = b22e[i__ - 1];
  1317. /* Computing 2nd power */
  1318. d__2 = b22bulge;
  1319. /* Computing 2nd power */
  1320. d__3 = thresh;
  1321. restart22 = d__1 * d__1 + d__2 * d__2 <= d__3 * d__3;
  1322. /* If possible, chase bulges from B11(I+1,I), B12(I+1,I-1), */
  1323. /* B21(I+1,I), and B22(I+1,I-1). If necessary, restart bulge- */
  1324. /* chasing by applying the original shift again. */
  1325. if (! restart11 && ! restart12) {
  1326. dlartgp_(&x2, &x1, &work[iu1sn + i__ - 1], &work[iu1cs + i__
  1327. - 1], &r__);
  1328. } else if (! restart11 && restart12) {
  1329. dlartgp_(&b11bulge, &b11d[i__], &work[iu1sn + i__ - 1], &work[
  1330. iu1cs + i__ - 1], &r__);
  1331. } else if (restart11 && ! restart12) {
  1332. dlartgp_(&b12bulge, &b12e[i__ - 1], &work[iu1sn + i__ - 1], &
  1333. work[iu1cs + i__ - 1], &r__);
  1334. } else if (mu <= nu) {
  1335. dlartgs_(&b11e[i__], &b11d[i__ + 1], &mu, &work[iu1cs + i__ -
  1336. 1], &work[iu1sn + i__ - 1]);
  1337. } else {
  1338. dlartgs_(&b12d[i__], &b12e[i__], &nu, &work[iu1cs + i__ - 1],
  1339. &work[iu1sn + i__ - 1]);
  1340. }
  1341. if (! restart21 && ! restart22) {
  1342. dlartgp_(&y2, &y1, &work[iu2sn + i__ - 1], &work[iu2cs + i__
  1343. - 1], &r__);
  1344. } else if (! restart21 && restart22) {
  1345. dlartgp_(&b21bulge, &b21d[i__], &work[iu2sn + i__ - 1], &work[
  1346. iu2cs + i__ - 1], &r__);
  1347. } else if (restart21 && ! restart22) {
  1348. dlartgp_(&b22bulge, &b22e[i__ - 1], &work[iu2sn + i__ - 1], &
  1349. work[iu2cs + i__ - 1], &r__);
  1350. } else if (nu < mu) {
  1351. dlartgs_(&b21e[i__], &b21e[i__ + 1], &nu, &work[iu2cs + i__ -
  1352. 1], &work[iu2sn + i__ - 1]);
  1353. } else {
  1354. dlartgs_(&b22d[i__], &b22e[i__], &mu, &work[iu2cs + i__ - 1],
  1355. &work[iu2sn + i__ - 1]);
  1356. }
  1357. work[iu2cs + i__ - 1] = -work[iu2cs + i__ - 1];
  1358. work[iu2sn + i__ - 1] = -work[iu2sn + i__ - 1];
  1359. temp = work[iu1cs + i__ - 1] * b11e[i__] + work[iu1sn + i__ - 1] *
  1360. b11d[i__ + 1];
  1361. b11d[i__ + 1] = work[iu1cs + i__ - 1] * b11d[i__ + 1] - work[
  1362. iu1sn + i__ - 1] * b11e[i__];
  1363. b11e[i__] = temp;
  1364. if (i__ < imax - 1) {
  1365. b11bulge = work[iu1sn + i__ - 1] * b11e[i__ + 1];
  1366. b11e[i__ + 1] = work[iu1cs + i__ - 1] * b11e[i__ + 1];
  1367. }
  1368. temp = work[iu2cs + i__ - 1] * b21e[i__] + work[iu2sn + i__ - 1] *
  1369. b21d[i__ + 1];
  1370. b21d[i__ + 1] = work[iu2cs + i__ - 1] * b21d[i__ + 1] - work[
  1371. iu2sn + i__ - 1] * b21e[i__];
  1372. b21e[i__] = temp;
  1373. if (i__ < imax - 1) {
  1374. b21bulge = work[iu2sn + i__ - 1] * b21e[i__ + 1];
  1375. b21e[i__ + 1] = work[iu2cs + i__ - 1] * b21e[i__ + 1];
  1376. }
  1377. temp = work[iu1cs + i__ - 1] * b12d[i__] + work[iu1sn + i__ - 1] *
  1378. b12e[i__];
  1379. b12e[i__] = work[iu1cs + i__ - 1] * b12e[i__] - work[iu1sn + i__
  1380. - 1] * b12d[i__];
  1381. b12d[i__] = temp;
  1382. b12bulge = work[iu1sn + i__ - 1] * b12d[i__ + 1];
  1383. b12d[i__ + 1] = work[iu1cs + i__ - 1] * b12d[i__ + 1];
  1384. temp = work[iu2cs + i__ - 1] * b22d[i__] + work[iu2sn + i__ - 1] *
  1385. b22e[i__];
  1386. b22e[i__] = work[iu2cs + i__ - 1] * b22e[i__] - work[iu2sn + i__
  1387. - 1] * b22d[i__];
  1388. b22d[i__] = temp;
  1389. b22bulge = work[iu2sn + i__ - 1] * b22d[i__ + 1];
  1390. b22d[i__ + 1] = work[iu2cs + i__ - 1] * b22d[i__ + 1];
  1391. }
  1392. /* Compute PHI(IMAX-1) */
  1393. x1 = sin(theta[imax - 1]) * b11e[imax - 1] + cos(theta[imax - 1]) *
  1394. b21e[imax - 1];
  1395. y1 = sin(theta[imax - 1]) * b12d[imax - 1] + cos(theta[imax - 1]) *
  1396. b22d[imax - 1];
  1397. y2 = sin(theta[imax - 1]) * b12bulge + cos(theta[imax - 1]) *
  1398. b22bulge;
  1399. /* Computing 2nd power */
  1400. d__1 = y1;
  1401. /* Computing 2nd power */
  1402. d__2 = y2;
  1403. phi[imax - 1] = atan2((abs(x1)), sqrt(d__1 * d__1 + d__2 * d__2));
  1404. /* Chase bulges from B12(IMAX-1,IMAX) and B22(IMAX-1,IMAX) */
  1405. /* Computing 2nd power */
  1406. d__1 = b12d[imax - 1];
  1407. /* Computing 2nd power */
  1408. d__2 = b12bulge;
  1409. /* Computing 2nd power */
  1410. d__3 = thresh;
  1411. restart12 = d__1 * d__1 + d__2 * d__2 <= d__3 * d__3;
  1412. /* Computing 2nd power */
  1413. d__1 = b22d[imax - 1];
  1414. /* Computing 2nd power */
  1415. d__2 = b22bulge;
  1416. /* Computing 2nd power */
  1417. d__3 = thresh;
  1418. restart22 = d__1 * d__1 + d__2 * d__2 <= d__3 * d__3;
  1419. if (! restart12 && ! restart22) {
  1420. dlartgp_(&y2, &y1, &work[iv2tsn + imax - 2], &work[iv2tcs + imax
  1421. - 2], &r__);
  1422. } else if (! restart12 && restart22) {
  1423. dlartgp_(&b12bulge, &b12d[imax - 1], &work[iv2tsn + imax - 2], &
  1424. work[iv2tcs + imax - 2], &r__);
  1425. } else if (restart12 && ! restart22) {
  1426. dlartgp_(&b22bulge, &b22d[imax - 1], &work[iv2tsn + imax - 2], &
  1427. work[iv2tcs + imax - 2], &r__);
  1428. } else if (nu < mu) {
  1429. dlartgs_(&b12e[imax - 1], &b12d[imax], &nu, &work[iv2tcs + imax -
  1430. 2], &work[iv2tsn + imax - 2]);
  1431. } else {
  1432. dlartgs_(&b22e[imax - 1], &b22d[imax], &mu, &work[iv2tcs + imax -
  1433. 2], &work[iv2tsn + imax - 2]);
  1434. }
  1435. temp = work[iv2tcs + imax - 2] * b12e[imax - 1] + work[iv2tsn + imax
  1436. - 2] * b12d[imax];
  1437. b12d[imax] = work[iv2tcs + imax - 2] * b12d[imax] - work[iv2tsn +
  1438. imax - 2] * b12e[imax - 1];
  1439. b12e[imax - 1] = temp;
  1440. temp = work[iv2tcs + imax - 2] * b22e[imax - 1] + work[iv2tsn + imax
  1441. - 2] * b22d[imax];
  1442. b22d[imax] = work[iv2tcs + imax - 2] * b22d[imax] - work[iv2tsn +
  1443. imax - 2] * b22e[imax - 1];
  1444. b22e[imax - 1] = temp;
  1445. /* Update singular vectors */
  1446. if (wantu1) {
  1447. if (colmajor) {
  1448. i__1 = imax - imin + 1;
  1449. dlasr_("R", "V", "F", p, &i__1, &work[iu1cs + imin - 1], &
  1450. work[iu1sn + imin - 1], &u1[imin * u1_dim1 + 1], ldu1);
  1451. } else {
  1452. i__1 = imax - imin + 1;
  1453. dlasr_("L", "V", "F", &i__1, p, &work[iu1cs + imin - 1], &
  1454. work[iu1sn + imin - 1], &u1[imin + u1_dim1], ldu1);
  1455. }
  1456. }
  1457. if (wantu2) {
  1458. if (colmajor) {
  1459. i__1 = *m - *p;
  1460. i__2 = imax - imin + 1;
  1461. dlasr_("R", "V", "F", &i__1, &i__2, &work[iu2cs + imin - 1], &
  1462. work[iu2sn + imin - 1], &u2[imin * u2_dim1 + 1], ldu2);
  1463. } else {
  1464. i__1 = imax - imin + 1;
  1465. i__2 = *m - *p;
  1466. dlasr_("L", "V", "F", &i__1, &i__2, &work[iu2cs + imin - 1], &
  1467. work[iu2sn + imin - 1], &u2[imin + u2_dim1], ldu2);
  1468. }
  1469. }
  1470. if (wantv1t) {
  1471. if (colmajor) {
  1472. i__1 = imax - imin + 1;
  1473. dlasr_("L", "V", "F", &i__1, q, &work[iv1tcs + imin - 1], &
  1474. work[iv1tsn + imin - 1], &v1t[imin + v1t_dim1], ldv1t);
  1475. } else {
  1476. i__1 = imax - imin + 1;
  1477. dlasr_("R", "V", "F", q, &i__1, &work[iv1tcs + imin - 1], &
  1478. work[iv1tsn + imin - 1], &v1t[imin * v1t_dim1 + 1],
  1479. ldv1t);
  1480. }
  1481. }
  1482. if (wantv2t) {
  1483. if (colmajor) {
  1484. i__1 = imax - imin + 1;
  1485. i__2 = *m - *q;
  1486. dlasr_("L", "V", "F", &i__1, &i__2, &work[iv2tcs + imin - 1],
  1487. &work[iv2tsn + imin - 1], &v2t[imin + v2t_dim1],
  1488. ldv2t);
  1489. } else {
  1490. i__1 = *m - *q;
  1491. i__2 = imax - imin + 1;
  1492. dlasr_("R", "V", "F", &i__1, &i__2, &work[iv2tcs + imin - 1],
  1493. &work[iv2tsn + imin - 1], &v2t[imin * v2t_dim1 + 1],
  1494. ldv2t);
  1495. }
  1496. }
  1497. /* Fix signs on B11(IMAX-1,IMAX) and B21(IMAX-1,IMAX) */
  1498. if (b11e[imax - 1] + b21e[imax - 1] > 0.) {
  1499. b11d[imax] = -b11d[imax];
  1500. b21d[imax] = -b21d[imax];
  1501. if (wantv1t) {
  1502. if (colmajor) {
  1503. dscal_(q, &c_b35, &v1t[imax + v1t_dim1], ldv1t);
  1504. } else {
  1505. dscal_(q, &c_b35, &v1t[imax * v1t_dim1 + 1], &c__1);
  1506. }
  1507. }
  1508. }
  1509. /* Compute THETA(IMAX) */
  1510. x1 = cos(phi[imax - 1]) * b11d[imax] + sin(phi[imax - 1]) * b12e[imax
  1511. - 1];
  1512. y1 = cos(phi[imax - 1]) * b21d[imax] + sin(phi[imax - 1]) * b22e[imax
  1513. - 1];
  1514. theta[imax] = atan2((abs(y1)), (abs(x1)));
  1515. /* Fix signs on B11(IMAX,IMAX), B12(IMAX,IMAX-1), B21(IMAX,IMAX), */
  1516. /* and B22(IMAX,IMAX-1) */
  1517. if (b11d[imax] + b12e[imax - 1] < 0.) {
  1518. b12d[imax] = -b12d[imax];
  1519. if (wantu1) {
  1520. if (colmajor) {
  1521. dscal_(p, &c_b35, &u1[imax * u1_dim1 + 1], &c__1);
  1522. } else {
  1523. dscal_(p, &c_b35, &u1[imax + u1_dim1], ldu1);
  1524. }
  1525. }
  1526. }
  1527. if (b21d[imax] + b22e[imax - 1] > 0.) {
  1528. b22d[imax] = -b22d[imax];
  1529. if (wantu2) {
  1530. if (colmajor) {
  1531. i__1 = *m - *p;
  1532. dscal_(&i__1, &c_b35, &u2[imax * u2_dim1 + 1], &c__1);
  1533. } else {
  1534. i__1 = *m - *p;
  1535. dscal_(&i__1, &c_b35, &u2[imax + u2_dim1], ldu2);
  1536. }
  1537. }
  1538. }
  1539. /* Fix signs on B12(IMAX,IMAX) and B22(IMAX,IMAX) */
  1540. if (b12d[imax] + b22d[imax] < 0.) {
  1541. if (wantv2t) {
  1542. if (colmajor) {
  1543. i__1 = *m - *q;
  1544. dscal_(&i__1, &c_b35, &v2t[imax + v2t_dim1], ldv2t);
  1545. } else {
  1546. i__1 = *m - *q;
  1547. dscal_(&i__1, &c_b35, &v2t[imax * v2t_dim1 + 1], &c__1);
  1548. }
  1549. }
  1550. }
  1551. /* Test for negligible sines or cosines */
  1552. i__1 = imax;
  1553. for (i__ = imin; i__ <= i__1; ++i__) {
  1554. if (theta[i__] < thresh) {
  1555. theta[i__] = 0.;
  1556. } else if (theta[i__] > 1.57079632679489662 - thresh) {
  1557. theta[i__] = 1.57079632679489662;
  1558. }
  1559. }
  1560. i__1 = imax - 1;
  1561. for (i__ = imin; i__ <= i__1; ++i__) {
  1562. if (phi[i__] < thresh) {
  1563. phi[i__] = 0.;
  1564. } else if (phi[i__] > 1.57079632679489662 - thresh) {
  1565. phi[i__] = 1.57079632679489662;
  1566. }
  1567. }
  1568. /* Deflate */
  1569. if (imax > 1) {
  1570. while(phi[imax - 1] == 0.) {
  1571. --imax;
  1572. if (imax <= 1) {
  1573. myexit_();
  1574. }
  1575. }
  1576. }
  1577. if (imin > imax - 1) {
  1578. imin = imax - 1;
  1579. }
  1580. if (imin > 1) {
  1581. while(phi[imin - 1] != 0.) {
  1582. --imin;
  1583. if (imin <= 1) {
  1584. myexit_();
  1585. }
  1586. }
  1587. }
  1588. /* Repeat main iteration loop */
  1589. }
  1590. /* Postprocessing: order THETA from least to greatest */
  1591. i__1 = *q;
  1592. for (i__ = 1; i__ <= i__1; ++i__) {
  1593. mini = i__;
  1594. thetamin = theta[i__];
  1595. i__2 = *q;
  1596. for (j = i__ + 1; j <= i__2; ++j) {
  1597. if (theta[j] < thetamin) {
  1598. mini = j;
  1599. thetamin = theta[j];
  1600. }
  1601. }
  1602. if (mini != i__) {
  1603. theta[mini] = theta[i__];
  1604. theta[i__] = thetamin;
  1605. if (colmajor) {
  1606. if (wantu1) {
  1607. dswap_(p, &u1[i__ * u1_dim1 + 1], &c__1, &u1[mini *
  1608. u1_dim1 + 1], &c__1);
  1609. }
  1610. if (wantu2) {
  1611. i__2 = *m - *p;
  1612. dswap_(&i__2, &u2[i__ * u2_dim1 + 1], &c__1, &u2[mini *
  1613. u2_dim1 + 1], &c__1);
  1614. }
  1615. if (wantv1t) {
  1616. dswap_(q, &v1t[i__ + v1t_dim1], ldv1t, &v1t[mini +
  1617. v1t_dim1], ldv1t);
  1618. }
  1619. if (wantv2t) {
  1620. i__2 = *m - *q;
  1621. dswap_(&i__2, &v2t[i__ + v2t_dim1], ldv2t, &v2t[mini +
  1622. v2t_dim1], ldv2t);
  1623. }
  1624. } else {
  1625. if (wantu1) {
  1626. dswap_(p, &u1[i__ + u1_dim1], ldu1, &u1[mini + u1_dim1],
  1627. ldu1);
  1628. }
  1629. if (wantu2) {
  1630. i__2 = *m - *p;
  1631. dswap_(&i__2, &u2[i__ + u2_dim1], ldu2, &u2[mini +
  1632. u2_dim1], ldu2);
  1633. }
  1634. if (wantv1t) {
  1635. dswap_(q, &v1t[i__ * v1t_dim1 + 1], &c__1, &v1t[mini *
  1636. v1t_dim1 + 1], &c__1);
  1637. }
  1638. if (wantv2t) {
  1639. i__2 = *m - *q;
  1640. dswap_(&i__2, &v2t[i__ * v2t_dim1 + 1], &c__1, &v2t[mini *
  1641. v2t_dim1 + 1], &c__1);
  1642. }
  1643. }
  1644. }
  1645. }
  1646. return;
  1647. /* End of DBBCSD */
  1648. } /* dbbcsd_ */