Index: /trunk/psModules/src/concepts/pmConcepts.c
===================================================================
--- /trunk/psModules/src/concepts/pmConcepts.c	(revision 10966)
+++ /trunk/psModules/src/concepts/pmConcepts.c	(revision 10967)
@@ -37,4 +37,51 @@
     return spec;
 }
+
+psList *pmConceptsList(pmFPALevel level)
+{
+    if (!conceptsInitialised) {
+        pmConceptsInit();
+    }
+
+    // Get the appropriate concepts
+    psMetadata *concepts = NULL;        // Metadata of concepts specs
+    switch (level) {
+    case PM_FPA_LEVEL_FPA:
+        concepts = conceptsFPA;
+        break;
+    case PM_FPA_LEVEL_CHIP:
+        concepts = conceptsChip;
+        break;
+    case PM_FPA_LEVEL_CELL:
+        concepts = conceptsCell;
+        break;
+    default:
+        psError(PS_ERR_IO, true, "Invalid concept level provided: %d\n", level);
+        return NULL;
+    }
+
+    // Pull out the names
+    psList *list = psListAlloc(NULL);   // List of concepts' names
+    psMetadataIterator *iter = psMetadataIteratorAlloc(concepts, PS_LIST_HEAD, NULL); // Iterator
+    psMetadataItem *item;               // Item from iteration
+    while ((item = psMetadataGetAndIncrement(iter))) {
+        psListAdd(list, PS_LIST_TAIL, item->name);
+    }
+    psFree(iter);
+    return list;
+}
+
+
+psList *psMetadataKeys(psMetadata *md)
+{
+    psList *list = psListAlloc(NULL);   // List with the keys
+    psMetadataIterator *iter = psMetadataIteratorAlloc(md, PS_LIST_HEAD, false);
+    psMetadataItem *item;               // Item from iteration
+    while ((item = psMetadataGetAndIncrement(iter))) {
+        psListAdd(list, PS_LIST_TAIL, item->name);
+    }
+    return list;
+}
+
 
 
@@ -246,5 +293,5 @@
         for (long i = 0; i < chips->n; i++) {
             pmChip *chip = chips->data[i]; // Chip of interest
-            if (chip && !chip->hdu) {
+            if (chip) {
                 success |= pmConceptsReadChip(chip, source, false, true, db);
             }
@@ -287,5 +334,5 @@
     bool success = conceptsRead(&conceptsChip, fpa, chip, NULL, &chip->conceptsRead, source, db,
                                 chip->concepts);
-    if (propagateUp && !fpa->hdu) {
+    if (propagateUp) {
         success |= conceptsRead(&conceptsFPA, fpa, chip, NULL, &fpa->conceptsRead, source, db, fpa->concepts);
     }
@@ -294,5 +341,5 @@
         for (long i = 0; i < cells->n; i++) {
             pmCell *cell = cells->data[i];  // Cell of interest
-            if (cell && !cell->hdu) {
+            if (cell) {
                 success |= pmConceptsReadCell(cell, source, false, db);
             }
@@ -341,12 +388,8 @@
                                 cell->concepts);
     if (propagateUp) {
-        if (!chip->hdu) {
-            success |= conceptsRead(&conceptsChip, fpa, chip, cell, &chip->conceptsRead, source, db,
-                                    chip->concepts);
-            if (!fpa->hdu) {
-                success |= conceptsRead(&conceptsFPA, fpa, chip, cell, &fpa->conceptsRead, source, db,
-                                        fpa->concepts);
-            }
-        }
+        success |= conceptsRead(&conceptsChip, fpa, chip, cell, &chip->conceptsRead, source, db,
+                                chip->concepts);
+        success |= conceptsRead(&conceptsFPA, fpa, chip, cell, &fpa->conceptsRead, source, db,
+                                fpa->concepts);
     }
 
Index: /trunk/psModules/src/concepts/pmConcepts.h
===================================================================
--- /trunk/psModules/src/concepts/pmConcepts.h	(revision 10966)
+++ /trunk/psModules/src/concepts/pmConcepts.h	(revision 10967)
@@ -7,6 +7,6 @@
 /// @author Paul Price, IfA
 ///
-/// @version $Revision: 1.9 $ $Name: not supported by cvs2svn $
-/// @date $Date: 2006-10-21 00:55:44 $
+/// @version $Revision: 1.10 $ $Name: not supported by cvs2svn $
+/// @date $Date: 2007-01-08 22:31:41 $
 ///
 /// Copyright 2005-2006 Institute for Astronomy, University of Hawaii
@@ -82,4 +82,7 @@
     PM_CONCEPT_SOURCE_ALL      = 0xff   ///< All concepts
 } pmConceptSource;
+
+/// Get a list of defined concepts for a particular level.
+psList *pmConceptsList(pmFPALevel level);
 
 /// Read the concepts for the given set of fpa, chip, cell
Index: /trunk/psModules/src/concepts/pmConceptsWrite.c
===================================================================
--- /trunk/psModules/src/concepts/pmConceptsWrite.c	(revision 10966)
+++ /trunk/psModules/src/concepts/pmConceptsWrite.c	(revision 10967)
@@ -119,5 +119,11 @@
         if (spec->format) {
             formatted = spec->format(concept, cameraFormat, fpa, chip, cell);
+        } else if (strcmp(concept->name, spec->blank->name) != 0) {
+            // Adjust so that the name is correct
+            formatted = psMetadataItemCopy(concept);
+            psFree(formatted->name);
+            formatted->name = psStringCopy(spec->blank->name);
         } else {
+            // Can get away with merely incrementing the reference counter
             formatted = psMemIncrRefCounter((const psPtr)concept);
         }
@@ -294,5 +300,5 @@
     PS_ASSERT_PTR_NON_NULL(concepts, false);
 
-    pmHDU *hdu = pmHDUGetLowest(NULL, NULL, cell); // The HDU at the lowest level
+    pmHDU *hdu = pmHDUGetLowest(fpa, chip, cell); // The HDU at the lowest level
     if (!hdu) {
         return false;
@@ -316,22 +322,28 @@
                 // It's a menu --- need to look up the .DEPEND
                 psString dependName = NULL; // The concept name with ".DEPEND" on the end
-                psStringAppend(&dependName, ".DEPEND");
+                psStringAppend(&dependName, "%s.DEPEND", defaultItem->name);
                 psString dependKey = psMetadataLookupStr(&mdok, defaults, dependName); // The keyword
-                psFree(dependName);
                 if (!mdok || !dependKey || strlen(dependKey) == 0) {
                     psLogMsg(__func__, PS_LOG_WARN, "Can't find %s in the DEFAULTS for %s --- ignored.\n",
                              dependName, name);
+                    psFree(dependName);
                     continue;
                 }
-                psString dependValue = psMetadataLookupStr(&mdok, concepts, dependName); // The value
-                if (!mdok || !dependKey || strlen(dependKey) == 0) {
+                psString dependValue = psMetadataLookupStr(&mdok, concepts, dependKey); // The value
+                if (!mdok || !dependValue || strlen(dependValue) == 0) {
                     psLogMsg(__func__, PS_LOG_WARN, "Concept %s specified by %s isn't of type STR -- "
-                             "ignored.\n", name, dependName);
+                             "ignored.\n", dependKey, dependName);
+                    psFree(dependName);
                     continue;
                 }
-                conceptItem = psMetadataLookup(defaultItem->data.V, dependValue);
+                psFree(dependName);
+                // Get the actual item of interest, and correct the name to match the concept name
+                defaultItem = psMetadataItemCopy(psMetadataLookup(defaultItem->data.md, dependValue));
+                psFree(defaultItem->name);
+                defaultItem->name = psStringCopy(name);
             } else {
-                conceptItem = psMetadataLookup(concepts, name); // The item from the concepts
-            }
+                psMemIncrRefCounter(defaultItem);
+            }
+            conceptItem = psMetadataLookup(concepts, name); // The item from the concepts
             psMetadataItem *formatted = conceptFormat(spec, conceptItem, cameraFormat, fpa, chip, cell);
             if (!formatted) {
@@ -342,4 +354,5 @@
                          "format, but the values don't match.\n", name);
             }
+            psFree(defaultItem);
             psFree(formatted);
         }
@@ -356,5 +369,5 @@
     PS_ASSERT_PTR_NON_NULL(concepts, false);
 
-    pmHDU *hdu = pmHDUGetLowest(NULL, NULL, cell); // The HDU at the lowest level
+    pmHDU *hdu = pmHDUGetLowest(fpa, chip, cell); // The HDU at the lowest level
     if (!hdu) {
         return false;
@@ -408,5 +421,5 @@
     #else
 
-    pmHDU *hdu = pmHDUGetLowest(NULL, NULL, cell); // The HDU at the lowest level
+    pmHDU *hdu = pmHDUGetLowest(fpa, chip, cell); // The HDU at the lowest level
     if (!hdu) {
         return false;
