Index: /branches/rel10_ifa/psModules/src/astrom/pmFPARead.c
===================================================================
--- /branches/rel10_ifa/psModules/src/astrom/pmFPARead.c	(revision 6519)
+++ /branches/rel10_ifa/psModules/src/astrom/pmFPARead.c	(revision 6520)
@@ -102,5 +102,5 @@
 // Portion out an image into the cell
 static bool generateReadouts(pmCell *cell, // The cell that gets its bits
-                             p_pmHDU *hdu // Pixel data, containing image, mask, weights
+                             pmHDU *hdu // Pixel data, containing image, mask, weights
                             )
 {
@@ -139,4 +139,106 @@
 // Public functions
 //////////////////////////////////////////////////////////////////////////////////////////////////////////////
+
+
+bool pmReadoutRead(pmReadout *readout,  // Readout to read into
+                   psFits *fits         // FITS file from which to read
+                  )
+{
+    //
+
+}
+
+// Carve a readout from the image pixels
+static pmReadout *readoutCarve(pmCell *cell, // Cell into which the new readout will be placed
+                               psImage *image, // Image that will be carved
+                               const psRegion *trimsec, // Trim section
+                               const psList *biassecs // Bias sections
+                              )
+{
+    pmReadout *readout = pmReadoutAlloc(cell);
+
+    // The image corresponding to the trim region
+    readout->image = psMemIncrRefCounter(psImageSubset(image, *trimsec));
+
+    // Get the list of overscans
+    psListIterator *iter = psListIteratorAlloc(biassecs, PS_LIST_HEAD, false); // Iterator
+    psRegion *biassec = NULL;       // A BIASSEC region from the list
+    while ((biassec = psListGetAndIncrement(iter))) {
+        psImage *overscan = psMemIncrRefCounter(psImageSubset(image, *biassec));
+        psListAdd(readout->bias, PS_LIST_TAIL, overscan);
+        psFree(overscan);
+    }
+    psFree(iter);
+
+    return readout;
+}
+
+
+bool pmCellRead(pmCell *cell,           // Cell to read into
+                psFits *fits,           // FITS file from which to read
+                psDB *db                // Database handle, for "concepts" ingest
+               )
+{
+    pmHDU *hdu = pmHDUFromCell(cell);   // The HDU
+    if (!hdu->images && !pmHDURead(hdu, fits)) {
+        psError(PS_ERR_IO, false, "Unable to read HDU for cell.\n");
+        return false;
+    }
+
+    // Read the "concepts"
+    pmConceptsReadCell(cell, db);
+
+    // Having read the cell, we now have to cut it up
+    psRegion *trimsec = psMetadataLookupPtr(NULL, cell->concepts, "CELL.TRIMSEC");
+    psList *biassecs = psMetadataLookupPtr(NULL, cell->concepts, "CELL.BIASSEC");
+
+    // Iterate over each of the image planes
+    for (int i = 0; i < hdu->images->n; i++) {
+        psImage *image = hdu->images->data[i]; // The i-th plane
+        pmReadout *readout = readoutCarve(cell, image, trimsec, biassecs);
+        readout->mask = NULL;
+        readout->weight = NULL;
+        psFree(readout);                // Drop reference
+    }
+
+    return true;
+}
+
+
+bool pmChipRead(pmChip *chip,           // Chip to read into
+                psFits *fits,           // FITS file from which to read
+                psDB *db                // Database handle, for "concepts" ingest
+               )
+{
+    psArray *cells = chip->cells;       // Array of cells
+    for (int i = 0; i < cells->n; i++) {
+        pmCell *cell = cells->data[i];  // The cell of interest
+        if (!pmCellRead(cell, fits, db)) {
+            psError(PS_ERR_IO, false, "Unable to read cell %d.\n", i);
+            return false;
+        }
+    }
+
+    return true;
+}
+
+bool pmFPARead(pmFPA *fpa,              // FPA to read into
+               psFits *fits,            // FITS file from which to read
+               psDB *db                 // Database handle, for "concepts" ingest
+              )
+{
+    psArray *chips = fpa->cells;       // Array of cells
+    for (int i = 0; i < chips->n; i++) {
+        pmCell *chip = chips->data[i];  // The cell of interest
+        if (!pmChipRead(chip, fits, db)) {
+            psError(PS_ERR_IO, false, "Unable to read chip %d.\n", i);
+            return false;
+        }
+    }
+
+    return true;
+}
+
+#if 0
 
 bool pmFPARead(pmFPA *fpa,              // FPA to read into
@@ -656,2 +758,5 @@
     return true;
 }
+
+
+#endif
