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.

zuncsd.c 38 kB

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