/* 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 */
/* "tr" is the name of a subroutine which transforms array indicies */
/* into world coordinates */

#include <stdio.h>
#include <stdlib.h>
#include "plplot.h"
#include "declare.h"

void plcont(z,nx,ny,kx,lx,ky,ly,clevel,nlevel,tr)
int nx, ny, kx, lx, ky, ly, nlevel;
float *z, clevel[];
void (*tr)();
{
      int i, mx, my, nstor;

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

      if (kx < 1 || lx > nx || kx >= lx || ky < 1 || ky > ny || ky >= ly)
               fatal("Argument error in PLCONT");
      
      nstor = mx*my/5;

      if( heapc != NULL)
         free(heapc);
      if(( heapc = (int *)malloc((mx+2*nstor)*sizeof(int))) == NULL)
         fatal("Not enough heap space 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,tr);

}
