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