/* nag_prob_normal_vector (g01sac) Example Program. * * Copyright 2011, Numerical Algorithms Group. * * Mark 23, 2011. */ #include #include #include #include #define ENUMLEN 30 int main(void) { /* Integer scalar and array declarations */ Integer ltail, lx, lxmu, lxstd, i, lout; Integer *ivalid = 0; Integer exit_status = 0; /* NAG structures */ NagError fail; Nag_TailProbability *tail = 0; /* Double scalar and array declarations */ double *x = 0, *xmu = 0, *xstd = 0, *p = 0; /* Character scalar and array declarations */ char ctail[ENUMLEN]; /* Initialise the error structure to print out any error messages */ INIT_FAIL(fail); printf("nag_prob_normal_vector (g01sac) Example Program Results\n\n"); /* Skip heading in data file*/ scanf("%*[^\n] "); /* Read in the input vectors */ scanf("%ld%*[^\n] ", <ail); if (!(tail = NAG_ALLOC(ltail, Nag_TailProbability))) { printf("Allocation failure\n"); exit_status = -1; goto END; } for (i = 0; i < ltail; i++) { scanf("%s", ctail); tail[i] = (Nag_TailProbability) nag_enum_name_to_value(ctail); } scanf("%*[^\n] "); scanf("%ld%*[^\n] ", &lx); if (!(x = NAG_ALLOC(lx, double))) { printf("Allocation failure\n"); exit_status = -1; goto END; } for (i = 0; i < lx; i++) scanf("%lf", &x[i]); scanf("%*[^\n] "); scanf("%ld%*[^\n] ", &lxmu); if (!(xmu = NAG_ALLOC(lxmu, double))) { printf("Allocation failure\n"); exit_status = -1; goto END; } for (i = 0; i < lxmu; i++) scanf("%lf", &xmu[i]); scanf("%*[^\n] "); scanf("%ld%*[^\n] ", &lxstd); if (!(xstd = NAG_ALLOC(lxstd, double))) { printf("Allocation failure\n"); exit_status = -1; goto END; } for (i = 0; i < lxstd; i++) scanf("%lf", &xstd[i]); scanf("%*[^\n] "); /* Allocate memory for output */ lout = MAX(ltail,MAX(lx,MAX(lxmu,lxstd))); if (!(p = NAG_ALLOC(lout, double)) || !(ivalid = NAG_ALLOC(lout, Integer))) { printf("Allocation failure\n"); exit_status = -1; goto END; } /* Calculate probability */ nag_prob_normal_vector(ltail, tail, lx, x, lxmu, xmu, lxstd, xstd, p, ivalid, &fail); if (fail.code != NE_NOERROR) { printf("Error from nag_prob_normal_vector (g01sac).\n%s\n", fail.message); exit_status = 1; if (fail.code != NW_IVALID) goto END; } /* Display title */ printf(" tail x xmu xstd "); printf("p ivalid\n"); printf("-------------------------------------------------------"); printf("--------------\n"); /* Display results */ for (i = 0; i < lout; i++) printf(" %17s %6.2f %6.2f %6.2f %6.3f %3ld\n", nag_enum_value_to_name(tail[i%ltail]), x[i%lx], xmu[i%lxmu], xstd[i%lxstd], p[i], ivalid[i]); END: if(tail) NAG_FREE(tail); if(x) NAG_FREE(x); if(xmu) NAG_FREE(xmu); if(xstd) NAG_FREE(xstd); if(p) NAG_FREE(p); if(ivalid) NAG_FREE(ivalid); return(exit_status); }