Index: unk/ppMerge/src/ppMergeCell.c
===================================================================
--- /trunk/ppMerge/src/ppMergeCell.c	(revision 7261)
+++ 	(revision )
@@ -1,74 +1,0 @@
-# include "ppMerge.h"
-
-pmReadout *ppDetrendSelectFirst (pmCell *cell, char *name, bool doThis) {
-
-    if (!doThis) {
-	return NULL;
-    }
-
-    if (cell->readouts->n > 1) {
-	psLogMsg("merge", PS_LOG_WARN, "%s contains multiple readouts: only the first will be used.", name);
-    }
-
-    pmReadout *readout = cell->readouts->data[0]; // Readout of interest in this cell
-
-    return readout;
-}
-
-bool ppMergeCell (pmCell *outputCell, pmCell *maskCell, psArray *cellList, ppOptions *options, ppConfig *config) {
-
-    pmCell *sample = cellList->data[0];
-    // pmReadout *mask = ppDetrendSelectFirst (maskCell, "mask", options->doMask);
-
-    // list to carry readouts for processing
-    psArray *inputs = psArrayAlloc (cellList->n);
-    inputs->n = 0;
-
-    psVector *combineZero = psVectorAlloc (128, PS_TYPE_F32);
-    combineZero->n = 0;
-
-    psVector *combineScale = psVectorAlloc (128, PS_TYPE_F32);
-    combineScale->n = 0;
-
-    int nVal = 0;
-
-    // push all readouts from each image onto the list
-    // not clear that this is the right process -- how to merge readouts?
-    // are all readouts from this cell equivalent? (ie, across images?)
-    // XXX need to set the zero,scale values correctly for each readout
-    for (int i = 0; i < cellList->n; i++) {
-	pmCell *cell = cellList->data[i];
-	for (int j = 0; j < cell->readouts->n; j++) {
-	    psArrayAdd (inputs, 16, cell->readouts->data[j]);
-
-	    combineZero->data.F32[nVal] = 0.0;
-	    combineScale->data.F32[nVal] = 1.0;
-	    psVectorExtend (combineZero, 100, 1);
-	    psVectorExtend (combineScale, 100, 1);
-	    nVal ++;
-	}
-    }
-
-    // XXX : need to assign these correctly
-    float combineGain = 1.0;
-    float combineNoise = 0.0;
-
-    // XXX somehow need to transfer the input cell concepts to the 
-    //     the output cell.  this is weak: are the concepts fixed 
-    //     or not for a collection of images...
-    outputCell->concepts = sample->concepts;
-
-    // XXX where is the output readouts array allocated?
-    pmReadout *outputReadout = pmReadoutAlloc (outputCell);
-    outputReadout->image = pmReadoutCombine (NULL, inputs, 
-					     combineZero, 
-					     combineScale, 
-					     options->combineParams, 
-					     options->applyZeroScale,
-					     combineGain, combineNoise);
-    return true;
-}
-
-
-// XXX a psList does not make sense here: we are using the fixed length psVectors
-//     to carry bzero and bscale, a psArray should be used for the images
Index: unk/ppMerge/src/ppMergeLoadPixels.c
===================================================================
--- /trunk/ppMerge/src/ppMergeLoadPixels.c	(revision 7261)
+++ 	(revision )
@@ -1,58 +1,0 @@
-# include "ppMerge.h"
-
-// this is identical to ppImageLoadPixels : merge and put in psModules
-bool ppMergeLoadPixels (ppFPA *input, ppFPA *process, psDB *db, int nChip, int nCell) {
-
-    // an input chip is valid if:
-    // (((nChip == i) || (nChip == -1)) && process.valid)
-
-    // if we have not opened the file, skip it
-    if (input->fits == NULL) {
-	return false;
-    }
-
-    fprintf (stderr, "loading %d,%d for %s\n", nChip, nCell, input->filename);
-
-    // set input:valid flags according to process and nChip/nCell
-    for (int i = 0; i < input->fpa->chips->n; i++) {
-	pmChip *pChip = process->fpa->chips->data[i];
-	pmChip *iChip = input->fpa->chips->data[i];
-
-	iChip->valid = pChip->valid;
-	iChip->valid &= (nChip == i) || (nChip == -1);
-
-        for (int j = 0; j < iChip->cells->n; j++) {
-
-	    pmCell *pCell = pChip->cells->data[j];
-	    pmCell *iCell = iChip->cells->data[j];
-
-	    iCell->valid =  pCell->valid;
-	    iCell->valid &= iChip->valid;
-	    iCell->valid &= (nCell == i) || (nCell == -1);
-	}
-    }
-
-    // Read in the input pixels
-    if (! pmFPARead(input->fpa, input->fits, input->header, db)) {
-        psErrorStackPrint(stderr, "Unable to populate camera from input FITS file\n");
-        exit(EXIT_FAILURE);
-    }
-
-    // reset input:valid flags to true
-    for (int i = 0; i < input->fpa->chips->n; i++) {
-
-	pmChip *iChip = input->fpa->chips->data[i];
-	iChip->valid = true;
-        for (int j = 0; j < iChip->cells->n; j++) {
-
-	    pmCell *iCell = iChip->cells->data[j];
-	    iCell->valid =  true;
-	}
-    }
-
-    return true;
-}
-
-// XXX this is not very efficient with fseeks : each pmFPARead is randomly accessing the file
-// XXX does this handle multi-file data?
-// XXX this does NOT preserve the state of the input valid flags
Index: unk/ppMerge/src/ppMergeLoop.c
===================================================================
--- /trunk/ppMerge/src/ppMergeLoop.c	(revision 7261)
+++ 	(revision )
@@ -1,86 +1,0 @@
-# include "ppMerge.h"
-
-bool ppMergeLoop (ppData *data, ppOptions *options, ppConfig *config) {
-
-    char name[128];
-    ppFPA *sample = data->input->data[0];
-    pmFPA *sampleFPA = sample->fpa;
-
-    psArray *cellList = psArrayAlloc (data->input->n);
-
-    // attempt to load at FPA level, if desired
-    if (options->imageLoadDepth == PP_LOAD_FPA) {
-	for (int n = 0; n < data->input->n; n++) {
-	    ppFPA *fpa = data->input->data[n];
-	    ppMergeLoadPixels (fpa, data->process, config->database, -1, -1);
-	}
-	ppMergeLoadPixels (data->mask, data->process, config->database, -1, -1);
-    }
-
-    // iterate over all chips, using sampleFPA as reference
-    for (int i = 0; i < sampleFPA->chips->n; i++) {
-        pmChip *maskChip = data->mask->fpa->chips->data[i]; // Chip of interest in input image
-        pmChip *outputChip = data->output->fpa->chips->data[i]; // Chip of interest in input image
-        pmChip *sampleChip = sampleFPA->chips->data[i]; // Chip of interest in input image
-        if (! sampleChip->valid) { continue; }
-
-	// attempt to load at CHIP level, if desired
-	if (options->imageLoadDepth == PP_LOAD_CHIP) {
-	    for (int n = 0; n < data->input->n; n++) {
-		ppFPA *fpa = data->input->data[n];
-		ppMergeLoadPixels (fpa, data->process, config->database, i, -1);
-	    }
-	    ppMergeLoadPixels (data->mask, data->process, config->database, i, -1);
-	}
-
-	// iterate over all cells, using sampleChip as reference
-        for (int j = 0; j < sampleChip->cells->n; j++) {
-	    pmCell *maskCell = maskChip->cells->data[j];
-	    pmCell *outputCell = outputChip->cells->data[j];
-	    pmCell *sampleCell = sampleChip->cells->data[j];
-            if (! sampleCell->valid) { continue; }
-
-	    // attempt to load at CELL level, if desired
-	    if (options->imageLoadDepth == PP_LOAD_CELL) {
-		for (int n = 0; n < data->input->n; n++) {
-		    ppFPA *fpa = data->input->data[n];
-		    ppMergeLoadPixels (fpa, data->process, config->database, i, j);
-		}
-		ppMergeLoadPixels (data->mask, data->process, config->database, i, j);
-	    }
-
-	    // build an array of the cells of interest
-	    for (int k = 0; k < cellList->n; k++) {
-		ppFPA *thisFrame = data->input->data[k];
-		pmFPA *thisFPA = thisFrame->fpa;
-		pmChip *thisChip = thisFPA->chips->data[i];
-		cellList->data[k] = thisChip->cells->data[j];
-	    }
-
-	    // run the merge function
-	    ppMergeCell (outputCell, maskCell, cellList, options, config);
-
-	    sprintf (name, "test.%d.%d.fits", i, j);
-	    psFits *fits = psFitsOpen (name, "w");
-	    pmReadout *readout = outputCell->readouts->data[0];
-	    psFitsWriteImage (fits, NULL, readout->image, 0);
-	    psFitsClose (fits);
-
-# if (0)
-	    if (sampleCell->hdu) {
-		outputCell->hdu = sampleCell->hdu;
-		outputCell->hdu->images = psArrayAlloc (1);
-		outputCell->hdu->images->data[0] = outputCell->readouts->data[0];
-	    }
-# endif
-	}
-# if (0)	
-	if (sampleChip->hdu) {
-	    outputChip->hdu = sampleChip->hdu;
-	    outputChip->hdu->images = psArrayAlloc (1);
-	    // outputChip->hdu->images->data[0] = outputChip->readouts->data[0];
-	}
-# endif
-    }
-    return true;
-}
Index: unk/ppMerge/src/ppMergeOutput.c
===================================================================
--- /trunk/ppMerge/src/ppMergeOutput.c	(revision 7261)
+++ 	(revision )
@@ -1,16 +1,0 @@
-# include "ppMerge.h"
-
-bool ppMergeOutput (ppData *data, ppOptions *options, ppConfig *config) {
-    
-    data->output->fits = psFitsOpen (data->output->filename, "w");
-    if (data->output->fits == NULL) {
-	psAbort ("merge", "failed to open output file %s", data->output->filename);
-    }
-
-    // Write the output
-    pmFPAWrite (data->output->fits, data->output->fpa, config->database);
-    psFitsClose (data->output->fits);
-
-    psLogMsg("merge", PS_LOG_INFO, "Output completed after %f sec.\n", psTimerMark("merge"));
-    return true;
-}
Index: unk/ppMerge/src/ppMergeParseCamera.c
===================================================================
--- /trunk/ppMerge/src/ppMergeParseCamera.c	(revision 7261)
+++ 	(revision )
@@ -1,167 +1,0 @@
-# include "ppMerge.h"
-
-static void ppFPA_Free (ppFPA *fpa) {
-    return;
-}
-
-ppFPA *ppFPA_Alloc (void) {
-
-    ppFPA *fpa = psAlloc (sizeof(ppFPA));
-    psMemSetDeallocator(fpa, (psFreeFunc) ppFPA_Free);
-
-    fpa->filename = NULL;
-    fpa->fpa = NULL;
-    fpa->fits = NULL;
-    fpa->header = NULL;
-    fpa->zero = 0;
-    fpa->scale = 1;
-
-    return fpa;
-}
-
-// psArray **data contains a list of the images to be merged (array of ppFPA)
-bool ppMergeParseCamera (ppData *data, ppConfig *config) {
-    
-    bool status;
-    glob_t globList;
-
-    psArray *input = psArrayAlloc (100);
-    input->n = 0;
-
-    // XXX EAM : push these into a ppMergeLoadInput function?
-    // load the list from the supplied file glob
-    char *globWord = psMetadataLookupPtr (NULL, config->arguments, "-glob");
-    if (*globWord) {
-	globList.gl_offs = 0;
-	glob (globWord, 0, NULL, &globList);
-	for (int i = 0; i < globList.gl_pathc; i++) {
-	    ppFPA *fpa = ppFPA_Alloc ();
-	    fpa->filename = psStringCopy (globList.gl_pathv[i]);
-	    psArrayAdd (input, 100, fpa);
-	}
-    }
-
-    // load the list from the supplied text file
-    char *textWord = psMetadataLookupPtr (NULL, config->arguments, "-text");
-    if (*textWord) {
-	int nItems;
-	char line[1024];
-	char filename[1024];
-	double zero;
-	double scale;
-	
-	FILE *f = fopen (textWord, "r");
-	if (f == NULL) {
-	    psAbort ("merge", "unable to open specified text file");
-	}
-	while (fgets (line, 1024, f) != NULL) {
-	    nItems = sscanf (line, "%s %lf %lf", filename, &zero, &scale);
-	    ppFPA *fpa = ppFPA_Alloc ();
-	    switch (nItems) {
-	      case 0:
-		psFree (fpa);
-		break;
-	      case 3:
-		fpa->zero  = zero;
-		fpa->scale = scale;
-		fpa->filename = psStringCopy (filename);
-		psArrayAdd (input, 100, fpa);
-		break;
-	      case 1:
-		fpa->filename = psStringCopy (filename);
-		psArrayAdd (input, 100, fpa);
-		break;
-	      default:
-		// rigid format, no comments allowed?
-		psAbort ("merge", "error parsing input text file");
-		break;
-	    }
-	}
-    }		
-
-    // load the list from the supplied XML file
-    char *xmlWord = psMetadataLookupPtr (NULL, config->arguments, "-xml");
-    if (*xmlWord) {
-	psAbort ("merge", "-xml input file not yet implemented");
-    }
-
-    // Open the input images, test that they are the same camera
-    psLogMsg("merge", PS_LOG_INFO, "Opening input images\n");
-    for (int i = 0; i < input->n; i++) {
-	
-	ppFPA *fpa = input->data[i];
-
-	psLogMsg("merge", PS_LOG_INFO, "Trying %s...\n", fpa->filename);
-
-	fpa->fits = psFitsOpen(fpa->filename, "r"); // File handle for FITS file
-	if (! fpa->fits) {
-	    psErrorStackPrint(stderr, "Can't open input image: %s\n", fpa->filename);
-	    exit(EXIT_FAILURE);
-	}
-	fpa->header = psFitsReadHeader(NULL, fpa->fits); // primary FITS header
-
-	// Get camera configuration from header if not already defined
-	// else, validate that header matches camera
-	if (! config->camera) {
-	    config->camera = pmConfigCameraFromHeader(config->site, fpa->header);
-	    if (! config->camera) {
-		psErrorStackPrint(stderr, "Can't find camera configuration!\n");
-		exit(EXIT_FAILURE);
-	    }
-	} else {
-	    if (!pmConfigValidateCamera(config->camera, fpa->header)) {
-		psError(PS_ERR_IO, true, "%s does not seem to be from the camera.\n", fpa->filename);
-		exit(EXIT_FAILURE);
-	    }
-	}
-
-	// determine the correct recipe to use
-	if (! config->recipe) {
-	    config->recipe = pmConfigRecipeFromCamera(config->camera, RECIPE);
-	    if (!config->recipe) {
-		psErrorStackPrint(stderr, "Can't find recipe configuration!\n");
-		exit(EXIT_FAILURE);
-	    }
-	}
-
-	// Construct camera in preparation for reading
-	fpa->fpa   = pmFPAConstruct(config->camera);
-    }
-    data->input = input;
-
-    // XXX EAM : extend this to allow an array of selected chips by name
-    // Chip selection: if we are using a single chip, select it for each FPA
-
-    // data->process acts as a process mask for the full FPA
-    data->process = ppFPA_Alloc ();
-    data->process->fpa = pmFPAConstruct(config->camera);
-
-    // see if we have selected a specific chip
-    int chipNum = psMetadataLookupS32(&status, config->arguments, "-chip"); // Chip number to work on
-    if (chipNum >= 0) {
-	if (! pmFPASelectChip(data->process->fpa, chipNum)) {
-	    psErrorStackPrint(stderr, "Chip number %d doesn't exist in camera.\n", chipNum);
-	    exit(EXIT_FAILURE);
-	}
-	psLogMsg("phase2", PS_LOG_INFO, "Operating only on chip %d\n", chipNum);
-    }
-
-    // data->mask carries a pixel mask for pixels to be ignored
-    // the name and contents of the mask are determined in ppMergeOptions
-    data->mask = ppFPA_Alloc ();
-    data->mask->fpa = pmFPAConstruct(config->camera);
-
-    // data->output will store the output file
-    // currently, we keep the complete output file and write it at the end
-    data->output = ppFPA_Alloc ();
-    data->output->fpa = pmFPAConstruct(config->camera);
-    data->output->filename = psMetadataLookupPtr (NULL, config->arguments, "-output");
-    if (! *data->output->filename) {
-	psAbort ("merge", "output file not specified");
-    }
-
-    return true;
-}
-
-// XXX : for split data (data spread across multiple files), this step is only operating on a component 
-//       of the FPA.  the other components should be set to 'invalid' in this case?
Index: unk/ppMerge/src/ppMergeParseDetrend.c
===================================================================
--- /trunk/ppMerge/src/ppMergeParseDetrend.c	(revision 7261)
+++ 	(revision )
@@ -1,30 +1,0 @@
-# include "ppMerge.h"
-
-// open all needed detrend files
-// read in primary headers
-// validate camera for each detrend image
-
-// XXX : keep the primary headers in data?
-// XXX : add fringe frame
-
-bool ppFPAOpen (ppFPA *fpa, psMetadata *camera, char *name, bool doThis) {
-
-    if (!doThis) {
-	return false;
-    }
-
-    psLogMsg("merge", PS_LOG_INFO, "Opening %s image: %s\n", name, fpa->filename);
-    fpa->fits = psFitsOpen(fpa->filename, "r"); // File handle
-    fpa->header = psFitsReadHeader(NULL, fpa->fits); // primary header
-    if (! pmConfigValidateCamera(camera, fpa->header)) {
-	psError(PS_ERR_IO, true, "%s (%s) does not seem to be from the correct camera.\n", name, fpa->filename);
-	exit(EXIT_FAILURE);
-    }
-    return true;
-}
-
-bool ppMergeParseDetrend (ppData *data, ppOptions *options, ppConfig *config) {
-
-    ppFPAOpen (data->mask, config->camera, "mask", options->doMask);
-    return true;
-}
