Index: trunk/Ohana/src/opihi/cmd.data/tv.c
===================================================================
--- trunk/Ohana/src/opihi/cmd.data/tv.c	(revision 4689)
+++ trunk/Ohana/src/opihi/cmd.data/tv.c	(revision 5846)
@@ -3,12 +3,9 @@
 int tv (int argc, char **argv) {
   
-  int N, j, Npix, Ncolors, size, ISLOG, NNcol;
-  char buffer[1024];
-  double a1, a2, max, min, zero, range;
-  float *in;
-  char *out, *outbuffer, *root;
-  int Ximage, Nimage;
+  int N, Ximage, Nimage;
   Coords coords;
   Buffer *buf;
+  KiiImage image;
+  KiiDisplayMode mode;
 
   Nimage = -1;
@@ -22,14 +19,13 @@
   /* shell exits on pipe close, FIX */
   if ((N = get_argument (argc, argv, "-kill"))) {
-    close (Ximage);
+    KiiClose (Ximage);
     Ximage = 0;
     return (TRUE);
   }
 
-  min = max = 0.0;
-  ISLOG = FALSE;
+  mode.logflux = FALSE;
   if ((N = get_argument (argc, argv, "-log"))) {
     remove_argument (N, &argc, argv);
-    ISLOG = TRUE;
+    mode.logflux = TRUE;
   }
 
@@ -39,55 +35,22 @@
   }
 
-  GetImageScale (&zero, &range);
+  GetImageScale (&mode.zero, &mode.range);
   if (argc == 4) {
-    zero = atof (argv[2]);
-    range = atof (argv[3]);
-    if (range == 0.0) range = 0.001;
-    SetImageScale (zero, range);
+    mode.zero = atof (argv[2]);
+    mode.range = atof (argv[3]);
+    if (mode.range == 0.0) mode.range = 0.001;
+    SetImageScale (mode.zero, mode.range);
   }
 
   if ((buf = SelectBuffer (argv[1], OLDBUFFER, TRUE)) == NULL) return (FALSE);
   GetCoords (&coords, &buf[0].header);
+  
+  image.data1d = (float *) buf[0].matrix.buffer;
+  image.Nx = buf[0].matrix.Naxis[0];
+  image.Ny = buf[0].matrix.Naxis[1];
+  image.file = buf[0].file;
+  image.name = buf[0].name;
 
-  Npix = buf[0].matrix.Naxis[0]*buf[0].matrix.Naxis[1];
-  size = Npix * sizeof (char);
-  in = (float *) (buf[0].matrix.buffer);
-  ALLOCATE (outbuffer, char, Npix);
-  out = outbuffer;
-
-  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*/
-  read (Ximage, buffer, 16); 
-  sscanf (buffer, "%*s %d", &Ncolors); 
-
-  /* need to invert the logic if range < 0 */
-  /* define color table, */
-  NNcol = Ncolors - 1;
-  if (ISLOG) {
-    range = MAX (2, range);
-    a1 = Ncolors / log10 (range);
-    for (j = 0; j < Npix; j++, in++, out++) {
-      *out = (char) MIN (a1 * log10 (MAX (*in - zero, 1.0)), NNcol);
-    }
-  }
-  if (!ISLOG) {
-    a1 = Ncolors / range;
-    a2 = Ncolors * zero / range;
-    for (j = 0; j < Npix; j++, in++, out++) {
-      *out = (char) MIN (MAX (a1 * *in - a2, 0), NNcol);
-    }
-  }
-  
-  /* done with the conversion, now send Ximage the converted picture */
-  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);
-
-  root = filerootname (buf[0].file);
-  SendGraphMessage (Ximage, "%s %s %s ", coords.ctype, root, buf[0].name);
-  write (Ximage, outbuffer, size);
-  free (outbuffer);
+  KiiNewPicture1D (Ximage, &image, &mode, &coords);
 
   SetImageName (argv[1]);
