/* nag_nag_2d_shep_interp (e01sgc) Example Program. * * Copyright 2005 Numerical Algorithms Group. * * Mark 8, 2005. */ #include #include #include #include int main(void) { /* Scalars */ Integer exit_status, i, m, n, nq, nw; Integer liq, lrq; /* Arrays */ double *f=0, *q=0, *qx=0, *qy=0, *rq=0, *u=0, *v=0, *x=0, *y=0; Integer *iq=0; /* Nag Types */ NagError fail; exit_status = 0; INIT_FAIL(fail); Vprintf( "nag_2d_shep_interp (e01sgc) Example Program Results\n\n"); /* Skip heading in data file */ Vscanf("%*[^\n] "); /* Input the number of nodes. */ Vscanf("%ld%*[^\n] ", &m); if (m > 6) { liq = 2*m+1; lrq = 6*m+5; /* Allocate memory */ if ( !(f = NAG_ALLOC(m, double)) || !(rq = NAG_ALLOC(lrq, double)) || !(x = NAG_ALLOC(m, double)) || !(y = NAG_ALLOC(m, double)) || !(iq = NAG_ALLOC(liq, Integer)) ) { Vprintf("Allocation failure\n"); exit_status = -1; goto END; } } else { Vprintf("Invalid m.\n"); exit_status = 1; return exit_status; } /* Input the data points X,Y and F. */ for (i = 1; i <= m; ++i) { Vscanf("%lf%lf%lf%*[^\n] ", &x[i - 1], &y[i - 1], &f[i - 1]); } /* Generate the interpolant. */ nq = 0; nw = 0; /* nag_2d_shep_interp (e01sgc). * Interpolating functions, modified Shepard's method, two * variables */ nag_2d_shep_interp(m, x, y, f, nw, nq, iq, rq, &fail); if (fail.code != NE_NOERROR) { Vprintf("Error from nag_2d_shep_interp (e01sgc).\n%s\n", fail.message); exit_status = 1; goto END; } /* Input the number of evaluation points. */ Vscanf("%ld%*[^\n] ", &n); if ( !(q = NAG_ALLOC(n, double)) || !(qx = NAG_ALLOC(n, double)) || !(qy = NAG_ALLOC(n, double)) || !(u = NAG_ALLOC(n, double)) || !(v = NAG_ALLOC(n, double)) ) { Vprintf("Allocation failure\n"); exit_status = 1; goto END; } /* Input the evaluation points. */ for (i = 1; i <= n; ++i) { Vscanf("%lf%lf%*[^\n] ", &u[i - 1], &v[i - 1]); } /* Evaluate the interpolant using nag_2d_shep_eval (e01shc). */ /* nag_2d_shep_eval (e01shc). * Interpolated values, evaluate interpolant computed by * nag_2d_shep_interp (e01sgc), function and first * derivatives, two variables */ nag_2d_shep_eval(m, x, y, f, iq, rq, n, u, v, q, qx, qy, &fail); if (fail.code != NE_NOERROR) { Vprintf("Error from nag_2d_shep_interp (e01sgc).\n%s\n", fail.message); exit_status = 1; goto END; } Vprintf("%s", " I U(I) V(I) Q(I)"); Vprintf("\n"); for (i = 1; i <= n; ++i) { Vprintf("%6ld%10.2f%10.2f%10.2f\n", i, u[i - 1], v[i - 1], q[i - 1]); } END: if (f) NAG_FREE(f); if (q) NAG_FREE(q); if (qx) NAG_FREE(qx); if (qy) NAG_FREE(qy); if (rq) NAG_FREE(rq); if (u) NAG_FREE(u); if (v) NAG_FREE(v); if (x) NAG_FREE(x); if (y) NAG_FREE(y); if (iq) NAG_FREE(iq); return exit_status; }