Index: trunk/Ohana/src/kapa2/include/constants.h
===================================================================
--- trunk/Ohana/src/kapa2/include/constants.h	(revision 40418)
+++ trunk/Ohana/src/kapa2/include/constants.h	(revision 40419)
@@ -27,5 +27,5 @@
 # define MIN_WIDTH 50
 # define MIN_HEIGHT 50
-# define LABEL_MAXLEN 128
+# define LABEL_MAXLEN 512
 
 typedef enum {
Index: trunk/Ohana/src/kapa2/include/structures.h
===================================================================
--- trunk/Ohana/src/kapa2/include/structures.h	(revision 40418)
+++ trunk/Ohana/src/kapa2/include/structures.h	(revision 40419)
@@ -115,7 +115,9 @@
 typedef struct {
   int x, y;
-  int dx, dy;
+  int dx, dy; // unused?
   double angle;
   int  size;
+  int justify;
+  int color;
   char font[64]; 
   char text[LABEL_MAXLEN];
Index: trunk/Ohana/src/kapa2/src/DrawTextlines.c
===================================================================
--- trunk/Ohana/src/kapa2/src/DrawTextlines.c	(revision 40418)
+++ trunk/Ohana/src/kapa2/src/DrawTextlines.c	(revision 40419)
@@ -12,13 +12,13 @@
   fontname = GetRotFont (&size);
   XSetForeground (graphic->display, graphic->gc, graphic->fore);
-  DrawRotTextInit (graphic->display, graphic->window, graphic->gc, graphic->fore, graphic->back);
 
   for (i = 0; i < graph[0].Ntextline; i++) {
     if (strcmp (graph[0].textline[i].text, "")) {
+      DrawRotTextInit (graphic->display, graphic->window, graphic->gc, graphic->color[graph[0].textline[i].color], graphic->back);
       angle = graph[0].textline[i].angle;
       x = graph[0].textline[i].x;
       y = graph[0].textline[i].y;
       SetRotFont (graph[0].textline[i].font, graph[0].textline[i].size);
-      DrawRotText (x, y, graph[0].textline[i].text, 5, angle);
+      DrawRotText (x, y, graph[0].textline[i].text, graph[0].textline[i].justify, angle);
     }
   }
Index: trunk/Ohana/src/kapa2/src/LoadTextlines.c
===================================================================
--- trunk/Ohana/src/kapa2/src/LoadTextlines.c	(revision 40418)
+++ trunk/Ohana/src/kapa2/src/LoadTextlines.c	(revision 40419)
@@ -4,5 +4,5 @@
   
   char *string;
-  int N, size;
+  int N, size, justify, color;
   double tX, tY, tT, L;
   Section *section;
@@ -23,5 +23,5 @@
   REALLOCATE (graph[0].textline, Label, graph[0].Ntextline);
 
-  KiiScanMessage (sock, "%lf %lf %lf", &tX, &tY, &tT);
+  KiiScanMessage (sock, "%lf %lf %lf %d %d", &tX, &tY, &tT, &justify, &color);
 
   L = graph[0].axis[0].dfx;
@@ -52,4 +52,6 @@
   graph[0].textline[N].size = size;
   strcpy (graph[0].textline[N].font, string);
+  graph[0].textline[N].justify = justify;
+  graph[0].textline[N].color = color;
 
   if (USE_XWINDOW) DrawTextlines (graph);
Index: trunk/Ohana/src/kapa2/src/PSTextlines.c
===================================================================
--- trunk/Ohana/src/kapa2/src/PSTextlines.c	(revision 40418)
+++ trunk/Ohana/src/kapa2/src/PSTextlines.c	(revision 40419)
@@ -16,6 +16,9 @@
       x = graph[0].textline[i].x;
       y = graphic->dy - graph[0].textline[i].y;
+      if (graph[0].textline[i].color >= 0) {
+	fprintf (f, "%s setrgbcolor\n", KapaColorRGBString(graph[0].textline[i].color));
+      }
       SetRotFont (graph[0].textline[i].font, graph[0].textline[i].size);
-      PSRotText (f, x, y, graph[0].textline[i].text, 5, angle);
+      PSRotText (f, x, y, graph[0].textline[i].text, graph[0].textline[i].justify, angle);
     }
   }
Index: trunk/Ohana/src/kapa2/src/bDrawLabels.c
===================================================================
--- trunk/Ohana/src/kapa2/src/bDrawLabels.c	(revision 40418)
+++ trunk/Ohana/src/kapa2/src/bDrawLabels.c	(revision 40419)
@@ -40,9 +40,10 @@
   for (i = 0; i < graph[0].Ntextline; i++) {
     if (strcmp (graph[0].textline[i].text, "")) {
+      bDrawSetColor (buffer, graph[0].textline[i].color);
       angle = graph[0].textline[i].angle;
       x = graph[0].textline[i].x;
       y = graph[0].textline[i].y;
       SetRotFont (graph[0].textline[i].font, graph[0].textline[i].size);
-      bDrawRotText (buffer, x, y, graph[0].textline[i].text, 5, angle);
+      bDrawRotText (buffer, x, y, graph[0].textline[i].text, graph[0].textline[i].justify, angle);
     }
   }
Index: trunk/Ohana/src/libkapa/include/kapa.h
===================================================================
--- trunk/Ohana/src/libkapa/include/kapa.h	(revision 40418)
+++ trunk/Ohana/src/libkapa/include/kapa.h	(revision 40419)
@@ -239,5 +239,5 @@
 int KapaSetFont (int fd, char *name, int size);
 int KapaSendLabel (int fd, char *string, int mode);
-int KapaSendTextline (int fd, char *string, float x, float y, float angle);
+int KapaSendTextline (int fd, char *string, float x, float y, float angle, int justify, int color);
 int KapaSetLimits (int fd, Graphdata *graphmode);
 int KapaGetLimits (int fd, float *dx, float *dy);
Index: trunk/Ohana/src/libkapa/src/DrawRotString.c
===================================================================
--- trunk/Ohana/src/libkapa/src/DrawRotString.c	(revision 40418)
+++ trunk/Ohana/src/libkapa/src/DrawRotString.c	(revision 40419)
@@ -12,4 +12,5 @@
 static unsigned long RotBackground;
 
+// fore and back are X colors
 int DrawRotTextInit (Display *display, Window window, GC gc, unsigned long fore, unsigned long back) {
 
Index: trunk/Ohana/src/libkapa/src/KapaWindow.c
===================================================================
--- trunk/Ohana/src/libkapa/src/KapaWindow.c	(revision 40418)
+++ trunk/Ohana/src/libkapa/src/KapaWindow.c	(revision 40419)
@@ -358,8 +358,11 @@
 }
 
-int KapaSendTextline (int fd, char *string, float x, float y, float angle) {
-  
+int KapaSendTextline (int fd, char *string, float x, float y, float angle, int justify, int color) {
+  
+  // must be in range 0 - 8
+  justify = MIN(MAX(justify, 0), 8);
+
   KiiSendCommand (fd, 4, "PTXT");
-  KiiSendMessage (fd, "%f %f %f ", x, y, angle);
+  KiiSendMessage (fd, "%f %f %f %d %d", x, y, angle, justify, color);
   KiiSendData (fd, string, strlen(string));
   KiiWaitAnswer (fd, "DONE");
Index: trunk/Ohana/src/opihi/cmd.astro/cgrid.c
===================================================================
--- trunk/Ohana/src/opihi/cmd.astro/cgrid.c	(revision 40418)
+++ trunk/Ohana/src/opihi/cmd.astro/cgrid.c	(revision 40419)
@@ -95,4 +95,38 @@
   }
 
+  int JustifyRA = 5;
+  double JustifyDEC = 5;
+  if ((N = get_argument (argc, argv, "-justify-ra"))) {
+    remove_argument (N, &argc, argv);
+    JustifyRA = atoi (argv[N]);
+    remove_argument (N, &argc, argv);
+  }
+  if ((N = get_argument (argc, argv, "-justify-dec"))) {
+    remove_argument (N, &argc, argv);
+    JustifyDEC = atoi (argv[N]);
+    remove_argument (N, &argc, argv);
+  }
+
+  double LabelRA = NAN;
+  double LabelDEC = NAN;
+  if ((N = get_argument (argc, argv, "-label-ra"))) {
+    remove_argument (N, &argc, argv);
+    LabelRA = atof (argv[N]);
+    remove_argument (N, &argc, argv);
+  }
+  if ((N = get_argument (argc, argv, "-label-dec"))) {
+    remove_argument (N, &argc, argv);
+    LabelDEC = atof (argv[N]);
+    remove_argument (N, &argc, argv);
+  }
+
+  int LabelColor = KapaColorByName ("black");
+  if ((N = get_argument (argc, argv, "-label-color"))) {
+    remove_argument (N, &argc, argv);
+    LabelColor = KapaColorByName (argv[N]);
+    if (LabelColor == -1) return (FALSE);
+    remove_argument (N, &argc, argv);
+  }
+
   if (!style_args (&graphmode, &argc, argv, &kapa)) return FALSE;
 
@@ -196,10 +230,12 @@
   if (Labels) { 
     char line[16], format[8];
-    double xt, yt, dx, dy, frac;
-    dx = +0.01 * (graphmode.xmax - graphmode.xmin);
-    dy = -0.02 * (graphmode.ymax - graphmode.ymin);
-
+    double xt, yt, frac;
+    // dx = +0.01 * (graphmode.xmax - graphmode.xmin);
+    // dy = -0.02 * (graphmode.ymax - graphmode.ymin);
+
+    if (isnan(LabelRA)) LabelRA = graphmode.coords.crval1;
+    if (isnan(LabelDEC)) LabelDEC = graphmode.coords.crval2;
     for (r = firstRA; r <= graphmode.coords.crval1 + 180.0; r += minorRA) {
-      status = RD_to_XY (&xt, &yt, r, graphmode.coords.crval2, &graphmode.coords);
+      status = RD_to_XY (&xt, &yt, r, LabelDEC, &graphmode.coords);
       if (!status) continue;
       if (xt < graphmode.xmin) continue;
@@ -212,14 +248,15 @@
       }
       if (frac <= 0.0) frac = 0.0;
-      snprintf (format, 8, "%%.%df", (int) frac);
       if (RAbyHour) {
+	snprintf (format, 8, "%%.%df^h", (int) frac);
 	snprintf (line, 16, format, r / 15.0);
       } else {
+	snprintf (format, 8, "%%.%df^o", (int) frac);
 	snprintf (line, 16, format, r);
       }
-      KapaSendTextline (kapa, line, xt + dx, yt + dy, 0.0);
+      KapaSendTextline (kapa, line, xt, yt, 0.0, JustifyRA, LabelColor);
     }
     for (r = firstRA; r >= graphmode.coords.crval1 - 180.0; r -= minorRA) {
-      status = RD_to_XY (&xt, &yt, r, graphmode.coords.crval2, &graphmode.coords);
+      status = RD_to_XY (&xt, &yt, r, LabelDEC, &graphmode.coords);
       if (!status) continue;
       if (xt < graphmode.xmin) continue;
@@ -232,14 +269,15 @@
       }
       if (frac <= 0.0) frac = 0.0;
-      snprintf (format, 8, "%%.%df", (int) frac);
       if (RAbyHour) {
+	snprintf (format, 8, "%%.%df^h", (int) frac);
 	snprintf (line, 16, format, r / 15.0);
       } else {
+	snprintf (format, 8, "%%.%df^o", (int) frac);
 	snprintf (line, 16, format, r);
       }
-      KapaSendTextline (kapa, line, xt + dx, yt + dy, 0.0);
+      KapaSendTextline (kapa, line, xt, yt, 0.0, JustifyRA, LabelColor);
     }
     for (d = firstDEC; d <= graphmode.coords.crval2 + 90.0; d += minorDEC) {
-      status = RD_to_XY (&xt, &yt, graphmode.coords.crval1, d, &graphmode.coords);
+      status = RD_to_XY (&xt, &yt, LabelRA, d, &graphmode.coords);
       if (!status) continue;
       if (xt < graphmode.xmin) continue;
@@ -252,10 +290,10 @@
       }
       if (frac <= 0.0) frac = 0.0;
-      snprintf (format, 8, "%%.%df", (int) frac);
+      snprintf (format, 8, "%%.%df^o", (int) frac);
       snprintf (line, 16, format, d);
-      KapaSendTextline (kapa, line, xt + dx, yt + dy, 0.0);
+      KapaSendTextline (kapa, line, xt, yt, 0.0, JustifyDEC, LabelColor);
     }
     for (d = firstDEC; d >= graphmode.coords.crval2 - 90.0; d -= minorDEC) {
-      status = RD_to_XY (&xt, &yt, graphmode.coords.crval1, d, &graphmode.coords);
+      status = RD_to_XY (&xt, &yt, LabelRA, d, &graphmode.coords);
       if (!status) continue;
       if (xt < graphmode.xmin) continue;
@@ -268,7 +306,7 @@
       }
       if (frac <= 0.0) frac = 0.0;
-      snprintf (format, 8, "%%.%df", (int) frac);
+      snprintf (format, 8, "%%.%df^o", (int) frac);
       snprintf (line, 16, format, d);
-      KapaSendTextline (kapa, line, xt + dx, yt + dy, 0.0);
+      KapaSendTextline (kapa, line, xt, yt, 0.0, JustifyDEC, LabelColor);
     }
   }
Index: trunk/Ohana/src/opihi/cmd.data/textline.c
===================================================================
--- trunk/Ohana/src/opihi/cmd.data/textline.c	(revision 40418)
+++ trunk/Ohana/src/opihi/cmd.data/textline.c	(revision 40419)
@@ -6,8 +6,26 @@
   char name[64];
   double x, y, angle;
-  int kapa;
   Graphdata graphmode;
 
-  if (!style_args (&graphmode, &argc, argv, &kapa)) return (FALSE);
+  // if (!style_args (&graphmode, &argc, argv, &kapa)) return (FALSE);
+
+  // Using only these style_args options
+  char *kapaName = NULL;
+  int kapa = -1;
+  if ((N = get_argument (argc, argv, "-n"))) {
+    remove_argument (N, &argc, argv);
+    kapaName = strcreate (argv[N]);
+    remove_argument (N, &argc, argv);
+  }
+  if (!GetGraph (&graphmode, &kapa, kapaName)) return (FALSE);
+  FREE (kapaName);
+
+  int color = KapaColorByName ("black");
+  if ((N = get_argument (argc, argv, "-c"))) {
+    remove_argument (N, &argc, argv);
+    color = KapaColorByName (argv[N]);
+    if (color == -1) return (FALSE);
+    remove_argument (N, &argc, argv);
+  }
 
   if ((N = get_argument (argc, argv, "-fn"))) {
@@ -34,6 +52,13 @@
   } 
 
+  int justify = 5; // default
+  if ((N = get_argument (argc, argv, "-justify"))) {
+    remove_argument (N, &argc, argv);
+    justify = atoi (argv[N]);
+    remove_argument (N, &argc, argv);
+  } 
+
   if (argc != 4) {
-    gprint (GP_ERR, "USAGE: text x y (line) [-fn (font) size] [-rot angle]\n");
+    gprint (GP_ERR, "USAGE: text x y (line) [-fn (font) size] [-rot angle] [-justify N]\n");
     return (FALSE);
   }
@@ -52,5 +77,5 @@
   }    
 
-  KapaSendTextline (kapa, argv[3], x, y, angle);
+  KapaSendTextline (kapa, argv[3], x, y, angle, justify, color);
   return (TRUE);
 }
Index: trunk/Ohana/src/opihi/dvo/fitcolors.c
===================================================================
--- trunk/Ohana/src/opihi/dvo/fitcolors.c	(revision 40418)
+++ trunk/Ohana/src/opihi/dvo/fitcolors.c	(revision 40419)
@@ -47,4 +47,6 @@
   if ((selection = SetRegionSelection (&argc, argv)) == NULL) goto escape;
   if (!SetPhotSelections (&argc, argv, 4)) goto usage;
+
+  int textcolor = KapaColorByName ("black");
 
   // range for valid data points (exclude extreme outliers)
@@ -324,7 +326,7 @@
 	KapaSetFont (kapa, "helvetica", 8);
 	sprintf (label, "%s", code[0][0].name);
-	KapaSendTextline (kapa, label, 0.2*maxColor + 0.8*minColor, 0.8*maxDelta + 0.2*minDelta, 0.0);
+	KapaSendTextline (kapa, label, 0.2*maxColor + 0.8*minColor, 0.8*maxDelta + 0.2*minDelta, 0.0, textcolor);
 	sprintf (label, "%s", code[1][0].name);
-	KapaSendTextline (kapa, label, 0.2*maxColor + 0.8*minColor, 0.2*maxDelta + 0.8*minDelta, 0.0);
+	KapaSendTextline (kapa, label, 0.2*maxColor + 0.8*minColor, 0.2*maxDelta + 0.8*minDelta, 0.0, textcolor);
 	KapaSetFont (kapa, "helvetica", 14);
 
