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.

zbbcsd.c 51 kB

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