/* nag_rngs_2_way_table (g05qdc) Example Program. * * Copyright 2001 Numerical Algorithms Group. * * Mark 7, 2001. */ #include #include #include #include int main(void) { /* Scalars */ Integer i, igen, j, rctot; Integer exit_status=0; Integer nrow, ncol, nr; Integer pdx; NagError fail; Nag_OrderType order; /* Arrays */ double *r=0; Integer *totc=0, *totr=0, *x=0; Integer iseed[4]; #ifdef NAG_COLUMN_MAJOR #define X(I,J) x[(J-1)*pdx + I - 1] order = Nag_ColMajor; #else #define X(I,J) x[(I-1)*pdx + J - 1] order = Nag_RowMajor; #endif INIT_FAIL(fail); Vprintf("nag_rngs_2_way_table (g05qdc) Example Program Results\n\n"); nrow = 4; ncol = 3; nr = 60; /* Allocate memory */ if ( !(r = NAG_ALLOC(nr, double)) || !(totc = NAG_ALLOC(ncol, Integer)) || !(totr = NAG_ALLOC(nrow, Integer)) || !(x = NAG_ALLOC(nrow * ncol, Integer)) ) { Vprintf("Allocation failure\n"); exit_status = -1; goto END; } #ifdef NAG_COLUMN_MAJOR pdx = nrow; #else pdx = ncol; #endif /* Set the table row and column totals */ totr[0] = 9; totr[1] = 11; totr[2] = 7; totr[3] = 23; totc[0] = 16; totc[1] = 17; totc[2] = 17; rctot = 50; /* igen identifies the stream. */ igen = 1; /* Initialise the seed to a repeatable sequence */ iseed[0] = 1762543; iseed[1] = 9324783; iseed[2] = 42344; iseed[3] = 742355; /* nag_rngs_init_repeatable (g05kbc). * Initialize seeds of a given generator for random number * generating functions (that pass seeds explicitly) to give * a repeatable sequence */ nag_rngs_init_repeatable(&igen, iseed); /* Choose MODE = 2 */ /* nag_rngs_2_way_table (g05qdc). * Generates a random table matrix */ nag_rngs_2_way_table(order, 2, nrow, ncol, totr, totc, x, pdx, igen, iseed, r, nr, &fail); if (fail.code != NE_NOERROR) { Vprintf("Error from nag_rngs_2_way_table (g05qdc).\n%s\n", fail.message); exit_status = 1; goto END; } for (i = 1; i <= nrow; ++i) { Vprintf("%1s", ""); for (j = 1; j <= ncol; ++j) { Vprintf("%4ld %s", X(i,j), j%3 == 0 ?" |":" "); } Vprintf("%5ld\n", totr[i - 1]); } Vprintf(" ---------------+-----\n"); Vprintf("%1s", ""); for (j = 1; j <= ncol; ++j) { Vprintf("%4ld %s", totc[j - 1], j%3 == 0 ?" |":" "); } Vprintf("%5ld\n", rctot); END: if (r) NAG_FREE(r); if (totc) NAG_FREE(totc); if (totr) NAG_FREE(totr); if (x) NAG_FREE(x); return exit_status; }