Index: trunk/ppSim/src/ppSimMakeStars.c
===================================================================
--- trunk/ppSim/src/ppSimMakeStars.c	(revision 17557)
+++ trunk/ppSim/src/ppSimMakeStars.c	(revision 17616)
@@ -24,4 +24,7 @@
     float seeing       = psMetadataLookupF32(&status, recipe, "SEEING"); // Seeing SIGMA (pixels)
     float scale        = psMetadataLookupF32(&status, recipe, "SCALE") * M_PI / 3600.0 / 180.0; // Plate scale (radians/pixel)
+
+    bool flatLum       = psMetadataLookupBool(&status,recipe, "STARS.FLAT.LUM"); // were real stars generated?
+    float flatNum      = psMetadataLookupS32(&status, recipe, "STARS.FLAT.NUM"); // were real stars generated?
 
     float skyRate = psMetadataLookupF32(&status, recipe, "SKY.RATE"); // Sky rate
@@ -93,7 +96,12 @@
 
     // Total number of stars down to the faint flux end
-    long nTotal = normScale * powf (10.0, (starsAlpha * faintMag));
+    long nTotal = 0;
+    if (flatLum) {
+	nTotal = flatNum;
+    } else {
+	nTotal = normScale * powf (10.0, (starsAlpha * faintMag));
+    }
 
-    psLogMsg("ppSim", PS_LOG_INFO, "Adding %ld stars down to %f mag\n", nTotal, faintMag);
+    psLogMsg("ppSim", PS_LOG_INFO, "Adding %ld stars between %f and %f mag\n", nTotal, brightMag, faintMag);
 
     long oldSize = stars->n;
@@ -107,6 +115,10 @@
         star->y    = psRandomUniform(rng) * ySize; // y position
 
-	// XXX this needs to respect the bright limit
-	float starMag = log10((i + 1.0) / normScale) / starsAlpha;
+	float starMag = 0;
+	if (flatLum) {
+	    starMag = psRandomUniform(rng) * (faintMag - brightMag) + brightMag;
+	} else {
+	    starMag = PS_MIN (faintMag, PS_MAX (brightMag, (log10((i + 1.0) / normScale) / starsAlpha)));
+	}
 	
         star->flux = ppSimMagToFlux (starMag, zp) * expTime;
