# include "Ximage.h"
# define TESTFREE(a) { if ((a) != (float *) NULL) free (a);}

int ErasePlot (int ClearSection) {
  
  int i, j;

  for (j = 0; j < Nsection; j++) {

    /* free data objects, then re-alloc those needed */
    for (i = 0; i < section[j].Nobjects; i++) {
      TESTFREE (section[j].objects[i].x);
      TESTFREE (section[j].objects[i].y);
      TESTFREE (section[j].objects[i].z);
      TESTFREE (section[j].objects[i].dxm);
      TESTFREE (section[j].objects[i].dxp);
      TESTFREE (section[j].objects[i].dym);
      TESTFREE (section[j].objects[i].dyp);
    }
    
    /* reset axes and labels */
    for (i = 0; i < 4; i++) {
      section[j].axis[i].isaxis = FALSE;
      section[j].axis[i].islabel = FALSE;
      section[j].axis[i].areticks = FALSE;
    }
    for (i = 0; i < 8; i++) {
      strcpy (section[j].label[i].text, "");
    }
    
    /* free objects and text entries, or re-zero */
    if (ClearSection && (j != 0)) {
      free (section[j].objects);
      free (section[j].ptext);
    } else {
      section[j].Nobjects = 0;
      REALLOCATE (section[j].objects, Gobjects, 1);
      section[j].Nptext = 0;
      REALLOCATE (section[j].ptext, Label, 1);
    }
  }

  if (ClearSection) {
    Nsection = 1;
    TheSection = 0;
    REALLOCATE (section, Layout, Nsection);
  }

  if (USE_XWINDOW) XClearWindow (graphic.display, graphic.window);
  Refresh (1);

  return (TRUE);
  
}


/** note that 'section' is the global variable
    of type 'Layout' which carries data and info 
    about each graph section 
**/
