/* nag_tabulate_margin (g11bcc) Example Program. * * Copyright 2002 Numerical Algorithms Group. * * Mark 7, 2002. */ #include #include #include #include int main(void) { /* Scalars */ Integer exit_status, i, j, k, maxst, mcells, mdim, ncells, ncol, ndim, nrow; NagError fail; Nag_TableStats stat_enum; char stat; /* Arrays */ double *auxt = 0, *stable = 0, *table = 0; Integer *idim = 0, *isdim = 0, *mlevel = 0; INIT_FAIL(fail); exit_status = 0; Vprintf("nag_tabulate_margin (g11bcc) Example Program Results\n"); /* Skip heading in data file */ Vscanf("%*[^\n] "); Vscanf(" '%c'%ld%ld%*[^\n] ", &stat, &ncells, &ndim); maxst = 54; /* Allocate arrays */ if ( !(auxt = NAG_ALLOC(maxst, double)) || !(stable = NAG_ALLOC(maxst, double)) || !(table = NAG_ALLOC(ncells, double)) || !(idim = NAG_ALLOC(ndim, Integer)) || !(isdim = NAG_ALLOC(ndim, Integer)) || !(mlevel = NAG_ALLOC(ndim, Integer)) ) { Vprintf("Allocation failure\n"); exit_status = -1; goto END; } for (i = 1; i <= ncells; ++i) Vscanf("%lf", &table[i-1]); Vscanf("%*[^\n] "); for (j = 1; j <= ndim; ++j) Vscanf("%ld", &idim[j-1]); Vscanf("%*[^\n] "); for (j = 1; j <= ndim; ++j) Vscanf("%ld", &isdim[j-1]); Vscanf("%*[^\n] "); switch (stat) { case 'T': stat_enum = Nag_TableStatsNObs; break; case 'A': stat_enum = Nag_TableStatsAv; break; case 'M': stat_enum = Nag_TableStatsMedian; break; case 'V': stat_enum = Nag_TableStatsVar; break; case 'L': stat_enum = Nag_TableStatsLarge; break; case 'S': stat_enum = Nag_TableStatsSmall; break; default: stat_enum = Nag_TableStatsNObs; } /* nag_tabulate_margin (g11bcc). * Computes marginal tables for multiway table computed by * nag_tabulate_stats (g11bac) or nag_tabulate_percentile * (g11bbc) */ nag_tabulate_margin(stat_enum, table, ncells, ndim, idim, isdim, stable, maxst, &mcells, &mdim, mlevel, auxt, &fail); if (fail.code != NE_NOERROR) { Vprintf("Error from nag_tabulate_margin (g11bcc).\n%s\n", fail.message); exit_status = 1; goto END; } Vprintf("\n"); Vprintf(" Marginal Table\n"); Vprintf("\n"); ncol = mlevel[mdim-1]; nrow = mcells / ncol; k = 1; for (i = 1; i <= nrow; ++i) { for (j = k; j <= k + ncol - 1; ++j) Vprintf("%7.2f ", stable[j-1]); Vprintf("\n"); k += ncol; } END: if (auxt) NAG_FREE(auxt); if (stable) NAG_FREE(stable); if (table) NAG_FREE(table); if (idim) NAG_FREE(idim); if (isdim) NAG_FREE(isdim); if (mlevel) NAG_FREE(mlevel); return exit_status; }