Index: trunk/psModules/src/concepts/pmConceptsStandard.c
===================================================================
--- trunk/psModules/src/concepts/pmConceptsStandard.c	(revision 11687)
+++ trunk/psModules/src/concepts/pmConceptsStandard.c	(revision 11749)
@@ -47,4 +47,5 @@
 psMetadataItem *p_pmConceptParse_FPA_FILTER(const psMetadataItem *concept,
         const psMetadataItem *pattern,
+                                            pmConceptSource source,
         const psMetadata *cameraFormat,
         const pmFPA *fpa,
@@ -82,4 +83,5 @@
 
 psMetadataItem *p_pmConceptFormat_FPA_FILTER(const psMetadataItem *concept,
+                                            pmConceptSource source,
         const psMetadata *cameraFormat,
         const pmFPA *fpa,
@@ -133,4 +135,5 @@
 psMetadataItem *p_pmConceptParse_FPA_Coords(const psMetadataItem *concept,
         const psMetadataItem *pattern,
+                                            pmConceptSource source,
         const psMetadata *cameraFormat,
         const pmFPA *fpa,
@@ -202,4 +205,5 @@
 // FPA.RA and FPA.DEC
 psMetadataItem *p_pmConceptFormat_FPA_Coords(const psMetadataItem *concept,
+                                            pmConceptSource source,
         const psMetadata *cameraFormat,
         const pmFPA *fpa,
@@ -264,4 +268,5 @@
 psMetadataItem *p_pmConceptParse_CELL_TRIMSEC(const psMetadataItem *concept,
         const psMetadataItem *pattern,
+                                            pmConceptSource source,
         const psMetadata *cameraFormat,
         const pmFPA *fpa,
@@ -277,6 +282,14 @@
     if (concept->type != PS_DATA_STRING) {
         psError(PS_ERR_UNKNOWN, true, "CELL.TRIMSEC after read is not of type STR (%x)\n", concept->type);
+        return NULL;
     } else {
         *trimsec = psRegionFromString(concept->data.V);
+    }
+
+    // Need to correct for binning when CELL.TRIMSEC are specified immutably in the CELLS
+    if (source == PM_CONCEPT_SOURCE_CELLS) {
+        psMetadataAddBool(cell->concepts, PS_LIST_TAIL, "CELL.TRIMSEC.UPDATE", 0,
+                          "Need to update CELL.TRIMSEC when the binning is available.",
+                          true);
     }
 
@@ -288,4 +301,5 @@
 psMetadataItem *p_pmConceptParse_CELL_BIASSEC(const psMetadataItem *concept,
         const psMetadataItem *pattern,
+                                            pmConceptSource source,
         const psMetadata *cameraFormat,
         const pmFPA *fpa,
@@ -336,4 +350,11 @@
     }
 
+    // Need to correct for binning when CELL.BIASSEC are specified immutably in the CELLS
+    if (source == PM_CONCEPT_SOURCE_CELLS) {
+        psMetadataAddBool(cell->concepts, PS_LIST_TAIL, "CELL.BIASSEC.UPDATE", 0,
+                          "Need to update CELL.BIASSEC when the binning is available.",
+                          true);
+    }
+
     psMetadataItem *item = psMetadataItemAllocPtr(pattern->name, PS_DATA_LIST, pattern->comment, biassecs);
     psFree(biassecs);               // Drop reference
@@ -344,4 +365,5 @@
 psMetadataItem *p_pmConceptParse_CELL_Binning(const psMetadataItem *concept,
         const psMetadataItem *pattern,
+                                            pmConceptSource source,
         const psMetadata *cameraFormat,
         const pmFPA *fpa,
@@ -381,4 +403,5 @@
 psMetadataItem *p_pmConceptParse_TIMESYS(const psMetadataItem *concept,
         const psMetadataItem *pattern,
+                                            pmConceptSource source,
         const psMetadata *cameraFormat,
         const pmFPA *fpa,
@@ -410,4 +433,5 @@
 psMetadataItem *p_pmConceptParse_TIME(const psMetadataItem *concept,
                                       const psMetadataItem *pattern,
+                                            pmConceptSource source,
                                       const psMetadata *cameraFormat,
                                       const pmFPA *fpa,
@@ -663,4 +687,5 @@
 psMetadataItem *p_pmConceptParse_Positions(const psMetadataItem *concept,
         const psMetadataItem *pattern,
+                                            pmConceptSource source,
         const psMetadata *cameraFormat,
         const pmFPA *fpa,
@@ -718,13 +743,31 @@
 
 psMetadataItem *p_pmConceptFormat_CELL_TRIMSEC(const psMetadataItem *concept,
-        const psMetadata *cameraFormat,
-        const pmFPA *fpa,
-        const pmChip *chip,
-        const pmCell *cell)
-{
-    assert(concept);
-
-    psRegion *trimsec = concept->data.V; // The trimsec region
+                                            pmConceptSource source,
+        const psMetadata *cameraFormat,
+        const pmFPA *fpa,
+        const pmChip *chip,
+        const pmCell *cell)
+{
+    assert(concept);
+
+    psRegion *trimsec = psMemIncrRefCounter(concept->data.V); // The trimsec region
+
+    // Correct trim section for binning if it's specified explicitly (i.e., immutably) in the CELLS.
+    if (source == PM_CONCEPT_SOURCE_CELLS) {
+        bool xStatus, yStatus;          // Status of MD lookups
+        int xBin = psMetadataLookupS32(&xStatus, cell->concepts, "CELL.XBIN");
+        int yBin = psMetadataLookupS32(&yStatus, cell->concepts, "CELL.YBIN");
+        if (!xStatus || !yStatus || xBin == 0 || yBin == 0) {
+            psWarning("Unable to find CELL.XBIN and CELL.YBIN to correct CELL.TRIMSEC.\n");
+            return psMemIncrRefCounter((psPtr)concept); // Casting away "const" to increment
+        }
+        psRegion *newTrimsec = psRegionAlloc(trimsec->x0 * xBin, trimsec->x1 * xBin,
+                                             trimsec->y0 * yBin, trimsec->y1 * yBin); // Adjusted for binning
+        psFree(trimsec);
+        trimsec = newTrimsec;
+    }
+
     psString trimsecString = psRegionToString(*trimsec);
+    psFree(trimsec);
     psMetadataItem *formatted = psMetadataItemAllocStr(concept->name, concept->comment,
                                 trimsecString);
@@ -734,4 +777,5 @@
 
 psMetadataItem *p_pmConceptFormat_CELL_BIASSEC(const psMetadataItem *concept,
+                                            pmConceptSource source,
         const psMetadata *cameraFormat,
         const pmFPA *fpa,
@@ -745,5 +789,23 @@
     psList *new = psListAlloc(NULL);    // New list containing metadatas
     while ((region = psListGetAndIncrement(biassecsIter))) {
+
+        // Correct bias section for binning if it's specified explicitly (i.e., immutably) in the CELLS.
+        if (source == PM_CONCEPT_SOURCE_CELLS) {
+            bool xStatus, yStatus;          // Status of MD lookups
+            int xBin = psMetadataLookupS32(&xStatus, cell->concepts, "CELL.XBIN");
+            int yBin = psMetadataLookupS32(&yStatus, cell->concepts, "CELL.YBIN");
+            if (!xStatus || !yStatus || xBin == 0 || yBin == 0) {
+                psWarning("Unable to find CELL.XBIN and CELL.YBIN to correct CELL.BIASSEC.\n");
+            } else {
+                psRegion *newTrimsec = psRegionAlloc(region->x0 * xBin, region->x1 * xBin,
+                                                     region->y0 * yBin, region->y1 * yBin);
+                region = newTrimsec;
+            }
+        } else {
+            psMemIncrRefCounter(region);
+        }
+
         psString regionString = psRegionToString(*region); // The string region "[x0:x1,y0:y1]"
+        psFree(region);
         psMetadataItem *item = psMetadataItemAllocStr(concept->name, concept->comment, regionString);
         psFree(regionString);           // Drop reference
@@ -760,4 +822,5 @@
 // same header.
 psMetadataItem *p_pmConceptFormat_CELL_XBIN(const psMetadataItem *concept,
+                                            pmConceptSource source,
         const psMetadata *cameraFormat,
         const pmFPA *fpa,
@@ -787,4 +850,5 @@
 // Only need to format if both if CELL.XBIN and CELL.YBIN are not specified by the same header.
 psMetadataItem *p_pmConceptFormat_CELL_YBIN(const psMetadataItem *concept,
+                                            pmConceptSource source,
         const psMetadata *cameraFormat,
         const pmFPA *fpa,
@@ -810,4 +874,5 @@
 
 psMetadataItem *p_pmConceptFormat_TIMESYS(const psMetadataItem *concept,
+                                            pmConceptSource source,
         const psMetadata *cameraFormat,
         const pmFPA *fpa,
@@ -839,4 +904,5 @@
 
 psMetadataItem *p_pmConceptFormat_TIME(const psMetadataItem *concept,
+                                            pmConceptSource source,
                                        const psMetadata *cameraFormat,
                                        const pmFPA *fpa,
@@ -973,4 +1039,5 @@
 
 psMetadataItem *p_pmConceptFormat_Positions(const psMetadataItem *concept,
+                                            pmConceptSource source,
         const psMetadata *cameraFormat,
         const pmFPA *fpa,
@@ -1042,2 +1109,3 @@
 }
 
+
