Index: trunk/ippconfig/cfh12k/psastro.config
===================================================================
--- trunk/ippconfig/cfh12k/psastro.config	(revision 15670)
+++ trunk/ippconfig/cfh12k/psastro.config	(revision 15671)
@@ -17,18 +17,24 @@
 PSASTRO.TWEAK.NSIGMA    F32      3
 
-PSASTRO.MAX.NRAW       S32      500   # max stars accepted for fitting (0 for all)
-PSASTRO.MAX.NREF       S32      500   # max stars accepted for fitting (0 for all)
+PSASTRO.MATCH.RADIUS   F32     12.0
+
+PSASTRO.MAX.NRAW       S32      1500   # max stars accepted for fitting (0 for all)
+PSASTRO.MAX.NREF       S32      1500   # max stars accepted for fitting (0 for all)
+
+PSASTRO.MIN.INST.MAG.RAW       F32      -14.0  # min instrumental magnitude for stars accepted for fitting
+PSASTRO.MAX.INST.MAG.RAW       F32       -8.0  # max instrumental magnitude for stars accepted for fitting
 
 PSASTRO.MAX.ERROR      F32      10.0 # max error in pixels
 PSASTRO.MIN.NSTAR      S32      10   # min fitted stars in solution
 
-PSASTRO.MOSAIC.MAX.ERROR.N0 F32    0.90 # max allow error for valid solution (arcsec)
-PSASTRO.MOSAIC.MAX.ERROR.N1 F32    0.90 # max allow error for valid solution (arcsec)
+PSASTRO.MOSAIC.MAX.ERROR.N0 F32    1.50 # max allow error for valid solution (arcsec)
+PSASTRO.MOSAIC.MAX.ERROR.N1 F32    1.50 # max allow error for valid solution (arcsec)
 PSASTRO.MOSAIC.MAX.ERROR.N2 F32    0.90 # max allow error for valid solution (arcsec)
 PSASTRO.MOSAIC.MAX.ERROR.N3 F32    0.90 # max allow error for valid solution (arcsec)
 
-PSASTRO.MOSAIC.RADIUS.N0    F32    8.0
-PSASTRO.MOSAIC.RADIUS.N1    F32    0.0 # do not refine the match
-PSASTRO.MOSAIC.RADIUS.N2    F32    0.0
+PSASTRO.MOSAIC.RADIUS.N0    F32   12.0 # initial match (after chip astrom)
+PSASTRO.MOSAIC.RADIUS.N1    F32    0.0 # (after first mosaic pass)
+PSASTRO.MOSAIC.RADIUS.N2    F32    0.0 # do not refine the match
+PSASTRO.MOSAIC.RADIUS.N3    F32    6.0 # 
 
 PSASTRO.MOSAIC.CHIP.ORDER.N0  S32      0 # fit order (-1 means use default)
@@ -42,16 +48,17 @@
 # use this recipe to set a tight constraint
 PSASTRO.FINE METADATA
-  PSASTRO.MOSAIC.MAX.ERROR.N0 F32    0.50 # max allow error for valid solution (arcsec)
-  PSASTRO.MOSAIC.MAX.ERROR.N1 F32    0.40 # max allow error for valid solution (arcsec)
-  PSASTRO.MOSAIC.MAX.ERROR.N2 F32    0.20 # max allow error for valid solution (arcsec)
-  PSASTRO.MOSAIC.MAX.ERROR.N3 F32    0.10 # max allow error for valid solution (arcsec)
+  PSASTRO.MOSAIC.MAX.ERROR.N0 F32    1.50 # max allow error for valid solution (arcsec)
+  PSASTRO.MOSAIC.MAX.ERROR.N1 F32    1.50 # max allow error for valid solution (arcsec)
+  PSASTRO.MOSAIC.MAX.ERROR.N2 F32    0.90 # max allow error for valid solution (arcsec)
+  PSASTRO.MOSAIC.MAX.ERROR.N3 F32    0.90 # max allow error for valid solution (arcsec)
 
-  PSASTRO.MOSAIC.RADIUS.N0    F32    3
-  PSASTRO.MOSAIC.RADIUS.N1    F32    2
-  PSASTRO.MOSAIC.RADIUS.N2    F32    1
+  PSASTRO.MOSAIC.RADIUS.N0    F32    8.0
+  PSASTRO.MOSAIC.RADIUS.N1    F32    0.0
+  PSASTRO.MOSAIC.RADIUS.N2    F32    4.0
+  PSASTRO.MOSAIC.RADIUS.N3    F32    4.0
 
   PSASTRO.MOSAIC.CHIP.ORDER.N0  S32      0 # fit order (-1 means use default)
-  PSASTRO.MOSAIC.CHIP.ORDER.N1  S32      0 # fit order (-1 means use default)
+  PSASTRO.MOSAIC.CHIP.ORDER.N1  S32      1 # fit order (-1 means use default)
   PSASTRO.MOSAIC.CHIP.ORDER.N2  S32      1 # fit order (-1 means use default)
-  PSASTRO.MOSAIC.CHIP.ORDER.N3  S32      1 # fit order (-1 means use default)
+  PSASTRO.MOSAIC.CHIP.ORDER.N3  S32      3 # fit order (-1 means use default)
 END
Index: trunk/ippconfig/megacam/camera.config
===================================================================
--- trunk/ippconfig/megacam/camera.config	(revision 15670)
+++ trunk/ippconfig/megacam/camera.config	(revision 15671)
@@ -229,10 +229,12 @@
 
 EXTNAME.RULES METADATA
-  CMF.HEAD STR {CHIP.NAME}.hdr
-  CMF.DATA STR {CHIP.NAME}.psf # use .PSF and .EXT?
-
-  PSF.HEAD  STR	{CHIP.NAME}.hdr
-  PSF.TABLE STR {CHIP.NAME}.psf_model
-  PSF.RESID STR {CHIP.NAME}.psf_resid
+  CMF.HEAD   STR {CHIP.NAME}.hdr
+  CMF.DATA   STR {CHIP.NAME}.psf # use .PSF and .EXT?
+
+  PSF.HEAD   STR {CHIP.NAME}.hdr
+  PSF.TABLE  STR {CHIP.NAME}.psf_model
+  PSF.RESID  STR {CHIP.NAME}.psf_resid
+
+  REF.ASTROM STR {CHIP.NAME}.ref_astrom
 END
 
Index: trunk/ippconfig/megacam/psastro.config
===================================================================
--- trunk/ippconfig/megacam/psastro.config	(revision 15670)
+++ trunk/ippconfig/megacam/psastro.config	(revision 15671)
@@ -8,6 +8,6 @@
 # max grid offset in FP units (microns)
 # use plate-scale to make this in pixels?
-PSASTRO.GRID.OFFSET    F32    200.
-PSASTRO.GRID.SCALE     F32     15.
+PSASTRO.GRID.OFFSET    F32    1000.
+PSASTRO.GRID.SCALE     F32      50.
 
 # these tweak are in FP units (pixels, currently)
@@ -17,9 +17,11 @@
 PSASTRO.TWEAK.NSIGMA    F32      3
 
-PSASTRO.MAX.NRAW       S32      1000   # max stars accepted for fitting (0 for all)
-PSASTRO.MAX.NREF       S32      1000   # max stars accepted for fitting (0 for all)
+PSASTRO.MATCH.RADIUS   F32     12.0
+
+PSASTRO.MAX.NRAW       S32      1500   # max stars accepted for fitting (0 for all)
+PSASTRO.MAX.NREF       S32      1500   # max stars accepted for fitting (0 for all)
 
 PSASTRO.MIN.INST.MAG.RAW       F32      -14.5  # min instrumental magnitude for stars accepted for fitting
-PSASTRO.MAX.INST.MAG.RAW       F32       -9.0  # max instrumental magnitude for stars accepted for fitting
+PSASTRO.MAX.INST.MAG.RAW       F32       -8.0  # max instrumental magnitude for stars accepted for fitting
 
 PSASTRO.MAX.ERROR      F32      10.0 # max error in pixels
@@ -31,8 +33,8 @@
 PSASTRO.MOSAIC.MAX.ERROR.N3 F32    0.90 # max allow error for valid solution (arcsec)
 
-PSASTRO.MOSAIC.RADIUS.N0    F32    8.0
+PSASTRO.MOSAIC.RADIUS.N0    F32    12.0
 PSASTRO.MOSAIC.RADIUS.N1    F32    0.0 # do not refine the match
 PSASTRO.MOSAIC.RADIUS.N2    F32    0.0 # do not refine the match
-PSASTRO.MOSAIC.RADIUS.N3    F32    0.0 # do not refine the match
+PSASTRO.MOSAIC.RADIUS.N3    F32    6.0 
 
 PSASTRO.MOSAIC.CHIP.ORDER.N0  S32      0 # fit order (-1 means use default)
Index: trunk/ippconfig/recipes/psastro.config
===================================================================
--- trunk/ippconfig/recipes/psastro.config	(revision 15670)
+++ trunk/ippconfig/recipes/psastro.config	(revision 15671)
@@ -14,7 +14,13 @@
 # pmAstromGridMatch:
 PSASTRO.GRID.SEARCH    BOOL TRUE
+
 PSASTRO.GRID.MIN.ANGLE F32 -2.0 # start angle (degrees)
 PSASTRO.GRID.MAX.ANGLE F32 +2.0
 PSASTRO.GRID.DEL.ANGLE F32  0.5
+
+PSASTRO.GRID.MIN.SCALE F32  0.98
+PSASTRO.GRID.MAX.SCALE F32  1.02
+PSASTRO.GRID.DEL.SCALE F32  0.02
+
 PSASTRO.GRID.MIN.SIGMA F32  5.0
 
Index: trunk/psastro/src/psastroMosaicGetGrads.c
===================================================================
--- trunk/psastro/src/psastroMosaicGetGrads.c	(revision 15670)
+++ trunk/psastro/src/psastroMosaicGetGrads.c	(revision 15671)
@@ -44,4 +44,5 @@
 	psFree (region);
     }
+    psFree (view);
     return (grads);
 }
Index: trunk/psastro/src/psastroMosaicGradients.c
===================================================================
--- trunk/psastro/src/psastroMosaicGradients.c	(revision 15670)
+++ trunk/psastro/src/psastroMosaicGradients.c	(revision 15671)
@@ -63,4 +63,6 @@
     if (!status) {
 	psError(PSASTRO_ERR_UNKNOWN, false, "failed to find single-chip fit order\n");
+	psFree (gradients);
+	psFree (view);
         return false;
     }
@@ -80,4 +82,6 @@
     if (!status) {
 	psError(PS_ERR_IO, false, "Failed to lookup pixel scale"); 
+	psFree (gradients);
+	psFree (view);
 	return false; 
     } 
Index: trunk/psastro/src/psastroMosaicSetMatch.c
===================================================================
--- trunk/psastro/src/psastroMosaicSetMatch.c	(revision 15670)
+++ trunk/psastro/src/psastroMosaicSetMatch.c	(revision 15671)
@@ -15,4 +15,5 @@
     if (!status) { 
 	psError(PS_ERR_IO, false, "Failed to lookup matching radius: %s", radiusWord); 
+	psFree (view);
 	return false; 
     } 
@@ -21,7 +22,9 @@
 	if (iteration == 0) {
 	    psError(PS_ERR_IO, false, "Invalid match radius for first iteration: %s", radiusWord); 
+	    psFree (view);
 	    return false; 
 	} 
 	psWarning ("skipping match for iteration %d\n", iteration);
+	psFree (view);
 	return true;
     }
Index: trunk/psastro/src/psastroOneChip.c
===================================================================
--- trunk/psastro/src/psastroOneChip.c	(revision 15670)
+++ trunk/psastro/src/psastroOneChip.c	(revision 15671)
@@ -41,5 +41,5 @@
 	}
 
-	// find initial offset / rotation
+	// find initial offset / rotation / scale
 	pmAstromStats *gridStats = pmAstromGridMatch (gridStars, refstars, recipe);
 	if (gridStats == NULL) {
