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 55 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 int logical;
  52. typedef short int shortlogical;
  53. typedef char logical1;
  54. typedef char integer1;
  55. #define TRUE_ (1)
  56. #define FALSE_ (0)
  57. /* Extern is for use with -E */
  58. #ifndef Extern
  59. #define Extern extern
  60. #endif
  61. /* I/O stuff */
  62. typedef int flag;
  63. typedef int ftnlen;
  64. typedef int ftnint;
  65. /*external read, write*/
  66. typedef struct
  67. { flag cierr;
  68. ftnint ciunit;
  69. flag ciend;
  70. char *cifmt;
  71. ftnint cirec;
  72. } cilist;
  73. /*internal read, write*/
  74. typedef struct
  75. { flag icierr;
  76. char *iciunit;
  77. flag iciend;
  78. char *icifmt;
  79. ftnint icirlen;
  80. ftnint icirnum;
  81. } icilist;
  82. /*open*/
  83. typedef struct
  84. { flag oerr;
  85. ftnint ounit;
  86. char *ofnm;
  87. ftnlen ofnmlen;
  88. char *osta;
  89. char *oacc;
  90. char *ofm;
  91. ftnint orl;
  92. char *oblnk;
  93. } olist;
  94. /*close*/
  95. typedef struct
  96. { flag cerr;
  97. ftnint cunit;
  98. char *csta;
  99. } cllist;
  100. /*rewind, backspace, endfile*/
  101. typedef struct
  102. { flag aerr;
  103. ftnint aunit;
  104. } alist;
  105. /* inquire */
  106. typedef struct
  107. { flag inerr;
  108. ftnint inunit;
  109. char *infile;
  110. ftnlen infilen;
  111. ftnint *inex; /*parameters in standard's order*/
  112. ftnint *inopen;
  113. ftnint *innum;
  114. ftnint *innamed;
  115. char *inname;
  116. ftnlen innamlen;
  117. char *inacc;
  118. ftnlen inacclen;
  119. char *inseq;
  120. ftnlen inseqlen;
  121. char *indir;
  122. ftnlen indirlen;
  123. char *infmt;
  124. ftnlen infmtlen;
  125. char *inform;
  126. ftnint informlen;
  127. char *inunf;
  128. ftnlen inunflen;
  129. ftnint *inrecl;
  130. ftnint *innrec;
  131. char *inblank;
  132. ftnlen inblanklen;
  133. } inlist;
  134. #define VOID void
  135. union Multitype { /* for multiple entry points */
  136. integer1 g;
  137. shortint h;
  138. integer i;
  139. /* longint j; */
  140. real r;
  141. doublereal d;
  142. complex c;
  143. doublecomplex z;
  144. };
  145. typedef union Multitype Multitype;
  146. struct Vardesc { /* for Namelist */
  147. char *name;
  148. char *addr;
  149. ftnlen *dims;
  150. int type;
  151. };
  152. typedef struct Vardesc Vardesc;
  153. struct Namelist {
  154. char *name;
  155. Vardesc **vars;
  156. int nvars;
  157. };
  158. typedef struct Namelist Namelist;
  159. #define abs(x) ((x) >= 0 ? (x) : -(x))
  160. #define dabs(x) (fabs(x))
  161. #define f2cmin(a,b) ((a) <= (b) ? (a) : (b))
  162. #define f2cmax(a,b) ((a) >= (b) ? (a) : (b))
  163. #define dmin(a,b) (f2cmin(a,b))
  164. #define dmax(a,b) (f2cmax(a,b))
  165. #define bit_test(a,b) ((a) >> (b) & 1)
  166. #define bit_clear(a,b) ((a) & ~((uinteger)1 << (b)))
  167. #define bit_set(a,b) ((a) | ((uinteger)1 << (b)))
  168. #define abort_() { sig_die("Fortran abort routine called", 1); }
  169. #define c_abs(z) (cabsf(Cf(z)))
  170. #define c_cos(R,Z) { pCf(R)=ccos(Cf(Z)); }
  171. #ifdef _MSC_VER
  172. #define c_div(c, a, b) {Cf(c)._Val[0] = (Cf(a)._Val[0]/Cf(b)._Val[0]); Cf(c)._Val[1]=(Cf(a)._Val[1]/Cf(b)._Val[1]);}
  173. #define z_div(c, a, b) {Cd(c)._Val[0] = (Cd(a)._Val[0]/Cd(b)._Val[0]); Cd(c)._Val[1]=(Cd(a)._Val[1]/df(b)._Val[1]);}
  174. #else
  175. #define c_div(c, a, b) {pCf(c) = Cf(a)/Cf(b);}
  176. #define z_div(c, a, b) {pCd(c) = Cd(a)/Cd(b);}
  177. #endif
  178. #define c_exp(R, Z) {pCf(R) = cexpf(Cf(Z));}
  179. #define c_log(R, Z) {pCf(R) = clogf(Cf(Z));}
  180. #define c_sin(R, Z) {pCf(R) = csinf(Cf(Z));}
  181. //#define c_sqrt(R, Z) {*(R) = csqrtf(Cf(Z));}
  182. #define c_sqrt(R, Z) {pCf(R) = csqrtf(Cf(Z));}
  183. #define d_abs(x) (fabs(*(x)))
  184. #define d_acos(x) (acos(*(x)))
  185. #define d_asin(x) (asin(*(x)))
  186. #define d_atan(x) (atan(*(x)))
  187. #define d_atn2(x, y) (atan2(*(x),*(y)))
  188. #define d_cnjg(R, Z) { pCd(R) = conj(Cd(Z)); }
  189. #define r_cnjg(R, Z) { pCf(R) = conjf(Cf(Z)); }
  190. #define d_cos(x) (cos(*(x)))
  191. #define d_cosh(x) (cosh(*(x)))
  192. #define d_dim(__a, __b) ( *(__a) > *(__b) ? *(__a) - *(__b) : 0.0 )
  193. #define d_exp(x) (exp(*(x)))
  194. #define d_imag(z) (cimag(Cd(z)))
  195. #define r_imag(z) (cimagf(Cf(z)))
  196. #define d_int(__x) (*(__x)>0 ? floor(*(__x)) : -floor(- *(__x)))
  197. #define r_int(__x) (*(__x)>0 ? floor(*(__x)) : -floor(- *(__x)))
  198. #define d_lg10(x) ( 0.43429448190325182765 * log(*(x)) )
  199. #define r_lg10(x) ( 0.43429448190325182765 * log(*(x)) )
  200. #define d_log(x) (log(*(x)))
  201. #define d_mod(x, y) (fmod(*(x), *(y)))
  202. #define u_nint(__x) ((__x)>=0 ? floor((__x) + .5) : -floor(.5 - (__x)))
  203. #define d_nint(x) u_nint(*(x))
  204. #define u_sign(__a,__b) ((__b) >= 0 ? ((__a) >= 0 ? (__a) : -(__a)) : -((__a) >= 0 ? (__a) : -(__a)))
  205. #define d_sign(a,b) u_sign(*(a),*(b))
  206. #define r_sign(a,b) u_sign(*(a),*(b))
  207. #define d_sin(x) (sin(*(x)))
  208. #define d_sinh(x) (sinh(*(x)))
  209. #define d_sqrt(x) (sqrt(*(x)))
  210. #define d_tan(x) (tan(*(x)))
  211. #define d_tanh(x) (tanh(*(x)))
  212. #define i_abs(x) abs(*(x))
  213. #define i_dnnt(x) ((integer)u_nint(*(x)))
  214. #define i_len(s, n) (n)
  215. #define i_nint(x) ((integer)u_nint(*(x)))
  216. #define i_sign(a,b) ((integer)u_sign((integer)*(a),(integer)*(b)))
  217. #define pow_dd(ap, bp) ( pow(*(ap), *(bp)))
  218. #define pow_si(B,E) spow_ui(*(B),*(E))
  219. #define pow_ri(B,E) spow_ui(*(B),*(E))
  220. #define pow_di(B,E) dpow_ui(*(B),*(E))
  221. #define pow_zi(p, a, b) {pCd(p) = zpow_ui(Cd(a), *(b));}
  222. #define pow_ci(p, a, b) {pCf(p) = cpow_ui(Cf(a), *(b));}
  223. #define pow_zz(R,A,B) {pCd(R) = cpow(Cd(A),*(B));}
  224. #define s_cat(lpp, rpp, rnp, np, llp) { ftnlen i, nc, ll; char *f__rp, *lp; ll = (llp); lp = (lpp); for(i=0; i < (int)*(np); ++i) { nc = ll; if((rnp)[i] < nc) nc = (rnp)[i]; ll -= nc; f__rp = (rpp)[i]; while(--nc >= 0) *lp++ = *(f__rp)++; } while(--ll >= 0) *lp++ = ' '; }
  225. #define s_cmp(a,b,c,d) ((integer)strncmp((a),(b),f2cmin((c),(d))))
  226. #define s_copy(A,B,C,D) { int __i,__m; for (__i=0, __m=f2cmin((C),(D)); __i<__m && (B)[__i] != 0; ++__i) (A)[__i] = (B)[__i]; }
  227. #define sig_die(s, kill) { exit(1); }
  228. #define s_stop(s, n) {exit(0);}
  229. static char junk[] = "\n@(#)LIBF77 VERSION 19990503\n";
  230. #define z_abs(z) (cabs(Cd(z)))
  231. #define z_exp(R, Z) {pCd(R) = cexp(Cd(Z));}
  232. #define z_sqrt(R, Z) {pCd(R) = csqrt(Cd(Z));}
  233. #define myexit_() break;
  234. #define mycycle() continue;
  235. #define myceiling(w) {ceil(w)}
  236. #define myhuge(w) {HUGE_VAL}
  237. //#define mymaxloc_(w,s,e,n) {if (sizeof(*(w)) == sizeof(double)) dmaxloc_((w),*(s),*(e),n); else dmaxloc_((w),*(s),*(e),n);}
  238. #define mymaxloc(w,s,e,n) {dmaxloc_(w,*(s),*(e),n)}
  239. /* procedure parameter types for -A and -C++ */
  240. #define F2C_proc_par_types 1
  241. #ifdef __cplusplus
  242. typedef logical (*L_fp)(...);
  243. #else
  244. typedef logical (*L_fp)();
  245. #endif
  246. static float spow_ui(float x, integer n) {
  247. float pow=1.0; unsigned long int u;
  248. if(n != 0) {
  249. if(n < 0) n = -n, x = 1/x;
  250. for(u = n; ; ) {
  251. if(u & 01) pow *= x;
  252. if(u >>= 1) x *= x;
  253. else break;
  254. }
  255. }
  256. return pow;
  257. }
  258. static double dpow_ui(double x, integer n) {
  259. double pow=1.0; unsigned long int u;
  260. if(n != 0) {
  261. if(n < 0) n = -n, x = 1/x;
  262. for(u = n; ; ) {
  263. if(u & 01) pow *= x;
  264. if(u >>= 1) x *= x;
  265. else break;
  266. }
  267. }
  268. return pow;
  269. }
  270. #ifdef _MSC_VER
  271. static _Fcomplex cpow_ui(complex x, integer n) {
  272. complex pow={1.0,0.0}; unsigned long int u;
  273. if(n != 0) {
  274. if(n < 0) n = -n, x.r = 1/x.r, x.i=1/x.i;
  275. for(u = n; ; ) {
  276. if(u & 01) pow.r *= x.r, pow.i *= x.i;
  277. if(u >>= 1) x.r *= x.r, x.i *= x.i;
  278. else break;
  279. }
  280. }
  281. _Fcomplex p={pow.r, pow.i};
  282. return p;
  283. }
  284. #else
  285. static _Complex float cpow_ui(_Complex float x, integer n) {
  286. _Complex float pow=1.0; unsigned long int u;
  287. if(n != 0) {
  288. if(n < 0) n = -n, x = 1/x;
  289. for(u = n; ; ) {
  290. if(u & 01) pow *= x;
  291. if(u >>= 1) x *= x;
  292. else break;
  293. }
  294. }
  295. return pow;
  296. }
  297. #endif
  298. #ifdef _MSC_VER
  299. static _Dcomplex zpow_ui(_Dcomplex x, integer n) {
  300. _Dcomplex pow={1.0,0.0}; unsigned long int u;
  301. if(n != 0) {
  302. if(n < 0) n = -n, x._Val[0] = 1/x._Val[0], x._Val[1] =1/x._Val[1];
  303. for(u = n; ; ) {
  304. if(u & 01) pow._Val[0] *= x._Val[0], pow._Val[1] *= x._Val[1];
  305. if(u >>= 1) x._Val[0] *= x._Val[0], x._Val[1] *= x._Val[1];
  306. else break;
  307. }
  308. }
  309. _Dcomplex p = {pow._Val[0], pow._Val[1]};
  310. return p;
  311. }
  312. #else
  313. static _Complex double zpow_ui(_Complex double x, integer n) {
  314. _Complex double pow=1.0; unsigned long int u;
  315. if(n != 0) {
  316. if(n < 0) n = -n, x = 1/x;
  317. for(u = n; ; ) {
  318. if(u & 01) pow *= x;
  319. if(u >>= 1) x *= x;
  320. else break;
  321. }
  322. }
  323. return pow;
  324. }
  325. #endif
  326. static integer pow_ii(integer x, integer n) {
  327. integer pow; unsigned long int u;
  328. if (n <= 0) {
  329. if (n == 0 || x == 1) pow = 1;
  330. else if (x != -1) pow = x == 0 ? 1/x : 0;
  331. else n = -n;
  332. }
  333. if ((n > 0) || !(n == 0 || x == 1 || x != -1)) {
  334. u = n;
  335. for(pow = 1; ; ) {
  336. if(u & 01) pow *= x;
  337. if(u >>= 1) x *= x;
  338. else break;
  339. }
  340. }
  341. return pow;
  342. }
  343. static integer dmaxloc_(double *w, integer s, integer e, integer *n)
  344. {
  345. double m; integer i, mi;
  346. for(m=w[s-1], mi=s, i=s+1; i<=e; i++)
  347. if (w[i-1]>m) mi=i ,m=w[i-1];
  348. return mi-s+1;
  349. }
  350. static integer smaxloc_(float *w, integer s, integer e, integer *n)
  351. {
  352. float m; integer i, mi;
  353. for(m=w[s-1], mi=s, i=s+1; i<=e; i++)
  354. if (w[i-1]>m) mi=i ,m=w[i-1];
  355. return mi-s+1;
  356. }
  357. static inline void cdotc_(complex *z, integer *n_, complex *x, integer *incx_, complex *y, integer *incy_) {
  358. integer n = *n_, incx = *incx_, incy = *incy_, i;
  359. #ifdef _MSC_VER
  360. _Fcomplex zdotc = {0.0, 0.0};
  361. if (incx == 1 && incy == 1) {
  362. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  363. zdotc._Val[0] += conjf(Cf(&x[i]))._Val[0] * Cf(&y[i])._Val[0];
  364. zdotc._Val[1] += conjf(Cf(&x[i]))._Val[1] * Cf(&y[i])._Val[1];
  365. }
  366. } else {
  367. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  368. zdotc._Val[0] += conjf(Cf(&x[i*incx]))._Val[0] * Cf(&y[i*incy])._Val[0];
  369. zdotc._Val[1] += conjf(Cf(&x[i*incx]))._Val[1] * Cf(&y[i*incy])._Val[1];
  370. }
  371. }
  372. pCf(z) = zdotc;
  373. }
  374. #else
  375. _Complex float zdotc = 0.0;
  376. if (incx == 1 && incy == 1) {
  377. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  378. zdotc += conjf(Cf(&x[i])) * Cf(&y[i]);
  379. }
  380. } else {
  381. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  382. zdotc += conjf(Cf(&x[i*incx])) * Cf(&y[i*incy]);
  383. }
  384. }
  385. pCf(z) = zdotc;
  386. }
  387. #endif
  388. static inline void zdotc_(doublecomplex *z, integer *n_, doublecomplex *x, integer *incx_, doublecomplex *y, integer *incy_) {
  389. integer n = *n_, incx = *incx_, incy = *incy_, i;
  390. #ifdef _MSC_VER
  391. _Dcomplex zdotc = {0.0, 0.0};
  392. if (incx == 1 && incy == 1) {
  393. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  394. zdotc._Val[0] += conj(Cd(&x[i]))._Val[0] * Cd(&y[i])._Val[0];
  395. zdotc._Val[1] += conj(Cd(&x[i]))._Val[1] * Cd(&y[i])._Val[1];
  396. }
  397. } else {
  398. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  399. zdotc._Val[0] += conj(Cd(&x[i*incx]))._Val[0] * Cd(&y[i*incy])._Val[0];
  400. zdotc._Val[1] += conj(Cd(&x[i*incx]))._Val[1] * Cd(&y[i*incy])._Val[1];
  401. }
  402. }
  403. pCd(z) = zdotc;
  404. }
  405. #else
  406. _Complex double zdotc = 0.0;
  407. if (incx == 1 && incy == 1) {
  408. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  409. zdotc += conj(Cd(&x[i])) * Cd(&y[i]);
  410. }
  411. } else {
  412. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  413. zdotc += conj(Cd(&x[i*incx])) * Cd(&y[i*incy]);
  414. }
  415. }
  416. pCd(z) = zdotc;
  417. }
  418. #endif
  419. static inline void cdotu_(complex *z, integer *n_, complex *x, integer *incx_, complex *y, integer *incy_) {
  420. integer n = *n_, incx = *incx_, incy = *incy_, i;
  421. #ifdef _MSC_VER
  422. _Fcomplex zdotc = {0.0, 0.0};
  423. if (incx == 1 && incy == 1) {
  424. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  425. zdotc._Val[0] += Cf(&x[i])._Val[0] * Cf(&y[i])._Val[0];
  426. zdotc._Val[1] += Cf(&x[i])._Val[1] * Cf(&y[i])._Val[1];
  427. }
  428. } else {
  429. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  430. zdotc._Val[0] += Cf(&x[i*incx])._Val[0] * Cf(&y[i*incy])._Val[0];
  431. zdotc._Val[1] += Cf(&x[i*incx])._Val[1] * Cf(&y[i*incy])._Val[1];
  432. }
  433. }
  434. pCf(z) = zdotc;
  435. }
  436. #else
  437. _Complex float zdotc = 0.0;
  438. if (incx == 1 && incy == 1) {
  439. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  440. zdotc += Cf(&x[i]) * Cf(&y[i]);
  441. }
  442. } else {
  443. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  444. zdotc += Cf(&x[i*incx]) * Cf(&y[i*incy]);
  445. }
  446. }
  447. pCf(z) = zdotc;
  448. }
  449. #endif
  450. static inline void zdotu_(doublecomplex *z, integer *n_, doublecomplex *x, integer *incx_, doublecomplex *y, integer *incy_) {
  451. integer n = *n_, incx = *incx_, incy = *incy_, i;
  452. #ifdef _MSC_VER
  453. _Dcomplex zdotc = {0.0, 0.0};
  454. if (incx == 1 && incy == 1) {
  455. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  456. zdotc._Val[0] += Cd(&x[i])._Val[0] * Cd(&y[i])._Val[0];
  457. zdotc._Val[1] += Cd(&x[i])._Val[1] * Cd(&y[i])._Val[1];
  458. }
  459. } else {
  460. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  461. zdotc._Val[0] += Cd(&x[i*incx])._Val[0] * Cd(&y[i*incy])._Val[0];
  462. zdotc._Val[1] += Cd(&x[i*incx])._Val[1] * Cd(&y[i*incy])._Val[1];
  463. }
  464. }
  465. pCd(z) = zdotc;
  466. }
  467. #else
  468. _Complex double zdotc = 0.0;
  469. if (incx == 1 && incy == 1) {
  470. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  471. zdotc += Cd(&x[i]) * Cd(&y[i]);
  472. }
  473. } else {
  474. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  475. zdotc += Cd(&x[i*incx]) * Cd(&y[i*incy]);
  476. }
  477. }
  478. pCd(z) = zdotc;
  479. }
  480. #endif
  481. /* -- translated by f2c (version 20000121).
  482. You must link the resulting object file with the libraries:
  483. -lf2c -lm (in that order)
  484. */
  485. /* Table of constant values */
  486. static doublereal c_b10 = -.125;
  487. static doublereal c_b35 = -1.;
  488. static integer c__1 = 1;
  489. /* > \brief \b DBBCSD */
  490. /* =========== DOCUMENTATION =========== */
  491. /* Online html documentation available at */
  492. /* http://www.netlib.org/lapack/explore-html/ */
  493. /* > \htmlonly */
  494. /* > Download DBBCSD + dependencies */
  495. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/dbbcsd.
  496. f"> */
  497. /* > [TGZ]</a> */
  498. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/dbbcsd.
  499. f"> */
  500. /* > [ZIP]</a> */
  501. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/dbbcsd.
  502. f"> */
  503. /* > [TXT]</a> */
  504. /* > \endhtmlonly */
  505. /* Definition: */
  506. /* =========== */
  507. /* SUBROUTINE DBBCSD( JOBU1, JOBU2, JOBV1T, JOBV2T, TRANS, M, P, Q, */
  508. /* THETA, PHI, U1, LDU1, U2, LDU2, V1T, LDV1T, */
  509. /* V2T, LDV2T, B11D, B11E, B12D, B12E, B21D, B21E, */
  510. /* B22D, B22E, WORK, LWORK, INFO ) */
  511. /* CHARACTER JOBU1, JOBU2, JOBV1T, JOBV2T, TRANS */
  512. /* INTEGER INFO, LDU1, LDU2, LDV1T, LDV2T, LWORK, M, P, Q */
  513. /* DOUBLE PRECISION B11D( * ), B11E( * ), B12D( * ), B12E( * ), */
  514. /* $ B21D( * ), B21E( * ), B22D( * ), B22E( * ), */
  515. /* $ PHI( * ), THETA( * ), WORK( * ) */
  516. /* DOUBLE PRECISION U1( LDU1, * ), U2( LDU2, * ), V1T( LDV1T, * ), */
  517. /* $ V2T( LDV2T, * ) */
  518. /* > \par Purpose: */
  519. /* ============= */
  520. /* > */
  521. /* > \verbatim */
  522. /* > */
  523. /* > DBBCSD computes the CS decomposition of an orthogonal matrix in */
  524. /* > bidiagonal-block form, */
  525. /* > */
  526. /* > */
  527. /* > [ B11 | B12 0 0 ] */
  528. /* > [ 0 | 0 -I 0 ] */
  529. /* > X = [----------------] */
  530. /* > [ B21 | B22 0 0 ] */
  531. /* > [ 0 | 0 0 I ] */
  532. /* > */
  533. /* > [ C | -S 0 0 ] */
  534. /* > [ U1 | ] [ 0 | 0 -I 0 ] [ V1 | ]**T */
  535. /* > = [---------] [---------------] [---------] . */
  536. /* > [ | U2 ] [ S | C 0 0 ] [ | V2 ] */
  537. /* > [ 0 | 0 0 I ] */
  538. /* > */
  539. /* > X is M-by-M, its top-left block is P-by-Q, and Q must be no larger */
  540. /* > than P, M-P, or M-Q. (If Q is not the smallest index, then X must be */
  541. /* > transposed and/or permuted. This can be done in constant time using */
  542. /* > the TRANS and SIGNS options. See DORCSD for details.) */
  543. /* > */
  544. /* > The bidiagonal matrices B11, B12, B21, and B22 are represented */
  545. /* > implicitly by angles THETA(1:Q) and PHI(1:Q-1). */
  546. /* > */
  547. /* > The orthogonal matrices U1, U2, V1T, and V2T are input/output. */
  548. /* > The input matrices are pre- or post-multiplied by the appropriate */
  549. /* > singular vector matrices. */
  550. /* > \endverbatim */
  551. /* Arguments: */
  552. /* ========== */
  553. /* > \param[in] JOBU1 */
  554. /* > \verbatim */
  555. /* > JOBU1 is CHARACTER */
  556. /* > = 'Y': U1 is updated; */
  557. /* > otherwise: U1 is not updated. */
  558. /* > \endverbatim */
  559. /* > */
  560. /* > \param[in] JOBU2 */
  561. /* > \verbatim */
  562. /* > JOBU2 is CHARACTER */
  563. /* > = 'Y': U2 is updated; */
  564. /* > otherwise: U2 is not updated. */
  565. /* > \endverbatim */
  566. /* > */
  567. /* > \param[in] JOBV1T */
  568. /* > \verbatim */
  569. /* > JOBV1T is CHARACTER */
  570. /* > = 'Y': V1T is updated; */
  571. /* > otherwise: V1T is not updated. */
  572. /* > \endverbatim */
  573. /* > */
  574. /* > \param[in] JOBV2T */
  575. /* > \verbatim */
  576. /* > JOBV2T is CHARACTER */
  577. /* > = 'Y': V2T is updated; */
  578. /* > otherwise: V2T is not updated. */
  579. /* > \endverbatim */
  580. /* > */
  581. /* > \param[in] TRANS */
  582. /* > \verbatim */
  583. /* > TRANS is CHARACTER */
  584. /* > = 'T': X, U1, U2, V1T, and V2T are stored in row-major */
  585. /* > order; */
  586. /* > otherwise: X, U1, U2, V1T, and V2T are stored in column- */
  587. /* > major order. */
  588. /* > \endverbatim */
  589. /* > */
  590. /* > \param[in] M */
  591. /* > \verbatim */
  592. /* > M is INTEGER */
  593. /* > The number of rows and columns in X, the orthogonal matrix in */
  594. /* > bidiagonal-block form. */
  595. /* > \endverbatim */
  596. /* > */
  597. /* > \param[in] P */
  598. /* > \verbatim */
  599. /* > P is INTEGER */
  600. /* > The number of rows in the top-left block of X. 0 <= P <= M. */
  601. /* > \endverbatim */
  602. /* > */
  603. /* > \param[in] Q */
  604. /* > \verbatim */
  605. /* > Q is INTEGER */
  606. /* > The number of columns in the top-left block of X. */
  607. /* > 0 <= Q <= MIN(P,M-P,M-Q). */
  608. /* > \endverbatim */
  609. /* > */
  610. /* > \param[in,out] THETA */
  611. /* > \verbatim */
  612. /* > THETA is DOUBLE PRECISION array, dimension (Q) */
  613. /* > On entry, the angles THETA(1),...,THETA(Q) that, along with */
  614. /* > PHI(1), ...,PHI(Q-1), define the matrix in bidiagonal-block */
  615. /* > form. On exit, the angles whose cosines and sines define the */
  616. /* > diagonal blocks in the CS decomposition. */
  617. /* > \endverbatim */
  618. /* > */
  619. /* > \param[in,out] PHI */
  620. /* > \verbatim */
  621. /* > PHI is DOUBLE PRECISION array, dimension (Q-1) */
  622. /* > The angles PHI(1),...,PHI(Q-1) that, along with THETA(1),..., */
  623. /* > THETA(Q), define the matrix in bidiagonal-block form. */
  624. /* > \endverbatim */
  625. /* > */
  626. /* > \param[in,out] U1 */
  627. /* > \verbatim */
  628. /* > U1 is DOUBLE PRECISION array, dimension (LDU1,P) */
  629. /* > On entry, a P-by-P matrix. On exit, U1 is postmultiplied */
  630. /* > by the left singular vector matrix common to [ B11 ; 0 ] and */
  631. /* > [ B12 0 0 ; 0 -I 0 0 ]. */
  632. /* > \endverbatim */
  633. /* > */
  634. /* > \param[in] LDU1 */
  635. /* > \verbatim */
  636. /* > LDU1 is INTEGER */
  637. /* > The leading dimension of the array U1, LDU1 >= MAX(1,P). */
  638. /* > \endverbatim */
  639. /* > */
  640. /* > \param[in,out] U2 */
  641. /* > \verbatim */
  642. /* > U2 is DOUBLE PRECISION array, dimension (LDU2,M-P) */
  643. /* > On entry, an (M-P)-by-(M-P) matrix. On exit, U2 is */
  644. /* > postmultiplied by the left singular vector matrix common to */
  645. /* > [ B21 ; 0 ] and [ B22 0 0 ; 0 0 I ]. */
  646. /* > \endverbatim */
  647. /* > */
  648. /* > \param[in] LDU2 */
  649. /* > \verbatim */
  650. /* > LDU2 is INTEGER */
  651. /* > The leading dimension of the array U2, LDU2 >= MAX(1,M-P). */
  652. /* > \endverbatim */
  653. /* > */
  654. /* > \param[in,out] V1T */
  655. /* > \verbatim */
  656. /* > V1T is DOUBLE PRECISION array, dimension (LDV1T,Q) */
  657. /* > On entry, a Q-by-Q matrix. On exit, V1T is premultiplied */
  658. /* > by the transpose of the right singular vector */
  659. /* > matrix common to [ B11 ; 0 ] and [ B21 ; 0 ]. */
  660. /* > \endverbatim */
  661. /* > */
  662. /* > \param[in] LDV1T */
  663. /* > \verbatim */
  664. /* > LDV1T is INTEGER */
  665. /* > The leading dimension of the array V1T, LDV1T >= MAX(1,Q). */
  666. /* > \endverbatim */
  667. /* > */
  668. /* > \param[in,out] V2T */
  669. /* > \verbatim */
  670. /* > V2T is DOUBLE PRECISION array, dimension (LDV2T,M-Q) */
  671. /* > On entry, an (M-Q)-by-(M-Q) matrix. On exit, V2T is */
  672. /* > premultiplied by the transpose of the right */
  673. /* > singular vector matrix common to [ B12 0 0 ; 0 -I 0 ] and */
  674. /* > [ B22 0 0 ; 0 0 I ]. */
  675. /* > \endverbatim */
  676. /* > */
  677. /* > \param[in] LDV2T */
  678. /* > \verbatim */
  679. /* > LDV2T is INTEGER */
  680. /* > The leading dimension of the array V2T, LDV2T >= MAX(1,M-Q). */
  681. /* > \endverbatim */
  682. /* > */
  683. /* > \param[out] B11D */
  684. /* > \verbatim */
  685. /* > B11D is DOUBLE PRECISION array, dimension (Q) */
  686. /* > When DBBCSD converges, B11D contains the cosines of THETA(1), */
  687. /* > ..., THETA(Q). If DBBCSD fails to converge, then B11D */
  688. /* > contains the diagonal of the partially reduced top-left */
  689. /* > block. */
  690. /* > \endverbatim */
  691. /* > */
  692. /* > \param[out] B11E */
  693. /* > \verbatim */
  694. /* > B11E is DOUBLE PRECISION array, dimension (Q-1) */
  695. /* > When DBBCSD converges, B11E contains zeros. If DBBCSD fails */
  696. /* > to converge, then B11E contains the superdiagonal of the */
  697. /* > partially reduced top-left block. */
  698. /* > \endverbatim */
  699. /* > */
  700. /* > \param[out] B12D */
  701. /* > \verbatim */
  702. /* > B12D is DOUBLE PRECISION array, dimension (Q) */
  703. /* > When DBBCSD converges, B12D contains the negative sines of */
  704. /* > THETA(1), ..., THETA(Q). If DBBCSD fails to converge, then */
  705. /* > B12D contains the diagonal of the partially reduced top-right */
  706. /* > block. */
  707. /* > \endverbatim */
  708. /* > */
  709. /* > \param[out] B12E */
  710. /* > \verbatim */
  711. /* > B12E is DOUBLE PRECISION array, dimension (Q-1) */
  712. /* > When DBBCSD converges, B12E contains zeros. If DBBCSD fails */
  713. /* > to converge, then B12E contains the subdiagonal of the */
  714. /* > partially reduced top-right block. */
  715. /* > \endverbatim */
  716. /* > */
  717. /* > \param[out] B21D */
  718. /* > \verbatim */
  719. /* > B21D is DOUBLE PRECISION array, dimension (Q) */
  720. /* > When DBBCSD converges, B21D contains the negative sines of */
  721. /* > THETA(1), ..., THETA(Q). If DBBCSD fails to converge, then */
  722. /* > B21D contains the diagonal of the partially reduced bottom-left */
  723. /* > block. */
  724. /* > \endverbatim */
  725. /* > */
  726. /* > \param[out] B21E */
  727. /* > \verbatim */
  728. /* > B21E is DOUBLE PRECISION array, dimension (Q-1) */
  729. /* > When DBBCSD converges, B21E contains zeros. If DBBCSD fails */
  730. /* > to converge, then B21E contains the subdiagonal of the */
  731. /* > partially reduced bottom-left block. */
  732. /* > \endverbatim */
  733. /* > */
  734. /* > \param[out] B22D */
  735. /* > \verbatim */
  736. /* > B22D is DOUBLE PRECISION array, dimension (Q) */
  737. /* > When DBBCSD converges, B22D contains the negative sines of */
  738. /* > THETA(1), ..., THETA(Q). If DBBCSD fails to converge, then */
  739. /* > B22D contains the diagonal of the partially reduced bottom-right */
  740. /* > block. */
  741. /* > \endverbatim */
  742. /* > */
  743. /* > \param[out] B22E */
  744. /* > \verbatim */
  745. /* > B22E is DOUBLE PRECISION array, dimension (Q-1) */
  746. /* > When DBBCSD converges, B22E contains zeros. If DBBCSD fails */
  747. /* > to converge, then B22E contains the subdiagonal of the */
  748. /* > partially reduced bottom-right block. */
  749. /* > \endverbatim */
  750. /* > */
  751. /* > \param[out] WORK */
  752. /* > \verbatim */
  753. /* > WORK is DOUBLE PRECISION array, dimension (MAX(1,LWORK)) */
  754. /* > On exit, if INFO = 0, WORK(1) returns the optimal LWORK. */
  755. /* > \endverbatim */
  756. /* > */
  757. /* > \param[in] LWORK */
  758. /* > \verbatim */
  759. /* > LWORK is INTEGER */
  760. /* > The dimension of the array WORK. LWORK >= MAX(1,8*Q). */
  761. /* > */
  762. /* > If LWORK = -1, then a workspace query is assumed; the */
  763. /* > routine only calculates the optimal size of the WORK array, */
  764. /* > returns this value as the first entry of the work array, and */
  765. /* > no error message related to LWORK is issued by XERBLA. */
  766. /* > \endverbatim */
  767. /* > */
  768. /* > \param[out] INFO */
  769. /* > \verbatim */
  770. /* > INFO is INTEGER */
  771. /* > = 0: successful exit. */
  772. /* > < 0: if INFO = -i, the i-th argument had an illegal value. */
  773. /* > > 0: if DBBCSD did not converge, INFO specifies the number */
  774. /* > of nonzero entries in PHI, and B11D, B11E, etc., */
  775. /* > contain the partially reduced matrix. */
  776. /* > \endverbatim */
  777. /* > \par Internal Parameters: */
  778. /* ========================= */
  779. /* > */
  780. /* > \verbatim */
  781. /* > TOLMUL DOUBLE PRECISION, default = MAX(10,MIN(100,EPS**(-1/8))) */
  782. /* > TOLMUL controls the convergence criterion of the QR loop. */
  783. /* > Angles THETA(i), PHI(i) are rounded to 0 or PI/2 when they */
  784. /* > are within TOLMUL*EPS of either bound. */
  785. /* > \endverbatim */
  786. /* > \par References: */
  787. /* ================ */
  788. /* > */
  789. /* > [1] Brian D. Sutton. Computing the complete CS decomposition. Numer. */
  790. /* > Algorithms, 50(1):33-65, 2009. */
  791. /* Authors: */
  792. /* ======== */
  793. /* > \author Univ. of Tennessee */
  794. /* > \author Univ. of California Berkeley */
  795. /* > \author Univ. of Colorado Denver */
  796. /* > \author NAG Ltd. */
  797. /* > \date June 2016 */
  798. /* > \ingroup doubleOTHERcomputational */
  799. /* ===================================================================== */
  800. /* Subroutine */ int dbbcsd_(char *jobu1, char *jobu2, char *jobv1t, char *
  801. jobv2t, char *trans, integer *m, integer *p, integer *q, doublereal *
  802. theta, doublereal *phi, doublereal *u1, integer *ldu1, doublereal *u2,
  803. integer *ldu2, doublereal *v1t, integer *ldv1t, doublereal *v2t,
  804. integer *ldv2t, doublereal *b11d, doublereal *b11e, doublereal *b12d,
  805. doublereal *b12e, doublereal *b21d, doublereal *b21e, doublereal *
  806. b22d, doublereal *b22e, doublereal *work, integer *lwork, integer *
  807. info)
  808. {
  809. /* System generated locals */
  810. integer u1_dim1, u1_offset, u2_dim1, u2_offset, v1t_dim1, v1t_offset,
  811. v2t_dim1, v2t_offset, i__1, i__2;
  812. doublereal d__1, d__2, d__3, d__4;
  813. /* Local variables */
  814. integer imin, mini, imax, iter;
  815. doublereal unfl, temp;
  816. logical colmajor;
  817. doublereal thetamin, thetamax;
  818. logical restart11, restart12, restart21, restart22;
  819. extern /* Subroutine */ int dlas2_(doublereal *, doublereal *, doublereal
  820. *, doublereal *, doublereal *);
  821. integer lworkmin, iu1cs, iu2cs, iu1sn, iu2sn, lworkopt, i__, j;
  822. doublereal r__;
  823. extern /* Subroutine */ int dscal_(integer *, doublereal *, doublereal *,
  824. integer *);
  825. extern logical lsame_(char *, char *);
  826. extern /* Subroutine */ int dlasr_(char *, char *, char *, integer *,
  827. integer *, doublereal *, doublereal *, doublereal *, integer *), dswap_(integer *, doublereal *, integer *
  828. , doublereal *, integer *);
  829. integer maxit;
  830. doublereal dummy, x1, x2, y1, y2;
  831. integer iv1tcs, iv2tcs;
  832. logical wantu1, wantu2;
  833. integer iv1tsn, iv2tsn;
  834. extern doublereal dlamch_(char *);
  835. doublereal mu, nu, sigma11, sigma21;
  836. extern /* Subroutine */ int xerbla_(char *, integer *, ftnlen);
  837. doublereal thresh, tolmul;
  838. extern /* Subroutine */ int mecago_();
  839. logical lquery;
  840. doublereal b11bulge;
  841. logical wantv1t, wantv2t;
  842. doublereal b12bulge, b21bulge, b22bulge, eps, tol;
  843. extern /* Subroutine */ int dlartgp_(doublereal *, doublereal *,
  844. doublereal *, doublereal *, doublereal *), dlartgs_(doublereal *,
  845. doublereal *, doublereal *, doublereal *, doublereal *);
  846. /* -- LAPACK computational routine (version 3.7.1) -- */
  847. /* -- LAPACK is a software package provided by Univ. of Tennessee, -- */
  848. /* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- */
  849. /* June 2016 */
  850. /* =================================================================== */
  851. /* Test input arguments */
  852. /* Parameter adjustments */
  853. --theta;
  854. --phi;
  855. u1_dim1 = *ldu1;
  856. u1_offset = 1 + u1_dim1 * 1;
  857. u1 -= u1_offset;
  858. u2_dim1 = *ldu2;
  859. u2_offset = 1 + u2_dim1 * 1;
  860. u2 -= u2_offset;
  861. v1t_dim1 = *ldv1t;
  862. v1t_offset = 1 + v1t_dim1 * 1;
  863. v1t -= v1t_offset;
  864. v2t_dim1 = *ldv2t;
  865. v2t_offset = 1 + v2t_dim1 * 1;
  866. v2t -= v2t_offset;
  867. --b11d;
  868. --b11e;
  869. --b12d;
  870. --b12e;
  871. --b21d;
  872. --b21e;
  873. --b22d;
  874. --b22e;
  875. --work;
  876. /* Function Body */
  877. *info = 0;
  878. lquery = *lwork == -1;
  879. wantu1 = lsame_(jobu1, "Y");
  880. wantu2 = lsame_(jobu2, "Y");
  881. wantv1t = lsame_(jobv1t, "Y");
  882. wantv2t = lsame_(jobv2t, "Y");
  883. colmajor = ! lsame_(trans, "T");
  884. if (*m < 0) {
  885. *info = -6;
  886. } else if (*p < 0 || *p > *m) {
  887. *info = -7;
  888. } else if (*q < 0 || *q > *m) {
  889. *info = -8;
  890. } else if (*q > *p || *q > *m - *p || *q > *m - *q) {
  891. *info = -8;
  892. } else if (wantu1 && *ldu1 < *p) {
  893. *info = -12;
  894. } else if (wantu2 && *ldu2 < *m - *p) {
  895. *info = -14;
  896. } else if (wantv1t && *ldv1t < *q) {
  897. *info = -16;
  898. } else if (wantv2t && *ldv2t < *m - *q) {
  899. *info = -18;
  900. }
  901. /* Quick return if Q = 0 */
  902. if (*info == 0 && *q == 0) {
  903. lworkmin = 1;
  904. work[1] = (doublereal) lworkmin;
  905. return 0;
  906. }
  907. /* Compute workspace */
  908. if (*info == 0) {
  909. iu1cs = 1;
  910. iu1sn = iu1cs + *q;
  911. iu2cs = iu1sn + *q;
  912. iu2sn = iu2cs + *q;
  913. iv1tcs = iu2sn + *q;
  914. iv1tsn = iv1tcs + *q;
  915. iv2tcs = iv1tsn + *q;
  916. iv2tsn = iv2tcs + *q;
  917. lworkopt = iv2tsn + *q - 1;
  918. lworkmin = lworkopt;
  919. work[1] = (doublereal) lworkopt;
  920. if (*lwork < lworkmin && ! lquery) {
  921. *info = -28;
  922. }
  923. }
  924. if (*info != 0) {
  925. i__1 = -(*info);
  926. xerbla_("DBBCSD", &i__1, (ftnlen)6);
  927. return 0;
  928. } else if (lquery) {
  929. return 0;
  930. }
  931. /* Get machine constants */
  932. eps = dlamch_("Epsilon");
  933. unfl = dlamch_("Safe minimum");
  934. /* Computing MAX */
  935. /* Computing MIN */
  936. d__3 = 100., d__4 = pow_dd(&eps, &c_b10);
  937. d__1 = 10., d__2 = f2cmin(d__3,d__4);
  938. tolmul = f2cmax(d__1,d__2);
  939. tol = tolmul * eps;
  940. /* Computing MAX */
  941. d__1 = tol, d__2 = *q * 6 * *q * unfl;
  942. thresh = f2cmax(d__1,d__2);
  943. /* Test for negligible sines or cosines */
  944. i__1 = *q;
  945. for (i__ = 1; i__ <= i__1; ++i__) {
  946. if (theta[i__] < thresh) {
  947. theta[i__] = 0.;
  948. } else if (theta[i__] > 1.57079632679489662 - thresh) {
  949. theta[i__] = 1.57079632679489662;
  950. }
  951. }
  952. i__1 = *q - 1;
  953. for (i__ = 1; i__ <= i__1; ++i__) {
  954. if (phi[i__] < thresh) {
  955. phi[i__] = 0.;
  956. } else if (phi[i__] > 1.57079632679489662 - thresh) {
  957. phi[i__] = 1.57079632679489662;
  958. }
  959. }
  960. /* Initial deflation */
  961. imax = *q;
  962. while(imax > 1) {
  963. if (phi[imax - 1] != 0.) {
  964. myexit_();
  965. }
  966. --imax;
  967. }
  968. imin = imax - 1;
  969. if (imin > 1) {
  970. while(phi[imin - 1] != 0.) {
  971. --imin;
  972. if (imin <= 1) {
  973. myexit_();
  974. }
  975. }
  976. }
  977. /* Initialize iteration counter */
  978. maxit = *q * 6 * *q;
  979. iter = 0;
  980. /* Begin main iteration loop */
  981. while(imax > 1) {
  982. /* Compute the matrix entries */
  983. b11d[imin] = cos(theta[imin]);
  984. b21d[imin] = -sin(theta[imin]);
  985. i__1 = imax - 1;
  986. for (i__ = imin; i__ <= i__1; ++i__) {
  987. b11e[i__] = -sin(theta[i__]) * sin(phi[i__]);
  988. b11d[i__ + 1] = cos(theta[i__ + 1]) * cos(phi[i__]);
  989. b12d[i__] = sin(theta[i__]) * cos(phi[i__]);
  990. b12e[i__] = cos(theta[i__ + 1]) * sin(phi[i__]);
  991. b21e[i__] = -cos(theta[i__]) * sin(phi[i__]);
  992. b21d[i__ + 1] = -sin(theta[i__ + 1]) * cos(phi[i__]);
  993. b22d[i__] = cos(theta[i__]) * cos(phi[i__]);
  994. b22e[i__] = -sin(theta[i__ + 1]) * sin(phi[i__]);
  995. }
  996. b12d[imax] = sin(theta[imax]);
  997. b22d[imax] = cos(theta[imax]);
  998. /* Abort if not converging; otherwise, increment ITER */
  999. if (iter > maxit) {
  1000. *info = 0;
  1001. i__1 = *q;
  1002. for (i__ = 1; i__ <= i__1; ++i__) {
  1003. if (phi[i__] != 0.) {
  1004. ++(*info);
  1005. }
  1006. }
  1007. return 0;
  1008. }
  1009. iter = iter + imax - imin;
  1010. /* Compute shifts */
  1011. thetamax = theta[imin];
  1012. thetamin = theta[imin];
  1013. i__1 = imax;
  1014. for (i__ = imin + 1; i__ <= i__1; ++i__) {
  1015. if (theta[i__] > thetamax) {
  1016. thetamax = theta[i__];
  1017. }
  1018. if (theta[i__] < thetamin) {
  1019. thetamin = theta[i__];
  1020. }
  1021. }
  1022. if (thetamax > 1.57079632679489662 - thresh) {
  1023. /* Zero on diagonals of B11 and B22; induce deflation with a */
  1024. /* zero shift */
  1025. mu = 0.;
  1026. nu = 1.;
  1027. } else if (thetamin < thresh) {
  1028. /* Zero on diagonals of B12 and B22; induce deflation with a */
  1029. /* zero shift */
  1030. mu = 1.;
  1031. nu = 0.;
  1032. } else {
  1033. /* Compute shifts for B11 and B21 and use the lesser */
  1034. dlas2_(&b11d[imax - 1], &b11e[imax - 1], &b11d[imax], &sigma11, &
  1035. dummy);
  1036. dlas2_(&b21d[imax - 1], &b21e[imax - 1], &b21d[imax], &sigma21, &
  1037. dummy);
  1038. if (sigma11 <= sigma21) {
  1039. mu = sigma11;
  1040. /* Computing 2nd power */
  1041. d__1 = mu;
  1042. nu = sqrt(1. - d__1 * d__1);
  1043. if (mu < thresh) {
  1044. mu = 0.;
  1045. nu = 1.;
  1046. }
  1047. } else {
  1048. nu = sigma21;
  1049. /* Computing 2nd power */
  1050. d__1 = nu;
  1051. mu = sqrt(1.f - d__1 * d__1);
  1052. if (nu < thresh) {
  1053. mu = 1.;
  1054. nu = 0.;
  1055. }
  1056. }
  1057. }
  1058. /* Rotate to produce bulges in B11 and B21 */
  1059. if (mu <= nu) {
  1060. dlartgs_(&b11d[imin], &b11e[imin], &mu, &work[iv1tcs + imin - 1],
  1061. &work[iv1tsn + imin - 1]);
  1062. } else {
  1063. dlartgs_(&b21d[imin], &b21e[imin], &nu, &work[iv1tcs + imin - 1],
  1064. &work[iv1tsn + imin - 1]);
  1065. }
  1066. temp = work[iv1tcs + imin - 1] * b11d[imin] + work[iv1tsn + imin - 1]
  1067. * b11e[imin];
  1068. b11e[imin] = work[iv1tcs + imin - 1] * b11e[imin] - work[iv1tsn +
  1069. imin - 1] * b11d[imin];
  1070. b11d[imin] = temp;
  1071. b11bulge = work[iv1tsn + imin - 1] * b11d[imin + 1];
  1072. b11d[imin + 1] = work[iv1tcs + imin - 1] * b11d[imin + 1];
  1073. temp = work[iv1tcs + imin - 1] * b21d[imin] + work[iv1tsn + imin - 1]
  1074. * b21e[imin];
  1075. b21e[imin] = work[iv1tcs + imin - 1] * b21e[imin] - work[iv1tsn +
  1076. imin - 1] * b21d[imin];
  1077. b21d[imin] = temp;
  1078. b21bulge = work[iv1tsn + imin - 1] * b21d[imin + 1];
  1079. b21d[imin + 1] = work[iv1tcs + imin - 1] * b21d[imin + 1];
  1080. /* Compute THETA(IMIN) */
  1081. /* Computing 2nd power */
  1082. d__1 = b21d[imin];
  1083. /* Computing 2nd power */
  1084. d__2 = b21bulge;
  1085. /* Computing 2nd power */
  1086. d__3 = b11d[imin];
  1087. /* Computing 2nd power */
  1088. d__4 = b11bulge;
  1089. theta[imin] = atan2(sqrt(d__1 * d__1 + d__2 * d__2), sqrt(d__3 * d__3
  1090. + d__4 * d__4));
  1091. /* Chase the bulges in B11(IMIN+1,IMIN) and B21(IMIN+1,IMIN) */
  1092. /* Computing 2nd power */
  1093. d__1 = b11d[imin];
  1094. /* Computing 2nd power */
  1095. d__2 = b11bulge;
  1096. /* Computing 2nd power */
  1097. d__3 = thresh;
  1098. if (d__1 * d__1 + d__2 * d__2 > d__3 * d__3) {
  1099. dlartgp_(&b11bulge, &b11d[imin], &work[iu1sn + imin - 1], &work[
  1100. iu1cs + imin - 1], &r__);
  1101. } else if (mu <= nu) {
  1102. dlartgs_(&b11e[imin], &b11d[imin + 1], &mu, &work[iu1cs + imin -
  1103. 1], &work[iu1sn + imin - 1]);
  1104. } else {
  1105. dlartgs_(&b12d[imin], &b12e[imin], &nu, &work[iu1cs + imin - 1], &
  1106. work[iu1sn + imin - 1]);
  1107. }
  1108. /* Computing 2nd power */
  1109. d__1 = b21d[imin];
  1110. /* Computing 2nd power */
  1111. d__2 = b21bulge;
  1112. /* Computing 2nd power */
  1113. d__3 = thresh;
  1114. if (d__1 * d__1 + d__2 * d__2 > d__3 * d__3) {
  1115. dlartgp_(&b21bulge, &b21d[imin], &work[iu2sn + imin - 1], &work[
  1116. iu2cs + imin - 1], &r__);
  1117. } else if (nu < mu) {
  1118. dlartgs_(&b21e[imin], &b21d[imin + 1], &nu, &work[iu2cs + imin -
  1119. 1], &work[iu2sn + imin - 1]);
  1120. } else {
  1121. dlartgs_(&b22d[imin], &b22e[imin], &mu, &work[iu2cs + imin - 1], &
  1122. work[iu2sn + imin - 1]);
  1123. }
  1124. work[iu2cs + imin - 1] = -work[iu2cs + imin - 1];
  1125. work[iu2sn + imin - 1] = -work[iu2sn + imin - 1];
  1126. temp = work[iu1cs + imin - 1] * b11e[imin] + work[iu1sn + imin - 1] *
  1127. b11d[imin + 1];
  1128. b11d[imin + 1] = work[iu1cs + imin - 1] * b11d[imin + 1] - work[iu1sn
  1129. + imin - 1] * b11e[imin];
  1130. b11e[imin] = temp;
  1131. if (imax > imin + 1) {
  1132. b11bulge = work[iu1sn + imin - 1] * b11e[imin + 1];
  1133. b11e[imin + 1] = work[iu1cs + imin - 1] * b11e[imin + 1];
  1134. }
  1135. temp = work[iu1cs + imin - 1] * b12d[imin] + work[iu1sn + imin - 1] *
  1136. b12e[imin];
  1137. b12e[imin] = work[iu1cs + imin - 1] * b12e[imin] - work[iu1sn + imin
  1138. - 1] * b12d[imin];
  1139. b12d[imin] = temp;
  1140. b12bulge = work[iu1sn + imin - 1] * b12d[imin + 1];
  1141. b12d[imin + 1] = work[iu1cs + imin - 1] * b12d[imin + 1];
  1142. temp = work[iu2cs + imin - 1] * b21e[imin] + work[iu2sn + imin - 1] *
  1143. b21d[imin + 1];
  1144. b21d[imin + 1] = work[iu2cs + imin - 1] * b21d[imin + 1] - work[iu2sn
  1145. + imin - 1] * b21e[imin];
  1146. b21e[imin] = temp;
  1147. if (imax > imin + 1) {
  1148. b21bulge = work[iu2sn + imin - 1] * b21e[imin + 1];
  1149. b21e[imin + 1] = work[iu2cs + imin - 1] * b21e[imin + 1];
  1150. }
  1151. temp = work[iu2cs + imin - 1] * b22d[imin] + work[iu2sn + imin - 1] *
  1152. b22e[imin];
  1153. b22e[imin] = work[iu2cs + imin - 1] * b22e[imin] - work[iu2sn + imin
  1154. - 1] * b22d[imin];
  1155. b22d[imin] = temp;
  1156. b22bulge = work[iu2sn + imin - 1] * b22d[imin + 1];
  1157. b22d[imin + 1] = work[iu2cs + imin - 1] * b22d[imin + 1];
  1158. /* Inner loop: chase bulges from B11(IMIN,IMIN+2), */
  1159. /* B12(IMIN,IMIN+1), B21(IMIN,IMIN+2), and B22(IMIN,IMIN+1) to */
  1160. /* bottom-right */
  1161. i__1 = imax - 1;
  1162. for (i__ = imin + 1; i__ <= i__1; ++i__) {
  1163. /* Compute PHI(I-1) */
  1164. x1 = sin(theta[i__ - 1]) * b11e[i__ - 1] + cos(theta[i__ - 1]) *
  1165. b21e[i__ - 1];
  1166. x2 = sin(theta[i__ - 1]) * b11bulge + cos(theta[i__ - 1]) *
  1167. b21bulge;
  1168. y1 = sin(theta[i__ - 1]) * b12d[i__ - 1] + cos(theta[i__ - 1]) *
  1169. b22d[i__ - 1];
  1170. y2 = sin(theta[i__ - 1]) * b12bulge + cos(theta[i__ - 1]) *
  1171. b22bulge;
  1172. /* Computing 2nd power */
  1173. d__1 = x1;
  1174. /* Computing 2nd power */
  1175. d__2 = x2;
  1176. /* Computing 2nd power */
  1177. d__3 = y1;
  1178. /* Computing 2nd power */
  1179. d__4 = y2;
  1180. phi[i__ - 1] = atan2(sqrt(d__1 * d__1 + d__2 * d__2), sqrt(d__3 *
  1181. d__3 + d__4 * d__4));
  1182. /* Determine if there are bulges to chase or if a new direct */
  1183. /* summand has been reached */
  1184. /* Computing 2nd power */
  1185. d__1 = b11e[i__ - 1];
  1186. /* Computing 2nd power */
  1187. d__2 = b11bulge;
  1188. /* Computing 2nd power */
  1189. d__3 = thresh;
  1190. restart11 = d__1 * d__1 + d__2 * d__2 <= d__3 * d__3;
  1191. /* Computing 2nd power */
  1192. d__1 = b21e[i__ - 1];
  1193. /* Computing 2nd power */
  1194. d__2 = b21bulge;
  1195. /* Computing 2nd power */
  1196. d__3 = thresh;
  1197. restart21 = d__1 * d__1 + d__2 * d__2 <= d__3 * d__3;
  1198. /* Computing 2nd power */
  1199. d__1 = b12d[i__ - 1];
  1200. /* Computing 2nd power */
  1201. d__2 = b12bulge;
  1202. /* Computing 2nd power */
  1203. d__3 = thresh;
  1204. restart12 = d__1 * d__1 + d__2 * d__2 <= d__3 * d__3;
  1205. /* Computing 2nd power */
  1206. d__1 = b22d[i__ - 1];
  1207. /* Computing 2nd power */
  1208. d__2 = b22bulge;
  1209. /* Computing 2nd power */
  1210. d__3 = thresh;
  1211. restart22 = d__1 * d__1 + d__2 * d__2 <= d__3 * d__3;
  1212. /* If possible, chase bulges from B11(I-1,I+1), B12(I-1,I), */
  1213. /* B21(I-1,I+1), and B22(I-1,I). If necessary, restart bulge- */
  1214. /* chasing by applying the original shift again. */
  1215. if (! restart11 && ! restart21) {
  1216. dlartgp_(&x2, &x1, &work[iv1tsn + i__ - 1], &work[iv1tcs +
  1217. i__ - 1], &r__);
  1218. } else if (! restart11 && restart21) {
  1219. dlartgp_(&b11bulge, &b11e[i__ - 1], &work[iv1tsn + i__ - 1], &
  1220. work[iv1tcs + i__ - 1], &r__);
  1221. } else if (restart11 && ! restart21) {
  1222. dlartgp_(&b21bulge, &b21e[i__ - 1], &work[iv1tsn + i__ - 1], &
  1223. work[iv1tcs + i__ - 1], &r__);
  1224. } else if (mu <= nu) {
  1225. dlartgs_(&b11d[i__], &b11e[i__], &mu, &work[iv1tcs + i__ - 1],
  1226. &work[iv1tsn + i__ - 1]);
  1227. } else {
  1228. dlartgs_(&b21d[i__], &b21e[i__], &nu, &work[iv1tcs + i__ - 1],
  1229. &work[iv1tsn + i__ - 1]);
  1230. }
  1231. work[iv1tcs + i__ - 1] = -work[iv1tcs + i__ - 1];
  1232. work[iv1tsn + i__ - 1] = -work[iv1tsn + i__ - 1];
  1233. if (! restart12 && ! restart22) {
  1234. dlartgp_(&y2, &y1, &work[iv2tsn + i__ - 2], &work[iv2tcs +
  1235. i__ - 2], &r__);
  1236. } else if (! restart12 && restart22) {
  1237. dlartgp_(&b12bulge, &b12d[i__ - 1], &work[iv2tsn + i__ - 2], &
  1238. work[iv2tcs + i__ - 2], &r__);
  1239. } else if (restart12 && ! restart22) {
  1240. dlartgp_(&b22bulge, &b22d[i__ - 1], &work[iv2tsn + i__ - 2], &
  1241. work[iv2tcs + i__ - 2], &r__);
  1242. } else if (nu < mu) {
  1243. dlartgs_(&b12e[i__ - 1], &b12d[i__], &nu, &work[iv2tcs + i__
  1244. - 2], &work[iv2tsn + i__ - 2]);
  1245. } else {
  1246. dlartgs_(&b22e[i__ - 1], &b22d[i__], &mu, &work[iv2tcs + i__
  1247. - 2], &work[iv2tsn + i__ - 2]);
  1248. }
  1249. temp = work[iv1tcs + i__ - 1] * b11d[i__] + work[iv1tsn + i__ - 1]
  1250. * b11e[i__];
  1251. b11e[i__] = work[iv1tcs + i__ - 1] * b11e[i__] - work[iv1tsn +
  1252. i__ - 1] * b11d[i__];
  1253. b11d[i__] = temp;
  1254. b11bulge = work[iv1tsn + i__ - 1] * b11d[i__ + 1];
  1255. b11d[i__ + 1] = work[iv1tcs + i__ - 1] * b11d[i__ + 1];
  1256. temp = work[iv1tcs + i__ - 1] * b21d[i__] + work[iv1tsn + i__ - 1]
  1257. * b21e[i__];
  1258. b21e[i__] = work[iv1tcs + i__ - 1] * b21e[i__] - work[iv1tsn +
  1259. i__ - 1] * b21d[i__];
  1260. b21d[i__] = temp;
  1261. b21bulge = work[iv1tsn + i__ - 1] * b21d[i__ + 1];
  1262. b21d[i__ + 1] = work[iv1tcs + i__ - 1] * b21d[i__ + 1];
  1263. temp = work[iv2tcs + i__ - 2] * b12e[i__ - 1] + work[iv2tsn + i__
  1264. - 2] * b12d[i__];
  1265. b12d[i__] = work[iv2tcs + i__ - 2] * b12d[i__] - work[iv2tsn +
  1266. i__ - 2] * b12e[i__ - 1];
  1267. b12e[i__ - 1] = temp;
  1268. b12bulge = work[iv2tsn + i__ - 2] * b12e[i__];
  1269. b12e[i__] = work[iv2tcs + i__ - 2] * b12e[i__];
  1270. temp = work[iv2tcs + i__ - 2] * b22e[i__ - 1] + work[iv2tsn + i__
  1271. - 2] * b22d[i__];
  1272. b22d[i__] = work[iv2tcs + i__ - 2] * b22d[i__] - work[iv2tsn +
  1273. i__ - 2] * b22e[i__ - 1];
  1274. b22e[i__ - 1] = temp;
  1275. b22bulge = work[iv2tsn + i__ - 2] * b22e[i__];
  1276. b22e[i__] = work[iv2tcs + i__ - 2] * b22e[i__];
  1277. /* Compute THETA(I) */
  1278. x1 = cos(phi[i__ - 1]) * b11d[i__] + sin(phi[i__ - 1]) * b12e[i__
  1279. - 1];
  1280. x2 = cos(phi[i__ - 1]) * b11bulge + sin(phi[i__ - 1]) * b12bulge;
  1281. y1 = cos(phi[i__ - 1]) * b21d[i__] + sin(phi[i__ - 1]) * b22e[i__
  1282. - 1];
  1283. y2 = cos(phi[i__ - 1]) * b21bulge + sin(phi[i__ - 1]) * b22bulge;
  1284. /* Computing 2nd power */
  1285. d__1 = y1;
  1286. /* Computing 2nd power */
  1287. d__2 = y2;
  1288. /* Computing 2nd power */
  1289. d__3 = x1;
  1290. /* Computing 2nd power */
  1291. d__4 = x2;
  1292. theta[i__] = atan2(sqrt(d__1 * d__1 + d__2 * d__2), sqrt(d__3 *
  1293. d__3 + d__4 * d__4));
  1294. /* Determine if there are bulges to chase or if a new direct */
  1295. /* summand has been reached */
  1296. /* Computing 2nd power */
  1297. d__1 = b11d[i__];
  1298. /* Computing 2nd power */
  1299. d__2 = b11bulge;
  1300. /* Computing 2nd power */
  1301. d__3 = thresh;
  1302. restart11 = d__1 * d__1 + d__2 * d__2 <= d__3 * d__3;
  1303. /* Computing 2nd power */
  1304. d__1 = b12e[i__ - 1];
  1305. /* Computing 2nd power */
  1306. d__2 = b12bulge;
  1307. /* Computing 2nd power */
  1308. d__3 = thresh;
  1309. restart12 = d__1 * d__1 + d__2 * d__2 <= d__3 * d__3;
  1310. /* Computing 2nd power */
  1311. d__1 = b21d[i__];
  1312. /* Computing 2nd power */
  1313. d__2 = b21bulge;
  1314. /* Computing 2nd power */
  1315. d__3 = thresh;
  1316. restart21 = d__1 * d__1 + d__2 * d__2 <= d__3 * d__3;
  1317. /* Computing 2nd power */
  1318. d__1 = b22e[i__ - 1];
  1319. /* Computing 2nd power */
  1320. d__2 = b22bulge;
  1321. /* Computing 2nd power */
  1322. d__3 = thresh;
  1323. restart22 = d__1 * d__1 + d__2 * d__2 <= d__3 * d__3;
  1324. /* If possible, chase bulges from B11(I+1,I), B12(I+1,I-1), */
  1325. /* B21(I+1,I), and B22(I+1,I-1). If necessary, restart bulge- */
  1326. /* chasing by applying the original shift again. */
  1327. if (! restart11 && ! restart12) {
  1328. dlartgp_(&x2, &x1, &work[iu1sn + i__ - 1], &work[iu1cs + i__
  1329. - 1], &r__);
  1330. } else if (! restart11 && restart12) {
  1331. dlartgp_(&b11bulge, &b11d[i__], &work[iu1sn + i__ - 1], &work[
  1332. iu1cs + i__ - 1], &r__);
  1333. } else if (restart11 && ! restart12) {
  1334. dlartgp_(&b12bulge, &b12e[i__ - 1], &work[iu1sn + i__ - 1], &
  1335. work[iu1cs + i__ - 1], &r__);
  1336. } else if (mu <= nu) {
  1337. dlartgs_(&b11e[i__], &b11d[i__ + 1], &mu, &work[iu1cs + i__ -
  1338. 1], &work[iu1sn + i__ - 1]);
  1339. } else {
  1340. dlartgs_(&b12d[i__], &b12e[i__], &nu, &work[iu1cs + i__ - 1],
  1341. &work[iu1sn + i__ - 1]);
  1342. }
  1343. if (! restart21 && ! restart22) {
  1344. dlartgp_(&y2, &y1, &work[iu2sn + i__ - 1], &work[iu2cs + i__
  1345. - 1], &r__);
  1346. } else if (! restart21 && restart22) {
  1347. dlartgp_(&b21bulge, &b21d[i__], &work[iu2sn + i__ - 1], &work[
  1348. iu2cs + i__ - 1], &r__);
  1349. } else if (restart21 && ! restart22) {
  1350. dlartgp_(&b22bulge, &b22e[i__ - 1], &work[iu2sn + i__ - 1], &
  1351. work[iu2cs + i__ - 1], &r__);
  1352. } else if (nu < mu) {
  1353. dlartgs_(&b21e[i__], &b21e[i__ + 1], &nu, &work[iu2cs + i__ -
  1354. 1], &work[iu2sn + i__ - 1]);
  1355. } else {
  1356. dlartgs_(&b22d[i__], &b22e[i__], &mu, &work[iu2cs + i__ - 1],
  1357. &work[iu2sn + i__ - 1]);
  1358. }
  1359. work[iu2cs + i__ - 1] = -work[iu2cs + i__ - 1];
  1360. work[iu2sn + i__ - 1] = -work[iu2sn + i__ - 1];
  1361. temp = work[iu1cs + i__ - 1] * b11e[i__] + work[iu1sn + i__ - 1] *
  1362. b11d[i__ + 1];
  1363. b11d[i__ + 1] = work[iu1cs + i__ - 1] * b11d[i__ + 1] - work[
  1364. iu1sn + i__ - 1] * b11e[i__];
  1365. b11e[i__] = temp;
  1366. if (i__ < imax - 1) {
  1367. b11bulge = work[iu1sn + i__ - 1] * b11e[i__ + 1];
  1368. b11e[i__ + 1] = work[iu1cs + i__ - 1] * b11e[i__ + 1];
  1369. }
  1370. temp = work[iu2cs + i__ - 1] * b21e[i__] + work[iu2sn + i__ - 1] *
  1371. b21d[i__ + 1];
  1372. b21d[i__ + 1] = work[iu2cs + i__ - 1] * b21d[i__ + 1] - work[
  1373. iu2sn + i__ - 1] * b21e[i__];
  1374. b21e[i__] = temp;
  1375. if (i__ < imax - 1) {
  1376. b21bulge = work[iu2sn + i__ - 1] * b21e[i__ + 1];
  1377. b21e[i__ + 1] = work[iu2cs + i__ - 1] * b21e[i__ + 1];
  1378. }
  1379. temp = work[iu1cs + i__ - 1] * b12d[i__] + work[iu1sn + i__ - 1] *
  1380. b12e[i__];
  1381. b12e[i__] = work[iu1cs + i__ - 1] * b12e[i__] - work[iu1sn + i__
  1382. - 1] * b12d[i__];
  1383. b12d[i__] = temp;
  1384. b12bulge = work[iu1sn + i__ - 1] * b12d[i__ + 1];
  1385. b12d[i__ + 1] = work[iu1cs + i__ - 1] * b12d[i__ + 1];
  1386. temp = work[iu2cs + i__ - 1] * b22d[i__] + work[iu2sn + i__ - 1] *
  1387. b22e[i__];
  1388. b22e[i__] = work[iu2cs + i__ - 1] * b22e[i__] - work[iu2sn + i__
  1389. - 1] * b22d[i__];
  1390. b22d[i__] = temp;
  1391. b22bulge = work[iu2sn + i__ - 1] * b22d[i__ + 1];
  1392. b22d[i__ + 1] = work[iu2cs + i__ - 1] * b22d[i__ + 1];
  1393. }
  1394. /* Compute PHI(IMAX-1) */
  1395. x1 = sin(theta[imax - 1]) * b11e[imax - 1] + cos(theta[imax - 1]) *
  1396. b21e[imax - 1];
  1397. y1 = sin(theta[imax - 1]) * b12d[imax - 1] + cos(theta[imax - 1]) *
  1398. b22d[imax - 1];
  1399. y2 = sin(theta[imax - 1]) * b12bulge + cos(theta[imax - 1]) *
  1400. b22bulge;
  1401. /* Computing 2nd power */
  1402. d__1 = y1;
  1403. /* Computing 2nd power */
  1404. d__2 = y2;
  1405. phi[imax - 1] = atan2((abs(x1)), sqrt(d__1 * d__1 + d__2 * d__2));
  1406. /* Chase bulges from B12(IMAX-1,IMAX) and B22(IMAX-1,IMAX) */
  1407. /* Computing 2nd power */
  1408. d__1 = b12d[imax - 1];
  1409. /* Computing 2nd power */
  1410. d__2 = b12bulge;
  1411. /* Computing 2nd power */
  1412. d__3 = thresh;
  1413. restart12 = d__1 * d__1 + d__2 * d__2 <= d__3 * d__3;
  1414. /* Computing 2nd power */
  1415. d__1 = b22d[imax - 1];
  1416. /* Computing 2nd power */
  1417. d__2 = b22bulge;
  1418. /* Computing 2nd power */
  1419. d__3 = thresh;
  1420. restart22 = d__1 * d__1 + d__2 * d__2 <= d__3 * d__3;
  1421. if (! restart12 && ! restart22) {
  1422. dlartgp_(&y2, &y1, &work[iv2tsn + imax - 2], &work[iv2tcs + imax
  1423. - 2], &r__);
  1424. } else if (! restart12 && restart22) {
  1425. dlartgp_(&b12bulge, &b12d[imax - 1], &work[iv2tsn + imax - 2], &
  1426. work[iv2tcs + imax - 2], &r__);
  1427. } else if (restart12 && ! restart22) {
  1428. dlartgp_(&b22bulge, &b22d[imax - 1], &work[iv2tsn + imax - 2], &
  1429. work[iv2tcs + imax - 2], &r__);
  1430. } else if (nu < mu) {
  1431. dlartgs_(&b12e[imax - 1], &b12d[imax], &nu, &work[iv2tcs + imax -
  1432. 2], &work[iv2tsn + imax - 2]);
  1433. } else {
  1434. dlartgs_(&b22e[imax - 1], &b22d[imax], &mu, &work[iv2tcs + imax -
  1435. 2], &work[iv2tsn + imax - 2]);
  1436. }
  1437. temp = work[iv2tcs + imax - 2] * b12e[imax - 1] + work[iv2tsn + imax
  1438. - 2] * b12d[imax];
  1439. b12d[imax] = work[iv2tcs + imax - 2] * b12d[imax] - work[iv2tsn +
  1440. imax - 2] * b12e[imax - 1];
  1441. b12e[imax - 1] = temp;
  1442. temp = work[iv2tcs + imax - 2] * b22e[imax - 1] + work[iv2tsn + imax
  1443. - 2] * b22d[imax];
  1444. b22d[imax] = work[iv2tcs + imax - 2] * b22d[imax] - work[iv2tsn +
  1445. imax - 2] * b22e[imax - 1];
  1446. b22e[imax - 1] = temp;
  1447. /* Update singular vectors */
  1448. if (wantu1) {
  1449. if (colmajor) {
  1450. i__1 = imax - imin + 1;
  1451. dlasr_("R", "V", "F", p, &i__1, &work[iu1cs + imin - 1], &
  1452. work[iu1sn + imin - 1], &u1[imin * u1_dim1 + 1], ldu1);
  1453. } else {
  1454. i__1 = imax - imin + 1;
  1455. dlasr_("L", "V", "F", &i__1, p, &work[iu1cs + imin - 1], &
  1456. work[iu1sn + imin - 1], &u1[imin + u1_dim1], ldu1);
  1457. }
  1458. }
  1459. if (wantu2) {
  1460. if (colmajor) {
  1461. i__1 = *m - *p;
  1462. i__2 = imax - imin + 1;
  1463. dlasr_("R", "V", "F", &i__1, &i__2, &work[iu2cs + imin - 1], &
  1464. work[iu2sn + imin - 1], &u2[imin * u2_dim1 + 1], ldu2);
  1465. } else {
  1466. i__1 = imax - imin + 1;
  1467. i__2 = *m - *p;
  1468. dlasr_("L", "V", "F", &i__1, &i__2, &work[iu2cs + imin - 1], &
  1469. work[iu2sn + imin - 1], &u2[imin + u2_dim1], ldu2);
  1470. }
  1471. }
  1472. if (wantv1t) {
  1473. if (colmajor) {
  1474. i__1 = imax - imin + 1;
  1475. dlasr_("L", "V", "F", &i__1, q, &work[iv1tcs + imin - 1], &
  1476. work[iv1tsn + imin - 1], &v1t[imin + v1t_dim1], ldv1t);
  1477. } else {
  1478. i__1 = imax - imin + 1;
  1479. dlasr_("R", "V", "F", q, &i__1, &work[iv1tcs + imin - 1], &
  1480. work[iv1tsn + imin - 1], &v1t[imin * v1t_dim1 + 1],
  1481. ldv1t);
  1482. }
  1483. }
  1484. if (wantv2t) {
  1485. if (colmajor) {
  1486. i__1 = imax - imin + 1;
  1487. i__2 = *m - *q;
  1488. dlasr_("L", "V", "F", &i__1, &i__2, &work[iv2tcs + imin - 1],
  1489. &work[iv2tsn + imin - 1], &v2t[imin + v2t_dim1],
  1490. ldv2t);
  1491. } else {
  1492. i__1 = *m - *q;
  1493. i__2 = imax - imin + 1;
  1494. dlasr_("R", "V", "F", &i__1, &i__2, &work[iv2tcs + imin - 1],
  1495. &work[iv2tsn + imin - 1], &v2t[imin * v2t_dim1 + 1],
  1496. ldv2t);
  1497. }
  1498. }
  1499. /* Fix signs on B11(IMAX-1,IMAX) and B21(IMAX-1,IMAX) */
  1500. if (b11e[imax - 1] + b21e[imax - 1] > 0.) {
  1501. b11d[imax] = -b11d[imax];
  1502. b21d[imax] = -b21d[imax];
  1503. if (wantv1t) {
  1504. if (colmajor) {
  1505. dscal_(q, &c_b35, &v1t[imax + v1t_dim1], ldv1t);
  1506. } else {
  1507. dscal_(q, &c_b35, &v1t[imax * v1t_dim1 + 1], &c__1);
  1508. }
  1509. }
  1510. }
  1511. /* Compute THETA(IMAX) */
  1512. x1 = cos(phi[imax - 1]) * b11d[imax] + sin(phi[imax - 1]) * b12e[imax
  1513. - 1];
  1514. y1 = cos(phi[imax - 1]) * b21d[imax] + sin(phi[imax - 1]) * b22e[imax
  1515. - 1];
  1516. theta[imax] = atan2((abs(y1)), (abs(x1)));
  1517. /* Fix signs on B11(IMAX,IMAX), B12(IMAX,IMAX-1), B21(IMAX,IMAX), */
  1518. /* and B22(IMAX,IMAX-1) */
  1519. if (b11d[imax] + b12e[imax - 1] < 0.) {
  1520. b12d[imax] = -b12d[imax];
  1521. if (wantu1) {
  1522. if (colmajor) {
  1523. dscal_(p, &c_b35, &u1[imax * u1_dim1 + 1], &c__1);
  1524. } else {
  1525. dscal_(p, &c_b35, &u1[imax + u1_dim1], ldu1);
  1526. }
  1527. }
  1528. }
  1529. if (b21d[imax] + b22e[imax - 1] > 0.) {
  1530. b22d[imax] = -b22d[imax];
  1531. if (wantu2) {
  1532. if (colmajor) {
  1533. i__1 = *m - *p;
  1534. dscal_(&i__1, &c_b35, &u2[imax * u2_dim1 + 1], &c__1);
  1535. } else {
  1536. i__1 = *m - *p;
  1537. dscal_(&i__1, &c_b35, &u2[imax + u2_dim1], ldu2);
  1538. }
  1539. }
  1540. }
  1541. /* Fix signs on B12(IMAX,IMAX) and B22(IMAX,IMAX) */
  1542. if (b12d[imax] + b22d[imax] < 0.) {
  1543. if (wantv2t) {
  1544. if (colmajor) {
  1545. i__1 = *m - *q;
  1546. dscal_(&i__1, &c_b35, &v2t[imax + v2t_dim1], ldv2t);
  1547. } else {
  1548. i__1 = *m - *q;
  1549. dscal_(&i__1, &c_b35, &v2t[imax * v2t_dim1 + 1], &c__1);
  1550. }
  1551. }
  1552. }
  1553. /* Test for negligible sines or cosines */
  1554. i__1 = imax;
  1555. for (i__ = imin; i__ <= i__1; ++i__) {
  1556. if (theta[i__] < thresh) {
  1557. theta[i__] = 0.;
  1558. } else if (theta[i__] > 1.57079632679489662 - thresh) {
  1559. theta[i__] = 1.57079632679489662;
  1560. }
  1561. }
  1562. i__1 = imax - 1;
  1563. for (i__ = imin; i__ <= i__1; ++i__) {
  1564. if (phi[i__] < thresh) {
  1565. phi[i__] = 0.;
  1566. } else if (phi[i__] > 1.57079632679489662 - thresh) {
  1567. phi[i__] = 1.57079632679489662;
  1568. }
  1569. }
  1570. /* Deflate */
  1571. if (imax > 1) {
  1572. while(phi[imax - 1] == 0.) {
  1573. --imax;
  1574. if (imax <= 1) {
  1575. myexit_();
  1576. }
  1577. }
  1578. }
  1579. if (imin > imax - 1) {
  1580. imin = imax - 1;
  1581. }
  1582. if (imin > 1) {
  1583. while(phi[imin - 1] != 0.) {
  1584. --imin;
  1585. if (imin <= 1) {
  1586. myexit_();
  1587. }
  1588. }
  1589. }
  1590. /* Repeat main iteration loop */
  1591. }
  1592. /* Postprocessing: order THETA from least to greatest */
  1593. i__1 = *q;
  1594. for (i__ = 1; i__ <= i__1; ++i__) {
  1595. mini = i__;
  1596. thetamin = theta[i__];
  1597. i__2 = *q;
  1598. for (j = i__ + 1; j <= i__2; ++j) {
  1599. if (theta[j] < thetamin) {
  1600. mini = j;
  1601. thetamin = theta[j];
  1602. }
  1603. }
  1604. if (mini != i__) {
  1605. theta[mini] = theta[i__];
  1606. theta[i__] = thetamin;
  1607. if (colmajor) {
  1608. if (wantu1) {
  1609. dswap_(p, &u1[i__ * u1_dim1 + 1], &c__1, &u1[mini *
  1610. u1_dim1 + 1], &c__1);
  1611. }
  1612. if (wantu2) {
  1613. i__2 = *m - *p;
  1614. dswap_(&i__2, &u2[i__ * u2_dim1 + 1], &c__1, &u2[mini *
  1615. u2_dim1 + 1], &c__1);
  1616. }
  1617. if (wantv1t) {
  1618. dswap_(q, &v1t[i__ + v1t_dim1], ldv1t, &v1t[mini +
  1619. v1t_dim1], ldv1t);
  1620. }
  1621. if (wantv2t) {
  1622. i__2 = *m - *q;
  1623. dswap_(&i__2, &v2t[i__ + v2t_dim1], ldv2t, &v2t[mini +
  1624. v2t_dim1], ldv2t);
  1625. }
  1626. } else {
  1627. if (wantu1) {
  1628. dswap_(p, &u1[i__ + u1_dim1], ldu1, &u1[mini + u1_dim1],
  1629. ldu1);
  1630. }
  1631. if (wantu2) {
  1632. i__2 = *m - *p;
  1633. dswap_(&i__2, &u2[i__ + u2_dim1], ldu2, &u2[mini +
  1634. u2_dim1], ldu2);
  1635. }
  1636. if (wantv1t) {
  1637. dswap_(q, &v1t[i__ * v1t_dim1 + 1], &c__1, &v1t[mini *
  1638. v1t_dim1 + 1], &c__1);
  1639. }
  1640. if (wantv2t) {
  1641. i__2 = *m - *q;
  1642. dswap_(&i__2, &v2t[i__ * v2t_dim1 + 1], &c__1, &v2t[mini *
  1643. v2t_dim1 + 1], &c__1);
  1644. }
  1645. }
  1646. }
  1647. }
  1648. return 0;
  1649. /* End of DBBCSD */
  1650. } /* dbbcsd_ */