Index: /branches/eam_branches/ipp-20110213/psModules/src/config/pmConfigRecipeValue.c
===================================================================
--- /branches/eam_branches/ipp-20110213/psModules/src/config/pmConfigRecipeValue.c	(revision 31090)
+++ /branches/eam_branches/ipp-20110213/psModules/src/config/pmConfigRecipeValue.c	(revision 31091)
@@ -32,6 +32,12 @@
         return NULL;
     }
-
-    psMetadataItem *fpaItem = psMetadataLookup(recipe, valueName); // Value for FPA or menu of chips
+    psMetadata *format = config->format;
+    
+    psMetadataItem *fpaItem;
+    fpaItem = psMetadataLookup(format, valueName);
+    if (!fpaItem) {
+      fpaItem = psMetadataLookup(recipe, valueName); // Value for FPA or menu of chips
+    }
+    
     if (!fpaItem) {
         psError(PS_ERR_UNEXPECTED_NULL, false, "Unable to find value %s in recipe %s", valueName, recipeName);
Index: /branches/eam_branches/ipp-20110213/psModules/src/detrend/pmDetrendDB.c
===================================================================
--- /branches/eam_branches/ipp-20110213/psModules/src/detrend/pmDetrendDB.c	(revision 31090)
+++ /branches/eam_branches/ipp-20110213/psModules/src/detrend/pmDetrendDB.c	(revision 31091)
@@ -7,4 +7,5 @@
 #include <pslib.h>
 
+#include "pmErrorCodes.h"
 #include "pmConfig.h"
 #include "pmConfigCommand.h"
@@ -120,4 +121,8 @@
     PS_ASSERT_PTR_NON_NULL(config, NULL);
 
+    psIOBuffer *buffer = NULL;
+    psPipe *pipe = NULL;
+    psMetadata *answer = NULL;
+
     int status, exit_status;
     psString line = NULL;
@@ -137,4 +142,19 @@
     psFree (realCamera);
 
+    // require a filter for certain types of detrends:
+    if ((options->type == PM_DETREND_TYPE_FLAT) && !options->filter) {
+        psError (PM_ERR_CONFIG, false, "requesting a FLAT-class of detrend without a filter");
+        goto failure;
+    }
+    if ((options->type == PM_DETREND_TYPE_FLATCORR) && !options->filter) {
+        psError (PM_ERR_CONFIG, false, "requesting a FLATCORR-class of detrend without a filter");
+        goto failure;
+    }
+    if ((options->type == PM_DETREND_TYPE_FRINGE) && !options->filter) {
+        psError (PM_ERR_CONFIG, false, "requesting a FRINGE-class of detrend without a filter");
+        goto failure;
+    }
+
+    // add the restrictions
     if (options->filter) {
         psStringAppend(&line, " -filter %s", options->filter);
@@ -155,8 +175,4 @@
         psStringAppend(&line, " -airmass %f", options->twilight);
     }
-
-    psIOBuffer *buffer = NULL;
-    psPipe *pipe = NULL;
-    psMetadata *answer = NULL;
 
     if (!pmConfigDatabaseCommand(&line, config)) {
Index: /branches/eam_branches/ipp-20110213/psModules/src/detrend/pmFringeStats.c
===================================================================
--- /branches/eam_branches/ipp-20110213/psModules/src/detrend/pmFringeStats.c	(revision 31090)
+++ /branches/eam_branches/ipp-20110213/psModules/src/detrend/pmFringeStats.c	(revision 31091)
@@ -1029,19 +1029,24 @@
     psVector *science_values   = psVectorAllocEmpty(4000,PS_TYPE_F32);
     psVector *science_errors   = psVectorAllocEmpty(4000,PS_TYPE_F32);
-
-    psStats *binStats = psStatsAlloc(PS_STAT_ROBUST_MEDIAN | PS_STAT_ROBUST_STDEV);
+    psVector *science_counts   = psVectorAllocEmpty(4000,PS_TYPE_S32);
+
+    psStats *binStats = psStatsAlloc(PS_STAT_CLIPPED_MEAN | PS_STAT_CLIPPED_STDEV);
     for (int i = 0; i < 4000; i++) {
       psVector *bin = bins->data[i];
-      if (bin->n > 2) {
+      if (bin->n > 10) {
 	psStatsInit(binStats);
 
 	psVectorStats(binStats,bin,NULL,NULL,1);
 	
-	if (isfinite(binStats->robustStdev) &&
-	    isfinite(binStats->robustMedian) &&
-	    binStats->robustStdev > 0) {
+	if (isfinite(binStats->clippedStdev) &&
+	    isfinite(binStats->clippedMean) &&
+	    (binStats->clippedStdev > 0) &&
+	    (binStats->clippedNvalues > 10) &&
+	    (binStats->clippedNvalues > 0.5 * bin->n)
+	    ) {
 	  psVectorAppend(fringe_positions,-0.1 + i * 5e-5);
-	  psVectorAppend(science_values, binStats->robustMedian);
-	  psVectorAppend(science_errors, binStats->robustStdev);
+	  psVectorAppend(science_values, binStats->clippedMean);
+	  psVectorAppend(science_errors, binStats->clippedStdev);
+	  psVectorAppend(science_counts, bin->n);
 	}
       }
@@ -1052,8 +1057,9 @@
 
     for (int i = 0; i < fringe_positions->n; i++) {
-      psTrace("psModules.detrend",7,"FITDATA: %f %f %f\n",
+      psTrace("psModules.detrend",7,"FITDATA: %f %f %f %d\n",
 	      fringe_positions->data.F32[i],
 	      science_values->data.F32[i],
-	      science_errors->data.F32[i]);
+	      science_errors->data.F32[i],
+	      science_counts->data.S32[i]);
     }
 /*     // Begin switch from old outlier removal and fitting code. */
@@ -1071,4 +1077,5 @@
     psFree(science_values);
     psFree(science_errors);
+    psFree(science_counts);
     
     for (int i = 0; i <= poly->nX; i++) {
Index: /branches/eam_branches/ipp-20110213/psModules/src/imcombine/pmSubtractionMatch.c
===================================================================
--- /branches/eam_branches/ipp-20110213/psModules/src/imcombine/pmSubtractionMatch.c	(revision 31090)
+++ /branches/eam_branches/ipp-20110213/psModules/src/imcombine/pmSubtractionMatch.c	(revision 31091)
@@ -684,5 +684,5 @@
 		    // if we failed, it might be due to the desired normWindow being larger than the current footprint.
 		    // in this case, just adjust the footprint and try again.
-		    if (tryAgain && (nTries >= 2)) {
+		    if (tryAgain && (nTries >= 5)) {
 			// unrecoverable error
 			psError(PM_ERR_STAMPS, true, "Unable to get stamp window (failure to converge).");
Index: /branches/eam_branches/ipp-20110213/psModules/src/imcombine/pmSubtractionStamps.c
===================================================================
--- /branches/eam_branches/ipp-20110213/psModules/src/imcombine/pmSubtractionStamps.c	(revision 31090)
+++ /branches/eam_branches/ipp-20110213/psModules/src/imcombine/pmSubtractionStamps.c	(revision 31091)
@@ -926,5 +926,5 @@
 
     // this is an unrecoverable error : something really bogus in the data
-    if (stamps->normWindow1 == 0) {
+    if (stamps->normWindow1 <= 0) {
         psError(PM_ERR_STAMPS, true, "Unable to determine normalisation window size (1).");
 	psFree (stats);
@@ -935,5 +935,5 @@
         return false;
     }
-    if (stamps->normWindow2 == 0) {
+    if (stamps->normWindow2 <= 0) {
         psError(PM_ERR_STAMPS, true, "Unable to determine normalisation window size (2).");
 	psFree (stats);
