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 int logical;
  52. typedef short int shortlogical;
  53. typedef char logical1;
  54. typedef char integer1;
  55. #define TRUE_ (1)
  56. #define FALSE_ (0)
  57. /* Extern is for use with -E */
  58. #ifndef Extern
  59. #define Extern extern
  60. #endif
  61. /* I/O stuff */
  62. typedef int flag;
  63. typedef int ftnlen;
  64. typedef int ftnint;
  65. /*external read, write*/
  66. typedef struct
  67. { flag cierr;
  68. ftnint ciunit;
  69. flag ciend;
  70. char *cifmt;
  71. ftnint cirec;
  72. } cilist;
  73. /*internal read, write*/
  74. typedef struct
  75. { flag icierr;
  76. char *iciunit;
  77. flag iciend;
  78. char *icifmt;
  79. ftnint icirlen;
  80. ftnint icirnum;
  81. } icilist;
  82. /*open*/
  83. typedef struct
  84. { flag oerr;
  85. ftnint ounit;
  86. char *ofnm;
  87. ftnlen ofnmlen;
  88. char *osta;
  89. char *oacc;
  90. char *ofm;
  91. ftnint orl;
  92. char *oblnk;
  93. } olist;
  94. /*close*/
  95. typedef struct
  96. { flag cerr;
  97. ftnint cunit;
  98. char *csta;
  99. } cllist;
  100. /*rewind, backspace, endfile*/
  101. typedef struct
  102. { flag aerr;
  103. ftnint aunit;
  104. } alist;
  105. /* inquire */
  106. typedef struct
  107. { flag inerr;
  108. ftnint inunit;
  109. char *infile;
  110. ftnlen infilen;
  111. ftnint *inex; /*parameters in standard's order*/
  112. ftnint *inopen;
  113. ftnint *innum;
  114. ftnint *innamed;
  115. char *inname;
  116. ftnlen innamlen;
  117. char *inacc;
  118. ftnlen inacclen;
  119. char *inseq;
  120. ftnlen inseqlen;
  121. char *indir;
  122. ftnlen indirlen;
  123. char *infmt;
  124. ftnlen infmtlen;
  125. char *inform;
  126. ftnint informlen;
  127. char *inunf;
  128. ftnlen inunflen;
  129. ftnint *inrecl;
  130. ftnint *innrec;
  131. char *inblank;
  132. ftnlen inblanklen;
  133. } inlist;
  134. #define VOID void
  135. union Multitype { /* for multiple entry points */
  136. integer1 g;
  137. shortint h;
  138. integer i;
  139. /* longint j; */
  140. real r;
  141. doublereal d;
  142. complex c;
  143. doublecomplex z;
  144. };
  145. typedef union Multitype Multitype;
  146. struct Vardesc { /* for Namelist */
  147. char *name;
  148. char *addr;
  149. ftnlen *dims;
  150. int type;
  151. };
  152. typedef struct Vardesc Vardesc;
  153. struct Namelist {
  154. char *name;
  155. Vardesc **vars;
  156. int nvars;
  157. };
  158. typedef struct Namelist Namelist;
  159. #define abs(x) ((x) >= 0 ? (x) : -(x))
  160. #define dabs(x) (fabs(x))
  161. #define f2cmin(a,b) ((a) <= (b) ? (a) : (b))
  162. #define f2cmax(a,b) ((a) >= (b) ? (a) : (b))
  163. #define dmin(a,b) (f2cmin(a,b))
  164. #define dmax(a,b) (f2cmax(a,b))
  165. #define bit_test(a,b) ((a) >> (b) & 1)
  166. #define bit_clear(a,b) ((a) & ~((uinteger)1 << (b)))
  167. #define bit_set(a,b) ((a) | ((uinteger)1 << (b)))
  168. #define abort_() { sig_die("Fortran abort routine called", 1); }
  169. #define c_abs(z) (cabsf(Cf(z)))
  170. #define c_cos(R,Z) { pCf(R)=ccos(Cf(Z)); }
  171. #ifdef _MSC_VER
  172. #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]);}
  173. #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]);}
  174. #else
  175. #define c_div(c, a, b) {pCf(c) = Cf(a)/Cf(b);}
  176. #define z_div(c, a, b) {pCd(c) = Cd(a)/Cd(b);}
  177. #endif
  178. #define c_exp(R, Z) {pCf(R) = cexpf(Cf(Z));}
  179. #define c_log(R, Z) {pCf(R) = clogf(Cf(Z));}
  180. #define c_sin(R, Z) {pCf(R) = csinf(Cf(Z));}
  181. //#define c_sqrt(R, Z) {*(R) = csqrtf(Cf(Z));}
  182. #define c_sqrt(R, Z) {pCf(R) = csqrtf(Cf(Z));}
  183. #define d_abs(x) (fabs(*(x)))
  184. #define d_acos(x) (acos(*(x)))
  185. #define d_asin(x) (asin(*(x)))
  186. #define d_atan(x) (atan(*(x)))
  187. #define d_atn2(x, y) (atan2(*(x),*(y)))
  188. #define d_cnjg(R, Z) { pCd(R) = conj(Cd(Z)); }
  189. #define r_cnjg(R, Z) { pCf(R) = conjf(Cf(Z)); }
  190. #define d_cos(x) (cos(*(x)))
  191. #define d_cosh(x) (cosh(*(x)))
  192. #define d_dim(__a, __b) ( *(__a) > *(__b) ? *(__a) - *(__b) : 0.0 )
  193. #define d_exp(x) (exp(*(x)))
  194. #define d_imag(z) (cimag(Cd(z)))
  195. #define r_imag(z) (cimagf(Cf(z)))
  196. #define d_int(__x) (*(__x)>0 ? floor(*(__x)) : -floor(- *(__x)))
  197. #define r_int(__x) (*(__x)>0 ? floor(*(__x)) : -floor(- *(__x)))
  198. #define d_lg10(x) ( 0.43429448190325182765 * log(*(x)) )
  199. #define r_lg10(x) ( 0.43429448190325182765 * log(*(x)) )
  200. #define d_log(x) (log(*(x)))
  201. #define d_mod(x, y) (fmod(*(x), *(y)))
  202. #define u_nint(__x) ((__x)>=0 ? floor((__x) + .5) : -floor(.5 - (__x)))
  203. #define d_nint(x) u_nint(*(x))
  204. #define u_sign(__a,__b) ((__b) >= 0 ? ((__a) >= 0 ? (__a) : -(__a)) : -((__a) >= 0 ? (__a) : -(__a)))
  205. #define d_sign(a,b) u_sign(*(a),*(b))
  206. #define r_sign(a,b) u_sign(*(a),*(b))
  207. #define d_sin(x) (sin(*(x)))
  208. #define d_sinh(x) (sinh(*(x)))
  209. #define d_sqrt(x) (sqrt(*(x)))
  210. #define d_tan(x) (tan(*(x)))
  211. #define d_tanh(x) (tanh(*(x)))
  212. #define i_abs(x) abs(*(x))
  213. #define i_dnnt(x) ((integer)u_nint(*(x)))
  214. #define i_len(s, n) (n)
  215. #define i_nint(x) ((integer)u_nint(*(x)))
  216. #define i_sign(a,b) ((integer)u_sign((integer)*(a),(integer)*(b)))
  217. #define pow_dd(ap, bp) ( pow(*(ap), *(bp)))
  218. #define pow_si(B,E) spow_ui(*(B),*(E))
  219. #define pow_ri(B,E) spow_ui(*(B),*(E))
  220. #define pow_di(B,E) dpow_ui(*(B),*(E))
  221. #define pow_zi(p, a, b) {pCd(p) = zpow_ui(Cd(a), *(b));}
  222. #define pow_ci(p, a, b) {pCf(p) = cpow_ui(Cf(a), *(b));}
  223. #define pow_zz(R,A,B) {pCd(R) = cpow(Cd(A),*(B));}
  224. #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++ = ' '; }
  225. #define s_cmp(a,b,c,d) ((integer)strncmp((a),(b),f2cmin((c),(d))))
  226. #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]; }
  227. #define sig_die(s, kill) { exit(1); }
  228. #define s_stop(s, n) {exit(0);}
  229. static char junk[] = "\n@(#)LIBF77 VERSION 19990503\n";
  230. #define z_abs(z) (cabs(Cd(z)))
  231. #define z_exp(R, Z) {pCd(R) = cexp(Cd(Z));}
  232. #define z_sqrt(R, Z) {pCd(R) = csqrt(Cd(Z));}
  233. #define myexit_() break;
  234. #define mycycle() continue;
  235. #define myceiling(w) {ceil(w)}
  236. #define myhuge(w) {HUGE_VAL}
  237. //#define mymaxloc_(w,s,e,n) {if (sizeof(*(w)) == sizeof(double)) dmaxloc_((w),*(s),*(e),n); else dmaxloc_((w),*(s),*(e),n);}
  238. #define mymaxloc(w,s,e,n) {dmaxloc_(w,*(s),*(e),n)}
  239. /* procedure parameter types for -A and -C++ */
  240. #define F2C_proc_par_types 1
  241. #ifdef __cplusplus
  242. typedef logical (*L_fp)(...);
  243. #else
  244. typedef logical (*L_fp)();
  245. #endif
  246. static float spow_ui(float x, integer n) {
  247. float pow=1.0; unsigned long int u;
  248. if(n != 0) {
  249. if(n < 0) n = -n, x = 1/x;
  250. for(u = n; ; ) {
  251. if(u & 01) pow *= x;
  252. if(u >>= 1) x *= x;
  253. else break;
  254. }
  255. }
  256. return pow;
  257. }
  258. static double dpow_ui(double x, integer n) {
  259. double pow=1.0; unsigned long int u;
  260. if(n != 0) {
  261. if(n < 0) n = -n, x = 1/x;
  262. for(u = n; ; ) {
  263. if(u & 01) pow *= x;
  264. if(u >>= 1) x *= x;
  265. else break;
  266. }
  267. }
  268. return pow;
  269. }
  270. #ifdef _MSC_VER
  271. static _Fcomplex cpow_ui(complex x, integer n) {
  272. complex pow={1.0,0.0}; unsigned long int u;
  273. if(n != 0) {
  274. if(n < 0) n = -n, x.r = 1/x.r, x.i=1/x.i;
  275. for(u = n; ; ) {
  276. if(u & 01) pow.r *= x.r, pow.i *= x.i;
  277. if(u >>= 1) x.r *= x.r, x.i *= x.i;
  278. else break;
  279. }
  280. }
  281. _Fcomplex p={pow.r, pow.i};
  282. return p;
  283. }
  284. #else
  285. static _Complex float cpow_ui(_Complex float x, integer n) {
  286. _Complex float pow=1.0; unsigned long int u;
  287. if(n != 0) {
  288. if(n < 0) n = -n, x = 1/x;
  289. for(u = n; ; ) {
  290. if(u & 01) pow *= x;
  291. if(u >>= 1) x *= x;
  292. else break;
  293. }
  294. }
  295. return pow;
  296. }
  297. #endif
  298. #ifdef _MSC_VER
  299. static _Dcomplex zpow_ui(_Dcomplex x, integer n) {
  300. _Dcomplex pow={1.0,0.0}; unsigned long int u;
  301. if(n != 0) {
  302. if(n < 0) n = -n, x._Val[0] = 1/x._Val[0], x._Val[1] =1/x._Val[1];
  303. for(u = n; ; ) {
  304. if(u & 01) pow._Val[0] *= x._Val[0], pow._Val[1] *= x._Val[1];
  305. if(u >>= 1) x._Val[0] *= x._Val[0], x._Val[1] *= x._Val[1];
  306. else break;
  307. }
  308. }
  309. _Dcomplex p = {pow._Val[0], pow._Val[1]};
  310. return p;
  311. }
  312. #else
  313. static _Complex double zpow_ui(_Complex double x, integer n) {
  314. _Complex double pow=1.0; unsigned long int u;
  315. if(n != 0) {
  316. if(n < 0) n = -n, x = 1/x;
  317. for(u = n; ; ) {
  318. if(u & 01) pow *= x;
  319. if(u >>= 1) x *= x;
  320. else break;
  321. }
  322. }
  323. return pow;
  324. }
  325. #endif
  326. static integer pow_ii(integer x, integer n) {
  327. integer pow; unsigned long int u;
  328. if (n <= 0) {
  329. if (n == 0 || x == 1) pow = 1;
  330. else if (x != -1) pow = x == 0 ? 1/x : 0;
  331. else n = -n;
  332. }
  333. if ((n > 0) || !(n == 0 || x == 1 || x != -1)) {
  334. u = n;
  335. for(pow = 1; ; ) {
  336. if(u & 01) pow *= x;
  337. if(u >>= 1) x *= x;
  338. else break;
  339. }
  340. }
  341. return pow;
  342. }
  343. static integer dmaxloc_(double *w, integer s, integer e, integer *n)
  344. {
  345. double m; integer i, mi;
  346. for(m=w[s-1], mi=s, i=s+1; i<=e; i++)
  347. if (w[i-1]>m) mi=i ,m=w[i-1];
  348. return mi-s+1;
  349. }
  350. static integer smaxloc_(float *w, integer s, integer e, integer *n)
  351. {
  352. float m; integer i, mi;
  353. for(m=w[s-1], mi=s, i=s+1; i<=e; i++)
  354. if (w[i-1]>m) mi=i ,m=w[i-1];
  355. return mi-s+1;
  356. }
  357. static inline void cdotc_(complex *z, integer *n_, complex *x, integer *incx_, complex *y, integer *incy_) {
  358. integer n = *n_, incx = *incx_, incy = *incy_, i;
  359. #ifdef _MSC_VER
  360. _Fcomplex zdotc = {0.0, 0.0};
  361. if (incx == 1 && incy == 1) {
  362. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  363. zdotc._Val[0] += conjf(Cf(&x[i]))._Val[0] * Cf(&y[i])._Val[0];
  364. zdotc._Val[1] += conjf(Cf(&x[i]))._Val[1] * Cf(&y[i])._Val[1];
  365. }
  366. } else {
  367. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  368. zdotc._Val[0] += conjf(Cf(&x[i*incx]))._Val[0] * Cf(&y[i*incy])._Val[0];
  369. zdotc._Val[1] += conjf(Cf(&x[i*incx]))._Val[1] * Cf(&y[i*incy])._Val[1];
  370. }
  371. }
  372. pCf(z) = zdotc;
  373. }
  374. #else
  375. _Complex float zdotc = 0.0;
  376. if (incx == 1 && incy == 1) {
  377. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  378. zdotc += conjf(Cf(&x[i])) * Cf(&y[i]);
  379. }
  380. } else {
  381. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  382. zdotc += conjf(Cf(&x[i*incx])) * Cf(&y[i*incy]);
  383. }
  384. }
  385. pCf(z) = zdotc;
  386. }
  387. #endif
  388. static inline void zdotc_(doublecomplex *z, integer *n_, doublecomplex *x, integer *incx_, doublecomplex *y, integer *incy_) {
  389. integer n = *n_, incx = *incx_, incy = *incy_, i;
  390. #ifdef _MSC_VER
  391. _Dcomplex zdotc = {0.0, 0.0};
  392. if (incx == 1 && incy == 1) {
  393. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  394. zdotc._Val[0] += conj(Cd(&x[i]))._Val[0] * Cd(&y[i])._Val[0];
  395. zdotc._Val[1] += conj(Cd(&x[i]))._Val[1] * Cd(&y[i])._Val[1];
  396. }
  397. } else {
  398. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  399. zdotc._Val[0] += conj(Cd(&x[i*incx]))._Val[0] * Cd(&y[i*incy])._Val[0];
  400. zdotc._Val[1] += conj(Cd(&x[i*incx]))._Val[1] * Cd(&y[i*incy])._Val[1];
  401. }
  402. }
  403. pCd(z) = zdotc;
  404. }
  405. #else
  406. _Complex double zdotc = 0.0;
  407. if (incx == 1 && incy == 1) {
  408. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  409. zdotc += conj(Cd(&x[i])) * Cd(&y[i]);
  410. }
  411. } else {
  412. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  413. zdotc += conj(Cd(&x[i*incx])) * Cd(&y[i*incy]);
  414. }
  415. }
  416. pCd(z) = zdotc;
  417. }
  418. #endif
  419. static inline void cdotu_(complex *z, integer *n_, complex *x, integer *incx_, complex *y, integer *incy_) {
  420. integer n = *n_, incx = *incx_, incy = *incy_, i;
  421. #ifdef _MSC_VER
  422. _Fcomplex zdotc = {0.0, 0.0};
  423. if (incx == 1 && incy == 1) {
  424. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  425. zdotc._Val[0] += Cf(&x[i])._Val[0] * Cf(&y[i])._Val[0];
  426. zdotc._Val[1] += Cf(&x[i])._Val[1] * Cf(&y[i])._Val[1];
  427. }
  428. } else {
  429. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  430. zdotc._Val[0] += Cf(&x[i*incx])._Val[0] * Cf(&y[i*incy])._Val[0];
  431. zdotc._Val[1] += Cf(&x[i*incx])._Val[1] * Cf(&y[i*incy])._Val[1];
  432. }
  433. }
  434. pCf(z) = zdotc;
  435. }
  436. #else
  437. _Complex float zdotc = 0.0;
  438. if (incx == 1 && incy == 1) {
  439. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  440. zdotc += Cf(&x[i]) * Cf(&y[i]);
  441. }
  442. } else {
  443. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  444. zdotc += Cf(&x[i*incx]) * Cf(&y[i*incy]);
  445. }
  446. }
  447. pCf(z) = zdotc;
  448. }
  449. #endif
  450. static inline void zdotu_(doublecomplex *z, integer *n_, doublecomplex *x, integer *incx_, doublecomplex *y, integer *incy_) {
  451. integer n = *n_, incx = *incx_, incy = *incy_, i;
  452. #ifdef _MSC_VER
  453. _Dcomplex zdotc = {0.0, 0.0};
  454. if (incx == 1 && incy == 1) {
  455. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  456. zdotc._Val[0] += Cd(&x[i])._Val[0] * Cd(&y[i])._Val[0];
  457. zdotc._Val[1] += Cd(&x[i])._Val[1] * Cd(&y[i])._Val[1];
  458. }
  459. } else {
  460. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  461. zdotc._Val[0] += Cd(&x[i*incx])._Val[0] * Cd(&y[i*incy])._Val[0];
  462. zdotc._Val[1] += Cd(&x[i*incx])._Val[1] * Cd(&y[i*incy])._Val[1];
  463. }
  464. }
  465. pCd(z) = zdotc;
  466. }
  467. #else
  468. _Complex double zdotc = 0.0;
  469. if (incx == 1 && incy == 1) {
  470. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  471. zdotc += Cd(&x[i]) * Cd(&y[i]);
  472. }
  473. } else {
  474. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  475. zdotc += Cd(&x[i*incx]) * Cd(&y[i*incy]);
  476. }
  477. }
  478. pCd(z) = zdotc;
  479. }
  480. #endif
  481. /* -- translated by f2c (version 20000121).
  482. You must link the resulting object file with the libraries:
  483. -lf2c -lm (in that order)
  484. */
  485. /* Table of constant values */
  486. static logical c_true = TRUE_;
  487. static integer c__2 = 2;
  488. static doublereal c_b34 = 1.;
  489. static integer c__1 = 1;
  490. static doublereal c_b36 = 0.;
  491. static logical c_false = FALSE_;
  492. /* > \brief \b DTGEVC */
  493. /* =========== DOCUMENTATION =========== */
  494. /* Online html documentation available at */
  495. /* http://www.netlib.org/lapack/explore-html/ */
  496. /* > \htmlonly */
  497. /* > Download DTGEVC + dependencies */
  498. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/dtgevc.
  499. f"> */
  500. /* > [TGZ]</a> */
  501. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/dtgevc.
  502. f"> */
  503. /* > [ZIP]</a> */
  504. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/dtgevc.
  505. f"> */
  506. /* > [TXT]</a> */
  507. /* > \endhtmlonly */
  508. /* Definition: */
  509. /* =========== */
  510. /* SUBROUTINE DTGEVC( SIDE, HOWMNY, SELECT, N, S, LDS, P, LDP, VL, */
  511. /* LDVL, VR, LDVR, MM, M, WORK, INFO ) */
  512. /* CHARACTER HOWMNY, SIDE */
  513. /* INTEGER INFO, LDP, LDS, LDVL, LDVR, M, MM, N */
  514. /* LOGICAL SELECT( * ) */
  515. /* DOUBLE PRECISION P( LDP, * ), S( LDS, * ), VL( LDVL, * ), */
  516. /* $ VR( LDVR, * ), WORK( * ) */
  517. /* > \par Purpose: */
  518. /* ============= */
  519. /* > */
  520. /* > \verbatim */
  521. /* > */
  522. /* > DTGEVC computes some or all of the right and/or left eigenvectors of */
  523. /* > a pair of real matrices (S,P), where S is a quasi-triangular matrix */
  524. /* > and P is upper triangular. Matrix pairs of this type are produced by */
  525. /* > the generalized Schur factorization of a matrix pair (A,B): */
  526. /* > */
  527. /* > A = Q*S*Z**T, B = Q*P*Z**T */
  528. /* > */
  529. /* > as computed by DGGHRD + DHGEQZ. */
  530. /* > */
  531. /* > The right eigenvector x and the left eigenvector y of (S,P) */
  532. /* > corresponding to an eigenvalue w are defined by: */
  533. /* > */
  534. /* > S*x = w*P*x, (y**H)*S = w*(y**H)*P, */
  535. /* > */
  536. /* > where y**H denotes the conjugate tranpose of y. */
  537. /* > The eigenvalues are not input to this routine, but are computed */
  538. /* > directly from the diagonal blocks of S and P. */
  539. /* > */
  540. /* > This routine returns the matrices X and/or Y of right and left */
  541. /* > eigenvectors of (S,P), or the products Z*X and/or Q*Y, */
  542. /* > where Z and Q are input matrices. */
  543. /* > If Q and Z are the orthogonal factors from the generalized Schur */
  544. /* > factorization of a matrix pair (A,B), then Z*X and Q*Y */
  545. /* > are the matrices of right and left eigenvectors of (A,B). */
  546. /* > */
  547. /* > \endverbatim */
  548. /* Arguments: */
  549. /* ========== */
  550. /* > \param[in] SIDE */
  551. /* > \verbatim */
  552. /* > SIDE is CHARACTER*1 */
  553. /* > = 'R': compute right eigenvectors only; */
  554. /* > = 'L': compute left eigenvectors only; */
  555. /* > = 'B': compute both right and left eigenvectors. */
  556. /* > \endverbatim */
  557. /* > */
  558. /* > \param[in] HOWMNY */
  559. /* > \verbatim */
  560. /* > HOWMNY is CHARACTER*1 */
  561. /* > = 'A': compute all right and/or left eigenvectors; */
  562. /* > = 'B': compute all right and/or left eigenvectors, */
  563. /* > backtransformed by the matrices in VR and/or VL; */
  564. /* > = 'S': compute selected right and/or left eigenvectors, */
  565. /* > specified by the logical array SELECT. */
  566. /* > \endverbatim */
  567. /* > */
  568. /* > \param[in] SELECT */
  569. /* > \verbatim */
  570. /* > SELECT is LOGICAL array, dimension (N) */
  571. /* > If HOWMNY='S', SELECT specifies the eigenvectors to be */
  572. /* > computed. If w(j) is a real eigenvalue, the corresponding */
  573. /* > real eigenvector is computed if SELECT(j) is .TRUE.. */
  574. /* > If w(j) and w(j+1) are the real and imaginary parts of a */
  575. /* > complex eigenvalue, the corresponding complex eigenvector */
  576. /* > is computed if either SELECT(j) or SELECT(j+1) is .TRUE., */
  577. /* > and on exit SELECT(j) is set to .TRUE. and SELECT(j+1) is */
  578. /* > set to .FALSE.. */
  579. /* > Not referenced if HOWMNY = 'A' or 'B'. */
  580. /* > \endverbatim */
  581. /* > */
  582. /* > \param[in] N */
  583. /* > \verbatim */
  584. /* > N is INTEGER */
  585. /* > The order of the matrices S and P. N >= 0. */
  586. /* > \endverbatim */
  587. /* > */
  588. /* > \param[in] S */
  589. /* > \verbatim */
  590. /* > S is DOUBLE PRECISION array, dimension (LDS,N) */
  591. /* > The upper quasi-triangular matrix S from a generalized Schur */
  592. /* > factorization, as computed by DHGEQZ. */
  593. /* > \endverbatim */
  594. /* > */
  595. /* > \param[in] LDS */
  596. /* > \verbatim */
  597. /* > LDS is INTEGER */
  598. /* > The leading dimension of array S. LDS >= f2cmax(1,N). */
  599. /* > \endverbatim */
  600. /* > */
  601. /* > \param[in] P */
  602. /* > \verbatim */
  603. /* > P is DOUBLE PRECISION array, dimension (LDP,N) */
  604. /* > The upper triangular matrix P from a generalized Schur */
  605. /* > factorization, as computed by DHGEQZ. */
  606. /* > 2-by-2 diagonal blocks of P corresponding to 2-by-2 blocks */
  607. /* > of S must be in positive diagonal form. */
  608. /* > \endverbatim */
  609. /* > */
  610. /* > \param[in] LDP */
  611. /* > \verbatim */
  612. /* > LDP is INTEGER */
  613. /* > The leading dimension of array P. LDP >= f2cmax(1,N). */
  614. /* > \endverbatim */
  615. /* > */
  616. /* > \param[in,out] VL */
  617. /* > \verbatim */
  618. /* > VL is DOUBLE PRECISION array, dimension (LDVL,MM) */
  619. /* > On entry, if SIDE = 'L' or 'B' and HOWMNY = 'B', VL must */
  620. /* > contain an N-by-N matrix Q (usually the orthogonal matrix Q */
  621. /* > of left Schur vectors returned by DHGEQZ). */
  622. /* > On exit, if SIDE = 'L' or 'B', VL contains: */
  623. /* > if HOWMNY = 'A', the matrix Y of left eigenvectors of (S,P); */
  624. /* > if HOWMNY = 'B', the matrix Q*Y; */
  625. /* > if HOWMNY = 'S', the left eigenvectors of (S,P) specified by */
  626. /* > SELECT, stored consecutively in the columns of */
  627. /* > VL, in the same order as their eigenvalues. */
  628. /* > */
  629. /* > A complex eigenvector corresponding to a complex eigenvalue */
  630. /* > is stored in two consecutive columns, the first holding the */
  631. /* > real part, and the second the imaginary part. */
  632. /* > */
  633. /* > Not referenced if SIDE = 'R'. */
  634. /* > \endverbatim */
  635. /* > */
  636. /* > \param[in] LDVL */
  637. /* > \verbatim */
  638. /* > LDVL is INTEGER */
  639. /* > The leading dimension of array VL. LDVL >= 1, and if */
  640. /* > SIDE = 'L' or 'B', LDVL >= N. */
  641. /* > \endverbatim */
  642. /* > */
  643. /* > \param[in,out] VR */
  644. /* > \verbatim */
  645. /* > VR is DOUBLE PRECISION array, dimension (LDVR,MM) */
  646. /* > On entry, if SIDE = 'R' or 'B' and HOWMNY = 'B', VR must */
  647. /* > contain an N-by-N matrix Z (usually the orthogonal matrix Z */
  648. /* > of right Schur vectors returned by DHGEQZ). */
  649. /* > */
  650. /* > On exit, if SIDE = 'R' or 'B', VR contains: */
  651. /* > if HOWMNY = 'A', the matrix X of right eigenvectors of (S,P); */
  652. /* > if HOWMNY = 'B' or 'b', the matrix Z*X; */
  653. /* > if HOWMNY = 'S' or 's', the right eigenvectors of (S,P) */
  654. /* > specified by SELECT, stored consecutively in the */
  655. /* > columns of VR, in the same order as their */
  656. /* > eigenvalues. */
  657. /* > */
  658. /* > A complex eigenvector corresponding to a complex eigenvalue */
  659. /* > is stored in two consecutive columns, the first holding the */
  660. /* > real part and the second the imaginary part. */
  661. /* > */
  662. /* > Not referenced if SIDE = 'L'. */
  663. /* > \endverbatim */
  664. /* > */
  665. /* > \param[in] LDVR */
  666. /* > \verbatim */
  667. /* > LDVR is INTEGER */
  668. /* > The leading dimension of the array VR. LDVR >= 1, and if */
  669. /* > SIDE = 'R' or 'B', LDVR >= N. */
  670. /* > \endverbatim */
  671. /* > */
  672. /* > \param[in] MM */
  673. /* > \verbatim */
  674. /* > MM is INTEGER */
  675. /* > The number of columns in the arrays VL and/or VR. MM >= M. */
  676. /* > \endverbatim */
  677. /* > */
  678. /* > \param[out] M */
  679. /* > \verbatim */
  680. /* > M is INTEGER */
  681. /* > The number of columns in the arrays VL and/or VR actually */
  682. /* > used to store the eigenvectors. If HOWMNY = 'A' or 'B', M */
  683. /* > is set to N. Each selected real eigenvector occupies one */
  684. /* > column and each selected complex eigenvector occupies two */
  685. /* > columns. */
  686. /* > \endverbatim */
  687. /* > */
  688. /* > \param[out] WORK */
  689. /* > \verbatim */
  690. /* > WORK is DOUBLE PRECISION array, dimension (6*N) */
  691. /* > \endverbatim */
  692. /* > */
  693. /* > \param[out] INFO */
  694. /* > \verbatim */
  695. /* > INFO is INTEGER */
  696. /* > = 0: successful exit. */
  697. /* > < 0: if INFO = -i, the i-th argument had an illegal value. */
  698. /* > > 0: the 2-by-2 block (INFO:INFO+1) does not have a complex */
  699. /* > eigenvalue. */
  700. /* > \endverbatim */
  701. /* Authors: */
  702. /* ======== */
  703. /* > \author Univ. of Tennessee */
  704. /* > \author Univ. of California Berkeley */
  705. /* > \author Univ. of Colorado Denver */
  706. /* > \author NAG Ltd. */
  707. /* > \date December 2016 */
  708. /* > \ingroup doubleGEcomputational */
  709. /* > \par Further Details: */
  710. /* ===================== */
  711. /* > */
  712. /* > \verbatim */
  713. /* > */
  714. /* > Allocation of workspace: */
  715. /* > ---------- -- --------- */
  716. /* > */
  717. /* > WORK( j ) = 1-norm of j-th column of A, above the diagonal */
  718. /* > WORK( N+j ) = 1-norm of j-th column of B, above the diagonal */
  719. /* > WORK( 2*N+1:3*N ) = real part of eigenvector */
  720. /* > WORK( 3*N+1:4*N ) = imaginary part of eigenvector */
  721. /* > WORK( 4*N+1:5*N ) = real part of back-transformed eigenvector */
  722. /* > WORK( 5*N+1:6*N ) = imaginary part of back-transformed eigenvector */
  723. /* > */
  724. /* > Rowwise vs. columnwise solution methods: */
  725. /* > ------- -- ---------- -------- ------- */
  726. /* > */
  727. /* > Finding a generalized eigenvector consists basically of solving the */
  728. /* > singular triangular system */
  729. /* > */
  730. /* > (A - w B) x = 0 (for right) or: (A - w B)**H y = 0 (for left) */
  731. /* > */
  732. /* > Consider finding the i-th right eigenvector (assume all eigenvalues */
  733. /* > are real). The equation to be solved is: */
  734. /* > n i */
  735. /* > 0 = sum C(j,k) v(k) = sum C(j,k) v(k) for j = i,. . .,1 */
  736. /* > k=j k=j */
  737. /* > */
  738. /* > where C = (A - w B) (The components v(i+1:n) are 0.) */
  739. /* > */
  740. /* > The "rowwise" method is: */
  741. /* > */
  742. /* > (1) v(i) := 1 */
  743. /* > for j = i-1,. . .,1: */
  744. /* > i */
  745. /* > (2) compute s = - sum C(j,k) v(k) and */
  746. /* > k=j+1 */
  747. /* > */
  748. /* > (3) v(j) := s / C(j,j) */
  749. /* > */
  750. /* > Step 2 is sometimes called the "dot product" step, since it is an */
  751. /* > inner product between the j-th row and the portion of the eigenvector */
  752. /* > that has been computed so far. */
  753. /* > */
  754. /* > The "columnwise" method consists basically in doing the sums */
  755. /* > for all the rows in parallel. As each v(j) is computed, the */
  756. /* > contribution of v(j) times the j-th column of C is added to the */
  757. /* > partial sums. Since FORTRAN arrays are stored columnwise, this has */
  758. /* > the advantage that at each step, the elements of C that are accessed */
  759. /* > are adjacent to one another, whereas with the rowwise method, the */
  760. /* > elements accessed at a step are spaced LDS (and LDP) words apart. */
  761. /* > */
  762. /* > When finding left eigenvectors, the matrix in question is the */
  763. /* > transpose of the one in storage, so the rowwise method then */
  764. /* > actually accesses columns of A and B at each step, and so is the */
  765. /* > preferred method. */
  766. /* > \endverbatim */
  767. /* > */
  768. /* ===================================================================== */
  769. /* Subroutine */ void dtgevc_(char *side, char *howmny, logical *select,
  770. integer *n, doublereal *s, integer *lds, doublereal *p, integer *ldp,
  771. doublereal *vl, integer *ldvl, doublereal *vr, integer *ldvr, integer
  772. *mm, integer *m, doublereal *work, integer *info)
  773. {
  774. /* System generated locals */
  775. integer p_dim1, p_offset, s_dim1, s_offset, vl_dim1, vl_offset, vr_dim1,
  776. vr_offset, i__1, i__2, i__3, i__4, i__5;
  777. doublereal d__1, d__2, d__3, d__4, d__5, d__6;
  778. /* Local variables */
  779. integer ibeg, ieig, iend;
  780. doublereal dmin__, temp, xmax, sump[4] /* was [2][2] */, sums[4]
  781. /* was [2][2] */;
  782. extern /* Subroutine */ void dlag2_(doublereal *, integer *, doublereal *,
  783. integer *, doublereal *, doublereal *, doublereal *, doublereal *,
  784. doublereal *, doublereal *);
  785. doublereal cim2a, cim2b, cre2a, cre2b, temp2, bdiag[2];
  786. integer i__, j;
  787. doublereal acoef, scale;
  788. logical ilall;
  789. integer iside;
  790. doublereal sbeta;
  791. extern logical lsame_(char *, char *);
  792. extern /* Subroutine */ void dgemv_(char *, integer *, integer *,
  793. doublereal *, doublereal *, integer *, doublereal *, integer *,
  794. doublereal *, doublereal *, integer *);
  795. logical il2by2;
  796. integer iinfo;
  797. doublereal small;
  798. logical compl;
  799. doublereal anorm, bnorm;
  800. logical compr;
  801. extern /* Subroutine */ void dlaln2_(logical *, integer *, integer *,
  802. doublereal *, doublereal *, doublereal *, integer *, doublereal *,
  803. doublereal *, doublereal *, integer *, doublereal *, doublereal *
  804. , doublereal *, integer *, doublereal *, doublereal *, integer *);
  805. doublereal temp2i;
  806. extern /* Subroutine */ void dlabad_(doublereal *, doublereal *);
  807. doublereal temp2r;
  808. integer ja;
  809. logical ilabad, ilbbad;
  810. integer jc, je, na;
  811. doublereal acoefa, bcoefa, cimaga, cimagb;
  812. logical ilback;
  813. integer im;
  814. doublereal bcoefi, ascale, bscale, creala;
  815. integer jr;
  816. doublereal crealb;
  817. extern doublereal dlamch_(char *);
  818. doublereal bcoefr;
  819. integer jw, nw;
  820. doublereal salfar, safmin;
  821. extern /* Subroutine */ void dlacpy_(char *, integer *, integer *,
  822. doublereal *, integer *, doublereal *, integer *);
  823. doublereal xscale, bignum;
  824. extern /* Subroutine */ int xerbla_(char *, integer *, ftnlen);
  825. logical ilcomp, ilcplx;
  826. integer ihwmny;
  827. doublereal big;
  828. logical lsa, lsb;
  829. doublereal ulp, sum[4] /* was [2][2] */;
  830. /* -- LAPACK computational routine (version 3.7.0) -- */
  831. /* -- LAPACK is a software package provided by Univ. of Tennessee, -- */
  832. /* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- */
  833. /* December 2016 */
  834. /* ===================================================================== */
  835. /* Decode and Test the input parameters */
  836. /* Parameter adjustments */
  837. --select;
  838. s_dim1 = *lds;
  839. s_offset = 1 + s_dim1 * 1;
  840. s -= s_offset;
  841. p_dim1 = *ldp;
  842. p_offset = 1 + p_dim1 * 1;
  843. p -= p_offset;
  844. vl_dim1 = *ldvl;
  845. vl_offset = 1 + vl_dim1 * 1;
  846. vl -= vl_offset;
  847. vr_dim1 = *ldvr;
  848. vr_offset = 1 + vr_dim1 * 1;
  849. vr -= vr_offset;
  850. --work;
  851. /* Function Body */
  852. if (lsame_(howmny, "A")) {
  853. ihwmny = 1;
  854. ilall = TRUE_;
  855. ilback = FALSE_;
  856. } else if (lsame_(howmny, "S")) {
  857. ihwmny = 2;
  858. ilall = FALSE_;
  859. ilback = FALSE_;
  860. } else if (lsame_(howmny, "B")) {
  861. ihwmny = 3;
  862. ilall = TRUE_;
  863. ilback = TRUE_;
  864. } else {
  865. ihwmny = -1;
  866. ilall = TRUE_;
  867. }
  868. if (lsame_(side, "R")) {
  869. iside = 1;
  870. compl = FALSE_;
  871. compr = TRUE_;
  872. } else if (lsame_(side, "L")) {
  873. iside = 2;
  874. compl = TRUE_;
  875. compr = FALSE_;
  876. } else if (lsame_(side, "B")) {
  877. iside = 3;
  878. compl = TRUE_;
  879. compr = TRUE_;
  880. } else {
  881. iside = -1;
  882. }
  883. *info = 0;
  884. if (iside < 0) {
  885. *info = -1;
  886. } else if (ihwmny < 0) {
  887. *info = -2;
  888. } else if (*n < 0) {
  889. *info = -4;
  890. } else if (*lds < f2cmax(1,*n)) {
  891. *info = -6;
  892. } else if (*ldp < f2cmax(1,*n)) {
  893. *info = -8;
  894. }
  895. if (*info != 0) {
  896. i__1 = -(*info);
  897. xerbla_("DTGEVC", &i__1, (ftnlen)6);
  898. return;
  899. }
  900. /* Count the number of eigenvectors to be computed */
  901. if (! ilall) {
  902. im = 0;
  903. ilcplx = FALSE_;
  904. i__1 = *n;
  905. for (j = 1; j <= i__1; ++j) {
  906. if (ilcplx) {
  907. ilcplx = FALSE_;
  908. goto L10;
  909. }
  910. if (j < *n) {
  911. if (s[j + 1 + j * s_dim1] != 0.) {
  912. ilcplx = TRUE_;
  913. }
  914. }
  915. if (ilcplx) {
  916. if (select[j] || select[j + 1]) {
  917. im += 2;
  918. }
  919. } else {
  920. if (select[j]) {
  921. ++im;
  922. }
  923. }
  924. L10:
  925. ;
  926. }
  927. } else {
  928. im = *n;
  929. }
  930. /* Check 2-by-2 diagonal blocks of A, B */
  931. ilabad = FALSE_;
  932. ilbbad = FALSE_;
  933. i__1 = *n - 1;
  934. for (j = 1; j <= i__1; ++j) {
  935. if (s[j + 1 + j * s_dim1] != 0.) {
  936. if (p[j + j * p_dim1] == 0. || p[j + 1 + (j + 1) * p_dim1] == 0.
  937. || p[j + (j + 1) * p_dim1] != 0.) {
  938. ilbbad = TRUE_;
  939. }
  940. if (j < *n - 1) {
  941. if (s[j + 2 + (j + 1) * s_dim1] != 0.) {
  942. ilabad = TRUE_;
  943. }
  944. }
  945. }
  946. /* L20: */
  947. }
  948. if (ilabad) {
  949. *info = -5;
  950. } else if (ilbbad) {
  951. *info = -7;
  952. } else if (compl && *ldvl < *n || *ldvl < 1) {
  953. *info = -10;
  954. } else if (compr && *ldvr < *n || *ldvr < 1) {
  955. *info = -12;
  956. } else if (*mm < im) {
  957. *info = -13;
  958. }
  959. if (*info != 0) {
  960. i__1 = -(*info);
  961. xerbla_("DTGEVC", &i__1, (ftnlen)6);
  962. return;
  963. }
  964. /* Quick return if possible */
  965. *m = im;
  966. if (*n == 0) {
  967. return;
  968. }
  969. /* Machine Constants */
  970. safmin = dlamch_("Safe minimum");
  971. big = 1. / safmin;
  972. dlabad_(&safmin, &big);
  973. ulp = dlamch_("Epsilon") * dlamch_("Base");
  974. small = safmin * *n / ulp;
  975. big = 1. / small;
  976. bignum = 1. / (safmin * *n);
  977. /* Compute the 1-norm of each column of the strictly upper triangular */
  978. /* part (i.e., excluding all elements belonging to the diagonal */
  979. /* blocks) of A and B to check for possible overflow in the */
  980. /* triangular solver. */
  981. anorm = (d__1 = s[s_dim1 + 1], abs(d__1));
  982. if (*n > 1) {
  983. anorm += (d__1 = s[s_dim1 + 2], abs(d__1));
  984. }
  985. bnorm = (d__1 = p[p_dim1 + 1], abs(d__1));
  986. work[1] = 0.;
  987. work[*n + 1] = 0.;
  988. i__1 = *n;
  989. for (j = 2; j <= i__1; ++j) {
  990. temp = 0.;
  991. temp2 = 0.;
  992. if (s[j + (j - 1) * s_dim1] == 0.) {
  993. iend = j - 1;
  994. } else {
  995. iend = j - 2;
  996. }
  997. i__2 = iend;
  998. for (i__ = 1; i__ <= i__2; ++i__) {
  999. temp += (d__1 = s[i__ + j * s_dim1], abs(d__1));
  1000. temp2 += (d__1 = p[i__ + j * p_dim1], abs(d__1));
  1001. /* L30: */
  1002. }
  1003. work[j] = temp;
  1004. work[*n + j] = temp2;
  1005. /* Computing MIN */
  1006. i__3 = j + 1;
  1007. i__2 = f2cmin(i__3,*n);
  1008. for (i__ = iend + 1; i__ <= i__2; ++i__) {
  1009. temp += (d__1 = s[i__ + j * s_dim1], abs(d__1));
  1010. temp2 += (d__1 = p[i__ + j * p_dim1], abs(d__1));
  1011. /* L40: */
  1012. }
  1013. anorm = f2cmax(anorm,temp);
  1014. bnorm = f2cmax(bnorm,temp2);
  1015. /* L50: */
  1016. }
  1017. ascale = 1. / f2cmax(anorm,safmin);
  1018. bscale = 1. / f2cmax(bnorm,safmin);
  1019. /* Left eigenvectors */
  1020. if (compl) {
  1021. ieig = 0;
  1022. /* Main loop over eigenvalues */
  1023. ilcplx = FALSE_;
  1024. i__1 = *n;
  1025. for (je = 1; je <= i__1; ++je) {
  1026. /* Skip this iteration if (a) HOWMNY='S' and SELECT=.FALSE., or */
  1027. /* (b) this would be the second of a complex pair. */
  1028. /* Check for complex eigenvalue, so as to be sure of which */
  1029. /* entry(-ies) of SELECT to look at. */
  1030. if (ilcplx) {
  1031. ilcplx = FALSE_;
  1032. goto L220;
  1033. }
  1034. nw = 1;
  1035. if (je < *n) {
  1036. if (s[je + 1 + je * s_dim1] != 0.) {
  1037. ilcplx = TRUE_;
  1038. nw = 2;
  1039. }
  1040. }
  1041. if (ilall) {
  1042. ilcomp = TRUE_;
  1043. } else if (ilcplx) {
  1044. ilcomp = select[je] || select[je + 1];
  1045. } else {
  1046. ilcomp = select[je];
  1047. }
  1048. if (! ilcomp) {
  1049. goto L220;
  1050. }
  1051. /* Decide if (a) singular pencil, (b) real eigenvalue, or */
  1052. /* (c) complex eigenvalue. */
  1053. if (! ilcplx) {
  1054. if ((d__1 = s[je + je * s_dim1], abs(d__1)) <= safmin && (
  1055. d__2 = p[je + je * p_dim1], abs(d__2)) <= safmin) {
  1056. /* Singular matrix pencil -- return unit eigenvector */
  1057. ++ieig;
  1058. i__2 = *n;
  1059. for (jr = 1; jr <= i__2; ++jr) {
  1060. vl[jr + ieig * vl_dim1] = 0.;
  1061. /* L60: */
  1062. }
  1063. vl[ieig + ieig * vl_dim1] = 1.;
  1064. goto L220;
  1065. }
  1066. }
  1067. /* Clear vector */
  1068. i__2 = nw * *n;
  1069. for (jr = 1; jr <= i__2; ++jr) {
  1070. work[(*n << 1) + jr] = 0.;
  1071. /* L70: */
  1072. }
  1073. /* T */
  1074. /* Compute coefficients in ( a A - b B ) y = 0 */
  1075. /* a is ACOEF */
  1076. /* b is BCOEFR + i*BCOEFI */
  1077. if (! ilcplx) {
  1078. /* Real eigenvalue */
  1079. /* Computing MAX */
  1080. d__3 = (d__1 = s[je + je * s_dim1], abs(d__1)) * ascale, d__4
  1081. = (d__2 = p[je + je * p_dim1], abs(d__2)) * bscale,
  1082. d__3 = f2cmax(d__3,d__4);
  1083. temp = 1. / f2cmax(d__3,safmin);
  1084. salfar = temp * s[je + je * s_dim1] * ascale;
  1085. sbeta = temp * p[je + je * p_dim1] * bscale;
  1086. acoef = sbeta * ascale;
  1087. bcoefr = salfar * bscale;
  1088. bcoefi = 0.;
  1089. /* Scale to avoid underflow */
  1090. scale = 1.;
  1091. lsa = abs(sbeta) >= safmin && abs(acoef) < small;
  1092. lsb = abs(salfar) >= safmin && abs(bcoefr) < small;
  1093. if (lsa) {
  1094. scale = small / abs(sbeta) * f2cmin(anorm,big);
  1095. }
  1096. if (lsb) {
  1097. /* Computing MAX */
  1098. d__1 = scale, d__2 = small / abs(salfar) * f2cmin(bnorm,big);
  1099. scale = f2cmax(d__1,d__2);
  1100. }
  1101. if (lsa || lsb) {
  1102. /* Computing MIN */
  1103. /* Computing MAX */
  1104. d__3 = 1., d__4 = abs(acoef), d__3 = f2cmax(d__3,d__4), d__4
  1105. = abs(bcoefr);
  1106. d__1 = scale, d__2 = 1. / (safmin * f2cmax(d__3,d__4));
  1107. scale = f2cmin(d__1,d__2);
  1108. if (lsa) {
  1109. acoef = ascale * (scale * sbeta);
  1110. } else {
  1111. acoef = scale * acoef;
  1112. }
  1113. if (lsb) {
  1114. bcoefr = bscale * (scale * salfar);
  1115. } else {
  1116. bcoefr = scale * bcoefr;
  1117. }
  1118. }
  1119. acoefa = abs(acoef);
  1120. bcoefa = abs(bcoefr);
  1121. /* First component is 1 */
  1122. work[(*n << 1) + je] = 1.;
  1123. xmax = 1.;
  1124. } else {
  1125. /* Complex eigenvalue */
  1126. d__1 = safmin * 100.;
  1127. dlag2_(&s[je + je * s_dim1], lds, &p[je + je * p_dim1], ldp, &
  1128. d__1, &acoef, &temp, &bcoefr, &temp2, &bcoefi);
  1129. bcoefi = -bcoefi;
  1130. if (bcoefi == 0.) {
  1131. *info = je;
  1132. return;
  1133. }
  1134. /* Scale to avoid over/underflow */
  1135. acoefa = abs(acoef);
  1136. bcoefa = abs(bcoefr) + abs(bcoefi);
  1137. scale = 1.;
  1138. if (acoefa * ulp < safmin && acoefa >= safmin) {
  1139. scale = safmin / ulp / acoefa;
  1140. }
  1141. if (bcoefa * ulp < safmin && bcoefa >= safmin) {
  1142. /* Computing MAX */
  1143. d__1 = scale, d__2 = safmin / ulp / bcoefa;
  1144. scale = f2cmax(d__1,d__2);
  1145. }
  1146. if (safmin * acoefa > ascale) {
  1147. scale = ascale / (safmin * acoefa);
  1148. }
  1149. if (safmin * bcoefa > bscale) {
  1150. /* Computing MIN */
  1151. d__1 = scale, d__2 = bscale / (safmin * bcoefa);
  1152. scale = f2cmin(d__1,d__2);
  1153. }
  1154. if (scale != 1.) {
  1155. acoef = scale * acoef;
  1156. acoefa = abs(acoef);
  1157. bcoefr = scale * bcoefr;
  1158. bcoefi = scale * bcoefi;
  1159. bcoefa = abs(bcoefr) + abs(bcoefi);
  1160. }
  1161. /* Compute first two components of eigenvector */
  1162. temp = acoef * s[je + 1 + je * s_dim1];
  1163. temp2r = acoef * s[je + je * s_dim1] - bcoefr * p[je + je *
  1164. p_dim1];
  1165. temp2i = -bcoefi * p[je + je * p_dim1];
  1166. if (abs(temp) > abs(temp2r) + abs(temp2i)) {
  1167. work[(*n << 1) + je] = 1.;
  1168. work[*n * 3 + je] = 0.;
  1169. work[(*n << 1) + je + 1] = -temp2r / temp;
  1170. work[*n * 3 + je + 1] = -temp2i / temp;
  1171. } else {
  1172. work[(*n << 1) + je + 1] = 1.;
  1173. work[*n * 3 + je + 1] = 0.;
  1174. temp = acoef * s[je + (je + 1) * s_dim1];
  1175. work[(*n << 1) + je] = (bcoefr * p[je + 1 + (je + 1) *
  1176. p_dim1] - acoef * s[je + 1 + (je + 1) * s_dim1]) /
  1177. temp;
  1178. work[*n * 3 + je] = bcoefi * p[je + 1 + (je + 1) * p_dim1]
  1179. / temp;
  1180. }
  1181. /* Computing MAX */
  1182. d__5 = (d__1 = work[(*n << 1) + je], abs(d__1)) + (d__2 =
  1183. work[*n * 3 + je], abs(d__2)), d__6 = (d__3 = work[(*
  1184. n << 1) + je + 1], abs(d__3)) + (d__4 = work[*n * 3 +
  1185. je + 1], abs(d__4));
  1186. xmax = f2cmax(d__5,d__6);
  1187. }
  1188. /* Computing MAX */
  1189. d__1 = ulp * acoefa * anorm, d__2 = ulp * bcoefa * bnorm, d__1 =
  1190. f2cmax(d__1,d__2);
  1191. dmin__ = f2cmax(d__1,safmin);
  1192. /* T */
  1193. /* Triangular solve of (a A - b B) y = 0 */
  1194. /* T */
  1195. /* (rowwise in (a A - b B) , or columnwise in (a A - b B) ) */
  1196. il2by2 = FALSE_;
  1197. i__2 = *n;
  1198. for (j = je + nw; j <= i__2; ++j) {
  1199. if (il2by2) {
  1200. il2by2 = FALSE_;
  1201. goto L160;
  1202. }
  1203. na = 1;
  1204. bdiag[0] = p[j + j * p_dim1];
  1205. if (j < *n) {
  1206. if (s[j + 1 + j * s_dim1] != 0.) {
  1207. il2by2 = TRUE_;
  1208. bdiag[1] = p[j + 1 + (j + 1) * p_dim1];
  1209. na = 2;
  1210. }
  1211. }
  1212. /* Check whether scaling is necessary for dot products */
  1213. xscale = 1. / f2cmax(1.,xmax);
  1214. /* Computing MAX */
  1215. d__1 = work[j], d__2 = work[*n + j], d__1 = f2cmax(d__1,d__2),
  1216. d__2 = acoefa * work[j] + bcoefa * work[*n + j];
  1217. temp = f2cmax(d__1,d__2);
  1218. if (il2by2) {
  1219. /* Computing MAX */
  1220. d__1 = temp, d__2 = work[j + 1], d__1 = f2cmax(d__1,d__2),
  1221. d__2 = work[*n + j + 1], d__1 = f2cmax(d__1,d__2),
  1222. d__2 = acoefa * work[j + 1] + bcoefa * work[*n +
  1223. j + 1];
  1224. temp = f2cmax(d__1,d__2);
  1225. }
  1226. if (temp > bignum * xscale) {
  1227. i__3 = nw - 1;
  1228. for (jw = 0; jw <= i__3; ++jw) {
  1229. i__4 = j - 1;
  1230. for (jr = je; jr <= i__4; ++jr) {
  1231. work[(jw + 2) * *n + jr] = xscale * work[(jw + 2)
  1232. * *n + jr];
  1233. /* L80: */
  1234. }
  1235. /* L90: */
  1236. }
  1237. xmax *= xscale;
  1238. }
  1239. /* Compute dot products */
  1240. /* j-1 */
  1241. /* SUM = sum conjg( a*S(k,j) - b*P(k,j) )*x(k) */
  1242. /* k=je */
  1243. /* To reduce the op count, this is done as */
  1244. /* _ j-1 _ j-1 */
  1245. /* a*conjg( sum S(k,j)*x(k) ) - b*conjg( sum P(k,j)*x(k) ) */
  1246. /* k=je k=je */
  1247. /* which may cause underflow problems if A or B are close */
  1248. /* to underflow. (E.g., less than SMALL.) */
  1249. i__3 = nw;
  1250. for (jw = 1; jw <= i__3; ++jw) {
  1251. i__4 = na;
  1252. for (ja = 1; ja <= i__4; ++ja) {
  1253. sums[ja + (jw << 1) - 3] = 0.;
  1254. sump[ja + (jw << 1) - 3] = 0.;
  1255. i__5 = j - 1;
  1256. for (jr = je; jr <= i__5; ++jr) {
  1257. sums[ja + (jw << 1) - 3] += s[jr + (j + ja - 1) *
  1258. s_dim1] * work[(jw + 1) * *n + jr];
  1259. sump[ja + (jw << 1) - 3] += p[jr + (j + ja - 1) *
  1260. p_dim1] * work[(jw + 1) * *n + jr];
  1261. /* L100: */
  1262. }
  1263. /* L110: */
  1264. }
  1265. /* L120: */
  1266. }
  1267. i__3 = na;
  1268. for (ja = 1; ja <= i__3; ++ja) {
  1269. if (ilcplx) {
  1270. sum[ja - 1] = -acoef * sums[ja - 1] + bcoefr * sump[
  1271. ja - 1] - bcoefi * sump[ja + 1];
  1272. sum[ja + 1] = -acoef * sums[ja + 1] + bcoefr * sump[
  1273. ja + 1] + bcoefi * sump[ja - 1];
  1274. } else {
  1275. sum[ja - 1] = -acoef * sums[ja - 1] + bcoefr * sump[
  1276. ja - 1];
  1277. }
  1278. /* L130: */
  1279. }
  1280. /* T */
  1281. /* Solve ( a A - b B ) y = SUM(,) */
  1282. /* with scaling and perturbation of the denominator */
  1283. dlaln2_(&c_true, &na, &nw, &dmin__, &acoef, &s[j + j * s_dim1]
  1284. , lds, bdiag, &bdiag[1], sum, &c__2, &bcoefr, &bcoefi,
  1285. &work[(*n << 1) + j], n, &scale, &temp, &iinfo);
  1286. if (scale < 1.) {
  1287. i__3 = nw - 1;
  1288. for (jw = 0; jw <= i__3; ++jw) {
  1289. i__4 = j - 1;
  1290. for (jr = je; jr <= i__4; ++jr) {
  1291. work[(jw + 2) * *n + jr] = scale * work[(jw + 2) *
  1292. *n + jr];
  1293. /* L140: */
  1294. }
  1295. /* L150: */
  1296. }
  1297. xmax = scale * xmax;
  1298. }
  1299. xmax = f2cmax(xmax,temp);
  1300. L160:
  1301. ;
  1302. }
  1303. /* Copy eigenvector to VL, back transforming if */
  1304. /* HOWMNY='B'. */
  1305. ++ieig;
  1306. if (ilback) {
  1307. i__2 = nw - 1;
  1308. for (jw = 0; jw <= i__2; ++jw) {
  1309. i__3 = *n + 1 - je;
  1310. dgemv_("N", n, &i__3, &c_b34, &vl[je * vl_dim1 + 1], ldvl,
  1311. &work[(jw + 2) * *n + je], &c__1, &c_b36, &work[(
  1312. jw + 4) * *n + 1], &c__1);
  1313. /* L170: */
  1314. }
  1315. dlacpy_(" ", n, &nw, &work[(*n << 2) + 1], n, &vl[je *
  1316. vl_dim1 + 1], ldvl);
  1317. ibeg = 1;
  1318. } else {
  1319. dlacpy_(" ", n, &nw, &work[(*n << 1) + 1], n, &vl[ieig *
  1320. vl_dim1 + 1], ldvl);
  1321. ibeg = je;
  1322. }
  1323. /* Scale eigenvector */
  1324. xmax = 0.;
  1325. if (ilcplx) {
  1326. i__2 = *n;
  1327. for (j = ibeg; j <= i__2; ++j) {
  1328. /* Computing MAX */
  1329. d__3 = xmax, d__4 = (d__1 = vl[j + ieig * vl_dim1], abs(
  1330. d__1)) + (d__2 = vl[j + (ieig + 1) * vl_dim1],
  1331. abs(d__2));
  1332. xmax = f2cmax(d__3,d__4);
  1333. /* L180: */
  1334. }
  1335. } else {
  1336. i__2 = *n;
  1337. for (j = ibeg; j <= i__2; ++j) {
  1338. /* Computing MAX */
  1339. d__2 = xmax, d__3 = (d__1 = vl[j + ieig * vl_dim1], abs(
  1340. d__1));
  1341. xmax = f2cmax(d__2,d__3);
  1342. /* L190: */
  1343. }
  1344. }
  1345. if (xmax > safmin) {
  1346. xscale = 1. / xmax;
  1347. i__2 = nw - 1;
  1348. for (jw = 0; jw <= i__2; ++jw) {
  1349. i__3 = *n;
  1350. for (jr = ibeg; jr <= i__3; ++jr) {
  1351. vl[jr + (ieig + jw) * vl_dim1] = xscale * vl[jr + (
  1352. ieig + jw) * vl_dim1];
  1353. /* L200: */
  1354. }
  1355. /* L210: */
  1356. }
  1357. }
  1358. ieig = ieig + nw - 1;
  1359. L220:
  1360. ;
  1361. }
  1362. }
  1363. /* Right eigenvectors */
  1364. if (compr) {
  1365. ieig = im + 1;
  1366. /* Main loop over eigenvalues */
  1367. ilcplx = FALSE_;
  1368. for (je = *n; je >= 1; --je) {
  1369. /* Skip this iteration if (a) HOWMNY='S' and SELECT=.FALSE., or */
  1370. /* (b) this would be the second of a complex pair. */
  1371. /* Check for complex eigenvalue, so as to be sure of which */
  1372. /* entry(-ies) of SELECT to look at -- if complex, SELECT(JE) */
  1373. /* or SELECT(JE-1). */
  1374. /* If this is a complex pair, the 2-by-2 diagonal block */
  1375. /* corresponding to the eigenvalue is in rows/columns JE-1:JE */
  1376. if (ilcplx) {
  1377. ilcplx = FALSE_;
  1378. goto L500;
  1379. }
  1380. nw = 1;
  1381. if (je > 1) {
  1382. if (s[je + (je - 1) * s_dim1] != 0.) {
  1383. ilcplx = TRUE_;
  1384. nw = 2;
  1385. }
  1386. }
  1387. if (ilall) {
  1388. ilcomp = TRUE_;
  1389. } else if (ilcplx) {
  1390. ilcomp = select[je] || select[je - 1];
  1391. } else {
  1392. ilcomp = select[je];
  1393. }
  1394. if (! ilcomp) {
  1395. goto L500;
  1396. }
  1397. /* Decide if (a) singular pencil, (b) real eigenvalue, or */
  1398. /* (c) complex eigenvalue. */
  1399. if (! ilcplx) {
  1400. if ((d__1 = s[je + je * s_dim1], abs(d__1)) <= safmin && (
  1401. d__2 = p[je + je * p_dim1], abs(d__2)) <= safmin) {
  1402. /* Singular matrix pencil -- unit eigenvector */
  1403. --ieig;
  1404. i__1 = *n;
  1405. for (jr = 1; jr <= i__1; ++jr) {
  1406. vr[jr + ieig * vr_dim1] = 0.;
  1407. /* L230: */
  1408. }
  1409. vr[ieig + ieig * vr_dim1] = 1.;
  1410. goto L500;
  1411. }
  1412. }
  1413. /* Clear vector */
  1414. i__1 = nw - 1;
  1415. for (jw = 0; jw <= i__1; ++jw) {
  1416. i__2 = *n;
  1417. for (jr = 1; jr <= i__2; ++jr) {
  1418. work[(jw + 2) * *n + jr] = 0.;
  1419. /* L240: */
  1420. }
  1421. /* L250: */
  1422. }
  1423. /* Compute coefficients in ( a A - b B ) x = 0 */
  1424. /* a is ACOEF */
  1425. /* b is BCOEFR + i*BCOEFI */
  1426. if (! ilcplx) {
  1427. /* Real eigenvalue */
  1428. /* Computing MAX */
  1429. d__3 = (d__1 = s[je + je * s_dim1], abs(d__1)) * ascale, d__4
  1430. = (d__2 = p[je + je * p_dim1], abs(d__2)) * bscale,
  1431. d__3 = f2cmax(d__3,d__4);
  1432. temp = 1. / f2cmax(d__3,safmin);
  1433. salfar = temp * s[je + je * s_dim1] * ascale;
  1434. sbeta = temp * p[je + je * p_dim1] * bscale;
  1435. acoef = sbeta * ascale;
  1436. bcoefr = salfar * bscale;
  1437. bcoefi = 0.;
  1438. /* Scale to avoid underflow */
  1439. scale = 1.;
  1440. lsa = abs(sbeta) >= safmin && abs(acoef) < small;
  1441. lsb = abs(salfar) >= safmin && abs(bcoefr) < small;
  1442. if (lsa) {
  1443. scale = small / abs(sbeta) * f2cmin(anorm,big);
  1444. }
  1445. if (lsb) {
  1446. /* Computing MAX */
  1447. d__1 = scale, d__2 = small / abs(salfar) * f2cmin(bnorm,big);
  1448. scale = f2cmax(d__1,d__2);
  1449. }
  1450. if (lsa || lsb) {
  1451. /* Computing MIN */
  1452. /* Computing MAX */
  1453. d__3 = 1., d__4 = abs(acoef), d__3 = f2cmax(d__3,d__4), d__4
  1454. = abs(bcoefr);
  1455. d__1 = scale, d__2 = 1. / (safmin * f2cmax(d__3,d__4));
  1456. scale = f2cmin(d__1,d__2);
  1457. if (lsa) {
  1458. acoef = ascale * (scale * sbeta);
  1459. } else {
  1460. acoef = scale * acoef;
  1461. }
  1462. if (lsb) {
  1463. bcoefr = bscale * (scale * salfar);
  1464. } else {
  1465. bcoefr = scale * bcoefr;
  1466. }
  1467. }
  1468. acoefa = abs(acoef);
  1469. bcoefa = abs(bcoefr);
  1470. /* First component is 1 */
  1471. work[(*n << 1) + je] = 1.;
  1472. xmax = 1.;
  1473. /* Compute contribution from column JE of A and B to sum */
  1474. /* (See "Further Details", above.) */
  1475. i__1 = je - 1;
  1476. for (jr = 1; jr <= i__1; ++jr) {
  1477. work[(*n << 1) + jr] = bcoefr * p[jr + je * p_dim1] -
  1478. acoef * s[jr + je * s_dim1];
  1479. /* L260: */
  1480. }
  1481. } else {
  1482. /* Complex eigenvalue */
  1483. d__1 = safmin * 100.;
  1484. dlag2_(&s[je - 1 + (je - 1) * s_dim1], lds, &p[je - 1 + (je -
  1485. 1) * p_dim1], ldp, &d__1, &acoef, &temp, &bcoefr, &
  1486. temp2, &bcoefi);
  1487. if (bcoefi == 0.) {
  1488. *info = je - 1;
  1489. return;
  1490. }
  1491. /* Scale to avoid over/underflow */
  1492. acoefa = abs(acoef);
  1493. bcoefa = abs(bcoefr) + abs(bcoefi);
  1494. scale = 1.;
  1495. if (acoefa * ulp < safmin && acoefa >= safmin) {
  1496. scale = safmin / ulp / acoefa;
  1497. }
  1498. if (bcoefa * ulp < safmin && bcoefa >= safmin) {
  1499. /* Computing MAX */
  1500. d__1 = scale, d__2 = safmin / ulp / bcoefa;
  1501. scale = f2cmax(d__1,d__2);
  1502. }
  1503. if (safmin * acoefa > ascale) {
  1504. scale = ascale / (safmin * acoefa);
  1505. }
  1506. if (safmin * bcoefa > bscale) {
  1507. /* Computing MIN */
  1508. d__1 = scale, d__2 = bscale / (safmin * bcoefa);
  1509. scale = f2cmin(d__1,d__2);
  1510. }
  1511. if (scale != 1.) {
  1512. acoef = scale * acoef;
  1513. acoefa = abs(acoef);
  1514. bcoefr = scale * bcoefr;
  1515. bcoefi = scale * bcoefi;
  1516. bcoefa = abs(bcoefr) + abs(bcoefi);
  1517. }
  1518. /* Compute first two components of eigenvector */
  1519. /* and contribution to sums */
  1520. temp = acoef * s[je + (je - 1) * s_dim1];
  1521. temp2r = acoef * s[je + je * s_dim1] - bcoefr * p[je + je *
  1522. p_dim1];
  1523. temp2i = -bcoefi * p[je + je * p_dim1];
  1524. if (abs(temp) >= abs(temp2r) + abs(temp2i)) {
  1525. work[(*n << 1) + je] = 1.;
  1526. work[*n * 3 + je] = 0.;
  1527. work[(*n << 1) + je - 1] = -temp2r / temp;
  1528. work[*n * 3 + je - 1] = -temp2i / temp;
  1529. } else {
  1530. work[(*n << 1) + je - 1] = 1.;
  1531. work[*n * 3 + je - 1] = 0.;
  1532. temp = acoef * s[je - 1 + je * s_dim1];
  1533. work[(*n << 1) + je] = (bcoefr * p[je - 1 + (je - 1) *
  1534. p_dim1] - acoef * s[je - 1 + (je - 1) * s_dim1]) /
  1535. temp;
  1536. work[*n * 3 + je] = bcoefi * p[je - 1 + (je - 1) * p_dim1]
  1537. / temp;
  1538. }
  1539. /* Computing MAX */
  1540. d__5 = (d__1 = work[(*n << 1) + je], abs(d__1)) + (d__2 =
  1541. work[*n * 3 + je], abs(d__2)), d__6 = (d__3 = work[(*
  1542. n << 1) + je - 1], abs(d__3)) + (d__4 = work[*n * 3 +
  1543. je - 1], abs(d__4));
  1544. xmax = f2cmax(d__5,d__6);
  1545. /* Compute contribution from columns JE and JE-1 */
  1546. /* of A and B to the sums. */
  1547. creala = acoef * work[(*n << 1) + je - 1];
  1548. cimaga = acoef * work[*n * 3 + je - 1];
  1549. crealb = bcoefr * work[(*n << 1) + je - 1] - bcoefi * work[*n
  1550. * 3 + je - 1];
  1551. cimagb = bcoefi * work[(*n << 1) + je - 1] + bcoefr * work[*n
  1552. * 3 + je - 1];
  1553. cre2a = acoef * work[(*n << 1) + je];
  1554. cim2a = acoef * work[*n * 3 + je];
  1555. cre2b = bcoefr * work[(*n << 1) + je] - bcoefi * work[*n * 3
  1556. + je];
  1557. cim2b = bcoefi * work[(*n << 1) + je] + bcoefr * work[*n * 3
  1558. + je];
  1559. i__1 = je - 2;
  1560. for (jr = 1; jr <= i__1; ++jr) {
  1561. work[(*n << 1) + jr] = -creala * s[jr + (je - 1) * s_dim1]
  1562. + crealb * p[jr + (je - 1) * p_dim1] - cre2a * s[
  1563. jr + je * s_dim1] + cre2b * p[jr + je * p_dim1];
  1564. work[*n * 3 + jr] = -cimaga * s[jr + (je - 1) * s_dim1] +
  1565. cimagb * p[jr + (je - 1) * p_dim1] - cim2a * s[jr
  1566. + je * s_dim1] + cim2b * p[jr + je * p_dim1];
  1567. /* L270: */
  1568. }
  1569. }
  1570. /* Computing MAX */
  1571. d__1 = ulp * acoefa * anorm, d__2 = ulp * bcoefa * bnorm, d__1 =
  1572. f2cmax(d__1,d__2);
  1573. dmin__ = f2cmax(d__1,safmin);
  1574. /* Columnwise triangular solve of (a A - b B) x = 0 */
  1575. il2by2 = FALSE_;
  1576. for (j = je - nw; j >= 1; --j) {
  1577. /* If a 2-by-2 block, is in position j-1:j, wait until */
  1578. /* next iteration to process it (when it will be j:j+1) */
  1579. if (! il2by2 && j > 1) {
  1580. if (s[j + (j - 1) * s_dim1] != 0.) {
  1581. il2by2 = TRUE_;
  1582. goto L370;
  1583. }
  1584. }
  1585. bdiag[0] = p[j + j * p_dim1];
  1586. if (il2by2) {
  1587. na = 2;
  1588. bdiag[1] = p[j + 1 + (j + 1) * p_dim1];
  1589. } else {
  1590. na = 1;
  1591. }
  1592. /* Compute x(j) (and x(j+1), if 2-by-2 block) */
  1593. dlaln2_(&c_false, &na, &nw, &dmin__, &acoef, &s[j + j *
  1594. s_dim1], lds, bdiag, &bdiag[1], &work[(*n << 1) + j],
  1595. n, &bcoefr, &bcoefi, sum, &c__2, &scale, &temp, &
  1596. iinfo);
  1597. if (scale < 1.) {
  1598. i__1 = nw - 1;
  1599. for (jw = 0; jw <= i__1; ++jw) {
  1600. i__2 = je;
  1601. for (jr = 1; jr <= i__2; ++jr) {
  1602. work[(jw + 2) * *n + jr] = scale * work[(jw + 2) *
  1603. *n + jr];
  1604. /* L280: */
  1605. }
  1606. /* L290: */
  1607. }
  1608. }
  1609. /* Computing MAX */
  1610. d__1 = scale * xmax;
  1611. xmax = f2cmax(d__1,temp);
  1612. i__1 = nw;
  1613. for (jw = 1; jw <= i__1; ++jw) {
  1614. i__2 = na;
  1615. for (ja = 1; ja <= i__2; ++ja) {
  1616. work[(jw + 1) * *n + j + ja - 1] = sum[ja + (jw << 1)
  1617. - 3];
  1618. /* L300: */
  1619. }
  1620. /* L310: */
  1621. }
  1622. /* w = w + x(j)*(a S(*,j) - b P(*,j) ) with scaling */
  1623. if (j > 1) {
  1624. /* Check whether scaling is necessary for sum. */
  1625. xscale = 1. / f2cmax(1.,xmax);
  1626. temp = acoefa * work[j] + bcoefa * work[*n + j];
  1627. if (il2by2) {
  1628. /* Computing MAX */
  1629. d__1 = temp, d__2 = acoefa * work[j + 1] + bcoefa *
  1630. work[*n + j + 1];
  1631. temp = f2cmax(d__1,d__2);
  1632. }
  1633. /* Computing MAX */
  1634. d__1 = f2cmax(temp,acoefa);
  1635. temp = f2cmax(d__1,bcoefa);
  1636. if (temp > bignum * xscale) {
  1637. i__1 = nw - 1;
  1638. for (jw = 0; jw <= i__1; ++jw) {
  1639. i__2 = je;
  1640. for (jr = 1; jr <= i__2; ++jr) {
  1641. work[(jw + 2) * *n + jr] = xscale * work[(jw
  1642. + 2) * *n + jr];
  1643. /* L320: */
  1644. }
  1645. /* L330: */
  1646. }
  1647. xmax *= xscale;
  1648. }
  1649. /* Compute the contributions of the off-diagonals of */
  1650. /* column j (and j+1, if 2-by-2 block) of A and B to the */
  1651. /* sums. */
  1652. i__1 = na;
  1653. for (ja = 1; ja <= i__1; ++ja) {
  1654. if (ilcplx) {
  1655. creala = acoef * work[(*n << 1) + j + ja - 1];
  1656. cimaga = acoef * work[*n * 3 + j + ja - 1];
  1657. crealb = bcoefr * work[(*n << 1) + j + ja - 1] -
  1658. bcoefi * work[*n * 3 + j + ja - 1];
  1659. cimagb = bcoefi * work[(*n << 1) + j + ja - 1] +
  1660. bcoefr * work[*n * 3 + j + ja - 1];
  1661. i__2 = j - 1;
  1662. for (jr = 1; jr <= i__2; ++jr) {
  1663. work[(*n << 1) + jr] = work[(*n << 1) + jr] -
  1664. creala * s[jr + (j + ja - 1) * s_dim1]
  1665. + crealb * p[jr + (j + ja - 1) *
  1666. p_dim1];
  1667. work[*n * 3 + jr] = work[*n * 3 + jr] -
  1668. cimaga * s[jr + (j + ja - 1) * s_dim1]
  1669. + cimagb * p[jr + (j + ja - 1) *
  1670. p_dim1];
  1671. /* L340: */
  1672. }
  1673. } else {
  1674. creala = acoef * work[(*n << 1) + j + ja - 1];
  1675. crealb = bcoefr * work[(*n << 1) + j + ja - 1];
  1676. i__2 = j - 1;
  1677. for (jr = 1; jr <= i__2; ++jr) {
  1678. work[(*n << 1) + jr] = work[(*n << 1) + jr] -
  1679. creala * s[jr + (j + ja - 1) * s_dim1]
  1680. + crealb * p[jr + (j + ja - 1) *
  1681. p_dim1];
  1682. /* L350: */
  1683. }
  1684. }
  1685. /* L360: */
  1686. }
  1687. }
  1688. il2by2 = FALSE_;
  1689. L370:
  1690. ;
  1691. }
  1692. /* Copy eigenvector to VR, back transforming if */
  1693. /* HOWMNY='B'. */
  1694. ieig -= nw;
  1695. if (ilback) {
  1696. i__1 = nw - 1;
  1697. for (jw = 0; jw <= i__1; ++jw) {
  1698. i__2 = *n;
  1699. for (jr = 1; jr <= i__2; ++jr) {
  1700. work[(jw + 4) * *n + jr] = work[(jw + 2) * *n + 1] *
  1701. vr[jr + vr_dim1];
  1702. /* L380: */
  1703. }
  1704. /* A series of compiler directives to defeat */
  1705. /* vectorization for the next loop */
  1706. i__2 = je;
  1707. for (jc = 2; jc <= i__2; ++jc) {
  1708. i__3 = *n;
  1709. for (jr = 1; jr <= i__3; ++jr) {
  1710. work[(jw + 4) * *n + jr] += work[(jw + 2) * *n +
  1711. jc] * vr[jr + jc * vr_dim1];
  1712. /* L390: */
  1713. }
  1714. /* L400: */
  1715. }
  1716. /* L410: */
  1717. }
  1718. i__1 = nw - 1;
  1719. for (jw = 0; jw <= i__1; ++jw) {
  1720. i__2 = *n;
  1721. for (jr = 1; jr <= i__2; ++jr) {
  1722. vr[jr + (ieig + jw) * vr_dim1] = work[(jw + 4) * *n +
  1723. jr];
  1724. /* L420: */
  1725. }
  1726. /* L430: */
  1727. }
  1728. iend = *n;
  1729. } else {
  1730. i__1 = nw - 1;
  1731. for (jw = 0; jw <= i__1; ++jw) {
  1732. i__2 = *n;
  1733. for (jr = 1; jr <= i__2; ++jr) {
  1734. vr[jr + (ieig + jw) * vr_dim1] = work[(jw + 2) * *n +
  1735. jr];
  1736. /* L440: */
  1737. }
  1738. /* L450: */
  1739. }
  1740. iend = je;
  1741. }
  1742. /* Scale eigenvector */
  1743. xmax = 0.;
  1744. if (ilcplx) {
  1745. i__1 = iend;
  1746. for (j = 1; j <= i__1; ++j) {
  1747. /* Computing MAX */
  1748. d__3 = xmax, d__4 = (d__1 = vr[j + ieig * vr_dim1], abs(
  1749. d__1)) + (d__2 = vr[j + (ieig + 1) * vr_dim1],
  1750. abs(d__2));
  1751. xmax = f2cmax(d__3,d__4);
  1752. /* L460: */
  1753. }
  1754. } else {
  1755. i__1 = iend;
  1756. for (j = 1; j <= i__1; ++j) {
  1757. /* Computing MAX */
  1758. d__2 = xmax, d__3 = (d__1 = vr[j + ieig * vr_dim1], abs(
  1759. d__1));
  1760. xmax = f2cmax(d__2,d__3);
  1761. /* L470: */
  1762. }
  1763. }
  1764. if (xmax > safmin) {
  1765. xscale = 1. / xmax;
  1766. i__1 = nw - 1;
  1767. for (jw = 0; jw <= i__1; ++jw) {
  1768. i__2 = iend;
  1769. for (jr = 1; jr <= i__2; ++jr) {
  1770. vr[jr + (ieig + jw) * vr_dim1] = xscale * vr[jr + (
  1771. ieig + jw) * vr_dim1];
  1772. /* L480: */
  1773. }
  1774. /* L490: */
  1775. }
  1776. }
  1777. L500:
  1778. ;
  1779. }
  1780. }
  1781. return;
  1782. /* End of DTGEVC */
  1783. } /* dtgevc_ */