/* nag_1d_spline_intg (e02bdc) 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, j; NagError fail; Nag_Spline spline; double integral; INIT_FAIL(fail); /* Initialise spline */ spline.lamda = 0; spline.c = 0; /* 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_1d_spline_intg (e02bdc) Example Program Results\n"); fscanf(fpin, "%*[^\n]"); /* Skip heading in data file */ while (fscanf(fpin, "%ld", &(spline.n)) != EOF) { if (spline.n > 0) { if (!(spline.c = NAG_ALLOC(spline.n, double)) || !(spline.lamda = NAG_ALLOC(spline.n, double))) { fprintf(fpout, "Storage allocation failed. Reduce the " "size of spline.n\n"); exit_status = 1; goto END; } } else { fprintf(fpout, "spline.n is out of range : spline.n = %ld\n", spline.n); exit_status = 1; goto END; } for (j = 0; j < spline.n; j++) fscanf(fpin, "%lf", &(spline.lamda[j])); for (j = 0; j < spline.n-3; j++) fscanf(fpin, "%lf", &(spline.c[j])); /* nag_1d_spline_intg (e02bdc). * Evaluation of fitted cubic spline, definite integral */ nag_1d_spline_intg(&spline, &integral, &fail); if (fail.code != NE_NOERROR) { fprintf(fpout, "Error from nag_1d_spline_intg (e02bdc).\n%s\n", fail.message); exit_status = 1; goto END; } fprintf(fpout, "Definite integral = %12.3e\n", integral); if (spline.c) NAG_FREE(spline.c); if (spline.lamda) NAG_FREE(spline.lamda); } END: if (fpin != stdin) fclose(fpin); if (fpout != stdout) fclose(fpout); return exit_status; }