/* nag_ftt_3d (c06pxc) Example Program. * * Copyright 2002 Numerical Algorithms Group. * * Mark 7, 2002. */ #include #include #include #include #include int main(void) { /* Scalars */ Integer i, j, k, n1, n2, n3; Integer exit_status=0; NagError fail; /* Arrays */ Complex *x=0; #define X(I,J,K) x[(K-1)*n2*n1 + (J-1)*n1 + I - 1] INIT_FAIL(fail); Vprintf("nag_fft_3d (c06pxc) Example Program Results\n"); /* Skip heading in data file */ Vscanf("%*[^\n]"); Vscanf("%ld%ld%ld", &n1, &n2, &n3); Vscanf("%*[^\n]"); if (n1*n2*n3>=1) { /* Allocate memory */ if ( !(x = NAG_ALLOC(n1 * n2 * n3, Complex)) ) { Vprintf("Allocation failure\n"); exit_status = -1; goto END; } /* Read in complex data and print out. */ for (i = 1; i <= n1; ++i) { for (j = 1; j <= n2; ++j) { for (k = 1; k <= n3; ++k) { Vscanf(" ( %lf, %lf ) ", &X(i,j,k).re, &X(i,j,k).im); } } } Vscanf("%*[^\n]"); Vprintf("\nOriginal data values\n\n"); /* nag_gen_complx_mat_print_comp (x04dbc). * Print complex general matrix (comprehensive) */ nag_gen_complx_mat_print_comp(Nag_ColMajor, Nag_GeneralMatrix, Nag_NonUnitDiag, n2, n3, x, n1*n2, Nag_BracketForm, "%6.3f", "X(i,j,k) for i = 1", Nag_NoLabels, 0, Nag_NoLabels, 0, 90, 0, 0, &fail); Vprintf("\n"); /* nag_gen_complx_mat_print_comp (x04dbc), see above. */ nag_gen_complx_mat_print_comp(Nag_ColMajor, Nag_GeneralMatrix, Nag_NonUnitDiag, n2, n3, &X(2,1,1), n1*n2, Nag_BracketForm, "%6.3f", "X(i,j,k) for i = 2", Nag_NoLabels, 0, Nag_NoLabels, 0, 90, 0, 0, &fail); if (fail.code != NE_NOERROR) { Vprintf("Error from nag_gen_complx_mat_print_comp (x04dbc).\n%s\n", fail.message); exit_status = 1; goto END; } /* Compute transform */ /* nag_fft_3d (c06pxc). * Three-dimensional complex discrete Fourier transform, * complex data format */ nag_fft_3d(Nag_ForwardTransform, n1, n2, n3, x, &fail); if (fail.code != NE_NOERROR) { Vprintf("Error from nag_fft_3d (c06pxc).\n%s\n", fail.message); exit_status = 1; goto END; } Vprintf("\nComponents of discrete Fourier transforms\n\n"); /* nag_gen_complx_mat_print_comp (x04dbc), see above. */ nag_gen_complx_mat_print_comp(Nag_ColMajor, Nag_GeneralMatrix, Nag_NonUnitDiag, n2, n3, x, n1*n2, Nag_BracketForm, "%6.3f", "X(i,j,k) for i = 1", Nag_NoLabels, 0, Nag_NoLabels, 0, 90, 0, 0, &fail); Vprintf("\n"); /* nag_gen_complx_mat_print_comp (x04dbc), see above. */ nag_gen_complx_mat_print_comp(Nag_ColMajor, Nag_GeneralMatrix, Nag_NonUnitDiag, n2, n3, &X(2,1,1), n1*n2, Nag_BracketForm, "%6.3f", "X(i,j,k) for i = 2", Nag_NoLabels, 0, Nag_NoLabels, 0, 90, 0, 0, &fail); if (fail.code != NE_NOERROR) { Vprintf("Error from nag_gen_complx_mat_print_comp (x04dbc).\n%s\n", fail.message); exit_status = 1; goto END; } /* Compute inverse transform */ /* nag_fft_3d (c06pxc), see above. */ nag_fft_3d(Nag_BackwardTransform, n1, n2, n3, x, &fail); if (fail.code != NE_NOERROR) { Vprintf("Error from nag_fft_3d (c06pxc).\n%s\n", fail.message); exit_status = 1; goto END; } Vprintf("\nOriginal data as restored by inverse transform\n\n"); /* nag_gen_complx_mat_print_comp (x04dbc), see above. */ nag_gen_complx_mat_print_comp(Nag_ColMajor, Nag_GeneralMatrix, Nag_NonUnitDiag, n2, n3, x, n1*n2, Nag_BracketForm, "%6.3f", "X(i,j,k) for i = 1", Nag_NoLabels, 0, Nag_NoLabels, 0, 90, 0, 0, &fail); Vprintf("\n"); /* nag_gen_complx_mat_print_comp (x04dbc), see above. */ nag_gen_complx_mat_print_comp(Nag_ColMajor, Nag_GeneralMatrix, Nag_NonUnitDiag, n2, n3, &X(2,1,1), n1*n2, Nag_BracketForm, "%6.3f", "X(i,j,k) for i = 2", Nag_NoLabels, 0, Nag_NoLabels, 0, 90, 0, 0, &fail); if (fail.code != NE_NOERROR) { Vprintf("Error from nag_gen_complx_mat_print_comp (x04dbc).\n%s\n", fail.message); exit_status = 1; goto END; } } else Vfprintf(stderr,"\nInvalid value of n1, n2 or n3.\n"); END: if (x) NAG_FREE(x); return exit_status; }