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