/* nag_tsa_uni_means (g13auc) Example Program.
*
* Copyright 2024 Numerical Algorithms Group.
*
* Mark 30.0, 2024.
*/
#include <nag.h>
#include <stdio.h>
int main(void) {
/* Scalars */
Integer exit_status, i, ngrps, m, n;
/* Arrays */
double *mean = 0, *range = 0, *z = 0;
NagError fail;
INIT_FAIL(fail);
exit_status = 0;
printf("nag_tsa_uni_means (g13auc) Example Program Results\n");
/* Skip heading in data file */
scanf("%*[^\n] ");
scanf("%" NAG_IFMT "%" NAG_IFMT "%*[^\n] ", &n, &m);
if (n >= m && m >= 1) {
ngrps = n / m;
/* Allocate arrays */
if (!(mean = NAG_ALLOC(ngrps, double)) ||
!(range = NAG_ALLOC(ngrps, double)) || !(z = NAG_ALLOC(n, double))) {
printf("Allocation failure\n");
exit_status = -1;
goto END;
}
for (i = 1; i <= n; ++i)
scanf("%lf", &z[i - 1]);
scanf("%*[^\n] ");
printf("\n");
/* nag_tsa_uni_means (g13auc).
* Computes quantities needed for range-mean or standard
* deviation-mean plot
*/
nag_tsa_uni_means(n, z, m, Nag_UseRange, range, mean, &fail);
if (fail.code != NE_NOERROR) {
printf("Error from nag_tsa_uni_means (g13auc).\n%s\n", fail.message);
exit_status = 1;
goto END;
}
printf(" Range Mean\n");
for (i = 1; i <= ngrps; i++)
printf("%8.3f %8.3f\n", range[i - 1], mean[i - 1]);
}
END:
NAG_FREE(mean);
NAG_FREE(range);
NAG_FREE(z);
return exit_status;
}