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.

dorcsd2by1.c 42 kB

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