Index: /trunk/psModules/src/config/pmConfig.c
===================================================================
--- /trunk/psModules/src/config/pmConfig.c	(revision 18035)
+++ /trunk/psModules/src/config/pmConfig.c	(revision 18036)
@@ -78,14 +78,20 @@
 }
 
-int checkEndForWord (const char *line, const char *word) {
-
-    int wlen = strlen (word);
-    int nlen = strlen (line);
-
-    if (nlen < wlen) return 0;
-
-    char *ptr = (char *) line + nlen - wlen;
-
-    if (strcasecmp (ptr, word)) return 0;
+// Check the end of a string for a word; return the length of the string without the ending word
+// Used to identify the camera base name (e.g., "MEGACAM" out of "_MEGACAM-CHIP")
+int checkEndForWord(const char *line,   // String to check for ending word
+                    const char *word    // Ending word to check for
+                    )
+{
+    int wlen = strlen(word);            // Length of word
+    int nlen = strlen(line);            // Length of line
+    if (nlen < wlen) {
+        return 0;
+    }
+
+    char *ptr = (char *)line + nlen - wlen; // Expected position of ending word
+    if (strcasecmp(ptr, word)) {
+        return 0;
+    }
 
     return (nlen - wlen);
@@ -93,24 +99,28 @@
 
 // the camera name is of the form: BASE, BASE_CHIP, or BASE_FPA.  pull out BASE:
-char *cameraBaseName (const char *name) {
-
-    int N;
+char *cameraBaseName(const char *name   // Name of meta-camera
+                     )
+{
     char *answer;
 
-    N = checkEndForWord (name, "-CHIP");
+    int N = checkEndForWord (name, "-CHIP");
     if (N && name[0] == '_') {
-	answer = psStringNCopy (name + 1, N - 1); 
-	psStringPrepend (&answer, "_");
-	return answer;
-    }
-    
-    N = checkEndForWord (name, "-FPA");
+        psString answer = psStringNCopy(name + 1, N - 1);
+        return answer;
+    }
+
+    N = checkEndForWord(name, "-FPA");
     if (N && name[0] == '_') {
-	answer = psStringNCopy (name + 1, N - 1); 
-	psStringPrepend (&answer, "_");
-	return answer;
-    }
-    
-    answer = psStringCopy (name); 
+        psString answer = psStringNCopy(name + 1, N - 1);
+        return answer;
+    }
+
+    N = checkEndForWord(name, "-SKYCELL");
+    if (N && name[0] == '_') {
+        psString answer = psStringNCopy(name + 1, N - 1);
+        return answer;
+    }
+
+    answer = psStringCopy(name);
     return answer;
 }
@@ -1014,5 +1024,5 @@
 // if so, return the winning format and the name of the winning format (both allocated here)
 static bool formatFromHeader(bool *status,
-			     psMetadata **format, // Format to return
+                             psMetadata **format, // Format to return
                              psString *name, // Name to return
                              psMetadata *camera, // Camera configuration
@@ -1027,5 +1037,5 @@
     assert(*cameraName);
 
-    *status = true; 			// error status
+    *status = true;                     // error status
     bool result = false;                // Did we find the first match?
 
@@ -1035,5 +1045,5 @@
     if (!mdok || !formats) {
         psError(PS_ERR_UNKNOWN, false, "Unable to find list of FORMATS in camera %s", cameraName);
-	*status = false;
+        *status = false;
         return false;
     }
@@ -1041,5 +1051,5 @@
     if (!metadataReadFiles(formats, "camera format")) {
         psError(PS_ERR_UNKNOWN, false, "Unable to read cameras formats within camera configuration.\n");
-	*status = false;
+        *status = false;
         return false;
     }
@@ -1058,5 +1068,5 @@
             psError (PS_ERR_UNKNOWN, false, "Error in config scripts for camera %s, format %s\n",
                      cameraName, formatsItem->name);
-	    *status = false;
+            *status = false;
             return false;
         }
@@ -1088,5 +1098,5 @@
     PS_ASSERT_PTR_NON_NULL(header, NULL);
 
-    bool status = false;		// error status
+    bool status = false;                // error status
     psMetadata *format = NULL;          // The winning format
     psString name = NULL;               // Name of the winning format
@@ -1094,7 +1104,7 @@
     // If we don't know what sort of camera we have, we try all that we know
     if (! config->camera) {
-	psAssert (!config->cameraName, "programming error: cameraName should be NULL if camera is undefined");
-	psAssert (!config->format,     "programming error: format should be NULL if camera is undefined");
-	psAssert (!config->formatName, "programming error: formatName should be NULL if camera is undefined");
+        psAssert (!config->cameraName, "programming error: cameraName should be NULL if camera is undefined");
+        psAssert (!config->format,     "programming error: format should be NULL if camera is undefined");
+        psAssert (!config->formatName, "programming error: formatName should be NULL if camera is undefined");
 
         bool mdok;                      // Metadata lookup status
@@ -1120,24 +1130,24 @@
             psMetadata *testCamera = camerasItem->data.md; // Camera to test against what we've got:
             if (formatFromHeader(&status, &format, &name, testCamera, header, camerasItem->name)) {
-		config->camera = psMemIncrRefCounter(testCamera);
-		config->cameraName = psStringCopy(camerasItem->name);
-		config->formatName = name;
-		config->format = format;
-		if (camera) {
-		    *camera = psMemIncrRefCounter(testCamera);	// view on value saved on config
-		} 
-		if (formatName) {
-		    *formatName = psMemIncrRefCounter(name);	// view on value saved on config
-		}
-	    } else {
-		if (!status) {
+                config->camera = psMemIncrRefCounter(testCamera);
+                config->cameraName = psStringCopy(camerasItem->name);
+                config->formatName = name;
+                config->format = format;
+                if (camera) {
+                    *camera = psMemIncrRefCounter(testCamera);  // view on value saved on config
+                }
+                if (formatName) {
+                    *formatName = psMemIncrRefCounter(name);    // view on value saved on config
+                }
+            } else {
+                if (!status) {
                     psError(PS_ERR_IO, false, "Error reading camera config data for %s", camerasItem->name);
                     return NULL;
                 }
             }
-        } 
+        }
         psFree(camerasIter);
 
-	// Done looking at all cameras
+        // Done looking at all cameras
         if (!config->camera) {
             psError(PS_ERR_IO, false, "Unable to find a camera that matches input FITS header!");
@@ -1174,37 +1184,50 @@
     // try the FPA metaCamera
     if (!found) {
-	testName = NULL;
-	psStringAppend (&testName, "_%s-FPA", baseName);
-
-	testCamera = psMetadataLookupMetadata (NULL, cameras, testName);
-	psAssert (testCamera, "missing %s in CAMERAS in complete metadata", testName);
-    
-	bool status;
-	found = formatFromHeader(&status, &format, &name, testCamera, header, testName);
-	if (!found) psFree (testName);
+        testName = NULL;
+        psStringAppend (&testName, "_%s-FPA", baseName);
+
+        testCamera = psMetadataLookupMetadata (NULL, cameras, testName);
+        psAssert (testCamera, "missing %s in CAMERAS in complete metadata", testName);
+
+        bool status;
+        found = formatFromHeader(&status, &format, &name, testCamera, header, testName);
+        if (!found) psFree (testName);
     }
 
     // try the CHIP metaCamera
     if (!found) {
-	testName = NULL;
-	psStringAppend (&testName, "_%s-CHIP", baseName);
-
-	testCamera = psMetadataLookupMetadata (NULL, cameras, testName);
-	psAssert (testCamera, "missing %s in CAMERAS in complete metadata", testName);
-    
-	bool status;
-	found = formatFromHeader(&status, &format, &name, testCamera, header, testName);
-	if (!found) psFree (testName);
+        testName = NULL;
+        psStringAppend (&testName, "_%s-CHIP", baseName);
+
+        testCamera = psMetadataLookupMetadata (NULL, cameras, testName);
+        psAssert (testCamera, "missing %s in CAMERAS in complete metadata", testName);
+
+        bool status;
+        found = formatFromHeader(&status, &format, &name, testCamera, header, testName);
+        if (!found) psFree (testName);
+    }
+
+    // try the SKYCELL metaCamera
+    if (!found) {
+        testName = NULL;
+        psStringAppend (&testName, "_%s-SKYCELL", baseName);
+
+        testCamera = psMetadataLookupMetadata (NULL, cameras, testName);
+        psAssert (testCamera, "missing %s in CAMERAS in complete metadata", testName);
+
+        bool status;
+        found = formatFromHeader(&status, &format, &name, testCamera, header, testName);
+        if (!found) psFree (testName);
     }
 
     // try the base name
     if (!found) {
-	testName = psMemIncrRefCounter (baseName);
-
-	testCamera = psMetadataLookupMetadata (NULL, cameras, testName);
-	psAssert (testCamera, "missing %s in CAMERAS in complete metadata", testName);
-    
-	bool status;
-	found = formatFromHeader(&status, &format, &name, testCamera, header, testName);
+        testName = psMemIncrRefCounter (baseName);
+
+        testCamera = psMetadataLookupMetadata (NULL, cameras, testName);
+        psAssert (testCamera, "missing %s in CAMERAS in complete metadata", testName);
+
+        bool status;
+        found = formatFromHeader(&status, &format, &name, testCamera, header, testName);
     }
 
@@ -1212,19 +1235,19 @@
         psError(PS_ERR_IO, true, "Unable to find a format with the specified camera (%s) that matches the "
                 "given header.\n", baseName);
-	psFree (baseName);
+        psFree (baseName);
         return NULL;
     }
-    
+
     psFree (name); // winning format name (for metaCamera) returned by formatFromHeader
 
     psFree (baseName);
     if (formatName) {
-	*formatName = testName;
+        *formatName = testName;
     } else {
-	psFree (testName);
+        psFree (testName);
     }
     if (camera) {
-	*camera = psMemIncrRefCounter(testCamera);
-    } 
+        *camera = psMemIncrRefCounter(testCamera);
+    }
     return format; // we do NOT need to incr ref counter: this is the only copy
 }
