Index: trunk/psastro/src/psastroOneChip.c
===================================================================
--- trunk/psastro/src/psastroOneChip.c	(revision 11470)
+++ trunk/psastro/src/psastroOneChip.c	(revision 12492)
@@ -10,4 +10,6 @@
 
     bool status;
+    pmAstromStats *gridStats = NULL;
+    pmAstromStats *stats = NULL;
 
     // supplied radius is in pixels
@@ -25,23 +27,29 @@
     REQUIRED_RECIPE_VALUE (int minNstar, "PSASTRO.MIN.NSTAR", S32, "failed to find single-chip min allowed stars\n");
 
-    // find initial offset / rotation
-    pmAstromStats *gridStats = pmAstromGridMatch (rawstars, refstars, recipe);
-    if (gridStats == NULL) {
-	psLogMsg ("psastro", 3, "failed to find a grid match solution\n");
-        return false;
+    // do we need to get a rough initial match?
+    REQUIRED_RECIPE_VALUE (bool gridSearch, "PSASTRO.GRID.SEARCH", Bool, "failed to find chip grid-search option\n");
+
+    if (gridSearch) {
+	// find initial offset / rotation
+	gridStats = pmAstromGridMatch (rawstars, refstars, recipe);
+	if (gridStats == NULL) {
+	    psLogMsg ("psastro", 3, "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);
+
+	// tweak the position by finding peak of matches stars
+	stats = pmAstromGridTweak (rawstars, refstars, recipe, gridStats);
+	if (stats == NULL) {
+	    psLogMsg ("psastro", 3, "failed to measure tweaked grid solution\n");
+	    psFree (gridStats);
+	    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);
+
+	// adjust the chip.toFPA terms only
+	pmAstromGridApply (chip->toFPA, stats);
+	psastroUpdateChipToFPA (fpa, chip, rawstars, refstars);
     }
-    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) {
-	psLogMsg ("psastro", 3, "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);
-
-    // adjust the chip.toFPA terms only
-    pmAstromGridApply (chip->toFPA, stats);
-    psastroUpdateChipToFPA (fpa, chip, rawstars, refstars);
 
     // use small radius to match stars
@@ -49,4 +57,6 @@
     if (match == NULL) {
 	psLogMsg ("psastro", 3, "failed to find radius-matched sources\n");
+	psFree (stats);
+	psFree (gridStats);
         return false;
     }
@@ -85,4 +95,8 @@
     if (!results) {
 	psLogMsg ("psastro", 3, "failed to perform the matched fit\n");
+	psFree (match);
+	psFree (stats);
+	psFree (fitStats);
+	psFree (gridStats);
         return false;
     }
