Index: trunk/psphot/src/psphotParseCamera.c
===================================================================
--- trunk/psphot/src/psphotParseCamera.c	(revision 6379)
+++ trunk/psphot/src/psphotParseCamera.c	(revision 6571)
@@ -8,60 +8,74 @@
       } }
 
-// 2006.02.07 : no leaks!
-ppFile *psphotParseCamera (ppConfig *config) {
+bool psphotParseCamera (pmConfig *config) {
 
-    ppFile *input = ppFileAlloc ();
+    // psphot is supplied with a list of input images (may be only one image)
+    psArray *infiles = psMetadataLookupPtr(NULL, config->arguments, "INPUT");
+    if (infiles->n < 1) psAbort (__func__, "empty input list");
 
-    input->filename = psMetadataLookupStr(NULL, config->arguments, "INPUT_FILE");
-    psMemCopy (input->filename); // keep for external use
-
-    // Open the input image
-    psLogMsg("psphot", PS_LOG_INFO, "Opening input image: %s\n", input->filename);
-    input->fits = psFitsOpen (input->filename, "r"); // File handle for FITS file
-    if (! input->fits) {
-        psErrorStackPrint(stderr, "Can't open input image: %s\n", input->filename);
-        exit(EXIT_FAILURE);
+    // if no camera has been specified, use the first image as a template for the rest.
+    if (config->camera == NULL) {
+	psFits *fits = psFitsOpen (infiles->data[0], "r");
+	psMetadata *phu = psFitsReadHeader (NULL, fits);
+	config->camera = pmConfigCameraFromHeader (config->site, phu);
+	psFitsClose (fits);
+	psFree (phu);
     }
-    input->phu = psFitsReadHeader(NULL, input->fits); // FITS header
-
-    // Get camera configuration from header if not already defined
+    // There's no point in continuing if we can't recognize what we've got
     if (! config->camera) {
-        config->camera = pmConfigCameraFromHeader(config->site, input->phu);
-        if (! config->camera) {
-             // There's no point in continuing if we can't recognize what we've got
-            psErrorStackPrint(stderr, "Can't find camera configuration!\n");
-            exit(EXIT_FAILURE);
-        }
-   } else if (! pmConfigValidateCamera(config->camera, 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",
-                input->filename);
-        exit(EXIT_FAILURE);
+	psErrorStackPrint(stderr, "Can't find camera configuration!\n");
+	exit(EXIT_FAILURE);
     }
 
-    // Determine the correct recipe to use (from camera or from user)
-    // if config->recipe is not NULL, it is a user-supplied recipe
-    if (!config->recipe) {
-	config->recipe = pmConfigRecipeFromCamera(config->camera, PSPHOT_RECIPE);
-	if (config->recipe == NULL) {
-	    psErrorStackPrint(stderr, "Can't find recipe configuration!\n");
-	    exit(EXIT_FAILURE);
-	}
+    // XXX place the "data" element on the pmConfig structure?
+    config->files = psMetadataAlloc ();
+
+    // build the template fpa, set up the basic view
+    pmFPA *input = pmFPAConstruct (camera);
+
+    // assign the I/O files (potentially) needed by psphot
+    pmFPAfile *file = pmFPAfileDefine (config->files, camera, input, "PSPHOT.INPUT");
+
+    pmFPAview *view = pmFPAviewAlloc (input, config->camera, 0);
+    for (int i = 0; i < infiles->n; i++) {
+	// XXX save the phu from above?
+	psFits *fits = psFitsOpen (infiles->data[i], "r");
+	psMetadata *phu = psFitsReadHeader (NULL, fits);
+	pmConfigValidateCamera (config->camera, phu);
+
+	// set the view to the corresponding entry for this phu
+	// XXX should I save the phu data at the appropriate location in the fpa?
+	pmFPAsetView (view, phu);
+
+	// XXX is this the correct psMD to save the filename?
+	name = pmFPAviewNameFromRule (file->filextra, view);
+	psMetadataAddStr (file->names, PS_LIST_TAIL, name, 0, "", infiles->data[i]);
     }
+    pmFPAfileDefine (config->files, camera, input, "PSPHOT.OUTPUT");
+    pmFPAfileDefine (config->files, camera, input, "PSPHOT.RESID");
+    pmFPAfileDefine (config->files, camera, input, "PSPHOT.PSF_INPUT");
+    pmFPAfileDefine (config->files, camera, input, "PSPHOT.PSF_OUTPUT");
+
+    // build the template fpa, set up the basic view
+    // supply the backgnd with a different camera?
+    pmFPAfileDefine (config->files, camera, NULL, "PSPHOT.BACKSUB");
+    pmFPAfileDefine (config->files, camera, NULL, "PSPHOT.BACKGND");
+    pmFPAfileDefine (config->files, camera, NULL, "PSPHOT.BACKMDL");
+    pmFPAfileDefine (config->files, camera, NULL, "PSPHOT.PSF_SAMPLE");
 
     // recipe override values (command-line options):
-    psMetadataItem *item = NULL;
-    psMetadataIterator *iter = psMetadataIteratorAlloc (config->options, PS_LIST_HEAD, NULL);
-    while ((item = psMetadataGetAndIncrement (iter)) != NULL) {
-	psMetadataAddItem (config->recipe, item, PS_LIST_TAIL, PS_META_REPLACE);
+    psMetadata *options = psMetadataLookupPtr (status, config->arguments, "PSPHOT.OPTIONS");
+    psMetadata *recipe = psMetadataLookupPtr (status, config->recipes, "PSPHOT");
+    psMetadataIterator *iter = psMetadataIteratorAlloc (options, PS_LIST_HEAD, NULL);
+    while ((psMetadataItem *item = psMetadataGetAndIncrement (iter)) != NULL) {
+	psMetadataAddItem (recipe, item, PS_LIST_TAIL, PS_META_REPLACE);
     }
     psFree (iter);
 
     // set default recipe values here
-    METADATA_ADD_DEFAULT (config->recipe, Str, "FITMODE", "NONE", "");
-    METADATA_ADD_DEFAULT (config->recipe, Str, "PHOTCODE", "NONE", "");
-    METADATA_ADD_DEFAULT (config->recipe, Str, "BREAK_POINT", "NONE", "");
-    METADATA_ADD_DEFAULT (config->recipe, Str, "OUTPUT_FORMAT", "CMP", "");
-    METADATA_ADD_DEFAULT (config->recipe, Str, "OUTPUT_MODE", "SPLIT", "");
+    // XXX this needs re-thinking...
+    METADATA_ADD_DEFAULT (recipe, Str, "FITMODE",     "NONE", "");
+    METADATA_ADD_DEFAULT (recipe, Str, "PHOTCODE",    "NONE", "");
+    METADATA_ADD_DEFAULT (recipe, Str, "BREAK_POINT", "NONE", "");
 
     // Chip selection: if we are using a single chip, select it for each FPA
@@ -88,9 +102,5 @@
         }
     }
-
-    // Construct cameras in preparation for reading
-    input->fpa = pmFPAConstruct(config->camera);
-
     psTrace(__func__, 1, "Done with psphotParseCamera...\n");
-    return input;
+    return true;
 }
