/* nag_rand_sample_unequal (g05nec) Example Program. * * Copyright 2011, Numerical Algorithms Group. * * Mark 23, 2011. */ #include #include #include #define ENUMLEN 30 int main(void) { /* Scalars */ Integer exit_status = 0, lseed = 1; Integer i, lstate, m, n, subid; /* Arrays */ Integer *ipop = 0, *isampl = 0, *state = 0; Integer seed[1]; double *wt = 0; char cgenid[ENUMLEN], csortorder[ENUMLEN], cpop_supplied[ENUMLEN]; /* NAG structures */ NagError fail; Nag_BaseRNG genid; Nag_SortOrder sortorder; Nag_Boolean pop_supplied; /* Initialise the error structure to print out any error messages */ INIT_FAIL(fail); printf("nag_rand_sample_unequal (g05nec) Example Program Results\n\n"); /* Skip heading in data file*/ scanf("%*[^\n] "); /* Read in the base generator information and seed */ scanf("%s%ld%ld%*[^\n] ", cgenid, &subid, &seed[0]); genid = (Nag_BaseRNG) nag_enum_name_to_value(cgenid); /* Query to obtain the length of the state array using * nag_rand_init_repeatable (g05kfc). */ lstate = 0; nag_rand_init_repeatable(genid,subid,seed,lseed,state,&lstate,&fail); if (fail.code != NE_NOERROR) { printf("Error from nag_rand_init_repeatable (g05kfc).\n%s\n", fail.message); exit_status = 1; goto END; } /* Allocate memory to state */ if (!(state = NAG_ALLOC(lstate, Integer))) { printf("Allocation failure\n"); exit_status = -1; goto END; } /* Initialise the RNG using * nag_rand_init_repeatable (g05kfc) */ nag_rand_init_repeatable(genid,subid,seed,lseed,state,&lstate,&fail); if (fail.code != NE_NOERROR) { printf("Error from nag_rand_init_repeatable (g05kfc).\n%s\n", fail.message); exit_status = 2; goto END; } /* Read in the problem size, pop_supplied is a True / False flag indicating * whether population flags are supplied (Nag_TRUE) or taken as the integers * 1 to n (Nag_FALSE) */ scanf("%ld%ld%s%s%*[^\n] ", &n,&m,csortorder,cpop_supplied); sortorder = (Nag_SortOrder) nag_enum_name_to_value(csortorder); pop_supplied = (Nag_Boolean) nag_enum_name_to_value(cpop_supplied); /* Allocate memory for input arrays */ if (!(wt = NAG_ALLOC(n, double))|| !(isampl = NAG_ALLOC(m, Integer)) ) { printf("Allocation failure\n"); exit_status = -2; goto END; } if (pop_supplied) { /* Read in the population and weights*/ if (!(ipop = NAG_ALLOC(n, Integer))) { printf("Allocation failure\n"); exit_status = -3; goto END; } for (i=0; i