Index: branches/eam_branches/ipp-20110213/psphot/src/psphotApResid.c
===================================================================
--- branches/eam_branches/ipp-20110213/psphot/src/psphotApResid.c	(revision 30771)
+++ branches/eam_branches/ipp-20110213/psphot/src/psphotApResid.c	(revision 30772)
@@ -117,5 +117,5 @@
 
     // set limits on the aperture magnitudes
-    pmSourceMagnitudesInit (recipe);
+    pmSourceMagnitudesInit (config, recipe);
 
     // threaded measurement of the source magnitudes
@@ -466,5 +466,5 @@
         psImageKeepCircle (source->maskObj, source->peak->x, source->peak->y, source->apRadius, "OR", markVal);
 
-        bool status = pmSourceMagnitudes (source, psf, photMode, maskVal, markVal);
+        bool status = pmSourceMagnitudes (source, psf, photMode, maskVal, markVal, source->apRadius);
 
         // clear the mask bit
Index: branches/eam_branches/ipp-20110213/psphot/src/psphotArguments.c
===================================================================
--- branches/eam_branches/ipp-20110213/psphot/src/psphotArguments.c	(revision 30771)
+++ branches/eam_branches/ipp-20110213/psphot/src/psphotArguments.c	(revision 30772)
@@ -109,12 +109,13 @@
     }
 
-    PSARGUMENTS_INSTANTIATE_GENERICS( psphot, config, argc, argv );
+    // generic arguments (version, dumpconfig)
+    PS_ARGUMENTS_GENERIC( psphot, config, argc, argv );
+
+    // thread arguments
+    PS_ARGUMENTS_THREADS( psphot, config, argc, argv )
 
     // save the following additional recipe values based on command-line options
     // these options override the PSPHOT recipe values loaded from recipe files
     psMetadata *options = pmConfigRecipeOptions (config, PSPHOT_RECIPE);
-
-    // Number of threads is handled
-    PSARGUMENTS_INSTANTIATE_THREADSARG( psphot, config, argc, argv )
 
     // run the test model (requires X,Y coordinate)
Index: branches/eam_branches/ipp-20110213/psphot/src/psphotChoosePSF.c
===================================================================
--- branches/eam_branches/ipp-20110213/psphot/src/psphotChoosePSF.c	(revision 30771)
+++ branches/eam_branches/ipp-20110213/psphot/src/psphotChoosePSF.c	(revision 30772)
@@ -448,4 +448,7 @@
 	    }
             psFree (modelPSF);
+
+	    // float fwhmtest = pmPSFtoFWHM(psf, xc, yc);
+	    // fprintf (stderr, "fwhm: %f, %f : %f\n", FWHM_MAJOR, FWHM_MINOR, fwhmtest);
         }
     }
Index: branches/eam_branches/ipp-20110213/psphot/src/psphotExtendedSourceFits.c
===================================================================
--- branches/eam_branches/ipp-20110213/psphot/src/psphotExtendedSourceFits.c	(revision 30771)
+++ branches/eam_branches/ipp-20110213/psphot/src/psphotExtendedSourceFits.c	(revision 30772)
@@ -43,4 +43,5 @@
     int NplainPass = 0;
     int Nfaint = 0;
+    int Nfail = 0;
 
     psTimerStart ("psphot.extended");
@@ -176,5 +177,6 @@
             PS_ARRAY_ADD_SCALAR(job->args, 0, PS_TYPE_S32); // this is used as a return value for Nplain
             PS_ARRAY_ADD_SCALAR(job->args, 0, PS_TYPE_S32); // this is used as a return value for NplainPass
-            PS_ARRAY_ADD_SCALAR(job->args, 0, PS_TYPE_S32); // this is used as a return value for Nfain
+            PS_ARRAY_ADD_SCALAR(job->args, 0, PS_TYPE_S32); // this is used as a return value for Nfaint
+            PS_ARRAY_ADD_SCALAR(job->args, 0, PS_TYPE_S32); // this is used as a return value for Nfail
 
 // set this to 0 to run without threading
@@ -204,4 +206,6 @@
 	    scalar = job->args->data[12];
 	    Nfaint += scalar->data.S32;
+	    scalar = job->args->data[13];
+	    Nfail += scalar->data.S32;
 	    psFree(job);
 # endif
@@ -234,4 +238,6 @@
                 scalar = job->args->data[12];
                 Nfaint += scalar->data.S32;
+                scalar = job->args->data[13];
+                Nfail += scalar->data.S32;
             }
             psFree(job);
@@ -244,5 +250,5 @@
     psLogMsg ("psphot", PS_LOG_INFO, "  %d convolved models (%d passed)\n", Nconvolve, NconvolvePass);
     psLogMsg ("psphot", PS_LOG_INFO, "  %d plain models (%d passed)\n", Nplain, NplainPass);
-    psLogMsg ("psphot", PS_LOG_INFO, "  %d too faint to fit\n", Nfaint);
+    psLogMsg ("psphot", PS_LOG_INFO, "  %d too faint to fit, %d failed\n", Nfaint, Nfail);
     return true;
 }
@@ -253,8 +259,9 @@
     bool status;
     int Next = 0;
+    int Nfaint = 0;
+    int Nfail = 0;
     int Nconvolve = 0;
     int NconvolvePass = 0;
     int Nplain = 0;
-    int Nfaint = 0;
     int NplainPass = 0;
     bool savePics = false;
@@ -271,5 +278,5 @@
     psImageMaskType markVal = PS_SCALAR_VALUE(job->args->data[6],PS_TYPE_IMAGE_MASK_DATA);
 
-    pthread_t tid = pthread_self();     // Thread identifier
+    // pthread_t tid = pthread_self();     // Thread identifier
 
     // Define source fitting parameters for extended source fits
@@ -305,5 +312,5 @@
         // if (source->modelEXT == NULL) continue;
 
-	fprintf (stderr, "fit %d,%d in thread %d\n", source->peak->x, source->peak->y, (int) tid);
+	// fprintf (stderr, "fit %d,%d in thread %d\n", source->peak->x, source->peak->y, (int) tid);
 
         // replace object in image
@@ -398,4 +405,5 @@
               if (!modelFit) {
                   psTrace ("psphot", 5, "failed to fit psf-conv model for object at %f, %f", source->moments->Mx, source->moments->My);
+		  Nfail ++;
                   continue;
               }
@@ -412,4 +420,5 @@
               if (!modelFit) {
                   psTrace ("psphot", 5, "failed to fit plain model for object at %f, %f", source->moments->Mx, source->moments->My);
+		  Nfail ++;
                   continue;
               }
@@ -529,4 +538,7 @@
     scalar->data.S32 = Nfaint;
 
+    scalar = job->args->data[13];
+    scalar->data.S32 = Nfail;
+
     return true;
 }
Index: branches/eam_branches/ipp-20110213/psphot/src/psphotForcedArguments.c
===================================================================
--- branches/eam_branches/ipp-20110213/psphot/src/psphotForcedArguments.c	(revision 30771)
+++ branches/eam_branches/ipp-20110213/psphot/src/psphotForcedArguments.c	(revision 30772)
@@ -103,5 +103,5 @@
     }
 
-    PSARGUMENTS_INSTANTIATE_GENERICS( psphot, config, argc, argv );
+    PS_ARGUMENTS_GENERIC( psphot, config, argc, argv );
 
     // save the following additional recipe values based on command-line options
@@ -110,5 +110,5 @@
 
     // Number of threads is handled
-    PSARGUMENTS_INSTANTIATE_THREADSARG( psphot, config, argc, argv )
+    PS_ARGUMENTS_THREADS( psphot, config, argc, argv )
 
     // visual : interactive display mode
Index: branches/eam_branches/ipp-20110213/psphot/src/psphotMagnitudes.c
===================================================================
--- branches/eam_branches/ipp-20110213/psphot/src/psphotMagnitudes.c	(revision 30771)
+++ branches/eam_branches/ipp-20110213/psphot/src/psphotMagnitudes.c	(revision 30772)
@@ -76,5 +76,5 @@
     maskVal |= markVal;
 
-    pmSourceMagnitudesInit (recipe);
+    pmSourceMagnitudesInit (config, recipe);
 
     // the binning details are saved on the analysis metadata
@@ -176,5 +176,5 @@
         psImageKeepCircle (source->maskObj, source->peak->x, source->peak->y, source->apRadius, "OR", markVal);
 
-        status = pmSourceMagnitudes (source, psf, photMode, maskVal, markVal);
+        status = pmSourceMagnitudes (source, psf, photMode, maskVal, markVal, source->apRadius);
         if (status && isfinite(source->apMag)) Nap ++;
 
@@ -295,5 +295,4 @@
     psArray *sources                = job->args->data[0];
     psImageMaskType maskVal         = PS_SCALAR_VALUE(job->args->data[1],PS_TYPE_IMAGE_MASK_DATA);
-    psImageMaskType markVal         = PS_SCALAR_VALUE(job->args->data[2],PS_TYPE_IMAGE_MASK_DATA);
 
     for (int i = 0; i < sources->n; i++) {
@@ -309,5 +308,5 @@
         }
 
-        status = pmSourcePixelWeight (&source->pixWeightNotBad, &source->pixWeightNotPoor, model, source->maskObj, maskVal, markVal);
+        status = pmSourcePixelWeight (source, model, source->maskObj, maskVal, source->apRadius);
         if (!status) {
           psTrace ("psphot", 3, "fail to measure pixel weight");
Index: branches/eam_branches/ipp-20110213/psphot/src/psphotMakeGrowthCurve.c
===================================================================
--- branches/eam_branches/ipp-20110213/psphot/src/psphotMakeGrowthCurve.c	(revision 30771)
+++ branches/eam_branches/ipp-20110213/psphot/src/psphotMakeGrowthCurve.c	(revision 30772)
@@ -8,5 +8,5 @@
 
     // set limits on the aperture magnitudes
-    pmSourceMagnitudesInit (recipe);
+    pmSourceMagnitudesInit (NULL, recipe);
 
     // bit-masks to test for good/bad pixels
Index: branches/eam_branches/ipp-20110213/psphot/src/psphotMakePSFArguments.c
===================================================================
--- branches/eam_branches/ipp-20110213/psphot/src/psphotMakePSFArguments.c	(revision 30771)
+++ branches/eam_branches/ipp-20110213/psphot/src/psphotMakePSFArguments.c	(revision 30772)
@@ -103,5 +103,5 @@
     }
 
-    PSARGUMENTS_INSTANTIATE_GENERICS( psphot, config, argc, argv );
+    PS_ARGUMENTS_GENERIC( psphot, config, argc, argv );
 
     // save the following additional recipe values based on command-line options
@@ -110,5 +110,5 @@
 
     // Number of threads is handled
-    PSARGUMENTS_INSTANTIATE_THREADSARG( psphot, config, argc, argv )
+    PS_ARGUMENTS_THREADS( psphot, config, argc, argv )
 
     // visual : interactive display mode
Index: branches/eam_branches/ipp-20110213/psphot/src/psphotSetThreads.c
===================================================================
--- branches/eam_branches/ipp-20110213/psphot/src/psphotSetThreads.c	(revision 30771)
+++ branches/eam_branches/ipp-20110213/psphot/src/psphotSetThreads.c	(revision 30772)
@@ -35,5 +35,5 @@
     psFree(task);
 
-    task = psThreadTaskAlloc("PSPHOT_EXTENDED_FIT", 13);
+    task = psThreadTaskAlloc("PSPHOT_EXTENDED_FIT", 14);
     task->function = &psphotExtendedSourceFits_Threaded;
     psThreadTaskAdd(task);
Index: branches/eam_branches/ipp-20110213/psphot/src/psphotSourceSize.c
===================================================================
--- branches/eam_branches/ipp-20110213/psphot/src/psphotSourceSize.c	(revision 30771)
+++ branches/eam_branches/ipp-20110213/psphot/src/psphotSourceSize.c	(revision 30772)
@@ -207,5 +207,5 @@
         num++;
 
-        pmSourceMagnitudes (source, psf, photMode, maskVal, markVal);
+        pmSourceMagnitudes (source, psf, photMode, maskVal, markVal, source->apRadius);
 
         float kMag = -2.5*log10(source->moments->KronFlux);
@@ -327,5 +327,5 @@
 
         // XXX can we test if psfMag is set and calculate only if needed?
-        pmSourceMagnitudes (source, psf, photMode, maskVal, markVal);
+        pmSourceMagnitudes (source, psf, photMode, maskVal, markVal, source->apRadius);
 
         // convert to Mmaj, Mmin:
@@ -501,5 +501,5 @@
         // psImageMaskPixels (source->maskObj, "AND", PS_NOT_IMAGE_MASK(options->markVal));
         // psImageKeepCircle (source->maskObj, source->peak->x, source->peak->y, source->apRadius, "OR", options->markVal);
-        pmSourceMagnitudes (source, psf, photMode, maskVal, markVal);
+        pmSourceMagnitudes (source, psf, photMode, maskVal, markVal, source->apRadius);
 
         // clear the mask bit
Index: branches/eam_branches/ipp-20110213/psphot/src/psphotStackArguments.c
===================================================================
--- branches/eam_branches/ipp-20110213/psphot/src/psphotStackArguments.c	(revision 30771)
+++ branches/eam_branches/ipp-20110213/psphot/src/psphotStackArguments.c	(revision 30772)
@@ -22,6 +22,9 @@
     }
 
-    // -version and -dumpconfig arguments
-    PSARGUMENTS_INSTANTIATE_GENERICS( psphot, config, argc, argv );
+    // generic arguments (version, dumpconfig)
+    PS_ARGUMENTS_GENERIC( psphot, config, argc, argv );
+
+    // thread arguments
+    PS_ARGUMENTS_THREADS( psphot, config, argc, argv )
 
     // save the following additional recipe values based on command-line options
@@ -29,11 +32,14 @@
     psMetadata *options = pmConfigRecipeOptions (config, PSPHOT_RECIPE);
 
-    // Number of threads is handled
-    PSARGUMENTS_INSTANTIATE_THREADSARG( psphot, config, argc, argv )
-
     // visual : interactive display mode
     if ((N = psArgumentGet (argc, argv, "-visual"))) {
         psArgumentRemove (N, &argc, argv);
         pmVisualSetVisual(true);
+    }
+
+    // memdump : enable memory spot checks
+    if ((N = psArgumentGet (argc, argv, "-memdump"))) {
+        psArgumentRemove (N, &argc, argv);
+        psMemDumpSetState(true);
     }
 
Index: branches/eam_branches/ipp-20110213/psphot/src/psphotStackImageLoop.c
===================================================================
--- branches/eam_branches/ipp-20110213/psphot/src/psphotStackImageLoop.c	(revision 30771)
+++ branches/eam_branches/ipp-20110213/psphot/src/psphotStackImageLoop.c	(revision 30772)
@@ -50,4 +50,6 @@
                 psLogMsg ("psphot", 6, "Readout %d: %x %x\n", view->readout, cell->file_exists, cell->process);
                 if (! readout->data_exists) { continue; }
+
+		psMemDump("load");
 
 		// PSF matching
@@ -57,4 +59,5 @@
                     return false;
 		}
+		psMemDump("stackmatch");
 
 		// XXX for now, we assume there is only a single chip in the PHU:
@@ -64,5 +67,5 @@
                     return false;
 		}
-
+		psMemDump("psphot");
 	    }
 	    // drop all versions of the internal files
Index: branches/eam_branches/ipp-20110213/psphot/src/psphotStackMatchPSFsUtils.c
===================================================================
--- branches/eam_branches/ipp-20110213/psphot/src/psphotStackMatchPSFsUtils.c	(revision 30771)
+++ branches/eam_branches/ipp-20110213/psphot/src/psphotStackMatchPSFsUtils.c	(revision 30772)
@@ -287,5 +287,5 @@
 
     float penalty = psMetadataLookupF32(NULL, subRecipe, "PENALTY"); // Penalty for wideness
-    int threads = psMetadataLookupS32(NULL, config->arguments, "-threads"); // Number of threads
+    int threads = psMetadataLookupS32(NULL, config->arguments, "NTHREADS"); // Number of threads
 
     int order = psMetadataLookupS32(NULL, subRecipe, "SPATIAL.ORDER"); // Spatial polynomial order
Index: branches/eam_branches/ipp-20110213/psphot/src/psphotStackPSF.c
===================================================================
--- branches/eam_branches/ipp-20110213/psphot/src/psphotStackPSF.c	(revision 30771)
+++ branches/eam_branches/ipp-20110213/psphot/src/psphotStackPSF.c	(revision 30772)
@@ -56,8 +56,34 @@
 	}
 
-	float Sxx = sqrt(2.0)*targetFWHM / 2.35;
+	// measured scale factors (fwhm = Sxx * 2.35 * scaleFactor / sqrt(2.0))
+	// GAUSS  : 1.000
+	// PGAUSS : 1.006
+	// QGAUSS : 1.151
+	// RGAUSS : 0.883
+	// PS1_V1 : 1.134
+	
+	float scaleFactor = NAN;
+	if (!strcmp(psfModel, "PS_MODEL_GAUSS")) {
+	    scaleFactor = 1.000;
+	}
+	if (!strcmp(psfModel, "PS_MODEL_PGAUSS")) {
+	    scaleFactor = 1.0006;
+	}
+	if (!strcmp(psfModel, "PS_MODEL_QGAUSS")) {
+	    scaleFactor = 1.151;
+	}
+	if (!strcmp(psfModel, "PS_MODEL_RGAUSS")) {
+	    scaleFactor = 0.883;
+	}
+	if (!strcmp(psfModel, "PS_MODEL_PS1_V1")) {
+	    scaleFactor = 1.134;
+	}
+	psAssert (isfinite(scaleFactor), "invalid model for PSF"); 
+
+	float Sxx = sqrt(2.0)*targetFWHM / 2.35 / scaleFactor;
 
 	// XXX probably should make the model type (and par 7) optional from recipe
-	psf = pmPSFBuildSimple(psfModel, Sxx, Sxx, 0.0, 1.0);
+	// psf = pmPSFBuildSimple(psfModel, Sxx, Sxx, 0.0, 1.0);
+	psf = pmPSFBuildSimple(psfModel, Sxx, Sxx, 0.0, 0.2);
 	if (!psf) {
 	    psError(PSPHOT_ERR_PSF, false, "Unable to build dummy PSF.");
