Index: trunk/psModules/src/concepts/Makefile.am
===================================================================
--- trunk/psModules/src/concepts/Makefile.am	(revision 11687)
+++ trunk/psModules/src/concepts/Makefile.am	(revision 11749)
@@ -9,5 +9,6 @@
 	pmConceptsWrite.c \
 	pmConceptsStandard.c \
-	pmConceptsPhotcode.c
+	pmConceptsPhotcode.c \
+	pmConceptsUpdate.c
 
 pkginclude_HEADERS = \
@@ -17,5 +18,6 @@
 	pmConceptsWrite.h \
 	pmConceptsStandard.h \
-	pmConceptsPhotcode.h
+	pmConceptsPhotcode.h \
+	pmConceptsUpdate.h
 
 CLEANFILES = *~
Index: trunk/psModules/src/concepts/pmConcepts.c
===================================================================
--- trunk/psModules/src/concepts/pmConcepts.c	(revision 11687)
+++ trunk/psModules/src/concepts/pmConcepts.c	(revision 11749)
@@ -13,4 +13,5 @@
 #include "pmConceptsWrite.h"
 #include "pmConceptsStandard.h"
+#include "pmConceptsUpdate.h"
 
 static bool conceptsInitialised = false;// Have concepts been read?
@@ -222,4 +223,6 @@
     #endif
 
+    pmConceptsUpdate(fpa, chip, cell);
+
     return success;
 }
@@ -486,5 +489,5 @@
         {
             psMetadataItem *fpaFilterid = psMetadataItemAllocStr("FPA.FILTERID",
-                                          "Filter used (parsed, abstract name) ", "");
+                                                                 "Filter used (parsed, abstract name) ", "");
             pmConceptRegister(fpaFilterid, (pmConceptParseFunc)p_pmConceptParse_FPA_FILTER,
                               (pmConceptFormatFunc)p_pmConceptFormat_FPA_FILTER, PM_FPA_LEVEL_FPA);
Index: trunk/psModules/src/concepts/pmConcepts.h
===================================================================
--- trunk/psModules/src/concepts/pmConcepts.h	(revision 11687)
+++ trunk/psModules/src/concepts/pmConcepts.h	(revision 11749)
@@ -4,6 +4,6 @@
  * @author Paul Price, IfA
  *
- * @version $Revision: 1.11 $ $Name: not supported by cvs2svn $
- * @date $Date: 2007-01-24 02:54:14 $
+ * @version $Revision: 1.12 $ $Name: not supported by cvs2svn $
+ * @date $Date: 2007-02-12 22:22:15 $
  * Copyright 2005-2006 Institute for Astronomy, University of Hawaii
  */
@@ -19,7 +19,23 @@
 #include "pmFPALevel.h"
 
+/// Source for concepts when reading and writing.
+///
+/// Since some sources become available at different times from others, we need to provide some specificity to
+/// reading and writing concepts (or we're forced to wait until everything's available, which we don't want to
+/// do).  Concepts may be read from or written to multiple sources at once by OR-ing them.
+typedef enum {
+    PM_CONCEPT_SOURCE_NONE     = 0x00,  ///< No concepts
+    PM_CONCEPT_SOURCE_CELLS    = 0x01,  ///< Concept comes from the camera information
+    PM_CONCEPT_SOURCE_DEFAULTS = 0x02,  ///< Concept comes from defaults
+    PM_CONCEPT_SOURCE_PHU      = 0x04,  ///< Concept comes from PHU
+    PM_CONCEPT_SOURCE_HEADER   = 0x08,  ///< Concept comes from FITS header
+    PM_CONCEPT_SOURCE_DATABASE = 0x10,  ///< Concept comes from database
+    PM_CONCEPT_SOURCE_ALL      = 0xff   ///< All concepts
+} pmConceptSource;
+
 /// Function to call to parse a concept once it has been read
 typedef psMetadataItem* (*pmConceptParseFunc)(const psMetadataItem *concept, ///< Concept to parse
         const psMetadataItem *pattern, ///< Pattern for parsing
+                                              pmConceptSource source, ///< Source of concept
         const psMetadata *cameraFormat, ///< Camera format definition
         const pmFPA *fpa, ///< FPA for concept, or NULL
@@ -30,4 +46,5 @@
 /// Function to call to format a concept for writing
 typedef psMetadataItem* (*pmConceptFormatFunc)(const psMetadataItem *concept, ///< Concept to format
+                                               pmConceptSource source, ///< Source of concept
         const psMetadata *cameraFormat, ///< Camera format definition
         const pmFPA *fpa, ///< FPA for concept, or NULL
@@ -65,19 +82,4 @@
                        pmFPALevel level ///< Level at which to store concept in the FPA hierarchy
                       );
-
-/// Source for concepts when reading and writing.
-///
-/// Since some sources become available at different times from others, we need to provide some specificity to
-/// reading and writing concepts (or we're forced to wait until everything's available, which we don't want to
-/// do).  Concepts may be read from or written to multiple sources at once by OR-ing them.
-typedef enum {
-    PM_CONCEPT_SOURCE_NONE     = 0x00,  ///< No concepts
-    PM_CONCEPT_SOURCE_CELLS    = 0x01,  ///< Concept comes from the camera information
-    PM_CONCEPT_SOURCE_DEFAULTS = 0x02,  ///< Concept comes from defaults
-    PM_CONCEPT_SOURCE_PHU      = 0x04,  ///< Concept comes from PHU
-    PM_CONCEPT_SOURCE_HEADER   = 0x08,  ///< Concept comes from FITS header
-    PM_CONCEPT_SOURCE_DATABASE = 0x10,  ///< Concept comes from database
-    PM_CONCEPT_SOURCE_ALL      = 0xff   ///< All concepts
-} pmConceptSource;
 
 /// Get a list of defined concepts for a particular level.
Index: trunk/psModules/src/concepts/pmConceptsRead.c
===================================================================
--- trunk/psModules/src/concepts/pmConceptsRead.c	(revision 11687)
+++ trunk/psModules/src/concepts/pmConceptsRead.c	(revision 11749)
@@ -53,4 +53,5 @@
 static bool conceptParse(pmConceptSpec *spec, // The concept specification
                          psMetadataItem *concept, // The concept to parse
+                         pmConceptSource source, // The concept source
                          psMetadata *cameraFormat, // The camera format
                          psMetadata *target, // The target
@@ -71,5 +72,5 @@
     psMetadataItem *parsed = NULL;  // The parsed concept
     if (spec->parse) {
-        parsed = spec->parse(concept, spec->blank, cameraFormat, fpa, chip, cell);
+        parsed = spec->parse(concept, spec->blank, source, cameraFormat, fpa, chip, cell);
     } else {
         parsed = parsePlain(concept, spec->blank);
@@ -144,6 +145,7 @@
                 psString source = psMetadataLookupStr(&mdok, cell->config, nameSource); // The source
                 psFree(nameSource);
-                if (mdok && strlen(source) > 0 && strcasecmp(source, "VALUE") == 0) {
-                    if (!conceptParse(spec, conceptItem, cameraFormat, target, NULL, NULL, cell)) {
+                if (mdok && source && strlen(source) > 0 && strcasecmp(source, "VALUE") == 0) {
+                    if (!conceptParse(spec, conceptItem, PM_CONCEPT_SOURCE_CELLS,
+                                      cameraFormat, target, NULL, NULL, cell)) {
                         psError(PS_ERR_UNEXPECTED_NULL, false, "Unable to parse concept %s from camera "
                                 "configuration\n", name);
@@ -158,5 +160,6 @@
             } else {
                 // Another type --- should be OK
-                if (!conceptParse(spec, conceptItem, cameraFormat, target, NULL, NULL, cell)) {
+                if (!conceptParse(spec, conceptItem, PM_CONCEPT_SOURCE_CELLS,
+                                  cameraFormat, target, NULL, NULL, cell)) {
                     psError(PS_ERR_UNEXPECTED_NULL, false, "Unable to parse concept %s from camera "
                             "configuration.\n", name);
@@ -241,5 +244,6 @@
             // Now we can parse this as we would ordinarily
         }
-        if (conceptItem && !conceptParse(spec, conceptItem, cameraFormat, target, fpa, chip, cell)) {
+        if (conceptItem && !conceptParse(spec, conceptItem, PM_CONCEPT_SOURCE_DEFAULTS,
+                                         cameraFormat, target, fpa, chip, cell)) {
             psError(PS_ERR_UNEXPECTED_NULL, false, "Unable to parse concept %s from DEFAULTS.\n", name);
             status = false;
@@ -340,5 +344,6 @@
         // This will also clean up the name
         if (headerItem) {
-            if (!conceptParse(spec, headerItem, cameraFormat, target, fpa, chip, cell)) {
+            if (!conceptParse(spec, headerItem, PM_CONCEPT_SOURCE_HEADER,
+                              cameraFormat, target, fpa, chip, cell)) {
                 psError(PS_ERR_UNEXPECTED_NULL, false, "Unable to parse concept %s from header.\n", name);
                 status = false;
@@ -459,5 +464,6 @@
 
                     // Now we have the result
-                    if (!conceptParse(spec, conceptItem, cameraFormat, target, fpa, chip, cell)) {
+                    if (!conceptParse(spec, conceptItem, PM_CONCEPT_SOURCE_DATABASE,
+                                      cameraFormat, target, fpa, chip, cell)) {
                         psError(PS_ERR_UNEXPECTED_NULL, false, "Unable to parse concept %s from database.\n",
                                 name);
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 @@
 }
 
+
Index: trunk/psModules/src/concepts/pmConceptsStandard.h
===================================================================
--- trunk/psModules/src/concepts/pmConceptsStandard.h	(revision 11687)
+++ trunk/psModules/src/concepts/pmConceptsStandard.h	(revision 11749)
@@ -4,6 +4,6 @@
  * @author Paul Price, IfA
  *
- * @version $Revision: 1.8 $ $Name: not supported by cvs2svn $
- * @date $Date: 2007-01-24 02:54:15 $
+ * @version $Revision: 1.9 $ $Name: not supported by cvs2svn $
+ * @date $Date: 2007-02-12 22:22:15 $
  * Copyright 2005-2006 Institute for Astronomy, University of Hawaii
  */
@@ -17,8 +17,10 @@
 #include <pslib.h>
 #include "pmFPA.h"
+#include "pmConcepts.h"
 
 /// Parse the FPA.FILTER concept to apply a lookup table
 psMetadataItem *p_pmConceptParse_FPA_FILTER(const psMetadataItem *concept, ///< Concept to parse
         const psMetadataItem *pattern, ///< Pattern to use in parsing
+                                            pmConceptSource source, ///< Source for concept
         const psMetadata *cameraFormat, ///< Camera format definition
         const pmFPA *fpa, ///< FPA for concept, or NULL
@@ -29,4 +31,5 @@
 /// Format the FPA.FILTER concept to (reverse-)apply a lookup table
 psMetadataItem *p_pmConceptFormat_FPA_FILTER(const psMetadataItem *concept, ///< Concept to format
+                                            pmConceptSource source, ///< Source for concept
         const psMetadata *cameraFormat, ///< Camera format definition
         const pmFPA *fpa, ///< FPA for concept, or NULL
@@ -38,4 +41,5 @@
 psMetadataItem *p_pmConceptParse_FPA_Coords(const psMetadataItem *concept, ///< Concept to parse
         const psMetadataItem *pattern, ///< Pattern to use in parsing
+                                            pmConceptSource source, ///< Source for concept
         const psMetadata *cameraFormat, ///< Camera format definition
         const pmFPA *fpa, ///< FPA for concept, or NULL
@@ -46,4 +50,5 @@
 /// Format the coordinates concepts: FPA.RA and FPA.DEC
 psMetadataItem *p_pmConceptFormat_FPA_Coords(const psMetadataItem *concept, ///< Concept to format
+                                            pmConceptSource source, ///< Source for concept
         const psMetadata *cameraFormat, ///< Camera format definition
         const pmFPA *fpa, ///< FPA for concept, or NULL
@@ -55,4 +60,5 @@
 psMetadataItem *p_pmConceptParse_CELL_TRIMSEC(const psMetadataItem *concept, ///< Concept to parse
         const psMetadataItem *pattern, ///< Pattern to use in parsing
+                                            pmConceptSource source, ///< Source for concept
         const psMetadata *cameraFormat, ///< Camera format definition
         const pmFPA *fpa, ///< FPA for concept, or NULL
@@ -64,4 +70,5 @@
 psMetadataItem *p_pmConceptParse_CELL_BIASSEC(const psMetadataItem *concept, ///< Concept to parse
         const psMetadataItem *pattern, ///< Pattern to use in parsing
+                                            pmConceptSource source, ///< Source for concept
         const psMetadata *cameraFormat, ///< Camera format definition
         const pmFPA *fpa, ///< FPA for concept, or NULL
@@ -73,4 +80,5 @@
 psMetadataItem *p_pmConceptParse_CELL_Binning(const psMetadataItem *concept, ///< Concept to parse
         const psMetadataItem *pattern, ///< Pattern to use in parsing
+                                            pmConceptSource source, ///< Source for concept
         const psMetadata *cameraFormat, ///< Camera format definition
         const pmFPA *fpa, ///< FPA for concept, or NULL
@@ -82,4 +90,5 @@
 psMetadataItem *p_pmConceptParse_TIMESYS(const psMetadataItem *concept, ///< Concept to parse
         const psMetadataItem *pattern, ///< Pattern to use in parsing
+                                            pmConceptSource source, ///< Source for concept
         const psMetadata *cameraFormat, ///< Camera format definition
         const pmFPA *fpa, ///< FPA for concept, or NULL
@@ -91,4 +100,5 @@
 psMetadataItem *p_pmConceptParse_TIME(const psMetadataItem *concept, ///< Concept to parse
                                       const psMetadataItem *pattern, ///< Pattern to use in parsing
+                                            pmConceptSource source, ///< Source for concept
                                       const psMetadata *cameraFormat, ///< Camera format definition
                                       const pmFPA *fpa, ///< FPA for concept, or NULL
@@ -100,5 +110,6 @@
 psMetadataItem *p_pmConceptParse_Positions(const psMetadataItem *concept, ///< Concept to parse
         const psMetadataItem *pattern, ///< Pattern to use in parsing
-        const psMetadata *cameraFormat, ///< Camera format definition
+                                            pmConceptSource source, ///< Source for concept
+       const psMetadata *cameraFormat, ///< Camera format definition
         const pmFPA *fpa, ///< FPA for concept, or NULL
         const pmChip *chip, ///< Chip for concept, or NULL
@@ -108,4 +119,5 @@
 /// Format the CELL.TRIMSEC concept
 psMetadataItem *p_pmConceptFormat_CELL_TRIMSEC(const psMetadataItem *concept, ///< Concept to format
+                                            pmConceptSource source, ///< Source for concept
         const psMetadata *cameraFormat, ///< Camera format definition
         const pmFPA *fpa, ///< FPA for concept, or NULL
@@ -116,4 +128,5 @@
 /// Format the CELL.BIASSEC concept
 psMetadataItem *p_pmConceptFormat_CELL_BIASSEC(const psMetadataItem *concept, ///< Concept to format
+                                            pmConceptSource source, ///< Source for concept
         const psMetadata *cameraFormat, ///< Camera format definition
         const pmFPA *fpa, ///< FPA for concept, or NULL
@@ -124,4 +137,5 @@
 /// Format the CELL.XBIN concept
 psMetadataItem *p_pmConceptFormat_CELL_XBIN(const psMetadataItem *concept, ///< Concept to format
+                                            pmConceptSource source, ///< Source for concept
         const psMetadata *cameraFormat, ///< Camera format definition
         const pmFPA *fpa, ///< FPA for concept, or NULL
@@ -132,4 +146,5 @@
 /// Format the CELL.YBIN concept
 psMetadataItem *p_pmConceptFormat_CELL_YBIN(const psMetadataItem *concept, ///< Concept to format
+                                            pmConceptSource source, ///< Source for concept
         const psMetadata *cameraFormat, ///< Camera format definition
         const pmFPA *fpa, ///< FPA for concept, or NULL
@@ -140,4 +155,5 @@
 /// Format the time system concepts: FPA.TIMESYS and CELL.TIMESYS
 psMetadataItem *p_pmConceptFormat_TIMESYS(const psMetadataItem *concept, ///< Concept to format
+                                            pmConceptSource source, ///< Source for concept
         const psMetadata *cameraFormat, ///< Camera format definition
         const pmFPA *fpa, ///< FPA for concept, or NULL
@@ -148,4 +164,5 @@
 /// Format the time concepts: FPA.TIME and CELL.TIME
 psMetadataItem *p_pmConceptFormat_TIME(const psMetadataItem *concept, ///< Concept to format
+                                            pmConceptSource source, ///< Source for concept
                                        const psMetadata *cameraFormat, ///< Camera format definition
                                        const pmFPA *fpa, ///< FPA for concept, or NULL
@@ -156,4 +173,5 @@
 /// Format a cell position concept, e.g., CELL.X0
 psMetadataItem *p_pmConceptFormat_Positions(const psMetadataItem *concept, ///< Concept to format
+                                            pmConceptSource source, ///< Source for concept
         const psMetadata *cameraFormat, ///< Camera format definition
         const pmFPA *fpa, ///< FPA for concept, or NULL
Index: trunk/psModules/src/concepts/pmConceptsUpdate.c
===================================================================
--- trunk/psModules/src/concepts/pmConceptsUpdate.c	(revision 11749)
+++ trunk/psModules/src/concepts/pmConceptsUpdate.c	(revision 11749)
@@ -0,0 +1,67 @@
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <stdio.h>
+#include <string.h>
+#include <assert.h>
+
+#include <pslib.h>
+
+#include "pmFPA.h"
+#include "pmConceptsUpdate.h"
+
+bool pmConceptsUpdate(const pmFPA *fpa, const pmChip *chip, const pmCell *cell)
+{
+    if (fpa) {
+        // Check for FPA concepts updates
+    }
+
+    if (chip) {
+        // Check for chip concepts updates
+    }
+
+    if (cell) {
+        // Check for cell concepts updates
+
+        // CELL.TRIMSEC needs to be updated for the binning
+        if (psMetadataLookup(cell->concepts, "CELL.TRIMSEC.UPDATE")) {
+            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) {
+                psRegion *trimsec = psMetadataLookupPtr(NULL, cell->concepts, "CELL.TRIMSEC"); // Trim section
+                trimsec->x0 /= xBin;
+                trimsec->x1 /= xBin;
+                trimsec->y0 /= yBin;
+                trimsec->y1 /= yBin;
+
+                psMetadataRemoveKey(cell->concepts, "CELL.TRIMSEC.UPDATE");
+            }
+        }
+
+        // CELL.BIASSEC needs to be updated for the binning
+        if (psMetadataLookup(cell->concepts, "CELL.BIASSEC.UPDATE")) {
+            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) {
+                psList *biassecs = psMetadataLookupPtr(NULL, cell->concepts, "CELL.BIASSEC"); // Bias sections
+                psListIterator *biassecsIter = psListIteratorAlloc(biassecs, PS_LIST_HEAD, true); // Iterator
+                psRegion *bias; // Bias region, from iteration
+                while ((bias = psListGetAndIncrement(biassecsIter))) {
+                    bias->x0 /= xBin;
+                    bias->x1 /= xBin;
+                    bias->y0 /= yBin;
+                    bias->y1 /= yBin;
+                }
+                psFree(biassecsIter);
+
+                psMetadataRemoveKey(cell->concepts, "CELL.BIASSEC.UPDATE");
+            }
+        }
+
+    }
+
+    return true;
+}
Index: trunk/psModules/src/concepts/pmConceptsUpdate.h
===================================================================
--- trunk/psModules/src/concepts/pmConceptsUpdate.h	(revision 11749)
+++ trunk/psModules/src/concepts/pmConceptsUpdate.h	(revision 11749)
@@ -0,0 +1,28 @@
+/* @file  pmConceptsUpdate.h
+ * @brief Function to update concepts.
+ *
+ * @author Paul Price, IfA
+ *
+ * @version $Revision: 1.1 $ $Name: not supported by cvs2svn $
+ * @date $Date: 2007-02-12 22:22:15 $
+ * Copyright 2005-2007 Institute for Astronomy, University of Hawaii
+ */
+
+#ifndef PM_CONCEPTS_UPDATE_H
+#define PM_CONCEPTS_UPDATE_H
+
+#include "pmFPA.h"
+
+
+/// Check for concepts to update.
+///
+/// Updating concepts is necessary if one concept depends on the value of another.  In that case, a flag
+/// (e.g., CONCEPTNAME.UPDATE" in the concepts) can be set, and it can be updated once the required value is
+/// known.
+bool pmConceptsUpdate(const pmFPA *fpa,       ///< FPA for which to update concepts
+                      const pmChip *chip,     ///< Chip for which to update concepts
+                      const pmCell *cell      ///< Cell for which to update concepts
+    );
+
+
+#endif
Index: trunk/psModules/src/concepts/pmConceptsWrite.c
===================================================================
--- trunk/psModules/src/concepts/pmConceptsWrite.c	(revision 11687)
+++ trunk/psModules/src/concepts/pmConceptsWrite.c	(revision 11749)
@@ -106,4 +106,5 @@
 static psMetadataItem *conceptFormat(const pmConceptSpec *spec, // The concept specification
                                      const psMetadataItem *concept, // The concept to parse
+                                     pmConceptSource source, // The concept source
                                      const psMetadata *cameraFormat, // The camera format
                                      const pmFPA *fpa, // The FPA
@@ -118,5 +119,5 @@
         psMetadataItem *formatted = NULL;  // The formatted concept
         if (spec->format) {
-            formatted = spec->format(concept, cameraFormat, fpa, chip, cell);
+            formatted = spec->format(concept, source, cameraFormat, fpa, chip, cell);
         } else if (strcmp(concept->name, spec->blank->name) != 0) {
             // Adjust so that the name is correct
@@ -251,9 +252,5 @@
             // Grab the concept
             psMetadataItem *conceptItem = psMetadataLookup(concepts, name); // The concept
-            // Formatted version
-            psMetadataItem *formatted = conceptFormat(spec, conceptItem, cameraFormat, NULL, NULL, cell);
-            if (!formatted) {
-                continue;
-            }
+
             psString nameSource = NULL; // String with the concept name and ".SOURCE" added
             psStringAppend(&nameSource, "%s.SOURCE", name);
@@ -268,7 +265,23 @@
                         continue;
                     }
+
+                    // Formatted version
+                    psMetadataItem *formatted = conceptFormat(spec, conceptItem, PM_CONCEPT_SOURCE_HEADER,
+                                                              cameraFormat, NULL, NULL, cell);
+                    if (!formatted) {
+                        continue;
+                    }
+
                     psTrace("psModules.concepts", 8, "Writing %s to header %s\n", name, cameraItem->data.str);
                     writeHeader(hdu, cameraItem->data.V, formatted);
+                    psFree(formatted);
                 } else if (strcasecmp(source, "VALUE") == 0) {
+                    // Formatted version
+                    psMetadataItem *formatted = conceptFormat(spec, conceptItem, PM_CONCEPT_SOURCE_CELLS,
+                                                              cameraFormat, NULL, NULL, cell);
+                    if (!formatted) {
+                        continue;
+                    }
+
                     psTrace("psModules.concepts", 8, "Checking %s against camera format.\n", name);
                     if (! compareConcepts(formatted, cameraItem)) {
@@ -276,14 +289,23 @@
                                  "format, but the values don't match.\n", name);
                     }
+                    psFree(formatted);
                 } else {
                     psLogMsg(__func__, PS_LOG_WARN, "Concept source %s isn't HEADER or VALUE --- can't "
                              "write\n", nameSource);
                 }
-            } else if (! compareConcepts(formatted, cameraItem)) {
+            } else {
                 // Assume it's specified by value
-                psLogMsg(__func__, PS_LOG_WARN, "Concept %s is specified by value in the camera "
-                         "format, but the values don't match.\n", name);
-            }
-            psFree(formatted);
+                psMetadataItem *formatted = conceptFormat(spec, conceptItem, PM_CONCEPT_SOURCE_CELLS,
+                                                          cameraFormat, NULL, NULL, cell);
+                if (!formatted) {
+                    continue;
+                }
+
+                if (! compareConcepts(formatted, cameraItem)) {
+                    psLogMsg(__func__, PS_LOG_WARN, "Concept %s is specified by value in the camera "
+                             "format, but the values don't match.\n", name);
+                }
+                psFree(formatted);
+            }
             psFree(nameSource);
         }
@@ -346,5 +368,6 @@
             }
             conceptItem = psMetadataLookup(concepts, name); // The item from the concepts
-            psMetadataItem *formatted = conceptFormat(spec, conceptItem, cameraFormat, fpa, chip, cell);
+            psMetadataItem *formatted = conceptFormat(spec, conceptItem, PM_CONCEPT_SOURCE_DEFAULTS,
+                                                      cameraFormat, fpa, chip, cell);
             if (!formatted) {
                 continue;
@@ -394,5 +417,6 @@
             psTrace("psModules.concepts", 3, "Writing %s to header %s\n", name, headerItem->data.str);
             psMetadataItem *conceptItem = psMetadataLookup(concepts, name); // The item from the concepts
-            psMetadataItem *formatted = conceptFormat(spec, conceptItem, cameraFormat, fpa, chip, cell);
+            psMetadataItem *formatted = conceptFormat(spec, conceptItem, PM_CONCEPT_SOURCE_HEADER,
+                                                      cameraFormat, fpa, chip, cell);
             if (!formatted) {
                 continue;
@@ -446,5 +470,6 @@
 
             psMetadataItem *conceptItem = psMetadataLookup(concepts, name); // The item from the concepts
-            psMetadataItem *formatted = conceptFormat(spec, conceptItem, cameraFormat, fpa, chip, cell);
+            psMetadataItem *formatted = conceptFormat(spec, conceptItem, PM_CONCEPT_SOURCE_DATABASE,
+                                                      cameraFormat, fpa, chip, cell);
             if (!formatted) {
                 continue;
