/* nag_conjugate_complex (c06gcc) 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, *y = 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_conjugate_complex (c06gcc) 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))) { fprintf(fpout, "Allocation failure\n"); exit_status = -1; goto END; } } else { fprintf(fpout, "\nInvalid n.\n"); exit_status = 1; return exit_status; } /* Read in complex data */ for (j = 0; j < n; ++j) fscanf(fpin, "%lf%lf", &x[j], &y[j]); /* Compute inverse transform */ /* Calculate conjugates of data */ /* 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; } /* Calculate transform of conjugated data */ /* 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; } /* Conjugate to give inverse transfom */ /* 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, "\nComponents of inverse discrete Fourier transform\n"); fprintf(fpout, "\n Real Imag\n\n"); for (j = 0; j < n; ++j) fprintf(fpout, "%3ld %10.5f %10.5f\n", 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); } return exit_status; }