Index: /branches/kapa-mods-2007-05/Ohana/src/kapa2/src/CheckPipe.c
===================================================================
--- /branches/kapa-mods-2007-05/Ohana/src/kapa2/src/CheckPipe.c	(revision 13393)
+++ /branches/kapa-mods-2007-05/Ohana/src/kapa2/src/CheckPipe.c	(revision 13394)
@@ -22,4 +22,5 @@
     if (sock == -1) return (TRUE);
     close (InitSocket); /* stop listening on this socket */
+    fcntl (sock, F_SETFL, O_NONBLOCK);  
   }
 
Index: /branches/kapa-mods-2007-05/Ohana/src/kapa2/src/Image.c
===================================================================
--- /branches/kapa-mods-2007-05/Ohana/src/kapa2/src/Image.c	(revision 13393)
+++ /branches/kapa-mods-2007-05/Ohana/src/kapa2/src/Image.c	(revision 13394)
@@ -106,11 +106,4 @@
 	     image[0].picture.dx, image[0].picture.dy);
 
-  XPutImage (graphic[0].display, graphic[0].window, graphic[0].gc,
-	     image[0].cmapbar.pix, 0, 0, 
-	     image[0].cmapbar.x, image[0].cmapbar.y, 
-	     image[0].cmapbar.dx, image[0].cmapbar.dy);
-
-  CrossHairs (graphic, image);
-
   for (i = 0; i < NOVERLAYS; i++) {
     if (image[0].overlay[i].active) {
@@ -122,6 +115,12 @@
 # endif
 
-  // XXX make this optional?a
-  if (1) {
+  if (image[0].location) {
+    XPutImage (graphic[0].display, graphic[0].window, graphic[0].gc,
+	       image[0].cmapbar.pix, 0, 0, 
+	       image[0].cmapbar.x, image[0].cmapbar.y, 
+	       image[0].cmapbar.dx, image[0].cmapbar.dy);
+
+    CrossHairs (graphic, image);
+  
     /* erase everything below zoom box, then draw */
     XSetForeground (graphic[0].display, graphic[0].gc, graphic[0].back);
@@ -139,7 +138,6 @@
       DrawButton (graphic, &image[0].overlay_button[i]);
     }
+    StatusBox (graphic, image);
   }
-
-  StatusBox (graphic, image);
 
   FlushDisplay (graphic[0].display);
Index: /branches/kapa-mods-2007-05/Ohana/src/kapa2/src/LoadFrame.c
===================================================================
--- /branches/kapa-mods-2007-05/Ohana/src/kapa2/src/LoadFrame.c	(revision 13393)
+++ /branches/kapa-mods-2007-05/Ohana/src/kapa2/src/LoadFrame.c	(revision 13394)
@@ -62,4 +62,5 @@
   }
 
+  SetGraphSize (section);
   if (USE_XWINDOW) DrawFrame (graph);
   FlushDisplay ();
Index: /branches/kapa-mods-2007-05/Ohana/src/kapa2/src/Refresh.c
===================================================================
--- /branches/kapa-mods-2007-05/Ohana/src/kapa2/src/Refresh.c	(revision 13393)
+++ /branches/kapa-mods-2007-05/Ohana/src/kapa2/src/Refresh.c	(revision 13394)
@@ -21,6 +21,6 @@
   for (i = 0; i < Nsection; i++) {
       section = GetSectionByNumber (i);
+      DrawImage (section->image);
       DrawGraph (section->graph);
-      DrawImage (section->image);
   }
 
Index: /branches/kapa-mods-2007-05/Ohana/src/kapa2/src/SetImageSize.c
===================================================================
--- /branches/kapa-mods-2007-05/Ohana/src/kapa2/src/SetImageSize.c	(revision 13393)
+++ /branches/kapa-mods-2007-05/Ohana/src/kapa2/src/SetImageSize.c	(revision 13394)
@@ -7,4 +7,5 @@
 void SetImageSize (Section *section) {
 
+  int Xs, Ys, Xe, Ye, dX, dY;
   KapaImageWidget *image;
   Graphic *graphic;
@@ -16,54 +17,131 @@
   graphic = GetGraphic ();
 
-  image[0].cmapbar.dx = graphic[0].dx - 2*PAD1; 
-  image[0].cmapbar.dy = COLORPAD;
-  image[0].cmapbar.x = PAD1;
-  image[0].cmapbar.y = PAD1;
+  /* the image is placed within the graphic window in region specified by section */
+  Xs = graphic[0].dx * section[0].x;
+  Ys = graphic[0].dy * (1 - section[0].y - section[0].dy);
+  dX = graphic[0].dx * section[0].dx;
+  dY = graphic[0].dy * section[0].dy;
 
-  image[0].zoom.dx = ZOOM_X; 
-  image[0].zoom.dy = ZOOM_Y;
-  image[0].zoom.x = graphic[0].dx - PAD1 - ZOOM_X;
-  image[0].zoom.y = image[0].cmapbar.y + image[0].cmapbar.dy + PAD2;
+  // XXX make this user-setable
+  image[0].location = 0;
 
-  image[0].picture.dx = image[0].zoom.x - 2*PAD1 - 25; 
-  image[0].picture.dy = graphic[0].dy - 2*PAD1 - PAD2 - COLORPAD - 25;
-  image[0].picture.x = PAD1 + 25;
-  image[0].picture.y = PAD1 + PAD2 + COLORPAD;
+  switch (image[0].location) {
+    case 0:
+      image[0].picture.dx = dX - 2*PAD1; 
+      image[0].picture.dy = dY - 2*PAD1;
+      image[0].picture.x = Xs + PAD1;
+      image[0].picture.y = Ys + PAD1;
+      if (USE_XWINDOW) CreatePicture (image, graphic);
+      Remap (graphic, image, &image[0].matrix);
+      return;
 
-  /** everything below is tied in x-dir to the zoom box **/
-  image[0].text_x = image[0].zoom.x;
-  image[0].text_y = image[0].zoom.y + image[0].zoom.dy + PAD2;
+    case 4:
+      image[0].picture.dx = dX - 2*PAD1 - ZOOM_X; 
+      image[0].picture.dy = dY - 2*PAD1 - PAD2 - COLORPAD - 25;
+      image[0].picture.x = Xs + PAD1;
+      image[0].picture.y = Ys + PAD1 + PAD2 + COLORPAD;
 
-  /*  image[0].PS_button.y = graphic[0].dy - BUTTON_HEIGHT - PAD1; */
-  image[0].PS_button.x = image[0].zoom.x + 5;
-  image[0].PS_button.y = 2*ZOOM_Y;
+      image[0].cmapbar.dx = dX - 2*PAD1; 
+      image[0].cmapbar.dy = COLORPAD;
+      image[0].cmapbar.x = Xs + PAD1;
+      image[0].cmapbar.y = Ys + PAD1;
 
-  /** everything below is tied to the PS_button in y-dir **/
-  image[0].grey_button.x = image[0].PS_button.x + image[0].PS_button.dx + PAD1;
-  image[0].grey_button.y = image[0].PS_button.y;
+      // XXX zoom should scale somewhat with the image (with a min and a max)
+      image[0].zoom.dx = ZOOM_X; 
+      image[0].zoom.dy = ZOOM_Y;
+      image[0].zoom.x = Xs + dX - PAD1 - ZOOM_X;
+      image[0].zoom.y = Ys + PAD1 + PAD2 + COLORPAD;
 
-  image[0].rainbow_button.x = image[0].grey_button.x + image[0].grey_button.dx + PAD1;
-  image[0].rainbow_button.y = image[0].PS_button.y;
+      /** everything below is tied in x-dir to the zoom box **/
+      image[0].text_x = image[0].zoom.x;
+      image[0].text_y = image[0].zoom.y + image[0].zoom.dy + PAD2;
 
-  image[0].puns_button.x = image[0].rainbow_button.x + image[0].rainbow_button.dx + PAD1;
-  image[0].puns_button.y = image[0].PS_button.y;
+      /*  image[0].PS_button.y = graphic[0].dy - BUTTON_HEIGHT - PAD1; */
+      image[0].PS_button.x = image[0].zoom.x + 5;
+      image[0].PS_button.y = Ys + 2*ZOOM_Y;
 
-  image[0].recenter_button.x = image[0].puns_button.x + image[0].puns_button.dx + PAD1;
-  image[0].recenter_button.y = image[0].PS_button.y;
+      /** everything below is tied to the PS_button in y-dir **/
+      image[0].grey_button.x = image[0].PS_button.x + image[0].PS_button.dx + PAD1;
+      image[0].grey_button.y = image[0].PS_button.y;
 
-  image[0].overlay_button[0].x = image[0].zoom.x + 5;
-  image[0].overlay_button[0].y = image[0].PS_button.y - BUTTON_HEIGHT - PAD1;
+      image[0].rainbow_button.x = image[0].grey_button.x + image[0].grey_button.dx + PAD1;
+      image[0].rainbow_button.y = image[0].PS_button.y;
+
+      image[0].puns_button.x = image[0].rainbow_button.x + image[0].rainbow_button.dx + PAD1;
+      image[0].puns_button.y = image[0].PS_button.y;
+
+      image[0].recenter_button.x = image[0].puns_button.x + image[0].puns_button.dx + PAD1;
+      image[0].recenter_button.y = image[0].PS_button.y;
+
+      image[0].overlay_button[0].x = image[0].zoom.x + 5;
+      image[0].overlay_button[0].y = image[0].PS_button.y - BUTTON_HEIGHT - PAD1;
    
-  image[0].overlay_button[1].x = image[0].overlay_button[0].x + image[0].overlay_button[0].dx + PAD1;
-  image[0].overlay_button[1].y = image[0].PS_button.y - BUTTON_HEIGHT - PAD1;
+      image[0].overlay_button[1].x = image[0].overlay_button[0].x + image[0].overlay_button[0].dx + PAD1;
+      image[0].overlay_button[1].y = image[0].PS_button.y - BUTTON_HEIGHT - PAD1;
 
-  image[0].overlay_button[2].x = image[0].overlay_button[1].x + image[0].overlay_button[1].dx + PAD1;
-  image[0].overlay_button[2].y = image[0].PS_button.y - BUTTON_HEIGHT - PAD1;
+      image[0].overlay_button[2].x = image[0].overlay_button[1].x + image[0].overlay_button[1].dx + PAD1;
+      image[0].overlay_button[2].y = image[0].PS_button.y - BUTTON_HEIGHT - PAD1;
 
-  image[0].overlay_button[3].x = image[0].overlay_button[2].x + image[0].overlay_button[2].dx + PAD1;
-  image[0].overlay_button[3].y = image[0].PS_button.y - BUTTON_HEIGHT - PAD1;
+      image[0].overlay_button[3].x = image[0].overlay_button[2].x + image[0].overlay_button[2].dx + PAD1;
+      image[0].overlay_button[3].y = image[0].PS_button.y - BUTTON_HEIGHT - PAD1;
 
-  image[0].hms_button.x = image[0].overlay_button[3].x + image[0].overlay_button[3].dx + PAD1;
-  image[0].hms_button.y = image[0].PS_button.y - BUTTON_HEIGHT - PAD1;
+      image[0].hms_button.x = image[0].overlay_button[3].x + image[0].overlay_button[3].dx + PAD1;
+      image[0].hms_button.y = image[0].PS_button.y - BUTTON_HEIGHT - PAD1;
+      break;
+
+    default:
+      image[0].picture.dx = dX - 2*PAD1 - ZOOM_X; 
+      image[0].picture.dy = dY - 2*PAD1 - PAD2 - COLORPAD - 25;
+      image[0].picture.x = Xs + PAD1;
+      image[0].picture.y = Ys + PAD1 + PAD2 + COLORPAD;
+
+      image[0].cmapbar.dx = dX - 2*PAD1; 
+      image[0].cmapbar.dy = COLORPAD;
+      image[0].cmapbar.x = Xs + PAD1;
+      image[0].cmapbar.y = Ys + PAD1;
+
+      // XXX zoom should scale somewhat with the image (with a min and a max)
+      image[0].zoom.dx = ZOOM_X; 
+      image[0].zoom.dy = ZOOM_Y;
+      image[0].zoom.x = Xs + dX - PAD1 - ZOOM_X;
+      image[0].zoom.y = Ys + PAD1 + PAD2 + COLORPAD;
+
+      /** everything below is tied in x-dir to the zoom box **/
+      image[0].text_x = image[0].zoom.x;
+      image[0].text_y = image[0].zoom.y + image[0].zoom.dy + PAD2;
+
+      /*  image[0].PS_button.y = graphic[0].dy - BUTTON_HEIGHT - PAD1; */
+      image[0].PS_button.x = image[0].zoom.x + 5;
+      image[0].PS_button.y = Ys + 2*ZOOM_Y;
+
+      /** everything below is tied to the PS_button in y-dir **/
+      image[0].grey_button.x = image[0].PS_button.x + image[0].PS_button.dx + PAD1;
+      image[0].grey_button.y = image[0].PS_button.y;
+
+      image[0].rainbow_button.x = image[0].grey_button.x + image[0].grey_button.dx + PAD1;
+      image[0].rainbow_button.y = image[0].PS_button.y;
+
+      image[0].puns_button.x = image[0].rainbow_button.x + image[0].rainbow_button.dx + PAD1;
+      image[0].puns_button.y = image[0].PS_button.y;
+
+      image[0].recenter_button.x = image[0].puns_button.x + image[0].puns_button.dx + PAD1;
+      image[0].recenter_button.y = image[0].PS_button.y;
+
+      image[0].overlay_button[0].x = image[0].zoom.x + 5;
+      image[0].overlay_button[0].y = image[0].PS_button.y - BUTTON_HEIGHT - PAD1;
+   
+      image[0].overlay_button[1].x = image[0].overlay_button[0].x + image[0].overlay_button[0].dx + PAD1;
+      image[0].overlay_button[1].y = image[0].PS_button.y - BUTTON_HEIGHT - PAD1;
+
+      image[0].overlay_button[2].x = image[0].overlay_button[1].x + image[0].overlay_button[1].dx + PAD1;
+      image[0].overlay_button[2].y = image[0].PS_button.y - BUTTON_HEIGHT - PAD1;
+
+      image[0].overlay_button[3].x = image[0].overlay_button[2].x + image[0].overlay_button[2].dx + PAD1;
+      image[0].overlay_button[3].y = image[0].PS_button.y - BUTTON_HEIGHT - PAD1;
+
+      image[0].hms_button.x = image[0].overlay_button[3].x + image[0].overlay_button[3].dx + PAD1;
+      image[0].hms_button.y = image[0].PS_button.y - BUTTON_HEIGHT - PAD1;
+      break;
+  }
 
   if (USE_XWINDOW) {
Index: /branches/kapa-mods-2007-05/Ohana/src/opihi/cmd.data/close.c
===================================================================
--- /branches/kapa-mods-2007-05/Ohana/src/opihi/cmd.data/close.c	(revision 13393)
+++ /branches/kapa-mods-2007-05/Ohana/src/opihi/cmd.data/close.c	(revision 13394)
@@ -15,7 +15,7 @@
 
   if (!GetGraph (NULL, &kapa, name)) return (FALSE);
+
+  close_kapa (name); 
   FREE (name);
-
-  // close_kapa (name); 
 
   return (TRUE);
Index: /branches/kapa-mods-2007-05/Ohana/src/opihi/dimm/dimm.c.in
===================================================================
--- /branches/kapa-mods-2007-05/Ohana/src/opihi/dimm/dimm.c.in	(revision 13393)
+++ /branches/kapa-mods-2007-05/Ohana/src/opihi/dimm/dimm.c.in	(revision 13394)
@@ -50,6 +50,5 @@
 /* add program-dependent exit functions here */
 void cleanup () {
-  QuitImage ();
-  QuitGraph ();
+  QuitKapa ();
   return;
 }
Index: /branches/kapa-mods-2007-05/Ohana/src/opihi/dvo/dvo.c.in
===================================================================
--- /branches/kapa-mods-2007-05/Ohana/src/opihi/dvo/dvo.c.in	(revision 13393)
+++ /branches/kapa-mods-2007-05/Ohana/src/opihi/dvo/dvo.c.in	(revision 13394)
@@ -55,6 +55,5 @@
 /* add program-dependent exit functions here */
 void cleanup () {
-  QuitImage ();
-  QuitGraph ();
+  QuitKapa ();
   return;
 }
Index: /branches/kapa-mods-2007-05/Ohana/src/opihi/include/display.h
===================================================================
--- /branches/kapa-mods-2007-05/Ohana/src/opihi/include/display.h	(revision 13393)
+++ /branches/kapa-mods-2007-05/Ohana/src/opihi/include/display.h	(revision 13394)
@@ -34,6 +34,8 @@
 int           SelectOverlay         PROTO((char *name, int *number));
 
+void QuitKapa ();
 void InitKapa ();
 int open_kapa (int entry);
+int close_kapa (char *name);
 int AddKapaDevice (char *name);
 int DelKapaDevice (char *name);
Index: /branches/kapa-mods-2007-05/Ohana/src/opihi/lib.data/open_kapa.c
===================================================================
--- /branches/kapa-mods-2007-05/Ohana/src/opihi/lib.data/open_kapa.c	(revision 13393)
+++ /branches/kapa-mods-2007-05/Ohana/src/opihi/lib.data/open_kapa.c	(revision 13394)
@@ -50,13 +50,20 @@
   N = FindKapaDevice (name);
   if (N == -1) return (FALSE);
+
   if (Socket[N] != -1) close (Socket[N]);
   free (Device[N]);
   for (i = N; i < Ndevice - 1; i++) {
-    Device[N] = Device[N+1];
-    Socket[N] = Socket[N+1];
-  }
+    Device[i] = Device[i+1];
+    Socket[i] = Socket[i+1];
+  }
+
+  if (N == Active) {
+    Active = -1;
+  }
+
   Ndevice --;
   REALLOCATE (Device, char *, Ndevice);
   REALLOCATE (Socket, int, Ndevice);
+
   return (TRUE);
 }
@@ -66,4 +73,6 @@
 
   int i;
+
+  if (name == NULL) return (-1); 
 
   for (i = 0; i < Ndevice; i++) {
@@ -255,2 +264,30 @@
   *range = Xrange;
 }
+
+int close_kapa (char *name) {
+
+  int N;
+
+  N = FindKapaDevice (name);
+  if (N == -1) {
+    if (Active < 0) return (FALSE);
+    name = Device[Active];
+  }
+  DelKapaDevice (name);
+  return (TRUE);
+}
+
+void QuitKapa () {
+
+  int i;
+  
+  for (i = 0; i < Ndevice; i++) {
+    if (Socket[i] != -1) close (Socket[i]);
+    if (Device[i] != NULL) free (Device[i]);
+  }
+  REALLOCATE (Socket, int, 1);
+  REALLOCATE (Device, char *, 1);
+
+  Ndevice = 0;
+  Active = -1;
+}
Index: /branches/kapa-mods-2007-05/Ohana/src/opihi/lib.data/style_args.c
===================================================================
--- /branches/kapa-mods-2007-05/Ohana/src/opihi/lib.data/style_args.c	(revision 13393)
+++ /branches/kapa-mods-2007-05/Ohana/src/opihi/lib.data/style_args.c	(revision 13394)
@@ -13,5 +13,5 @@
     remove_argument (N, argc, argv);
   }
-  if (!GetGraph (&graphmode, kapa, name)) return (FALSE);
+  if (!GetGraph (graphmode, kapa, name)) return (FALSE);
   FREE (name);
 
Index: /branches/kapa-mods-2007-05/Ohana/src/opihi/mana/mana.c.in
===================================================================
--- /branches/kapa-mods-2007-05/Ohana/src/opihi/mana/mana.c.in	(revision 13393)
+++ /branches/kapa-mods-2007-05/Ohana/src/opihi/mana/mana.c.in	(revision 13394)
@@ -51,6 +51,5 @@
 /* add program-dependent exit functions here */
 void cleanup () {
-	//   QuitImage ();
-	//   QuitGraph ();
+  QuitKapa ();
   return;
 }
Index: /branches/kapa-mods-2007-05/Ohana/src/opihi/mana/opihi.c
===================================================================
--- /branches/kapa-mods-2007-05/Ohana/src/opihi/mana/opihi.c	(revision 13393)
+++ /branches/kapa-mods-2007-05/Ohana/src/opihi/mana/opihi.c	(revision 13394)
@@ -64,7 +64,5 @@
 /* add program-dependent exit functions here */
 void cleanup () {
-  /* -libdisplay
-  QuitImage ();
-  QuitGraph (); */
+  QuitKapa ();
   return;
 }
Index: /branches/kapa-mods-2007-05/Ohana/src/opihi/pantasks/pantasks.c.in
===================================================================
--- /branches/kapa-mods-2007-05/Ohana/src/opihi/pantasks/pantasks.c.in	(revision 13393)
+++ /branches/kapa-mods-2007-05/Ohana/src/opihi/pantasks/pantasks.c.in	(revision 13394)
@@ -64,6 +64,5 @@
 /* add program-dependent exit functions here */
 void cleanup () {
-  QuitImage ();
-  QuitGraph ();
+  QuitKapa ();
   QuitController ();
   return;
Index: /branches/kapa-mods-2007-05/Ohana/src/opihi/pantasks/pantasks_client.c.in
===================================================================
--- /branches/kapa-mods-2007-05/Ohana/src/opihi/pantasks/pantasks_client.c.in	(revision 13393)
+++ /branches/kapa-mods-2007-05/Ohana/src/opihi/pantasks/pantasks_client.c.in	(revision 13394)
@@ -54,6 +54,5 @@
 /* add program-dependent exit functions here */
 void cleanup () {
-  QuitImage ();
-  QuitGraph ();
+  QuitKapa ();
   return;
 }
Index: /branches/kapa-mods-2007-05/Ohana/src/opihi/pantasks/pantasks_server.c
===================================================================
--- /branches/kapa-mods-2007-05/Ohana/src/opihi/pantasks/pantasks_server.c	(revision 13393)
+++ /branches/kapa-mods-2007-05/Ohana/src/opihi/pantasks/pantasks_server.c	(revision 13394)
@@ -74,7 +74,6 @@
 /* add program-dependent exit functions here */
 void cleanup () {
-  // QuitImage ();
-  // QuitGraph ();
-  // QuitController ();
+  QuitKapa ();
+  QuitController ();
   return;
 }
