Index: trunk/Ohana/src/opihi/cmd.data/center.c
===================================================================
--- trunk/Ohana/src/opihi/cmd.data/center.c	(revision 3692)
+++ trunk/Ohana/src/opihi/cmd.data/center.c	(revision 3693)
@@ -28,12 +28,6 @@
   }
 
-  write (Ximage, "CENT", 4); /* tell Ximage to look for the incoming image */
-
-  sprintf (buffer, "%8.3f %8.3f %8d ", x, y, zoom);
-  sprintf (buffer2, "NBYTES %8d ", strlen (buffer));
-  write (Ximage, buffer2, 16);
-  write (Ximage, buffer, strlen (buffer));
-  
+  SendGraphCommand (Ximage, 4, "CENT");
+  SendGraphMessage (Ximage, "%8.3f %8.3f %8d ", x, y, zoom);
   return (TRUE);
-
 }
Index: trunk/Ohana/src/opihi/cmd.data/erase.c
===================================================================
--- trunk/Ohana/src/opihi/cmd.data/erase.c	(revision 3692)
+++ trunk/Ohana/src/opihi/cmd.data/erase.c	(revision 3693)
@@ -31,7 +31,6 @@
     if (!(strcmp (argv[i], "all"))) {
       for (n = 0; n < 4; n++) {
-	write (Ximage, "ERAS", 4); /* force Ximage to look for the incoming image */
-	sprintf (buffer, "OVERLAY %7d ", n);
-	write (Ximage, buffer, 16);
+	SendGraphCommand (Ximage, 4, "ERAS");
+	SendGraphCommand (Ximage, 16, "OVERLAY %7d ", n);
       }
       return (TRUE);
@@ -44,10 +43,7 @@
     if (!(strcmp (argv[i], "tick"))) n = 4;
     
-    write (Ximage, "ERAS", 4); /* force Ximage to look for the incoming image */
-    sprintf (buffer, "OVERLAY %7d ", n);
-    write (Ximage, buffer, 16);
+    SendGraphCommand (Ximage, 4, "ERAS");
+    SendGraphCommand (Ximage, 16, "OVERLAY %7d ", n);
   }
-
   return (TRUE);
-  
 }
Index: trunk/Ohana/src/opihi/cmd.data/jpeg.c
===================================================================
--- trunk/Ohana/src/opihi/cmd.data/jpeg.c	(revision 3692)
+++ trunk/Ohana/src/opihi/cmd.data/jpeg.c	(revision 3693)
@@ -51,8 +51,6 @@
   }
 
-  strcpy (buffer, type);
-  write (Source, buffer, 4);
-  sprintf (buffer, "LEN: %11d", strlen(filename));
-  write (Source, buffer, 16);
+  SendGraphCommand (Source, 4, type);
+  SendGraphCommand (Source, 16, "LEN: %11d", strlen(filename));
   write (Source, filename, strlen(filename));
   read (Source, buffer, 4);
Index: trunk/Ohana/src/opihi/cmd.data/load.c
===================================================================
--- trunk/Ohana/src/opihi/cmd.data/load.c	(revision 3692)
+++ trunk/Ohana/src/opihi/cmd.data/load.c	(revision 3693)
@@ -55,7 +55,6 @@
   Nline = 0;
 
-  write (Ximage, "LOAD", 4); /* force Ximage to look for the incoming image */
-  sprintf (line, "OVER %9d ", n);
-  write (Ximage, line, 16);
+  SendGraphCommand (Ximage, 4, "LOAD");
+  SendGraphCommand (Ximage, 16, "OVER %9d ", n);
   
   for (n = 0; scan_line (f, line) != EOF;) {
@@ -123,6 +122,5 @@
     Nline ++;
     if (Nline == 512) {
-      sprintf (line, "NLINES  %7d ", Nline);
-      write (Ximage, line, 16);
+      SendGraphCommand (Ximage, 16, "NLINES  %7d ", Nline);
       write (Ximage, buffer, Nline*128);
       bzero (buffer, 65536);
@@ -131,9 +129,7 @@
   }
 
-  sprintf (line, "NLINES  %7d ", Nline);
-  write (Ximage, line, 16);
+  SendGraphCommand (Ximage, 16, "NLINES  %7d ", Nline);
   write (Ximage, buffer, Nline*128);
-  sprintf (line, "DONE ");
-  write (Ximage, line, 16);
+  SendGraphCommand (Ximage, 16, "DONE");
 
   free (buffer);
Index: trunk/Ohana/src/opihi/cmd.data/point.c
===================================================================
--- trunk/Ohana/src/opihi/cmd.data/point.c	(revision 3692)
+++ trunk/Ohana/src/opihi/cmd.data/point.c	(revision 3693)
@@ -44,6 +44,4 @@
   }
 
-  ALLOCATE (line, char, 1024);     /* space to read the file */
-
   ra = atof(argv[3]);
   dec = atof(argv[4]);
@@ -70,18 +68,10 @@
   }
 
-  write (Ximage, "LOAD", 4); /* force Ximage to look for the incoming image */
-  sprintf (line, "OVERLAY %6d ", n);
-  write (Ximage, line, 16);
-  sprintf (line, "NLINES %7d ", 1);
-  write (Ximage, line, 16);
-  sprintf (line, "%15s %20.10f %20.10f %20.10f %20.10f ", argv[2], x, y, dx, dy);
-  write (Ximage, line, 128);
-  sprintf (line, "DONE ");
-  write (Ximage, line, 16);
-
-  free (line);
-
+  SendGraphCommand (Ximage, 4, "LOAD");
+  SendGraphCommand (Ximage, 16, "OVERLAY %6d ", n);
+  SendGraphCommand (Ximage, 16, "NLINES %7d ", 1);
+  SendGraphCommand (Ximage, 128, "%15s %20.10f %20.10f %20.10f %20.10f ", argv[2], x, y, dx, dy);
+  SendGraphCommand (Ximage, 16, "DONE");
   return (TRUE);
-
 }
 
Index: trunk/Ohana/src/opihi/cmd.data/ps.c
===================================================================
--- trunk/Ohana/src/opihi/cmd.data/ps.c	(revision 3692)
+++ trunk/Ohana/src/opihi/cmd.data/ps.c	(revision 3693)
@@ -60,9 +60,6 @@
   if (!RawImage && !NoScale) SendGraphCommand (Source, 4, "PSIT");
 
-  /* I need to fix kapa and kii to read NBYTES, etc like other messages
-  SendGraphMessage (Source, "%s", filename); */
-
-  sprintf (buffer, "LEN: %11d", strlen(filename));
-  write (Source, buffer, 16);
+  /* I need to fix kapa and kii to read NBYTES, etc like other messages */
+  SendGraphCommand (Source, 16, "LEN: %11d", strlen(filename));
   write (Source, filename, strlen(filename));
   read (Source, buffer, 4);
Index: trunk/Ohana/src/opihi/cmd.data/save.c
===================================================================
--- trunk/Ohana/src/opihi/cmd.data/save.c	(revision 3692)
+++ trunk/Ohana/src/opihi/cmd.data/save.c	(revision 3693)
@@ -27,18 +27,12 @@
   }
 
-  if (!SelectOverlay (argv[1], &n)) 
-    return (FALSE);
-
-  sprintf (buffer, "FILE: %d %s", n, argv[2]);
-  sprintf (buffer2, "NBYTES: %8d", strlen(buffer));
+  if (!SelectOverlay (argv[1], &n)) return (FALSE);
   
   if (ISCEL) 
-    write (Ximage, "CSVE", 4); /* force Ximage to look for the incoming image */
+    SendGraphCommand (Ximage, 4, "CSVE");
   else 
-    write (Ximage, "SAVE", 4); /* force Ximage to look for the incoming image */
-  write (Ximage, buffer2, 16);
-  write (Ximage, buffer, strlen(buffer));
-  
+    SendGraphCommand (Ximage, 4, "SAVE");
+
+  SendGraphMessage (Ximage, "FILE: %d %s", n, argv[2]);
   return (TRUE);
-
 }
Index: trunk/Ohana/src/opihi/cmd.data/tv.c
===================================================================
--- trunk/Ohana/src/opihi/cmd.data/tv.c	(revision 3692)
+++ trunk/Ohana/src/opihi/cmd.data/tv.c	(revision 3693)
@@ -88,5 +88,4 @@
   root = filerootname (buf[0].file);
   SendGraphMessage (Ximage, "%s %s %s ", coords.ctype, root, buf[0].name);
-
   write (Ximage, outbuffer, size);
   free (outbuffer);
Index: trunk/Ohana/src/opihi/cmd.data/tvcontour.c
===================================================================
--- trunk/Ohana/src/opihi/cmd.data/tvcontour.c	(revision 3692)
+++ trunk/Ohana/src/opihi/cmd.data/tvcontour.c	(revision 3693)
@@ -45,6 +45,5 @@
 Nline ++; \
 if (Nline == 512) { \
-  sprintf (line, "NLINES  %7d ", Nline); \
-  write (Ximage, line, 16); \
+  SendGraphCommand (Ximage, 16, "NLINES  %7d ", Nline); \
   write (Ximage, buffer, Nline*128); \
   bzero (buffer, 65536); \
@@ -57,6 +56,5 @@
 Nline ++; \
 if (Nline == 512) { \
-  sprintf (line, "NLINES  %7d ", Nline); \
-  write (Ximage, line, 16); \
+  SendGraphCommand (Ximage, 16, "NLINES  %7d ", Nline); \
   write (Ximage, buffer, Nline*128); \
   bzero (buffer, 65536); \
@@ -123,7 +121,6 @@
   }
 
-  write (Ximage, "LOAD", 4); /* force Ximage to look for the incoming image */
-  sprintf (line, "OVERLAY %7d ", n);
-  write (Ximage, line, 16);
+  SendGraphCommand (Ximage, 4, "LOAD"); /* force Ximage to look for the incoming image */
+  SendGraphCommand (Ximage, 16, "OVERLAY %7d ", n);
   ALLOCATE (buffer, char, 65536);  /* space for 512 lines of 128 bytes */
   bzero (buffer, 65536);
@@ -282,15 +279,12 @@
   
   if (Nline > 0) {
-    sprintf (line, "NLINES  %7d ", Nline); 
-    write (Ximage, line, 16); 
+    SendGraphCommand (Ximage, 16, "NLINES  %7d ", Nline); 
     write (Ximage, buffer, Nline*128); 
   }
 
   free (buffer);
-  sprintf (line, "DONE ");
-  write (Ximage, line, 16);
-  if (Npix != 1) {
-    free (matrix);
-  }
+  SendGraphCommand (Ximage, 16, "DONE"); 
+
+  if (Npix != 1) free (matrix);
   fprintf (stderr, "\n");
   return (TRUE);
Index: trunk/Ohana/src/opihi/cmd.data/tvgrid.c
===================================================================
--- trunk/Ohana/src/opihi/cmd.data/tvgrid.c	(revision 3692)
+++ trunk/Ohana/src/opihi/cmd.data/tvgrid.c	(revision 3693)
@@ -51,7 +51,6 @@
   
   /* tell KII to expect overlay data */
-  write (Ximage, "LOAD", 4); 
-  sprintf (buffer, "OVERLAY: %7d", ncolor);
-  write (Ximage, buffer, 16);
+  SendGraphCommand (Ximage, 4, "LOAD"); 
+  SendGraphCommand (Ximage, 16, "OVERLAY: %7d", ncolor);
   
   dDEC = fabs(dec1 - dec0);
@@ -84,11 +83,4 @@
   NY = buf[0].header.Naxis[1];
 
-    /* find starting position
-    RD_to_XY (&x0, &y0, MIN(ra0, ra1), dec + 0.1*dDEC, &coords);
-    sprintf (label, format, dec);
-    sprintf (buffer, "%15s %20.10f %20.10f %20.10f %20.10f ", "TEXT", x0, y0, (double)(strlen(label) + 1), 0.0);
-    write (Ximage, buffer, 128);
-    write (Ximage, label, strlen(label) + 1); */
-
   dRA = MAX (fabs(ra1 - ra0) / 100.0, 0.1);
   connect = FALSE;
@@ -97,13 +89,9 @@
       RD_to_XY (&x1, &y1, ra, dec, &coords);
       if ((x1 >= 0) && (x1 < NX) && (y1 >= 0) && (y1 < NY)) {
-	if (connect) {
-	  sprintf (buffer, "%15s %20.10f %20.10f %20.10f %20.10f ", "LINE", x0, y0, (x1 - x0), (y1 - y0));
-	  write (Ximage, buffer, 128);
-	}
+	if (connect) SendGraphCommand (Ximage, 128, "%15s %20.10f %20.10f %20.10f %20.10f ", "LINE", x0, y0, (x1 - x0), (y1 - y0));
 	x0 = x1;
 	y0 = y1;
 	connect = TRUE;
-      }
-      else {
+      } else {
 	connect = FALSE;
       }
@@ -143,13 +131,9 @@
       RD_to_XY (&x1, &y1, ra, dec, &coords);
       if ((x1 >= 0) && (x1 < NX) && (y1 >= 0) && (y1 < NY)) {
-	if (connect) {
-	  sprintf (buffer, "%15s %20.10f %20.10f %20.10f %20.10f ", "LINE", x0, y0, (x1 - x0), (y1 - y0));
-	  write (Ximage, buffer, 128);
-	}
+	if (connect) SendGraphCommand (Ximage, 128, "%15s %20.10f %20.10f %20.10f %20.10f ", "LINE", x0, y0, (x1 - x0), (y1 - y0));
 	x0 = x1;
 	y0 = y1;
 	connect = TRUE;
-      }
-      else {
+      } else {
 	connect = FALSE;
       }
@@ -176,11 +160,7 @@
   */
 
-  sprintf (buffer, "DONE");
-  write (Ximage, buffer, 128);
+  SendGraphCommand (Ximage, 128, "DONE");
   return (TRUE);
 }
-
-
-  
 
 /*
Index: trunk/Ohana/src/opihi/cmd.data/vcontour.c
===================================================================
--- trunk/Ohana/src/opihi/cmd.data/vcontour.c	(revision 3692)
+++ trunk/Ohana/src/opihi/cmd.data/vcontour.c	(revision 3693)
@@ -45,6 +45,5 @@
 Nline ++; \
 if (Nline == 512) { \
-  sprintf (line, "NLINES  %7d \0", Nline); \
-  write (Ximage, line, 16); \
+  SendGraphCommand (Ximage, 16, "NLINES  %7d \0", Nline); \
   write (Ximage, buffer, Nline*128); \
   bzero (buffer, 65536); \
@@ -57,6 +56,5 @@
 Nline ++; \
 if (Nline == 512) { \
-  sprintf (line, "NLINES  %7d \0", Nline); \
-  write (Ximage, line, 16); \
+  SendGraphCommand (Ximage, 16, "NLINES  %7d \0", Nline); \
   write (Ximage, buffer, Nline*128); \
   bzero (buffer, 65536); \
@@ -263,15 +261,11 @@
   
   if (Nline > 0) {
-    sprintf (line, "NLINES  %7d \0", Nline); 
-    write (Ximage, line, 16); 
+    SendGraphCommand (Ximage, 16, "NLINES  %7d \0", Nline); 
     write (Ximage, buffer, Nline*128); 
   }
 
   free (buffer);
-  sprintf (line, "DONE \0");
-  write (Ximage, line, 16);
-  if (Npix != 1) {
-    free (matrix);
-  }
+  SendGraphCommand (Ximage, 16, "DONE");
+  if (Npix != 1) free (matrix);
   fprintf (stderr, "\n");
 }
Index: trunk/Ohana/src/opihi/cmd.data/vload.c
===================================================================
--- trunk/Ohana/src/opihi/cmd.data/vload.c	(revision 3692)
+++ trunk/Ohana/src/opihi/cmd.data/vload.c	(revision 3693)
@@ -6,5 +6,5 @@
   int Ximage, Nimage;
   double dx, dy;
-  char *buffer, *line;
+  char *buffer;
   Vector *vecx, *vecy;
   
@@ -33,13 +33,10 @@
   ALLOCATE (buffer, char, 65536);  /* space for 512 lines of 128 bytes */
   bzero (buffer, 65536);
-  ALLOCATE (line, char, 1024);     /* space to read the file */
   Nline = 0;
 
-  write (Ximage, "LOAD", 4); /* force Ximage to look for the incoming image */
-  sprintf (line, "OVER %9d ", n);
-  write (Ximage, line, 16);
-  
+  SendGraphCommand (Ximage, 4, "LOAD");
+  SendGraphCommand (Ximage, 16, "OVER %9d ", n);
+
   dx = dy = 1.0;
-
   for (i = 0; i < vecx[0].Nelements; i++) {
     snprintf (&buffer[Nline*128], 128, "%15s %20.10f %20.10f %20.10f %20.10f ", "BOX", 
@@ -47,6 +44,5 @@
     Nline ++;
     if (Nline == 512) {
-      sprintf (line, "NLINES  %7d ", Nline);
-      write (Ximage, line, 16);
+      SendGraphCommand (Ximage, 16, "NLINES  %7d ", Nline);
       write (Ximage, buffer, Nline*128);
       bzero (buffer, 65536);
@@ -55,12 +51,9 @@
   }
 
-  sprintf (line, "NLINES  %7d ", Nline);
-  write (Ximage, line, 16);
+  SendGraphCommand (Ximage, 16, "NLINES  %7d ", Nline);
   write (Ximage, buffer, Nline*128);
-  sprintf (line, "DONE ");
-  write (Ximage, line, 16);
+  SendGraphCommand (Ximage, 16, "DONE");
 
   free (buffer);
-  free (line);
   fprintf (stderr, "loaded %d objects\n", n);
 
