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.

claghe.c 18 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618
  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. #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. #define F2C_proc_par_types 1
  240. /* Table of constant values */
  241. static complex c_b1 = {0.f,0.f};
  242. static complex c_b2 = {1.f,0.f};
  243. static integer c__3 = 3;
  244. static integer c__1 = 1;
  245. /* > \brief \b CLAGHE */
  246. /* =========== DOCUMENTATION =========== */
  247. /* Online html documentation available at */
  248. /* http://www.netlib.org/lapack/explore-html/ */
  249. /* Definition: */
  250. /* =========== */
  251. /* SUBROUTINE CLAGHE( N, K, D, A, LDA, ISEED, WORK, INFO ) */
  252. /* INTEGER INFO, K, LDA, N */
  253. /* INTEGER ISEED( 4 ) */
  254. /* REAL D( * ) */
  255. /* COMPLEX A( LDA, * ), WORK( * ) */
  256. /* > \par Purpose: */
  257. /* ============= */
  258. /* > */
  259. /* > \verbatim */
  260. /* > */
  261. /* > CLAGHE generates a complex hermitian matrix A, by pre- and post- */
  262. /* > multiplying a real diagonal matrix D with a random unitary matrix: */
  263. /* > A = U*D*U'. The semi-bandwidth may then be reduced to k by additional */
  264. /* > unitary transformations. */
  265. /* > \endverbatim */
  266. /* Arguments: */
  267. /* ========== */
  268. /* > \param[in] N */
  269. /* > \verbatim */
  270. /* > N is INTEGER */
  271. /* > The order of the matrix A. N >= 0. */
  272. /* > \endverbatim */
  273. /* > */
  274. /* > \param[in] K */
  275. /* > \verbatim */
  276. /* > K is INTEGER */
  277. /* > The number of nonzero subdiagonals within the band of A. */
  278. /* > 0 <= K <= N-1. */
  279. /* > \endverbatim */
  280. /* > */
  281. /* > \param[in] D */
  282. /* > \verbatim */
  283. /* > D is REAL array, dimension (N) */
  284. /* > The diagonal elements of the diagonal matrix D. */
  285. /* > \endverbatim */
  286. /* > */
  287. /* > \param[out] A */
  288. /* > \verbatim */
  289. /* > A is COMPLEX array, dimension (LDA,N) */
  290. /* > The generated n by n hermitian matrix A (the full matrix is */
  291. /* > stored). */
  292. /* > \endverbatim */
  293. /* > */
  294. /* > \param[in] LDA */
  295. /* > \verbatim */
  296. /* > LDA is INTEGER */
  297. /* > The leading dimension of the array A. LDA >= N. */
  298. /* > \endverbatim */
  299. /* > */
  300. /* > \param[in,out] ISEED */
  301. /* > \verbatim */
  302. /* > ISEED is INTEGER array, dimension (4) */
  303. /* > On entry, the seed of the random number generator; the array */
  304. /* > elements must be between 0 and 4095, and ISEED(4) must be */
  305. /* > odd. */
  306. /* > On exit, the seed is updated. */
  307. /* > \endverbatim */
  308. /* > */
  309. /* > \param[out] WORK */
  310. /* > \verbatim */
  311. /* > WORK is COMPLEX array, dimension (2*N) */
  312. /* > \endverbatim */
  313. /* > */
  314. /* > \param[out] INFO */
  315. /* > \verbatim */
  316. /* > INFO is INTEGER */
  317. /* > = 0: successful exit */
  318. /* > < 0: if INFO = -i, the i-th argument had an illegal value */
  319. /* > \endverbatim */
  320. /* Authors: */
  321. /* ======== */
  322. /* > \author Univ. of Tennessee */
  323. /* > \author Univ. of California Berkeley */
  324. /* > \author Univ. of Colorado Denver */
  325. /* > \author NAG Ltd. */
  326. /* > \date December 2016 */
  327. /* > \ingroup complex_matgen */
  328. /* ===================================================================== */
  329. /* Subroutine */ void claghe_(integer *n, integer *k, real *d__, complex *a,
  330. integer *lda, integer *iseed, complex *work, integer *info)
  331. {
  332. /* System generated locals */
  333. integer a_dim1, a_offset, i__1, i__2, i__3;
  334. real r__1;
  335. complex q__1, q__2, q__3, q__4;
  336. /* Local variables */
  337. extern /* Subroutine */ void cher2_(char *, integer *, complex *, complex *
  338. , integer *, complex *, integer *, complex *, integer *);
  339. integer i__, j;
  340. extern /* Subroutine */ void cgerc_(integer *, integer *, complex *,
  341. complex *, integer *, complex *, integer *, complex *, integer *);
  342. complex alpha;
  343. extern /* Subroutine */ void cscal_(integer *, complex *, complex *,
  344. integer *);
  345. extern /* Complex */ VOID cdotc_(complex *, integer *, complex *, integer
  346. *, complex *, integer *);
  347. extern /* Subroutine */ void cgemv_(char *, integer *, integer *, complex *
  348. , complex *, integer *, complex *, integer *, complex *, complex *
  349. , integer *), chemv_(char *, integer *, complex *,
  350. complex *, integer *, complex *, integer *, complex *, complex *,
  351. integer *), caxpy_(integer *, complex *, complex *,
  352. integer *, complex *, integer *);
  353. extern real scnrm2_(integer *, complex *, integer *);
  354. complex wa, wb;
  355. real wn;
  356. extern /* Subroutine */ int xerbla_(char *, integer *, ftnlen);
  357. extern void clarnv_(
  358. integer *, integer *, integer *, complex *);
  359. complex 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_("CLAGHE", &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.f, a[i__3].i = 0.f;
  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.f;
  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. clarnv_(&c__3, &iseed[1], &i__1, &work[1]);
  410. i__1 = *n - i__ + 1;
  411. wn = scnrm2_(&i__1, &work[1], &c__1);
  412. r__1 = wn / c_abs(&work[1]);
  413. q__1.r = r__1 * work[1].r, q__1.i = r__1 * work[1].i;
  414. wa.r = q__1.r, wa.i = q__1.i;
  415. if (wn == 0.f) {
  416. tau.r = 0.f, tau.i = 0.f;
  417. } else {
  418. q__1.r = work[1].r + wa.r, q__1.i = work[1].i + wa.i;
  419. wb.r = q__1.r, wb.i = q__1.i;
  420. i__1 = *n - i__;
  421. c_div(&q__1, &c_b2, &wb);
  422. cscal_(&i__1, &q__1, &work[2], &c__1);
  423. work[1].r = 1.f, work[1].i = 0.f;
  424. c_div(&q__1, &wb, &wa);
  425. r__1 = q__1.r;
  426. tau.r = r__1, tau.i = 0.f;
  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. chemv_("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. q__3.r = -.5f, q__3.i = 0.f;
  436. q__2.r = q__3.r * tau.r - q__3.i * tau.i, q__2.i = q__3.r * tau.i +
  437. q__3.i * tau.r;
  438. i__1 = *n - i__ + 1;
  439. cdotc_(&q__4, &i__1, &work[*n + 1], &c__1, &work[1], &c__1);
  440. q__1.r = q__2.r * q__4.r - q__2.i * q__4.i, q__1.i = q__2.r * q__4.i
  441. + q__2.i * q__4.r;
  442. alpha.r = q__1.r, alpha.i = q__1.i;
  443. i__1 = *n - i__ + 1;
  444. caxpy_(&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. q__1.r = -1.f, q__1.i = 0.f;
  448. cher2_("Lower", &i__1, &q__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 = scnrm2_(&i__2, &a[*k + i__ + i__ * a_dim1], &c__1);
  458. r__1 = wn / c_abs(&a[*k + i__ + i__ * a_dim1]);
  459. i__2 = *k + i__ + i__ * a_dim1;
  460. q__1.r = r__1 * a[i__2].r, q__1.i = r__1 * a[i__2].i;
  461. wa.r = q__1.r, wa.i = q__1.i;
  462. if (wn == 0.f) {
  463. tau.r = 0.f, tau.i = 0.f;
  464. } else {
  465. i__2 = *k + i__ + i__ * a_dim1;
  466. q__1.r = a[i__2].r + wa.r, q__1.i = a[i__2].i + wa.i;
  467. wb.r = q__1.r, wb.i = q__1.i;
  468. i__2 = *n - *k - i__;
  469. c_div(&q__1, &c_b2, &wb);
  470. cscal_(&i__2, &q__1, &a[*k + i__ + 1 + i__ * a_dim1], &c__1);
  471. i__2 = *k + i__ + i__ * a_dim1;
  472. a[i__2].r = 1.f, a[i__2].i = 0.f;
  473. c_div(&q__1, &wb, &wa);
  474. r__1 = q__1.r;
  475. tau.r = r__1, tau.i = 0.f;
  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. cgemv_("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. q__1.r = -tau.r, q__1.i = -tau.i;
  486. cgerc_(&i__2, &i__3, &q__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. chemv_("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. q__3.r = -.5f, q__3.i = 0.f;
  495. q__2.r = q__3.r * tau.r - q__3.i * tau.i, q__2.i = q__3.r * tau.i +
  496. q__3.i * tau.r;
  497. i__2 = *n - *k - i__ + 1;
  498. cdotc_(&q__4, &i__2, &work[1], &c__1, &a[*k + i__ + i__ * a_dim1], &
  499. c__1);
  500. q__1.r = q__2.r * q__4.r - q__2.i * q__4.i, q__1.i = q__2.r * q__4.i
  501. + q__2.i * q__4.r;
  502. alpha.r = q__1.r, alpha.i = q__1.i;
  503. i__2 = *n - *k - i__ + 1;
  504. caxpy_(&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. q__1.r = -1.f, q__1.i = 0.f;
  509. cher2_("Lower", &i__2, &q__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. q__1.r = -wa.r, q__1.i = -wa.i;
  513. a[i__2].r = q__1.r, a[i__2].i = q__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.f, a[i__3].i = 0.f;
  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. r_cnjg(&q__1, &a[i__ + j * a_dim1]);
  529. a[i__3].r = q__1.r, a[i__3].i = q__1.i;
  530. /* L70: */
  531. }
  532. /* L80: */
  533. }
  534. return;
  535. /* End of CLAGHE */
  536. } /* claghe_ */