/* nag_running_median_smoother (g10cac) Example Program. * * Copyright 1992 Numerical Algorithms Group. * * Mark 3, 1992. * Mark 8 revised, 2004. */ #include #include #include #include int main(void) { Integer exit_status = 0, i, isel, n; NagError fail; Nag_Smooth_Type smoother; double *rough = 0, *smooth = 0, *y = 0; INIT_FAIL(fail); printf( "nag_running_median_smoother (g10cac) Example Program Results\n"); /* Skip heading in data file */ scanf("%*[^\n]"); scanf("%ld", &n); if (n >= 1) { if (!(rough = NAG_ALLOC(n, double)) || !(smooth = NAG_ALLOC(n, double)) || !(y = NAG_ALLOC(n, double))) { printf("Allocation failure\n"); exit_status = -1; goto END; } } else { printf("Invalid n.\n"); exit_status = 1; return exit_status; } for (i = 0; i < n; ++i) scanf("%lf", &y[i]); for (isel = 1; isel <= 2; ++isel) { /* Select the smoothing method. */ if (isel == 1) smoother = Nag_4253H; else if (isel == 2) smoother = Nag_3RSSH; if (smoother == Nag_4253H) printf("\nExample 1: Data smoothing using 4253H method.\n\n"); else if (smoother == Nag_3RSSH) printf( "\n\nExample 2: Data smoothing using 3RSSH method.\n\n"); /* nag_running_median_smoother (g10cac). * Compute smoothed data sequence using running median * smoothers */ nag_running_median_smoother(smoother, n, y, smooth, rough, &fail); if (fail.code != NE_NOERROR) { printf( "Error from nag_running_median_smoother (g10cac).\n%s\n", fail.message); exit_status = 1; goto END; } printf(" index data smooth rough\n"); for (i = 0; i < n; ++i) printf("%9ld%15.4f%15.4f%15.4f\n", i, y[i], smooth[i], rough[i]); } END: NAG_FREE(rough); NAG_FREE(smooth); NAG_FREE(y); return exit_status; }