/* nag_fft_complex (c06ecc) Example Program. * * Copyright 1990 Numerical Algorithms Group. * * Mark 1, 1990. * Mark 8 revised, 2004. */ #include #include #include #include #include int main(int argc, char *argv[]) { FILE *fpin, *fpout; Integer exit_status = 0, j, n; NagError fail; double *x = 0, *xx = 0, *y = 0, *yy = 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); fprintf(fpout, "nag_fft_complex (c06ecc) Example Program Results\n"); /* Skip heading in data file */ fscanf(fpin, "%*[^\n]"); while (fscanf(fpin, "%ld", &n) != EOF) { if (n > 1) { if (!(x = NAG_ALLOC(n, double)) || !(y = NAG_ALLOC(n, double)) || !(xx = NAG_ALLOC(n, double)) || !(yy = NAG_ALLOC(n, double))) { fprintf(fpout, "Allocation failure\n"); exit_status = -1; goto END; } } else { fprintf(fpout, "Invalid n.\n"); exit_status = 1; return exit_status; } for (j = 0; j < n; ++j) { fscanf(fpin, "%lf%lf", &x[j], &y[j]); xx[j] = x[j]; yy[j] = y[j]; } /* Compute transform */ /* nag_fft_complex (c06ecc). * Single one-dimensional complex discrete Fourier transform */ nag_fft_complex(n, x, y, &fail); if (fail.code != NE_NOERROR) { fprintf(fpout, "Error from nag_fft_complex (c06ecc).\n%s\n", fail.message); exit_status = 1; goto END; } fprintf(fpout, "\nComponents of discrete Fourier transform\n\n"); fprintf(fpout, " Real Imag\n\n"); for (j = 0; j < n; ++j) fprintf(fpout, "%3ld %10.5f %10.5f\n", j, x[j], y[j]); /* Compute inverse transform */ /* Conjugate the transform */ /* nag_conjugate_complex (c06gcc). * Complex conjugate of complex sequence */ nag_conjugate_complex(n, y, &fail); if (fail.code != NE_NOERROR) { fprintf(fpout, "Error from nag_conjugate_complex (c06gcc).\n%s\n", fail.message); exit_status = 1; goto END; } /* Transform */ /* nag_fft_complex (c06ecc), see above. */ nag_fft_complex(n, x, y, &fail); if (fail.code != NE_NOERROR) { fprintf(fpout, "Error from nag_fft_complex (c06ecc).\n%s\n", fail.message); exit_status = 1; goto END; } /* Conjugate to give inverse transform */ /* nag_conjugate_complex (c06gcc), see above. */ nag_conjugate_complex(n, y, &fail); if (fail.code != NE_NOERROR) { fprintf(fpout, "Error from nag_conjugate_complex (c06gcc).\n%s\n", fail.message); exit_status = 1; goto END; } fprintf(fpout, "\nOriginal sequence as restored by inverse transform\n"); fprintf(fpout, "\n Original Restored\n"); fprintf(fpout, " Real Imag Real Imag\n\n"); for (j = 0; j < n; ++j) fprintf(fpout, "%3ld %10.5f %10.5f %10.5f %10.5f\n", j, xx[j], yy[j], x[j], y[j]); END: if (fpin != stdin) fclose(fpin); if (fpout != stdout) fclose(fpout); if (x) NAG_FREE(x); if (y) NAG_FREE(y); if (xx) NAG_FREE(xx); if (yy) NAG_FREE(yy); } return exit_status; }