Index: trunk/Ohana/src/kapa2/include/prototypes.h
===================================================================
--- trunk/Ohana/src/kapa2/include/prototypes.h	(revision 38464)
+++ trunk/Ohana/src/kapa2/include/prototypes.h	(revision 38465)
@@ -83,4 +83,5 @@
 int           SetChannel          PROTO((int sock));
 int           SetColormapFromPipe PROTO((int sock));
+int           SetNanColorFromPipe PROTO((int sock));
 
 int           LoadVectorData      PROTO((int sock, KapaGraphWidget *graph, int N, char *type));
Index: trunk/Ohana/src/kapa2/include/structures.h
===================================================================
--- trunk/Ohana/src/kapa2/include/structures.h	(revision 38464)
+++ trunk/Ohana/src/kapa2/include/structures.h	(revision 38465)
@@ -35,4 +35,5 @@
   unsigned long *color;      // graph plotting colors
   int            Ncolors;
+  char          *colormapName;
 
   unsigned long *pixels;      // image pixel colors
Index: trunk/Ohana/src/kapa2/src/CheckPipe.c
===================================================================
--- trunk/Ohana/src/kapa2/src/CheckPipe.c	(revision 38464)
+++ trunk/Ohana/src/kapa2/src/CheckPipe.c	(revision 38465)
@@ -316,4 +316,10 @@
   }
 
+  if (!strcmp (word, "CNAN")) {
+    status = SetNanColorFromPipe (sock);
+    KiiSendCommand (sock, 4, "DONE");
+    FINISHED (status);
+  }
+
   if (!strcmp (word, "SAVE")) {
     status = SaveOverlay (sock);
Index: trunk/Ohana/src/kapa2/src/InterpretKeys.c
===================================================================
--- trunk/Ohana/src/kapa2/src/InterpretKeys.c	(revision 38464)
+++ trunk/Ohana/src/kapa2/src/InterpretKeys.c	(revision 38465)
@@ -102,4 +102,5 @@
       UpdateStatusBox (graphic, image, X, Y, 0.0, 1); \
       Remap (graphic, image); \
+      Refresh (); \
       break;
 
Index: trunk/Ohana/src/kapa2/src/SetChannel.c
===================================================================
--- trunk/Ohana/src/kapa2/src/SetChannel.c	(revision 38464)
+++ trunk/Ohana/src/kapa2/src/SetChannel.c	(revision 38465)
@@ -57,5 +57,5 @@
     // image = section->image;
     SetColorScale (graphic, section->image);
-    if (!USE_XWINDOW) return (TRUE);
+    if (!USE_XWINDOW) return TRUE;
     Remap (graphic, section->image);
   }
@@ -66,2 +66,36 @@
   return (TRUE);
 }
+
+int SetNanColorFromPipe (int sock) {
+
+  int i, red_value, green_value, blue_value;
+  KiiScanMessage (sock, "%d %d %d", &red_value, &green_value, &blue_value);
+
+  NAN_RED   = red_value;
+  NAN_GREEN = green_value;
+  NAN_BLUE  = blue_value;
+
+  // use graphic->colormapName saved value
+  SetColormap (NULL);
+
+  if (!USE_XWINDOW) return (TRUE);
+  
+  Graphic *graphic = GetGraphic ();
+
+  int NeedRefresh = FALSE;
+  int Nsection = GetNumberOfSections ();
+  for (i = 0; i < Nsection; i++) {
+    Section *section = GetSectionByNumber (i);
+    if (section->image) { 
+      NeedRefresh = TRUE;
+      SetColorScale (graphic, section->image);
+      Remap (graphic, section->image);
+    }
+  }
+  if (NeedRefresh) {
+    Refresh ();
+    XFlush (graphic[0].display);
+  }
+
+  return (TRUE);
+}
Index: trunk/Ohana/src/kapa2/src/SetColormap.c
===================================================================
--- trunk/Ohana/src/kapa2/src/SetColormap.c	(revision 38464)
+++ trunk/Ohana/src/kapa2/src/SetColormap.c	(revision 38465)
@@ -16,5 +16,5 @@
 // display of) an image, we simply remap the lit pixels (in Remap32.c, etc).
 
-int SetColormap (char *name) {
+int SetColormap (char *inName) {
 
   int i, red, blue, green;
@@ -24,4 +24,11 @@
   graphic = GetGraphic();
 
+  if (!inName && !graphic->colormapName) abort();
+
+  if (inName) {
+    if (graphic->colormapName) free (graphic->colormapName);
+    graphic->colormapName = strcreate (inName);
+  }
+
   int NANValue = graphic[0].Npixels - 1;
   int MaxValue = graphic[0].Npixels - 1;
@@ -29,5 +36,5 @@
   // the "fullcolor" colormap is uniquely defined for each image;
   // defer to the 'SetColorScale' step
-  if (!strcasecmp (name, "fullcolor")) {
+  if (!strcasecmp (graphic->colormapName, "fullcolor")) {
     graphic[0].ColorScaleMode = KAPA_SCALE_3D_FULL;
     if (SetColorCubeHistogram ()) return TRUE;
@@ -44,5 +51,5 @@
 
   // very simple color model: evenly spaced cube 
-  if (!strcasecmp (name, "ruffcolor")) {
+  if (!strcasecmp (graphic->colormapName, "ruffcolor")) {
       graphic[0].nRed  = pow (graphic[0].Npixels, 0.333);
       graphic[0].nBlue = pow (graphic[0].Npixels, 0.333);
@@ -79,5 +86,5 @@
 
   /* greyscale */
-  if ((!strcasecmp (name, "grayscale")) || (!strcasecmp (name, "greyscale"))) {
+  if ((!strcasecmp (graphic->colormapName, "grayscale")) || (!strcasecmp (graphic->colormapName, "greyscale"))) {
     for (i = 0; i < MaxValue; i++) {  
       SETVALUE (graphic[0].cmap[i].red,   0xffff - i*scale, 0, 0xffff);
@@ -89,5 +96,5 @@
   }
   /* -grayscale */
-  if ((!strcasecmp (name, "-grayscale")) || (!strcasecmp (name, "-greyscale"))) {
+  if ((!strcasecmp (graphic->colormapName, "-grayscale")) || (!strcasecmp (graphic->colormapName, "-greyscale"))) {
     for (i = 0; i < MaxValue; i++) {  
       SETVALUE (graphic[0].cmap[i].red,   i*scale, 0, 0xffff);
@@ -99,5 +106,5 @@
   }
   /* heat */
-  if (!strcasecmp (name, "Heat")) {
+  if (!strcasecmp (graphic->colormapName, "Heat")) {
     greenRef = 0.25*MaxValue*scale*2.0;
     blueRef  = 0.50*MaxValue*scale*2.0;
@@ -129,5 +136,5 @@
   }
   /* rainbow */
-  if (!strcasecmp (name, "Rainbow")) {
+  if (!strcasecmp (graphic->colormapName, "Rainbow")) {
     redRef   = 0.25*MaxValue*scale*4.0;
     greenRef = 0.50*MaxValue*scale*4.0;
@@ -167,5 +174,5 @@
   }
   /* anuenue */
-  if (!strcasecmp (name, "anuenue")) {
+  if (!strcasecmp (graphic->colormapName, "anuenue")) {
     redRef   = 0.25*MaxValue*scale*4.0; // value at 0.0
     greenRef = 0.50*MaxValue*scale*4.0;
@@ -207,8 +214,8 @@
 
   /* anuenue */
-  if (!strncmp (name, "file:", 5)) {
-    FILE *f = fopen (&name[5], "r");
+  if (!strncmp (graphic->colormapName, "file:", 5)) {
+    FILE *f = fopen (&graphic->colormapName[5], "r");
     if (!f) {
-      fprintf (stderr, "failed to open colormap file %s\n", &name[5]);
+      fprintf (stderr, "failed to open colormap file %s\n", &graphic->colormapName[5]);
       return FALSE;
     }
Index: trunk/Ohana/src/kapa2/src/SetGraphSize.c
===================================================================
--- trunk/Ohana/src/kapa2/src/SetGraphSize.c	(revision 38464)
+++ trunk/Ohana/src/kapa2/src/SetGraphSize.c	(revision 38465)
@@ -21,6 +21,6 @@
   double X0 = graphic[0].dx * section[0].x  + x0;
   double Y0 = graphic[0].dy * section[0].y  + y0;
-  double dX = graphic[0].dx * section[0].dx - x1;
-  double dY = graphic[0].dy * section[0].dy - y1;
+  double dX = MAX(graphic[0].dx * section[0].dx - x1, 1);
+  double dY = MAX(graphic[0].dy * section[0].dy - y1, 1);
 
   /* define locations of coordinate axes */
Index: trunk/Ohana/src/kapa2/src/SetImageSize.c
===================================================================
--- trunk/Ohana/src/kapa2/src/SetImageSize.c	(revision 38464)
+++ trunk/Ohana/src/kapa2/src/SetImageSize.c	(revision 38465)
@@ -306,6 +306,6 @@
 	image[0].picture.x = Xs + PAD1;
 	image[0].picture.y = Ys + 2*PAD1 + COLORPAD;
-	image[0].picture.dx = dX - 3*PAD1 - 1 - ZOOM_X; 
-	image[0].picture.dy = dY - 3*PAD1 - 1 - COLORPAD;
+	image[0].picture.dx = MAX(dX - 3*PAD1 - 1 - ZOOM_X, 1); 
+	image[0].picture.dy = MAX(dY - 3*PAD1 - 1 - COLORPAD, 1);
       }
 
Index: trunk/Ohana/src/kapa2/src/SetUpGraphic.c
===================================================================
--- trunk/Ohana/src/kapa2/src/SetUpGraphic.c	(revision 38464)
+++ trunk/Ohana/src/kapa2/src/SetUpGraphic.c	(revision 38465)
@@ -42,4 +42,6 @@
   CheckColors (graphic, argc, argv);
 
+  graphic->colormapName = NULL;
+
   icon.width = icon_width;
   icon.height = icon_height;
Index: trunk/Ohana/src/kapa2/src/bDrawIt.c
===================================================================
--- trunk/Ohana/src/kapa2/src/bDrawIt.c	(revision 38464)
+++ trunk/Ohana/src/kapa2/src/bDrawIt.c	(revision 38465)
@@ -23,4 +23,7 @@
       section = GetSectionByNumber (i);
       bDrawImage (buffer, section->image, graphic);
+      for (i = 0; section->image && (i < NOVERLAYS); i++) {
+	if (section->image->overlay[i].active) bDrawOverlay (buffer, section->image, i);
+      }
       bDrawGraph (buffer, section->graph);
   }
