Index: trunk/Ohana/src/opihi/cmd.data/box.c
===================================================================
--- trunk/Ohana/src/opihi/cmd.data/box.c	(revision 3687)
+++ trunk/Ohana/src/opihi/cmd.data/box.c	(revision 3692)
@@ -51,16 +51,7 @@
   if (argc != 1) goto usage;
 
-  write (Xgraph, "DBOX", 4);
-
-  snprintf (buffer, 64, "%12.6g %12.6g %12.6g %12.6g", graphmode.xmin, graphmode.xmax, graphmode.ymin, graphmode.ymax);
-  snprintf (buffer2, 64, "NBYTES: %6d", strlen (buffer));
-  write (Xgraph, buffer2, 16);
-  write (Xgraph, buffer, strlen (buffer));
-  
-  snprintf (buffer, 64, "%s %s %s", Axis, Labels, Ticks);
-  snprintf (buffer2, 64, "NBYTES: %6d", strlen (buffer));
-  write (Xgraph, buffer2, 16);
-  write (Xgraph, buffer, strlen (buffer));
-  
+  SendGraphCommand (Xgraph, 4, "DBOX");
+  SendGraphMessage (Xgraph, "%12.6g %12.6g %12.6g %12.6g", graphmode.xmin, graphmode.xmax, graphmode.ymin, graphmode.ymax);
+  SendGraphMessage (Xgraph, "%s %s %s", Axis, Labels, Ticks);
   return (TRUE);
       
@@ -68,5 +59,4 @@
   fprintf (stderr, "USAGE: box [-ticks NNNN] [-axis NNNN] [-labels NNNN]\n");
   return (FALSE);
-
 }
 
Index: trunk/Ohana/src/opihi/cmd.data/clear.c
===================================================================
--- trunk/Ohana/src/opihi/cmd.data/clear.c	(revision 3687)
+++ trunk/Ohana/src/opihi/cmd.data/clear.c	(revision 3692)
@@ -26,11 +26,8 @@
 
   if (ClearSection) {
-    write (Xgraph, "ERAS", 4);
+    SendGraphCommand (Xgraph, 4, "ERAS");
   } else {
-    write (Xgraph, "ERSS", 4);
+    SendGraphCommand (Xgraph, 4, "ERSS");
   }
-  
   return (TRUE);
-  
 }
-
Index: trunk/Ohana/src/opihi/cmd.data/labels.c
===================================================================
--- trunk/Ohana/src/opihi/cmd.data/labels.c	(revision 3687)
+++ trunk/Ohana/src/opihi/cmd.data/labels.c	(revision 3692)
@@ -3,5 +3,5 @@
 int labels (int argc, char **argv) {
   
-  char name[64], buffer[32];
+  char name[64];
   int N, size, Xgraph;
 
@@ -36,9 +36,7 @@
     size = atof (argv[N]);
     remove_argument (N, &argc, argv);
-    write (Xgraph, "FONT", 4);
-    sprintf (buffer, "%s", name);
-    write (Xgraph, buffer, 16);
-    sprintf (buffer, "%d", size);
-    write (Xgraph, buffer, 16);
+    SendGraphCommand (Xgraph, 4, "FONT");
+    SendGraphCommand (Xgraph, 16, "%s", name);
+    SendGraphCommand (Xgraph, 16, "%d", size);
   } 
 
Index: trunk/Ohana/src/opihi/cmd.data/ps.c
===================================================================
--- trunk/Ohana/src/opihi/cmd.data/ps.c	(revision 3687)
+++ trunk/Ohana/src/opihi/cmd.data/ps.c	(revision 3692)
@@ -55,7 +55,11 @@
   }
   
-  if (RawImage) write (Source, "PSRW", 4); /* tell Ximage to ps the image */
-  if (NoScale)  write (Source, "PSNS", 4); /* tell Ximage to ps the image */
-  if (!RawImage && !NoScale) write (Source, "PSIT", 4); /* tell Ximage to ps the image */
+  /* tell Ximage/Xgraph to ps the image */
+  if (RawImage) SendGraphCommand (Source, 4, "PSRW"); 
+  if (NoScale)  SendGraphCommand (Source, 4, "PSNS");
+  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));
Index: trunk/Ohana/src/opihi/cmd.data/section.c
===================================================================
--- trunk/Ohana/src/opihi/cmd.data/section.c	(revision 3687)
+++ trunk/Ohana/src/opihi/cmd.data/section.c	(revision 3692)
@@ -24,9 +24,6 @@
   if (argc == 1) {
     /* list section */
-    write (Xgraph, "LSEC", 4);
-    sprintf (buffer, "* %s", argv[1]);
-    sprintf (buffer2, "NBYTES: %6d ", strlen (buffer));
-    write (Xgraph, buffer2, 16);
-    write (Xgraph, buffer, strlen (buffer));
+    SendGraphCommand (Xgraph, 4, "LSEC");
+    SendGraphMessage (Xgraph, "* %s", argv[1]);
     fprintf (stderr, "USAGE: section name [x y dx dy]\n");
     return (TRUE);
@@ -36,12 +33,9 @@
     /* set section */
     if (List) {
-      write (Xgraph, "LSEC", 4);
+      SendGraphCommand (Xgraph, 4, "LSEC");
     } else {
-      write (Xgraph, "SSEC", 4);
+      SendGraphCommand (Xgraph, 4, "SSEC");
     }
-    sprintf (buffer, "%s", argv[1]);
-    sprintf (buffer2, "NBYTES: %6d ", strlen (buffer));
-    write (Xgraph, buffer2, 16);
-    write (Xgraph, buffer, strlen (buffer));
+    SendGraphMessage (Xgraph, "%s", argv[1]);
     return (TRUE);
   } 
@@ -49,15 +43,10 @@
   if (argc == 6) {
     /* define section */
-    write (Xgraph, "DSEC", 4);
-    snprintf (buffer, 65, "%s %6.3f %6.3f %6.3f %6.3f", argv[1], atof (argv[2]), atof (argv[3]), atof (argv[4]), atof (argv[5]));
-    snprintf (buffer2, 65, "NBYTES: %6d ", strlen (buffer));
-    write (Xgraph, buffer2, 16);
-    write (Xgraph, buffer, strlen (buffer));
+    SendGraphCommand (Xgraph, 4, "DSEC");
+    SendGraphMessage (Xgraph, "%s %6.3f %6.3f %6.3f %6.3f", argv[1], atof (argv[2]), atof (argv[3]), atof (argv[4]), atof (argv[5]));
     return (TRUE);
   }
-      
   fprintf (stderr, "USAGE: section name [x y dx dy]\n");
   return (FALSE);
-  
 }
 
Index: trunk/Ohana/src/opihi/cmd.data/textline.c
===================================================================
--- trunk/Ohana/src/opihi/cmd.data/textline.c	(revision 3687)
+++ trunk/Ohana/src/opihi/cmd.data/textline.c	(revision 3692)
@@ -23,9 +23,7 @@
     size = atof (argv[N]);
     remove_argument (N, &argc, argv);
-    write (Xgraph, "FONT", 4);
-    sprintf (buffer, "%s", name);
-    write (Xgraph, buffer, 16);
-    sprintf (buffer, "%d", size);
-    write (Xgraph, buffer, 16);
+    SendGraphCommand (Xgraph, 4, "FONT");
+    SendGraphCommand (Xgraph, 16, "%s", name);
+    SendGraphCommand (Xgraph, 16, "%d", size);
   } 
 
@@ -62,17 +60,10 @@
   }    
 
-  write (Xgraph, "PTXT", 4);
-  sprintf (buffer, "%f", x);
-  write (Xgraph, buffer, 16);
-  sprintf (buffer, "%f", y);
-  write (Xgraph, buffer, 16);
-  sprintf (buffer, "%f", angle);
-  write (Xgraph, buffer, 16);
-
-  bzero (buffer, 128);
-  strcpy (buffer, argv[3]);
-  write (Xgraph, buffer, 128);
-
+  /* WARNING: this is a bit dangerous - convert to SendGraphMessage format */
+  SendGraphCommand (Xgraph, 4, "PTXT");
+  SendGraphCommand (Xgraph, 16, "%f", x);
+  SendGraphCommand (Xgraph, 16, "%f", y);
+  SendGraphCommand (Xgraph, 16, "%f", angle);
+  SendGraphCommand (Xgraph, 128, "%s", argv[3]);
   return (TRUE);
 }
-  
Index: trunk/Ohana/src/opihi/cmd.data/tv.c
===================================================================
--- trunk/Ohana/src/opihi/cmd.data/tv.c	(revision 3687)
+++ trunk/Ohana/src/opihi/cmd.data/tv.c	(revision 3692)
@@ -7,5 +7,5 @@
   double a1, a2, max, min, zero, range;
   float *in;
-  char *out, *outbuffer, *p, *tmpstring;
+  char *out, *outbuffer, *root;
   int Ximage, Nimage;
   Coords coords;
@@ -56,5 +56,5 @@
   out = outbuffer;
 
-  status = write (Ximage, "READ", 4); /* tell Ximage to look for the incoming image */
+  SendGraphCommand (Ximage, 4, "READ"); /* tell Ximage to look for the incoming image */
 
   /* convert from (float) internal rep to 1 byte chars -- depends on how many colors Kii owns*/
@@ -81,36 +81,13 @@
   
   /* done with the conversion, now send Ximage the converted picture */
-  sprintf (buffer, "%8d %8d 8 1 %f %f ", buf[0].matrix.Naxis[0], buf[0].matrix.Naxis[1], 0.0, 1.0);
-  sprintf (buffer2, "NBYTES: %6d ", strlen (buffer));
-  write (Ximage, buffer2, 16);
-  write (Ximage, buffer, strlen (buffer));
-  
-  sprintf (buffer, "%f %f %f %f %d ", zero, range, min, max, size);
-  sprintf (buffer2, "NBYTES: %6d ", strlen (buffer));
-  write (Ximage, buffer2, 16);
-  write (Ximage, buffer, strlen (buffer));
+  SendGraphMessage (Ximage, "%8d %8d 8 1 %f %f", buf[0].matrix.Naxis[0], buf[0].matrix.Naxis[1], 0.0, 1.0);
+  SendGraphMessage (Ximage, "%f %f %f %f %d ", zero, range, min, max, size);
+  SendGraphMessage (Ximage, "%f %f %g %g %g ", coords.crval1, coords.crpix1, coords.cdelt1, coords.pc1_1, coords.pc1_2);
+  SendGraphMessage (Ximage, "%f %f %g %g %g ", coords.crval2, coords.crpix2, coords.cdelt2, coords.pc2_1, coords.pc2_2);
 
-  sprintf (buffer, "%f %f %g %g %g ", coords.crval1, coords.crpix1, coords.cdelt1, coords.pc1_1, coords.pc1_2);
-  sprintf (buffer2, "NBYTES: %6d ", strlen (buffer));
-  write (Ximage, buffer2, 16);
-  write (Ximage, buffer, strlen (buffer));
-
-  sprintf (buffer, "%f %f %g %g %g ", coords.crval2, coords.crpix2, coords.cdelt2, coords.pc2_1, coords.pc2_2);
-  sprintf (buffer2, "NBYTES: %6d ", strlen (buffer));
-  write (Ximage, buffer2, 16);
-  write (Ximage, buffer, strlen (buffer));
-
-  p = strrchr (buf[0].file, '/');
-  if (p == (char *) NULL) p = buf[0].file;
-  else p++;
-  tmpstring = strcreate (p);
-  sprintf (buffer, "%s %s %s ", coords.ctype, tmpstring, buf[0].name);
-  free (tmpstring);
-  sprintf (buffer2, "NBYTES: %6d ", strlen (buffer));
-  write (Ximage, buffer2, 16);
-  write (Ximage, buffer, strlen (buffer));
+  root = filerootname (buf[0].file);
+  SendGraphMessage (Ximage, "%s %s %s ", coords.ctype, root, buf[0].name);
 
   write (Ximage, outbuffer, size);
-
   free (outbuffer);
 
@@ -118,5 +95,4 @@
   set_str_variable ("TV", argv[1]);
   return (TRUE);
-
 }
 
