/* nag_prob_lin_non_central_chi_sq (g01jcc) Example Program. * * Copyright 2001 Numerical Algorithms Group. * * Mark 7, 2001. */ #include #include #include #include int main(void) { /* Initialized data */ Integer maxit = 500; double tol = 1e-4; /* Scalars */ double c, p, pdf; Integer exit_status, i, n; NagError fail; /* Arrays */ double *a=0, *rlamda=0; Integer *mult=0; INIT_FAIL(fail); exit_status = 0; Vprintf("g01jcc Example Program Results\n"); /* Skip heading in data file */ Vscanf("%*[^\n] "); Vprintf("\n A MULT RLAMDA\n"); while (scanf("%ld%lf%*[^\n] ", &n, &c) != EOF) { /* Allocate memory */ if ( !(a = NAG_ALLOC(n, double)) || !(rlamda = NAG_ALLOC(n, double)) || !(mult = NAG_ALLOC(n, Integer)) ) { Vprintf("Allocation failure\n"); exit_status = -1; goto END; } Vprintf("\n"); for (i = 1; i <= n; ++i) Vscanf("%lf", &a[i - 1]); Vscanf("%*[^\n] "); for (i = 1; i <= n; ++i) Vscanf("%ld", &mult[i - 1]); Vscanf("%*[^\n] "); for (i = 1; i <= n; ++i) Vscanf("%lf", &rlamda[i - 1]); Vscanf("%*[^\n] "); g01jcc(a, mult, rlamda, n, c, &p, &pdf, tol, maxit, &fail); if (fail.code == NE_NOERROR || fail.code == NE_ACCURACY || fail.code == NE_PROB_BOUNDARY) { for (i = 1; i <= n; ++i) Vprintf(" %10.2f%6ld%9.2f\n", a[i - 1], mult[i - 1], rlamda[i - 1]); Vprintf("c = %6.2f Prob = %6.4f\n", c, p); } else { Vprintf("Error from g01dac.\n%s\n", fail.message); exit_status = 1; goto END; } if (a) NAG_FREE(a); if (rlamda) NAG_FREE(rlamda); if (mult) NAG_FREE(mult); } END: if (a) NAG_FREE(a); if (rlamda) NAG_FREE(rlamda); if (mult) NAG_FREE(mult); return exit_status; }