Index: /trunk/Ohana/src/opihi/cmd.astro/gauss.c
===================================================================
--- /trunk/Ohana/src/opihi/cmd.astro/gauss.c	(revision 3692)
+++ /trunk/Ohana/src/opihi/cmd.astro/gauss.c	(revision 3693)
@@ -51,5 +51,5 @@
 
   fcntl (Ximage, F_SETFL, !O_NONBLOCK);  
-  write (Ximage, "CURS", 4); /* ask Ximage to look for the keystrokes */
+  SendGraphCommand (Ximage, 4, "CURS");
   
   for (i = 0; (i < Nspot) || (Nspot == 0); i++) {
@@ -64,5 +64,6 @@
     
   }
-  write (Ximage, "NCUR", 4); /* tell Ximage "end of keystrokes" */
+  SendGraphCommand (Ximage, 4, "NCUR");
+
   return (TRUE);
 }
Index: /trunk/Ohana/src/opihi/cmd.astro/objload.c
===================================================================
--- /trunk/Ohana/src/opihi/cmd.astro/objload.c	(revision 3692)
+++ /trunk/Ohana/src/opihi/cmd.astro/objload.c	(revision 3693)
@@ -66,8 +66,8 @@
   free (buffer);
 
-  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);
   
+  /** NOTE: modify to use NBYTE **/
   ALLOCATE (buffer, char, 66000);
   bzero (buffer, 65536);
@@ -75,6 +75,5 @@
     snprintf (&buffer[Nout*128], 129, "%15s %20.10f %20.10f %20.10f %20.10f ", "BOX", X[i], Y[i], 5.0, 5.0);
     if (Nout == 512) {
-      sprintf (line, "NLINES  %7d ", Nout);
-      write (Ximage, line, 16);
+      SendGraphCommand (Ximage, 16, "NLINES  %7d ", Nout);
       write (Ximage, buffer, Nout*128);
       bzero (buffer, 65536);
@@ -84,10 +83,8 @@
 
   if (Nout) {
-    sprintf (line, "NLINES  %7d ", Nout);
-    write (Ximage, line, 16);
+    SendGraphCommand (Ximage, 16, "NLINES  %7d ", Nout);
     write (Ximage, buffer, Nout*128);
   }
-  sprintf (line, "DONE ");
-  write (Ximage, line, 16);
+  SendGraphCommand (Ximage, 16, "DONE");
 
   free (X);
Index: /trunk/Ohana/src/opihi/cmd.astro/outline.c
===================================================================
--- /trunk/Ohana/src/opihi/cmd.astro/outline.c	(revision 3692)
+++ /trunk/Ohana/src/opihi/cmd.astro/outline.c	(revision 3693)
@@ -158,7 +158,6 @@
       Nline = 0;
       
-      write (Ximage, "LOAD", 4); /* force Ximage to look for the incoming image */
-      sprintf (line, "OVER %9d ", 0);
-      write (Ximage, line, 16);
+      SendGraphCommand (Ximage, 4, "LOAD");
+      SendGraphCommand (Ximage, 16, "OVER %9d ", 0);
       
       dx = par[2];
@@ -178,6 +177,5 @@
 	
 	if (Nline >= 510) {
-	  sprintf (line, "NLINES  %7d ", Nline);
-	  write (Ximage, line, 16);
+	  SendGraphCommand (Ximage, 16, "NLINES  %7d ", Nline);
 	  write (Ximage, buffer, Nline*128);
 	  bzero (buffer, 65536);
@@ -185,10 +183,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);
Index: /trunk/Ohana/src/opihi/cmd.astro/outline2.c
===================================================================
--- /trunk/Ohana/src/opihi/cmd.astro/outline2.c	(revision 3692)
+++ /trunk/Ohana/src/opihi/cmd.astro/outline2.c	(revision 3693)
@@ -316,7 +316,6 @@
   Nline = 0;
   
-  write (Ximage, "LOAD", 4); /* force Ximage to look for the incoming image */
-  sprintf (line, "OVER %9d ", 0);
-  write (Ximage, line, 16);
+  SendGraphCommand (Ximage, 4, "LOAD");
+  SendGraphCommand (Ximage, 16, "OVER %9d ", 0);
   
   dx = par[2];
@@ -336,6 +335,5 @@
     
     if (Nline >= 510) {
-      sprintf (line, "NLINES  %7d ", Nline);
-      write (Ximage, line, 16);
+      SendGraphCommand (Ximage, 16, "NLINES  %7d ", Nline);
       write (Ximage, buffer, Nline*128);
       bzero (buffer, 65536);
@@ -344,9 +342,8 @@
   }
   
-  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);
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);
 
Index: /trunk/Ohana/src/opihi/dvo/cmpload.c
===================================================================
--- /trunk/Ohana/src/opihi/dvo/cmpload.c	(revision 3692)
+++ /trunk/Ohana/src/opihi/dvo/cmpload.c	(revision 3693)
@@ -12,7 +12,7 @@
   double dtmp;
   FILE *f;
-  char *buffer, *buffer2, *line;
+  char *buffer, *buffer2;
+  int Ximage, Nimage;
   Header header;
-  int Ximage, Nimage;
   
   Nimage = -1;
@@ -121,16 +121,13 @@
   fclose (f);
 
-  ALLOCATE (line, char, 129);
-  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);
   ALLOCATE (buffer2, char, 66000);
   bzero (buffer2, 65536);
+
   for (Nout = i = 0; i < Nin; i++, Nout++) {
     sprintf (&buffer2[Nout*128], "%15s %20.10f %20.10f %20.10f %20.10f ", "BOX", X[i], Y[i], 5.0, 5.0);
     if (Nout == 512) {
-      sprintf (line, "NLINES  %7d ", Nout);
-      write (Ximage, line, 16);
+      SendGraphCommand (Ximage, 16, "NLINES  %7d ", Nout);
       write (Ximage, buffer2, Nout*128);
       bzero (buffer2, 65536);
@@ -140,10 +137,8 @@
 
   if (Nout) {
-    sprintf (line, "NLINES  %7d ", Nout);
-    write (Ximage, line, 16);
+    SendGraphCommand (Ximage, 16, "NLINES  %7d ", Nout);
     write (Ximage, buffer2, Nout*128);
   }
-  sprintf (line, "DONE ");
-  write (Ximage, line, 16);
+  SendGraphCommand (Ximage, 16, "DONE");
 
   fits_free_header (&header);
@@ -152,8 +147,5 @@
   free (M);
   free (buffer);
-  /*  */
-
   free (buffer2);
-  free (line);
 
   fprintf (stderr, "loaded %d objects\n", Nin);
Index: /trunk/Ohana/src/opihi/lib.data/graphtools.c
===================================================================
--- /trunk/Ohana/src/opihi/lib.data/graphtools.c	(revision 3692)
+++ /trunk/Ohana/src/opihi/lib.data/graphtools.c	(revision 3693)
@@ -47,9 +47,5 @@
   if (!apply) return;
 
-  write (Xgraph, "SLIM", 4);
-  sprintf (buffer, "%g %g %g %g ", graphmode[0].xmin, graphmode[0].xmax, graphmode[0].ymin, graphmode[0].ymax);
-  sprintf (buffer2, "NBYTES: %6d ", strlen (buffer));
-  write (Xgraph, buffer2, 16);
-  write (Xgraph, buffer, strlen (buffer));
+  SendGraphCommand (Xgraph, 4, "SLIM");
+  SendGraphMessage (Xgraph, "%g %g %g %g ", graphmode[0].xmin, graphmode[0].xmax, graphmode[0].ymin, graphmode[0].ymax);
 }
-
Index: /trunk/Ohana/src/opihi/lib.data/open_graph.c
===================================================================
--- /trunk/Ohana/src/opihi/lib.data/open_graph.c	(revision 3692)
+++ /trunk/Ohana/src/opihi/lib.data/open_graph.c	(revision 3693)
@@ -294,4 +294,5 @@
   memset (string, 0, length + 1);
   vsnprintf (string, length + 1, format, argp);
+
   /* fprintf (stderr, "msg: %s\n", string); */
   write (device, string, length);
Index: /trunk/Ohana/src/opihi/lib.data/open_image.c
===================================================================
--- /trunk/Ohana/src/opihi/lib.data/open_image.c	(revision 3692)
+++ /trunk/Ohana/src/opihi/lib.data/open_image.c	(revision 3693)
@@ -19,5 +19,5 @@
   for (i = 0; i < NXIMAGE; i++) {
     if (Ximage[i] > 0) {
-      write (Ximage[i], "QUIT", 4);
+      SendGraphCommand (Ximage[i], 4, "QUIT");
     }
   }
