Index: trunk/ppMerge/src/ppMergeCamera.c
===================================================================
--- trunk/ppMerge/src/ppMergeCamera.c	(revision 17929)
+++ trunk/ppMerge/src/ppMergeCamera.c	(revision 18365)
@@ -30,4 +30,41 @@
         return false;
     }
+
+    // Chip selection: turn on only the chips specified.
+    bool status;
+    char *chipLine = psMetadataLookupStr(&status, config->arguments, "CHIP_SELECTIONS");
+    psArray *chips = psStringSplitArray (chipLine, ",", false);
+    if (chips->n > 0) {
+        pmFPASelectChip (fpa, -1, true); // deselect all chips
+        for (int i = 0; i < chips->n; i++) {
+            int chipNum = atoi(chips->data[i]);
+            if (! pmFPASelectChip(fpa, chipNum, false)) {
+                psError(PS_ERR_IO, false, "Chip number %d doesn't exist in camera.\n", chipNum);
+		psFree (chips);
+                return false;
+            }
+        }
+    }
+    psFree (chips);
+
+    // Cell selection: turn on only the cells specified.  Note that this affects the same cell
+    // for all chips
+    char *cellLine = psMetadataLookupStr(&status, config->arguments, "CELL_SELECTIONS");
+    psArray *cells = psStringSplitArray (cellLine, ",", false);
+    if (cells->n > 0) {
+	for (int i = 0; i < fpa->chips->n; i++) {
+	    pmChip *chip = fpa->chips->data[i];
+	    pmChipSelectCell (chip, -1, true); // deselect all cells
+	    for (int j = 0; j < cells->n; j++) {
+		int cellNum = atoi(cells->data[j]);
+		if (! pmChipSelectCell(chip, cellNum, false)) {
+		    psError(PS_ERR_IO, false, "Cell number %d doesn't exist in camera.\n", cellNum);
+		    psFree (cells);
+		    return false;
+		}
+	    }
+	}
+    }
+    psFree (cells);
 
     pmFPAfile *output = pmFPAfileDefineOutput(config, fpa, name);
@@ -229,16 +266,20 @@
                 pmHDU *hdu = pmHDUGetLowest(fpa, chip, cell); // HDU for cell
                 if (!hdu || hdu->blankPHU) {
-                    psFree(cell->concepts);
-                    cell->concepts = NULL;
                     cell->data_exists = false;
                     cell->file_exists = false;
                     culled++;
+		    if (cell->concepts) {
+			psFree(cell->concepts);
+			cell->concepts = NULL;
+		    }
                 }
             }
             if (culled == cells->n) {
-                psFree(chip->concepts);
-                chip->concepts = NULL;
                 chip->data_exists = false;
                 chip->file_exists = false;
+		if (chip->concepts) {
+		    psFree(chip->concepts);
+		    chip->concepts = NULL;
+		}
             }
         }
