/* nag_3d_shep_interp (e01tgc) Example Program. * * Copyright 2001 Numerical Algorithms Group. * * Mark 7, 2001. */ #include #include #include #include int main(void) { /* Scalars */ Integer exit_status, i, m, n, nq, nw, liq, lrq; NagError fail; /* Arrays */ double *f = 0, *q = 0, *qx = 0, *qy = 0, *qz = 0, *rq = 0, *u = 0, *v = 0, *w = 0, *x = 0, *y = 0, *z = 0; Integer *iq = 0; exit_status = 0; INIT_FAIL(fail); Vprintf("nag_3d_shep_interp (e01tgc) Example Program Results\n"); /* Skip heading in data file */ Vscanf("%*[^\n] "); /* Input the number of nodes. */ Vscanf("%ld%*[^\n] ", &m); if (m > 0) { /* Allocate memory */ lrq = 10 * m + 7; liq = 2 * m + 1; if ( !(f = NAG_ALLOC(m, double)) || !(x = NAG_ALLOC(m, double)) || !(y = NAG_ALLOC(m, double)) || !(z = NAG_ALLOC(m, double)) || !(rq = NAG_ALLOC(lrq, double)) || !(iq = NAG_ALLOC(liq, Integer)) ) { Vprintf("Allocation failure\n"); exit_status = -1; goto END; } /* Input the data points X,Y,Z and F. */ for (i = 0; i < m; ++i) Vscanf("%lf%lf%lf%lf%*[^\n] ", &x[i], &y[i], &z[i], &f[i]); /* Generate the interpolant. */ nq = 0; nw = 0; /* nag_3d_shep_interp (e01tgc). * Interpolating functions, modified Shepard's method, three * variables */ nag_3d_shep_interp(m, x, y, z, f, nw, nq, iq, rq, &fail); if (fail.code != NE_NOERROR) { Vprintf("Error from nag_3d_shep_interp (e01tgc).\n%s\n", fail.message); exit_status = 1; goto END; } /* Input the number of evaluation points. */ Vscanf("%ld%*[^\n] ", &n); /* Allocate memory for nag_3d_shep_eval (e01thc) */ if ( !(q = NAG_ALLOC(n, double)) || !(qx = NAG_ALLOC(n, double)) || !(qy = NAG_ALLOC(n, double)) || !(qz = NAG_ALLOC(n, double)) || !(u = NAG_ALLOC(n, double)) || !(v = NAG_ALLOC(n, double)) || !(w = NAG_ALLOC(n, double)) ) { Vprintf("Allocation failure\n"); exit_status = -1; goto END; } /* Input the evaluation points. */ for (i = 0; i < n; ++i) Vscanf("%lf%lf%lf%*[^\n] ", &u[i], &v[i], &w[i]); /* Evaluate the interpolant using nag_3d_shep_eval (e01thc). */ fail.print = Nag_TRUE; /* nag_3d_shep_eval (e01thc). * Interpolated values, evaluate interpolant computed by * nag_3d_shep_interp (e01tgc), function and first * derivatives, three variables */ nag_3d_shep_eval(m, x, y, z, f, iq, rq, n, u, v, w, q, qx, qy, qz, &fail); Vprintf("\n"); Vprintf(" i u(i) v(i) w(i) Q(i)\n"); for (i = 0; i < n; ++i) Vprintf("%6ld%10.4f%10.4f%10.4f%10.4f\n", i, u[i], v[i], w[i], q[i]); } END: if (f) NAG_FREE(f); if (q) NAG_FREE(q); if (qx) NAG_FREE(qx); if (qy) NAG_FREE(qy); if (qz) NAG_FREE(qz); if (rq) NAG_FREE(rq); if (u) NAG_FREE(u); if (v) NAG_FREE(v); if (w) NAG_FREE(w); if (x) NAG_FREE(x); if (y) NAG_FREE(y); if (z) NAG_FREE(z); if (iq) NAG_FREE(iq); return exit_status; }