Index: /trunk/Ohana/src/opihi/cmd.astro/Makefile
===================================================================
--- /trunk/Ohana/src/opihi/cmd.astro/Makefile	(revision 18717)
+++ /trunk/Ohana/src/opihi/cmd.astro/Makefile	(revision 18718)
@@ -41,4 +41,5 @@
 $(SRC)/precess.$(ARCH).o	   \
 $(SRC)/profile.$(ARCH).o	   \
+$(SRC)/radec.$(ARCH).o	   \
 $(SRC)/region.$(ARCH).o	   \
 $(SRC)/rotcurve.$(ARCH).o	   \
Index: /trunk/Ohana/src/opihi/cmd.astro/init.c
===================================================================
--- /trunk/Ohana/src/opihi/cmd.astro/init.c	(revision 18717)
+++ /trunk/Ohana/src/opihi/cmd.astro/init.c	(revision 18718)
@@ -27,4 +27,5 @@
 int precess                 PROTO((int, char **));
 int profile                 PROTO((int, char **));
+int radec                   PROTO((int, char **));
 int region                  PROTO((int, char **));
 int rotcurve                PROTO((int, char **));
@@ -62,4 +63,5 @@
   {1, "precess",     precess,      "precess coordinates"},
   {1, "profile",     profile,      "radial profile at X, Y"},
+  {1, "radec",       radec,        "convert to/from radec in hms or dd"},
   {1, "region",      region,       "define sky region for plot"},
   {1, "rotcurve",    rotcurve,     "convert CO images to polar coords"},
Index: /trunk/Ohana/src/opihi/cmd.astro/radec.c
===================================================================
--- /trunk/Ohana/src/opihi/cmd.astro/radec.c	(revision 18718)
+++ /trunk/Ohana/src/opihi/cmd.astro/radec.c	(revision 18718)
@@ -0,0 +1,56 @@
+# include "astro.h"
+
+int radec (int argc, char **argv) {
+
+  int N, QUIET;
+  double ra, dec;
+  char ra_string[32], dec_string[32];
+
+  QUIET = FALSE;
+  if ((N = get_argument (argc, argv, "-q"))) {
+    QUIET = TRUE;
+    remove_argument (N, &argc, argv);
+  }
+  if ((N = get_argument (argc, argv, "-quiet"))) {
+    QUIET = TRUE;
+    remove_argument (N, &argc, argv);
+  }
+
+  if (argc != 4) {
+    gprint (GP_ERR, "USAGE:  radec (-hh | -hms) RA DEC [-q | -quiet]\n");
+    gprint (GP_ERR, "   convert to decimal (-hh) or sexigesimal (-hms)\n");
+    gprint (GP_ERR, "   output goes to $RA, $DEC\n");
+    return (FALSE);
+  }
+
+  if (strcmp (argv[1], "-hh") && strcmp (argv[1], "-hms")) {
+    gprint (GP_ERR, "USAGE:  radec (-hh | -hms) RA DEC [-q | -quiet]\n");
+    gprint (GP_ERR, "   convert to decimal (-hh) or sexigesimal (-hms)\n");
+    gprint (GP_ERR, "   output goes to $RA, $DEC\n");
+    return (FALSE);
+  }    
+
+  if (!ohana_str_to_radec (&ra, &dec, argv[2], argv[3])) {
+    return (FALSE);
+  }
+
+  if (!strcmp (argv[1], "-hh")) {
+    set_variable ("RA", ra);
+    set_variable ("DEC", dec);
+    if (!QUIET) {
+      gprint (GP_LOG, "%10.6f %10.6f\n", ra, dec);
+    }
+    return (TRUE);
+  }
+
+  // convert to hms, dms
+  hms_format (ra_string, ra/15.0);
+  hms_format (dec_string, dec);
+
+  set_str_variable ("RA", ra_string);
+  set_str_variable ("DEC", dec_string);
+  if (!QUIET) {
+    gprint (GP_LOG, "%s %s\n", ra_string, dec_string);
+  }
+  return (TRUE);
+}  
Index: /trunk/Ohana/src/opihi/lib.data/convert.c
===================================================================
--- /trunk/Ohana/src/opihi/lib.data/convert.c	(revision 18717)
+++ /trunk/Ohana/src/opihi/lib.data/convert.c	(revision 18718)
@@ -7,12 +7,22 @@
 int hh_hms (double hh, int *hr, int *mn, double *sc) {
 
-  int flag;
+  int N, flag;
 
   flag = SIGN(hh);
-  hh *= flag;
-  hh = 24.0*(hh/24.0 - (int)(hh/24.0));
-  *sc = 60.0*(60.0*hh - (int)(60.0*hh));
-  *mn = 60.0*(hh - (int)hh);
+  hh = fabs(hh);
+
+  // rationalize hh to range -24.0 < hh < 24.0
+  if (hh >= 24.0) {
+    N = (int)(hh/24.0);
+    hh -= 24.0*N;
+  }
+
   *hr = (int) hh;
+  *mn = (int) 60*(hh - *hr);
+  *sc = 3600.0*(hh - *hr - *mn / 60.0);
+  if (*sc > 59.99) {
+    *sc = 0.0;
+    *mn += 1.0;
+  }
   *hr *= flag;
   return (TRUE);
@@ -49,5 +59,5 @@
       sprintf (line, "-%02d:%02d:%05.2f", abs(hr), mn, sc);
     } else {
-      sprintf (line, "%02d:%02d:%05.2f", hr, mn, sc);
+      sprintf (line, "+%02d:%02d:%05.2f", hr, mn, sc);
     }
   }      
@@ -64,5 +74,5 @@
     sprintf (line, "-%02d:%02d:%05.2f", abs(dg), mn, sc);
   } else {
-    sprintf (line, "%02d:%02d:%05.2f", dg, mn, sc);
+    sprintf (line, "+%02d:%02d:%05.2f", dg, mn, sc);
   }
   return (TRUE);
