Index: trunk/ppImage/src/ppImageParseCamera.c
===================================================================
--- trunk/ppImage/src/ppImageParseCamera.c	(revision 5860)
+++ trunk/ppImage/src/ppImageParseCamera.c	(revision 5976)
@@ -1,63 +1,52 @@
-# include "ppImage.h"
+#include "ppImage.h"
 
-static void ppFPA_Free (ppFPA *fpa) {
-    return;
-}
+bool ppImageParseCamera(ppData *data, ppConfig *config)
+{
+    // Initialise the containers where the files will go
+    data->input   = ppFileAlloc();
+    data->mask    = ppFileAlloc();
+    data->bias    = ppFileAlloc();
+    data->dark    = ppFileAlloc();
+    data->flat    = ppFileAlloc();
+    data->fringe  = ppFileAlloc();
+#if 0
+    data->process = ppFileAlloc();
+#endif
 
-ppFPA *ppFPA_Alloc (void) {
-
-    ppFPA *fpa = psAlloc (sizeof(ppFPA));
-    psMemSetDeallocator(fpa, (psFreeFunc) ppFPA_Free);
-
-    fpa->filename = NULL;
-    fpa->fpa = NULL;
-    fpa->fits = NULL;
-    fpa->header = NULL;
-
-    return fpa;
-}
-
-bool ppImageParseCamera (ppData *data, ppConfig *config) {
-    
-    bool status;
-
-    data->input   = ppFPA_Alloc ();
-    data->mask 	  = ppFPA_Alloc ();
-    data->bias 	  = ppFPA_Alloc ();
-    data->dark 	  = ppFPA_Alloc ();
-    data->flat 	  = ppFPA_Alloc ();
-    data->fringe  = ppFPA_Alloc ();
-    data->process = ppFPA_Alloc ();
-    
-    data->input->filename = psMetadataLookupPtr (NULL, config->arguments, "-input");
+    data->input->filename = psMemIncrRefCounter(psMetadataLookupStr(NULL, config->arguments, "-input"));
 
     // Open the input image
-    psLogMsg("phase2", PS_LOG_INFO, "Opening input image: %s\n", data->input->filename);
+    psLogMsg("ppImage", PS_LOG_INFO, "Opening input image: %s\n", data->input->filename);
     data->input->fits = psFitsOpen(data->input->filename, "r"); // File handle for FITS file
     if (! data->input->fits) {
+        // There's no point in continuing if we can't open the input
         psErrorStackPrint(stderr, "Can't open input image: %s\n", data->input->filename);
         exit(EXIT_FAILURE);
     }
-    data->input->header = psFitsReadHeader(NULL, data->input->fits); // FITS header
+    data->input->phu = psFitsReadHeader(NULL, data->input->fits); // FITS header
 
     // Get camera configuration from header if not already defined
     if (! config->camera) {
-        config->camera = pmConfigCameraFromHeader(config->site, data->input->header);
+        config->camera = pmConfigCameraFromHeader(config->site, data->input->phu);
         if (! config->camera) {
+             // There's no point in continuing if we can't recognise what we've got
             psErrorStackPrint(stderr, "Can't find camera configuration!\n");
             exit(EXIT_FAILURE);
         }
-   } else if (! pmConfigValidateCamera(config->camera, data->input->header)) {
-        psError(PS_ERR_IO, true, "%s does not seem to be from the camera.\n", data->input->filename);
+   } else if (! pmConfigValidateCamera(config->camera, data->input->phu)) {
+       // There's no point in continuing if what we've got doesn't match what we've been told
+        psError(PS_ERR_IO, true, "%s does not seem to be from the specified camera.\n",
+                data->input->filename);
         exit(EXIT_FAILURE);
     }
 
-    // determine the correct recipe to use
+    // Determine the correct recipe to use
     if (! config->recipe && !(config->recipe = pmConfigRecipeFromCamera(config->camera, RECIPE))) {
+        // There's no point in continuing if we can't work out what recipe to use
         psErrorStackPrint(stderr, "Can't find recipe configuration!\n");
         exit(EXIT_FAILURE);
     }
 
-    // Construct camera in preparation for reading
+    // Construct cameras in preparation for reading
     data->input->fpa   = pmFPAConstruct(config->camera);
     data->mask->fpa    = pmFPAConstruct(config->camera);
@@ -66,16 +55,17 @@
     data->flat->fpa    = pmFPAConstruct(config->camera);
     data->fringe->fpa  = pmFPAConstruct(config->camera);
+#if 0
     data->process->fpa = pmFPAConstruct(config->camera);
+#endif
 
     // XXX EAM : extend this to allow an array of selected chips by name
     // Chip selection: if we are using a single chip, select it for each FPA
-    // data->process acts as a process mask for the full FPA
-    int chipNum = psMetadataLookupS32(&status, config->arguments, "-chip"); // Chip number to work on
+    int chipNum = psMetadataLookupS32(NULL, config->arguments, "-chip"); // Chip number to work on
     if (chipNum >= 0) {
-        if (! pmFPASelectChip(data->process->fpa, chipNum)) {
+        if (! pmFPASelectChip(data->input->fpa, chipNum)) {
             psErrorStackPrint(stderr, "Chip number %d doesn't exist in camera.\n", chipNum);
             exit(EXIT_FAILURE);
         }
-        psLogMsg("phase2", PS_LOG_INFO, "Operating only on chip %d\n", chipNum);
+        psLogMsg("ppImage", PS_LOG_INFO, "Operating only on chip %d\n", chipNum);
     }
     return true;
@@ -84,4 +74,4 @@
 // XXX EAM : I dropped the pre-open of the output files; replace with a stats test of output permissions
 
-// XXX : for split data (data spread across multiple files), this step is only operating on a component 
+// XXX : for split data (data spread across multiple files), this step is only operating on a component
 //       of the FPA.  the other components should be set to 'invalid' in this case?
