/* nag_1d_quad_vals (d01gac) Example Program. * * Copyright 1991 Numerical Algorithms Group. * * Mark 2, 1991. * Mark 8 revised, 2004. */ #include #include #include #include int main(void) { Integer exit_status=0, i, n; NagError fail; double ans, error, *x=0, *y=0; INIT_FAIL(fail); Vprintf("nag_1d_quad_vals (d01gac) Example Program Results\n"); Vscanf("%*[^\n]"); /* Skip heading in data file */ Vscanf("%ld",&n); if (n>=4) { if ( !( x = NAG_ALLOC(n, double)) || !( y = NAG_ALLOC(n, double)) ) { Vprintf("Allocation failure\n"); exit_status = -1; goto END; } } else { Vprintf("Invalid n.\n"); exit_status = 1; return exit_status; } for (i=0; i < n; ++i) Vscanf("%lf%lf", &x[i], &y[i]); /* nag_1d_quad_vals (d01gac). * One-dimensional integration of a function defined by data * values only */ nag_1d_quad_vals(n, x, y, &ans, &error, &fail); if (fail.code == NE_NOERROR) { Vprintf("Integral = %7.4f\n", ans); Vprintf("Estimated error = %7.4f\n", error); } else { Vprintf("Error from nag_1d_quad_vals (d01gac).\n%s\n", fail.message); Vprintf("%s\n", fail.message); exit_status = 1; } END: if (x) NAG_FREE(x); if (y) NAG_FREE(y); return exit_status; }