Index: /trunk/ppImage/src/ppFile.c
===================================================================
--- /trunk/ppImage/src/ppFile.c	(revision 6124)
+++ /trunk/ppImage/src/ppFile.c	(revision 6125)
@@ -7,5 +7,7 @@
     psFree(file->fpa);
     psFree(file->phu);
-    psFitsClose(file->fits);
+    if (file->fits) {
+        psFitsClose(file->fits);
+    }
     return;
 }
Index: /trunk/ppImage/src/ppImage.h
===================================================================
--- /trunk/ppImage/src/ppImage.h	(revision 6124)
+++ /trunk/ppImage/src/ppImage.h	(revision 6125)
@@ -78,4 +78,5 @@
     ppFile *flat;                       // The flat-field correction image
     ppFile *fringe;                     // The fringe correction image
+    psFits *output;                     // The output file
 #if 0
     ppFile *process;                    // A dummy file pointing out what needs to be processed
Index: /trunk/ppImage/src/ppImageDetrendBias.c
===================================================================
--- /trunk/ppImage/src/ppImageDetrendBias.c	(revision 6124)
+++ /trunk/ppImage/src/ppImageDetrendBias.c	(revision 6125)
@@ -1,8 +1,8 @@
 #include "ppImage.h"
 
-bool ppDetrendBias(pmReadout *inputReadout, pmReadout *bias, pmReadout *dark, ppOptions *options) {
-
-
-//    psMetadataPrint(inputCell->concepts, 7);
+bool ppDetrendBias(pmReadout *inputReadout, pmReadout *bias, pmReadout *dark, ppOptions *options)
+{
+    psTrace(__func__, 1, "Commencing bias processing....\n");
+//    psMetadataPrint(inputReadout->parent->concepts, 7);
 
     pmSubtractBias(inputReadout, options->overscan, bias, dark);
Index: /trunk/ppImage/src/ppImageDetrendCell.c
===================================================================
--- /trunk/ppImage/src/ppImageDetrendCell.c	(revision 6124)
+++ /trunk/ppImage/src/ppImageDetrendCell.c	(revision 6125)
@@ -6,5 +6,4 @@
 pmReadout *ppDetrendSelectFirst(pmCell *cell, char *name, bool doThis)
 {
-
     if (!doThis) {
         return NULL;
@@ -34,14 +33,4 @@
 #endif
 
-    // Dark time for dark image
-    float darkTime = 1.0;
-    if (options->doDark) {
-        darkTime = psMetadataLookupF32(NULL, detrend->dark->concepts, "CELL.DARKTIME");
-        if (darkTime <= 0.0) {
-            psErrorStackPrint(stderr, "DARKTIME for dark image (%f) is non-positive.\n", darkTime);
-            exit(EXIT_FAILURE);
-        }
-    }
-
     for (int k = 0; k < detrend->input->readouts->n; k++) {
 
@@ -50,10 +39,10 @@
         // Mask bad pixels
         if (options->doMask) {
-            ppDetrendMask (detrend->input, input, mask);
+            ppDetrendMask(detrend->input, input, mask);
         }
 
         // Non-linearity correction
         if (options->doNonLin) {
-            ppDetrendNonLinear (detrend->input, input, options);
+            ppDetrendNonLinear(detrend->input, input, options);
         }
 
Index: /trunk/ppImage/src/ppImageLoop.c
===================================================================
--- /trunk/ppImage/src/ppImageLoop.c	(revision 6124)
+++ /trunk/ppImage/src/ppImageLoop.c	(revision 6125)
@@ -1,3 +1,14 @@
 # include "ppImage.h"
+
+psMemId ppMemPrint(const psMemBlock *ptr)
+{
+    psLogMsg(__func__, PS_LOG_INFO,
+             "Memory block %d (%ld):\n"
+             "\tFile %s, line %d, size %d\n"
+             "\tPosts: %lx %lx %lx\n",
+             ptr->id, ptr->refCounter, ptr->file, ptr->lineno, ptr->userMemorySize, ptr->startblock,
+             ptr->endblock, *(void**)((int8_t *)(ptr + 1) + ptr->userMemorySize));
+    return 0;
+}
 
 // Read the entire FPA
@@ -51,4 +62,9 @@
     psArray *chips = data->input->fpa->chips; // Component chips
     for (int i = 0; i < chips->n; i++) {
+
+        if (i > 6) {
+            continue;
+        }
+
         if (processChip >= 0 && i != processChip) {
             continue;
@@ -100,5 +116,38 @@
         psLogMsg(__func__, PS_LOG_INFO, "%d cells mosaicked.\n", numMosaicked);
 
+        // XXX EAM: Photometry goes here!
+
+        // A kludge to get the write to behave wrt the concepts
+        const psMetadata *camera = data->input->fpa->camera;
+        data->input->fpa->camera = NULL;
+        pmFPAWrite(data->output, data->input->fpa, config->database);
+        data->input->fpa->camera = camera;
+
+        // Now I can blow away the mosaic so I can then read more.
+        psFree(chips->data[i]);
+        ppMemPrint((psMemBlock*)chips->data[i]-1);
     }
+
+#if 0
+    // Write out the mosaicked chip, just to see; this wouldn't normally happen
+    psFits *mosaicFile = psFitsOpen("mosaic.fits", "w");
+    for (int i = 0; i < chips->n; i++) {
+        pmChip *chip = chips->data[i];
+        if (! chip || ! chip->exists || ! chip->process) {
+            continue;
+        }
+#if 0
+        psArray *cells = chip->cells;
+        pmCell *cell = cells->data[0];
+        psArray *readouts = cell->readouts;
+        pmReadout *readout = readouts->data[0];
+        psImage *image = readout->image;
+#else
+        psImage *image = chip->hdu->images->data[0];
+#endif
+        psFitsWriteImage(mosaicFile, NULL, image, 0);
+
+    }
+#endif
 
     // Free the detrend FPA and chips
@@ -108,4 +157,5 @@
     psFree(data->flat);
 
+    psFitsClose(data->output);
 
     return true;
Index: /trunk/ppImage/src/ppImageParseCamera.c
===================================================================
--- /trunk/ppImage/src/ppImageParseCamera.c	(revision 6124)
+++ /trunk/ppImage/src/ppImageParseCamera.c	(revision 6125)
@@ -56,4 +56,12 @@
     data->fringe->fpa  = pmFPAConstruct(config->camera);
 
+    // Open output file
+    const char *outname = psMetadataLookupStr(NULL, config->arguments, "-output"); // Name of output file
+    data->output = psFitsOpen(outname, "w"); // File for writing
+    if (! data->output) {
+        psError(PS_ERR_IO, false, "Unable to open output file %s.\n", data->output);
+        exit(EXIT_FAILURE);
+    }
+
     // 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
Index: /trunk/ppImage/test/ipprc.config
===================================================================
--- /trunk/ppImage/test/ipprc.config	(revision 6124)
+++ /trunk/ppImage/test/ipprc.config	(revision 6125)
@@ -21,15 +21,15 @@
 LOGDEST	STR	STDOUT				# Log destination
 TRACE		METADATA			# Trace levels
-#	ppImageLoop		S32	10
+	ppImageLoop		S32	10
 #	ppImageLoadPixels	S32	10
+#	pmFPAWrite		S32	10
+#	pmFPARead		S32	10
 #	pmSubtractBias		S32	10
+#	ppDetrendBias		S32	10
 #	pmFPAPrint		S32	10
 #	psModule.concepts	S32	10
-#	pmFPAWrite		S32	10
 #	pmConfigRead		S32	10
 #	pmFPAWriteMask		S32	10
 #	pmFPAWriteWeight	S32	10
 #	pmChipMosaic		S32	10
-#	pmFPAMorph		S32	10
-#	pap_psMetadataCopy	S32	9
 END
Index: /trunk/ppImage/test/phase2.config
===================================================================
--- /trunk/ppImage/test/phase2.config	(revision 6124)
+++ /trunk/ppImage/test/phase2.config	(revision 6125)
@@ -5,7 +5,7 @@
 NONLIN		BOOL	FALSE		# Non-linearity correction
 OVERSCAN	BOOL	TRUE		# Overscan subtraction
-BIAS		BOOL	TRUE		# Bias subtraction
+BIAS		BOOL	FALSE		# Bias subtraction
 DARK		BOOL	FALSE		# Dark subtraction
-FLAT		BOOL	TRUE		# Flat-field normalisation
+FLAT		BOOL	FALSE		# Flat-field normalisation
 FRINGE		BOOL	FALSE		# Fringe subtraction
 SOURCE		BOOL	FALSE		# Source identification and photometry
