Index: trunk/psModules/src/camera/pmFPAfileDefine.c
===================================================================
--- trunk/psModules/src/camera/pmFPAfileDefine.c	(revision 17437)
+++ trunk/psModules/src/camera/pmFPAfileDefine.c	(revision 17489)
@@ -172,6 +172,6 @@
     }
 
-    psMetadata *data = pmConfigFileRule(config, camera, name); // File rule
-    if (!data) {
+    psMetadata *filerule = pmConfigFileRule(config, camera, name); // File rule
+    if (!filerule) {
         psError(PS_ERR_IO, true, "Can't find file rule %s!", name);
         return NULL;
@@ -183,7 +183,8 @@
     file->name = psStringCopy(name);
 
-    file->filerule = psMemIncrRefCounter(psMetadataLookupStr(&status, data, "FILENAME.RULE"));
-
-    const char *type = psMetadataLookupStr(&status, data, "FILE.TYPE");
+    // this is the filename rule
+    file->filerule = psMemIncrRefCounter(psMetadataLookupStr(&status, filerule, "FILENAME.RULE"));
+
+    const char *type = psMetadataLookupStr(&status, filerule, "FILE.TYPE");
     file->type = pmFPAfileTypeFromString(type);
     if (file->type == PM_FPA_FILE_NONE) {
@@ -214,5 +215,5 @@
     if (!formatName || strlen(formatName) == 0) {
         // select the format list from the selected camera
-        formatName = psMetadataLookupStr(&status, data, "FILE.FORMAT");
+        formatName = psMetadataLookupStr(&status, filerule, "FILE.FORMAT");
         if (!formatName || strcmp(formatName, "NONE") == 0) {
             // Try to get by with the default
@@ -238,13 +239,11 @@
 
     // Get FITS output scheme
-    const char *fitsType = psMetadataLookupStr(&status, data, "FITS.TYPE"); // Name of FITS scheme to use
+    const char *fitsType = psMetadataLookupStr(&status, filerule, "FITS.TYPE"); // Name of FITS scheme to use
     if (fitsType && strcasecmp(fitsType, "NONE") != 0) {
-        psMetadata *fitsTypes = psMetadataLookupMetadata(&status, camera, "FITS"); // The FITS schemes
-        if (!fitsTypes) {
-            psWarning("Unable to find FITS in camera configuration.");
-            goto FITS_OPTIONS_DONE;
-        }
-        psMetadata *scheme = psMetadataLookupMetadata(NULL, fitsTypes, fitsType); // FITS scheme
+
+	// load the FITSTYPE scheme for this file
+	psMetadata *scheme = pmConfigFitsType(config, camera, fitsType); // File rule
         if (!scheme) {
+	    // XXX change to a config error?
             psWarning("Unable to find %s in FITS in camera configuration --- will use defaults.", fitsType);
             goto FITS_OPTIONS_DONE;
@@ -337,5 +336,5 @@
     }
 
-    file->dataLevel = pmFPALevelFromName(psMetadataLookupStr(&status, data, "DATA.LEVEL"));
+    file->dataLevel = pmFPALevelFromName(psMetadataLookupStr(&status, filerule, "DATA.LEVEL"));
     if (file->dataLevel == PM_FPA_LEVEL_NONE) {
         psError(PS_ERR_IO, true, "DATA.LEVEL is not set for %s\n", name);
Index: trunk/psModules/src/config/pmConfig.c
===================================================================
--- trunk/psModules/src/config/pmConfig.c	(revision 17437)
+++ trunk/psModules/src/config/pmConfig.c	(revision 17489)
@@ -1513,2 +1513,33 @@
 }
 
+psMetadata *pmConfigFitsType (const pmConfig *config, const psMetadata *camera, const char *fitsType)
+{
+    bool mdok;
+
+    PS_ASSERT_PTR_NON_NULL(config, NULL);
+    PS_ASSERT_METADATA_NON_NULL(camera, NULL);
+    PS_ASSERT_STRING_NON_EMPTY(fitsType, NULL);
+
+    psMetadataItem *item = psMetadataLookup(camera, "FITSTYPES"); // Item with the file rule of interest
+    if (!item) {
+        psError(PS_ERR_UNEXPECTED_NULL, false, "Unable to find FITSTYPES in the camera configuration.");
+        return NULL;
+    }
+
+    if (!metadataItemReadFile(item, "FITS Types")) {
+        psError(PM_ERR_CONFIG, false, "Unable to read file rules for camera.");
+        return NULL;
+    }
+
+    assert(item->type == PS_DATA_METADATA);
+    psMetadata *fitstypes = item->data.md; // FITS Types from the camera configuration
+
+    // select the name from the FITSTYPES
+    psMetadata *scheme = psMetadataLookupMetadata(&mdok, fitstypes, fitsType);
+    if (!scheme) {
+	psWarning("Unable to find specified FITS Type %s in camera configuration.", fitsType);
+	return NULL;
+    }
+
+    return scheme;
+}
Index: trunk/psModules/src/config/pmConfig.h
===================================================================
--- trunk/psModules/src/config/pmConfig.h	(revision 17437)
+++ trunk/psModules/src/config/pmConfig.h	(revision 17489)
@@ -5,6 +5,6 @@
  *  @author Eugene Magnier, IfA
  *
- *  @version $Revision: 1.33 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2008-02-22 20:20:38 $
+ *  @version $Revision: 1.34 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2008-04-28 21:13:46 $
  *  Copyright 2005-2006 Institute for Astronomy, University of Hawaii
  */
@@ -176,4 +176,7 @@
     );
 
+// look up the specified fitstype, interpolating the file if needed
+psMetadata *pmConfigFitsType (const pmConfig *config, const psMetadata *camera, const char *fitsType);
+
 /// @}
 #endif
