Index: trunk/archive/scripts/src/phase2/pmFPA.c
===================================================================
--- trunk/archive/scripts/src/phase2/pmFPA.c	(revision 5104)
+++ trunk/archive/scripts/src/phase2/pmFPA.c	(revision 5371)
@@ -7,24 +7,57 @@
 #include "pmFPA.h"
 
+// Get the bias images for a readout, using the CELL.BIASSEC
+psList *pmReadoutGetBias(pmReadout *readout // Readout for which to get the bias sections
+    )
+{
+    pmCell *cell = readout->parent;	// The parent cell
+    psList *sections = (psList*)psMetadataLookupPtr(NULL, cell->concepts, "CELL.BIASSEC"); // CELL.BIASSEC
+
+    psImage *image = readout->image;	// The image that contains both the biassec and the trimsec
+
+    psList *images = psListAlloc(NULL);	// List of images from bias sections
+    psListIterator *sectionsIter = psListIteratorAlloc(sections, PS_LIST_HEAD, true); // Iterator
+    psRegion *region = NULL;		// Bias region from list
+    while (region = psListGetAndIncrement(sectionsIter)) {
+#if 0
+	// Convert from FITS standard to PS standard
+	// We don't touch the x1 and y1 values because they aren't included by psImageSubset.
+	region->x0 -= 1;
+	region->y0 -= 1;
+#endif
+
+	psImage *bias = psImageSubset(image, *region); // Image from bias section
+	psListAdd(images, PS_LIST_TAIL, bias);
+	psFree(bias);
+    }
+    psFree(sectionsIter);
+
+    return images;
+}
+
 //////////////////////////////////////////////////////////////////////////////////////////////////////////////
 // Allocators
 //////////////////////////////////////////////////////////////////////////////////////////////////////////////
 
-p_pmHDU *p_pmHDUAlloc(const char *extname)
-{
-    p_pmHDU *hdu = psAlloc(sizeof(p_pmHDU));
-    psMemSetDeallocator(hdu, (psFreeFunc)p_pmHDUFree);
-
-    hdu->extname = extname;
-    hdu->pixels = NULL;
-    hdu->header = NULL;
-
-    return hdu;
-}
-
-void p_pmHDUFree(p_pmHDU *hdu)
-{
-    psFree(hdu->pixels);
-    psFree(hdu->header);
+pmPixelData *pmPixelDataAlloc(const char *extname)
+{
+    pmPixelData *pd = psAlloc(sizeof(pmPixelData));
+    psMemSetDeallocator(pd, (psFreeFunc)p_pmPixelDataFree);
+
+    pd->extname = extname;
+    pd->header = NULL;
+    pd->images = NULL;
+    pd->masks = NULL;
+    pd->weights = NULL;
+
+    return pd;
+}
+
+void p_pmPixelDataFree(pmPixelData *pd)
+{
+    psFree(pd->header);
+    psFree(pd->images);
+    psFree(pd->masks);
+    psFree(pd->weights);
 }
 
@@ -44,5 +77,5 @@
     fpa->chips = psArrayAlloc(0);
 
-    fpa->private = NULL;
+    fpa->data = NULL;
 
     return fpa;
@@ -59,5 +92,5 @@
     psFree(fpa->chips);
 
-    psFree(fpa->private);
+    psFree(fpa->data);
 }
 
@@ -86,5 +119,5 @@
     chip->valid = true;    
 
-    chip->private = NULL;
+    chip->data = NULL;
 
     psMetadataAddStr(chip->concepts, PS_LIST_HEAD, "CHIP.NAME", 0, "Chip name added at pmChipAlloc", name);
@@ -101,5 +134,5 @@
     psFree(chip->cells);
 
-    psFree(chip->private);
+    psFree(chip->data);
 
     // We don't free the parent member, since that would generate a circular call.  We don't increment the
@@ -138,5 +171,5 @@
     cell->valid = true;
 
-    cell->private = NULL;
+    cell->data = NULL;
 
     return cell;
@@ -155,5 +188,5 @@
     psFree(cell->readouts);
 
-    psFree(cell->private);
+    psFree(cell->data);
 
     // We don't free the parent member, since that would generate a circular call.  We don't increment the
@@ -163,5 +196,5 @@
 pmReadout *pmReadoutAlloc(pmCell *cell, // Cell to which the readout belongs
 			  psImage *image, // The pixels
-			  psList *overscans, // The overscan images
+			  psImage *mask,// The mask pixels
 			  int col0, int row0, int colParity, int rowParity, int colBin, int rowBin // Data
     )
@@ -173,6 +206,6 @@
     // Set the components
     readout->image = psMemIncrRefCounter(image);
-    readout->mask = NULL;
-    readout->overscans = psMemIncrRefCounter(overscans);
+    readout->mask = psMemIncrRefCounter(mask);
+    readout->weight = NULL;
     
     //readout->concepts = psMetadataAlloc();
@@ -185,4 +218,6 @@
     *(int*)&readout->rowBins = rowBin;
 
+    readout->parent = cell;
+
     return readout;
 }
@@ -191,6 +226,6 @@
 {
     psFree(readout->image);
-    psFree(readout->mask); 
-    psFree(readout->overscans);
+    psFree(readout->mask);
+    psFree(readout->weight);
     //psFree(readout->concepts);
 }
