Index: trunk/ppImage/src/ppImageDetrendRecord.c
===================================================================
--- trunk/ppImage/src/ppImageDetrendRecord.c	(revision 20444)
+++ trunk/ppImage/src/ppImageDetrendRecord.c	(revision 20454)
@@ -32,6 +32,26 @@
     pmCell *input = pmFPAfileThisCell(config->files, view, "PPIMAGE.INPUT"); // File we're processing
     psAssert(input, "Should be there");
-    pmHDU *hdu = pmHDUFromCell(input);  // HDU for cell
-    psMetadataAddStr(hdu->header, PS_LIST_TAIL, name, PS_META_DUPLICATE_OK, desc, basename(file->filename));
+    pmHDU *hdu = pmHDUGetHighest(input->parent->parent, input->parent, input);  // HDU for cell
+
+    const char *base = basename(file->filename); // Base name of file
+
+    // We don't want multiple listings in the header saying the same thing, so make sure we haven't put the
+    // same entry there.  Usually (if the detrend and the image have the same file level) there'll only end up
+    // being one entry.
+    psString regexp = NULL;             // Regular expression
+    psStringAppend(&regexp, "^%s$", name);
+    psMetadataIterator *iter = psMetadataIteratorAlloc(hdu->header, PS_LIST_HEAD, regexp); // Iterator for hdr
+    psFree(regexp);
+    psMetadataItem *item;               // Item from iteration
+    bool found = false;
+    while (!found && (item = psMetadataGetAndIncrement(iter))) {
+        if (item->type == PS_DATA_STRING && strcmp(item->data.str, base) == 0) {
+            found = true;
+        }
+    }
+    psFree(iter);
+    if (!found) {
+        psMetadataAddStr(hdu->header, PS_LIST_TAIL, name, PS_META_DUPLICATE_OK, desc, base);
+    }
 
     return;
