Index: trunk/psModules/src/camera/pmFPARead.c
===================================================================
--- trunk/psModules/src/camera/pmFPARead.c	(revision 11792)
+++ trunk/psModules/src/camera/pmFPARead.c	(revision 11793)
@@ -26,5 +26,6 @@
     FPA_READ_TYPE_IMAGE,                // Read image
     FPA_READ_TYPE_MASK,                 // Read mask
-    FPA_READ_TYPE_WEIGHT                // Read weight map
+    FPA_READ_TYPE_WEIGHT,               // Read weight map
+    FPA_READ_TYPE_HEADER                // Read header
 } fpaReadType;
 
@@ -35,8 +36,8 @@
 // Carve a readout from the image pixels
 static bool readoutCarve(pmReadout *readout, // Readout to be carved up
-                         psImage **target, // Target pointer for the carved image
                          psImage *image, // Image that will be carved
                          const psRegion *trimsec, // Trim section
-                         const psList *biassecs // Bias sections
+                         const psList *biassecs, // Bias sections
+			 fpaReadType type
                         )
 {
@@ -59,10 +60,33 @@
                                   PS_MIN(trimsec->y1 - readout->row0, image->numRows) // y1
                                  );
-    if (readout->image) {
-        psFree(readout->image);         // Make way!
-    }
-    *target = psMemIncrRefCounter(psImageSubset(image, region));
-
+
+    // place the image subset in the appropriate target location, freeing if needed
+    // XXX why psMemIncrRefCounter on psImageSubset??
+    switch (type) {
+      case FPA_READ_TYPE_IMAGE:
+	if (readout->image) {
+	    psFree (readout->image);
+	}
+	readout->image = psMemIncrRefCounter(psImageSubset(image, region));	
+	break;
+      case FPA_READ_TYPE_MASK:
+	if (readout->mask) {
+	    psFree (readout->mask);
+	}
+	readout->mask = psMemIncrRefCounter(psImageSubset(image, region));	
+	break;
+      case FPA_READ_TYPE_WEIGHT:
+	if (readout->weight) {
+	    psFree (readout->weight);
+	}
+	readout->weight = psMemIncrRefCounter(psImageSubset(image, region));	
+	break;
+      default:
+	psAbort("Unknown read type: %x\n", type);
+    }
+    
     // Get the list of overscans
+    // XXX should this step only be performed for IMAGE, not MASK and WEIGHT types?
+    // XXX that would allow us to overlay a MASK and WEIGHT which have been trimmed...
     if (readout->bias->n != 0) {
         // Make way!
@@ -184,36 +208,68 @@
     }
 
+    // check if we have read the desired data, read it if needed
     bool (*hduReadFunc)(pmHDU*, psFits*) = NULL; // Function to use to read the HDU
-    psArray **imageArray = NULL; // Array of images in the HDU
-    psElemType imageType = PS_TYPE_F32; // Expected type for image
+    void *dataPointer = NULL; 		// pointer to location of desired data
     switch (type) {
-    case FPA_READ_TYPE_IMAGE:
+      case FPA_READ_TYPE_IMAGE:
         hduReadFunc = pmHDURead;
-        imageArray = &hdu->images;
-        imageType = PS_TYPE_F32;
+        dataPointer = hdu->images;
         break;
-    case FPA_READ_TYPE_MASK:
+      case FPA_READ_TYPE_HEADER:
+        hduReadFunc = pmHDUReadHeader;
+        dataPointer = hdu->header;
+        break;
+      case FPA_READ_TYPE_MASK:
         hduReadFunc = pmHDUReadMask;
-        imageArray = &hdu->masks;
-        imageType = PS_TYPE_MASK;
+        dataPointer = hdu->masks;
         break;
-    case FPA_READ_TYPE_WEIGHT:
+      case FPA_READ_TYPE_WEIGHT:
         hduReadFunc = pmHDUReadWeight;
-        imageArray = &hdu->weights;
-        imageType = PS_TYPE_F32;
+        dataPointer = hdu->weights;
         break;
-    default:
+      default:
         psAbort("Unknown read type: %x\n", type);
     }
 
-    if (!(*imageArray) && !hduReadFunc(hdu, fits)) {
-        psError(PS_ERR_UNKNOWN, false, "Unable to read HDU for cell.\n");
-        return false;
-    }
-
+    // do we have the data we want (image, header, or etc).
+    if (!dataPointer) {
+	// attempt to read in the desired data
+	if (!hduReadFunc(hdu, fits)) {
+	    psError(PS_ERR_UNKNOWN, false, "Unable to read HDU for cell.\n");
+	    return false;
+	}
+    }
+
+    // load in the concept information for this cell
     if (!pmConceptsReadCell(cell, PM_CONCEPT_SOURCE_HEADER, true, NULL)) {
         //psError(PS_ERR_UNKNOWN, false, "Failed to read concepts for cell");
         //return false;
         psWarning("Difficulty reading concepts for cell; attempting to proceed.");
+    }
+
+    // skip the image arrays completely for the header-only files
+    if (type == FPA_READ_TYPE_HEADER) {
+	pmCellSetDataStatus(cell, true);
+	return true;
+    }
+
+    // set up pointers for the different possible image arrays
+    psArray *imageArray = NULL;	// Array of images in the HDU
+    psElemType imageType = PS_TYPE_F32; // Expected type for image
+    switch (type) {
+      case FPA_READ_TYPE_IMAGE:
+        imageArray = hdu->images;
+        imageType = PS_TYPE_F32;
+        break;
+      case FPA_READ_TYPE_MASK:
+	imageArray = hdu->masks;
+        imageType = PS_TYPE_MASK;
+        break;
+      case FPA_READ_TYPE_WEIGHT:
+        imageArray = hdu->weights;
+        imageType = PS_TYPE_F32;
+        break;
+      default:
+        psAbort("Unknown read type: %x\n", type);
     }
 
@@ -228,12 +284,12 @@
     // Iterate over each of the image planes, converting type if necessary, and extracting the bits that
     // matter (CELL.TRIMSEC, CELL.BIASSEC) into readouts with readoutCarve.
-    for (int i = 0; i < (*imageArray)->n; i++) {
-        psImage *source = (*imageArray)->data[i]; // Source image, from the i-th plane
+    for (int i = 0; i < imageArray->n; i++) {
+        psImage *source = imageArray->data[i]; // Source image, from the i-th plane
 
         // Type conversion here to support the modules, which don't have multiple type support yet
         if (source->type.type != imageType) {
             psImage *temp = psImageCopy(NULL, source, imageType); // Temporary image
-            psFree((*imageArray)->data[i]);
-            (*imageArray)->data[i] = temp;
+            psFree(imageArray->data[i]);
+            imageArray->data[i] = temp;
             source = temp;
         }
@@ -246,20 +302,5 @@
         }
 
-        psImage **target = NULL;               // Place in readout to put carved image
-        switch (type) {
-        case FPA_READ_TYPE_IMAGE:
-            target = &readout->image;
-            break;
-        case FPA_READ_TYPE_MASK:
-            target = &readout->mask;
-            break;
-        case FPA_READ_TYPE_WEIGHT:
-            target = &readout->weight;
-            break;
-        default:
-            psAbort("Unknown read type: %x\n", type);
-        }
-
-        if (!readoutCarve(readout, target, source, trimsec, biassecs)) {
+        if (!readoutCarve(readout, source, trimsec, biassecs, type)) {
             psError(PS_ERR_UNEXPECTED_NULL, false,
                     "Unable to carve readout into image and bias sections for %d the plane.", i);
@@ -594,4 +635,32 @@
 
 //////////////////////////////////////////////////////////////////////////////////////////////////////////////
+// Reading the image header
+//////////////////////////////////////////////////////////////////////////////////////////////////////////////
+
+bool pmCellReadHeaderSet(pmCell *cell, psFits *fits, psDB *db)
+{
+    PS_ASSERT_PTR_NON_NULL(cell, false);
+    PS_ASSERT_PTR_NON_NULL(fits, false);
+
+    return cellRead(cell, fits, db, FPA_READ_TYPE_HEADER);
+}
+
+bool pmChipReadHeaderSet(pmChip *chip, psFits *fits, psDB *db)
+{
+    PS_ASSERT_PTR_NON_NULL(chip, false);
+    PS_ASSERT_PTR_NON_NULL(fits, false);
+
+    return chipRead(chip, fits, db, FPA_READ_TYPE_HEADER);
+}
+
+bool pmFPAReadHeaderSet(pmFPA *fpa, psFits *fits, psDB *db)
+{
+    PS_ASSERT_PTR_NON_NULL(fpa, false);
+    PS_ASSERT_PTR_NON_NULL(fits, false);
+
+    return fpaRead(fpa, fits, db, FPA_READ_TYPE_HEADER);
+}
+
+//////////////////////////////////////////////////////////////////////////////////////////////////////////////
 // Reading FITS tables
 //////////////////////////////////////////////////////////////////////////////////////////////////////////////
Index: trunk/psModules/src/camera/pmFPARead.h
===================================================================
--- trunk/psModules/src/camera/pmFPARead.h	(revision 11792)
+++ trunk/psModules/src/camera/pmFPARead.h	(revision 11793)
@@ -4,6 +4,6 @@
  * @author Paul Price, IfA
  *
- * @version $Revision: 1.6 $ $Name: not supported by cvs2svn $
- * @date $Date: 2007-01-24 02:54:14 $
+ * @version $Revision: 1.7 $ $Name: not supported by cvs2svn $
+ * @date $Date: 2007-02-15 00:34:00 $
  * Copyright 2005-2006 Institute for Astronomy, University of Hawaii
  */
@@ -107,4 +107,28 @@
                     );
 
+/// Read cell headers
+///
+/// Same as pmCellRead, but reads only the headers of the readouts.
+bool pmCellReadHeaderSet(pmCell *cell,           // Cell to read into
+			 psFits *fits,           // FITS file from which to read
+			 psDB *db                // Database handle, for "concepts" ingest
+    );
+
+/// Read chip headers
+///
+/// Same as pmChipRead, but reads only the headers of the readouts.
+bool pmChipReadHeaderSet(pmChip *chip,           // Chip to read into
+                      psFits *fits,           // FITS file from which to read
+                      psDB *db                // Database handle, for "concepts" ingest
+                     );
+
+/// Read FPA headers
+///
+/// Same as pmFPARead, but reads only the headers of the readouts.
+bool pmFPAReadHeaderSet(pmFPA *fpa,              // FPA to read into
+			psFits *fits,            // FITS file from which to read
+			psDB *db                 // Database handle, for "concepts" ingest
+    );
+
 /// Read a FITS table into the cell
 ///
Index: trunk/psModules/src/camera/pmFPAfile.c
===================================================================
--- trunk/psModules/src/camera/pmFPAfile.c	(revision 11792)
+++ trunk/psModules/src/camera/pmFPAfile.c	(revision 11793)
@@ -408,4 +408,7 @@
         return PM_FPA_FILE_FRINGE;
     }
+    if (!strcasecmp (type, "HEADER"))     {
+        return PM_FPA_FILE_HEADER;
+    }
 
     return PM_FPA_FILE_NONE;
Index: trunk/psModules/src/camera/pmFPAfile.h
===================================================================
--- trunk/psModules/src/camera/pmFPAfile.h	(revision 11792)
+++ trunk/psModules/src/camera/pmFPAfile.h	(revision 11793)
@@ -4,6 +4,6 @@
  * @author EAM, IfA
  *
- * @version $Revision: 1.12 $ $Name: not supported by cvs2svn $
- * @date $Date: 2007-01-24 02:54:14 $
+ * @version $Revision: 1.13 $ $Name: not supported by cvs2svn $
+ * @date $Date: 2007-02-15 00:34:00 $
  * Copyright 2004-2005 Institute for Astronomy, University of Hawaii
  */
@@ -40,4 +40,5 @@
     PM_FPA_FILE_WEIGHT,
     PM_FPA_FILE_FRINGE,
+    PM_FPA_FILE_HEADER,
 } pmFPAfileType;
 
Index: trunk/psModules/src/camera/pmFPAfileFitsIO.c
===================================================================
--- trunk/psModules/src/camera/pmFPAfileFitsIO.c	(revision 11792)
+++ trunk/psModules/src/camera/pmFPAfileFitsIO.c	(revision 11793)
@@ -218,4 +218,11 @@
 }
 
+bool pmFPAviewReadFitsHeaderSet(const pmFPAview *view, pmFPAfile *file)
+{
+    PS_ASSERT_PTR_NON_NULL(view, false);
+    PS_ASSERT_PTR_NON_NULL(file, false);
+    return fpaViewReadFitsImage(view, file, pmFPAReadHeaderSet, pmChipReadHeaderSet, pmCellReadHeaderSet);
+}
+
 // given an already-opened fits file, write the components corresponding
 // to the specified view. when the file was opened, pmFPA/Chip/CellWrite was
Index: trunk/psModules/src/camera/pmFPAfileFitsIO.h
===================================================================
--- trunk/psModules/src/camera/pmFPAfileFitsIO.h	(revision 11792)
+++ trunk/psModules/src/camera/pmFPAfileFitsIO.h	(revision 11793)
@@ -5,6 +5,6 @@
  * @author PAP, IfA
  *
- * @version $Revision: 1.6 $ $Name: not supported by cvs2svn $
- * @date $Date: 2007-01-27 03:33:37 $
+ * @version $Revision: 1.7 $ $Name: not supported by cvs2svn $
+ * @date $Date: 2007-02-15 00:34:00 $
  * Copyright 2004-2005 Institute for Astronomy, University of Hawaii
  */
@@ -29,4 +29,9 @@
                              pmFPAfile *file ///< FPA file into which to read
                             );
+
+/// Read an image header into the current view
+bool pmFPAviewReadFitsHeaderSet(const pmFPAview *view,  ///< View specifying level of interest
+				pmFPAfile *file ///< FPA file into which to read
+    );
 
 /// Write the image for the specified view
Index: trunk/psModules/src/camera/pmFPAfileIO.c
===================================================================
--- trunk/psModules/src/camera/pmFPAfileIO.c	(revision 11792)
+++ trunk/psModules/src/camera/pmFPAfileIO.c	(revision 11793)
@@ -251,9 +251,10 @@
 
     switch (file->type) {
-        // open the FITS types:
-    case PM_FPA_FILE_IMAGE:
-    case PM_FPA_FILE_MASK:
-    case PM_FPA_FILE_WEIGHT:
-    case PM_FPA_FILE_FRINGE:
+      // open the FITS types:
+      case PM_FPA_FILE_IMAGE:
+      case PM_FPA_FILE_MASK:
+      case PM_FPA_FILE_WEIGHT:
+      case PM_FPA_FILE_HEADER:
+      case PM_FPA_FILE_FRINGE:
         psTrace ("pmFPAfile", 5, "opening %s (type: %d)\n", file->filename, file->type);
         if (!openImage(file, view, mode, config)) {
@@ -263,5 +264,5 @@
         break;
         // open the FITS object files
-    case PM_FPA_FILE_CMF:
+      case PM_FPA_FILE_CMF:
         psTrace ("pmFPAfile", 5, "opening %s (type: %d)\n", file->filename, file->type);
         file->fits = psFitsOpen (file->filename, mode);
@@ -273,17 +274,17 @@
         break;
 
-        // defer opening TEXT types:
-    case PM_FPA_FILE_SX:
-    case PM_FPA_FILE_OBJ:
-    case PM_FPA_FILE_CMP:
-    case PM_FPA_FILE_RAW:
-    case PM_FPA_FILE_PSF:
-    case PM_FPA_FILE_JPEG:
-    case PM_FPA_FILE_KAPA:
-    case PM_FPA_FILE_MANAPLOT:
+      // defer opening TEXT types:
+      case PM_FPA_FILE_SX:
+      case PM_FPA_FILE_OBJ:
+      case PM_FPA_FILE_CMP:
+      case PM_FPA_FILE_RAW:
+      case PM_FPA_FILE_PSF:
+      case PM_FPA_FILE_JPEG:
+      case PM_FPA_FILE_KAPA:
+      case PM_FPA_FILE_MANAPLOT:
         psTrace ("pmFPAfile", 5, "defer opening %s\n", file->filename);
         break;
 
-    default:
+      default:
         psError(PS_ERR_IO, true, "type mismatch for %s : %d\n", file->filename, file->type);
         return false;
@@ -357,4 +358,11 @@
     case PM_FPA_FILE_WEIGHT:
         if (!pmFPAviewReadFitsWeight(view, file)) {
+            psError(PS_ERR_UNKNOWN, false, "skipping %s (type: %d)\n", file->filename, file->type);
+            return false;
+        }
+        psTrace ("pmFPAfile", 5, "reading %s (type: %d)\n", file->filename, file->type);
+        break;
+    case PM_FPA_FILE_HEADER:
+        if (!pmFPAviewReadFitsHeaderSet(view, file)) {
             psError(PS_ERR_UNKNOWN, false, "skipping %s (type: %d)\n", file->filename, file->type);
             return false;
@@ -432,4 +440,5 @@
     case PM_FPA_FILE_MASK:
     case PM_FPA_FILE_WEIGHT:
+    case PM_FPA_FILE_HEADER:
     case PM_FPA_FILE_FRINGE:
         if (pmFPAviewFreeData(view, file)) {
@@ -525,4 +534,9 @@
         pmFPAviewWriteFitsWeight(view, file, config);
         psTrace ("pmFPAfile", 5, "wrote weight %s (fpa: %p)\n", file->filename, file->fpa);
+        break;
+    case PM_FPA_FILE_HEADER:
+      // pmFPAviewWriteFitsWeight(view, file, config);
+      // psTrace ("pmFPAfile", 5, "wrote weight %s (fpa: %p)\n", file->filename, file->fpa);
+      psAbort ("no HEADER write functions defined");
         break;
     case PM_FPA_FILE_FRINGE:
@@ -616,28 +630,32 @@
     case PM_FPA_FILE_WEIGHT:
     case PM_FPA_FILE_FRINGE: {
-            // create FPA structure component based on view
-            #if 0
-            psMetadata *format = file->format; // Camera format configuration
-            if (!format) {
-                // It's likely a mosaic, for which we don't yet know the appropriate format
-                const psMetadata *camera = file->fpa->camera; // Camera configuration
-                psMetadata *formats = psMetadataLookupMetadata(NULL, camera, "FORMATS"); // The FORMATS
-                if (!formats) {
-                    psError(PS_ERR_UNEXPECTED_NULL, false, "Unable to find FORMATS in camera configuration.\n");
-                    return false;
-                }
-                format = psMetadataLookupMetadata(NULL, formats, config->formatName);
-                if (!format) {
-                    psError(PS_ERR_UNEXPECTED_NULL, false,
-                            "Unable to find format %s in camera configuration.\n", config->formatName);
-                    return false;
-                }
-                file->format = psMemIncrRefCounter(format);
-            }
-            #endif
-            pmFPAAddSourceFromView (file->fpa, view, file->format);
-            psTrace ("pmFPAfile", 5, "created fpa data elements for %s (fpa: %p)\n", file->name, file->fpa);
-            break;
-        }
+	// create FPA structure component based on view
+	// XXX drop this ifdef'ed out code??
+#if 0
+	psMetadata *format = file->format; // Camera format configuration
+	if (!format) {
+	    // It's likely a mosaic, for which we don't yet know the appropriate format
+	    const psMetadata *camera = file->fpa->camera; // Camera configuration
+	    psMetadata *formats = psMetadataLookupMetadata(NULL, camera, "FORMATS"); // The FORMATS
+	    if (!formats) {
+		psError(PS_ERR_UNEXPECTED_NULL, false, "Unable to find FORMATS in camera configuration.\n");
+		return false;
+	    }
+	    format = psMetadataLookupMetadata(NULL, formats, config->formatName);
+	    if (!format) {
+		psError(PS_ERR_UNEXPECTED_NULL, false,
+			"Unable to find format %s in camera configuration.\n", config->formatName);
+		return false;
+	    }
+	    file->format = psMemIncrRefCounter(format);
+	}
+#endif
+	pmFPAAddSourceFromView (file->fpa, view, file->format);
+	psTrace ("pmFPAfile", 5, "created fpa data elements for %s (fpa: %p)\n", file->name, file->fpa);
+	break;
+    }
+    case PM_FPA_FILE_HEADER:
+      psAbort ("Create not defined for HEADER");
+      break;
     case PM_FPA_FILE_SX:
     case PM_FPA_FILE_RAW:
@@ -691,4 +709,5 @@
     case PM_FPA_FILE_MASK:
     case PM_FPA_FILE_WEIGHT:
+    case PM_FPA_FILE_HEADER:
     case PM_FPA_FILE_FRINGE:
     case PM_FPA_FILE_CMF:
