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.

ztgsen.c 44 kB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381
  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__1 = 1;
  485. /* > \brief \b ZTGSEN */
  486. /* =========== DOCUMENTATION =========== */
  487. /* Online html documentation available at */
  488. /* http://www.netlib.org/lapack/explore-html/ */
  489. /* > \htmlonly */
  490. /* > Download ZTGSEN + dependencies */
  491. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/ztgsen.
  492. f"> */
  493. /* > [TGZ]</a> */
  494. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/ztgsen.
  495. f"> */
  496. /* > [ZIP]</a> */
  497. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/ztgsen.
  498. f"> */
  499. /* > [TXT]</a> */
  500. /* > \endhtmlonly */
  501. /* Definition: */
  502. /* =========== */
  503. /* SUBROUTINE ZTGSEN( IJOB, WANTQ, WANTZ, SELECT, N, A, LDA, B, LDB, */
  504. /* ALPHA, BETA, Q, LDQ, Z, LDZ, M, PL, PR, DIF, */
  505. /* WORK, LWORK, IWORK, LIWORK, INFO ) */
  506. /* LOGICAL WANTQ, WANTZ */
  507. /* INTEGER IJOB, INFO, LDA, LDB, LDQ, LDZ, LIWORK, LWORK, */
  508. /* $ M, N */
  509. /* DOUBLE PRECISION PL, PR */
  510. /* LOGICAL SELECT( * ) */
  511. /* INTEGER IWORK( * ) */
  512. /* DOUBLE PRECISION DIF( * ) */
  513. /* COMPLEX*16 A( LDA, * ), ALPHA( * ), B( LDB, * ), */
  514. /* $ BETA( * ), Q( LDQ, * ), WORK( * ), Z( LDZ, * ) */
  515. /* > \par Purpose: */
  516. /* ============= */
  517. /* > */
  518. /* > \verbatim */
  519. /* > */
  520. /* > ZTGSEN reorders the generalized Schur decomposition of a complex */
  521. /* > matrix pair (A, B) (in terms of an unitary equivalence trans- */
  522. /* > formation Q**H * (A, B) * Z), so that a selected cluster of eigenvalues */
  523. /* > appears in the leading diagonal blocks of the pair (A,B). The leading */
  524. /* > columns of Q and Z form unitary bases of the corresponding left and */
  525. /* > right eigenspaces (deflating subspaces). (A, B) must be in */
  526. /* > generalized Schur canonical form, that is, A and B are both upper */
  527. /* > triangular. */
  528. /* > */
  529. /* > ZTGSEN also computes the generalized eigenvalues */
  530. /* > */
  531. /* > w(j)= ALPHA(j) / BETA(j) */
  532. /* > */
  533. /* > of the reordered matrix pair (A, B). */
  534. /* > */
  535. /* > Optionally, the routine computes estimates of reciprocal condition */
  536. /* > numbers for eigenvalues and eigenspaces. These are Difu[(A11,B11), */
  537. /* > (A22,B22)] and Difl[(A11,B11), (A22,B22)], i.e. the separation(s) */
  538. /* > between the matrix pairs (A11, B11) and (A22,B22) that correspond to */
  539. /* > the selected cluster and the eigenvalues outside the cluster, resp., */
  540. /* > and norms of "projections" onto left and right eigenspaces w.r.t. */
  541. /* > the selected cluster in the (1,1)-block. */
  542. /* > */
  543. /* > \endverbatim */
  544. /* Arguments: */
  545. /* ========== */
  546. /* > \param[in] IJOB */
  547. /* > \verbatim */
  548. /* > IJOB is INTEGER */
  549. /* > Specifies whether condition numbers are required for the */
  550. /* > cluster of eigenvalues (PL and PR) or the deflating subspaces */
  551. /* > (Difu and Difl): */
  552. /* > =0: Only reorder w.r.t. SELECT. No extras. */
  553. /* > =1: Reciprocal of norms of "projections" onto left and right */
  554. /* > eigenspaces w.r.t. the selected cluster (PL and PR). */
  555. /* > =2: Upper bounds on Difu and Difl. F-norm-based estimate */
  556. /* > (DIF(1:2)). */
  557. /* > =3: Estimate of Difu and Difl. 1-norm-based estimate */
  558. /* > (DIF(1:2)). */
  559. /* > About 5 times as expensive as IJOB = 2. */
  560. /* > =4: Compute PL, PR and DIF (i.e. 0, 1 and 2 above): Economic */
  561. /* > version to get it all. */
  562. /* > =5: Compute PL, PR and DIF (i.e. 0, 1 and 3 above) */
  563. /* > \endverbatim */
  564. /* > */
  565. /* > \param[in] WANTQ */
  566. /* > \verbatim */
  567. /* > WANTQ is LOGICAL */
  568. /* > .TRUE. : update the left transformation matrix Q; */
  569. /* > .FALSE.: do not update Q. */
  570. /* > \endverbatim */
  571. /* > */
  572. /* > \param[in] WANTZ */
  573. /* > \verbatim */
  574. /* > WANTZ is LOGICAL */
  575. /* > .TRUE. : update the right transformation matrix Z; */
  576. /* > .FALSE.: do not update Z. */
  577. /* > \endverbatim */
  578. /* > */
  579. /* > \param[in] SELECT */
  580. /* > \verbatim */
  581. /* > SELECT is LOGICAL array, dimension (N) */
  582. /* > SELECT specifies the eigenvalues in the selected cluster. To */
  583. /* > select an eigenvalue w(j), SELECT(j) must be set to */
  584. /* > .TRUE.. */
  585. /* > \endverbatim */
  586. /* > */
  587. /* > \param[in] N */
  588. /* > \verbatim */
  589. /* > N is INTEGER */
  590. /* > The order of the matrices A and B. N >= 0. */
  591. /* > \endverbatim */
  592. /* > */
  593. /* > \param[in,out] A */
  594. /* > \verbatim */
  595. /* > A is COMPLEX*16 array, dimension(LDA,N) */
  596. /* > On entry, the upper triangular matrix A, in generalized */
  597. /* > Schur canonical form. */
  598. /* > On exit, A is overwritten by the reordered matrix A. */
  599. /* > \endverbatim */
  600. /* > */
  601. /* > \param[in] LDA */
  602. /* > \verbatim */
  603. /* > LDA is INTEGER */
  604. /* > The leading dimension of the array A. LDA >= f2cmax(1,N). */
  605. /* > \endverbatim */
  606. /* > */
  607. /* > \param[in,out] B */
  608. /* > \verbatim */
  609. /* > B is COMPLEX*16 array, dimension(LDB,N) */
  610. /* > On entry, the upper triangular matrix B, in generalized */
  611. /* > Schur canonical form. */
  612. /* > On exit, B is overwritten by the reordered matrix B. */
  613. /* > \endverbatim */
  614. /* > */
  615. /* > \param[in] LDB */
  616. /* > \verbatim */
  617. /* > LDB is INTEGER */
  618. /* > The leading dimension of the array B. LDB >= f2cmax(1,N). */
  619. /* > \endverbatim */
  620. /* > */
  621. /* > \param[out] ALPHA */
  622. /* > \verbatim */
  623. /* > ALPHA is COMPLEX*16 array, dimension (N) */
  624. /* > \endverbatim */
  625. /* > */
  626. /* > \param[out] BETA */
  627. /* > \verbatim */
  628. /* > BETA is COMPLEX*16 array, dimension (N) */
  629. /* > */
  630. /* > The diagonal elements of A and B, respectively, */
  631. /* > when the pair (A,B) has been reduced to generalized Schur */
  632. /* > form. ALPHA(i)/BETA(i) i=1,...,N are the generalized */
  633. /* > eigenvalues. */
  634. /* > \endverbatim */
  635. /* > */
  636. /* > \param[in,out] Q */
  637. /* > \verbatim */
  638. /* > Q is COMPLEX*16 array, dimension (LDQ,N) */
  639. /* > On entry, if WANTQ = .TRUE., Q is an N-by-N matrix. */
  640. /* > On exit, Q has been postmultiplied by the left unitary */
  641. /* > transformation matrix which reorder (A, B); The leading M */
  642. /* > columns of Q form orthonormal bases for the specified pair of */
  643. /* > left eigenspaces (deflating subspaces). */
  644. /* > If WANTQ = .FALSE., Q is not referenced. */
  645. /* > \endverbatim */
  646. /* > */
  647. /* > \param[in] LDQ */
  648. /* > \verbatim */
  649. /* > LDQ is INTEGER */
  650. /* > The leading dimension of the array Q. LDQ >= 1. */
  651. /* > If WANTQ = .TRUE., LDQ >= N. */
  652. /* > \endverbatim */
  653. /* > */
  654. /* > \param[in,out] Z */
  655. /* > \verbatim */
  656. /* > Z is COMPLEX*16 array, dimension (LDZ,N) */
  657. /* > On entry, if WANTZ = .TRUE., Z is an N-by-N matrix. */
  658. /* > On exit, Z has been postmultiplied by the left unitary */
  659. /* > transformation matrix which reorder (A, B); The leading M */
  660. /* > columns of Z form orthonormal bases for the specified pair of */
  661. /* > left eigenspaces (deflating subspaces). */
  662. /* > If WANTZ = .FALSE., Z is not referenced. */
  663. /* > \endverbatim */
  664. /* > */
  665. /* > \param[in] LDZ */
  666. /* > \verbatim */
  667. /* > LDZ is INTEGER */
  668. /* > The leading dimension of the array Z. LDZ >= 1. */
  669. /* > If WANTZ = .TRUE., LDZ >= N. */
  670. /* > \endverbatim */
  671. /* > */
  672. /* > \param[out] M */
  673. /* > \verbatim */
  674. /* > M is INTEGER */
  675. /* > The dimension of the specified pair of left and right */
  676. /* > eigenspaces, (deflating subspaces) 0 <= M <= N. */
  677. /* > \endverbatim */
  678. /* > */
  679. /* > \param[out] PL */
  680. /* > \verbatim */
  681. /* > PL is DOUBLE PRECISION */
  682. /* > \endverbatim */
  683. /* > */
  684. /* > \param[out] PR */
  685. /* > \verbatim */
  686. /* > PR is DOUBLE PRECISION */
  687. /* > */
  688. /* > If IJOB = 1, 4 or 5, PL, PR are lower bounds on the */
  689. /* > reciprocal of the norm of "projections" onto left and right */
  690. /* > eigenspace with respect to the selected cluster. */
  691. /* > 0 < PL, PR <= 1. */
  692. /* > If M = 0 or M = N, PL = PR = 1. */
  693. /* > If IJOB = 0, 2 or 3 PL, PR are not referenced. */
  694. /* > \endverbatim */
  695. /* > */
  696. /* > \param[out] DIF */
  697. /* > \verbatim */
  698. /* > DIF is DOUBLE PRECISION array, dimension (2). */
  699. /* > If IJOB >= 2, DIF(1:2) store the estimates of Difu and Difl. */
  700. /* > If IJOB = 2 or 4, DIF(1:2) are F-norm-based upper bounds on */
  701. /* > Difu and Difl. If IJOB = 3 or 5, DIF(1:2) are 1-norm-based */
  702. /* > estimates of Difu and Difl, computed using reversed */
  703. /* > communication with ZLACN2. */
  704. /* > If M = 0 or N, DIF(1:2) = F-norm([A, B]). */
  705. /* > If IJOB = 0 or 1, DIF is not referenced. */
  706. /* > \endverbatim */
  707. /* > */
  708. /* > \param[out] WORK */
  709. /* > \verbatim */
  710. /* > WORK is COMPLEX*16 array, dimension (MAX(1,LWORK)) */
  711. /* > On exit, if INFO = 0, WORK(1) returns the optimal LWORK. */
  712. /* > \endverbatim */
  713. /* > */
  714. /* > \param[in] LWORK */
  715. /* > \verbatim */
  716. /* > LWORK is INTEGER */
  717. /* > The dimension of the array WORK. LWORK >= 1 */
  718. /* > If IJOB = 1, 2 or 4, LWORK >= 2*M*(N-M) */
  719. /* > If IJOB = 3 or 5, LWORK >= 4*M*(N-M) */
  720. /* > */
  721. /* > If LWORK = -1, then a workspace query is assumed; the routine */
  722. /* > only calculates the optimal size of the WORK array, returns */
  723. /* > this value as the first entry of the WORK array, and no error */
  724. /* > message related to LWORK is issued by XERBLA. */
  725. /* > \endverbatim */
  726. /* > */
  727. /* > \param[out] IWORK */
  728. /* > \verbatim */
  729. /* > IWORK is INTEGER array, dimension (MAX(1,LIWORK)) */
  730. /* > On exit, if INFO = 0, IWORK(1) returns the optimal LIWORK. */
  731. /* > \endverbatim */
  732. /* > */
  733. /* > \param[in] LIWORK */
  734. /* > \verbatim */
  735. /* > LIWORK is INTEGER */
  736. /* > The dimension of the array IWORK. LIWORK >= 1. */
  737. /* > If IJOB = 1, 2 or 4, LIWORK >= N+2; */
  738. /* > If IJOB = 3 or 5, LIWORK >= MAX(N+2, 2*M*(N-M)); */
  739. /* > */
  740. /* > If LIWORK = -1, then a workspace query is assumed; the */
  741. /* > routine only calculates the optimal size of the IWORK array, */
  742. /* > returns this value as the first entry of the IWORK array, and */
  743. /* > no error message related to LIWORK is issued by XERBLA. */
  744. /* > \endverbatim */
  745. /* > */
  746. /* > \param[out] INFO */
  747. /* > \verbatim */
  748. /* > INFO is INTEGER */
  749. /* > =0: Successful exit. */
  750. /* > <0: If INFO = -i, the i-th argument had an illegal value. */
  751. /* > =1: Reordering of (A, B) failed because the transformed */
  752. /* > matrix pair (A, B) would be too far from generalized */
  753. /* > Schur form; the problem is very ill-conditioned. */
  754. /* > (A, B) may have been partially reordered. */
  755. /* > If requested, 0 is returned in DIF(*), PL and PR. */
  756. /* > \endverbatim */
  757. /* Authors: */
  758. /* ======== */
  759. /* > \author Univ. of Tennessee */
  760. /* > \author Univ. of California Berkeley */
  761. /* > \author Univ. of Colorado Denver */
  762. /* > \author NAG Ltd. */
  763. /* > \date June 2016 */
  764. /* > \ingroup complex16OTHERcomputational */
  765. /* > \par Further Details: */
  766. /* ===================== */
  767. /* > */
  768. /* > \verbatim */
  769. /* > */
  770. /* > ZTGSEN first collects the selected eigenvalues by computing unitary */
  771. /* > U and W that move them to the top left corner of (A, B). In other */
  772. /* > words, the selected eigenvalues are the eigenvalues of (A11, B11) in */
  773. /* > */
  774. /* > U**H*(A, B)*W = (A11 A12) (B11 B12) n1 */
  775. /* > ( 0 A22),( 0 B22) n2 */
  776. /* > n1 n2 n1 n2 */
  777. /* > */
  778. /* > where N = n1+n2 and U**H means the conjugate transpose of U. The first */
  779. /* > n1 columns of U and W span the specified pair of left and right */
  780. /* > eigenspaces (deflating subspaces) of (A, B). */
  781. /* > */
  782. /* > If (A, B) has been obtained from the generalized real Schur */
  783. /* > decomposition of a matrix pair (C, D) = Q*(A, B)*Z**H, then the */
  784. /* > reordered generalized Schur form of (C, D) is given by */
  785. /* > */
  786. /* > (C, D) = (Q*U)*(U**H *(A, B)*W)*(Z*W)**H, */
  787. /* > */
  788. /* > and the first n1 columns of Q*U and Z*W span the corresponding */
  789. /* > deflating subspaces of (C, D) (Q and Z store Q*U and Z*W, resp.). */
  790. /* > */
  791. /* > Note that if the selected eigenvalue is sufficiently ill-conditioned, */
  792. /* > then its value may differ significantly from its value before */
  793. /* > reordering. */
  794. /* > */
  795. /* > The reciprocal condition numbers of the left and right eigenspaces */
  796. /* > spanned by the first n1 columns of U and W (or Q*U and Z*W) may */
  797. /* > be returned in DIF(1:2), corresponding to Difu and Difl, resp. */
  798. /* > */
  799. /* > The Difu and Difl are defined as: */
  800. /* > */
  801. /* > Difu[(A11, B11), (A22, B22)] = sigma-f2cmin( Zu ) */
  802. /* > and */
  803. /* > Difl[(A11, B11), (A22, B22)] = Difu[(A22, B22), (A11, B11)], */
  804. /* > */
  805. /* > where sigma-f2cmin(Zu) is the smallest singular value of the */
  806. /* > (2*n1*n2)-by-(2*n1*n2) matrix */
  807. /* > */
  808. /* > Zu = [ kron(In2, A11) -kron(A22**H, In1) ] */
  809. /* > [ kron(In2, B11) -kron(B22**H, In1) ]. */
  810. /* > */
  811. /* > Here, Inx is the identity matrix of size nx and A22**H is the */
  812. /* > conjugate transpose of A22. kron(X, Y) is the Kronecker product between */
  813. /* > the matrices X and Y. */
  814. /* > */
  815. /* > When DIF(2) is small, small changes in (A, B) can cause large changes */
  816. /* > in the deflating subspace. An approximate (asymptotic) bound on the */
  817. /* > maximum angular error in the computed deflating subspaces is */
  818. /* > */
  819. /* > EPS * norm((A, B)) / DIF(2), */
  820. /* > */
  821. /* > where EPS is the machine precision. */
  822. /* > */
  823. /* > The reciprocal norm of the projectors on the left and right */
  824. /* > eigenspaces associated with (A11, B11) may be returned in PL and PR. */
  825. /* > They are computed as follows. First we compute L and R so that */
  826. /* > P*(A, B)*Q is block diagonal, where */
  827. /* > */
  828. /* > P = ( I -L ) n1 Q = ( I R ) n1 */
  829. /* > ( 0 I ) n2 and ( 0 I ) n2 */
  830. /* > n1 n2 n1 n2 */
  831. /* > */
  832. /* > and (L, R) is the solution to the generalized Sylvester equation */
  833. /* > */
  834. /* > A11*R - L*A22 = -A12 */
  835. /* > B11*R - L*B22 = -B12 */
  836. /* > */
  837. /* > Then PL = (F-norm(L)**2+1)**(-1/2) and PR = (F-norm(R)**2+1)**(-1/2). */
  838. /* > An approximate (asymptotic) bound on the average absolute error of */
  839. /* > the selected eigenvalues is */
  840. /* > */
  841. /* > EPS * norm((A, B)) / PL. */
  842. /* > */
  843. /* > There are also global error bounds which valid for perturbations up */
  844. /* > to a certain restriction: A lower bound (x) on the smallest */
  845. /* > F-norm(E,F) for which an eigenvalue of (A11, B11) may move and */
  846. /* > coalesce with an eigenvalue of (A22, B22) under perturbation (E,F), */
  847. /* > (i.e. (A + E, B + F), is */
  848. /* > */
  849. /* > x = f2cmin(Difu,Difl)/((1/(PL*PL)+1/(PR*PR))**(1/2)+2*f2cmax(1/PL,1/PR)). */
  850. /* > */
  851. /* > An approximate bound on x can be computed from DIF(1:2), PL and PR. */
  852. /* > */
  853. /* > If y = ( F-norm(E,F) / x) <= 1, the angles between the perturbed */
  854. /* > (L', R') and unperturbed (L, R) left and right deflating subspaces */
  855. /* > associated with the selected cluster in the (1,1)-blocks can be */
  856. /* > bounded as */
  857. /* > */
  858. /* > f2cmax-angle(L, L') <= arctan( y * PL / (1 - y * (1 - PL * PL)**(1/2)) */
  859. /* > f2cmax-angle(R, R') <= arctan( y * PR / (1 - y * (1 - PR * PR)**(1/2)) */
  860. /* > */
  861. /* > See LAPACK User's Guide section 4.11 or the following references */
  862. /* > for more information. */
  863. /* > */
  864. /* > Note that if the default method for computing the Frobenius-norm- */
  865. /* > based estimate DIF is not wanted (see ZLATDF), then the parameter */
  866. /* > IDIFJB (see below) should be changed from 3 to 4 (routine ZLATDF */
  867. /* > (IJOB = 2 will be used)). See ZTGSYL for more details. */
  868. /* > \endverbatim */
  869. /* > \par Contributors: */
  870. /* ================== */
  871. /* > */
  872. /* > Bo Kagstrom and Peter Poromaa, Department of Computing Science, */
  873. /* > Umea University, S-901 87 Umea, Sweden. */
  874. /* > \par References: */
  875. /* ================ */
  876. /* > */
  877. /* > [1] B. Kagstrom; A Direct Method for Reordering Eigenvalues in the */
  878. /* > Generalized Real Schur Form of a Regular Matrix Pair (A, B), in */
  879. /* > M.S. Moonen et al (eds), Linear Algebra for Large Scale and */
  880. /* > Real-Time Applications, Kluwer Academic Publ. 1993, pp 195-218. */
  881. /* > \n */
  882. /* > [2] B. Kagstrom and P. Poromaa; Computing Eigenspaces with Specified */
  883. /* > Eigenvalues of a Regular Matrix Pair (A, B) and Condition */
  884. /* > Estimation: Theory, Algorithms and Software, Report */
  885. /* > UMINF - 94.04, Department of Computing Science, Umea University, */
  886. /* > S-901 87 Umea, Sweden, 1994. Also as LAPACK Working Note 87. */
  887. /* > To appear in Numerical Algorithms, 1996. */
  888. /* > \n */
  889. /* > [3] B. Kagstrom and P. Poromaa, LAPACK-Style Algorithms and Software */
  890. /* > for Solving the Generalized Sylvester Equation and Estimating the */
  891. /* > Separation between Regular Matrix Pairs, Report UMINF - 93.23, */
  892. /* > Department of Computing Science, Umea University, S-901 87 Umea, */
  893. /* > Sweden, December 1993, Revised April 1994, Also as LAPACK working */
  894. /* > Note 75. To appear in ACM Trans. on Math. Software, Vol 22, No 1, */
  895. /* > 1996. */
  896. /* > */
  897. /* ===================================================================== */
  898. /* Subroutine */ void ztgsen_(integer *ijob, logical *wantq, logical *wantz,
  899. logical *select, integer *n, doublecomplex *a, integer *lda,
  900. doublecomplex *b, integer *ldb, doublecomplex *alpha, doublecomplex *
  901. beta, doublecomplex *q, integer *ldq, doublecomplex *z__, integer *
  902. ldz, integer *m, doublereal *pl, doublereal *pr, doublereal *dif,
  903. doublecomplex *work, integer *lwork, integer *iwork, integer *liwork,
  904. integer *info)
  905. {
  906. /* System generated locals */
  907. integer a_dim1, a_offset, b_dim1, b_offset, q_dim1, q_offset, z_dim1,
  908. z_offset, i__1, i__2, i__3;
  909. doublecomplex z__1, z__2;
  910. /* Local variables */
  911. integer kase, ierr;
  912. doublereal dsum;
  913. logical swap;
  914. doublecomplex temp1, temp2;
  915. integer i__, k, isave[3];
  916. extern /* Subroutine */ void zscal_(integer *, doublecomplex *,
  917. doublecomplex *, integer *);
  918. logical wantd;
  919. integer lwmin;
  920. logical wantp;
  921. integer n1, n2;
  922. extern /* Subroutine */ void zlacn2_(integer *, doublecomplex *,
  923. doublecomplex *, doublereal *, integer *, integer *);
  924. logical wantd1, wantd2;
  925. extern doublereal dlamch_(char *);
  926. doublereal dscale;
  927. integer ks;
  928. doublereal rdscal, safmin;
  929. extern /* Subroutine */ int xerbla_(char *, integer *, ftnlen);
  930. integer liwmin;
  931. extern /* Subroutine */ void zlacpy_(char *, integer *, integer *,
  932. doublecomplex *, integer *, doublecomplex *, integer *),
  933. ztgexc_(logical *, logical *, integer *, doublecomplex *, integer
  934. *, doublecomplex *, integer *, doublecomplex *, integer *,
  935. doublecomplex *, integer *, integer *, integer *, integer *);
  936. integer mn2;
  937. extern /* Subroutine */ void zlassq_(integer *, doublecomplex *, integer *,
  938. doublereal *, doublereal *);
  939. logical lquery;
  940. extern /* Subroutine */ void ztgsyl_(char *, integer *, integer *, integer
  941. *, doublecomplex *, integer *, doublecomplex *, integer *,
  942. doublecomplex *, integer *, doublecomplex *, integer *,
  943. doublecomplex *, integer *, doublecomplex *, integer *,
  944. doublereal *, doublereal *, doublecomplex *, integer *, integer *,
  945. integer *);
  946. integer ijb;
  947. /* -- LAPACK computational routine (version 3.7.1) -- */
  948. /* -- LAPACK is a software package provided by Univ. of Tennessee, -- */
  949. /* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- */
  950. /* June 2016 */
  951. /* ===================================================================== */
  952. /* Decode and test the input parameters */
  953. /* Parameter adjustments */
  954. --select;
  955. a_dim1 = *lda;
  956. a_offset = 1 + a_dim1 * 1;
  957. a -= a_offset;
  958. b_dim1 = *ldb;
  959. b_offset = 1 + b_dim1 * 1;
  960. b -= b_offset;
  961. --alpha;
  962. --beta;
  963. q_dim1 = *ldq;
  964. q_offset = 1 + q_dim1 * 1;
  965. q -= q_offset;
  966. z_dim1 = *ldz;
  967. z_offset = 1 + z_dim1 * 1;
  968. z__ -= z_offset;
  969. --dif;
  970. --work;
  971. --iwork;
  972. /* Function Body */
  973. *info = 0;
  974. lquery = *lwork == -1 || *liwork == -1;
  975. if (*ijob < 0 || *ijob > 5) {
  976. *info = -1;
  977. } else if (*n < 0) {
  978. *info = -5;
  979. } else if (*lda < f2cmax(1,*n)) {
  980. *info = -7;
  981. } else if (*ldb < f2cmax(1,*n)) {
  982. *info = -9;
  983. } else if (*ldq < 1 || *wantq && *ldq < *n) {
  984. *info = -13;
  985. } else if (*ldz < 1 || *wantz && *ldz < *n) {
  986. *info = -15;
  987. }
  988. if (*info != 0) {
  989. i__1 = -(*info);
  990. xerbla_("ZTGSEN", &i__1, (ftnlen)6);
  991. return;
  992. }
  993. ierr = 0;
  994. wantp = *ijob == 1 || *ijob >= 4;
  995. wantd1 = *ijob == 2 || *ijob == 4;
  996. wantd2 = *ijob == 3 || *ijob == 5;
  997. wantd = wantd1 || wantd2;
  998. /* Set M to the dimension of the specified pair of deflating */
  999. /* subspaces. */
  1000. *m = 0;
  1001. if (! lquery || *ijob != 0) {
  1002. i__1 = *n;
  1003. for (k = 1; k <= i__1; ++k) {
  1004. i__2 = k;
  1005. i__3 = k + k * a_dim1;
  1006. alpha[i__2].r = a[i__3].r, alpha[i__2].i = a[i__3].i;
  1007. i__2 = k;
  1008. i__3 = k + k * b_dim1;
  1009. beta[i__2].r = b[i__3].r, beta[i__2].i = b[i__3].i;
  1010. if (k < *n) {
  1011. if (select[k]) {
  1012. ++(*m);
  1013. }
  1014. } else {
  1015. if (select[*n]) {
  1016. ++(*m);
  1017. }
  1018. }
  1019. /* L10: */
  1020. }
  1021. }
  1022. if (*ijob == 1 || *ijob == 2 || *ijob == 4) {
  1023. /* Computing MAX */
  1024. i__1 = 1, i__2 = (*m << 1) * (*n - *m);
  1025. lwmin = f2cmax(i__1,i__2);
  1026. /* Computing MAX */
  1027. i__1 = 1, i__2 = *n + 2;
  1028. liwmin = f2cmax(i__1,i__2);
  1029. } else if (*ijob == 3 || *ijob == 5) {
  1030. /* Computing MAX */
  1031. i__1 = 1, i__2 = (*m << 2) * (*n - *m);
  1032. lwmin = f2cmax(i__1,i__2);
  1033. /* Computing MAX */
  1034. i__1 = 1, i__2 = (*m << 1) * (*n - *m), i__1 = f2cmax(i__1,i__2), i__2 =
  1035. *n + 2;
  1036. liwmin = f2cmax(i__1,i__2);
  1037. } else {
  1038. lwmin = 1;
  1039. liwmin = 1;
  1040. }
  1041. work[1].r = (doublereal) lwmin, work[1].i = 0.;
  1042. iwork[1] = liwmin;
  1043. if (*lwork < lwmin && ! lquery) {
  1044. *info = -21;
  1045. } else if (*liwork < liwmin && ! lquery) {
  1046. *info = -23;
  1047. }
  1048. if (*info != 0) {
  1049. i__1 = -(*info);
  1050. xerbla_("ZTGSEN", &i__1, (ftnlen)6);
  1051. return;
  1052. } else if (lquery) {
  1053. return;
  1054. }
  1055. /* Quick return if possible. */
  1056. if (*m == *n || *m == 0) {
  1057. if (wantp) {
  1058. *pl = 1.;
  1059. *pr = 1.;
  1060. }
  1061. if (wantd) {
  1062. dscale = 0.;
  1063. dsum = 1.;
  1064. i__1 = *n;
  1065. for (i__ = 1; i__ <= i__1; ++i__) {
  1066. zlassq_(n, &a[i__ * a_dim1 + 1], &c__1, &dscale, &dsum);
  1067. zlassq_(n, &b[i__ * b_dim1 + 1], &c__1, &dscale, &dsum);
  1068. /* L20: */
  1069. }
  1070. dif[1] = dscale * sqrt(dsum);
  1071. dif[2] = dif[1];
  1072. }
  1073. goto L70;
  1074. }
  1075. /* Get machine constant */
  1076. safmin = dlamch_("S");
  1077. /* Collect the selected blocks at the top-left corner of (A, B). */
  1078. ks = 0;
  1079. i__1 = *n;
  1080. for (k = 1; k <= i__1; ++k) {
  1081. swap = select[k];
  1082. if (swap) {
  1083. ++ks;
  1084. /* Swap the K-th block to position KS. Compute unitary Q */
  1085. /* and Z that will swap adjacent diagonal blocks in (A, B). */
  1086. if (k != ks) {
  1087. ztgexc_(wantq, wantz, n, &a[a_offset], lda, &b[b_offset], ldb,
  1088. &q[q_offset], ldq, &z__[z_offset], ldz, &k, &ks, &
  1089. ierr);
  1090. }
  1091. if (ierr > 0) {
  1092. /* Swap is rejected: exit. */
  1093. *info = 1;
  1094. if (wantp) {
  1095. *pl = 0.;
  1096. *pr = 0.;
  1097. }
  1098. if (wantd) {
  1099. dif[1] = 0.;
  1100. dif[2] = 0.;
  1101. }
  1102. goto L70;
  1103. }
  1104. }
  1105. /* L30: */
  1106. }
  1107. if (wantp) {
  1108. /* Solve generalized Sylvester equation for R and L: */
  1109. /* A11 * R - L * A22 = A12 */
  1110. /* B11 * R - L * B22 = B12 */
  1111. n1 = *m;
  1112. n2 = *n - *m;
  1113. i__ = n1 + 1;
  1114. zlacpy_("Full", &n1, &n2, &a[i__ * a_dim1 + 1], lda, &work[1], &n1);
  1115. zlacpy_("Full", &n1, &n2, &b[i__ * b_dim1 + 1], ldb, &work[n1 * n2 +
  1116. 1], &n1);
  1117. ijb = 0;
  1118. i__1 = *lwork - (n1 << 1) * n2;
  1119. ztgsyl_("N", &ijb, &n1, &n2, &a[a_offset], lda, &a[i__ + i__ * a_dim1]
  1120. , lda, &work[1], &n1, &b[b_offset], ldb, &b[i__ + i__ *
  1121. b_dim1], ldb, &work[n1 * n2 + 1], &n1, &dscale, &dif[1], &
  1122. work[(n1 * n2 << 1) + 1], &i__1, &iwork[1], &ierr);
  1123. /* Estimate the reciprocal of norms of "projections" onto */
  1124. /* left and right eigenspaces */
  1125. rdscal = 0.;
  1126. dsum = 1.;
  1127. i__1 = n1 * n2;
  1128. zlassq_(&i__1, &work[1], &c__1, &rdscal, &dsum);
  1129. *pl = rdscal * sqrt(dsum);
  1130. if (*pl == 0.) {
  1131. *pl = 1.;
  1132. } else {
  1133. *pl = dscale / (sqrt(dscale * dscale / *pl + *pl) * sqrt(*pl));
  1134. }
  1135. rdscal = 0.;
  1136. dsum = 1.;
  1137. i__1 = n1 * n2;
  1138. zlassq_(&i__1, &work[n1 * n2 + 1], &c__1, &rdscal, &dsum);
  1139. *pr = rdscal * sqrt(dsum);
  1140. if (*pr == 0.) {
  1141. *pr = 1.;
  1142. } else {
  1143. *pr = dscale / (sqrt(dscale * dscale / *pr + *pr) * sqrt(*pr));
  1144. }
  1145. }
  1146. if (wantd) {
  1147. /* Compute estimates Difu and Difl. */
  1148. if (wantd1) {
  1149. n1 = *m;
  1150. n2 = *n - *m;
  1151. i__ = n1 + 1;
  1152. ijb = 3;
  1153. /* Frobenius norm-based Difu estimate. */
  1154. i__1 = *lwork - (n1 << 1) * n2;
  1155. ztgsyl_("N", &ijb, &n1, &n2, &a[a_offset], lda, &a[i__ + i__ *
  1156. a_dim1], lda, &work[1], &n1, &b[b_offset], ldb, &b[i__ +
  1157. i__ * b_dim1], ldb, &work[n1 * n2 + 1], &n1, &dscale, &
  1158. dif[1], &work[(n1 * n2 << 1) + 1], &i__1, &iwork[1], &
  1159. ierr);
  1160. /* Frobenius norm-based Difl estimate. */
  1161. i__1 = *lwork - (n1 << 1) * n2;
  1162. ztgsyl_("N", &ijb, &n2, &n1, &a[i__ + i__ * a_dim1], lda, &a[
  1163. a_offset], lda, &work[1], &n2, &b[i__ + i__ * b_dim1],
  1164. ldb, &b[b_offset], ldb, &work[n1 * n2 + 1], &n2, &dscale,
  1165. &dif[2], &work[(n1 * n2 << 1) + 1], &i__1, &iwork[1], &
  1166. ierr);
  1167. } else {
  1168. /* Compute 1-norm-based estimates of Difu and Difl using */
  1169. /* reversed communication with ZLACN2. In each step a */
  1170. /* generalized Sylvester equation or a transposed variant */
  1171. /* is solved. */
  1172. kase = 0;
  1173. n1 = *m;
  1174. n2 = *n - *m;
  1175. i__ = n1 + 1;
  1176. ijb = 0;
  1177. mn2 = (n1 << 1) * n2;
  1178. /* 1-norm-based estimate of Difu. */
  1179. L40:
  1180. zlacn2_(&mn2, &work[mn2 + 1], &work[1], &dif[1], &kase, isave);
  1181. if (kase != 0) {
  1182. if (kase == 1) {
  1183. /* Solve generalized Sylvester equation */
  1184. i__1 = *lwork - (n1 << 1) * n2;
  1185. ztgsyl_("N", &ijb, &n1, &n2, &a[a_offset], lda, &a[i__ +
  1186. i__ * a_dim1], lda, &work[1], &n1, &b[b_offset],
  1187. ldb, &b[i__ + i__ * b_dim1], ldb, &work[n1 * n2 +
  1188. 1], &n1, &dscale, &dif[1], &work[(n1 * n2 << 1) +
  1189. 1], &i__1, &iwork[1], &ierr);
  1190. } else {
  1191. /* Solve the transposed variant. */
  1192. i__1 = *lwork - (n1 << 1) * n2;
  1193. ztgsyl_("C", &ijb, &n1, &n2, &a[a_offset], lda, &a[i__ +
  1194. i__ * a_dim1], lda, &work[1], &n1, &b[b_offset],
  1195. ldb, &b[i__ + i__ * b_dim1], ldb, &work[n1 * n2 +
  1196. 1], &n1, &dscale, &dif[1], &work[(n1 * n2 << 1) +
  1197. 1], &i__1, &iwork[1], &ierr);
  1198. }
  1199. goto L40;
  1200. }
  1201. dif[1] = dscale / dif[1];
  1202. /* 1-norm-based estimate of Difl. */
  1203. L50:
  1204. zlacn2_(&mn2, &work[mn2 + 1], &work[1], &dif[2], &kase, isave);
  1205. if (kase != 0) {
  1206. if (kase == 1) {
  1207. /* Solve generalized Sylvester equation */
  1208. i__1 = *lwork - (n1 << 1) * n2;
  1209. ztgsyl_("N", &ijb, &n2, &n1, &a[i__ + i__ * a_dim1], lda,
  1210. &a[a_offset], lda, &work[1], &n2, &b[i__ + i__ *
  1211. b_dim1], ldb, &b[b_offset], ldb, &work[n1 * n2 +
  1212. 1], &n2, &dscale, &dif[2], &work[(n1 * n2 << 1) +
  1213. 1], &i__1, &iwork[1], &ierr);
  1214. } else {
  1215. /* Solve the transposed variant. */
  1216. i__1 = *lwork - (n1 << 1) * n2;
  1217. ztgsyl_("C", &ijb, &n2, &n1, &a[i__ + i__ * a_dim1], lda,
  1218. &a[a_offset], lda, &work[1], &n2, &b[b_offset],
  1219. ldb, &b[i__ + i__ * b_dim1], ldb, &work[n1 * n2 +
  1220. 1], &n2, &dscale, &dif[2], &work[(n1 * n2 << 1) +
  1221. 1], &i__1, &iwork[1], &ierr);
  1222. }
  1223. goto L50;
  1224. }
  1225. dif[2] = dscale / dif[2];
  1226. }
  1227. }
  1228. /* If B(K,K) is complex, make it real and positive (normalization */
  1229. /* of the generalized Schur form) and Store the generalized */
  1230. /* eigenvalues of reordered pair (A, B) */
  1231. i__1 = *n;
  1232. for (k = 1; k <= i__1; ++k) {
  1233. dscale = z_abs(&b[k + k * b_dim1]);
  1234. if (dscale > safmin) {
  1235. i__2 = k + k * b_dim1;
  1236. z__2.r = b[i__2].r / dscale, z__2.i = b[i__2].i / dscale;
  1237. d_cnjg(&z__1, &z__2);
  1238. temp1.r = z__1.r, temp1.i = z__1.i;
  1239. i__2 = k + k * b_dim1;
  1240. z__1.r = b[i__2].r / dscale, z__1.i = b[i__2].i / dscale;
  1241. temp2.r = z__1.r, temp2.i = z__1.i;
  1242. i__2 = k + k * b_dim1;
  1243. b[i__2].r = dscale, b[i__2].i = 0.;
  1244. i__2 = *n - k;
  1245. zscal_(&i__2, &temp1, &b[k + (k + 1) * b_dim1], ldb);
  1246. i__2 = *n - k + 1;
  1247. zscal_(&i__2, &temp1, &a[k + k * a_dim1], lda);
  1248. if (*wantq) {
  1249. zscal_(n, &temp2, &q[k * q_dim1 + 1], &c__1);
  1250. }
  1251. } else {
  1252. i__2 = k + k * b_dim1;
  1253. b[i__2].r = 0., b[i__2].i = 0.;
  1254. }
  1255. i__2 = k;
  1256. i__3 = k + k * a_dim1;
  1257. alpha[i__2].r = a[i__3].r, alpha[i__2].i = a[i__3].i;
  1258. i__2 = k;
  1259. i__3 = k + k * b_dim1;
  1260. beta[i__2].r = b[i__3].r, beta[i__2].i = b[i__3].i;
  1261. /* L60: */
  1262. }
  1263. L70:
  1264. work[1].r = (doublereal) lwmin, work[1].i = 0.;
  1265. iwork[1] = liwmin;
  1266. return;
  1267. /* End of ZTGSEN */
  1268. } /* ztgsen_ */