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.

ctgevc.c 44 kB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552
  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]/df(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 complex c_b1 = {0.f,0.f};
  485. static complex c_b2 = {1.f,0.f};
  486. static integer c__1 = 1;
  487. /* > \brief \b CTGEVC */
  488. /* =========== DOCUMENTATION =========== */
  489. /* Online html documentation available at */
  490. /* http://www.netlib.org/lapack/explore-html/ */
  491. /* > \htmlonly */
  492. /* > Download CTGEVC + dependencies */
  493. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/ctgevc.
  494. f"> */
  495. /* > [TGZ]</a> */
  496. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/ctgevc.
  497. f"> */
  498. /* > [ZIP]</a> */
  499. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/ctgevc.
  500. f"> */
  501. /* > [TXT]</a> */
  502. /* > \endhtmlonly */
  503. /* Definition: */
  504. /* =========== */
  505. /* SUBROUTINE CTGEVC( SIDE, HOWMNY, SELECT, N, S, LDS, P, LDP, VL, */
  506. /* LDVL, VR, LDVR, MM, M, WORK, RWORK, INFO ) */
  507. /* CHARACTER HOWMNY, SIDE */
  508. /* INTEGER INFO, LDP, LDS, LDVL, LDVR, M, MM, N */
  509. /* LOGICAL SELECT( * ) */
  510. /* REAL RWORK( * ) */
  511. /* COMPLEX P( LDP, * ), S( LDS, * ), VL( LDVL, * ), */
  512. /* $ VR( LDVR, * ), WORK( * ) */
  513. /* > \par Purpose: */
  514. /* ============= */
  515. /* > */
  516. /* > \verbatim */
  517. /* > */
  518. /* > CTGEVC computes some or all of the right and/or left eigenvectors of */
  519. /* > a pair of complex matrices (S,P), where S and P are upper triangular. */
  520. /* > Matrix pairs of this type are produced by the generalized Schur */
  521. /* > factorization of a complex matrix pair (A,B): */
  522. /* > */
  523. /* > A = Q*S*Z**H, B = Q*P*Z**H */
  524. /* > */
  525. /* > as computed by CGGHRD + CHGEQZ. */
  526. /* > */
  527. /* > The right eigenvector x and the left eigenvector y of (S,P) */
  528. /* > corresponding to an eigenvalue w are defined by: */
  529. /* > */
  530. /* > S*x = w*P*x, (y**H)*S = w*(y**H)*P, */
  531. /* > */
  532. /* > where y**H denotes the conjugate tranpose of y. */
  533. /* > The eigenvalues are not input to this routine, but are computed */
  534. /* > directly from the diagonal elements of S and P. */
  535. /* > */
  536. /* > This routine returns the matrices X and/or Y of right and left */
  537. /* > eigenvectors of (S,P), or the products Z*X and/or Q*Y, */
  538. /* > where Z and Q are input matrices. */
  539. /* > If Q and Z are the unitary factors from the generalized Schur */
  540. /* > factorization of a matrix pair (A,B), then Z*X and Q*Y */
  541. /* > are the matrices of right and left eigenvectors of (A,B). */
  542. /* > \endverbatim */
  543. /* Arguments: */
  544. /* ========== */
  545. /* > \param[in] SIDE */
  546. /* > \verbatim */
  547. /* > SIDE is CHARACTER*1 */
  548. /* > = 'R': compute right eigenvectors only; */
  549. /* > = 'L': compute left eigenvectors only; */
  550. /* > = 'B': compute both right and left eigenvectors. */
  551. /* > \endverbatim */
  552. /* > */
  553. /* > \param[in] HOWMNY */
  554. /* > \verbatim */
  555. /* > HOWMNY is CHARACTER*1 */
  556. /* > = 'A': compute all right and/or left eigenvectors; */
  557. /* > = 'B': compute all right and/or left eigenvectors, */
  558. /* > backtransformed by the matrices in VR and/or VL; */
  559. /* > = 'S': compute selected right and/or left eigenvectors, */
  560. /* > specified by the logical array SELECT. */
  561. /* > \endverbatim */
  562. /* > */
  563. /* > \param[in] SELECT */
  564. /* > \verbatim */
  565. /* > SELECT is LOGICAL array, dimension (N) */
  566. /* > If HOWMNY='S', SELECT specifies the eigenvectors to be */
  567. /* > computed. The eigenvector corresponding to the j-th */
  568. /* > eigenvalue is computed if SELECT(j) = .TRUE.. */
  569. /* > Not referenced if HOWMNY = 'A' or 'B'. */
  570. /* > \endverbatim */
  571. /* > */
  572. /* > \param[in] N */
  573. /* > \verbatim */
  574. /* > N is INTEGER */
  575. /* > The order of the matrices S and P. N >= 0. */
  576. /* > \endverbatim */
  577. /* > */
  578. /* > \param[in] S */
  579. /* > \verbatim */
  580. /* > S is COMPLEX array, dimension (LDS,N) */
  581. /* > The upper triangular matrix S from a generalized Schur */
  582. /* > factorization, as computed by CHGEQZ. */
  583. /* > \endverbatim */
  584. /* > */
  585. /* > \param[in] LDS */
  586. /* > \verbatim */
  587. /* > LDS is INTEGER */
  588. /* > The leading dimension of array S. LDS >= f2cmax(1,N). */
  589. /* > \endverbatim */
  590. /* > */
  591. /* > \param[in] P */
  592. /* > \verbatim */
  593. /* > P is COMPLEX array, dimension (LDP,N) */
  594. /* > The upper triangular matrix P from a generalized Schur */
  595. /* > factorization, as computed by CHGEQZ. P must have real */
  596. /* > diagonal elements. */
  597. /* > \endverbatim */
  598. /* > */
  599. /* > \param[in] LDP */
  600. /* > \verbatim */
  601. /* > LDP is INTEGER */
  602. /* > The leading dimension of array P. LDP >= f2cmax(1,N). */
  603. /* > \endverbatim */
  604. /* > */
  605. /* > \param[in,out] VL */
  606. /* > \verbatim */
  607. /* > VL is COMPLEX array, dimension (LDVL,MM) */
  608. /* > On entry, if SIDE = 'L' or 'B' and HOWMNY = 'B', VL must */
  609. /* > contain an N-by-N matrix Q (usually the unitary matrix Q */
  610. /* > of left Schur vectors returned by CHGEQZ). */
  611. /* > On exit, if SIDE = 'L' or 'B', VL contains: */
  612. /* > if HOWMNY = 'A', the matrix Y of left eigenvectors of (S,P); */
  613. /* > if HOWMNY = 'B', the matrix Q*Y; */
  614. /* > if HOWMNY = 'S', the left eigenvectors of (S,P) specified by */
  615. /* > SELECT, stored consecutively in the columns of */
  616. /* > VL, in the same order as their eigenvalues. */
  617. /* > Not referenced if SIDE = 'R'. */
  618. /* > \endverbatim */
  619. /* > */
  620. /* > \param[in] LDVL */
  621. /* > \verbatim */
  622. /* > LDVL is INTEGER */
  623. /* > The leading dimension of array VL. LDVL >= 1, and if */
  624. /* > SIDE = 'L' or 'l' or 'B' or 'b', LDVL >= N. */
  625. /* > \endverbatim */
  626. /* > */
  627. /* > \param[in,out] VR */
  628. /* > \verbatim */
  629. /* > VR is COMPLEX array, dimension (LDVR,MM) */
  630. /* > On entry, if SIDE = 'R' or 'B' and HOWMNY = 'B', VR must */
  631. /* > contain an N-by-N matrix Q (usually the unitary matrix Z */
  632. /* > of right Schur vectors returned by CHGEQZ). */
  633. /* > On exit, if SIDE = 'R' or 'B', VR contains: */
  634. /* > if HOWMNY = 'A', the matrix X of right eigenvectors of (S,P); */
  635. /* > if HOWMNY = 'B', the matrix Z*X; */
  636. /* > if HOWMNY = 'S', the right eigenvectors of (S,P) specified by */
  637. /* > SELECT, stored consecutively in the columns of */
  638. /* > VR, in the same order as their eigenvalues. */
  639. /* > Not referenced if SIDE = 'L'. */
  640. /* > \endverbatim */
  641. /* > */
  642. /* > \param[in] LDVR */
  643. /* > \verbatim */
  644. /* > LDVR is INTEGER */
  645. /* > The leading dimension of the array VR. LDVR >= 1, and if */
  646. /* > SIDE = 'R' or 'B', LDVR >= N. */
  647. /* > \endverbatim */
  648. /* > */
  649. /* > \param[in] MM */
  650. /* > \verbatim */
  651. /* > MM is INTEGER */
  652. /* > The number of columns in the arrays VL and/or VR. MM >= M. */
  653. /* > \endverbatim */
  654. /* > */
  655. /* > \param[out] M */
  656. /* > \verbatim */
  657. /* > M is INTEGER */
  658. /* > The number of columns in the arrays VL and/or VR actually */
  659. /* > used to store the eigenvectors. If HOWMNY = 'A' or 'B', M */
  660. /* > is set to N. Each selected eigenvector occupies one column. */
  661. /* > \endverbatim */
  662. /* > */
  663. /* > \param[out] WORK */
  664. /* > \verbatim */
  665. /* > WORK is COMPLEX array, dimension (2*N) */
  666. /* > \endverbatim */
  667. /* > */
  668. /* > \param[out] RWORK */
  669. /* > \verbatim */
  670. /* > RWORK is REAL array, dimension (2*N) */
  671. /* > \endverbatim */
  672. /* > */
  673. /* > \param[out] INFO */
  674. /* > \verbatim */
  675. /* > INFO is INTEGER */
  676. /* > = 0: successful exit. */
  677. /* > < 0: if INFO = -i, the i-th argument had an illegal value. */
  678. /* > \endverbatim */
  679. /* Authors: */
  680. /* ======== */
  681. /* > \author Univ. of Tennessee */
  682. /* > \author Univ. of California Berkeley */
  683. /* > \author Univ. of Colorado Denver */
  684. /* > \author NAG Ltd. */
  685. /* > \date December 2016 */
  686. /* > \ingroup complexGEcomputational */
  687. /* ===================================================================== */
  688. /* Subroutine */ void ctgevc_(char *side, char *howmny, logical *select,
  689. integer *n, complex *s, integer *lds, complex *p, integer *ldp,
  690. complex *vl, integer *ldvl, complex *vr, integer *ldvr, integer *mm,
  691. integer *m, complex *work, real *rwork, integer *info)
  692. {
  693. /* System generated locals */
  694. integer p_dim1, p_offset, s_dim1, s_offset, vl_dim1, vl_offset, vr_dim1,
  695. vr_offset, i__1, i__2, i__3, i__4, i__5;
  696. real r__1, r__2, r__3, r__4, r__5, r__6;
  697. complex q__1, q__2, q__3, q__4;
  698. /* Local variables */
  699. integer ibeg, ieig, iend;
  700. real dmin__;
  701. integer isrc;
  702. real temp;
  703. complex suma, sumb;
  704. real xmax;
  705. complex d__;
  706. integer i__, j;
  707. real scale;
  708. logical ilall;
  709. integer iside;
  710. real sbeta;
  711. extern logical lsame_(char *, char *);
  712. extern /* Subroutine */ void cgemv_(char *, integer *, integer *, complex *
  713. , complex *, integer *, complex *, integer *, complex *, complex *
  714. , integer *);
  715. real small;
  716. logical compl;
  717. real anorm, bnorm;
  718. logical compr;
  719. complex ca, cb;
  720. logical ilbbad;
  721. real acoefa;
  722. integer je;
  723. real bcoefa, acoeff;
  724. complex bcoeff;
  725. logical ilback;
  726. integer im;
  727. extern /* Subroutine */ void slabad_(real *, real *);
  728. real ascale, bscale;
  729. integer jr;
  730. extern /* Complex */ VOID cladiv_(complex *, complex *, complex *);
  731. extern real slamch_(char *);
  732. complex salpha;
  733. real safmin;
  734. extern /* Subroutine */ int xerbla_(char *, integer *, ftnlen);
  735. real bignum;
  736. logical ilcomp;
  737. integer ihwmny;
  738. real big;
  739. logical lsa, lsb;
  740. real ulp;
  741. complex sum;
  742. /* -- LAPACK computational routine (version 3.7.0) -- */
  743. /* -- LAPACK is a software package provided by Univ. of Tennessee, -- */
  744. /* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- */
  745. /* December 2016 */
  746. /* ===================================================================== */
  747. /* Decode and Test the input parameters */
  748. /* Parameter adjustments */
  749. --select;
  750. s_dim1 = *lds;
  751. s_offset = 1 + s_dim1 * 1;
  752. s -= s_offset;
  753. p_dim1 = *ldp;
  754. p_offset = 1 + p_dim1 * 1;
  755. p -= p_offset;
  756. vl_dim1 = *ldvl;
  757. vl_offset = 1 + vl_dim1 * 1;
  758. vl -= vl_offset;
  759. vr_dim1 = *ldvr;
  760. vr_offset = 1 + vr_dim1 * 1;
  761. vr -= vr_offset;
  762. --work;
  763. --rwork;
  764. /* Function Body */
  765. if (lsame_(howmny, "A")) {
  766. ihwmny = 1;
  767. ilall = TRUE_;
  768. ilback = FALSE_;
  769. } else if (lsame_(howmny, "S")) {
  770. ihwmny = 2;
  771. ilall = FALSE_;
  772. ilback = FALSE_;
  773. } else if (lsame_(howmny, "B")) {
  774. ihwmny = 3;
  775. ilall = TRUE_;
  776. ilback = TRUE_;
  777. } else {
  778. ihwmny = -1;
  779. }
  780. if (lsame_(side, "R")) {
  781. iside = 1;
  782. compl = FALSE_;
  783. compr = TRUE_;
  784. } else if (lsame_(side, "L")) {
  785. iside = 2;
  786. compl = TRUE_;
  787. compr = FALSE_;
  788. } else if (lsame_(side, "B")) {
  789. iside = 3;
  790. compl = TRUE_;
  791. compr = TRUE_;
  792. } else {
  793. iside = -1;
  794. }
  795. *info = 0;
  796. if (iside < 0) {
  797. *info = -1;
  798. } else if (ihwmny < 0) {
  799. *info = -2;
  800. } else if (*n < 0) {
  801. *info = -4;
  802. } else if (*lds < f2cmax(1,*n)) {
  803. *info = -6;
  804. } else if (*ldp < f2cmax(1,*n)) {
  805. *info = -8;
  806. }
  807. if (*info != 0) {
  808. i__1 = -(*info);
  809. xerbla_("CTGEVC", &i__1, (ftnlen)6);
  810. return;
  811. }
  812. /* Count the number of eigenvectors */
  813. if (! ilall) {
  814. im = 0;
  815. i__1 = *n;
  816. for (j = 1; j <= i__1; ++j) {
  817. if (select[j]) {
  818. ++im;
  819. }
  820. /* L10: */
  821. }
  822. } else {
  823. im = *n;
  824. }
  825. /* Check diagonal of B */
  826. ilbbad = FALSE_;
  827. i__1 = *n;
  828. for (j = 1; j <= i__1; ++j) {
  829. if (r_imag(&p[j + j * p_dim1]) != 0.f) {
  830. ilbbad = TRUE_;
  831. }
  832. /* L20: */
  833. }
  834. if (ilbbad) {
  835. *info = -7;
  836. } else if (compl && *ldvl < *n || *ldvl < 1) {
  837. *info = -10;
  838. } else if (compr && *ldvr < *n || *ldvr < 1) {
  839. *info = -12;
  840. } else if (*mm < im) {
  841. *info = -13;
  842. }
  843. if (*info != 0) {
  844. i__1 = -(*info);
  845. xerbla_("CTGEVC", &i__1, (ftnlen)6);
  846. return;
  847. }
  848. /* Quick return if possible */
  849. *m = im;
  850. if (*n == 0) {
  851. return;
  852. }
  853. /* Machine Constants */
  854. safmin = slamch_("Safe minimum");
  855. big = 1.f / safmin;
  856. slabad_(&safmin, &big);
  857. ulp = slamch_("Epsilon") * slamch_("Base");
  858. small = safmin * *n / ulp;
  859. big = 1.f / small;
  860. bignum = 1.f / (safmin * *n);
  861. /* Compute the 1-norm of each column of the strictly upper triangular */
  862. /* part of A and B to check for possible overflow in the triangular */
  863. /* solver. */
  864. i__1 = s_dim1 + 1;
  865. anorm = (r__1 = s[i__1].r, abs(r__1)) + (r__2 = r_imag(&s[s_dim1 + 1]),
  866. abs(r__2));
  867. i__1 = p_dim1 + 1;
  868. bnorm = (r__1 = p[i__1].r, abs(r__1)) + (r__2 = r_imag(&p[p_dim1 + 1]),
  869. abs(r__2));
  870. rwork[1] = 0.f;
  871. rwork[*n + 1] = 0.f;
  872. i__1 = *n;
  873. for (j = 2; j <= i__1; ++j) {
  874. rwork[j] = 0.f;
  875. rwork[*n + j] = 0.f;
  876. i__2 = j - 1;
  877. for (i__ = 1; i__ <= i__2; ++i__) {
  878. i__3 = i__ + j * s_dim1;
  879. rwork[j] += (r__1 = s[i__3].r, abs(r__1)) + (r__2 = r_imag(&s[i__
  880. + j * s_dim1]), abs(r__2));
  881. i__3 = i__ + j * p_dim1;
  882. rwork[*n + j] += (r__1 = p[i__3].r, abs(r__1)) + (r__2 = r_imag(&
  883. p[i__ + j * p_dim1]), abs(r__2));
  884. /* L30: */
  885. }
  886. /* Computing MAX */
  887. i__2 = j + j * s_dim1;
  888. r__3 = anorm, r__4 = rwork[j] + ((r__1 = s[i__2].r, abs(r__1)) + (
  889. r__2 = r_imag(&s[j + j * s_dim1]), abs(r__2)));
  890. anorm = f2cmax(r__3,r__4);
  891. /* Computing MAX */
  892. i__2 = j + j * p_dim1;
  893. r__3 = bnorm, r__4 = rwork[*n + j] + ((r__1 = p[i__2].r, abs(r__1)) +
  894. (r__2 = r_imag(&p[j + j * p_dim1]), abs(r__2)));
  895. bnorm = f2cmax(r__3,r__4);
  896. /* L40: */
  897. }
  898. ascale = 1.f / f2cmax(anorm,safmin);
  899. bscale = 1.f / f2cmax(bnorm,safmin);
  900. /* Left eigenvectors */
  901. if (compl) {
  902. ieig = 0;
  903. /* Main loop over eigenvalues */
  904. i__1 = *n;
  905. for (je = 1; je <= i__1; ++je) {
  906. if (ilall) {
  907. ilcomp = TRUE_;
  908. } else {
  909. ilcomp = select[je];
  910. }
  911. if (ilcomp) {
  912. ++ieig;
  913. i__2 = je + je * s_dim1;
  914. i__3 = je + je * p_dim1;
  915. if ((r__2 = s[i__2].r, abs(r__2)) + (r__3 = r_imag(&s[je + je
  916. * s_dim1]), abs(r__3)) <= safmin && (r__1 = p[i__3].r,
  917. abs(r__1)) <= safmin) {
  918. /* Singular matrix pencil -- return unit eigenvector */
  919. i__2 = *n;
  920. for (jr = 1; jr <= i__2; ++jr) {
  921. i__3 = jr + ieig * vl_dim1;
  922. vl[i__3].r = 0.f, vl[i__3].i = 0.f;
  923. /* L50: */
  924. }
  925. i__2 = ieig + ieig * vl_dim1;
  926. vl[i__2].r = 1.f, vl[i__2].i = 0.f;
  927. goto L140;
  928. }
  929. /* Non-singular eigenvalue: */
  930. /* Compute coefficients a and b in */
  931. /* H */
  932. /* y ( a A - b B ) = 0 */
  933. /* Computing MAX */
  934. i__2 = je + je * s_dim1;
  935. i__3 = je + je * p_dim1;
  936. r__4 = ((r__2 = s[i__2].r, abs(r__2)) + (r__3 = r_imag(&s[je
  937. + je * s_dim1]), abs(r__3))) * ascale, r__5 = (r__1 =
  938. p[i__3].r, abs(r__1)) * bscale, r__4 = f2cmax(r__4,r__5);
  939. temp = 1.f / f2cmax(r__4,safmin);
  940. i__2 = je + je * s_dim1;
  941. q__2.r = temp * s[i__2].r, q__2.i = temp * s[i__2].i;
  942. q__1.r = ascale * q__2.r, q__1.i = ascale * q__2.i;
  943. salpha.r = q__1.r, salpha.i = q__1.i;
  944. i__2 = je + je * p_dim1;
  945. sbeta = temp * p[i__2].r * bscale;
  946. acoeff = sbeta * ascale;
  947. q__1.r = bscale * salpha.r, q__1.i = bscale * salpha.i;
  948. bcoeff.r = q__1.r, bcoeff.i = q__1.i;
  949. /* Scale to avoid underflow */
  950. lsa = abs(sbeta) >= safmin && abs(acoeff) < small;
  951. lsb = (r__1 = salpha.r, abs(r__1)) + (r__2 = r_imag(&salpha),
  952. abs(r__2)) >= safmin && (r__3 = bcoeff.r, abs(r__3))
  953. + (r__4 = r_imag(&bcoeff), abs(r__4)) < small;
  954. scale = 1.f;
  955. if (lsa) {
  956. scale = small / abs(sbeta) * f2cmin(anorm,big);
  957. }
  958. if (lsb) {
  959. /* Computing MAX */
  960. r__3 = scale, r__4 = small / ((r__1 = salpha.r, abs(r__1))
  961. + (r__2 = r_imag(&salpha), abs(r__2))) * f2cmin(
  962. bnorm,big);
  963. scale = f2cmax(r__3,r__4);
  964. }
  965. if (lsa || lsb) {
  966. /* Computing MIN */
  967. /* Computing MAX */
  968. r__5 = 1.f, r__6 = abs(acoeff), r__5 = f2cmax(r__5,r__6),
  969. r__6 = (r__1 = bcoeff.r, abs(r__1)) + (r__2 =
  970. r_imag(&bcoeff), abs(r__2));
  971. r__3 = scale, r__4 = 1.f / (safmin * f2cmax(r__5,r__6));
  972. scale = f2cmin(r__3,r__4);
  973. if (lsa) {
  974. acoeff = ascale * (scale * sbeta);
  975. } else {
  976. acoeff = scale * acoeff;
  977. }
  978. if (lsb) {
  979. q__2.r = scale * salpha.r, q__2.i = scale * salpha.i;
  980. q__1.r = bscale * q__2.r, q__1.i = bscale * q__2.i;
  981. bcoeff.r = q__1.r, bcoeff.i = q__1.i;
  982. } else {
  983. q__1.r = scale * bcoeff.r, q__1.i = scale * bcoeff.i;
  984. bcoeff.r = q__1.r, bcoeff.i = q__1.i;
  985. }
  986. }
  987. acoefa = abs(acoeff);
  988. bcoefa = (r__1 = bcoeff.r, abs(r__1)) + (r__2 = r_imag(&
  989. bcoeff), abs(r__2));
  990. xmax = 1.f;
  991. i__2 = *n;
  992. for (jr = 1; jr <= i__2; ++jr) {
  993. i__3 = jr;
  994. work[i__3].r = 0.f, work[i__3].i = 0.f;
  995. /* L60: */
  996. }
  997. i__2 = je;
  998. work[i__2].r = 1.f, work[i__2].i = 0.f;
  999. /* Computing MAX */
  1000. r__1 = ulp * acoefa * anorm, r__2 = ulp * bcoefa * bnorm,
  1001. r__1 = f2cmax(r__1,r__2);
  1002. dmin__ = f2cmax(r__1,safmin);
  1003. /* H */
  1004. /* Triangular solve of (a A - b B) y = 0 */
  1005. /* H */
  1006. /* (rowwise in (a A - b B) , or columnwise in a A - b B) */
  1007. i__2 = *n;
  1008. for (j = je + 1; j <= i__2; ++j) {
  1009. /* Compute */
  1010. /* j-1 */
  1011. /* SUM = sum conjg( a*S(k,j) - b*P(k,j) )*x(k) */
  1012. /* k=je */
  1013. /* (Scale if necessary) */
  1014. temp = 1.f / xmax;
  1015. if (acoefa * rwork[j] + bcoefa * rwork[*n + j] > bignum *
  1016. temp) {
  1017. i__3 = j - 1;
  1018. for (jr = je; jr <= i__3; ++jr) {
  1019. i__4 = jr;
  1020. i__5 = jr;
  1021. q__1.r = temp * work[i__5].r, q__1.i = temp *
  1022. work[i__5].i;
  1023. work[i__4].r = q__1.r, work[i__4].i = q__1.i;
  1024. /* L70: */
  1025. }
  1026. xmax = 1.f;
  1027. }
  1028. suma.r = 0.f, suma.i = 0.f;
  1029. sumb.r = 0.f, sumb.i = 0.f;
  1030. i__3 = j - 1;
  1031. for (jr = je; jr <= i__3; ++jr) {
  1032. r_cnjg(&q__3, &s[jr + j * s_dim1]);
  1033. i__4 = jr;
  1034. q__2.r = q__3.r * work[i__4].r - q__3.i * work[i__4]
  1035. .i, q__2.i = q__3.r * work[i__4].i + q__3.i *
  1036. work[i__4].r;
  1037. q__1.r = suma.r + q__2.r, q__1.i = suma.i + q__2.i;
  1038. suma.r = q__1.r, suma.i = q__1.i;
  1039. r_cnjg(&q__3, &p[jr + j * p_dim1]);
  1040. i__4 = jr;
  1041. q__2.r = q__3.r * work[i__4].r - q__3.i * work[i__4]
  1042. .i, q__2.i = q__3.r * work[i__4].i + q__3.i *
  1043. work[i__4].r;
  1044. q__1.r = sumb.r + q__2.r, q__1.i = sumb.i + q__2.i;
  1045. sumb.r = q__1.r, sumb.i = q__1.i;
  1046. /* L80: */
  1047. }
  1048. q__2.r = acoeff * suma.r, q__2.i = acoeff * suma.i;
  1049. r_cnjg(&q__4, &bcoeff);
  1050. q__3.r = q__4.r * sumb.r - q__4.i * sumb.i, q__3.i =
  1051. q__4.r * sumb.i + q__4.i * sumb.r;
  1052. q__1.r = q__2.r - q__3.r, q__1.i = q__2.i - q__3.i;
  1053. sum.r = q__1.r, sum.i = q__1.i;
  1054. /* Form x(j) = - SUM / conjg( a*S(j,j) - b*P(j,j) ) */
  1055. /* with scaling and perturbation of the denominator */
  1056. i__3 = j + j * s_dim1;
  1057. q__3.r = acoeff * s[i__3].r, q__3.i = acoeff * s[i__3].i;
  1058. i__4 = j + j * p_dim1;
  1059. q__4.r = bcoeff.r * p[i__4].r - bcoeff.i * p[i__4].i,
  1060. q__4.i = bcoeff.r * p[i__4].i + bcoeff.i * p[i__4]
  1061. .r;
  1062. q__2.r = q__3.r - q__4.r, q__2.i = q__3.i - q__4.i;
  1063. r_cnjg(&q__1, &q__2);
  1064. d__.r = q__1.r, d__.i = q__1.i;
  1065. if ((r__1 = d__.r, abs(r__1)) + (r__2 = r_imag(&d__), abs(
  1066. r__2)) <= dmin__) {
  1067. q__1.r = dmin__, q__1.i = 0.f;
  1068. d__.r = q__1.r, d__.i = q__1.i;
  1069. }
  1070. if ((r__1 = d__.r, abs(r__1)) + (r__2 = r_imag(&d__), abs(
  1071. r__2)) < 1.f) {
  1072. if ((r__1 = sum.r, abs(r__1)) + (r__2 = r_imag(&sum),
  1073. abs(r__2)) >= bignum * ((r__3 = d__.r, abs(
  1074. r__3)) + (r__4 = r_imag(&d__), abs(r__4)))) {
  1075. temp = 1.f / ((r__1 = sum.r, abs(r__1)) + (r__2 =
  1076. r_imag(&sum), abs(r__2)));
  1077. i__3 = j - 1;
  1078. for (jr = je; jr <= i__3; ++jr) {
  1079. i__4 = jr;
  1080. i__5 = jr;
  1081. q__1.r = temp * work[i__5].r, q__1.i = temp *
  1082. work[i__5].i;
  1083. work[i__4].r = q__1.r, work[i__4].i = q__1.i;
  1084. /* L90: */
  1085. }
  1086. xmax = temp * xmax;
  1087. q__1.r = temp * sum.r, q__1.i = temp * sum.i;
  1088. sum.r = q__1.r, sum.i = q__1.i;
  1089. }
  1090. }
  1091. i__3 = j;
  1092. q__2.r = -sum.r, q__2.i = -sum.i;
  1093. cladiv_(&q__1, &q__2, &d__);
  1094. work[i__3].r = q__1.r, work[i__3].i = q__1.i;
  1095. /* Computing MAX */
  1096. i__3 = j;
  1097. r__3 = xmax, r__4 = (r__1 = work[i__3].r, abs(r__1)) + (
  1098. r__2 = r_imag(&work[j]), abs(r__2));
  1099. xmax = f2cmax(r__3,r__4);
  1100. /* L100: */
  1101. }
  1102. /* Back transform eigenvector if HOWMNY='B'. */
  1103. if (ilback) {
  1104. i__2 = *n + 1 - je;
  1105. cgemv_("N", n, &i__2, &c_b2, &vl[je * vl_dim1 + 1], ldvl,
  1106. &work[je], &c__1, &c_b1, &work[*n + 1], &c__1);
  1107. isrc = 2;
  1108. ibeg = 1;
  1109. } else {
  1110. isrc = 1;
  1111. ibeg = je;
  1112. }
  1113. /* Copy and scale eigenvector into column of VL */
  1114. xmax = 0.f;
  1115. i__2 = *n;
  1116. for (jr = ibeg; jr <= i__2; ++jr) {
  1117. /* Computing MAX */
  1118. i__3 = (isrc - 1) * *n + jr;
  1119. r__3 = xmax, r__4 = (r__1 = work[i__3].r, abs(r__1)) + (
  1120. r__2 = r_imag(&work[(isrc - 1) * *n + jr]), abs(
  1121. r__2));
  1122. xmax = f2cmax(r__3,r__4);
  1123. /* L110: */
  1124. }
  1125. if (xmax > safmin) {
  1126. temp = 1.f / xmax;
  1127. i__2 = *n;
  1128. for (jr = ibeg; jr <= i__2; ++jr) {
  1129. i__3 = jr + ieig * vl_dim1;
  1130. i__4 = (isrc - 1) * *n + jr;
  1131. q__1.r = temp * work[i__4].r, q__1.i = temp * work[
  1132. i__4].i;
  1133. vl[i__3].r = q__1.r, vl[i__3].i = q__1.i;
  1134. /* L120: */
  1135. }
  1136. } else {
  1137. ibeg = *n + 1;
  1138. }
  1139. i__2 = ibeg - 1;
  1140. for (jr = 1; jr <= i__2; ++jr) {
  1141. i__3 = jr + ieig * vl_dim1;
  1142. vl[i__3].r = 0.f, vl[i__3].i = 0.f;
  1143. /* L130: */
  1144. }
  1145. }
  1146. L140:
  1147. ;
  1148. }
  1149. }
  1150. /* Right eigenvectors */
  1151. if (compr) {
  1152. ieig = im + 1;
  1153. /* Main loop over eigenvalues */
  1154. for (je = *n; je >= 1; --je) {
  1155. if (ilall) {
  1156. ilcomp = TRUE_;
  1157. } else {
  1158. ilcomp = select[je];
  1159. }
  1160. if (ilcomp) {
  1161. --ieig;
  1162. i__1 = je + je * s_dim1;
  1163. i__2 = je + je * p_dim1;
  1164. if ((r__2 = s[i__1].r, abs(r__2)) + (r__3 = r_imag(&s[je + je
  1165. * s_dim1]), abs(r__3)) <= safmin && (r__1 = p[i__2].r,
  1166. abs(r__1)) <= safmin) {
  1167. /* Singular matrix pencil -- return unit eigenvector */
  1168. i__1 = *n;
  1169. for (jr = 1; jr <= i__1; ++jr) {
  1170. i__2 = jr + ieig * vr_dim1;
  1171. vr[i__2].r = 0.f, vr[i__2].i = 0.f;
  1172. /* L150: */
  1173. }
  1174. i__1 = ieig + ieig * vr_dim1;
  1175. vr[i__1].r = 1.f, vr[i__1].i = 0.f;
  1176. goto L250;
  1177. }
  1178. /* Non-singular eigenvalue: */
  1179. /* Compute coefficients a and b in */
  1180. /* ( a A - b B ) x = 0 */
  1181. /* Computing MAX */
  1182. i__1 = je + je * s_dim1;
  1183. i__2 = je + je * p_dim1;
  1184. r__4 = ((r__2 = s[i__1].r, abs(r__2)) + (r__3 = r_imag(&s[je
  1185. + je * s_dim1]), abs(r__3))) * ascale, r__5 = (r__1 =
  1186. p[i__2].r, abs(r__1)) * bscale, r__4 = f2cmax(r__4,r__5);
  1187. temp = 1.f / f2cmax(r__4,safmin);
  1188. i__1 = je + je * s_dim1;
  1189. q__2.r = temp * s[i__1].r, q__2.i = temp * s[i__1].i;
  1190. q__1.r = ascale * q__2.r, q__1.i = ascale * q__2.i;
  1191. salpha.r = q__1.r, salpha.i = q__1.i;
  1192. i__1 = je + je * p_dim1;
  1193. sbeta = temp * p[i__1].r * bscale;
  1194. acoeff = sbeta * ascale;
  1195. q__1.r = bscale * salpha.r, q__1.i = bscale * salpha.i;
  1196. bcoeff.r = q__1.r, bcoeff.i = q__1.i;
  1197. /* Scale to avoid underflow */
  1198. lsa = abs(sbeta) >= safmin && abs(acoeff) < small;
  1199. lsb = (r__1 = salpha.r, abs(r__1)) + (r__2 = r_imag(&salpha),
  1200. abs(r__2)) >= safmin && (r__3 = bcoeff.r, abs(r__3))
  1201. + (r__4 = r_imag(&bcoeff), abs(r__4)) < small;
  1202. scale = 1.f;
  1203. if (lsa) {
  1204. scale = small / abs(sbeta) * f2cmin(anorm,big);
  1205. }
  1206. if (lsb) {
  1207. /* Computing MAX */
  1208. r__3 = scale, r__4 = small / ((r__1 = salpha.r, abs(r__1))
  1209. + (r__2 = r_imag(&salpha), abs(r__2))) * f2cmin(
  1210. bnorm,big);
  1211. scale = f2cmax(r__3,r__4);
  1212. }
  1213. if (lsa || lsb) {
  1214. /* Computing MIN */
  1215. /* Computing MAX */
  1216. r__5 = 1.f, r__6 = abs(acoeff), r__5 = f2cmax(r__5,r__6),
  1217. r__6 = (r__1 = bcoeff.r, abs(r__1)) + (r__2 =
  1218. r_imag(&bcoeff), abs(r__2));
  1219. r__3 = scale, r__4 = 1.f / (safmin * f2cmax(r__5,r__6));
  1220. scale = f2cmin(r__3,r__4);
  1221. if (lsa) {
  1222. acoeff = ascale * (scale * sbeta);
  1223. } else {
  1224. acoeff = scale * acoeff;
  1225. }
  1226. if (lsb) {
  1227. q__2.r = scale * salpha.r, q__2.i = scale * salpha.i;
  1228. q__1.r = bscale * q__2.r, q__1.i = bscale * q__2.i;
  1229. bcoeff.r = q__1.r, bcoeff.i = q__1.i;
  1230. } else {
  1231. q__1.r = scale * bcoeff.r, q__1.i = scale * bcoeff.i;
  1232. bcoeff.r = q__1.r, bcoeff.i = q__1.i;
  1233. }
  1234. }
  1235. acoefa = abs(acoeff);
  1236. bcoefa = (r__1 = bcoeff.r, abs(r__1)) + (r__2 = r_imag(&
  1237. bcoeff), abs(r__2));
  1238. xmax = 1.f;
  1239. i__1 = *n;
  1240. for (jr = 1; jr <= i__1; ++jr) {
  1241. i__2 = jr;
  1242. work[i__2].r = 0.f, work[i__2].i = 0.f;
  1243. /* L160: */
  1244. }
  1245. i__1 = je;
  1246. work[i__1].r = 1.f, work[i__1].i = 0.f;
  1247. /* Computing MAX */
  1248. r__1 = ulp * acoefa * anorm, r__2 = ulp * bcoefa * bnorm,
  1249. r__1 = f2cmax(r__1,r__2);
  1250. dmin__ = f2cmax(r__1,safmin);
  1251. /* Triangular solve of (a A - b B) x = 0 (columnwise) */
  1252. /* WORK(1:j-1) contains sums w, */
  1253. /* WORK(j+1:JE) contains x */
  1254. i__1 = je - 1;
  1255. for (jr = 1; jr <= i__1; ++jr) {
  1256. i__2 = jr;
  1257. i__3 = jr + je * s_dim1;
  1258. q__2.r = acoeff * s[i__3].r, q__2.i = acoeff * s[i__3].i;
  1259. i__4 = jr + je * p_dim1;
  1260. q__3.r = bcoeff.r * p[i__4].r - bcoeff.i * p[i__4].i,
  1261. q__3.i = bcoeff.r * p[i__4].i + bcoeff.i * p[i__4]
  1262. .r;
  1263. q__1.r = q__2.r - q__3.r, q__1.i = q__2.i - q__3.i;
  1264. work[i__2].r = q__1.r, work[i__2].i = q__1.i;
  1265. /* L170: */
  1266. }
  1267. i__1 = je;
  1268. work[i__1].r = 1.f, work[i__1].i = 0.f;
  1269. for (j = je - 1; j >= 1; --j) {
  1270. /* Form x(j) := - w(j) / d */
  1271. /* with scaling and perturbation of the denominator */
  1272. i__1 = j + j * s_dim1;
  1273. q__2.r = acoeff * s[i__1].r, q__2.i = acoeff * s[i__1].i;
  1274. i__2 = j + j * p_dim1;
  1275. q__3.r = bcoeff.r * p[i__2].r - bcoeff.i * p[i__2].i,
  1276. q__3.i = bcoeff.r * p[i__2].i + bcoeff.i * p[i__2]
  1277. .r;
  1278. q__1.r = q__2.r - q__3.r, q__1.i = q__2.i - q__3.i;
  1279. d__.r = q__1.r, d__.i = q__1.i;
  1280. if ((r__1 = d__.r, abs(r__1)) + (r__2 = r_imag(&d__), abs(
  1281. r__2)) <= dmin__) {
  1282. q__1.r = dmin__, q__1.i = 0.f;
  1283. d__.r = q__1.r, d__.i = q__1.i;
  1284. }
  1285. if ((r__1 = d__.r, abs(r__1)) + (r__2 = r_imag(&d__), abs(
  1286. r__2)) < 1.f) {
  1287. i__1 = j;
  1288. if ((r__1 = work[i__1].r, abs(r__1)) + (r__2 = r_imag(
  1289. &work[j]), abs(r__2)) >= bignum * ((r__3 =
  1290. d__.r, abs(r__3)) + (r__4 = r_imag(&d__), abs(
  1291. r__4)))) {
  1292. i__1 = j;
  1293. temp = 1.f / ((r__1 = work[i__1].r, abs(r__1)) + (
  1294. r__2 = r_imag(&work[j]), abs(r__2)));
  1295. i__1 = je;
  1296. for (jr = 1; jr <= i__1; ++jr) {
  1297. i__2 = jr;
  1298. i__3 = jr;
  1299. q__1.r = temp * work[i__3].r, q__1.i = temp *
  1300. work[i__3].i;
  1301. work[i__2].r = q__1.r, work[i__2].i = q__1.i;
  1302. /* L180: */
  1303. }
  1304. }
  1305. }
  1306. i__1 = j;
  1307. i__2 = j;
  1308. q__2.r = -work[i__2].r, q__2.i = -work[i__2].i;
  1309. cladiv_(&q__1, &q__2, &d__);
  1310. work[i__1].r = q__1.r, work[i__1].i = q__1.i;
  1311. if (j > 1) {
  1312. /* w = w + x(j)*(a S(*,j) - b P(*,j) ) with scaling */
  1313. i__1 = j;
  1314. if ((r__1 = work[i__1].r, abs(r__1)) + (r__2 = r_imag(
  1315. &work[j]), abs(r__2)) > 1.f) {
  1316. i__1 = j;
  1317. temp = 1.f / ((r__1 = work[i__1].r, abs(r__1)) + (
  1318. r__2 = r_imag(&work[j]), abs(r__2)));
  1319. if (acoefa * rwork[j] + bcoefa * rwork[*n + j] >=
  1320. bignum * temp) {
  1321. i__1 = je;
  1322. for (jr = 1; jr <= i__1; ++jr) {
  1323. i__2 = jr;
  1324. i__3 = jr;
  1325. q__1.r = temp * work[i__3].r, q__1.i =
  1326. temp * work[i__3].i;
  1327. work[i__2].r = q__1.r, work[i__2].i =
  1328. q__1.i;
  1329. /* L190: */
  1330. }
  1331. }
  1332. }
  1333. i__1 = j;
  1334. q__1.r = acoeff * work[i__1].r, q__1.i = acoeff *
  1335. work[i__1].i;
  1336. ca.r = q__1.r, ca.i = q__1.i;
  1337. i__1 = j;
  1338. q__1.r = bcoeff.r * work[i__1].r - bcoeff.i * work[
  1339. i__1].i, q__1.i = bcoeff.r * work[i__1].i +
  1340. bcoeff.i * work[i__1].r;
  1341. cb.r = q__1.r, cb.i = q__1.i;
  1342. i__1 = j - 1;
  1343. for (jr = 1; jr <= i__1; ++jr) {
  1344. i__2 = jr;
  1345. i__3 = jr;
  1346. i__4 = jr + j * s_dim1;
  1347. q__3.r = ca.r * s[i__4].r - ca.i * s[i__4].i,
  1348. q__3.i = ca.r * s[i__4].i + ca.i * s[i__4]
  1349. .r;
  1350. q__2.r = work[i__3].r + q__3.r, q__2.i = work[
  1351. i__3].i + q__3.i;
  1352. i__5 = jr + j * p_dim1;
  1353. q__4.r = cb.r * p[i__5].r - cb.i * p[i__5].i,
  1354. q__4.i = cb.r * p[i__5].i + cb.i * p[i__5]
  1355. .r;
  1356. q__1.r = q__2.r - q__4.r, q__1.i = q__2.i -
  1357. q__4.i;
  1358. work[i__2].r = q__1.r, work[i__2].i = q__1.i;
  1359. /* L200: */
  1360. }
  1361. }
  1362. /* L210: */
  1363. }
  1364. /* Back transform eigenvector if HOWMNY='B'. */
  1365. if (ilback) {
  1366. cgemv_("N", n, &je, &c_b2, &vr[vr_offset], ldvr, &work[1],
  1367. &c__1, &c_b1, &work[*n + 1], &c__1);
  1368. isrc = 2;
  1369. iend = *n;
  1370. } else {
  1371. isrc = 1;
  1372. iend = je;
  1373. }
  1374. /* Copy and scale eigenvector into column of VR */
  1375. xmax = 0.f;
  1376. i__1 = iend;
  1377. for (jr = 1; jr <= i__1; ++jr) {
  1378. /* Computing MAX */
  1379. i__2 = (isrc - 1) * *n + jr;
  1380. r__3 = xmax, r__4 = (r__1 = work[i__2].r, abs(r__1)) + (
  1381. r__2 = r_imag(&work[(isrc - 1) * *n + jr]), abs(
  1382. r__2));
  1383. xmax = f2cmax(r__3,r__4);
  1384. /* L220: */
  1385. }
  1386. if (xmax > safmin) {
  1387. temp = 1.f / xmax;
  1388. i__1 = iend;
  1389. for (jr = 1; jr <= i__1; ++jr) {
  1390. i__2 = jr + ieig * vr_dim1;
  1391. i__3 = (isrc - 1) * *n + jr;
  1392. q__1.r = temp * work[i__3].r, q__1.i = temp * work[
  1393. i__3].i;
  1394. vr[i__2].r = q__1.r, vr[i__2].i = q__1.i;
  1395. /* L230: */
  1396. }
  1397. } else {
  1398. iend = 0;
  1399. }
  1400. i__1 = *n;
  1401. for (jr = iend + 1; jr <= i__1; ++jr) {
  1402. i__2 = jr + ieig * vr_dim1;
  1403. vr[i__2].r = 0.f, vr[i__2].i = 0.f;
  1404. /* L240: */
  1405. }
  1406. }
  1407. L250:
  1408. ;
  1409. }
  1410. }
  1411. return;
  1412. /* End of CTGEVC */
  1413. } /* ctgevc_ */