# Example 2 - nonlinear interpolation (C single precision)

```#include <stdio.h>

extern float *c_natgrids(int, float [], float [], float [],
int, int, float [], float [], int *);
extern void drwsrfc (int, int, float *, float *, float *,
float, float, float, int *);

#define NUMIN 6
#define NUMXOUT 21
#define NUMYOUT 21

main()
{
int i, j, ier, iert, *iwk;

float x[] = {0.00, 1.00, 0.00, 1.00, 0.40, 0.75},
y[] = {0.00, 0.00, 1.00, 1.00, 0.20, 0.65},
z[] = {0.00, 0.00, 0.00, 0.00, 1.25, 0.80};
float *out, xo[NUMXOUT], yo[NUMYOUT], xc, yc;

iwk = (int *) calloc(2*NUMXOUT*NUMYOUT,sizeof(float));

xc = 1./(NUMXOUT-1.);
for (i = 0 ; i < NUMXOUT ; i++) {
xo[i] = i * xc;
}

yc = 1./(NUMYOUT-1.);
for (j = 0 ; j < NUMYOUT ; j++) {
yo[j] = j * yc;
}

/*
*  Set the flag to indicate use of gradient estimates.
*/
c_nnseti("igr",1);

/*
*  Do the regridding.
*/
out = c_natgrids(NUMIN, x, y, z, NUMXOUT, NUMYOUT, xo, yo, &ier);
if (ier != 0) {
printf (" Error return from c_natgrids = %d\n",ier);
}

/*
*  Draw the surface plot.
*/
drwsrfc (NUMXOUT, NUMYOUT, xo, yo, out, 15.,-25.,90., iwk);

}
```

home | contents | defs | params | procedures | exmpls | index