Index: trunk/psLib/src/fits/psFitsImage.c
===================================================================
--- trunk/psLib/src/fits/psFitsImage.c	(revision 19383)
+++ trunk/psLib/src/fits/psFitsImage.c	(revision 19384)
@@ -7,6 +7,6 @@
  *  @author Robert DeSonia, MHPCC
  *
- *  @version $Revision: 1.39 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2008-09-05 07:51:09 $
+ *  @version $Revision: 1.40 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2008-09-05 08:08:33 $
  *
  *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
@@ -892,7 +892,17 @@
 bool psFitsWriteImageCube(psFits *fits, psMetadata *header, const psArray *input, const char *extname)
 {
+    return psFitsWriteImageCubeWithMask(fits, header, input, NULL, 0, extname);
+}
+
+bool psFitsWriteImageCubeWithMask(psFits *fits, psMetadata *header, const psArray *input,
+                                  const psArray *masks, psMaskType maskVal, const char *extname)
+{
     PS_ASSERT_FITS_NON_NULL(fits, false);
     PS_ASSERT_FITS_WRITABLE(fits, false);
     PS_ASSERT_ARRAY_NON_NULL(input, false);
+    if (masks) {
+        PS_ASSERT_ARRAY_NON_NULL(masks, false);
+        PS_ASSERT_ARRAYS_SIZE_EQUAL(masks, input, false);
+    }
 
     if (input->n == 0) {
@@ -903,5 +913,6 @@
     if (input->n == 1) {
         // The problem reduces to one already solved
-        return psFitsWriteImage(fits, header, input->data[0], 1, extname);
+        return psFitsWriteImageWithMask(fits, header, input->data[0],
+                                        masks ? masks->data[0] : NULL, maskVal, 1, extname);
     }
 
@@ -930,5 +941,5 @@
         psMetadataAddS32(headerCopy, PS_LIST_HEAD, "NAXIS3", PS_META_REPLACE, "Number of image planes",
                          input->n);
-    if (! update) {
+    if (!update) {
         psError(PS_ERR_UNKNOWN, false, _("Failed to add metadata item, %s."),
                 "NAXIS, NAXIS1, NAXIS2, NAXIS3");
@@ -940,5 +951,6 @@
     // The first is an psFitsImageWrite to create the extension.
     // The next are psFitsImageUpdate to write into the extension.
-    if (! psFitsWriteImage(fits, headerCopy, input->data[0], input->n, extname)) {
+    if (!psFitsWriteImageWithMask(fits, headerCopy, input->data[0],
+                                  masks ? masks->data[0] : NULL, maskVal, input->n, extname)) {
         psError(PS_ERR_UNKNOWN, false, _("Could not write image plane %d."), 0);
         psFree(headerCopy);
@@ -948,5 +960,6 @@
 
     for (int i = 1; i < input->n; i++) {
-        if (! psFitsUpdateImage(fits, input->data[i], 0, 0, i)) {
+        if (!psFitsUpdateImageWithMask(fits, input->data[i],
+                                       masks ? masks->data[i] : NULL, maskVal, 0, 0, i)) {
             psError(PS_ERR_UNKNOWN, false, _("Could not write image plane %d."), i);
             return false;
@@ -958,4 +971,10 @@
 
 bool psFitsUpdateImageCube(psFits *fits, const psArray *input, int x0, int y0)
+{
+    return psFitsUpdateImageCubeWithMask(fits, input, NULL, 0, x0, y0);
+}
+
+bool psFitsUpdateImageCubeWithMask(psFits *fits, const psArray *input,
+                                   const psArray *masks, psMaskType maskVal, int x0, int y0)
 {
     PS_ASSERT_FITS_NON_NULL(fits, false);
@@ -969,5 +988,6 @@
 
     for (int i = 0; i < input->n; i++) {
-        if (! psFitsUpdateImage(fits, input->data[i], x0, y0, i)) {
+        if (!psFitsUpdateImageWithMask(fits, input->data[i],
+                                       masks ? masks->data[i] : NULL, maskVal, x0, y0, i)) {
             psError(PS_ERR_UNKNOWN, false, _("Could not update image plane %d."), i);
             return false;
Index: trunk/psLib/src/fits/psFitsImage.h
===================================================================
--- trunk/psLib/src/fits/psFitsImage.h	(revision 19383)
+++ trunk/psLib/src/fits/psFitsImage.h	(revision 19384)
@@ -4,6 +4,6 @@
  * @author Robert DeSonia, MHPCC
  *
- * @version $Revision: 1.9 $ $Name: not supported by cvs2svn $
- * @date $Date: 2008-09-05 07:51:09 $
+ * @version $Revision: 1.10 $ $Name: not supported by cvs2svn $
+ * @date $Date: 2008-09-05 08:08:33 $
  * Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
  */
@@ -134,9 +134,49 @@
 );
 
-psArray *psFitsReadImageCube(const psFits *fits, psRegion region);
+/// Read an image cube (3D image with each plane a separate image)
+///
+/// Images are returned in an array of psImage
+psArray *psFitsReadImageCube(
+    const psFits *fits,                 ///< FITS file to read
+    psRegion region                     ///< Region to read
+    );
 
-bool psFitsWriteImageCube(psFits *fits, psMetadata *header, const psArray *input, const char *extname);
+/// Write an image cube (3D image from an array of images)
+bool psFitsWriteImageCube(
+    psFits *fits,                       ///< FITS file to write
+    psMetadata *header,                 ///< Header to write
+    const psArray *input,               ///< Array of images
+    const char *extname                 ///< Name of extension
+    );
 
-bool psFitsUpdateImageCube(psFits *fits, const psArray *input, int x0, int y0);
+/// Write an image cube (3D image from an array of images), optionally using the supplied mask images to do
+/// statistics when compressing
+bool psFitsWriteImageCubeWithMask(
+    psFits *fits,                       ///< FITS file to write
+    psMetadata *header,                 ///< Header to write
+    const psArray *input,               ///< Array of images
+    const psArray *masks,               ///< Array of masks
+    psMaskType maskVal,                 ///< Value to mask
+    const char *extname                 ///< Name of extension
+    );
+
+/// Update an image cube (3D image from an array of images)
+bool psFitsUpdateImageCube(
+    psFits *fits,                       ///< FITS file to update
+    const psArray *input,               ///< Array of images
+    int x0,                             ///< x origin of images in FITS image coordinates
+    int y0                              ///< y origin of images in FITS image coordinates
+    );
+
+/// Update an image cube (3D image from an array of images), optionally using the supplied mask images to do
+/// statistics when compressing
+bool psFitsUpdateImageCubeWithMask(
+    psFits *fits,                       ///< FITS file to update
+    const psArray *input,               ///< Array of images
+    const psArray *masks,               ///< Array of masks
+    psMaskType maskVal,                 ///< Value to mask
+    int x0,                             ///< x origin of images in FITS image coordinates
+    int y0                              ///< y origin of images in FITS image coordinates
+    );
 
 /// @}
