Index: /branches/eam_branches/20091201/ppImage/src/ppImageDetrendPattern.c
===================================================================
--- /branches/eam_branches/20091201/ppImage/src/ppImageDetrendPattern.c	(revision 26779)
+++ /branches/eam_branches/20091201/ppImage/src/ppImageDetrendPattern.c	(revision 26780)
@@ -5,9 +5,11 @@
 #include "ppImage.h"
 
-#define ESCAPE(MESSAGE) {                               \
-        psError(PS_ERR_UNKNOWN, false, MESSAGE);        \
+#define ESCAPE(STATUS,...) {                    \
+        psError(PS_ERR_UNKNOWN, STATUS, __VA_ARGS__);   \
         psFree(view);                                   \
         return false;                                   \
     }
+
+static bool doPatternForView (bool *doit, const pmConfig *config, const pmChip *chip, const pmFPAview *view, const char *recipename, const char *recipevalue);
 
 bool ppImageDetrendPatternApply(pmConfig *config, pmChip *chip, const pmFPAview *inputView,
@@ -31,5 +33,5 @@
             }
             if (!pmFPAfileIOChecks(config, view, PM_FPA_BEFORE)) {
-                ESCAPE("load failure for Cell");
+	      ESCAPE(false, "load failure for Cell");
             }
 
@@ -43,12 +45,9 @@
             }
 
-            psMetadataItem *doPattern = pmConfigRecipeValueByView(config, RECIPE_NAME, "PATTERN.ROW.SUBSET",
-                                                                  chip->parent, view); // Do pattern corr?
-            if (!doPattern || doPattern->type != PS_DATA_BOOL) {
-                ESCAPE("Unable to determine whether row pattern correction should be applied.");
-            }
-            if (!doPattern->data.B) {
-                continue;
-            }
+	    bool doPattern = false; 
+	    if (!doPatternForView(&doPattern, config, chip, view, RECIPE_NAME, "PATTERN.ROW.SUBSET")) {
+		ESCAPE(false, "Unable to determine whether row pattern matching should be applied.");
+	    }
+	    if (!doPattern) continue;
 
             psLogMsg("ppImage", PS_LOG_INFO, "Performing row pattern correction for %d,%d\n",
@@ -59,5 +58,5 @@
             while ((readout = pmFPAviewNextReadout (view, input->fpa, 1)) != NULL) {
                 if (!pmFPAfileIOChecks(config, view, PM_FPA_BEFORE)) {
-                    ESCAPE("load failure for Readout");
+		    ESCAPE(false, "load failure for Readout");
                 }
                 if (!readout->data_exists) {
@@ -84,12 +83,12 @@
         for (int i = 0; i < chip->cells->n; i++) {
             view->cell = i;
-            psMetadataItem *doPattern = pmConfigRecipeValueByView(config, RECIPE_NAME, "PATTERN.CELL.SUBSET",
-                                                                  chip->parent, view); // Do pattern sub?
-            if (!doPattern || doPattern->type != PS_DATA_BOOL) {
-                ESCAPE("Unable to determine whether cell pattern correction  should be applied.");
-            }
-            if (doPattern->data.B) {
-                tweak->data.U8[i] = 0xFF;
-            }
+
+	    bool doPattern = false; 
+	    if (!doPatternForView(&doPattern, config, chip, view, RECIPE_NAME, "PATTERN.CELL.SUBSET")) {
+		ESCAPE(false, "Unable to determine whether row pattern matching should be applied.");
+	    }
+	    if (doPattern) {
+		tweak->data.U8[i] = 0xFF;
+	    }
         }
 
@@ -108,3 +107,46 @@
 }
 
+static bool doPatternForView (bool *doit, const pmConfig *config, const pmChip *chip, const pmFPAview *view, const char *recipeName, const char *recipeValue) {
 
+    *doit = false;
+
+    psMetadataItem *doPattern = pmConfigRecipeValueByView(config, recipeName, recipeValue, chip->parent, view);
+    if (!doPattern) {
+	psError(PS_ERR_UNKNOWN, false, "Unable to determine whether row pattern matching should be applied.");
+	return false;
+    }
+    if (doPattern->type == PS_DATA_BOOL) {
+	*doit = doPattern->data.B;
+	return true;
+    }
+    if (doPattern->type == PS_DATA_STRING) {
+	// expect a string of the form "000110001001" with at least view->cell entries
+	char *string = doPattern->data.str;
+	if (strlen(string) < view->cell) {
+	    psError(PS_ERR_UNKNOWN, true, "error in PATTERN.ROW.SUBSET chip string (too few elements %d)", (int) strlen(string));
+	    return false;
+	}
+	switch (string[view->cell]) {
+	  case '0':
+	  case 'f':
+	  case 'F':
+	  case 'n':
+	  case 'N':
+	    *doit = false;
+	    return true;
+	  case '1':
+	  case 't':
+	  case 'T':
+	  case 'y':
+	  case 'Y':
+	    *doit = true;
+	    return true;
+	  default:
+	    psError(PS_ERR_UNKNOWN, true, "error in PATTERN.ROW.SUBSET chip string %s (unknown value %c))", string, string[view->cell]);
+	    return false;
+	}
+	psAbort("imposible to reach here");
+    }
+    psError(PS_ERR_UNKNOWN, true, "error in PATTERN.ROW.SUBSET : invalid data type");
+    return false;
+}
