/* nag_tabulate_percentile (g11bbc) Example Program. * * Copyright 2000 Numerical Algorithms Group. * * Mark 6a revised, 2001. */ #include #include #include #include int main (void) { char type[2], weight[2]; double percnt, *table=0, *wt=0, *wtptr, *y=0; Integer items, i, *count=0, *idim=0, *factor=0, ifail, *sf=0, j, k, tdf; Integer ltmax, *lfac=0, maxt, n, ncells, ncol, ndim, nfac, nrow; Integer exit_status=0; Nag_TabulateVar type_enum; NagError fail; #define FACTOR(I,J) factor[((I)-1)*nfac +(J)-1] INIT_FAIL(fail); Vprintf("g11bbc Example Program Results\n"); /* Skip heading in data file */ Vscanf("%*[^\n]"); Vscanf(" %s %s %ld %ld %lf", type, weight, &n, &nfac, &percnt); ltmax = 18; maxt = ltmax; if (!(sf = NAG_ALLOC(nfac, Integer)) || !(lfac = NAG_ALLOC(nfac, Integer)) || !(idim = NAG_ALLOC(nfac, Integer)) || !(factor = NAG_ALLOC(n*nfac, Integer)) || !(count = NAG_ALLOC(maxt, Integer)) || !(y = NAG_ALLOC(n, double)) || !(table = NAG_ALLOC(maxt, double)) || !(wt = NAG_ALLOC(n, double))) { Vprintf("Allocation failure\n"); exit_status = -1; goto END; } if (*weight == 'W' || *weight == 'V' ) { for (i = 1; i <= n; ++i) { for (j = 1; j <= nfac; ++j) Vscanf("%ld", &FACTOR(i,j)); Vscanf("%lf %lf ", &y[i - 1], &wt[i - 1]); } wtptr=wt; } else { for (i = 1; i <= n; ++i) { for (j = 1; j <= nfac; ++j) Vscanf("%ld", &FACTOR(i,j)); Vscanf("%lf", &y[i - 1]); } wtptr = 0; } for (j = 1; j <= nfac; ++j) Vscanf("%ld", &lfac[j - 1]); for (j = 1; j <= nfac; ++j) Vscanf("%ld", &sf[j - 1]); tdf = nfac; ifail = 0; if (*type == 'D') type_enum = Nag_TabulateVarDiscr; else if (*type == 'C') type_enum = Nag_TabulateVarCont; else type_enum = (Nag_TabulateVar)-999; g11bbc(type_enum, n, nfac, sf, lfac, factor, tdf, percnt, y, wtptr, table, maxt, &ncells, &ndim, idim, count, &fail); if (fail.code != NE_NOERROR) { Vprintf("Error from g11bbc.\n%s\n", fail.message); exit_status = 1; goto END; } Vprintf("\n"); Vprintf("%s%4.0f%s\n", "Table for ", percnt, "th percentile"); Vprintf("\n"); ncol = idim[ndim - 1]; nrow = ncells / ncol; k = 1; for (i = 1; i <= nrow; ++i) { for (items = 1, j = k; j <= k + ncol - 1; ++j, items++) { Vprintf("%8.2f(%2ld)%s", table[j - 1], count[j - 1], items%6?"":"\n"); } k += ncol; } END: if (sf) NAG_FREE(sf); if (lfac) NAG_FREE(lfac); if (idim) NAG_FREE(idim); if (factor) NAG_FREE(factor); if (count) NAG_FREE(count); if (y) NAG_FREE(y); if (table) NAG_FREE(table); if (wt) NAG_FREE(wt); return exit_status; }