/* nag_2d_cheb_eval (e02cbc) Example Program. * * Copyright 2001 Numerical Algorithms Group. * * Mark 7, 2001. * Mark 7b revised, 2004. */ #include #include #include #include #include int main(int argc, char *argv[]) { FILE *fpin, *fpout; /* Scalars */ double x1, xm, xmax, xmin, y, ymax, ymin; Integer exit_status, i, j, k, l, m, n, ncoef, one; NagError fail; /* Arrays */ double *a = 0, *ff = 0, *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); exit_status = 0; fprintf(fpout, "nag_2d_cheb_eval (e02cbc) Example Program Results\n"); /* Skip heading in data file */ fscanf(fpin, "%*[^\n] "); while (fscanf(fpin, "%ld%ld%ld%*[^\n] ", &n, &k, &l) != EOF) { /* Allocate array a */ ncoef = (k + 1) * (l + 1); if (!(a = NAG_ALLOC(ncoef, double))) { fprintf(fpout, "Allocation failure\n"); exit_status = -1; goto END; } for (i = 0; i < ncoef; ++i) fscanf(fpin, "%lf", &a[i]); fscanf(fpin, "%*[^\n] "); fscanf(fpin, "%lf%lf%*[^\n] ", &ymin, &ymax); for (i = 0; i < n; ++i) { fscanf(fpin, "%lf%ld%lf%lf%lf%lf%*[^\n] ", &y, &m, &xmin, &xmax, &x1, &xm); /* Allocate arrays x and ff */ if (!(x = NAG_ALLOC(m, double)) || !(ff = NAG_ALLOC(m, double))) { fprintf(fpout, "Allocation failure\n"); exit_status = -1; goto END; } for (j = 0; j < m; ++j) x[j] = x1 + (xm - x1) * (double) j / (double)(m - 1); one = 1; /* nag_2d_cheb_eval (e02cbc). * Evaluation of fitted polynomial in two variables */ nag_2d_cheb_eval(one, m, k, l, x, xmin, xmax, y, ymin, ymax, ff, a, &fail); if (fail.code != NE_NOERROR) { fprintf(fpout, "Error from nag_2d_cheb_eval (e02cbc).\n%s\n", fail.message); exit_status = 1; goto END; } fprintf(fpout, "\n"); fprintf(fpout, "y = %13.4e\n", y); fprintf(fpout, "\n"); fprintf(fpout, " i x(i) Poly(x(i),y)\n"); for (j = 0; j < m; ++j) fprintf(fpout, "%3ld%13.4e%13.4e\n", j, x[j], ff[j]); if (ff) NAG_FREE(ff); if (x) NAG_FREE(x); } if (a) NAG_FREE(a); } END: if (fpin != stdin) fclose(fpin); if (fpout != stdout) fclose(fpout); if (a) NAG_FREE(a); if (ff) NAG_FREE(ff); if (x) NAG_FREE(x); return exit_status; }