/* nag_fft_multid_full (c06pjc) Example Program. * * Copyright 2002 Numerical Algorithms Group. * * Mark 7, 2002. */ #include #include #include #include #include int main(int argc, char *argv[]) { FILE *fpin, *fpout; char *outfile = 0; /* Scalars */ Integer i, n, ndim; Integer exit_status = 0; NagError fail; /* Arrays */ Complex *x = 0; Integer *nd = 0; INIT_FAIL(fail); /* Check for command-line IO options */ fpin = nag_example_file_io(argc, argv, "-data", NULL); fpout = nag_example_file_io(argc, argv, "-results", NULL); (void) nag_example_file_io(argc, argv, "-nag_write", &outfile); fprintf(fpout, "nag_fft_multid_full (c06pjc) Example Program Results\n"); /* Skip heading in data file */ fscanf(fpin, "%*[^\n]"); fscanf(fpin, "%ld%ld", &ndim, &n); if (n >= 1) { /* Allocate memory */ if (!(x = NAG_ALLOC(n, Complex)) || !(nd = NAG_ALLOC(ndim, Integer))) { fprintf(fpout, "Allocation failure\n"); exit_status = -1; goto END; } for (i = 0; i < ndim; ++i) { fscanf(fpin, "%ld", &nd[i]); } /* Read in complex data and print out. */ fscanf(fpin, "%*[^\n]"); for (i = 0; i < n; ++i) { fscanf(fpin, " ( %lf, %lf ) ", &x[i].re, &x[i].im); } fscanf(fpin, "%*[^\n]"); fprintf(fpout, "\n"); /* nag_gen_complx_mat_print_comp (x04dbc). * Print complex general matrix (comprehensive) */ if (outfile) fclose(fpout); nag_gen_complx_mat_print_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, outfile, &fail); if (outfile && !(fpout = fopen(outfile, "a"))) { exit_status = 2; goto END; } if (fail.code != NE_NOERROR) { fprintf(fpout, "Error from nag_gen_complx_mat_print_comp (x04dbc).\n%s\n", fail.message); exit_status = 1; goto END; } /* Compute transform */ /* nag_fft_multid_full (c06pjc). * Multi-dimensional complex discrete Fourier transform of * multi-dimensional data (using complex data type) */ nag_fft_multid_full(Nag_ForwardTransform, ndim, nd, n, x, &fail); if (fail.code != NE_NOERROR) { fprintf(fpout, "Error from nag_fft_multid_full (c06pjc).\n%s\n", fail.message); exit_status = 1; goto END; } fprintf(fpout, "\n"); /* nag_gen_complx_mat_print_comp (x04dbc), see above. */ if (outfile) fclose(fpout); nag_gen_complx_mat_print_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, outfile, &fail); if (outfile && !(fpout = fopen(outfile, "a"))) { exit_status = 2; goto END; } if (fail.code != NE_NOERROR) { fprintf(fpout, "Error from nag_gen_complx_mat_print_comp (x04dbc).\n%s\n", fail.message); exit_status = 1; goto END; } /* Compute inverse transform */ /* nag_fft_multid_full (c06pjc), see above. */ nag_fft_multid_full(Nag_BackwardTransform, ndim, nd, n, x, &fail); if (fail.code != NE_NOERROR) { fprintf(fpout, "Error from nag_fft_multid_full (c06pjc).\n%s\n", fail.message); exit_status = 1; goto END; } fprintf(fpout, "\n"); /* nag_gen_complx_mat_print_comp (x04dbc), see above. */ if (outfile) fclose(fpout); nag_gen_complx_mat_print_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, outfile, &fail); if (outfile && !(fpout = fopen(outfile, "a"))) { exit_status = 2; goto END; } if (fail.code != NE_NOERROR) { fprintf(fpout, "Error from nag_gen_complx_mat_print_comp (x04dbc).\n%s\n", fail.message); exit_status = 1; goto END; } } else { fprintf(fpout, "\nInvalid value of n.\n"); } END: if (fpin != stdin) fclose(fpin); if (fpout != stdout) fclose(fpout); if (x) NAG_FREE(x); if (nd) NAG_FREE(nd); return exit_status; }