Index: trunk/ppSim/src/ppSimArguments.c
===================================================================
--- trunk/ppSim/src/ppSimArguments.c	(revision 29002)
+++ trunk/ppSim/src/ppSimArguments.c	(revision 29011)
@@ -55,4 +55,6 @@
     psMetadataAddStr(arguments,  PS_LIST_TAIL, "-galmodel", 0, "Type of Galaxy model", NULL);
     psMetadataAddS32(arguments,  PS_LIST_TAIL, "-bin", 0, "Binning in x and y", 1);
+    psMetadataAddS32(arguments,  PS_LIST_TAIL, "-nx", 0, "cell x-size in pixels", 0);
+    psMetadataAddS32(arguments,  PS_LIST_TAIL, "-ny", 0, "cell y-size in pixels", 0);
     psMetadataAddBool(arguments, PS_LIST_TAIL, "+photom", 0, "Perform photometry on fake sources", false);
 
@@ -197,4 +199,7 @@
     ppSimArgToRecipeS32(&status,  options, "BINNING",       arguments, "-bin");
 
+    ppSimArgToRecipeS32(&status,  config->arguments, "NX.CELL", arguments, "-nx");
+    ppSimArgToRecipeS32(&status,  config->arguments, "NY.CELL", arguments, "-ny");
+
     if (type == PPSIM_TYPE_OBJECT) {
         // Load values required for adding stars
Index: trunk/ppSim/src/ppSimCreate.c
===================================================================
--- trunk/ppSim/src/ppSimCreate.c	(revision 29002)
+++ trunk/ppSim/src/ppSimCreate.c	(revision 29011)
@@ -26,6 +26,22 @@
     }
 
+    assert (config->camera);
+
+    // int nx = psMetadataLookupS32 (&status, config->arguments, "NX.CELL");
+    // if (nx) {
+    //   psMetadata *defaults = psMetadataLookupPtr(&status, config->camera, "DEFAULTS");
+    //   psMetadataLookupS32 (&status, defaults, "CELL.XSIZE");
+    //   psAssert (status, "CELL.XSIZE should be in DEFAULTS");
+    //   psMetadataAddF32(defaults, PS_LIST_TAIL, "CELL.XSIZE", PS_META_REPLACE, "", nx);
+    // }
+    // int ny = psMetadataLookupS32 (&status, config->arguments, "NY.CELL");
+    // if (ny) {
+    //   psMetadata *defaults = psMetadataLookupPtr(&status, config->camera, "DEFAULTS");
+    //   psMetadataLookupS32 (&status, defaults, "CELL.YSIZE");
+    //   psAssert (status, "CELL.YSIZE should be in DEFAULTS");
+    //   psMetadataAddF32(defaults, PS_LIST_TAIL, "CELL.YSIZE", PS_META_REPLACE, "", ny);
+    // }
+
     // generate the fpa structure used by the output camera (determined from INPUT or specified)
-    assert (config->camera);
     fpa = pmFPAConstruct(config->camera, config->cameraName); // FPA to contain the observation
     if (!fpa) {
Index: trunk/ppSim/src/ppSimMakeGalaxies.c
===================================================================
--- trunk/ppSim/src/ppSimMakeGalaxies.c	(revision 29002)
+++ trunk/ppSim/src/ppSimMakeGalaxies.c	(revision 29011)
@@ -109,10 +109,12 @@
 		// galaxy->index = (1/2n)
 
-		float factor = galaxyGridRandom ? drand48() : i / num;
-		float index = (galaxyIndexMin  + factor * galaxyIndexSlope); // factor of 0.5 because the Sersic model creates exp(-z^n), not exp(-r^n)
-		galaxy->index = 0.5/index;
+		float rndValue;
 
-		factor = galaxyGridRandom ? drand48() : i / num;
-		float scale = (galaxyRmajorMin + factor * galaxyRmajorSlope);
+		rndValue = galaxyGridRandom ? drand48() : i / num;
+		float index = (galaxyIndexMin  + rndValue * galaxyIndexSlope);
+		galaxy->index = 0.5/index; // factor of 0.5 because the Sersic model creates exp(-z^n), not exp(-r^n)
+
+		rndValue = galaxyGridRandom ? drand48() : i / num;
+		float scale = (galaxyRmajorMin + rndValue * galaxyRmajorSlope);
 
 		// for a sersic model, 
@@ -121,13 +123,11 @@
                 float Io = exp(bn);
 
-		// galaxy->Rmaj  = scale * fR;
-
 		galaxy->Rmaj  = scale;
 
-		factor = galaxyGridRandom ? drand48() : i / num;
-		galaxy->Rmin  = (galaxyARatioMin + factor * galaxyARatioSlope) * galaxy->Rmaj;
+		rndValue = galaxyGridRandom ? drand48() : i / num;
+		galaxy->Rmin  = (galaxyARatioMin + rndValue * galaxyARatioSlope) * galaxy->Rmaj;
 
-		factor = galaxyGridRandom ? drand48() : i / num;
-		galaxy->theta = (galaxyThetaMin  + factor * galaxyThetaSlope);
+		rndValue = galaxyGridRandom ? drand48() : i / num;
+		galaxy->theta = (galaxyThetaMin  + rndValue * galaxyThetaSlope);
 
 		// galaxy->peak *= Io;
@@ -158,10 +158,19 @@
 	    galaxy->y    = psRandomUniform(rng) * ySize; // y position
 
-	    // galaxy->flux = pow ((double)((i + 1) / norm), (double) (1.0 / galaxyLum));
+	    float index = (sqrt(psRandomUniform(rng)) * galaxyIndexSlope  + galaxyIndexMin);
+	    galaxy->index = 0.5/index; // factor of 0.5 because the Sersic model creates exp(-z^n), not exp(-r^n)
 
-	    galaxy->index = (sqrt(psRandomUniform(rng)) * galaxyIndexSlope  + galaxyIndexMin);
+	    float scale = (psRandomUniform(rng) * galaxyRmajorSlope + galaxyRmajorMin);
+
+	    // for a sersic model, 
+	    float bn = 1.9992*index - 0.3271;
+	    float fR = 1.0 / (sqrt(2.0) * pow (bn, index));
+	    float Io = exp(bn);
+
+	    galaxy->Rmaj  = scale;
+
+	    galaxy->Rmin  = (PS_SQR(psRandomUniform(rng)) * galaxyARatioSlope + galaxyARatioMin) * galaxy->Rmaj;
+
 	    galaxy->theta = (psRandomUniform(rng) * galaxyThetaSlope  + galaxyThetaMin);
-	    galaxy->Rmaj  = (psRandomUniform(rng) * galaxyRmajorSlope + galaxyRmajorMin);
-	    galaxy->Rmin  = (PS_SQR(psRandomUniform(rng)) * galaxyARatioSlope + galaxyARatioMin) * galaxy->Rmaj;
 
 	    // the flux is only approximately correct (scaling of the peak is wrong)
@@ -170,4 +179,8 @@
 	    galaxy->peak = galaxy->flux / (2.0*M_PI*PS_SQR(seeing));
 
+	    if (0) {
+	      fprintf (stderr, "Rmaj: %f, scale: %f, index: %f, bn: %f, Ro: %f, Io: %f\n", galaxy->Rmaj, scale, index, bn, fR, Io);
+	    }
+
 	    psArrayAdd (galaxies, 100, galaxy);
 	}
