Index: trunk/Ohana/src/opihi/cmd.data/tvgrid.c
===================================================================
--- trunk/Ohana/src/opihi/cmd.data/tvgrid.c	(revision 4689)
+++ trunk/Ohana/src/opihi/cmd.data/tvgrid.c	(revision 5846)
@@ -4,5 +4,5 @@
 int tvgrid (int argc, char **argv) {
   
-  int ncolor, ndig1, ndig2, NX, NY, connect;
+  int ndig1, ndig2, NX, NY, connect;
   int tDEC, tRA;
   double ra, dec, ra0, dec0, ra1, dec1;
@@ -11,6 +11,7 @@
   char format[16];
   Coords coords;
-  int Ximage, Nimage, N;
+  int Ximage, Nimage, N, Noverlay, NOVERLAY;
   Buffer *buf;
+  KiiOverlay *overlay;
 
   Nimage = -1;
@@ -23,23 +24,8 @@
   
   if (argc != 3) {
-    fprintf (stderr, "USAGE: load (overlay) (buffer)\n");
+    fprintf (stderr, "USAGE: tvgrid (overlay) (buffer)\n");
     fprintf (stderr, " (overlay) may be: red, green, blue, yellow\n");
     return (FALSE);
   }
-  if (strcmp (argv[1], "0")   && strcmp (argv[1], "1")     && strcmp (argv[1], "2")   && strcmp (argv[1], "3") &&
-      strcmp (argv[1], "red") && strcmp (argv[1], "green") && strcmp (argv[1], "blue") && strcmp (argv[1], "yellow")) {
-    fprintf (stderr, "valid overlays may be: 0, red, 1, green, 2, blue, 3, yellow\n");
-    return (FALSE);
-  }
-
-  ncolor = atof (argv[1]);
-  if (!(strcmp (argv[1], "red"))) 
-    ncolor = 0;
-  if (!(strcmp (argv[1], "green"))) 
-    ncolor = 1;
-  if (!(strcmp (argv[1], "blue"))) 
-    ncolor = 2;
-  if (!(strcmp (argv[1], "yellow"))) 
-    ncolor = 3;
 
   if ((buf = SelectBuffer (argv[2], OLDBUFFER, TRUE)) == NULL) return (FALSE);
@@ -50,8 +36,8 @@
   fprintf (stderr, "%f %f  %f %f\n", ra0, dec0, ra1, dec1);
   
-  /* tell KII to expect overlay data */
-  SendGraphCommand (Ximage, 4, "LOAD"); 
-  SendGraphCommand (Ximage, 16, "OVERLAY: %7d", ncolor);
-  
+  Noverlay = 0;
+  NOVERLAY = 1000;
+  ALLOCATE (overlay, KiiOverlay, NOVERLAY);
+
   dDEC = fabs(dec1 - dec0);
   tDEC = log10(dDEC) - log10(5.0);
@@ -90,5 +76,13 @@
       RD_to_XY (&x1, &y1, ra, dec, &coords);
       if ((x1 >= 0) && (x1 < NX) && (y1 >= 0) && (y1 < NY)) {
-	if (connect) SendGraphCommand (Ximage, 128, "%15s %20.10f %20.10f %20.10f %20.10f ", "LINE", x0, y0, (x1 - x0), (y1 - y0));
+	if (connect) {
+	  overlay[Noverlay].type = KII_OVERLAY_LINE;
+	  overlay[Noverlay].x = x0;
+	  overlay[Noverlay].y = y0;
+	  overlay[Noverlay].dx = x1 - x0;
+	  overlay[Noverlay].dy = y1 - y0;
+	  Noverlay ++;
+	  CHECK_REALLOCATE (overlay, KiiOverlay, NOVERLAY, Noverlay, 1000);
+	}
 	x0 = x1;
 	y0 = y1;
@@ -132,5 +126,13 @@
       RD_to_XY (&x1, &y1, ra, dec, &coords);
       if ((x1 >= 0) && (x1 < NX) && (y1 >= 0) && (y1 < NY)) {
-	if (connect) SendGraphCommand (Ximage, 128, "%15s %20.10f %20.10f %20.10f %20.10f ", "LINE", x0, y0, (x1 - x0), (y1 - y0));
+	if (connect) {
+	  overlay[Noverlay].type = KII_OVERLAY_LINE;
+	  overlay[Noverlay].x = x0;
+	  overlay[Noverlay].y = y0;
+	  overlay[Noverlay].dx = x1 - x0;
+	  overlay[Noverlay].dy = y1 - y0;
+	  Noverlay ++;
+	  CHECK_REALLOCATE (overlay, KiiOverlay, NOVERLAY, Noverlay, 1000);
+	}
 	x0 = x1;
 	y0 = y1;
@@ -142,5 +144,6 @@
   }
 
-  /*
+  # if (0)
+  /* write the labels on the axes */
   dDEC = fabs(dec1 - dec0) / 100;
   for (ra = dRA * ((int)(MIN(ra0, ra1)/dRA) + 1); ra < MAX(ra0, ra1); ra += dRA) {
@@ -159,38 +162,9 @@
     }
   }
-  */
+  # endif
 
-  SendGraphCommand (Ximage, 128, "DONE");
+  KiiLoadOverlay (Ximage, overlay, Noverlay, argv[1]);
+  free (overlay);
+
   return (TRUE);
 }
-
-/*
-  write (Ximage, "LOAD", 4); 
-  sprintf (buffer, "OVERLAY: %7d", n);
-  write (Ximage, buffer, 16);
-  
-  for (n = 0; scan_line (f, buffer) != EOF; n++) {
-    c = strchr (buffer, '#');
-    if (c != (char *) NULL) 
-      *c = 0;  
-    while ((c = strchr (buffer, '(')) != (char *) NULL) 
-      *c = ' ';
-    while ((c = strchr (buffer, ')')) != (char *) NULL) 
-      *c = ' ';
-    while ((c = strchr (buffer, ',')) != (char *) NULL) 
-      *c = ' ';
-    N = sscanf (buffer, "%s %lf %lf %lf %lf", type, &x, &y, &dx, &dy);
-    if (N > 3) {
-      if (N == 4)
-	dy = dx;
-      sprintf (buffer, "%15s %20.10f %20.10f %20.10f %20.10f ", type, x, y, dx, dy);
-      write (Ximage, buffer, 128);
-    }
-  }
-  fprintf (stderr, "loaded %d objects\n", n);
-  sprintf (buffer, "DONE");
-  write (Ximage, buffer, 128);
-  if (f != stdin) {
-    fclose (f);
-  }
-*/
