Index: trunk/psphot/src/testPSphotLoop.c
===================================================================
--- trunk/psphot/src/testPSphotLoop.c	(revision 6522)
+++ trunk/psphot/src/testPSphotLoop.c	(revision 6571)
@@ -1,45 +1,96 @@
 # include "psphot.h"
 
-bool psphotLoop (psphotData *data, ppConfig *config) {
+bool psphotImageLoop (pmConfig *config) {
 
-    psRegion region = {0,0,0,0};
-    pmFPA *fpa = data->input->fpa;
-    pmFPAiterator *fpi = pmFPAiteratorAlloc (fpa, region);
+    psMetadata *recipe = psMetadataLookupPts (NULL, config->recipes, PSPHOT_RECIPE);
+    if (!recipe) {
+	psErrorStackPrint(stderr, "Can't find recipe configuration!\n");
+	exit(EXIT_FAILURE);
+    }
+
+    pmFPA *input = psMetadataLookupPtr (&status, config->files, "PSPHOT.INPUT");
+    pmFPAview *view = pmFPAviewAlloc (0);
 
     // files associated with the science image
-    pmFileDefine (fpi, config->camera, "PPIMAGE.INPUT");
-    pmFileDefine (fpi, config->camera, "PPIMAGE.OUTPUT.HEAD");
-    pmFileDefine (fpi, config->camera, "PPIMAGE.OUTPUT.DATA");
-    pmFileDefine (fpi, config->camera, "PPIMAGE.BACKGND");
-    pmFileDefine (fpi, config->camera, "PPIMAGE.BACKSUB");
-    pmFileDefine (fpi, config->camera, "PPIMAGE.RESID");
-    pmFileDefine (fpi, config->camera, "PPIMAGE.PSF");
-    pmFileIOChecks (fpi);
+    pmFPAfileReadChecks (config->files, view);
 
-    while ((chip = pmChipNext (fpi)) != NULL) {
+    while ((chip = pmChipNext (view, input)) != NULL) {
 
         psLogMsg ("psphot", 4, "Chip %d: %x %x\n", i, chip->exists, chip->process);
         if (! chip->process) { continue; }
-	pmFileIOChecks (fpi);
+	pmFPAfileReadChecks (config->files, view);
 
-	while ((cell = pmCellNext (fpi)) != NULL) {
+	while ((cell = pmCellNext (view, input)) != NULL) {
 
             psLogMsg ("psphot", 4, "Cell %d: %x %x\n", j, cell->exists, cell->process);
             if (! cell->process) { continue; }
-	    pmFileIOChecks (fpi);
+	    pmFPAfileReadChecks (config->files, view);
+
+	    // 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
+	    pmCellSetWeights(cell);
+
+	    // I have a valid mask, now mask in the analysis region of interest
+	    pmCellSetMask (cell, recipe); 
 
 	    // process each of the readouts
-	    while ((readout = pmReadoutNext (fpi)) != NULL) {
-		pmFileIOChecks (fpi);
+	    while ((readout = pmReadoutNext (view, input)) != NULL) {
+		pmFPAfileReadChecks (config->files, view);
 		
+		// run a single-model test if desired
+		// XXX move this to psphotReadout??
+		// psphotModelTest (readout, recipe);
+
 		// run the actual photometry analysis
-		psphotReadout (readout, config);
+		psphotReadout (config, view);
+
+		pmFPAfileWriteChecks (config->files, view);
 
 		// write out the desired output dataset(s)
-		psphotOutput (readout, config);
+		// psphotOutput (view, recipe);
 	    }
+	    pmFPAfileWriteChecks (config->files, view);
 	}
+	pmFPAfileWriteChecks (config->files, view);
     }
-    pmFileClose (fpi);
+    pmFPAfileWriteChecks (config->files, view);
     return true;
 }
+
+// I/O files related to psphot:
+// PSPHOT.INPUT   : input image file(s)
+// PSPHOT.RESID   : residual image
+// PSPHOT.OUTPUT  : output object tables (object)
+
+// PSPHOT.BACKSUB : background subtracted image
+// PSPHOT.BACKGND : background model (full-scale image?)
+// PSPHOT.BACKMDL : background model (binned image?)
+// PSPHOT.PSF     : sample PSF images
+
+
+/**
+
+filename | pmFPAfile  | pmFPA  | pmFPAview
+chip00.f | PSPHOT.IN  | input  | view
+chip01.f | PSPHOT.IN  | input  | view
+chip02.f | PSPHOT.IN  | input  | view
+chip03.f | PSPHOT.IN  | input  | view
+
+out00.f  | PSPHOT.OUT | input  | view
+out01.f  | PSPHOT.OUT | input  | view
+out02.f  | PSPHOT.OUT | input  | view
+out03.f  | PSPHOT.OUT | input  | view
+
+obj00.f  | PSPHOT.OBJ | input  | view
+obj01.f  | PSPHOT.OBJ | input  | view
+obj02.f  | PSPHOT.OBJ | input  | view
+obj03.f  | PSPHOT.OBJ | input  | view
+
+bin00.f  | PSPHOT.BIN | binned | view
+bin01.f  | PSPHOT.BIN | binned | view
+bin02.f  | PSPHOT.BIN | binned | view
+bin03.f  | PSPHOT.BIN | binned | view
+
+mosaic.f | PSPHOT.MOS | mosaic | view
+
+**/
