/* nag_2d_scat_interpolant (e01sac) Example Program. * * Copyright 1996 Numerical Algorithms Group. * * Mark 4, 1996. * Mark 8 revised, 2004. */ #include #include #include #include int main(void) { Integer exit_status=0, i, isel, j, m, n, nx, ny; NagError fail; Nag_2d_Scat_Method method; Nag_E01_Opt optional; Nag_Scat_Struct comm; double *f=0, *pf=0, *px=0, *py=0, *x=0, xhi, xlo, *y=0, yhi, ylo; INIT_FAIL(fail); Vprintf("nag_2d_scat_interpolant (e01sac) Example Program Results\n"); /* Skip heading in data file */ Vscanf("%*[^\n]"); /* Input the number of nodes. */ Vscanf("%ld", &m); if (m>=3) { if ( !( f = NAG_ALLOC(m, double)) || !( x = NAG_ALLOC(m, double)) || !( y = NAG_ALLOC(m, double)) ) { Vprintf("Allocation failure\n"); exit_status = -1; goto ENDL; } } else { Vprintf("Invalid m.\n"); exit_status = 1; return exit_status; } /* Input the nodes (x,y) and heights, f. */ for (i=0; i=1 && ny>=1) { if ( !( pf = NAG_ALLOC(nx*ny, double)) || !( px = NAG_ALLOC(nx*ny, double)) || !( py = NAG_ALLOC(nx*ny, double)) ) { Vprintf("Allocation failure\n"); exit_status = -1; goto END; } } else { Vprintf("Invalid nx or ny.\n"); exit_status = 1; return exit_status; } /* * Evaluate the interpolant on a rectangular grid at nx*ny points * over the domain (xlo to xhi) x (ylo to yhi). */ n = 0; for (j=0; j= 0; --i) { Vprintf("%8.2f ", py[nx * i]); for (j = 0; j < nx; j++) Vprintf("%8.2f", pf[nx * i + j]); Vprintf("\n"); } END: /* Free the memory allocated to the pointers in structure comm. */ /* nag_2d_scat_free (e01szc). * Freeing function for use with nag_2d_scat_eval (e01sbc) */ nag_2d_scat_free(&comm); if (pf) NAG_FREE(pf); if (px) NAG_FREE(px); if (py) NAG_FREE(py); } ENDL: if (f) NAG_FREE(f); if (x) NAG_FREE(x); if (y) NAG_FREE(y); return exit_status; }