/* nag_5pt_summary_stats (g01alc) Example Program. * * Copyright 1996 Numerical Algorithms Group. * * Mark 4, 1996. * Mark 8 revised, 2004. * */ #include #include #include #include int main(void) { Integer exit_status=0, i, n; NagError fail; double *res=0, *x=0; INIT_FAIL(fail); Vprintf("nag_5pt_summary_stats (g01alc) Example Program Results\n"); /* Skip heading in data file */ Vscanf("%*[^\n] "); Vscanf("%ld ", &n); if (n>=5) { if ( !( x = NAG_ALLOC(n, double)) || !( res = NAG_ALLOC(5, double)) ) { Vprintf("Allocation failure\n"); exit_status = -1; goto END; } } else { Vprintf("Invalid n.\n"); exit_status = 1; return exit_status; } for (i = 1; i <= n; ++i) Vscanf("%lf ", &x[i - 1]); /* nag_5pt_summary_stats (g01alc). * Five-point summary (median, hinges and extremes) */ nag_5pt_summary_stats(n, x, res, &fail); if (fail.code != NE_NOERROR) { Vprintf("Error from nag_5pt_summary_stats (g01alc).\n%s\n", fail.message); exit_status = 1; goto END; } Vprintf("\n"); Vprintf(" Maximum %16.4f\n", res[4]); Vprintf(" Upper Hinge %16.4f\n", res[3]); Vprintf(" Median %16.4f\n", res[2]); Vprintf(" Lower Hinge %16.4f\n", res[1]); Vprintf(" Minimum %16.4f\n", res[0]); END: if (x) NAG_FREE(x); if (res) NAG_FREE(res); return exit_status; }