Index: /trunk/psLib/src/dataManip/psMatrix.h
===================================================================
--- /trunk/psLib/src/dataManip/psMatrix.h	(revision 597)
+++ /trunk/psLib/src/dataManip/psMatrix.h	(revision 597)
@@ -0,0 +1,74 @@
+#if !defined(PS_MATRIX_H)
+#define PS_MATRIX_H
+
+/** \file psMatrix.h
+ *  \brief matrix math operators
+ *  \ingroup MathGroup
+ */
+
+/** Functions **************************************************************/
+/** \addtogroup MathGroup Math Utilities
+ *  \{
+ */
+
+
+/* Linear Algebra */
+
+/** Invert matrix.  Not using restrict, to allow inversion to be done in-place */
+psImage *
+psMatrixInvert(psImage *out,  ///< Matrix to return, or NULL
+               const psImage *myMatrix, ///< Matrix to be inverted
+               float *restrict determinant ///< Determinant to return, or NULL
+              );
+
+/** Matrix determinant */
+float
+psMatrixDeterminant(const psImage *restrict myMatrix ///< Matrix to get determinant for
+                   );
+
+/** Matrix operation: addition, subtraction, multiplication */
+psImage *
+psMatrixOp(psImage *out,  ///< Matrix to return, or NULL
+           const psImage *matrix1, ///< Matrix 1
+           const char *op,              ///< Operation to perform: "+", "-", "*"
+           const psImage *matrix2 ///< Matrix 2
+          );
+
+/** Transpose Matrix */
+psImage *
+psMatrixTranspose(psImage *out,  ///< Matrix to return, or NULL
+                  const psImage *myMatrix ///< Matrix to transpose
+                 );
+
+/** LU Decomposition of a matrix */
+psImage *
+psMatrixLUD(psImage *out,  ///< Matrix to return, or NULL
+            psImage *myMatrix  ///< Matrix to decompose
+           );
+
+/** LU Solution.  Solves for and returns x in the equation Ax = b */
+psVector *
+psMatrixLUSolve(psVector *out,  ///< Vector to return, or NULL
+                const psImage *luMatrix, ///< LU-decomposed matrix
+                const psVector *rhsVector ///< right-hand-side of the equation
+               );
+
+/***********************************************************************************************************/
+
+/* Conversions */
+
+/** Convert matrix to vector.  Intended for a 1-d matrix. */
+psVector *
+psMatrixToVector(psVector *out,  ///< Vector to return, or NULL
+                 psImage *myMatrix ///< Matrix to convert
+                );
+
+/** Convert vector to matrix. */
+psImage *
+psVectorToMatrix(psImage *out,  ///< Matrix to return, or NULL
+                 psVector *myVector ///< Vector to convert
+                );
+
+/* \} */ // End of MathGroup Functions
+
+#endif
Index: /trunk/psLib/src/image/psImage.h
===================================================================
--- /trunk/psLib/src/image/psImage.h	(revision 597)
+++ /trunk/psLib/src/image/psImage.h	(revision 597)
@@ -0,0 +1,284 @@
+# ifndef PS_IMAGE_H
+# define PS_IMAGE_H
+
+/** \file psImage.h
+ *  \brief Basic image definitions and operations.
+ *  \ingroup AstroGroup
+ */
+
+/// basic image data structure.
+typedef struct psImage
+{
+    psType type;    ///< image data type and dimension
+    int nx, ny;    ///< size of image
+    int x0, y0;    ///< data region relative to parent
+    union {
+        psF32 **rows;          ///< == rows_f32
+        psS8  **rows_s8;  ///< pointers to psS8 data
+        psS16 **rows_s16;  ///< pointers to psS16 data
+        psS32 **rows_s32;  ///< pointers to psS32 data
+        psU8  **rows_u8;  ///< pointers to psU8 data
+        psU16 **rows_u16;  ///< pointers to psU16 data
+        psU32 **rows_u32;  ///< pointers to psU32 data
+        psF32 **rows_f32;  ///< pointers to psF32 data
+        psF64 **rows_f64;  ///< pointers to psF64 data
+        psComplex **rows_complex; ///< pointers to psComplex data
+    } rows;
+    struct psImage *parent;  ///< parent, if a subimage
+    int Nchildren;   ///< number of subimages
+    struct psImage *children;  ///< children of this region; array of Nchildren pointers
+}
+psImage;
+
+/** Functions **************************************************************/
+/** \addtogroup AstroGroup Astronomy-Specific Utilities
+ *  \{
+ */
+
+/*** Image structure manipulation ***/
+
+/// Create an image of the specified size and type.
+psImage *
+psImageAlloc (int nx,   ///< image width
+              int ny,   ///< image height
+              psType type  ///< image data type
+             );
+
+/// Create a subimage of the specified area.
+psImage *
+psImageSubset(psImage *out,  ///< Subimage to return, or NULL
+              const psImage *image, ///< parent image
+              int nx,   ///< subimage width (<= image.nx - x0)
+              int ny,   ///< subimage width (<= image.ny - y0)
+              int x0,   ///< subimage x-offset (0 <= x0 < nx)
+              int y0   ///< subimage y-offset (0 <= y0 < ny)
+             );
+
+/// Destroy the specified image (destroy children if they exist).
+void
+psImageFree(psImage *restrict image ///< free this image
+           );
+
+/** Destroy the pixels of the specified image */
+psImage *
+psImageFreePixels(psImage *restrict image ///< Image whose pixels are to be freed
+                 );
+
+/// Destroy the children of the specified image.  Returns number of children freed.
+int
+psImageFreeChildren(const psImage *image ///< free children of this image
+                   );
+
+/// Create a copy of the specified image.
+psImage *
+psImageCopy(psImage *output,   ///< target structure for output image data
+            const psImage *input ///< copy this image
+           );
+
+/*** various image pixel extractions ***/
+
+/// Extract pixels from rectlinear region to a vector.
+psFloatArray *
+psImageSlice(psFloatArray *out,  ///< Vector to output, or NULL
+             const psImage *input, ///< extract slice from this image
+             int x,    ///< starting x coord of region to slice
+             int y,    ///< starting y coord of region to slice
+             int nx,    ///< width of region in x
+             int ny,    ///< width of region in y
+             int direction,  ///< direction of vector along slice
+             const psStats *stats ///< defines statistics used to find output values
+            );
+
+/// Extract pixels along a line to a vector.
+psFloatArray *
+psImageCut(psFloatArray *out,  ///< Vector to output, or NULL
+           const psImage *input, ///< extract cut from this image
+           float xs,    ///< starting x coord of cut
+           float ys,    ///< starting y coord of cut
+           float xe,    ///< ending x coord of cut
+           float ye,    ///< ending y coord of cut
+           float dw,    ///< width of cut
+           const psStats *stats  ///< defines statistics used to find output values
+          );
+
+/// Extract radial annulii data to a vector.
+psFloatArray *
+psImageRadialCut(psFloatArray *out, ///< Vector to output, or NULL
+                 const psImage *input, ///< extract profile from this image
+                 float x,   ///< center x coord of annulii
+                 float y,   ///< center y coord of annulii
+                 float radius,  ///< outer radius of annulii
+                 float dr,  ///< radial step size of annulii
+                 const psStats *stats ///< defines statistics used to find output values
+                );
+
+/* Contour is a high-level function */
+#if 0
+/// Extract a 2-d contour from an image at the given threshold.
+psFloatArray *
+psImageContour(psFloatArray *out, ///< Vector to output, or NULL
+               const psImage *input,  ///< create contour for this image
+               float threshold, ///< contour image at this threshold
+               int binning  ///< bin image by this value for contour calculation
+              );
+#endif
+
+/*** various image geometry manipulation ***/
+/// Rebin image to new scale.
+psImage *
+psImageRebin(psImage *out,  ///< Image to output, or NULL
+             const psImage *input, ///< rebin this image
+             float scale,   ///< rebinning scale: doutput = scale*dinput
+             const psStats *stats ///< defines statistics used to find output values
+            );
+
+/// Rotate image by given angle.
+psImage *
+psImageRotate(psImage *out,  ///< Image to output, or NULL
+              const psImage *input, ///< rotate this image
+              float angle  ///< rotate by this amount anti-clockwise (degrees)
+             );
+
+/// Shift image by an arbitrary number of pixels in either direction.
+/// Drop edge pixels, and set newly exposed pixels to 'exposed'.
+psImage *
+psImageShift(psImage *out,  ///< Image to output, or NULL
+             const psImage *input, ///< shift this image
+             float dx,   ///< shift by this amount in x
+             float dy,   ///< shift by this amount in y
+             float exposed  ///< set exposed pixels to this value
+            );
+
+/// Roll image by an integer number of pixels in either direction.
+/// Edge pixels wrap to the other side (no values are lost).
+psImage *
+psImageRoll(psImage *out,  ///< Image to output, or NULL
+            const psImage *input, ///< roll this image
+            int dx,    ///< roll this amount in x
+            int dy   ///< roll this amount in y
+           );
+
+/// Determine statistics for image (or subimage).
+psStats *
+psImageGetStats(const psImage *input,  ///< image (or subimage) to calculate stats
+                psStats *stats  ///< defines statistics to be calculated & target
+               );
+
+/// Construct a histogram from an image (or subimage).
+psHistogram *
+psImageHistogram(psHistogram *hist, ///< input histogram description & target
+                 const psImage *input ///< determine histogram of this image
+                );
+
+/// Fit a 2-D polynomial surface to an image.
+psPolynomial2D *
+psImageFitPolynomial(const psImage *input, ///< image to fit
+                     psPolynomial2D *coeffs ///< coefficient structure carries in desired terms & target
+                    );
+
+/// Evaluate a 2-D polynomial surface to image pixels.
+int
+psImageEvalPolynomial(const psImage *input, ///< image to fit
+                      const psPolynomial2D *coeffs ///< coefficient structure carries in desired terms
+                     );
+
+/*** image input/output routines ***/
+/// Read an image or subimage from a named file.
+psImage *
+psImageReadSection(psImage *output,  ///< place data in this structure for output
+                   int x,   ///< starting x coord of region
+                   int y,   ///< starting y coord of region
+                   int nx,   ///< x size of region (-1 for full range)
+                   int ny,   ///< y size of region (-1 for full range)
+                   int z,   ///< plane of interest
+                   const char *extname, ///< MEF extension name ("PHU" for primary header)
+                   int extnum,  ///< MEF extension number (-1 for "PHU", 0 : Nextend - 1)
+                   const char *filename ///< file to read data from
+                  );
+
+/// Read an image or subimage from file descriptor.
+psImage *
+psImageFReadSection(psImage *output, ///< place data in this structure for output
+                    int x,  ///< starting x coord of region
+                    int y,  ///< starting y coord of region
+                    int nx,  ///< x size of region (-1 for full range)
+                    int ny,  ///< y size of region (-1 for full range)
+                    int z,  ///< plane of interest
+                    const char *extname, ///< MEF extension name ("PHU" for primary header)
+                    int extnum,  ///< MEF extension number (-1 for "PHU", 0 : Nextend - 1)
+                    FILE *f  ///< file descriptor to read data from
+                   );
+
+/// Write an image section to named file (which may exist).
+psImage *
+psImageWriteSection(psImage *input,    ///< image to write out
+                    int x,   ///< starting x coord of region
+                    int y,   ///< starting y coord of region
+                    int z,   ///< plane of interest
+                    const char *extname, ///< MEF extension name ("PHU" for primary header)
+                    int extnum,  ///< MEF extension number (-1 for "PHU", 0 : Nextend - 1)
+                    const char *filename ///< file to write data to
+                   );
+
+/// Write an image section to named file (which may exist).
+psImage *
+psImageFWriteSection(psImage *input, ///< image to write out
+                     int x,   ///< starting x coord of region
+                     int y,   ///< starting y coord of region
+                     int z,   ///< plane of interest
+                     const char *extname, ///< MEF extension name
+                     int extnum,  ///< MEF extension number (-1 for "PHU", 0 : Nextend - 1)
+                     FILE *f  ///< file descriptor to write data to
+                    );
+
+/// Read only header from image file.
+psMetadata *
+psImageReadHeader(psMetadata *output, ///< read data to this structure
+                  const char *extname,  ///< MEF extension name ("PHU" for primary header)
+                  int extnum,  ///< MEF extension number (-1 for "PHU", 0 : Nextend - 1)
+                  const char *filename ///< file to read from
+                 );
+
+/// Read only header from image file descriptor.
+psMetadata *
+psImageFReadHeader(psMetadata *output, ///< read data to this structure
+                   const char *extname, ///< MEF extension name ("PHU" for primary header)
+                   int extnum,  ///< MEF extension number (-1 for "PHU", 0 : Nextend - 1)
+                   FILE *f  ///< file descriptor to read from
+                  );
+
+/*** basic pixel manipulations ***/
+/// Clip image values outside of range to given values.  Return number of clipped pixels.
+int
+psImageClip(psImage *input,   ///< clip this image
+            float min,   ///< clip pixels with values < min
+            float vmin,   ///< set min-clipped pixels to vmin
+            float max,   ///< clip pixels with values > max
+            float vmax   ///< set max-clipped pixels to vmax
+           );
+
+/// Clip NaN image pixels to given value.  Return number of clipped pixels.
+int
+psImageClipNaN(psImage *input,  ///< clip this image & target
+               float value  ///< set nan pixels to this value
+              );
+
+/// Overlay subregion of image with another image.  Return number of pixels replaced.
+int
+psImageOverlaySection(psImage *image, ///< input image & target
+                      const psImage *overlay, ///< image to overlay
+                      int x0,  ///< x offset of overlay subimage
+                      int y0,  ///< y offset of overlay subimage
+                      const char *op ///< overlay operation
+                     );
+
+/* \} */ // End of AstroGroup Functions
+
+# endif
+/* image overlay operations
+    PS_OVERLAY_EQUALS   = '=', 
+    PS_OVERLAY_ADD      = '+', 
+    PS_OVERLAY_SUBTRACT = '-', 
+    PS_OVERLAY_MULTIPLY = '*', 
+    PS_OVERLAY_DIVIDE   = '/', 
+*/
Index: /trunk/psLib/src/math/psMatrix.h
===================================================================
--- /trunk/psLib/src/math/psMatrix.h	(revision 597)
+++ /trunk/psLib/src/math/psMatrix.h	(revision 597)
@@ -0,0 +1,74 @@
+#if !defined(PS_MATRIX_H)
+#define PS_MATRIX_H
+
+/** \file psMatrix.h
+ *  \brief matrix math operators
+ *  \ingroup MathGroup
+ */
+
+/** Functions **************************************************************/
+/** \addtogroup MathGroup Math Utilities
+ *  \{
+ */
+
+
+/* Linear Algebra */
+
+/** Invert matrix.  Not using restrict, to allow inversion to be done in-place */
+psImage *
+psMatrixInvert(psImage *out,  ///< Matrix to return, or NULL
+               const psImage *myMatrix, ///< Matrix to be inverted
+               float *restrict determinant ///< Determinant to return, or NULL
+              );
+
+/** Matrix determinant */
+float
+psMatrixDeterminant(const psImage *restrict myMatrix ///< Matrix to get determinant for
+                   );
+
+/** Matrix operation: addition, subtraction, multiplication */
+psImage *
+psMatrixOp(psImage *out,  ///< Matrix to return, or NULL
+           const psImage *matrix1, ///< Matrix 1
+           const char *op,              ///< Operation to perform: "+", "-", "*"
+           const psImage *matrix2 ///< Matrix 2
+          );
+
+/** Transpose Matrix */
+psImage *
+psMatrixTranspose(psImage *out,  ///< Matrix to return, or NULL
+                  const psImage *myMatrix ///< Matrix to transpose
+                 );
+
+/** LU Decomposition of a matrix */
+psImage *
+psMatrixLUD(psImage *out,  ///< Matrix to return, or NULL
+            psImage *myMatrix  ///< Matrix to decompose
+           );
+
+/** LU Solution.  Solves for and returns x in the equation Ax = b */
+psVector *
+psMatrixLUSolve(psVector *out,  ///< Vector to return, or NULL
+                const psImage *luMatrix, ///< LU-decomposed matrix
+                const psVector *rhsVector ///< right-hand-side of the equation
+               );
+
+/***********************************************************************************************************/
+
+/* Conversions */
+
+/** Convert matrix to vector.  Intended for a 1-d matrix. */
+psVector *
+psMatrixToVector(psVector *out,  ///< Vector to return, or NULL
+                 psImage *myMatrix ///< Matrix to convert
+                );
+
+/** Convert vector to matrix. */
+psImage *
+psVectorToMatrix(psImage *out,  ///< Matrix to return, or NULL
+                 psVector *myVector ///< Vector to convert
+                );
+
+/* \} */ // End of MathGroup Functions
+
+#endif
Index: /trunk/psLib/src/mathtypes/psImage.h
===================================================================
--- /trunk/psLib/src/mathtypes/psImage.h	(revision 597)
+++ /trunk/psLib/src/mathtypes/psImage.h	(revision 597)
@@ -0,0 +1,284 @@
+# ifndef PS_IMAGE_H
+# define PS_IMAGE_H
+
+/** \file psImage.h
+ *  \brief Basic image definitions and operations.
+ *  \ingroup AstroGroup
+ */
+
+/// basic image data structure.
+typedef struct psImage
+{
+    psType type;    ///< image data type and dimension
+    int nx, ny;    ///< size of image
+    int x0, y0;    ///< data region relative to parent
+    union {
+        psF32 **rows;          ///< == rows_f32
+        psS8  **rows_s8;  ///< pointers to psS8 data
+        psS16 **rows_s16;  ///< pointers to psS16 data
+        psS32 **rows_s32;  ///< pointers to psS32 data
+        psU8  **rows_u8;  ///< pointers to psU8 data
+        psU16 **rows_u16;  ///< pointers to psU16 data
+        psU32 **rows_u32;  ///< pointers to psU32 data
+        psF32 **rows_f32;  ///< pointers to psF32 data
+        psF64 **rows_f64;  ///< pointers to psF64 data
+        psComplex **rows_complex; ///< pointers to psComplex data
+    } rows;
+    struct psImage *parent;  ///< parent, if a subimage
+    int Nchildren;   ///< number of subimages
+    struct psImage *children;  ///< children of this region; array of Nchildren pointers
+}
+psImage;
+
+/** Functions **************************************************************/
+/** \addtogroup AstroGroup Astronomy-Specific Utilities
+ *  \{
+ */
+
+/*** Image structure manipulation ***/
+
+/// Create an image of the specified size and type.
+psImage *
+psImageAlloc (int nx,   ///< image width
+              int ny,   ///< image height
+              psType type  ///< image data type
+             );
+
+/// Create a subimage of the specified area.
+psImage *
+psImageSubset(psImage *out,  ///< Subimage to return, or NULL
+              const psImage *image, ///< parent image
+              int nx,   ///< subimage width (<= image.nx - x0)
+              int ny,   ///< subimage width (<= image.ny - y0)
+              int x0,   ///< subimage x-offset (0 <= x0 < nx)
+              int y0   ///< subimage y-offset (0 <= y0 < ny)
+             );
+
+/// Destroy the specified image (destroy children if they exist).
+void
+psImageFree(psImage *restrict image ///< free this image
+           );
+
+/** Destroy the pixels of the specified image */
+psImage *
+psImageFreePixels(psImage *restrict image ///< Image whose pixels are to be freed
+                 );
+
+/// Destroy the children of the specified image.  Returns number of children freed.
+int
+psImageFreeChildren(const psImage *image ///< free children of this image
+                   );
+
+/// Create a copy of the specified image.
+psImage *
+psImageCopy(psImage *output,   ///< target structure for output image data
+            const psImage *input ///< copy this image
+           );
+
+/*** various image pixel extractions ***/
+
+/// Extract pixels from rectlinear region to a vector.
+psFloatArray *
+psImageSlice(psFloatArray *out,  ///< Vector to output, or NULL
+             const psImage *input, ///< extract slice from this image
+             int x,    ///< starting x coord of region to slice
+             int y,    ///< starting y coord of region to slice
+             int nx,    ///< width of region in x
+             int ny,    ///< width of region in y
+             int direction,  ///< direction of vector along slice
+             const psStats *stats ///< defines statistics used to find output values
+            );
+
+/// Extract pixels along a line to a vector.
+psFloatArray *
+psImageCut(psFloatArray *out,  ///< Vector to output, or NULL
+           const psImage *input, ///< extract cut from this image
+           float xs,    ///< starting x coord of cut
+           float ys,    ///< starting y coord of cut
+           float xe,    ///< ending x coord of cut
+           float ye,    ///< ending y coord of cut
+           float dw,    ///< width of cut
+           const psStats *stats  ///< defines statistics used to find output values
+          );
+
+/// Extract radial annulii data to a vector.
+psFloatArray *
+psImageRadialCut(psFloatArray *out, ///< Vector to output, or NULL
+                 const psImage *input, ///< extract profile from this image
+                 float x,   ///< center x coord of annulii
+                 float y,   ///< center y coord of annulii
+                 float radius,  ///< outer radius of annulii
+                 float dr,  ///< radial step size of annulii
+                 const psStats *stats ///< defines statistics used to find output values
+                );
+
+/* Contour is a high-level function */
+#if 0
+/// Extract a 2-d contour from an image at the given threshold.
+psFloatArray *
+psImageContour(psFloatArray *out, ///< Vector to output, or NULL
+               const psImage *input,  ///< create contour for this image
+               float threshold, ///< contour image at this threshold
+               int binning  ///< bin image by this value for contour calculation
+              );
+#endif
+
+/*** various image geometry manipulation ***/
+/// Rebin image to new scale.
+psImage *
+psImageRebin(psImage *out,  ///< Image to output, or NULL
+             const psImage *input, ///< rebin this image
+             float scale,   ///< rebinning scale: doutput = scale*dinput
+             const psStats *stats ///< defines statistics used to find output values
+            );
+
+/// Rotate image by given angle.
+psImage *
+psImageRotate(psImage *out,  ///< Image to output, or NULL
+              const psImage *input, ///< rotate this image
+              float angle  ///< rotate by this amount anti-clockwise (degrees)
+             );
+
+/// Shift image by an arbitrary number of pixels in either direction.
+/// Drop edge pixels, and set newly exposed pixels to 'exposed'.
+psImage *
+psImageShift(psImage *out,  ///< Image to output, or NULL
+             const psImage *input, ///< shift this image
+             float dx,   ///< shift by this amount in x
+             float dy,   ///< shift by this amount in y
+             float exposed  ///< set exposed pixels to this value
+            );
+
+/// Roll image by an integer number of pixels in either direction.
+/// Edge pixels wrap to the other side (no values are lost).
+psImage *
+psImageRoll(psImage *out,  ///< Image to output, or NULL
+            const psImage *input, ///< roll this image
+            int dx,    ///< roll this amount in x
+            int dy   ///< roll this amount in y
+           );
+
+/// Determine statistics for image (or subimage).
+psStats *
+psImageGetStats(const psImage *input,  ///< image (or subimage) to calculate stats
+                psStats *stats  ///< defines statistics to be calculated & target
+               );
+
+/// Construct a histogram from an image (or subimage).
+psHistogram *
+psImageHistogram(psHistogram *hist, ///< input histogram description & target
+                 const psImage *input ///< determine histogram of this image
+                );
+
+/// Fit a 2-D polynomial surface to an image.
+psPolynomial2D *
+psImageFitPolynomial(const psImage *input, ///< image to fit
+                     psPolynomial2D *coeffs ///< coefficient structure carries in desired terms & target
+                    );
+
+/// Evaluate a 2-D polynomial surface to image pixels.
+int
+psImageEvalPolynomial(const psImage *input, ///< image to fit
+                      const psPolynomial2D *coeffs ///< coefficient structure carries in desired terms
+                     );
+
+/*** image input/output routines ***/
+/// Read an image or subimage from a named file.
+psImage *
+psImageReadSection(psImage *output,  ///< place data in this structure for output
+                   int x,   ///< starting x coord of region
+                   int y,   ///< starting y coord of region
+                   int nx,   ///< x size of region (-1 for full range)
+                   int ny,   ///< y size of region (-1 for full range)
+                   int z,   ///< plane of interest
+                   const char *extname, ///< MEF extension name ("PHU" for primary header)
+                   int extnum,  ///< MEF extension number (-1 for "PHU", 0 : Nextend - 1)
+                   const char *filename ///< file to read data from
+                  );
+
+/// Read an image or subimage from file descriptor.
+psImage *
+psImageFReadSection(psImage *output, ///< place data in this structure for output
+                    int x,  ///< starting x coord of region
+                    int y,  ///< starting y coord of region
+                    int nx,  ///< x size of region (-1 for full range)
+                    int ny,  ///< y size of region (-1 for full range)
+                    int z,  ///< plane of interest
+                    const char *extname, ///< MEF extension name ("PHU" for primary header)
+                    int extnum,  ///< MEF extension number (-1 for "PHU", 0 : Nextend - 1)
+                    FILE *f  ///< file descriptor to read data from
+                   );
+
+/// Write an image section to named file (which may exist).
+psImage *
+psImageWriteSection(psImage *input,    ///< image to write out
+                    int x,   ///< starting x coord of region
+                    int y,   ///< starting y coord of region
+                    int z,   ///< plane of interest
+                    const char *extname, ///< MEF extension name ("PHU" for primary header)
+                    int extnum,  ///< MEF extension number (-1 for "PHU", 0 : Nextend - 1)
+                    const char *filename ///< file to write data to
+                   );
+
+/// Write an image section to named file (which may exist).
+psImage *
+psImageFWriteSection(psImage *input, ///< image to write out
+                     int x,   ///< starting x coord of region
+                     int y,   ///< starting y coord of region
+                     int z,   ///< plane of interest
+                     const char *extname, ///< MEF extension name
+                     int extnum,  ///< MEF extension number (-1 for "PHU", 0 : Nextend - 1)
+                     FILE *f  ///< file descriptor to write data to
+                    );
+
+/// Read only header from image file.
+psMetadata *
+psImageReadHeader(psMetadata *output, ///< read data to this structure
+                  const char *extname,  ///< MEF extension name ("PHU" for primary header)
+                  int extnum,  ///< MEF extension number (-1 for "PHU", 0 : Nextend - 1)
+                  const char *filename ///< file to read from
+                 );
+
+/// Read only header from image file descriptor.
+psMetadata *
+psImageFReadHeader(psMetadata *output, ///< read data to this structure
+                   const char *extname, ///< MEF extension name ("PHU" for primary header)
+                   int extnum,  ///< MEF extension number (-1 for "PHU", 0 : Nextend - 1)
+                   FILE *f  ///< file descriptor to read from
+                  );
+
+/*** basic pixel manipulations ***/
+/// Clip image values outside of range to given values.  Return number of clipped pixels.
+int
+psImageClip(psImage *input,   ///< clip this image
+            float min,   ///< clip pixels with values < min
+            float vmin,   ///< set min-clipped pixels to vmin
+            float max,   ///< clip pixels with values > max
+            float vmax   ///< set max-clipped pixels to vmax
+           );
+
+/// Clip NaN image pixels to given value.  Return number of clipped pixels.
+int
+psImageClipNaN(psImage *input,  ///< clip this image & target
+               float value  ///< set nan pixels to this value
+              );
+
+/// Overlay subregion of image with another image.  Return number of pixels replaced.
+int
+psImageOverlaySection(psImage *image, ///< input image & target
+                      const psImage *overlay, ///< image to overlay
+                      int x0,  ///< x offset of overlay subimage
+                      int y0,  ///< y offset of overlay subimage
+                      const char *op ///< overlay operation
+                     );
+
+/* \} */ // End of AstroGroup Functions
+
+# endif
+/* image overlay operations
+    PS_OVERLAY_EQUALS   = '=', 
+    PS_OVERLAY_ADD      = '+', 
+    PS_OVERLAY_SUBTRACT = '-', 
+    PS_OVERLAY_MULTIPLY = '*', 
+    PS_OVERLAY_DIVIDE   = '/', 
+*/
