Index: /trunk/psastro/src/psastroOneChip.c
===================================================================
--- /trunk/psastro/src/psastroOneChip.c	(revision 9646)
+++ /trunk/psastro/src/psastroOneChip.c	(revision 9647)
@@ -8,10 +8,17 @@
     psastroWriteStars ("raw.0.dat", rawstars);
     psastroWriteStars ("ref.0.dat", refstars);
-    psastroWriteTransform (chip->toFPA);
+    // psastroWriteTransform (chip->toFPA);
 
     // find initial offset / rotation
-    pmAstromStats stats = pmAstromGridMatch (rawstars, refstars, recipe);
-    stats = pmAstromGridTweak (rawstars, refstars, recipe, stats);
-    psLogMsg ("psastro", 3, "grid search result: %f,%f @ %f deg\n", stats.offset.x, stats.offset.y, DEG_RAD*stats.angle);
+    pmAstromStats *gridStats = pmAstromGridMatch (rawstars, refstars, recipe);
+    if (gridStats == NULL) {
+	psError(PSASTRO_ERR_DATA, false, "failed to find a grid match solution\n");
+        return false;
+    }
+    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);
+
+    pmAstromStats *stats = pmAstromGridTweak (rawstars, refstars, recipe, gridStats);
+
+    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);
 
     // adjust the chip.toFPA terms only
@@ -21,5 +28,5 @@
     psastroWriteStars ("raw.1.dat", rawstars);
     psastroWriteStars ("ref.1.dat", refstars);
-    psastroWriteTransform (chip->toFPA);
+    // psastroWriteTransform (chip->toFPA);
 
     // use small radius to match stars
@@ -27,5 +34,10 @@
 
     // improved fit for astrometric terms
-    pmAstromMatchFit (chip->toFPA, rawstars, refstars, match, recipe, updates);
+    if (!pmAstromMatchFit (chip->toFPA, rawstars, refstars, match, recipe, updates)) {
+	psError(PSASTRO_ERR_DATA, false, "failed to find a valid fitted match solution\n");
+        return false;
+    }
+
+    // write results
     psastroUpdateChipToFPA (fpa, chip, rawstars, refstars);
 
@@ -35,4 +47,6 @@
 
     psFree (match);
+    psFree (stats);
+    psFree (gridStats);
     return true;
 }
