Index: /trunk/psModules/src/objects/Makefile.am
===================================================================
--- /trunk/psModules/src/objects/Makefile.am	(revision 23183)
+++ /trunk/psModules/src/objects/Makefile.am	(revision 23184)
@@ -19,4 +19,5 @@
 	pmModelUtils.c \
 	pmSource.c \
+	pmSourceMasks.c \
 	pmSourceMoments.c \
 	pmSourceExtendedPars.c \
@@ -69,4 +70,5 @@
 	pmModelUtils.h \
 	pmSource.h \
+	pmSourceMasks.h \
 	pmSourceExtendedPars.h \
 	pmSourceUtils.h \
Index: /trunk/psModules/src/objects/pmSource.h
===================================================================
--- /trunk/psModules/src/objects/pmSource.h	(revision 23183)
+++ /trunk/psModules/src/objects/pmSource.h	(revision 23184)
@@ -19,4 +19,6 @@
 /// @addtogroup Objects Object Detection / Analysis Functions
 /// @{
+
+#include <pmSourceMasks.h>
 
 /** pmSourceType enumeration
@@ -34,37 +36,4 @@
     PM_SOURCE_TYPE_EXTENDED,            ///< an extended object (eg, galaxy) (subtracted model is EXT)
 } pmSourceType;
-
-// bit flags to distinguish analysis results
-typedef enum {
-    PM_SOURCE_MODE_DEFAULT    	    = 0x00000000, ///< Initial value: resets all bits
-    PM_SOURCE_MODE_PSFMODEL   	    = 0x00000001, ///< Source fitted with a psf model (linear or non-linear)
-    PM_SOURCE_MODE_EXTMODEL   	    = 0x00000002, ///< Source fitted with an extended-source model
-    PM_SOURCE_MODE_FITTED     	    = 0x00000004, ///< Source fitted with non-linear model (PSF or EXT; good or bad)
-    PM_SOURCE_MODE_FAIL       	    = 0x00000008, ///< Fit (non-linear) failed (non-converge, off-edge, run to zero)
-    PM_SOURCE_MODE_POOR       	    = 0x00000010, ///< Fit succeeds, but low-SN, high-Chisq, or large (for PSF -- drop?)
-    PM_SOURCE_MODE_PAIR       	    = 0x00000020, ///< Source fitted with a double psf
-    PM_SOURCE_MODE_PSFSTAR    	    = 0x00000040, ///< Source used to define PSF model
-    PM_SOURCE_MODE_SATSTAR    	    = 0x00000080, ///< Source model peak is above saturation
-    PM_SOURCE_MODE_BLEND      	    = 0x00000100, ///< Source is a blend with other sourcers
-    PM_SOURCE_MODE_EXTERNAL   	    = 0x00000200, ///< Source based on supplied input position
-    PM_SOURCE_MODE_BADPSF     	    = 0x00000400, ///< Failed to get good estimate of object's PSF
-    PM_SOURCE_MODE_DEFECT     	    = 0x00000800, ///< Source is thought to be a defect
-    PM_SOURCE_MODE_SATURATED  	    = 0x00001000, ///< Source is thought to be saturated pixels (bleed trail)
-    PM_SOURCE_MODE_CR_LIMIT   	    = 0x00002000, ///< Source has crNsigma above limit
-    PM_SOURCE_MODE_EXT_LIMIT  	    = 0x00004000, ///< Source has extNsigma above limit
-    PM_SOURCE_MODE_MOMENTS_FAILURE  = 0x00008000, ///< could not measure the moments
-    PM_SOURCE_MODE_SKY_FAILURE      = 0x00010000, ///< could not measure the local sky
-    PM_SOURCE_MODE_SKYVAR_FAILURE   = 0x00020000, ///< could not measure the local sky variance
-    PM_SOURCE_MODE_BELOW_MOMENTS_SN = 0x00040000, ///< moments not measured due to low S/N
-    PM_SOURCE_MODE_BIG_RADIUS       = 0x00100000, ///< poor moments for small radius, try large radius
-    PM_SOURCE_MODE_AP_MAGS          = 0x00200000, ///< source has an aperture magnitude
-    PM_SOURCE_MODE_BLEND_FIT        = 0x00400000, ///< source was fitted as a blend
-    PM_SOURCE_MODE_EXTENDED_FIT     = 0x00800000, ///< full extended fit was used
-    PM_SOURCE_MODE_EXTENDED_STATS   = 0x01000000, ///< extended aperture stats calculated
-    PM_SOURCE_MODE_LINEAR_FIT       = 0x02000000, ///< source fitted with the linear fit
-    PM_SOURCE_MODE_NONLINEAR_FIT    = 0x04000000, ///< source fitted with the non-linear fit
-    PM_SOURCE_MODE_RADIAL_FLUX      = 0x08000000, ///< radial flux measurements calculated
-    PM_SOURCE_MODE_SIZE_SKIPPED     = 0x10000000, ///< size could not be determined
-} pmSourceMode;
 
 typedef enum {
@@ -101,5 +70,5 @@
     pmSourceType type;                  ///< Best identification of object.
     pmSourceMode mode;                  ///< analysis flags set for object.
-    pmSourceTmpF tmpFlags;		///< internal-only flags
+    pmSourceTmpF tmpFlags;              ///< internal-only flags
     psArray *blends;                    ///< collection of sources thought to be confused with object
     float psfMag;                       ///< calculated from flux in modelPSF
Index: /trunk/psModules/src/objects/pmSourceIO_CMF_PS1_V1.c
===================================================================
--- /trunk/psModules/src/objects/pmSourceIO_CMF_PS1_V1.c	(revision 23183)
+++ /trunk/psModules/src/objects/pmSourceIO_CMF_PS1_V1.c	(revision 23184)
@@ -209,17 +209,23 @@
     }
 
+    psMetadata *header = psMetadataCopy(NULL, tableHeader);
+    pmSourceMasksHeader(header);
+
     if (table->n == 0) {
-        psFitsWriteBlank (fits, tableHeader, extname);
-        psFree (table);
+        psFitsWriteBlank(fits, header, extname);
+        psFree(table);
+        psFree(header);
         return true;
     }
 
     psTrace ("pmFPAfile", 5, "writing ext data %s\n", extname);
-    if (!psFitsWriteTable (fits, tableHeader, table, extname)) {
+    if (!psFitsWriteTable(fits, header, table, extname)) {
         psError(PS_ERR_IO, false, "writing ext data %s\n", extname);
         psFree(table);
+        psFree(header);
         return false;
     }
-    psFree (table);
+    psFree(table);
+    psFree(header);
 
     return true;
Index: /trunk/psModules/src/objects/pmSourceMasks.c
===================================================================
--- /trunk/psModules/src/objects/pmSourceMasks.c	(revision 23184)
+++ /trunk/psModules/src/objects/pmSourceMasks.c	(revision 23184)
@@ -0,0 +1,48 @@
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <stdio.h>
+#include <pslib.h>
+
+#include "pmSourceMasks.h"
+
+#define ADD_MASK(HEADER, NAME, COMMENT) \
+    psMetadataAddU32(HEADER, PS_LIST_TAIL, "SOURCE.MASK." #NAME, \
+                     PS_META_REPLACE, COMMENT, (psU32)PM_SOURCE_MODE_##NAME);
+
+bool pmSourceMasksHeader(psMetadata *header)
+{
+    PS_ASSERT_METADATA_NON_NULL(header, false);
+
+    ADD_MASK(header, PSFMODEL        , "Fit with PSF model");
+    ADD_MASK(header, EXTMODEL        , "Fit with extended model");
+    ADD_MASK(header, FITTED          , "Fit with non-linear model");
+    ADD_MASK(header, FAIL            , "Non-linear fit failed");
+    ADD_MASK(header, POOR            , "Non-linear fit poor");
+    ADD_MASK(header, PAIR            , "Fit with double PSF");
+    ADD_MASK(header, PSFSTAR         , "Used to define PSF model");
+    ADD_MASK(header, SATSTAR         , "Model peak is above saturation");
+    ADD_MASK(header, BLEND           , "Blended with other sources");
+    ADD_MASK(header, EXTERNAL        , "Based on supplied input position");
+    ADD_MASK(header, BADPSF          , "Unable to estimate object PSF");
+    ADD_MASK(header, DEFECT          , "Suspected defect");
+    ADD_MASK(header, SATURATED       , "Suspected saturated (bleed trail)");
+    ADD_MASK(header, CR_LIMIT        , "Suspected cosmic ray");
+    ADD_MASK(header, EXT_LIMIT       , "Suspected extended");
+    ADD_MASK(header, MOMENTS_FAILURE , "Failed to measure moments");
+    ADD_MASK(header, SKY_FAILURE     , "Failed to measure local sky");
+    ADD_MASK(header, SKYVAR_FAILURE  , "Failed to measure sky variance");
+    ADD_MASK(header, BELOW_MOMENTS_SN, "Moments not measured due to low S/N");
+    ADD_MASK(header, BIG_RADIUS      , "Small radius has poor moments");
+    ADD_MASK(header, AP_MAGS         , "Measured aperture magnitude");
+    ADD_MASK(header, BLEND_FIT       , "Fit as a blend");
+    ADD_MASK(header, EXTENDED_FIT    , "Fit with full extended fit");
+    ADD_MASK(header, EXTENDED_STATS  , "Calculated extended aperture stats");
+    ADD_MASK(header, LINEAR_FIT      , "Fit with linear fit");
+    ADD_MASK(header, NONLINEAR_FIT   , "Fit with non-linear fit");
+    ADD_MASK(header, RADIAL_FLUX     , "Calculated radial flux measurements");
+    ADD_MASK(header, SIZE_SKIPPED    , "Could not be determine size");
+
+    return true;
+}
Index: /trunk/psModules/src/objects/pmSourceMasks.h
===================================================================
--- /trunk/psModules/src/objects/pmSourceMasks.h	(revision 23184)
+++ /trunk/psModules/src/objects/pmSourceMasks.h	(revision 23184)
@@ -0,0 +1,46 @@
+#ifndef PM_SOURCE_MASKS_H
+#define PM_SOURCE_MASKS_H
+
+// Bit flags to distinguish analysis results
+// When adding to or subtracting from this list, please also modify pmSourceMaskHeader
+typedef enum {
+    PM_SOURCE_MODE_DEFAULT          = 0x00000000, ///< Initial value: resets all bits
+    PM_SOURCE_MODE_PSFMODEL         = 0x00000001, ///< Source fitted with a psf model (linear or non-linear)
+    PM_SOURCE_MODE_EXTMODEL         = 0x00000002, ///< Source fitted with an extended-source model
+    PM_SOURCE_MODE_FITTED           = 0x00000004, ///< Source fitted with non-linear model (PSF or EXT; good or bad)
+    PM_SOURCE_MODE_FAIL             = 0x00000008, ///< Fit (non-linear) failed (non-converge, off-edge, run to zero)
+    PM_SOURCE_MODE_POOR             = 0x00000010, ///< Fit succeeds, but low-SN, high-Chisq, or large (for PSF -- drop?)
+    PM_SOURCE_MODE_PAIR             = 0x00000020, ///< Source fitted with a double psf
+    PM_SOURCE_MODE_PSFSTAR          = 0x00000040, ///< Source used to define PSF model
+    PM_SOURCE_MODE_SATSTAR          = 0x00000080, ///< Source model peak is above saturation
+    PM_SOURCE_MODE_BLEND            = 0x00000100, ///< Source is a blend with other sourcers
+    PM_SOURCE_MODE_EXTERNAL         = 0x00000200, ///< Source based on supplied input position
+    PM_SOURCE_MODE_BADPSF           = 0x00000400, ///< Failed to get good estimate of object's PSF
+    PM_SOURCE_MODE_DEFECT           = 0x00000800, ///< Source is thought to be a defect
+    PM_SOURCE_MODE_SATURATED        = 0x00001000, ///< Source is thought to be saturated pixels (bleed trail)
+    PM_SOURCE_MODE_CR_LIMIT         = 0x00002000, ///< Source has crNsigma above limit
+    PM_SOURCE_MODE_EXT_LIMIT        = 0x00004000, ///< Source has extNsigma above limit
+    PM_SOURCE_MODE_MOMENTS_FAILURE  = 0x00008000, ///< could not measure the moments
+    PM_SOURCE_MODE_SKY_FAILURE      = 0x00010000, ///< could not measure the local sky
+    PM_SOURCE_MODE_SKYVAR_FAILURE   = 0x00020000, ///< could not measure the local sky variance
+    PM_SOURCE_MODE_BELOW_MOMENTS_SN = 0x00040000, ///< moments not measured due to low S/N
+    PM_SOURCE_MODE_BIG_RADIUS       = 0x00100000, ///< poor moments for small radius, try large radius
+    PM_SOURCE_MODE_AP_MAGS          = 0x00200000, ///< source has an aperture magnitude
+    PM_SOURCE_MODE_BLEND_FIT        = 0x00400000, ///< source was fitted as a blend
+    PM_SOURCE_MODE_EXTENDED_FIT     = 0x00800000, ///< full extended fit was used
+    PM_SOURCE_MODE_EXTENDED_STATS   = 0x01000000, ///< extended aperture stats calculated
+    PM_SOURCE_MODE_LINEAR_FIT       = 0x02000000, ///< source fitted with the linear fit
+    PM_SOURCE_MODE_NONLINEAR_FIT    = 0x04000000, ///< source fitted with the non-linear fit
+    PM_SOURCE_MODE_RADIAL_FLUX      = 0x08000000, ///< radial flux measurements calculated
+    PM_SOURCE_MODE_SIZE_SKIPPED     = 0x10000000, ///< size could not be determined
+} pmSourceMode;
+
+
+/// Populate header with mask values
+bool pmSourceMasksHeader(
+    psMetadata *header                  ///< Header to populate
+    );
+
+
+
+#endif
Index: /trunk/psModules/src/psmodules.h
===================================================================
--- /trunk/psModules/src/psmodules.h	(revision 23183)
+++ /trunk/psModules/src/psmodules.h	(revision 23184)
@@ -113,4 +113,5 @@
 #include <pmPSF.h>
 #include <pmModel.h>
+#include <pmSourceMasks.h>
 #include <pmSource.h>
 #include <pmSourceUtils.h>
