/* nag_zhfrk (f16zqc) Example Program.
*
* NAGPRODCODE Version.
*
* Copyright 2016 Numerical Algorithms Group.
*
* Mark 26, 2016.
*/
#include <nag.h>
#include <nag_stdlib.h>
#include <nagf01.h>
#include <nagf16.h>
#include <nagx04.h>
int main(void)
{
/* Scalars */
Integer exit_status = 0;
double alpha, beta;
Integer i, j, k, n, pda, pdc;
/* Arrays */
Complex *a = 0, *c = 0, *cr = 0;
char nag_enum_arg[40];
/* Nag Types */
Nag_OrderType order;
Nag_RFP_Store transr;
Nag_UploType uplo;
Nag_MatrixType matrix;
Nag_TransType trans;
NagError fail;
INIT_FAIL(fail);
printf("nag_zhfrk (f16zqc) Example Program Results\n");
/* Skip heading in data file */
scanf("%*[^\n] ");
scanf("%" NAG_IFMT "%" NAG_IFMT "%*[^\n] ", &n, &k);
pdc = n;
#ifdef NAG_COLUMN_MAJOR
order = Nag_ColMajor;
pda = n;
#define C(I, J) c[(J-1)*pdc + I-1]
#define A(I, J) a[(J-1)*pda + I-1]
#else
order = Nag_RowMajor;
pda = k;
#define C(I, J) c[(I-1)*pdc + J-1]
#define A(I, J) a[(I-1)*pda + J-1]
#endif
if (!(c = NAG_ALLOC(pdc * n, Complex)) ||
!(cr = NAG_ALLOC((n * (n + 1)) / 2, Complex)) ||
!(a = NAG_ALLOC(n * k, Complex)))
{
printf("Allocation failure\n");
exit_status = -1;
goto END;
}
/* Nag_RFP_Store */
scanf("%39s ", nag_enum_arg);
transr = (Nag_RFP_Store) nag_enum_name_to_value(nag_enum_arg);
/* Nag_UploType */
scanf("%39s ", nag_enum_arg);
uplo = (Nag_UploType) nag_enum_name_to_value(nag_enum_arg);
/* Nag_TransType */
scanf("%39s %*[^\n] ", nag_enum_arg);
trans = (Nag_TransType) nag_enum_name_to_value(nag_enum_arg);
scanf("%lf%lf%*[^\n] ", &alpha, &beta);
/* Read upper or lower triangle of matrix C from data file */
if (uplo == Nag_Lower) {
for (i = 1; i <= n; i++) {
for (j = 1; j <= i; j++) {
scanf(" ( %lf , %lf ) ", &C(i, j).re, &C(i, j).im);
}
}
}
else {
for (i = 1; i <= n; i++) {
for (j = i; j <= n; j++) {
scanf(" ( %lf , %lf ) ", &C(i, j).re, &C(i, j).im);
}
}
}
scanf("%*[^\n] ");
/* Read matrix A from data file */
for (i = 1; i <= n; i++) {
for (j = 1; j <= k; j++) {
scanf(" ( %lf , %lf ) ", &A(i, j).re, &A(i, j).im);
}
}
/* Convert Hermitian matrix C from full triangular storage to rectangular full
* packed storage (in cr) using nag_ztrttf (f01vfc).
*/
nag_ztrttf(order, transr, uplo, n, c, pdc, cr, &fail);
if (fail.code != NE_NOERROR) {
printf("Error from nag_ztrttf (f01vfc).\n%s\n", fail.message);
exit_status = 1;
goto END;
}
printf("\n");
/* Perform the rank-k update of Hermitian matrix C by complex matrix A
* using nag_zhfrk (f16zqc).
*/
nag_zhfrk(order, transr, uplo, trans, n, k, alpha, a, pda, beta, cr, &fail);
if (fail.code != NE_NOERROR) {
printf("Error from nag_zhfrk (f16zqc).\n%s\n", fail.message);
exit_status = 1;
goto END;
}
/* Convert C back from rectangular full packed (cr) to standard triangular
* storage format (c) using nag_ztfttr (f01vhc).
*/
nag_ztfttr(order, transr, uplo, n, cr, c, pdc, &fail);
if (fail.code != NE_NOERROR) {
printf("Error from nag_ztfttr (f01vhc).\n%s\n", fail.message);
exit_status = 1;
goto END;
}
matrix = (uplo == Nag_Upper ? Nag_UpperMatrix : Nag_LowerMatrix);
/* Print out the result, stored in the lower triangle of matrix C using
* the easy-to-use print routine nag_gen_cmplx_mat_print (x04dac).
*/
fflush(stdout);
nag_gen_complx_mat_print(order, matrix, Nag_NonUnitDiag, n, n, c, pdc,
"The Solution", 0, &fail);
if (fail.code != NE_NOERROR) {
printf("Error from nag_gen_complx_mat_print (x04dac).\n%s\n",
fail.message);
exit_status = 1;
}
END:
NAG_FREE(a);
NAG_FREE(c);
NAG_FREE(cr);
return exit_status;
}