Index: /trunk/ippconfig/gpc1/ppImage.config
===================================================================
--- /trunk/ippconfig/gpc1/ppImage.config	(revision 26628)
+++ /trunk/ippconfig/gpc1/ppImage.config	(revision 26629)
@@ -14,4 +14,6 @@
 
 OLDDARK                 BOOL    FALSE
+
+GAIN.OVERRIDE		BOOL	TRUE		# Override a non-finite gain?
 
 # use the deburned image instead of the raw, if it exists
Index: /trunk/ippconfig/recipes/ppImage.config
===================================================================
--- /trunk/ippconfig/recipes/ppImage.config	(revision 26628)
+++ /trunk/ippconfig/recipes/ppImage.config	(revision 26629)
@@ -128,4 +128,6 @@
 FRINGE.FILTERS  MULTI
 FRINGE.FILTERS  STR UNDEF
+
+GAIN.OVERRIDE	BOOL	FALSE		# Override a non-finite gain?
 
 DETREND.CONSTRAINTS  METADATA
Index: /trunk/ippconfig/recipes/ppMerge.config
===================================================================
--- /trunk/ippconfig/recipes/ppMerge.config	(revision 26628)
+++ /trunk/ippconfig/recipes/ppMerge.config	(revision 26629)
@@ -43,4 +43,6 @@
 STATS.BY.CHIP       BOOL    TRUE            # measure stats for masking by chip (or by readout)
 MASK.GROW.NPIX      S32     3               # measure stats for masking by chip (or by readout)
+
+GAIN.OVERRIDE	    BOOL    FALSE	    # Override non-finite gain?
 
 # Ordinates for fitting dark current
Index: /trunk/ppImage/src/ppImageDetrendReadout.c
===================================================================
--- /trunk/ppImage/src/ppImageDetrendReadout.c	(revision 26628)
+++ /trunk/ppImage/src/ppImageDetrendReadout.c	(revision 26629)
@@ -89,4 +89,24 @@
             psFree (binning);
         }
+
+        // Check that the gain is set
+        float gain = psMetadataLookupF32(NULL, input->parent->concepts, "CELL.GAIN"); // Gain for cell
+        if (!isfinite(gain)) {
+            psMetadata *recipe = psMetadataLookupMetadata(NULL, config->recipes, RECIPE_NAME); // Recipe
+            psAssert(recipe, "Should be there!");
+            bool override = psMetadataLookupBool(NULL, recipe, "GAIN.OVERRIDE"); // Override the bad gain?
+            if (override) {
+                psWarning("CELL.GAIN is not set for readout (%d,%d,%d) --- setting to unity.",
+                          view->chip, view->cell, view->readout);
+                psMetadataItem *item = psMetadataLookup(input->parent->concepts, "CELL.GAIN"); // Gain item
+                psAssert(item, "Should be there!");
+                item->data.F32 = 1.0;
+            } else {
+                psError(PS_ERR_BAD_PARAMETER_VALUE, false, "CELL.GAIN is not set for readout (%d,%d,%d)",
+                        view->chip, view->cell, view->readout);
+                return false;
+            }
+        }
+
         pmReadoutGenerateVariance(input, noiseImage, true);
         psFree (noiseImage);
Index: /trunk/ppMerge/src/ppMergeScaleZero.c
===================================================================
--- /trunk/ppMerge/src/ppMergeScaleZero.c	(revision 26628)
+++ /trunk/ppMerge/src/ppMergeScaleZero.c	(revision 26629)
@@ -67,7 +67,7 @@
         pmChip *chip;                   ///< Chip of interest
         while ((chip = pmFPAviewNextChip(view, fpa, 1))) {
-	    if (!chip->process || !chip->file_exists) {
-		continue;
-	    }
+            if (!chip->process || !chip->file_exists) {
+                continue;
+            }
             if (!pmFPAfileIOChecks(config, view, PM_FPA_BEFORE)) {
                 goto ERROR;
@@ -76,7 +76,7 @@
             pmCell *cell;               ///< Cell of interest
             while ((cell = pmFPAviewNextCell(view, fpa, 1))) {
-		if (!cell->process || !cell->file_exists) {
-		    continue;
-		}
+                if (!cell->process || !cell->file_exists) {
+                    continue;
+                }
                 if (!pmFPAfileIOChecks(config, view, PM_FPA_BEFORE)) {
                     goto ERROR;
@@ -87,10 +87,11 @@
                 }
 
-		// skip cells with video data
+                // skip cells with video data
                 if (cell->readouts->n > 1) {
-		    // psError(PS_ERR_BAD_PARAMETER_VALUE, true, "File %d chip %d cell %d contains more than one readout (%ld)", i, view->chip, view->cell, cell->readouts->n);
-		    // goto ERROR;
-		  psWarning("File %d chip %d cell %d contains more than one readout (%ld), skipping", i, view->chip, view->cell, cell->readouts->n);
-		  continue;
+                    // psError(PS_ERR_BAD_PARAMETER_VALUE, true, "File %d chip %d cell %d contains more than one readout (%ld)", i, view->chip, view->cell, cell->readouts->n);
+                    // goto ERROR;
+                  psWarning("File %d chip %d cell %d contains more than one readout (%ld), skipping",
+                            i, view->chip, view->cell, cell->readouts->n);
+                  continue;
                 }
                 pmReadout *readout = cell->readouts->data[0]; ///< Readout of interest
@@ -104,9 +105,25 @@
                       float gain = psMetadataLookupF32(NULL, cell->concepts, "CELL.GAIN"); ///< Cell gain
                       if (!isfinite(gain)) {
-                        // psError(PS_ERR_BAD_PARAMETER_VALUE, false,
-                        // "CELL.GAIN for file %d chip %d cell %d is not set.",
-                        // i, view->chip, view->cell);
-                        // goto ERROR;
-                        psWarning ("CELL.GAIN for file %d chip %d cell %d is NaN", i, view->chip, view->cell);
+                          psMetadata *recipe = psMetadataLookupMetadata(NULL, config->recipes,
+                                                                        PPMERGE_RECIPE); // Recipe
+                          psAssert(recipe, "Should be there!");
+                          bool override = psMetadataLookupBool(NULL, recipe,
+                                                               "GAIN.OVERRIDE"); // Override the bad gain?
+                          if (override) {
+                              psWarning("CELL.GAIN is not set for readout (%d,%d,%d) on file %d "
+                                        "--- setting to unity.",
+                                        view->chip, view->cell, view->readout, i);
+                              psMetadataItem *item = psMetadataLookup(cell->concepts,
+                                                                      "CELL.GAIN"); // Item with gain
+                              psAssert(item, "Should be there!");
+                              item->data.F32 = 1.0;
+                          } else {
+                              // psError(PS_ERR_BAD_PARAMETER_VALUE, false,
+                              // "CELL.GAIN for file %d chip %d cell %d is not set.",
+                              // i, view->chip, view->cell);
+                              // goto ERROR;
+                              psWarning("CELL.GAIN for file %d chip %d cell %d is NaN",
+                                        i, view->chip, view->cell);
+                          }
                       }
                       gains->data.F32[cellNum] = gain;
@@ -118,5 +135,6 @@
                         // i, view->chip, view->cell);
                         // goto ERROR;
-                        psWarning ("Unable to get statistics for file %d chip %d cell %d", i, view->chip, view->cell);
+                        psWarning ("Unable to get statistics for file %d chip %d cell %d",
+                                   i, view->chip, view->cell);
                         background->data.F32[i][cellNum] = NAN;
                       } else {
