/* Draws a contour plot from data in z(nx,ny), using the subarray */
/* from kx to lx in the x direction and from ky to ly in the y */
/* direction. The array of contour levels is clevel(nlevel), and */
/* "pltr" is the name of a subroutine which transforms array indicies */
/* into world coordinates */

#include "plplot.h"
#include "declare.h"
#include <stdio.h>
#ifdef PLSTDC
#include <stdlib.h>
#else
extern char *malloc();
extern void free();
#endif

void plcont(z,nx,ny,kx,lx,ky,ly,clevel,nlevel,pltr)
PLINT nx, ny, kx, lx, ky, ly, nlevel;
PLFLT *z, *clevel;
void (*pltr)();
{
      PLINT i, mx, my, nstor, *heapc;

      mx = lx - kx + 1;
      my = ly - ky + 1;

      if (kx < 1 || lx > nx || kx >= lx || ky < 1 || ky > ny || ky >= ly)
               plexit("Argument error in plcont.");

      nstor = mx*my/5;
      if(( heapc = (PLINT *)malloc((mx+2*nstor)*sizeof(PLINT))) == NULL)
         plexit("Out of memory in plcont.");
      for (i=0; i<nlevel; i++) {
        plcntr(z,nx,ny,kx,lx,ky,ly,clevel[i],&heapc[0],
               &heapc[nx],&heapc[nx+nstor],nstor,pltr);
      }
      free((VOID *)heapc);

}
