Index: trunk/psphot/src/.cvsignore
===================================================================
--- trunk/psphot/src/.cvsignore	(revision 9838)
+++ trunk/psphot/src/.cvsignore	(revision 9839)
@@ -16,2 +16,3 @@
 
 polyfitTest
+growthTest
Index: trunk/psphot/src/Makefile.am
===================================================================
--- trunk/psphot/src/Makefile.am	(revision 9838)
+++ trunk/psphot/src/Makefile.am	(revision 9839)
@@ -3,5 +3,5 @@
 libpsphot_la_CPPFLAGS = $(PSLIB_CFLAGS) $(PSMODULE_CFLAGS) $(PSPHOT_CFLAGS)
 
-bin_PROGRAMS = psphot polyfitTest
+bin_PROGRAMS = psphot polyfitTest growthTest
 
 psphot_CPPFLAGS = $(PSLIB_CFLAGS) $(PSMODULE_CFLAGS) $(PSPHOT_CFLAGS)
@@ -13,4 +13,8 @@
 polyfitTest_LDFLAGS = $(PSLIB_LIBS) $(PSMODULE_LIBS)
 polyfitTest_SOURCES = polyfitTest.c		
+
+growthTest_CPPFLAGS = $(PSLIB_CFLAGS) $(PSMODULE_CFLAGS) $(PSPHOT_CFLAGS)
+growthTest_LDFLAGS = $(PSLIB_LIBS) $(PSMODULE_LIBS)
+growthTest_SOURCES = growthTest.c psphotGrowthCurve.c		
 
 libpsphot_la_SOURCES = \
Index: trunk/psphot/src/growthTest.c
===================================================================
--- trunk/psphot/src/growthTest.c	(revision 9839)
+++ trunk/psphot/src/growthTest.c	(revision 9839)
@@ -0,0 +1,198 @@
+# include "psphot.h"
+
+int main (int argc, char **argv) {
+
+    if (argc != 3) {
+	fprintf (stderr, "USAGE: growthTest\n");
+	exit (2);
+    }
+
+    // does the growth curve correctly fix aperture mags?
+    pmModelGroupInit ();
+
+    // generate a simple readout
+    pmReadout *readout = pmReadoutAlloc (NULL);
+    readout->image = psImageAlloc (512, 512, PS_TYPE_F32);
+    readout->mask  = psImageAlloc (512, 512, PS_TYPE_U8);
+
+    // generate a simple psf
+    pmModelType type = pmModelSetType ("PS_MODEL_GAUSS");
+    psPolynomial2D *psfTrend = psPolynomial2DAlloc (PS_POLYNOMIAL_ORD, 0, 0);
+    pmPSF *psf = pmPSFAlloc (type, true, psfTrend);
+    psf->growth = pmGrowthCurveAlloc (2.0, 100.0, 15.0);
+
+    psPolynomial2D *poly;
+    
+    poly = psf->params_NEW->data[PM_PAR_SXX];
+    poly->coeff[0][0] = M_SQRT2*1.5;
+
+    poly = psf->params_NEW->data[PM_PAR_SYY];
+    poly->coeff[0][0] = M_SQRT2*1.5;
+
+    poly = psf->params_NEW->data[PM_PAR_SXY];
+    poly->coeff[0][0] = 0;
+
+    // create template model
+    pmModel *modelRef = pmModelAlloc(psf->type);
+    modelRef->params->data.F32[PM_PAR_SKY] = 0;
+    modelRef->params->data.F32[PM_PAR_I0] = 1000;
+    
+    // test of psImageShift 
+    { 
+	// assign the x and y coords to the image center
+	// create an object with center intensity of 1000
+	modelRef->params->data.F32[PM_PAR_XPOS] = 200+0.2;
+	modelRef->params->data.F32[PM_PAR_YPOS] = 200+0.6;
+	
+	// create modelPSF from this model
+	pmModel *model = pmModelFromPSF (modelRef, psf);
+
+	psRegion region = {180, 220, 180, 220};
+	psImage *imageView = psImageSubset (readout->image, region);
+	psImage *maskView = psImageSubset (readout->mask, region);
+	pmModelAdd (imageView, maskView, model, false, false);
+	// imageView->data.F32[20][20] = 1000;
+	float dx = 0.5 - model->params->data.F32[PM_PAR_XPOS] + (int)model->params->data.F32[PM_PAR_XPOS];
+	float dy = 0.5 - model->params->data.F32[PM_PAR_YPOS] + (int)model->params->data.F32[PM_PAR_YPOS];
+	psImage *tmpImage = tmp_psImageShift (imageView, dx, dy);
+
+	psFits *fits;
+	fits = psFitsOpen ("unshift.fits", "w");
+	psFitsWriteImage (fits, NULL, imageView, 0, NULL);
+	psFitsClose (fits);
+	
+	fits = psFitsOpen ("shift.fits", "w");
+	psFitsWriteImage (fits, NULL, tmpImage, 0, NULL);
+	psFitsClose (fits);
+    }
+
+    // test of model insert, mask, shift
+    { 
+	psFits *fits;
+	pmModel *model;
+	psRegion region = {180, 220, 180, 220};
+
+	// create an object with center intensity of 1000 at 0.5,0.5 frac pixel center
+	modelRef->params->data.F32[PM_PAR_XPOS] = 200+0.5;
+	modelRef->params->data.F32[PM_PAR_YPOS] = 200+0.5;
+	model = pmModelFromPSF (modelRef, psf);
+
+	psImageInit (readout->image, 0.0);
+	psImageInit (readout->mask, 0);
+
+	psImage *image1 = psImageSubset (readout->image, region);
+	psImage *mask1 = psImageSubset (readout->mask, region);
+	psImageKeepCircle (mask1, model->params->data.F32[PM_PAR_XPOS], model->params->data.F32[PM_PAR_YPOS], 3, "OR", PM_MASK_MARK);
+	pmModelAdd (image1, mask1, model, false, false);
+
+	// write ref object
+	fits = psFitsOpen ("refobj.fits", "w");
+	psFitsWriteImage (fits, NULL, image1, 0, NULL);
+	psFitsClose (fits);
+	
+	// write ref mask
+	fits = psFitsOpen ("refmask.fits", "w");
+	psFitsWriteImage (fits, NULL, mask1, 0, NULL);
+	psFitsClose (fits);
+	
+	// create an object with center intensity of 1000 at 0.3,0.6 frac pixel center
+	modelRef->params->data.F32[PM_PAR_XPOS] = 200+0.3;
+	modelRef->params->data.F32[PM_PAR_YPOS] = 200+0.6;
+	model = pmModelFromPSF (modelRef, psf);
+
+	psImageInit (readout->image, 0.0);
+	psImageInit (readout->mask, 0);
+
+	psImage *image2 = psImageSubset (readout->image, region);
+	psImage *mask2 = psImageSubset (readout->mask, region);
+	psImageKeepCircle (mask2, model->params->data.F32[PM_PAR_XPOS], model->params->data.F32[PM_PAR_YPOS], 3, "OR", PM_MASK_MARK);
+	pmModelAdd (image2, mask2, model, false, false);
+
+	// write sci object
+	fits = psFitsOpen ("sciobj.fits", "w");
+	psFitsWriteImage (fits, NULL, image2, 0, NULL);
+	psFitsClose (fits);
+	
+	// write sci mask
+	fits = psFitsOpen ("scimask.fits", "w");
+	psFitsWriteImage (fits, NULL, mask2, 0, NULL);
+	psFitsClose (fits);
+	
+	// shift image to match ref object
+	float dx = 0.5 - model->params->data.F32[PM_PAR_XPOS] + (int)model->params->data.F32[PM_PAR_XPOS];
+	float dy = 0.5 - model->params->data.F32[PM_PAR_YPOS] + (int)model->params->data.F32[PM_PAR_YPOS];
+	psImage *tmpImage = tmp_psImageShift (image2, dx, dy);
+
+	fits = psFitsOpen ("scishift.fits", "w");
+	psFitsWriteImage (fits, NULL, tmpImage, 0, NULL);
+	psFitsClose (fits);
+    }
+
+    // generate the growth curve (element of psf)
+    psphotGrowthCurve (readout, psf, false);
+
+    for (float radius = 2; radius < 8; radius += 1.0) {
+	for (float dx = -1; dx <= 1; dx += 0.1) {
+	    for (float dy = -1; dy <= 1; dy += 0.1) {
+	    
+		float fitMag, apMag, deltaMag;
+
+		// assign the x and y coords to the image center
+		// create an object with center intensity of 1000
+		modelRef->params->data.F32[PM_PAR_XPOS] = 200+dx;
+		modelRef->params->data.F32[PM_PAR_YPOS] = 200+dy;
+	    
+		// create modelPSF from this model
+		pmModel *model = pmModelFromPSF (modelRef, psf);
+		model->radiusFit = radius;
+
+		// measure the fitMag for this model
+		pmSourcePhotometryModel (&fitMag, model);
+
+		psRegion region = {180, 220, 180, 220};
+		psImage *imageView = psImageSubset (readout->image, region);
+		psImage *maskView = psImageSubset (readout->mask, region);
+
+		psImageInit (imageView, 0.0);
+		psImageInit (maskView, 0);
+		pmModelAdd (imageView, maskView, model, false, false);
+
+		// fits = psFitsOpen ("imo.fits", "w");
+		// psFitsWriteImage (fits, NULL, imageView, 0, NULL);
+		// psFitsClose (fits);
+
+		float dX = 0.5 - model->params->data.F32[PM_PAR_XPOS] + (int)model->params->data.F32[PM_PAR_XPOS];
+		float dY = 0.5 - model->params->data.F32[PM_PAR_YPOS] + (int)model->params->data.F32[PM_PAR_YPOS];
+		psImage *tmpImage = tmp_psImageShift (imageView, dX, dY);
+
+		psImageKeepCircle (maskView, 200+dx+dX, 200+dy+dY, radius, "OR", PM_MASK_MARK);
+		pmSourcePhotometryAper (&apMag, model, imageView, maskView);
+
+		# if 0
+		char name[64];
+		psFits *fits;
+		sprintf (name, "im.%.1f.fits", dx);
+		fits = psFitsOpen (name, "w");
+		psFitsWriteImage (fits, NULL, tmpImage, 0, NULL);
+		psFitsClose (fits);
+
+		sprintf (name, "mk.%.1f.fits", dx);
+		fits = psFitsOpen (name, "w");
+		psFitsWriteImage (fits, NULL, maskView, 0, NULL);
+		psFitsClose (fits);
+		# endif
+
+		psImageKeepCircle (maskView, 200+dx+dX, 200+dy+dY, radius, "AND", PS_NOT_U8(PM_MASK_MARK));
+
+		deltaMag = pmGrowthCurveCorrect (psf->growth, radius);
+
+		fprintf (stdout, "%f %f %f  %f %f %f\n", radius, dx, dy, fitMag, apMag, deltaMag);
+
+		psFree (tmpImage);
+		psFree (imageView);
+		psFree (maskView);
+		psFree (model);
+	    }
+	}
+    }
+}
