/* nag_rngs_corr_matrix (g05qbc) Example Program. * * Copyright 2001 Numerical Algorithms Group. * * Mark 7, 2001. */ #include #include #include #include #include int main(int argc, char *argv[]) { FILE *fpin, *fpout; /* Scalars */ double eps; Integer i, igen, j, n; Integer exit_status = 0; Integer pdc; NagError fail; Nag_OrderType order; /* Arrays */ double *c = 0, *d = 0; Integer iseed[4]; #ifdef NAG_COLUMN_MAJOR #define C(I, J) c[(J-1)*pdc + I - 1] order = Nag_ColMajor; #else #define C(I, J) c[(I-1)*pdc + J - 1] order = Nag_RowMajor; #endif INIT_FAIL(fail); /* Check for command-line IO options */ fpin = nag_example_file_io(argc, argv, "-data", NULL); fpout = nag_example_file_io(argc, argv, "-results", NULL); fprintf(fpout, "nag_rngs_corr_matrix (g05qbc) Example Program Results\n\n"); /* Skip heading in data file */ fscanf(fpin, "%*[^\n] "); fscanf(fpin, "%ld%*[^\n] ", &n); /* Allocate memory */ if (!(c = NAG_ALLOC(10 * 10, double)) || !(d = NAG_ALLOC(10, double))) { fprintf(fpout, "Allocation failure\n"); exit_status = -1; goto END; } #ifdef NAG_COLUMN_MAJOR pdc = n; #else pdc = n; #endif if (n <= 10) { for (i = 0; i < n; ++i) { fscanf(fpin, "%lf", &d[i]); } fscanf(fpin, "%*[^\n] "); eps = 1e-4; /* igen identifies the stream. */ igen = 1; /* Initialise the seed to a repeatable sequence */ iseed[0] = 1762543; iseed[1] = 9324783; iseed[2] = 423446; 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); /* nag_rngs_corr_matrix (g05qbc). * Computes a random correlation matrix */ nag_rngs_corr_matrix(order, n, d, c, pdc, eps, igen, iseed, &fail); if (fail.code != NE_NOERROR) { fprintf(fpout, "Error from nag_rngs_corr_matrix (g05qbc).\n%s\n", fail.message); exit_status = 1; goto END; } for (i = 1; i <= n; ++i) { for (j = 1; j <= n; ++j) { fprintf(fpout, "%9.3f%s", C(i, j), j%3 == 0 || j == n?"\n":" "); } } } END: if (fpin != stdin) fclose(fpin); if (fpout != stdout) fclose(fpout); if (c) NAG_FREE(c); if (d) NAG_FREE(d); return exit_status; }