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.

cuncsd.c 37 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206
  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 integer c_n1 = -1;
  363. static logical c_false = FALSE_;
  364. /* > \brief \b CUNCSD */
  365. /* =========== DOCUMENTATION =========== */
  366. /* Online html documentation available at */
  367. /* http://www.netlib.org/lapack/explore-html/ */
  368. /* > \htmlonly */
  369. /* > Download CUNCSD + dependencies */
  370. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/cuncsd.
  371. f"> */
  372. /* > [TGZ]</a> */
  373. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/cuncsd.
  374. f"> */
  375. /* > [ZIP]</a> */
  376. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/cuncsd.
  377. f"> */
  378. /* > [TXT]</a> */
  379. /* > \endhtmlonly */
  380. /* Definition: */
  381. /* =========== */
  382. /* SUBROUTINE CUNCSD( JOBU1, JOBU2, JOBV1T, JOBV2T, TRANS, */
  383. /* SIGNS, M, P, Q, X11, LDX11, X12, */
  384. /* LDX12, X21, LDX21, X22, LDX22, THETA, */
  385. /* U1, LDU1, U2, LDU2, V1T, LDV1T, V2T, */
  386. /* LDV2T, WORK, LWORK, RWORK, LRWORK, */
  387. /* IWORK, INFO ) */
  388. /* CHARACTER JOBU1, JOBU2, JOBV1T, JOBV2T, SIGNS, TRANS */
  389. /* INTEGER INFO, LDU1, LDU2, LDV1T, LDV2T, LDX11, LDX12, */
  390. /* $ LDX21, LDX22, LRWORK, LWORK, M, P, Q */
  391. /* INTEGER IWORK( * ) */
  392. /* REAL THETA( * ) */
  393. /* REAL RWORK( * ) */
  394. /* COMPLEX U1( LDU1, * ), U2( LDU2, * ), V1T( LDV1T, * ), */
  395. /* $ V2T( LDV2T, * ), WORK( * ), X11( LDX11, * ), */
  396. /* $ X12( LDX12, * ), X21( LDX21, * ), X22( LDX22, */
  397. /* $ * ) */
  398. /* > \par Purpose: */
  399. /* ============= */
  400. /* > */
  401. /* > \verbatim */
  402. /* > */
  403. /* > CUNCSD computes the CS decomposition of an M-by-M partitioned */
  404. /* > unitary matrix X: */
  405. /* > */
  406. /* > [ I 0 0 | 0 0 0 ] */
  407. /* > [ 0 C 0 | 0 -S 0 ] */
  408. /* > [ X11 | X12 ] [ U1 | ] [ 0 0 0 | 0 0 -I ] [ V1 | ]**H */
  409. /* > X = [-----------] = [---------] [---------------------] [---------] . */
  410. /* > [ X21 | X22 ] [ | U2 ] [ 0 0 0 | I 0 0 ] [ | V2 ] */
  411. /* > [ 0 S 0 | 0 C 0 ] */
  412. /* > [ 0 0 I | 0 0 0 ] */
  413. /* > */
  414. /* > X11 is P-by-Q. The unitary matrices U1, U2, V1, and V2 are P-by-P, */
  415. /* > (M-P)-by-(M-P), Q-by-Q, and (M-Q)-by-(M-Q), respectively. C and S are */
  416. /* > R-by-R nonnegative diagonal matrices satisfying C^2 + S^2 = I, in */
  417. /* > which R = MIN(P,M-P,Q,M-Q). */
  418. /* > \endverbatim */
  419. /* Arguments: */
  420. /* ========== */
  421. /* > \param[in] JOBU1 */
  422. /* > \verbatim */
  423. /* > JOBU1 is CHARACTER */
  424. /* > = 'Y': U1 is computed; */
  425. /* > otherwise: U1 is not computed. */
  426. /* > \endverbatim */
  427. /* > */
  428. /* > \param[in] JOBU2 */
  429. /* > \verbatim */
  430. /* > JOBU2 is CHARACTER */
  431. /* > = 'Y': U2 is computed; */
  432. /* > otherwise: U2 is not computed. */
  433. /* > \endverbatim */
  434. /* > */
  435. /* > \param[in] JOBV1T */
  436. /* > \verbatim */
  437. /* > JOBV1T is CHARACTER */
  438. /* > = 'Y': V1T is computed; */
  439. /* > otherwise: V1T is not computed. */
  440. /* > \endverbatim */
  441. /* > */
  442. /* > \param[in] JOBV2T */
  443. /* > \verbatim */
  444. /* > JOBV2T is CHARACTER */
  445. /* > = 'Y': V2T is computed; */
  446. /* > otherwise: V2T is not computed. */
  447. /* > \endverbatim */
  448. /* > */
  449. /* > \param[in] TRANS */
  450. /* > \verbatim */
  451. /* > TRANS is CHARACTER */
  452. /* > = 'T': X, U1, U2, V1T, and V2T are stored in row-major */
  453. /* > order; */
  454. /* > otherwise: X, U1, U2, V1T, and V2T are stored in column- */
  455. /* > major order. */
  456. /* > \endverbatim */
  457. /* > */
  458. /* > \param[in] SIGNS */
  459. /* > \verbatim */
  460. /* > SIGNS is CHARACTER */
  461. /* > = 'O': The lower-left block is made nonpositive (the */
  462. /* > "other" convention); */
  463. /* > otherwise: The upper-right block is made nonpositive (the */
  464. /* > "default" convention). */
  465. /* > \endverbatim */
  466. /* > */
  467. /* > \param[in] M */
  468. /* > \verbatim */
  469. /* > M is INTEGER */
  470. /* > The number of rows and columns in X. */
  471. /* > \endverbatim */
  472. /* > */
  473. /* > \param[in] P */
  474. /* > \verbatim */
  475. /* > P is INTEGER */
  476. /* > The number of rows in X11 and X12. 0 <= P <= M. */
  477. /* > \endverbatim */
  478. /* > */
  479. /* > \param[in] Q */
  480. /* > \verbatim */
  481. /* > Q is INTEGER */
  482. /* > The number of columns in X11 and X21. 0 <= Q <= M. */
  483. /* > \endverbatim */
  484. /* > */
  485. /* > \param[in,out] X11 */
  486. /* > \verbatim */
  487. /* > X11 is COMPLEX array, dimension (LDX11,Q) */
  488. /* > On entry, part of the unitary matrix whose CSD is desired. */
  489. /* > \endverbatim */
  490. /* > */
  491. /* > \param[in] LDX11 */
  492. /* > \verbatim */
  493. /* > LDX11 is INTEGER */
  494. /* > The leading dimension of X11. LDX11 >= MAX(1,P). */
  495. /* > \endverbatim */
  496. /* > */
  497. /* > \param[in,out] X12 */
  498. /* > \verbatim */
  499. /* > X12 is COMPLEX array, dimension (LDX12,M-Q) */
  500. /* > On entry, part of the unitary matrix whose CSD is desired. */
  501. /* > \endverbatim */
  502. /* > */
  503. /* > \param[in] LDX12 */
  504. /* > \verbatim */
  505. /* > LDX12 is INTEGER */
  506. /* > The leading dimension of X12. LDX12 >= MAX(1,P). */
  507. /* > \endverbatim */
  508. /* > */
  509. /* > \param[in,out] X21 */
  510. /* > \verbatim */
  511. /* > X21 is COMPLEX array, dimension (LDX21,Q) */
  512. /* > On entry, part of the unitary matrix whose CSD is desired. */
  513. /* > \endverbatim */
  514. /* > */
  515. /* > \param[in] LDX21 */
  516. /* > \verbatim */
  517. /* > LDX21 is INTEGER */
  518. /* > The leading dimension of X11. LDX21 >= MAX(1,M-P). */
  519. /* > \endverbatim */
  520. /* > */
  521. /* > \param[in,out] X22 */
  522. /* > \verbatim */
  523. /* > X22 is COMPLEX array, dimension (LDX22,M-Q) */
  524. /* > On entry, part of the unitary matrix whose CSD is desired. */
  525. /* > \endverbatim */
  526. /* > */
  527. /* > \param[in] LDX22 */
  528. /* > \verbatim */
  529. /* > LDX22 is INTEGER */
  530. /* > The leading dimension of X11. LDX22 >= MAX(1,M-P). */
  531. /* > \endverbatim */
  532. /* > */
  533. /* > \param[out] THETA */
  534. /* > \verbatim */
  535. /* > THETA is REAL array, dimension (R), in which R = */
  536. /* > MIN(P,M-P,Q,M-Q). */
  537. /* > C = DIAG( COS(THETA(1)), ... , COS(THETA(R)) ) and */
  538. /* > S = DIAG( SIN(THETA(1)), ... , SIN(THETA(R)) ). */
  539. /* > \endverbatim */
  540. /* > */
  541. /* > \param[out] U1 */
  542. /* > \verbatim */
  543. /* > U1 is COMPLEX array, dimension (LDU1,P) */
  544. /* > If JOBU1 = 'Y', U1 contains the P-by-P unitary matrix U1. */
  545. /* > \endverbatim */
  546. /* > */
  547. /* > \param[in] LDU1 */
  548. /* > \verbatim */
  549. /* > LDU1 is INTEGER */
  550. /* > The leading dimension of U1. If JOBU1 = 'Y', LDU1 >= */
  551. /* > MAX(1,P). */
  552. /* > \endverbatim */
  553. /* > */
  554. /* > \param[out] U2 */
  555. /* > \verbatim */
  556. /* > U2 is COMPLEX array, dimension (LDU2,M-P) */
  557. /* > If JOBU2 = 'Y', U2 contains the (M-P)-by-(M-P) unitary */
  558. /* > matrix U2. */
  559. /* > \endverbatim */
  560. /* > */
  561. /* > \param[in] LDU2 */
  562. /* > \verbatim */
  563. /* > LDU2 is INTEGER */
  564. /* > The leading dimension of U2. If JOBU2 = 'Y', LDU2 >= */
  565. /* > MAX(1,M-P). */
  566. /* > \endverbatim */
  567. /* > */
  568. /* > \param[out] V1T */
  569. /* > \verbatim */
  570. /* > V1T is COMPLEX array, dimension (LDV1T,Q) */
  571. /* > If JOBV1T = 'Y', V1T contains the Q-by-Q matrix unitary */
  572. /* > matrix V1**H. */
  573. /* > \endverbatim */
  574. /* > */
  575. /* > \param[in] LDV1T */
  576. /* > \verbatim */
  577. /* > LDV1T is INTEGER */
  578. /* > The leading dimension of V1T. If JOBV1T = 'Y', LDV1T >= */
  579. /* > MAX(1,Q). */
  580. /* > \endverbatim */
  581. /* > */
  582. /* > \param[out] V2T */
  583. /* > \verbatim */
  584. /* > V2T is COMPLEX array, dimension (LDV2T,M-Q) */
  585. /* > If JOBV2T = 'Y', V2T contains the (M-Q)-by-(M-Q) unitary */
  586. /* > matrix V2**H. */
  587. /* > \endverbatim */
  588. /* > */
  589. /* > \param[in] LDV2T */
  590. /* > \verbatim */
  591. /* > LDV2T is INTEGER */
  592. /* > The leading dimension of V2T. If JOBV2T = 'Y', LDV2T >= */
  593. /* > MAX(1,M-Q). */
  594. /* > \endverbatim */
  595. /* > */
  596. /* > \param[out] WORK */
  597. /* > \verbatim */
  598. /* > WORK is COMPLEX array, dimension (MAX(1,LWORK)) */
  599. /* > On exit, if INFO = 0, WORK(1) returns the optimal LWORK. */
  600. /* > \endverbatim */
  601. /* > */
  602. /* > \param[in] LWORK */
  603. /* > \verbatim */
  604. /* > LWORK is INTEGER */
  605. /* > The dimension of the array WORK. */
  606. /* > */
  607. /* > If LWORK = -1, then a workspace query is assumed; the routine */
  608. /* > only calculates the optimal size of the WORK array, returns */
  609. /* > this value as the first entry of the work array, and no error */
  610. /* > message related to LWORK is issued by XERBLA. */
  611. /* > \endverbatim */
  612. /* > */
  613. /* > \param[out] RWORK */
  614. /* > \verbatim */
  615. /* > RWORK is REAL array, dimension MAX(1,LRWORK) */
  616. /* > On exit, if INFO = 0, RWORK(1) returns the optimal LRWORK. */
  617. /* > If INFO > 0 on exit, RWORK(2:R) contains the values PHI(1), */
  618. /* > ..., PHI(R-1) that, together with THETA(1), ..., THETA(R), */
  619. /* > define the matrix in intermediate bidiagonal-block form */
  620. /* > remaining after nonconvergence. INFO specifies the number */
  621. /* > of nonzero PHI's. */
  622. /* > \endverbatim */
  623. /* > */
  624. /* > \param[in] LRWORK */
  625. /* > \verbatim */
  626. /* > LRWORK is INTEGER */
  627. /* > The dimension of the array RWORK. */
  628. /* > */
  629. /* > If LRWORK = -1, then a workspace query is assumed; the routine */
  630. /* > only calculates the optimal size of the RWORK array, returns */
  631. /* > this value as the first entry of the work array, and no error */
  632. /* > message related to LRWORK is issued by XERBLA. */
  633. /* > \endverbatim */
  634. /* > */
  635. /* > \param[out] IWORK */
  636. /* > \verbatim */
  637. /* > IWORK is INTEGER array, dimension (M-MIN(P,M-P,Q,M-Q)) */
  638. /* > \endverbatim */
  639. /* > */
  640. /* > \param[out] INFO */
  641. /* > \verbatim */
  642. /* > INFO is INTEGER */
  643. /* > = 0: successful exit. */
  644. /* > < 0: if INFO = -i, the i-th argument had an illegal value. */
  645. /* > > 0: CBBCSD did not converge. See the description of RWORK */
  646. /* > above for details. */
  647. /* > \endverbatim */
  648. /* > \par References: */
  649. /* ================ */
  650. /* > */
  651. /* > [1] Brian D. Sutton. Computing the complete CS decomposition. Numer. */
  652. /* > Algorithms, 50(1):33-65, 2009. */
  653. /* Authors: */
  654. /* ======== */
  655. /* > \author Univ. of Tennessee */
  656. /* > \author Univ. of California Berkeley */
  657. /* > \author Univ. of Colorado Denver */
  658. /* > \author NAG Ltd. */
  659. /* > \date June 2016 */
  660. /* > \ingroup complexOTHERcomputational */
  661. /* ===================================================================== */
  662. /* Subroutine */ int cuncsd_(char *jobu1, char *jobu2, char *jobv1t, char *
  663. jobv2t, char *trans, char *signs, integer *m, integer *p, integer *q,
  664. complex *x11, integer *ldx11, complex *x12, integer *ldx12, complex *
  665. x21, integer *ldx21, complex *x22, integer *ldx22, real *theta,
  666. complex *u1, integer *ldu1, complex *u2, integer *ldu2, complex *v1t,
  667. integer *ldv1t, complex *v2t, integer *ldv2t, complex *work, integer *
  668. lwork, real *rwork, integer *lrwork, integer *iwork, integer *info)
  669. {
  670. /* System generated locals */
  671. integer u1_dim1, u1_offset, u2_dim1, u2_offset, v1t_dim1, v1t_offset,
  672. v2t_dim1, v2t_offset, x11_dim1, x11_offset, x12_dim1, x12_offset,
  673. x21_dim1, x21_offset, x22_dim1, x22_offset, i__1, i__2, i__3,
  674. i__4, i__5, i__6;
  675. /* Local variables */
  676. integer ib11d, ib11e, ib12d, ib12e, ib21d, ib21e, ib22d, ib22e, iphi;
  677. logical colmajor;
  678. integer lworkmin;
  679. logical defaultsigns;
  680. integer lworkopt, i__, j;
  681. extern logical lsame_(char *, char *);
  682. integer childinfo, p1, q1, lbbcsdworkmin, itaup1, itaup2, itauq1, itauq2,
  683. lorbdbworkmin, lrworkmin, lbbcsdworkopt;
  684. logical wantu1, wantu2;
  685. extern /* Subroutine */ int cbbcsd_(char *, char *, char *, char *, char *
  686. , integer *, integer *, integer *, real *, real *, complex *,
  687. integer *, complex *, integer *, complex *, integer *, complex *,
  688. integer *, real *, real *, real *, real *, real *, real *, real *,
  689. real *, real *, integer *, integer *);
  690. integer lrworkopt, ibbcsd, lorbdbworkopt;
  691. extern /* Subroutine */ int cunbdb_(char *, char *, integer *, integer *,
  692. integer *, complex *, integer *, complex *, integer *, complex *,
  693. integer *, complex *, integer *, real *, real *, complex *,
  694. complex *, complex *, complex *, complex *, integer *, integer *);
  695. integer iorbdb, lorglqworkmin, lorgqrworkmin;
  696. extern /* Subroutine */ int clacpy_(char *, integer *, integer *, complex
  697. *, integer *, complex *, integer *), xerbla_(char *,
  698. integer *, ftnlen), clapmr_(logical *, integer *, integer *,
  699. complex *, integer *, integer *), clapmt_(logical *, integer *,
  700. integer *, complex *, integer *, integer *);
  701. integer lorglqworkopt;
  702. extern /* Subroutine */ int cunglq_(integer *, integer *, integer *,
  703. complex *, integer *, complex *, complex *, integer *, integer *);
  704. integer lorgqrworkopt, iorglq;
  705. extern /* Subroutine */ int cungqr_(integer *, integer *, integer *,
  706. complex *, integer *, complex *, complex *, integer *, integer *);
  707. integer iorgqr;
  708. char signst[1], transt[1];
  709. integer lbbcsdwork;
  710. logical lquery;
  711. integer lorbdbwork, lorglqwork, lorgqrwork;
  712. logical wantv1t, wantv2t, lrquery;
  713. /* -- LAPACK computational routine (version 3.7.1) -- */
  714. /* -- LAPACK is a software package provided by Univ. of Tennessee, -- */
  715. /* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- */
  716. /* June 2016 */
  717. /* =================================================================== */
  718. /* Test input arguments */
  719. /* Parameter adjustments */
  720. x11_dim1 = *ldx11;
  721. x11_offset = 1 + x11_dim1 * 1;
  722. x11 -= x11_offset;
  723. x12_dim1 = *ldx12;
  724. x12_offset = 1 + x12_dim1 * 1;
  725. x12 -= x12_offset;
  726. x21_dim1 = *ldx21;
  727. x21_offset = 1 + x21_dim1 * 1;
  728. x21 -= x21_offset;
  729. x22_dim1 = *ldx22;
  730. x22_offset = 1 + x22_dim1 * 1;
  731. x22 -= x22_offset;
  732. --theta;
  733. u1_dim1 = *ldu1;
  734. u1_offset = 1 + u1_dim1 * 1;
  735. u1 -= u1_offset;
  736. u2_dim1 = *ldu2;
  737. u2_offset = 1 + u2_dim1 * 1;
  738. u2 -= u2_offset;
  739. v1t_dim1 = *ldv1t;
  740. v1t_offset = 1 + v1t_dim1 * 1;
  741. v1t -= v1t_offset;
  742. v2t_dim1 = *ldv2t;
  743. v2t_offset = 1 + v2t_dim1 * 1;
  744. v2t -= v2t_offset;
  745. --work;
  746. --rwork;
  747. --iwork;
  748. /* Function Body */
  749. *info = 0;
  750. wantu1 = lsame_(jobu1, "Y");
  751. wantu2 = lsame_(jobu2, "Y");
  752. wantv1t = lsame_(jobv1t, "Y");
  753. wantv2t = lsame_(jobv2t, "Y");
  754. colmajor = ! lsame_(trans, "T");
  755. defaultsigns = ! lsame_(signs, "O");
  756. lquery = *lwork == -1;
  757. lrquery = *lrwork == -1;
  758. if (*m < 0) {
  759. *info = -7;
  760. } else if (*p < 0 || *p > *m) {
  761. *info = -8;
  762. } else if (*q < 0 || *q > *m) {
  763. *info = -9;
  764. } else if (colmajor && *ldx11 < f2cmax(1,*p)) {
  765. *info = -11;
  766. } else if (! colmajor && *ldx11 < f2cmax(1,*q)) {
  767. *info = -11;
  768. } else if (colmajor && *ldx12 < f2cmax(1,*p)) {
  769. *info = -13;
  770. } else /* if(complicated condition) */ {
  771. /* Computing MAX */
  772. i__1 = 1, i__2 = *m - *q;
  773. if (! colmajor && *ldx12 < f2cmax(i__1,i__2)) {
  774. *info = -13;
  775. } else /* if(complicated condition) */ {
  776. /* Computing MAX */
  777. i__1 = 1, i__2 = *m - *p;
  778. if (colmajor && *ldx21 < f2cmax(i__1,i__2)) {
  779. *info = -15;
  780. } else if (! colmajor && *ldx21 < f2cmax(1,*q)) {
  781. *info = -15;
  782. } else /* if(complicated condition) */ {
  783. /* Computing MAX */
  784. i__1 = 1, i__2 = *m - *p;
  785. if (colmajor && *ldx22 < f2cmax(i__1,i__2)) {
  786. *info = -17;
  787. } else /* if(complicated condition) */ {
  788. /* Computing MAX */
  789. i__1 = 1, i__2 = *m - *q;
  790. if (! colmajor && *ldx22 < f2cmax(i__1,i__2)) {
  791. *info = -17;
  792. } else if (wantu1 && *ldu1 < *p) {
  793. *info = -20;
  794. } else if (wantu2 && *ldu2 < *m - *p) {
  795. *info = -22;
  796. } else if (wantv1t && *ldv1t < *q) {
  797. *info = -24;
  798. } else if (wantv2t && *ldv2t < *m - *q) {
  799. *info = -26;
  800. }
  801. }
  802. }
  803. }
  804. }
  805. /* Work with transpose if convenient */
  806. /* Computing MIN */
  807. i__1 = *p, i__2 = *m - *p;
  808. /* Computing MIN */
  809. i__3 = *q, i__4 = *m - *q;
  810. if (*info == 0 && f2cmin(i__1,i__2) < f2cmin(i__3,i__4)) {
  811. if (colmajor) {
  812. *(unsigned char *)transt = 'T';
  813. } else {
  814. *(unsigned char *)transt = 'N';
  815. }
  816. if (defaultsigns) {
  817. *(unsigned char *)signst = 'O';
  818. } else {
  819. *(unsigned char *)signst = 'D';
  820. }
  821. cuncsd_(jobv1t, jobv2t, jobu1, jobu2, transt, signst, m, q, p, &x11[
  822. x11_offset], ldx11, &x21[x21_offset], ldx21, &x12[x12_offset],
  823. ldx12, &x22[x22_offset], ldx22, &theta[1], &v1t[v1t_offset],
  824. ldv1t, &v2t[v2t_offset], ldv2t, &u1[u1_offset], ldu1, &u2[
  825. u2_offset], ldu2, &work[1], lwork, &rwork[1], lrwork, &iwork[
  826. 1], info);
  827. return 0;
  828. }
  829. /* Work with permutation [ 0 I; I 0 ] * X * [ 0 I; I 0 ] if */
  830. /* convenient */
  831. if (*info == 0 && *m - *q < *q) {
  832. if (defaultsigns) {
  833. *(unsigned char *)signst = 'O';
  834. } else {
  835. *(unsigned char *)signst = 'D';
  836. }
  837. i__1 = *m - *p;
  838. i__2 = *m - *q;
  839. cuncsd_(jobu2, jobu1, jobv2t, jobv1t, trans, signst, m, &i__1, &i__2,
  840. &x22[x22_offset], ldx22, &x21[x21_offset], ldx21, &x12[
  841. x12_offset], ldx12, &x11[x11_offset], ldx11, &theta[1], &u2[
  842. u2_offset], ldu2, &u1[u1_offset], ldu1, &v2t[v2t_offset],
  843. ldv2t, &v1t[v1t_offset], ldv1t, &work[1], lwork, &rwork[1],
  844. lrwork, &iwork[1], info);
  845. return 0;
  846. }
  847. /* Compute workspace */
  848. if (*info == 0) {
  849. /* Real workspace */
  850. iphi = 2;
  851. /* Computing MAX */
  852. i__1 = 1, i__2 = *q - 1;
  853. ib11d = iphi + f2cmax(i__1,i__2);
  854. ib11e = ib11d + f2cmax(1,*q);
  855. /* Computing MAX */
  856. i__1 = 1, i__2 = *q - 1;
  857. ib12d = ib11e + f2cmax(i__1,i__2);
  858. ib12e = ib12d + f2cmax(1,*q);
  859. /* Computing MAX */
  860. i__1 = 1, i__2 = *q - 1;
  861. ib21d = ib12e + f2cmax(i__1,i__2);
  862. ib21e = ib21d + f2cmax(1,*q);
  863. /* Computing MAX */
  864. i__1 = 1, i__2 = *q - 1;
  865. ib22d = ib21e + f2cmax(i__1,i__2);
  866. ib22e = ib22d + f2cmax(1,*q);
  867. /* Computing MAX */
  868. i__1 = 1, i__2 = *q - 1;
  869. ibbcsd = ib22e + f2cmax(i__1,i__2);
  870. cbbcsd_(jobu1, jobu2, jobv1t, jobv2t, trans, m, p, q, &theta[1], &
  871. theta[1], &u1[u1_offset], ldu1, &u2[u2_offset], ldu2, &v1t[
  872. v1t_offset], ldv1t, &v2t[v2t_offset], ldv2t, &theta[1], &
  873. theta[1], &theta[1], &theta[1], &theta[1], &theta[1], &theta[
  874. 1], &theta[1], &rwork[1], &c_n1, &childinfo);
  875. lbbcsdworkopt = (integer) rwork[1];
  876. lbbcsdworkmin = lbbcsdworkopt;
  877. lrworkopt = ibbcsd + lbbcsdworkopt - 1;
  878. lrworkmin = ibbcsd + lbbcsdworkmin - 1;
  879. rwork[1] = (real) lrworkopt;
  880. /* Complex workspace */
  881. itaup1 = 2;
  882. itaup2 = itaup1 + f2cmax(1,*p);
  883. /* Computing MAX */
  884. i__1 = 1, i__2 = *m - *p;
  885. itauq1 = itaup2 + f2cmax(i__1,i__2);
  886. itauq2 = itauq1 + f2cmax(1,*q);
  887. /* Computing MAX */
  888. i__1 = 1, i__2 = *m - *q;
  889. iorgqr = itauq2 + f2cmax(i__1,i__2);
  890. i__1 = *m - *q;
  891. i__2 = *m - *q;
  892. i__3 = *m - *q;
  893. /* Computing MAX */
  894. i__5 = 1, i__6 = *m - *q;
  895. i__4 = f2cmax(i__5,i__6);
  896. cungqr_(&i__1, &i__2, &i__3, &u1[u1_offset], &i__4, &u1[u1_offset], &
  897. work[1], &c_n1, &childinfo);
  898. lorgqrworkopt = (integer) work[1].r;
  899. /* Computing MAX */
  900. i__1 = 1, i__2 = *m - *q;
  901. lorgqrworkmin = f2cmax(i__1,i__2);
  902. /* Computing MAX */
  903. i__1 = 1, i__2 = *m - *q;
  904. iorglq = itauq2 + f2cmax(i__1,i__2);
  905. i__1 = *m - *q;
  906. i__2 = *m - *q;
  907. i__3 = *m - *q;
  908. /* Computing MAX */
  909. i__5 = 1, i__6 = *m - *q;
  910. i__4 = f2cmax(i__5,i__6);
  911. cunglq_(&i__1, &i__2, &i__3, &u1[u1_offset], &i__4, &u1[u1_offset], &
  912. work[1], &c_n1, &childinfo);
  913. lorglqworkopt = (integer) work[1].r;
  914. /* Computing MAX */
  915. i__1 = 1, i__2 = *m - *q;
  916. lorglqworkmin = f2cmax(i__1,i__2);
  917. /* Computing MAX */
  918. i__1 = 1, i__2 = *m - *q;
  919. iorbdb = itauq2 + f2cmax(i__1,i__2);
  920. cunbdb_(trans, signs, m, p, q, &x11[x11_offset], ldx11, &x12[
  921. x12_offset], ldx12, &x21[x21_offset], ldx21, &x22[x22_offset],
  922. ldx22, &theta[1], &theta[1], &u1[u1_offset], &u2[u2_offset],
  923. &v1t[v1t_offset], &v2t[v2t_offset], &work[1], &c_n1, &
  924. childinfo);
  925. lorbdbworkopt = (integer) work[1].r;
  926. lorbdbworkmin = lorbdbworkopt;
  927. /* Computing MAX */
  928. i__1 = iorgqr + lorgqrworkopt, i__2 = iorglq + lorglqworkopt, i__1 =
  929. f2cmax(i__1,i__2), i__2 = iorbdb + lorbdbworkopt;
  930. lworkopt = f2cmax(i__1,i__2) - 1;
  931. /* Computing MAX */
  932. i__1 = iorgqr + lorgqrworkmin, i__2 = iorglq + lorglqworkmin, i__1 =
  933. f2cmax(i__1,i__2), i__2 = iorbdb + lorbdbworkmin;
  934. lworkmin = f2cmax(i__1,i__2) - 1;
  935. i__1 = f2cmax(lworkopt,lworkmin);
  936. work[1].r = (real) i__1, work[1].i = 0.f;
  937. if (*lwork < lworkmin && ! (lquery || lrquery)) {
  938. *info = -22;
  939. } else if (*lrwork < lrworkmin && ! (lquery || lrquery)) {
  940. *info = -24;
  941. } else {
  942. lorgqrwork = *lwork - iorgqr + 1;
  943. lorglqwork = *lwork - iorglq + 1;
  944. lorbdbwork = *lwork - iorbdb + 1;
  945. lbbcsdwork = *lrwork - ibbcsd + 1;
  946. }
  947. }
  948. /* Abort if any illegal arguments */
  949. if (*info != 0) {
  950. i__1 = -(*info);
  951. xerbla_("CUNCSD", &i__1, (ftnlen)6);
  952. return 0;
  953. } else if (lquery || lrquery) {
  954. return 0;
  955. }
  956. /* Transform to bidiagonal block form */
  957. cunbdb_(trans, signs, m, p, q, &x11[x11_offset], ldx11, &x12[x12_offset],
  958. ldx12, &x21[x21_offset], ldx21, &x22[x22_offset], ldx22, &theta[1]
  959. , &rwork[iphi], &work[itaup1], &work[itaup2], &work[itauq1], &
  960. work[itauq2], &work[iorbdb], &lorbdbwork, &childinfo);
  961. /* Accumulate Householder reflectors */
  962. if (colmajor) {
  963. if (wantu1 && *p > 0) {
  964. clacpy_("L", p, q, &x11[x11_offset], ldx11, &u1[u1_offset], ldu1);
  965. cungqr_(p, p, q, &u1[u1_offset], ldu1, &work[itaup1], &work[
  966. iorgqr], &lorgqrwork, info);
  967. }
  968. if (wantu2 && *m - *p > 0) {
  969. i__1 = *m - *p;
  970. clacpy_("L", &i__1, q, &x21[x21_offset], ldx21, &u2[u2_offset],
  971. ldu2);
  972. i__1 = *m - *p;
  973. i__2 = *m - *p;
  974. cungqr_(&i__1, &i__2, q, &u2[u2_offset], ldu2, &work[itaup2], &
  975. work[iorgqr], &lorgqrwork, info);
  976. }
  977. if (wantv1t && *q > 0) {
  978. i__1 = *q - 1;
  979. i__2 = *q - 1;
  980. clacpy_("U", &i__1, &i__2, &x11[(x11_dim1 << 1) + 1], ldx11, &v1t[
  981. (v1t_dim1 << 1) + 2], ldv1t);
  982. i__1 = v1t_dim1 + 1;
  983. v1t[i__1].r = 1.f, v1t[i__1].i = 0.f;
  984. i__1 = *q;
  985. for (j = 2; j <= i__1; ++j) {
  986. i__2 = j * v1t_dim1 + 1;
  987. v1t[i__2].r = 0.f, v1t[i__2].i = 0.f;
  988. i__2 = j + v1t_dim1;
  989. v1t[i__2].r = 0.f, v1t[i__2].i = 0.f;
  990. }
  991. i__1 = *q - 1;
  992. i__2 = *q - 1;
  993. i__3 = *q - 1;
  994. cunglq_(&i__1, &i__2, &i__3, &v1t[(v1t_dim1 << 1) + 2], ldv1t, &
  995. work[itauq1], &work[iorglq], &lorglqwork, info);
  996. }
  997. if (wantv2t && *m - *q > 0) {
  998. i__1 = *m - *q;
  999. clacpy_("U", p, &i__1, &x12[x12_offset], ldx12, &v2t[v2t_offset],
  1000. ldv2t);
  1001. if (*m - *p > *q) {
  1002. i__1 = *m - *p - *q;
  1003. i__2 = *m - *p - *q;
  1004. clacpy_("U", &i__1, &i__2, &x22[*q + 1 + (*p + 1) * x22_dim1],
  1005. ldx22, &v2t[*p + 1 + (*p + 1) * v2t_dim1], ldv2t);
  1006. }
  1007. if (*m > *q) {
  1008. i__1 = *m - *q;
  1009. i__2 = *m - *q;
  1010. i__3 = *m - *q;
  1011. cunglq_(&i__1, &i__2, &i__3, &v2t[v2t_offset], ldv2t, &work[
  1012. itauq2], &work[iorglq], &lorglqwork, info);
  1013. }
  1014. }
  1015. } else {
  1016. if (wantu1 && *p > 0) {
  1017. clacpy_("U", q, p, &x11[x11_offset], ldx11, &u1[u1_offset], ldu1);
  1018. cunglq_(p, p, q, &u1[u1_offset], ldu1, &work[itaup1], &work[
  1019. iorglq], &lorglqwork, info);
  1020. }
  1021. if (wantu2 && *m - *p > 0) {
  1022. i__1 = *m - *p;
  1023. clacpy_("U", q, &i__1, &x21[x21_offset], ldx21, &u2[u2_offset],
  1024. ldu2);
  1025. i__1 = *m - *p;
  1026. i__2 = *m - *p;
  1027. cunglq_(&i__1, &i__2, q, &u2[u2_offset], ldu2, &work[itaup2], &
  1028. work[iorglq], &lorglqwork, info);
  1029. }
  1030. if (wantv1t && *q > 0) {
  1031. i__1 = *q - 1;
  1032. i__2 = *q - 1;
  1033. clacpy_("L", &i__1, &i__2, &x11[x11_dim1 + 2], ldx11, &v1t[(
  1034. v1t_dim1 << 1) + 2], ldv1t);
  1035. i__1 = v1t_dim1 + 1;
  1036. v1t[i__1].r = 1.f, v1t[i__1].i = 0.f;
  1037. i__1 = *q;
  1038. for (j = 2; j <= i__1; ++j) {
  1039. i__2 = j * v1t_dim1 + 1;
  1040. v1t[i__2].r = 0.f, v1t[i__2].i = 0.f;
  1041. i__2 = j + v1t_dim1;
  1042. v1t[i__2].r = 0.f, v1t[i__2].i = 0.f;
  1043. }
  1044. i__1 = *q - 1;
  1045. i__2 = *q - 1;
  1046. i__3 = *q - 1;
  1047. cungqr_(&i__1, &i__2, &i__3, &v1t[(v1t_dim1 << 1) + 2], ldv1t, &
  1048. work[itauq1], &work[iorgqr], &lorgqrwork, info);
  1049. }
  1050. if (wantv2t && *m - *q > 0) {
  1051. /* Computing MIN */
  1052. i__1 = *p + 1;
  1053. p1 = f2cmin(i__1,*m);
  1054. /* Computing MIN */
  1055. i__1 = *q + 1;
  1056. q1 = f2cmin(i__1,*m);
  1057. i__1 = *m - *q;
  1058. clacpy_("L", &i__1, p, &x12[x12_offset], ldx12, &v2t[v2t_offset],
  1059. ldv2t);
  1060. if (*m > *p + *q) {
  1061. i__1 = *m - *p - *q;
  1062. i__2 = *m - *p - *q;
  1063. clacpy_("L", &i__1, &i__2, &x22[p1 + q1 * x22_dim1], ldx22, &
  1064. v2t[*p + 1 + (*p + 1) * v2t_dim1], ldv2t);
  1065. }
  1066. i__1 = *m - *q;
  1067. i__2 = *m - *q;
  1068. i__3 = *m - *q;
  1069. cungqr_(&i__1, &i__2, &i__3, &v2t[v2t_offset], ldv2t, &work[
  1070. itauq2], &work[iorgqr], &lorgqrwork, info);
  1071. }
  1072. }
  1073. /* Compute the CSD of the matrix in bidiagonal-block form */
  1074. cbbcsd_(jobu1, jobu2, jobv1t, jobv2t, trans, m, p, q, &theta[1], &rwork[
  1075. iphi], &u1[u1_offset], ldu1, &u2[u2_offset], ldu2, &v1t[
  1076. v1t_offset], ldv1t, &v2t[v2t_offset], ldv2t, &rwork[ib11d], &
  1077. rwork[ib11e], &rwork[ib12d], &rwork[ib12e], &rwork[ib21d], &rwork[
  1078. ib21e], &rwork[ib22d], &rwork[ib22e], &rwork[ibbcsd], &lbbcsdwork,
  1079. info);
  1080. /* Permute rows and columns to place identity submatrices in top- */
  1081. /* left corner of (1,1)-block and/or bottom-right corner of (1,2)- */
  1082. /* block and/or bottom-right corner of (2,1)-block and/or top-left */
  1083. /* corner of (2,2)-block */
  1084. if (*q > 0 && wantu2) {
  1085. i__1 = *q;
  1086. for (i__ = 1; i__ <= i__1; ++i__) {
  1087. iwork[i__] = *m - *p - *q + i__;
  1088. }
  1089. i__1 = *m - *p;
  1090. for (i__ = *q + 1; i__ <= i__1; ++i__) {
  1091. iwork[i__] = i__ - *q;
  1092. }
  1093. if (colmajor) {
  1094. i__1 = *m - *p;
  1095. i__2 = *m - *p;
  1096. clapmt_(&c_false, &i__1, &i__2, &u2[u2_offset], ldu2, &iwork[1]);
  1097. } else {
  1098. i__1 = *m - *p;
  1099. i__2 = *m - *p;
  1100. clapmr_(&c_false, &i__1, &i__2, &u2[u2_offset], ldu2, &iwork[1]);
  1101. }
  1102. }
  1103. if (*m > 0 && wantv2t) {
  1104. i__1 = *p;
  1105. for (i__ = 1; i__ <= i__1; ++i__) {
  1106. iwork[i__] = *m - *p - *q + i__;
  1107. }
  1108. i__1 = *m - *q;
  1109. for (i__ = *p + 1; i__ <= i__1; ++i__) {
  1110. iwork[i__] = i__ - *p;
  1111. }
  1112. if (! colmajor) {
  1113. i__1 = *m - *q;
  1114. i__2 = *m - *q;
  1115. clapmt_(&c_false, &i__1, &i__2, &v2t[v2t_offset], ldv2t, &iwork[1]
  1116. );
  1117. } else {
  1118. i__1 = *m - *q;
  1119. i__2 = *m - *q;
  1120. clapmr_(&c_false, &i__1, &i__2, &v2t[v2t_offset], ldv2t, &iwork[1]
  1121. );
  1122. }
  1123. }
  1124. return 0;
  1125. /* End CUNCSD */
  1126. } /* cuncsd_ */