Index: trunk/Ohana/src/relphot/include/relphot.h
===================================================================
--- trunk/Ohana/src/relphot/include/relphot.h	(revision 5997)
+++ trunk/Ohana/src/relphot/include/relphot.h	(revision 5998)
@@ -1,4 +1,5 @@
 # include <ohana.h>
 # include <dvo.h>
+# include <kapa.h>
 # include <signal.h>
 
@@ -6,4 +7,5 @@
 # define GRID_V2
 
+# if (0)
 typedef struct {
   double xmin, xmax, ymin, ymax;
@@ -11,4 +13,5 @@
   double lweight, size;
 } Graphdata;
+# endif
 
 typedef struct {
Index: trunk/Ohana/src/relphot/src/plotstuff.c
===================================================================
--- trunk/Ohana/src/relphot/src/plotstuff.c	(revision 5997)
+++ trunk/Ohana/src/relphot/src/plotstuff.c	(revision 5998)
@@ -21,89 +21,36 @@
 int open_graph (int N) {
 
-# ifdef ANSI
-#   define F_SETFL      4   
-#   define O_NONBLOCK 0200000  
-#   define       AF_UNIX         1          
-#   define       SOCK_STREAM     1          
-#define ENOENT          2       /* No such file or directory    */
-# endif /* ANSI */
+  int fd;
 
-  int InitSocket, status, addreslen;
-  struct sockaddr_un Address;
-  char temp[100];
-  char socket_name[100];
-  
-  active = N;
-  sprintf (socket_name, "/tmp/kapa%d", N);
-  sprintf (temp, "rm -f %s", socket_name);
-  system (temp);
-    
-  strcpy (Address.sun_path, socket_name); 
-  Address.sun_family = AF_UNIX; 
-  InitSocket = socket (AF_UNIX, SOCK_STREAM, 0); 
-  status = bind (InitSocket, (struct sockaddr *) &Address, sizeof (Address));
-  status = listen (InitSocket, 1);
-  
-  sprintf (temp, "kapa %s &", socket_name);
-# ifndef DEBUG
-  system (temp);
-# else  
-  fprintf (stderr, "start kapa, press return: %s\n", temp);
-  fscanf (stdin, "%d", &i);
-# endif
-  
-  addreslen =  sizeof (Address);
-  Xgraph[N] = accept (InitSocket, (struct sockaddr *) &Address, &addreslen);
+  Xgraph[N] = KiiOpen ("kapa", NULL);
   if (Xgraph[N] < 0) {
     fprintf (stderr, "error starting kapa\n");
     return (FALSE);
   }
-  else {
-    return (TRUE);
-  }
-  
+  return (TRUE);
 }
 
 void DonePlotting (Graphdata *graphmode, int N) {
-  char buffer[65], buffer2[65];
 
   if (Xgraph[N] == 0) return;
 
-  write (Xgraph[N], "DBOX", 4);
-  sprintf (buffer, "%f %f %f %f", graphmode[0].xmin, graphmode[0].xmax, graphmode[0].ymin, graphmode[0].ymax);
-  sprintf (buffer2, "NBYTES: %6d", (int) strlen (buffer));
-  write (Xgraph[N], buffer2, 16);
-  write (Xgraph[N], buffer, strlen (buffer));
-
-  sprintf (buffer, "%s %s %s", "2222", "2222", "2222");
-  sprintf (buffer2, "NBYTES: %6d", (int) strlen (buffer));
-  write (Xgraph[N], buffer2, 16);
-  write (Xgraph[N], buffer, strlen (buffer));
+  KapaBox (Xgraph[N], graphmode);
+  return;
 }
 
 void JpegPlot (Graphdata *graphmode, int N, char *filename) {
 
-  char buffer[65];
-
   if (Xgraph[N] == 0) return;
 
-  write (Xgraph[N], "PNGF", 4);
-  sprintf (buffer, "LEN: %11d", (int) strlen (filename));
-  write (Xgraph[N], buffer, 16);
-  write (Xgraph[N], filename, strlen (filename));
-  read (Xgraph[N], buffer, 4);
+  KapaPNG (Xgraph[N], filename);
+  return;
 }
 
 void PSPlot (Graphdata *graphmode, int N, char *filename) {
 
-  char buffer[65];
-
   if (Xgraph[N] == 0) return;
 
-  write (Xgraph[N], "PSIT", 4);
-  sprintf (buffer, "LEN: %11d", (int) strlen (filename));
-  write (Xgraph[N], buffer, 16);
-  write (Xgraph[N], filename, strlen (filename));
-  read (Xgraph[N], buffer, 4);
+  KiiPS (Xgraph[N], FALSE, FALSE, filename);
+  return;
 }
 
@@ -113,49 +60,30 @@
   char buffer[128], buffer2[128];
 
-  active = N;
   if (Npts < 1) return;
 
   if (Xgraph[N] < 1) if (!open_graph(N)) return;
 
-  /* test Xgraph[N], flush junk from pipe */
-  signal (SIGPIPE, XDead);
-  fcntl (Xgraph[N], F_SETFL,  O_NONBLOCK); 
-  for (i = 0; (read (Xgraph[N], buffer, 64) > 0) && (i < 20); i++);
-  fcntl (Xgraph[N], F_SETFL, !O_NONBLOCK); 
+  KapaClear (Xgraph[N], TRUE);
+
+  KiiSendCommand (Xgraph[N], 4, "PLOT");
   
-  write (Xgraph[N], "ERAS", 4);
-  
-  /* tell kapa to look for the incoming image */
-  status = write (Xgraph[N], "PLOT", 4); 
+  /* send Xgraph the plot details */
+  KiiSendMessage (Xgraph[N], "%8d %8d %d %d %d %d %d %f %f", 
+		  Npts, graphmode[0].style, 
+		  graphmode[0].ptype, graphmode[0].ltype, 
+		  graphmode[0].etype, graphmode[0].ebar, graphmode[0].color, 
+		  graphmode[0].lweight, graphmode[0].size);
+  KiiSendMessage (Xgraph[N], "%g %g %g %g", 
+		  graphmode[0].xmin, graphmode[0].xmax, 
+		  graphmode[0].ymin, graphmode[0].ymax);
 
-  /* send Xgraph[N] the plot details */
-  sprintf (buffer, "%8d %8d %d %d %d %d %f %f", 
-	   Npts, graphmode[0].style, 
-	   graphmode[0].ptype, graphmode[0].ltype, 
-	   graphmode[0].etype, graphmode[0].color, 
-	   graphmode[0].lweight, graphmode[0].size);
-  sprintf (buffer2, "NBYTES: %6d", (int) strlen (buffer));
-  write (Xgraph[N], buffer2, 16);
-  write (Xgraph[N], buffer, strlen (buffer));
-  
-  sprintf (buffer, "%f %f %f %f", 
-	   graphmode[0].xmin, graphmode[0].xmax, 
-	   graphmode[0].ymin, graphmode[0].ymax);
-  sprintf (buffer2, "NBYTES: %6d", (int) strlen (buffer));
-  write (Xgraph[N], buffer2, 16);
-  write (Xgraph[N], buffer, strlen (buffer));
-
+  return;
 }
 
 void PlotLabel (char *string, int N) {
 
-  char buffer[32];
-
   if (Xgraph[N] == 0) return;
 
-  write (Xgraph[N], "LABL", 4);
-  sprintf (buffer, " %6d %6d", (int) strlen (string), 2);
-  write (Xgraph[N], buffer, 16);
-  write (Xgraph[N], string, strlen (string));
+  KapaSendLabel (Xgraph[N], string, 2);
 }
 
@@ -165,5 +93,4 @@
   int i, Nbytes;
 
-  active = N;
   if (Npts < 1) return;
 
@@ -176,5 +103,5 @@
   write (Xgraph[N], values, Nbytes);
   free (values);
-
+  return;
 }
 
