Index: trunk/psModules/src/objects/pmSourceIO_PS1_DEV_1.c
===================================================================
--- trunk/psModules/src/objects/pmSourceIO_PS1_DEV_1.c	(revision 19903)
+++ trunk/psModules/src/objects/pmSourceIO_PS1_DEV_1.c	(revision 19904)
@@ -3,6 +3,6 @@
  *  @author EAM, IfA
  *
- *  @version $Revision: 1.10 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2008-04-08 18:35:38 $
+ *  @version $Revision: 1.11 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2008-10-06 13:02:43 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -61,4 +61,5 @@
     psF32 xPos, yPos;
     psF32 xErr, yErr;
+    psF32 errMag;
 
     // let's write these out in S/N order
@@ -67,5 +68,5 @@
     table = psArrayAllocEmpty (sources->n);
 
-    // we write out all sources, regardless of quality.  the source flags tell us the state
+    // we write out PSF-fits for all sources, regardless of quality.  the source flags tell us the state
     for (i = 0; i < sources->n; i++) {
         pmSource *source = (pmSource *) sources->data[i];
@@ -73,5 +74,5 @@
 
         // no difference between PSF and non-PSF model
-        pmModel *model = pmSourceGetModel (NULL, source);
+        pmModel *model = source->modelPSF;
 
         if (model != NULL) {
@@ -82,6 +83,8 @@
             xErr = dPAR[PM_PAR_XPOS];
             yErr = dPAR[PM_PAR_YPOS];
-
             axes = pmPSF_ModelToAxes (PAR, 20.0);
+
+	    // need to determine the PSF photometry error: source->errMag is the error on the 'best' model mag.
+	    errMag = model->dparams->data.F32[PM_PAR_I0] / model->params->data.F32[PM_PAR_I0];
         } else {
             xPos = source->peak->xf;
@@ -89,7 +92,8 @@
             xErr = source->peak->dx;
             yErr = source->peak->dy;
-            axes.major = 0.0;
-            axes.minor = 0.0;
-            axes.theta = 0.0;
+            axes.major = NAN;
+            axes.minor = NAN;
+            axes.theta = NAN;
+	    errMag = NAN;
         }
 
@@ -104,13 +108,21 @@
         psMetadataAdd (row, PS_LIST_TAIL, "X_PSF_SIG",        PS_DATA_F32, "Sigma in PSF x coordinate",                  xErr);
         psMetadataAdd (row, PS_LIST_TAIL, "Y_PSF_SIG",        PS_DATA_F32, "Sigma in PSF y coordinate",                  yErr);
-        psMetadataAdd (row, PS_LIST_TAIL, "PSF_INST_MAG",     PS_DATA_F32, "PSF fit instrumental magnitude",             PS_MIN (99.0, source->psfMag));
-        psMetadataAdd (row, PS_LIST_TAIL, "PSF_INST_MAG_SIG", PS_DATA_F32, "Sigma of PSF instrumental magnitude",        PS_MIN (99.0, source->errMag));
-        psMetadataAdd (row, PS_LIST_TAIL, "PEAK_FLUX_AS_MAG", PS_DATA_F32, "Peak flux expressed as magnitude",           PS_MIN (99.0, peakMag));
+        psMetadataAdd (row, PS_LIST_TAIL, "PSF_INST_MAG",     PS_DATA_F32, "PSF fit instrumental magnitude",             source->psfMag);
+        psMetadataAdd (row, PS_LIST_TAIL, "PSF_INST_MAG_SIG", PS_DATA_F32, "Sigma of PSF instrumental magnitude",        source->errMag);
+        psMetadataAdd (row, PS_LIST_TAIL, "PEAK_FLUX_AS_MAG", PS_DATA_F32, "Peak flux expressed as magnitude",           peakMag);
         psMetadataAdd (row, PS_LIST_TAIL, "SKY",              PS_DATA_F32, "Sky level",                                  source->sky);
         psMetadataAdd (row, PS_LIST_TAIL, "SKY_SIGMA",        PS_DATA_F32, "Sigma of sky level",                         source->skyErr);
 
-        psMetadataAdd (row, PS_LIST_TAIL, "PSF_CHISQ",        PS_DATA_F32,  "Chisq of PSF-fit to top 9 pixels",          source->psfChisq);
+        psMetadataAdd (row, PS_LIST_TAIL, "PSF_CHISQ",        PS_DATA_F32,  "Chisq of PSF-fit",                          model->chisq);
         psMetadataAdd (row, PS_LIST_TAIL, "CR_NSIGMA",        PS_DATA_F32,  "Nsigma deviations from PSF to CF",          source->crNsigma);
         psMetadataAdd (row, PS_LIST_TAIL, "EXT_NSIGMA",       PS_DATA_F32,  "Nsigma deviations from PSF to EXT",         source->extNsigma);
+
+	// EXT_NSIGMA will be NAN if: 1) contour ellipse is imaginary; 2) source is not
+	// subtracted
+
+	// CR_NSIGMA will be NAN if: 1) source is not subtracted; 2) source is on the image
+	// edge; 3) any pixels in the 3x3 peak region are masked; 
+
+	// CR_NSIGMA and 
 
         // XXX these should be major and minor, not 'x' and 'y'
