Index: /branches/eam_branches/ipp-20101205/ppSim/src/ppSimArguments.c
===================================================================
--- /branches/eam_branches/ipp-20101205/ppSim/src/ppSimArguments.c	(revision 30267)
+++ /branches/eam_branches/ipp-20101205/ppSim/src/ppSimArguments.c	(revision 30268)
@@ -49,4 +49,6 @@
     psMetadataAddF32(arguments,  PS_LIST_TAIL, "-zp", 0, "Photometric zero point", NAN);
     psMetadataAddF32(arguments,  PS_LIST_TAIL, "-seeing", 0, "Seeing FWHM (arcsec)", NAN);
+    psMetadataAddF32(arguments,  PS_LIST_TAIL, "-seeing-max", 0, "Seeing FWHM (arcsec) at end of ramp", NAN);
+    psMetadataAddBool(arguments,  PS_LIST_TAIL, "-seeing-ramp", 0, "Use a seeing ramp", false);
     psMetadataAddF32(arguments,  PS_LIST_TAIL, "-starslum", 0, "Fake star luminosity function slope", NAN);
     psMetadataAddF32(arguments,  PS_LIST_TAIL, "-starsmag", 0, "Brightest magnitude for fake stars", NAN);
@@ -130,4 +132,6 @@
 	// 'seeing' is not required: we can load a psf-model instead; but if not, it is allowed
         ppSimArgToRecipeF32(&status, options, "SEEING", arguments, "-seeing"); // seeing (FWHM in arcsec)
+        ppSimArgToRecipeF32(&status, options, "SEEING.MAX", arguments, "-seeing-max"); // seeing (FWHM in arcsec)
+        ppSimArgToRecipeBool(&status, options, "SEEING.RAMP", arguments, "-seeing-ramp"); // seeing (FWHM in arcsec)
 
 	// 'scale' is not required: we can use the WCS instead; but if not, it is allowed
@@ -227,4 +231,10 @@
         psMetadataAddF32(options, PS_LIST_TAIL, "PA", 0, "Boresight position angle (radians)",pa * M_PI / 180.0);
 
+        if (psMetadataLookupBool(NULL, arguments, "-seeing-ramp")) {
+	    float seeingMax = psMetadataLookupF32(NULL, arguments, "-seeing-max"); // seeing at ramp end
+	    psMetadataAddF32(options, PS_LIST_TAIL, "SEEING.MAX", 0, "Seeing FWHM (arcsec)", seeingMax);
+	    psMetadataAddBool(options, PS_LIST_TAIL, "SEEING.RAMP", 0, "use seeing ramp", true);
+	}
+
         ppSimArgToRecipeF32(&status, options, "ZEROPOINT", arguments, "-zp"); // Zero point
     }
Index: /branches/eam_branches/ipp-20101205/ppSim/src/ppSimCreate.c
===================================================================
--- /branches/eam_branches/ipp-20101205/ppSim/src/ppSimCreate.c	(revision 30267)
+++ /branches/eam_branches/ipp-20101205/ppSim/src/ppSimCreate.c	(revision 30268)
@@ -103,4 +103,7 @@
         psMetadataAddF32(recipe, PS_LIST_TAIL, "SEEING", PS_META_REPLACE, "Seeing SIGMA (pixels)", seeing / 2.0 / sqrt(2.0 * log(2.0)) / scale);
 
+        float seeingMax = psMetadataLookupF32(&status, recipe, "SEEING.MAX");
+        psMetadataAddF32(recipe, PS_LIST_TAIL, "SEEING.MAX", PS_META_REPLACE, "Seeing SIGMA (pixels)", seeingMax / 2.0 / sqrt(2.0 * log(2.0)) / scale);
+
         // if we have been supplied an input image, but no ra & dec, use the input image values
         if (input) {
@@ -211,4 +214,17 @@
                 }
             }
+	    // XXX this is a hack, but I don't have a better way at the moment: assumes a single cell per chip
+	    if (nx) {
+		psMetadataAddS32(chip->concepts, PS_LIST_TAIL, "CHIP.XSIZE", PS_META_REPLACE, "", nx);
+	    } else {
+		nx = psMetadataLookupF32(&status, cell->concepts, "CELL.XSIZE");
+		psMetadataAddS32(chip->concepts, PS_LIST_TAIL, "CHIP.XSIZE", PS_META_REPLACE, "", nx);
+	    }
+	    if (ny) {
+		psMetadataAddS32(chip->concepts, PS_LIST_TAIL, "CHIP.YSIZE", PS_META_REPLACE, "", ny);
+	    } else {
+		ny = psMetadataLookupF32(&status, cell->concepts, "CELL.YSIZE");
+		psMetadataAddS32(chip->concepts, PS_LIST_TAIL, "CHIP.YSIZE", PS_META_REPLACE, "", ny);
+	    }
         }
     }
Index: /branches/eam_branches/ipp-20101205/ppSim/src/ppSimSetPSF.c
===================================================================
--- /branches/eam_branches/ipp-20101205/ppSim/src/ppSimSetPSF.c	(revision 30267)
+++ /branches/eam_branches/ipp-20101205/ppSim/src/ppSimSetPSF.c	(revision 30268)
@@ -23,4 +23,7 @@
     float theta    = psMetadataLookupF32(&status, recipe, "PSF.THETA"); // Seeing SIGMA (pixels)
 
+    float seeingMax = psMetadataLookupF32(&status, recipe, "SEEING.MAX"); // Seeing SIGMA (pixels)
+    bool seeingRamp = psMetadataLookupBool(&status, recipe, "SEEING.RAMP"); // Seeing SIGMA (pixels)
+
     char *psfModelName = psMetadataLookupStr(&status, recipe, "PSF.MODEL"); // Name of PSF model
     if (psfModelName == NULL) {
@@ -39,44 +42,99 @@
     int xSize = psMetadataLookupS32(NULL, chip->concepts, "CHIP.XSIZE");
     int ySize = psMetadataLookupS32(NULL, chip->concepts, "CHIP.YSIZE");
-    xSize = 1000;
-    ySize = 1000;
 
-    // no spatial variation
-    options->psfTrendMode = PM_TREND_POLY_ORD;
-    options->psfTrendNx = 0;
-    options->psfTrendNy = 0;
-    options->psfFieldNx = xSize;
-    options->psfFieldNy = ySize;
+    if (seeingRamp) {
+	psEllipseAxes axes;
+	psEllipsePol pol;
+	psEllipsePol polMax;
 
-    // generate the psf
-    psf = pmPSFAlloc (options);
+	// try spatial variation
+	options->psfTrendMode = PM_TREND_POLY_ORD;
+	options->psfTrendNx = 1;
+	options->psfTrendNy = 1;
+	options->psfFieldNx = xSize;
+	options->psfFieldNy = ySize;
 
-    psEllipseAxes axes;
-    psEllipsePol pol;
+	// generate the psf
+	psf = pmPSFAlloc (options);
 
-    // supply the semi-major axis (these are SIGMA values in PIXELS)
-    axes.major = seeing;
-    axes.minor = aRatio * seeing;
-    axes.theta = theta * PS_RAD_DEG;
+	// supply the semi-major axis (these are SIGMA values in PIXELS)
+	axes.major = seeing;
+	axes.minor = aRatio * seeing;
+	axes.theta = theta * PS_RAD_DEG;
 
-    pol = psEllipseAxesToPol (axes);
+	pol = psEllipseAxesToPol (axes);
     
-    param = psf->params->data[PM_PAR_E0];
-    param->poly->coeff[0][0] = pol.e0;
+	axes.major = seeingMax;
+	axes.minor = aRatio * seeingMax;
+	polMax = psEllipseAxesToPol (axes);
 
-    param = psf->params->data[PM_PAR_E1];
-    param->poly->coeff[0][0] = pol.e1;
+	param = psf->params->data[PM_PAR_E0];
+	param->poly->coeff[0][0] = pol.e0;
+	param->poly->coeff[1][0] = (polMax.e0 - pol.e0) / xSize;
+	param->poly->coeff[0][1] = (polMax.e0 - pol.e0) / ySize;
 
-    param = psf->params->data[PM_PAR_E2];
-    param->poly->coeff[0][0] = pol.e2;
+	param = psf->params->data[PM_PAR_E1];
+	param->poly->coeff[0][0] = pol.e1;
+	param->poly->coeff[1][0] = 0.0;
+	param->poly->coeff[0][1] = 0.0;
 
-    if (!strcasecmp (psfModelName, "PS_MODEL_QGAUSS")) {
-        param = psf->params->data[PM_PAR_7];
-        param->poly->coeff[0][0] = 1.0;
-    }
+	param = psf->params->data[PM_PAR_E2];
+	param->poly->coeff[0][0] = pol.e2;
+	param->poly->coeff[1][0] = 0.0;
+	param->poly->coeff[0][1] = 0.0;
 
-    if (!strcasecmp (psfModelName, "PS_MODEL_RGAUSS")) {
-        param = psf->params->data[PM_PAR_7];
-        param->poly->coeff[0][0] = 1.0;
+	if (!strcasecmp (psfModelName, "PS_MODEL_QGAUSS")) {
+	    param = psf->params->data[PM_PAR_7];
+	    param->poly->coeff[0][0] = 1.0;
+	    param->poly->coeff[1][0] = 0.0;
+	    param->poly->coeff[0][1] = 0.0;
+	}
+
+	if (!strcasecmp (psfModelName, "PS_MODEL_RGAUSS")) {
+	    param = psf->params->data[PM_PAR_7];
+	    param->poly->coeff[0][0] = 1.0;
+	    param->poly->coeff[1][0] = 0.0;
+	    param->poly->coeff[0][1] = 0.0;
+	}
+
+    } else {
+	psEllipseAxes axes;
+	psEllipsePol pol;
+
+	// no spatial variation
+	options->psfTrendMode = PM_TREND_POLY_ORD;
+	options->psfTrendNx = 0;
+	options->psfTrendNy = 0;
+	options->psfFieldNx = xSize;
+	options->psfFieldNy = ySize;
+
+	// generate the psf
+	psf = pmPSFAlloc (options);
+
+	// supply the semi-major axis (these are SIGMA values in PIXELS)
+	axes.major = seeing;
+	axes.minor = aRatio * seeing;
+	axes.theta = theta * PS_RAD_DEG;
+
+	pol = psEllipseAxesToPol (axes);
+    
+	param = psf->params->data[PM_PAR_E0];
+	param->poly->coeff[0][0] = pol.e0;
+
+	param = psf->params->data[PM_PAR_E1];
+	param->poly->coeff[0][0] = pol.e1;
+
+	param = psf->params->data[PM_PAR_E2];
+	param->poly->coeff[0][0] = pol.e2;
+
+	if (!strcasecmp (psfModelName, "PS_MODEL_QGAUSS")) {
+	    param = psf->params->data[PM_PAR_7];
+	    param->poly->coeff[0][0] = 1.0;
+	}
+
+	if (!strcasecmp (psfModelName, "PS_MODEL_RGAUSS")) {
+	    param = psf->params->data[PM_PAR_7];
+	    param->poly->coeff[0][0] = 1.0;
+	}
     }
 
