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.

stgevc.c 55 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965
  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 logical c_true = TRUE_;
  485. static integer c__2 = 2;
  486. static real c_b34 = 1.f;
  487. static integer c__1 = 1;
  488. static real c_b36 = 0.f;
  489. static logical c_false = FALSE_;
  490. /* > \brief \b STGEVC */
  491. /* =========== DOCUMENTATION =========== */
  492. /* Online html documentation available at */
  493. /* http://www.netlib.org/lapack/explore-html/ */
  494. /* > \htmlonly */
  495. /* > Download STGEVC + dependencies */
  496. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/stgevc.
  497. f"> */
  498. /* > [TGZ]</a> */
  499. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/stgevc.
  500. f"> */
  501. /* > [ZIP]</a> */
  502. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/stgevc.
  503. f"> */
  504. /* > [TXT]</a> */
  505. /* > \endhtmlonly */
  506. /* Definition: */
  507. /* =========== */
  508. /* SUBROUTINE STGEVC( SIDE, HOWMNY, SELECT, N, S, LDS, P, LDP, VL, */
  509. /* LDVL, VR, LDVR, MM, M, WORK, INFO ) */
  510. /* CHARACTER HOWMNY, SIDE */
  511. /* INTEGER INFO, LDP, LDS, LDVL, LDVR, M, MM, N */
  512. /* LOGICAL SELECT( * ) */
  513. /* REAL P( LDP, * ), S( LDS, * ), VL( LDVL, * ), */
  514. /* $ VR( LDVR, * ), WORK( * ) */
  515. /* > \par Purpose: */
  516. /* ============= */
  517. /* > */
  518. /* > \verbatim */
  519. /* > */
  520. /* > STGEVC computes some or all of the right and/or left eigenvectors of */
  521. /* > a pair of real matrices (S,P), where S is a quasi-triangular matrix */
  522. /* > and P is upper triangular. Matrix pairs of this type are produced by */
  523. /* > the generalized Schur factorization of a matrix pair (A,B): */
  524. /* > */
  525. /* > A = Q*S*Z**T, B = Q*P*Z**T */
  526. /* > */
  527. /* > as computed by SGGHRD + SHGEQZ. */
  528. /* > */
  529. /* > The right eigenvector x and the left eigenvector y of (S,P) */
  530. /* > corresponding to an eigenvalue w are defined by: */
  531. /* > */
  532. /* > S*x = w*P*x, (y**H)*S = w*(y**H)*P, */
  533. /* > */
  534. /* > where y**H denotes the conjugate tranpose of y. */
  535. /* > The eigenvalues are not input to this routine, but are computed */
  536. /* > directly from the diagonal blocks of S and P. */
  537. /* > */
  538. /* > This routine returns the matrices X and/or Y of right and left */
  539. /* > eigenvectors of (S,P), or the products Z*X and/or Q*Y, */
  540. /* > where Z and Q are input matrices. */
  541. /* > If Q and Z are the orthogonal factors from the generalized Schur */
  542. /* > factorization of a matrix pair (A,B), then Z*X and Q*Y */
  543. /* > are the matrices of right and left eigenvectors of (A,B). */
  544. /* > */
  545. /* > \endverbatim */
  546. /* Arguments: */
  547. /* ========== */
  548. /* > \param[in] SIDE */
  549. /* > \verbatim */
  550. /* > SIDE is CHARACTER*1 */
  551. /* > = 'R': compute right eigenvectors only; */
  552. /* > = 'L': compute left eigenvectors only; */
  553. /* > = 'B': compute both right and left eigenvectors. */
  554. /* > \endverbatim */
  555. /* > */
  556. /* > \param[in] HOWMNY */
  557. /* > \verbatim */
  558. /* > HOWMNY is CHARACTER*1 */
  559. /* > = 'A': compute all right and/or left eigenvectors; */
  560. /* > = 'B': compute all right and/or left eigenvectors, */
  561. /* > backtransformed by the matrices in VR and/or VL; */
  562. /* > = 'S': compute selected right and/or left eigenvectors, */
  563. /* > specified by the logical array SELECT. */
  564. /* > \endverbatim */
  565. /* > */
  566. /* > \param[in] SELECT */
  567. /* > \verbatim */
  568. /* > SELECT is LOGICAL array, dimension (N) */
  569. /* > If HOWMNY='S', SELECT specifies the eigenvectors to be */
  570. /* > computed. If w(j) is a real eigenvalue, the corresponding */
  571. /* > real eigenvector is computed if SELECT(j) is .TRUE.. */
  572. /* > If w(j) and w(j+1) are the real and imaginary parts of a */
  573. /* > complex eigenvalue, the corresponding complex eigenvector */
  574. /* > is computed if either SELECT(j) or SELECT(j+1) is .TRUE., */
  575. /* > and on exit SELECT(j) is set to .TRUE. and SELECT(j+1) is */
  576. /* > set to .FALSE.. */
  577. /* > Not referenced if HOWMNY = 'A' or 'B'. */
  578. /* > \endverbatim */
  579. /* > */
  580. /* > \param[in] N */
  581. /* > \verbatim */
  582. /* > N is INTEGER */
  583. /* > The order of the matrices S and P. N >= 0. */
  584. /* > \endverbatim */
  585. /* > */
  586. /* > \param[in] S */
  587. /* > \verbatim */
  588. /* > S is REAL array, dimension (LDS,N) */
  589. /* > The upper quasi-triangular matrix S from a generalized Schur */
  590. /* > factorization, as computed by SHGEQZ. */
  591. /* > \endverbatim */
  592. /* > */
  593. /* > \param[in] LDS */
  594. /* > \verbatim */
  595. /* > LDS is INTEGER */
  596. /* > The leading dimension of array S. LDS >= f2cmax(1,N). */
  597. /* > \endverbatim */
  598. /* > */
  599. /* > \param[in] P */
  600. /* > \verbatim */
  601. /* > P is REAL array, dimension (LDP,N) */
  602. /* > The upper triangular matrix P from a generalized Schur */
  603. /* > factorization, as computed by SHGEQZ. */
  604. /* > 2-by-2 diagonal blocks of P corresponding to 2-by-2 blocks */
  605. /* > of S must be in positive diagonal form. */
  606. /* > \endverbatim */
  607. /* > */
  608. /* > \param[in] LDP */
  609. /* > \verbatim */
  610. /* > LDP is INTEGER */
  611. /* > The leading dimension of array P. LDP >= f2cmax(1,N). */
  612. /* > \endverbatim */
  613. /* > */
  614. /* > \param[in,out] VL */
  615. /* > \verbatim */
  616. /* > VL is REAL array, dimension (LDVL,MM) */
  617. /* > On entry, if SIDE = 'L' or 'B' and HOWMNY = 'B', VL must */
  618. /* > contain an N-by-N matrix Q (usually the orthogonal matrix Q */
  619. /* > of left Schur vectors returned by SHGEQZ). */
  620. /* > On exit, if SIDE = 'L' or 'B', VL contains: */
  621. /* > if HOWMNY = 'A', the matrix Y of left eigenvectors of (S,P); */
  622. /* > if HOWMNY = 'B', the matrix Q*Y; */
  623. /* > if HOWMNY = 'S', the left eigenvectors of (S,P) specified by */
  624. /* > SELECT, stored consecutively in the columns of */
  625. /* > VL, in the same order as their eigenvalues. */
  626. /* > */
  627. /* > A complex eigenvector corresponding to a complex eigenvalue */
  628. /* > is stored in two consecutive columns, the first holding the */
  629. /* > real part, and the second the imaginary part. */
  630. /* > */
  631. /* > Not referenced if SIDE = 'R'. */
  632. /* > \endverbatim */
  633. /* > */
  634. /* > \param[in] LDVL */
  635. /* > \verbatim */
  636. /* > LDVL is INTEGER */
  637. /* > The leading dimension of array VL. LDVL >= 1, and if */
  638. /* > SIDE = 'L' or 'B', LDVL >= N. */
  639. /* > \endverbatim */
  640. /* > */
  641. /* > \param[in,out] VR */
  642. /* > \verbatim */
  643. /* > VR is REAL array, dimension (LDVR,MM) */
  644. /* > On entry, if SIDE = 'R' or 'B' and HOWMNY = 'B', VR must */
  645. /* > contain an N-by-N matrix Z (usually the orthogonal matrix Z */
  646. /* > of right Schur vectors returned by SHGEQZ). */
  647. /* > */
  648. /* > On exit, if SIDE = 'R' or 'B', VR contains: */
  649. /* > if HOWMNY = 'A', the matrix X of right eigenvectors of (S,P); */
  650. /* > if HOWMNY = 'B' or 'b', the matrix Z*X; */
  651. /* > if HOWMNY = 'S' or 's', the right eigenvectors of (S,P) */
  652. /* > specified by SELECT, stored consecutively in the */
  653. /* > columns of VR, in the same order as their */
  654. /* > eigenvalues. */
  655. /* > */
  656. /* > A complex eigenvector corresponding to a complex eigenvalue */
  657. /* > is stored in two consecutive columns, the first holding the */
  658. /* > real part and the second the imaginary part. */
  659. /* > */
  660. /* > Not referenced if SIDE = 'L'. */
  661. /* > \endverbatim */
  662. /* > */
  663. /* > \param[in] LDVR */
  664. /* > \verbatim */
  665. /* > LDVR is INTEGER */
  666. /* > The leading dimension of the array VR. LDVR >= 1, and if */
  667. /* > SIDE = 'R' or 'B', LDVR >= N. */
  668. /* > \endverbatim */
  669. /* > */
  670. /* > \param[in] MM */
  671. /* > \verbatim */
  672. /* > MM is INTEGER */
  673. /* > The number of columns in the arrays VL and/or VR. MM >= M. */
  674. /* > \endverbatim */
  675. /* > */
  676. /* > \param[out] M */
  677. /* > \verbatim */
  678. /* > M is INTEGER */
  679. /* > The number of columns in the arrays VL and/or VR actually */
  680. /* > used to store the eigenvectors. If HOWMNY = 'A' or 'B', M */
  681. /* > is set to N. Each selected real eigenvector occupies one */
  682. /* > column and each selected complex eigenvector occupies two */
  683. /* > columns. */
  684. /* > \endverbatim */
  685. /* > */
  686. /* > \param[out] WORK */
  687. /* > \verbatim */
  688. /* > WORK is REAL array, dimension (6*N) */
  689. /* > \endverbatim */
  690. /* > */
  691. /* > \param[out] INFO */
  692. /* > \verbatim */
  693. /* > INFO is INTEGER */
  694. /* > = 0: successful exit. */
  695. /* > < 0: if INFO = -i, the i-th argument had an illegal value. */
  696. /* > > 0: the 2-by-2 block (INFO:INFO+1) does not have a complex */
  697. /* > eigenvalue. */
  698. /* > \endverbatim */
  699. /* Authors: */
  700. /* ======== */
  701. /* > \author Univ. of Tennessee */
  702. /* > \author Univ. of California Berkeley */
  703. /* > \author Univ. of Colorado Denver */
  704. /* > \author NAG Ltd. */
  705. /* > \date December 2016 */
  706. /* > \ingroup realGEcomputational */
  707. /* > \par Further Details: */
  708. /* ===================== */
  709. /* > */
  710. /* > \verbatim */
  711. /* > */
  712. /* > Allocation of workspace: */
  713. /* > ---------- -- --------- */
  714. /* > */
  715. /* > WORK( j ) = 1-norm of j-th column of A, above the diagonal */
  716. /* > WORK( N+j ) = 1-norm of j-th column of B, above the diagonal */
  717. /* > WORK( 2*N+1:3*N ) = real part of eigenvector */
  718. /* > WORK( 3*N+1:4*N ) = imaginary part of eigenvector */
  719. /* > WORK( 4*N+1:5*N ) = real part of back-transformed eigenvector */
  720. /* > WORK( 5*N+1:6*N ) = imaginary part of back-transformed eigenvector */
  721. /* > */
  722. /* > Rowwise vs. columnwise solution methods: */
  723. /* > ------- -- ---------- -------- ------- */
  724. /* > */
  725. /* > Finding a generalized eigenvector consists basically of solving the */
  726. /* > singular triangular system */
  727. /* > */
  728. /* > (A - w B) x = 0 (for right) or: (A - w B)**H y = 0 (for left) */
  729. /* > */
  730. /* > Consider finding the i-th right eigenvector (assume all eigenvalues */
  731. /* > are real). The equation to be solved is: */
  732. /* > n i */
  733. /* > 0 = sum C(j,k) v(k) = sum C(j,k) v(k) for j = i,. . .,1 */
  734. /* > k=j k=j */
  735. /* > */
  736. /* > where C = (A - w B) (The components v(i+1:n) are 0.) */
  737. /* > */
  738. /* > The "rowwise" method is: */
  739. /* > */
  740. /* > (1) v(i) := 1 */
  741. /* > for j = i-1,. . .,1: */
  742. /* > i */
  743. /* > (2) compute s = - sum C(j,k) v(k) and */
  744. /* > k=j+1 */
  745. /* > */
  746. /* > (3) v(j) := s / C(j,j) */
  747. /* > */
  748. /* > Step 2 is sometimes called the "dot product" step, since it is an */
  749. /* > inner product between the j-th row and the portion of the eigenvector */
  750. /* > that has been computed so far. */
  751. /* > */
  752. /* > The "columnwise" method consists basically in doing the sums */
  753. /* > for all the rows in parallel. As each v(j) is computed, the */
  754. /* > contribution of v(j) times the j-th column of C is added to the */
  755. /* > partial sums. Since FORTRAN arrays are stored columnwise, this has */
  756. /* > the advantage that at each step, the elements of C that are accessed */
  757. /* > are adjacent to one another, whereas with the rowwise method, the */
  758. /* > elements accessed at a step are spaced LDS (and LDP) words apart. */
  759. /* > */
  760. /* > When finding left eigenvectors, the matrix in question is the */
  761. /* > transpose of the one in storage, so the rowwise method then */
  762. /* > actually accesses columns of A and B at each step, and so is the */
  763. /* > preferred method. */
  764. /* > \endverbatim */
  765. /* > */
  766. /* ===================================================================== */
  767. /* Subroutine */ void stgevc_(char *side, char *howmny, logical *select,
  768. integer *n, real *s, integer *lds, real *p, integer *ldp, real *vl,
  769. integer *ldvl, real *vr, integer *ldvr, integer *mm, integer *m, real
  770. *work, integer *info)
  771. {
  772. /* System generated locals */
  773. integer p_dim1, p_offset, s_dim1, s_offset, vl_dim1, vl_offset, vr_dim1,
  774. vr_offset, i__1, i__2, i__3, i__4, i__5;
  775. real r__1, r__2, r__3, r__4, r__5, r__6;
  776. /* Local variables */
  777. integer ibeg, ieig, iend;
  778. real dmin__, temp, xmax, sump[4] /* was [2][2] */, sums[4] /*
  779. was [2][2] */, cim2a, cim2b, cre2a, cre2b;
  780. extern /* Subroutine */ void slag2_(real *, integer *, real *, integer *,
  781. real *, real *, real *, real *, real *, real *);
  782. real temp2, bdiag[2];
  783. integer i__, j;
  784. real acoef, scale;
  785. logical ilall;
  786. integer iside;
  787. real sbeta;
  788. extern logical lsame_(char *, char *);
  789. logical il2by2;
  790. integer iinfo;
  791. real small;
  792. logical compl;
  793. real anorm, bnorm;
  794. logical compr;
  795. extern /* Subroutine */ void sgemv_(char *, integer *, integer *, real *,
  796. real *, integer *, real *, integer *, real *, real *, integer *), slaln2_(logical *, integer *, integer *, real *, real *,
  797. real *, integer *, real *, real *, real *, integer *, real *,
  798. real *, real *, integer *, real *, real *, integer *);
  799. real temp2i, temp2r;
  800. integer ja;
  801. logical ilabad, ilbbad;
  802. integer jc, je, na;
  803. real acoefa, bcoefa, cimaga, cimagb;
  804. logical ilback;
  805. integer im;
  806. real bcoefi, ascale, bscale, creala;
  807. integer jr;
  808. real crealb;
  809. extern /* Subroutine */ void slabad_(real *, real *);
  810. real bcoefr;
  811. integer jw, nw;
  812. extern real slamch_(char *);
  813. real salfar, safmin;
  814. extern /* Subroutine */ int xerbla_(char *, integer *, ftnlen);
  815. real xscale, bignum;
  816. logical ilcomp, ilcplx;
  817. extern /* Subroutine */ void slacpy_(char *, integer *, integer *, real *,
  818. integer *, real *, integer *);
  819. integer ihwmny;
  820. real big;
  821. logical lsa, lsb;
  822. real ulp, sum[4] /* was [2][2] */;
  823. /* -- LAPACK computational routine (version 3.7.0) -- */
  824. /* -- LAPACK is a software package provided by Univ. of Tennessee, -- */
  825. /* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- */
  826. /* December 2016 */
  827. /* ===================================================================== */
  828. /* Decode and Test the input parameters */
  829. /* Parameter adjustments */
  830. --select;
  831. s_dim1 = *lds;
  832. s_offset = 1 + s_dim1 * 1;
  833. s -= s_offset;
  834. p_dim1 = *ldp;
  835. p_offset = 1 + p_dim1 * 1;
  836. p -= p_offset;
  837. vl_dim1 = *ldvl;
  838. vl_offset = 1 + vl_dim1 * 1;
  839. vl -= vl_offset;
  840. vr_dim1 = *ldvr;
  841. vr_offset = 1 + vr_dim1 * 1;
  842. vr -= vr_offset;
  843. --work;
  844. /* Function Body */
  845. if (lsame_(howmny, "A")) {
  846. ihwmny = 1;
  847. ilall = TRUE_;
  848. ilback = FALSE_;
  849. } else if (lsame_(howmny, "S")) {
  850. ihwmny = 2;
  851. ilall = FALSE_;
  852. ilback = FALSE_;
  853. } else if (lsame_(howmny, "B")) {
  854. ihwmny = 3;
  855. ilall = TRUE_;
  856. ilback = TRUE_;
  857. } else {
  858. ihwmny = -1;
  859. ilall = TRUE_;
  860. }
  861. if (lsame_(side, "R")) {
  862. iside = 1;
  863. compl = FALSE_;
  864. compr = TRUE_;
  865. } else if (lsame_(side, "L")) {
  866. iside = 2;
  867. compl = TRUE_;
  868. compr = FALSE_;
  869. } else if (lsame_(side, "B")) {
  870. iside = 3;
  871. compl = TRUE_;
  872. compr = TRUE_;
  873. } else {
  874. iside = -1;
  875. }
  876. *info = 0;
  877. if (iside < 0) {
  878. *info = -1;
  879. } else if (ihwmny < 0) {
  880. *info = -2;
  881. } else if (*n < 0) {
  882. *info = -4;
  883. } else if (*lds < f2cmax(1,*n)) {
  884. *info = -6;
  885. } else if (*ldp < f2cmax(1,*n)) {
  886. *info = -8;
  887. }
  888. if (*info != 0) {
  889. i__1 = -(*info);
  890. xerbla_("STGEVC", &i__1, (ftnlen)6);
  891. return;
  892. }
  893. /* Count the number of eigenvectors to be computed */
  894. if (! ilall) {
  895. im = 0;
  896. ilcplx = FALSE_;
  897. i__1 = *n;
  898. for (j = 1; j <= i__1; ++j) {
  899. if (ilcplx) {
  900. ilcplx = FALSE_;
  901. goto L10;
  902. }
  903. if (j < *n) {
  904. if (s[j + 1 + j * s_dim1] != 0.f) {
  905. ilcplx = TRUE_;
  906. }
  907. }
  908. if (ilcplx) {
  909. if (select[j] || select[j + 1]) {
  910. im += 2;
  911. }
  912. } else {
  913. if (select[j]) {
  914. ++im;
  915. }
  916. }
  917. L10:
  918. ;
  919. }
  920. } else {
  921. im = *n;
  922. }
  923. /* Check 2-by-2 diagonal blocks of A, B */
  924. ilabad = FALSE_;
  925. ilbbad = FALSE_;
  926. i__1 = *n - 1;
  927. for (j = 1; j <= i__1; ++j) {
  928. if (s[j + 1 + j * s_dim1] != 0.f) {
  929. if (p[j + j * p_dim1] == 0.f || p[j + 1 + (j + 1) * p_dim1] ==
  930. 0.f || p[j + (j + 1) * p_dim1] != 0.f) {
  931. ilbbad = TRUE_;
  932. }
  933. if (j < *n - 1) {
  934. if (s[j + 2 + (j + 1) * s_dim1] != 0.f) {
  935. ilabad = TRUE_;
  936. }
  937. }
  938. }
  939. /* L20: */
  940. }
  941. if (ilabad) {
  942. *info = -5;
  943. } else if (ilbbad) {
  944. *info = -7;
  945. } else if (compl && *ldvl < *n || *ldvl < 1) {
  946. *info = -10;
  947. } else if (compr && *ldvr < *n || *ldvr < 1) {
  948. *info = -12;
  949. } else if (*mm < im) {
  950. *info = -13;
  951. }
  952. if (*info != 0) {
  953. i__1 = -(*info);
  954. xerbla_("STGEVC", &i__1, (ftnlen)6);
  955. return;
  956. }
  957. /* Quick return if possible */
  958. *m = im;
  959. if (*n == 0) {
  960. return;
  961. }
  962. /* Machine Constants */
  963. safmin = slamch_("Safe minimum");
  964. big = 1.f / safmin;
  965. slabad_(&safmin, &big);
  966. ulp = slamch_("Epsilon") * slamch_("Base");
  967. small = safmin * *n / ulp;
  968. big = 1.f / small;
  969. bignum = 1.f / (safmin * *n);
  970. /* Compute the 1-norm of each column of the strictly upper triangular */
  971. /* part (i.e., excluding all elements belonging to the diagonal */
  972. /* blocks) of A and B to check for possible overflow in the */
  973. /* triangular solver. */
  974. anorm = (r__1 = s[s_dim1 + 1], abs(r__1));
  975. if (*n > 1) {
  976. anorm += (r__1 = s[s_dim1 + 2], abs(r__1));
  977. }
  978. bnorm = (r__1 = p[p_dim1 + 1], abs(r__1));
  979. work[1] = 0.f;
  980. work[*n + 1] = 0.f;
  981. i__1 = *n;
  982. for (j = 2; j <= i__1; ++j) {
  983. temp = 0.f;
  984. temp2 = 0.f;
  985. if (s[j + (j - 1) * s_dim1] == 0.f) {
  986. iend = j - 1;
  987. } else {
  988. iend = j - 2;
  989. }
  990. i__2 = iend;
  991. for (i__ = 1; i__ <= i__2; ++i__) {
  992. temp += (r__1 = s[i__ + j * s_dim1], abs(r__1));
  993. temp2 += (r__1 = p[i__ + j * p_dim1], abs(r__1));
  994. /* L30: */
  995. }
  996. work[j] = temp;
  997. work[*n + j] = temp2;
  998. /* Computing MIN */
  999. i__3 = j + 1;
  1000. i__2 = f2cmin(i__3,*n);
  1001. for (i__ = iend + 1; i__ <= i__2; ++i__) {
  1002. temp += (r__1 = s[i__ + j * s_dim1], abs(r__1));
  1003. temp2 += (r__1 = p[i__ + j * p_dim1], abs(r__1));
  1004. /* L40: */
  1005. }
  1006. anorm = f2cmax(anorm,temp);
  1007. bnorm = f2cmax(bnorm,temp2);
  1008. /* L50: */
  1009. }
  1010. ascale = 1.f / f2cmax(anorm,safmin);
  1011. bscale = 1.f / f2cmax(bnorm,safmin);
  1012. /* Left eigenvectors */
  1013. if (compl) {
  1014. ieig = 0;
  1015. /* Main loop over eigenvalues */
  1016. ilcplx = FALSE_;
  1017. i__1 = *n;
  1018. for (je = 1; je <= i__1; ++je) {
  1019. /* Skip this iteration if (a) HOWMNY='S' and SELECT=.FALSE., or */
  1020. /* (b) this would be the second of a complex pair. */
  1021. /* Check for complex eigenvalue, so as to be sure of which */
  1022. /* entry(-ies) of SELECT to look at. */
  1023. if (ilcplx) {
  1024. ilcplx = FALSE_;
  1025. goto L220;
  1026. }
  1027. nw = 1;
  1028. if (je < *n) {
  1029. if (s[je + 1 + je * s_dim1] != 0.f) {
  1030. ilcplx = TRUE_;
  1031. nw = 2;
  1032. }
  1033. }
  1034. if (ilall) {
  1035. ilcomp = TRUE_;
  1036. } else if (ilcplx) {
  1037. ilcomp = select[je] || select[je + 1];
  1038. } else {
  1039. ilcomp = select[je];
  1040. }
  1041. if (! ilcomp) {
  1042. goto L220;
  1043. }
  1044. /* Decide if (a) singular pencil, (b) real eigenvalue, or */
  1045. /* (c) complex eigenvalue. */
  1046. if (! ilcplx) {
  1047. if ((r__1 = s[je + je * s_dim1], abs(r__1)) <= safmin && (
  1048. r__2 = p[je + je * p_dim1], abs(r__2)) <= safmin) {
  1049. /* Singular matrix pencil -- return unit eigenvector */
  1050. ++ieig;
  1051. i__2 = *n;
  1052. for (jr = 1; jr <= i__2; ++jr) {
  1053. vl[jr + ieig * vl_dim1] = 0.f;
  1054. /* L60: */
  1055. }
  1056. vl[ieig + ieig * vl_dim1] = 1.f;
  1057. goto L220;
  1058. }
  1059. }
  1060. /* Clear vector */
  1061. i__2 = nw * *n;
  1062. for (jr = 1; jr <= i__2; ++jr) {
  1063. work[(*n << 1) + jr] = 0.f;
  1064. /* L70: */
  1065. }
  1066. /* T */
  1067. /* Compute coefficients in ( a A - b B ) y = 0 */
  1068. /* a is ACOEF */
  1069. /* b is BCOEFR + i*BCOEFI */
  1070. if (! ilcplx) {
  1071. /* Real eigenvalue */
  1072. /* Computing MAX */
  1073. r__3 = (r__1 = s[je + je * s_dim1], abs(r__1)) * ascale, r__4
  1074. = (r__2 = p[je + je * p_dim1], abs(r__2)) * bscale,
  1075. r__3 = f2cmax(r__3,r__4);
  1076. temp = 1.f / f2cmax(r__3,safmin);
  1077. salfar = temp * s[je + je * s_dim1] * ascale;
  1078. sbeta = temp * p[je + je * p_dim1] * bscale;
  1079. acoef = sbeta * ascale;
  1080. bcoefr = salfar * bscale;
  1081. bcoefi = 0.f;
  1082. /* Scale to avoid underflow */
  1083. scale = 1.f;
  1084. lsa = abs(sbeta) >= safmin && abs(acoef) < small;
  1085. lsb = abs(salfar) >= safmin && abs(bcoefr) < small;
  1086. if (lsa) {
  1087. scale = small / abs(sbeta) * f2cmin(anorm,big);
  1088. }
  1089. if (lsb) {
  1090. /* Computing MAX */
  1091. r__1 = scale, r__2 = small / abs(salfar) * f2cmin(bnorm,big);
  1092. scale = f2cmax(r__1,r__2);
  1093. }
  1094. if (lsa || lsb) {
  1095. /* Computing MIN */
  1096. /* Computing MAX */
  1097. r__3 = 1.f, r__4 = abs(acoef), r__3 = f2cmax(r__3,r__4),
  1098. r__4 = abs(bcoefr);
  1099. r__1 = scale, r__2 = 1.f / (safmin * f2cmax(r__3,r__4));
  1100. scale = f2cmin(r__1,r__2);
  1101. if (lsa) {
  1102. acoef = ascale * (scale * sbeta);
  1103. } else {
  1104. acoef = scale * acoef;
  1105. }
  1106. if (lsb) {
  1107. bcoefr = bscale * (scale * salfar);
  1108. } else {
  1109. bcoefr = scale * bcoefr;
  1110. }
  1111. }
  1112. acoefa = abs(acoef);
  1113. bcoefa = abs(bcoefr);
  1114. /* First component is 1 */
  1115. work[(*n << 1) + je] = 1.f;
  1116. xmax = 1.f;
  1117. } else {
  1118. /* Complex eigenvalue */
  1119. r__1 = safmin * 100.f;
  1120. slag2_(&s[je + je * s_dim1], lds, &p[je + je * p_dim1], ldp, &
  1121. r__1, &acoef, &temp, &bcoefr, &temp2, &bcoefi);
  1122. bcoefi = -bcoefi;
  1123. if (bcoefi == 0.f) {
  1124. *info = je;
  1125. return;
  1126. }
  1127. /* Scale to avoid over/underflow */
  1128. acoefa = abs(acoef);
  1129. bcoefa = abs(bcoefr) + abs(bcoefi);
  1130. scale = 1.f;
  1131. if (acoefa * ulp < safmin && acoefa >= safmin) {
  1132. scale = safmin / ulp / acoefa;
  1133. }
  1134. if (bcoefa * ulp < safmin && bcoefa >= safmin) {
  1135. /* Computing MAX */
  1136. r__1 = scale, r__2 = safmin / ulp / bcoefa;
  1137. scale = f2cmax(r__1,r__2);
  1138. }
  1139. if (safmin * acoefa > ascale) {
  1140. scale = ascale / (safmin * acoefa);
  1141. }
  1142. if (safmin * bcoefa > bscale) {
  1143. /* Computing MIN */
  1144. r__1 = scale, r__2 = bscale / (safmin * bcoefa);
  1145. scale = f2cmin(r__1,r__2);
  1146. }
  1147. if (scale != 1.f) {
  1148. acoef = scale * acoef;
  1149. acoefa = abs(acoef);
  1150. bcoefr = scale * bcoefr;
  1151. bcoefi = scale * bcoefi;
  1152. bcoefa = abs(bcoefr) + abs(bcoefi);
  1153. }
  1154. /* Compute first two components of eigenvector */
  1155. temp = acoef * s[je + 1 + je * s_dim1];
  1156. temp2r = acoef * s[je + je * s_dim1] - bcoefr * p[je + je *
  1157. p_dim1];
  1158. temp2i = -bcoefi * p[je + je * p_dim1];
  1159. if (abs(temp) > abs(temp2r) + abs(temp2i)) {
  1160. work[(*n << 1) + je] = 1.f;
  1161. work[*n * 3 + je] = 0.f;
  1162. work[(*n << 1) + je + 1] = -temp2r / temp;
  1163. work[*n * 3 + je + 1] = -temp2i / temp;
  1164. } else {
  1165. work[(*n << 1) + je + 1] = 1.f;
  1166. work[*n * 3 + je + 1] = 0.f;
  1167. temp = acoef * s[je + (je + 1) * s_dim1];
  1168. work[(*n << 1) + je] = (bcoefr * p[je + 1 + (je + 1) *
  1169. p_dim1] - acoef * s[je + 1 + (je + 1) * s_dim1]) /
  1170. temp;
  1171. work[*n * 3 + je] = bcoefi * p[je + 1 + (je + 1) * p_dim1]
  1172. / temp;
  1173. }
  1174. /* Computing MAX */
  1175. r__5 = (r__1 = work[(*n << 1) + je], abs(r__1)) + (r__2 =
  1176. work[*n * 3 + je], abs(r__2)), r__6 = (r__3 = work[(*
  1177. n << 1) + je + 1], abs(r__3)) + (r__4 = work[*n * 3 +
  1178. je + 1], abs(r__4));
  1179. xmax = f2cmax(r__5,r__6);
  1180. }
  1181. /* Computing MAX */
  1182. r__1 = ulp * acoefa * anorm, r__2 = ulp * bcoefa * bnorm, r__1 =
  1183. f2cmax(r__1,r__2);
  1184. dmin__ = f2cmax(r__1,safmin);
  1185. /* T */
  1186. /* Triangular solve of (a A - b B) y = 0 */
  1187. /* T */
  1188. /* (rowwise in (a A - b B) , or columnwise in (a A - b B) ) */
  1189. il2by2 = FALSE_;
  1190. i__2 = *n;
  1191. for (j = je + nw; j <= i__2; ++j) {
  1192. if (il2by2) {
  1193. il2by2 = FALSE_;
  1194. goto L160;
  1195. }
  1196. na = 1;
  1197. bdiag[0] = p[j + j * p_dim1];
  1198. if (j < *n) {
  1199. if (s[j + 1 + j * s_dim1] != 0.f) {
  1200. il2by2 = TRUE_;
  1201. bdiag[1] = p[j + 1 + (j + 1) * p_dim1];
  1202. na = 2;
  1203. }
  1204. }
  1205. /* Check whether scaling is necessary for dot products */
  1206. xscale = 1.f / f2cmax(1.f,xmax);
  1207. /* Computing MAX */
  1208. r__1 = work[j], r__2 = work[*n + j], r__1 = f2cmax(r__1,r__2),
  1209. r__2 = acoefa * work[j] + bcoefa * work[*n + j];
  1210. temp = f2cmax(r__1,r__2);
  1211. if (il2by2) {
  1212. /* Computing MAX */
  1213. r__1 = temp, r__2 = work[j + 1], r__1 = f2cmax(r__1,r__2),
  1214. r__2 = work[*n + j + 1], r__1 = f2cmax(r__1,r__2),
  1215. r__2 = acoefa * work[j + 1] + bcoefa * work[*n +
  1216. j + 1];
  1217. temp = f2cmax(r__1,r__2);
  1218. }
  1219. if (temp > bignum * xscale) {
  1220. i__3 = nw - 1;
  1221. for (jw = 0; jw <= i__3; ++jw) {
  1222. i__4 = j - 1;
  1223. for (jr = je; jr <= i__4; ++jr) {
  1224. work[(jw + 2) * *n + jr] = xscale * work[(jw + 2)
  1225. * *n + jr];
  1226. /* L80: */
  1227. }
  1228. /* L90: */
  1229. }
  1230. xmax *= xscale;
  1231. }
  1232. /* Compute dot products */
  1233. /* j-1 */
  1234. /* SUM = sum conjg( a*S(k,j) - b*P(k,j) )*x(k) */
  1235. /* k=je */
  1236. /* To reduce the op count, this is done as */
  1237. /* _ j-1 _ j-1 */
  1238. /* a*conjg( sum S(k,j)*x(k) ) - b*conjg( sum P(k,j)*x(k) ) */
  1239. /* k=je k=je */
  1240. /* which may cause underflow problems if A or B are close */
  1241. /* to underflow. (E.g., less than SMALL.) */
  1242. i__3 = nw;
  1243. for (jw = 1; jw <= i__3; ++jw) {
  1244. i__4 = na;
  1245. for (ja = 1; ja <= i__4; ++ja) {
  1246. sums[ja + (jw << 1) - 3] = 0.f;
  1247. sump[ja + (jw << 1) - 3] = 0.f;
  1248. i__5 = j - 1;
  1249. for (jr = je; jr <= i__5; ++jr) {
  1250. sums[ja + (jw << 1) - 3] += s[jr + (j + ja - 1) *
  1251. s_dim1] * work[(jw + 1) * *n + jr];
  1252. sump[ja + (jw << 1) - 3] += p[jr + (j + ja - 1) *
  1253. p_dim1] * work[(jw + 1) * *n + jr];
  1254. /* L100: */
  1255. }
  1256. /* L110: */
  1257. }
  1258. /* L120: */
  1259. }
  1260. i__3 = na;
  1261. for (ja = 1; ja <= i__3; ++ja) {
  1262. if (ilcplx) {
  1263. sum[ja - 1] = -acoef * sums[ja - 1] + bcoefr * sump[
  1264. ja - 1] - bcoefi * sump[ja + 1];
  1265. sum[ja + 1] = -acoef * sums[ja + 1] + bcoefr * sump[
  1266. ja + 1] + bcoefi * sump[ja - 1];
  1267. } else {
  1268. sum[ja - 1] = -acoef * sums[ja - 1] + bcoefr * sump[
  1269. ja - 1];
  1270. }
  1271. /* L130: */
  1272. }
  1273. /* T */
  1274. /* Solve ( a A - b B ) y = SUM(,) */
  1275. /* with scaling and perturbation of the denominator */
  1276. slaln2_(&c_true, &na, &nw, &dmin__, &acoef, &s[j + j * s_dim1]
  1277. , lds, bdiag, &bdiag[1], sum, &c__2, &bcoefr, &bcoefi,
  1278. &work[(*n << 1) + j], n, &scale, &temp, &iinfo);
  1279. if (scale < 1.f) {
  1280. i__3 = nw - 1;
  1281. for (jw = 0; jw <= i__3; ++jw) {
  1282. i__4 = j - 1;
  1283. for (jr = je; jr <= i__4; ++jr) {
  1284. work[(jw + 2) * *n + jr] = scale * work[(jw + 2) *
  1285. *n + jr];
  1286. /* L140: */
  1287. }
  1288. /* L150: */
  1289. }
  1290. xmax = scale * xmax;
  1291. }
  1292. xmax = f2cmax(xmax,temp);
  1293. L160:
  1294. ;
  1295. }
  1296. /* Copy eigenvector to VL, back transforming if */
  1297. /* HOWMNY='B'. */
  1298. ++ieig;
  1299. if (ilback) {
  1300. i__2 = nw - 1;
  1301. for (jw = 0; jw <= i__2; ++jw) {
  1302. i__3 = *n + 1 - je;
  1303. sgemv_("N", n, &i__3, &c_b34, &vl[je * vl_dim1 + 1], ldvl,
  1304. &work[(jw + 2) * *n + je], &c__1, &c_b36, &work[(
  1305. jw + 4) * *n + 1], &c__1);
  1306. /* L170: */
  1307. }
  1308. slacpy_(" ", n, &nw, &work[(*n << 2) + 1], n, &vl[je *
  1309. vl_dim1 + 1], ldvl);
  1310. ibeg = 1;
  1311. } else {
  1312. slacpy_(" ", n, &nw, &work[(*n << 1) + 1], n, &vl[ieig *
  1313. vl_dim1 + 1], ldvl);
  1314. ibeg = je;
  1315. }
  1316. /* Scale eigenvector */
  1317. xmax = 0.f;
  1318. if (ilcplx) {
  1319. i__2 = *n;
  1320. for (j = ibeg; j <= i__2; ++j) {
  1321. /* Computing MAX */
  1322. r__3 = xmax, r__4 = (r__1 = vl[j + ieig * vl_dim1], abs(
  1323. r__1)) + (r__2 = vl[j + (ieig + 1) * vl_dim1],
  1324. abs(r__2));
  1325. xmax = f2cmax(r__3,r__4);
  1326. /* L180: */
  1327. }
  1328. } else {
  1329. i__2 = *n;
  1330. for (j = ibeg; j <= i__2; ++j) {
  1331. /* Computing MAX */
  1332. r__2 = xmax, r__3 = (r__1 = vl[j + ieig * vl_dim1], abs(
  1333. r__1));
  1334. xmax = f2cmax(r__2,r__3);
  1335. /* L190: */
  1336. }
  1337. }
  1338. if (xmax > safmin) {
  1339. xscale = 1.f / xmax;
  1340. i__2 = nw - 1;
  1341. for (jw = 0; jw <= i__2; ++jw) {
  1342. i__3 = *n;
  1343. for (jr = ibeg; jr <= i__3; ++jr) {
  1344. vl[jr + (ieig + jw) * vl_dim1] = xscale * vl[jr + (
  1345. ieig + jw) * vl_dim1];
  1346. /* L200: */
  1347. }
  1348. /* L210: */
  1349. }
  1350. }
  1351. ieig = ieig + nw - 1;
  1352. L220:
  1353. ;
  1354. }
  1355. }
  1356. /* Right eigenvectors */
  1357. if (compr) {
  1358. ieig = im + 1;
  1359. /* Main loop over eigenvalues */
  1360. ilcplx = FALSE_;
  1361. for (je = *n; je >= 1; --je) {
  1362. /* Skip this iteration if (a) HOWMNY='S' and SELECT=.FALSE., or */
  1363. /* (b) this would be the second of a complex pair. */
  1364. /* Check for complex eigenvalue, so as to be sure of which */
  1365. /* entry(-ies) of SELECT to look at -- if complex, SELECT(JE) */
  1366. /* or SELECT(JE-1). */
  1367. /* If this is a complex pair, the 2-by-2 diagonal block */
  1368. /* corresponding to the eigenvalue is in rows/columns JE-1:JE */
  1369. if (ilcplx) {
  1370. ilcplx = FALSE_;
  1371. goto L500;
  1372. }
  1373. nw = 1;
  1374. if (je > 1) {
  1375. if (s[je + (je - 1) * s_dim1] != 0.f) {
  1376. ilcplx = TRUE_;
  1377. nw = 2;
  1378. }
  1379. }
  1380. if (ilall) {
  1381. ilcomp = TRUE_;
  1382. } else if (ilcplx) {
  1383. ilcomp = select[je] || select[je - 1];
  1384. } else {
  1385. ilcomp = select[je];
  1386. }
  1387. if (! ilcomp) {
  1388. goto L500;
  1389. }
  1390. /* Decide if (a) singular pencil, (b) real eigenvalue, or */
  1391. /* (c) complex eigenvalue. */
  1392. if (! ilcplx) {
  1393. if ((r__1 = s[je + je * s_dim1], abs(r__1)) <= safmin && (
  1394. r__2 = p[je + je * p_dim1], abs(r__2)) <= safmin) {
  1395. /* Singular matrix pencil -- unit eigenvector */
  1396. --ieig;
  1397. i__1 = *n;
  1398. for (jr = 1; jr <= i__1; ++jr) {
  1399. vr[jr + ieig * vr_dim1] = 0.f;
  1400. /* L230: */
  1401. }
  1402. vr[ieig + ieig * vr_dim1] = 1.f;
  1403. goto L500;
  1404. }
  1405. }
  1406. /* Clear vector */
  1407. i__1 = nw - 1;
  1408. for (jw = 0; jw <= i__1; ++jw) {
  1409. i__2 = *n;
  1410. for (jr = 1; jr <= i__2; ++jr) {
  1411. work[(jw + 2) * *n + jr] = 0.f;
  1412. /* L240: */
  1413. }
  1414. /* L250: */
  1415. }
  1416. /* Compute coefficients in ( a A - b B ) x = 0 */
  1417. /* a is ACOEF */
  1418. /* b is BCOEFR + i*BCOEFI */
  1419. if (! ilcplx) {
  1420. /* Real eigenvalue */
  1421. /* Computing MAX */
  1422. r__3 = (r__1 = s[je + je * s_dim1], abs(r__1)) * ascale, r__4
  1423. = (r__2 = p[je + je * p_dim1], abs(r__2)) * bscale,
  1424. r__3 = f2cmax(r__3,r__4);
  1425. temp = 1.f / f2cmax(r__3,safmin);
  1426. salfar = temp * s[je + je * s_dim1] * ascale;
  1427. sbeta = temp * p[je + je * p_dim1] * bscale;
  1428. acoef = sbeta * ascale;
  1429. bcoefr = salfar * bscale;
  1430. bcoefi = 0.f;
  1431. /* Scale to avoid underflow */
  1432. scale = 1.f;
  1433. lsa = abs(sbeta) >= safmin && abs(acoef) < small;
  1434. lsb = abs(salfar) >= safmin && abs(bcoefr) < small;
  1435. if (lsa) {
  1436. scale = small / abs(sbeta) * f2cmin(anorm,big);
  1437. }
  1438. if (lsb) {
  1439. /* Computing MAX */
  1440. r__1 = scale, r__2 = small / abs(salfar) * f2cmin(bnorm,big);
  1441. scale = f2cmax(r__1,r__2);
  1442. }
  1443. if (lsa || lsb) {
  1444. /* Computing MIN */
  1445. /* Computing MAX */
  1446. r__3 = 1.f, r__4 = abs(acoef), r__3 = f2cmax(r__3,r__4),
  1447. r__4 = abs(bcoefr);
  1448. r__1 = scale, r__2 = 1.f / (safmin * f2cmax(r__3,r__4));
  1449. scale = f2cmin(r__1,r__2);
  1450. if (lsa) {
  1451. acoef = ascale * (scale * sbeta);
  1452. } else {
  1453. acoef = scale * acoef;
  1454. }
  1455. if (lsb) {
  1456. bcoefr = bscale * (scale * salfar);
  1457. } else {
  1458. bcoefr = scale * bcoefr;
  1459. }
  1460. }
  1461. acoefa = abs(acoef);
  1462. bcoefa = abs(bcoefr);
  1463. /* First component is 1 */
  1464. work[(*n << 1) + je] = 1.f;
  1465. xmax = 1.f;
  1466. /* Compute contribution from column JE of A and B to sum */
  1467. /* (See "Further Details", above.) */
  1468. i__1 = je - 1;
  1469. for (jr = 1; jr <= i__1; ++jr) {
  1470. work[(*n << 1) + jr] = bcoefr * p[jr + je * p_dim1] -
  1471. acoef * s[jr + je * s_dim1];
  1472. /* L260: */
  1473. }
  1474. } else {
  1475. /* Complex eigenvalue */
  1476. r__1 = safmin * 100.f;
  1477. slag2_(&s[je - 1 + (je - 1) * s_dim1], lds, &p[je - 1 + (je -
  1478. 1) * p_dim1], ldp, &r__1, &acoef, &temp, &bcoefr, &
  1479. temp2, &bcoefi);
  1480. if (bcoefi == 0.f) {
  1481. *info = je - 1;
  1482. return;
  1483. }
  1484. /* Scale to avoid over/underflow */
  1485. acoefa = abs(acoef);
  1486. bcoefa = abs(bcoefr) + abs(bcoefi);
  1487. scale = 1.f;
  1488. if (acoefa * ulp < safmin && acoefa >= safmin) {
  1489. scale = safmin / ulp / acoefa;
  1490. }
  1491. if (bcoefa * ulp < safmin && bcoefa >= safmin) {
  1492. /* Computing MAX */
  1493. r__1 = scale, r__2 = safmin / ulp / bcoefa;
  1494. scale = f2cmax(r__1,r__2);
  1495. }
  1496. if (safmin * acoefa > ascale) {
  1497. scale = ascale / (safmin * acoefa);
  1498. }
  1499. if (safmin * bcoefa > bscale) {
  1500. /* Computing MIN */
  1501. r__1 = scale, r__2 = bscale / (safmin * bcoefa);
  1502. scale = f2cmin(r__1,r__2);
  1503. }
  1504. if (scale != 1.f) {
  1505. acoef = scale * acoef;
  1506. acoefa = abs(acoef);
  1507. bcoefr = scale * bcoefr;
  1508. bcoefi = scale * bcoefi;
  1509. bcoefa = abs(bcoefr) + abs(bcoefi);
  1510. }
  1511. /* Compute first two components of eigenvector */
  1512. /* and contribution to sums */
  1513. temp = acoef * s[je + (je - 1) * s_dim1];
  1514. temp2r = acoef * s[je + je * s_dim1] - bcoefr * p[je + je *
  1515. p_dim1];
  1516. temp2i = -bcoefi * p[je + je * p_dim1];
  1517. if (abs(temp) >= abs(temp2r) + abs(temp2i)) {
  1518. work[(*n << 1) + je] = 1.f;
  1519. work[*n * 3 + je] = 0.f;
  1520. work[(*n << 1) + je - 1] = -temp2r / temp;
  1521. work[*n * 3 + je - 1] = -temp2i / temp;
  1522. } else {
  1523. work[(*n << 1) + je - 1] = 1.f;
  1524. work[*n * 3 + je - 1] = 0.f;
  1525. temp = acoef * s[je - 1 + je * s_dim1];
  1526. work[(*n << 1) + je] = (bcoefr * p[je - 1 + (je - 1) *
  1527. p_dim1] - acoef * s[je - 1 + (je - 1) * s_dim1]) /
  1528. temp;
  1529. work[*n * 3 + je] = bcoefi * p[je - 1 + (je - 1) * p_dim1]
  1530. / temp;
  1531. }
  1532. /* Computing MAX */
  1533. r__5 = (r__1 = work[(*n << 1) + je], abs(r__1)) + (r__2 =
  1534. work[*n * 3 + je], abs(r__2)), r__6 = (r__3 = work[(*
  1535. n << 1) + je - 1], abs(r__3)) + (r__4 = work[*n * 3 +
  1536. je - 1], abs(r__4));
  1537. xmax = f2cmax(r__5,r__6);
  1538. /* Compute contribution from columns JE and JE-1 */
  1539. /* of A and B to the sums. */
  1540. creala = acoef * work[(*n << 1) + je - 1];
  1541. cimaga = acoef * work[*n * 3 + je - 1];
  1542. crealb = bcoefr * work[(*n << 1) + je - 1] - bcoefi * work[*n
  1543. * 3 + je - 1];
  1544. cimagb = bcoefi * work[(*n << 1) + je - 1] + bcoefr * work[*n
  1545. * 3 + je - 1];
  1546. cre2a = acoef * work[(*n << 1) + je];
  1547. cim2a = acoef * work[*n * 3 + je];
  1548. cre2b = bcoefr * work[(*n << 1) + je] - bcoefi * work[*n * 3
  1549. + je];
  1550. cim2b = bcoefi * work[(*n << 1) + je] + bcoefr * work[*n * 3
  1551. + je];
  1552. i__1 = je - 2;
  1553. for (jr = 1; jr <= i__1; ++jr) {
  1554. work[(*n << 1) + jr] = -creala * s[jr + (je - 1) * s_dim1]
  1555. + crealb * p[jr + (je - 1) * p_dim1] - cre2a * s[
  1556. jr + je * s_dim1] + cre2b * p[jr + je * p_dim1];
  1557. work[*n * 3 + jr] = -cimaga * s[jr + (je - 1) * s_dim1] +
  1558. cimagb * p[jr + (je - 1) * p_dim1] - cim2a * s[jr
  1559. + je * s_dim1] + cim2b * p[jr + je * p_dim1];
  1560. /* L270: */
  1561. }
  1562. }
  1563. /* Computing MAX */
  1564. r__1 = ulp * acoefa * anorm, r__2 = ulp * bcoefa * bnorm, r__1 =
  1565. f2cmax(r__1,r__2);
  1566. dmin__ = f2cmax(r__1,safmin);
  1567. /* Columnwise triangular solve of (a A - b B) x = 0 */
  1568. il2by2 = FALSE_;
  1569. for (j = je - nw; j >= 1; --j) {
  1570. /* If a 2-by-2 block, is in position j-1:j, wait until */
  1571. /* next iteration to process it (when it will be j:j+1) */
  1572. if (! il2by2 && j > 1) {
  1573. if (s[j + (j - 1) * s_dim1] != 0.f) {
  1574. il2by2 = TRUE_;
  1575. goto L370;
  1576. }
  1577. }
  1578. bdiag[0] = p[j + j * p_dim1];
  1579. if (il2by2) {
  1580. na = 2;
  1581. bdiag[1] = p[j + 1 + (j + 1) * p_dim1];
  1582. } else {
  1583. na = 1;
  1584. }
  1585. /* Compute x(j) (and x(j+1), if 2-by-2 block) */
  1586. slaln2_(&c_false, &na, &nw, &dmin__, &acoef, &s[j + j *
  1587. s_dim1], lds, bdiag, &bdiag[1], &work[(*n << 1) + j],
  1588. n, &bcoefr, &bcoefi, sum, &c__2, &scale, &temp, &
  1589. iinfo);
  1590. if (scale < 1.f) {
  1591. i__1 = nw - 1;
  1592. for (jw = 0; jw <= i__1; ++jw) {
  1593. i__2 = je;
  1594. for (jr = 1; jr <= i__2; ++jr) {
  1595. work[(jw + 2) * *n + jr] = scale * work[(jw + 2) *
  1596. *n + jr];
  1597. /* L280: */
  1598. }
  1599. /* L290: */
  1600. }
  1601. }
  1602. /* Computing MAX */
  1603. r__1 = scale * xmax;
  1604. xmax = f2cmax(r__1,temp);
  1605. i__1 = nw;
  1606. for (jw = 1; jw <= i__1; ++jw) {
  1607. i__2 = na;
  1608. for (ja = 1; ja <= i__2; ++ja) {
  1609. work[(jw + 1) * *n + j + ja - 1] = sum[ja + (jw << 1)
  1610. - 3];
  1611. /* L300: */
  1612. }
  1613. /* L310: */
  1614. }
  1615. /* w = w + x(j)*(a S(*,j) - b P(*,j) ) with scaling */
  1616. if (j > 1) {
  1617. /* Check whether scaling is necessary for sum. */
  1618. xscale = 1.f / f2cmax(1.f,xmax);
  1619. temp = acoefa * work[j] + bcoefa * work[*n + j];
  1620. if (il2by2) {
  1621. /* Computing MAX */
  1622. r__1 = temp, r__2 = acoefa * work[j + 1] + bcoefa *
  1623. work[*n + j + 1];
  1624. temp = f2cmax(r__1,r__2);
  1625. }
  1626. /* Computing MAX */
  1627. r__1 = f2cmax(temp,acoefa);
  1628. temp = f2cmax(r__1,bcoefa);
  1629. if (temp > bignum * xscale) {
  1630. i__1 = nw - 1;
  1631. for (jw = 0; jw <= i__1; ++jw) {
  1632. i__2 = je;
  1633. for (jr = 1; jr <= i__2; ++jr) {
  1634. work[(jw + 2) * *n + jr] = xscale * work[(jw
  1635. + 2) * *n + jr];
  1636. /* L320: */
  1637. }
  1638. /* L330: */
  1639. }
  1640. xmax *= xscale;
  1641. }
  1642. /* Compute the contributions of the off-diagonals of */
  1643. /* column j (and j+1, if 2-by-2 block) of A and B to the */
  1644. /* sums. */
  1645. i__1 = na;
  1646. for (ja = 1; ja <= i__1; ++ja) {
  1647. if (ilcplx) {
  1648. creala = acoef * work[(*n << 1) + j + ja - 1];
  1649. cimaga = acoef * work[*n * 3 + j + ja - 1];
  1650. crealb = bcoefr * work[(*n << 1) + j + ja - 1] -
  1651. bcoefi * work[*n * 3 + j + ja - 1];
  1652. cimagb = bcoefi * work[(*n << 1) + j + ja - 1] +
  1653. bcoefr * work[*n * 3 + j + ja - 1];
  1654. i__2 = j - 1;
  1655. for (jr = 1; jr <= i__2; ++jr) {
  1656. work[(*n << 1) + jr] = work[(*n << 1) + jr] -
  1657. creala * s[jr + (j + ja - 1) * s_dim1]
  1658. + crealb * p[jr + (j + ja - 1) *
  1659. p_dim1];
  1660. work[*n * 3 + jr] = work[*n * 3 + jr] -
  1661. cimaga * s[jr + (j + ja - 1) * s_dim1]
  1662. + cimagb * p[jr + (j + ja - 1) *
  1663. p_dim1];
  1664. /* L340: */
  1665. }
  1666. } else {
  1667. creala = acoef * work[(*n << 1) + j + ja - 1];
  1668. crealb = bcoefr * work[(*n << 1) + j + ja - 1];
  1669. i__2 = j - 1;
  1670. for (jr = 1; jr <= i__2; ++jr) {
  1671. work[(*n << 1) + jr] = work[(*n << 1) + jr] -
  1672. creala * s[jr + (j + ja - 1) * s_dim1]
  1673. + crealb * p[jr + (j + ja - 1) *
  1674. p_dim1];
  1675. /* L350: */
  1676. }
  1677. }
  1678. /* L360: */
  1679. }
  1680. }
  1681. il2by2 = FALSE_;
  1682. L370:
  1683. ;
  1684. }
  1685. /* Copy eigenvector to VR, back transforming if */
  1686. /* HOWMNY='B'. */
  1687. ieig -= nw;
  1688. if (ilback) {
  1689. i__1 = nw - 1;
  1690. for (jw = 0; jw <= i__1; ++jw) {
  1691. i__2 = *n;
  1692. for (jr = 1; jr <= i__2; ++jr) {
  1693. work[(jw + 4) * *n + jr] = work[(jw + 2) * *n + 1] *
  1694. vr[jr + vr_dim1];
  1695. /* L380: */
  1696. }
  1697. /* A series of compiler directives to defeat */
  1698. /* vectorization for the next loop */
  1699. i__2 = je;
  1700. for (jc = 2; jc <= i__2; ++jc) {
  1701. i__3 = *n;
  1702. for (jr = 1; jr <= i__3; ++jr) {
  1703. work[(jw + 4) * *n + jr] += work[(jw + 2) * *n +
  1704. jc] * vr[jr + jc * vr_dim1];
  1705. /* L390: */
  1706. }
  1707. /* L400: */
  1708. }
  1709. /* L410: */
  1710. }
  1711. i__1 = nw - 1;
  1712. for (jw = 0; jw <= i__1; ++jw) {
  1713. i__2 = *n;
  1714. for (jr = 1; jr <= i__2; ++jr) {
  1715. vr[jr + (ieig + jw) * vr_dim1] = work[(jw + 4) * *n +
  1716. jr];
  1717. /* L420: */
  1718. }
  1719. /* L430: */
  1720. }
  1721. iend = *n;
  1722. } else {
  1723. i__1 = nw - 1;
  1724. for (jw = 0; jw <= i__1; ++jw) {
  1725. i__2 = *n;
  1726. for (jr = 1; jr <= i__2; ++jr) {
  1727. vr[jr + (ieig + jw) * vr_dim1] = work[(jw + 2) * *n +
  1728. jr];
  1729. /* L440: */
  1730. }
  1731. /* L450: */
  1732. }
  1733. iend = je;
  1734. }
  1735. /* Scale eigenvector */
  1736. xmax = 0.f;
  1737. if (ilcplx) {
  1738. i__1 = iend;
  1739. for (j = 1; j <= i__1; ++j) {
  1740. /* Computing MAX */
  1741. r__3 = xmax, r__4 = (r__1 = vr[j + ieig * vr_dim1], abs(
  1742. r__1)) + (r__2 = vr[j + (ieig + 1) * vr_dim1],
  1743. abs(r__2));
  1744. xmax = f2cmax(r__3,r__4);
  1745. /* L460: */
  1746. }
  1747. } else {
  1748. i__1 = iend;
  1749. for (j = 1; j <= i__1; ++j) {
  1750. /* Computing MAX */
  1751. r__2 = xmax, r__3 = (r__1 = vr[j + ieig * vr_dim1], abs(
  1752. r__1));
  1753. xmax = f2cmax(r__2,r__3);
  1754. /* L470: */
  1755. }
  1756. }
  1757. if (xmax > safmin) {
  1758. xscale = 1.f / xmax;
  1759. i__1 = nw - 1;
  1760. for (jw = 0; jw <= i__1; ++jw) {
  1761. i__2 = iend;
  1762. for (jr = 1; jr <= i__2; ++jr) {
  1763. vr[jr + (ieig + jw) * vr_dim1] = xscale * vr[jr + (
  1764. ieig + jw) * vr_dim1];
  1765. /* L480: */
  1766. }
  1767. /* L490: */
  1768. }
  1769. }
  1770. L500:
  1771. ;
  1772. }
  1773. }
  1774. return;
  1775. /* End of STGEVC */
  1776. } /* stgevc_ */