Index: /branches/kapa-mods-2007-05/Ohana/src/kapa2/Makefile
===================================================================
--- /branches/kapa-mods-2007-05/Ohana/src/kapa2/Makefile	(revision 13431)
+++ /branches/kapa-mods-2007-05/Ohana/src/kapa2/Makefile	(revision 13432)
@@ -49,5 +49,5 @@
 $(SRC)/Graphs.$(ARCH).o                   $(SRC)/SetGraphSize.$(ARCH).o       \
 $(SRC)/Resize.$(ARCH).o                   $(SRC)/ErasePlots.$(ARCH).o         \
-$(SRC)/EraseImage.$(ARCH).o         \
+$(SRC)/EraseImage.$(ARCH).o         	  $(SRC)/SetToolbox.$(ARCH).o         \
 $(SRC)/EraseCurrentPlot.$(ARCH).o         $(SRC)/EraseSections.$(ARCH).o      \
 $(SRC)/SetSection.$(ARCH).o		  $(SRC)/DefineSection.$(ARCH).o      \
@@ -65,7 +65,7 @@
 $(SRC)/CreatePicture.$(ARCH).o            $(SRC)/CreateColorbar.$(ARCH).o     \
 $(SRC)/MakeColormap.$(ARCH).o		  $(SRC)/SetColormap.$(ARCH).o        \
-$(SRC)/PaintOverlay.$(ARCH).o		  $(SRC)/PaintTickmarks.$(ARCH).o     \
+$(SRC)/PaintOverlay.$(ARCH).o		  $(SRC)/SetGraphStyle.$(ARCH).o      \
 $(SRC)/LoadOverlay.$(ARCH).o		  $(SRC)/EraseOverlay.$(ARCH).o       \
-$(SRC)/LoadTickmarks.$(ARCH).o		  $(SRC)/SaveOverlay.$(ARCH).o        \
+$(SRC)/SaveOverlay.$(ARCH).o        \
 $(SRC)/CSaveOverlay.$(ARCH).o		  $(SRC)/EraseOverlay.$(ARCH).o       \
 $(SRC)/CheckVisual.$(ARCH).o              $(SRC)/CursorOps.$(ARCH).o          \
Index: /branches/kapa-mods-2007-05/Ohana/src/kapa2/include/prototypes.h
===================================================================
--- /branches/kapa-mods-2007-05/Ohana/src/kapa2/include/prototypes.h	(revision 13431)
+++ /branches/kapa-mods-2007-05/Ohana/src/kapa2/include/prototypes.h	(revision 13432)
@@ -63,4 +63,6 @@
 int           EraseSections       PROTO((void));
 int           EraseImage          PROTO((void));
+int           SetGraphStyle       PROTO((int sock));
+int           GetGraphStyle       PROTO((int sock));
 
 int           LoadVectorData      PROTO((int sock, KapaGraphWidget *graph, int N, char *type));
Index: /branches/kapa-mods-2007-05/Ohana/src/kapa2/include/structures.h
===================================================================
--- /branches/kapa-mods-2007-05/Ohana/src/kapa2/include/structures.h	(revision 13431)
+++ /branches/kapa-mods-2007-05/Ohana/src/kapa2/include/structures.h	(revision 13432)
@@ -95,5 +95,5 @@
   int Nobjects;
   unsigned long color;
-  Object *objects;
+  KiiOverlay *objects;
 } Overlay;
   
@@ -116,4 +116,5 @@
   Axis      axis[4];    /* coordinate axes */
   Label     label[8];   /* fixed axis labels */
+  Graphdata style;      /* current graph style */
 
   Gobjects *objects;    /* graphic objects */    
Index: /branches/kapa-mods-2007-05/Ohana/src/kapa2/src/CSaveOverlay.c
===================================================================
--- /branches/kapa-mods-2007-05/Ohana/src/kapa2/src/CSaveOverlay.c	(revision 13431)
+++ /branches/kapa-mods-2007-05/Ohana/src/kapa2/src/CSaveOverlay.c	(revision 13432)
@@ -3,5 +3,5 @@
 int CSaveOverlay (int sock) {
 
-  char filename[256];
+  char filename[256], *type;
   int i, N;
   double ra, dec, ra1, dec1, x1, y1, dra, ddec;
@@ -23,5 +23,5 @@
 
   for (i = 0; i < image[0].overlay[N].Nobjects; i++) {
-    if (!strcmp (image[0].overlay[N].objects[i].type, "LINE")) {
+    if (image[0].overlay[N].objects[i].type == KII_OVERLAY_LINE) {
       XY_to_RD (&ra, &dec, image[0].overlay[N].objects[i].x, image[0].overlay[N].objects[i].y, &image[0].coords);
       x1 = image[0].overlay[N].objects[i].x + image[0].overlay[N].objects[i].dx;
@@ -41,5 +41,7 @@
       dra = cos (dec*RAD_DEG) * fabs (ra1 - ra);
     }
-    fprintf (f, "%s %lf %lf %lf %lf\n", image[0].overlay[N].objects[i].type, ra, dec, dra, ddec);
+    type = KiiOverlayTypeByNumber (image[0].overlay[N].objects[i].type);
+    if (type == NULL) continue;
+    fprintf (f, "%s %lf %lf %lf %lf\n", type, ra, dec, dra, ddec);
    }
   fclose (f);
Index: /branches/kapa-mods-2007-05/Ohana/src/kapa2/src/CheckPipe.c
===================================================================
--- /branches/kapa-mods-2007-05/Ohana/src/kapa2/src/CheckPipe.c	(revision 13431)
+++ /branches/kapa-mods-2007-05/Ohana/src/kapa2/src/CheckPipe.c	(revision 13432)
@@ -119,5 +119,5 @@
   }
 
-  if (!strcmp (word, "LIMS")) {
+  if (!strcmp (word, "GLIM")) {
     GetLimits (sock);
     KiiSendCommand (sock, 4, "DONE");
@@ -127,4 +127,22 @@
   if (!strcmp (word, "SLIM")) {
     status = SetLimits (sock);
+    KiiSendCommand (sock, 4, "DONE");
+    FINISHED (TRUE);
+  }
+  
+  if (!strcmp (word, "GSTY")) {
+    GetGraphStyle (sock);
+    KiiSendCommand (sock, 4, "DONE");
+    FINISHED (TRUE);
+  }
+  
+  if (!strcmp (word, "SSTY")) {
+    status = SetGraphStyle (sock);
+    KiiSendCommand (sock, 4, "DONE");
+    FINISHED (TRUE);
+  }
+  
+  if (!strcmp (word, "TOOL")) {
+    status = SetToolbox (sock);
     KiiSendCommand (sock, 4, "DONE");
     FINISHED (TRUE);
@@ -208,14 +226,4 @@
   }
 
-  /* this is not currently used?
-     tickmarks were equivalent to the overlays, but fixed wrt the window.
-     this functionality is probably supplanted by the graph 
-  if (!strcmp (word, "TICK")) {
-    status = LoadTickmarks (sock);
-    KiiSendCommand (sock, 4, "DONE");
-    FINISHED (status);
-  }
-  */
-
   if (!strcmp (word, "SAVE")) {
     status = SaveOverlay (sock);
Index: /branches/kapa-mods-2007-05/Ohana/src/kapa2/src/EraseOverlay.c
===================================================================
--- /branches/kapa-mods-2007-05/Ohana/src/kapa2/src/EraseOverlay.c	(revision 13431)
+++ /branches/kapa-mods-2007-05/Ohana/src/kapa2/src/EraseOverlay.c	(revision 13432)
@@ -17,13 +17,13 @@
 
   if (N > NOVERLAYS) {
-    REALLOCATE (image[0].tickmarks.objects, Object, 1);
+    REALLOCATE (image[0].tickmarks.objects, KiiOverlay, 1);
     image[0].tickmarks.Nobjects = 0;
   } else {
     for (i = 0; i < image[0].overlay[N].Nobjects; i++) {
-      if (!strcmp (image[0].overlay[N].objects[i].type, "TEXT")) {
+      if (image[0].overlay[N].objects[i].type == KII_OVERLAY_TEXT) {
 	free (image[0].overlay[N].objects[i].text);
       }
     }
-    REALLOCATE (image[0].overlay[N].objects, Object, 1);
+    REALLOCATE (image[0].overlay[N].objects, KiiOverlay, 1);
     image[0].overlay[N].Nobjects = 0;
     image[0].overlay[N].active = FALSE;
Index: /branches/kapa-mods-2007-05/Ohana/src/kapa2/src/Image.c
===================================================================
--- /branches/kapa-mods-2007-05/Ohana/src/kapa2/src/Image.c	(revision 13431)
+++ /branches/kapa-mods-2007-05/Ohana/src/kapa2/src/Image.c	(revision 13432)
@@ -21,9 +21,10 @@
   image[0].start = 0;
   image[0].slope = 1;
+  image[0].location = 4;
 
   image[0].coords.Npolyterms = 0;
   for (i = 0; i < NOVERLAYS; i++) {
     image[0].overlay[i].Nobjects = 0;
-    ALLOCATE (image[0].overlay[i].objects, Object, 1);  /* allocate so later free will not crash! */
+    ALLOCATE (image[0].overlay[i].objects, KiiOverlay, 1);  /* allocate so later free will not crash! */
     image[0].overlay[i].active = FALSE;
     image[0].overlay[i].color = graphic[0].overlay_color[i];
@@ -111,7 +112,4 @@
     }
   }
-# if (0)
-  PaintTickmarks (graphic, image);
-# endif
 
   if (image[0].location) {
Index: /branches/kapa-mods-2007-05/Ohana/src/kapa2/src/LoadObject.c
===================================================================
--- /branches/kapa-mods-2007-05/Ohana/src/kapa2/src/LoadObject.c	(revision 13431)
+++ /branches/kapa-mods-2007-05/Ohana/src/kapa2/src/LoadObject.c	(revision 13432)
@@ -106,14 +106,14 @@
 int LoadVectorData (int sock, KapaGraphWidget *graph, int N, char *type) {
   
-  int Npts, Ninpts, status, Ntry;
+  int i, Npts, Ninpts, status, Ntry;
   int bytes_left;
-  char *buff, type_send[16];
-  int Npts_send, Nbytes_send;
-
-  buff = NULL;
+  char *byte, *buffer, type_send[16], tmp;
+  int Npts_send, Nbytes_send, swap_client, swap_host;
+
+  buffer = NULL;
   Npts = graph[0].objects[N].Npts;
 
   KiiWaitAnswer (sock, "PLOB");
-  KiiScanMessage (sock, "%s %d %d", type_send, &Npts_send, &Nbytes_send);
+  KiiScanMessage (sock, "%s %d %d %d", type_send, &Npts_send, &Nbytes_send, &swap_client);
   if (strcmp (type, type_send)) {
     fprintf (stderr, "Kapa Communication error: unexpected data type %s vs %s\n", type_send, type);
@@ -129,29 +129,29 @@
   if (!strcmp (type, "x")) {
     ALLOCATE (graph[0].objects[N].x, float, MAX (1, Npts));
-    buff = (char *) graph[0].objects[N].x;
+    buffer = (char *) graph[0].objects[N].x;
   }
   if (!strcmp (type, "y")) {
     ALLOCATE (graph[0].objects[N].y, float, MAX (1, Npts));
-    buff = (char *) graph[0].objects[N].y;
+    buffer = (char *) graph[0].objects[N].y;
   }
   if (!strcmp (type, "z")) {
     ALLOCATE (graph[0].objects[N].z, float, MAX (1, Npts));
-    buff = (char *) graph[0].objects[N].z;
+    buffer = (char *) graph[0].objects[N].z;
   }
   if (!strcmp (type, "dxm")) {
     ALLOCATE (graph[0].objects[N].dxm, float, MAX (1, Npts));
-    buff = (char *) graph[0].objects[N].dxm;
+    buffer = (char *) graph[0].objects[N].dxm;
   }
   if (!strcmp (type, "dxp")) {
     ALLOCATE (graph[0].objects[N].dxp, float, MAX (1, Npts));
-    buff = (char *) graph[0].objects[N].dxp;
+    buffer = (char *) graph[0].objects[N].dxp;
   }
   if (!strcmp (type, "dym")) {
     ALLOCATE (graph[0].objects[N].dym, float, MAX (1, Npts));
-    buff = (char *) graph[0].objects[N].dym;
+    buffer = (char *) graph[0].objects[N].dym;
   }
   if (!strcmp (type, "dyp")) {
     ALLOCATE (graph[0].objects[N].dyp, float, MAX (1, Npts));
-    buff = (char *) graph[0].objects[N].dyp;
+    buffer = (char *) graph[0].objects[N].dyp;
   }
 
@@ -160,9 +160,11 @@
   fcntl (sock, F_SETFL, O_NONBLOCK);  
 
+  // read the vector data as raw binary in client machine byte order (floats)
   Ntry = 0;
   if (DEBUG) fprintf (stderr, "starting vector load\n");
   Ninpts = 0;
+  byte = buffer;
   while (bytes_left > 0) {
-    status = read (sock, buff, bytes_left);
+    status = read (sock, byte, bytes_left);
     if (DEBUG) fprintf (stderr, "status: %d, %d\n", status, bytes_left);
     if (status == 0) {  /* No more pipe */
@@ -173,5 +175,5 @@
       Ninpts += status;
       bytes_left -= status;
-      buff = (char *)(buff + status);
+      byte = (char *)(byte + status);
       Ntry = 0;
       continue;
@@ -192,4 +194,20 @@
   KiiSendCommand (sock, 4, "DONE"); 
 
+# ifdef BYTE_SWAP
+  swap_host = 1;
+# else 
+  swap_host = 0;
+# endif  
+
+  // if host and client have opposite swap parities, word swap the incoming data
+  // SWAP_WORD is strangely defined... it takes the number of the start byte in a
+  // buffer called 'byte'
+  if ((swap_host && !swap_client) || (!swap_host && swap_client)) {
+    byte = buffer;
+    for (i = 0; i < Nbytes_send; i+=4) {
+      SWAP_WORD (i);
+    }
+  }
+
   if (Ninpts != Npts*sizeof(float)) {  
     fprintf (stderr, "error: expected %d bytes, but got only %d\n", Ninpts, (unsigned int)(Npts*sizeof(float)));
@@ -212,3 +230,2 @@
   if (object[0].dyp != (float *) NULL) free (object[0].dyp);
 }
-
Index: /branches/kapa-mods-2007-05/Ohana/src/kapa2/src/LoadOverlay.c
===================================================================
--- /branches/kapa-mods-2007-05/Ohana/src/kapa2/src/LoadOverlay.c	(revision 13431)
+++ /branches/kapa-mods-2007-05/Ohana/src/kapa2/src/LoadOverlay.c	(revision 13432)
@@ -1,15 +1,13 @@
 # include "Ximage.h"
 
-// XXX this is a very inefficient method to send the data: binary would be better
 int LoadOverlay (int sock) {
   
-  char word[17], type[16], string[128];
-  char *buffer, *buff;
-  double x, y, dx, dy;
-  int Nin, bytes, status;
-  int i, N, NOBJECTS, Nobjects, Nstart;
+  int i, j, Ntotal, Nbytes, Nread, Nfound, Ntext, Nobjects, overnum;
+  int Noverlay, NOVERLAY, Ntextdata;
+  char *textdata, *buffer, *p, *q;
   Section *section;
   KapaImageWidget *image;
   Graphic *graphic;
+  KiiOverlayBase *overlay;
 
   graphic = GetGraphic ();
@@ -19,74 +17,102 @@
     SetSectionSizes (section);
   }
-  image   = section->image;
+  image = section->image;
 
-  ALLOCATE (buffer, char, 65536);  /* space for 512 lines of 128 bytes */
-  bzero (buffer, 65536);
+  KiiScanMessage (sock, "%d %d %d %d", &overnum, &Noverlay, &Ntext, &Ntextdata);
 
-  KiiScanCommand (sock, 16, "%*s %d", &N);
-  Nstart = image[0].overlay[N].Nobjects;
+  // XXX need to validate overnum 
+  if ((overnum < 0) || (overnum >= NOVERLAYS)) overnum = 0;
 
-  while (1) {
-    KiiScanCommand (sock, 16, "%s %d", word, &Nin);
-    if (!strcmp (word, "DONE")) break;
-    if (strcmp (word, "NLINES")) abort();
+  // read the overlay data as binary 
+  Ntotal = 0;
+  Nbytes = Noverlay*sizeof(KiiOverlayBase);
+  fcntl (sock, F_SETFL, O_NONBLOCK);  
+  ALLOCATE (overlay, KiiOverlayBase, Noverlay);
+  buffer = (char *) overlay;
+  while (Nbytes > 0) { 
+    Nread = read (sock, &buffer[Ntotal], Nbytes);
+    // fprintf (stderr, "read: %d of %d remaining, %d so far, %d expected\n", Nread, Nbytes, Ntotal, Noverlay*sizeof(KiiOverlayBase));
+    if (Nread == 0) {  /* No more pipe */
+      fprintf (stderr, "error: pipe closed\n");
+      free (overlay);
+      fcntl (sock, F_SETFL, !O_NONBLOCK);  
+      return (FALSE);
+    }
+    if (Nread != -1) { /* pipe has data */
+      Nbytes -= Nread;
+      Ntotal += Nread;
+    }
+  }
+  fcntl (sock, F_SETFL, !O_NONBLOCK);  
+  KiiSendCommand (sock,  4, "DONE");
 
-    buff = buffer;
-    bytes = 128*Nin;
+  // read the textdata as binary
+  Ntotal = 0;
+  Nbytes = Ntextdata;
+  fcntl (sock, F_SETFL, O_NONBLOCK);  
+  ALLOCATE (textdata, char, Ntextdata);
+  while (Nbytes > 0) { 
+    Nread = read (sock, &textdata[Ntotal], Nbytes);
+    if (Nread == 0) {  /* No more pipe */
+      fprintf (stderr, "error: pipe closed\n");
+      free (textdata);
+      free (overlay);
+      fcntl (sock, F_SETFL, !O_NONBLOCK);  
+      return (FALSE);
+    }
+    if (Nread != -1) { /* pipe has data */
+      Nbytes -= Nread;
+      Ntotal += Nread;
+    }
+  }
+  fcntl (sock, F_SETFL, !O_NONBLOCK);  
+  KiiSendCommand (sock,  4, "DONE");
 
-    /* accept data from the socket until we have all of the bytes */
-    fcntl (sock, F_SETFL, O_NONBLOCK);  
-    while (bytes > 0) { 
-      status = read (sock, buff, bytes);
-      if (status == 0) {  /* No more pipe */
-	fprintf (stderr, "error: pipe closed\n");
-	free (buffer);
-	fcntl (sock, F_SETFL, !O_NONBLOCK);  
-	return (FALSE);
-      }
-      if (status != -1) { /* pipe has data */
-	bytes -= status;
-	buff = (char *)(buff + status);
-      }
-    }
-    fcntl (sock, F_SETFL, !O_NONBLOCK);  
+  // add new overlay objects to existing data
+  Nobjects = image[0].overlay[overnum].Nobjects + Noverlay;
+  REALLOCATE (image[0].overlay[overnum].objects, KiiOverlay, Nobjects);
 
-    /* parse buffer data */
-    NOBJECTS = image[0].overlay[N].Nobjects + Nin;
-    Nobjects = image[0].overlay[N].Nobjects;
-    REALLOCATE (image[0].overlay[N].objects, Object, NOBJECTS);
-    for (i = 0; i < Nin; i++) {
-      sscanf (&buffer[i*128], "%s %lf %lf %lf %lf\n", type, &x, &y, &dx, &dy);
-
-      if (strcasecmp (type, "TEXT") && strcasecmp (type, "LINE") && strcasecmp (type, "BOX") && strcasecmp (type, "CIRCLE")) {  /* skip */
-	fprintf (stderr, "don't know %s, skipping\n", type);
-	continue;
-      }
-
-      if (!strcasecmp (type, "TEXT")) { /* end of objects */
-	sscanf (&buffer[i*128], "%s %lf %lf %s\n", type, &x, &y, string);
-      }
-	
-      strcpy (image[0].overlay[N].objects[Nobjects].type, type);
-      image[0].overlay[N].objects[Nobjects].x = x;
-      image[0].overlay[N].objects[Nobjects].y = y;
-      if (!strcmp (type, "TEXT")) {
-	image[0].overlay[N].objects[Nobjects].dx = 0;
-	image[0].overlay[N].objects[Nobjects].dy = 0;
-	image[0].overlay[N].objects[Nobjects].text = strcreate (string);
-      } else {
-	image[0].overlay[N].objects[Nobjects].dx = dx;
-	image[0].overlay[N].objects[Nobjects].dy = dy;
-      }
-      Nobjects++;
-    }
-    REALLOCATE (image[0].overlay[N].objects, Object, MAX(Nobjects, 1));
-    image[0].overlay[N].Nobjects = Nobjects;
+  j = image[0].overlay[overnum].Nobjects;
+  for (i = 0; i < Noverlay; i++, j++) {
+    image[0].overlay[overnum].objects[j].x = overlay[i].x;
+    image[0].overlay[overnum].objects[j].y = overlay[i].y;
+    image[0].overlay[overnum].objects[j].dx = overlay[i].dx;
+    image[0].overlay[overnum].objects[j].dy = overlay[i].dy;
+    image[0].overlay[overnum].objects[j].type = overlay[i].type;
+    image[0].overlay[overnum].objects[j].text = NULL;
   }
 
-  /* cleanup */
-  free (buffer);
-  REALLOCATE (image[0].overlay[N].objects, Object, MAX (1, image[0].overlay[N].Nobjects));
-  image[0].overlay[N].active = TRUE;
+  // parse the text data : text lines are separated by '\n', one per text entry
+  p = textdata;
+  Nfound = 0;
+  for (i = 0; i < Noverlay; i++) {
+    if (overlay[i].type != KII_OVERLAY_TEXT) continue;
+    if (Nfound >= Ntext) {
+      fprintf (stderr, "inconsistent number of text lines\n");
+      break;
+    }
+    if (! *p) {
+      fprintf (stderr, "inconsistent number of text lines\n");
+      break;
+    }
+    q = strchr (p, '\n');
+    if (q == NULL) {
+      fprintf (stderr, "inconsistent text line\n");
+      break;
+    }
+    j = image[0].overlay[overnum].Nobjects + i;
+    image[0].overlay[overnum].objects[j].text = strncreate (p, q-p);
+    p = q + 1;
+    Nfound ++;
+  }
+  if (Nfound != Ntext) {
+    fprintf (stderr, "read %d text lines, expected %d\n", Nfound, Ntext);
+  }
+
+  free (textdata);
+  free (overlay);
+
+  image[0].overlay[overnum].Nobjects = Nobjects;
+  image[0].overlay[overnum].active = TRUE;
 
   if (USE_XWINDOW) {
@@ -96,5 +122,4 @@
       }
     }
-    PaintTickmarks (graphic, image);
     XFlush (graphic[0].display);
   }
Index: /branches/kapa-mods-2007-05/Ohana/src/kapa2/src/LoadTickmarks.c
===================================================================
--- /branches/kapa-mods-2007-05/Ohana/src/kapa2/src/LoadTickmarks.c	(revision 13431)
+++ /branches/kapa-mods-2007-05/Ohana/src/kapa2/src/LoadTickmarks.c	(revision 13432)
@@ -18,5 +18,5 @@
   Nobjects = image[0].tickmarks.Nobjects;
   NOBJECTS = Nobjects + 100;
-  REALLOCATE (image[0].tickmarks.objects, Object, NOBJECTS);
+  REALLOCATE (image[0].tickmarks.objects, KiiOverlay, NOBJECTS);
   
   done = FALSE;
@@ -54,10 +54,10 @@
     if (Nobjects >= NOBJECTS) {
       NOBJECTS = Nobjects + 100;
-      REALLOCATE (image[0].tickmarks.objects, Object, NOBJECTS);
+      REALLOCATE (image[0].tickmarks.objects, KiiOverlay, NOBJECTS);
     }
 
   }
 
-  REALLOCATE (image[0].tickmarks.objects, Object, MAX(Nobjects, 1));
+  REALLOCATE (image[0].tickmarks.objects, KiiOverlay, MAX(Nobjects, 1));
   image[0].tickmarks.Nobjects = Nobjects;
 
Index: /branches/kapa-mods-2007-05/Ohana/src/kapa2/src/PSOverlay.c
===================================================================
--- /branches/kapa-mods-2007-05/Ohana/src/kapa2/src/PSOverlay.c	(revision 13431)
+++ /branches/kapa-mods-2007-05/Ohana/src/kapa2/src/PSOverlay.c	(revision 13432)
@@ -31,38 +31,37 @@
     dY = (image[0].overlay[N].objects[i].dy)/expand;
     
-    if (!strcmp (image[0].overlay[N].objects[i].type, "LINE")) {
-      if (((X < Xmin) && (X + dX < Xmin)) || ((X > Xmax) && (X + dX > Xmax)) ||
-	  ((Y < Ymin) && (Y + dY < Ymin)) || ((Y > Ymax) && (Y + dY > Ymax))) {
-	continue;
-      }
-      fprintf (f, " %6.1f %6.1f %6.1f %6.1f L\n", X + extra, Y + extra, (X+dX + extra), (Y-dY + extra));
-      continue;
+    switch (image[0].overlay[N].objects[i].type) {
+      case KII_OVERLAY_LINE:
+	if (((X < Xmin) && (X + dX < Xmin)) || ((X > Xmax) && (X + dX > Xmax)) ||
+	    ((Y < Ymin) && (Y + dY < Ymin)) || ((Y > Ymax) && (Y + dY > Ymax))) {
+	  break;
+	}
+	fprintf (f, " %6.1f %6.1f %6.1f %6.1f L\n", X + extra, Y + extra, (X+dX + extra), (Y-dY + extra));
+	break;
+      case KII_OVERLAY_TEXT:
+	if (((X < Xmin) && (X + dX < Xmin)) || ((X > Xmax) && (X + dX > Xmax)) ||
+	    ((Y < Ymin) && (Y + dY < Ymin)) || ((Y > Ymax) && (Y + dY > Ymax))) {
+	  break;
+	}
+	fprintf (f, "(%s) %6.1f %6.1f T\n", image[0].overlay[N].objects[i].text, X + extra, Y + extra); 
+	break;
+      case KII_OVERLAY_BOX:
+	if (((X - 0.5*dX < Xmin) && (X + 0.5*dX < Xmin)) || ((X - 0.5*dX > Xmax) && (X + 0.5*dX > Xmax)) ||
+	    ((Y - 0.5*dY < Ymin) && (Y + 0.5*dY < Ymin)) || ((Y - 0.5*dY > Ymax) && (Y + 0.5*dY > Ymax))) {
+	  break;
+	}
+	fprintf (f, " %6.1f %6.1f %6.1f %6.1f B\n", (dX + 2*extra), (dY + 2*extra), (X - 0.5*dX - extra), (Y - 0.5*dY - extra));
+	break;
+      case KII_OVERLAY_CIRCLE:
+	if (((X - dX < Xmin) && (X + dX < Xmin)) || ((X - dX > Xmax) && (X + dX > Xmax)) ||
+	    ((Y - dY < Ymin) && (Y + dY < Ymin)) || ((Y - dY > Ymax) && (Y + dY > Ymax))) {
+	  break;
+	}
+	fprintf (f, " %6.1f %6.1f %6.1f C\n", X, Y, fabs(dX + extra));
+	break;
+      default:
+	fprintf (stderr, "skipping unknown object\n");
+	break;
     }
-    if (!strcmp (image[0].overlay[N].objects[i].type, "TEXT")) {
-      if (((X < Xmin) && (X + dX < Xmin)) || ((X > Xmax) && (X + dX > Xmax)) ||
-	  ((Y < Ymin) && (Y + dY < Ymin)) || ((Y > Ymax) && (Y + dY > Ymax))) {
-	continue;
-      }
-      fprintf (f, "(%s) %6.1f %6.1f T\n", image[0].overlay[N].objects[i].text, X + extra, Y + extra); 
-      continue;
-    }
-    if (!strcmp (image[0].overlay[N].objects[i].type, "BOX")) {
-      if (((X - 0.5*dX < Xmin) && (X + 0.5*dX < Xmin)) || ((X - 0.5*dX > Xmax) && (X + 0.5*dX > Xmax)) ||
-	  ((Y - 0.5*dY < Ymin) && (Y + 0.5*dY < Ymin)) || ((Y - 0.5*dY > Ymax) && (Y + 0.5*dY > Ymax))) {
-	continue;
-      }
-      fprintf (f, " %6.1f %6.1f %6.1f %6.1f B\n", (dX + 2*extra), (dY + 2*extra), (X - 0.5*dX - extra), (Y - 0.5*dY - extra));
-      continue;
-    }
-    if (!strcmp (image[0].overlay[N].objects[i].type, "CIRCLE")) {
-      if (((X - dX < Xmin) && (X + dX < Xmin)) || ((X - dX > Xmax) && (X + dX > Xmax)) ||
-	  ((Y - dY < Ymin) && (Y + dY < Ymin)) || ((Y - dY > Ymax) && (Y + dY > Ymax))) {
-	continue;
-      }
-      fprintf (f, " %6.1f %6.1f %6.1f C\n", X, Y, fabs(dX + extra));
-      continue;
-    }
-    fprintf (stderr, "don't know %s, skipping\n", image[0].overlay[N].objects[i].type);
   }
-  
 }
Index: /branches/kapa-mods-2007-05/Ohana/src/kapa2/src/PaintOverlay.c
===================================================================
--- /branches/kapa-mods-2007-05/Ohana/src/kapa2/src/PaintOverlay.c	(revision 13431)
+++ /branches/kapa-mods-2007-05/Ohana/src/kapa2/src/PaintOverlay.c	(revision 13432)
@@ -41,25 +41,25 @@
        for a BOX (x, y) is the center, (dx, dy) is the width */
 
-    if (!strcasecmp (image[0].overlay[N].objects[i].type, "LINE")) {
-      XDrawLine (graphic[0].display, graphic[0].window, graphic[0].gc, X, Y, (X+dX), (Y+dY));
-      continue;
+    switch (image[0].overlay[N].objects[i].type) {
+      case KII_OVERLAY_LINE:
+	XDrawLine (graphic[0].display, graphic[0].window, graphic[0].gc, X, Y, (X+dX), (Y+dY));
+	break;
+      case KII_OVERLAY_TEXT:
+	XDrawString (graphic[0].display, graphic[0].window, graphic[0].gc, X, Y, image[0].overlay[N].objects[i].text, strlen(image[0].overlay[N].objects[i].text));
+	break;
+      case KII_OVERLAY_BOX:
+	dx = MAX (abs(dX),2) / 2;
+	dy = MAX (abs(dY),2) / 2;
+	XDrawRectangle (graphic[0].display, graphic[0].window, graphic[0].gc, (X - dx), (Y - dy), 2*dx, 2*dy);
+	break;
+      case KII_OVERLAY_CIRCLE:
+	dx = MAX (abs(dX),2);
+	dy = MAX (abs(dY),2);
+	XDrawArc (graphic[0].display, graphic[0].window, graphic[0].gc, (X - dx), (Y - dy), 2*dx, 2*dy, 0, 23040);
+	break;
+      default:
+	fprintf (stderr, "skipping unknown object\n");
+	break;
     }
-    if (!strcasecmp (image[0].overlay[N].objects[i].type, "TEXT")) {
-      XDrawString (graphic[0].display, graphic[0].window, graphic[0].gc, X, Y, image[0].overlay[N].objects[i].text, strlen(image[0].overlay[N].objects[i].text));
-      continue;
-    }
-    if (!strcasecmp (image[0].overlay[N].objects[i].type, "BOX")) {
-      dx = MAX (abs(dX),2) / 2;
-      dy = MAX (abs(dY),2) / 2;
-      XDrawRectangle (graphic[0].display, graphic[0].window, graphic[0].gc, (X - dx), (Y - dy), 2*dx, 2*dy);
-       continue;
-    }
-    if (!strcasecmp (image[0].overlay[N].objects[i].type, "CIRCLE")) {
-      dx = MAX (abs(dX),2);
-      dy = MAX (abs(dY),2);
-      XDrawArc (graphic[0].display, graphic[0].window, graphic[0].gc, (X - dx), (Y - dy), 2*dx, 2*dy, 0, 23040);
-      continue;
-    }
-    fprintf (stderr, "don't know %s, skipping (PO)\n", image[0].overlay[N].objects[i].type);
   }
   
Index: /branches/kapa-mods-2007-05/Ohana/src/kapa2/src/PaintTickmarks.c
===================================================================
--- /branches/kapa-mods-2007-05/Ohana/src/kapa2/src/PaintTickmarks.c	(revision 13431)
+++ /branches/kapa-mods-2007-05/Ohana/src/kapa2/src/PaintTickmarks.c	(revision 13432)
@@ -22,35 +22,33 @@
     dY = image[0].tickmarks.objects[i].dy * Yrange;
 
-    if (!strcmp (image[0].tickmarks.objects[i].type, "LINE")) {
-      XDrawLine (graphic[0].display, graphic[0].window, graphic[0].gc, X, Y, (X+dX), (Y+dY));
-      continue;
+    switch (image[0].overlay[0].objects[i].type) {
+      case KII_OVERLAY_LINE:
+	XDrawLine (graphic[0].display, graphic[0].window, graphic[0].gc, X, Y, (X+dX), (Y+dY));
+	break;
+      case KII_OVERLAY_TEXT:
+	if (image[0].tickmarks.objects[i].dy == 0) {
+	    XSetForeground (graphic[0].display, graphic[0].gc, graphic[0].back);
+	    XFillRectangle (graphic[0].display, graphic[0].window, graphic[0].gc, X, Y-11, 6*strlen(image[0].tickmarks.objects[i].text), 11); 
+	    XSetForeground (graphic[0].display, graphic[0].gc, graphic[0].fore);
+	    XDrawString (graphic[0].display, graphic[0].window, graphic[0].gc, X, Y, image[0].tickmarks.objects[i].text, strlen(image[0].tickmarks.objects[i].text));
+	}
+	if (image[0].tickmarks.objects[i].dy == 90) {
+	    XSetForeground (graphic[0].display, graphic[0].gc, graphic[0].back);
+	    XFillRectangle (graphic[0].display, graphic[0].window, graphic[0].gc, X, Y-6*strlen(image[0].tickmarks.objects[i].text), 11, 6*strlen(image[0].tickmarks.objects[i].text)); 
+	    XSetForeground (graphic[0].display, graphic[0].gc, graphic[0].fore);
+	    /* XDrawRotString (graphic[0].display, graphic[0].window, graphic[0].gc, X, Y, image[0].tickmarks.objects[i].text, strlen(image[0].tickmarks.objects[i].text)); */
+	}
+	break;
+      case KII_OVERLAY_BOX:
+	XDrawRectangle (graphic[0].display, graphic[0].window, graphic[0].gc, (int)(X - 0.5*dX), (int)(Y - 0.5*dY), abs(dX), abs(dY));
+	break;
+      case KII_OVERLAY_CIRCLE:
+	XDrawArc (graphic[0].display, graphic[0].window, graphic[0].gc, X - dX, Y - dY, abs(2*dX), abs(2*dY), 0, 23040);
+	break;
+      default:
+	fprintf (stderr, "skipping unknown object\n");
+	break;
     }
-    if (!strcmp (image[0].tickmarks.objects[i].type, "TEXT")) {
-      if (image[0].tickmarks.objects[i].dy == 0) {
-	XSetForeground (graphic[0].display, graphic[0].gc, graphic[0].back);
-	XFillRectangle (graphic[0].display, graphic[0].window, graphic[0].gc, X, Y-11, 6*strlen(image[0].tickmarks.objects[i].text), 11); 
-	XSetForeground (graphic[0].display, graphic[0].gc, graphic[0].fore);
-	XDrawString (graphic[0].display, graphic[0].window, graphic[0].gc, X, Y, image[0].tickmarks.objects[i].text, strlen(image[0].tickmarks.objects[i].text));
-      }
-      if (image[0].tickmarks.objects[i].dy == 90) {
-	XSetForeground (graphic[0].display, graphic[0].gc, graphic[0].back);
-	XFillRectangle (graphic[0].display, graphic[0].window, graphic[0].gc, X, Y-6*strlen(image[0].tickmarks.objects[i].text), 11, 6*strlen(image[0].tickmarks.objects[i].text)); 
-	XSetForeground (graphic[0].display, graphic[0].gc, graphic[0].fore);
-	/* XDrawRotString (graphic[0].display, graphic[0].window, graphic[0].gc, X, Y, image[0].tickmarks.objects[i].text, strlen(image[0].tickmarks.objects[i].text)); */
-      }
-      continue;
-    }
-    if (!strcmp (image[0].tickmarks.objects[i].type, "BOX")) {
-      XDrawRectangle (graphic[0].display, graphic[0].window, graphic[0].gc, (int)(X - 0.5*dX), (int)(Y - 0.5*dY), abs(dX), abs(dY));
-       continue;
-    }
-    if (!strcmp (image[0].tickmarks.objects[i].type, "CIRCLE")) {
-      XDrawArc (graphic[0].display, graphic[0].window, graphic[0].gc, X - dX, Y - dY, abs(2*dX), abs(2*dY), 0, 23040);
-      continue;
-    }
-    fprintf (stderr, "don't know %s, skipping (PO)\n", image[0].tickmarks.objects[i].type);
   }
-  
   XSetForeground (graphic[0].display, graphic[0].gc, graphic[0].fore);
-
 }
Index: /branches/kapa-mods-2007-05/Ohana/src/kapa2/src/SaveOverlay.c
===================================================================
--- /branches/kapa-mods-2007-05/Ohana/src/kapa2/src/SaveOverlay.c	(revision 13431)
+++ /branches/kapa-mods-2007-05/Ohana/src/kapa2/src/SaveOverlay.c	(revision 13432)
@@ -4,5 +4,5 @@
 
   int i, N;
-  char filename[256];
+  char filename[256], *type;
   FILE *f;
   Section *section;
@@ -22,6 +22,8 @@
 
   for (i = 0; i < image[0].overlay[N].Nobjects; i++) {
+    type = KiiOverlayTypeByNumber (image[0].overlay[N].objects[i].type);
+    if (type == NULL) continue;
     fprintf (f, "%s %lf %lf %lf %lf\n", 
-	     image[0].overlay[N].objects[i].type,
+	     type,
 	     image[0].overlay[N].objects[i].x,
 	     image[0].overlay[N].objects[i].y,
@@ -32,2 +34,6 @@
   return (TRUE);
 }
+
+/* this is asymmetric with LoadOverlay.c.  In that case, the client reads the file and sends
+ * the overlay objects to kapa.  In this case, kapa writes the file directly... 
+ */
Index: /branches/kapa-mods-2007-05/Ohana/src/kapa2/src/Sections.c
===================================================================
--- /branches/kapa-mods-2007-05/Ohana/src/kapa2/src/Sections.c	(revision 13431)
+++ /branches/kapa-mods-2007-05/Ohana/src/kapa2/src/Sections.c	(revision 13432)
@@ -176,5 +176,5 @@
       tmpSection = sections[N];
       sections[N] = sections[N+1];
-      sections[N] = tmpSection;
+      sections[N+1] = tmpSection;
       Refresh (1);
       return (TRUE);
@@ -186,5 +186,5 @@
       tmpSection = sections[N];
       sections[N] = sections[N-1];
-      sections[N] = tmpSection;
+      sections[N-1] = tmpSection;
       Refresh (1);
       return (TRUE);
Index: /branches/kapa-mods-2007-05/Ohana/src/kapa2/src/SetGraphStyle.c
===================================================================
--- /branches/kapa-mods-2007-05/Ohana/src/kapa2/src/SetGraphStyle.c	(revision 13432)
+++ /branches/kapa-mods-2007-05/Ohana/src/kapa2/src/SetGraphStyle.c	(revision 13432)
@@ -0,0 +1,84 @@
+# include "Ximage.h"
+
+int SetGraphStyle (int sock) {
+  
+  int i;
+  double xmin, xmax, ymin, ymax;
+  Graphic *graphic;
+  Section *section;
+  KapaGraphWidget *graph;
+
+  graphic = GetGraphic();
+
+  section = GetActiveSection();
+  if (section->graph == NULL) {
+    section->graph = InitGraph ();
+    SetSectionSizes (section);
+  }
+  graph = section->graph;
+  
+  // get graph style from client 
+  KiiScanMessage (sock, "%d %d %d %d %d %d %lf %lf", 
+		  &graph[0].style.style, 
+		  &graph[0].style.ptype, 
+		  &graph[0].style.ltype, 
+		  &graph[0].style.etype, 
+		  &graph[0].style.ebar, 
+		  &graph[0].style.color, 
+		  &graph[0].style.lweight, 
+		  &graph[0].style.size);
+
+  KiiScanMessage (sock, "%lf %lf %lf %lf", 
+		  &graph[0].style.xmin, 
+		  &graph[0].style.xmax, 
+		  &graph[0].style.ymin, 
+		  &graph[0].style.ymax);
+
+  xmin = graph[0].style.xmin;
+  xmax = graph[0].style.xmax;
+  ymin = graph[0].style.ymin;
+  ymax = graph[0].style.ymax;
+
+  // XXX there are now two things which track the graph limits
+  // make sure these are kept in sync (or drop one!)
+  graph[0].axis[2].min = graph[0].axis[0].min = xmin;
+  graph[0].axis[2].max = graph[0].axis[0].max = xmax;
+  graph[0].axis[3].min = graph[0].axis[1].min = ymin; 
+  graph[0].axis[3].max = graph[0].axis[1].max = ymax;
+  
+  for (i = 0; i < graph[0].Nobjects; i++) {
+    graph[0].objects[i].x0 = xmin;
+    graph[0].objects[i].x1 = xmax;
+    graph[0].objects[i].y0 = ymin;
+    graph[0].objects[i].y1 = ymax;
+  }
+
+  if (USE_XWINDOW) XClearWindow (graphic->display, graphic->window);
+  Refresh (1);
+
+  return (TRUE);  
+}
+
+int GetGraphStyle (int sock) {
+  
+  Section *section;
+  KapaGraphWidget *graph;
+
+  section = GetActiveSection();
+  if (section->graph == NULL) {
+    section->graph = InitGraph ();
+    SetSectionSizes (section);
+  }
+  graph = section->graph;
+
+  KiiSendMessage (sock, "%8d %d %d %d %d %d %f %f", 
+		  graph[0].style.style, 
+		  graph[0].style.ptype, graph[0].style.ltype, 
+		  graph[0].style.etype, graph[0].style.ebar, graph[0].style.color, 
+		  graph[0].style.lweight, graph[0].style.size);
+  KiiSendMessage (sock, "%g %g %g %g", 
+		  graph[0].style.xmin, graph[0].style.xmax, 
+		  graph[0].style.ymin, graph[0].style.ymax);
+
+  return (TRUE);
+}
Index: /branches/kapa-mods-2007-05/Ohana/src/kapa2/src/SetImageSize.c
===================================================================
--- /branches/kapa-mods-2007-05/Ohana/src/kapa2/src/SetImageSize.c	(revision 13431)
+++ /branches/kapa-mods-2007-05/Ohana/src/kapa2/src/SetImageSize.c	(revision 13432)
@@ -25,7 +25,4 @@
   dX = graphic[0].dx * section[0].dx;
   dY = graphic[0].dy * section[0].dy;
-
-  // XXX make this user-setable
-  image[0].location = 0;
 
   switch (image[0].location) {
Index: /branches/kapa-mods-2007-05/Ohana/src/kapa2/src/SetToolbox.c
===================================================================
--- /branches/kapa-mods-2007-05/Ohana/src/kapa2/src/SetToolbox.c	(revision 13432)
+++ /branches/kapa-mods-2007-05/Ohana/src/kapa2/src/SetToolbox.c	(revision 13432)
@@ -0,0 +1,33 @@
+# include "Ximage.h"
+
+// set the position of the image toolbox
+void SetToolbox (int sock) {
+
+  int location;
+  Section *section;
+  Graphic *graphic;
+
+  KiiScanMessage (sock, "%d", &location);
+  if ((location < 0) || (location > 4)) {
+    fprintf (stderr, "invalid toolbox location %d\n", location);
+    return;
+  }
+
+  graphic = GetGraphic ();
+  section = GetActiveSection();
+  if (section->image == NULL) { 
+    section->image = InitImage ();
+  }
+  section->image->location = location;
+  SetSectionSizes (section);
+
+  if (!USE_XWINDOW) return;
+
+  Remap (graphic, section->image, &section->image->matrix);
+  if (DEBUG) fprintf (stderr, "remapped image\n");
+  Refresh ();
+  if (DEBUG) fprintf (stderr, "refreshed\n");
+  XFlush (graphic->display);
+
+  return;
+}
Index: /branches/kapa-mods-2007-05/Ohana/src/kapa2/src/bDrawOverlay.c
===================================================================
--- /branches/kapa-mods-2007-05/Ohana/src/kapa2/src/bDrawOverlay.c	(revision 13431)
+++ /branches/kapa-mods-2007-05/Ohana/src/kapa2/src/bDrawOverlay.c	(revision 13432)
@@ -24,8 +24,8 @@
   }
   /* 
-  X = 0.5*image[0].matrix.Naxis[0] - expand*((int)(0.5*image[0].picture.dx + 0.5) - 0.0) - image[0].X;
-  Y = 0.5*image[0].matrix.Naxis[1] - expand*((int)(0.5*image[0].picture.dy + 0.5) - 0.0) - image[0].Y;  
-  X0 =  (image[0].X + 1 - (int)(0.5*image[0].matrix.Naxis[0] + 0.5) - X + (int)X)/expand + image[0].picture.x + 0.5*image[0].picture.dx;
-  Y0 =  (image[0].Y + 1 - (int)(0.5*image[0].matrix.Naxis[1] + 0.5) - Y + (int)Y)/expand + image[0].picture.y + 0.5*image[0].picture.dy;
+     X = 0.5*image[0].matrix.Naxis[0] - expand*((int)(0.5*image[0].picture.dx + 0.5) - 0.0) - image[0].X;
+     Y = 0.5*image[0].matrix.Naxis[1] - expand*((int)(0.5*image[0].picture.dy + 0.5) - 0.0) - image[0].Y;  
+     X0 =  (image[0].X + 1 - (int)(0.5*image[0].matrix.Naxis[0] + 0.5) - X + (int)X)/expand + image[0].picture.x + 0.5*image[0].picture.dx;
+     Y0 =  (image[0].Y + 1 - (int)(0.5*image[0].matrix.Naxis[1] + 0.5) - Y + (int)Y)/expand + image[0].picture.y + 0.5*image[0].picture.dy;
   */
 
@@ -62,26 +62,26 @@
        for a BOX (x, y) is the center, (dx, dy) is the width */
 
-    if (!strcasecmp (image[0].overlay[N].objects[i].type, "LINE")) {
-      bDrawLine (X, Y, (X+dX), (Y+dY));
-      continue;
+    switch (image[0].overlay[N].objects[i].type) {
+      case KII_OVERLAY_LINE:
+	bDrawLine (X, Y, (X+dX), (Y+dY));
+	break;
+      case KII_OVERLAY_TEXT:
+	bDrawRotText (X, Y, image[0].overlay[N].objects[i].text, 8, 0.0);
+	break;
+      case KII_OVERLAY_BOX:
+	dx = MAX (abs(dX),2) / 2;
+	dy = MAX (abs(dY),2) / 2;
+	bDrawRectOpen ((X-dx), (Y-dy), (X+dx), (Y+dy));
+	// bDrawRectOpen ((X-dx), (Y-dy), (X), (Y));
+	break;
+      case KII_OVERLAY_CIRCLE:
+	dx = MAX (abs(dX),2);
+	dy = MAX (abs(dY),2);
+	bDrawArc (X, Y, dx, dy, 0, 360);
+	break;
+      default:
+	fprintf (stderr, "skipping unknown object\n");
+	break;
     }
-    if (!strcasecmp (image[0].overlay[N].objects[i].type, "TEXT")) {
-      bDrawRotText (X, Y, image[0].overlay[N].objects[i].text, 8, 0.0);
-      continue;
-    }
-    if (!strcasecmp (image[0].overlay[N].objects[i].type, "BOX")) {
-      dx = MAX (abs(dX),2) / 2;
-      dy = MAX (abs(dY),2) / 2;
-      bDrawRectOpen ((X-dx), (Y-dy), (X+dx), (Y+dy));
-      // bDrawRectOpen ((X-dx), (Y-dy), (X), (Y));
-       continue;
-    }
-    if (!strcasecmp (image[0].overlay[N].objects[i].type, "CIRCLE")) {
-      dx = MAX (abs(dX),2);
-      dy = MAX (abs(dY),2);
-      bDrawArc (X, Y, dx, dy, 0, 360);
-      continue;
-    }
-    fprintf (stderr, "don't know %s, skipping (PO)\n", image[0].overlay[N].objects[i].type);
   }
   
Index: /branches/kapa-mods-2007-05/Ohana/src/libkapa/include/kapa.h
===================================================================
--- /branches/kapa-mods-2007-05/Ohana/src/libkapa/include/kapa.h	(revision 13431)
+++ /branches/kapa-mods-2007-05/Ohana/src/libkapa/include/kapa.h	(revision 13432)
@@ -29,4 +29,12 @@
   int logflux;
 } KiiDisplayMode;
+
+typedef struct {
+  float x;
+  float y;
+  float dx;
+  float dy;
+  int type;
+} KiiOverlayBase;
 
 typedef struct {
@@ -156,4 +164,6 @@
 int KapaGetSection (int fd, char *name);
 int KapaMoveSection (int fd, char *name, char *direction);
+int KapaSetGraphStyle (int fd, Graphdata *graphmode);
+int KapaGetGraphStyle (int fd, Graphdata *graphmode);
 
 /* KapaColors */
Index: /branches/kapa-mods-2007-05/Ohana/src/libkapa/src/KapaWindow.c
===================================================================
--- /branches/kapa-mods-2007-05/Ohana/src/libkapa/src/KapaWindow.c	(revision 13431)
+++ /branches/kapa-mods-2007-05/Ohana/src/libkapa/src/KapaWindow.c	(revision 13432)
@@ -53,4 +53,12 @@
   
   KiiSendCommand (fd, 4, "ERSI");
+  KiiWaitAnswer (fd, "DONE");
+  return (TRUE);
+}
+
+int KapaSetToolbox (int fd, int location) {
+  
+  KiiSendCommand (fd, 4, "TOOL");
+  KiiSendMessage (fd, "%d", location); 
   KiiWaitAnswer (fd, "DONE");
   return (TRUE);
@@ -101,7 +109,50 @@
 }
 
+int KapaSetGraphStyle (int fd, Graphdata *graphmode) {
+
+  /* tell kapa to look for the incoming image */
+  KiiSendCommand (fd, 4, "SSTY"); 
+  
+  /* send Xgraph the plot details */
+  KiiSendMessage (fd, "%8d %d %d %d %d %d %f %f", 
+		  graphmode[0].style, 
+		  graphmode[0].ptype, graphmode[0].ltype, 
+		  graphmode[0].etype, graphmode[0].ebar, graphmode[0].color, 
+		  graphmode[0].lweight, graphmode[0].size);
+  KiiSendMessage (fd, "%g %g %g %g", 
+		  graphmode[0].xmin, graphmode[0].xmax, 
+		  graphmode[0].ymin, graphmode[0].ymax);
+  KiiWaitAnswer (fd, "DONE");
+  return (TRUE);
+}
+
+int KapaGetGraphStyle (int fd, Graphdata *graphmode) {
+
+  /* tell kapa to look for the incoming image */
+  KiiSendCommand (fd, 4, "GSTY"); 
+  
+  /* send Xgraph the plot details */
+  KiiScanMessage (fd, "%d %d %d %d %d %d %lf %lf", 
+		  &graphmode[0].style, 
+		  &graphmode[0].ptype, &graphmode[0].ltype, 
+		  &graphmode[0].etype, &graphmode[0].ebar, &graphmode[0].color, 
+		  &graphmode[0].lweight, &graphmode[0].size);
+  KiiScanMessage (fd, "%lf %lf %lf %lf", 
+		  &graphmode[0].xmin, &graphmode[0].xmax, 
+		  &graphmode[0].ymin, &graphmode[0].ymax);
+  KiiWaitAnswer (fd, "DONE");
+  return (TRUE);
+}
+
 int KapaPlotVector (int fd, int Npts, float *values, char *type) {
 
   int Nbytes;
+  int swap;
+
+# ifdef BYTE_SWAP
+  swap = 1;
+# else
+  swap = 0;
+# endif
 
   Nbytes = Npts * sizeof (float);
@@ -118,6 +169,5 @@
 valid:
   KiiSendCommand (fd, 4, "PLOB"); 
-  KiiSendMessage (fd, "%s %d %d", type, Npts, Nbytes); 
-  // XXX send the byte-swap as well...
+  KiiSendMessage (fd, "%s %d %d %d", type, Npts, Nbytes, swap); 
 
   write (fd, values, Nbytes);
@@ -164,5 +214,5 @@
 int KapaGetLimits (int fd, float *dx, float *dy) {
 
-  KiiSendCommand (fd, 4, "LIMS"); 
+  KiiSendCommand (fd, 4, "GLIM"); 
   KiiScanMessage (fd, "%lf %lf", dx, dy); 
   KiiWaitAnswer (fd, "DONE");
Index: /branches/kapa-mods-2007-05/Ohana/src/libkapa/src/KiiOverlay.c
===================================================================
--- /branches/kapa-mods-2007-05/Ohana/src/libkapa/src/KiiOverlay.c	(revision 13431)
+++ /branches/kapa-mods-2007-05/Ohana/src/libkapa/src/KiiOverlay.c	(revision 13432)
@@ -50,5 +50,5 @@
 }
 
-int KiiLoadOverlay (int fd, KiiOverlay *overlay, int Noverlay, char *overname) {
+int KiiLoadOverlayOld (int fd, KiiOverlay *overlay, int Noverlay, char *overname) {
 
   int i, n, Nline;
@@ -93,4 +93,55 @@
 }
 
+int KiiLoadOverlay (int fd, KiiOverlay *overlay, int Noverlay, char *overname) {
+
+  int i, overnum, Ntextdata, NTEXTDATA, Ntext, Nchar;
+  char *textdata;
+  KiiOverlayBase *buffer;
+
+  Ntext = 0;
+  KiiSelectOverlay (overname, &overnum);
+
+  Ntextdata = 0;
+  NTEXTDATA = 1024;
+  ALLOCATE (textdata, char, 1024);
+
+  // we send the position information as a binary block
+  ALLOCATE (buffer, KiiOverlayBase, Noverlay);
+  for (i = 0; i < Noverlay; i++) {
+    buffer[i].x    = overlay[i].x;
+    buffer[i].y    = overlay[i].y;
+    buffer[i].dx   = overlay[i].dx;
+    buffer[i].dy   = overlay[i].dy;
+    buffer[i].type = overlay[i].type;
+    if (buffer[i].type == KII_OVERLAY_TEXT) {
+      Ntext ++;
+      Nchar = strlen(overlay[i].text) + 1;
+      if (Ntextdata + Nchar >= NTEXTDATA) {
+	NTEXTDATA += 1024;
+	REALLOCATE (textdata, char, NTEXTDATA);
+      }
+      sprintf (&textdata[Ntextdata], "%s\n", overlay[i].text);
+      Ntextdata += Nchar;
+    }
+  }
+
+  KiiSendCommand (fd,  4, "LOAD");
+  KiiSendMessage (fd, "%d %d %d %d", overnum, Noverlay, Ntext, Ntextdata);
+
+  // we could break this into segments if we want to trap an interrupt, but why bother?
+  Nchar = write (fd, buffer, Noverlay*sizeof(KiiOverlayBase));
+  fprintf (stderr, "sent %d of %d bytes\n", Nchar, Noverlay*sizeof(KiiOverlayBase));
+  KiiWaitAnswer (fd, "DONE");
+
+  write (fd, textdata, Ntextdata);
+  KiiWaitAnswer (fd, "DONE");
+
+  free (buffer);
+  free (textdata);
+
+  KiiWaitAnswer (fd, "DONE");
+  return (TRUE);
+}
+
 int KiiEraseOverlay (int fd, char *overname) {
 
Index: /branches/kapa-mods-2007-05/Ohana/src/opihi/cmd.astro/cgrid.c
===================================================================
--- /branches/kapa-mods-2007-05/Ohana/src/opihi/cmd.astro/cgrid.c	(revision 13431)
+++ /branches/kapa-mods-2007-05/Ohana/src/opihi/cmd.astro/cgrid.c	(revision 13432)
@@ -14,8 +14,8 @@
   double x, y;
   Vector Xvec, Yvec;
-  int NorthPole, SouthPole, N, OnPic, LOnPic, status, NELEMENTS, First;
+  int kapa, NorthPole, SouthPole, N, OnPic, LOnPic, status, NELEMENTS, First;
   Graphdata graphmode;
 
-  if (!style_args (&graphmode, &argc, argv, NULL)) return FALSE;
+  if (!style_args (&graphmode, &argc, argv, &kapa)) return FALSE;
 
   if (argc != 1) {
@@ -23,5 +23,4 @@
     return (FALSE);
   }
-  SetGraph (graphmode);
 
   /* are we plotting one of the poles? */
@@ -392,7 +391,5 @@
   graphmode.ptype = 100; /* connect a pair */
   graphmode.etype = 0;
-  PrepPlotting (N, &graphmode);
-  PlotVector (N, Xvec.elements, "x");
-  PlotVector (N, Yvec.elements, "y");
+  PlotVectorPair (kapa, N, Xvec.elements, Yvec.elements, &graphmode);
 
   free (Xvec.elements);
Index: /branches/kapa-mods-2007-05/Ohana/src/opihi/cmd.astro/cplot.c
===================================================================
--- /branches/kapa-mods-2007-05/Ohana/src/opihi/cmd.astro/cplot.c	(revision 13431)
+++ /branches/kapa-mods-2007-05/Ohana/src/opihi/cmd.astro/cplot.c	(revision 13432)
@@ -3,10 +3,10 @@
 int cplot (int argc, char **argv) {
   
-  int i, Npts, status;
+  int i, kapa, Npts, status;
   float *x, *y, *r, *d, Rmin, Rmax;
   Vector Xvec, Yvec, *xvec, *yvec;
   Graphdata graphmode;
 
-  if (!style_args (&graphmode, &argc, argv, NULL)) return FALSE;
+  if (!style_args (&graphmode, &argc, argv, &kapa)) return FALSE;
 
   if (argc != 3) {
@@ -14,5 +14,4 @@
     return (FALSE);
   }
-  SetGraph (graphmode);
 
   Rmin = graphmode.coords.crval1 - 182.0;
@@ -67,7 +66,5 @@
 
   graphmode.etype = 0;
-  PrepPlotting (Npts, &graphmode);
-  PlotVector (Npts, Xvec.elements, "x");
-  PlotVector (Npts, Yvec.elements, "y");
+  PlotVectorPair (kapa, Npts, Xvec.elements, Yvec.elements, &graphmode);
   
   free (Xvec.elements);
Index: /branches/kapa-mods-2007-05/Ohana/src/opihi/cmd.astro/czplot.c
===================================================================
--- /branches/kapa-mods-2007-05/Ohana/src/opihi/cmd.astro/czplot.c	(revision 13431)
+++ /branches/kapa-mods-2007-05/Ohana/src/opihi/cmd.astro/czplot.c	(revision 13432)
@@ -3,5 +3,5 @@
 int czplot (int argc, char **argv) {
   
-  int i, Npts;
+  int i, kapa, Npts;
   double min, range, Rmin, Rmax;
   float *in, *out, *r, *d, *x, *y;
@@ -9,5 +9,5 @@
   Graphdata graphmode;
 
-  if (!style_args (&graphmode, &argc, argv, NULL)) return FALSE;
+  if (!style_args (&graphmode, &argc, argv, &kapa)) return FALSE;
 
   if (argc != 6) {
@@ -15,5 +15,4 @@
     return (FALSE);
   }
-  SetGraph (graphmode);
 
   min = atof(argv[4]);
@@ -59,9 +58,5 @@
   graphmode.etype = 0;
   Npts = Xvec.Nelements;
-  PrepPlotting (Npts, &graphmode);
-
-  PlotVector (Npts, Xvec.elements, "x");
-  PlotVector (Npts, Yvec.elements, "y");
-  PlotVector (Npts, Zvec.elements, "z");
+  PlotVectorTriplet (kapa, Npts, Xvec.elements, Yvec.elements, Zvec.elements, &graphmode);
 
   free (Xvec.elements);
Index: /branches/kapa-mods-2007-05/Ohana/src/opihi/cmd.astro/region.c
===================================================================
--- /branches/kapa-mods-2007-05/Ohana/src/opihi/cmd.astro/region.c	(revision 13431)
+++ /branches/kapa-mods-2007-05/Ohana/src/opihi/cmd.astro/region.c	(revision 13432)
@@ -114,5 +114,6 @@
   KapaSendLabel (kapa, string, 2);
 
-  SetGraph (graphmode);
+  // XXX is this the right thing to be doing?
+  SetGraph (&graphmode);
   return (TRUE);
 }
Index: /branches/kapa-mods-2007-05/Ohana/src/opihi/cmd.data/dot.c
===================================================================
--- /branches/kapa-mods-2007-05/Ohana/src/opihi/cmd.data/dot.c	(revision 13431)
+++ /branches/kapa-mods-2007-05/Ohana/src/opihi/cmd.data/dot.c	(revision 13432)
@@ -3,8 +3,9 @@
 int dot (int argc, char **argv) {
   
+  int kapa;
   Graphdata graphmode;
   float x, y;
 
-  if (!style_args (&graphmode, &argc, argv, NULL)) return FALSE;
+  if (!style_args (&graphmode, &argc, argv, &kapa)) return FALSE;
 
   if (argc != 3) {
@@ -15,15 +16,11 @@
   y = atof(argv[2]);
 
-  /* set plotting options (these are sticky) */
-  SetGraph (graphmode);
-
   /* set point style and errorbar mode (these are NOT sticky) */
   graphmode.style = 2;
   graphmode.etype = 0;
 
-  if (!PrepPlotting (1, &graphmode)) return (FALSE);
-  
-  PlotVector (1, &x, "x");
-  PlotVector (1, &y, "y");
+  if (!KapaPrepPlot (kapa, 1, &graphmode)) return (FALSE);
+  KapaPlotVector (kapa, 1, &x, "x");
+  KapaPlotVector (kapa, 1, &y, "y");
   
   return (TRUE);
Index: /branches/kapa-mods-2007-05/Ohana/src/opihi/cmd.data/grid.c
===================================================================
--- /branches/kapa-mods-2007-05/Ohana/src/opihi/cmd.data/grid.c	(revision 13431)
+++ /branches/kapa-mods-2007-05/Ohana/src/opihi/cmd.data/grid.c	(revision 13432)
@@ -3,10 +3,10 @@
 int grid (int argc, char **argv) {
   
-  int j, N, MinorTick, MajorTick;
+  int j, kapa, N, MinorTick, MajorTick;
   Vector Xvec, Yvec;
   double range, lrange, factor, mantis, fmantis, power, major, minor, first, next;
   Graphdata graphmode;
 
-  if (!style_args (&graphmode, &argc, argv, NULL)) return (FALSE);
+  if (!style_args (&graphmode, &argc, argv, &kapa)) return (FALSE);
 
   MajorTick = TRUE;
@@ -193,7 +193,5 @@
   graphmode.ptype = 100; /* connect a pair */
   graphmode.etype = 0;
-  PrepPlotting (N, &graphmode);
-  PlotVector (N, Xvec.elements, "x");
-  PlotVector (N, Yvec.elements, "y");
+  PlotVectorPair (kapa, N, Xvec.elements, Yvec.elements, &graphmode);
 
   free (Xvec.elements);
Index: /branches/kapa-mods-2007-05/Ohana/src/opihi/cmd.data/line.c
===================================================================
--- /branches/kapa-mods-2007-05/Ohana/src/opihi/cmd.data/line.c	(revision 13431)
+++ /branches/kapa-mods-2007-05/Ohana/src/opihi/cmd.data/line.c	(revision 13432)
@@ -3,8 +3,9 @@
 int line (int argc, char **argv) {
   
+  int kapa;
   Graphdata graphmode;
   float x[2], y[2];
 
-  if (!style_args (&graphmode, &argc, argv, NULL)) return FALSE;
+  if (!style_args (&graphmode, &argc, argv, &kapa)) return FALSE;
 
   if (argc != 6) {
@@ -17,16 +18,12 @@
   y[1] = atof(argv[5]);
 
-  SetGraph (graphmode);
-
   /* set point style and errorbar mode (these are NOT sticky) */
   graphmode.style = 0;
   graphmode.etype = 0;
 
-  if (!PrepPlotting (2, &graphmode)) return (FALSE);
-  
-  PlotVector (2, x, "x");
-  PlotVector (2, y, "y");
+  if (!KapaPrepPlot (kapa, 2, &graphmode)) return (FALSE);
+  KapaPlotVector (kapa, 2, x, "x");
+  KapaPlotVector (kapa, 2, y, "y");
   
   return (TRUE);
-
 }
Index: /branches/kapa-mods-2007-05/Ohana/src/opihi/cmd.data/plot.c
===================================================================
--- /branches/kapa-mods-2007-05/Ohana/src/opihi/cmd.data/plot.c	(revision 13431)
+++ /branches/kapa-mods-2007-05/Ohana/src/opihi/cmd.data/plot.c	(revision 13432)
@@ -3,9 +3,9 @@
 int plot (int argc, char **argv) {
   
-  int N, Npts;
+  int kapa, N, Npts;
   Graphdata graphmode;
   Vector *xvec, *yvec, *dxmvec, *dxpvec, *dymvec, *dypvec;
 
-  if (!style_args (&graphmode, &argc, argv, NULL)) return FALSE;
+  if (!style_args (&graphmode, &argc, argv, &kapa)) return FALSE;
 
   /* decide on error bars */
@@ -36,5 +36,4 @@
     return (FALSE);
   }
-  SetGraph (graphmode);
 
   /* set errorbar mode (these are NOT sticky) */
@@ -57,18 +56,16 @@
   if (Npts == 0) return (TRUE);
 
-  if (!PrepPlotting (Npts, &graphmode)) return (FALSE);
+  if (!KapaPrepPlot (kapa, Npts, &graphmode)) return (FALSE);
   
-  PlotVector (Npts, xvec[0].elements, "x");
-  PlotVector (Npts, yvec[0].elements, "y");
+  KapaPlotVector (kapa, Npts, xvec[0].elements, "x");
+  KapaPlotVector (kapa, Npts, yvec[0].elements, "y");
   if (graphmode.etype & 0x01) {
-    PlotVector (Npts, dymvec[0].elements, "dym");
-    PlotVector (Npts, dypvec[0].elements, "dyp");
+    KapaPlotVector (kapa, Npts, dymvec[0].elements, "dym");
+    KapaPlotVector (kapa, Npts, dypvec[0].elements, "dyp");
   }
   if (graphmode.etype & 0x02) {
-    PlotVector (Npts, dxmvec[0].elements, "dxm");
-    PlotVector (Npts, dxpvec[0].elements, "dxp");
+    KapaPlotVector (kapa, Npts, dxmvec[0].elements, "dxm");
+    KapaPlotVector (kapa, Npts, dxpvec[0].elements, "dxp");
   }
-  
   return (TRUE);
-
 }
Index: /branches/kapa-mods-2007-05/Ohana/src/opihi/cmd.data/section.c
===================================================================
--- /branches/kapa-mods-2007-05/Ohana/src/opihi/cmd.data/section.c	(revision 13431)
+++ /branches/kapa-mods-2007-05/Ohana/src/opihi/cmd.data/section.c	(revision 13432)
@@ -1,11 +1,10 @@
 # include "data.h"
 
-enum {NONE, LIST, UP, DOWN, TOP, BOTTOM};
+enum {NONE, LIST, UP, DOWN, TOP, BOTTOM, TOOL};
 
 int section (int argc, char **argv) {
   
-  int N, action;
-  int kapa;
-  char *name;
+  int N, action, kapa;
+  char *name, *location;
   Graphdata graphmode;
   KapaSection section;
@@ -13,22 +12,28 @@
   action = NONE;
   if ((N = get_argument (argc, argv, "-list"))) {
+    action = LIST;
     remove_argument (N, &argc, argv);
-    action = LIST;
   }
   if ((N = get_argument (argc, argv, "-up"))) {
+    action = UP;
     remove_argument (N, &argc, argv);
-    action = UP;
   }
   if ((N = get_argument (argc, argv, "-down"))) {
+    action = DOWN;
     remove_argument (N, &argc, argv);
-    action = DOWN;
   }
   if ((N = get_argument (argc, argv, "-top"))) {
+    action = TOP;
     remove_argument (N, &argc, argv);
-    action = TOP;
   }
   if ((N = get_argument (argc, argv, "-bottom"))) {
+    action = BOTTOM;
     remove_argument (N, &argc, argv);
-    action = BOTTOM;
+  }
+  if ((N = get_argument (argc, argv, "-imtool"))) {
+    action = TOOL;
+    remove_argument (N, &argc, argv);
+    location = argv[N];
+    remove_argument (N, &argc, argv);
   }
 
@@ -43,5 +48,5 @@
 
   /* list sections */
-  if (argc == 1) {
+  if ((argc == 1) && (action == NONE)) {
     KapaGetSection (kapa, "*");
     gprint (GP_ERR, "USAGE: section name [x y dx dy]\n");
@@ -69,4 +74,29 @@
 	KapaMoveSection (kapa, argv[1], "bottom");
 	break;
+
+      case TOOL:
+	if (!strcmp(location, "-x")) {
+	  KapaSetToolbox (kapa, 1);
+	  break;
+	}
+	if (!strcmp(location, "+x")) {
+	  KapaSetToolbox (kapa, 3);
+	  break;
+	}
+	if (!strcmp(location, "-y")) {
+	  KapaSetToolbox (kapa, 2);
+	  break;
+	}
+	if (!strcmp(location, "+y")) {
+	  KapaSetToolbox (kapa, 4);
+	  break;
+	}
+	if (!strcmp(location, "none")) {
+	  KapaSetToolbox (kapa, 0);
+	  break;
+	}
+	gprint (GP_ERR, "unknown toolbox location %s\n", location);
+	gprint (GP_ERR, "valid values: -x, +x, -y, +y, none\n");
+	return (FALSE);
 
       case LIST:
Index: /branches/kapa-mods-2007-05/Ohana/src/opihi/cmd.data/style.c
===================================================================
--- /branches/kapa-mods-2007-05/Ohana/src/opihi/cmd.data/style.c	(revision 13431)
+++ /branches/kapa-mods-2007-05/Ohana/src/opihi/cmd.data/style.c	(revision 13432)
@@ -3,7 +3,8 @@
 int style (int argc, char **argv) {
   
+  int kapa;
   Graphdata graphmode;
 
-  if (!style_args (&graphmode, &argc, argv, NULL)) return FALSE;
+  if (!style_args (&graphmode, &argc, argv, &kapa)) return FALSE;
 
   if (argc > 1) {
@@ -11,5 +12,5 @@
     return (FALSE);
   }
-  SetGraph (graphmode);
+  KapaSetGraphStyle (kapa, &graphmode);
 
   return (TRUE);
Index: /branches/kapa-mods-2007-05/Ohana/src/opihi/cmd.data/zplot.c
===================================================================
--- /branches/kapa-mods-2007-05/Ohana/src/opihi/cmd.data/zplot.c	(revision 13431)
+++ /branches/kapa-mods-2007-05/Ohana/src/opihi/cmd.data/zplot.c	(revision 13432)
@@ -3,5 +3,5 @@
 int zplot (int argc, char **argv) {
   
-  int i, N, Npts;
+  int i, kapa, N, Npts;
   float *in, *out;
   double min, range;
@@ -9,5 +9,5 @@
   Vector *xvec, *yvec, *zvec, Zvec;
 
-  if (!style_args (&graphmode, &argc, argv, NULL)) return (FALSE);
+  if (!style_args (&graphmode, &argc, argv, &kapa)) return (FALSE);
 
   if (argc != 6) {
@@ -45,9 +45,5 @@
   graphmode.etype = 0; /* no errorbars */
   Npts = xvec[0].Nelements;
-  PrepPlotting (Npts, &graphmode);
-
-  PlotVector (Npts, xvec[0].elements, "x");
-  PlotVector (Npts, yvec[0].elements, "y");
-  PlotVector (Npts, Zvec.elements, "z");
+  PlotVectorTriplet (kapa, Npts, xvec[0].elements, yvec[0].elements, Zvec.elements, &graphmode);
 
   free (Zvec.elements);
Index: /branches/kapa-mods-2007-05/Ohana/src/opihi/dvo/dmt.c
===================================================================
--- /branches/kapa-mods-2007-05/Ohana/src/opihi/dvo/dmt.c	(revision 13431)
+++ /branches/kapa-mods-2007-05/Ohana/src/opihi/dvo/dmt.c	(revision 13432)
@@ -40,5 +40,6 @@
   // XXX this needs to be fixed: how to access different graphs at once?
   gprint (GP_ERR, "ERROR: this function is currently disabled\n");
-  if (!GetGraphData (&graphsky, NULL, NULL)) return (FALSE);
+  return (FALSE);
+  if (!GetGraphData (&graphsky, &kapa, NULL)) return (FALSE);
   if (!GetGraph (&graphmode, NULL, NULL)) return (FALSE);
 
@@ -143,8 +144,5 @@
   } else {
     graphmode.style = 2; /* set style to points */
-    PrepPlotting (N, &graphmode);
-    
-    PlotVector (N, Xvec.elements, "x");
-    PlotVector (N, Yvec.elements, "y");
+    PlotVector (kapa, N, Xvec.elements, Yvec.elements, &graphmode);
 
     free (Xvec.elements);
Index: /branches/kapa-mods-2007-05/Ohana/src/opihi/dvo/images.c
===================================================================
--- /branches/kapa-mods-2007-05/Ohana/src/opihi/dvo/images.c	(revision 13431)
+++ /branches/kapa-mods-2007-05/Ohana/src/opihi/dvo/images.c	(revision 13432)
@@ -14,5 +14,5 @@
   int WITH_MOSAIC, SOLO_MOSAIC, HIDDEN;
   time_t tzero, tend;
-  int N, NPTS, n, npts, Npts;
+  int N, NPTS, n, npts, Npts, kapa;
   Vector Xvec, Yvec;
   double r[8], d[8], x[8], y[8], Rmin, Rmax, Rmid, trange, Radius;
@@ -22,5 +22,5 @@
   int typehash;
 
-  if (!style_args (&graphmode, &argc, argv, NULL)) return FALSE;
+  if (!style_args (&graphmode, &argc, argv, &kapa)) return FALSE;
 
   WITH_MOSAIC = FALSE;
@@ -101,5 +101,4 @@
     return (FALSE);
   }
-  SetGraph (graphmode);
   
   /* it is not an error for the database not to have any images */
@@ -282,7 +281,5 @@
     graphmode.ptype = 100; /* connect pairs of points */
     graphmode.etype = 0;
-    PrepPlotting (N, &graphmode);
-    PlotVector (N, Xvec.elements, "x");
-    PlotVector (N, Yvec.elements, "y");
+    PlotVectorPair (kapa, N, Xvec.elements, Yvec.elements, &graphmode);
   }
 
Index: /branches/kapa-mods-2007-05/Ohana/src/opihi/dvo/imbox.c
===================================================================
--- /branches/kapa-mods-2007-05/Ohana/src/opihi/dvo/imbox.c	(revision 13431)
+++ /branches/kapa-mods-2007-05/Ohana/src/opihi/dvo/imbox.c	(revision 13432)
@@ -3,5 +3,5 @@
 int imbox (int argc, char **argv) {
   
-  int j, Nskip, status, InPic, flipped;
+  int j, kapa, Nskip, status, InPic, flipped;
   Vector Xvec, Yvec;
   double r, d, x[4], y[4], Rmin, Rmax, Rmid;
@@ -12,5 +12,5 @@
   FILE *f;
 
-  if (!style_args (&graphmode, &argc, argv, NULL)) return FALSE;
+  if (!style_args (&graphmode, &argc, argv, &kapa)) return FALSE;
 
   if (argc != 2) {
@@ -76,7 +76,5 @@
       graphmode.ptype = 100; /* connect pairs of points */
       graphmode.etype = 0;
-      PrepPlotting (8, &graphmode);
-      PlotVector (8, Xvec.elements, "x");
-      PlotVector (8, Yvec.elements, "y");
+      PlotVectorPair (kapa, 8, Xvec.elements, Yvec.elements, &graphmode);
     }
   skip:
Index: /branches/kapa-mods-2007-05/Ohana/src/opihi/dvo/imdense.c
===================================================================
--- /branches/kapa-mods-2007-05/Ohana/src/opihi/dvo/imdense.c	(revision 13431)
+++ /branches/kapa-mods-2007-05/Ohana/src/opihi/dvo/imdense.c	(revision 13432)
@@ -5,5 +5,5 @@
   
   long A, B;
-  int i, N, Nimage, status, NPTS;
+  int i, kapa, N, Nimage, status, NPTS;
   double r, d, x, y, Rmin, Rmax;
   Vector Xvec, Yvec;
@@ -11,5 +11,5 @@
   Graphdata graphmode;
 
-  if (!style_args (&graphmode, &argc, argv, NULL)) return FALSE;
+  if (!style_args (&graphmode, &argc, argv, &kapa)) return FALSE;
 
   /* need options to list only images in region and only images in a time range */
@@ -62,7 +62,5 @@
     graphmode.style = 2; /* points */
     graphmode.etype = 0;
-    PrepPlotting (N, &graphmode);
-    PlotVector (N, Xvec.elements, "x");
-    PlotVector (N, Yvec.elements, "y");
+    PlotVectorPair (kapa, N, Xvec.elements, Yvec.elements, &graphmode);
   }
 
Index: /branches/kapa-mods-2007-05/Ohana/src/opihi/dvo/imstats.c
===================================================================
--- /branches/kapa-mods-2007-05/Ohana/src/opihi/dvo/imstats.c	(revision 13431)
+++ /branches/kapa-mods-2007-05/Ohana/src/opihi/dvo/imstats.c	(revision 13432)
@@ -3,5 +3,5 @@
 int imstats (int argc, char **argv) {
   
-  int i, Nimage, N;
+  int i, kapa, Nimage, N;
   int Mcal, AutoLimits;
   double r, d;
@@ -10,5 +10,5 @@
   Graphdata graphmode;
 
-  if (!style_args (&graphmode, &argc, argv, NULL)) return (FALSE);
+  if (!style_args (&graphmode, &argc, argv, &kapa)) return (FALSE);
 
   Mcal = TRUE;
@@ -54,7 +54,5 @@
   graphmode.style = 2;
   graphmode.etype = 0;
-  PrepPlotting (Nimage, &graphmode);
-  PlotVector (Nimage, Xvec.elements, "x");
-  PlotVector (Nimage, Yvec.elements, "y");
+  PlotVectorPair (kapa, Nimage, Xvec.elements, Yvec.elements, &graphmode);
   
   free (Xvec.elements);
Index: /branches/kapa-mods-2007-05/Ohana/src/opihi/dvo/lcurve.c
===================================================================
--- /branches/kapa-mods-2007-05/Ohana/src/opihi/dvo/lcurve.c	(revision 13431)
+++ /branches/kapa-mods-2007-05/Ohana/src/opihi/dvo/lcurve.c	(revision 13432)
@@ -154,10 +154,10 @@
     graphmode.etype = 0;  
 
-  PrepPlotting (N, &graphmode);
-  PlotVector (N, Xvec.elements, "x");
-  PlotVector (N, Yvec.elements, "y");
+  KapaPrepPlot (kapa, N, &graphmode);
+  KapaPlotVector (kapa, N, Xvec.elements, "x");
+  KapaPlotVector (kapa, N, Yvec.elements, "y");
   if (ErrorBars) {
-    PlotVector (N, dYvec.elements, "x");
-    PlotVector (N, dYvec.elements, "y");
+    KapaPlotVector (kapa, N, dYvec.elements, "dym");
+    KapaPlotVector (kapa, N, dYvec.elements, "dyp");
   }
 
Index: /branches/kapa-mods-2007-05/Ohana/src/opihi/dvo/paverage.c
===================================================================
--- /branches/kapa-mods-2007-05/Ohana/src/opihi/dvo/paverage.c	(revision 13431)
+++ /branches/kapa-mods-2007-05/Ohana/src/opihi/dvo/paverage.c	(revision 13432)
@@ -5,5 +5,5 @@
   
   FILE *f;
-  int i, j, Narg, Npts, NPTS, status, VERBOSE;
+  int i, j, kapa, Narg, Npts, NPTS, status, VERBOSE;
   int Nsecfilt, Nsec;
   double Mz, Mr, mag;
@@ -23,5 +23,5 @@
   Nsecfilt = GetPhotcodeNsecfilt ();
 
-  if (!style_args (&graphmode, &argc, argv, NULL)) return FALSE;
+  if (!style_args (&graphmode, &argc, argv, &kapa)) return FALSE;
 
   f = (FILE *) NULL;
@@ -82,5 +82,4 @@
     return (FALSE);
   }
-  SetGraph (graphmode);
   graphmode.style = 2; /* set style to points */
   graphmode.size = -1; /* point size determined by Zvec */
@@ -141,5 +140,5 @@
       }
       if (Npts > NCHUNK) {
-	  PlotVectorTriplet (Npts, Xvec, Yvec, Zvec, &graphmode);
+	  PlotVectorTriplet (kapa, Npts, Xvec, Yvec, Zvec, &graphmode);
 	  Npts = 0;
       }
@@ -147,5 +146,5 @@
     dvo_catalog_free (&catalog);
   }
-  if (Npts > 0) PlotVectorTriplet (Npts, Xvec, Yvec, Zvec, &graphmode);
+  if (Npts > 0) PlotVectorTriplet (kapa, Npts, Xvec, Yvec, Zvec, &graphmode);
 
   free (Xvec);
Index: /branches/kapa-mods-2007-05/Ohana/src/opihi/dvo/pcat.c
===================================================================
--- /branches/kapa-mods-2007-05/Ohana/src/opihi/dvo/pcat.c	(revision 13431)
+++ /branches/kapa-mods-2007-05/Ohana/src/opihi/dvo/pcat.c	(revision 13432)
@@ -6,5 +6,5 @@
   
   double Radius;
-  int i, j, N, Nregions, ShowAll, NPTS, Npts, leftside;
+  int i, j, kapa, N, Nregions, ShowAll, NPTS, Npts, leftside;
   RegionFile *regions;
   char filename[128];
@@ -33,5 +33,5 @@
     return (FALSE);
   }
-  if (!GetGraph (&graphmode, NULL, NULL)) return (FALSE);
+  if (!GetGraph (&graphmode, &kapa, NULL)) return (FALSE);
   
   Radius = MAX (fabs(graphmode.xmax), fabs(graphmode.ymax));
@@ -83,7 +83,5 @@
     graphmode.ptype = 100; /* connect pairs of points */
     graphmode.etype = 0;
-    PrepPlotting (Npts, &graphmode);
-    PlotVector (Npts, Xvec.elements, "x");
-    PlotVector (Npts, Yvec.elements, "y");
+    PlotVectorPair (kapa, Npts, Xvec.elements, Yvec.elements, &graphmode);
   }
 
Index: /branches/kapa-mods-2007-05/Ohana/src/opihi/dvo/pmeasure.c
===================================================================
--- /branches/kapa-mods-2007-05/Ohana/src/opihi/dvo/pmeasure.c	(revision 13431)
+++ /branches/kapa-mods-2007-05/Ohana/src/opihi/dvo/pmeasure.c	(revision 13432)
@@ -5,5 +5,5 @@
   
   FILE *f;
-  int i, j, k, m, Narg, Npts, NPTS, status, VERBOSE;
+  int i, j, k, m, kapa, Narg, Npts, NPTS, status, VERBOSE;
   double Mz, Mr, mag;
   double Radius, Rmin, Rmax, R, D;
@@ -19,5 +19,5 @@
 
   if (!InitPhotcodes ()) return (FALSE);
-  if (!style_args (&graphmode, &argc, argv, NULL)) return FALSE;
+  if (!style_args (&graphmode, &argc, argv, &kapa)) return FALSE;
 
   f = (FILE *) NULL;
@@ -75,5 +75,4 @@
     return (FALSE);
   }
-  SetGraph (graphmode);
   graphmode.style = 2; /* set style to points */
   graphmode.size = -1; /* point size determined by Zvec */
@@ -144,5 +143,5 @@
 	}
 	if (Npts > NCHUNK) {
-	    PlotVectorTriplet (Npts, Xvec, Yvec, Zvec, &graphmode);
+	    PlotVectorTriplet (kapa, Npts, Xvec, Yvec, Zvec, &graphmode);
 	    Npts = 0;
 	}
@@ -151,5 +150,5 @@
     dvo_catalog_free (&catalog);
   }
-  if (Npts > 0) PlotVectorTriplet (Npts, Xvec, Yvec, Zvec, &graphmode);
+  if (Npts > 0) PlotVectorTriplet (kapa, Npts, Xvec, Yvec, Zvec, &graphmode);
 
   free (Xvec);
Index: /branches/kapa-mods-2007-05/Ohana/src/opihi/dvo/procks.c
===================================================================
--- /branches/kapa-mods-2007-05/Ohana/src/opihi/dvo/procks.c	(revision 13431)
+++ /branches/kapa-mods-2007-05/Ohana/src/opihi/dvo/procks.c	(revision 13432)
@@ -16,5 +16,5 @@
   FILE *f;
   Vector Xvec, Yvec;
-  int i, j, N, NROCKS;
+  int kapa, i, j, N, NROCKS;
   int N0, N1, SpeedClip, Reload;
   unsigned int t0, t1;
@@ -25,5 +25,5 @@
 
   VarConfig ("ROCK_CATALOG", "%s", rockcat);
-  if (!GetGraph (&graphmode, NULL, NULL)) return (FALSE);
+  if (!GetGraph (&graphmode, &kapa, NULL)) return (FALSE);
 
   f = (FILE *) NULL;
@@ -113,8 +113,5 @@
   graphmode.style = 2; /* set style to points */
   graphmode.etype = 0; /* no errorbars */
-  PrepPlotting (N, &graphmode);
-  
-  PlotVector (N, Xvec.elements, "x");
-  PlotVector (N, Yvec.elements, "y");
+  PlotVectorPair (kapa, N, Xvec.elements, Yvec.elements, &graphmode);
 
   /* now plot vectors between two extrema */
@@ -146,8 +143,6 @@
   graphmode.ptype = 100; /* connect pairs */
   graphmode.etype = 0; /* no errorbars */
-  PrepPlotting (N, &graphmode);
-  
-  PlotVector (N, Xvec.elements, "x");
-  PlotVector (N, Yvec.elements, "y");
+
+  PlotVectorPair (kapa, N, Xvec.elements, Yvec.elements, &graphmode);
 
   free (Xvec.elements);
Index: /branches/kapa-mods-2007-05/Ohana/src/opihi/dvo/showtile.c
===================================================================
--- /branches/kapa-mods-2007-05/Ohana/src/opihi/dvo/showtile.c	(revision 13431)
+++ /branches/kapa-mods-2007-05/Ohana/src/opihi/dvo/showtile.c	(revision 13432)
@@ -5,5 +5,5 @@
 int showtile (int argc, char **argv) {
 
-  int Nd, N, NPTS, status, i, InPic;
+  int kapa, Nd, N, NPTS, status, i, InPic;
   Graphdata graphmode;
   Coords coords;
@@ -13,5 +13,5 @@
 
   /* show tile pattern in viewed region */
-  if (!GetGraph (&graphmode, NULL, NULL)) return (FALSE);
+  if (!GetGraph (&graphmode, &kapa, NULL)) return (FALSE);
 
   if (argc != 1) {
@@ -86,7 +86,5 @@
     graphmode.ptype = 100; /* connect pairs of points */
     graphmode.etype = 0;
-    PrepPlotting (N, &graphmode);
-    PlotVector (N, Xvec.elements, "x");
-    PlotVector (N, Yvec.elements, "y");
+    PlotVectorPair (kapa, N, Xvec.elements, Yvec.elements, &graphmode);
   }
 
Index: /branches/kapa-mods-2007-05/Ohana/src/opihi/dvo/simage.c
===================================================================
--- /branches/kapa-mods-2007-05/Ohana/src/opihi/dvo/simage.c	(revision 13431)
+++ /branches/kapa-mods-2007-05/Ohana/src/opihi/dvo/simage.c	(revision 13432)
@@ -12,8 +12,8 @@
   Header header;
   Coords coords;
-  int i, j, Nstars, nstars, Nbytes, nbytes, Npts, N;
+  int i, j, kapa, Nstars, nstars, Nbytes, nbytes, Npts, N;
   Graphdata graphmode;
 
-  if (!GetGraph (&graphmode, NULL, NULL)) return (FALSE);
+  if (!GetGraph (&graphmode, &kapa, NULL)) return (FALSE);
 
   zero = 17.0;
@@ -154,9 +154,6 @@
   graphmode.etype = 0;
   Npts = Xvec.Nelements;
-  PrepPlotting (Npts, &graphmode);
 
-  PlotVector (Npts, Xvec.elements, "x");
-  PlotVector (Npts, Yvec.elements, "y");
-  PlotVector (Npts, Zvec.elements, "z");
+  PlotVectorTriplet (kapa, Npts, Xvec.elements, Yvec.elements, Zvec.elements, &graphmode);
 
   free (Xvec.elements);
Index: /branches/kapa-mods-2007-05/Ohana/src/opihi/dvo/skycat.c
===================================================================
--- /branches/kapa-mods-2007-05/Ohana/src/opihi/dvo/skycat.c	(revision 13431)
+++ /branches/kapa-mods-2007-05/Ohana/src/opihi/dvo/skycat.c	(revision 13432)
@@ -6,5 +6,5 @@
   
   double Radius;
-  int i, j, N, Nregions, ShowAll, NPTS, Npts, leftside, Depth, VERBOSE;
+  int i, j, N, Nregions, kapa, ShowAll, NPTS, Npts, leftside, Depth, VERBOSE;
   struct stat filestat;
   Vector Xvec, Yvec;
@@ -32,5 +32,5 @@
   }
 
-  if (!style_args (&graphmode, &argc, argv, NULL)) return FALSE;
+  if (!style_args (&graphmode, &argc, argv, &kapa)) return FALSE;
 
   if (argc != 1) {
@@ -38,5 +38,4 @@
     return (FALSE);
   }
-  SetGraph (graphmode);
 
   Radius = MAX (fabs(graphmode.xmax), fabs(graphmode.ymax));
@@ -97,7 +96,5 @@
     graphmode.ptype = 100; /* connect pairs of points */
     graphmode.etype = 0;
-    PrepPlotting (Npts, &graphmode);
-    PlotVector (Npts, Xvec.elements, "x");
-    PlotVector (Npts, Yvec.elements, "y");
+    PlotVectorPair (kapa, Npts, Xvec.elements, Yvec.elements, &graphmode);
   }
 
Index: /branches/kapa-mods-2007-05/Ohana/src/opihi/include/display.h
===================================================================
--- /branches/kapa-mods-2007-05/Ohana/src/opihi/include/display.h	(revision 13431)
+++ /branches/kapa-mods-2007-05/Ohana/src/opihi/include/display.h	(revision 13432)
@@ -7,7 +7,6 @@
 /*** plotting functions ***/
 int           GetCurrentDevice      PROTO((void));
-int           PrepPlotting          PROTO((int Npts, Graphdata *graphmode));
-int           PlotVector            PROTO((int Npts, float *values, char *type));
-int           PlotVectorTriplet     PROTO((int N, float *xValues, float *yValues, float *zValues, Graphdata *graphmode));
+int           PlotVectorPair        PROTO((int kapa, int Npts, float *xValues, float *yValues, Graphdata *graphmode));
+int           PlotVectorTriplet     PROTO((int kapa, int Npts, float *xValues, float *yValues, float *zValues, Graphdata *graphmode));
 int           GetGraphData          PROTO((Graphdata *data, int *kapa, char *name));
 int           GetGraph              PROTO((Graphdata *data, int *kapa, char *name));
@@ -16,5 +15,5 @@
 int           close_graph           PROTO((int N));
 void          QuitGraph             PROTO((void));
-void          SetGraph              PROTO((Graphdata data));
+void          SetGraph              PROTO((Graphdata *data));
 void          XGraphDead            PROTO((int input));
 int           GetColor              PROTO((char *name));
Index: /branches/kapa-mods-2007-05/Ohana/src/opihi/lib.data/PlotVectors.c
===================================================================
--- /branches/kapa-mods-2007-05/Ohana/src/opihi/lib.data/PlotVectors.c	(revision 13431)
+++ /branches/kapa-mods-2007-05/Ohana/src/opihi/lib.data/PlotVectors.c	(revision 13432)
@@ -1,39 +1,20 @@
 # include "display.h"
 
-static int kapa;
+int PlotVectorPair (int kapa, int Npts, float *xValues, float *yValues, Graphdata *graphmode) {
 
-int PrepPlotting (int Npts, Graphdata *graphmode) {
-
-  if (!GetGraph (NULL, &kapa, NULL)) return (FALSE);
   KapaPrepPlot (kapa, Npts, graphmode);
-  return (TRUE);
-}
-
-int PlotVector (int Npts, float *values, char *type) {
-
-  KapaPlotVector (kapa, Npts, values, type);
-  return (TRUE);
-}
-
-int PlotVectorPair (int N, float *xValues, float *yValues, Graphdata *graphmode) {
-
-  PrepPlotting (N, graphmode);
-  PlotVector (N, xValues, "x");
-  PlotVector (N, yValues, "y");
+  KapaPlotVector (kapa, Npts, xValues, "x");
+  KapaPlotVector (kapa, Npts, yValues, "y");
 
   return (TRUE);
 }
 
-int PlotVectorTriplet (int N, float *xValues, float *yValues, float *zValues, Graphdata *graphmode) {
+int PlotVectorTriplet (int kapa, int Npts, float *xValues, float *yValues, float *zValues, Graphdata *graphmode) {
 
-  PrepPlotting (N, graphmode);
-  PlotVector (N, xValues, "x");
-  PlotVector (N, yValues, "y");
-  PlotVector (N, zValues, "z");
+  KapaPrepPlot   (kapa, Npts, graphmode);
+  KapaPlotVector (kapa, Npts, xValues, "x");
+  KapaPlotVector (kapa, Npts, yValues, "y");
+  KapaPlotVector (kapa, Npts, zValues, "z");
 
   return (TRUE);
 }
-
-/* we don't use GetGraph in PlotVector because it flushes the connection */
-/* PlotVector currently operates on the static identified socket 
-   rather than the currently active socket -- must be preceeded by PrepPlotting */
Index: /branches/kapa-mods-2007-05/Ohana/src/opihi/lib.data/graphtools.c
===================================================================
--- /branches/kapa-mods-2007-05/Ohana/src/opihi/lib.data/graphtools.c	(revision 13431)
+++ /branches/kapa-mods-2007-05/Ohana/src/opihi/lib.data/graphtools.c	(revision 13432)
@@ -33,5 +33,5 @@
     graphmode[0].ymax = maxY + 0.05*range;
   }
-  SetGraph (graphmode[0]);
+  SetGraph (graphmode);
 
   set_variable ("XMIN", graphmode[0].xmin);
@@ -73,5 +73,5 @@
     graphmode[0].ymax = maxY + 0.05*range;
   }
-  SetGraph (graphmode[0]);
+  SetGraph (graphmode);
 
   set_variable ("XMIN", graphmode[0].xmin);
Index: /branches/kapa-mods-2007-05/Ohana/src/opihi/lib.data/open_kapa.c
===================================================================
--- /branches/kapa-mods-2007-05/Ohana/src/opihi/lib.data/open_kapa.c	(revision 13431)
+++ /branches/kapa-mods-2007-05/Ohana/src/opihi/lib.data/open_kapa.c	(revision 13432)
@@ -180,5 +180,5 @@
   }
   
-  if (data != NULL) *data = graphdata;
+  if (data != NULL) KapaGetGraphStyle (Socket[Active], data);
   if (fd != NULL) *fd = Socket[Active];
 
@@ -206,11 +206,19 @@
 
   if (fd != NULL) *fd = Socket[entry];
-  if (data != NULL) *data = graphdata;
+  if (data != NULL) KapaGetGraphStyle (Socket[entry], data);
   return (TRUE);
 }
 
 /* assign given values to current Xgraph */
-void SetGraph (Graphdata data) {
-  graphdata = data;
+void SetGraph (Graphdata *data) {
+  if (Active < 0) {
+    gprint (GP_ERR, "no active kapa window\n"); 
+    return (FALSE);
+  }
+  if (Socket[Active] == -1) {
+    gprint (GP_ERR, "no active kapa window\n"); 
+    return (FALSE);
+  }
+  KapaSetGraphStyle (Socket[Active], data);
 }
 
