Index: trunk/psphot/src/psphotImageLoop.c
===================================================================
--- trunk/psphot/src/psphotImageLoop.c	(revision 6379)
+++ trunk/psphot/src/psphotImageLoop.c	(revision 6522)
@@ -1,39 +1,17 @@
 # include "psphot.h"
 
-bool psphotImageLoop (ppFile *file, ppConfig *config) {
+bool psphotImageLoop (psphotData *data, ppConfig *config) {
 
-    bool status;
-    ppImageLoadDepth imageLoadDepth;
+    pmFPA *fpa = data->input->fpa;
 
-    // determine the load depth
-    const char *depth = psMetadataLookupStr(&status, config->recipe, "LOAD.DEPTH");
-    if (! status || ! depth || strlen(depth) == 0) {
-        psLogMsg("psphot", PS_LOG_ERROR, "LOAD.DEPTH not specified in recipe.");
-        exit(EXIT_FAILURE);
-    }
-    imageLoadDepth = PP_LOAD_NONE;
-    if (!strcasecmp(depth, "FPA")) imageLoadDepth = PP_LOAD_FPA;
-    if (!strcasecmp(depth, "CHIP")) imageLoadDepth = PP_LOAD_CHIP;
-    if (!strcasecmp(depth, "CELL")) imageLoadDepth = PP_LOAD_CELL;
-    if (imageLoadDepth == PP_LOAD_NONE) {
-        psLogMsg(__func__, PS_LOG_ERROR, "LOAD.DEPTH in recipe is not FPA, CHIP or CELL.");
-        exit(EXIT_FAILURE);
-    }
+    psphotDataIO (data, config, -1, -1);
 
-    if (imageLoadDepth == PP_LOAD_FPA) {
-        psTrace(__func__, 1, "Loading pixels for FPA...\n");
-        ppImageLoadPixels(file, config->database, -1, -1);
-    }
-
-    for (int i = 0; i < file->fpa->chips->n; i++) {
-        pmChip *chip = file->fpa->chips->data[i]; // Chip of interest in input image
+    for (int i = 0; i < fpa->chips->n; i++) {
+        pmChip *chip = fpa->chips->data[i]; // Chip of interest in input image
 
         psLogMsg ("psphot", 4, "Chip %d: %x %x\n", i, chip->exists, chip->process);
         if (! chip->process) { continue; }
 
-	if (imageLoadDepth == PP_LOAD_CHIP) {
-            psTrace(__func__, 1, "Loading pixels for chip %d...\n", i);
-            ppImageLoadPixels(file, config->database, i, -1);
-        }
+	psphotDataIO (data, config, i, -1);
 
         for (int j = 0; j < chip->cells->n; j++) {
@@ -43,9 +21,6 @@
             if (! cell->process) { continue; }
 
-            if (imageLoadDepth == PP_LOAD_CELL) {
-                psTrace(__func__, 1, "Loading pixels for chip %d, cell %d...\n", i, j);
-                ppImageLoadPixels(file, config->database, i, j);
-            }
-	    
+	    psphotDataIO (data, config, i, j);
+
 	    // XXX optional mask and weight input image should be loaded here?
 	    // this sets the weight map and basic mask applying CELL.BAD and CELL.SATURATION
@@ -61,9 +36,14 @@
 		// run a single-model test if desired
 		psphotModelTest (readout, config->arguments, config->recipe);
-		psphotReadout (readout, config->recipe);
-		psphotOutput (readout, config->arguments);
+
+		// run the actual photometry analysis
+		psphotReadout (readout, data, config);
+
+		// XXX what do we do if we have multiple readouts?
+		psphotOutput (readout, data, config);
 	    }
         }
     }
+    psphotOutputClose (data);
     return true;
 }
