Index: /trunk/doc/modules/CameraImages.tex
===================================================================
--- /trunk/doc/modules/CameraImages.tex	(revision 9711)
+++ /trunk/doc/modules/CameraImages.tex	(revision 9712)
@@ -52,6 +52,5 @@
 The top level of our image container hierarchy is a complete focal
 plane array (\code{pmFPA}).  This structure represents the collection
-of chips in the camera, all of which are read out in a given
-exposure.  
+of chips in the camera, all of which are read out in a given exposure.
 
 For example, take a mosaic camera consisting of eight $2k\times 4k$
@@ -85,207 +84,188 @@
 those metadata containers.
 
-While the \code{psMetadata} pointers provide a mechanism to carry
-generic information about the image, the hierarchy of data structures
-also provides an explicit set of information defining the geometrical
-relationships between the levels of the hierarchy.  Two types of
-information are provided.  In the first case, basic offsets (and in
-the case of the readouts, binning and flips) are defined to specify
-the location of a given \code{pmCell} with respect to its containing
-\code{pmChip} in the assumption that the pixels in the entire focal
-plane array are laid out on a uniform grid.  This is a crude
-approximation, and cannot be assumed for careful astrometric analysis,
-but it can be used as a starting point or to place the the pixels in a
-test image.  For higher precision, detailed astrometric
-transformations between one frame and the next are also provided.
-
-\tbd{In the future, it may be worthwhile to migrate all of these
-additional pieces to the psMetadata since there is no pressing need to
-have them visible in the data structures}
-
-\subsection{Image Data Container Hierarchy}
+\subsection{Focal Plane Hierarchy}
 
 Here we specify the contents of the focal plane hierarchy:
-\code{pmReadout}, \code{pmCell}, \code{pmChip} and \code{pmFPA}.  Many
-of the components of these are similar.  All but the \code{pmFPA}
-contain offsets from the level above (\code{col0,row0}), and a link to
-the parent. All but the \code{pmReadout} contain a private pointer to
-FITS data and more detailed astrometric transforms.  Each contains an
-\code{analysis} metadata container which is intended to store results
-of analyses (e.g., the r.m.s. of the overscan fit).
-
-\tbd{At what stage are the offsets ({\tt col0,row0}) set, and how are
-they known?}
+\code{pmReadout}, \code{pmCell}, \code{pmChip} and \code{pmFPA}.
 
 \subsubsection{A Readout}
 
-A readout is the result of a single read of a cell (or a portion
-thereof).  It contains the offset from the lower-left corner of the
-chip, in the case that the CCD was windowed, as well as the binning
-factors and parity (if the binning value is negative, then the parity
-is reversed).  It also contains the pixel data (with corresponding
-mask and weight), metadata container for the analysis, and a link to
-the parent.
+A readout corresponds to an individual read of a cell (e.g., a single
+image as part of a video sequence, or one of multiple coadds).  It
+contains the actual pixels used in analysis (along with mask and
+weight maps).  When reading from a FITS file, the images are subimages
+(from CELL.TRIMSEC) of the pixels read from the appropriate HDU (at
+the FPA, chip or cell level).  The readout also contains a list of
+bias sections (prescans or overscans, or otherwise), a summary of
+analysis tasks that have been performed, status flags, and the offsets
+used for reading a FITS file incrementally.
 
 \begin{verbatim}
 typedef struct {
-    // Information
-    psMetadata *analysis;              // Readout-level analysis metadata
-    pmCell *parent;                    // Parent cell
-    // Data
-    psImage *image;                    // Imaging area of readout
-    psImage *mask;                     // Mask for image
-    psImage *weight;                   // Weight for image
-    psList *bias;                      // List of bias section (sub-)images
+    int col0;                           ///< Column offset; non-zero if reading in columns incrementally
+    int row0;                           ///< Row offset; non-zero if reading in rows incrementally
+    psImage *image;                     ///< Imaging area of readout (corresponds to CELL.TRIMSEC region)
+    psImage *mask;                      ///< Mask of input image (corresponds to CELL.TRIMSEC region)
+    psImage *weight;                    ///< Weight of input image (corresponds to CELL.TRIMSEC region)
+    psList *bias;                       ///< List of bias (prescan/overscan) images
+    psMetadata *analysis;               ///< Readout-level analysis metadata
+    pmCell *parent;                     ///< Parent cell
+    bool process;                       ///< Do we bother about reading and working with this readout?
+    bool file_exists;                   ///< Does the file for this readout exist (read case only)?
+    bool data_exists;                   ///< Does the data for this readout exist (read case only)?
 } pmReadout;
 \end{verbatim}    
 
-The constructor for \code{pmReadout} shall be:
-\begin{verbatim}
-pmReadout *pmReadoutAlloc(void);
+The constructor for \code{pmReadout} is:
+\begin{verbatim}
+pmReadout *pmReadoutAlloc(pmCell *cell  ///< Parent cell, or NULL
+                          );
 \end{verbatim}
 The constructor shall make an empty \code{pmReadout}.  The metadata
 container and the \code{bias} list shall be allocated.  All other
 pointers in the structure shall be initialized to \code{NULL}.
+Processing is on by default; the existence flags are initially set to
+\code{false}.
+
+All data within a \code{pmReadout} may be freed:
+\begin{prototype}
+void pmReadoutFreeData(pmReadout *readout ///< Readout for which to free data
+                      );
+\end{prototype}
 
 \subsubsection{A Cell}
 
-A cell consists of one or more readouts (usually only one except in
-the case that the cell has been used for fast guiding, or similar
-situations).  It has values which specifies the position of the cell
-on the chip for rough positioning, along with more precise coordinate
-transforms from the cell to the chip and, as a convenience, from the
-cell directly to the focal plane.  It is expected that these
-transforms will consist of two first-order 2D polynomials, simply
-specifying a translation, rotation and magnification; hence they are
-easily inverted, and there is no need to add reverse transformations.
-We also add an additional transformation, which is intended to provide
-a ``quick and dirty'' transform from the cell coordinates to the sky;
-this transformation not guaranteed to be as precise as the
-``standard'' transformation of Cell $\rightarrow$ Chip $\rightarrow$
-Focal Plane $\rightarrow$ Tangent Plane $\rightarrow$ Sky, but will be
-faster.  The cell also contains metadata containers for the concepts
-and analysis, a link to the parent, and a container for the FITS data,
-if that corresponds to this level.  A boolean indicates whether the
-cell is of interest, allowing it to be excluded from analysis.
+A cell is the lowest-level camera structure, being part of a chip
+(e.g., an amplifier).  It may consist of one or more readouts, which
+are individual reads of the cell.  It also contains the concepts
+metadata appropriate to this level, the cell configuration information
+(for convenience) from the camera configuration, a summary of analysis
+tasks that have been performed, status flags, and any HDU that
+corresponds to this level for the file of interest
+
+\begin{verbatim}
+typedef struct {
+    psMetadata *concepts;               ///< Cell-level concepts
+    unsigned int conceptsRead;          ///< Which concepts have been read; see pmConceptsSource
+    psMetadata *config;                 ///< Cell configuration information (from CELLS in the camera config)
+    psMetadata *analysis;               ///< Cell-level analysis metadata
+    psArray *readouts;                  ///< The component readouts
+    pmChip *parent;                     ///< Parent chip
+    bool process;                       ///< Do we bother about reading and working with this cell?
+    bool file_exists;                   ///< Does the file for this cell exist (read case only)?
+    bool data_exists;                   ///< Does the data for this cell exist (read case only)?
+    pmHDU *hdu;                         ///< FITS header data unit of interest
+} pmCell;
+\end{verbatim}
+
+The constructor for \code{pmCell} shall be:
+\begin{verbatim}
+pmCell *pmCellAlloc(pmChip *chip,       ///< Parent chip, or NULL
+                    const char *name    ///< Name of cell, for CELL.NAME
+                   );
+\end{verbatim}
+The constructor shall make an empty \code{pmCell}.  The
+\code{readouts} array shall be allocated with a zero size, and the
+metadata containers constructed.  Processing is on by default; the
+existence flags are initially set to \code{false}.  The \code{name} is
+used to set \code{CELL.NAME} in the \code{concepts}.  All other
+pointers in the structure are initialized to \code{NULL}.
+
+All readouts, or all data (readouts and metadata) within a cell may be
+freed:
+\begin{prototype}
+void pmCellFreeReadouts(pmCell *cell    ///< Cell for which to free readouts
+                       );
+void pmCellFreeData(pmCell *cell        ///< Cell for which to free data
+                   );
+\end{prototype}
+
+\subsubsection{A Chip}
+
+The chip is the mid-level camera structure, being part of an FPA, and
+consisting of one or more cells (e.g., a CCD).  It also contains the
+concepts metadata appropriate to this level, a summary of analysis
+tasks that have been performed, status flags, any HDU that corresponds
+to this level for the file of interest, and astrometric
+transformations.  The astrometric transformations provide transforms
+between the chip and FPA coordinates and back.
+
+\tbd{The astrometric transformations will likely disappear into the
+analysis metadata in the future.}
 
 \begin{verbatim}
 typedef struct {
     // Astrometric transformations
-    psPlaneTransform* toChip;          // Transformations from cell to chip coordinates
-    psPlaneTransform* toFPA;           // Transformations from cell to FPA coordinates
-    psPlaneTransform* toSky;           // Transformations from cell to sky coordinates
+    psPlaneTransform *toFPA;            ///< Transformation from chip to FPA coordinates, or NULL
+    psPlaneTransform *fromFPA;          ///< Transformation from FPA to chip coordinates, or NULL
     // Information
-    psMetadata *concepts;              // Cache for PS concepts
-    psMetadata *camera;                // Camera information
-    psMetadata *analysis;              // Cell-level analysis metadata
-    bool process;                      // Do we want to process?
-    bool exists;                       // Does the data exist?
-    // Levels    
-    psArray *readouts;                 // The readouts (referred to by number)
-    pmChip *parent;                    // Parent chip
-    // Sources
-    pmFile *imageSource;               // Image file on disk
-    pmFile *maskSource;                // Mask file on disk
-    pmFile *weightSource;              // Weight file on disk
-} pmCell;
-\end{verbatim}
-
-The constructor for \code{pmCell} shall be:
-\begin{verbatim}
-pmCell *pmCellAlloc(psMetadata *cameraData, psString name);
-\end{verbatim}
-The constructor shall make an empty \code{pmCell}.  The
-\code{readouts} array shall be allocated with a zero size, and the
-metadata containers constructed.  The cell's \code{camera} pointer
-shall be set to the provided \code{cameraData}, the \code{exists}
-boolean shall be set to \code{false}, the \code{process} boolean shall
-be set to \code{true}, and the \code{name} shall be used to set
-\code{CELL.NAME} in the \code{concepts}.  All other pointers in the
+    psMetadata *concepts;               ///< Chip-level concepts
+    unsigned int conceptsRead;          ///< Which concepts have been read; see pmConceptsSource
+    psMetadata *analysis;               ///< Chip-level analysis metadata
+    psArray *cells;                     ///< The component cells
+    pmFPA *parent;                      ///< Parent FPA
+    bool process;                       ///< Do we bother about reading and working with this chip?
+    bool file_exists;                   ///< Does the file for this chip exist (read case only)?
+    bool data_exists;                   ///< Does the data for this chip exist (read case only)?
+    pmHDU *hdu;                         ///< FITS header data unit of interest,
+} pmChip;
+\end{verbatim}
+
+The constructor for \code{pmChip} shall be:
+\begin{verbatim}
+pmChip *pmChipAlloc(pmFPA *fpa,         ///< Parent FPA, or NULL
+                    const char *name    ///< Name of cell, for CELL.NAME
+                   );
+\end{verbatim}
+The constructor shall make an empty \code{pmChip}.  The \code{cells}
+array shall be allocated with a zero size and the metadata containers
+constructed.  Processing is on by default; the existence flags are
+initially set to \code{false}.  The \code{name} shall be used to set
+\code{CHIP.NAME} in the \code{concepts}.  All other pointers in the
 structure shall be initialized to \code{NULL}.
+
+All cells, or all data (cells and metadata) within a chip may be
+freed:
+\begin{prototype}
+void pmChipFreeCells(pmChip *chip       ///< Chip for which to free cells
+                    );
+void pmChipFreeData(pmChip *chip        ///< Chip for which to free data
+                   );
+\end{prototype}
+
+\subsubsection{A Focal Plane}
+
+The FPA is the top-level camera structure, and consists of one or more
+chips.  It also contains the concepts metadata appropriate to this
+level, a summary of analysis tasks that have been performed, the
+camera configuration information, any HDU that corresponds to this
+level for the file of interest, and astrometric transformations.  The
+astrometric transformations encode how to transform from the tangent
+plane to the sky, and back.
+
+It is expected that the astrometric transformation will consist of two
+4D polynomials (i.e.\ a function of two coordinates in position, the
+magnitude of the object, and the color of the object) in order to
+correct for optical distortions and the effects of the atmosphere;
+hence we think that it is prudent to include a reverse transformation
+which will be derived from numerically inverting the forward
+transformation.
 
 \tbd{The astrometric transformations will likely disappear into the
 analysis metadata in the future.}
 
-\subsubsection{A Chip}
-
-A chip consists of one or more cells (according to the number of
-amplifiers on the device).  The chip contains metadata containers for
-the concepts and analysis, a link to the parent, and pointers to the
-pointers to the various FITS data, if that corresponds to this level.
-For astrometry, in addition to the rough positioning information, it
-contains a coordinate transform from the chip to the focal plane.  It
-is expected that this transform will consist of two second-order 2D
-polynomials; hence we think that it is prudent to include a reverse
-transformation which will be derived from numerically inverting the
-forward transformation.  A boolean indicates whether the chip is of
-interest, allowing it to be excluded from analysis.
-
 \begin{verbatim}
 typedef struct {
     // Astrometric transformations
-    psPlaneTransform* toFPA;           // Transformation from chip to FPA coordinates
-    psPlaneTransform* fromFPA;         // Transformation from FPA to chip coordinates
+    psPlaneDistort *fromTangentPlane;   ///< Transformation from tangent plane to focal plane, or NULL
+    psPlaneDistort *toTangentPlane;     ///< Transformation from focal plane to tangent plane, or NULL
+    psProjection *projection;           ///< Projection from tangent plane to sky, or NULL
     // Information
-    psMetadata *concepts;              // Cache for PS concepts
-    psMetadata *analysis;              // Chip-level analysis metadata
-    bool process;                      // Do we want to process?
-    bool exists;                       // Does the data exist?
-    // Levels
-    psArray *cells;                    // The cells (referred to by name)
-    pmFPA *parent;                     // Parent FPA
-    // Sources
-    pmFile *imageSource;               // Image file on disk
-    pmFile *maskSource;                // Mask file on disk
-    pmFile *weightSource;              // Weight file on disk
-} pmChip;
-\end{verbatim}
-
-The constructor for \code{pmChip} shall be:
-\begin{verbatim}
-pmChip *pmChipAlloc(psString name);
-\end{verbatim}
-The constructor shall make an empty \code{pmChip}.  The \code{cells}
-array shall be allocated with a zero size, the metadata containers
-constructed, the \code{exists} boolean shall be set to \code{false},
-the \code{process} boolean shall be set to \code{true}, andhe
-\code{name} shall be used to set \code{CHIP.NAME} in the
-\code{concepts}.  All other pointers in the structure shall be
-initialized to \code{NULL}.
-
-\tbd{The astrometric transformations will likely disappear into the
-analysis metadata in the future.}
-
-\subsubsection{A Focal Plane}
-
-A focal plane consists of one or more chips (according to the number
-of pieces of contiguous silicon).  It contains metadata containers for
-the concepts and analysis, a link to the parent, and pointers to the
-FITS header, if that corresponds to this level (the FPA may be the
-PHU, but will not ever contain pixels).  For astrometry, it contains a
-transformation from the focal plane to the tangent plane and the fixed
-pattern residuals.  It is expected that the transformation will
-consist of two 4D polynomials (i.e.\ a function of two coordinates in
-position, the magnitude of the object, and the color of the object) in
-order to correct for optical distortions and the effects of the
-atmosphere; hence we think that it is prudent to include a reverse
-transformation which will be derived from numerically inverting the
-forward transformation.
-
-\begin{verbatim}
-typedef struct {
-    // Astrometric transformations
-    psPlaneDistort* fromTangentPlane;  // Transformation from tangent plane to focal plane
-    psPlaneDistort* toTangentPlane;    // Transformation from focal plane to tangent plane
-    psProjection *projection;          // Projection from tangent plane to sky
-    // Information
-    psMetadata *concepts;              // Cache for PS concepts
-    psMetadata *analysis;              // FPA-level analysis metadata
-    const psMetadata *camera;          // Camera configuration
-    // Levels
-    psArray *chips;                    // The chips
-    // Sources
-    pmFile *imageSource;               // Image file on disk
-    pmFile *maskSource;                // Mask file on disk
-    pmFile *weightSource;              // Weight file on disk
+    psMetadata *concepts;               ///< FPA-level concepts
+    unsigned int conceptsRead;          ///< Which concepts have been read; see pmConceptsSource
+    psMetadata *analysis;               ///< FPA-level analysis metadata
+    const psMetadata *camera;           ///< Camera configuration
+    psArray *chips;                     ///< The component chips
+    pmHDU *hdu;                         ///< FITS header data unit of interest, or NULL
 } pmFPA;
 \end{verbatim}
@@ -293,56 +273,20 @@
 The constructor for \code{pmFPA} shall be:
 \begin{verbatim}
-pmFPA *pmFPAAlloc(const psMetadata *camera);
+pmFPA *pmFPAAlloc(const psMetadata *camera ///< Camera configuration (to store in FPA)
+                 );
 \end{verbatim}
 The constructor shall make an empty \code{pmFPA}.  The \code{chips}
 array shall be allocated with a zero size, the \code{camera} pointer
 set to the value provided, and the \code{concepts} metadata
-constructed. All other pointers in the structure shall be initialized
+constructed.  All other pointers in the structure shall be initialized
 to \code{NULL}.
 
-\tbd{The astrometric transformations will likely disappear into the
-analysis metadata in the future.}
-
-\subsubsection{Disk files}
-
-Each of the levels in the hierarchy have a place to hold a
-\code{pmFile}, which is the representation of a FITS file and ``header
-data unit'':
-\begin{datatype}
-typedef struct {
-    const char *filename;               // Name of file
-    psFits *fits;                       // FITS file
-    psMetadata *phu;                    // Primary extension
-    const char *extname;                // Extension name, or NULL
-    psMetadata *header;                 // The FITS header, or NULL if primary
-    psArray *images;                    // The pixel data
-    psDB *database;                     // Database handle for concepts
-} pmFile;
-\end{datatype}
-
+All data (chips and metadata) within an FPA may be freed:
+\begin{prototype}
+void pmFPAFreeData(pmFPA *fpa           ///< FPA for which to free data
+                  );
+\end{prototype}
 
 \subsubsection{Links between levels}
-
-We provide functions to attach readouts, cells and chips with their
-parents:
-\begin{prototype}
-bool pmReadoutParent(pmReadout *readout, pmCell *cell);
-bool pmCellParent(pmCell *cell, pmChip *chip);
-bool pmChipParent(pmChip *chip, pmFPA *fpa);
-\end{prototype}
-In the case of \code{pmReadoutParent}, the function shall set the
-\code{parent} pointer for the \code{readout} to \code{cell}, and add
-the \code{readout} to the array of \code{readouts} in the \code{cell}.
-The other cases are similar.  \textit{Note that, in order to avoid
-infinite loops when freeing, the reference counter should \textbf{not}
-be incremented when attaching to the \code{parent} pointer, and the
-deallocators should \textbf{not} free the parent.}
-
-The following functions remove all levels below that specified:
-\begin{prototype}
-void pmCellFreeReadouts(pmCell *cell);
-void pmChipFreeCells(pmChip *chip);
-void pmFPAFreeChips(pmFPA *fpa);
-\end{prototype}
 
 The inclusion of hierarchical links pointing both down (via the
@@ -351,5 +295,5 @@
 collection of upward-pointing links:
 \begin{prototype}
-bool pmFPACheckLinks(pmFPA *fpa);
+bool pmFPACheckParents(pmFPA *fpa);
 \end{prototype}
 This function checks the validity of the \code{parent} links in the
@@ -358,4 +302,217 @@
 shall return \code{false}.  If all the \code{parent} pointers were
 correct, the function shall return \code{true}.
+
+
+\subsection{Header Data Units}
+
+Each of the levels in the hierarchy have a place to hold a
+\code{pmHDU}, which is the representation of a FITS ``header data
+unit'':
+\begin{datatype}
+typedef struct {
+    psString extname;                   ///< The extension name
+    bool blankPHU;                      ///< Is this a blank FITS Primary Header Unit, i.e., no data?
+    psMetadata *format;                 ///< The camera format
+    psMetadata *header;                 ///< The FITS header, or NULL if primary for FITS; or section info
+    psArray *images;                    ///< The pixel data
+    psArray *weights;                   ///< The pixel data
+    psArray *masks;                     ///< The pixel data
+} pmHDU;
+\end{datatype}
+
+The \code{pmHDU} simplifies the input/output from/to FITS files, since
+it is, for the most part, a representation of the HDU on disk.  Of
+course, it is not an exact replica of a FITS HDU --- they have no mask
+and weight data, but these are stored here for convenience --- it
+keeps all the relevant data about the image in one place.
+
+The allocator is:
+\begin{prototype}
+pmHDU *pmHDUAlloc(const char *extname   ///< Extension name, or NULL for PHU
+                 );
+\end{prototype}
+
+
+\subsubsection{HDU I/O}
+
+The following function moves to the appropriate extension and reads
+the FITS header into the \code{pmHDU.header} member:
+\begin{prototype}
+bool pmHDUReadHeader(pmHDU *hdu,        ///< HDU for which to read header
+                     psFits *fits       ///< FITS file from which to read
+                    );
+\end{prototype}
+
+The following function moves to the appropriate extension and reads
+the FITS header and pixels into the \code{pmHDU}:
+\begin{prototype}
+bool pmHDURead(pmHDU *hdu,              ///< HDU to read
+               psFits *fits             ///< FITS file to read from
+              );
+\end{prototype}
+
+The following function writes the HDU header and pixels to the end of
+the FITS file:
+\begin{prototype}
+bool pmHDUWrite(pmHDU *hdu,             ///< HDU to write
+                psFits *fits            ///< FITS file to write to
+               );
+\end{prototype}
+
+
+\subsubsection{HDU Utilities}
+
+The following functions return the appropriate HDU, given a member of
+the focal plane hierarchy.  If no HDU is present at the particular
+level, it searches the next highest level.  If no HDU can be found,
+the function returns \code{NULL}.
+
+\begin{prototype}
+pmHDU *pmHDUFromFPA(const pmFPA *fpa    ///< FPA for which to find HDU
+                   );
+pmHDU *pmHDUFromChip(const pmChip *chip ///< Chip for which to find HDU
+                    );
+pmHDU *pmHDUFromCell(const pmCell *cell ///< Cell for which to find HDU
+                    );
+pmHDU *pmHDUFromReadout(const pmReadout *readout ///< Readout for which to find HDU
+                       );
+\end{prototype}
+
+The following functions take multiple components of a focal plane
+hierarchy, and return the HDU at the lowest/highest level of the
+components passed to the function.  If components at all levels are
+supplied, the lowest HDU in the hierarchy is the one with the actual
+pixels, while the highest HDU is the PHU.
+\begin{prototype}
+pmHDU *pmHDUGetLowest(const pmFPA *fpa, ///< The FPA
+                      const pmChip *chip, ///< The chip, or NULL
+                      const pmCell *cell ///< The cell, or NULL
+                     );
+pmHDU *pmHDUGetHighest(const pmFPA *fpa, ///< The FPA
+                       const pmChip *chip, ///< The chip, or NULL
+                       const pmCell *cell ///< The cell, or NULL
+                      );
+\end{prototype}
+
+The following function prints details about an HDU: the extension
+name, headers (if requested), and image sizes.  This function is
+intended for testing or development use.
+
+\begin{prototype}
+void pmHDUPrint(FILE *fd,               ///< File descriptor to which to print
+                const pmHDU *hdu,       ///< HDU to print
+                int level,              ///< Level at which to print
+                bool header             ///< Print header?
+               );
+\end{prototype}
+
+
+\subsection{FPA View}
+
+The following structure allows the identification of a single
+component of the focal plane hierarchy (or multiple, if we consider
+selecting all those components below the selected component).
+Components are identified on the basis of their chip, cell, readout
+index.  An index of -1 means all components at that level.
+Additionally, since readouts may be read piecemeal, there are
+additional indices for these.
+\begin{datatype}
+typedef struct {
+    int chip;                           // Number of the chip, or -1 for all
+    int cell;                           // Number of the cell, or -1 for all
+    int readout;                        // Number of the readout, or -1 for all
+    int nRows;                          // Maximum number of rows per readout segment read, or 0 for all
+    int iRows;                          // Starting point for this read
+} pmFPAview;
+\end{datatype}
+
+The allocator is:
+\begin{prototype}
+pmFPAview *pmFPAviewAlloc(int nRows     ///< Maximum number of rows per readout segment read, or 0 for all
+    );
+\end{prototype}
+
+\subsubsection{Utilities}
+
+A view may have all components reset (select the entire FPA):
+\begin{prototype}
+bool pmFPAviewReset(pmFPAview *view     ///< View to reset
+    );
+\end{prototype}
+
+The view level is the highest index that isn't set to -1.
+\begin{prototype}
+pmFPALevel pmFPAviewLevel(const pmFPAview *view ///< View to examine
+    );
+\end{prototype}
+
+\subsubsection{Lookups}
+
+The following functions return the appropriate currently selected
+hierarchy component.  The functions return \code{NULL} if the selection
+is not specific or invalid for the appropriate level.
+
+\begin{prototype}
+pmChip *pmFPAviewThisChip(const pmFPAview *view, ///< Current view
+                          const pmFPA *fpa ///< FPA containing chip
+    );
+pmCell *pmFPAviewThisCell(const pmFPAview *view, ///< Current view
+                          const pmFPA *fpa ///< FPA containing cell
+    );
+pmReadout *pmFPAviewThisReadout(const pmFPAview *view, ///< Current view
+                                const pmFPA *fpa ///< FPA containing readout
+    );
+\end{prototype}
+
+\subsubsection{Incrementors}
+
+The following functions return the next hierarchy component, according
+to the current selection in the \code{view}.  The functions return
+\code{NULL} if there is no next.
+
+\begin{prototype}
+pmChip *pmFPAviewNextChip(pmFPAview *view, ///< Current view
+                          const pmFPA *fpa, ///< FPA containing chips
+                          int nStep     ///< Number of chips to increment
+    );
+pmCell *pmFPAviewNextCell(pmFPAview *view, ///< Current view
+                          const pmFPA *fpa, ///< FPA containing cells
+                          int nStep     ///< Number of cells to increment
+    );
+pmReadout *pmFPAviewNextReadout(pmFPAview *view, ///< Current view
+                                const pmFPA *fpa, ///< FPA containing readouts
+                                int nStep ///< Number of readouts to increment
+    );
+\end{prototype}
+
+\subsubsection{HDUs}
+
+The following function returns the HDU corresponding to the current view,
+using the \code{pmHDUFrom...} functions, combined with the \code{view}.
+\begin{prototype}
+pmHDU *pmFPAviewThisHDU(const pmFPAview *view, ///< Current view
+                        const pmFPA *fpa ///< FPA for view
+    );
+\end{prototype}
+
+This function returns the blank Primary HDU corresponding to the
+current view, if one exists.  The operation is similar to
+pmFPAviewThisHDU, except it returns \code{NULL} if no HDU is found, or
+the HDU is not a blank Primary HDU.
+\begin{prototype}
+pmHDU *pmFPAviewThisPHU(const pmFPAview *view, ///< Current view
+                        const pmFPA *fpa ///< FPA for view
+    );
+\end{prototype}
+
+
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+
+
+
 
 
