Index: /branches/eam_branches/ipp-20110404/psModules/src/objects/models/pmModel_DEV.c
===================================================================
--- /branches/eam_branches/ipp-20110404/psModules/src/objects/models/pmModel_DEV.c	(revision 31437)
+++ /branches/eam_branches/ipp-20110404/psModules/src/objects/models/pmModel_DEV.c	(revision 31438)
@@ -268,5 +268,5 @@
     float f0 = 1.0;
     float f1, f2;
-    for (z = DZ; z < 50; z += DZ) {
+    for (z = DZ; z < 150; z += DZ) {
 	f1 = exp(-pow(z,ALPHA));
         z += DZ;
Index: /branches/eam_branches/ipp-20110404/psModules/src/objects/models/pmModel_EXP.c
===================================================================
--- /branches/eam_branches/ipp-20110404/psModules/src/objects/models/pmModel_EXP.c	(revision 31437)
+++ /branches/eam_branches/ipp-20110404/psModules/src/objects/models/pmModel_EXP.c	(revision 31438)
@@ -255,5 +255,5 @@
     float f0 = 1.0;
     float f1, f2;
-    for (z = DZ; z < 50; z += DZ) {
+    for (z = DZ; z < 150; z += DZ) {
         f1 = exp(-sqrt(z));
         z += DZ;
Index: /branches/eam_branches/ipp-20110404/psModules/src/objects/models/pmModel_PGAUSS.c
===================================================================
--- /branches/eam_branches/ipp-20110404/psModules/src/objects/models/pmModel_PGAUSS.c	(revision 31437)
+++ /branches/eam_branches/ipp-20110404/psModules/src/objects/models/pmModel_PGAUSS.c	(revision 31438)
@@ -239,5 +239,5 @@
     float f0 = 1.0;
     float f1, f2;
-    for (z = DZ; z < 50; z += DZ) {
+    for (z = DZ; z < 150; z += DZ) {
         f1 = 1.0 / (1 + z + z*z/2.0 + z*z*z/6.0);
         z += DZ;
Index: /branches/eam_branches/ipp-20110404/psModules/src/objects/models/pmModel_PS1_V1.c
===================================================================
--- /branches/eam_branches/ipp-20110404/psModules/src/objects/models/pmModel_PS1_V1.c	(revision 31437)
+++ /branches/eam_branches/ipp-20110404/psModules/src/objects/models/pmModel_PS1_V1.c	(revision 31438)
@@ -261,5 +261,5 @@
     float f0 = 1.0;
     float f1, f2;
-    for (z = DZ; z < 50; z += DZ) {
+    for (z = DZ; z < 150; z += DZ) {
         f1 = 1.0 / (1 + PAR[PM_PAR_7]*z + pow(z, ALPHA));
         z += DZ;
Index: /branches/eam_branches/ipp-20110404/psModules/src/objects/models/pmModel_QGAUSS.c
===================================================================
--- /branches/eam_branches/ipp-20110404/psModules/src/objects/models/pmModel_QGAUSS.c	(revision 31437)
+++ /branches/eam_branches/ipp-20110404/psModules/src/objects/models/pmModel_QGAUSS.c	(revision 31438)
@@ -262,5 +262,5 @@
     float f0 = 1.0;
     float f1, f2;
-    for (z = DZ; z < 50; z += DZ) {
+    for (z = DZ; z < 150; z += DZ) {
         f1 = 1.0 / (1 + PAR[PM_PAR_7]*z + pow(z, ALPHA));
         z += DZ;
Index: /branches/eam_branches/ipp-20110404/psModules/src/objects/models/pmModel_RGAUSS.c
===================================================================
--- /branches/eam_branches/ipp-20110404/psModules/src/objects/models/pmModel_RGAUSS.c	(revision 31437)
+++ /branches/eam_branches/ipp-20110404/psModules/src/objects/models/pmModel_RGAUSS.c	(revision 31438)
@@ -251,5 +251,5 @@
     float f0 = 1.0;
     float f1, f2;
-    for (z = DZ; z < 50; z += DZ) {
+    for (z = DZ; z < 150; z += DZ) {
         f1 = 1.0 / (1 + z + pow(z, PAR[PM_PAR_7]));
         z += DZ;
Index: /branches/eam_branches/ipp-20110404/psModules/src/objects/models/pmModel_SERSIC.c
===================================================================
--- /branches/eam_branches/ipp-20110404/psModules/src/objects/models/pmModel_SERSIC.c	(revision 31437)
+++ /branches/eam_branches/ipp-20110404/psModules/src/objects/models/pmModel_SERSIC.c	(revision 31438)
@@ -316,5 +316,5 @@
     float f0 = 1.0;
     float f1, f2;
-    for (z = DZ; z < 50; z += DZ) {
+    for (z = DZ; z < 150; z += DZ) {
         // f1 = 1.0 / (1 + PAR[PM_PAR_7]*z + pow(z, 2.25));
 	f1 = exp(-pow(z,PAR[PM_PAR_7]));
Index: /branches/eam_branches/ipp-20110404/psModules/src/objects/pmGrowthCurve.c
===================================================================
--- /branches/eam_branches/ipp-20110404/psModules/src/objects/pmGrowthCurve.c	(revision 31437)
+++ /branches/eam_branches/ipp-20110404/psModules/src/objects/pmGrowthCurve.c	(revision 31438)
@@ -73,5 +73,5 @@
     // Fractional pixel radii are not well defined; use integer pixel radii.  Use 1 pixel steps
     // until the scaling factor steps in intervals larger than 1 pixel
-    float Rlin = 1.0 / (fR - 1.0);
+    // float Rlin = 1.0 / (fR - 1.0);
 
     growth->radius = psVectorAllocEmpty (NPTS, PS_DATA_F32);
@@ -79,9 +79,10 @@
     // there will be NPTS radii + a few extras 
     float radius = minRadius;
-    while (radius < Rlin) {
+    while (radius < refRadius) {
 	// fprintf (stderr, "r: %f\n", radius);
 	psVectorAppend (growth->radius, radius - 0.001);
 	radius += 1.0;
     }    
+    growth->refBin = growth->radius->n - 1;
     while (radius < maxRadius) {
 	// fprintf (stderr, "r: %f\n", radius);
@@ -97,4 +98,5 @@
     growth->maxRadius = maxRadius;
     growth->fitMag = NAN;
+    growth->refMag = NAN;
     growth->apRef  = NAN;
     growth->apLoss = NAN;
Index: /branches/eam_branches/ipp-20110404/psModules/src/objects/pmGrowthCurve.h
===================================================================
--- /branches/eam_branches/ipp-20110404/psModules/src/objects/pmGrowthCurve.h	(revision 31437)
+++ /branches/eam_branches/ipp-20110404/psModules/src/objects/pmGrowthCurve.h	(revision 31438)
@@ -22,6 +22,8 @@
     psF32 maxRadius;
     psF32 fitMag;
+    psF32 refMag;
     psF32 apRef;   // apMag[refRadius]
     psF32 apLoss;  // fitMag - apRef
+    int refBin;
 }
 pmGrowthCurve;
Index: /branches/eam_branches/ipp-20110404/psModules/src/objects/pmGrowthCurveGenerate.c
===================================================================
--- /branches/eam_branches/ipp-20110404/psModules/src/objects/pmGrowthCurveGenerate.c	(revision 31437)
+++ /branches/eam_branches/ipp-20110404/psModules/src/objects/pmGrowthCurveGenerate.c	(revision 31438)
@@ -226,4 +226,9 @@
 }
 
+# define DEBUG 0
+# if (DEBUG)
+static FILE *fgr = NULL;
+# endif
+
 // we generate the growth curve for the center of the image with the specified psf model
 bool pmGrowthCurveGenerateFromSources (pmReadout *readout, pmPSF *psf, psArray *sources, bool INTERPOLATE_AP, psImageMaskType maskVal, psImageMaskType markVal)
@@ -240,4 +245,8 @@
     psArray *growths = psArrayAllocEmpty (100);
 
+# if (DEBUG)
+    fgr = fopen ("growth.mags.dat", "w");
+# endif
+
     for (int i = 0; i < sources->n; i++) {
 
@@ -254,23 +263,6 @@
     psAssert (growths->n, "cannot build growth curve (no valid PSF stars?)");
 
-# if (0)
-    FILE *f = fopen ("growth.dat", "w");
-    assert (f);
-
-    for (int j = 0; j < psf->growth->radius->n; j++) {
-
-	fprintf (f, "%f : ", psf->growth->radius->data.F32[j]);
-
-	// XXX dump the growth curves:
-	for (int i = 0; i < growths->n; i++) {
-	    
-	    pmGrowthCurve *growth = growths->data[i];
-	    if (!growth) continue;
-
-	    fprintf (f, "%8.4f ", growth->apMag->data.F32[j]);
-	}
-	fprintf (f, "\n");
-    }
-    fclose (f);
+# if (DEBUG)
+    fclose (fgr);
 # endif
 
@@ -290,5 +282,5 @@
 	    pmGrowthCurve *growth = growths->data[j];
 	    if (!isfinite(growth->apMag->data.F32[i])) continue;
-	    psVectorAppend (values, growth->apMag->data.F32[i] - growth->fitMag);
+	    psVectorAppend (values, growth->apMag->data.F32[i] - growth->refMag);
 	}
 	if (values->n == 0) {
@@ -354,59 +346,15 @@
 	growth->apMag->data.F32[i] = source->apMag;
     }
+    psAssert(growth->refBin >= 0, "invalid growth reference bin");
+    psAssert(growth->refBin < growth->apMag->n, "invalid growth reference bin");
+    growth->refMag = growth->apMag->data.F32[growth->refBin];
+
+    // Loop over the range of radii
+# if (DEBUG)
+    for (int i = 0; i < growth->radius->n; i++) {
+	fprintf (fgr, "%f %f  %f %f %f %f\n", xc, yc, growth->radius->data.F32[i], growth->apMag->data.F32[i], growth->fitMag, growth->refMag);
+    }
+# endif
+
     return growth;
 }
-
-# if (0)
-    // solve for the best growth and the offsets per star to minimize the scatter
-
-    // generate the per-star and per-radius sums
-    int Nradius = psf->growth->radius->n;
-    int Nstar = growths->n;
-
-    psVector *Mstar   = psVectorAlloc (Nstar, PS_DATA_F32);
-    psVector *Mradius = psVectorAlloc (Nradius, PS_DATA_F32);
-
-    psVectorInit (Mstar, 0.0);
-    psVectorInit (Mradius, 0.0);
-
-    for (int i = 0; i < Nstar; i++) {
-	pmGrowthCurve *growth = growths->data[i];
-	for (int j = 0; j < Nradius; j++) {
-	    Mstar->data.F32[i] += growth->apMag->data.F32[j];
-	    Mradius->data.F32[j] += growth->apMag->data.F32[j];
-	}
-    }
-
-    psImage *A = psImageAlloc(Nstar + Nradius, Nstar + Nradius, PS_DATA_F32);
-    psVector *B = psVectorAlloc(Nstar + Nradius, PS_DATA_F32);
-
-    psImageInit (A, 0.0);
-    psVectorInit (B, 0.0);
-
-    for (int i = 0; i < Nstar; i++) {
-	A->data.F32[i][i] = Nradius;
-	B->data.F32[i] = Mstar->data.F32[i];
-    }
-    for (int i = 0; i < Nradius; i++) {
-	int j = i + Nstar;
-	A->data.F32[j][j] = Nstar;
-	B->data.F32[j] = Mradius->data.F32[i];
-    }
-    
-    if (!psMatrixGJSolve(A, B)) {
-	psAbort("GJ failure");
-    }
-
-    for (int i = 0; i < Nradius; i++) {
-	psf->growth->apMag->data.F32[i] = B->data.F32[Nstar+i];
-    }
-
-    // XXX this analysis produces a biased growth curve: points with small radius are more
-    // likely to err on the side of being too faint (bacause of mis-aligned aperture), while on
-    // the bright side the tend to be too bright (because of contaminating neighbors).  Bright
-    // stars are less likely to be biased, 
-
-    // XXX at this point, we could iterate and exclude some of the stars with low data quality
-    // XXX we could also weight the above by flux or something
-
-# endif
Index: /branches/eam_branches/ipp-20110404/psModules/src/objects/pmPCMdata.c
===================================================================
--- /branches/eam_branches/ipp-20110404/psModules/src/objects/pmPCMdata.c	(revision 31437)
+++ /branches/eam_branches/ipp-20110404/psModules/src/objects/pmPCMdata.c	(revision 31438)
@@ -263,8 +263,11 @@
 bool pmPCMupdate(pmPCMdata *pcm, pmSource *source, pmSourceFitOptions *fitOptions, pmModel *model) {
 
-    bool newWindow = (source->pixels->numRows != pcm->modelFlux->numRows) || (source->pixels->numCols != pcm->modelFlux->numCols);
+    bool sameWindow = (source->pixels->numRows == pcm->modelFlux->numRows);
+    sameWindow     &= (source->pixels->numCols == pcm->modelFlux->numCols);
+    sameWindow     &= (source->pixels->col0    == pcm->modelFlux->col0);
+    sameWindow     &= (source->pixels->row0    == pcm->modelFlux->row0);
 
     // re-count the number of unmasked pixels:
-    if (newWindow) {
+    if (!sameWindow) {
 	for (psS32 i = 0; i < source->pixels->numRows; i++) {
 	    for (psS32 j = 0; j < source->pixels->numCols; j++) {
@@ -346,5 +349,5 @@
 
     // has the source pixel window changed?
-    if (newWindow) {
+    if (!sameWindow) {
 
 	// adjust all supporting images:
Index: /branches/eam_branches/ipp-20110404/psModules/src/objects/pmSource.c
===================================================================
--- /branches/eam_branches/ipp-20110404/psModules/src/objects/pmSource.c	(revision 31437)
+++ /branches/eam_branches/ipp-20110404/psModules/src/objects/pmSource.c	(revision 31438)
@@ -285,4 +285,16 @@
     extend |= (mySource->maskObj == NULL);
     extend |= (mySource->maskView == NULL);
+
+    // if ((fabs(x - 2020) < 5) && (fabs(y - 366) < 5)) {
+    // 	if (extend) {
+    // 	    fprintf (stderr, "extend T, %f, %f : %f, %f vs %f, %f : %f, %f\n", 
+    // 		     newRegion.x0, newRegion.y0, newRegion.x1, newRegion.y1, 
+    // 		     mySource->region.x0, mySource->region.y0, mySource->region.x1, mySource->region.y1);
+    // 	} else {
+    // 	    fprintf (stderr, "extend F, %f, %f : %f, %f vs %f, %f : %f, %f\n", 
+    // 		     newRegion.x0, newRegion.y0, newRegion.x1, newRegion.y1, 
+    // 		     mySource->region.x0, mySource->region.y0, mySource->region.x1, mySource->region.y1);
+    // 	}
+    // }
 
     if (extend) {
