/* nag_fft_hermitian (c06ebc) 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, n2, nj; NagError fail; double *u = 0, *v = 0, *x = 0, *xx = 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_hermitian (c06ebc) Example Program Results\n"); /* Skip heading in data file */ fscanf(fpin, "%*[^\n]"); while (fscanf(fpin, "%ld", &n) != EOF) { if (n > 1) { if (!(u = NAG_ALLOC(n, double)) || !(v = NAG_ALLOC(n, double)) || !(x = NAG_ALLOC(n, double)) || !(xx = 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", &x[j]); xx[j] = x[j]; } /* Calculate full complex form of Hermitian sequence */ u[0] = x[0]; v[0] = 0.0; n2 = (n-1)/2; for (j = 1; j <= n2; j++) { nj = n - j; u[j] = x[j]; u[nj] = x[j]; v[j] = x[nj]; v[nj] = -x[nj]; } if (n % 2 == 0) { u[n2+1] = x[n2+1]; v[n2+1] = 0.0; } fprintf(fpout, "\nOriginal and corresponding complex sequence\n"); fprintf(fpout, "\n Data Real Imag \n\n"); for (j = 0; j < n; j++) fprintf(fpout, "%3ld %10.5f %10.5f %10.5f\n", j, x[j], u[j], v[j]); /* Calculate transform */ /* nag_fft_hermitian (c06ebc). * Single one-dimensional Hermitian discrete Fourier * transform */ nag_fft_hermitian(n, x, &fail); if (fail.code != NE_NOERROR) { fprintf(fpout, "Error from nag_fft_hermitian (c06ebc).\n%s\n", fail.message); exit_status = 1; goto END; } fprintf(fpout, "\nComponents of discrete Fourier transform\n\n"); for (j = 0; j < n; j++) fprintf(fpout, "%3ld %10.5f\n", j, x[j]); /* Calculate inverse transform */ /* nag_fft_real (c06eac). * Single one-dimensional real discrete Fourier transform */ nag_fft_real(n, x, &fail); if (fail.code != NE_NOERROR) { fprintf(fpout, "Error from nag_fft_real (c06eac).\n%s\n", fail.message); exit_status = 1; goto END; } /* nag_conjugate_hermitian (c06gbc). * Complex conjugate of Hermitian sequence */ nag_conjugate_hermitian(n, x, &fail); if (fail.code != NE_NOERROR) { fprintf(fpout, "Error from nag_conjugate_hermitian (c06gbc).\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\n"); for (j = 0; j < n; j++) fprintf(fpout, "%3ld %10.5f %10.5f\n", j, xx[j], x[j]); END: if (fpin != stdin) fclose(fpin); if (fpout != stdout) fclose(fpout); if (u) NAG_FREE(u); if (v) NAG_FREE(v); if (x) NAG_FREE(x); if (xx) NAG_FREE(xx); } return exit_status; }