Index: trunk/psphot/src/psphot.c
===================================================================
--- trunk/psphot/src/psphot.c	(revision 6056)
+++ trunk/psphot/src/psphot.c	(revision 6117)
@@ -1,83 +1,24 @@
 # include "psphot.h"
 
-// XXX need a better structure for handling optional sequence
+// XXX need a better structure for handling optional sequences
 int main (int argc, char **argv) {
-
-    psMetadata  *config  = NULL;
-    psMetadata  *header  = NULL;
-    pmReadout   *readout  = NULL;
-    psArray     *sources = NULL;
-    psArray     *peaks   = NULL;
-    pmPSF       *psf     = NULL;
-    psStats     *sky     = NULL;
-    bool         status;
 
     psTimerStart ("complete");
 
-    // load command-line arguments and options
-    config = psphotArguments (&argc, argv);
+    // load implementation-specific models
+    psphotModelGroupInit ();
+
+    // load command-line arguments, options, and system config data
+    ppConfig *config = psphotArguments (&argc, argv);
 
     // load input data (config and images (signal, noise, mask)
-    readout = psphotSetup (config, &header);
+    ppFile *input = psphotParseCamera (config);
 
-    // run a single-model test if desired
-    psphotModelTest (readout, config);
+    // run a single-model test if desired - XXX push in psphotImageLoop?
+    // psphotModelTest (input, options);
 
-    // measure image stats for initial guess 
-    sky = psphotImageStats (readout, config);
+    // call psphot for each readout
+    psphotImageLoop (input, config);
 
-    // generate a background model (currently, 2D polynomial)
-    // XXX this should be available to be re-added to the original image
-    psphotImageBackground (readout, config, sky);
-
-    // find the peaks in the image
-    peaks = psphotFindPeaks (readout, config, sky);
-
-    // construct sources and measure basic stats
-    sources = psphotSourceStats (readout, config, peaks);
-
-    // classify sources based on moments, brightness
-    psphotRoughClass (sources, config);
-
-    // mark blended peaks PS_SOURCE_BLEND
-    psphotBasicDeblend (sources, config, sky);
-
-    // use bright stellar objects to measure PSF
-    psf = psphotChoosePSF (config, sources, sky);
-
-    // XXX change FITMODE to a string
-    int FITMODE = psMetadataLookupS32 (&status, config, "FIT_MODE");
-    switch (FITMODE) {
-      case 0:
-	psphotEnsemblePSF (readout, config, sources, psf, sky);
-	break;
-
-      case 1:
-	psphotEnsemblePSF (readout, config, sources, psf, sky);
-	psphotFullFit (readout, config, sources, psf, sky);
-	psphotReplaceUnfit (sources);
-	psphotApResid (readout, sources, config, psf);
-	break;
-
-      case 2:
-	psphotEnsemblePSF (readout, config, sources, psf, sky);
-	psphotBlendFit (readout, config, sources, psf, sky);
-	psphotReplaceUnfit (sources);
-	psphotApResid (readout, sources, config, psf);
-	break;
-
-      case 3:
-	psphotApplyPSF (readout, config, sources, psf, sky);
-	break;
-
-      case 4:
-	psphotApplyPSF (readout, config, sources, psf, sky);
-	psphotFitExtended (readout, config, sources, sky);
-	break;
-    }
-
-    // write out data in appropriate format
-    psphotOutput (readout, header, config, sources, psf, sky);
-    psLogMsg ("psphot", 3, "wrote output: %f sec\n", psTimerMark ("psphot"));
     psLogMsg ("psphot", 3, "complete psphot run: %f sec\n", psTimerMark ("complete"));
     exit (0);
