Index: /trunk/psphot/src/Makefile.am
===================================================================
--- /trunk/psphot/src/Makefile.am	(revision 6714)
+++ /trunk/psphot/src/Makefile.am	(revision 6715)
@@ -16,6 +16,6 @@
 	psphotArguments.c	\
 	psphotParseCamera.c	\
-	testPSphotLoop.c	\
-	psphotMaskCell.c	\
+	psphotImageLoop.c	\
+	psphotMaskReadout.c	\
 	psphotReadout.c		\
 	psphotImageMedian.c	\
@@ -33,12 +33,13 @@
 	psphotEvalPSF.c		\
 	psphotEvalFLT.c		\
-	psphotSourceFits.c	
+	psphotSourceFits.c	\
+	psphotRadiusChecks.c	\
+	psphotSortBySN.c	\
+	psphotOutput.c		\
+	psphotGrowthCurve.c	\
+	psphotFakeSources.c	\
+	psphotCleanup.c	   	
 
-junk =	psphotGrowthCurve.c	\
-	psphotCleanup.c	        \
-	psphotSortBySN.c	\
-	psphotDefinePixels.c	\
-	psphotRadiusChecks.c	\
-	psModulesUtils.c	\
+junk =	psphotDefinePixels.c	\
 	pmSourceContour.c	\
 	pmModelFitSet.c		\
@@ -47,8 +48,5 @@
 
 noinst_HEADERS =		\
-	psLibUtils.h		\
-	psModulesUtils.h	\
-	psphot.h		\
-	psSparse.h
+	psphot.h		
 
 clean-local:
@@ -58,10 +56,6 @@
 	etags `find . -name \*.[ch] -print`
 
-
 #	psphotFullFit.c		
 #	psphotApplyPSF.c	
 #	psphotFitGalaxies.c
-#	psphotImageStats.c	
-#	psphotImageBackground.c 
-#	psphotOutput.c		
 #	psphotLoadPixels.c	
Index: unk/psphot/src/psImageData.c
===================================================================
--- /trunk/psphot/src/psImageData.c	(revision 6714)
+++ 	(revision )
@@ -1,24 +1,0 @@
-# include "psphot.h"
-
-static void eamReadoutFree (eamReadout *imdata) {
-
-  if (imdata == NULL) return;
-
-  psFree (imdata->image);
-  psFree (imdata->header);
-  psFree (imdata->weight);
-  psFree (imdata->mask);
-  return;
-}
-
-eamReadout *eamReadoutAlloc (psImage *image, psImage *weight, psImage *mask, psMetadata *header) {
-  
-    eamReadout *imdata = psAlloc(sizeof(eamReadout));
-    imdata->image = image;
-    imdata->header = header;
-    imdata->weight = weight;
-    imdata->mask = mask;
-
-    psMemSetDeallocator(imdata, (psFreeFunc) eamReadoutFree);
-    return (imdata);
-}
Index: unk/psphot/src/psModulesUtils.c
===================================================================
--- /trunk/psphot/src/psModulesUtils.c	(revision 6714)
+++ 	(revision )
@@ -1,105 +1,0 @@
-# include "psModulesUtils.h"
-
-static void ppConfigFree (ppConfig *config) {
-
-  if (config == NULL) return;
-  psFree (config->site);
-  psFree (config->camera);
-  psFree (config->recipe);
-  psFree (config->arguments);
-  psFree (config->options);
-  psFree (config->database);
-  return;
-}
-
-// allocate a ppConfig structrue
-ppConfig *ppConfigAlloc (void) {
-
-  ppConfig *config = psAlloc (sizeof(ppConfig));
-  psMemSetDeallocator(config, (psFreeFunc) ppConfigFree);
-
-  config->site = NULL;
-  config->camera = NULL;
-  config->recipe = NULL;
-  config->arguments = NULL;
-  config->options = NULL;
-  config->database = NULL;
-
-  return (config);
-}
-
-static void ppFileFree (ppFile *file) {
-
-  if (file == NULL) return;
-  psFree (file->phu);
-  psFree (file->filename);
-  psFree (file->fpa);
-  psFitsClose (file->fits);
-  return;
-}
-
-// allocate a ppFile structrue
-ppFile *ppFileAlloc (void) {
-
-  ppFile *file = psAlloc (sizeof(ppFile));
-  psMemSetDeallocator(file, (psFreeFunc) ppFileFree);
-
-  file->filename = NULL;
-  file->fits = NULL;
-  file->phu = NULL;
-  file->fpa = NULL;
-
-  return (file);
-}
-
-psMetadata *pmReadoutGetHeader (pmReadout *readout) {
-
-    p_pmHDU *hdu = NULL;
-
-    pmCell *cell = readout->parent;	// cell containing this readout;
-    hdu = cell->hdu;			// The data unit, containing the weight and mask originals
-    if (hdu) return hdu->header;
-    
-    pmChip *chip = cell->parent;	// The parent chip
-    hdu = chip->hdu;			// The data unit, containing the weight and mask originals
-    if (hdu) return hdu->header;
-
-    pmFPA *fpa = chip->parent;		// The parent FPA
-    hdu = fpa->hdu;
-    if (hdu) return hdu->header;
-
-    if (fpa->phu) return fpa->phu;
-    
-    psError(PS_ERR_UNKNOWN, true, "Unable to find the HDU in the hierarchy!\n");
-    return NULL;
-}
-
-bool psRegionIsNaN (psRegion region) {
-
-    if (!isfinite(region.x0)) return true;
-    if (!isfinite(region.x1)) return true;
-    if (!isfinite(region.y0)) return true;
-    if (!isfinite(region.y1)) return true;
-    return false;
-}
-
-ppImageLoadDepth ppImageCheckDepth (psMetadata *recipe, char *name) {
-
-    bool status;
-
-    // determine the load depth
-    const char *depth = psMetadataLookupStr(&status, recipe, name);
-    if (! status || ! depth || strlen(depth) == 0) {
-        psLogMsg("psphot", PS_LOG_ERROR, "%s not specified in recipe.", name);
-        exit(EXIT_FAILURE);
-    }
-
-    if (!strcasecmp(depth, "FPA"))  return (PP_LOAD_FPA);
-    if (!strcasecmp(depth, "CHIP")) return (PP_LOAD_CHIP);
-    if (!strcasecmp(depth, "CELL")) return (PP_LOAD_CELL);
-
-    psLogMsg(__func__, PS_LOG_ERROR, "%s in recipe is not FPA, CHIP or CELL.", name);
-    exit(EXIT_FAILURE);
-
-    return PP_LOAD_NONE;
-}
Index: unk/psphot/src/psModulesUtils.h
===================================================================
--- /trunk/psphot/src/psModulesUtils.h	(revision 6714)
+++ 	(revision )
@@ -1,63 +1,0 @@
-
-# ifndef PS_MODULE_UTILS
-# define PS_MODULE_UTILS
-
-# include <strings.h>  // for strcasecmp
-# include <pslib.h>
-# include <pmObjects.h>
-# include <pmModelGroup.h>
-# include "psLibUtils.h"
-
-// How much of the FPA to load at a time
-typedef enum {
-    PP_LOAD_NONE,                       // Don't load anything
-    PP_LOAD_FPA,                        // Load the entire FPA at once
-    PP_LOAD_CHIP,                       // Load by chip
-    PP_LOAD_CELL,                       // Load by cell
-} ppImageLoadDepth;
-
-// Configuration data
-typedef struct {
-    psMetadata *site;                   // The site configuration
-    psMetadata *camera;                 // The camera configuration
-    psMetadata *recipe;                 // The recipe (i.e., specific setups)
-    psMetadata *arguments;              // Command-line arguments
-    psDB       *database;               // Database handle
-} ppConfig;
-
-// A file to process
-typedef struct {
-    char *filename;                     // File name
-    psFits *fits;                       // The FITS file handle
-    psMetadata *phu;                    // The FITS header
-    pmFPA *fpa;                         // The FPA, with pixels and extensions
-} ppFile;
-
-typedef struct {
-    ppFile *input;
-    ppFile *resid;
-    ppFile *background;
-    ppFile *backSub;
-    ppFile *output;
-    ppFile *psfdata;
-    ppFile *psfsample;
-} psphotData;
-
-// psModule extra utilities
-// bool	     pmSourceFitModel_EAM(pmSource *source, pmModel *model, const bool PSF);
-bool 	     pmModelFitStatus (pmModel *model);
-int	     pmSourceDophotType (pmSource *source);
-bool	     pmSourcePhotometry (float *fitMag, float *obsMag, pmModel *model, psImage *image, psImage *mask);
-bool         pmModelSkyOffset (pmModel *model, float x, float y, float radius);
-
-// unify with paul's image/header/metadata functions
-psF32        pmConfigLookupF32 (bool *status, psMetadata *config, psMetadata *header, char *name);
-pmModel     *pmModelSelect (pmSource *source);
-
-ppConfig    *ppConfigAlloc (void);
-ppFile      *ppFileAlloc (void);
-psMetadata  *pmReadoutGetHeader (pmReadout *readout);
-
-bool psRegionIsNaN (psRegion region);
-
-# endif
Index: /trunk/psphot/src/psphot.c
===================================================================
--- /trunk/psphot/src/psphot.c	(revision 6714)
+++ /trunk/psphot/src/psphot.c	(revision 6715)
@@ -3,4 +3,6 @@
 // XXX need a better structure for handling optional sequences
 int main (int argc, char **argv) {
+
+    // headtest (argc, argv);
 
     psTimerStart ("complete");
Index: /trunk/psphot/src/psphot.h
===================================================================
--- /trunk/psphot/src/psphot.h	(revision 6714)
+++ /trunk/psphot/src/psphot.h	(revision 6715)
@@ -3,16 +3,37 @@
 # include <unistd.h>   // for unlink
 # include <pslib.h>
-# include <pmObjects.h>
+# include <psmodules.h>
+
+# if (0)
+# include <psLine.h>
+# include <psSparse.h>
+# include <psEllipse.h>
+# include <psAdditionals.h>
+# include <pmConfig.h>
+# include <pmHDU.h>
+# include <pmHDUUtils.h>
+# include <pmFPA.h>
+# include <pmFPAview.h>
+# include <pmFPAfile.h>
+# include <pmFPARead.h>
+# include <pmFPAConstruct.h>
+# include <pmMaskBadPixels.h>
+# include <pmConcepts.h>
+
+# include <pmPeaks.h>
+# include <pmMoments.h>
+# include <pmModel.h>
+# include <pmSource.h>
+# include <pmSourceIO.h>
+# include <pmSourceSky.h>
+# include <pmSourceFitModel.h>
+# include <pmSourceFitSet.h>
+# include <pmSourceContour.h>
 # include <pmGrowthCurve.h>
-# include <pmConfig.h>
-# include <pmFPARead.h>
 # include <pmPSF.h>
 # include <pmPSFtry.h>
 # include <pmModelGroup.h>
-// # include "psLibUtils.h"
-// # include "psModulesUtils.h"
-// # include "psSparse.h"
-# include "pmFPAConstruct.h"
-# include "pmConcepts.h"
+# include <pmSourcePhotometry.h>
+# endif
 
 # define PSPHOT_RECIPE "PSPHOT"
@@ -26,25 +47,23 @@
 
 bool            psphotModelTest (pmReadout *readout, psMetadata *arguments, psMetadata *recipe);
-bool            psphotReadout (pmReadout *readout, psMetadata *config);
+bool            psphotReadout (pmConfig *config, pmFPAview *view);
 void            psphotCleanup (void);
 
-// bool            ppImageLoadPixels (ppFile *input, psDB *db, int chipNum, int cellNum);
+psArray        *psphotFakeSources ();
+int             psphotSaveImage (psMetadata *header, psImage *image, char *filename);
 
 // psphotReadout functions
-psStats        *psphotImageStats (pmReadout *readout, psMetadata *config);
-psPolynomial2D *psphotImageBackground (pmReadout *readout, psMetadata *config, psStats *sky);
+bool            psphotImageMedian (pmConfig *config, pmFPAview *view);
 psArray        *psphotFindPeaks (pmReadout *readout, psMetadata *config);
 psArray        *psphotSourceStats (pmReadout *readout, psMetadata *config, psArray *allpeaks);
 bool            psphotRoughClass (psArray *sources, psMetadata *config);
 bool            psphotBasicDeblend (psArray *sources, psMetadata *config);
-pmPSF          *psphotChoosePSF (psMetadata *config, psArray *sources);
-void            psphotOutput (pmReadout *readout, psMetadata *arguments);
-psImage        *psphotImageMedian (pmReadout *readout, psMetadata *config);
-
-// optional object analysis steps
-bool 	        psphotEnsemblePSF (pmReadout *readout, psMetadata *config, psArray *sources, pmPSF *psf, bool final);
-bool            psphotBlendFit (pmReadout *readout, psMetadata *config, psArray *sources, pmPSF *psf);
+pmPSF          *psphotChoosePSF (psArray *sources, psMetadata *config);
+bool 	        psphotEnsemblePSF (pmReadout *readout, psArray *sources, psMetadata *config, pmPSF *psf, bool final);
+bool            psphotBlendFit (pmReadout *readout, psArray *sources, psMetadata *config, pmPSF *psf);
 bool            psphotReplaceUnfit (psArray *sources);
 bool            psphotApResid (pmReadout *readout, psArray *sources, psMetadata *config, pmPSF *psf);
+bool            psphotMagnitudes (psArray *sources, psMetadata *config, pmPSF *psf);
+bool            psphotSkyReplace (pmConfig *config, pmFPAview *view);
 
 // basic support functions
@@ -54,7 +73,6 @@
 bool            psphotGrowthCurve (pmReadout *readout, pmPSF *psf);
 void            psphotTestArguments (int *argc, char **argv);
-bool            psphotMaskCell (pmCell *cell, psMetadata *recipe);
+bool            psphotMaskReadout (pmReadout *readout, psMetadata *recipe);
 bool            psphotBackgroundNames (psMetadata *arguments);
-bool            psphotSkyReplace (pmReadout *readout, psImage *background);
 
 // functions to set the correct source pixels
@@ -66,27 +84,6 @@
 
 // output functions
-# if (0)
-bool 	     	pmSourcesWriteSX   (psArray *sources, char *filename);
-bool 	     	pmSourcesWriteOBJ  (psArray *sources, char *filename);
-bool 	     	pmSourcesWriteCMP  (psArray *sources, char *filename, psMetadata *header);
-bool 	     	pmSourcesWriteCMF  (psArray *sources, char *filename, psMetadata *header);
-bool 	     	pmSourcesWriteText (psArray *sources, char *filename);
-
-bool 	     	pmModelWritePSFs (psArray *sources, char *filename);
-bool 	     	pmModelWriteEXTs (psArray *sources, char *filename);
-bool 	     	pmModelWriteNULLs (psArray *sources, char *filename);
-bool 	     	pmPeaksWriteText (psArray *sources, char *filename);
-bool 	     	pmMomentsWriteText (psArray *sources, char *filename);
-
-bool            psphotSamplePSFs (pmPSF *psf, psImage *image, char *output);
 bool 		psphotDumpMoments (psMetadata *config, psArray *sources);
-int             psphotSaveImage (psMetadata *header, psImage *image, char *filename);
 bool            psphotUpdateHeader (psMetadata *header, psMetadata *config);
-# endif
-
-// void            psphotOutputPrep (ppFile *file, ppConfig *config);
-// void            psphotOutputCleanup (void);
-
-bool            psphotMagnitudes (psMetadata *config, psArray *sources, pmPSF *psf);
 
 // PSF / DBL / EXT evaluation functions
@@ -106,4 +103,25 @@
 // XXX these can probably be dropped:
 
+// functions to support simultaneous multi-source fitting
+bool 		psphotFitSet (pmSource *oneSrc, pmModel *oneModel, char *fitset, bool PSF);
+
+# if (0)
+
+pmHDU          *pmHDUFromReadout (pmReadout *readout);
+bool            psRegionIsNaN (psRegion region);
+bool            pmReadoutSetWeights(pmReadout *readout);
+
+// bicubic interpolation
+psPolynomial2D *psImageBicubeFit (psImage *image, int x, int y);
+psPlane         psImageBicubeMin (psPolynomial2D *poly);
+
+bool            psImageJpegColormap (char *name);
+bool            psImageJpeg (psImage *image, char *filename, float zero, float scale);
+
+bool 		pmSourceFitSet (pmSource *source, psArray *modelSet, const bool PSF);
+psF32           pmModelFitSet (psVector *deriv, const psVector *params, const psVector *x);
+bool            pmModelFitSetInit (pmModelType type);
+void            pmModelFitSetClear (void);
+
 // optional mode for clip fit?
 psPolynomial4D *psVectorChiClipFitPolynomial4D(
@@ -119,18 +137,22 @@
     const psVector *t);
 
-// functions to support simultaneous multi-source fitting
-bool 		psphotFitSet (pmSource *oneSrc, pmModel *oneModel, char *fitset, bool PSF);
-bool 		pmSourceFitSet (pmSource *source, psArray *modelSet, const bool PSF);
-psF32           pmModelFitSet (psVector *deriv, const psVector *params, const psVector *x);
-bool            pmModelFitSetInit (pmModelType type);
-void            pmModelFitSetClear (void);
+# endif
 
-// bicubic interpolation
-psPolynomial2D *psImageBicubeFit (psImage *image, int x, int y);
-psPlane         psImageBicubeMin (psPolynomial2D *poly);
+# if (0)
+bool            psphotSamplePSFs (pmPSF *psf, psImage *image, char *output);
+int             psphotSaveImage (psMetadata *header, psImage *image, char *filename);
 
-bool psImageJpegColormap (char *name);
-bool psImageJpeg (psImage *image, char *filename, float zero, float scale);
+bool 	     	pmSourcesWriteSX   (psArray *sources, char *filename);
+bool 	     	pmSourcesWriteOBJ  (psArray *sources, char *filename);
+bool 	     	pmSourcesWriteCMP  (psArray *sources, char *filename, psMetadata *header);
+bool 	     	pmSourcesWriteCMF  (psArray *sources, char *filename, psMetadata *header);
+bool 	     	pmSourcesWriteText (psArray *sources, char *filename);
+bool 	     	pmPeaksWriteText (psArray *sources, char *filename);
 
+bool 	     	pmModelWritePSFs (psArray *sources, char *filename);
+bool 	     	pmModelWriteEXTs (psArray *sources, char *filename);
+bool 	     	pmModelWriteNULLs (psArray *sources, char *filename);
+bool 	     	pmMomentsWriteText (psArray *sources, char *filename);
+# endif
 
 // XXX deprecate
@@ -142,2 +164,11 @@
 // float           pmSourceCrossWeight (pmSource *Mi, pmSource *Mj);
 // psArray        *pmSourceContour_EAM (psImage *image, int x, int y, float threshold);
+// psStats        *psphotImageStats (pmReadout *readout, psMetadata *config);
+// psPolynomial2D *psphotImageBackground (pmReadout *readout, psMetadata *config, psStats *sky);
+// void            psphotOutput (pmReadout *readout, psMetadata *arguments);
+
+// void            psphotOutputPrep (ppFile *file, ppConfig *config);
+// void            psphotOutputCleanup (void);
+
+// bool            ppImageLoadPixels (ppFile *input, psDB *db, int chipNum, int cellNum);
+
Index: /trunk/psphot/src/psphotApResid.c
===================================================================
--- /trunk/psphot/src/psphotApResid.c	(revision 6714)
+++ /trunk/psphot/src/psphotApResid.c	(revision 6715)
@@ -30,13 +30,13 @@
     Npsf = 0;
 
-    // select all good PM_SOURCE_STAR entries
+    // select all good PM_SOURCE_TYPE_STAR entries
     for (int i = 0; i < sources->n; i++) {
 	source = sources->data[i];
 
-	if (source->type != PM_SOURCE_STAR) continue; 
-	if (source->mode &  PM_SOURCE_SATSTAR) continue;
-	if (source->mode &  PM_SOURCE_BLEND) continue;
-	if (source->mode &  PM_SOURCE_FAIL) continue;
-	if (source->mode &  PM_SOURCE_POOR) continue;
+	if (source->type != PM_SOURCE_TYPE_STAR) continue; 
+	if (source->mode &  PM_SOURCE_MODE_SATSTAR) continue;
+	if (source->mode &  PM_SOURCE_MODE_BLEND) continue;
+	if (source->mode &  PM_SOURCE_MODE_FAIL) continue;
+	if (source->mode &  PM_SOURCE_MODE_POOR) continue;
 
 	// XXX tune independently?
@@ -51,8 +51,8 @@
 	yPos->data.F64[Npsf] = model->params->data.F32[3];
 
-	flux->data.F64[Npsf] = pow(10.0, -0.4*source->fitMag);
+	flux->data.F64[Npsf] = pow(10.0, -0.4*source->psfMag);
 	r2rflux->data.F64[Npsf] = PS_SQR(model->radius) / flux->data.F64[Npsf];
 	
-	apResid->data.F64[Npsf] = source->apMag + pmGrowthCurveCorrect (psf->growth, model->radius) - source->fitMag ;
+	apResid->data.F64[Npsf] = source->apMag + pmGrowthCurveCorrect (psf->growth, model->radius) - source->psfMag;
 
 	// XXX sanity clip?
Index: /trunk/psphot/src/psphotApplyPSF.c
===================================================================
--- /trunk/psphot/src/psphotApplyPSF.c	(revision 6714)
+++ /trunk/psphot/src/psphotApplyPSF.c	(revision 6715)
@@ -20,7 +20,7 @@
 
 	// skip non-astronomical objects (very likely defects)
-	if (source->mode  & PM_SOURCE_BLEND) continue; 
-	if (source->type == PM_SOURCE_DEFECT) continue; 
-	if (source->type == PM_SOURCE_SATURATED) continue;
+	if (source->mode  & PM_SOURCE_MODE_BLEND) continue; 
+	if (source->type == PM_SOURCE_TYPE_DEFECT) continue; 
+	if (source->type == PM_SOURCE_TYPE_SATURATED) continue;
 
 	// use the source moments, etc to guess basic model parameters
@@ -49,7 +49,7 @@
 	// check if model fit is acceptable
 	if (psphotEvalPSF (source, source->modelPSF)) {
-	    pmSourceSubModel (source->pixels, source->mask, source->modelPSF, false, false);
-	    source->mode |=  PM_SOURCE_SUBTRACTED;
-	    source->mode &= ~PM_SOURCE_TEMPSUB;
+	    pmModelSub (source->pixels, source->mask, source->modelPSF, false, false);
+	    source->mode |=  PM_SOURCE_MODE_SUBTRACTED;
+	    source->mode &= ~PM_SOURCE_MODE_TEMPSUB;
 	    Nsub ++;
 	}
Index: /trunk/psphot/src/psphotArguments.c
===================================================================
--- /trunk/psphot/src/psphotArguments.c	(revision 6714)
+++ /trunk/psphot/src/psphotArguments.c	(revision 6715)
@@ -2,5 +2,8 @@
 # include <glob.h>
 
-static void usage (void);
+static void usage (void) {
+    fprintf (stderr, "USAGE: psphot [-file image(s)] [-list imagelist] (output)\n");
+    exit (2);
+}
 
 pmConfig *psphotArguments (int *argc, char **argv) {
@@ -99,5 +102,5 @@
 
     // load config data from default locations 
-    pmConfig *config = pmConfigRead(argc, argv, PSPHOT_RECIPE);
+    pmConfig *config = pmConfigRead(argc, argv);
 
     // Storage for other command-line arguments
@@ -105,10 +108,11 @@
 
     // save these recipe options until we have loaded the options
-    psMetadataAddPtr (config->arguments, PS_LIST_TAIL, "PSPHOT.OPTIONS",  PS_META_REPLACE, "", options);
+    psMetadataAddPtr (config->arguments, PS_LIST_TAIL, "PSPHOT.OPTIONS",  PS_DATA_METADATA, "", options);
+    psFree (options);
 
     // chip selection is used to limit chips to be processed
     if ((N = psArgumentGet (*argc, argv, "-chip"))) {
 	psArgumentRemove (N, argc, argv);
-	psMetadataAddStr (config->arguments, PS_LIST_TAIL, "CHIP_SELECTION", PS_META_REPLACE, "", argv[N]);
+	psMetadataAddStr (config->arguments, PS_LIST_TAIL, "CHIP_SELECTION", PS_DATA_STRING, "", psStringCopy(argv[N]));
 	psArgumentRemove (N, argc, argv);
     }
@@ -116,4 +120,5 @@
     // we load all input files onto a psArray, to be parsed later
     psArray *input = psArrayAlloc (16);
+    input->n = 0;
 
     // load the list of filenames the supplied file (may be a glob: "file*.fits")
@@ -126,4 +131,5 @@
 	    char *filename = psStringCopy (globList.gl_pathv[i]);
 	    psArrayAdd (input, 16, filename);
+	    psFree (filename);
 	}
 	psArgumentRemove (N, argc, argv);
@@ -150,4 +156,5 @@
 		filename = psStringCopy (word);
 		psArrayAdd (input, 16, filename);
+		psFree (filename);
 		break;
 	      default:
@@ -162,17 +169,13 @@
 
     // input list gets places as an array on the config->arguements list
-    psMetadataAddPtr (config->arguments, PS_LIST_TAIL, "INPUT",  PS_META_REPLACE, "", input);
+    psMetadataAddPtr (config->arguments, PS_LIST_TAIL, "INPUT",  PS_DATA_ARRAY, "", input);
+    psFree (input);
 
     if (*argc != 2) usage ();
 
-    // input and output positions are fixed
-    psMetadataAddStr (config->arguments, PS_LIST_TAIL, "OUTPUT", PS_META_REPLACE, "", argv[1]);
+    // output position is fixed
+    psMetadataAddStr (config->arguments, PS_LIST_TAIL, "OUTPUT", 0, "", argv[1]);
 
     psTrace(__func__, 1, "Done with psphotArguments...\n");
     return (config);
 }
-
-static void usage (void) {
-    fprintf (stderr, "USAGE: psphot [-file image(s)] [-list imagelist] (output)\n");
-    exit (2);
-}
Index: /trunk/psphot/src/psphotBasicDeblend.c
===================================================================
--- /trunk/psphot/src/psphotBasicDeblend.c	(revision 6714)
+++ /trunk/psphot/src/psphotBasicDeblend.c	(revision 6715)
@@ -37,5 +37,5 @@
 	source = sources->data[N];
 
-	if (source->mode & PM_SOURCE_BLEND) continue;
+	if (source->mode & PM_SOURCE_MODE_BLEND) continue;
 
 	// temporary array for overlapping objects we find
@@ -89,5 +89,5 @@
 
 	// generate a basic contour (set of x,y coordinates at-or-below flux level)
-	psArray *contour = pmSourceContour_EAM (source->pixels, source->peak->x, source->peak->y, threshold);
+	psArray *contour = pmSourceContour (source->pixels, source->peak->x, source->peak->y, threshold);
 	if (contour == NULL) {
 	    psFree (overlap);
@@ -110,5 +110,5 @@
 		if (xv->data.F32[j+1] < testSource->peak->x) break;
 
-		testSource->mode |= PM_SOURCE_BLEND;
+		testSource->mode |= PM_SOURCE_MODE_BLEND;
 
 		// add this to the list of source->blends
Index: /trunk/psphot/src/psphotBlendFit.c
===================================================================
--- /trunk/psphot/src/psphotBlendFit.c	(revision 6714)
+++ /trunk/psphot/src/psphotBlendFit.c	(revision 6715)
@@ -2,5 +2,5 @@
 
 // XXX I don't like this name
-bool psphotBlendFit (pmReadout *readout, psMetadata *config, psArray *sources, pmPSF *psf) { 
+bool psphotBlendFit (pmReadout *readout, psArray *sources, psMetadata *config, pmPSF *psf) { 
 
     int Nfit = 0;
@@ -28,7 +28,7 @@
 
 	// skip non-astronomical objects (very likely defects)
-	if (source->mode &  PM_SOURCE_BLEND) continue;
-	if (source->type == PM_SOURCE_DEFECT) continue; 
-	if (source->type == PM_SOURCE_SATURATED) continue;
+	if (source->mode &  PM_SOURCE_MODE_BLEND) continue;
+	if (source->type == PM_SOURCE_TYPE_DEFECT) continue; 
+	if (source->type == PM_SOURCE_TYPE_SATURATED) continue;
 
 	// limit selection to some SN limit
@@ -45,5 +45,5 @@
 
 	// replace object in image
-	pmSourceAddModel (source->pixels, source->mask, source->modelPSF, false, false);
+	pmModelAdd (source->pixels, source->mask, source->modelPSF, false, false);
 	Nfit ++;
 
@@ -57,7 +57,7 @@
 
 	// re-subtract PSF for object, leave local sky
-	pmSourceSubModel (source->pixels, source->mask, source->modelPSF, false, false);
-	source->mode |= PM_SOURCE_SUBTRACTED;
-	source->mode |= PM_SOURCE_TEMPSUB;
+	pmModelSub (source->pixels, source->mask, source->modelPSF, false, false);
+	source->mode |= PM_SOURCE_MODE_SUBTRACTED;
+	source->mode |= PM_SOURCE_MODE_TEMPSUB;
     }
 
Index: /trunk/psphot/src/psphotChoosePSF.c
===================================================================
--- /trunk/psphot/src/psphotChoosePSF.c	(revision 6714)
+++ /trunk/psphot/src/psphotChoosePSF.c	(revision 6715)
@@ -34,5 +34,5 @@
     for (int i = 0; (i < sources->n) && (stars->n < NSTARS); i++) {
 	pmSource *source = sources->data[i];
-	if (source->mode & PM_SOURCE_PSFSTAR) psArrayAdd (stars, 200, source);
+	if (source->mode & PM_SOURCE_MODE_PSFSTAR) psArrayAdd (stars, 200, source);
     }
     psLogMsg ("psphot.pspsf", 4, "selected candidate %d PSF objects\n", stars->n);
@@ -90,5 +90,5 @@
 	pmSource *source = try->sources->data[i];
 	if (try->mask->data.U8[i] & PSFTRY_MASK_EXT_FAIL) {
-	    source->mode &= ~PM_SOURCE_PSFSTAR;
+	    source->mode &= ~PM_SOURCE_MODE_PSFSTAR;
 	}
     }
Index: /trunk/psphot/src/psphotCleanup.c
===================================================================
--- /trunk/psphot/src/psphotCleanup.c	(revision 6714)
+++ /trunk/psphot/src/psphotCleanup.c	(revision 6715)
@@ -6,8 +6,8 @@
     psMemCheckCorruption (true);
     pmModelGroupCleanup ();
-    psphotOutputCleanup ();
+//    psphotOutputCleanup ();
     psTimeFinalize ();
     pmConceptsDone ();
-    fprintf (stderr, "found %d leaks at %s\n", psMemCheckLeaks (0, NULL, NULL, false), "psphot");
+    fprintf (stderr, "found %d leaks at %s\n", psMemCheckLeaks (0, NULL, stdout, false), "psphot");
     return;
 }
Index: /trunk/psphot/src/psphotEnsemblePSF.c
===================================================================
--- /trunk/psphot/src/psphotEnsemblePSF.c	(revision 6714)
+++ /trunk/psphot/src/psphotEnsemblePSF.c	(revision 6715)
@@ -44,10 +44,10 @@
 	// skip non-astronomical objects (very likely defects)
 	// XXX EAM : should we try these anyway?
-	if (inSource->type == PM_SOURCE_DEFECT) continue; 
-	if (inSource->type == PM_SOURCE_SATURATED) continue;
+	if (inSource->type == PM_SOURCE_TYPE_DEFECT) continue; 
+	if (inSource->type == PM_SOURCE_TYPE_SATURATED) continue;
 	if (final) {
-	    if (inSource->mode &  PM_SOURCE_SUBTRACTED) continue;
+	    if (inSource->mode &  PM_SOURCE_MODE_SUBTRACTED) continue;
 	} else {
-	    if (inSource->mode &  PM_SOURCE_BLEND) continue;
+	    if (inSource->mode &  PM_SOURCE_MODE_BLEND) continue;
 	}
 
@@ -61,5 +61,5 @@
 	// really saturated stars should be re-measured for a better centroid
 	// XXX EAM : move this to a 'clear satstar function'
-	if (inSource->mode &  PM_SOURCE_SATSTAR) {
+	if (inSource->mode &  PM_SOURCE_MODE_SATSTAR) {
 	    status = pmSourceMoments (inSource, INNER_RADIUS);
 	}
@@ -68,5 +68,5 @@
 	// use the source moments, etc to guess basic model parameters
 	pmModel *modelEXT = pmSourceModelGuess (inSource, psf->type); 
-	if (inSource->mode &  PM_SOURCE_SATSTAR) {
+	if (inSource->mode &  PM_SOURCE_MODE_SATSTAR) {
 	    modelEXT->params->data.F32[2] = inSource->moments->x;
 	    modelEXT->params->data.F32[3] = inSource->moments->y;
@@ -118,9 +118,9 @@
 	// fill in the model pixel values
 	psImageInit (flux, 0.0);
-	psImageKeepCircle (mask, x, y, model->radius, "OR", PSPHOT_MASK_MARKED);
-	pmSourceAddModel (flux, mask, model, false, false);
+	psImageKeepCircle (mask, x, y, model->radius, "OR", PM_SOURCE_MASK_MARKED);
+	pmModelAdd (flux, mask, model, false, false);
 
 	// calculate nDOF (nPix - 1)
-	// int Nmaskpix = psImageCountPixelMask (mask, allArray, PSPHOT_MASK_SATURATED);
+	// int Nmaskpix = psImageCountPixelMask (mask, allArray, PM_SOURCE_MASK_SATURATED);
 	// model->nDOF  = mask->numCols*mask->numRows - Nmaskpix - 1;
 
@@ -195,7 +195,7 @@
 
 	// subtract object
-	pmSourceSubModel (Fi->pixels, Fi->mask, Fi->modelPSF, false, false);
-	Fi->mode |= PM_SOURCE_SUBTRACTED;
-	if (!final) Fi->mode |= PM_SOURCE_TEMPSUB;
+	pmModelSub (Fi->pixels, Fi->mask, Fi->modelPSF, false, false);
+	Fi->mode |= PM_SOURCE_MODE_SUBTRACTED;
+	if (!final) Fi->mode |= PM_SOURCE_MODE_TEMPSUB;
     }
 
@@ -209,7 +209,7 @@
 	y = model->params->data.F32[3];
 
-	psImageKeepCircle (Fi->mask, x, y, model->radius, "OR", PSPHOT_MASK_MARKED);
+	psImageKeepCircle (Fi->mask, x, y, model->radius, "OR", PM_SOURCE_MASK_MARKED);
 	pmSourceChisq (model, Fi->pixels, Fi->mask, Fi->weight);
-	psImageKeepCircle (Fi->mask, x, y, model->radius, "AND", ~PSPHOT_MASK_MARKED);
+	psImageKeepCircle (Fi->mask, x, y, model->radius, "AND", ~PM_SOURCE_MASK_MARKED);
     }
 
Index: /trunk/psphot/src/psphotEvalFLT.c
===================================================================
--- /trunk/psphot/src/psphotEvalFLT.c	(revision 6714)
+++ /trunk/psphot/src/psphotEvalFLT.c	(revision 6715)
@@ -7,5 +7,5 @@
     // do we actually have a valid EXT model?
     if (model == NULL) {
-	source->mode &= ~PM_SOURCE_FITTED;
+	source->mode &= ~PM_SOURCE_MODE_FITTED;
 	return false;
     }
@@ -16,5 +16,5 @@
 	break;
       case PM_MODEL_UNTRIED:
-	source->mode &= ~PM_SOURCE_FITTED; 
+	source->mode &= ~PM_SOURCE_MODE_FITTED; 
 	return false;
       case PM_MODEL_BADARGS:
@@ -23,17 +23,17 @@
       default:
 	psLogMsg ("psphot", 5, "EXT fail fit\n");
-	source->mode |= PM_SOURCE_FAIL;
+	source->mode |= PM_SOURCE_MODE_FAIL;
 	return false;
     }
 
     // unless we prove otherwise, this object is extended
-    source->type = PM_SOURCE_EXTENDED;
+    source->type = PM_SOURCE_TYPE_EXTENDED;
 
     // the following source->mode information pertains to modelEXT:
-    source->mode |= PM_SOURCE_EXTMODEL;
+    source->mode |= PM_SOURCE_MODE_EXTMODEL;
 
     // if the object has a fitted peak below 0, the fit did not converge cleanly
     if (model->params->data.F32[1] <= 0) {
-	source->mode |= PM_SOURCE_FAIL;
+	source->mode |= PM_SOURCE_MODE_FAIL;
 	return false;
     } 
@@ -44,5 +44,5 @@
     // poor-quality fit; only keep if nothing else works...
     psLogMsg ("psphot", 5, "EXT poor fit\n");
-    source->mode |= PM_SOURCE_POOR;
+    source->mode |= PM_SOURCE_MODE_POOR;
     return false;
 }	
Index: /trunk/psphot/src/psphotEvalPSF.c
===================================================================
--- /trunk/psphot/src/psphotEvalPSF.c	(revision 6714)
+++ /trunk/psphot/src/psphotEvalPSF.c	(revision 6715)
@@ -54,5 +54,5 @@
     // do we actually have a valid PSF model?
     if (model == NULL) {
-	source->mode &= ~PM_SOURCE_FITTED;
+	source->mode &= ~PM_SOURCE_MODE_FITTED;
 	return false;
     }
@@ -63,5 +63,5 @@
 	break;
       case PM_MODEL_UNTRIED:
-	source->mode &= ~PM_SOURCE_FITTED; 
+	source->mode &= ~PM_SOURCE_MODE_FITTED; 
 	return false;
       case PM_MODEL_BADARGS:
@@ -69,13 +69,13 @@
       case PM_MODEL_OFFIMAGE:
       default:
-	source->mode |= PM_SOURCE_FAIL;
+	source->mode |= PM_SOURCE_MODE_FAIL;
 	return false;
     }
 
     // unless we prove otherwise, this object is a star.
-    source->type = PM_SOURCE_STAR;
+    source->type = PM_SOURCE_TYPE_STAR;
 
     // the following source->mode information pertains to modelPSF:
-    source->mode |= PM_SOURCE_PSFMODEL;
+    source->mode |= PM_SOURCE_MODE_PSFMODEL;
 
     // if the object has fitted peak above saturation, label as SATSTAR
@@ -84,8 +84,8 @@
     // XXX no extended object can saturate and stay extended...
     if (model->params->data.F32[1] >= SATURATION) {
-	if (source->mode & PM_SOURCE_PSFSTAR) {
+	if (source->mode & PM_SOURCE_MODE_PSFSTAR) {
 	    psLogMsg ("psphot", 5, "PSFSTAR marked SATSTAR\n");
 	}
-	source->mode |=  PM_SOURCE_SATSTAR;
+	source->mode |=  PM_SOURCE_MODE_SATSTAR;
 	return true;
     } 
@@ -93,5 +93,5 @@
     // if the object has a fitted peak below 0, the fit did not converge cleanly
     if (model->params->data.F32[1] <= 0) {
-	source->mode |= PM_SOURCE_FAIL;
+	source->mode |= PM_SOURCE_MODE_FAIL;
 	return false;
     } 
@@ -99,7 +99,7 @@
     // if the source was predicted to be a SATSTAR, but it fitted below saturation, 
     // make a note to the user
-    if (source->mode & PM_SOURCE_SATSTAR) {
+    if (source->mode & PM_SOURCE_MODE_SATSTAR) {
 	psLogMsg ("psphot", 5, "SATSTAR marked normal (fitted peak below saturation)\n");
-	source->mode &= ~PM_SOURCE_SATSTAR;
+	source->mode &= ~PM_SOURCE_MODE_SATSTAR;
     }
 
@@ -115,5 +115,5 @@
     nSy = dSY / hypot (MIN_DS, 1 / (SY * SN));
 
-    // assign PM_SOURCE_GOODSTAR to bright objects within PSF region of dparams[]
+    // assign PM_SOURCE_MODE_GOODSTAR to bright objects within PSF region of dparams[]
     keep = TRUE;
     keep &= (fabs(nSx) < PSF_SHAPE_NSIGMA);
@@ -124,5 +124,5 @@
 
     // this source is not a star, warn if it was a PSFSTAR
-    if (source->mode & PM_SOURCE_PSFSTAR) {
+    if (source->mode & PM_SOURCE_MODE_PSFSTAR) {
 	psLogMsg ("psphot", 5, "PSFSTAR demoted based on fit quality   (%f, %f  :  %f %f %f %f)\n", 
 		  model->params->data.F32[2], model->params->data.F32[3], nSx, nSy, SN, Chi);
@@ -134,5 +134,5 @@
     // object appears to be small, suspected defect
     if ((nSx <= -PSF_SHAPE_NSIGMA) || (nSy <= -PSF_SHAPE_NSIGMA)) {
-	source->type = PM_SOURCE_DEFECT;
+	source->type = PM_SOURCE_TYPE_DEFECT;
 	return false;
     }
@@ -140,10 +140,10 @@
     // object appears to be large, suspected extended source
     if ((nSx >= PSF_SHAPE_NSIGMA) || (nSy >= PSF_SHAPE_NSIGMA)) {
-	source->type = PM_SOURCE_EXTENDED;
+	source->type = PM_SOURCE_TYPE_EXTENDED;
 	return false;
     }
 
     // poor-quality fit; only keep if nothing else works...
-    source->mode |= PM_SOURCE_POOR;
+    source->mode |= PM_SOURCE_MODE_POOR;
     return false;
 }	
@@ -155,5 +155,5 @@
     // do we actually have a valid PSF model?
     if (model == NULL) {
-	source->mode &= ~PM_SOURCE_FITTED;
+	source->mode &= ~PM_SOURCE_MODE_FITTED;
 	return false;
     }
@@ -164,5 +164,5 @@
 	break;
       case PM_MODEL_UNTRIED:
-	source->mode &= ~PM_SOURCE_FITTED; 
+	source->mode &= ~PM_SOURCE_MODE_FITTED; 
 	return false;
       case PM_MODEL_BADARGS:
@@ -170,13 +170,13 @@
       case PM_MODEL_OFFIMAGE:
       default:
-	source->mode |= PM_SOURCE_FAIL;
+	source->mode |= PM_SOURCE_MODE_FAIL;
 	return false;
     }
 
     // unless we prove otherwise, this object is a star.
-    source->type = PM_SOURCE_STAR;
+    source->type = PM_SOURCE_TYPE_STAR;
 
     // the following source->mode information pertains to modelPSF:
-    source->mode |= PM_SOURCE_PSFMODEL;
+    source->mode |= PM_SOURCE_MODE_PSFMODEL;
 
     // if the object has fitted peak above saturation, label as SATSTAR
@@ -185,8 +185,8 @@
     // XXX no extended object can saturate and stay extended...
     if (model->params->data.F32[1] >= SATURATION) {
-	if (source->mode & PM_SOURCE_PSFSTAR) {
+	if (source->mode & PM_SOURCE_MODE_PSFSTAR) {
 	    psLogMsg ("psphot", 5, "PSFSTAR marked SATSTAR\n");
 	}
-	source->mode |=  PM_SOURCE_SATSTAR;
+	source->mode |=  PM_SOURCE_MODE_SATSTAR;
 	return true;
     } 
@@ -194,5 +194,5 @@
     // if the object has a fitted peak below 0, the fit did not converge cleanly
     if (model->params->data.F32[1] <= 0) {
-	source->mode |= PM_SOURCE_FAIL;
+	source->mode |= PM_SOURCE_MODE_FAIL;
 	return false;
     } 
@@ -200,7 +200,7 @@
     // if the source was predicted to be a SATSTAR, but it fitted below saturation, 
     // make a note to the user
-    if (source->mode & PM_SOURCE_SATSTAR) {
+    if (source->mode & PM_SOURCE_MODE_SATSTAR) {
 	psLogMsg ("psphot", 5, "SATSTAR marked normal (fitted peak below saturation)\n");
-	source->mode &= ~PM_SOURCE_SATSTAR;
+	source->mode &= ~PM_SOURCE_MODE_SATSTAR;
     }
     return true;
Index: /trunk/psphot/src/psphotFakeSources.c
===================================================================
--- /trunk/psphot/src/psphotFakeSources.c	(revision 6715)
+++ /trunk/psphot/src/psphotFakeSources.c	(revision 6715)
@@ -0,0 +1,49 @@
+# include "psphot.h"
+
+# if (0)
+psArray *psphotFakeSources () {
+
+    // psphotUpdateHeader (header, config);
+
+    psArray *sources = psArrayAlloc (50);
+
+    for (int i = 0; i < sources->n; i++) {
+	pmSource *source = pmSourceAlloc ();
+	modelType = pmModelSetType ("PS_MODEL_QGAUSS");
+	source->modelPSF = pmSourceModelGuess (source, modelType);
+	source->peak = pmPeakAlloc (10, 10, 0, 0);
+	sources->data[i] = source;
+    }
+    return sources;
+}
+# endif
+
+psArray *psphotFakeSources () {
+
+    // psphotUpdateHeader (header, config);
+
+    psArray *sources = psArrayAlloc (50);
+    sources->n = 50;
+
+    for (int i = 0; i < sources->n; i++) {
+	pmSource *source = pmSourceAlloc ();
+	source->moments = pmMomentsAlloc ();
+	source->moments->x = 10;
+	source->moments->y = 10;
+	source->moments->Sx = 1;
+	source->moments->Sy = 1;
+	source->moments->Sxy = 0;
+	source->moments->Sum = 1000;
+	source->moments->Peak = 100;
+	source->moments->Sky = 10;
+	source->moments->nPixels = 10;
+
+	source->peak = pmPeakAlloc (10, 10, 0, 0);
+	source->type = PM_SOURCE_TYPE_STAR;
+
+	pmModelType modelType = pmModelSetType ("PS_MODEL_QGAUSS");
+	source->modelPSF = pmSourceModelGuess (source, modelType);
+	sources->data[i] = source;
+    }
+    return sources;
+}
Index: /trunk/psphot/src/psphotFitGalaxies.c
===================================================================
--- /trunk/psphot/src/psphotFitGalaxies.c	(revision 6714)
+++ /trunk/psphot/src/psphotFitGalaxies.c	(revision 6715)
@@ -23,6 +23,6 @@
 
 	// only fit suspected extended sources
-	if (source->type != PM_SOURCE_EXTENDED) continue;
-	if (source->mode  & PM_SOURCE_BLEND) continue; 
+	if (source->type != PM_SOURCE_TYPE_EXTENDED) continue;
+	if (source->mode  & PM_SOURCE_MODE_BLEND) continue; 
 
 	// skip possible extended sources below fit threshold
@@ -32,5 +32,5 @@
 	status = pmSourceMoments (source, EXT_MOMENTS_RAD);
 	if (!status) {
-	  source->mode |= PM_SOURCE_FAIL;  // better choice?
+	  source->mode |= PM_SOURCE_MODE_FAIL;  // better choice?
 	  continue;
 	}
@@ -46,7 +46,7 @@
 
 	// fit EXT (not PSF) model (set/unset the pixel mask)
-	psImageKeepCircle (source->mask, x, y, model->radius, "OR", PSPHOT_MASK_MARKED);
+	psImageKeepCircle (source->mask, x, y, model->radius, "OR", PM_SOURCE_MASK_MARKED);
 	pmSourceFitModel (source, model, false);
-	psImageKeepCircle (source->mask, x, y, model->radius, "AND", ~PSPHOT_MASK_MARKED);
+	psImageKeepCircle (source->mask, x, y, model->radius, "AND", ~PM_SOURCE_MASK_MARKED);
 
 	Niter += model[0].nIter;
@@ -55,7 +55,7 @@
 	// check if model fit is acceptable
 	if (pmModelFitStatus (model)) {
-	    pmSourceSubModel (source->pixels, source->mask, model, false, false);
-	    source->mode |=  PM_SOURCE_SUBTRACTED;
-	    source->mode &= ~PM_SOURCE_TEMPSUB;
+	    pmModelSub (source->pixels, source->mask, model, false, false);
+	    source->mode |=  PM_SOURCE_MODE_SUBTRACTED;
+	    source->mode &= ~PM_SOURCE_MODE_TEMPSUB;
 	    Nsub ++;
 	}
Index: /trunk/psphot/src/psphotFitSet.c
===================================================================
--- /trunk/psphot/src/psphotFitSet.c	(revision 6714)
+++ /trunk/psphot/src/psphotFitSet.c	(revision 6715)
@@ -32,5 +32,5 @@
     for (int i = 0; i < modelSet->n; i++) {
 	pmModel *model = modelSet->data[i];
-	pmSourceSubModel (source->pixels, source->mask, model, false, false);
+	pmModelSub (source->pixels, source->mask, model, false, false);
     
 	fprintf (stderr, "output parameters (obj %d):\n", i);
Index: /trunk/psphot/src/psphotFullFit.c
===================================================================
--- /trunk/psphot/src/psphotFullFit.c	(revision 6714)
+++ /trunk/psphot/src/psphotFullFit.c	(revision 6715)
@@ -32,7 +32,7 @@
 	// skip non-astronomical objects (very likely defects)
 	// XXX EAM : should we try these anyway?
-	if (source->mode &  PM_SOURCE_BLEND) continue;
-	if (source->type == PM_SOURCE_DEFECT) continue; 
-	if (source->type == PM_SOURCE_SATURATED) continue;
+	if (source->mode &  PM_SOURCE_MODE_BLEND) continue;
+	if (source->type == PM_SOURCE_TYPE_DEFECT) continue; 
+	if (source->type == PM_SOURCE_TYPE_SATURATED) continue;
 
 	// save the PSF model from the Ensemble fit
@@ -43,6 +43,6 @@
 
 	// replace object in image
-	pmSourceAddModel (source->pixels, source->mask, modelPSF, false, false);
-	source->mode &= ~PM_SOURCE_SUBTRACTED;
+	pmModelAdd (source->pixels, source->mask, modelPSF, false, false);
+	source->mode &= ~PM_SOURCE_MODE_SUBTRACTED;
 
 	psphotCheckRadiusPSF (readout, source, modelPSF);
@@ -52,7 +52,7 @@
 
 	// fit PSF model (set/unset the pixel mask)
-	psImageKeepCircle (source->mask, x, y, modelPSF->radius, "OR", PSPHOT_MASK_MARKED);
+	psImageKeepCircle (source->mask, x, y, modelPSF->radius, "OR", PM_SOURCE_MASK_MARKED);
 	pmSourceFitModel (source, modelPSF, true);
-	psImageKeepCircle (source->mask, x, y, modelPSF->radius, "AND", ~PSPHOT_MASK_MARKED);
+	psImageKeepCircle (source->mask, x, y, modelPSF->radius, "AND", ~PM_SOURCE_MASK_MARKED);
 
 	// track model evaluations
@@ -62,7 +62,7 @@
 	// does the PSF model succeed?
 	if (psphotEvalPSF (source, source->modelPSF)) {
-	    pmSourceSubModel (source->pixels, source->mask, source->modelPSF, false, false);
-	    source->mode |=  PM_SOURCE_SUBTRACTED;
-	    source->mode &= ~PM_SOURCE_TEMPSUB;
+	    pmModelSub (source->pixels, source->mask, source->modelPSF, false, false);
+	    source->mode |=  PM_SOURCE_MODE_SUBTRACTED;
+	    source->mode &= ~PM_SOURCE_MODE_TEMPSUB;
 	    psFree (LIN);
 	    Nsub ++;
@@ -82,5 +82,5 @@
 
 	// skip the source if we don't think it is extended
-	if (source->type != PM_SOURCE_EXTENDED) goto subLINEAR;
+	if (source->type != PM_SOURCE_TYPE_EXTENDED) goto subLINEAR;
 	if (source->moments->SN < EXT_MIN_SN) goto subLINEAR;
 
@@ -101,7 +101,7 @@
 
 	// fit EXT (not PSF) model (set/unset the pixel mask)
-	psImageKeepCircle (source->mask, x, y, modelEXT->radius, "OR", PSPHOT_MASK_MARKED);
+	psImageKeepCircle (source->mask, x, y, modelEXT->radius, "OR", PM_SOURCE_MASK_MARKED);
 	pmSourceFitModel (source, modelEXT, false);
-	psImageKeepCircle (source->mask, x, y, modelEXT->radius, "AND", ~PSPHOT_MASK_MARKED);
+	psImageKeepCircle (source->mask, x, y, modelEXT->radius, "AND", ~PM_SOURCE_MASK_MARKED);
 
 	// track model evaluations
@@ -111,7 +111,7 @@
 	// does the EXT model succeed?
 	if (psphotEvalEXT (source, source->modelEXT)) {
-	    pmSourceSubModel (source->pixels, source->mask, source->modelEXT, false, false);
-	    source->mode |=  PM_SOURCE_SUBTRACTED;
-	    source->mode &= ~PM_SOURCE_TEMPSUB;
+	    pmModelSub (source->pixels, source->mask, source->modelEXT, false, false);
+	    source->mode |=  PM_SOURCE_MODE_SUBTRACTED;
+	    source->mode &= ~PM_SOURCE_MODE_TEMPSUB;
 	    psFree (LIN);
 	    Nsub ++;
@@ -123,7 +123,7 @@
 	psFree (source->modelPSF);
 	source->modelPSF = LIN;
-	pmSourceSubModel (source->pixels, source->mask, source->modelPSF, false, false);
-	source->mode |= PM_SOURCE_SUBTRACTED;
-	source->mode |= PM_SOURCE_TEMPSUB;
+	pmModelSub (source->pixels, source->mask, source->modelPSF, false, false);
+	source->mode |= PM_SOURCE_MODE_SUBTRACTED;
+	source->mode |= PM_SOURCE_MODE_TEMPSUB;
 	Nsub ++;
     }
Index: /trunk/psphot/src/psphotGrowthCurve.c
===================================================================
--- /trunk/psphot/src/psphotGrowthCurve.c	(revision 6714)
+++ /trunk/psphot/src/psphotGrowthCurve.c	(revision 6715)
@@ -16,6 +16,6 @@
 
     // use center of the image 
-    xc = 0.5*(readout->image->numCols + readout->image->col0);
-    yc = 0.5*(readout->image->numRows + readout->image->row0);
+    xc = 0.5*readout->image->numCols + readout->image->col0;
+    yc = 0.5*readout->image->numRows + readout->image->row0;
     dx = psf->growth->maxRadius + 1;
     dy = psf->growth->maxRadius + 1;
@@ -45,14 +45,15 @@
 	radius = psf->growth->radius->data.F32[i];
 
-	psImageKeepCircle (mask, xc, yc, radius, "OR", PSPHOT_MASK_MARKED);
+	psImageKeepCircle (mask, xc, yc, radius, "OR", PM_SOURCE_MASK_MARKED);
 
-	pmSourceAddModel (image, mask, model, false, false);
+	pmModelAdd (image, mask, model, false, false);
 
-	pmSourcePhotometry (&fitMag, &apMag, model, image, mask);
+	pmSourcePhotometryAper (&apMag, model, image, mask);
 
-	psImageKeepCircle (mask, xc, yc, radius, "AND", ~PSPHOT_MASK_MARKED);
+	psImageKeepCircle (mask, xc, yc, radius, "AND", ~PM_SOURCE_MASK_MARKED);
 
 	psf->growth->apMag->data.F32[i] = apMag;
     }
+    pmSourcePhotometryModel (&fitMag, model);
     psf->growth->fitMag = fitMag;
 
Index: /trunk/psphot/src/psphotImageLoop.c
===================================================================
--- /trunk/psphot/src/psphotImageLoop.c	(revision 6714)
+++ /trunk/psphot/src/psphotImageLoop.c	(revision 6715)
@@ -1,49 +1,99 @@
 # include "psphot.h"
 
-bool psphotImageLoop (psphotData *data, ppConfig *config) {
+// XXX where do we load optional mask and weight input images?
 
-    pmFPA *fpa = data->input->fpa;
+bool psphotImageLoop (pmConfig *config) {
 
-    psphotDataIO (data, config, -1, -1);
+    bool status;
+    pmChip *chip;
+    pmCell *cell;
+    pmReadout *readout;
 
-    for (int i = 0; i < fpa->chips->n; i++) {
-        pmChip *chip = fpa->chips->data[i]; // Chip of interest in input image
+    pmFPAfile *input = psMetadataLookupPtr (&status, config->files, "PSPHOT.INPUT");
+    if (!status) {
+	psErrorStackPrint(stderr, "Can't find input data!\n");
+	exit(EXIT_FAILURE);
+    }
 
-        psLogMsg ("psphot", 4, "Chip %d: %x %x\n", i, chip->exists, chip->process);
+    pmFPAview *view = pmFPAviewAlloc (0);
+
+    // files associated with the science image
+    pmFPAfileIOChecks (config->files, view, PM_FPA_BEFORE);
+
+    while ((chip = pmFPAviewNextChip (view, input->fpa, 1)) != NULL) {
+        psLogMsg ("psphot", 4, "Chip %d: %x %x\n", view->chip, chip->file_exists, chip->process);
         if (! chip->process) { continue; }
+        if (! chip->file_exists) { continue; }
+	pmFPAfileIOChecks (config->files, view, PM_FPA_BEFORE);
 
-	psphotDataIO (data, config, i, -1);
-
-        for (int j = 0; j < chip->cells->n; j++) {
-            pmCell *cell = chip->cells->data[j]; // Cell of interest in input image
-
-            psLogMsg ("psphot", 4, "Cell %d: %x %x\n", j, cell->exists, cell->process);
+	while ((cell = pmFPAviewNextCell (view, input->fpa, 1)) != NULL) {
+	    continue;
+            psLogMsg ("psphot", 4, "Cell %d: %x %x\n", view->cell, cell->file_exists, cell->process);
             if (! cell->process) { continue; }
-
-	    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
-	    pmCellSetWeights(cell);
-
-	    // I have a valid mask, now mask in the analysis region of interest
-	    pmCellSetMask (cell, config->recipe); 
+	    if (! cell->file_exists) { continue; }
+	    pmFPAfileIOChecks (config->files, view, PM_FPA_BEFORE);
 
 	    // process each of the readouts
-	    for (int k = 0; k < cell->readouts->n; k++) {
-		pmReadout *readout = cell->readouts->data[k]; // Readout of interest in input image
+	    while ((readout = pmFPAviewNextReadout (view, input->fpa, 1)) != NULL) {
+		pmFPAfileIOChecks (config->files, view, PM_FPA_BEFORE);
+		if (! readout->data_exists) { continue; }
 
 		// run a single-model test if desired
-		psphotModelTest (readout, config->arguments, config->recipe);
+		// XXX move this to psphotReadout??
+		// psphotModelTest (readout, recipe);
 
 		// run the actual photometry analysis
-		psphotReadout (readout, data, config);
+		psphotReadout (config, view);
 
-		// XXX what do we do if we have multiple readouts?
-		psphotOutput (readout, data, config);
+		pmFPAfileIOChecks (config->files, view, PM_FPA_AFTER);
+
+		// write out the desired output dataset(s)
+		// psphotOutput (view, recipe);
 	    }
-        }
+	    pmFPAfileIOChecks (config->files, view, PM_FPA_AFTER);
+	}
+	pmFPAfileIOChecks (config->files, view, PM_FPA_AFTER);
     }
-    psphotOutputClose (data);
+    pmFPAfileIOChecks (config->files, view, PM_FPA_AFTER);
+
+    psFree (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
+
+**/
Index: /trunk/psphot/src/psphotImageMedian.c
===================================================================
--- /trunk/psphot/src/psphotImageMedian.c	(revision 6714)
+++ /trunk/psphot/src/psphotImageMedian.c	(revision 6715)
@@ -11,5 +11,5 @@
 // generate the median in NxN boxes, clipping heavily
 // linear interpolation to generate full-scale model
-psImage *psphotImageMedian (psMetadata *config, pmFPAview *view) 
+bool psphotImageMedian (pmConfig *config, pmFPAview *view) 
 { 
     bool status;
@@ -21,6 +21,6 @@
     // find the currently selected readout
     psMetadata *recipe  = psMetadataLookupPtr (&status, config->recipes, "PSPHOT");
-    pmFPA *input = psMetadataLookupPtr (&status, config->files, "PSPHOT.INPUT");
-    pmReadout  *readout = pmFPAviewThisReadout (view, input);
+    pmFPAfile  *input   = psMetadataLookupPtr (&status, config->files, "PSPHOT.INPUT");
+    pmReadout  *readout = pmFPAviewThisReadout (view, input->fpa);
 
     psImage *image = readout->image;
@@ -28,5 +28,5 @@
 
     rnd = psRandomAlloc (PS_RANDOM_TAUS, 0);
-    MAX_SAMPLE_PIXELS = psMetadataLookupF32 (&status, config, "IMSTATS_NPIX");
+    MAX_SAMPLE_PIXELS = psMetadataLookupF32 (&status, recipe, "IMSTATS_NPIX");
     if (!status) MAX_SAMPLE_PIXELS = 1000;
 
@@ -36,7 +36,7 @@
 
     // scaling factor
-    int DX = psMetadataLookupS32 (&status, config, "BACKGROUND_XBIN");
+    int DX = psMetadataLookupS32 (&status, recipe, "BACKGROUND_XBIN");
     if (!status) {DX = 64;}
-    int DY = psMetadataLookupS32 (&status, config, "BACKGROUND_YBIN");
+    int DY = psMetadataLookupS32 (&status, recipe, "BACKGROUND_YBIN");
     if (!status) {DY = 64;}
 
@@ -79,5 +79,5 @@
 
     // select background pixels, from output background file, or create
-    background = pmFPAfileReadoutImage (config->files, view, "PSPHOT.BACKGND", Nx, Ny, PS_TYPE_F32);
+    psImage *background = pmFPAfileReadoutImage (config->files, view, "PSPHOT.BACKGND", Nx, Ny, PS_TYPE_F32);
 
     // XXX this code skips the initial pixels
@@ -212,5 +212,5 @@
 
     // back-sub image pixels, from output background file (don't create if not requested)
-    backSub = pmFPAfileReadoutImage (config->files, view, "PSPHOT.BACKSUB", 0, 0, PS_TYPE_F32);
+    psImage *backSub = pmFPAfileReadoutImage (config->files, view, "PSPHOT.BACKSUB", 0, 0, PS_TYPE_F32);
 
     // subtract the background model
Index: /trunk/psphot/src/psphotMagnitudes.c
===================================================================
--- /trunk/psphot/src/psphotMagnitudes.c	(revision 6714)
+++ /trunk/psphot/src/psphotMagnitudes.c	(revision 6715)
@@ -1,5 +1,5 @@
 # include "psphot.h"
 
-bool psphotMagnitudes (psMetadata *config, psArray *sources, pmPSF *psf) {
+bool psphotMagnitudes (psArray *sources, psMetadata *config, pmPSF *psf) {
 
     bool status;
Index: /trunk/psphot/src/psphotMaskReadout.c
===================================================================
--- /trunk/psphot/src/psphotMaskReadout.c	(revision 6715)
+++ /trunk/psphot/src/psphotMaskReadout.c	(revision 6715)
@@ -0,0 +1,26 @@
+# include "psphot.h"
+
+// 2006.02.04 : no leaks
+bool psphotMaskReadout (pmReadout *readout, psMetadata *recipe) {
+    
+    bool status;
+
+    // mask the excluded outer pixels
+    // these coordinates refer to the parent image
+    // these bounds will saturate on the subimage
+    // negative upper bounds will subtract from the *subimage*
+    float XMIN  = psMetadataLookupF32 (&status, recipe, "XMIN");
+    float XMAX  = psMetadataLookupF32 (&status, recipe, "XMAX");
+    float YMIN  = psMetadataLookupF32 (&status, recipe, "YMIN");
+    float YMAX  = psMetadataLookupF32 (&status, recipe, "YMAX");
+    psRegion valid = psRegionSet (XMIN, XMAX, YMIN, YMAX);
+
+    // psRegionForImage creates a region for the subimage, not the parent
+    // XXX I propose that psRegionForImage treat the region as referring to the parent...
+    psRegion keep = psRegionForImage (readout->image, valid);
+
+    // psImageKeepRegion assumes the region refers to the parent coordinates
+    psImageKeepRegion (readout->mask, keep, "OR", PM_SOURCE_MASK_INVALID);
+
+    return true;
+}
Index: /trunk/psphot/src/psphotModelTest.c
===================================================================
--- /trunk/psphot/src/psphotModelTest.c	(revision 6714)
+++ /trunk/psphot/src/psphotModelTest.c	(revision 6715)
@@ -84,5 +84,5 @@
     pmSource *source = pmSourceAlloc();
     source->peak = pmPeakAlloc (xObj, yObj, 0, 0);
-    psphotDefinePixels (source, readout, xObj, yObj, OUTER);
+    pmSourceDefinePixels (source, readout, xObj, yObj, OUTER);
 
     // find the local sky
@@ -170,5 +170,5 @@
 
     // subtract object, leave local sky
-    pmSourceSubModel (source->pixels, source->mask, model, false, false);
+    pmModelSub (source->pixels, source->mask, model, false, false);
     
     fprintf (stderr, "output parameters: \n");
Index: /trunk/psphot/src/psphotOutput.c
===================================================================
--- /trunk/psphot/src/psphotOutput.c	(revision 6714)
+++ /trunk/psphot/src/psphotOutput.c	(revision 6715)
@@ -1,4 +1,5 @@
 # include "psphot.h"
 
+# if (0)
 // output functions: we have several fixed modes (sx, obj, cmp)
 void psphotOutput (pmReadout *readout, psMetadata *arguments) {
@@ -21,12 +22,4 @@
 }
 
-int psphotSaveImage (psMetadata *header, psImage *image, char *filename) {
-
-    psFits *fits = psFitsOpen (filename, "w");
-    psFitsWriteImage (fits, NULL, image, 0);
-    psFitsClose (fits);
-    return (TRUE);
-}
-
 psImage *pmModelPSFatXY (psImage *image, pmModel *modelEXT, pmPSF *psf, int x, int y, int dx, int dy) {
 
@@ -38,5 +31,5 @@
     modelEXT->params->data.F32[3] = y;
     pmModel *modelPSF = pmModelFromPSF (modelEXT, psf);
-    pmSourceAddModel (sample, NULL, modelPSF, false, false);
+    pmModelAdd (sample, NULL, modelPSF, false, false);
     psFree (modelPSF);
     return (sample);
@@ -69,4 +62,13 @@
     psFitsWriteImage (fits, NULL, sample, 0);
 
+    psFitsClose (fits);
+    return (TRUE);
+}
+# endif
+
+int psphotSaveImage (psMetadata *header, psImage *image, char *filename) {
+
+    psFits *fits = psFitsOpen (filename, "w");
+    psFitsWriteImage (fits, NULL, image, 0, NULL);
     psFitsClose (fits);
     return (TRUE);
Index: /trunk/psphot/src/psphotParseCamera.c
===================================================================
--- /trunk/psphot/src/psphotParseCamera.c	(revision 6714)
+++ /trunk/psphot/src/psphotParseCamera.c	(revision 6715)
@@ -1,24 +1,22 @@
 # include "psphot.h"
-
-# define METADATA_ADD_DEFAULT(CONFIG, TYPE, NAME, VALUE, COMMENT)\
-    { psMetadataItem *ITEM; \
-      ITEM = psMetadataLookup (CONFIG, NAME); \
-      if (ITEM == NULL) { \
-	psMetadataAdd##TYPE (CONFIG, PS_LIST_TAIL, NAME, 0, COMMENT, VALUE); \
-      } }
 
 bool psphotParseCamera (pmConfig *config) {
 
+    bool status;
+    psFits *fits = NULL;
+    psMetadata *phu = NULL;
+    psMetadata *format = NULL;
+
     // psphot is supplied with a list of input images (may be only one image)
-    psArray *infiles = psMetadataLookupPtr(NULL, config->arguments, "INPUT");
+    psArray *infiles = psMetadataLookupPtr(&status, config->arguments, "INPUT");
+    if (!status) psAbort (__func__, "missing INPUT entry");
     if (infiles->n < 1) psAbort (__func__, "empty input list");
 
     // 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);
+	fits = psFitsOpen (infiles->data[0], "r");
+	phu = psFitsReadHeader (NULL, fits);
+	format = pmConfigCameraFormatFromHeader (config, phu);
 	psFitsClose (fits);
-	psFree (phu);
     }
     // There's no point in continuing if we can't recognize what we've got
@@ -28,45 +26,65 @@
     }
 
-    // XXX place the "data" element on the pmConfig structure?
+    // files
     config->files = psMetadataAlloc ();
 
     // build the template fpa, set up the basic view
-    pmFPA *input = pmFPAConstruct (camera);
+    // XXX : 216 leaks in pmFPAConstruct / psFree (input)
+    pmFPA *input = pmFPAConstruct (config->camera);
 
     // assign the I/O files (potentially) needed by psphot
-    pmFPAfile *file = pmFPAfileDefine (config->files, camera, input, "PSPHOT.INPUT");
+    // the output file is just a view to the file on config->files 
+    pmFPAfile *file = pmFPAfileDefine (config->files, format, input, "PSPHOT.INPUT");
+    if (!file) {
+	exit(EXIT_FAILURE);
+    }
 
-    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);
+	if (phu == NULL) {
+	    fits = psFitsOpen (infiles->data[i], "r");
+	    phu = psFitsReadHeader (NULL, fits);
+	    pmConfigValidateCameraFormat (format, phu);
+	    psFitsClose (fits);
+	}
 
 	// 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);
+	pmFPAview *view = pmFPAAddSource (input, phu, format);
 
 	// XXX is this the correct psMD to save the filename?
-	name = pmFPAviewNameFromRule (file->filextra, view);
+	char *name = pmFPAfileNameFromRule (file->filextra, file, view);
 	psMetadataAddStr (file->names, PS_LIST_TAIL, name, 0, "", infiles->data[i]);
+
+	psFree (view);
+	psFree (name);
+	psFree (phu);
+	phu = NULL;
     }
-    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");
+
+    pmFPAfileDefine (config->files, format, input, "PSPHOT.OUTPUT");
+
+    // pmFPAfileDefine (config->files, format, input, "PSPHOT.RESID");
+    // pmFPAfileDefine (config->files, format, input, "PSPHOT.PSF_INPUT");
+    // pmFPAfileDefine (config->files, format, 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");
+    // allow alternate format?
+    // pmFPAfileConstruct (config->files, format, config->camera, "PSPHOT.BACKSUB");
+    // pmFPAfileConstruct (config->files, format, config->camera, "PSPHOT.BACKGND");
+    // pmFPAfileConstruct (config->files, format, config->camera, "PSPHOT.BACKMDL");
+    // pmFPAfileConstruct (config->files, format, config->camera, "PSPHOT.PSF_SAMPLE");
+
+    // psphot is supplied with the output name
+    char *output = psMetadataLookupPtr(&status, config->arguments, "OUTPUT");
+    file = psMetadataLookupPtr (&status, config->files, "PSPHOT.OUTPUT");
+    if (!status) psAbort (__func__, "missing OUTPUT entry");
+    psMetadataAddStr (file->names, PS_LIST_TAIL, "OUTPUT", 0, "", output);
 
     // recipe override values (command-line options):
-    psMetadata *options = psMetadataLookupPtr (status, config->arguments, "PSPHOT.OPTIONS");
-    psMetadata *recipe = psMetadataLookupPtr (status, config->recipes, "PSPHOT");
+    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) {
+    psMetadataItem *item = NULL;
+    while ((item = psMetadataGetAndIncrement (iter)) != NULL) {
 	psMetadataAddItem (recipe, item, PS_LIST_TAIL, PS_META_REPLACE);
     }
@@ -74,11 +92,11 @@
 
     // set default recipe values here
-    // 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", "");
+    psMetadataAddStr (recipe, PS_LIST_TAIL, "FITMODE", PS_META_NO_REPLACE, "default fitting mode", "NONE");
+    psMetadataAddStr (recipe, PS_LIST_TAIL, "PHOTCODE", PS_META_NO_REPLACE, "default photcode", "NONE");
+    psMetadataAddStr (recipe, PS_LIST_TAIL, "BREAK_POINT", PS_META_NO_REPLACE, "default break point", "NONE");
 
     // Chip selection: if we are using a single chip, select it for each FPA
     // Chip numbers to work on: -chip 1,2,3,5,8,10
+    # if (0)
     char *chips = psMetadataLookupStr(NULL, config->arguments, "CHIP_SELECTIONS"); 
     if (chips != NULL) {
@@ -102,4 +120,9 @@
         }
     }
+    # endif
+
+    psFree (input);
+    psFree (format);
+
     psTrace(__func__, 1, "Done with psphotParseCamera...\n");
     return true;
Index: /trunk/psphot/src/psphotRadiusChecks.c
===================================================================
--- /trunk/psphot/src/psphotRadiusChecks.c	(revision 6714)
+++ /trunk/psphot/src/psphotRadiusChecks.c	(revision 6715)
@@ -26,9 +26,9 @@
     if (isnan(model->radius)) psAbort ("apply_psf_model", "error in radius");
 	
-    if (source->mode &  PM_SOURCE_SATSTAR) {
+    if (source->mode &  PM_SOURCE_MODE_SATSTAR) {
 	model->radius *= 2;
     }
 
-    bool status = psphotRedefinePixels (source, readout, model->params->data.F32[2], model->params->data.F32[3], model->radius);
+    bool status = pmSourceRedefinePixels (source, readout, model->params->data.F32[2], model->params->data.F32[3], model->radius);
     return status;
 }
@@ -43,9 +43,9 @@
     if (isnan(model->radius)) psAbort ("apply_psf_model", "error in radius");
 	
-    if (source->mode &  PM_SOURCE_SATSTAR) {
+    if (source->mode &  PM_SOURCE_MODE_SATSTAR) {
 	model->radius *= 2;
     }
 
-    bool status = psphotRedefinePixels (source, readout, model->params->data.F32[2], model->params->data.F32[3], model->radius);
+    bool status = pmSourceRedefinePixels (source, readout, model->params->data.F32[2], model->params->data.F32[3], model->radius);
     return status;
 }
@@ -77,5 +77,5 @@
 
     // redefine the pixels if needed
-    bool status = psphotRedefinePixels (source, readout, model->params->data.F32[2], model->params->data.F32[3], model->radius);
+    bool status = pmSourceRedefinePixels (source, readout, model->params->data.F32[2], model->params->data.F32[3], model->radius);
     return status;
 }
Index: /trunk/psphot/src/psphotReadout.c
===================================================================
--- /trunk/psphot/src/psphotReadout.c	(revision 6714)
+++ /trunk/psphot/src/psphotReadout.c	(revision 6715)
@@ -12,6 +12,17 @@
     // find the currently selected readout
     psMetadata *recipe  = psMetadataLookupPtr (&status, config->recipes, "PSPHOT");
-    pmFPA *input = psMetadataLookupPtr (&status, config->files, "PSPHOT.INPUT");
-    pmReadout  *readout = pmFPAviewThisReadout (view, input);
+    pmFPAfile  *input   = psMetadataLookupPtr (&status, config->files, "PSPHOT.INPUT");
+    pmReadout  *readout = pmFPAviewThisReadout (view, input->fpa);
+
+    sources = psphotFakeSources();
+    status = psMetadataAdd (readout->analysis, PS_LIST_TAIL, "PSPHOT.SOURCES",   PS_DATA_ARRAY,   "psphot sources", sources);
+    psFree (sources);
+    return true;
+
+    // XXX does this need to invoke I/O?
+    pmReadoutSetWeights (readout);
+
+    // I have a valid mask, now mask in the analysis region of interest
+    psphotMaskReadout (readout, recipe); 
 
     // generate a background model (median, smoothed image)
@@ -58,6 +69,6 @@
     // update the header with stats results
     // XXX need to do this conditionally?
-    psMetadata *header = pmReadoutGetHeader (readout);
-    psphotUpdateHeader (header, config);
+    // XXX psMetadata *header = pmReadoutGetHeader (readout);
+    // XXX psphotUpdateHeader (header, config);
 
     // XXX make this an option?
@@ -99,3 +110,10 @@
     }
 
+
+
+    psphotSaveImage (NULL, readout->image,  "pixels.fits");
+    psphotSaveImage (NULL, readout->weight, "weight.fits");
+    psphotSaveImage (NULL, readout->mask,   "mask.fits");
+    exit (1);
+
 # endif
Index: /trunk/psphot/src/psphotReplaceUnfit.c
===================================================================
--- /trunk/psphot/src/psphotReplaceUnfit.c	(revision 6714)
+++ /trunk/psphot/src/psphotReplaceUnfit.c	(revision 6715)
@@ -10,10 +10,10 @@
       source = sources->data[i];
 
-	if (!(source->mode & PM_SOURCE_TEMPSUB)) continue;
+	if (!(source->mode & PM_SOURCE_MODE_TEMPSUB)) continue;
 	if (source->modelPSF == NULL) continue;
 
-	pmSourceAddModel (source->pixels, source->mask, source->modelPSF, false, false);
-	source->mode &= ~PM_SOURCE_SUBTRACTED;
-	source->mode &= ~PM_SOURCE_TEMPSUB;
+	pmModelAdd (source->pixels, source->mask, source->modelPSF, false, false);
+	source->mode &= ~PM_SOURCE_MODE_SUBTRACTED;
+	source->mode &= ~PM_SOURCE_MODE_TEMPSUB;
     }
     psLogMsg ("psphot.replace", 3, "replace unfitted models: %f sec (%d objects)\n", psTimerMark ("psphot"), sources->n);
Index: /trunk/psphot/src/psphotSkyReplace.c
===================================================================
--- /trunk/psphot/src/psphotSkyReplace.c	(revision 6714)
+++ /trunk/psphot/src/psphotSkyReplace.c	(revision 6715)
@@ -2,10 +2,12 @@
 
 // in order to  successfully replace the sky, we must define a corresponding file...
-bool psphotSkyReplace (psMetadata *config, pmFPAview *view) {
+bool psphotSkyReplace (pmConfig *config, pmFPAview *view) {
+
+    bool status;
 
     // find the currently selected readout
-    psMetadata *recipe  = psMetadataLookupPtr (&status, config->recipes, "PSPHOT");
-    pmFPA *input = psMetadataLookupPtr (&status, config->files, "PSPHOT.INPUT");
-    pmReadout  *readout = pmFPAviewThisReadout (view, input);
+    //  psMetadata *recipe  = psMetadataLookupPtr (&status, config->recipes, "PSPHOT");
+    pmFPAfile *input   = psMetadataLookupPtr (&status, config->files, "PSPHOT.INPUT");
+    pmReadout *readout = pmFPAviewThisReadout (view, input->fpa);
 
     // select the corresponding images
@@ -14,5 +16,5 @@
 
     // select background pixels, from output background file, or create
-    background = pmFPAfileReadoutImage (config->files, view, "PSPHOT.BACKGND", 0, 0, PS_TYPE_F32);
+    psImage *background = pmFPAfileReadoutImage (config->files, view, "PSPHOT.BACKGND", 0, 0, PS_TYPE_F32);
     if (background == NULL) {
 	return false;
Index: /trunk/psphot/src/psphotSourceFits.c
===================================================================
--- /trunk/psphot/src/psphotSourceFits.c	(revision 6714)
+++ /trunk/psphot/src/psphotSourceFits.c	(revision 6715)
@@ -1,4 +1,3 @@
 # include "psphot.h"
-# include "psEllipse.h"
 
 // given a source with an existing modelPSF, attempt a full PSF fit, subtract if successful
@@ -18,7 +17,7 @@
 
     // fit PSF model (set/unset the pixel mask)
-    psImageKeepCircle (source->mask, x, y, PSF->radius, "OR", PSPHOT_MASK_MARKED);
+    psImageKeepCircle (source->mask, x, y, PSF->radius, "OR", PM_SOURCE_MASK_MARKED);
     pmSourceFitModel (source, PSF, true);
-    psImageKeepCircle (source->mask, x, y, PSF->radius, "AND", ~PSPHOT_MASK_MARKED);
+    psImageKeepCircle (source->mask, x, y, PSF->radius, "AND", ~PM_SOURCE_MASK_MARKED);
 
     // does the PSF model succeed?
@@ -29,5 +28,5 @@
 
     psTrace ("psphot.blend", 5, "fitted as PSF\n");
-    pmSourceSubModel (source->pixels, source->mask, PSF, false, false);
+    pmModelSub (source->pixels, source->mask, PSF, false, false);
 
     // free old model, save new model 
@@ -35,6 +34,6 @@
     source->modelPSF = PSF;
 
-    source->mode |=  PM_SOURCE_SUBTRACTED;
-    source->mode &= ~PM_SOURCE_TEMPSUB;
+    source->mode |=  PM_SOURCE_MODE_SUBTRACTED;
+    source->mode &= ~PM_SOURCE_MODE_TEMPSUB;
     return true;
 }
@@ -67,7 +66,7 @@
 
     // skip the source if we don't think it is extended
-    if (source->type == PM_SOURCE_UNKNOWN) return false;
-    if (source->type == PM_SOURCE_DEFECT) return false;
-    if (source->type == PM_SOURCE_SATURATED) return false;
+    if (source->type == PM_SOURCE_TYPE_UNKNOWN) return false;
+    if (source->type == PM_SOURCE_TYPE_DEFECT) return false;
+    if (source->type == PM_SOURCE_TYPE_SATURATED) return false;
     if (source->moments->SN < EXT_MIN_SN) return false;
 
@@ -110,11 +109,11 @@
     // sub EXT
     psFree (DBL);
-    pmSourceSubModel (source->pixels, source->mask, EXT, false, false);
+    pmModelSub (source->pixels, source->mask, EXT, false, false);
     psTrace ("psphot.blend", 5, "blob as EXT: %f %f\n", EXT->params->data.F32[2], EXT->params->data.F32[3]);
 
     // save new model
     source->modelEXT = EXT;
-    source->mode |=  PM_SOURCE_SUBTRACTED;
-    source->mode &= ~PM_SOURCE_TEMPSUB;
+    source->mode |=  PM_SOURCE_MODE_SUBTRACTED;
+    source->mode &= ~PM_SOURCE_MODE_TEMPSUB;
     return true;
 
@@ -122,6 +121,6 @@
     // sub DLB
     psFree (EXT);
-    pmSourceSubModel (source->pixels, source->mask, (pmModel *) DBL->data[0], false, false);
-    pmSourceSubModel (source->pixels, source->mask, (pmModel *) DBL->data[1], false, false);
+    pmModelSub (source->pixels, source->mask, (pmModel *) DBL->data[0], false, false);
+    pmModelSub (source->pixels, source->mask, (pmModel *) DBL->data[1], false, false);
     psTrace ("psphot.blend", 5, "blob as DBL: %f %f\n", ONE->params->data.F32[2], ONE->params->data.F32[3]);
 
@@ -129,7 +128,7 @@
     psFree (source->modelPSF);
     source->modelPSF = psMemCopy (DBL->data[0]);
-    source->mode    |= PM_SOURCE_SUBTRACTED;
-    source->mode    |= PM_SOURCE_PAIR;
-    source->mode    &= ~PM_SOURCE_TEMPSUB;
+    source->mode    |= PM_SOURCE_MODE_SUBTRACTED;
+    source->mode    |= PM_SOURCE_MODE_PAIR;
+    source->mode    &= ~PM_SOURCE_MODE_TEMPSUB;
 
     // copy most data from the primary source (modelEXT, blends stay NULL)
@@ -155,6 +154,6 @@
     pmModel *DBL;
     pmModel *PSF;
-    EllipseAxes axes;
-    EllipseMoments moments;
+    psEllipseAxes axes;
+    psEllipseMoments moments;
     psArray *modelSet;
     
@@ -163,5 +162,5 @@
     moments.y2 = source->moments->Sy;
     moments.xy = source->moments->Sxy;
-    axes = EllipseMomentsToAxes (moments);
+    axes = psEllipseMomentsToAxes (moments);
 
     dx = 2 * cos (axes.theta);
@@ -190,7 +189,7 @@
 
     // fit EXT (not PSF) model (set/unset the pixel mask)
-    psImageKeepCircle (source->mask, x, y, PSF->radius, "OR", PSPHOT_MASK_MARKED);
+    psImageKeepCircle (source->mask, x, y, PSF->radius, "OR", PM_SOURCE_MASK_MARKED);
     pmSourceFitSet (source, modelSet, true);
-    psImageKeepCircle (source->mask, x, y, PSF->radius, "AND", ~PSPHOT_MASK_MARKED);
+    psImageKeepCircle (source->mask, x, y, PSF->radius, "AND", ~PM_SOURCE_MASK_MARKED);
 
     return (modelSet);
@@ -210,7 +209,7 @@
 
     // fit EXT (not PSF) model (set/unset the pixel mask)
-    psImageKeepCircle (source->mask, x, y, EXT->radius, "OR", PSPHOT_MASK_MARKED);
+    psImageKeepCircle (source->mask, x, y, EXT->radius, "OR", PM_SOURCE_MASK_MARKED);
     pmSourceFitModel (source, EXT, false);
-    psImageKeepCircle (source->mask, x, y, EXT->radius, "AND", ~PSPHOT_MASK_MARKED);
+    psImageKeepCircle (source->mask, x, y, EXT->radius, "AND", ~PM_SOURCE_MASK_MARKED);
 
     return (EXT);
@@ -222,5 +221,5 @@
 
     // if this source is not a possible blend, just fit as PSF
-    if ((source->blends == NULL) || (source->mode & PM_SOURCE_SATSTAR)) {
+    if ((source->blends == NULL) || (source->mode & PM_SOURCE_MODE_SATSTAR)) {
 	bool status = psphotFitPSF (readout, source);
 	return status;
@@ -273,7 +272,7 @@
 
     // fit PSF model (set/unset the pixel mask)
-    psImageKeepCircle (source->mask, x, y, PSF->radius, "OR", PSPHOT_MASK_MARKED);
+    psImageKeepCircle (source->mask, x, y, PSF->radius, "OR", PM_SOURCE_MASK_MARKED);
     pmSourceFitSet (source, modelSet, true);
-    psImageKeepCircle (source->mask, x, y, PSF->radius, "AND", ~PSPHOT_MASK_MARKED);
+    psImageKeepCircle (source->mask, x, y, PSF->radius, "AND", ~PM_SOURCE_MASK_MARKED);
 
     // evaluate the blend objects, subtract if good, free otherwise
@@ -291,7 +290,7 @@
 
 	psTrace ("psphot.blend", 5, "fitted blend as PSF\n");
-	pmSourceSubModel (source->pixels, source->mask, model, false, false);
-	src->mode |=  PM_SOURCE_SUBTRACTED;
-	src->mode &= ~PM_SOURCE_TEMPSUB;
+	pmModelSub (source->pixels, source->mask, model, false, false);
+	src->mode |=  PM_SOURCE_MODE_SUBTRACTED;
+	src->mode &= ~PM_SOURCE_MODE_TEMPSUB;
     }
     psFree (modelSet);
@@ -305,9 +304,9 @@
 
     psTrace ("psphot.blend", 5, "fitted primary as PSF\n");
-    pmSourceSubModel (source->pixels, source->mask, PSF, false, false);
+    pmModelSub (source->pixels, source->mask, PSF, false, false);
     psFree (source->modelPSF);
     source->modelPSF = PSF;
-    source->mode |=  PM_SOURCE_SUBTRACTED;
-    source->mode &= ~PM_SOURCE_TEMPSUB;
-    return true;
-}
+    source->mode |=  PM_SOURCE_MODE_SUBTRACTED;
+    source->mode &= ~PM_SOURCE_MODE_TEMPSUB;
+    return true;
+}
Index: /trunk/psphot/src/psphotSourceStats.c
===================================================================
--- /trunk/psphot/src/psphotSourceStats.c	(revision 6714)
+++ /trunk/psphot/src/psphotSourceStats.c	(revision 6715)
@@ -25,5 +25,5 @@
 
 	// allocate image, weight, mask arrays for each peak (square of radius OUTER)
-	psphotDefinePixels (source, readout, source->peak->x, source->peak->y, OUTER);
+	pmSourceDefinePixels (source, readout, source->peak->x, source->peak->y, OUTER);
 
 	// XXX skip faint sources?
Index: unk/psphot/src/testPPimageLoop.c
===================================================================
--- /trunk/psphot/src/testPPimageLoop.c	(revision 6714)
+++ 	(revision )
@@ -1,116 +1,0 @@
-# include "psphot.h"
-
-bool FileList () {
-
-    psArray *filenames = psArrayFromGlob (char *names);
-    
-    psFits *fits = psFitsOpen (filenames->data[0], "r");
-    psMetadata *phu = psFitsReadHeader (NULL, fits);
-    camera = pmConfigCameraFromHeader (site, phu);
-    psFitsClose (fits);
-    
-    fpa = pmFPAConstruct (camera);
-    pmFPAview *fpi = pmFPAviewAlloc (fpa, config->camera, 0);
-
-    pmFile *file = pmFileDefine (fpi, config->camera, "PPIMAGE.INPUT");
-    pmFileDefine (fpi, config->camera, "PPIMAGE.OUTPUT");
-    pmFileDefine (fpi, config->camera, "PPIMAGE.BIN16");
-    pmFileDefine (fpi, config->camera, "PPIMAGE.BIN64");
-
-    for (int i = 1; i < filenames->n; i++) {
-	fits = psFitsOpen (filenames->data[i], "r");
-	phu = psFitsReadHeader (NULL, fits);
-	pmConfigValidateCamera (camera, phu);
-
-	// set the view to the corresponding entry for this phu
-	pmFPAsetView (fpi, phu);
-
-	name = pmConfigNameFromRule (file->rulename, camera, fpi);
-	
-	psMetadataAdd (fpi->IO, name);
-
-    psRegion region = {0,0,0,0};
-    pmFPA *fpa = data->input->fpa;
-    pmFPAview *fpi = pmFPAviewAlloc (fpa, region);
-
-    }
-}
-
-bool ImageLoop (psphotData *data, ppConfig *config) {
-
-
-    // files associated with the science image
-    pmFileIOChecks (fpi);
-
-    // fpa views for the detrend images
-    pmFPAview *bias = pmFPAviewAlloc (data->bias->fpa, region);
-    pmFPAview *dark = pmFPAviewAlloc (data->dark->fpa, region);
-    pmFPAview *mask = pmFPAviewAlloc (data->mask->fpa, region);
-    pmFPAview *flat = pmFPAviewAlloc (data->flat->fpa, region);
-
-    // files associated with detrend images
-    pmFileDefine (bias, config->camera, "PPIMAGE.BIAS");
-    pmFileDefine (dark, config->camera, "PPIMAGE.DARK");
-    pmFileDefine (mask, config->camera, "PPIMAGE.MASK");
-    pmFileDefine (flat, config->camera, "PPIMAGE.FLAT");
-
-    while ((chip = pmFPAviewNextChip (fpi, 1)) != NULL) {
-	pmFPAviewNextChip (bias, 1);
-	pmFPAviewNextChip (dark, 1);
-	pmFPAviewNextChip (mask, 1);
-	pmFPAviewNextChip (flat, 1);
-
-        psLogMsg ("psphot", 4, "Chip %d: %x %x\n", i, chip->exists, chip->process);
-        if (! chip->process) { continue; }
-	pmFileIOChecks (fpi);
-	pmFileIOChecks (bias);
-	pmFileIOChecks (dark);
-	pmFileIOChecks (mask);
-	pmFileIOChecks (flat);
-
-	while ((cell = pmFPAviewNextCell (fpi, 1)) != NULL) {
-	    detrend.bias = pmFPAviewNextCell (bias, 1);
-	    detrend.dark = pmFPAviewNextCell (dark, 1);
-	    detrend.mask = pmFPAviewNextCell (mask, 1);
-	    detrend.flat = pmFPAviewNextCell (flat, 1);
-
-            psLogMsg ("psphot", 4, "Cell %d: %x %x\n", j, cell->exists, cell->process);
-            if (! cell->process) { continue; }
-	    pmFileIOChecks (fpi);
-	    pmFileIOChecks (bias);
-	    pmFileIOChecks (dark);
-	    pmFileIOChecks (mask);
-	    pmFileIOChecks (flat);
-
-	    // process each of the readouts
-	    while ((readout = pmFPAviewNextReadout (fpi)) != NULL) {
-		pmFileIOChecks (fpi);
-		
-		// run the actual photometry analysis
-		ppImageDetrend (&detrend, options, config);
-		pmFileWrite (fpi, "PPIMAGE.OUTPUT");
-	    }
-	    pmFileWrite (fpi, "PPIMAGE.OUTPUT");
-	}
-	pmFileWrite (fpi, "PPIMAGE.OUTPUT");
-	new = pmChipMosaic (chip);
-
-	pmChipRebin (chip, 16);
-	pmFileWrite (fpi, "PPIMAGE.BIN16");
-    }
-    pmFileWrite (fpi, "PPIMAGE.OUTPUT");
-    pmFileWrite (fpi, "PPIMAGE.BIN16");
-
-    pmFPAMosaic (fpa);
-    pmFPARebin (chip, 4);
-    pmFileWrite (fpi, "PPIMAGE.BIN64");
-
-    pmFileClose (fpi);
-    pmFileClose (bias);
-    pmFileClose (dark);
-    pmFileClose (mask);
-    pmFileClose (flat);
-
-    return true;
-}
-
Index: unk/psphot/src/testPSastroLoop.c
===================================================================
--- /trunk/psphot/src/testPSastroLoop.c	(revision 6714)
+++ 	(revision )
@@ -1,36 +1,0 @@
-
-bool ImageLoop (psphotData *data, ppConfig *config) {
-
-    psRegion region = {0,0,0,0};
-    pmFPA *fpa = data->input->fpa;
-    pmFPAiterator *fpi = pmFPAiteratorAlloc (fpa, region);
-
-    // the depths are probably interpreted from the camera config file
-    pmFileAlloc (fpi, config->camera, "PSASTRO.INPUT");
-    pmFileAlloc (fpi, config->camera, "PSASTRO.OUTPUT");
-    pmFileIOChecks (fpi);
-
-    while ((chip = pmChipNext (fpi)) != NULL) {
-
-        psLogMsg ("psphot", 4, "Chip %d: %x %x\n", i, chip->exists, chip->process);
-        if (! chip->process) { continue; }
-	pmFileIOChecks (fpi);
-
-	while ((cell = pmCellNext (fpi)) != NULL) {
-
-            psLogMsg ("psphot", 4, "Cell %d: %x %x\n", j, cell->exists, cell->process);
-            if (! cell->process) { continue; }
-	    pmFileIOChecks (fpi);
-
-	    // process each of the readouts
-	    while ((readout = pmReadoutNext (fpi) != NULL) {
-		pmFileIOChecks (fpi);
-
-		// run the actual photometry analysis
-		psphotReadout (readout, fpi, config);
-	    }
-        }
-    }
-    psphotOutputClose (data);
-    return true;
-}
Index: unk/psphot/src/testPSphotLoop.c
===================================================================
--- /trunk/psphot/src/testPSphotLoop.c	(revision 6714)
+++ 	(revision )
@@ -1,96 +1,0 @@
-# include "psphot.h"
-
-bool psphotImageLoop (pmConfig *config) {
-
-    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
-    pmFPAfileReadChecks (config->files, view);
-
-    while ((chip = pmChipNext (view, input)) != NULL) {
-
-        psLogMsg ("psphot", 4, "Chip %d: %x %x\n", i, chip->exists, chip->process);
-        if (! chip->process) { continue; }
-	pmFPAfileReadChecks (config->files, view);
-
-	while ((cell = pmCellNext (view, input)) != NULL) {
-
-            psLogMsg ("psphot", 4, "Cell %d: %x %x\n", j, cell->exists, cell->process);
-            if (! cell->process) { continue; }
-	    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 (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 (config, view);
-
-		pmFPAfileWriteChecks (config->files, view);
-
-		// write out the desired output dataset(s)
-		// psphotOutput (view, recipe);
-	    }
-	    pmFPAfileWriteChecks (config->files, view);
-	}
-	pmFPAfileWriteChecks (config->files, view);
-    }
-    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
-
-**/
