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.

cggsvp.c 28 kB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030
  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 d_lg10(x) ( 0.43429448190325182765 * log(*(x)) )
  191. #define d_log(x) (log(*(x)))
  192. #define d_mod(x, y) (fmod(*(x), *(y)))
  193. #define u_nint(__x) ((__x)>=0 ? floor((__x) + .5) : -floor(.5 - (__x)))
  194. #define d_nint(x) u_nint(*(x))
  195. #define u_sign(__a,__b) ((__b) >= 0 ? ((__a) >= 0 ? (__a) : -(__a)) : -((__a) >= 0 ? (__a) : -(__a)))
  196. #define d_sign(a,b) u_sign(*(a),*(b))
  197. #define d_sin(x) (sin(*(x)))
  198. #define d_sinh(x) (sinh(*(x)))
  199. #define d_sqrt(x) (sqrt(*(x)))
  200. #define d_tan(x) (tan(*(x)))
  201. #define d_tanh(x) (tanh(*(x)))
  202. #define i_abs(x) abs(*(x))
  203. #define i_dnnt(x) ((integer)u_nint(*(x)))
  204. #define i_len(s, n) (n)
  205. #define i_nint(x) ((integer)u_nint(*(x)))
  206. #define i_sign(a,b) ((integer)u_sign((integer)*(a),(integer)*(b)))
  207. #define pow_dd(ap, bp) ( pow(*(ap), *(bp)))
  208. #define pow_si(B,E) spow_ui(*(B),*(E))
  209. #define pow_di(B,E) dpow_ui(*(B),*(E))
  210. #define pow_zi(p, a, b) {pCd(p) = zpow_ui(Cd(a), *(b));}
  211. #define pow_zz(R,A,B) {pCd(R) = cpow(Cd(A),*(B));}
  212. #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++ = ' '; }
  213. #define s_cmp(a,b,c,d) ((integer)strncmp((a),(b),f2cmin((c),(d))))
  214. #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]; }
  215. #define sig_die(s, kill) { exit(1); }
  216. #define s_stop(s, n) {exit(0);}
  217. static char junk[] = "\n@(#)LIBF77 VERSION 19990503\n";
  218. #define z_abs(z) (cabs(Cd(z)))
  219. #define z_exp(R, Z) {pCd(R) = cexp(Cd(Z));}
  220. #define z_sqrt(R, Z) {pCd(R) = csqrt(Cd(Z));}
  221. #define myexit_() break;
  222. #define mycycle() continue;
  223. #define myceiling(w) {ceil(w)}
  224. #define myhuge(w) {HUGE_VAL}
  225. #define mymaxloc_(w,s,e,n) {if (sizeof(*(w)) == sizeof(double)) dmaxloc_((w),*(s),*(e),n); else dmaxloc_((w),*(s),*(e),n);}
  226. /* procedure parameter types for -A and -C++ */
  227. #define F2C_proc_par_types 1
  228. #ifdef __cplusplus
  229. typedef logical (*L_fp)(...);
  230. #else
  231. typedef logical (*L_fp)();
  232. #endif
  233. static float spow_ui(float x, integer n) {
  234. float pow=1.0; unsigned long int u;
  235. if(n != 0) {
  236. if(n < 0) n = -n, x = 1/x;
  237. for(u = n; ; ) {
  238. if(u & 01) pow *= x;
  239. if(u >>= 1) x *= x;
  240. else break;
  241. }
  242. }
  243. return pow;
  244. }
  245. static double dpow_ui(double x, integer n) {
  246. double pow=1.0; unsigned long int u;
  247. if(n != 0) {
  248. if(n < 0) n = -n, x = 1/x;
  249. for(u = n; ; ) {
  250. if(u & 01) pow *= x;
  251. if(u >>= 1) x *= x;
  252. else break;
  253. }
  254. }
  255. return pow;
  256. }
  257. static _Complex float cpow_ui(_Complex float x, integer n) {
  258. _Complex float pow=1.0; unsigned long int u;
  259. if(n != 0) {
  260. if(n < 0) n = -n, x = 1/x;
  261. for(u = n; ; ) {
  262. if(u & 01) pow *= x;
  263. if(u >>= 1) x *= x;
  264. else break;
  265. }
  266. }
  267. return pow;
  268. }
  269. static _Complex double zpow_ui(_Complex double x, integer n) {
  270. _Complex double pow=1.0; unsigned long int u;
  271. if(n != 0) {
  272. if(n < 0) n = -n, x = 1/x;
  273. for(u = n; ; ) {
  274. if(u & 01) pow *= x;
  275. if(u >>= 1) x *= x;
  276. else break;
  277. }
  278. }
  279. return pow;
  280. }
  281. static integer pow_ii(integer x, integer n) {
  282. integer pow; unsigned long int u;
  283. if (n <= 0) {
  284. if (n == 0 || x == 1) pow = 1;
  285. else if (x != -1) pow = x == 0 ? 1/x : 0;
  286. else n = -n;
  287. }
  288. if ((n > 0) || !(n == 0 || x == 1 || x != -1)) {
  289. u = n;
  290. for(pow = 1; ; ) {
  291. if(u & 01) pow *= x;
  292. if(u >>= 1) x *= x;
  293. else break;
  294. }
  295. }
  296. return pow;
  297. }
  298. static integer dmaxloc_(double *w, integer s, integer e, integer *n)
  299. {
  300. double m; integer i, mi;
  301. for(m=w[s-1], mi=s, i=s+1; i<=e; i++)
  302. if (w[i-1]>m) mi=i ,m=w[i-1];
  303. return mi-s+1;
  304. }
  305. static integer smaxloc_(float *w, integer s, integer e, integer *n)
  306. {
  307. float m; integer i, mi;
  308. for(m=w[s-1], mi=s, i=s+1; i<=e; i++)
  309. if (w[i-1]>m) mi=i ,m=w[i-1];
  310. return mi-s+1;
  311. }
  312. static inline void cdotc_(complex *z, integer *n_, complex *x, integer *incx_, complex *y, integer *incy_) {
  313. integer n = *n_, incx = *incx_, incy = *incy_, i;
  314. _Complex float zdotc = 0.0;
  315. if (incx == 1 && incy == 1) {
  316. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  317. zdotc += conjf(Cf(&x[i])) * Cf(&y[i]);
  318. }
  319. } else {
  320. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  321. zdotc += conjf(Cf(&x[i*incx])) * Cf(&y[i*incy]);
  322. }
  323. }
  324. pCf(z) = zdotc;
  325. }
  326. static inline void zdotc_(doublecomplex *z, integer *n_, doublecomplex *x, integer *incx_, doublecomplex *y, integer *incy_) {
  327. integer n = *n_, incx = *incx_, incy = *incy_, i;
  328. _Complex double zdotc = 0.0;
  329. if (incx == 1 && incy == 1) {
  330. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  331. zdotc += conj(Cd(&x[i])) * Cd(&y[i]);
  332. }
  333. } else {
  334. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  335. zdotc += conj(Cd(&x[i*incx])) * Cd(&y[i*incy]);
  336. }
  337. }
  338. pCd(z) = zdotc;
  339. }
  340. static inline void cdotu_(complex *z, integer *n_, complex *x, integer *incx_, complex *y, integer *incy_) {
  341. integer n = *n_, incx = *incx_, incy = *incy_, i;
  342. _Complex float zdotc = 0.0;
  343. if (incx == 1 && incy == 1) {
  344. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  345. zdotc += Cf(&x[i]) * Cf(&y[i]);
  346. }
  347. } else {
  348. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  349. zdotc += Cf(&x[i*incx]) * Cf(&y[i*incy]);
  350. }
  351. }
  352. pCf(z) = zdotc;
  353. }
  354. static inline void zdotu_(doublecomplex *z, integer *n_, doublecomplex *x, integer *incx_, doublecomplex *y, integer *incy_) {
  355. integer n = *n_, incx = *incx_, incy = *incy_, i;
  356. _Complex double zdotc = 0.0;
  357. if (incx == 1 && incy == 1) {
  358. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  359. zdotc += Cd(&x[i]) * Cd(&y[i]);
  360. }
  361. } else {
  362. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  363. zdotc += Cd(&x[i*incx]) * Cd(&y[i*incy]);
  364. }
  365. }
  366. pCd(z) = zdotc;
  367. }
  368. #endif
  369. /* -- translated by f2c (version 20000121).
  370. You must link the resulting object file with the libraries:
  371. -lf2c -lm (in that order)
  372. */
  373. /* Table of constant values */
  374. static complex c_b1 = {0.f,0.f};
  375. static complex c_b2 = {1.f,0.f};
  376. /* > \brief \b CGGSVP */
  377. /* =========== DOCUMENTATION =========== */
  378. /* Online html documentation available at */
  379. /* http://www.netlib.org/lapack/explore-html/ */
  380. /* > \htmlonly */
  381. /* > Download CGGSVP + dependencies */
  382. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/cggsvp.
  383. f"> */
  384. /* > [TGZ]</a> */
  385. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/cggsvp.
  386. f"> */
  387. /* > [ZIP]</a> */
  388. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/cggsvp.
  389. f"> */
  390. /* > [TXT]</a> */
  391. /* > \endhtmlonly */
  392. /* Definition: */
  393. /* =========== */
  394. /* SUBROUTINE CGGSVP( JOBU, JOBV, JOBQ, M, P, N, A, LDA, B, LDB, */
  395. /* TOLA, TOLB, K, L, U, LDU, V, LDV, Q, LDQ, */
  396. /* IWORK, RWORK, TAU, WORK, INFO ) */
  397. /* CHARACTER JOBQ, JOBU, JOBV */
  398. /* INTEGER INFO, K, L, LDA, LDB, LDQ, LDU, LDV, M, N, P */
  399. /* REAL TOLA, TOLB */
  400. /* INTEGER IWORK( * ) */
  401. /* REAL RWORK( * ) */
  402. /* COMPLEX A( LDA, * ), B( LDB, * ), Q( LDQ, * ), */
  403. /* $ TAU( * ), U( LDU, * ), V( LDV, * ), WORK( * ) */
  404. /* > \par Purpose: */
  405. /* ============= */
  406. /* > */
  407. /* > \verbatim */
  408. /* > */
  409. /* > This routine is deprecated and has been replaced by routine CGGSVP3. */
  410. /* > */
  411. /* > CGGSVP computes unitary matrices U, V and Q such that */
  412. /* > */
  413. /* > N-K-L K L */
  414. /* > U**H*A*Q = K ( 0 A12 A13 ) if M-K-L >= 0; */
  415. /* > L ( 0 0 A23 ) */
  416. /* > M-K-L ( 0 0 0 ) */
  417. /* > */
  418. /* > N-K-L K L */
  419. /* > = K ( 0 A12 A13 ) if M-K-L < 0; */
  420. /* > M-K ( 0 0 A23 ) */
  421. /* > */
  422. /* > N-K-L K L */
  423. /* > V**H*B*Q = L ( 0 0 B13 ) */
  424. /* > P-L ( 0 0 0 ) */
  425. /* > */
  426. /* > where the K-by-K matrix A12 and L-by-L matrix B13 are nonsingular */
  427. /* > upper triangular; A23 is L-by-L upper triangular if M-K-L >= 0, */
  428. /* > otherwise A23 is (M-K)-by-L upper trapezoidal. K+L = the effective */
  429. /* > numerical rank of the (M+P)-by-N matrix (A**H,B**H)**H. */
  430. /* > */
  431. /* > This decomposition is the preprocessing step for computing the */
  432. /* > Generalized Singular Value Decomposition (GSVD), see subroutine */
  433. /* > CGGSVD. */
  434. /* > \endverbatim */
  435. /* Arguments: */
  436. /* ========== */
  437. /* > \param[in] JOBU */
  438. /* > \verbatim */
  439. /* > JOBU is CHARACTER*1 */
  440. /* > = 'U': Unitary matrix U is computed; */
  441. /* > = 'N': U is not computed. */
  442. /* > \endverbatim */
  443. /* > */
  444. /* > \param[in] JOBV */
  445. /* > \verbatim */
  446. /* > JOBV is CHARACTER*1 */
  447. /* > = 'V': Unitary matrix V is computed; */
  448. /* > = 'N': V is not computed. */
  449. /* > \endverbatim */
  450. /* > */
  451. /* > \param[in] JOBQ */
  452. /* > \verbatim */
  453. /* > JOBQ is CHARACTER*1 */
  454. /* > = 'Q': Unitary matrix Q is computed; */
  455. /* > = 'N': Q is not computed. */
  456. /* > \endverbatim */
  457. /* > */
  458. /* > \param[in] M */
  459. /* > \verbatim */
  460. /* > M is INTEGER */
  461. /* > The number of rows of the matrix A. M >= 0. */
  462. /* > \endverbatim */
  463. /* > */
  464. /* > \param[in] P */
  465. /* > \verbatim */
  466. /* > P is INTEGER */
  467. /* > The number of rows of the matrix B. P >= 0. */
  468. /* > \endverbatim */
  469. /* > */
  470. /* > \param[in] N */
  471. /* > \verbatim */
  472. /* > N is INTEGER */
  473. /* > The number of columns of the matrices A and B. N >= 0. */
  474. /* > \endverbatim */
  475. /* > */
  476. /* > \param[in,out] A */
  477. /* > \verbatim */
  478. /* > A is COMPLEX array, dimension (LDA,N) */
  479. /* > On entry, the M-by-N matrix A. */
  480. /* > On exit, A contains the triangular (or trapezoidal) matrix */
  481. /* > described in the Purpose section. */
  482. /* > \endverbatim */
  483. /* > */
  484. /* > \param[in] LDA */
  485. /* > \verbatim */
  486. /* > LDA is INTEGER */
  487. /* > The leading dimension of the array A. LDA >= f2cmax(1,M). */
  488. /* > \endverbatim */
  489. /* > */
  490. /* > \param[in,out] B */
  491. /* > \verbatim */
  492. /* > B is COMPLEX array, dimension (LDB,N) */
  493. /* > On entry, the P-by-N matrix B. */
  494. /* > On exit, B contains the triangular matrix described in */
  495. /* > the Purpose section. */
  496. /* > \endverbatim */
  497. /* > */
  498. /* > \param[in] LDB */
  499. /* > \verbatim */
  500. /* > LDB is INTEGER */
  501. /* > The leading dimension of the array B. LDB >= f2cmax(1,P). */
  502. /* > \endverbatim */
  503. /* > */
  504. /* > \param[in] TOLA */
  505. /* > \verbatim */
  506. /* > TOLA is REAL */
  507. /* > \endverbatim */
  508. /* > */
  509. /* > \param[in] TOLB */
  510. /* > \verbatim */
  511. /* > TOLB is REAL */
  512. /* > */
  513. /* > TOLA and TOLB are the thresholds to determine the effective */
  514. /* > numerical rank of matrix B and a subblock of A. Generally, */
  515. /* > they are set to */
  516. /* > TOLA = MAX(M,N)*norm(A)*MACHEPS, */
  517. /* > TOLB = MAX(P,N)*norm(B)*MACHEPS. */
  518. /* > The size of TOLA and TOLB may affect the size of backward */
  519. /* > errors of the decomposition. */
  520. /* > \endverbatim */
  521. /* > */
  522. /* > \param[out] K */
  523. /* > \verbatim */
  524. /* > K is INTEGER */
  525. /* > \endverbatim */
  526. /* > */
  527. /* > \param[out] L */
  528. /* > \verbatim */
  529. /* > L is INTEGER */
  530. /* > */
  531. /* > On exit, K and L specify the dimension of the subblocks */
  532. /* > described in Purpose section. */
  533. /* > K + L = effective numerical rank of (A**H,B**H)**H. */
  534. /* > \endverbatim */
  535. /* > */
  536. /* > \param[out] U */
  537. /* > \verbatim */
  538. /* > U is COMPLEX array, dimension (LDU,M) */
  539. /* > If JOBU = 'U', U contains the unitary matrix U. */
  540. /* > If JOBU = 'N', U is not referenced. */
  541. /* > \endverbatim */
  542. /* > */
  543. /* > \param[in] LDU */
  544. /* > \verbatim */
  545. /* > LDU is INTEGER */
  546. /* > The leading dimension of the array U. LDU >= f2cmax(1,M) if */
  547. /* > JOBU = 'U'; LDU >= 1 otherwise. */
  548. /* > \endverbatim */
  549. /* > */
  550. /* > \param[out] V */
  551. /* > \verbatim */
  552. /* > V is COMPLEX array, dimension (LDV,P) */
  553. /* > If JOBV = 'V', V contains the unitary matrix V. */
  554. /* > If JOBV = 'N', V is not referenced. */
  555. /* > \endverbatim */
  556. /* > */
  557. /* > \param[in] LDV */
  558. /* > \verbatim */
  559. /* > LDV is INTEGER */
  560. /* > The leading dimension of the array V. LDV >= f2cmax(1,P) if */
  561. /* > JOBV = 'V'; LDV >= 1 otherwise. */
  562. /* > \endverbatim */
  563. /* > */
  564. /* > \param[out] Q */
  565. /* > \verbatim */
  566. /* > Q is COMPLEX array, dimension (LDQ,N) */
  567. /* > If JOBQ = 'Q', Q contains the unitary matrix Q. */
  568. /* > If JOBQ = 'N', Q is not referenced. */
  569. /* > \endverbatim */
  570. /* > */
  571. /* > \param[in] LDQ */
  572. /* > \verbatim */
  573. /* > LDQ is INTEGER */
  574. /* > The leading dimension of the array Q. LDQ >= f2cmax(1,N) if */
  575. /* > JOBQ = 'Q'; LDQ >= 1 otherwise. */
  576. /* > \endverbatim */
  577. /* > */
  578. /* > \param[out] IWORK */
  579. /* > \verbatim */
  580. /* > IWORK is INTEGER array, dimension (N) */
  581. /* > \endverbatim */
  582. /* > */
  583. /* > \param[out] RWORK */
  584. /* > \verbatim */
  585. /* > RWORK is REAL array, dimension (2*N) */
  586. /* > \endverbatim */
  587. /* > */
  588. /* > \param[out] TAU */
  589. /* > \verbatim */
  590. /* > TAU is COMPLEX array, dimension (N) */
  591. /* > \endverbatim */
  592. /* > */
  593. /* > \param[out] WORK */
  594. /* > \verbatim */
  595. /* > WORK is COMPLEX array, dimension (f2cmax(3*N,M,P)) */
  596. /* > \endverbatim */
  597. /* > */
  598. /* > \param[out] INFO */
  599. /* > \verbatim */
  600. /* > INFO is INTEGER */
  601. /* > = 0: successful exit */
  602. /* > < 0: if INFO = -i, the i-th argument had an illegal value. */
  603. /* > \endverbatim */
  604. /* Authors: */
  605. /* ======== */
  606. /* > \author Univ. of Tennessee */
  607. /* > \author Univ. of California Berkeley */
  608. /* > \author Univ. of Colorado Denver */
  609. /* > \author NAG Ltd. */
  610. /* > \date December 2016 */
  611. /* > \ingroup complexOTHERcomputational */
  612. /* > \par Further Details: */
  613. /* ===================== */
  614. /* > */
  615. /* > The subroutine uses LAPACK subroutine CGEQPF for the QR factorization */
  616. /* > with column pivoting to detect the effective numerical rank of the */
  617. /* > a matrix. It may be replaced by a better rank determination strategy. */
  618. /* > */
  619. /* ===================================================================== */
  620. /* Subroutine */ int cggsvp_(char *jobu, char *jobv, char *jobq, integer *m,
  621. integer *p, integer *n, complex *a, integer *lda, complex *b, integer
  622. *ldb, real *tola, real *tolb, integer *k, integer *l, complex *u,
  623. integer *ldu, complex *v, integer *ldv, complex *q, integer *ldq,
  624. integer *iwork, real *rwork, complex *tau, complex *work, integer *
  625. info)
  626. {
  627. /* System generated locals */
  628. integer a_dim1, a_offset, b_dim1, b_offset, q_dim1, q_offset, u_dim1,
  629. u_offset, v_dim1, v_offset, i__1, i__2, i__3;
  630. real r__1, r__2;
  631. /* Local variables */
  632. integer i__, j;
  633. extern logical lsame_(char *, char *);
  634. logical wantq, wantu, wantv;
  635. extern /* Subroutine */ int cgeqr2_(integer *, integer *, complex *,
  636. integer *, complex *, complex *, integer *), cgerq2_(integer *,
  637. integer *, complex *, integer *, complex *, complex *, integer *),
  638. cung2r_(integer *, integer *, integer *, complex *, integer *,
  639. complex *, complex *, integer *), cunm2r_(char *, char *, integer
  640. *, integer *, integer *, complex *, integer *, complex *, complex
  641. *, integer *, complex *, integer *), cunmr2_(char
  642. *, char *, integer *, integer *, integer *, complex *, integer *,
  643. complex *, complex *, integer *, complex *, integer *), cgeqpf_(integer *, integer *, complex *, integer *,
  644. integer *, complex *, complex *, real *, integer *), clacpy_(char
  645. *, integer *, integer *, complex *, integer *, complex *, integer
  646. *), claset_(char *, integer *, integer *, complex *,
  647. complex *, complex *, integer *), xerbla_(char *, integer
  648. *), clapmt_(logical *, integer *, integer *, complex *,
  649. integer *, integer *);
  650. logical forwrd;
  651. /* -- LAPACK computational routine (version 3.7.0) -- */
  652. /* -- LAPACK is a software package provided by Univ. of Tennessee, -- */
  653. /* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- */
  654. /* December 2016 */
  655. /* ===================================================================== */
  656. /* Test the input parameters */
  657. /* Parameter adjustments */
  658. a_dim1 = *lda;
  659. a_offset = 1 + a_dim1 * 1;
  660. a -= a_offset;
  661. b_dim1 = *ldb;
  662. b_offset = 1 + b_dim1 * 1;
  663. b -= b_offset;
  664. u_dim1 = *ldu;
  665. u_offset = 1 + u_dim1 * 1;
  666. u -= u_offset;
  667. v_dim1 = *ldv;
  668. v_offset = 1 + v_dim1 * 1;
  669. v -= v_offset;
  670. q_dim1 = *ldq;
  671. q_offset = 1 + q_dim1 * 1;
  672. q -= q_offset;
  673. --iwork;
  674. --rwork;
  675. --tau;
  676. --work;
  677. /* Function Body */
  678. wantu = lsame_(jobu, "U");
  679. wantv = lsame_(jobv, "V");
  680. wantq = lsame_(jobq, "Q");
  681. forwrd = TRUE_;
  682. *info = 0;
  683. if (! (wantu || lsame_(jobu, "N"))) {
  684. *info = -1;
  685. } else if (! (wantv || lsame_(jobv, "N"))) {
  686. *info = -2;
  687. } else if (! (wantq || lsame_(jobq, "N"))) {
  688. *info = -3;
  689. } else if (*m < 0) {
  690. *info = -4;
  691. } else if (*p < 0) {
  692. *info = -5;
  693. } else if (*n < 0) {
  694. *info = -6;
  695. } else if (*lda < f2cmax(1,*m)) {
  696. *info = -8;
  697. } else if (*ldb < f2cmax(1,*p)) {
  698. *info = -10;
  699. } else if (*ldu < 1 || wantu && *ldu < *m) {
  700. *info = -16;
  701. } else if (*ldv < 1 || wantv && *ldv < *p) {
  702. *info = -18;
  703. } else if (*ldq < 1 || wantq && *ldq < *n) {
  704. *info = -20;
  705. }
  706. if (*info != 0) {
  707. i__1 = -(*info);
  708. xerbla_("CGGSVP", &i__1);
  709. return 0;
  710. }
  711. /* QR with column pivoting of B: B*P = V*( S11 S12 ) */
  712. /* ( 0 0 ) */
  713. i__1 = *n;
  714. for (i__ = 1; i__ <= i__1; ++i__) {
  715. iwork[i__] = 0;
  716. /* L10: */
  717. }
  718. cgeqpf_(p, n, &b[b_offset], ldb, &iwork[1], &tau[1], &work[1], &rwork[1],
  719. info);
  720. /* Update A := A*P */
  721. clapmt_(&forwrd, m, n, &a[a_offset], lda, &iwork[1]);
  722. /* Determine the effective rank of matrix B. */
  723. *l = 0;
  724. i__1 = f2cmin(*p,*n);
  725. for (i__ = 1; i__ <= i__1; ++i__) {
  726. i__2 = i__ + i__ * b_dim1;
  727. if ((r__1 = b[i__2].r, abs(r__1)) + (r__2 = r_imag(&b[i__ + i__ *
  728. b_dim1]), abs(r__2)) > *tolb) {
  729. ++(*l);
  730. }
  731. /* L20: */
  732. }
  733. if (wantv) {
  734. /* Copy the details of V, and form V. */
  735. claset_("Full", p, p, &c_b1, &c_b1, &v[v_offset], ldv);
  736. if (*p > 1) {
  737. i__1 = *p - 1;
  738. clacpy_("Lower", &i__1, n, &b[b_dim1 + 2], ldb, &v[v_dim1 + 2],
  739. ldv);
  740. }
  741. i__1 = f2cmin(*p,*n);
  742. cung2r_(p, p, &i__1, &v[v_offset], ldv, &tau[1], &work[1], info);
  743. }
  744. /* Clean up B */
  745. i__1 = *l - 1;
  746. for (j = 1; j <= i__1; ++j) {
  747. i__2 = *l;
  748. for (i__ = j + 1; i__ <= i__2; ++i__) {
  749. i__3 = i__ + j * b_dim1;
  750. b[i__3].r = 0.f, b[i__3].i = 0.f;
  751. /* L30: */
  752. }
  753. /* L40: */
  754. }
  755. if (*p > *l) {
  756. i__1 = *p - *l;
  757. claset_("Full", &i__1, n, &c_b1, &c_b1, &b[*l + 1 + b_dim1], ldb);
  758. }
  759. if (wantq) {
  760. /* Set Q = I and Update Q := Q*P */
  761. claset_("Full", n, n, &c_b1, &c_b2, &q[q_offset], ldq);
  762. clapmt_(&forwrd, n, n, &q[q_offset], ldq, &iwork[1]);
  763. }
  764. if (*p >= *l && *n != *l) {
  765. /* RQ factorization of ( S11 S12 ) = ( 0 S12 )*Z */
  766. cgerq2_(l, n, &b[b_offset], ldb, &tau[1], &work[1], info);
  767. /* Update A := A*Z**H */
  768. cunmr2_("Right", "Conjugate transpose", m, n, l, &b[b_offset], ldb, &
  769. tau[1], &a[a_offset], lda, &work[1], info);
  770. if (wantq) {
  771. /* Update Q := Q*Z**H */
  772. cunmr2_("Right", "Conjugate transpose", n, n, l, &b[b_offset],
  773. ldb, &tau[1], &q[q_offset], ldq, &work[1], info);
  774. }
  775. /* Clean up B */
  776. i__1 = *n - *l;
  777. claset_("Full", l, &i__1, &c_b1, &c_b1, &b[b_offset], ldb);
  778. i__1 = *n;
  779. for (j = *n - *l + 1; j <= i__1; ++j) {
  780. i__2 = *l;
  781. for (i__ = j - *n + *l + 1; i__ <= i__2; ++i__) {
  782. i__3 = i__ + j * b_dim1;
  783. b[i__3].r = 0.f, b[i__3].i = 0.f;
  784. /* L50: */
  785. }
  786. /* L60: */
  787. }
  788. }
  789. /* Let N-L L */
  790. /* A = ( A11 A12 ) M, */
  791. /* then the following does the complete QR decomposition of A11: */
  792. /* A11 = U*( 0 T12 )*P1**H */
  793. /* ( 0 0 ) */
  794. i__1 = *n - *l;
  795. for (i__ = 1; i__ <= i__1; ++i__) {
  796. iwork[i__] = 0;
  797. /* L70: */
  798. }
  799. i__1 = *n - *l;
  800. cgeqpf_(m, &i__1, &a[a_offset], lda, &iwork[1], &tau[1], &work[1], &rwork[
  801. 1], info);
  802. /* Determine the effective rank of A11 */
  803. *k = 0;
  804. /* Computing MIN */
  805. i__2 = *m, i__3 = *n - *l;
  806. i__1 = f2cmin(i__2,i__3);
  807. for (i__ = 1; i__ <= i__1; ++i__) {
  808. i__2 = i__ + i__ * a_dim1;
  809. if ((r__1 = a[i__2].r, abs(r__1)) + (r__2 = r_imag(&a[i__ + i__ *
  810. a_dim1]), abs(r__2)) > *tola) {
  811. ++(*k);
  812. }
  813. /* L80: */
  814. }
  815. /* Update A12 := U**H*A12, where A12 = A( 1:M, N-L+1:N ) */
  816. /* Computing MIN */
  817. i__2 = *m, i__3 = *n - *l;
  818. i__1 = f2cmin(i__2,i__3);
  819. cunm2r_("Left", "Conjugate transpose", m, l, &i__1, &a[a_offset], lda, &
  820. tau[1], &a[(*n - *l + 1) * a_dim1 + 1], lda, &work[1], info);
  821. if (wantu) {
  822. /* Copy the details of U, and form U */
  823. claset_("Full", m, m, &c_b1, &c_b1, &u[u_offset], ldu);
  824. if (*m > 1) {
  825. i__1 = *m - 1;
  826. i__2 = *n - *l;
  827. clacpy_("Lower", &i__1, &i__2, &a[a_dim1 + 2], lda, &u[u_dim1 + 2]
  828. , ldu);
  829. }
  830. /* Computing MIN */
  831. i__2 = *m, i__3 = *n - *l;
  832. i__1 = f2cmin(i__2,i__3);
  833. cung2r_(m, m, &i__1, &u[u_offset], ldu, &tau[1], &work[1], info);
  834. }
  835. if (wantq) {
  836. /* Update Q( 1:N, 1:N-L ) = Q( 1:N, 1:N-L )*P1 */
  837. i__1 = *n - *l;
  838. clapmt_(&forwrd, n, &i__1, &q[q_offset], ldq, &iwork[1]);
  839. }
  840. /* Clean up A: set the strictly lower triangular part of */
  841. /* A(1:K, 1:K) = 0, and A( K+1:M, 1:N-L ) = 0. */
  842. i__1 = *k - 1;
  843. for (j = 1; j <= i__1; ++j) {
  844. i__2 = *k;
  845. for (i__ = j + 1; i__ <= i__2; ++i__) {
  846. i__3 = i__ + j * a_dim1;
  847. a[i__3].r = 0.f, a[i__3].i = 0.f;
  848. /* L90: */
  849. }
  850. /* L100: */
  851. }
  852. if (*m > *k) {
  853. i__1 = *m - *k;
  854. i__2 = *n - *l;
  855. claset_("Full", &i__1, &i__2, &c_b1, &c_b1, &a[*k + 1 + a_dim1], lda);
  856. }
  857. if (*n - *l > *k) {
  858. /* RQ factorization of ( T11 T12 ) = ( 0 T12 )*Z1 */
  859. i__1 = *n - *l;
  860. cgerq2_(k, &i__1, &a[a_offset], lda, &tau[1], &work[1], info);
  861. if (wantq) {
  862. /* Update Q( 1:N,1:N-L ) = Q( 1:N,1:N-L )*Z1**H */
  863. i__1 = *n - *l;
  864. cunmr2_("Right", "Conjugate transpose", n, &i__1, k, &a[a_offset],
  865. lda, &tau[1], &q[q_offset], ldq, &work[1], info);
  866. }
  867. /* Clean up A */
  868. i__1 = *n - *l - *k;
  869. claset_("Full", k, &i__1, &c_b1, &c_b1, &a[a_offset], lda);
  870. i__1 = *n - *l;
  871. for (j = *n - *l - *k + 1; j <= i__1; ++j) {
  872. i__2 = *k;
  873. for (i__ = j - *n + *l + *k + 1; i__ <= i__2; ++i__) {
  874. i__3 = i__ + j * a_dim1;
  875. a[i__3].r = 0.f, a[i__3].i = 0.f;
  876. /* L110: */
  877. }
  878. /* L120: */
  879. }
  880. }
  881. if (*m > *k) {
  882. /* QR factorization of A( K+1:M,N-L+1:N ) */
  883. i__1 = *m - *k;
  884. cgeqr2_(&i__1, l, &a[*k + 1 + (*n - *l + 1) * a_dim1], lda, &tau[1], &
  885. work[1], info);
  886. if (wantu) {
  887. /* Update U(:,K+1:M) := U(:,K+1:M)*U1 */
  888. i__1 = *m - *k;
  889. /* Computing MIN */
  890. i__3 = *m - *k;
  891. i__2 = f2cmin(i__3,*l);
  892. cunm2r_("Right", "No transpose", m, &i__1, &i__2, &a[*k + 1 + (*n
  893. - *l + 1) * a_dim1], lda, &tau[1], &u[(*k + 1) * u_dim1 +
  894. 1], ldu, &work[1], info);
  895. }
  896. /* Clean up */
  897. i__1 = *n;
  898. for (j = *n - *l + 1; j <= i__1; ++j) {
  899. i__2 = *m;
  900. for (i__ = j - *n + *k + *l + 1; i__ <= i__2; ++i__) {
  901. i__3 = i__ + j * a_dim1;
  902. a[i__3].r = 0.f, a[i__3].i = 0.f;
  903. /* L130: */
  904. }
  905. /* L140: */
  906. }
  907. }
  908. return 0;
  909. /* End of CGGSVP */
  910. } /* cggsvp_ */