/* nag_sum_fft_sine (c06rec) Example Program.
*
* Copyright 2024 Numerical Algorithms Group.
*
* Mark 30.3, 2024.
*/
#include <nag.h>
#include <stdio.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_sine (c06rec) 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_file_print_matrix_real_gen_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_file_print_matrix_real_gen_comp (x04cbc).\n%s\n",
fail.message);
exit_status = 1;
goto END;
}
/* nag_sum_fft_sine (c06rec).
* Discrete sine transforms
*/
nag_sum_fft_sine(m, n, x, &fail);
if (fail.code != NE_NOERROR) {
printf("Error from nag_sum_fft_sine (c06rec).\n%s\n", fail.message);
exit_status = 2;
goto END;
}
sprintf(title, "\n Discrete Fourier sine transforms\n");
nag_file_print_matrix_real_gen_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_file_print_matrix_real_gen_comp (x04cbc).\n%s\n",
fail.message);
exit_status = 3;
goto END;
}
/* Two consecutive calls should restore the original data. */
nag_sum_fft_sine(m, n, x, &fail);
if (fail.code != NE_NOERROR) {
printf("Error from nag_sum_fft_sine (c06rec).\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, 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_file_print_matrix_real_gen_comp (x04cbc).\n%s\n",
fail.message);
exit_status = 5;
goto END;
}
END:
NAG_FREE(x);
return exit_status;
}