Index: trunk/archive/scripts/src/pmCameraFromHeader.c
===================================================================
--- trunk/archive/scripts/src/pmCameraFromHeader.c	(revision 4309)
+++ trunk/archive/scripts/src/pmCameraFromHeader.c	(revision 4395)
@@ -5,7 +5,7 @@
 
 // Work out what camera we have, based on the FITS header and a set of rules specified in the IPP
-// configuration
-char *pmCameraFromHeader(const psMetadata *header, // The FITS header
-			 const psMetadata *ipprc // The IPP configuration
+// configuration; return the camera configuration
+psMetadata *pmCameraFromHeader(const psMetadata *header, // The FITS header
+			       const psMetadata *ipprc // The IPP configuration
     )
 {
@@ -17,5 +17,6 @@
     }
 
-    char *winner = NULL;		// The instrument whose rule first matches the supplied header
+    psMetadata *winner = NULL;		// The instrument configuration whose rule first matches the supplied
+					// header
 
     // Iterate over the instruments
@@ -31,5 +32,10 @@
 	} else if (instrumentItem->type == PS_META_STR) {
 	    psTrace(__func__, 5, "Reading instrument configuration for %s...\n", instrumentItem->name);
-	    instrument = psMetadataConfigParse(NULL, NULL, instrumentItem->data.V, true);
+	    int badLines = 0;		// Number of bad lines in reading instrument configuration
+	    instrument = psMetadataConfigParse(NULL, &badLines, instrumentItem->data.V, true);
+	    if (badLines > 0) {
+		psLogMsg(__func__, PS_LOG_WARN, "%d bad lines encountered while reading camera"
+			 "configuration %s\n", badLines, instrumentItem->name);
+	    }
 	}
 
@@ -58,7 +64,13 @@
 			switch (ruleItem->type) {
 			  case PS_META_STR:
-			    match = (strcmp(ruleItem->data.V, headerItem->data.V) == 0) ? true : false;
+			    psTrace(__func__, 8, "Matching %s: '%s' vs '%s'\n", ruleItem->name,
+				    ruleItem->data.V, headerItem->data.V);
+			    match = (strncmp(ruleItem->data.V, headerItem->data.V,
+					     strlen(ruleItem->data.V)) == 0) ? true : false;
 			    break;
 			  case PS_TYPE_S32:
+			  case PS_TYPE_BOOL:
+			    psTrace(__func__, 8, "Matching %s: %d vs %d\n", ruleItem->name,
+				    ruleItem->data.S32, headerItem->data.S32);
 			    if (ruleItem->data.S32 != headerItem->data.S32) {
 				match = false;
@@ -66,4 +78,6 @@
 			    break;
 			  case PS_TYPE_F32:
+			    psTrace(__func__, 8, "Matching %s: %f vs %f\n", ruleItem->name,
+				    ruleItem->data.F32, headerItem->data.F32);
 			    if (ruleItem->data.F32 != headerItem->data.F32) {
 				match = false;
@@ -71,4 +85,6 @@
 			    break;
 			  case PS_TYPE_F64:
+			    psTrace(__func__, 8, "Matching %s: %g vs %g\n", ruleItem->name,
+				    ruleItem->data.F64, headerItem->data.F64);
 			    if (ruleItem->data.F64 != headerItem->data.F64) {
 				match = false;
@@ -85,5 +101,7 @@
 		    if (! winner) {
 			// This is the first match
-			winner = instrumentItem->name;
+			winner = instrument;
+			psLogMsg(__func__, PS_LOG_INFO, "FITS header matches instrument %s\n",
+				 instrumentItem->name);
 		    } else {
 			// We have a duplicate match
@@ -100,4 +118,8 @@
     psFree(iterator);
 
+    if (! winner) {
+	psError(PS_ERR_IO, true, "Unable to find an instrument that matches input FITS header!\n");
+    }
+
     return winner;
 }
