Index: trunk/psModules/src/camera/pmFPAfileIO.c
===================================================================
--- trunk/psModules/src/camera/pmFPAfileIO.c	(revision 11801)
+++ trunk/psModules/src/camera/pmFPAfileIO.c	(revision 12300)
@@ -225,23 +225,41 @@
     // get name from detrend database
     // extrule expands to yield the class_id
-    // filextra contains the desired -det_id detID -iteration iter string
+    // file->detrend->detID contains the desired -det_id detID -iteration iter string
     if (!strcasecmp (file->filename, "@DETDB")) {
-        char *extra = pmFPAfileNameFromRule (file->extrule, file, view);
-        if (extra == NULL) {
-            psError(PS_ERR_IO, false, "error converting extrule to name %s\n", file->extrule);
-            return false;
-        }
-        psTrace ("pmFPAfile", 6, "looking for detrend (%s, %s)\n", file->filextra, extra);
-
+        if (!file->detrend) {
+            psError(PS_ERR_UNEXPECTED_NULL, true, "Unable to find information about selected detrend.");
+            return false;
+        }
+
+        psString classId = NULL;        // The class identifier, to pass to pmDetrendFile
+        psMetadata *menu = psMetadataLookupMetadata(&status, file->camera, "CLASSID"); // Menu of class IDs
+        if (!status || !menu) {
+            psWarning("Unable to find CLASSID metadata in camera configuration --- "
+                      "assuming no class identifier required.");
+        } else {
+            const char *rule = psMetadataLookupStr(&status, menu, file->detrend->level); // Rule for class_id
+            if (!status || !rule || strlen(rule) == 0) {
+                psWarning("Unable to find %s in CLASSID within camera configuration --- "
+                          "attempting to proceed without it.", file->detrend->level);
+            } else {
+                classId = pmFPAfileNameFromRule(rule, file, view);
+                if (!classId) {
+                    psError(PS_ERR_IO, false, "error converting extrule to name: %s\n", rule);
+                    return false;
+                }
+            }
+        }
+        psTrace ("pmFPAfile", 6, "looking for detrend (%s, %s)\n", file->detrend->detID, classId);
         psFree (file->filename);
-        file->filename = pmDetrendFile(file->filextra, extra, config);
+
+        file->filename = pmDetrendFile(file->detrend->detID, classId, config);
         if (file->filename == NULL) {
-            psError(PS_ERR_IO, false, "failed to find a valid detrend image for detID %s : classID %s\n", file->filextra, extra);
-            psFree (extra);
+            psError(PS_ERR_IO, false, "failed to find a valid detrend image for detID %s : classID %s\n", file->detrend->detID, classId);
+            psFree (classId);
             return false;
         }
 
         psTrace ("pmFPAfile", 6, "got detrend file %s\n", file->filename);
-        psFree (extra);
+        psFree (classId);
     }
 
