Index: trunk/psastro/src/psastroOneChip.c
===================================================================
--- trunk/psastro/src/psastroOneChip.c	(revision 9647)
+++ trunk/psastro/src/psastroOneChip.c	(revision 9655)
@@ -2,11 +2,4 @@
 
 bool psastroOneChip (pmFPA *fpa, pmChip *chip, psArray *refstars, psArray *rawstars, psMetadata *recipe, psMetadata *updates) {
-
-    // bool status;
-    psArray *match;
-
-    psastroWriteStars ("raw.0.dat", rawstars);
-    psastroWriteStars ("ref.0.dat", refstars);
-    // psastroWriteTransform (chip->toFPA);
 
     // find initial offset / rotation
@@ -18,6 +11,10 @@
     psLogMsg ("psastro", 3, "basic grid search result - offset: %f,%f pixels, rotation: %f deg\n", gridStats->offset.x, gridStats->offset.y, DEG_RAD*gridStats->angle);
 
+    // tweak the position by finding peak of matches stars
     pmAstromStats *stats = pmAstromGridTweak (rawstars, refstars, recipe, gridStats);
-
+    if (stats == NULL) {
+	psError(PSASTRO_ERR_DATA, false, "failed to measure tweaked grid solution\n");
+        return false;
+    }
     psLogMsg ("psastro", 3, "tweak grid search result - offset: %f,%f pixels, rotation: %f deg\n", stats->offset.x, stats->offset.y, DEG_RAD*stats->angle);
 
@@ -26,10 +23,10 @@
     psastroUpdateChipToFPA (fpa, chip, rawstars, refstars);
 
-    psastroWriteStars ("raw.1.dat", rawstars);
-    psastroWriteStars ("ref.1.dat", refstars);
-    // psastroWriteTransform (chip->toFPA);
-
     // use small radius to match stars
-    match = pmAstromRadiusMatch (rawstars, refstars, recipe);
+    psArray *match = pmAstromRadiusMatch (rawstars, refstars, recipe);
+    if (stats == NULL) {
+	psError(PSASTRO_ERR_UNKNOWN, false, "failed to find radius-matched sources\n");
+        return false;
+    }
 
     // improved fit for astrometric terms
@@ -42,8 +39,4 @@
     psastroUpdateChipToFPA (fpa, chip, rawstars, refstars);
 
-    psastroWriteStars ("raw.2.dat", rawstars);
-    psastroWriteStars ("ref.2.dat", refstars);
-    psastroWriteTransform (chip->toFPA);
-
     psFree (match);
     psFree (stats);
@@ -52,2 +45,6 @@
 }
 
+// psastroWriteStars ("raw.1.dat", rawstars);
+// psastroWriteStars ("ref.1.dat", refstars);
+// psastroWriteTransform (chip->toFPA);
+
