/* nag_summary_stats_freq (g01adc) Example Program. * * Copyright 2001 Numerical Algorithms Group. * * Mark 7, 2001. */ #include #include #include #include int main(void) { /* Scalars */ double xsd, xskew, xkurt, xmean; Integer exit_status=0, i, j, k, kmin1, n, nprob; NagError fail; /* Arrays */ double *x=0; Integer *ifreq=0; INIT_FAIL(fail); Vprintf("nag_summary_stats_freq (g01adc) Example Program Results\n"); /* Skip heading in data file */ Vscanf("%*[^\n] "); Vscanf("%ld%*[^\n] ", &nprob); for (j = 1; j <= nprob; ++j) { Vscanf("%ld%*[^\n] ", &kmin1); k = kmin1 + 1; /* Allocate memory */ if ( !(x = NAG_ALLOC(k, double)) || !(ifreq = NAG_ALLOC(k, Integer)) ) { Vprintf("Allocation failure\n"); exit_status = -1; goto END; } for (i = 1; i <= kmin1; ++i) Vscanf("%lf%ld", &x[i - 1], &ifreq[i - 1]); Vscanf("%lf%*[^\n] ", &x[k - 1]); Vprintf("\nProblem %4ld\n", j); Vprintf("Number of classes %4ld\n", kmin1); /* nag_summary_stats_freq (g01adc). * Mean, variance, skewness, kurtosis, etc., one variable, * from frequency table */ nag_summary_stats_freq(k, x, ifreq, &xmean, &xsd, &xskew, &xkurt, &n, &fail); if (fail.code == NE_NOERROR) { Vprintf("Successful call of g01adc\n\n"); Vprintf(" Class Frequency\n\n"); for (i = 1; i <= kmin1; ++i) Vprintf("%10.2f%10.2f%12ld\n", x[i-1], x[i], ifreq[i-1]); Vprintf("\n Mean %16.4f\n", xmean); Vprintf(" Std devn%13.4f\n", xsd); Vprintf(" Skewness%13.4f\n", xskew); Vprintf(" Kurtosis%13.4f\n", xkurt); Vprintf(" Number of cases%8ld\n", n); } else { Vprintf("Error from nag_summary_stats_freq (g01adc).\n%s\n", fail.message); exit_status = 1; } if (x) NAG_FREE(x); if (ifreq) NAG_FREE(ifreq); } END: return exit_status; }