Index: trunk/Ohana/src/opihi/cmd.astro/cplot.c
===================================================================
--- trunk/Ohana/src/opihi/cmd.astro/cplot.c	(revision 21153)
+++ trunk/Ohana/src/opihi/cmd.astro/cplot.c	(revision 34584)
@@ -3,4 +3,5 @@
 int cplot (int argc, char **argv) {
   
+  double ra_prev;
   int i, kapa, Npts, status, leftside;
   opihi_flt *x, *y, *r, *d, Rmin, Rmax, Rmid;
@@ -41,15 +42,19 @@
   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;
+    double ra = ohana_normalize_angle (*r);
+    while (ra < Rmin) ra += 360.0;
+    while (ra > Rmax) ra -= 360.0;
 
     // for pair-by-pair connections, check on second point if we straddle the back midline
-    if ((graphmode.ptype == 100) && (i % 2)) {
-      leftside = (r[-1] < Rmid); // if first of the pair is left, second must be as well
-      if ( leftside && (r[0] > Rmid + 90)) { r[0] -= 360.0; }
-      if (!leftside && (r[0] < Rmid - 90)) { r[0] += 360.0; }
+    if (graphmode.ptype == 100) {
+      if (i % 2) {
+	leftside = (ra_prev < Rmid); // if first of the pair is left, second must be as well
+	if ( leftside && (ra > Rmid + 90)) { ra -= 360.0; }
+	if (!leftside && (ra < Rmid - 90)) { ra += 360.0; }
+      } else {
+	ra_prev = ra;
+      }
     }
-    status = RD_to_XY (x, y, *r, *d, &graphmode.coords);
+    status = RD_to_XY (x, y, ra, *d, &graphmode.coords);
 
     // if we fail on one of the points, drop the corresponding pair
@@ -78,5 +83,5 @@
 
   graphmode.etype = 0;
-  PlotVectorPair (kapa, &Xvec, &Yvec, &graphmode);
+  PlotVectorPair (kapa, &Xvec, &Yvec, NULL, &graphmode);
   
   free (Xvec.elements.Ptr);
