Index: /trunk/psModules/src/camera/pmFPAfileDefine.c
===================================================================
--- /trunk/psModules/src/camera/pmFPAfileDefine.c	(revision 20635)
+++ /trunk/psModules/src/camera/pmFPAfileDefine.c	(revision 20636)
@@ -77,5 +77,5 @@
 
 // define an input-type pmFPAfile, bind to the optional fpa if supplied
-pmFPAfile *pmFPAfileDefineInput(const pmConfig *config, pmFPA *fpa, const char *name)
+pmFPAfile *pmFPAfileDefineInput(const pmConfig *config, pmFPA *fpa, char *cameraName, const char *name)
 {
     PS_ASSERT_PTR_NON_NULL(config, NULL);
@@ -125,5 +125,5 @@
         file->fpa = psMemIncrRefCounter(fpa);
         file->camera = psMemIncrRefCounter((psMetadata *)fpa->camera);
-        file->cameraName = psMemIncrRefCounter(config->cameraName); // XXX Is this the correct thing to do?
+        file->cameraName = cameraName ? psMemIncrRefCounter(cameraName) : psMemIncrRefCounter(config->cameraName); // XXX Is this the correct thing to do?
     } else {
         file->camera = psMemIncrRefCounter(config->camera);
@@ -483,5 +483,6 @@
     // Determine the current format from the header; Determine camera if not specified already.
     // the returned pointers 'camera' and 'formatName' are allocated here
-    format = pmConfigCameraFormatFromHeader(&camera, &formatName, config, phu, true);
+    psString cameraName = NULL;
+    format = pmConfigCameraFormatFromHeader(&camera, &cameraName, &formatName, config, phu, true);
     if (!format) {
         psError(PS_ERR_IO, false, "Failed to read CCD format from %s\n", realName);
@@ -495,5 +496,5 @@
     // build the template fpa, set up the basic view
     // XXX do we want this to be the baseCamera name or the metaCamera name?
-    fpa = pmFPAConstruct(camera, config->cameraName);
+    fpa = pmFPAConstruct(camera, cameraName);
     if (!fpa) {
         psError(PS_ERR_IO, false, "Failed to construct FPA from %s", realName);
@@ -510,5 +511,5 @@
     // load the given filerule (from config->camera) and bind it to the fpa
     // the returned file is just a view to the entry on config->files
-    file = pmFPAfileDefineInput(config, fpa, filename);
+    file = pmFPAfileDefineInput(config, fpa, cameraName, filename);
     if (!file) {
         psError(PS_ERR_IO, false, "file %s not defined\n", filename);
@@ -519,5 +520,7 @@
         return NULL;
     }
+    psFree (cameraName);
     psFree (file->filerule); // this is set in pmFPAfileDefineInput
+
     file->format = format;
     file->formatName = formatName;
@@ -659,5 +662,5 @@
     // load the given filerule (from config->camera) and bind it to the fpa
     // the returned file is just a view to the entry on config->files
-    file = pmFPAfileDefineInput (config, input->fpa, filename);
+    file = pmFPAfileDefineInput (config, input->fpa, NULL, filename);
     if (!file) {
         psError(PS_ERR_IO, false, "file %s not defined\n", filename);
@@ -703,5 +706,5 @@
 
         if (!format) {
-            format = pmConfigCameraFormatFromHeader(NULL, NULL, config, phu, true);
+            format = pmConfigCameraFormatFromHeader(NULL, NULL, NULL, config, phu, true);
             if (!format) {
                 psError(PS_ERR_IO, false, "Failed to read CCD format from %s\n", realName);
@@ -816,5 +819,6 @@
     psMetadata *camera = NULL;
     psString formatName = NULL;
-    format = pmConfigCameraFormatFromHeader (&camera, &formatName, config, phu, true);
+    psString cameraName = NULL;
+    format = pmConfigCameraFormatFromHeader (&camera, &cameraName, &formatName, config, phu, true);
     if (!format) {
         psError(PS_ERR_IO, false, "Failed to read CCD format from %s\n", (char *)infiles->data[0]);
@@ -826,5 +830,5 @@
 
     // build the template fpa, set up the basic view
-    fpa = pmFPAConstruct (camera, config->cameraName);
+    fpa = pmFPAConstruct (camera, cameraName);
     if (!fpa) {
         psError(PS_ERR_IO, false, "Failed to construct FPA from %s", (char *)infiles->data[0]);
@@ -840,5 +844,5 @@
     // the returned file is just a view to the entry on config->files
     // we need a variable name here... (but in filerule)
-    file = pmFPAfileDefineInput (config, fpa, filename);
+    file = pmFPAfileDefineInput (config, fpa, cameraName, filename);
     if (!file) {
         psError(PS_ERR_IO, false, "file %s not defined\n", filename);
@@ -848,5 +852,7 @@
         return NULL;
     }
+    psFree(cameraName);
     FPA_TEST_ASSERT (file);
+
     file->format = format;
     file->formatName = formatName;
@@ -922,5 +928,5 @@
     // load the given filerule (from config->camera) and bind it to the fpa
     // the returned file is just a view to the entry on config->files
-    pmFPAfile *file = pmFPAfileDefineInput(config, fpa, filename);
+    pmFPAfile *file = pmFPAfileDefineInput(config, fpa, NULL, filename);
     psFree (fpa);
     if (!file) {
@@ -1003,5 +1009,5 @@
         // load the given filerule (from config->camera) and bind it to the fpa
         // the returned file is just a view to the entry on config->files
-        file = pmFPAfileDefineInput (config, fpa, filename);
+        file = pmFPAfileDefineInput (config, fpa, NULL, filename);
         if (!file) {
             psError(PS_ERR_IO, false, "file %s not defined\n", filename);
