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 42 kB

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