/* nag_conjugate_hermitian (c06gbc) 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 *a = 0, *b = 0, *x = 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_hermitian (c06gbc) Example Program Results\n"); /* Skip heading in data file */ fscanf(fpin, "%*[^\n]"); while (fscanf(fpin, "%ld", &n) != EOF) { if (n > 1) { if (!(a = NAG_ALLOC(n, double)) || !(b = NAG_ALLOC(n, double)) || !(x = 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]); /* Calculate the Fourier transform of data */ /* 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; } /* Calculate conjugates of Hermitian result to */ /* give inverse tranform */ /* 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; } /* Expand conjugated Hermitian sequence to full complex */ a[0] = x[0]; b[0] = 0.0; n2 = (n-1)/2; for (j = 1; j <= n2; j++) { nj = n - j; a[j] = x[j]; a[nj] = x[j]; b[j] = x[nj]; b[nj] = -x[nj]; } if (n % 2 == 0) { a[n2+1] = x[n2+1]; b[n2+1] = 0.0; } 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, a[j], b[j]); END: if (fpin != stdin) fclose(fpin); if (fpout != stdout) fclose(fpout); if (a) NAG_FREE(a); if (b) NAG_FREE(b); if (x) NAG_FREE(x); } return exit_status; }