/* nag_sum_fft_complex_multid (c06pjc) Example Program.
*
* Copyright 2020 Numerical Algorithms Group.
*
* Mark 27.1, 2020.
*/
#include <nag.h>
#include <stdio.h>
int main(void) {
/* Scalars */
Integer i, n, ndim;
Integer exit_status = 0;
NagError fail;
/* Arrays */
Complex *x = 0;
Integer *nd = 0;
INIT_FAIL(fail);
printf("nag_sum_fft_complex_multid (c06pjc) Example Program Results\n");
/* Skip heading in data file */
scanf("%*[^\n]");
scanf("%" NAG_IFMT "%" NAG_IFMT "", &ndim, &n);
if (n >= 1) {
/* Allocate memory */
if (!(x = NAG_ALLOC(n, Complex)) || !(nd = NAG_ALLOC(ndim, Integer))) {
printf("Allocation failure\n");
exit_status = -1;
goto END;
}
for (i = 0; i < ndim; ++i) {
scanf("%" NAG_IFMT "", &nd[i]);
}
/* Read in complex data and print out. */
scanf("%*[^\n]");
for (i = 0; i < n; ++i) {
scanf(" ( %lf, %lf ) ", &x[i].re, &x[i].im);
}
scanf("%*[^\n]");
printf("\n");
/* nag_file_print_matrix_complex_gen_comp (x04dbc).
* Print complex general matrix (comprehensive)
*/
fflush(stdout);
nag_file_print_matrix_complex_gen_comp(
Nag_ColMajor, Nag_GeneralMatrix, Nag_NonUnitDiag, nd[0], n / nd[0], x,
nd[0], Nag_BracketForm, "%6.3f", "Original data values", Nag_NoLabels,
0, Nag_NoLabels, 0, 80, 0, 0, &fail);
if (fail.code != NE_NOERROR) {
printf(
"Error from nag_file_print_matrix_complex_gen_comp (x04dbc).\n%s\n",
fail.message);
exit_status = 1;
goto END;
}
/* Compute transform */
/* nag_sum_fft_complex_multid (c06pjc).
* Multi-dimensional complex discrete Fourier transform of
* multi-dimensional data (using complex data type)
*/
nag_sum_fft_complex_multid(Nag_ForwardTransform, ndim, nd, n, x, &fail);
if (fail.code != NE_NOERROR) {
printf("Error from nag_sum_fft_complex_multid (c06pjc).\n%s\n",
fail.message);
exit_status = 1;
goto END;
}
printf("\n");
/* nag_file_print_matrix_complex_gen_comp (x04dbc), see above. */
fflush(stdout);
nag_file_print_matrix_complex_gen_comp(
Nag_ColMajor, Nag_GeneralMatrix, Nag_NonUnitDiag, nd[0], n / nd[0], x,
nd[0], Nag_BracketForm, "%6.3f",
"Components of discrete Fourier transform", Nag_NoLabels, 0,
Nag_NoLabels, 0, 80, 0, 0, &fail);
if (fail.code != NE_NOERROR) {
printf(
"Error from nag_file_print_matrix_complex_gen_comp (x04dbc).\n%s\n",
fail.message);
exit_status = 1;
goto END;
}
/* Compute inverse transform */
/* nag_sum_fft_complex_multid (c06pjc), see above. */
nag_sum_fft_complex_multid(Nag_BackwardTransform, ndim, nd, n, x, &fail);
if (fail.code != NE_NOERROR) {
printf("Error from nag_sum_fft_complex_multid (c06pjc).\n%s\n",
fail.message);
exit_status = 1;
goto END;
}
printf("\n");
/* nag_file_print_matrix_complex_gen_comp (x04dbc), see above. */
fflush(stdout);
nag_file_print_matrix_complex_gen_comp(
Nag_ColMajor, Nag_GeneralMatrix, Nag_NonUnitDiag, nd[0], n / nd[0], x,
nd[0], Nag_BracketForm, "%6.3f",
"Original data as restored by inverse "
"transform",
Nag_NoLabels, 0, Nag_NoLabels, 0, 80, 0, 0, &fail);
if (fail.code != NE_NOERROR) {
printf(
"Error from nag_file_print_matrix_complex_gen_comp (x04dbc).\n%s\n",
fail.message);
exit_status = 1;
goto END;
}
} else {
printf("\nInvalid value of n.\n");
}
END:
NAG_FREE(x);
NAG_FREE(nd);
return exit_status;
}