Index: trunk/psModules/src/concepts/pmConceptsWrite.c
===================================================================
--- trunk/psModules/src/concepts/pmConceptsWrite.c	(revision 11257)
+++ 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;
