Index: /trunk/psModules/src/camera/pmFPAfileDefine.c
===================================================================
--- /trunk/psModules/src/camera/pmFPAfileDefine.c	(revision 13896)
+++ /trunk/psModules/src/camera/pmFPAfileDefine.c	(revision 13897)
@@ -489,6 +489,4 @@
     // set derived values
     file->fileLevel = input->fileLevel;
-    psFree (file->format);
-    file->format = psMemIncrRefCounter(input->format);
 
     // define the rule to identify these files in the file->names data
@@ -501,4 +499,5 @@
     // associated each filename with an element of the FPA
     // save the association on file->names
+    psMetadata *format = NULL;
     for (int i = 0; i < infiles->n; i++) {
         // this function is implicitly an INPUT operation: do not create the file
@@ -521,22 +520,39 @@
             return NULL;
         }
-        bool valid = false;
-        if (!pmConfigValidateCameraFormat (&valid, input->format, phu)) {
-            psError (PS_ERR_UNKNOWN, false, "Error in config scripts\n");
-            psFree (realName);
-            psFitsClose (fits);
-            return NULL;
-        }
-        if (!valid) {
-            psError(PS_ERR_IO, false, "specified data file %s does not match format of supplied INPUT\n", realName);
-            psFree (realName);
-            psFitsClose (fits);
-            return NULL;
-        }
+
+        if (!format) {
+            format = pmConfigCameraFormatFromHeader((pmConfig*)config, phu, true);
+            if (!format) {
+                psError(PS_ERR_IO, false, "Failed to read CCD format from %s\n", realName);
+                psFree(phu);
+                psFree(realName);
+                psFitsClose(fits);
+                psFree(file);
+                return NULL;
+            }
+        } else {
+            bool valid = false;
+            if (!pmConfigValidateCameraFormat(&valid, format, phu)) {
+                psError(PS_ERR_UNKNOWN, false, "Error in config scripts\n");
+                psFree(realName);
+                psFree(file);
+                psFitsClose(fits);
+                return NULL;
+            }
+            if (!valid) {
+                psError(PS_ERR_IO, false, "specified data file %s does not match format of supplied INPUT\n",
+                        realName);
+                psFree(realName);
+                psFree(file);
+                psFitsClose(fits);
+                return NULL;
+            }
+        }
+
         psFree(realName);
-        psFitsClose (fits);
+        psFitsClose(fits);
 
         // set the view to the corresponding entry for this phu
-        pmFPAview *view = pmFPAIdentifySourceFromHeader (input->fpa, phu, input->format);
+        pmFPAview *view = pmFPAIdentifySourceFromHeader (input->fpa, phu, format);
         if (!view) {
             psError(PS_ERR_IO, false, "Unable to determine source for %s", file->name);
@@ -546,5 +562,5 @@
 
         // associate the filename with the FPA element
-        char *name = pmFPAfileNameFromRule (file->filesrc, file, view);
+        char *name = pmFPAfileNameFromRule(file->filesrc, file, view);
 
         // save the name association in the pmFPAfile structure
@@ -555,4 +571,7 @@
         psFree (phu);
     }
+    psFree(file->format);
+    file->format = format;
+
     if (success) *success = true;
     return file;
@@ -962,10 +981,19 @@
         file = fpaFileDefineOutput(config, fpa, filename, config->cameraName, "SKYCELL");
     } else {
-        // Find the correct camera configuration
-        psString cameraName = NULL;         // Name of the new (automatically-generated) camera configuration
-        psStringAppend(&cameraName, "_%s-SKYCELL", config->cameraName);
-
-        file = fpaFileDefineOutput(config, fpa, filename, cameraName, "SKYCELL");
+        psString cameraName = NULL;         // Name of the old camera configuration
+        if (config->cameraName[0] == '_' &&
+            strcmp(config->cameraName + strlen(config->cameraName) - 5, "-CHIP") == 0) {
+            cameraName = psStringNCopy(config->cameraName + 1, strlen(config->cameraName) - 6);
+        } else if (config->cameraName[0] == '_' &&
+                   strcmp(config->cameraName + strlen(config->cameraName) - 4 , "-FPA") == 0) {
+            cameraName = psStringNCopy(config->cameraName + 1, strlen(config->cameraName) - 5);
+        } else {
+            cameraName = psMemIncrRefCounter(config->cameraName);
+        }
+        psString newCameraName = NULL;  // Name of the new (automatically-generated) camera configuration
+        psStringAppend(&newCameraName, "_%s-SKYCELL", cameraName);
+        file = fpaFileDefineOutput(config, fpa, filename, newCameraName, "SKYCELL");
         psFree(cameraName);
+        psFree(newCameraName);
     }
 
