Example 1 - linear interpolation (C double precision)


#include <stdio.h>

extern double *c_natgridd(int, double [], double [], double [],
                          int, int, double [], double [], 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;

  double 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};
  double *out, xo[NUMXOUT], yo[NUMYOUT], xc, yc;
  float outd[NUMXOUT * NUMYOUT], xp[NUMXOUT], yp[NUMYOUT];

  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;
  }

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

  for (i = 0; i < NUMXOUT; i++) {
    xp[i] = xo[i];
    for (j = 0; j < NUMYOUT; j++) {
      yp[j] = yo[j];
      outd[i*NUMYOUT+j] = (float) out[i*NUMYOUT+j];
    }
  }

/*
 *  Draw the surface plot.
 */
  drwsrfc (NUMXOUT, NUMYOUT, xp, yp, outd, 15.,-25.,90., iwk);

}

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