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