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