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.

chbtrd.c 37 kB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376
  1. #include <math.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <stdio.h>
  5. #include <complex.h>
  6. #ifdef complex
  7. #undef complex
  8. #endif
  9. #ifdef I
  10. #undef I
  11. #endif
  12. #if defined(_WIN64)
  13. typedef long long BLASLONG;
  14. typedef unsigned long long BLASULONG;
  15. #else
  16. typedef long BLASLONG;
  17. typedef unsigned long BLASULONG;
  18. #endif
  19. #ifdef LAPACK_ILP64
  20. typedef BLASLONG blasint;
  21. #if defined(_WIN64)
  22. #define blasabs(x) llabs(x)
  23. #else
  24. #define blasabs(x) labs(x)
  25. #endif
  26. #else
  27. typedef int blasint;
  28. #define blasabs(x) abs(x)
  29. #endif
  30. typedef blasint integer;
  31. typedef unsigned int uinteger;
  32. typedef char *address;
  33. typedef short int shortint;
  34. typedef float real;
  35. typedef double doublereal;
  36. typedef struct { real r, i; } complex;
  37. typedef struct { doublereal r, i; } doublecomplex;
  38. #ifdef _MSC_VER
  39. static inline _Fcomplex Cf(complex *z) {_Fcomplex zz={z->r , z->i}; return zz;}
  40. static inline _Dcomplex Cd(doublecomplex *z) {_Dcomplex zz={z->r , z->i};return zz;}
  41. static inline _Fcomplex * _pCf(complex *z) {return (_Fcomplex*)z;}
  42. static inline _Dcomplex * _pCd(doublecomplex *z) {return (_Dcomplex*)z;}
  43. #else
  44. static inline _Complex float Cf(complex *z) {return z->r + z->i*_Complex_I;}
  45. static inline _Complex double Cd(doublecomplex *z) {return z->r + z->i*_Complex_I;}
  46. static inline _Complex float * _pCf(complex *z) {return (_Complex float*)z;}
  47. static inline _Complex double * _pCd(doublecomplex *z) {return (_Complex double*)z;}
  48. #endif
  49. #define pCf(z) (*_pCf(z))
  50. #define pCd(z) (*_pCd(z))
  51. typedef blasint logical;
  52. typedef char logical1;
  53. typedef char integer1;
  54. #define TRUE_ (1)
  55. #define FALSE_ (0)
  56. /* Extern is for use with -E */
  57. #ifndef Extern
  58. #define Extern extern
  59. #endif
  60. /* I/O stuff */
  61. typedef int flag;
  62. typedef int ftnlen;
  63. typedef int ftnint;
  64. /*external read, write*/
  65. typedef struct
  66. { flag cierr;
  67. ftnint ciunit;
  68. flag ciend;
  69. char *cifmt;
  70. ftnint cirec;
  71. } cilist;
  72. /*internal read, write*/
  73. typedef struct
  74. { flag icierr;
  75. char *iciunit;
  76. flag iciend;
  77. char *icifmt;
  78. ftnint icirlen;
  79. ftnint icirnum;
  80. } icilist;
  81. /*open*/
  82. typedef struct
  83. { flag oerr;
  84. ftnint ounit;
  85. char *ofnm;
  86. ftnlen ofnmlen;
  87. char *osta;
  88. char *oacc;
  89. char *ofm;
  90. ftnint orl;
  91. char *oblnk;
  92. } olist;
  93. /*close*/
  94. typedef struct
  95. { flag cerr;
  96. ftnint cunit;
  97. char *csta;
  98. } cllist;
  99. /*rewind, backspace, endfile*/
  100. typedef struct
  101. { flag aerr;
  102. ftnint aunit;
  103. } alist;
  104. /* inquire */
  105. typedef struct
  106. { flag inerr;
  107. ftnint inunit;
  108. char *infile;
  109. ftnlen infilen;
  110. ftnint *inex; /*parameters in standard's order*/
  111. ftnint *inopen;
  112. ftnint *innum;
  113. ftnint *innamed;
  114. char *inname;
  115. ftnlen innamlen;
  116. char *inacc;
  117. ftnlen inacclen;
  118. char *inseq;
  119. ftnlen inseqlen;
  120. char *indir;
  121. ftnlen indirlen;
  122. char *infmt;
  123. ftnlen infmtlen;
  124. char *inform;
  125. ftnint informlen;
  126. char *inunf;
  127. ftnlen inunflen;
  128. ftnint *inrecl;
  129. ftnint *innrec;
  130. char *inblank;
  131. ftnlen inblanklen;
  132. } inlist;
  133. #define VOID void
  134. union Multitype { /* for multiple entry points */
  135. integer1 g;
  136. shortint h;
  137. integer i;
  138. /* longint j; */
  139. real r;
  140. doublereal d;
  141. complex c;
  142. doublecomplex z;
  143. };
  144. typedef union Multitype Multitype;
  145. struct Vardesc { /* for Namelist */
  146. char *name;
  147. char *addr;
  148. ftnlen *dims;
  149. int type;
  150. };
  151. typedef struct Vardesc Vardesc;
  152. struct Namelist {
  153. char *name;
  154. Vardesc **vars;
  155. int nvars;
  156. };
  157. typedef struct Namelist Namelist;
  158. #define abs(x) ((x) >= 0 ? (x) : -(x))
  159. #define dabs(x) (fabs(x))
  160. #define f2cmin(a,b) ((a) <= (b) ? (a) : (b))
  161. #define f2cmax(a,b) ((a) >= (b) ? (a) : (b))
  162. #define dmin(a,b) (f2cmin(a,b))
  163. #define dmax(a,b) (f2cmax(a,b))
  164. #define bit_test(a,b) ((a) >> (b) & 1)
  165. #define bit_clear(a,b) ((a) & ~((uinteger)1 << (b)))
  166. #define bit_set(a,b) ((a) | ((uinteger)1 << (b)))
  167. #define abort_() { sig_die("Fortran abort routine called", 1); }
  168. #define c_abs(z) (cabsf(Cf(z)))
  169. #define c_cos(R,Z) { pCf(R)=ccos(Cf(Z)); }
  170. #ifdef _MSC_VER
  171. #define c_div(c, a, b) {Cf(c)._Val[0] = (Cf(a)._Val[0]/Cf(b)._Val[0]); Cf(c)._Val[1]=(Cf(a)._Val[1]/Cf(b)._Val[1]);}
  172. #define z_div(c, a, b) {Cd(c)._Val[0] = (Cd(a)._Val[0]/Cd(b)._Val[0]); Cd(c)._Val[1]=(Cd(a)._Val[1]/df(b)._Val[1]);}
  173. #else
  174. #define c_div(c, a, b) {pCf(c) = Cf(a)/Cf(b);}
  175. #define z_div(c, a, b) {pCd(c) = Cd(a)/Cd(b);}
  176. #endif
  177. #define c_exp(R, Z) {pCf(R) = cexpf(Cf(Z));}
  178. #define c_log(R, Z) {pCf(R) = clogf(Cf(Z));}
  179. #define c_sin(R, Z) {pCf(R) = csinf(Cf(Z));}
  180. //#define c_sqrt(R, Z) {*(R) = csqrtf(Cf(Z));}
  181. #define c_sqrt(R, Z) {pCf(R) = csqrtf(Cf(Z));}
  182. #define d_abs(x) (fabs(*(x)))
  183. #define d_acos(x) (acos(*(x)))
  184. #define d_asin(x) (asin(*(x)))
  185. #define d_atan(x) (atan(*(x)))
  186. #define d_atn2(x, y) (atan2(*(x),*(y)))
  187. #define d_cnjg(R, Z) { pCd(R) = conj(Cd(Z)); }
  188. #define r_cnjg(R, Z) { pCf(R) = conjf(Cf(Z)); }
  189. #define d_cos(x) (cos(*(x)))
  190. #define d_cosh(x) (cosh(*(x)))
  191. #define d_dim(__a, __b) ( *(__a) > *(__b) ? *(__a) - *(__b) : 0.0 )
  192. #define d_exp(x) (exp(*(x)))
  193. #define d_imag(z) (cimag(Cd(z)))
  194. #define r_imag(z) (cimagf(Cf(z)))
  195. #define d_int(__x) (*(__x)>0 ? floor(*(__x)) : -floor(- *(__x)))
  196. #define r_int(__x) (*(__x)>0 ? floor(*(__x)) : -floor(- *(__x)))
  197. #define d_lg10(x) ( 0.43429448190325182765 * log(*(x)) )
  198. #define r_lg10(x) ( 0.43429448190325182765 * log(*(x)) )
  199. #define d_log(x) (log(*(x)))
  200. #define d_mod(x, y) (fmod(*(x), *(y)))
  201. #define u_nint(__x) ((__x)>=0 ? floor((__x) + .5) : -floor(.5 - (__x)))
  202. #define d_nint(x) u_nint(*(x))
  203. #define u_sign(__a,__b) ((__b) >= 0 ? ((__a) >= 0 ? (__a) : -(__a)) : -((__a) >= 0 ? (__a) : -(__a)))
  204. #define d_sign(a,b) u_sign(*(a),*(b))
  205. #define r_sign(a,b) u_sign(*(a),*(b))
  206. #define d_sin(x) (sin(*(x)))
  207. #define d_sinh(x) (sinh(*(x)))
  208. #define d_sqrt(x) (sqrt(*(x)))
  209. #define d_tan(x) (tan(*(x)))
  210. #define d_tanh(x) (tanh(*(x)))
  211. #define i_abs(x) abs(*(x))
  212. #define i_dnnt(x) ((integer)u_nint(*(x)))
  213. #define i_len(s, n) (n)
  214. #define i_nint(x) ((integer)u_nint(*(x)))
  215. #define i_sign(a,b) ((integer)u_sign((integer)*(a),(integer)*(b)))
  216. #define pow_dd(ap, bp) ( pow(*(ap), *(bp)))
  217. #define pow_si(B,E) spow_ui(*(B),*(E))
  218. #define pow_ri(B,E) spow_ui(*(B),*(E))
  219. #define pow_di(B,E) dpow_ui(*(B),*(E))
  220. #define pow_zi(p, a, b) {pCd(p) = zpow_ui(Cd(a), *(b));}
  221. #define pow_ci(p, a, b) {pCf(p) = cpow_ui(Cf(a), *(b));}
  222. #define pow_zz(R,A,B) {pCd(R) = cpow(Cd(A),*(B));}
  223. #define s_cat(lpp, rpp, rnp, np, llp) { ftnlen i, nc, ll; char *f__rp, *lp; ll = (llp); lp = (lpp); for(i=0; i < (int)*(np); ++i) { nc = ll; if((rnp)[i] < nc) nc = (rnp)[i]; ll -= nc; f__rp = (rpp)[i]; while(--nc >= 0) *lp++ = *(f__rp)++; } while(--ll >= 0) *lp++ = ' '; }
  224. #define s_cmp(a,b,c,d) ((integer)strncmp((a),(b),f2cmin((c),(d))))
  225. #define s_copy(A,B,C,D) { int __i,__m; for (__i=0, __m=f2cmin((C),(D)); __i<__m && (B)[__i] != 0; ++__i) (A)[__i] = (B)[__i]; }
  226. #define sig_die(s, kill) { exit(1); }
  227. #define s_stop(s, n) {exit(0);}
  228. static char junk[] = "\n@(#)LIBF77 VERSION 19990503\n";
  229. #define z_abs(z) (cabs(Cd(z)))
  230. #define z_exp(R, Z) {pCd(R) = cexp(Cd(Z));}
  231. #define z_sqrt(R, Z) {pCd(R) = csqrt(Cd(Z));}
  232. #define myexit_() break;
  233. #define mycycle() continue;
  234. #define myceiling(w) {ceil(w)}
  235. #define myhuge(w) {HUGE_VAL}
  236. //#define mymaxloc_(w,s,e,n) {if (sizeof(*(w)) == sizeof(double)) dmaxloc_((w),*(s),*(e),n); else dmaxloc_((w),*(s),*(e),n);}
  237. #define mymaxloc(w,s,e,n) {dmaxloc_(w,*(s),*(e),n)}
  238. /* procedure parameter types for -A and -C++ */
  239. #ifdef __cplusplus
  240. typedef logical (*L_fp)(...);
  241. #else
  242. typedef logical (*L_fp)();
  243. #endif
  244. static float spow_ui(float x, integer n) {
  245. float pow=1.0; unsigned long int u;
  246. if(n != 0) {
  247. if(n < 0) n = -n, x = 1/x;
  248. for(u = n; ; ) {
  249. if(u & 01) pow *= x;
  250. if(u >>= 1) x *= x;
  251. else break;
  252. }
  253. }
  254. return pow;
  255. }
  256. static double dpow_ui(double x, integer n) {
  257. double pow=1.0; unsigned long int u;
  258. if(n != 0) {
  259. if(n < 0) n = -n, x = 1/x;
  260. for(u = n; ; ) {
  261. if(u & 01) pow *= x;
  262. if(u >>= 1) x *= x;
  263. else break;
  264. }
  265. }
  266. return pow;
  267. }
  268. #ifdef _MSC_VER
  269. static _Fcomplex cpow_ui(complex x, integer n) {
  270. complex pow={1.0,0.0}; unsigned long int u;
  271. if(n != 0) {
  272. if(n < 0) n = -n, x.r = 1/x.r, x.i=1/x.i;
  273. for(u = n; ; ) {
  274. if(u & 01) pow.r *= x.r, pow.i *= x.i;
  275. if(u >>= 1) x.r *= x.r, x.i *= x.i;
  276. else break;
  277. }
  278. }
  279. _Fcomplex p={pow.r, pow.i};
  280. return p;
  281. }
  282. #else
  283. static _Complex float cpow_ui(_Complex float x, integer n) {
  284. _Complex float pow=1.0; unsigned long int u;
  285. if(n != 0) {
  286. if(n < 0) n = -n, x = 1/x;
  287. for(u = n; ; ) {
  288. if(u & 01) pow *= x;
  289. if(u >>= 1) x *= x;
  290. else break;
  291. }
  292. }
  293. return pow;
  294. }
  295. #endif
  296. #ifdef _MSC_VER
  297. static _Dcomplex zpow_ui(_Dcomplex x, integer n) {
  298. _Dcomplex pow={1.0,0.0}; unsigned long int u;
  299. if(n != 0) {
  300. if(n < 0) n = -n, x._Val[0] = 1/x._Val[0], x._Val[1] =1/x._Val[1];
  301. for(u = n; ; ) {
  302. if(u & 01) pow._Val[0] *= x._Val[0], pow._Val[1] *= x._Val[1];
  303. if(u >>= 1) x._Val[0] *= x._Val[0], x._Val[1] *= x._Val[1];
  304. else break;
  305. }
  306. }
  307. _Dcomplex p = {pow._Val[0], pow._Val[1]};
  308. return p;
  309. }
  310. #else
  311. static _Complex double zpow_ui(_Complex double x, integer n) {
  312. _Complex double pow=1.0; unsigned long int u;
  313. if(n != 0) {
  314. if(n < 0) n = -n, x = 1/x;
  315. for(u = n; ; ) {
  316. if(u & 01) pow *= x;
  317. if(u >>= 1) x *= x;
  318. else break;
  319. }
  320. }
  321. return pow;
  322. }
  323. #endif
  324. static integer pow_ii(integer x, integer n) {
  325. integer pow; unsigned long int u;
  326. if (n <= 0) {
  327. if (n == 0 || x == 1) pow = 1;
  328. else if (x != -1) pow = x == 0 ? 1/x : 0;
  329. else n = -n;
  330. }
  331. if ((n > 0) || !(n == 0 || x == 1 || x != -1)) {
  332. u = n;
  333. for(pow = 1; ; ) {
  334. if(u & 01) pow *= x;
  335. if(u >>= 1) x *= x;
  336. else break;
  337. }
  338. }
  339. return pow;
  340. }
  341. static integer dmaxloc_(double *w, integer s, integer e, integer *n)
  342. {
  343. double m; integer i, mi;
  344. for(m=w[s-1], mi=s, i=s+1; i<=e; i++)
  345. if (w[i-1]>m) mi=i ,m=w[i-1];
  346. return mi-s+1;
  347. }
  348. static integer smaxloc_(float *w, integer s, integer e, integer *n)
  349. {
  350. float m; integer i, mi;
  351. for(m=w[s-1], mi=s, i=s+1; i<=e; i++)
  352. if (w[i-1]>m) mi=i ,m=w[i-1];
  353. return mi-s+1;
  354. }
  355. static inline void cdotc_(complex *z, integer *n_, complex *x, integer *incx_, complex *y, integer *incy_) {
  356. integer n = *n_, incx = *incx_, incy = *incy_, i;
  357. #ifdef _MSC_VER
  358. _Fcomplex zdotc = {0.0, 0.0};
  359. if (incx == 1 && incy == 1) {
  360. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  361. zdotc._Val[0] += conjf(Cf(&x[i]))._Val[0] * Cf(&y[i])._Val[0];
  362. zdotc._Val[1] += conjf(Cf(&x[i]))._Val[1] * Cf(&y[i])._Val[1];
  363. }
  364. } else {
  365. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  366. zdotc._Val[0] += conjf(Cf(&x[i*incx]))._Val[0] * Cf(&y[i*incy])._Val[0];
  367. zdotc._Val[1] += conjf(Cf(&x[i*incx]))._Val[1] * Cf(&y[i*incy])._Val[1];
  368. }
  369. }
  370. pCf(z) = zdotc;
  371. }
  372. #else
  373. _Complex float zdotc = 0.0;
  374. if (incx == 1 && incy == 1) {
  375. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  376. zdotc += conjf(Cf(&x[i])) * Cf(&y[i]);
  377. }
  378. } else {
  379. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  380. zdotc += conjf(Cf(&x[i*incx])) * Cf(&y[i*incy]);
  381. }
  382. }
  383. pCf(z) = zdotc;
  384. }
  385. #endif
  386. static inline void zdotc_(doublecomplex *z, integer *n_, doublecomplex *x, integer *incx_, doublecomplex *y, integer *incy_) {
  387. integer n = *n_, incx = *incx_, incy = *incy_, i;
  388. #ifdef _MSC_VER
  389. _Dcomplex zdotc = {0.0, 0.0};
  390. if (incx == 1 && incy == 1) {
  391. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  392. zdotc._Val[0] += conj(Cd(&x[i]))._Val[0] * Cd(&y[i])._Val[0];
  393. zdotc._Val[1] += conj(Cd(&x[i]))._Val[1] * Cd(&y[i])._Val[1];
  394. }
  395. } else {
  396. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  397. zdotc._Val[0] += conj(Cd(&x[i*incx]))._Val[0] * Cd(&y[i*incy])._Val[0];
  398. zdotc._Val[1] += conj(Cd(&x[i*incx]))._Val[1] * Cd(&y[i*incy])._Val[1];
  399. }
  400. }
  401. pCd(z) = zdotc;
  402. }
  403. #else
  404. _Complex double zdotc = 0.0;
  405. if (incx == 1 && incy == 1) {
  406. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  407. zdotc += conj(Cd(&x[i])) * Cd(&y[i]);
  408. }
  409. } else {
  410. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  411. zdotc += conj(Cd(&x[i*incx])) * Cd(&y[i*incy]);
  412. }
  413. }
  414. pCd(z) = zdotc;
  415. }
  416. #endif
  417. static inline void cdotu_(complex *z, integer *n_, complex *x, integer *incx_, complex *y, integer *incy_) {
  418. integer n = *n_, incx = *incx_, incy = *incy_, i;
  419. #ifdef _MSC_VER
  420. _Fcomplex zdotc = {0.0, 0.0};
  421. if (incx == 1 && incy == 1) {
  422. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  423. zdotc._Val[0] += Cf(&x[i])._Val[0] * Cf(&y[i])._Val[0];
  424. zdotc._Val[1] += Cf(&x[i])._Val[1] * Cf(&y[i])._Val[1];
  425. }
  426. } else {
  427. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  428. zdotc._Val[0] += Cf(&x[i*incx])._Val[0] * Cf(&y[i*incy])._Val[0];
  429. zdotc._Val[1] += Cf(&x[i*incx])._Val[1] * Cf(&y[i*incy])._Val[1];
  430. }
  431. }
  432. pCf(z) = zdotc;
  433. }
  434. #else
  435. _Complex float zdotc = 0.0;
  436. if (incx == 1 && incy == 1) {
  437. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  438. zdotc += Cf(&x[i]) * Cf(&y[i]);
  439. }
  440. } else {
  441. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  442. zdotc += Cf(&x[i*incx]) * Cf(&y[i*incy]);
  443. }
  444. }
  445. pCf(z) = zdotc;
  446. }
  447. #endif
  448. static inline void zdotu_(doublecomplex *z, integer *n_, doublecomplex *x, integer *incx_, doublecomplex *y, integer *incy_) {
  449. integer n = *n_, incx = *incx_, incy = *incy_, i;
  450. #ifdef _MSC_VER
  451. _Dcomplex zdotc = {0.0, 0.0};
  452. if (incx == 1 && incy == 1) {
  453. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  454. zdotc._Val[0] += Cd(&x[i])._Val[0] * Cd(&y[i])._Val[0];
  455. zdotc._Val[1] += Cd(&x[i])._Val[1] * Cd(&y[i])._Val[1];
  456. }
  457. } else {
  458. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  459. zdotc._Val[0] += Cd(&x[i*incx])._Val[0] * Cd(&y[i*incy])._Val[0];
  460. zdotc._Val[1] += Cd(&x[i*incx])._Val[1] * Cd(&y[i*incy])._Val[1];
  461. }
  462. }
  463. pCd(z) = zdotc;
  464. }
  465. #else
  466. _Complex double zdotc = 0.0;
  467. if (incx == 1 && incy == 1) {
  468. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  469. zdotc += Cd(&x[i]) * Cd(&y[i]);
  470. }
  471. } else {
  472. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  473. zdotc += Cd(&x[i*incx]) * Cd(&y[i*incy]);
  474. }
  475. }
  476. pCd(z) = zdotc;
  477. }
  478. #endif
  479. /* -- translated by f2c (version 20000121).
  480. You must link the resulting object file with the libraries:
  481. -lf2c -lm (in that order)
  482. */
  483. /* Table of constant values */
  484. static complex c_b1 = {0.f,0.f};
  485. static complex c_b2 = {1.f,0.f};
  486. static integer c__1 = 1;
  487. /* > \brief \b CHBTRD */
  488. /* =========== DOCUMENTATION =========== */
  489. /* Online html documentation available at */
  490. /* http://www.netlib.org/lapack/explore-html/ */
  491. /* > \htmlonly */
  492. /* > Download CHBTRD + dependencies */
  493. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/chbtrd.
  494. f"> */
  495. /* > [TGZ]</a> */
  496. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/chbtrd.
  497. f"> */
  498. /* > [ZIP]</a> */
  499. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/chbtrd.
  500. f"> */
  501. /* > [TXT]</a> */
  502. /* > \endhtmlonly */
  503. /* Definition: */
  504. /* =========== */
  505. /* SUBROUTINE CHBTRD( VECT, UPLO, N, KD, AB, LDAB, D, E, Q, LDQ, */
  506. /* WORK, INFO ) */
  507. /* CHARACTER UPLO, VECT */
  508. /* INTEGER INFO, KD, LDAB, LDQ, N */
  509. /* REAL D( * ), E( * ) */
  510. /* COMPLEX AB( LDAB, * ), Q( LDQ, * ), WORK( * ) */
  511. /* > \par Purpose: */
  512. /* ============= */
  513. /* > */
  514. /* > \verbatim */
  515. /* > */
  516. /* > CHBTRD reduces a complex Hermitian band matrix A to real symmetric */
  517. /* > tridiagonal form T by a unitary similarity transformation: */
  518. /* > Q**H * A * Q = T. */
  519. /* > \endverbatim */
  520. /* Arguments: */
  521. /* ========== */
  522. /* > \param[in] VECT */
  523. /* > \verbatim */
  524. /* > VECT is CHARACTER*1 */
  525. /* > = 'N': do not form Q; */
  526. /* > = 'V': form Q; */
  527. /* > = 'U': update a matrix X, by forming X*Q. */
  528. /* > \endverbatim */
  529. /* > */
  530. /* > \param[in] UPLO */
  531. /* > \verbatim */
  532. /* > UPLO is CHARACTER*1 */
  533. /* > = 'U': Upper triangle of A is stored; */
  534. /* > = 'L': Lower triangle of A is stored. */
  535. /* > \endverbatim */
  536. /* > */
  537. /* > \param[in] N */
  538. /* > \verbatim */
  539. /* > N is INTEGER */
  540. /* > The order of the matrix A. N >= 0. */
  541. /* > \endverbatim */
  542. /* > */
  543. /* > \param[in] KD */
  544. /* > \verbatim */
  545. /* > KD is INTEGER */
  546. /* > The number of superdiagonals of the matrix A if UPLO = 'U', */
  547. /* > or the number of subdiagonals if UPLO = 'L'. KD >= 0. */
  548. /* > \endverbatim */
  549. /* > */
  550. /* > \param[in,out] AB */
  551. /* > \verbatim */
  552. /* > AB is COMPLEX array, dimension (LDAB,N) */
  553. /* > On entry, the upper or lower triangle of the Hermitian band */
  554. /* > matrix A, stored in the first KD+1 rows of the array. The */
  555. /* > j-th column of A is stored in the j-th column of the array AB */
  556. /* > as follows: */
  557. /* > if UPLO = 'U', AB(kd+1+i-j,j) = A(i,j) for f2cmax(1,j-kd)<=i<=j; */
  558. /* > if UPLO = 'L', AB(1+i-j,j) = A(i,j) for j<=i<=f2cmin(n,j+kd). */
  559. /* > On exit, the diagonal elements of AB are overwritten by the */
  560. /* > diagonal elements of the tridiagonal matrix T; if KD > 0, the */
  561. /* > elements on the first superdiagonal (if UPLO = 'U') or the */
  562. /* > first subdiagonal (if UPLO = 'L') are overwritten by the */
  563. /* > off-diagonal elements of T; the rest of AB is overwritten by */
  564. /* > values generated during the reduction. */
  565. /* > \endverbatim */
  566. /* > */
  567. /* > \param[in] LDAB */
  568. /* > \verbatim */
  569. /* > LDAB is INTEGER */
  570. /* > The leading dimension of the array AB. LDAB >= KD+1. */
  571. /* > \endverbatim */
  572. /* > */
  573. /* > \param[out] D */
  574. /* > \verbatim */
  575. /* > D is REAL array, dimension (N) */
  576. /* > The diagonal elements of the tridiagonal matrix T. */
  577. /* > \endverbatim */
  578. /* > */
  579. /* > \param[out] E */
  580. /* > \verbatim */
  581. /* > E is REAL array, dimension (N-1) */
  582. /* > The off-diagonal elements of the tridiagonal matrix T: */
  583. /* > E(i) = T(i,i+1) if UPLO = 'U'; E(i) = T(i+1,i) if UPLO = 'L'. */
  584. /* > \endverbatim */
  585. /* > */
  586. /* > \param[in,out] Q */
  587. /* > \verbatim */
  588. /* > Q is COMPLEX array, dimension (LDQ,N) */
  589. /* > On entry, if VECT = 'U', then Q must contain an N-by-N */
  590. /* > matrix X; if VECT = 'N' or 'V', then Q need not be set. */
  591. /* > */
  592. /* > On exit: */
  593. /* > if VECT = 'V', Q contains the N-by-N unitary matrix Q; */
  594. /* > if VECT = 'U', Q contains the product X*Q; */
  595. /* > if VECT = 'N', the array Q is not referenced. */
  596. /* > \endverbatim */
  597. /* > */
  598. /* > \param[in] LDQ */
  599. /* > \verbatim */
  600. /* > LDQ is INTEGER */
  601. /* > The leading dimension of the array Q. */
  602. /* > LDQ >= 1, and LDQ >= N if VECT = 'V' or 'U'. */
  603. /* > \endverbatim */
  604. /* > */
  605. /* > \param[out] WORK */
  606. /* > \verbatim */
  607. /* > WORK is COMPLEX array, dimension (N) */
  608. /* > \endverbatim */
  609. /* > */
  610. /* > \param[out] INFO */
  611. /* > \verbatim */
  612. /* > INFO is INTEGER */
  613. /* > = 0: successful exit */
  614. /* > < 0: if INFO = -i, the i-th argument had an illegal value */
  615. /* > \endverbatim */
  616. /* Authors: */
  617. /* ======== */
  618. /* > \author Univ. of Tennessee */
  619. /* > \author Univ. of California Berkeley */
  620. /* > \author Univ. of Colorado Denver */
  621. /* > \author NAG Ltd. */
  622. /* > \date December 2016 */
  623. /* > \ingroup complexOTHERcomputational */
  624. /* > \par Further Details: */
  625. /* ===================== */
  626. /* > */
  627. /* > \verbatim */
  628. /* > */
  629. /* > Modified by Linda Kaufman, Bell Labs. */
  630. /* > \endverbatim */
  631. /* > */
  632. /* ===================================================================== */
  633. /* Subroutine */ void chbtrd_(char *vect, char *uplo, integer *n, integer *kd,
  634. complex *ab, integer *ldab, real *d__, real *e, complex *q, integer *
  635. ldq, complex *work, integer *info)
  636. {
  637. /* System generated locals */
  638. integer ab_dim1, ab_offset, q_dim1, q_offset, i__1, i__2, i__3, i__4,
  639. i__5, i__6;
  640. real r__1;
  641. complex q__1;
  642. /* Local variables */
  643. integer inca, jend, lend, jinc;
  644. real abst;
  645. integer incx, last;
  646. complex temp;
  647. extern /* Subroutine */ void crot_(integer *, complex *, integer *,
  648. complex *, integer *, real *, complex *);
  649. integer j1end, j1inc, i__, j, k, l;
  650. complex t;
  651. extern /* Subroutine */ void cscal_(integer *, complex *, complex *,
  652. integer *);
  653. integer iqend;
  654. extern logical lsame_(char *, char *);
  655. logical initq, wantq, upper;
  656. integer i2, j1, j2;
  657. extern /* Subroutine */ void clar2v_(integer *, complex *, complex *,
  658. complex *, integer *, real *, complex *, integer *);
  659. integer nq, nr, iqaend;
  660. extern /* Subroutine */ void clacgv_(integer *, complex *, integer *),
  661. claset_(char *, integer *, integer *, complex *, complex *,
  662. complex *, integer *), clartg_(complex *, complex *, real
  663. *, complex *, complex *);
  664. extern int xerbla_(char *, integer *, ftnlen);
  665. extern void clargv_(integer *, complex *, integer *, complex *, integer *,
  666. real *, integer *), clartv_(integer *, complex *, integer *,
  667. complex *, integer *, real *, complex *, integer *);
  668. integer kd1, ibl, iqb, kdn, jin, nrt, kdm1;
  669. /* -- LAPACK computational routine (version 3.7.0) -- */
  670. /* -- LAPACK is a software package provided by Univ. of Tennessee, -- */
  671. /* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- */
  672. /* December 2016 */
  673. /* ===================================================================== */
  674. /* Test the input parameters */
  675. /* Parameter adjustments */
  676. ab_dim1 = *ldab;
  677. ab_offset = 1 + ab_dim1 * 1;
  678. ab -= ab_offset;
  679. --d__;
  680. --e;
  681. q_dim1 = *ldq;
  682. q_offset = 1 + q_dim1 * 1;
  683. q -= q_offset;
  684. --work;
  685. /* Function Body */
  686. initq = lsame_(vect, "V");
  687. wantq = initq || lsame_(vect, "U");
  688. upper = lsame_(uplo, "U");
  689. kd1 = *kd + 1;
  690. kdm1 = *kd - 1;
  691. incx = *ldab - 1;
  692. iqend = 1;
  693. *info = 0;
  694. if (! wantq && ! lsame_(vect, "N")) {
  695. *info = -1;
  696. } else if (! upper && ! lsame_(uplo, "L")) {
  697. *info = -2;
  698. } else if (*n < 0) {
  699. *info = -3;
  700. } else if (*kd < 0) {
  701. *info = -4;
  702. } else if (*ldab < kd1) {
  703. *info = -6;
  704. } else if (*ldq < f2cmax(1,*n) && wantq) {
  705. *info = -10;
  706. }
  707. if (*info != 0) {
  708. i__1 = -(*info);
  709. xerbla_("CHBTRD", &i__1, (ftnlen)6);
  710. return;
  711. }
  712. /* Quick return if possible */
  713. if (*n == 0) {
  714. return;
  715. }
  716. /* Initialize Q to the unit matrix, if needed */
  717. if (initq) {
  718. claset_("Full", n, n, &c_b1, &c_b2, &q[q_offset], ldq);
  719. }
  720. /* Wherever possible, plane rotations are generated and applied in */
  721. /* vector operations of length NR over the index set J1:J2:KD1. */
  722. /* The real cosines and complex sines of the plane rotations are */
  723. /* stored in the arrays D and WORK. */
  724. inca = kd1 * *ldab;
  725. /* Computing MIN */
  726. i__1 = *n - 1;
  727. kdn = f2cmin(i__1,*kd);
  728. if (upper) {
  729. if (*kd > 1) {
  730. /* Reduce to complex Hermitian tridiagonal form, working with */
  731. /* the upper triangle */
  732. nr = 0;
  733. j1 = kdn + 2;
  734. j2 = 1;
  735. i__1 = kd1 + ab_dim1;
  736. i__2 = kd1 + ab_dim1;
  737. r__1 = ab[i__2].r;
  738. ab[i__1].r = r__1, ab[i__1].i = 0.f;
  739. i__1 = *n - 2;
  740. for (i__ = 1; i__ <= i__1; ++i__) {
  741. /* Reduce i-th row of matrix to tridiagonal form */
  742. for (k = kdn + 1; k >= 2; --k) {
  743. j1 += kdn;
  744. j2 += kdn;
  745. if (nr > 0) {
  746. /* generate plane rotations to annihilate nonzero */
  747. /* elements which have been created outside the band */
  748. clargv_(&nr, &ab[(j1 - 1) * ab_dim1 + 1], &inca, &
  749. work[j1], &kd1, &d__[j1], &kd1);
  750. /* apply rotations from the right */
  751. /* Dependent on the the number of diagonals either */
  752. /* CLARTV or CROT is used */
  753. if (nr >= (*kd << 1) - 1) {
  754. i__2 = *kd - 1;
  755. for (l = 1; l <= i__2; ++l) {
  756. clartv_(&nr, &ab[l + 1 + (j1 - 1) * ab_dim1],
  757. &inca, &ab[l + j1 * ab_dim1], &inca, &
  758. d__[j1], &work[j1], &kd1);
  759. /* L10: */
  760. }
  761. } else {
  762. jend = j1 + (nr - 1) * kd1;
  763. i__2 = jend;
  764. i__3 = kd1;
  765. for (jinc = j1; i__3 < 0 ? jinc >= i__2 : jinc <=
  766. i__2; jinc += i__3) {
  767. crot_(&kdm1, &ab[(jinc - 1) * ab_dim1 + 2], &
  768. c__1, &ab[jinc * ab_dim1 + 1], &c__1,
  769. &d__[jinc], &work[jinc]);
  770. /* L20: */
  771. }
  772. }
  773. }
  774. if (k > 2) {
  775. if (k <= *n - i__ + 1) {
  776. /* generate plane rotation to annihilate a(i,i+k-1) */
  777. /* within the band */
  778. clartg_(&ab[*kd - k + 3 + (i__ + k - 2) * ab_dim1]
  779. , &ab[*kd - k + 2 + (i__ + k - 1) *
  780. ab_dim1], &d__[i__ + k - 1], &work[i__ +
  781. k - 1], &temp);
  782. i__3 = *kd - k + 3 + (i__ + k - 2) * ab_dim1;
  783. ab[i__3].r = temp.r, ab[i__3].i = temp.i;
  784. /* apply rotation from the right */
  785. i__3 = k - 3;
  786. crot_(&i__3, &ab[*kd - k + 4 + (i__ + k - 2) *
  787. ab_dim1], &c__1, &ab[*kd - k + 3 + (i__ +
  788. k - 1) * ab_dim1], &c__1, &d__[i__ + k -
  789. 1], &work[i__ + k - 1]);
  790. }
  791. ++nr;
  792. j1 = j1 - kdn - 1;
  793. }
  794. /* apply plane rotations from both sides to diagonal */
  795. /* blocks */
  796. if (nr > 0) {
  797. clar2v_(&nr, &ab[kd1 + (j1 - 1) * ab_dim1], &ab[kd1 +
  798. j1 * ab_dim1], &ab[*kd + j1 * ab_dim1], &inca,
  799. &d__[j1], &work[j1], &kd1);
  800. }
  801. /* apply plane rotations from the left */
  802. if (nr > 0) {
  803. clacgv_(&nr, &work[j1], &kd1);
  804. if ((*kd << 1) - 1 < nr) {
  805. /* Dependent on the the number of diagonals either */
  806. /* CLARTV or CROT is used */
  807. i__3 = *kd - 1;
  808. for (l = 1; l <= i__3; ++l) {
  809. if (j2 + l > *n) {
  810. nrt = nr - 1;
  811. } else {
  812. nrt = nr;
  813. }
  814. if (nrt > 0) {
  815. clartv_(&nrt, &ab[*kd - l + (j1 + l) *
  816. ab_dim1], &inca, &ab[*kd - l + 1
  817. + (j1 + l) * ab_dim1], &inca, &
  818. d__[j1], &work[j1], &kd1);
  819. }
  820. /* L30: */
  821. }
  822. } else {
  823. j1end = j1 + kd1 * (nr - 2);
  824. if (j1end >= j1) {
  825. i__3 = j1end;
  826. i__2 = kd1;
  827. for (jin = j1; i__2 < 0 ? jin >= i__3 : jin <=
  828. i__3; jin += i__2) {
  829. i__4 = *kd - 1;
  830. crot_(&i__4, &ab[*kd - 1 + (jin + 1) *
  831. ab_dim1], &incx, &ab[*kd + (jin +
  832. 1) * ab_dim1], &incx, &d__[jin], &
  833. work[jin]);
  834. /* L40: */
  835. }
  836. }
  837. /* Computing MIN */
  838. i__2 = kdm1, i__3 = *n - j2;
  839. lend = f2cmin(i__2,i__3);
  840. last = j1end + kd1;
  841. if (lend > 0) {
  842. crot_(&lend, &ab[*kd - 1 + (last + 1) *
  843. ab_dim1], &incx, &ab[*kd + (last + 1)
  844. * ab_dim1], &incx, &d__[last], &work[
  845. last]);
  846. }
  847. }
  848. }
  849. if (wantq) {
  850. /* accumulate product of plane rotations in Q */
  851. if (initq) {
  852. /* take advantage of the fact that Q was */
  853. /* initially the Identity matrix */
  854. iqend = f2cmax(iqend,j2);
  855. /* Computing MAX */
  856. i__2 = 0, i__3 = k - 3;
  857. i2 = f2cmax(i__2,i__3);
  858. iqaend = i__ * *kd + 1;
  859. if (k == 2) {
  860. iqaend += *kd;
  861. }
  862. iqaend = f2cmin(iqaend,iqend);
  863. i__2 = j2;
  864. i__3 = kd1;
  865. for (j = j1; i__3 < 0 ? j >= i__2 : j <= i__2; j
  866. += i__3) {
  867. ibl = i__ - i2 / kdm1;
  868. ++i2;
  869. /* Computing MAX */
  870. i__4 = 1, i__5 = j - ibl;
  871. iqb = f2cmax(i__4,i__5);
  872. nq = iqaend + 1 - iqb;
  873. /* Computing MIN */
  874. i__4 = iqaend + *kd;
  875. iqaend = f2cmin(i__4,iqend);
  876. r_cnjg(&q__1, &work[j]);
  877. crot_(&nq, &q[iqb + (j - 1) * q_dim1], &c__1,
  878. &q[iqb + j * q_dim1], &c__1, &d__[j],
  879. &q__1);
  880. /* L50: */
  881. }
  882. } else {
  883. i__3 = j2;
  884. i__2 = kd1;
  885. for (j = j1; i__2 < 0 ? j >= i__3 : j <= i__3; j
  886. += i__2) {
  887. r_cnjg(&q__1, &work[j]);
  888. crot_(n, &q[(j - 1) * q_dim1 + 1], &c__1, &q[
  889. j * q_dim1 + 1], &c__1, &d__[j], &
  890. q__1);
  891. /* L60: */
  892. }
  893. }
  894. }
  895. if (j2 + kdn > *n) {
  896. /* adjust J2 to keep within the bounds of the matrix */
  897. --nr;
  898. j2 = j2 - kdn - 1;
  899. }
  900. i__2 = j2;
  901. i__3 = kd1;
  902. for (j = j1; i__3 < 0 ? j >= i__2 : j <= i__2; j += i__3)
  903. {
  904. /* create nonzero element a(j-1,j+kd) outside the band */
  905. /* and store it in WORK */
  906. i__4 = j + *kd;
  907. i__5 = j;
  908. i__6 = (j + *kd) * ab_dim1 + 1;
  909. q__1.r = work[i__5].r * ab[i__6].r - work[i__5].i *
  910. ab[i__6].i, q__1.i = work[i__5].r * ab[i__6]
  911. .i + work[i__5].i * ab[i__6].r;
  912. work[i__4].r = q__1.r, work[i__4].i = q__1.i;
  913. i__4 = (j + *kd) * ab_dim1 + 1;
  914. i__5 = j;
  915. i__6 = (j + *kd) * ab_dim1 + 1;
  916. q__1.r = d__[i__5] * ab[i__6].r, q__1.i = d__[i__5] *
  917. ab[i__6].i;
  918. ab[i__4].r = q__1.r, ab[i__4].i = q__1.i;
  919. /* L70: */
  920. }
  921. /* L80: */
  922. }
  923. /* L90: */
  924. }
  925. }
  926. if (*kd > 0) {
  927. /* make off-diagonal elements real and copy them to E */
  928. i__1 = *n - 1;
  929. for (i__ = 1; i__ <= i__1; ++i__) {
  930. i__3 = *kd + (i__ + 1) * ab_dim1;
  931. t.r = ab[i__3].r, t.i = ab[i__3].i;
  932. abst = c_abs(&t);
  933. i__3 = *kd + (i__ + 1) * ab_dim1;
  934. ab[i__3].r = abst, ab[i__3].i = 0.f;
  935. e[i__] = abst;
  936. if (abst != 0.f) {
  937. q__1.r = t.r / abst, q__1.i = t.i / abst;
  938. t.r = q__1.r, t.i = q__1.i;
  939. } else {
  940. t.r = 1.f, t.i = 0.f;
  941. }
  942. if (i__ < *n - 1) {
  943. i__3 = *kd + (i__ + 2) * ab_dim1;
  944. i__2 = *kd + (i__ + 2) * ab_dim1;
  945. q__1.r = ab[i__2].r * t.r - ab[i__2].i * t.i, q__1.i = ab[
  946. i__2].r * t.i + ab[i__2].i * t.r;
  947. ab[i__3].r = q__1.r, ab[i__3].i = q__1.i;
  948. }
  949. if (wantq) {
  950. r_cnjg(&q__1, &t);
  951. cscal_(n, &q__1, &q[(i__ + 1) * q_dim1 + 1], &c__1);
  952. }
  953. /* L100: */
  954. }
  955. } else {
  956. /* set E to zero if original matrix was diagonal */
  957. i__1 = *n - 1;
  958. for (i__ = 1; i__ <= i__1; ++i__) {
  959. e[i__] = 0.f;
  960. /* L110: */
  961. }
  962. }
  963. /* copy diagonal elements to D */
  964. i__1 = *n;
  965. for (i__ = 1; i__ <= i__1; ++i__) {
  966. i__3 = i__;
  967. i__2 = kd1 + i__ * ab_dim1;
  968. d__[i__3] = ab[i__2].r;
  969. /* L120: */
  970. }
  971. } else {
  972. if (*kd > 1) {
  973. /* Reduce to complex Hermitian tridiagonal form, working with */
  974. /* the lower triangle */
  975. nr = 0;
  976. j1 = kdn + 2;
  977. j2 = 1;
  978. i__1 = ab_dim1 + 1;
  979. i__3 = ab_dim1 + 1;
  980. r__1 = ab[i__3].r;
  981. ab[i__1].r = r__1, ab[i__1].i = 0.f;
  982. i__1 = *n - 2;
  983. for (i__ = 1; i__ <= i__1; ++i__) {
  984. /* Reduce i-th column of matrix to tridiagonal form */
  985. for (k = kdn + 1; k >= 2; --k) {
  986. j1 += kdn;
  987. j2 += kdn;
  988. if (nr > 0) {
  989. /* generate plane rotations to annihilate nonzero */
  990. /* elements which have been created outside the band */
  991. clargv_(&nr, &ab[kd1 + (j1 - kd1) * ab_dim1], &inca, &
  992. work[j1], &kd1, &d__[j1], &kd1);
  993. /* apply plane rotations from one side */
  994. /* Dependent on the the number of diagonals either */
  995. /* CLARTV or CROT is used */
  996. if (nr > (*kd << 1) - 1) {
  997. i__3 = *kd - 1;
  998. for (l = 1; l <= i__3; ++l) {
  999. clartv_(&nr, &ab[kd1 - l + (j1 - kd1 + l) *
  1000. ab_dim1], &inca, &ab[kd1 - l + 1 + (
  1001. j1 - kd1 + l) * ab_dim1], &inca, &d__[
  1002. j1], &work[j1], &kd1);
  1003. /* L130: */
  1004. }
  1005. } else {
  1006. jend = j1 + kd1 * (nr - 1);
  1007. i__3 = jend;
  1008. i__2 = kd1;
  1009. for (jinc = j1; i__2 < 0 ? jinc >= i__3 : jinc <=
  1010. i__3; jinc += i__2) {
  1011. crot_(&kdm1, &ab[*kd + (jinc - *kd) * ab_dim1]
  1012. , &incx, &ab[kd1 + (jinc - *kd) *
  1013. ab_dim1], &incx, &d__[jinc], &work[
  1014. jinc]);
  1015. /* L140: */
  1016. }
  1017. }
  1018. }
  1019. if (k > 2) {
  1020. if (k <= *n - i__ + 1) {
  1021. /* generate plane rotation to annihilate a(i+k-1,i) */
  1022. /* within the band */
  1023. clartg_(&ab[k - 1 + i__ * ab_dim1], &ab[k + i__ *
  1024. ab_dim1], &d__[i__ + k - 1], &work[i__ +
  1025. k - 1], &temp);
  1026. i__2 = k - 1 + i__ * ab_dim1;
  1027. ab[i__2].r = temp.r, ab[i__2].i = temp.i;
  1028. /* apply rotation from the left */
  1029. i__2 = k - 3;
  1030. i__3 = *ldab - 1;
  1031. i__4 = *ldab - 1;
  1032. crot_(&i__2, &ab[k - 2 + (i__ + 1) * ab_dim1], &
  1033. i__3, &ab[k - 1 + (i__ + 1) * ab_dim1], &
  1034. i__4, &d__[i__ + k - 1], &work[i__ + k -
  1035. 1]);
  1036. }
  1037. ++nr;
  1038. j1 = j1 - kdn - 1;
  1039. }
  1040. /* apply plane rotations from both sides to diagonal */
  1041. /* blocks */
  1042. if (nr > 0) {
  1043. clar2v_(&nr, &ab[(j1 - 1) * ab_dim1 + 1], &ab[j1 *
  1044. ab_dim1 + 1], &ab[(j1 - 1) * ab_dim1 + 2], &
  1045. inca, &d__[j1], &work[j1], &kd1);
  1046. }
  1047. /* apply plane rotations from the right */
  1048. /* Dependent on the the number of diagonals either */
  1049. /* CLARTV or CROT is used */
  1050. if (nr > 0) {
  1051. clacgv_(&nr, &work[j1], &kd1);
  1052. if (nr > (*kd << 1) - 1) {
  1053. i__2 = *kd - 1;
  1054. for (l = 1; l <= i__2; ++l) {
  1055. if (j2 + l > *n) {
  1056. nrt = nr - 1;
  1057. } else {
  1058. nrt = nr;
  1059. }
  1060. if (nrt > 0) {
  1061. clartv_(&nrt, &ab[l + 2 + (j1 - 1) *
  1062. ab_dim1], &inca, &ab[l + 1 + j1 *
  1063. ab_dim1], &inca, &d__[j1], &work[
  1064. j1], &kd1);
  1065. }
  1066. /* L150: */
  1067. }
  1068. } else {
  1069. j1end = j1 + kd1 * (nr - 2);
  1070. if (j1end >= j1) {
  1071. i__2 = j1end;
  1072. i__3 = kd1;
  1073. for (j1inc = j1; i__3 < 0 ? j1inc >= i__2 :
  1074. j1inc <= i__2; j1inc += i__3) {
  1075. crot_(&kdm1, &ab[(j1inc - 1) * ab_dim1 +
  1076. 3], &c__1, &ab[j1inc * ab_dim1 +
  1077. 2], &c__1, &d__[j1inc], &work[
  1078. j1inc]);
  1079. /* L160: */
  1080. }
  1081. }
  1082. /* Computing MIN */
  1083. i__3 = kdm1, i__2 = *n - j2;
  1084. lend = f2cmin(i__3,i__2);
  1085. last = j1end + kd1;
  1086. if (lend > 0) {
  1087. crot_(&lend, &ab[(last - 1) * ab_dim1 + 3], &
  1088. c__1, &ab[last * ab_dim1 + 2], &c__1,
  1089. &d__[last], &work[last]);
  1090. }
  1091. }
  1092. }
  1093. if (wantq) {
  1094. /* accumulate product of plane rotations in Q */
  1095. if (initq) {
  1096. /* take advantage of the fact that Q was */
  1097. /* initially the Identity matrix */
  1098. iqend = f2cmax(iqend,j2);
  1099. /* Computing MAX */
  1100. i__3 = 0, i__2 = k - 3;
  1101. i2 = f2cmax(i__3,i__2);
  1102. iqaend = i__ * *kd + 1;
  1103. if (k == 2) {
  1104. iqaend += *kd;
  1105. }
  1106. iqaend = f2cmin(iqaend,iqend);
  1107. i__3 = j2;
  1108. i__2 = kd1;
  1109. for (j = j1; i__2 < 0 ? j >= i__3 : j <= i__3; j
  1110. += i__2) {
  1111. ibl = i__ - i2 / kdm1;
  1112. ++i2;
  1113. /* Computing MAX */
  1114. i__4 = 1, i__5 = j - ibl;
  1115. iqb = f2cmax(i__4,i__5);
  1116. nq = iqaend + 1 - iqb;
  1117. /* Computing MIN */
  1118. i__4 = iqaend + *kd;
  1119. iqaend = f2cmin(i__4,iqend);
  1120. crot_(&nq, &q[iqb + (j - 1) * q_dim1], &c__1,
  1121. &q[iqb + j * q_dim1], &c__1, &d__[j],
  1122. &work[j]);
  1123. /* L170: */
  1124. }
  1125. } else {
  1126. i__2 = j2;
  1127. i__3 = kd1;
  1128. for (j = j1; i__3 < 0 ? j >= i__2 : j <= i__2; j
  1129. += i__3) {
  1130. crot_(n, &q[(j - 1) * q_dim1 + 1], &c__1, &q[
  1131. j * q_dim1 + 1], &c__1, &d__[j], &
  1132. work[j]);
  1133. /* L180: */
  1134. }
  1135. }
  1136. }
  1137. if (j2 + kdn > *n) {
  1138. /* adjust J2 to keep within the bounds of the matrix */
  1139. --nr;
  1140. j2 = j2 - kdn - 1;
  1141. }
  1142. i__3 = j2;
  1143. i__2 = kd1;
  1144. for (j = j1; i__2 < 0 ? j >= i__3 : j <= i__3; j += i__2)
  1145. {
  1146. /* create nonzero element a(j+kd,j-1) outside the */
  1147. /* band and store it in WORK */
  1148. i__4 = j + *kd;
  1149. i__5 = j;
  1150. i__6 = kd1 + j * ab_dim1;
  1151. q__1.r = work[i__5].r * ab[i__6].r - work[i__5].i *
  1152. ab[i__6].i, q__1.i = work[i__5].r * ab[i__6]
  1153. .i + work[i__5].i * ab[i__6].r;
  1154. work[i__4].r = q__1.r, work[i__4].i = q__1.i;
  1155. i__4 = kd1 + j * ab_dim1;
  1156. i__5 = j;
  1157. i__6 = kd1 + j * ab_dim1;
  1158. q__1.r = d__[i__5] * ab[i__6].r, q__1.i = d__[i__5] *
  1159. ab[i__6].i;
  1160. ab[i__4].r = q__1.r, ab[i__4].i = q__1.i;
  1161. /* L190: */
  1162. }
  1163. /* L200: */
  1164. }
  1165. /* L210: */
  1166. }
  1167. }
  1168. if (*kd > 0) {
  1169. /* make off-diagonal elements real and copy them to E */
  1170. i__1 = *n - 1;
  1171. for (i__ = 1; i__ <= i__1; ++i__) {
  1172. i__2 = i__ * ab_dim1 + 2;
  1173. t.r = ab[i__2].r, t.i = ab[i__2].i;
  1174. abst = c_abs(&t);
  1175. i__2 = i__ * ab_dim1 + 2;
  1176. ab[i__2].r = abst, ab[i__2].i = 0.f;
  1177. e[i__] = abst;
  1178. if (abst != 0.f) {
  1179. q__1.r = t.r / abst, q__1.i = t.i / abst;
  1180. t.r = q__1.r, t.i = q__1.i;
  1181. } else {
  1182. t.r = 1.f, t.i = 0.f;
  1183. }
  1184. if (i__ < *n - 1) {
  1185. i__2 = (i__ + 1) * ab_dim1 + 2;
  1186. i__3 = (i__ + 1) * ab_dim1 + 2;
  1187. q__1.r = ab[i__3].r * t.r - ab[i__3].i * t.i, q__1.i = ab[
  1188. i__3].r * t.i + ab[i__3].i * t.r;
  1189. ab[i__2].r = q__1.r, ab[i__2].i = q__1.i;
  1190. }
  1191. if (wantq) {
  1192. cscal_(n, &t, &q[(i__ + 1) * q_dim1 + 1], &c__1);
  1193. }
  1194. /* L220: */
  1195. }
  1196. } else {
  1197. /* set E to zero if original matrix was diagonal */
  1198. i__1 = *n - 1;
  1199. for (i__ = 1; i__ <= i__1; ++i__) {
  1200. e[i__] = 0.f;
  1201. /* L230: */
  1202. }
  1203. }
  1204. /* copy diagonal elements to D */
  1205. i__1 = *n;
  1206. for (i__ = 1; i__ <= i__1; ++i__) {
  1207. i__2 = i__;
  1208. i__3 = i__ * ab_dim1 + 1;
  1209. d__[i__2] = ab[i__3].r;
  1210. /* L240: */
  1211. }
  1212. }
  1213. return;
  1214. /* End of CHBTRD */
  1215. } /* chbtrd_ */