Index: /trunk/Ohana/src/addstar/src/find_matches.c
===================================================================
--- /trunk/Ohana/src/addstar/src/find_matches.c	(revision 8643)
+++ /trunk/Ohana/src/addstar/src/find_matches.c	(revision 8644)
@@ -1,5 +1,5 @@
 # include "addstar.h"
 
-void find_matches (SkyRegion *region, Stars *stars, int NstarsIn, Catalog *catalog, Image *image, Image *overlap, int Noverlap, Coords *mosaic, AddstarClientOptions options) {
+int find_matches (SkyRegion *region, Stars *stars, int NstarsIn, Catalog *catalog, Image *image, Image *overlap, int Noverlap, Coords *mosaic, AddstarClientOptions options) {
 
   int i, j, n, N, J, status, Nstars;
@@ -41,7 +41,11 @@
   NMISS = Nmiss = catalog[0].Nmissing;
   
-  /* project onto rectilinear grid with 1 arcsec pixels */
-  /* we keep the original crpix1,2 and crref1,2 */
-  /* for mosaic astrometry, the grid should be w.r.t. the tangent-plane, not chip coords */
+  /* project onto rectilinear grid with 1 arcsec pixels. the choice of ZEA projection has the
+     advantage that every point in R,D has a mapping to a unique X,Y.  However, note that not all
+     possible X,Y points map back to R,D and the local plate scale changes substantially far from
+     the projection pole.  a better mapping might be ARC, not yet implemented (see
+     coordops.update.c).  We keep the original crpix1,2 and crref1,2.  For mosaic astrometry, the
+     grid should be w.r.t. the tangent-plane, not chip coords */
+
   if (!strcmp (&image[0].coords.ctype[4], "-WRP")) {
     tcoords = mosaic[0];
@@ -50,5 +54,5 @@
     tcoords.pc1_2 = tcoords.pc2_1 = 0.0;
     tcoords.Npolyterms = 1;
-    strcpy (tcoords.ctype, "RA---TAN");
+    strcpy (tcoords.ctype, "RA---ZEA");
   } else {
     tcoords = image[0].coords;
@@ -57,5 +61,5 @@
     tcoords.pc1_2 = tcoords.pc2_1 = 0.0;
     tcoords.Npolyterms = 1;
-    strcpy (tcoords.ctype, "RA---TAN");
+    strcpy (tcoords.ctype, "RA---ZEA");
   }
 
@@ -151,4 +155,21 @@
       /** dR,dD now represent arcsec **/
       catalog[0].measure[Nmeas].dR_PS       = 3600.0*(catalog[0].average[n].R - stars[N].R);
+      if (catalog[0].measure[Nmeas].dR_PS > +180.0*3600.0) {
+	  // average on high end of boundary, move star up
+	  stars[N].R += 360.0;
+	  catalog[0].measure[Nmeas].dR_PS = 3600.0*(catalog[0].average[n].R - stars[N].R);
+      }
+      if (catalog[0].measure[Nmeas].dR_PS < -180.0*3600.0) {
+	  // average on low end of boundary, move star down
+	  stars[N].R -= 360.0;
+	  catalog[0].measure[Nmeas].dR_PS = 3600.0*(catalog[0].average[n].R - stars[N].R);
+      }
+      if (fabs(catalog[0].measure[Nmeas].dR_PS) > 10*RADIUS) {
+	  fprintf (stderr, "error: %10.6f,%10.6f vs %10.6f,%10.6f (%f,%f vs %f,%f)\n", 
+		   catalog[0].average[n].R, catalog[0].average[n].D, 
+		   stars[N].R, stars[N].D,
+		   X1[i], X2[Jmin], 
+		   Y1[i], Y2[Jmin]);
+      }
       catalog[0].measure[Nmeas].dD_PS       = 3600.0*(catalog[0].average[n].D - stars[N].D);
       catalog[0].measure[Nmeas].M_PS        = MIN (stars[N].M + MTIME, NO_MAG);
@@ -369,5 +390,5 @@
   free (Y2);
   free (N2);
-  return;
+  return (Nmatch);
 }
 
Index: /trunk/Ohana/src/addstar/src/find_matches_closest.c
===================================================================
--- /trunk/Ohana/src/addstar/src/find_matches_closest.c	(revision 8643)
+++ /trunk/Ohana/src/addstar/src/find_matches_closest.c	(revision 8644)
@@ -1,5 +1,5 @@
 # include "addstar.h"
 
-void find_matches_closest (SkyRegion *region, Stars *stars, int NstarsIn, Catalog *catalog, Image *image, Image *overlap, int Noverlap, Coords *mosaic, AddstarClientOptions options) {
+int find_matches_closest (SkyRegion *region, Stars *stars, int NstarsIn, Catalog *catalog, Image *image, Image *overlap, int Noverlap, Coords *mosaic, AddstarClientOptions options) {
 
   int i, j, n, N, J, Jmin, status, Nstars;
@@ -40,7 +40,11 @@
   NMISS = Nmiss = catalog[0].Nmissing;
 
-  /* project onto rectilinear grid with 1 arcsec pixels */
-  /* we keep the original crpix1,2 and crref1,2 */
-  /* for mosaic astrometry, the grid should be w.r.t. the tangent-plane, not chip coords */
+  /* project onto rectilinear grid with 1 arcsec pixels. the choice of ZEA projection has the
+     advantage that every point in R,D has a mapping to a unique X,Y.  However, note that not all
+     possible X,Y points map back to R,D and the local plate scale changes substantially far from
+     the projection pole.  a better mapping might be ARC, not yet implemented (see
+     coordops.update.c).  We keep the original crpix1,2 and crref1,2.  For mosaic astrometry, the
+     grid should be w.r.t. the tangent-plane, not chip coords */
+
   if (!strcmp (&image[0].coords.ctype[4], "-WRP")) {
     tcoords = mosaic[0];
@@ -49,5 +53,5 @@
     tcoords.pc1_2 = tcoords.pc2_1 = 0.0;
     tcoords.Npolyterms = 1;
-    strcpy (tcoords.ctype, "RA---TAN");
+    strcpy (tcoords.ctype, "RA---ZEA");
   } else {
     tcoords = image[0].coords;
@@ -56,5 +60,5 @@
     tcoords.pc1_2 = tcoords.pc2_1 = 0.0;
     tcoords.Npolyterms = 1;
-    strcpy (tcoords.ctype, "RA---TAN");
+    strcpy (tcoords.ctype, "RA---ZEA");
   }
 
@@ -174,4 +178,21 @@
     /** dR,dD now represent arcsec **/
     catalog[0].measure[Nmeas].dR_PS       = 3600.0*(catalog[0].average[n].R - stars[N].R);
+    if (catalog[0].measure[Nmeas].dR_PS > +180.0*3600.0) {
+      // average on high end of boundary, move star up
+      stars[N].R += 360.0;
+      catalog[0].measure[Nmeas].dR_PS = 3600.0*(catalog[0].average[n].R - stars[N].R);
+    }
+    if (catalog[0].measure[Nmeas].dR_PS < -180.0*3600.0) {
+      // average on low end of boundary, move star down
+      stars[N].R -= 360.0;
+      catalog[0].measure[Nmeas].dR_PS = 3600.0*(catalog[0].average[n].R - stars[N].R);
+    }
+    if (fabs(catalog[0].measure[Nmeas].dR_PS) > 10*RADIUS) {
+      fprintf (stderr, "error: %10.6f,%10.6f vs %10.6f,%10.6f (%f,%f vs %f,%f)\n", 
+	       catalog[0].average[n].R, catalog[0].average[n].D, 
+	       stars[N].R, stars[N].D,
+	       X1[i], X2[Jmin], 
+	       Y1[i], Y2[Jmin]);
+    }
     catalog[0].measure[Nmeas].dD_PS       = 3600.0*(catalog[0].average[n].D - stars[N].D);
     catalog[0].measure[Nmeas].M_PS        = MIN (stars[N].M + MTIME, NO_MAG);
@@ -374,5 +395,5 @@
   free (Y2);
   free (N2);
-  return;
+  return (Nmatch);
 }
 
Index: /trunk/Ohana/src/addstar/src/find_matches_refstars.c
===================================================================
--- /trunk/Ohana/src/addstar/src/find_matches_refstars.c	(revision 8643)
+++ /trunk/Ohana/src/addstar/src/find_matches_refstars.c	(revision 8644)
@@ -1,5 +1,5 @@
 # include "addstar.h"
 
-void find_matches_refstars (SkyRegion *region, Stars **stars, int Nstars, Catalog *catalog, AddstarClientOptions options) {
+int find_matches_refstars (SkyRegion *region, Stars **stars, int Nstars, Catalog *catalog, AddstarClientOptions options) {
 
   int i, j, k, n, m, N, J;
@@ -55,5 +55,5 @@
   tcoords.pc1_1 = tcoords.pc2_2 = 1.0;
   tcoords.pc1_2 = tcoords.pc2_1 = 0.0;
-  strcpy (tcoords.ctype, "RA---TAN");
+  strcpy (tcoords.ctype, "RA---ZEA");
   tcoords.Npolyterms = 0;
   
@@ -337,3 +337,4 @@
   catalog[0].Nmissing = Nmiss;
   if (VERBOSE) fprintf (stderr, "Nstars, Nave, Nmeas, Nmiss: %d %d %d %d, (%d matches)\n", Nstars, Nave, Nmeas, Nmiss, Nmatch);
+  return (Nmatch);
 }
