/* nag_sum_fft_cosine (c06rfc) Example Program.
*
* NAGPRODCODE Version.
*
* Copyright 2016 Numerical Algorithms Group.
*
* Mark 26, 2016.
*/
#include <nag.h>
#include <stdio.h>
#include <nag_stdlib.h>
#include <nagc06.h>
int main(void)
{
/* Scalars */
Integer exit_status = 0, j, m, n, n1;
/* Arrays */
double *x = 0;
char title[60];
/* Nag Types */
NagError fail;
INIT_FAIL(fail);
printf("nag_sum_fft_cosine (c06rfc) Example Program Results\n");
fflush(stdout);
/* Read dimensions of array from data file. */
scanf("%*[^\n] %" NAG_IFMT "%" NAG_IFMT "%*[^\n]", &m, &n1);
n = n1 - 1;
if (!(x = NAG_ALLOC((m * n1), double)))
{
printf("Allocation failure\n");
exit_status = -1;
goto END;
}
/* Read array values from data file and print out. */
for (j = 0; j < m * n1; j++)
scanf("%lf", &x[j]);
sprintf(title, "\n Original data values\n");
nag_gen_real_mat_print_comp(Nag_RowMajor, Nag_GeneralMatrix,
Nag_NonUnitDiag, m, n1, x, n1, "%9.4f",
title, Nag_NoLabels, 0, Nag_NoLabels,
0, 80, 0, NULL, &fail);
if (fail.code != NE_NOERROR) {
printf("Error from nag_gen_real_mat_print_comp (x04cbc).\n%s\n",
fail.message);
exit_status = 1;
goto END;
}
/* nag_sum_fft_cosine (c06rfc).
* Discrete sine transforms
*/
nag_sum_fft_cosine(m, n, x, &fail);
if (fail.code != NE_NOERROR) {
printf("Error from nag_sum_fft_cosine (c06rfc).\n%s\n", fail.message);
exit_status = 2;
goto END;
}
sprintf(title, "\n Discrete Fourier cosine transforms\n");
nag_gen_real_mat_print_comp(Nag_RowMajor, Nag_GeneralMatrix,
Nag_NonUnitDiag, m, n1, x, n1, "%9.4f",
title, Nag_NoLabels, 0, Nag_NoLabels,
0, 80, 0, NULL, &fail);
if (fail.code != NE_NOERROR) {
printf("Error from nag_gen_real_mat_print_comp (x04cbc).\n%s\n",
fail.message);
exit_status = 3;
goto END;
}
/* Two consecutive calls should restore the original data. */
nag_sum_fft_cosine(m, n, x, &fail);
if (fail.code != NE_NOERROR) {
printf("Error from nag_sum_fft_cosine (c06rfc).\n%s\n", fail.message);
exit_status = 4;
goto END;
}
sprintf(title, "\n Original data as restored by inverse transform\n");
nag_gen_real_mat_print_comp(Nag_RowMajor, Nag_GeneralMatrix,
Nag_NonUnitDiag, m, n1, x, n1, "%9.4f",
title, Nag_NoLabels, 0, Nag_NoLabels,
0, 80, 0, NULL, &fail);
if (fail.code != NE_NOERROR) {
printf("Error from nag_gen_real_mat_print_comp (x04cbc).\n%s\n",
fail.message);
exit_status = 5;
goto END;
}
END:
NAG_FREE(x);
return exit_status;
}