/* nag_2d_spline_interpolant (e01dac) Example Program. * * Copyright 1991 Numerical Algorithms Group. * * Mark 2, 1991. * * Mark 6 revised, 2000. * Mark 8 revised, 2004. */ #include #include #include #include #include #define F(I,J) f[my*(I)+(J)] #define FG(I,J) fg[npy*(I)+(J)] #define C(I,J) spline.c[my*(I)+(J)] int main(void) { Integer exit_status=0, i, j, mx, my, npx, npy; NagError fail; Nag_2dSpline spline; double *f=0, *fg=0, step, *tx=0, *ty=0, *x=0, xhi, xlo, *y=0, yhi, ylo; INIT_FAIL(fail); Vprintf("nag_2d_spline_interpolant (e01dac) Example Program Results\n"); Vscanf("%*[^\n]"); /* Skip heading in data file */ /* Read the number of x points, mx, and the values of the * x co-ordinates. */ Vscanf("%ld%ld",&mx, &my); if (mx>=4 && my>= 4) { if ( !( f = NAG_ALLOC(mx*my, double)) || !( x = NAG_ALLOC(mx, double)) || !( y = NAG_ALLOC(my, double)) ) { Vprintf("Allocation failure\n"); exit_status = -1; goto END; } } else { Vprintf("Invalid mx or my.\n"); exit_status = 1; return exit_status; } for (i=0; i=1 && npy>=1) { if ( !( fg = NAG_ALLOC(npx*npy, double)) || !( tx = NAG_ALLOC(npx, double)) || !( ty = NAG_ALLOC(npy, double)) ) { Vprintf("Allocation failure\n"); exit_status = -1; goto END; } } else { Vprintf("Invalid npx or npy.\n"); exit_status = 1; return exit_status; } step = (xhi-xlo)/(double)(npx-1); Vprintf("\nSpline evaluated on a regular mesh " " (x across, y down): \n "); /* Generate nx equispaced x co-ordinates. */ for (i=0; i