/* nag_prob_hypergeom_vector (g01slc) Example Program. * * Copyright 2011, Numerical Algorithms Group. * * Mark 23, 2011. */ #include #include #include #include int main(void) { /* Integer scalar and array declarations */ Integer ln, ll, lm, lk, i, lout; Integer *ivalid = 0, *n = 0, *l = 0, *m = 0, *k = 0; Integer exit_status = 0; /* NAG structures */ NagError fail; /* Double scalar and array declarations */ double *peqk = 0, *pgtk = 0, *plek = 0; /* Initialise the error structure to print out any error messages */ INIT_FAIL(fail); printf("nag_prob_hypergeom_vector (g01slc) Example Program Results\n\n"); /* Skip heading in data file*/ scanf("%*[^\n] "); scanf("%ld%*[^\n] ", &ln); if (!(n = NAG_ALLOC(ln, Integer))) { printf("Allocation failure\n"); exit_status = -1; goto END; } for (i = 0; i < ln; i++) scanf("%ld", &n[i]); scanf("%*[^\n] "); scanf("%ld%*[^\n] ", &ll); if (!(l = NAG_ALLOC(ll, Integer))) { printf("Allocation failure\n"); exit_status = -1; goto END; } for (i = 0; i < ll; i++) scanf("%ld", &l[i]); scanf("%*[^\n] "); scanf("%ld%*[^\n] ", &lm); if (!(m = NAG_ALLOC(lm, Integer))) { printf("Allocation failure\n"); exit_status = -1; goto END; } for (i = 0; i < lm; i++) scanf("%ld", &m[i]); scanf("%*[^\n] "); scanf("%ld%*[^\n] ", &lk); if (!(k = NAG_ALLOC(lk, Integer))) { printf("Allocation failure\n"); exit_status = -1; goto END; } for (i = 0; i < lk; i++) scanf("%ld", &k[i]); scanf("%*[^\n] "); /* Allocate memory for output */ lout = MAX(ln,MAX(ll,MAX(lm,lk))); if (!(peqk = NAG_ALLOC(lout, double)) || !(pgtk = NAG_ALLOC(lout, double)) || !(plek = NAG_ALLOC(lout, double)) || !(ivalid = NAG_ALLOC(lout, Integer))) { printf("Allocation failure\n"); exit_status = -1; goto END; } /* Calculate probability */ nag_prob_hypergeom_vector(ln, n, ll, l, lm, m, lk, k, plek, pgtk, peqk, ivalid, &fail); if (fail.code != NE_NOERROR) { printf("Error from nag_prob_hypergeom_vector (g01slc).\n%s\n", fail.message); exit_status = 1; if (fail.code != NW_IVALID) goto END; } /* Display title */ printf(" n l m k "); printf("plek pgtk peqk ivalid\n"); printf(" -----------------------------------"); printf("-----------------------------------------\n"); /* Display results */ for (i = 0; i < lout; i++) { printf(" %6ld %6ld %6ld %6ld", n[i%ln], l[i%ll], m[i%lm], k[i%lk]); printf(" %6.3f %6.3f %6.3f %3ld\n", plek[i], pgtk[i], peqk[i], ivalid[i]); } END: NAG_FREE(n); NAG_FREE(l); NAG_FREE(m); NAG_FREE(k); NAG_FREE(plek); NAG_FREE(pgtk); NAG_FREE(peqk); NAG_FREE(ivalid); return(exit_status); }