/* nag_monotonic_intg (e01bhc) Example Program. * * Copyright 1991 Numerical Algorithms Group. * * Mark 2, 1991. * Mark 8 revised, 2004. */ #include #include #include #include #include int main(int argc, char *argv[]) { FILE *fpin, *fpout; Integer exit_status = 0, n, r; NagError fail; double a, b, *d = 0, *f = 0, integral, *x = 0; 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_monotonic_intg (e01bhc) Example Program Results\n"); fscanf(fpin, "%*[^\n]"); /* Skip heading in data file */ fscanf(fpin, "%ld", &n); if (n >= 2) { if (!(d = NAG_ALLOC(n, double)) || !(f = NAG_ALLOC(n, double)) || !(x = NAG_ALLOC(n, double))) { fprintf(fpout, "Allocation failure\n"); exit_status = -1; goto END; } } else { fprintf(fpout, "Invalid n.\n"); exit_status = 1; return exit_status; } for (r = 0; r < n; r++) fscanf(fpin, "%lf%lf%lf", &x[r], &f[r], &d[r]); fprintf(fpout, " Integral\n"); fprintf(fpout, " a b over (a,b)\n"); /* Read a, b pairs until end of file and compute * definite integrals. */ while (fscanf(fpin, "%lf%lf", &a, &b) != EOF) { /* nag_monotonic_intg (e01bhc). * Evaluation of interpolant computed by * nag_monotonic_interpolant (e01bec), definite integral */ nag_monotonic_intg(n, x, f, d, a, b, &integral, &fail); if (fail.code != NE_NOERROR) { fprintf(fpout, "Error from nag_monotonic_intg (e01bhc).\n%s\n", fail.message); exit_status = 1; goto END; } fprintf(fpout, "%13.4f %13.4f %13.4f\n", a, b, integral); } END: if (fpin != stdin) fclose(fpin); if (fpout != stdout) fclose(fpout); if (d) NAG_FREE(d); if (f) NAG_FREE(f); if (x) NAG_FREE(x); return exit_status; }