Index: trunk/psphot/src/psphotRoughClass.c
===================================================================
--- trunk/psphot/src/psphotRoughClass.c	(revision 29936)
+++ trunk/psphot/src/psphotRoughClass.c	(revision 31154)
@@ -63,13 +63,39 @@
     }
 
+    int NstarsInClump = psMetadataLookupS32 (&status, readout->analysis, "PSF_CLUMP_NSTARS");
+    // if NstarsInClump is not defined, use the user-selected option:
+    if (!status) {
+	NstarsInClump = 1000;
+    }
+
+    int ScaleForClump = 1;
+    if (NstarsInClump >= 12) ScaleForClump = 2; // 4 cells
+    if (NstarsInClump >= 27) ScaleForClump = 3; // 9 cells
+    if (NstarsInClump >= 48) ScaleForClump = 4; // 16 cells
+    if (NstarsInClump >  75) ScaleForClump = 5; // 25 cells
+
     // we make this measurement on a NxM grid of regions across the readout
     int NX  = psMetadataLookupS32 (&status, recipe, "PSF_CLUMP_NX");  CHECK_STATUS (status, "PSF_CLUMP_NX");
     int NY  = psMetadataLookupS32 (&status, recipe, "PSF_CLUMP_NY");  CHECK_STATUS (status, "PSF_CLUMP_NY");
-    int dX  = readout->image->numCols / NX;
-    int dY  = readout->image->numRows / NY;
+
+    int NXuse, NYuse;
+
+    ScaleForClump = PS_MIN(ScaleForClump, PS_MAX(NX, NY));
+    if (NX > NY) {
+	NXuse = ScaleForClump;
+	NYuse = (int) (ScaleForClump * (NY / NX) + 0.5);
+    } else {
+	NYuse = ScaleForClump;
+	NXuse = (int) (ScaleForClump * (NY / NX) + 0.5);
+    }
+
+    psLogMsg ("psphot", 4, "With %d stars, using %d x %d grid for PSF clump\n", NstarsInClump, NXuse, NYuse);
+
+    int dX  = readout->image->numCols / NXuse;
+    int dY  = readout->image->numRows / NYuse;
 
     int nRegion = 0;
-    for (int ix = 0; ix < NX; ix ++) {
-        for (int iy = 0; iy < NY; iy ++) {
+    for (int ix = 0; ix < NXuse; ix ++) {
+        for (int iy = 0; iy < NYuse; iy ++) {
 
             psRegion *region = psRegionAlloc (ix*dX, (ix + 1)*dX, iy*dY, (iy + 1)*dY);
@@ -181,6 +207,5 @@
         return false;
     }
-    psLogMsg ("psphot", 3, "psf clump  X,  Y: %f, %f\n", psfClump.X, psfClump.Y);
-    psLogMsg ("psphot", 3, "psf clump DX, DY: %f, %f\n", psfClump.dX, psfClump.dY);
+    psLogMsg ("psphot", 3, "psf clump  X,  Y: %f, %f : DX, DY: %f, %f : nStars %d of %d\n", psfClump.X, psfClump.Y, psfClump.dX, psfClump.dY, psfClump.nStars, psfClump.nTotal);
 
     // get basic parameters, or set defaults
