Index: /trunk/Ohana/src/addstar/src/FilterStars.c
===================================================================
--- /trunk/Ohana/src/addstar/src/FilterStars.c	(revision 19822)
+++ /trunk/Ohana/src/addstar/src/FilterStars.c	(revision 19823)
@@ -28,6 +28,5 @@
 
     XY_to_RD (&stars[N].R, &stars[N].D, stars[N].X, stars[N].Y, &image[0].coords);
-    while (stars[N].R <    0.0) stars[N].R += 360.0;
-    while (stars[N].R >= 360.0) stars[N].R -= 360.0;
+    stars[N].R = ohana_normalize_angle (stars[N].R);
     stars[N].found = -1;
     stars[N].code = image[0].photcode;
Index: /trunk/Ohana/src/addstar/src/ReadImageHeader.c
===================================================================
--- /trunk/Ohana/src/addstar/src/ReadImageHeader.c	(revision 19822)
+++ /trunk/Ohana/src/addstar/src/ReadImageHeader.c	(revision 19823)
@@ -76,6 +76,5 @@
   } else {
     /* force image to lie in 0-360 range */
-    while (image[0].coords.crval1 < 0) image[0].coords.crval1 += 360.0;
-    while (image[0].coords.crval1 > 360.0) image[0].coords.crval1 -= 360.0;
+    image[0].coords.crval1 = ohana_normalize_angle (image[0].coords.crval1);
   }
 
Index: /trunk/Ohana/src/addstar/src/grefstars.c
===================================================================
--- /trunk/Ohana/src/addstar/src/grefstars.c	(revision 19822)
+++ /trunk/Ohana/src/addstar/src/grefstars.c	(revision 19823)
@@ -25,6 +25,5 @@
     dparse (&stars[N].M,  3, line);
     dparse (&stars[N].dM, 4, line);
-    while (stars[N].R < 0.0) stars[N].R += 360.0;
-    while (stars[N].R >= 360.0) stars[N].R -= 360.0;
+    stars[N].R = ohana_normalize_angle (stars[N].R);
     stars[N].t = 0;
     stars[N].code = photcode;
Index: /trunk/Ohana/src/delstar/src/gimages.c
===================================================================
--- /trunk/Ohana/src/delstar/src/gimages.c	(revision 19822)
+++ /trunk/Ohana/src/delstar/src/gimages.c	(revision 19823)
@@ -39,11 +39,9 @@
     Shutdown ("ERROR: no astrometric solution in header");
   }
-  while (image[0].coords.crval1 < 0) image[0].coords.crval1 += 360.0;
-  while (image[0].coords.crval1 > 360.0) image[0].coords.crval1 -= 360.0;
+  
+  image[0].coords.crval1 = ohana_normalize_angle (image[0].coords.crval1);
 
   /* CERROR in data file is in pixels, convert to 20*arcsec */
   image[0].cerror = tmp * 50.0 * image[0].coords.cdelt1 * 3600.0;
-  while (image[0].coords.crval1 < 0) image[0].coords.crval1 += 360.0;
-  while (image[0].coords.crval1 > 360.0) image[0].coords.crval1 -= 360.0;
  
   /* get other header info */
Index: /trunk/Ohana/src/fixcat/src/aregion.c
===================================================================
--- /trunk/Ohana/src/fixcat/src/aregion.c	(revision 19822)
+++ /trunk/Ohana/src/fixcat/src/aregion.c	(revision 19823)
@@ -38,6 +38,5 @@
   int i, NBigDec, NLINES, done, nregion;
   
-  while (ra < 0) { ra += 360.0; }
-  while (ra >= 360.0) { ra -= 360.0; }
+  ra = ohana_normalize_angle (ra);
     
   if (dec >= 86.25) {
Index: /trunk/Ohana/src/gastro/src/gfit.c
===================================================================
--- /trunk/Ohana/src/gastro/src/gfit.c	(revision 19822)
+++ /trunk/Ohana/src/gastro/src/gfit.c	(revision 19823)
@@ -437,6 +437,5 @@
   }
 
-  while (coords[0].crval1 < 0) coords[0].crval1 += 360.0;
-  while (coords[0].crval1 > 360.0) coords[0].crval1 -= 360.0;
+  coords[0].crval1 = ohana_normalize_angle (coords[0].crval1);
 
   *DR = sqrt (SQ(dX*coords[0].cdelt1*3600.0) + SQ(dY*coords[0].cdelt1*3600.0));
Index: /trunk/Ohana/src/gastro/src/gfitpoly.c
===================================================================
--- /trunk/Ohana/src/gastro/src/gfitpoly.c	(revision 19822)
+++ /trunk/Ohana/src/gastro/src/gfitpoly.c	(revision 19823)
@@ -288,6 +288,5 @@
   }
 
-  while (coords[0].crval1 < 0) coords[0].crval1 += 360.0;
-  while (coords[0].crval1 > 360.0) coords[0].crval1 -= 360.0;
+  coords[0].crval1 = ohana_normalize_angle (coords[0].crval1);
 
   {
Index: /trunk/Ohana/src/gastro/src/greference.c
===================================================================
--- /trunk/Ohana/src/gastro/src/greference.c	(revision 19822)
+++ /trunk/Ohana/src/gastro/src/greference.c	(revision 19823)
@@ -18,8 +18,6 @@
   /* get stars from the USNO catalog for the given region */
   if (!strcmp (REFCAT, "USNO") || !strcmp (REFCAT, "BOTH")) {
-    while (catstats.RA[0] > 360.0) catstats.RA[0] -= 360.0;
-    while (catstats.RA[0] <   0.0) catstats.RA[0] += 360.0;
-    while (catstats.RA[1] > 360.0) catstats.RA[1] -= 360.0;
-    while (catstats.RA[1] <   0.0) catstats.RA[1] += 360.0;
+    catstats.RA[0] = ohana_normalize_angle (catstats.RA[0]);
+    catstats.RA[1] = ohana_normalize_angle (catstats.RA[1]);
 
     /* if RA crosses 0,360 boundary, do 2 passes */
Index: /trunk/Ohana/src/gastro/src/gstars.c
===================================================================
--- /trunk/Ohana/src/gastro/src/gstars.c	(revision 19822)
+++ /trunk/Ohana/src/gastro/src/gstars.c	(revision 19823)
@@ -142,6 +142,5 @@
     coords[0].crval1 = (DEG_RAD * atan2 (T2, T1)) + PR;
     coords[0].crval2 = (DEG_RAD * asin (T3));
-    while (coords[0].crval1 < 0) coords[0].crval1 += 360.0;
-    while (coords[0].crval1 > 360.0) coords[0].crval1 -= 360.0;
+    coords[0].crval1 = ohana_normalize_angle (coords[0].crval1);
     
     if (VERBOSE) fprintf (stderr, "  after polar alignment: %9.4f %9.4f\n", coords[0].crval1, coords[0].crval2);
Index: /trunk/Ohana/src/gastro2/src/gstars2.c
===================================================================
--- /trunk/Ohana/src/gastro2/src/gstars2.c	(revision 19822)
+++ /trunk/Ohana/src/gastro2/src/gstars2.c	(revision 19823)
@@ -113,6 +113,5 @@
     Target[0].coords.crval1 = (DEG_RAD * atan2 (T2, T1)) + PR;
     Target[0].coords.crval2 = (DEG_RAD * asin (T3));
-    while (Target[0].coords.crval1 < 0) Target[0].coords.crval1 += 360.0;
-    while (Target[0].coords.crval1 > 360.0) Target[0].coords.crval1 -= 360.0;
+    Target[0].coords.crval1 = ohana_normalize_angle (Target[0].coords.crval1);
     
     if (VERBOSE) fprintf (stderr, "  after polar alignment: %9.4f %9.4f\n", Target[0].coords.crval1, Target[0].coords.crval2);
Index: /trunk/Ohana/src/gastro2/src/polyfit.c
===================================================================
--- /trunk/Ohana/src/gastro2/src/polyfit.c	(revision 19822)
+++ /trunk/Ohana/src/gastro2/src/polyfit.c	(revision 19823)
@@ -375,6 +375,5 @@
   }
 
-  while (coords[0].crval1 < 0) coords[0].crval1 += 360.0;
-  while (coords[0].crval1 > 360.0) coords[0].crval1 -= 360.0;
+  coords[0].crval1 = ohana_normalize_angle (coords[0].crval1);
 
   /* test for valid solution */
Index: /trunk/Ohana/src/getstar/src/ReadImageHeader.c
===================================================================
--- /trunk/Ohana/src/getstar/src/ReadImageHeader.c	(revision 19822)
+++ /trunk/Ohana/src/getstar/src/ReadImageHeader.c	(revision 19823)
@@ -58,6 +58,5 @@
   } else {
     /* force image to lie in 0-360 range */
-    while (image[0].coords.crval1 < 0) image[0].coords.crval1 += 360.0;
-    while (image[0].coords.crval1 > 360.0) image[0].coords.crval1 -= 360.0;
+    image[0].coords.crval1 = ohana_normalize_angle (image[0].coords.crval1);
   }
 
Index: /trunk/Ohana/src/getstar/src/args.c
===================================================================
--- /trunk/Ohana/src/getstar/src/args.c	(revision 19822)
+++ /trunk/Ohana/src/getstar/src/args.c	(revision 19823)
@@ -96,8 +96,7 @@
     // XXX we will have issues at 0,360 boundary...
     // see code in dvo/pmeasure for fixes
-    while (REGION.Rmin > 360) REGION.Rmin -= 360.0;
-    while (REGION.Rmin <   0) REGION.Rmin += 360.0;
-    while (REGION.Rmax > 360) REGION.Rmax -= 360.0;
-    while (REGION.Rmax <   0) REGION.Rmax += 360.0;
+    REGION.Rmin = ohana_normalize_angle (REGION.Rmin);
+    REGION.Rmax = ohana_normalize_angle (REGION.Rmax);
+
     if (REGION.Dmax < REGION.Dmin) {
 	SWAP (REGION.Dmax, REGION.Dmin);
Index: /trunk/Ohana/src/libdvo/src/coordops.c
===================================================================
--- /trunk/Ohana/src/libdvo/src/coordops.c	(revision 19822)
+++ /trunk/Ohana/src/libdvo/src/coordops.c	(revision 19823)
@@ -134,7 +134,5 @@
     *dec = DEG_RAD*delta;
 
-    /* rationalize ra range 0 - 360.0 */
-    while (*ra < 0.0)   *ra += 360.0;
-    while (*ra > 360.0) *ra -= 360.0;
+    *ra = ohana_normalize_angle (*ra);
 
     return (TRUE);
@@ -168,7 +166,5 @@
     *dec = delta + coords[0].crval2;
 
-    /* rationalize ra range 0 - 360.0 */
-    while (*ra < 0.0)   *ra += 360.0;
-    while (*ra > 360.0) *ra -= 360.0;
+    *ra = ohana_normalize_angle (*ra);
 
     return (TRUE);
Index: /trunk/Ohana/src/libdvo/src/skydb.c
===================================================================
--- /trunk/Ohana/src/libdvo/src/skydb.c	(revision 19822)
+++ /trunk/Ohana/src/libdvo/src/skydb.c	(revision 19823)
@@ -99,8 +99,6 @@
   SkyRegion *list, *new, *sub;
 
-  while (c1.r > 360.0) c1.r -= 360.0;
-  while (c1.r <   0.0) c1.r += 360.0;
-  while (c2.r > 360.0) c2.r -= 360.0;
-  while (c2.r <   0.0) c2.r += 360.0;
+  c1.r = ohana_normalize_angle (c1.r);
+  c2.r = ohana_normalize_angle (c2.r);
 
   /* check on c1.r > c2.r : cross boundary */
Index: /trunk/Ohana/src/libdvo/src/skyregion_ops.c
===================================================================
--- /trunk/Ohana/src/libdvo/src/skyregion_ops.c	(revision 19822)
+++ /trunk/Ohana/src/libdvo/src/skyregion_ops.c	(revision 19823)
@@ -206,9 +206,6 @@
   SkyList *list, *extra;
 
-  /* rationalize Rmin, Rmax */
-  while (Rmin <   0.0) Rmin += 360;
-  while (Rmin > 360.0) Rmin -= 360;
-  while (Rmax <   0.0) Rmax += 360;
-  while (Rmax > 360.0) Rmax -= 360;
+  Rmin = ohana_normalize_angle (Rmin);
+  Rmax = ohana_normalize_angle (Rmax);
 
   /* handle 0,360 boundary requests */
Index: /trunk/Ohana/src/libohana/include/ohana.h
===================================================================
--- /trunk/Ohana/src/libohana/include/ohana.h	(revision 19822)
+++ /trunk/Ohana/src/libohana/include/ohana.h	(revision 19823)
@@ -203,4 +203,5 @@
 double  ohana_lst              PROTO((double jd, double longitude));
 int     ohana_str_to_radec     PROTO((double *ra, double *dec, char *str1, char *str2));
+double  ohana_normalize_angle  PROTO((double angle));
 
 int     hstgsc_hms_to_deg      PROTO((double *h0, double *h1, double *d0, double *d1, char *string));
Index: /trunk/Ohana/src/libohana/src/time.c
===================================================================
--- /trunk/Ohana/src/libohana/src/time.c	(revision 19822)
+++ /trunk/Ohana/src/libohana/src/time.c	(revision 19823)
@@ -434,2 +434,36 @@
   return (sid_g);
 }
+
+double ohana_normalize_angle (double angle) {
+
+    double result;
+
+    // take an input angle and force the domain to be 0.0 - 360.0
+    // there are a few ways to do this:  
+
+    // option 1: This is a potentially very slow method, also subject to round off errors
+# if (0)
+    while (angle > 360.0) angle -= 360.0;
+    while (angle <   0.0) angle += 360.0;
+# endif
+    
+    // option 2: take sin & cos, apply atan2 (y, x) 
+# if (1)    
+    double x, y;
+
+    x = cos(angle*RAD_DEG);
+    y = sin(angle*RAD_DEG);
+
+    result = atan2 (y, x);
+    if (result < 0.0) result += 360.0;
+# endif
+
+# if (0)
+    // option 3:
+    int nCircle = angle / 360.0;
+    result -= 360.0*nCircle;
+    if (result < 0.0) result += 360.0;
+# endif
+
+    return (result);
+}
Index: /trunk/Ohana/src/mosastro/src/LoadStars.c
===================================================================
--- /trunk/Ohana/src/mosastro/src/LoadStars.c	(revision 19822)
+++ /trunk/Ohana/src/mosastro/src/LoadStars.c	(revision 19823)
@@ -33,6 +33,5 @@
       continue;
     }
-    while (chip[Nchip].coords.crval1 < 0) chip[Nchip].coords.crval1 += 360.0;
-    while (chip[Nchip].coords.crval1 > 360.0) chip[Nchip].coords.crval1 -= 360.0;
+    chip[Nchip].coords.crval1 = ohana_normalize_angle (chip[Nchip].coords.crval1);
 
     itmp = 0;
Index: /trunk/Ohana/src/mosastro/src/transforms.c
===================================================================
--- /trunk/Ohana/src/mosastro/src/transforms.c	(revision 19822)
+++ /trunk/Ohana/src/mosastro/src/transforms.c	(revision 19823)
@@ -5,6 +5,5 @@
   for (i = 0; i < Nstars; i++) {
     XY_to_RD (&stars[i].R, &stars[i].D, stars[i].X, stars[i].Y, coords);
-    while (stars[i].R < 0.0)    stars[i].R += 360.0;
-    while (stars[i].R >= 360.0) stars[i].R -= 360.0;
+    stars[i].R = ohana_normalize_angle (stars[i].R);
   }
 }
@@ -28,6 +27,5 @@
   for (i = 0; i < Nstars; i++) {
     XY_to_RD (&stars[i].R, &stars[i].D, stars[i].P, stars[i].Q, coords);
-    while (stars[i].R < 0.0)    stars[i].R += 360.0;
-    while (stars[i].R >= 360.0) stars[i].R -= 360.0;
+    stars[i].R = ohana_normalize_angle (stars[i].R);
   }
 }
Index: /trunk/Ohana/src/opihi/cmd.astro/cplot.c
===================================================================
--- /trunk/Ohana/src/opihi/cmd.astro/cplot.c	(revision 19822)
+++ /trunk/Ohana/src/opihi/cmd.astro/cplot.c	(revision 19823)
@@ -41,4 +41,5 @@
   Npts = 0;
   for (i = 0; i < Xvec.Nelements; i++, r++, d++) {
+      *r = ohana_normalize_angle (*r);
     while (*r < Rmin) *r += 360.0;
     while (*r > Rmax) *r -= 360.0;
Index: /trunk/Ohana/src/opihi/cmd.astro/czplot.c
===================================================================
--- /trunk/Ohana/src/opihi/cmd.astro/czplot.c	(revision 19822)
+++ /trunk/Ohana/src/opihi/cmd.astro/czplot.c	(revision 19823)
@@ -49,6 +49,5 @@
   for (i = 0; i < Zvec.Nelements; i++, in++, out++, r++, d++, x++, y++) {
     *out = MIN (1.0, MAX (0.01, (*in - min) / range));
-    while (*r < Rmin) *r += 360.0;
-    while (*r > Rmax) *r -= 360.0;
+    *r = ohana_normalize_angle (*r);
     fRD_to_XY (x, y, *r, *d, &graphmode.coords);
   }
Index: /trunk/Ohana/src/opihi/cmd.astro/drizzle.c
===================================================================
--- /trunk/Ohana/src/opihi/cmd.astro/drizzle.c	(revision 19822)
+++ /trunk/Ohana/src/opihi/cmd.astro/drizzle.c	(revision 19823)
@@ -221,6 +221,5 @@
   *phi   = DEG_RAD*atan2(y,x) + rot_phi;
   
-  while (*phi <   0.0) *phi += 360.0;
-  while (*phi > 360.0) *phi -= 360.0;
+  *phi = ohana_normalize_angle(*phi);
   return (TRUE);
 }
Index: /trunk/Ohana/src/opihi/cmd.astro/getvel.c
===================================================================
--- /trunk/Ohana/src/opihi/cmd.astro/getvel.c	(revision 19822)
+++ /trunk/Ohana/src/opihi/cmd.astro/getvel.c	(revision 19823)
@@ -43,6 +43,5 @@
   dV *= 0.001;
 
-  while (L >= 360) {L -= 360.0;}
-  while (L < 0.0)  {L += 360.0;}
+  L = ohana_normalize_angle (L);
   gprint (GP_ERR, "L: %f\n", L);
 
Index: /trunk/Ohana/src/opihi/cmd.astro/polar.c
===================================================================
--- /trunk/Ohana/src/opihi/cmd.astro/polar.c	(revision 19822)
+++ /trunk/Ohana/src/opihi/cmd.astro/polar.c	(revision 19823)
@@ -55,7 +55,5 @@
       y = (j - Yo) * dN + No;
       r = hypot(x, y);
-      t = DEG_RAD*atan2 (y, x);
-      while (t < 360.0) {t += 360.0;}
-      while (t > 360.0) {t -= 360.0;}
+      t = ohana_normalize_angle(DEG_RAD*atan2 (y, x));
       X = (t - Lo) / dL + xo;
       Y = (r - Do) / dD + yo;
Index: /trunk/Ohana/src/opihi/cmd.astro/rotcurve.c
===================================================================
--- /trunk/Ohana/src/opihi/cmd.astro/rotcurve.c	(revision 19822)
+++ /trunk/Ohana/src/opihi/cmd.astro/rotcurve.c	(revision 19823)
@@ -70,6 +70,6 @@
   gfits_scan (&out[0].header, "CRPIX2", "%lf", 1, &Yo);
 
-  while (L >= 360) {L -= 360.0;}
-  while (L < 0.0)  {L += 360.0;}
+  L = ohana_normalize_angle (L);
+
   X = (L - Lo) / dL + Xo;
   if ((X >= Nx) || (X < 0)) {
Index: /trunk/Ohana/src/opihi/dimm/telescope.c
===================================================================
--- /trunk/Ohana/src/opihi/dimm/telescope.c	(revision 19822)
+++ /trunk/Ohana/src/opihi/dimm/telescope.c	(revision 19823)
@@ -63,8 +63,6 @@
     }
 
-    ra  = atof (argv[2]);
+    ra  = ohana_normalize_angle(atof (argv[2]));
     dec = atof (argv[3]);
-    while (ra  < 360.0) ra += 360.0;   
-    while (ra  > 360.0) ra -= 360.0;   
 
     status = gotoRD (ra, dec);
Index: /trunk/Ohana/src/opihi/dvo/ImageOps.c
===================================================================
--- /trunk/Ohana/src/opihi/dvo/ImageOps.c	(revision 19822)
+++ /trunk/Ohana/src/opihi/dvo/ImageOps.c	(revision 19823)
@@ -65,4 +65,5 @@
 	if ((j == 0) && (r < Rmin)) flipped = TRUE; 
 	if ((j == 0) && (r > Rmax)) flipped = TRUE; 
+	r = ohana_normalize_angle (r);
 	while (flipped && (r < Rmid)) r+= 360.0;
 	while (flipped && (r > Rmid)) r-= 360.0;
Index: /trunk/Ohana/src/opihi/dvo/aregion.c
===================================================================
--- /trunk/Ohana/src/opihi/dvo/aregion.c	(revision 19822)
+++ /trunk/Ohana/src/opihi/dvo/aregion.c	(revision 19823)
@@ -9,6 +9,5 @@
   int i, NBigDec, NLINES, done;
   
-  while (ra < 0) { ra += 360.0; }
-  while (ra >= 360.0) { ra -= 360.0; }
+  ra = ohana_normalize_angle (ra);
 
   if (dec >= 86.25) {
Index: /trunk/Ohana/src/opihi/dvo/catalog.c
===================================================================
--- /trunk/Ohana/src/opihi/dvo/catalog.c	(revision 19822)
+++ /trunk/Ohana/src/opihi/dvo/catalog.c	(revision 19823)
@@ -344,4 +344,5 @@
 	if (LimExclude && (Zvec.elements[N] > 0.99)) continue;
 	if (Zvec.elements[N] < 0.011) continue;
+	catalog.average[i].R = ohana_normalize_angle (catalog.average[i].R);
 	while (catalog.average[i].R < Rmin) catalog.average[i].R += 360.0;
 	while (catalog.average[i].R > Rmax) catalog.average[i].R -= 360.0;
@@ -359,4 +360,5 @@
 	if (Zvec.elements[N] == 0.01) 
 	  continue;
+	catalog.average[i].R = ohana_normalize_angle (catalog.average[i].R);
 	while (catalog.average[i].R < Rmin) catalog.average[i].R += 360.0;
 	while (catalog.average[i].R > Rmax) catalog.average[i].R -= 360.0;
@@ -374,4 +376,5 @@
 	if (Zvec.elements[N] == 0.01) 
 	  continue;
+	catalog.average[i].R = ohana_normalize_angle (catalog.average[i].R);
 	while (catalog.average[i].R < Rmin) catalog.average[i].R += 360.0;
 	while (catalog.average[i].R > Rmax) catalog.average[i].R -= 360.0;
Index: /trunk/Ohana/src/opihi/dvo/find_regions.c
===================================================================
--- /trunk/Ohana/src/opihi/dvo/find_regions.c	(revision 19822)
+++ /trunk/Ohana/src/opihi/dvo/find_regions.c	(revision 19823)
@@ -27,6 +27,5 @@
   nregion = 0;
 
-  while (Ra < 0) Ra += 360.0;
-  while (Ra >= 360) Ra -= 360.0;
+  Ra = ohana_normalize_angle (Ra);
 
   minDec = Dec - radius;
Index: /trunk/Ohana/src/opihi/dvo/gstar.c
===================================================================
--- /trunk/Ohana/src/opihi/dvo/gstar.c	(revision 19822)
+++ /trunk/Ohana/src/opihi/dvo/gstar.c	(revision 19823)
@@ -75,6 +75,5 @@
   Radius = atof (argv[3]);
 
-  while (Ra < 0.0) Ra += 360.0;
-  while (Ra > 360.0) Ra -= 360.0;
+  Ra = ohana_normalize_angle (Ra);
   
   /* load sky from correct table */
Index: /trunk/Ohana/src/opihi/dvo/images.c
===================================================================
--- /trunk/Ohana/src/opihi/dvo/images.c	(revision 19822)
+++ /trunk/Ohana/src/opihi/dvo/images.c	(revision 19823)
@@ -179,4 +179,5 @@
       status = XY_to_RD (&r[j], &d[j], x[j], y[j], &image[i].coords);
       if (!status) break;
+      r[j] = ohana_normalize_angle (r[j]);
       while (r[j] < Rmin) { r[j] += 360.0; }
       while (r[j] > Rmax) { r[j] -= 360.0; }
@@ -216,4 +217,5 @@
 	  status = XY_to_RD (&r[j], &d[j], x[jp], y[jp], &image[i].coords);
 	  if (!status) continue;
+	  r[j] = ohana_normalize_angle (r[j]);
 	  while (r[j] < Rmin) { r[j] += 360.0; }
 	  while (r[j] > Rmax) { r[j] -= 360.0; }
Index: /trunk/Ohana/src/opihi/dvo/imbox.c
===================================================================
--- /trunk/Ohana/src/opihi/dvo/imbox.c	(revision 19822)
+++ /trunk/Ohana/src/opihi/dvo/imbox.c	(revision 19823)
@@ -70,4 +70,5 @@
     for (j = 0; j < 4; j++) {
       XY_to_RD (&r, &d, x[j], y[j], &coords);
+      r = ohana_normalize_angle (r);
       while ((j == 0) && (r < Rmin)) { flipped = TRUE; r += 360.0; }
       while ((j == 0) && (r > Rmax)) { flipped = TRUE; r -= 360.0; }
Index: /trunk/Ohana/src/opihi/dvo/imdense.c
===================================================================
--- /trunk/Ohana/src/opihi/dvo/imdense.c	(revision 19822)
+++ /trunk/Ohana/src/opihi/dvo/imdense.c	(revision 19823)
@@ -42,4 +42,5 @@
     if (!FindMosaicForImage (image, Nimage, i)) continue;
     XY_to_RD (&r, &d, x, y, &image[i].coords);
+    r = ohana_normalize_angle (r);
     while (r < Rmin) r += 360.0; 
     while (r > Rmax) r -= 360.0; 
Index: /trunk/Ohana/src/opihi/dvo/paverage.c
===================================================================
--- /trunk/Ohana/src/opihi/dvo/paverage.c	(revision 19822)
+++ /trunk/Ohana/src/opihi/dvo/paverage.c	(revision 19823)
@@ -117,4 +117,5 @@
     for (i = 0; i < catalog.Naverage; i++) {
       if (IDclip && (average[i].code != IDchoice)) continue;
+      average[i].R = ohana_normalize_angle (average[i].R);
       while (average[i].R < Rmin) average[i].R += 360.0;
       while (average[i].R > Rmax) average[i].R -= 360.0;
Index: /trunk/Ohana/src/opihi/dvo/pmeasure.c
===================================================================
--- /trunk/Ohana/src/opihi/dvo/pmeasure.c	(revision 19822)
+++ /trunk/Ohana/src/opihi/dvo/pmeasure.c	(revision 19823)
@@ -187,4 +187,5 @@
     for (i = 0; i < catalog.Naverage; i++) {
       if (IDclip && (catalog.average[i].code != IDchoice)) continue;
+      catalog.average[i].R = ohana_normalize_angle (catalog.average[i].R);
       while (catalog.average[i].R < Rmin) catalog.average[i].R += 360.0;
       while (catalog.average[i].R > Rmax) catalog.average[i].R -= 360.0;
Index: /trunk/Ohana/src/opihi/dvo/procks.c
===================================================================
--- /trunk/Ohana/src/opihi/dvo/procks.c	(revision 19822)
+++ /trunk/Ohana/src/opihi/dvo/procks.c	(revision 19823)
@@ -103,4 +103,5 @@
     if (SpeedClip && ((rocks[i].Y[0] < S0) || (rocks[i].Y[0] > S1))) continue;
     for (j = 0; j < 3; j++) {
+      rocks[i].ra[j]= ohana_normalize_angle (rocks[i].ra[j]);	
       while (rocks[i].ra[j] < Rmin) rocks[i].ra[j] += 360.0;
       while (rocks[i].ra[j] > Rmax) rocks[i].ra[j] -= 360.0;
@@ -129,4 +130,6 @@
       if (rocks[i].t[j] > t1) { N1 = j; t1 = rocks[i].t[j]; }
     }
+    rocks[i].ra[N0]= ohana_normalize_angle (rocks[i].ra[N0]);	
+    rocks[i].ra[N1]= ohana_normalize_angle (rocks[i].ra[N1]);	
     while (rocks[i].ra[N0] < Rmin) rocks[i].ra[N0] += 360.0;
     while (rocks[i].ra[N0] > Rmax) rocks[i].ra[N0] -= 360.0;
Index: /trunk/Ohana/src/opihi/dvo/skycat.c
===================================================================
--- /trunk/Ohana/src/opihi/dvo/skycat.c	(revision 19822)
+++ /trunk/Ohana/src/opihi/dvo/skycat.c	(revision 19823)
@@ -110,6 +110,5 @@
 int RD_to_XYpic (double *x, double *y, double r, double d, Coords *coords, double Rmin, double Rmax, double Rmid, int *leftside) {
 
-  while (r < Rmin) { r += 360.0; }
-  while (r > Rmax) { r -= 360.0; }
+  r = ohana_normalize_angle (r);
 
   if (*leftside == -1) {
Index: /trunk/Ohana/src/opihi/dvo/skycoverage.c
===================================================================
--- /trunk/Ohana/src/opihi/dvo/skycoverage.c	(revision 19822)
+++ /trunk/Ohana/src/opihi/dvo/skycoverage.c	(revision 19823)
@@ -128,6 +128,5 @@
       for (Xi = x[0] + 0.5*dPix; Xi < x[1]; Xi += dPix) {
 	XY_to_RD (&r, &d, Xi, Yi, &image[i].coords);
-	while (r <   0.0) { r += 360.0; }
-	while (r > 360.0) { r -= 360.0; }
+	r = ohana_normalize_angle (r);
 	status = RD_to_XY (&Xs, &Ys, r, d, &coords);
 	if (status) {
Index: /trunk/Ohana/src/opihi/dvo/subpix.c
===================================================================
--- /trunk/Ohana/src/opihi/dvo/subpix.c	(revision 19822)
+++ /trunk/Ohana/src/opihi/dvo/subpix.c	(revision 19823)
@@ -27,6 +27,6 @@
   }
   if (!ohana_str_to_radec (&Ra, &Dec, argv[1], argv[2])) return (FALSE);
-  if (Ra < 0) Ra += 360.0;
-  if (Ra > 360.0) Ra -= 360.0;
+  Ra = ohana_normalize_angle (Ra);
+
   Radius = atof (argv[3]);
 
Index: /trunk/Ohana/src/skycalc/src/moon_interference.c
===================================================================
--- /trunk/Ohana/src/skycalc/src/moon_interference.c	(revision 19822)
+++ /trunk/Ohana/src/skycalc/src/moon_interference.c	(revision 19823)
@@ -771,6 +771,5 @@
     
     *az *= DEG_IN_RADIAN;  /* done with taking trig functions of it ... */ 
-    while(*az < 0.) *az += 360.;  /* force 0 -> 360 */
-    while(*az >= 360.) *az -= 360.;
+    *az = ohana_normalize_angle (*az);
     
     return(x);
Index: /trunk/Ohana/src/uniphot/src/update.c
===================================================================
--- /trunk/Ohana/src/uniphot/src/update.c	(revision 19822)
+++ /trunk/Ohana/src/uniphot/src/update.c	(revision 19823)
@@ -62,8 +62,7 @@
     gfits_scan (&catalog.header, "DEC0", "%lf", 1, &Dmin);
     gfits_scan (&catalog.header, "DEC1", "%lf", 1, &Dmax);
-    while (Rmin <   0.0) { Rmin += 360.0; }
-    while (Rmin > 360.0) { Rmin -= 360.0; }
-    while (Rmax <   0.0) { Rmax += 360.0; }
-    while (Rmax > 360.0) { Rmax -= 360.0; }
+
+    Rmin = ohana_normalize_angle (Rmin);
+    Rmax = ohana_normalize_angle (Rmax);
 
     coords.crval1 = 0.5*(Rmin + Rmax);
