Index: trunk/Ohana/src/opihi/cmd.astro/cplot.c
===================================================================
--- trunk/Ohana/src/opihi/cmd.astro/cplot.c	(revision 19789)
+++ 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 19789)
+++ 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 19789)
+++ 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 19789)
+++ 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 19789)
+++ 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 19789)
+++ 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 19789)
+++ 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 19789)
+++ 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 19789)
+++ 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 19789)
+++ 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 19789)
+++ 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 19789)
+++ 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 19789)
+++ 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 19789)
+++ 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 19789)
+++ 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 19789)
+++ 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 19789)
+++ 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 19789)
+++ 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 19789)
+++ 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 19789)
+++ 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 19789)
+++ 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]);
 
