/* nag_5pt_summary_stats (g01alc) Example Program. * * Copyright 1996 Numerical Algorithms Group. * * Mark 4, 1996. * Mark 8 revised, 2004. * */ #include #include #include #include #include int main(int argc, char *argv[]) { FILE *fpin, *fpout; Integer exit_status = 0, i, n; NagError fail; double *res = 0, *x = 0; INIT_FAIL(fail); /* Check for command-line IO options */ fpin = nag_example_file_io(argc, argv, "-data", NULL); fpout = nag_example_file_io(argc, argv, "-results", NULL); fprintf(fpout, "nag_5pt_summary_stats (g01alc) Example Program Results\n"); /* Skip heading in data file */ fscanf(fpin, "%*[^\n] "); fscanf(fpin, "%ld ", &n); if (n >= 5) { if (!(x = NAG_ALLOC(n, double)) || !(res = NAG_ALLOC(5, double))) { fprintf(fpout, "Allocation failure\n"); exit_status = -1; goto END; } } else { fprintf(fpout, "Invalid n.\n"); exit_status = 1; return exit_status; } for (i = 1; i <= n; ++i) fscanf(fpin, "%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) { fprintf(fpout, "Error from nag_5pt_summary_stats (g01alc).\n%s\n", fail.message); exit_status = 1; goto END; } fprintf(fpout, "\n"); fprintf(fpout, " Maximum %16.4f\n", res[4]); fprintf(fpout, " Upper Hinge %16.4f\n", res[3]); fprintf(fpout, " Median %16.4f\n", res[2]); fprintf(fpout, " Lower Hinge %16.4f\n", res[1]); fprintf(fpout, " Minimum %16.4f\n", res[0]); END: if (fpin != stdin) fclose(fpin); if (fpout != stdout) fclose(fpout); if (x) NAG_FREE(x); if (res) NAG_FREE(res); return exit_status; }