/* nag_fft_init_trig (c06gzc) Example Program. * * Copyright 1990 Numerical Algorithms Group. * * Mark 1, 1990. * Mark 8 revised, 2004. */ #include #include #include #include int main(void) { Integer exit_status = 0, i, j, m, n; NagError fail; double *trig = 0, *u = 0, *v = 0, *x = 0; INIT_FAIL(fail); printf("nag_fft_init_trig (c06gzc) Example Program Results\n"); scanf("%*[^\n]"); /* Skip heading in data file */ while (scanf("%ld%ld", &m, &n) != EOF) { if (m >= 1 && n >= 1) { if (!(trig = NAG_ALLOC(2*n, double)) || !(u = NAG_ALLOC(m*n, double)) || !(v = NAG_ALLOC(m*n, double)) || !(x = NAG_ALLOC(m*n, double))) { printf("Allocation failure\n"); exit_status = -1; goto END; } } else { printf("Invalid m or n.\n"); exit_status = 1; } printf("\n\nm = %2ld n = %2ld\n", m, n); /* Read in data and print out. */ for (j = 0; j < m; ++j) for (i = 0; i < n; ++i) scanf("%lf", &x[j*n + i]); printf("\nOriginal data values\n\n"); for (j = 0; j < m; ++j) { printf(" "); for (i = 0; i < n; ++i) printf("%10.4f%s", x[j*n + i], (i%6 == 5 && i != n-1?"\n ":"")); printf("\n"); } /* nag_fft_init_trig (c06gzc). * Initialization function for other c06 functions */ nag_fft_init_trig(n, trig, &fail); if (fail.code != NE_NOERROR) { printf("Error from nag_fft_init_trig (c06gzc).\n%s\n", fail.message); exit_status = 1; goto END; } /* Initialize trig array */ /* Calculate transform */ /* nag_fft_multiple_real (c06fpc). * Multiple one-dimensional real discrete Fourier transforms */ nag_fft_multiple_real(m, n, x, trig, &fail); if (fail.code != NE_NOERROR) { printf("Error from nag_fft_multiple_real (c06fpc).\n%s\n", fail.message); exit_status = 1; goto END; } printf("\nDiscrete Fourier transforms in Hermitian format\n\n"); for (j = 0; j < m; ++j) { printf(" "); for (i = 0; i < n; ++i) printf("%10.4f%s", x[j*n + i], (i%6 == 5 && i != n-1?"\n ":"")); printf("\n"); } /* Convert Hermitian form to full complex */ /* nag_multiple_hermitian_to_complex (c06gsc). * Convert Hermitian sequences to general complex sequences */ nag_multiple_hermitian_to_complex(m, n, x, u, v, &fail); if (fail.code != NE_NOERROR) { printf("Error from nag_multiple_hermitian_to_complex" " (c06gsc).\n%s\n", fail.message); exit_status = 1; goto END; } printf("\nFourier transforms in full complex form\n\n"); for (j = 0; j < m; ++j) { printf("Real"); for (i = 0; i < n; ++i) printf("%10.4f%s", u[j*n + i], (i%6 == 5 && i != n-1?"\n ":"")); printf("\nImag"); for (i = 0; i < n; ++i) printf("%10.4f%s", v[j*n + i], (i%6 == 5 && i != n-1?"\n ":"")); printf("\n\n"); } END: if (trig) NAG_FREE(trig); if (u) NAG_FREE(u); if (v) NAG_FREE(v); if (x) NAG_FREE(x); } return exit_status; }