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.

dtgevc.c 55 kB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970
  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 doublereal c_b34 = 1.;
  487. static integer c__1 = 1;
  488. static doublereal c_b36 = 0.;
  489. static logical c_false = FALSE_;
  490. /* > \brief \b DTGEVC */
  491. /* =========== DOCUMENTATION =========== */
  492. /* Online html documentation available at */
  493. /* http://www.netlib.org/lapack/explore-html/ */
  494. /* > \htmlonly */
  495. /* > Download DTGEVC + dependencies */
  496. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/dtgevc.
  497. f"> */
  498. /* > [TGZ]</a> */
  499. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/dtgevc.
  500. f"> */
  501. /* > [ZIP]</a> */
  502. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/dtgevc.
  503. f"> */
  504. /* > [TXT]</a> */
  505. /* > \endhtmlonly */
  506. /* Definition: */
  507. /* =========== */
  508. /* SUBROUTINE DTGEVC( 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. /* DOUBLE PRECISION P( LDP, * ), S( LDS, * ), VL( LDVL, * ), */
  514. /* $ VR( LDVR, * ), WORK( * ) */
  515. /* > \par Purpose: */
  516. /* ============= */
  517. /* > */
  518. /* > \verbatim */
  519. /* > */
  520. /* > DTGEVC 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 DGGHRD + DHGEQZ. */
  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 DOUBLE PRECISION array, dimension (LDS,N) */
  589. /* > The upper quasi-triangular matrix S from a generalized Schur */
  590. /* > factorization, as computed by DHGEQZ. */
  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 DOUBLE PRECISION array, dimension (LDP,N) */
  602. /* > The upper triangular matrix P from a generalized Schur */
  603. /* > factorization, as computed by DHGEQZ. */
  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 DOUBLE PRECISION 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 DHGEQZ). */
  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 DOUBLE PRECISION 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 DHGEQZ). */
  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 DOUBLE PRECISION 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 doubleGEcomputational */
  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 dtgevc_(char *side, char *howmny, logical *select,
  768. integer *n, doublereal *s, integer *lds, doublereal *p, integer *ldp,
  769. doublereal *vl, integer *ldvl, doublereal *vr, integer *ldvr, integer
  770. *mm, integer *m, doublereal *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. doublereal d__1, d__2, d__3, d__4, d__5, d__6;
  776. /* Local variables */
  777. integer ibeg, ieig, iend;
  778. doublereal dmin__, temp, xmax, sump[4] /* was [2][2] */, sums[4]
  779. /* was [2][2] */;
  780. extern /* Subroutine */ void dlag2_(doublereal *, integer *, doublereal *,
  781. integer *, doublereal *, doublereal *, doublereal *, doublereal *,
  782. doublereal *, doublereal *);
  783. doublereal cim2a, cim2b, cre2a, cre2b, temp2, bdiag[2];
  784. integer i__, j;
  785. doublereal acoef, scale;
  786. logical ilall;
  787. integer iside;
  788. doublereal sbeta;
  789. extern logical lsame_(char *, char *);
  790. extern /* Subroutine */ void dgemv_(char *, integer *, integer *,
  791. doublereal *, doublereal *, integer *, doublereal *, integer *,
  792. doublereal *, doublereal *, integer *);
  793. logical il2by2;
  794. integer iinfo;
  795. doublereal small;
  796. logical compl;
  797. doublereal anorm, bnorm;
  798. logical compr;
  799. extern /* Subroutine */ void dlaln2_(logical *, integer *, integer *,
  800. doublereal *, doublereal *, doublereal *, integer *, doublereal *,
  801. doublereal *, doublereal *, integer *, doublereal *, doublereal *
  802. , doublereal *, integer *, doublereal *, doublereal *, integer *);
  803. doublereal temp2i;
  804. extern /* Subroutine */ void dlabad_(doublereal *, doublereal *);
  805. doublereal temp2r;
  806. integer ja;
  807. logical ilabad, ilbbad;
  808. integer jc, je, na;
  809. doublereal acoefa, bcoefa, cimaga, cimagb;
  810. logical ilback;
  811. integer im;
  812. doublereal bcoefi, ascale, bscale, creala;
  813. integer jr;
  814. doublereal crealb;
  815. extern doublereal dlamch_(char *);
  816. doublereal bcoefr;
  817. integer jw, nw;
  818. doublereal salfar, safmin;
  819. extern /* Subroutine */ void dlacpy_(char *, integer *, integer *,
  820. doublereal *, integer *, doublereal *, integer *);
  821. doublereal xscale, bignum;
  822. extern /* Subroutine */ int xerbla_(char *, integer *, ftnlen);
  823. logical ilcomp, ilcplx;
  824. integer ihwmny;
  825. doublereal big;
  826. logical lsa, lsb;
  827. doublereal ulp, sum[4] /* was [2][2] */;
  828. /* -- LAPACK computational routine (version 3.7.0) -- */
  829. /* -- LAPACK is a software package provided by Univ. of Tennessee, -- */
  830. /* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- */
  831. /* December 2016 */
  832. /* ===================================================================== */
  833. /* Decode and Test the input parameters */
  834. /* Parameter adjustments */
  835. --select;
  836. s_dim1 = *lds;
  837. s_offset = 1 + s_dim1 * 1;
  838. s -= s_offset;
  839. p_dim1 = *ldp;
  840. p_offset = 1 + p_dim1 * 1;
  841. p -= p_offset;
  842. vl_dim1 = *ldvl;
  843. vl_offset = 1 + vl_dim1 * 1;
  844. vl -= vl_offset;
  845. vr_dim1 = *ldvr;
  846. vr_offset = 1 + vr_dim1 * 1;
  847. vr -= vr_offset;
  848. --work;
  849. /* Function Body */
  850. if (lsame_(howmny, "A")) {
  851. ihwmny = 1;
  852. ilall = TRUE_;
  853. ilback = FALSE_;
  854. } else if (lsame_(howmny, "S")) {
  855. ihwmny = 2;
  856. ilall = FALSE_;
  857. ilback = FALSE_;
  858. } else if (lsame_(howmny, "B")) {
  859. ihwmny = 3;
  860. ilall = TRUE_;
  861. ilback = TRUE_;
  862. } else {
  863. ihwmny = -1;
  864. ilall = TRUE_;
  865. }
  866. if (lsame_(side, "R")) {
  867. iside = 1;
  868. compl = FALSE_;
  869. compr = TRUE_;
  870. } else if (lsame_(side, "L")) {
  871. iside = 2;
  872. compl = TRUE_;
  873. compr = FALSE_;
  874. } else if (lsame_(side, "B")) {
  875. iside = 3;
  876. compl = TRUE_;
  877. compr = TRUE_;
  878. } else {
  879. iside = -1;
  880. }
  881. *info = 0;
  882. if (iside < 0) {
  883. *info = -1;
  884. } else if (ihwmny < 0) {
  885. *info = -2;
  886. } else if (*n < 0) {
  887. *info = -4;
  888. } else if (*lds < f2cmax(1,*n)) {
  889. *info = -6;
  890. } else if (*ldp < f2cmax(1,*n)) {
  891. *info = -8;
  892. }
  893. if (*info != 0) {
  894. i__1 = -(*info);
  895. xerbla_("DTGEVC", &i__1, (ftnlen)6);
  896. return;
  897. }
  898. /* Count the number of eigenvectors to be computed */
  899. if (! ilall) {
  900. im = 0;
  901. ilcplx = FALSE_;
  902. i__1 = *n;
  903. for (j = 1; j <= i__1; ++j) {
  904. if (ilcplx) {
  905. ilcplx = FALSE_;
  906. goto L10;
  907. }
  908. if (j < *n) {
  909. if (s[j + 1 + j * s_dim1] != 0.) {
  910. ilcplx = TRUE_;
  911. }
  912. }
  913. if (ilcplx) {
  914. if (select[j] || select[j + 1]) {
  915. im += 2;
  916. }
  917. } else {
  918. if (select[j]) {
  919. ++im;
  920. }
  921. }
  922. L10:
  923. ;
  924. }
  925. } else {
  926. im = *n;
  927. }
  928. /* Check 2-by-2 diagonal blocks of A, B */
  929. ilabad = FALSE_;
  930. ilbbad = FALSE_;
  931. i__1 = *n - 1;
  932. for (j = 1; j <= i__1; ++j) {
  933. if (s[j + 1 + j * s_dim1] != 0.) {
  934. if (p[j + j * p_dim1] == 0. || p[j + 1 + (j + 1) * p_dim1] == 0.
  935. || p[j + (j + 1) * p_dim1] != 0.) {
  936. ilbbad = TRUE_;
  937. }
  938. if (j < *n - 1) {
  939. if (s[j + 2 + (j + 1) * s_dim1] != 0.) {
  940. ilabad = TRUE_;
  941. }
  942. }
  943. }
  944. /* L20: */
  945. }
  946. if (ilabad) {
  947. *info = -5;
  948. } else if (ilbbad) {
  949. *info = -7;
  950. } else if (compl && *ldvl < *n || *ldvl < 1) {
  951. *info = -10;
  952. } else if (compr && *ldvr < *n || *ldvr < 1) {
  953. *info = -12;
  954. } else if (*mm < im) {
  955. *info = -13;
  956. }
  957. if (*info != 0) {
  958. i__1 = -(*info);
  959. xerbla_("DTGEVC", &i__1, (ftnlen)6);
  960. return;
  961. }
  962. /* Quick return if possible */
  963. *m = im;
  964. if (*n == 0) {
  965. return;
  966. }
  967. /* Machine Constants */
  968. safmin = dlamch_("Safe minimum");
  969. big = 1. / safmin;
  970. dlabad_(&safmin, &big);
  971. ulp = dlamch_("Epsilon") * dlamch_("Base");
  972. small = safmin * *n / ulp;
  973. big = 1. / small;
  974. bignum = 1. / (safmin * *n);
  975. /* Compute the 1-norm of each column of the strictly upper triangular */
  976. /* part (i.e., excluding all elements belonging to the diagonal */
  977. /* blocks) of A and B to check for possible overflow in the */
  978. /* triangular solver. */
  979. anorm = (d__1 = s[s_dim1 + 1], abs(d__1));
  980. if (*n > 1) {
  981. anorm += (d__1 = s[s_dim1 + 2], abs(d__1));
  982. }
  983. bnorm = (d__1 = p[p_dim1 + 1], abs(d__1));
  984. work[1] = 0.;
  985. work[*n + 1] = 0.;
  986. i__1 = *n;
  987. for (j = 2; j <= i__1; ++j) {
  988. temp = 0.;
  989. temp2 = 0.;
  990. if (s[j + (j - 1) * s_dim1] == 0.) {
  991. iend = j - 1;
  992. } else {
  993. iend = j - 2;
  994. }
  995. i__2 = iend;
  996. for (i__ = 1; i__ <= i__2; ++i__) {
  997. temp += (d__1 = s[i__ + j * s_dim1], abs(d__1));
  998. temp2 += (d__1 = p[i__ + j * p_dim1], abs(d__1));
  999. /* L30: */
  1000. }
  1001. work[j] = temp;
  1002. work[*n + j] = temp2;
  1003. /* Computing MIN */
  1004. i__3 = j + 1;
  1005. i__2 = f2cmin(i__3,*n);
  1006. for (i__ = iend + 1; i__ <= i__2; ++i__) {
  1007. temp += (d__1 = s[i__ + j * s_dim1], abs(d__1));
  1008. temp2 += (d__1 = p[i__ + j * p_dim1], abs(d__1));
  1009. /* L40: */
  1010. }
  1011. anorm = f2cmax(anorm,temp);
  1012. bnorm = f2cmax(bnorm,temp2);
  1013. /* L50: */
  1014. }
  1015. ascale = 1. / f2cmax(anorm,safmin);
  1016. bscale = 1. / f2cmax(bnorm,safmin);
  1017. /* Left eigenvectors */
  1018. if (compl) {
  1019. ieig = 0;
  1020. /* Main loop over eigenvalues */
  1021. ilcplx = FALSE_;
  1022. i__1 = *n;
  1023. for (je = 1; je <= i__1; ++je) {
  1024. /* Skip this iteration if (a) HOWMNY='S' and SELECT=.FALSE., or */
  1025. /* (b) this would be the second of a complex pair. */
  1026. /* Check for complex eigenvalue, so as to be sure of which */
  1027. /* entry(-ies) of SELECT to look at. */
  1028. if (ilcplx) {
  1029. ilcplx = FALSE_;
  1030. goto L220;
  1031. }
  1032. nw = 1;
  1033. if (je < *n) {
  1034. if (s[je + 1 + je * s_dim1] != 0.) {
  1035. ilcplx = TRUE_;
  1036. nw = 2;
  1037. }
  1038. }
  1039. if (ilall) {
  1040. ilcomp = TRUE_;
  1041. } else if (ilcplx) {
  1042. ilcomp = select[je] || select[je + 1];
  1043. } else {
  1044. ilcomp = select[je];
  1045. }
  1046. if (! ilcomp) {
  1047. goto L220;
  1048. }
  1049. /* Decide if (a) singular pencil, (b) real eigenvalue, or */
  1050. /* (c) complex eigenvalue. */
  1051. if (! ilcplx) {
  1052. if ((d__1 = s[je + je * s_dim1], abs(d__1)) <= safmin && (
  1053. d__2 = p[je + je * p_dim1], abs(d__2)) <= safmin) {
  1054. /* Singular matrix pencil -- return unit eigenvector */
  1055. ++ieig;
  1056. i__2 = *n;
  1057. for (jr = 1; jr <= i__2; ++jr) {
  1058. vl[jr + ieig * vl_dim1] = 0.;
  1059. /* L60: */
  1060. }
  1061. vl[ieig + ieig * vl_dim1] = 1.;
  1062. goto L220;
  1063. }
  1064. }
  1065. /* Clear vector */
  1066. i__2 = nw * *n;
  1067. for (jr = 1; jr <= i__2; ++jr) {
  1068. work[(*n << 1) + jr] = 0.;
  1069. /* L70: */
  1070. }
  1071. /* T */
  1072. /* Compute coefficients in ( a A - b B ) y = 0 */
  1073. /* a is ACOEF */
  1074. /* b is BCOEFR + i*BCOEFI */
  1075. if (! ilcplx) {
  1076. /* Real eigenvalue */
  1077. /* Computing MAX */
  1078. d__3 = (d__1 = s[je + je * s_dim1], abs(d__1)) * ascale, d__4
  1079. = (d__2 = p[je + je * p_dim1], abs(d__2)) * bscale,
  1080. d__3 = f2cmax(d__3,d__4);
  1081. temp = 1. / f2cmax(d__3,safmin);
  1082. salfar = temp * s[je + je * s_dim1] * ascale;
  1083. sbeta = temp * p[je + je * p_dim1] * bscale;
  1084. acoef = sbeta * ascale;
  1085. bcoefr = salfar * bscale;
  1086. bcoefi = 0.;
  1087. /* Scale to avoid underflow */
  1088. scale = 1.;
  1089. lsa = abs(sbeta) >= safmin && abs(acoef) < small;
  1090. lsb = abs(salfar) >= safmin && abs(bcoefr) < small;
  1091. if (lsa) {
  1092. scale = small / abs(sbeta) * f2cmin(anorm,big);
  1093. }
  1094. if (lsb) {
  1095. /* Computing MAX */
  1096. d__1 = scale, d__2 = small / abs(salfar) * f2cmin(bnorm,big);
  1097. scale = f2cmax(d__1,d__2);
  1098. }
  1099. if (lsa || lsb) {
  1100. /* Computing MIN */
  1101. /* Computing MAX */
  1102. d__3 = 1., d__4 = abs(acoef), d__3 = f2cmax(d__3,d__4), d__4
  1103. = abs(bcoefr);
  1104. d__1 = scale, d__2 = 1. / (safmin * f2cmax(d__3,d__4));
  1105. scale = f2cmin(d__1,d__2);
  1106. if (lsa) {
  1107. acoef = ascale * (scale * sbeta);
  1108. } else {
  1109. acoef = scale * acoef;
  1110. }
  1111. if (lsb) {
  1112. bcoefr = bscale * (scale * salfar);
  1113. } else {
  1114. bcoefr = scale * bcoefr;
  1115. }
  1116. }
  1117. acoefa = abs(acoef);
  1118. bcoefa = abs(bcoefr);
  1119. /* First component is 1 */
  1120. work[(*n << 1) + je] = 1.;
  1121. xmax = 1.;
  1122. } else {
  1123. /* Complex eigenvalue */
  1124. d__1 = safmin * 100.;
  1125. dlag2_(&s[je + je * s_dim1], lds, &p[je + je * p_dim1], ldp, &
  1126. d__1, &acoef, &temp, &bcoefr, &temp2, &bcoefi);
  1127. bcoefi = -bcoefi;
  1128. if (bcoefi == 0.) {
  1129. *info = je;
  1130. return;
  1131. }
  1132. /* Scale to avoid over/underflow */
  1133. acoefa = abs(acoef);
  1134. bcoefa = abs(bcoefr) + abs(bcoefi);
  1135. scale = 1.;
  1136. if (acoefa * ulp < safmin && acoefa >= safmin) {
  1137. scale = safmin / ulp / acoefa;
  1138. }
  1139. if (bcoefa * ulp < safmin && bcoefa >= safmin) {
  1140. /* Computing MAX */
  1141. d__1 = scale, d__2 = safmin / ulp / bcoefa;
  1142. scale = f2cmax(d__1,d__2);
  1143. }
  1144. if (safmin * acoefa > ascale) {
  1145. scale = ascale / (safmin * acoefa);
  1146. }
  1147. if (safmin * bcoefa > bscale) {
  1148. /* Computing MIN */
  1149. d__1 = scale, d__2 = bscale / (safmin * bcoefa);
  1150. scale = f2cmin(d__1,d__2);
  1151. }
  1152. if (scale != 1.) {
  1153. acoef = scale * acoef;
  1154. acoefa = abs(acoef);
  1155. bcoefr = scale * bcoefr;
  1156. bcoefi = scale * bcoefi;
  1157. bcoefa = abs(bcoefr) + abs(bcoefi);
  1158. }
  1159. /* Compute first two components of eigenvector */
  1160. temp = acoef * s[je + 1 + je * s_dim1];
  1161. temp2r = acoef * s[je + je * s_dim1] - bcoefr * p[je + je *
  1162. p_dim1];
  1163. temp2i = -bcoefi * p[je + je * p_dim1];
  1164. if (abs(temp) > abs(temp2r) + abs(temp2i)) {
  1165. work[(*n << 1) + je] = 1.;
  1166. work[*n * 3 + je] = 0.;
  1167. work[(*n << 1) + je + 1] = -temp2r / temp;
  1168. work[*n * 3 + je + 1] = -temp2i / temp;
  1169. } else {
  1170. work[(*n << 1) + je + 1] = 1.;
  1171. work[*n * 3 + je + 1] = 0.;
  1172. temp = acoef * s[je + (je + 1) * s_dim1];
  1173. work[(*n << 1) + je] = (bcoefr * p[je + 1 + (je + 1) *
  1174. p_dim1] - acoef * s[je + 1 + (je + 1) * s_dim1]) /
  1175. temp;
  1176. work[*n * 3 + je] = bcoefi * p[je + 1 + (je + 1) * p_dim1]
  1177. / temp;
  1178. }
  1179. /* Computing MAX */
  1180. d__5 = (d__1 = work[(*n << 1) + je], abs(d__1)) + (d__2 =
  1181. work[*n * 3 + je], abs(d__2)), d__6 = (d__3 = work[(*
  1182. n << 1) + je + 1], abs(d__3)) + (d__4 = work[*n * 3 +
  1183. je + 1], abs(d__4));
  1184. xmax = f2cmax(d__5,d__6);
  1185. }
  1186. /* Computing MAX */
  1187. d__1 = ulp * acoefa * anorm, d__2 = ulp * bcoefa * bnorm, d__1 =
  1188. f2cmax(d__1,d__2);
  1189. dmin__ = f2cmax(d__1,safmin);
  1190. /* T */
  1191. /* Triangular solve of (a A - b B) y = 0 */
  1192. /* T */
  1193. /* (rowwise in (a A - b B) , or columnwise in (a A - b B) ) */
  1194. il2by2 = FALSE_;
  1195. i__2 = *n;
  1196. for (j = je + nw; j <= i__2; ++j) {
  1197. if (il2by2) {
  1198. il2by2 = FALSE_;
  1199. goto L160;
  1200. }
  1201. na = 1;
  1202. bdiag[0] = p[j + j * p_dim1];
  1203. if (j < *n) {
  1204. if (s[j + 1 + j * s_dim1] != 0.) {
  1205. il2by2 = TRUE_;
  1206. bdiag[1] = p[j + 1 + (j + 1) * p_dim1];
  1207. na = 2;
  1208. }
  1209. }
  1210. /* Check whether scaling is necessary for dot products */
  1211. xscale = 1. / f2cmax(1.,xmax);
  1212. /* Computing MAX */
  1213. d__1 = work[j], d__2 = work[*n + j], d__1 = f2cmax(d__1,d__2),
  1214. d__2 = acoefa * work[j] + bcoefa * work[*n + j];
  1215. temp = f2cmax(d__1,d__2);
  1216. if (il2by2) {
  1217. /* Computing MAX */
  1218. d__1 = temp, d__2 = work[j + 1], d__1 = f2cmax(d__1,d__2),
  1219. d__2 = work[*n + j + 1], d__1 = f2cmax(d__1,d__2),
  1220. d__2 = acoefa * work[j + 1] + bcoefa * work[*n +
  1221. j + 1];
  1222. temp = f2cmax(d__1,d__2);
  1223. }
  1224. if (temp > bignum * xscale) {
  1225. i__3 = nw - 1;
  1226. for (jw = 0; jw <= i__3; ++jw) {
  1227. i__4 = j - 1;
  1228. for (jr = je; jr <= i__4; ++jr) {
  1229. work[(jw + 2) * *n + jr] = xscale * work[(jw + 2)
  1230. * *n + jr];
  1231. /* L80: */
  1232. }
  1233. /* L90: */
  1234. }
  1235. xmax *= xscale;
  1236. }
  1237. /* Compute dot products */
  1238. /* j-1 */
  1239. /* SUM = sum conjg( a*S(k,j) - b*P(k,j) )*x(k) */
  1240. /* k=je */
  1241. /* To reduce the op count, this is done as */
  1242. /* _ j-1 _ j-1 */
  1243. /* a*conjg( sum S(k,j)*x(k) ) - b*conjg( sum P(k,j)*x(k) ) */
  1244. /* k=je k=je */
  1245. /* which may cause underflow problems if A or B are close */
  1246. /* to underflow. (E.g., less than SMALL.) */
  1247. i__3 = nw;
  1248. for (jw = 1; jw <= i__3; ++jw) {
  1249. i__4 = na;
  1250. for (ja = 1; ja <= i__4; ++ja) {
  1251. sums[ja + (jw << 1) - 3] = 0.;
  1252. sump[ja + (jw << 1) - 3] = 0.;
  1253. i__5 = j - 1;
  1254. for (jr = je; jr <= i__5; ++jr) {
  1255. sums[ja + (jw << 1) - 3] += s[jr + (j + ja - 1) *
  1256. s_dim1] * work[(jw + 1) * *n + jr];
  1257. sump[ja + (jw << 1) - 3] += p[jr + (j + ja - 1) *
  1258. p_dim1] * work[(jw + 1) * *n + jr];
  1259. /* L100: */
  1260. }
  1261. /* L110: */
  1262. }
  1263. /* L120: */
  1264. }
  1265. i__3 = na;
  1266. for (ja = 1; ja <= i__3; ++ja) {
  1267. if (ilcplx) {
  1268. sum[ja - 1] = -acoef * sums[ja - 1] + bcoefr * sump[
  1269. ja - 1] - bcoefi * sump[ja + 1];
  1270. sum[ja + 1] = -acoef * sums[ja + 1] + bcoefr * sump[
  1271. ja + 1] + bcoefi * sump[ja - 1];
  1272. } else {
  1273. sum[ja - 1] = -acoef * sums[ja - 1] + bcoefr * sump[
  1274. ja - 1];
  1275. }
  1276. /* L130: */
  1277. }
  1278. /* T */
  1279. /* Solve ( a A - b B ) y = SUM(,) */
  1280. /* with scaling and perturbation of the denominator */
  1281. dlaln2_(&c_true, &na, &nw, &dmin__, &acoef, &s[j + j * s_dim1]
  1282. , lds, bdiag, &bdiag[1], sum, &c__2, &bcoefr, &bcoefi,
  1283. &work[(*n << 1) + j], n, &scale, &temp, &iinfo);
  1284. if (scale < 1.) {
  1285. i__3 = nw - 1;
  1286. for (jw = 0; jw <= i__3; ++jw) {
  1287. i__4 = j - 1;
  1288. for (jr = je; jr <= i__4; ++jr) {
  1289. work[(jw + 2) * *n + jr] = scale * work[(jw + 2) *
  1290. *n + jr];
  1291. /* L140: */
  1292. }
  1293. /* L150: */
  1294. }
  1295. xmax = scale * xmax;
  1296. }
  1297. xmax = f2cmax(xmax,temp);
  1298. L160:
  1299. ;
  1300. }
  1301. /* Copy eigenvector to VL, back transforming if */
  1302. /* HOWMNY='B'. */
  1303. ++ieig;
  1304. if (ilback) {
  1305. i__2 = nw - 1;
  1306. for (jw = 0; jw <= i__2; ++jw) {
  1307. i__3 = *n + 1 - je;
  1308. dgemv_("N", n, &i__3, &c_b34, &vl[je * vl_dim1 + 1], ldvl,
  1309. &work[(jw + 2) * *n + je], &c__1, &c_b36, &work[(
  1310. jw + 4) * *n + 1], &c__1);
  1311. /* L170: */
  1312. }
  1313. dlacpy_(" ", n, &nw, &work[(*n << 2) + 1], n, &vl[je *
  1314. vl_dim1 + 1], ldvl);
  1315. ibeg = 1;
  1316. } else {
  1317. dlacpy_(" ", n, &nw, &work[(*n << 1) + 1], n, &vl[ieig *
  1318. vl_dim1 + 1], ldvl);
  1319. ibeg = je;
  1320. }
  1321. /* Scale eigenvector */
  1322. xmax = 0.;
  1323. if (ilcplx) {
  1324. i__2 = *n;
  1325. for (j = ibeg; j <= i__2; ++j) {
  1326. /* Computing MAX */
  1327. d__3 = xmax, d__4 = (d__1 = vl[j + ieig * vl_dim1], abs(
  1328. d__1)) + (d__2 = vl[j + (ieig + 1) * vl_dim1],
  1329. abs(d__2));
  1330. xmax = f2cmax(d__3,d__4);
  1331. /* L180: */
  1332. }
  1333. } else {
  1334. i__2 = *n;
  1335. for (j = ibeg; j <= i__2; ++j) {
  1336. /* Computing MAX */
  1337. d__2 = xmax, d__3 = (d__1 = vl[j + ieig * vl_dim1], abs(
  1338. d__1));
  1339. xmax = f2cmax(d__2,d__3);
  1340. /* L190: */
  1341. }
  1342. }
  1343. if (xmax > safmin) {
  1344. xscale = 1. / xmax;
  1345. i__2 = nw - 1;
  1346. for (jw = 0; jw <= i__2; ++jw) {
  1347. i__3 = *n;
  1348. for (jr = ibeg; jr <= i__3; ++jr) {
  1349. vl[jr + (ieig + jw) * vl_dim1] = xscale * vl[jr + (
  1350. ieig + jw) * vl_dim1];
  1351. /* L200: */
  1352. }
  1353. /* L210: */
  1354. }
  1355. }
  1356. ieig = ieig + nw - 1;
  1357. L220:
  1358. ;
  1359. }
  1360. }
  1361. /* Right eigenvectors */
  1362. if (compr) {
  1363. ieig = im + 1;
  1364. /* Main loop over eigenvalues */
  1365. ilcplx = FALSE_;
  1366. for (je = *n; je >= 1; --je) {
  1367. /* Skip this iteration if (a) HOWMNY='S' and SELECT=.FALSE., or */
  1368. /* (b) this would be the second of a complex pair. */
  1369. /* Check for complex eigenvalue, so as to be sure of which */
  1370. /* entry(-ies) of SELECT to look at -- if complex, SELECT(JE) */
  1371. /* or SELECT(JE-1). */
  1372. /* If this is a complex pair, the 2-by-2 diagonal block */
  1373. /* corresponding to the eigenvalue is in rows/columns JE-1:JE */
  1374. if (ilcplx) {
  1375. ilcplx = FALSE_;
  1376. goto L500;
  1377. }
  1378. nw = 1;
  1379. if (je > 1) {
  1380. if (s[je + (je - 1) * s_dim1] != 0.) {
  1381. ilcplx = TRUE_;
  1382. nw = 2;
  1383. }
  1384. }
  1385. if (ilall) {
  1386. ilcomp = TRUE_;
  1387. } else if (ilcplx) {
  1388. ilcomp = select[je] || select[je - 1];
  1389. } else {
  1390. ilcomp = select[je];
  1391. }
  1392. if (! ilcomp) {
  1393. goto L500;
  1394. }
  1395. /* Decide if (a) singular pencil, (b) real eigenvalue, or */
  1396. /* (c) complex eigenvalue. */
  1397. if (! ilcplx) {
  1398. if ((d__1 = s[je + je * s_dim1], abs(d__1)) <= safmin && (
  1399. d__2 = p[je + je * p_dim1], abs(d__2)) <= safmin) {
  1400. /* Singular matrix pencil -- unit eigenvector */
  1401. --ieig;
  1402. i__1 = *n;
  1403. for (jr = 1; jr <= i__1; ++jr) {
  1404. vr[jr + ieig * vr_dim1] = 0.;
  1405. /* L230: */
  1406. }
  1407. vr[ieig + ieig * vr_dim1] = 1.;
  1408. goto L500;
  1409. }
  1410. }
  1411. /* Clear vector */
  1412. i__1 = nw - 1;
  1413. for (jw = 0; jw <= i__1; ++jw) {
  1414. i__2 = *n;
  1415. for (jr = 1; jr <= i__2; ++jr) {
  1416. work[(jw + 2) * *n + jr] = 0.;
  1417. /* L240: */
  1418. }
  1419. /* L250: */
  1420. }
  1421. /* Compute coefficients in ( a A - b B ) x = 0 */
  1422. /* a is ACOEF */
  1423. /* b is BCOEFR + i*BCOEFI */
  1424. if (! ilcplx) {
  1425. /* Real eigenvalue */
  1426. /* Computing MAX */
  1427. d__3 = (d__1 = s[je + je * s_dim1], abs(d__1)) * ascale, d__4
  1428. = (d__2 = p[je + je * p_dim1], abs(d__2)) * bscale,
  1429. d__3 = f2cmax(d__3,d__4);
  1430. temp = 1. / f2cmax(d__3,safmin);
  1431. salfar = temp * s[je + je * s_dim1] * ascale;
  1432. sbeta = temp * p[je + je * p_dim1] * bscale;
  1433. acoef = sbeta * ascale;
  1434. bcoefr = salfar * bscale;
  1435. bcoefi = 0.;
  1436. /* Scale to avoid underflow */
  1437. scale = 1.;
  1438. lsa = abs(sbeta) >= safmin && abs(acoef) < small;
  1439. lsb = abs(salfar) >= safmin && abs(bcoefr) < small;
  1440. if (lsa) {
  1441. scale = small / abs(sbeta) * f2cmin(anorm,big);
  1442. }
  1443. if (lsb) {
  1444. /* Computing MAX */
  1445. d__1 = scale, d__2 = small / abs(salfar) * f2cmin(bnorm,big);
  1446. scale = f2cmax(d__1,d__2);
  1447. }
  1448. if (lsa || lsb) {
  1449. /* Computing MIN */
  1450. /* Computing MAX */
  1451. d__3 = 1., d__4 = abs(acoef), d__3 = f2cmax(d__3,d__4), d__4
  1452. = abs(bcoefr);
  1453. d__1 = scale, d__2 = 1. / (safmin * f2cmax(d__3,d__4));
  1454. scale = f2cmin(d__1,d__2);
  1455. if (lsa) {
  1456. acoef = ascale * (scale * sbeta);
  1457. } else {
  1458. acoef = scale * acoef;
  1459. }
  1460. if (lsb) {
  1461. bcoefr = bscale * (scale * salfar);
  1462. } else {
  1463. bcoefr = scale * bcoefr;
  1464. }
  1465. }
  1466. acoefa = abs(acoef);
  1467. bcoefa = abs(bcoefr);
  1468. /* First component is 1 */
  1469. work[(*n << 1) + je] = 1.;
  1470. xmax = 1.;
  1471. /* Compute contribution from column JE of A and B to sum */
  1472. /* (See "Further Details", above.) */
  1473. i__1 = je - 1;
  1474. for (jr = 1; jr <= i__1; ++jr) {
  1475. work[(*n << 1) + jr] = bcoefr * p[jr + je * p_dim1] -
  1476. acoef * s[jr + je * s_dim1];
  1477. /* L260: */
  1478. }
  1479. } else {
  1480. /* Complex eigenvalue */
  1481. d__1 = safmin * 100.;
  1482. dlag2_(&s[je - 1 + (je - 1) * s_dim1], lds, &p[je - 1 + (je -
  1483. 1) * p_dim1], ldp, &d__1, &acoef, &temp, &bcoefr, &
  1484. temp2, &bcoefi);
  1485. if (bcoefi == 0.) {
  1486. *info = je - 1;
  1487. return;
  1488. }
  1489. /* Scale to avoid over/underflow */
  1490. acoefa = abs(acoef);
  1491. bcoefa = abs(bcoefr) + abs(bcoefi);
  1492. scale = 1.;
  1493. if (acoefa * ulp < safmin && acoefa >= safmin) {
  1494. scale = safmin / ulp / acoefa;
  1495. }
  1496. if (bcoefa * ulp < safmin && bcoefa >= safmin) {
  1497. /* Computing MAX */
  1498. d__1 = scale, d__2 = safmin / ulp / bcoefa;
  1499. scale = f2cmax(d__1,d__2);
  1500. }
  1501. if (safmin * acoefa > ascale) {
  1502. scale = ascale / (safmin * acoefa);
  1503. }
  1504. if (safmin * bcoefa > bscale) {
  1505. /* Computing MIN */
  1506. d__1 = scale, d__2 = bscale / (safmin * bcoefa);
  1507. scale = f2cmin(d__1,d__2);
  1508. }
  1509. if (scale != 1.) {
  1510. acoef = scale * acoef;
  1511. acoefa = abs(acoef);
  1512. bcoefr = scale * bcoefr;
  1513. bcoefi = scale * bcoefi;
  1514. bcoefa = abs(bcoefr) + abs(bcoefi);
  1515. }
  1516. /* Compute first two components of eigenvector */
  1517. /* and contribution to sums */
  1518. temp = acoef * s[je + (je - 1) * s_dim1];
  1519. temp2r = acoef * s[je + je * s_dim1] - bcoefr * p[je + je *
  1520. p_dim1];
  1521. temp2i = -bcoefi * p[je + je * p_dim1];
  1522. if (abs(temp) >= abs(temp2r) + abs(temp2i)) {
  1523. work[(*n << 1) + je] = 1.;
  1524. work[*n * 3 + je] = 0.;
  1525. work[(*n << 1) + je - 1] = -temp2r / temp;
  1526. work[*n * 3 + je - 1] = -temp2i / temp;
  1527. } else {
  1528. work[(*n << 1) + je - 1] = 1.;
  1529. work[*n * 3 + je - 1] = 0.;
  1530. temp = acoef * s[je - 1 + je * s_dim1];
  1531. work[(*n << 1) + je] = (bcoefr * p[je - 1 + (je - 1) *
  1532. p_dim1] - acoef * s[je - 1 + (je - 1) * s_dim1]) /
  1533. temp;
  1534. work[*n * 3 + je] = bcoefi * p[je - 1 + (je - 1) * p_dim1]
  1535. / temp;
  1536. }
  1537. /* Computing MAX */
  1538. d__5 = (d__1 = work[(*n << 1) + je], abs(d__1)) + (d__2 =
  1539. work[*n * 3 + je], abs(d__2)), d__6 = (d__3 = work[(*
  1540. n << 1) + je - 1], abs(d__3)) + (d__4 = work[*n * 3 +
  1541. je - 1], abs(d__4));
  1542. xmax = f2cmax(d__5,d__6);
  1543. /* Compute contribution from columns JE and JE-1 */
  1544. /* of A and B to the sums. */
  1545. creala = acoef * work[(*n << 1) + je - 1];
  1546. cimaga = acoef * work[*n * 3 + je - 1];
  1547. crealb = bcoefr * work[(*n << 1) + je - 1] - bcoefi * work[*n
  1548. * 3 + je - 1];
  1549. cimagb = bcoefi * work[(*n << 1) + je - 1] + bcoefr * work[*n
  1550. * 3 + je - 1];
  1551. cre2a = acoef * work[(*n << 1) + je];
  1552. cim2a = acoef * work[*n * 3 + je];
  1553. cre2b = bcoefr * work[(*n << 1) + je] - bcoefi * work[*n * 3
  1554. + je];
  1555. cim2b = bcoefi * work[(*n << 1) + je] + bcoefr * work[*n * 3
  1556. + je];
  1557. i__1 = je - 2;
  1558. for (jr = 1; jr <= i__1; ++jr) {
  1559. work[(*n << 1) + jr] = -creala * s[jr + (je - 1) * s_dim1]
  1560. + crealb * p[jr + (je - 1) * p_dim1] - cre2a * s[
  1561. jr + je * s_dim1] + cre2b * p[jr + je * p_dim1];
  1562. work[*n * 3 + jr] = -cimaga * s[jr + (je - 1) * s_dim1] +
  1563. cimagb * p[jr + (je - 1) * p_dim1] - cim2a * s[jr
  1564. + je * s_dim1] + cim2b * p[jr + je * p_dim1];
  1565. /* L270: */
  1566. }
  1567. }
  1568. /* Computing MAX */
  1569. d__1 = ulp * acoefa * anorm, d__2 = ulp * bcoefa * bnorm, d__1 =
  1570. f2cmax(d__1,d__2);
  1571. dmin__ = f2cmax(d__1,safmin);
  1572. /* Columnwise triangular solve of (a A - b B) x = 0 */
  1573. il2by2 = FALSE_;
  1574. for (j = je - nw; j >= 1; --j) {
  1575. /* If a 2-by-2 block, is in position j-1:j, wait until */
  1576. /* next iteration to process it (when it will be j:j+1) */
  1577. if (! il2by2 && j > 1) {
  1578. if (s[j + (j - 1) * s_dim1] != 0.) {
  1579. il2by2 = TRUE_;
  1580. goto L370;
  1581. }
  1582. }
  1583. bdiag[0] = p[j + j * p_dim1];
  1584. if (il2by2) {
  1585. na = 2;
  1586. bdiag[1] = p[j + 1 + (j + 1) * p_dim1];
  1587. } else {
  1588. na = 1;
  1589. }
  1590. /* Compute x(j) (and x(j+1), if 2-by-2 block) */
  1591. dlaln2_(&c_false, &na, &nw, &dmin__, &acoef, &s[j + j *
  1592. s_dim1], lds, bdiag, &bdiag[1], &work[(*n << 1) + j],
  1593. n, &bcoefr, &bcoefi, sum, &c__2, &scale, &temp, &
  1594. iinfo);
  1595. if (scale < 1.) {
  1596. i__1 = nw - 1;
  1597. for (jw = 0; jw <= i__1; ++jw) {
  1598. i__2 = je;
  1599. for (jr = 1; jr <= i__2; ++jr) {
  1600. work[(jw + 2) * *n + jr] = scale * work[(jw + 2) *
  1601. *n + jr];
  1602. /* L280: */
  1603. }
  1604. /* L290: */
  1605. }
  1606. }
  1607. /* Computing MAX */
  1608. d__1 = scale * xmax;
  1609. xmax = f2cmax(d__1,temp);
  1610. i__1 = nw;
  1611. for (jw = 1; jw <= i__1; ++jw) {
  1612. i__2 = na;
  1613. for (ja = 1; ja <= i__2; ++ja) {
  1614. work[(jw + 1) * *n + j + ja - 1] = sum[ja + (jw << 1)
  1615. - 3];
  1616. /* L300: */
  1617. }
  1618. /* L310: */
  1619. }
  1620. /* w = w + x(j)*(a S(*,j) - b P(*,j) ) with scaling */
  1621. if (j > 1) {
  1622. /* Check whether scaling is necessary for sum. */
  1623. xscale = 1. / f2cmax(1.,xmax);
  1624. temp = acoefa * work[j] + bcoefa * work[*n + j];
  1625. if (il2by2) {
  1626. /* Computing MAX */
  1627. d__1 = temp, d__2 = acoefa * work[j + 1] + bcoefa *
  1628. work[*n + j + 1];
  1629. temp = f2cmax(d__1,d__2);
  1630. }
  1631. /* Computing MAX */
  1632. d__1 = f2cmax(temp,acoefa);
  1633. temp = f2cmax(d__1,bcoefa);
  1634. if (temp > bignum * xscale) {
  1635. i__1 = nw - 1;
  1636. for (jw = 0; jw <= i__1; ++jw) {
  1637. i__2 = je;
  1638. for (jr = 1; jr <= i__2; ++jr) {
  1639. work[(jw + 2) * *n + jr] = xscale * work[(jw
  1640. + 2) * *n + jr];
  1641. /* L320: */
  1642. }
  1643. /* L330: */
  1644. }
  1645. xmax *= xscale;
  1646. }
  1647. /* Compute the contributions of the off-diagonals of */
  1648. /* column j (and j+1, if 2-by-2 block) of A and B to the */
  1649. /* sums. */
  1650. i__1 = na;
  1651. for (ja = 1; ja <= i__1; ++ja) {
  1652. if (ilcplx) {
  1653. creala = acoef * work[(*n << 1) + j + ja - 1];
  1654. cimaga = acoef * work[*n * 3 + j + ja - 1];
  1655. crealb = bcoefr * work[(*n << 1) + j + ja - 1] -
  1656. bcoefi * work[*n * 3 + j + ja - 1];
  1657. cimagb = bcoefi * work[(*n << 1) + j + ja - 1] +
  1658. bcoefr * work[*n * 3 + j + ja - 1];
  1659. i__2 = j - 1;
  1660. for (jr = 1; jr <= i__2; ++jr) {
  1661. work[(*n << 1) + jr] = work[(*n << 1) + jr] -
  1662. creala * s[jr + (j + ja - 1) * s_dim1]
  1663. + crealb * p[jr + (j + ja - 1) *
  1664. p_dim1];
  1665. work[*n * 3 + jr] = work[*n * 3 + jr] -
  1666. cimaga * s[jr + (j + ja - 1) * s_dim1]
  1667. + cimagb * p[jr + (j + ja - 1) *
  1668. p_dim1];
  1669. /* L340: */
  1670. }
  1671. } else {
  1672. creala = acoef * work[(*n << 1) + j + ja - 1];
  1673. crealb = bcoefr * work[(*n << 1) + j + ja - 1];
  1674. i__2 = j - 1;
  1675. for (jr = 1; jr <= i__2; ++jr) {
  1676. work[(*n << 1) + jr] = work[(*n << 1) + jr] -
  1677. creala * s[jr + (j + ja - 1) * s_dim1]
  1678. + crealb * p[jr + (j + ja - 1) *
  1679. p_dim1];
  1680. /* L350: */
  1681. }
  1682. }
  1683. /* L360: */
  1684. }
  1685. }
  1686. il2by2 = FALSE_;
  1687. L370:
  1688. ;
  1689. }
  1690. /* Copy eigenvector to VR, back transforming if */
  1691. /* HOWMNY='B'. */
  1692. ieig -= nw;
  1693. if (ilback) {
  1694. i__1 = nw - 1;
  1695. for (jw = 0; jw <= i__1; ++jw) {
  1696. i__2 = *n;
  1697. for (jr = 1; jr <= i__2; ++jr) {
  1698. work[(jw + 4) * *n + jr] = work[(jw + 2) * *n + 1] *
  1699. vr[jr + vr_dim1];
  1700. /* L380: */
  1701. }
  1702. /* A series of compiler directives to defeat */
  1703. /* vectorization for the next loop */
  1704. i__2 = je;
  1705. for (jc = 2; jc <= i__2; ++jc) {
  1706. i__3 = *n;
  1707. for (jr = 1; jr <= i__3; ++jr) {
  1708. work[(jw + 4) * *n + jr] += work[(jw + 2) * *n +
  1709. jc] * vr[jr + jc * vr_dim1];
  1710. /* L390: */
  1711. }
  1712. /* L400: */
  1713. }
  1714. /* L410: */
  1715. }
  1716. i__1 = nw - 1;
  1717. for (jw = 0; jw <= i__1; ++jw) {
  1718. i__2 = *n;
  1719. for (jr = 1; jr <= i__2; ++jr) {
  1720. vr[jr + (ieig + jw) * vr_dim1] = work[(jw + 4) * *n +
  1721. jr];
  1722. /* L420: */
  1723. }
  1724. /* L430: */
  1725. }
  1726. iend = *n;
  1727. } else {
  1728. i__1 = nw - 1;
  1729. for (jw = 0; jw <= i__1; ++jw) {
  1730. i__2 = *n;
  1731. for (jr = 1; jr <= i__2; ++jr) {
  1732. vr[jr + (ieig + jw) * vr_dim1] = work[(jw + 2) * *n +
  1733. jr];
  1734. /* L440: */
  1735. }
  1736. /* L450: */
  1737. }
  1738. iend = je;
  1739. }
  1740. /* Scale eigenvector */
  1741. xmax = 0.;
  1742. if (ilcplx) {
  1743. i__1 = iend;
  1744. for (j = 1; j <= i__1; ++j) {
  1745. /* Computing MAX */
  1746. d__3 = xmax, d__4 = (d__1 = vr[j + ieig * vr_dim1], abs(
  1747. d__1)) + (d__2 = vr[j + (ieig + 1) * vr_dim1],
  1748. abs(d__2));
  1749. xmax = f2cmax(d__3,d__4);
  1750. /* L460: */
  1751. }
  1752. } else {
  1753. i__1 = iend;
  1754. for (j = 1; j <= i__1; ++j) {
  1755. /* Computing MAX */
  1756. d__2 = xmax, d__3 = (d__1 = vr[j + ieig * vr_dim1], abs(
  1757. d__1));
  1758. xmax = f2cmax(d__2,d__3);
  1759. /* L470: */
  1760. }
  1761. }
  1762. if (xmax > safmin) {
  1763. xscale = 1. / xmax;
  1764. i__1 = nw - 1;
  1765. for (jw = 0; jw <= i__1; ++jw) {
  1766. i__2 = iend;
  1767. for (jr = 1; jr <= i__2; ++jr) {
  1768. vr[jr + (ieig + jw) * vr_dim1] = xscale * vr[jr + (
  1769. ieig + jw) * vr_dim1];
  1770. /* L480: */
  1771. }
  1772. /* L490: */
  1773. }
  1774. }
  1775. L500:
  1776. ;
  1777. }
  1778. }
  1779. return;
  1780. /* End of DTGEVC */
  1781. } /* dtgevc_ */