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.

zlaghe.c 18 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619
  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 char integer1;
  52. #define TRUE_ (1)
  53. #define FALSE_ (0)
  54. /* Extern is for use with -E */
  55. #ifndef Extern
  56. #define Extern extern
  57. #endif
  58. /* I/O stuff */
  59. typedef int flag;
  60. typedef int ftnlen;
  61. typedef int ftnint;
  62. /*external read, write*/
  63. typedef struct
  64. { flag cierr;
  65. ftnint ciunit;
  66. flag ciend;
  67. char *cifmt;
  68. ftnint cirec;
  69. } cilist;
  70. /*internal read, write*/
  71. typedef struct
  72. { flag icierr;
  73. char *iciunit;
  74. flag iciend;
  75. char *icifmt;
  76. ftnint icirlen;
  77. ftnint icirnum;
  78. } icilist;
  79. /*open*/
  80. typedef struct
  81. { flag oerr;
  82. ftnint ounit;
  83. char *ofnm;
  84. ftnlen ofnmlen;
  85. char *osta;
  86. char *oacc;
  87. char *ofm;
  88. ftnint orl;
  89. char *oblnk;
  90. } olist;
  91. /*close*/
  92. typedef struct
  93. { flag cerr;
  94. ftnint cunit;
  95. char *csta;
  96. } cllist;
  97. /*rewind, backspace, endfile*/
  98. typedef struct
  99. { flag aerr;
  100. ftnint aunit;
  101. } alist;
  102. /* inquire */
  103. typedef struct
  104. { flag inerr;
  105. ftnint inunit;
  106. char *infile;
  107. ftnlen infilen;
  108. ftnint *inex; /*parameters in standard's order*/
  109. ftnint *inopen;
  110. ftnint *innum;
  111. ftnint *innamed;
  112. char *inname;
  113. ftnlen innamlen;
  114. char *inacc;
  115. ftnlen inacclen;
  116. char *inseq;
  117. ftnlen inseqlen;
  118. char *indir;
  119. ftnlen indirlen;
  120. char *infmt;
  121. ftnlen infmtlen;
  122. char *inform;
  123. ftnint informlen;
  124. char *inunf;
  125. ftnlen inunflen;
  126. ftnint *inrecl;
  127. ftnint *innrec;
  128. char *inblank;
  129. ftnlen inblanklen;
  130. } inlist;
  131. #define VOID void
  132. union Multitype { /* for multiple entry points */
  133. integer1 g;
  134. shortint h;
  135. integer i;
  136. /* longint j; */
  137. real r;
  138. doublereal d;
  139. complex c;
  140. doublecomplex z;
  141. };
  142. typedef union Multitype Multitype;
  143. struct Vardesc { /* for Namelist */
  144. char *name;
  145. char *addr;
  146. ftnlen *dims;
  147. int type;
  148. };
  149. typedef struct Vardesc Vardesc;
  150. struct Namelist {
  151. char *name;
  152. Vardesc **vars;
  153. int nvars;
  154. };
  155. typedef struct Namelist Namelist;
  156. #define abs(x) ((x) >= 0 ? (x) : -(x))
  157. #define dabs(x) (fabs(x))
  158. #define f2cmin(a,b) ((a) <= (b) ? (a) : (b))
  159. #define f2cmax(a,b) ((a) >= (b) ? (a) : (b))
  160. #define dmin(a,b) (f2cmin(a,b))
  161. #define dmax(a,b) (f2cmax(a,b))
  162. #define bit_test(a,b) ((a) >> (b) & 1)
  163. #define bit_clear(a,b) ((a) & ~((uinteger)1 << (b)))
  164. #define bit_set(a,b) ((a) | ((uinteger)1 << (b)))
  165. #define abort_() { sig_die("Fortran abort routine called", 1); }
  166. #define c_abs(z) (cabsf(Cf(z)))
  167. #define c_cos(R,Z) { pCf(R)=ccos(Cf(Z)); }
  168. #ifdef _MSC_VER
  169. #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]);}
  170. #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]/Cd(b)._Val[1]);}
  171. #else
  172. #define c_div(c, a, b) {pCf(c) = Cf(a)/Cf(b);}
  173. #define z_div(c, a, b) {pCd(c) = Cd(a)/Cd(b);}
  174. #endif
  175. #define c_exp(R, Z) {pCf(R) = cexpf(Cf(Z));}
  176. #define c_log(R, Z) {pCf(R) = clogf(Cf(Z));}
  177. #define c_sin(R, Z) {pCf(R) = csinf(Cf(Z));}
  178. //#define c_sqrt(R, Z) {*(R) = csqrtf(Cf(Z));}
  179. #define c_sqrt(R, Z) {pCf(R) = csqrtf(Cf(Z));}
  180. #define d_abs(x) (fabs(*(x)))
  181. #define d_acos(x) (acos(*(x)))
  182. #define d_asin(x) (asin(*(x)))
  183. #define d_atan(x) (atan(*(x)))
  184. #define d_atn2(x, y) (atan2(*(x),*(y)))
  185. #define d_cnjg(R, Z) { pCd(R) = conj(Cd(Z)); }
  186. #define r_cnjg(R, Z) { pCf(R) = conjf(Cf(Z)); }
  187. #define d_cos(x) (cos(*(x)))
  188. #define d_cosh(x) (cosh(*(x)))
  189. #define d_dim(__a, __b) ( *(__a) > *(__b) ? *(__a) - *(__b) : 0.0 )
  190. #define d_exp(x) (exp(*(x)))
  191. #define d_imag(z) (cimag(Cd(z)))
  192. #define r_imag(z) (cimagf(Cf(z)))
  193. #define d_int(__x) (*(__x)>0 ? floor(*(__x)) : -floor(- *(__x)))
  194. #define r_int(__x) (*(__x)>0 ? floor(*(__x)) : -floor(- *(__x)))
  195. #define d_lg10(x) ( 0.43429448190325182765 * log(*(x)) )
  196. #define r_lg10(x) ( 0.43429448190325182765 * log(*(x)) )
  197. #define d_log(x) (log(*(x)))
  198. #define d_mod(x, y) (fmod(*(x), *(y)))
  199. #define u_nint(__x) ((__x)>=0 ? floor((__x) + .5) : -floor(.5 - (__x)))
  200. #define d_nint(x) u_nint(*(x))
  201. #define u_sign(__a,__b) ((__b) >= 0 ? ((__a) >= 0 ? (__a) : -(__a)) : -((__a) >= 0 ? (__a) : -(__a)))
  202. #define d_sign(a,b) u_sign(*(a),*(b))
  203. #define r_sign(a,b) u_sign(*(a),*(b))
  204. #define d_sin(x) (sin(*(x)))
  205. #define d_sinh(x) (sinh(*(x)))
  206. #define d_sqrt(x) (sqrt(*(x)))
  207. #define d_tan(x) (tan(*(x)))
  208. #define d_tanh(x) (tanh(*(x)))
  209. #define i_abs(x) abs(*(x))
  210. #define i_dnnt(x) ((integer)u_nint(*(x)))
  211. #define i_len(s, n) (n)
  212. #define i_nint(x) ((integer)u_nint(*(x)))
  213. #define i_sign(a,b) ((integer)u_sign((integer)*(a),(integer)*(b)))
  214. #define pow_dd(ap, bp) ( pow(*(ap), *(bp)))
  215. #define pow_si(B,E) spow_ui(*(B),*(E))
  216. #define pow_ri(B,E) spow_ui(*(B),*(E))
  217. #define pow_di(B,E) dpow_ui(*(B),*(E))
  218. #define pow_zi(p, a, b) {pCd(p) = zpow_ui(Cd(a), *(b));}
  219. #define pow_ci(p, a, b) {pCf(p) = cpow_ui(Cf(a), *(b));}
  220. #define pow_zz(R,A,B) {pCd(R) = cpow(Cd(A),*(B));}
  221. #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++ = ' '; }
  222. #define s_cmp(a,b,c,d) ((integer)strncmp((a),(b),f2cmin((c),(d))))
  223. #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]; }
  224. #define sig_die(s, kill) { exit(1); }
  225. #define s_stop(s, n) {exit(0);}
  226. #define z_abs(z) (cabs(Cd(z)))
  227. #define z_exp(R, Z) {pCd(R) = cexp(Cd(Z));}
  228. #define z_sqrt(R, Z) {pCd(R) = csqrt(Cd(Z));}
  229. #define myexit_() break;
  230. #define mycycle_() continue;
  231. #define myceiling_(w) {ceil(w)}
  232. #define myhuge_(w) {HUGE_VAL}
  233. //#define mymaxloc_(w,s,e,n) {if (sizeof(*(w)) == sizeof(double)) dmaxloc_((w),*(s),*(e),n); else dmaxloc_((w),*(s),*(e),n);}
  234. #define mymaxloc_(w,s,e,n) {dmaxloc_(w,*(s),*(e),n)}
  235. /* procedure parameter types for -A and -C++ */
  236. /* Table of constant values */
  237. static doublecomplex c_b1 = {0.,0.};
  238. static doublecomplex c_b2 = {1.,0.};
  239. static integer c__3 = 3;
  240. static integer c__1 = 1;
  241. /* > \brief \b ZLAGHE */
  242. /* =========== DOCUMENTATION =========== */
  243. /* Online html documentation available at */
  244. /* http://www.netlib.org/lapack/explore-html/ */
  245. /* Definition: */
  246. /* =========== */
  247. /* SUBROUTINE ZLAGHE( N, K, D, A, LDA, ISEED, WORK, INFO ) */
  248. /* INTEGER INFO, K, LDA, N */
  249. /* INTEGER ISEED( 4 ) */
  250. /* DOUBLE PRECISION D( * ) */
  251. /* COMPLEX*16 A( LDA, * ), WORK( * ) */
  252. /* > \par Purpose: */
  253. /* ============= */
  254. /* > */
  255. /* > \verbatim */
  256. /* > */
  257. /* > ZLAGHE generates a complex hermitian matrix A, by pre- and post- */
  258. /* > multiplying a real diagonal matrix D with a random unitary matrix: */
  259. /* > A = U*D*U'. The semi-bandwidth may then be reduced to k by additional */
  260. /* > unitary transformations. */
  261. /* > \endverbatim */
  262. /* Arguments: */
  263. /* ========== */
  264. /* > \param[in] N */
  265. /* > \verbatim */
  266. /* > N is INTEGER */
  267. /* > The order of the matrix A. N >= 0. */
  268. /* > \endverbatim */
  269. /* > */
  270. /* > \param[in] K */
  271. /* > \verbatim */
  272. /* > K is INTEGER */
  273. /* > The number of nonzero subdiagonals within the band of A. */
  274. /* > 0 <= K <= N-1. */
  275. /* > \endverbatim */
  276. /* > */
  277. /* > \param[in] D */
  278. /* > \verbatim */
  279. /* > D is DOUBLE PRECISION array, dimension (N) */
  280. /* > The diagonal elements of the diagonal matrix D. */
  281. /* > \endverbatim */
  282. /* > */
  283. /* > \param[out] A */
  284. /* > \verbatim */
  285. /* > A is COMPLEX*16 array, dimension (LDA,N) */
  286. /* > The generated n by n hermitian matrix A (the full matrix is */
  287. /* > stored). */
  288. /* > \endverbatim */
  289. /* > */
  290. /* > \param[in] LDA */
  291. /* > \verbatim */
  292. /* > LDA is INTEGER */
  293. /* > The leading dimension of the array A. LDA >= N. */
  294. /* > \endverbatim */
  295. /* > */
  296. /* > \param[in,out] ISEED */
  297. /* > \verbatim */
  298. /* > ISEED is INTEGER array, dimension (4) */
  299. /* > On entry, the seed of the random number generator; the array */
  300. /* > elements must be between 0 and 4095, and ISEED(4) must be */
  301. /* > odd. */
  302. /* > On exit, the seed is updated. */
  303. /* > \endverbatim */
  304. /* > */
  305. /* > \param[out] WORK */
  306. /* > \verbatim */
  307. /* > WORK is COMPLEX*16 array, dimension (2*N) */
  308. /* > \endverbatim */
  309. /* > */
  310. /* > \param[out] INFO */
  311. /* > \verbatim */
  312. /* > INFO is INTEGER */
  313. /* > = 0: successful exit */
  314. /* > < 0: if INFO = -i, the i-th argument had an illegal value */
  315. /* > \endverbatim */
  316. /* Authors: */
  317. /* ======== */
  318. /* > \author Univ. of Tennessee */
  319. /* > \author Univ. of California Berkeley */
  320. /* > \author Univ. of Colorado Denver */
  321. /* > \author NAG Ltd. */
  322. /* > \date December 2016 */
  323. /* > \ingroup complex16_matgen */
  324. /* ===================================================================== */
  325. /* Subroutine */ void zlaghe_(integer *n, integer *k, doublereal *d__,
  326. doublecomplex *a, integer *lda, integer *iseed, doublecomplex *work,
  327. integer *info)
  328. {
  329. /* System generated locals */
  330. integer a_dim1, a_offset, i__1, i__2, i__3;
  331. doublereal d__1;
  332. doublecomplex z__1, z__2, z__3, z__4;
  333. /* Local variables */
  334. extern /* Subroutine */ void zher2_(char *, integer *, doublecomplex *,
  335. doublecomplex *, integer *, doublecomplex *, integer *,
  336. doublecomplex *, integer *);
  337. integer i__, j;
  338. doublecomplex alpha;
  339. extern /* Subroutine */ void zgerc_(integer *, integer *, doublecomplex *,
  340. doublecomplex *, integer *, doublecomplex *, integer *,
  341. doublecomplex *, integer *), zscal_(integer *, doublecomplex *,
  342. doublecomplex *, integer *);
  343. extern /* Double Complex */ VOID zdotc_(doublecomplex *, integer *,
  344. doublecomplex *, integer *, doublecomplex *, integer *);
  345. extern /* Subroutine */ void zgemv_(char *, integer *, integer *,
  346. doublecomplex *, doublecomplex *, integer *, doublecomplex *,
  347. integer *, doublecomplex *, doublecomplex *, integer *),
  348. zhemv_(char *, integer *, doublecomplex *, doublecomplex *,
  349. integer *, doublecomplex *, integer *, doublecomplex *,
  350. doublecomplex *, integer *), zaxpy_(integer *,
  351. doublecomplex *, doublecomplex *, integer *, doublecomplex *,
  352. integer *);
  353. extern doublereal dznrm2_(integer *, doublecomplex *, integer *);
  354. doublecomplex wa, wb;
  355. doublereal wn;
  356. extern /* Subroutine */ int xerbla_(char *, integer *, ftnlen);
  357. extern void zlarnv_(
  358. integer *, integer *, integer *, doublecomplex *);
  359. doublecomplex tau;
  360. /* -- LAPACK auxiliary routine (version 3.7.0) -- */
  361. /* -- LAPACK is a software package provided by Univ. of Tennessee, -- */
  362. /* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- */
  363. /* December 2016 */
  364. /* ===================================================================== */
  365. /* Test the input arguments */
  366. /* Parameter adjustments */
  367. --d__;
  368. a_dim1 = *lda;
  369. a_offset = 1 + a_dim1 * 1;
  370. a -= a_offset;
  371. --iseed;
  372. --work;
  373. /* Function Body */
  374. *info = 0;
  375. if (*n < 0) {
  376. *info = -1;
  377. } else if (*k < 0 || *k > *n - 1) {
  378. *info = -2;
  379. } else if (*lda < f2cmax(1,*n)) {
  380. *info = -5;
  381. }
  382. if (*info < 0) {
  383. i__1 = -(*info);
  384. xerbla_("ZLAGHE", &i__1, 6);
  385. return;
  386. }
  387. /* initialize lower triangle of A to diagonal matrix */
  388. i__1 = *n;
  389. for (j = 1; j <= i__1; ++j) {
  390. i__2 = *n;
  391. for (i__ = j + 1; i__ <= i__2; ++i__) {
  392. i__3 = i__ + j * a_dim1;
  393. a[i__3].r = 0., a[i__3].i = 0.;
  394. /* L10: */
  395. }
  396. /* L20: */
  397. }
  398. i__1 = *n;
  399. for (i__ = 1; i__ <= i__1; ++i__) {
  400. i__2 = i__ + i__ * a_dim1;
  401. i__3 = i__;
  402. a[i__2].r = d__[i__3], a[i__2].i = 0.;
  403. /* L30: */
  404. }
  405. /* Generate lower triangle of hermitian matrix */
  406. for (i__ = *n - 1; i__ >= 1; --i__) {
  407. /* generate random reflection */
  408. i__1 = *n - i__ + 1;
  409. zlarnv_(&c__3, &iseed[1], &i__1, &work[1]);
  410. i__1 = *n - i__ + 1;
  411. wn = dznrm2_(&i__1, &work[1], &c__1);
  412. d__1 = wn / z_abs(&work[1]);
  413. z__1.r = d__1 * work[1].r, z__1.i = d__1 * work[1].i;
  414. wa.r = z__1.r, wa.i = z__1.i;
  415. if (wn == 0.) {
  416. tau.r = 0., tau.i = 0.;
  417. } else {
  418. z__1.r = work[1].r + wa.r, z__1.i = work[1].i + wa.i;
  419. wb.r = z__1.r, wb.i = z__1.i;
  420. i__1 = *n - i__;
  421. z_div(&z__1, &c_b2, &wb);
  422. zscal_(&i__1, &z__1, &work[2], &c__1);
  423. work[1].r = 1., work[1].i = 0.;
  424. z_div(&z__1, &wb, &wa);
  425. d__1 = z__1.r;
  426. tau.r = d__1, tau.i = 0.;
  427. }
  428. /* apply random reflection to A(i:n,i:n) from the left */
  429. /* and the right */
  430. /* compute y := tau * A * u */
  431. i__1 = *n - i__ + 1;
  432. zhemv_("Lower", &i__1, &tau, &a[i__ + i__ * a_dim1], lda, &work[1], &
  433. c__1, &c_b1, &work[*n + 1], &c__1);
  434. /* compute v := y - 1/2 * tau * ( y, u ) * u */
  435. z__3.r = -.5, z__3.i = 0.;
  436. z__2.r = z__3.r * tau.r - z__3.i * tau.i, z__2.i = z__3.r * tau.i +
  437. z__3.i * tau.r;
  438. i__1 = *n - i__ + 1;
  439. zdotc_(&z__4, &i__1, &work[*n + 1], &c__1, &work[1], &c__1);
  440. z__1.r = z__2.r * z__4.r - z__2.i * z__4.i, z__1.i = z__2.r * z__4.i
  441. + z__2.i * z__4.r;
  442. alpha.r = z__1.r, alpha.i = z__1.i;
  443. i__1 = *n - i__ + 1;
  444. zaxpy_(&i__1, &alpha, &work[1], &c__1, &work[*n + 1], &c__1);
  445. /* apply the transformation as a rank-2 update to A(i:n,i:n) */
  446. i__1 = *n - i__ + 1;
  447. z__1.r = -1., z__1.i = 0.;
  448. zher2_("Lower", &i__1, &z__1, &work[1], &c__1, &work[*n + 1], &c__1, &
  449. a[i__ + i__ * a_dim1], lda);
  450. /* L40: */
  451. }
  452. /* Reduce number of subdiagonals to K */
  453. i__1 = *n - 1 - *k;
  454. for (i__ = 1; i__ <= i__1; ++i__) {
  455. /* generate reflection to annihilate A(k+i+1:n,i) */
  456. i__2 = *n - *k - i__ + 1;
  457. wn = dznrm2_(&i__2, &a[*k + i__ + i__ * a_dim1], &c__1);
  458. d__1 = wn / z_abs(&a[*k + i__ + i__ * a_dim1]);
  459. i__2 = *k + i__ + i__ * a_dim1;
  460. z__1.r = d__1 * a[i__2].r, z__1.i = d__1 * a[i__2].i;
  461. wa.r = z__1.r, wa.i = z__1.i;
  462. if (wn == 0.) {
  463. tau.r = 0., tau.i = 0.;
  464. } else {
  465. i__2 = *k + i__ + i__ * a_dim1;
  466. z__1.r = a[i__2].r + wa.r, z__1.i = a[i__2].i + wa.i;
  467. wb.r = z__1.r, wb.i = z__1.i;
  468. i__2 = *n - *k - i__;
  469. z_div(&z__1, &c_b2, &wb);
  470. zscal_(&i__2, &z__1, &a[*k + i__ + 1 + i__ * a_dim1], &c__1);
  471. i__2 = *k + i__ + i__ * a_dim1;
  472. a[i__2].r = 1., a[i__2].i = 0.;
  473. z_div(&z__1, &wb, &wa);
  474. d__1 = z__1.r;
  475. tau.r = d__1, tau.i = 0.;
  476. }
  477. /* apply reflection to A(k+i:n,i+1:k+i-1) from the left */
  478. i__2 = *n - *k - i__ + 1;
  479. i__3 = *k - 1;
  480. zgemv_("Conjugate transpose", &i__2, &i__3, &c_b2, &a[*k + i__ + (i__
  481. + 1) * a_dim1], lda, &a[*k + i__ + i__ * a_dim1], &c__1, &
  482. c_b1, &work[1], &c__1);
  483. i__2 = *n - *k - i__ + 1;
  484. i__3 = *k - 1;
  485. z__1.r = -tau.r, z__1.i = -tau.i;
  486. zgerc_(&i__2, &i__3, &z__1, &a[*k + i__ + i__ * a_dim1], &c__1, &work[
  487. 1], &c__1, &a[*k + i__ + (i__ + 1) * a_dim1], lda);
  488. /* apply reflection to A(k+i:n,k+i:n) from the left and the right */
  489. /* compute y := tau * A * u */
  490. i__2 = *n - *k - i__ + 1;
  491. zhemv_("Lower", &i__2, &tau, &a[*k + i__ + (*k + i__) * a_dim1], lda,
  492. &a[*k + i__ + i__ * a_dim1], &c__1, &c_b1, &work[1], &c__1);
  493. /* compute v := y - 1/2 * tau * ( y, u ) * u */
  494. z__3.r = -.5, z__3.i = 0.;
  495. z__2.r = z__3.r * tau.r - z__3.i * tau.i, z__2.i = z__3.r * tau.i +
  496. z__3.i * tau.r;
  497. i__2 = *n - *k - i__ + 1;
  498. zdotc_(&z__4, &i__2, &work[1], &c__1, &a[*k + i__ + i__ * a_dim1], &
  499. c__1);
  500. z__1.r = z__2.r * z__4.r - z__2.i * z__4.i, z__1.i = z__2.r * z__4.i
  501. + z__2.i * z__4.r;
  502. alpha.r = z__1.r, alpha.i = z__1.i;
  503. i__2 = *n - *k - i__ + 1;
  504. zaxpy_(&i__2, &alpha, &a[*k + i__ + i__ * a_dim1], &c__1, &work[1], &
  505. c__1);
  506. /* apply hermitian rank-2 update to A(k+i:n,k+i:n) */
  507. i__2 = *n - *k - i__ + 1;
  508. z__1.r = -1., z__1.i = 0.;
  509. zher2_("Lower", &i__2, &z__1, &a[*k + i__ + i__ * a_dim1], &c__1, &
  510. work[1], &c__1, &a[*k + i__ + (*k + i__) * a_dim1], lda);
  511. i__2 = *k + i__ + i__ * a_dim1;
  512. z__1.r = -wa.r, z__1.i = -wa.i;
  513. a[i__2].r = z__1.r, a[i__2].i = z__1.i;
  514. i__2 = *n;
  515. for (j = *k + i__ + 1; j <= i__2; ++j) {
  516. i__3 = j + i__ * a_dim1;
  517. a[i__3].r = 0., a[i__3].i = 0.;
  518. /* L50: */
  519. }
  520. /* L60: */
  521. }
  522. /* Store full hermitian matrix */
  523. i__1 = *n;
  524. for (j = 1; j <= i__1; ++j) {
  525. i__2 = *n;
  526. for (i__ = j + 1; i__ <= i__2; ++i__) {
  527. i__3 = j + i__ * a_dim1;
  528. d_cnjg(&z__1, &a[i__ + j * a_dim1]);
  529. a[i__3].r = z__1.r, a[i__3].i = z__1.i;
  530. /* L70: */
  531. }
  532. /* L80: */
  533. }
  534. return;
  535. /* End of ZLAGHE */
  536. } /* zlaghe_ */