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.

dtrevc.c 49 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803
  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_false = FALSE_;
  485. static integer c__1 = 1;
  486. static doublereal c_b22 = 1.;
  487. static doublereal c_b25 = 0.;
  488. static integer c__2 = 2;
  489. static logical c_true = TRUE_;
  490. /* > \brief \b DTREVC */
  491. /* =========== DOCUMENTATION =========== */
  492. /* Online html documentation available at */
  493. /* http://www.netlib.org/lapack/explore-html/ */
  494. /* > \htmlonly */
  495. /* > Download DTREVC + dependencies */
  496. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/dtrevc.
  497. f"> */
  498. /* > [TGZ]</a> */
  499. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/dtrevc.
  500. f"> */
  501. /* > [ZIP]</a> */
  502. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/dtrevc.
  503. f"> */
  504. /* > [TXT]</a> */
  505. /* > \endhtmlonly */
  506. /* Definition: */
  507. /* =========== */
  508. /* SUBROUTINE DTREVC( SIDE, HOWMNY, SELECT, N, T, LDT, VL, LDVL, VR, */
  509. /* LDVR, MM, M, WORK, INFO ) */
  510. /* CHARACTER HOWMNY, SIDE */
  511. /* INTEGER INFO, LDT, LDVL, LDVR, M, MM, N */
  512. /* LOGICAL SELECT( * ) */
  513. /* DOUBLE PRECISION T( LDT, * ), VL( LDVL, * ), VR( LDVR, * ), */
  514. /* $ WORK( * ) */
  515. /* > \par Purpose: */
  516. /* ============= */
  517. /* > */
  518. /* > \verbatim */
  519. /* > */
  520. /* > DTREVC computes some or all of the right and/or left eigenvectors of */
  521. /* > a real upper quasi-triangular matrix T. */
  522. /* > Matrices of this type are produced by the Schur factorization of */
  523. /* > a real general matrix: A = Q*T*Q**T, as computed by DHSEQR. */
  524. /* > */
  525. /* > The right eigenvector x and the left eigenvector y of T corresponding */
  526. /* > to an eigenvalue w are defined by: */
  527. /* > */
  528. /* > T*x = w*x, (y**H)*T = w*(y**H) */
  529. /* > */
  530. /* > where y**H denotes the conjugate transpose of y. */
  531. /* > The eigenvalues are not input to this routine, but are read directly */
  532. /* > from the diagonal blocks of T. */
  533. /* > */
  534. /* > This routine returns the matrices X and/or Y of right and left */
  535. /* > eigenvectors of T, or the products Q*X and/or Q*Y, where Q is an */
  536. /* > input matrix. If Q is the orthogonal factor that reduces a matrix */
  537. /* > A to Schur form T, then Q*X and Q*Y are the matrices of right and */
  538. /* > left eigenvectors of A. */
  539. /* > \endverbatim */
  540. /* Arguments: */
  541. /* ========== */
  542. /* > \param[in] SIDE */
  543. /* > \verbatim */
  544. /* > SIDE is CHARACTER*1 */
  545. /* > = 'R': compute right eigenvectors only; */
  546. /* > = 'L': compute left eigenvectors only; */
  547. /* > = 'B': compute both right and left eigenvectors. */
  548. /* > \endverbatim */
  549. /* > */
  550. /* > \param[in] HOWMNY */
  551. /* > \verbatim */
  552. /* > HOWMNY is CHARACTER*1 */
  553. /* > = 'A': compute all right and/or left eigenvectors; */
  554. /* > = 'B': compute all right and/or left eigenvectors, */
  555. /* > backtransformed by the matrices in VR and/or VL; */
  556. /* > = 'S': compute selected right and/or left eigenvectors, */
  557. /* > as indicated by the logical array SELECT. */
  558. /* > \endverbatim */
  559. /* > */
  560. /* > \param[in,out] SELECT */
  561. /* > \verbatim */
  562. /* > SELECT is LOGICAL array, dimension (N) */
  563. /* > If HOWMNY = 'S', SELECT specifies the eigenvectors to be */
  564. /* > computed. */
  565. /* > If w(j) is a real eigenvalue, the corresponding real */
  566. /* > eigenvector is computed if SELECT(j) is .TRUE.. */
  567. /* > If w(j) and w(j+1) are the real and imaginary parts of a */
  568. /* > complex eigenvalue, the corresponding complex eigenvector is */
  569. /* > computed if either SELECT(j) or SELECT(j+1) is .TRUE., and */
  570. /* > on exit SELECT(j) is set to .TRUE. and SELECT(j+1) is set to */
  571. /* > .FALSE.. */
  572. /* > Not referenced if HOWMNY = 'A' or 'B'. */
  573. /* > \endverbatim */
  574. /* > */
  575. /* > \param[in] N */
  576. /* > \verbatim */
  577. /* > N is INTEGER */
  578. /* > The order of the matrix T. N >= 0. */
  579. /* > \endverbatim */
  580. /* > */
  581. /* > \param[in] T */
  582. /* > \verbatim */
  583. /* > T is DOUBLE PRECISION array, dimension (LDT,N) */
  584. /* > The upper quasi-triangular matrix T in Schur canonical form. */
  585. /* > \endverbatim */
  586. /* > */
  587. /* > \param[in] LDT */
  588. /* > \verbatim */
  589. /* > LDT is INTEGER */
  590. /* > The leading dimension of the array T. LDT >= f2cmax(1,N). */
  591. /* > \endverbatim */
  592. /* > */
  593. /* > \param[in,out] VL */
  594. /* > \verbatim */
  595. /* > VL is DOUBLE PRECISION array, dimension (LDVL,MM) */
  596. /* > On entry, if SIDE = 'L' or 'B' and HOWMNY = 'B', VL must */
  597. /* > contain an N-by-N matrix Q (usually the orthogonal matrix Q */
  598. /* > of Schur vectors returned by DHSEQR). */
  599. /* > On exit, if SIDE = 'L' or 'B', VL contains: */
  600. /* > if HOWMNY = 'A', the matrix Y of left eigenvectors of T; */
  601. /* > if HOWMNY = 'B', the matrix Q*Y; */
  602. /* > if HOWMNY = 'S', the left eigenvectors of T specified by */
  603. /* > SELECT, stored consecutively in the columns */
  604. /* > of VL, in the same order as their */
  605. /* > eigenvalues. */
  606. /* > A complex eigenvector corresponding to a complex eigenvalue */
  607. /* > is stored in two consecutive columns, the first holding the */
  608. /* > real part, and the second the imaginary part. */
  609. /* > Not referenced if SIDE = 'R'. */
  610. /* > \endverbatim */
  611. /* > */
  612. /* > \param[in] LDVL */
  613. /* > \verbatim */
  614. /* > LDVL is INTEGER */
  615. /* > The leading dimension of the array VL. LDVL >= 1, and if */
  616. /* > SIDE = 'L' or 'B', LDVL >= N. */
  617. /* > \endverbatim */
  618. /* > */
  619. /* > \param[in,out] VR */
  620. /* > \verbatim */
  621. /* > VR is DOUBLE PRECISION array, dimension (LDVR,MM) */
  622. /* > On entry, if SIDE = 'R' or 'B' and HOWMNY = 'B', VR must */
  623. /* > contain an N-by-N matrix Q (usually the orthogonal matrix Q */
  624. /* > of Schur vectors returned by DHSEQR). */
  625. /* > On exit, if SIDE = 'R' or 'B', VR contains: */
  626. /* > if HOWMNY = 'A', the matrix X of right eigenvectors of T; */
  627. /* > if HOWMNY = 'B', the matrix Q*X; */
  628. /* > if HOWMNY = 'S', the right eigenvectors of T specified by */
  629. /* > SELECT, stored consecutively in the columns */
  630. /* > of VR, in the same order as their */
  631. /* > eigenvalues. */
  632. /* > A complex eigenvector corresponding to a complex eigenvalue */
  633. /* > is stored in two consecutive columns, the first holding the */
  634. /* > real part and the second the imaginary part. */
  635. /* > Not referenced if SIDE = 'L'. */
  636. /* > \endverbatim */
  637. /* > */
  638. /* > \param[in] LDVR */
  639. /* > \verbatim */
  640. /* > LDVR is INTEGER */
  641. /* > The leading dimension of the array VR. LDVR >= 1, and if */
  642. /* > SIDE = 'R' or 'B', LDVR >= N. */
  643. /* > \endverbatim */
  644. /* > */
  645. /* > \param[in] MM */
  646. /* > \verbatim */
  647. /* > MM is INTEGER */
  648. /* > The number of columns in the arrays VL and/or VR. MM >= M. */
  649. /* > \endverbatim */
  650. /* > */
  651. /* > \param[out] M */
  652. /* > \verbatim */
  653. /* > M is INTEGER */
  654. /* > The number of columns in the arrays VL and/or VR actually */
  655. /* > used to store the eigenvectors. */
  656. /* > If HOWMNY = 'A' or 'B', M is set to N. */
  657. /* > Each selected real eigenvector occupies one column and each */
  658. /* > selected complex eigenvector occupies two columns. */
  659. /* > \endverbatim */
  660. /* > */
  661. /* > \param[out] WORK */
  662. /* > \verbatim */
  663. /* > WORK is DOUBLE PRECISION array, dimension (3*N) */
  664. /* > \endverbatim */
  665. /* > */
  666. /* > \param[out] INFO */
  667. /* > \verbatim */
  668. /* > INFO is INTEGER */
  669. /* > = 0: successful exit */
  670. /* > < 0: if INFO = -i, the i-th argument had an illegal value */
  671. /* > \endverbatim */
  672. /* Authors: */
  673. /* ======== */
  674. /* > \author Univ. of Tennessee */
  675. /* > \author Univ. of California Berkeley */
  676. /* > \author Univ. of Colorado Denver */
  677. /* > \author NAG Ltd. */
  678. /* > \date November 2017 */
  679. /* > \ingroup doubleOTHERcomputational */
  680. /* > \par Further Details: */
  681. /* ===================== */
  682. /* > */
  683. /* > \verbatim */
  684. /* > */
  685. /* > The algorithm used in this program is basically backward (forward) */
  686. /* > substitution, with scaling to make the the code robust against */
  687. /* > possible overflow. */
  688. /* > */
  689. /* > Each eigenvector is normalized so that the element of largest */
  690. /* > magnitude has magnitude 1; here the magnitude of a complex number */
  691. /* > (x,y) is taken to be |x| + |y|. */
  692. /* > \endverbatim */
  693. /* > */
  694. /* ===================================================================== */
  695. /* Subroutine */ void dtrevc_(char *side, char *howmny, logical *select,
  696. integer *n, doublereal *t, integer *ldt, doublereal *vl, integer *
  697. ldvl, doublereal *vr, integer *ldvr, integer *mm, integer *m,
  698. doublereal *work, integer *info)
  699. {
  700. /* System generated locals */
  701. integer t_dim1, t_offset, vl_dim1, vl_offset, vr_dim1, vr_offset, i__1,
  702. i__2, i__3;
  703. doublereal d__1, d__2, d__3, d__4;
  704. /* Local variables */
  705. doublereal beta, emax;
  706. logical pair;
  707. extern doublereal ddot_(integer *, doublereal *, integer *, doublereal *,
  708. integer *);
  709. logical allv;
  710. integer ierr;
  711. doublereal unfl, ovfl, smin;
  712. logical over;
  713. doublereal vmax;
  714. integer jnxt, i__, j, k;
  715. extern /* Subroutine */ void dscal_(integer *, doublereal *, doublereal *,
  716. integer *);
  717. doublereal scale, x[4] /* was [2][2] */;
  718. extern logical lsame_(char *, char *);
  719. extern /* Subroutine */ void dgemv_(char *, integer *, integer *,
  720. doublereal *, doublereal *, integer *, doublereal *, integer *,
  721. doublereal *, doublereal *, integer *);
  722. doublereal remax;
  723. extern /* Subroutine */ void dcopy_(integer *, doublereal *, integer *,
  724. doublereal *, integer *);
  725. logical leftv, bothv;
  726. extern /* Subroutine */ void daxpy_(integer *, doublereal *, doublereal *,
  727. integer *, doublereal *, integer *);
  728. doublereal vcrit;
  729. logical somev;
  730. integer j1, j2, n2;
  731. doublereal xnorm;
  732. extern /* Subroutine */ void dlaln2_(logical *, integer *, integer *,
  733. doublereal *, doublereal *, doublereal *, integer *, doublereal *,
  734. doublereal *, doublereal *, integer *, doublereal *, doublereal *
  735. , doublereal *, integer *, doublereal *, doublereal *, integer *),
  736. dlabad_(doublereal *, doublereal *);
  737. integer ii, ki;
  738. extern doublereal dlamch_(char *);
  739. integer ip, is;
  740. doublereal wi;
  741. extern integer idamax_(integer *, doublereal *, integer *);
  742. doublereal wr;
  743. extern /* Subroutine */ int xerbla_(char *, integer *, ftnlen);
  744. doublereal bignum;
  745. logical rightv;
  746. doublereal smlnum, rec, ulp;
  747. /* -- LAPACK computational routine (version 3.8.0) -- */
  748. /* -- LAPACK is a software package provided by Univ. of Tennessee, -- */
  749. /* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- */
  750. /* November 2017 */
  751. /* ===================================================================== */
  752. /* Decode and test the input parameters */
  753. /* Parameter adjustments */
  754. --select;
  755. t_dim1 = *ldt;
  756. t_offset = 1 + t_dim1 * 1;
  757. t -= t_offset;
  758. vl_dim1 = *ldvl;
  759. vl_offset = 1 + vl_dim1 * 1;
  760. vl -= vl_offset;
  761. vr_dim1 = *ldvr;
  762. vr_offset = 1 + vr_dim1 * 1;
  763. vr -= vr_offset;
  764. --work;
  765. /* Function Body */
  766. bothv = lsame_(side, "B");
  767. rightv = lsame_(side, "R") || bothv;
  768. leftv = lsame_(side, "L") || bothv;
  769. allv = lsame_(howmny, "A");
  770. over = lsame_(howmny, "B");
  771. somev = lsame_(howmny, "S");
  772. *info = 0;
  773. if (! rightv && ! leftv) {
  774. *info = -1;
  775. } else if (! allv && ! over && ! somev) {
  776. *info = -2;
  777. } else if (*n < 0) {
  778. *info = -4;
  779. } else if (*ldt < f2cmax(1,*n)) {
  780. *info = -6;
  781. } else if (*ldvl < 1 || leftv && *ldvl < *n) {
  782. *info = -8;
  783. } else if (*ldvr < 1 || rightv && *ldvr < *n) {
  784. *info = -10;
  785. } else {
  786. /* Set M to the number of columns required to store the selected */
  787. /* eigenvectors, standardize the array SELECT if necessary, and */
  788. /* test MM. */
  789. if (somev) {
  790. *m = 0;
  791. pair = FALSE_;
  792. i__1 = *n;
  793. for (j = 1; j <= i__1; ++j) {
  794. if (pair) {
  795. pair = FALSE_;
  796. select[j] = FALSE_;
  797. } else {
  798. if (j < *n) {
  799. if (t[j + 1 + j * t_dim1] == 0.) {
  800. if (select[j]) {
  801. ++(*m);
  802. }
  803. } else {
  804. pair = TRUE_;
  805. if (select[j] || select[j + 1]) {
  806. select[j] = TRUE_;
  807. *m += 2;
  808. }
  809. }
  810. } else {
  811. if (select[*n]) {
  812. ++(*m);
  813. }
  814. }
  815. }
  816. /* L10: */
  817. }
  818. } else {
  819. *m = *n;
  820. }
  821. if (*mm < *m) {
  822. *info = -11;
  823. }
  824. }
  825. if (*info != 0) {
  826. i__1 = -(*info);
  827. xerbla_("DTREVC", &i__1, (ftnlen)6);
  828. return;
  829. }
  830. /* Quick return if possible. */
  831. if (*n == 0) {
  832. return;
  833. }
  834. /* Set the constants to control overflow. */
  835. unfl = dlamch_("Safe minimum");
  836. ovfl = 1. / unfl;
  837. dlabad_(&unfl, &ovfl);
  838. ulp = dlamch_("Precision");
  839. smlnum = unfl * (*n / ulp);
  840. bignum = (1. - ulp) / smlnum;
  841. /* Compute 1-norm of each column of strictly upper triangular */
  842. /* part of T to control overflow in triangular solver. */
  843. work[1] = 0.;
  844. i__1 = *n;
  845. for (j = 2; j <= i__1; ++j) {
  846. work[j] = 0.;
  847. i__2 = j - 1;
  848. for (i__ = 1; i__ <= i__2; ++i__) {
  849. work[j] += (d__1 = t[i__ + j * t_dim1], abs(d__1));
  850. /* L20: */
  851. }
  852. /* L30: */
  853. }
  854. /* Index IP is used to specify the real or complex eigenvalue: */
  855. /* IP = 0, real eigenvalue, */
  856. /* 1, first of conjugate complex pair: (wr,wi) */
  857. /* -1, second of conjugate complex pair: (wr,wi) */
  858. n2 = *n << 1;
  859. if (rightv) {
  860. /* Compute right eigenvectors. */
  861. ip = 0;
  862. is = *m;
  863. for (ki = *n; ki >= 1; --ki) {
  864. if (ip == 1) {
  865. goto L130;
  866. }
  867. if (ki == 1) {
  868. goto L40;
  869. }
  870. if (t[ki + (ki - 1) * t_dim1] == 0.) {
  871. goto L40;
  872. }
  873. ip = -1;
  874. L40:
  875. if (somev) {
  876. if (ip == 0) {
  877. if (! select[ki]) {
  878. goto L130;
  879. }
  880. } else {
  881. if (! select[ki - 1]) {
  882. goto L130;
  883. }
  884. }
  885. }
  886. /* Compute the KI-th eigenvalue (WR,WI). */
  887. wr = t[ki + ki * t_dim1];
  888. wi = 0.;
  889. if (ip != 0) {
  890. wi = sqrt((d__1 = t[ki + (ki - 1) * t_dim1], abs(d__1))) *
  891. sqrt((d__2 = t[ki - 1 + ki * t_dim1], abs(d__2)));
  892. }
  893. /* Computing MAX */
  894. d__1 = ulp * (abs(wr) + abs(wi));
  895. smin = f2cmax(d__1,smlnum);
  896. if (ip == 0) {
  897. /* Real right eigenvector */
  898. work[ki + *n] = 1.;
  899. /* Form right-hand side */
  900. i__1 = ki - 1;
  901. for (k = 1; k <= i__1; ++k) {
  902. work[k + *n] = -t[k + ki * t_dim1];
  903. /* L50: */
  904. }
  905. /* Solve the upper quasi-triangular system: */
  906. /* (T(1:KI-1,1:KI-1) - WR)*X = SCALE*WORK. */
  907. jnxt = ki - 1;
  908. for (j = ki - 1; j >= 1; --j) {
  909. if (j > jnxt) {
  910. goto L60;
  911. }
  912. j1 = j;
  913. j2 = j;
  914. jnxt = j - 1;
  915. if (j > 1) {
  916. if (t[j + (j - 1) * t_dim1] != 0.) {
  917. j1 = j - 1;
  918. jnxt = j - 2;
  919. }
  920. }
  921. if (j1 == j2) {
  922. /* 1-by-1 diagonal block */
  923. dlaln2_(&c_false, &c__1, &c__1, &smin, &c_b22, &t[j +
  924. j * t_dim1], ldt, &c_b22, &c_b22, &work[j + *
  925. n], n, &wr, &c_b25, x, &c__2, &scale, &xnorm,
  926. &ierr);
  927. /* Scale X(1,1) to avoid overflow when updating */
  928. /* the right-hand side. */
  929. if (xnorm > 1.) {
  930. if (work[j] > bignum / xnorm) {
  931. x[0] /= xnorm;
  932. scale /= xnorm;
  933. }
  934. }
  935. /* Scale if necessary */
  936. if (scale != 1.) {
  937. dscal_(&ki, &scale, &work[*n + 1], &c__1);
  938. }
  939. work[j + *n] = x[0];
  940. /* Update right-hand side */
  941. i__1 = j - 1;
  942. d__1 = -x[0];
  943. daxpy_(&i__1, &d__1, &t[j * t_dim1 + 1], &c__1, &work[
  944. *n + 1], &c__1);
  945. } else {
  946. /* 2-by-2 diagonal block */
  947. dlaln2_(&c_false, &c__2, &c__1, &smin, &c_b22, &t[j -
  948. 1 + (j - 1) * t_dim1], ldt, &c_b22, &c_b22, &
  949. work[j - 1 + *n], n, &wr, &c_b25, x, &c__2, &
  950. scale, &xnorm, &ierr);
  951. /* Scale X(1,1) and X(2,1) to avoid overflow when */
  952. /* updating the right-hand side. */
  953. if (xnorm > 1.) {
  954. /* Computing MAX */
  955. d__1 = work[j - 1], d__2 = work[j];
  956. beta = f2cmax(d__1,d__2);
  957. if (beta > bignum / xnorm) {
  958. x[0] /= xnorm;
  959. x[1] /= xnorm;
  960. scale /= xnorm;
  961. }
  962. }
  963. /* Scale if necessary */
  964. if (scale != 1.) {
  965. dscal_(&ki, &scale, &work[*n + 1], &c__1);
  966. }
  967. work[j - 1 + *n] = x[0];
  968. work[j + *n] = x[1];
  969. /* Update right-hand side */
  970. i__1 = j - 2;
  971. d__1 = -x[0];
  972. daxpy_(&i__1, &d__1, &t[(j - 1) * t_dim1 + 1], &c__1,
  973. &work[*n + 1], &c__1);
  974. i__1 = j - 2;
  975. d__1 = -x[1];
  976. daxpy_(&i__1, &d__1, &t[j * t_dim1 + 1], &c__1, &work[
  977. *n + 1], &c__1);
  978. }
  979. L60:
  980. ;
  981. }
  982. /* Copy the vector x or Q*x to VR and normalize. */
  983. if (! over) {
  984. dcopy_(&ki, &work[*n + 1], &c__1, &vr[is * vr_dim1 + 1], &
  985. c__1);
  986. ii = idamax_(&ki, &vr[is * vr_dim1 + 1], &c__1);
  987. remax = 1. / (d__1 = vr[ii + is * vr_dim1], abs(d__1));
  988. dscal_(&ki, &remax, &vr[is * vr_dim1 + 1], &c__1);
  989. i__1 = *n;
  990. for (k = ki + 1; k <= i__1; ++k) {
  991. vr[k + is * vr_dim1] = 0.;
  992. /* L70: */
  993. }
  994. } else {
  995. if (ki > 1) {
  996. i__1 = ki - 1;
  997. dgemv_("N", n, &i__1, &c_b22, &vr[vr_offset], ldvr, &
  998. work[*n + 1], &c__1, &work[ki + *n], &vr[ki *
  999. vr_dim1 + 1], &c__1);
  1000. }
  1001. ii = idamax_(n, &vr[ki * vr_dim1 + 1], &c__1);
  1002. remax = 1. / (d__1 = vr[ii + ki * vr_dim1], abs(d__1));
  1003. dscal_(n, &remax, &vr[ki * vr_dim1 + 1], &c__1);
  1004. }
  1005. } else {
  1006. /* Complex right eigenvector. */
  1007. /* Initial solve */
  1008. /* [ (T(KI-1,KI-1) T(KI-1,KI) ) - (WR + I* WI)]*X = 0. */
  1009. /* [ (T(KI,KI-1) T(KI,KI) ) ] */
  1010. if ((d__1 = t[ki - 1 + ki * t_dim1], abs(d__1)) >= (d__2 = t[
  1011. ki + (ki - 1) * t_dim1], abs(d__2))) {
  1012. work[ki - 1 + *n] = 1.;
  1013. work[ki + n2] = wi / t[ki - 1 + ki * t_dim1];
  1014. } else {
  1015. work[ki - 1 + *n] = -wi / t[ki + (ki - 1) * t_dim1];
  1016. work[ki + n2] = 1.;
  1017. }
  1018. work[ki + *n] = 0.;
  1019. work[ki - 1 + n2] = 0.;
  1020. /* Form right-hand side */
  1021. i__1 = ki - 2;
  1022. for (k = 1; k <= i__1; ++k) {
  1023. work[k + *n] = -work[ki - 1 + *n] * t[k + (ki - 1) *
  1024. t_dim1];
  1025. work[k + n2] = -work[ki + n2] * t[k + ki * t_dim1];
  1026. /* L80: */
  1027. }
  1028. /* Solve upper quasi-triangular system: */
  1029. /* (T(1:KI-2,1:KI-2) - (WR+i*WI))*X = SCALE*(WORK+i*WORK2) */
  1030. jnxt = ki - 2;
  1031. for (j = ki - 2; j >= 1; --j) {
  1032. if (j > jnxt) {
  1033. goto L90;
  1034. }
  1035. j1 = j;
  1036. j2 = j;
  1037. jnxt = j - 1;
  1038. if (j > 1) {
  1039. if (t[j + (j - 1) * t_dim1] != 0.) {
  1040. j1 = j - 1;
  1041. jnxt = j - 2;
  1042. }
  1043. }
  1044. if (j1 == j2) {
  1045. /* 1-by-1 diagonal block */
  1046. dlaln2_(&c_false, &c__1, &c__2, &smin, &c_b22, &t[j +
  1047. j * t_dim1], ldt, &c_b22, &c_b22, &work[j + *
  1048. n], n, &wr, &wi, x, &c__2, &scale, &xnorm, &
  1049. ierr);
  1050. /* Scale X(1,1) and X(1,2) to avoid overflow when */
  1051. /* updating the right-hand side. */
  1052. if (xnorm > 1.) {
  1053. if (work[j] > bignum / xnorm) {
  1054. x[0] /= xnorm;
  1055. x[2] /= xnorm;
  1056. scale /= xnorm;
  1057. }
  1058. }
  1059. /* Scale if necessary */
  1060. if (scale != 1.) {
  1061. dscal_(&ki, &scale, &work[*n + 1], &c__1);
  1062. dscal_(&ki, &scale, &work[n2 + 1], &c__1);
  1063. }
  1064. work[j + *n] = x[0];
  1065. work[j + n2] = x[2];
  1066. /* Update the right-hand side */
  1067. i__1 = j - 1;
  1068. d__1 = -x[0];
  1069. daxpy_(&i__1, &d__1, &t[j * t_dim1 + 1], &c__1, &work[
  1070. *n + 1], &c__1);
  1071. i__1 = j - 1;
  1072. d__1 = -x[2];
  1073. daxpy_(&i__1, &d__1, &t[j * t_dim1 + 1], &c__1, &work[
  1074. n2 + 1], &c__1);
  1075. } else {
  1076. /* 2-by-2 diagonal block */
  1077. dlaln2_(&c_false, &c__2, &c__2, &smin, &c_b22, &t[j -
  1078. 1 + (j - 1) * t_dim1], ldt, &c_b22, &c_b22, &
  1079. work[j - 1 + *n], n, &wr, &wi, x, &c__2, &
  1080. scale, &xnorm, &ierr);
  1081. /* Scale X to avoid overflow when updating */
  1082. /* the right-hand side. */
  1083. if (xnorm > 1.) {
  1084. /* Computing MAX */
  1085. d__1 = work[j - 1], d__2 = work[j];
  1086. beta = f2cmax(d__1,d__2);
  1087. if (beta > bignum / xnorm) {
  1088. rec = 1. / xnorm;
  1089. x[0] *= rec;
  1090. x[2] *= rec;
  1091. x[1] *= rec;
  1092. x[3] *= rec;
  1093. scale *= rec;
  1094. }
  1095. }
  1096. /* Scale if necessary */
  1097. if (scale != 1.) {
  1098. dscal_(&ki, &scale, &work[*n + 1], &c__1);
  1099. dscal_(&ki, &scale, &work[n2 + 1], &c__1);
  1100. }
  1101. work[j - 1 + *n] = x[0];
  1102. work[j + *n] = x[1];
  1103. work[j - 1 + n2] = x[2];
  1104. work[j + n2] = x[3];
  1105. /* Update the right-hand side */
  1106. i__1 = j - 2;
  1107. d__1 = -x[0];
  1108. daxpy_(&i__1, &d__1, &t[(j - 1) * t_dim1 + 1], &c__1,
  1109. &work[*n + 1], &c__1);
  1110. i__1 = j - 2;
  1111. d__1 = -x[1];
  1112. daxpy_(&i__1, &d__1, &t[j * t_dim1 + 1], &c__1, &work[
  1113. *n + 1], &c__1);
  1114. i__1 = j - 2;
  1115. d__1 = -x[2];
  1116. daxpy_(&i__1, &d__1, &t[(j - 1) * t_dim1 + 1], &c__1,
  1117. &work[n2 + 1], &c__1);
  1118. i__1 = j - 2;
  1119. d__1 = -x[3];
  1120. daxpy_(&i__1, &d__1, &t[j * t_dim1 + 1], &c__1, &work[
  1121. n2 + 1], &c__1);
  1122. }
  1123. L90:
  1124. ;
  1125. }
  1126. /* Copy the vector x or Q*x to VR and normalize. */
  1127. if (! over) {
  1128. dcopy_(&ki, &work[*n + 1], &c__1, &vr[(is - 1) * vr_dim1
  1129. + 1], &c__1);
  1130. dcopy_(&ki, &work[n2 + 1], &c__1, &vr[is * vr_dim1 + 1], &
  1131. c__1);
  1132. emax = 0.;
  1133. i__1 = ki;
  1134. for (k = 1; k <= i__1; ++k) {
  1135. /* Computing MAX */
  1136. d__3 = emax, d__4 = (d__1 = vr[k + (is - 1) * vr_dim1]
  1137. , abs(d__1)) + (d__2 = vr[k + is * vr_dim1],
  1138. abs(d__2));
  1139. emax = f2cmax(d__3,d__4);
  1140. /* L100: */
  1141. }
  1142. remax = 1. / emax;
  1143. dscal_(&ki, &remax, &vr[(is - 1) * vr_dim1 + 1], &c__1);
  1144. dscal_(&ki, &remax, &vr[is * vr_dim1 + 1], &c__1);
  1145. i__1 = *n;
  1146. for (k = ki + 1; k <= i__1; ++k) {
  1147. vr[k + (is - 1) * vr_dim1] = 0.;
  1148. vr[k + is * vr_dim1] = 0.;
  1149. /* L110: */
  1150. }
  1151. } else {
  1152. if (ki > 2) {
  1153. i__1 = ki - 2;
  1154. dgemv_("N", n, &i__1, &c_b22, &vr[vr_offset], ldvr, &
  1155. work[*n + 1], &c__1, &work[ki - 1 + *n], &vr[(
  1156. ki - 1) * vr_dim1 + 1], &c__1);
  1157. i__1 = ki - 2;
  1158. dgemv_("N", n, &i__1, &c_b22, &vr[vr_offset], ldvr, &
  1159. work[n2 + 1], &c__1, &work[ki + n2], &vr[ki *
  1160. vr_dim1 + 1], &c__1);
  1161. } else {
  1162. dscal_(n, &work[ki - 1 + *n], &vr[(ki - 1) * vr_dim1
  1163. + 1], &c__1);
  1164. dscal_(n, &work[ki + n2], &vr[ki * vr_dim1 + 1], &
  1165. c__1);
  1166. }
  1167. emax = 0.;
  1168. i__1 = *n;
  1169. for (k = 1; k <= i__1; ++k) {
  1170. /* Computing MAX */
  1171. d__3 = emax, d__4 = (d__1 = vr[k + (ki - 1) * vr_dim1]
  1172. , abs(d__1)) + (d__2 = vr[k + ki * vr_dim1],
  1173. abs(d__2));
  1174. emax = f2cmax(d__3,d__4);
  1175. /* L120: */
  1176. }
  1177. remax = 1. / emax;
  1178. dscal_(n, &remax, &vr[(ki - 1) * vr_dim1 + 1], &c__1);
  1179. dscal_(n, &remax, &vr[ki * vr_dim1 + 1], &c__1);
  1180. }
  1181. }
  1182. --is;
  1183. if (ip != 0) {
  1184. --is;
  1185. }
  1186. L130:
  1187. if (ip == 1) {
  1188. ip = 0;
  1189. }
  1190. if (ip == -1) {
  1191. ip = 1;
  1192. }
  1193. /* L140: */
  1194. }
  1195. }
  1196. if (leftv) {
  1197. /* Compute left eigenvectors. */
  1198. ip = 0;
  1199. is = 1;
  1200. i__1 = *n;
  1201. for (ki = 1; ki <= i__1; ++ki) {
  1202. if (ip == -1) {
  1203. goto L250;
  1204. }
  1205. if (ki == *n) {
  1206. goto L150;
  1207. }
  1208. if (t[ki + 1 + ki * t_dim1] == 0.) {
  1209. goto L150;
  1210. }
  1211. ip = 1;
  1212. L150:
  1213. if (somev) {
  1214. if (! select[ki]) {
  1215. goto L250;
  1216. }
  1217. }
  1218. /* Compute the KI-th eigenvalue (WR,WI). */
  1219. wr = t[ki + ki * t_dim1];
  1220. wi = 0.;
  1221. if (ip != 0) {
  1222. wi = sqrt((d__1 = t[ki + (ki + 1) * t_dim1], abs(d__1))) *
  1223. sqrt((d__2 = t[ki + 1 + ki * t_dim1], abs(d__2)));
  1224. }
  1225. /* Computing MAX */
  1226. d__1 = ulp * (abs(wr) + abs(wi));
  1227. smin = f2cmax(d__1,smlnum);
  1228. if (ip == 0) {
  1229. /* Real left eigenvector. */
  1230. work[ki + *n] = 1.;
  1231. /* Form right-hand side */
  1232. i__2 = *n;
  1233. for (k = ki + 1; k <= i__2; ++k) {
  1234. work[k + *n] = -t[ki + k * t_dim1];
  1235. /* L160: */
  1236. }
  1237. /* Solve the quasi-triangular system: */
  1238. /* (T(KI+1:N,KI+1:N) - WR)**T*X = SCALE*WORK */
  1239. vmax = 1.;
  1240. vcrit = bignum;
  1241. jnxt = ki + 1;
  1242. i__2 = *n;
  1243. for (j = ki + 1; j <= i__2; ++j) {
  1244. if (j < jnxt) {
  1245. goto L170;
  1246. }
  1247. j1 = j;
  1248. j2 = j;
  1249. jnxt = j + 1;
  1250. if (j < *n) {
  1251. if (t[j + 1 + j * t_dim1] != 0.) {
  1252. j2 = j + 1;
  1253. jnxt = j + 2;
  1254. }
  1255. }
  1256. if (j1 == j2) {
  1257. /* 1-by-1 diagonal block */
  1258. /* Scale if necessary to avoid overflow when forming */
  1259. /* the right-hand side. */
  1260. if (work[j] > vcrit) {
  1261. rec = 1. / vmax;
  1262. i__3 = *n - ki + 1;
  1263. dscal_(&i__3, &rec, &work[ki + *n], &c__1);
  1264. vmax = 1.;
  1265. vcrit = bignum;
  1266. }
  1267. i__3 = j - ki - 1;
  1268. work[j + *n] -= ddot_(&i__3, &t[ki + 1 + j * t_dim1],
  1269. &c__1, &work[ki + 1 + *n], &c__1);
  1270. /* Solve (T(J,J)-WR)**T*X = WORK */
  1271. dlaln2_(&c_false, &c__1, &c__1, &smin, &c_b22, &t[j +
  1272. j * t_dim1], ldt, &c_b22, &c_b22, &work[j + *
  1273. n], n, &wr, &c_b25, x, &c__2, &scale, &xnorm,
  1274. &ierr);
  1275. /* Scale if necessary */
  1276. if (scale != 1.) {
  1277. i__3 = *n - ki + 1;
  1278. dscal_(&i__3, &scale, &work[ki + *n], &c__1);
  1279. }
  1280. work[j + *n] = x[0];
  1281. /* Computing MAX */
  1282. d__2 = (d__1 = work[j + *n], abs(d__1));
  1283. vmax = f2cmax(d__2,vmax);
  1284. vcrit = bignum / vmax;
  1285. } else {
  1286. /* 2-by-2 diagonal block */
  1287. /* Scale if necessary to avoid overflow when forming */
  1288. /* the right-hand side. */
  1289. /* Computing MAX */
  1290. d__1 = work[j], d__2 = work[j + 1];
  1291. beta = f2cmax(d__1,d__2);
  1292. if (beta > vcrit) {
  1293. rec = 1. / vmax;
  1294. i__3 = *n - ki + 1;
  1295. dscal_(&i__3, &rec, &work[ki + *n], &c__1);
  1296. vmax = 1.;
  1297. vcrit = bignum;
  1298. }
  1299. i__3 = j - ki - 1;
  1300. work[j + *n] -= ddot_(&i__3, &t[ki + 1 + j * t_dim1],
  1301. &c__1, &work[ki + 1 + *n], &c__1);
  1302. i__3 = j - ki - 1;
  1303. work[j + 1 + *n] -= ddot_(&i__3, &t[ki + 1 + (j + 1) *
  1304. t_dim1], &c__1, &work[ki + 1 + *n], &c__1);
  1305. /* Solve */
  1306. /* [T(J,J)-WR T(J,J+1) ]**T * X = SCALE*( WORK1 ) */
  1307. /* [T(J+1,J) T(J+1,J+1)-WR] ( WORK2 ) */
  1308. dlaln2_(&c_true, &c__2, &c__1, &smin, &c_b22, &t[j +
  1309. j * t_dim1], ldt, &c_b22, &c_b22, &work[j + *
  1310. n], n, &wr, &c_b25, x, &c__2, &scale, &xnorm,
  1311. &ierr);
  1312. /* Scale if necessary */
  1313. if (scale != 1.) {
  1314. i__3 = *n - ki + 1;
  1315. dscal_(&i__3, &scale, &work[ki + *n], &c__1);
  1316. }
  1317. work[j + *n] = x[0];
  1318. work[j + 1 + *n] = x[1];
  1319. /* Computing MAX */
  1320. d__3 = (d__1 = work[j + *n], abs(d__1)), d__4 = (d__2
  1321. = work[j + 1 + *n], abs(d__2)), d__3 = f2cmax(
  1322. d__3,d__4);
  1323. vmax = f2cmax(d__3,vmax);
  1324. vcrit = bignum / vmax;
  1325. }
  1326. L170:
  1327. ;
  1328. }
  1329. /* Copy the vector x or Q*x to VL and normalize. */
  1330. if (! over) {
  1331. i__2 = *n - ki + 1;
  1332. dcopy_(&i__2, &work[ki + *n], &c__1, &vl[ki + is *
  1333. vl_dim1], &c__1);
  1334. i__2 = *n - ki + 1;
  1335. ii = idamax_(&i__2, &vl[ki + is * vl_dim1], &c__1) + ki -
  1336. 1;
  1337. remax = 1. / (d__1 = vl[ii + is * vl_dim1], abs(d__1));
  1338. i__2 = *n - ki + 1;
  1339. dscal_(&i__2, &remax, &vl[ki + is * vl_dim1], &c__1);
  1340. i__2 = ki - 1;
  1341. for (k = 1; k <= i__2; ++k) {
  1342. vl[k + is * vl_dim1] = 0.;
  1343. /* L180: */
  1344. }
  1345. } else {
  1346. if (ki < *n) {
  1347. i__2 = *n - ki;
  1348. dgemv_("N", n, &i__2, &c_b22, &vl[(ki + 1) * vl_dim1
  1349. + 1], ldvl, &work[ki + 1 + *n], &c__1, &work[
  1350. ki + *n], &vl[ki * vl_dim1 + 1], &c__1);
  1351. }
  1352. ii = idamax_(n, &vl[ki * vl_dim1 + 1], &c__1);
  1353. remax = 1. / (d__1 = vl[ii + ki * vl_dim1], abs(d__1));
  1354. dscal_(n, &remax, &vl[ki * vl_dim1 + 1], &c__1);
  1355. }
  1356. } else {
  1357. /* Complex left eigenvector. */
  1358. /* Initial solve: */
  1359. /* ((T(KI,KI) T(KI,KI+1) )**T - (WR - I* WI))*X = 0. */
  1360. /* ((T(KI+1,KI) T(KI+1,KI+1)) ) */
  1361. if ((d__1 = t[ki + (ki + 1) * t_dim1], abs(d__1)) >= (d__2 =
  1362. t[ki + 1 + ki * t_dim1], abs(d__2))) {
  1363. work[ki + *n] = wi / t[ki + (ki + 1) * t_dim1];
  1364. work[ki + 1 + n2] = 1.;
  1365. } else {
  1366. work[ki + *n] = 1.;
  1367. work[ki + 1 + n2] = -wi / t[ki + 1 + ki * t_dim1];
  1368. }
  1369. work[ki + 1 + *n] = 0.;
  1370. work[ki + n2] = 0.;
  1371. /* Form right-hand side */
  1372. i__2 = *n;
  1373. for (k = ki + 2; k <= i__2; ++k) {
  1374. work[k + *n] = -work[ki + *n] * t[ki + k * t_dim1];
  1375. work[k + n2] = -work[ki + 1 + n2] * t[ki + 1 + k * t_dim1]
  1376. ;
  1377. /* L190: */
  1378. }
  1379. /* Solve complex quasi-triangular system: */
  1380. /* ( T(KI+2,N:KI+2,N) - (WR-i*WI) )*X = WORK1+i*WORK2 */
  1381. vmax = 1.;
  1382. vcrit = bignum;
  1383. jnxt = ki + 2;
  1384. i__2 = *n;
  1385. for (j = ki + 2; j <= i__2; ++j) {
  1386. if (j < jnxt) {
  1387. goto L200;
  1388. }
  1389. j1 = j;
  1390. j2 = j;
  1391. jnxt = j + 1;
  1392. if (j < *n) {
  1393. if (t[j + 1 + j * t_dim1] != 0.) {
  1394. j2 = j + 1;
  1395. jnxt = j + 2;
  1396. }
  1397. }
  1398. if (j1 == j2) {
  1399. /* 1-by-1 diagonal block */
  1400. /* Scale if necessary to avoid overflow when */
  1401. /* forming the right-hand side elements. */
  1402. if (work[j] > vcrit) {
  1403. rec = 1. / vmax;
  1404. i__3 = *n - ki + 1;
  1405. dscal_(&i__3, &rec, &work[ki + *n], &c__1);
  1406. i__3 = *n - ki + 1;
  1407. dscal_(&i__3, &rec, &work[ki + n2], &c__1);
  1408. vmax = 1.;
  1409. vcrit = bignum;
  1410. }
  1411. i__3 = j - ki - 2;
  1412. work[j + *n] -= ddot_(&i__3, &t[ki + 2 + j * t_dim1],
  1413. &c__1, &work[ki + 2 + *n], &c__1);
  1414. i__3 = j - ki - 2;
  1415. work[j + n2] -= ddot_(&i__3, &t[ki + 2 + j * t_dim1],
  1416. &c__1, &work[ki + 2 + n2], &c__1);
  1417. /* Solve (T(J,J)-(WR-i*WI))*(X11+i*X12)= WK+I*WK2 */
  1418. d__1 = -wi;
  1419. dlaln2_(&c_false, &c__1, &c__2, &smin, &c_b22, &t[j +
  1420. j * t_dim1], ldt, &c_b22, &c_b22, &work[j + *
  1421. n], n, &wr, &d__1, x, &c__2, &scale, &xnorm, &
  1422. ierr);
  1423. /* Scale if necessary */
  1424. if (scale != 1.) {
  1425. i__3 = *n - ki + 1;
  1426. dscal_(&i__3, &scale, &work[ki + *n], &c__1);
  1427. i__3 = *n - ki + 1;
  1428. dscal_(&i__3, &scale, &work[ki + n2], &c__1);
  1429. }
  1430. work[j + *n] = x[0];
  1431. work[j + n2] = x[2];
  1432. /* Computing MAX */
  1433. d__3 = (d__1 = work[j + *n], abs(d__1)), d__4 = (d__2
  1434. = work[j + n2], abs(d__2)), d__3 = f2cmax(d__3,
  1435. d__4);
  1436. vmax = f2cmax(d__3,vmax);
  1437. vcrit = bignum / vmax;
  1438. } else {
  1439. /* 2-by-2 diagonal block */
  1440. /* Scale if necessary to avoid overflow when forming */
  1441. /* the right-hand side elements. */
  1442. /* Computing MAX */
  1443. d__1 = work[j], d__2 = work[j + 1];
  1444. beta = f2cmax(d__1,d__2);
  1445. if (beta > vcrit) {
  1446. rec = 1. / vmax;
  1447. i__3 = *n - ki + 1;
  1448. dscal_(&i__3, &rec, &work[ki + *n], &c__1);
  1449. i__3 = *n - ki + 1;
  1450. dscal_(&i__3, &rec, &work[ki + n2], &c__1);
  1451. vmax = 1.;
  1452. vcrit = bignum;
  1453. }
  1454. i__3 = j - ki - 2;
  1455. work[j + *n] -= ddot_(&i__3, &t[ki + 2 + j * t_dim1],
  1456. &c__1, &work[ki + 2 + *n], &c__1);
  1457. i__3 = j - ki - 2;
  1458. work[j + n2] -= ddot_(&i__3, &t[ki + 2 + j * t_dim1],
  1459. &c__1, &work[ki + 2 + n2], &c__1);
  1460. i__3 = j - ki - 2;
  1461. work[j + 1 + *n] -= ddot_(&i__3, &t[ki + 2 + (j + 1) *
  1462. t_dim1], &c__1, &work[ki + 2 + *n], &c__1);
  1463. i__3 = j - ki - 2;
  1464. work[j + 1 + n2] -= ddot_(&i__3, &t[ki + 2 + (j + 1) *
  1465. t_dim1], &c__1, &work[ki + 2 + n2], &c__1);
  1466. /* Solve 2-by-2 complex linear equation */
  1467. /* ([T(j,j) T(j,j+1) ]**T-(wr-i*wi)*I)*X = SCALE*B */
  1468. /* ([T(j+1,j) T(j+1,j+1)] ) */
  1469. d__1 = -wi;
  1470. dlaln2_(&c_true, &c__2, &c__2, &smin, &c_b22, &t[j +
  1471. j * t_dim1], ldt, &c_b22, &c_b22, &work[j + *
  1472. n], n, &wr, &d__1, x, &c__2, &scale, &xnorm, &
  1473. ierr);
  1474. /* Scale if necessary */
  1475. if (scale != 1.) {
  1476. i__3 = *n - ki + 1;
  1477. dscal_(&i__3, &scale, &work[ki + *n], &c__1);
  1478. i__3 = *n - ki + 1;
  1479. dscal_(&i__3, &scale, &work[ki + n2], &c__1);
  1480. }
  1481. work[j + *n] = x[0];
  1482. work[j + n2] = x[2];
  1483. work[j + 1 + *n] = x[1];
  1484. work[j + 1 + n2] = x[3];
  1485. /* Computing MAX */
  1486. d__1 = abs(x[0]), d__2 = abs(x[2]), d__1 = f2cmax(d__1,
  1487. d__2), d__2 = abs(x[1]), d__1 = f2cmax(d__1,d__2)
  1488. , d__2 = abs(x[3]), d__1 = f2cmax(d__1,d__2);
  1489. vmax = f2cmax(d__1,vmax);
  1490. vcrit = bignum / vmax;
  1491. }
  1492. L200:
  1493. ;
  1494. }
  1495. /* Copy the vector x or Q*x to VL and normalize. */
  1496. if (! over) {
  1497. i__2 = *n - ki + 1;
  1498. dcopy_(&i__2, &work[ki + *n], &c__1, &vl[ki + is *
  1499. vl_dim1], &c__1);
  1500. i__2 = *n - ki + 1;
  1501. dcopy_(&i__2, &work[ki + n2], &c__1, &vl[ki + (is + 1) *
  1502. vl_dim1], &c__1);
  1503. emax = 0.;
  1504. i__2 = *n;
  1505. for (k = ki; k <= i__2; ++k) {
  1506. /* Computing MAX */
  1507. d__3 = emax, d__4 = (d__1 = vl[k + is * vl_dim1], abs(
  1508. d__1)) + (d__2 = vl[k + (is + 1) * vl_dim1],
  1509. abs(d__2));
  1510. emax = f2cmax(d__3,d__4);
  1511. /* L220: */
  1512. }
  1513. remax = 1. / emax;
  1514. i__2 = *n - ki + 1;
  1515. dscal_(&i__2, &remax, &vl[ki + is * vl_dim1], &c__1);
  1516. i__2 = *n - ki + 1;
  1517. dscal_(&i__2, &remax, &vl[ki + (is + 1) * vl_dim1], &c__1)
  1518. ;
  1519. i__2 = ki - 1;
  1520. for (k = 1; k <= i__2; ++k) {
  1521. vl[k + is * vl_dim1] = 0.;
  1522. vl[k + (is + 1) * vl_dim1] = 0.;
  1523. /* L230: */
  1524. }
  1525. } else {
  1526. if (ki < *n - 1) {
  1527. i__2 = *n - ki - 1;
  1528. dgemv_("N", n, &i__2, &c_b22, &vl[(ki + 2) * vl_dim1
  1529. + 1], ldvl, &work[ki + 2 + *n], &c__1, &work[
  1530. ki + *n], &vl[ki * vl_dim1 + 1], &c__1);
  1531. i__2 = *n - ki - 1;
  1532. dgemv_("N", n, &i__2, &c_b22, &vl[(ki + 2) * vl_dim1
  1533. + 1], ldvl, &work[ki + 2 + n2], &c__1, &work[
  1534. ki + 1 + n2], &vl[(ki + 1) * vl_dim1 + 1], &
  1535. c__1);
  1536. } else {
  1537. dscal_(n, &work[ki + *n], &vl[ki * vl_dim1 + 1], &
  1538. c__1);
  1539. dscal_(n, &work[ki + 1 + n2], &vl[(ki + 1) * vl_dim1
  1540. + 1], &c__1);
  1541. }
  1542. emax = 0.;
  1543. i__2 = *n;
  1544. for (k = 1; k <= i__2; ++k) {
  1545. /* Computing MAX */
  1546. d__3 = emax, d__4 = (d__1 = vl[k + ki * vl_dim1], abs(
  1547. d__1)) + (d__2 = vl[k + (ki + 1) * vl_dim1],
  1548. abs(d__2));
  1549. emax = f2cmax(d__3,d__4);
  1550. /* L240: */
  1551. }
  1552. remax = 1. / emax;
  1553. dscal_(n, &remax, &vl[ki * vl_dim1 + 1], &c__1);
  1554. dscal_(n, &remax, &vl[(ki + 1) * vl_dim1 + 1], &c__1);
  1555. }
  1556. }
  1557. ++is;
  1558. if (ip != 0) {
  1559. ++is;
  1560. }
  1561. L250:
  1562. if (ip == -1) {
  1563. ip = 0;
  1564. }
  1565. if (ip == 1) {
  1566. ip = -1;
  1567. }
  1568. /* L260: */
  1569. }
  1570. }
  1571. return;
  1572. /* End of DTREVC */
  1573. } /* dtrevc_ */