Index: trunk/psModules/src/camera/pmFPAfileIO.c
===================================================================
--- trunk/psModules/src/camera/pmFPAfileIO.c	(revision 17010)
+++ trunk/psModules/src/camera/pmFPAfileIO.c	(revision 17025)
@@ -761,17 +761,36 @@
         file->fits->options = psMemIncrRefCounter(file->options);
 
-        // if needed, set the optional EXTWORD field based on the camera value
-        if (file->format) {
-            psMetadata *fileMenu = psMetadataLookupMetadata (NULL, file->format, "FILE");
-            if (!fileMenu) {
-                psError (PS_ERR_IO, true, "FILE METADATA missing from camera format %s\n",
-                         config->formatName);
-                return false;
-            }
-            char *extword = psMetadataLookupStr (&status, fileMenu, "EXTWORD");
-            if (status) {
-                psFitsSetExtnameWord (file->fits, extword);
-            }
-        }
+	// in most cases, we have already open and read the phu and determined the format.
+	// in some cases, (eg DetDB images), we have only just determined the filename.
+	// we need to check the file format before we can work with the file
+	if (!file->format) {
+	  psMetadata *phu = psFitsReadHeader (NULL, file->fits);
+	  if (!phu) {
+	    psError(PS_ERR_IO, false, "Failed to read file header %s\n", file->filename);
+	    return false;
+	  }
+
+	  // determine the current format from the header
+	  // determine camera if not specified already
+	  file->format = pmConfigCameraFormatFromHeader (config, phu, true);
+	  if (!file->format) {
+	    psError(PS_ERR_IO, false, "Failed to read CCD format from %s\n", file->filename);
+	    psFree(phu);
+	    return false;
+	  }
+	  psFree(phu);
+	}
+
+	// if needed, set the optional EXTWORD field based on the camera value
+	psMetadata *fileMenu = psMetadataLookupMetadata (NULL, file->format, "FILE");
+	if (!fileMenu) {
+	  psError (PS_ERR_IO, true, "FILE METADATA missing from camera format %s\n",
+		   config->formatName);
+	  return false;
+	}
+	char *extword = psMetadataLookupStr (&status, fileMenu, "EXTWORD");
+	if (status) {
+	  psFitsSetExtnameWord (file->fits, extword);
+	}
 
         // XXX these are probably only needed for WRITE files
