/* nag_fft_multiple_qtr_sine (c06hcc) Example Program. * * Copyright 1991 Numerical Algorithms Group. * * Mark 2, 1991. * Mark 8 revised, 2004. */ #include #include #include #include #define X(I, J) x[(I) *n + (J)] int main(void) { Integer exit_status = 0, i, j, m, n; double *trig = 0, *x = 0; NagError fail; INIT_FAIL(fail); printf( "nag_fft_multiple_qtr_sine (c06hcc) 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)) || !(x = NAG_ALLOC(m*n, double))) { printf("Allocation failure\n"); exit_status = -1; goto END; } } else { printf("\nInvalid m or n.\n"); exit_status = 1; return exit_status; } scanf(" %*[^\n]"); /* Skip text in data file */ scanf(" %*[^\n]"); for (i = 0; i < m; ++i) for (j = 0; j < n; ++j) scanf("%lf", &X(i, j)); printf("\nOriginal data values\n\n"); for (i = 0; i < m; ++i) { for (j = 0; j < n; ++j) printf(" %10.4f%s", X(i, j), (j%7 == 6 && j != n-1?"\n":"")); printf("\n"); } /* Initialise trig array */ /* 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; } /* Compute transform */ /* nag_fft_multiple_qtr_sine (c06hcc). * Discrete quarter-wave sine transform */ nag_fft_multiple_qtr_sine(Nag_ForwardTransform, m, n, x, trig, &fail); if (fail.code != NE_NOERROR) { printf( "Error from nag_fft_multiple_qtr_sine (c06hcc).\n%s\n", fail.message); exit_status = 1; goto END; } printf("\nDiscrete quarter-wave Fourier sine transforms\n\n"); for (i = 0; i < m; ++i) { for (j = 0; j < n; ++j) printf(" %10.4f%s", X(i, j), (j%7 == 6 && j != n-1?"\n":"")); printf("\n"); } /* Compute inverse transform */ /* nag_fft_multiple_qtr_sine (c06hcc), see above. */ nag_fft_multiple_qtr_sine(Nag_BackwardTransform, m, n, x, trig, &fail); if (fail.code != NE_NOERROR) { printf( "Error from nag_fft_multiple_qtr_sine (c06hcc).\n%s\n", fail.message); exit_status = 1; goto END; } printf("\nOriginal data as restored by inverse transform\n\n"); for (i = 0; i < m; ++i) { for (j = 0; j < n; ++j) printf(" %10.4f%s", X(i, j), (j%7 == 6 && j != n-1?"\n":"")); printf("\n"); } END: if (trig) NAG_FREE(trig); if (x) NAG_FREE(x); } return exit_status; }