/* nag_tsa_mean_range (g13auc) Example Program. * * Copyright 2002 Numerical Algorithms Group. * * Mark 7, 2002. */ #include #include #include #include #include int main(int argc, char *argv[]) { FILE *fpin, *fpout; /* Scalars */ Integer exit_status, i, ngrps, m, n; /* Arrays */ double *mean = 0, *range = 0, *z = 0; NagError fail; 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); exit_status = 0; fprintf(fpout, "nag_tsa_mean_range (g13auc) Example Program Results\n"); /* Skip heading in data file */ fscanf(fpin, "%*[^\n] "); fscanf(fpin, "%ld%ld%*[^\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))) { fprintf(fpout, "Allocation failure\n"); exit_status = -1; goto END; } for (i = 1; i <= n; ++i) fscanf(fpin, "%lf", &z[i-1]); fscanf(fpin, "%*[^\n] "); fprintf(fpout, "\n"); /* nag_tsa_mean_range (g13auc). * Computes quantities needed for range-mean or standard * deviation-mean plot */ nag_tsa_mean_range(n, z, m, Nag_UseRange, range, mean, &fail); if (fail.code != NE_NOERROR) { fprintf(fpout, "Error from nag_tsa_mean_range (g13auc).\n%s\n", fail.message); exit_status = 1; goto END; } fprintf(fpout, " Range Mean\n"); for (i = 1; i <= ngrps; i++) fprintf(fpout, "%8.3f %8.3f\n", range[i-1], mean[i-1]); } END: if (fpin != stdin) fclose(fpin); if (fpout != stdout) fclose(fpout); if (mean) NAG_FREE(mean); if (range) NAG_FREE(range); if (z) NAG_FREE(z); return exit_status; }