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.

zuncsd2by1.c 44 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386
  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. #if defined(_WIN64)
  18. typedef long long BLASLONG;
  19. typedef unsigned long long BLASULONG;
  20. #else
  21. typedef long BLASLONG;
  22. typedef unsigned long BLASULONG;
  23. #endif
  24. #ifdef LAPACK_ILP64
  25. typedef BLASLONG blasint;
  26. #if defined(_WIN64)
  27. #define blasabs(x) llabs(x)
  28. #else
  29. #define blasabs(x) labs(x)
  30. #endif
  31. #else
  32. typedef int blasint;
  33. #define blasabs(x) abs(x)
  34. #endif
  35. typedef blasint integer;
  36. typedef unsigned int uinteger;
  37. typedef char *address;
  38. typedef short int shortint;
  39. typedef float real;
  40. typedef double doublereal;
  41. typedef struct { real r, i; } complex;
  42. typedef struct { doublereal r, i; } doublecomplex;
  43. static inline _Complex float Cf(complex *z) {return z->r + z->i*_Complex_I;}
  44. static inline _Complex double Cd(doublecomplex *z) {return z->r + z->i*_Complex_I;}
  45. static inline _Complex float * _pCf(complex *z) {return (_Complex float*)z;}
  46. static inline _Complex double * _pCd(doublecomplex *z) {return (_Complex double*)z;}
  47. #define pCf(z) (*_pCf(z))
  48. #define pCd(z) (*_pCd(z))
  49. typedef int logical;
  50. typedef short int shortlogical;
  51. typedef char logical1;
  52. typedef char integer1;
  53. #define TRUE_ (1)
  54. #define FALSE_ (0)
  55. /* Extern is for use with -E */
  56. #ifndef Extern
  57. #define Extern extern
  58. #endif
  59. /* I/O stuff */
  60. typedef int flag;
  61. typedef int ftnlen;
  62. typedef int ftnint;
  63. /*external read, write*/
  64. typedef struct
  65. { flag cierr;
  66. ftnint ciunit;
  67. flag ciend;
  68. char *cifmt;
  69. ftnint cirec;
  70. } cilist;
  71. /*internal read, write*/
  72. typedef struct
  73. { flag icierr;
  74. char *iciunit;
  75. flag iciend;
  76. char *icifmt;
  77. ftnint icirlen;
  78. ftnint icirnum;
  79. } icilist;
  80. /*open*/
  81. typedef struct
  82. { flag oerr;
  83. ftnint ounit;
  84. char *ofnm;
  85. ftnlen ofnmlen;
  86. char *osta;
  87. char *oacc;
  88. char *ofm;
  89. ftnint orl;
  90. char *oblnk;
  91. } olist;
  92. /*close*/
  93. typedef struct
  94. { flag cerr;
  95. ftnint cunit;
  96. char *csta;
  97. } cllist;
  98. /*rewind, backspace, endfile*/
  99. typedef struct
  100. { flag aerr;
  101. ftnint aunit;
  102. } alist;
  103. /* inquire */
  104. typedef struct
  105. { flag inerr;
  106. ftnint inunit;
  107. char *infile;
  108. ftnlen infilen;
  109. ftnint *inex; /*parameters in standard's order*/
  110. ftnint *inopen;
  111. ftnint *innum;
  112. ftnint *innamed;
  113. char *inname;
  114. ftnlen innamlen;
  115. char *inacc;
  116. ftnlen inacclen;
  117. char *inseq;
  118. ftnlen inseqlen;
  119. char *indir;
  120. ftnlen indirlen;
  121. char *infmt;
  122. ftnlen infmtlen;
  123. char *inform;
  124. ftnint informlen;
  125. char *inunf;
  126. ftnlen inunflen;
  127. ftnint *inrecl;
  128. ftnint *innrec;
  129. char *inblank;
  130. ftnlen inblanklen;
  131. } inlist;
  132. #define VOID void
  133. union Multitype { /* for multiple entry points */
  134. integer1 g;
  135. shortint h;
  136. integer i;
  137. /* longint j; */
  138. real r;
  139. doublereal d;
  140. complex c;
  141. doublecomplex z;
  142. };
  143. typedef union Multitype Multitype;
  144. struct Vardesc { /* for Namelist */
  145. char *name;
  146. char *addr;
  147. ftnlen *dims;
  148. int type;
  149. };
  150. typedef struct Vardesc Vardesc;
  151. struct Namelist {
  152. char *name;
  153. Vardesc **vars;
  154. int nvars;
  155. };
  156. typedef struct Namelist Namelist;
  157. #define abs(x) ((x) >= 0 ? (x) : -(x))
  158. #define dabs(x) (fabs(x))
  159. #define f2cmin(a,b) ((a) <= (b) ? (a) : (b))
  160. #define f2cmax(a,b) ((a) >= (b) ? (a) : (b))
  161. #define dmin(a,b) (f2cmin(a,b))
  162. #define dmax(a,b) (f2cmax(a,b))
  163. #define bit_test(a,b) ((a) >> (b) & 1)
  164. #define bit_clear(a,b) ((a) & ~((uinteger)1 << (b)))
  165. #define bit_set(a,b) ((a) | ((uinteger)1 << (b)))
  166. #define abort_() { sig_die("Fortran abort routine called", 1); }
  167. #define c_abs(z) (cabsf(Cf(z)))
  168. #define c_cos(R,Z) { pCf(R)=ccos(Cf(Z)); }
  169. #define c_div(c, a, b) {pCf(c) = Cf(a)/Cf(b);}
  170. #define z_div(c, a, b) {pCd(c) = Cd(a)/Cd(b);}
  171. #define c_exp(R, Z) {pCf(R) = cexpf(Cf(Z));}
  172. #define c_log(R, Z) {pCf(R) = clogf(Cf(Z));}
  173. #define c_sin(R, Z) {pCf(R) = csinf(Cf(Z));}
  174. //#define c_sqrt(R, Z) {*(R) = csqrtf(Cf(Z));}
  175. #define c_sqrt(R, Z) {pCf(R) = csqrtf(Cf(Z));}
  176. #define d_abs(x) (fabs(*(x)))
  177. #define d_acos(x) (acos(*(x)))
  178. #define d_asin(x) (asin(*(x)))
  179. #define d_atan(x) (atan(*(x)))
  180. #define d_atn2(x, y) (atan2(*(x),*(y)))
  181. #define d_cnjg(R, Z) { pCd(R) = conj(Cd(Z)); }
  182. #define r_cnjg(R, Z) { pCf(R) = conj(Cf(Z)); }
  183. #define d_cos(x) (cos(*(x)))
  184. #define d_cosh(x) (cosh(*(x)))
  185. #define d_dim(__a, __b) ( *(__a) > *(__b) ? *(__a) - *(__b) : 0.0 )
  186. #define d_exp(x) (exp(*(x)))
  187. #define d_imag(z) (cimag(Cd(z)))
  188. #define r_imag(z) (cimag(Cf(z)))
  189. #define d_int(__x) (*(__x)>0 ? floor(*(__x)) : -floor(- *(__x)))
  190. #define r_int(__x) (*(__x)>0 ? floor(*(__x)) : -floor(- *(__x)))
  191. #define d_lg10(x) ( 0.43429448190325182765 * log(*(x)) )
  192. #define r_lg10(x) ( 0.43429448190325182765 * log(*(x)) )
  193. #define d_log(x) (log(*(x)))
  194. #define d_mod(x, y) (fmod(*(x), *(y)))
  195. #define u_nint(__x) ((__x)>=0 ? floor((__x) + .5) : -floor(.5 - (__x)))
  196. #define d_nint(x) u_nint(*(x))
  197. #define u_sign(__a,__b) ((__b) >= 0 ? ((__a) >= 0 ? (__a) : -(__a)) : -((__a) >= 0 ? (__a) : -(__a)))
  198. #define d_sign(a,b) u_sign(*(a),*(b))
  199. #define r_sign(a,b) u_sign(*(a),*(b))
  200. #define d_sin(x) (sin(*(x)))
  201. #define d_sinh(x) (sinh(*(x)))
  202. #define d_sqrt(x) (sqrt(*(x)))
  203. #define d_tan(x) (tan(*(x)))
  204. #define d_tanh(x) (tanh(*(x)))
  205. #define i_abs(x) abs(*(x))
  206. #define i_dnnt(x) ((integer)u_nint(*(x)))
  207. #define i_len(s, n) (n)
  208. #define i_nint(x) ((integer)u_nint(*(x)))
  209. #define i_sign(a,b) ((integer)u_sign((integer)*(a),(integer)*(b)))
  210. #define pow_dd(ap, bp) ( pow(*(ap), *(bp)))
  211. #define pow_si(B,E) spow_ui(*(B),*(E))
  212. #define pow_ri(B,E) spow_ui(*(B),*(E))
  213. #define pow_di(B,E) dpow_ui(*(B),*(E))
  214. #define pow_zi(p, a, b) {pCd(p) = zpow_ui(Cd(a), *(b));}
  215. #define pow_ci(p, a, b) {pCf(p) = cpow_ui(Cf(a), *(b));}
  216. #define pow_zz(R,A,B) {pCd(R) = cpow(Cd(A),*(B));}
  217. #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++ = ' '; }
  218. #define s_cmp(a,b,c,d) ((integer)strncmp((a),(b),f2cmin((c),(d))))
  219. #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]; }
  220. #define sig_die(s, kill) { exit(1); }
  221. #define s_stop(s, n) {exit(0);}
  222. static char junk[] = "\n@(#)LIBF77 VERSION 19990503\n";
  223. #define z_abs(z) (cabs(Cd(z)))
  224. #define z_exp(R, Z) {pCd(R) = cexp(Cd(Z));}
  225. #define z_sqrt(R, Z) {pCd(R) = csqrt(Cd(Z));}
  226. #define myexit_() break;
  227. #define mycycle() continue;
  228. #define myceiling(w) {ceil(w)}
  229. #define myhuge(w) {HUGE_VAL}
  230. //#define mymaxloc_(w,s,e,n) {if (sizeof(*(w)) == sizeof(double)) dmaxloc_((w),*(s),*(e),n); else dmaxloc_((w),*(s),*(e),n);}
  231. #define mymaxloc(w,s,e,n) {dmaxloc_(w,*(s),*(e),n)}
  232. /* procedure parameter types for -A and -C++ */
  233. #define F2C_proc_par_types 1
  234. #ifdef __cplusplus
  235. typedef logical (*L_fp)(...);
  236. #else
  237. typedef logical (*L_fp)();
  238. #endif
  239. static float spow_ui(float x, integer n) {
  240. float pow=1.0; unsigned long int u;
  241. if(n != 0) {
  242. if(n < 0) n = -n, x = 1/x;
  243. for(u = n; ; ) {
  244. if(u & 01) pow *= x;
  245. if(u >>= 1) x *= x;
  246. else break;
  247. }
  248. }
  249. return pow;
  250. }
  251. static double dpow_ui(double x, integer n) {
  252. double pow=1.0; unsigned long int u;
  253. if(n != 0) {
  254. if(n < 0) n = -n, x = 1/x;
  255. for(u = n; ; ) {
  256. if(u & 01) pow *= x;
  257. if(u >>= 1) x *= x;
  258. else break;
  259. }
  260. }
  261. return pow;
  262. }
  263. static _Complex float cpow_ui(_Complex float x, integer n) {
  264. _Complex float pow=1.0; unsigned long int u;
  265. if(n != 0) {
  266. if(n < 0) n = -n, x = 1/x;
  267. for(u = n; ; ) {
  268. if(u & 01) pow *= x;
  269. if(u >>= 1) x *= x;
  270. else break;
  271. }
  272. }
  273. return pow;
  274. }
  275. static _Complex double zpow_ui(_Complex double x, integer n) {
  276. _Complex double pow=1.0; unsigned long int u;
  277. if(n != 0) {
  278. if(n < 0) n = -n, x = 1/x;
  279. for(u = n; ; ) {
  280. if(u & 01) pow *= x;
  281. if(u >>= 1) x *= x;
  282. else break;
  283. }
  284. }
  285. return pow;
  286. }
  287. static integer pow_ii(integer x, integer n) {
  288. integer pow; unsigned long int u;
  289. if (n <= 0) {
  290. if (n == 0 || x == 1) pow = 1;
  291. else if (x != -1) pow = x == 0 ? 1/x : 0;
  292. else n = -n;
  293. }
  294. if ((n > 0) || !(n == 0 || x == 1 || x != -1)) {
  295. u = n;
  296. for(pow = 1; ; ) {
  297. if(u & 01) pow *= x;
  298. if(u >>= 1) x *= x;
  299. else break;
  300. }
  301. }
  302. return pow;
  303. }
  304. static integer dmaxloc_(double *w, integer s, integer e, integer *n)
  305. {
  306. double m; integer i, mi;
  307. for(m=w[s-1], mi=s, i=s+1; i<=e; i++)
  308. if (w[i-1]>m) mi=i ,m=w[i-1];
  309. return mi-s+1;
  310. }
  311. static integer smaxloc_(float *w, integer s, integer e, integer *n)
  312. {
  313. float m; integer i, mi;
  314. for(m=w[s-1], mi=s, i=s+1; i<=e; i++)
  315. if (w[i-1]>m) mi=i ,m=w[i-1];
  316. return mi-s+1;
  317. }
  318. static inline void cdotc_(complex *z, integer *n_, complex *x, integer *incx_, complex *y, integer *incy_) {
  319. integer n = *n_, incx = *incx_, incy = *incy_, i;
  320. _Complex float zdotc = 0.0;
  321. if (incx == 1 && incy == 1) {
  322. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  323. zdotc += conjf(Cf(&x[i])) * Cf(&y[i]);
  324. }
  325. } else {
  326. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  327. zdotc += conjf(Cf(&x[i*incx])) * Cf(&y[i*incy]);
  328. }
  329. }
  330. pCf(z) = zdotc;
  331. }
  332. static inline void zdotc_(doublecomplex *z, integer *n_, doublecomplex *x, integer *incx_, doublecomplex *y, integer *incy_) {
  333. integer n = *n_, incx = *incx_, incy = *incy_, i;
  334. _Complex double zdotc = 0.0;
  335. if (incx == 1 && incy == 1) {
  336. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  337. zdotc += conj(Cd(&x[i])) * Cd(&y[i]);
  338. }
  339. } else {
  340. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  341. zdotc += conj(Cd(&x[i*incx])) * Cd(&y[i*incy]);
  342. }
  343. }
  344. pCd(z) = zdotc;
  345. }
  346. static inline void cdotu_(complex *z, integer *n_, complex *x, integer *incx_, complex *y, integer *incy_) {
  347. integer n = *n_, incx = *incx_, incy = *incy_, i;
  348. _Complex float zdotc = 0.0;
  349. if (incx == 1 && incy == 1) {
  350. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  351. zdotc += Cf(&x[i]) * Cf(&y[i]);
  352. }
  353. } else {
  354. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  355. zdotc += Cf(&x[i*incx]) * Cf(&y[i*incy]);
  356. }
  357. }
  358. pCf(z) = zdotc;
  359. }
  360. static inline void zdotu_(doublecomplex *z, integer *n_, doublecomplex *x, integer *incx_, doublecomplex *y, integer *incy_) {
  361. integer n = *n_, incx = *incx_, incy = *incy_, i;
  362. _Complex double zdotc = 0.0;
  363. if (incx == 1 && incy == 1) {
  364. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  365. zdotc += Cd(&x[i]) * Cd(&y[i]);
  366. }
  367. } else {
  368. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  369. zdotc += Cd(&x[i*incx]) * Cd(&y[i*incy]);
  370. }
  371. }
  372. pCd(z) = zdotc;
  373. }
  374. #endif
  375. /* -- translated by f2c (version 20000121).
  376. You must link the resulting object file with the libraries:
  377. -lf2c -lm (in that order)
  378. */
  379. /* Table of constant values */
  380. static integer c_n1 = -1;
  381. static integer c__1 = 1;
  382. static logical c_false = FALSE_;
  383. /* > \brief \b ZUNCSD2BY1 */
  384. /* =========== DOCUMENTATION =========== */
  385. /* Online html documentation available at */
  386. /* http://www.netlib.org/lapack/explore-html/ */
  387. /* > \htmlonly */
  388. /* > Download ZUNCSD2BY1 + dependencies */
  389. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/zuncsd2
  390. by1.f"> */
  391. /* > [TGZ]</a> */
  392. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/zuncsd2
  393. by1.f"> */
  394. /* > [ZIP]</a> */
  395. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/zuncsd2
  396. by1.f"> */
  397. /* > [TXT]</a> */
  398. /* > \endhtmlonly */
  399. /* Definition: */
  400. /* =========== */
  401. /* SUBROUTINE ZUNCSD2BY1( JOBU1, JOBU2, JOBV1T, M, P, Q, X11, LDX11, */
  402. /* X21, LDX21, THETA, U1, LDU1, U2, LDU2, V1T, */
  403. /* LDV1T, WORK, LWORK, RWORK, LRWORK, IWORK, */
  404. /* INFO ) */
  405. /* CHARACTER JOBU1, JOBU2, JOBV1T */
  406. /* INTEGER INFO, LDU1, LDU2, LDV1T, LWORK, LDX11, LDX21, */
  407. /* $ M, P, Q */
  408. /* INTEGER LRWORK, LRWORKMIN, LRWORKOPT */
  409. /* DOUBLE PRECISION RWORK(*) */
  410. /* DOUBLE PRECISION THETA(*) */
  411. /* COMPLEX*16 U1(LDU1,*), U2(LDU2,*), V1T(LDV1T,*), WORK(*), */
  412. /* $ X11(LDX11,*), X21(LDX21,*) */
  413. /* INTEGER IWORK(*) */
  414. /* > \par Purpose: */
  415. /* ============= */
  416. /* > */
  417. /* >\verbatim */
  418. /* > */
  419. /* > ZUNCSD2BY1 computes the CS decomposition of an M-by-Q matrix X with */
  420. /* > orthonormal columns that has been partitioned into a 2-by-1 block */
  421. /* > structure: */
  422. /* > */
  423. /* > [ I1 0 0 ] */
  424. /* > [ 0 C 0 ] */
  425. /* > [ X11 ] [ U1 | ] [ 0 0 0 ] */
  426. /* > X = [-----] = [---------] [----------] V1**T . */
  427. /* > [ X21 ] [ | U2 ] [ 0 0 0 ] */
  428. /* > [ 0 S 0 ] */
  429. /* > [ 0 0 I2] */
  430. /* > */
  431. /* > X11 is P-by-Q. The unitary matrices U1, U2, and V1 are P-by-P, */
  432. /* > (M-P)-by-(M-P), and Q-by-Q, respectively. C and S are R-by-R */
  433. /* > nonnegative diagonal matrices satisfying C^2 + S^2 = I, in which */
  434. /* > R = MIN(P,M-P,Q,M-Q). I1 is a K1-by-K1 identity matrix and I2 is a */
  435. /* > K2-by-K2 identity matrix, where K1 = MAX(Q+P-M,0), K2 = MAX(Q-P,0). */
  436. /* > \endverbatim */
  437. /* Arguments: */
  438. /* ========== */
  439. /* > \param[in] JOBU1 */
  440. /* > \verbatim */
  441. /* > JOBU1 is CHARACTER */
  442. /* > = 'Y': U1 is computed; */
  443. /* > otherwise: U1 is not computed. */
  444. /* > \endverbatim */
  445. /* > */
  446. /* > \param[in] JOBU2 */
  447. /* > \verbatim */
  448. /* > JOBU2 is CHARACTER */
  449. /* > = 'Y': U2 is computed; */
  450. /* > otherwise: U2 is not computed. */
  451. /* > \endverbatim */
  452. /* > */
  453. /* > \param[in] JOBV1T */
  454. /* > \verbatim */
  455. /* > JOBV1T is CHARACTER */
  456. /* > = 'Y': V1T is computed; */
  457. /* > otherwise: V1T is not computed. */
  458. /* > \endverbatim */
  459. /* > */
  460. /* > \param[in] M */
  461. /* > \verbatim */
  462. /* > M is INTEGER */
  463. /* > The number of rows in X. */
  464. /* > \endverbatim */
  465. /* > */
  466. /* > \param[in] P */
  467. /* > \verbatim */
  468. /* > P is INTEGER */
  469. /* > The number of rows in X11. 0 <= P <= M. */
  470. /* > \endverbatim */
  471. /* > */
  472. /* > \param[in] Q */
  473. /* > \verbatim */
  474. /* > Q is INTEGER */
  475. /* > The number of columns in X11 and X21. 0 <= Q <= M. */
  476. /* > \endverbatim */
  477. /* > */
  478. /* > \param[in,out] X11 */
  479. /* > \verbatim */
  480. /* > X11 is COMPLEX*16 array, dimension (LDX11,Q) */
  481. /* > On entry, part of the unitary matrix whose CSD is desired. */
  482. /* > \endverbatim */
  483. /* > */
  484. /* > \param[in] LDX11 */
  485. /* > \verbatim */
  486. /* > LDX11 is INTEGER */
  487. /* > The leading dimension of X11. LDX11 >= MAX(1,P). */
  488. /* > \endverbatim */
  489. /* > */
  490. /* > \param[in,out] X21 */
  491. /* > \verbatim */
  492. /* > X21 is COMPLEX*16 array, dimension (LDX21,Q) */
  493. /* > On entry, part of the unitary matrix whose CSD is desired. */
  494. /* > \endverbatim */
  495. /* > */
  496. /* > \param[in] LDX21 */
  497. /* > \verbatim */
  498. /* > LDX21 is INTEGER */
  499. /* > The leading dimension of X21. LDX21 >= MAX(1,M-P). */
  500. /* > \endverbatim */
  501. /* > */
  502. /* > \param[out] THETA */
  503. /* > \verbatim */
  504. /* > THETA is DOUBLE PRECISION array, dimension (R), in which R = */
  505. /* > MIN(P,M-P,Q,M-Q). */
  506. /* > C = DIAG( COS(THETA(1)), ... , COS(THETA(R)) ) and */
  507. /* > S = DIAG( SIN(THETA(1)), ... , SIN(THETA(R)) ). */
  508. /* > \endverbatim */
  509. /* > */
  510. /* > \param[out] U1 */
  511. /* > \verbatim */
  512. /* > U1 is COMPLEX*16 array, dimension (P) */
  513. /* > If JOBU1 = 'Y', U1 contains the P-by-P unitary matrix U1. */
  514. /* > \endverbatim */
  515. /* > */
  516. /* > \param[in] LDU1 */
  517. /* > \verbatim */
  518. /* > LDU1 is INTEGER */
  519. /* > The leading dimension of U1. If JOBU1 = 'Y', LDU1 >= */
  520. /* > MAX(1,P). */
  521. /* > \endverbatim */
  522. /* > */
  523. /* > \param[out] U2 */
  524. /* > \verbatim */
  525. /* > U2 is COMPLEX*16 array, dimension (M-P) */
  526. /* > If JOBU2 = 'Y', U2 contains the (M-P)-by-(M-P) unitary */
  527. /* > matrix U2. */
  528. /* > \endverbatim */
  529. /* > */
  530. /* > \param[in] LDU2 */
  531. /* > \verbatim */
  532. /* > LDU2 is INTEGER */
  533. /* > The leading dimension of U2. If JOBU2 = 'Y', LDU2 >= */
  534. /* > MAX(1,M-P). */
  535. /* > \endverbatim */
  536. /* > */
  537. /* > \param[out] V1T */
  538. /* > \verbatim */
  539. /* > V1T is COMPLEX*16 array, dimension (Q) */
  540. /* > If JOBV1T = 'Y', V1T contains the Q-by-Q matrix unitary */
  541. /* > matrix V1**T. */
  542. /* > \endverbatim */
  543. /* > */
  544. /* > \param[in] LDV1T */
  545. /* > \verbatim */
  546. /* > LDV1T is INTEGER */
  547. /* > The leading dimension of V1T. If JOBV1T = 'Y', LDV1T >= */
  548. /* > MAX(1,Q). */
  549. /* > \endverbatim */
  550. /* > */
  551. /* > \param[out] WORK */
  552. /* > \verbatim */
  553. /* > WORK is COMPLEX*16 array, dimension (MAX(1,LWORK)) */
  554. /* > On exit, if INFO = 0, WORK(1) returns the optimal LWORK. */
  555. /* > \endverbatim */
  556. /* > */
  557. /* > \param[in] LWORK */
  558. /* > \verbatim */
  559. /* > LWORK is INTEGER */
  560. /* > The dimension of the array WORK. */
  561. /* > */
  562. /* > If LWORK = -1, then a workspace query is assumed; the routine */
  563. /* > only calculates the optimal size of the WORK array, returns */
  564. /* > this value as the first entry of the work array, and no error */
  565. /* > message related to LWORK is issued by XERBLA. */
  566. /* > \endverbatim */
  567. /* > */
  568. /* > \param[out] RWORK */
  569. /* > \verbatim */
  570. /* > RWORK is DOUBLE PRECISION array, dimension (MAX(1,LRWORK)) */
  571. /* > On exit, if INFO = 0, RWORK(1) returns the optimal LRWORK. */
  572. /* > If INFO > 0 on exit, RWORK(2:R) contains the values PHI(1), */
  573. /* > ..., PHI(R-1) that, together with THETA(1), ..., THETA(R), */
  574. /* > define the matrix in intermediate bidiagonal-block form */
  575. /* > remaining after nonconvergence. INFO specifies the number */
  576. /* > of nonzero PHI's. */
  577. /* > \endverbatim */
  578. /* > */
  579. /* > \param[in] LRWORK */
  580. /* > \verbatim */
  581. /* > LRWORK is INTEGER */
  582. /* > The dimension of the array RWORK. */
  583. /* > */
  584. /* > If LRWORK = -1, then a workspace query is assumed; the routine */
  585. /* > only calculates the optimal size of the RWORK array, returns */
  586. /* > this value as the first entry of the work array, and no error */
  587. /* > message related to LRWORK is issued by XERBLA. */
  588. /* > \endverbatim */
  589. /* > \param[out] IWORK */
  590. /* > \verbatim */
  591. /* > IWORK is INTEGER array, dimension (M-MIN(P,M-P,Q,M-Q)) */
  592. /* > \endverbatim */
  593. /* > */
  594. /* > \param[out] INFO */
  595. /* > \verbatim */
  596. /* > INFO is INTEGER */
  597. /* > = 0: successful exit. */
  598. /* > < 0: if INFO = -i, the i-th argument had an illegal value. */
  599. /* > > 0: ZBBCSD did not converge. See the description of WORK */
  600. /* > above for details. */
  601. /* > \endverbatim */
  602. /* > \par References: */
  603. /* ================ */
  604. /* > */
  605. /* > [1] Brian D. Sutton. Computing the complete CS decomposition. Numer. */
  606. /* > Algorithms, 50(1):33-65, 2009. */
  607. /* Authors: */
  608. /* ======== */
  609. /* > \author Univ. of Tennessee */
  610. /* > \author Univ. of California Berkeley */
  611. /* > \author Univ. of Colorado Denver */
  612. /* > \author NAG Ltd. */
  613. /* > \date July 2012 */
  614. /* > \ingroup complex16OTHERcomputational */
  615. /* ===================================================================== */
  616. /* Subroutine */ int zuncsd2by1_(char *jobu1, char *jobu2, char *jobv1t,
  617. integer *m, integer *p, integer *q, doublecomplex *x11, integer *
  618. ldx11, doublecomplex *x21, integer *ldx21, doublereal *theta,
  619. doublecomplex *u1, integer *ldu1, doublecomplex *u2, integer *ldu2,
  620. doublecomplex *v1t, integer *ldv1t, doublecomplex *work, integer *
  621. lwork, doublereal *rwork, integer *lrwork, integer *iwork, integer *
  622. info)
  623. {
  624. /* System generated locals */
  625. integer u1_dim1, u1_offset, u2_dim1, u2_offset, v1t_dim1, v1t_offset,
  626. x11_dim1, x11_offset, x21_dim1, x21_offset, i__1, i__2, i__3;
  627. /* Local variables */
  628. integer ib11d, ib11e, ib12d, ib12e, ib21d, ib21e, ib22d, ib22e;
  629. doublecomplex cdum[1] /* was [1][1] */;
  630. integer iphi, lworkmin, lworkopt, i__, j, r__;
  631. extern logical lsame_(char *, char *);
  632. integer childinfo;
  633. extern /* Subroutine */ int zcopy_(integer *, doublecomplex *, integer *,
  634. doublecomplex *, integer *);
  635. integer lorglqmin, lorgqrmin, lorglqopt, lrworkmin, itaup1, itaup2,
  636. itauq1, lorgqropt;
  637. logical wantu1, wantu2;
  638. integer lrworkopt, ibbcsd, lbbcsd, iorbdb, lorbdb;
  639. extern /* Subroutine */ int zbbcsd_(char *, char *, char *, char *, char *
  640. , integer *, integer *, integer *, doublereal *, doublereal *,
  641. doublecomplex *, integer *, doublecomplex *, integer *,
  642. doublecomplex *, integer *, doublecomplex *, integer *,
  643. doublereal *, doublereal *, doublereal *, doublereal *,
  644. doublereal *, doublereal *, doublereal *, doublereal *,
  645. doublereal *, integer *, integer *), xerbla_(char *, integer *, ftnlen);
  646. integer iorglq, lorglq;
  647. extern /* Subroutine */ int zlacpy_(char *, integer *, integer *,
  648. doublecomplex *, integer *, doublecomplex *, integer *);
  649. integer iorgqr;
  650. extern /* Subroutine */ int zlapmr_(logical *, integer *, integer *,
  651. doublecomplex *, integer *, integer *);
  652. integer lorgqr;
  653. extern /* Subroutine */ int zlapmt_(logical *, integer *, integer *,
  654. doublecomplex *, integer *, integer *);
  655. logical lquery;
  656. extern /* Subroutine */ int zunglq_(integer *, integer *, integer *,
  657. doublecomplex *, integer *, doublecomplex *, doublecomplex *,
  658. integer *, integer *), zungqr_(integer *, integer *, integer *,
  659. doublecomplex *, integer *, doublecomplex *, doublecomplex *,
  660. integer *, integer *), zunbdb1_(integer *, integer *, integer *,
  661. doublecomplex *, integer *, doublecomplex *, integer *,
  662. doublereal *, doublereal *, doublecomplex *, doublecomplex *,
  663. doublecomplex *, doublecomplex *, integer *, integer *), zunbdb2_(
  664. integer *, integer *, integer *, doublecomplex *, integer *,
  665. doublecomplex *, integer *, doublereal *, doublereal *,
  666. doublecomplex *, doublecomplex *, doublecomplex *, doublecomplex *
  667. , integer *, integer *), zunbdb3_(integer *, integer *, integer *,
  668. doublecomplex *, integer *, doublecomplex *, integer *,
  669. doublereal *, doublereal *, doublecomplex *, doublecomplex *,
  670. doublecomplex *, doublecomplex *, integer *, integer *), zunbdb4_(
  671. integer *, integer *, integer *, doublecomplex *, integer *,
  672. doublecomplex *, integer *, doublereal *, doublereal *,
  673. doublecomplex *, doublecomplex *, doublecomplex *, doublecomplex *
  674. , doublecomplex *, integer *, integer *);
  675. logical wantv1t;
  676. doublereal dum[1];
  677. /* -- LAPACK computational routine (version 3.7.1) -- */
  678. /* -- LAPACK is a software package provided by Univ. of Tennessee, -- */
  679. /* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- */
  680. /* July 2012 */
  681. /* ===================================================================== */
  682. /* Test input arguments */
  683. /* Parameter adjustments */
  684. x11_dim1 = *ldx11;
  685. x11_offset = 1 + x11_dim1 * 1;
  686. x11 -= x11_offset;
  687. x21_dim1 = *ldx21;
  688. x21_offset = 1 + x21_dim1 * 1;
  689. x21 -= x21_offset;
  690. --theta;
  691. u1_dim1 = *ldu1;
  692. u1_offset = 1 + u1_dim1 * 1;
  693. u1 -= u1_offset;
  694. u2_dim1 = *ldu2;
  695. u2_offset = 1 + u2_dim1 * 1;
  696. u2 -= u2_offset;
  697. v1t_dim1 = *ldv1t;
  698. v1t_offset = 1 + v1t_dim1 * 1;
  699. v1t -= v1t_offset;
  700. --work;
  701. --rwork;
  702. --iwork;
  703. /* Function Body */
  704. *info = 0;
  705. wantu1 = lsame_(jobu1, "Y");
  706. wantu2 = lsame_(jobu2, "Y");
  707. wantv1t = lsame_(jobv1t, "Y");
  708. lquery = *lwork == -1;
  709. if (*m < 0) {
  710. *info = -4;
  711. } else if (*p < 0 || *p > *m) {
  712. *info = -5;
  713. } else if (*q < 0 || *q > *m) {
  714. *info = -6;
  715. } else if (*ldx11 < f2cmax(1,*p)) {
  716. *info = -8;
  717. } else /* if(complicated condition) */ {
  718. /* Computing MAX */
  719. i__1 = 1, i__2 = *m - *p;
  720. if (*ldx21 < f2cmax(i__1,i__2)) {
  721. *info = -10;
  722. } else if (wantu1 && *ldu1 < f2cmax(1,*p)) {
  723. *info = -13;
  724. } else /* if(complicated condition) */ {
  725. /* Computing MAX */
  726. i__1 = 1, i__2 = *m - *p;
  727. if (wantu2 && *ldu2 < f2cmax(i__1,i__2)) {
  728. *info = -15;
  729. } else if (wantv1t && *ldv1t < f2cmax(1,*q)) {
  730. *info = -17;
  731. }
  732. }
  733. }
  734. /* Computing MIN */
  735. i__1 = *p, i__2 = *m - *p, i__1 = f2cmin(i__1,i__2), i__1 = f2cmin(i__1,*q),
  736. i__2 = *m - *q;
  737. r__ = f2cmin(i__1,i__2);
  738. /* Compute workspace */
  739. /* WORK layout: */
  740. /* |-----------------------------------------| */
  741. /* | LWORKOPT (1) | */
  742. /* |-----------------------------------------| */
  743. /* | TAUP1 (MAX(1,P)) | */
  744. /* | TAUP2 (MAX(1,M-P)) | */
  745. /* | TAUQ1 (MAX(1,Q)) | */
  746. /* |-----------------------------------------| */
  747. /* | ZUNBDB WORK | ZUNGQR WORK | ZUNGLQ WORK | */
  748. /* | | | | */
  749. /* | | | | */
  750. /* | | | | */
  751. /* | | | | */
  752. /* |-----------------------------------------| */
  753. /* RWORK layout: */
  754. /* |------------------| */
  755. /* | LRWORKOPT (1) | */
  756. /* |------------------| */
  757. /* | PHI (MAX(1,R-1)) | */
  758. /* |------------------| */
  759. /* | B11D (R) | */
  760. /* | B11E (R-1) | */
  761. /* | B12D (R) | */
  762. /* | B12E (R-1) | */
  763. /* | B21D (R) | */
  764. /* | B21E (R-1) | */
  765. /* | B22D (R) | */
  766. /* | B22E (R-1) | */
  767. /* | ZBBCSD RWORK | */
  768. /* |------------------| */
  769. if (*info == 0) {
  770. iphi = 2;
  771. /* Computing MAX */
  772. i__1 = 1, i__2 = r__ - 1;
  773. ib11d = iphi + f2cmax(i__1,i__2);
  774. ib11e = ib11d + f2cmax(1,r__);
  775. /* Computing MAX */
  776. i__1 = 1, i__2 = r__ - 1;
  777. ib12d = ib11e + f2cmax(i__1,i__2);
  778. ib12e = ib12d + f2cmax(1,r__);
  779. /* Computing MAX */
  780. i__1 = 1, i__2 = r__ - 1;
  781. ib21d = ib12e + f2cmax(i__1,i__2);
  782. ib21e = ib21d + f2cmax(1,r__);
  783. /* Computing MAX */
  784. i__1 = 1, i__2 = r__ - 1;
  785. ib22d = ib21e + f2cmax(i__1,i__2);
  786. ib22e = ib22d + f2cmax(1,r__);
  787. /* Computing MAX */
  788. i__1 = 1, i__2 = r__ - 1;
  789. ibbcsd = ib22e + f2cmax(i__1,i__2);
  790. itaup1 = 2;
  791. itaup2 = itaup1 + f2cmax(1,*p);
  792. /* Computing MAX */
  793. i__1 = 1, i__2 = *m - *p;
  794. itauq1 = itaup2 + f2cmax(i__1,i__2);
  795. iorbdb = itauq1 + f2cmax(1,*q);
  796. iorgqr = itauq1 + f2cmax(1,*q);
  797. iorglq = itauq1 + f2cmax(1,*q);
  798. lorgqrmin = 1;
  799. lorgqropt = 1;
  800. lorglqmin = 1;
  801. lorglqopt = 1;
  802. if (r__ == *q) {
  803. zunbdb1_(m, p, q, &x11[x11_offset], ldx11, &x21[x21_offset],
  804. ldx21, &theta[1], dum, cdum, cdum, cdum, &work[1], &c_n1,
  805. &childinfo);
  806. lorbdb = (integer) work[1].r;
  807. if (wantu1 && *p > 0) {
  808. zungqr_(p, p, q, &u1[u1_offset], ldu1, cdum, &work[1], &c_n1,
  809. &childinfo);
  810. lorgqrmin = f2cmax(lorgqrmin,*p);
  811. /* Computing MAX */
  812. i__1 = lorgqropt, i__2 = (integer) work[1].r;
  813. lorgqropt = f2cmax(i__1,i__2);
  814. }
  815. if (wantu2 && *m - *p > 0) {
  816. i__1 = *m - *p;
  817. i__2 = *m - *p;
  818. zungqr_(&i__1, &i__2, q, &u2[u2_offset], ldu2, cdum, &work[1],
  819. &c_n1, &childinfo);
  820. /* Computing MAX */
  821. i__1 = lorgqrmin, i__2 = *m - *p;
  822. lorgqrmin = f2cmax(i__1,i__2);
  823. /* Computing MAX */
  824. i__1 = lorgqropt, i__2 = (integer) work[1].r;
  825. lorgqropt = f2cmax(i__1,i__2);
  826. }
  827. if (wantv1t && *q > 0) {
  828. i__1 = *q - 1;
  829. i__2 = *q - 1;
  830. i__3 = *q - 1;
  831. zunglq_(&i__1, &i__2, &i__3, &v1t[v1t_offset], ldv1t, cdum, &
  832. work[1], &c_n1, &childinfo);
  833. /* Computing MAX */
  834. i__1 = lorglqmin, i__2 = *q - 1;
  835. lorglqmin = f2cmax(i__1,i__2);
  836. /* Computing MAX */
  837. i__1 = lorglqopt, i__2 = (integer) work[1].r;
  838. lorglqopt = f2cmax(i__1,i__2);
  839. }
  840. zbbcsd_(jobu1, jobu2, jobv1t, "N", "N", m, p, q, &theta[1], dum, &
  841. u1[u1_offset], ldu1, &u2[u2_offset], ldu2, &v1t[
  842. v1t_offset], ldv1t, cdum, &c__1, dum, dum, dum, dum, dum,
  843. dum, dum, dum, &rwork[1], &c_n1, &childinfo);
  844. lbbcsd = (integer) rwork[1];
  845. } else if (r__ == *p) {
  846. zunbdb2_(m, p, q, &x11[x11_offset], ldx11, &x21[x21_offset],
  847. ldx21, &theta[1], dum, cdum, cdum, cdum, &work[1], &c_n1,
  848. &childinfo);
  849. lorbdb = (integer) work[1].r;
  850. if (wantu1 && *p > 0) {
  851. i__1 = *p - 1;
  852. i__2 = *p - 1;
  853. i__3 = *p - 1;
  854. zungqr_(&i__1, &i__2, &i__3, &u1[(u1_dim1 << 1) + 2], ldu1,
  855. cdum, &work[1], &c_n1, &childinfo);
  856. /* Computing MAX */
  857. i__1 = lorgqrmin, i__2 = *p - 1;
  858. lorgqrmin = f2cmax(i__1,i__2);
  859. /* Computing MAX */
  860. i__1 = lorgqropt, i__2 = (integer) work[1].r;
  861. lorgqropt = f2cmax(i__1,i__2);
  862. }
  863. if (wantu2 && *m - *p > 0) {
  864. i__1 = *m - *p;
  865. i__2 = *m - *p;
  866. zungqr_(&i__1, &i__2, q, &u2[u2_offset], ldu2, cdum, &work[1],
  867. &c_n1, &childinfo);
  868. /* Computing MAX */
  869. i__1 = lorgqrmin, i__2 = *m - *p;
  870. lorgqrmin = f2cmax(i__1,i__2);
  871. /* Computing MAX */
  872. i__1 = lorgqropt, i__2 = (integer) work[1].r;
  873. lorgqropt = f2cmax(i__1,i__2);
  874. }
  875. if (wantv1t && *q > 0) {
  876. zunglq_(q, q, &r__, &v1t[v1t_offset], ldv1t, cdum, &work[1], &
  877. c_n1, &childinfo);
  878. lorglqmin = f2cmax(lorglqmin,*q);
  879. /* Computing MAX */
  880. i__1 = lorglqopt, i__2 = (integer) work[1].r;
  881. lorglqopt = f2cmax(i__1,i__2);
  882. }
  883. zbbcsd_(jobv1t, "N", jobu1, jobu2, "T", m, q, p, &theta[1], dum, &
  884. v1t[v1t_offset], ldv1t, cdum, &c__1, &u1[u1_offset], ldu1,
  885. &u2[u2_offset], ldu2, dum, dum, dum, dum, dum, dum, dum,
  886. dum, &rwork[1], &c_n1, &childinfo);
  887. lbbcsd = (integer) rwork[1];
  888. } else if (r__ == *m - *p) {
  889. zunbdb3_(m, p, q, &x11[x11_offset], ldx11, &x21[x21_offset],
  890. ldx21, &theta[1], dum, cdum, cdum, cdum, &work[1], &c_n1,
  891. &childinfo);
  892. lorbdb = (integer) work[1].r;
  893. if (wantu1 && *p > 0) {
  894. zungqr_(p, p, q, &u1[u1_offset], ldu1, cdum, &work[1], &c_n1,
  895. &childinfo);
  896. lorgqrmin = f2cmax(lorgqrmin,*p);
  897. /* Computing MAX */
  898. i__1 = lorgqropt, i__2 = (integer) work[1].r;
  899. lorgqropt = f2cmax(i__1,i__2);
  900. }
  901. if (wantu2 && *m - *p > 0) {
  902. i__1 = *m - *p - 1;
  903. i__2 = *m - *p - 1;
  904. i__3 = *m - *p - 1;
  905. zungqr_(&i__1, &i__2, &i__3, &u2[(u2_dim1 << 1) + 2], ldu2,
  906. cdum, &work[1], &c_n1, &childinfo);
  907. /* Computing MAX */
  908. i__1 = lorgqrmin, i__2 = *m - *p - 1;
  909. lorgqrmin = f2cmax(i__1,i__2);
  910. /* Computing MAX */
  911. i__1 = lorgqropt, i__2 = (integer) work[1].r;
  912. lorgqropt = f2cmax(i__1,i__2);
  913. }
  914. if (wantv1t && *q > 0) {
  915. zunglq_(q, q, &r__, &v1t[v1t_offset], ldv1t, cdum, &work[1], &
  916. c_n1, &childinfo);
  917. lorglqmin = f2cmax(lorglqmin,*q);
  918. /* Computing MAX */
  919. i__1 = lorglqopt, i__2 = (integer) work[1].r;
  920. lorglqopt = f2cmax(i__1,i__2);
  921. }
  922. i__1 = *m - *q;
  923. i__2 = *m - *p;
  924. zbbcsd_("N", jobv1t, jobu2, jobu1, "T", m, &i__1, &i__2, &theta[1]
  925. , dum, cdum, &c__1, &v1t[v1t_offset], ldv1t, &u2[
  926. u2_offset], ldu2, &u1[u1_offset], ldu1, dum, dum, dum,
  927. dum, dum, dum, dum, dum, &rwork[1], &c_n1, &childinfo);
  928. lbbcsd = (integer) rwork[1];
  929. } else {
  930. zunbdb4_(m, p, q, &x11[x11_offset], ldx11, &x21[x21_offset],
  931. ldx21, &theta[1], dum, cdum, cdum, cdum, cdum, &work[1], &
  932. c_n1, &childinfo);
  933. lorbdb = *m + (integer) work[1].r;
  934. if (wantu1 && *p > 0) {
  935. i__1 = *m - *q;
  936. zungqr_(p, p, &i__1, &u1[u1_offset], ldu1, cdum, &work[1], &
  937. c_n1, &childinfo);
  938. lorgqrmin = f2cmax(lorgqrmin,*p);
  939. /* Computing MAX */
  940. i__1 = lorgqropt, i__2 = (integer) work[1].r;
  941. lorgqropt = f2cmax(i__1,i__2);
  942. }
  943. if (wantu2 && *m - *p > 0) {
  944. i__1 = *m - *p;
  945. i__2 = *m - *p;
  946. i__3 = *m - *q;
  947. zungqr_(&i__1, &i__2, &i__3, &u2[u2_offset], ldu2, cdum, &
  948. work[1], &c_n1, &childinfo);
  949. /* Computing MAX */
  950. i__1 = lorgqrmin, i__2 = *m - *p;
  951. lorgqrmin = f2cmax(i__1,i__2);
  952. /* Computing MAX */
  953. i__1 = lorgqropt, i__2 = (integer) work[1].r;
  954. lorgqropt = f2cmax(i__1,i__2);
  955. }
  956. if (wantv1t && *q > 0) {
  957. zunglq_(q, q, q, &v1t[v1t_offset], ldv1t, cdum, &work[1], &
  958. c_n1, &childinfo);
  959. lorglqmin = f2cmax(lorglqmin,*q);
  960. /* Computing MAX */
  961. i__1 = lorglqopt, i__2 = (integer) work[1].r;
  962. lorglqopt = f2cmax(i__1,i__2);
  963. }
  964. i__1 = *m - *p;
  965. i__2 = *m - *q;
  966. zbbcsd_(jobu2, jobu1, "N", jobv1t, "N", m, &i__1, &i__2, &theta[1]
  967. , dum, &u2[u2_offset], ldu2, &u1[u1_offset], ldu1, cdum, &
  968. c__1, &v1t[v1t_offset], ldv1t, dum, dum, dum, dum, dum,
  969. dum, dum, dum, &rwork[1], &c_n1, &childinfo);
  970. lbbcsd = (integer) rwork[1];
  971. }
  972. lrworkmin = ibbcsd + lbbcsd - 1;
  973. lrworkopt = lrworkmin;
  974. rwork[1] = (doublereal) lrworkopt;
  975. /* Computing MAX */
  976. i__1 = iorbdb + lorbdb - 1, i__2 = iorgqr + lorgqrmin - 1, i__1 = f2cmax(
  977. i__1,i__2), i__2 = iorglq + lorglqmin - 1;
  978. lworkmin = f2cmax(i__1,i__2);
  979. /* Computing MAX */
  980. i__1 = iorbdb + lorbdb - 1, i__2 = iorgqr + lorgqropt - 1, i__1 = f2cmax(
  981. i__1,i__2), i__2 = iorglq + lorglqopt - 1;
  982. lworkopt = f2cmax(i__1,i__2);
  983. work[1].r = (doublereal) lworkopt, work[1].i = 0.;
  984. if (*lwork < lworkmin && ! lquery) {
  985. *info = -19;
  986. }
  987. }
  988. if (*info != 0) {
  989. i__1 = -(*info);
  990. xerbla_("ZUNCSD2BY1", &i__1, (ftnlen)10);
  991. return 0;
  992. } else if (lquery) {
  993. return 0;
  994. }
  995. lorgqr = *lwork - iorgqr + 1;
  996. lorglq = *lwork - iorglq + 1;
  997. /* Handle four cases separately: R = Q, R = P, R = M-P, and R = M-Q, */
  998. /* in which R = MIN(P,M-P,Q,M-Q) */
  999. if (r__ == *q) {
  1000. /* Case 1: R = Q */
  1001. /* Simultaneously bidiagonalize X11 and X21 */
  1002. zunbdb1_(m, p, q, &x11[x11_offset], ldx11, &x21[x21_offset], ldx21, &
  1003. theta[1], &rwork[iphi], &work[itaup1], &work[itaup2], &work[
  1004. itauq1], &work[iorbdb], &lorbdb, &childinfo);
  1005. /* Accumulate Householder reflectors */
  1006. if (wantu1 && *p > 0) {
  1007. zlacpy_("L", p, q, &x11[x11_offset], ldx11, &u1[u1_offset], ldu1);
  1008. zungqr_(p, p, q, &u1[u1_offset], ldu1, &work[itaup1], &work[
  1009. iorgqr], &lorgqr, &childinfo);
  1010. }
  1011. if (wantu2 && *m - *p > 0) {
  1012. i__1 = *m - *p;
  1013. zlacpy_("L", &i__1, q, &x21[x21_offset], ldx21, &u2[u2_offset],
  1014. ldu2);
  1015. i__1 = *m - *p;
  1016. i__2 = *m - *p;
  1017. zungqr_(&i__1, &i__2, q, &u2[u2_offset], ldu2, &work[itaup2], &
  1018. work[iorgqr], &lorgqr, &childinfo);
  1019. }
  1020. if (wantv1t && *q > 0) {
  1021. i__1 = v1t_dim1 + 1;
  1022. v1t[i__1].r = 1., v1t[i__1].i = 0.;
  1023. i__1 = *q;
  1024. for (j = 2; j <= i__1; ++j) {
  1025. i__2 = j * v1t_dim1 + 1;
  1026. v1t[i__2].r = 0., v1t[i__2].i = 0.;
  1027. i__2 = j + v1t_dim1;
  1028. v1t[i__2].r = 0., v1t[i__2].i = 0.;
  1029. }
  1030. i__1 = *q - 1;
  1031. i__2 = *q - 1;
  1032. zlacpy_("U", &i__1, &i__2, &x21[(x21_dim1 << 1) + 1], ldx21, &v1t[
  1033. (v1t_dim1 << 1) + 2], ldv1t);
  1034. i__1 = *q - 1;
  1035. i__2 = *q - 1;
  1036. i__3 = *q - 1;
  1037. zunglq_(&i__1, &i__2, &i__3, &v1t[(v1t_dim1 << 1) + 2], ldv1t, &
  1038. work[itauq1], &work[iorglq], &lorglq, &childinfo);
  1039. }
  1040. /* Simultaneously diagonalize X11 and X21. */
  1041. zbbcsd_(jobu1, jobu2, jobv1t, "N", "N", m, p, q, &theta[1], &rwork[
  1042. iphi], &u1[u1_offset], ldu1, &u2[u2_offset], ldu2, &v1t[
  1043. v1t_offset], ldv1t, cdum, &c__1, &rwork[ib11d], &rwork[ib11e],
  1044. &rwork[ib12d], &rwork[ib12e], &rwork[ib21d], &rwork[ib21e], &
  1045. rwork[ib22d], &rwork[ib22e], &rwork[ibbcsd], &lbbcsd, &
  1046. childinfo);
  1047. /* Permute rows and columns to place zero submatrices in */
  1048. /* preferred positions */
  1049. if (*q > 0 && wantu2) {
  1050. i__1 = *q;
  1051. for (i__ = 1; i__ <= i__1; ++i__) {
  1052. iwork[i__] = *m - *p - *q + i__;
  1053. }
  1054. i__1 = *m - *p;
  1055. for (i__ = *q + 1; i__ <= i__1; ++i__) {
  1056. iwork[i__] = i__ - *q;
  1057. }
  1058. i__1 = *m - *p;
  1059. i__2 = *m - *p;
  1060. zlapmt_(&c_false, &i__1, &i__2, &u2[u2_offset], ldu2, &iwork[1]);
  1061. }
  1062. } else if (r__ == *p) {
  1063. /* Case 2: R = P */
  1064. /* Simultaneously bidiagonalize X11 and X21 */
  1065. zunbdb2_(m, p, q, &x11[x11_offset], ldx11, &x21[x21_offset], ldx21, &
  1066. theta[1], &rwork[iphi], &work[itaup1], &work[itaup2], &work[
  1067. itauq1], &work[iorbdb], &lorbdb, &childinfo);
  1068. /* Accumulate Householder reflectors */
  1069. if (wantu1 && *p > 0) {
  1070. i__1 = u1_dim1 + 1;
  1071. u1[i__1].r = 1., u1[i__1].i = 0.;
  1072. i__1 = *p;
  1073. for (j = 2; j <= i__1; ++j) {
  1074. i__2 = j * u1_dim1 + 1;
  1075. u1[i__2].r = 0., u1[i__2].i = 0.;
  1076. i__2 = j + u1_dim1;
  1077. u1[i__2].r = 0., u1[i__2].i = 0.;
  1078. }
  1079. i__1 = *p - 1;
  1080. i__2 = *p - 1;
  1081. zlacpy_("L", &i__1, &i__2, &x11[x11_dim1 + 2], ldx11, &u1[(
  1082. u1_dim1 << 1) + 2], ldu1);
  1083. i__1 = *p - 1;
  1084. i__2 = *p - 1;
  1085. i__3 = *p - 1;
  1086. zungqr_(&i__1, &i__2, &i__3, &u1[(u1_dim1 << 1) + 2], ldu1, &work[
  1087. itaup1], &work[iorgqr], &lorgqr, &childinfo);
  1088. }
  1089. if (wantu2 && *m - *p > 0) {
  1090. i__1 = *m - *p;
  1091. zlacpy_("L", &i__1, q, &x21[x21_offset], ldx21, &u2[u2_offset],
  1092. ldu2);
  1093. i__1 = *m - *p;
  1094. i__2 = *m - *p;
  1095. zungqr_(&i__1, &i__2, q, &u2[u2_offset], ldu2, &work[itaup2], &
  1096. work[iorgqr], &lorgqr, &childinfo);
  1097. }
  1098. if (wantv1t && *q > 0) {
  1099. zlacpy_("U", p, q, &x11[x11_offset], ldx11, &v1t[v1t_offset],
  1100. ldv1t);
  1101. zunglq_(q, q, &r__, &v1t[v1t_offset], ldv1t, &work[itauq1], &work[
  1102. iorglq], &lorglq, &childinfo);
  1103. }
  1104. /* Simultaneously diagonalize X11 and X21. */
  1105. zbbcsd_(jobv1t, "N", jobu1, jobu2, "T", m, q, p, &theta[1], &rwork[
  1106. iphi], &v1t[v1t_offset], ldv1t, cdum, &c__1, &u1[u1_offset],
  1107. ldu1, &u2[u2_offset], ldu2, &rwork[ib11d], &rwork[ib11e], &
  1108. rwork[ib12d], &rwork[ib12e], &rwork[ib21d], &rwork[ib21e], &
  1109. rwork[ib22d], &rwork[ib22e], &rwork[ibbcsd], &lbbcsd, &
  1110. childinfo);
  1111. /* Permute rows and columns to place identity submatrices in */
  1112. /* preferred positions */
  1113. if (*q > 0 && wantu2) {
  1114. i__1 = *q;
  1115. for (i__ = 1; i__ <= i__1; ++i__) {
  1116. iwork[i__] = *m - *p - *q + i__;
  1117. }
  1118. i__1 = *m - *p;
  1119. for (i__ = *q + 1; i__ <= i__1; ++i__) {
  1120. iwork[i__] = i__ - *q;
  1121. }
  1122. i__1 = *m - *p;
  1123. i__2 = *m - *p;
  1124. zlapmt_(&c_false, &i__1, &i__2, &u2[u2_offset], ldu2, &iwork[1]);
  1125. }
  1126. } else if (r__ == *m - *p) {
  1127. /* Case 3: R = M-P */
  1128. /* Simultaneously bidiagonalize X11 and X21 */
  1129. zunbdb3_(m, p, q, &x11[x11_offset], ldx11, &x21[x21_offset], ldx21, &
  1130. theta[1], &rwork[iphi], &work[itaup1], &work[itaup2], &work[
  1131. itauq1], &work[iorbdb], &lorbdb, &childinfo);
  1132. /* Accumulate Householder reflectors */
  1133. if (wantu1 && *p > 0) {
  1134. zlacpy_("L", p, q, &x11[x11_offset], ldx11, &u1[u1_offset], ldu1);
  1135. zungqr_(p, p, q, &u1[u1_offset], ldu1, &work[itaup1], &work[
  1136. iorgqr], &lorgqr, &childinfo);
  1137. }
  1138. if (wantu2 && *m - *p > 0) {
  1139. i__1 = u2_dim1 + 1;
  1140. u2[i__1].r = 1., u2[i__1].i = 0.;
  1141. i__1 = *m - *p;
  1142. for (j = 2; j <= i__1; ++j) {
  1143. i__2 = j * u2_dim1 + 1;
  1144. u2[i__2].r = 0., u2[i__2].i = 0.;
  1145. i__2 = j + u2_dim1;
  1146. u2[i__2].r = 0., u2[i__2].i = 0.;
  1147. }
  1148. i__1 = *m - *p - 1;
  1149. i__2 = *m - *p - 1;
  1150. zlacpy_("L", &i__1, &i__2, &x21[x21_dim1 + 2], ldx21, &u2[(
  1151. u2_dim1 << 1) + 2], ldu2);
  1152. i__1 = *m - *p - 1;
  1153. i__2 = *m - *p - 1;
  1154. i__3 = *m - *p - 1;
  1155. zungqr_(&i__1, &i__2, &i__3, &u2[(u2_dim1 << 1) + 2], ldu2, &work[
  1156. itaup2], &work[iorgqr], &lorgqr, &childinfo);
  1157. }
  1158. if (wantv1t && *q > 0) {
  1159. i__1 = *m - *p;
  1160. zlacpy_("U", &i__1, q, &x21[x21_offset], ldx21, &v1t[v1t_offset],
  1161. ldv1t);
  1162. zunglq_(q, q, &r__, &v1t[v1t_offset], ldv1t, &work[itauq1], &work[
  1163. iorglq], &lorglq, &childinfo);
  1164. }
  1165. /* Simultaneously diagonalize X11 and X21. */
  1166. i__1 = *m - *q;
  1167. i__2 = *m - *p;
  1168. zbbcsd_("N", jobv1t, jobu2, jobu1, "T", m, &i__1, &i__2, &theta[1], &
  1169. rwork[iphi], cdum, &c__1, &v1t[v1t_offset], ldv1t, &u2[
  1170. u2_offset], ldu2, &u1[u1_offset], ldu1, &rwork[ib11d], &rwork[
  1171. ib11e], &rwork[ib12d], &rwork[ib12e], &rwork[ib21d], &rwork[
  1172. ib21e], &rwork[ib22d], &rwork[ib22e], &rwork[ibbcsd], &lbbcsd,
  1173. &childinfo);
  1174. /* Permute rows and columns to place identity submatrices in */
  1175. /* preferred positions */
  1176. if (*q > r__) {
  1177. i__1 = r__;
  1178. for (i__ = 1; i__ <= i__1; ++i__) {
  1179. iwork[i__] = *q - r__ + i__;
  1180. }
  1181. i__1 = *q;
  1182. for (i__ = r__ + 1; i__ <= i__1; ++i__) {
  1183. iwork[i__] = i__ - r__;
  1184. }
  1185. if (wantu1) {
  1186. zlapmt_(&c_false, p, q, &u1[u1_offset], ldu1, &iwork[1]);
  1187. }
  1188. if (wantv1t) {
  1189. zlapmr_(&c_false, q, q, &v1t[v1t_offset], ldv1t, &iwork[1]);
  1190. }
  1191. }
  1192. } else {
  1193. /* Case 4: R = M-Q */
  1194. /* Simultaneously bidiagonalize X11 and X21 */
  1195. i__1 = lorbdb - *m;
  1196. zunbdb4_(m, p, q, &x11[x11_offset], ldx11, &x21[x21_offset], ldx21, &
  1197. theta[1], &rwork[iphi], &work[itaup1], &work[itaup2], &work[
  1198. itauq1], &work[iorbdb], &work[iorbdb + *m], &i__1, &childinfo)
  1199. ;
  1200. /* Accumulate Householder reflectors */
  1201. if (wantu1 && *p > 0) {
  1202. zcopy_(p, &work[iorbdb], &c__1, &u1[u1_offset], &c__1);
  1203. i__1 = *p;
  1204. for (j = 2; j <= i__1; ++j) {
  1205. i__2 = j * u1_dim1 + 1;
  1206. u1[i__2].r = 0., u1[i__2].i = 0.;
  1207. }
  1208. i__1 = *p - 1;
  1209. i__2 = *m - *q - 1;
  1210. zlacpy_("L", &i__1, &i__2, &x11[x11_dim1 + 2], ldx11, &u1[(
  1211. u1_dim1 << 1) + 2], ldu1);
  1212. i__1 = *m - *q;
  1213. zungqr_(p, p, &i__1, &u1[u1_offset], ldu1, &work[itaup1], &work[
  1214. iorgqr], &lorgqr, &childinfo);
  1215. }
  1216. if (wantu2 && *m - *p > 0) {
  1217. i__1 = *m - *p;
  1218. zcopy_(&i__1, &work[iorbdb + *p], &c__1, &u2[u2_offset], &c__1);
  1219. i__1 = *m - *p;
  1220. for (j = 2; j <= i__1; ++j) {
  1221. i__2 = j * u2_dim1 + 1;
  1222. u2[i__2].r = 0., u2[i__2].i = 0.;
  1223. }
  1224. i__1 = *m - *p - 1;
  1225. i__2 = *m - *q - 1;
  1226. zlacpy_("L", &i__1, &i__2, &x21[x21_dim1 + 2], ldx21, &u2[(
  1227. u2_dim1 << 1) + 2], ldu2);
  1228. i__1 = *m - *p;
  1229. i__2 = *m - *p;
  1230. i__3 = *m - *q;
  1231. zungqr_(&i__1, &i__2, &i__3, &u2[u2_offset], ldu2, &work[itaup2],
  1232. &work[iorgqr], &lorgqr, &childinfo);
  1233. }
  1234. if (wantv1t && *q > 0) {
  1235. i__1 = *m - *q;
  1236. zlacpy_("U", &i__1, q, &x21[x21_offset], ldx21, &v1t[v1t_offset],
  1237. ldv1t);
  1238. i__1 = *p - (*m - *q);
  1239. i__2 = *q - (*m - *q);
  1240. zlacpy_("U", &i__1, &i__2, &x11[*m - *q + 1 + (*m - *q + 1) *
  1241. x11_dim1], ldx11, &v1t[*m - *q + 1 + (*m - *q + 1) *
  1242. v1t_dim1], ldv1t);
  1243. i__1 = -(*p) + *q;
  1244. i__2 = *q - *p;
  1245. zlacpy_("U", &i__1, &i__2, &x21[*m - *q + 1 + (*p + 1) * x21_dim1]
  1246. , ldx21, &v1t[*p + 1 + (*p + 1) * v1t_dim1], ldv1t);
  1247. zunglq_(q, q, q, &v1t[v1t_offset], ldv1t, &work[itauq1], &work[
  1248. iorglq], &lorglq, &childinfo);
  1249. }
  1250. /* Simultaneously diagonalize X11 and X21. */
  1251. i__1 = *m - *p;
  1252. i__2 = *m - *q;
  1253. zbbcsd_(jobu2, jobu1, "N", jobv1t, "N", m, &i__1, &i__2, &theta[1], &
  1254. rwork[iphi], &u2[u2_offset], ldu2, &u1[u1_offset], ldu1, cdum,
  1255. &c__1, &v1t[v1t_offset], ldv1t, &rwork[ib11d], &rwork[ib11e],
  1256. &rwork[ib12d], &rwork[ib12e], &rwork[ib21d], &rwork[ib21e], &
  1257. rwork[ib22d], &rwork[ib22e], &rwork[ibbcsd], &lbbcsd, &
  1258. childinfo);
  1259. /* Permute rows and columns to place identity submatrices in */
  1260. /* preferred positions */
  1261. if (*p > r__) {
  1262. i__1 = r__;
  1263. for (i__ = 1; i__ <= i__1; ++i__) {
  1264. iwork[i__] = *p - r__ + i__;
  1265. }
  1266. i__1 = *p;
  1267. for (i__ = r__ + 1; i__ <= i__1; ++i__) {
  1268. iwork[i__] = i__ - r__;
  1269. }
  1270. if (wantu1) {
  1271. zlapmt_(&c_false, p, p, &u1[u1_offset], ldu1, &iwork[1]);
  1272. }
  1273. if (wantv1t) {
  1274. zlapmr_(&c_false, p, q, &v1t[v1t_offset], ldv1t, &iwork[1]);
  1275. }
  1276. }
  1277. }
  1278. return 0;
  1279. /* End of ZUNCSD2BY1 */
  1280. } /* zuncsd2by1_ */