Index: trunk/Ohana/src/addstar/src/loadgalphot_readstars.c
===================================================================
--- trunk/Ohana/src/addstar/src/loadgalphot_readstars.c	(revision 39124)
+++ trunk/Ohana/src/addstar/src/loadgalphot_readstars.c	(revision 39125)
@@ -217,4 +217,6 @@
     stars[i].found = FALSE;
 
+    dvo_galphot_init (&stars[i].galphot);
+
     // stars[i].galphot.R = R;
     // stars[i].galphot.D = D;
@@ -238,7 +240,5 @@
 
     // I want to use this flag to set a bit in secfilt.  is that possible?  or maybe galphot.dummy becomes flags
-    if (!FitChisqMinimum (fit, &stars[i].galphot, &GAL_CHISQ[Nsample*i], &GAL_FLUX[Nsample*i], &GAL_FLUX_ERR[Nsample*i], Nsample, FR_MAJOR_MIN[i], FR_MAJOR_MAX[i], FR_MAJOR_DEL[i], FR_MINOR_MIN[i], FR_MINOR_MAX[i], FR_MINOR_DEL[i])) {
-      stars[i].flag = TRUE;
-    }
+    FitChisqMinimum (fit, &stars[i].galphot, &GAL_CHISQ[Nsample*i], &GAL_FLUX[Nsample*i], &GAL_FLUX_ERR[Nsample*i], Nsample, FR_MAJOR_MIN[i], FR_MAJOR_MAX[i], FR_MAJOR_DEL[i], FR_MINOR_MIN[i], FR_MINOR_MAX[i], FR_MINOR_DEL[i]);
 
     // I could either multiply FR_MAJOR_MIN, etc above or the fitted values below
@@ -330,5 +330,5 @@
   }
 
-  if (Nvalid < 6) goto bad_fit;
+  if (Nvalid < 6) { galphot->flags |= ID_GALPHOT_TOO_FEW; goto bad_fit; }
 
 # if (0)
@@ -344,5 +344,5 @@
   // fit with 3 iterations, 5 sigma clipping (set above after fit2d_init)
   // on failure (for any reason), the stars[i].flag is set to TRUE (XXX bad choice)
-  if (!fit2d (fit, Xpt, Ypt, chisq, chisqFit, mask, Npts)) goto bad_fit;
+  if (!fit2d (fit, Xpt, Ypt, chisq, chisqFit, mask, Npts)) { galphot->flags |= ID_GALPHOT_FAIL_FIT; goto bad_fit; }
 
   // get X,Y for the chisq min from the fit:
@@ -358,5 +358,5 @@
   inRange = inRange && (Ymin < MinorMax + MinorDel);
 
-  if (!inRange) goto bad_fit;
+  if (!inRange) { galphot->flags |= ID_GALPHOT_OUT_OF_RANGE; goto bad_fit; }
 
   // chisqMin @ (Xmin,Ymin)
@@ -368,5 +368,6 @@
   C = -1;
   Q = B*B - 4*A*C;
-  if (Q < 0.0) goto bad_err;
+  if (Q < 0.0) { galphot->flags |= ID_GALPHOT_BAD_ERROR; goto bad_err; }
+  if (A <= 0.0) { galphot->flags |= ID_GALPHOT_BAD_ERROR; goto bad_err; }
   
   float dXmin = (-B + sqrt(Q)) / (2.0 * A);
@@ -377,5 +378,6 @@
   C = -1;
   Q = B*B - 4*A*C;
-  if (Q < 0.0) goto bad_err;
+  if (Q <  0.0) { galphot->flags |= ID_GALPHOT_BAD_ERROR; goto bad_err; }
+  if (A <= 0.0) { galphot->flags |= ID_GALPHOT_BAD_ERROR; goto bad_err; }
 
   float dYmin = (-B + sqrt(Q)) / (2.0 * A);
@@ -443,4 +445,8 @@
   galphot->majorAxisErr = MajorDel;
   galphot->minorAxisErr = MinorDel;
+
+  galphot->mag    = -2.5*log10(flux[iMin]) + ZeroPt; // correct for exptime?
+  galphot->magErr = sqrt(fluxErr[iMin]) / flux[iMin];
+  galphot->chisq  = chisqMin;
   return FALSE;
 }
Index: trunk/Ohana/src/libautocode/def/galphot-ps1-v5-r1.d
===================================================================
--- trunk/Ohana/src/libautocode/def/galphot-ps1-v5-r1.d	(revision 39124)
+++ trunk/Ohana/src/libautocode/def/galphot-ps1-v5-r1.d	(revision 39125)
@@ -26,5 +26,5 @@
 
 FIELD averef,       AVEREF,         unsigned int,   reference to average table
-FIELD dummy,        DUMMY,          unsigned int,   filler
+FIELD flags,        FLAGS,          unsigned int,   info flags
 
 FIELD photcode,     PHOTCODE,       short
Index: trunk/Ohana/src/libautocode/def/galphot-ps1-v5.d
===================================================================
--- trunk/Ohana/src/libautocode/def/galphot-ps1-v5.d	(revision 39124)
+++ trunk/Ohana/src/libautocode/def/galphot-ps1-v5.d	(revision 39125)
@@ -26,5 +26,5 @@
 
 FIELD averef,       AVEREF,         unsigned int,   reference to average table
-FIELD dummy,        DUMMY,          unsigned int,   filler
+FIELD flags,        FLAGS,          unsigned int,   info flags
 
 FIELD photcode,     PHOTCODE,       short
Index: trunk/Ohana/src/libautocode/def/galphot.d
===================================================================
--- trunk/Ohana/src/libautocode/def/galphot.d	(revision 39124)
+++ trunk/Ohana/src/libautocode/def/galphot.d	(revision 39125)
@@ -26,5 +26,5 @@
 
 FIELD averef,       AVEREF,         unsigned int,   reference to average table
-FIELD dummy,        DUMMY,          unsigned int,   filler
+FIELD flags,        FLAGS,          unsigned int,   info flags
 
 FIELD photcode,     PHOTCODE,       short
Index: trunk/Ohana/src/libdvo/include/dvo.h
===================================================================
--- trunk/Ohana/src/libdvo/include/dvo.h	(revision 39124)
+++ trunk/Ohana/src/libdvo/include/dvo.h	(revision 39125)
@@ -138,4 +138,11 @@
   ID_MEAS_PHOTOM_KRON    = 0x00400000,  // this measurement is used for the mean kron mag
 } DVOMeasureFlags;
+
+typedef enum {
+  ID_GALPHOT_FAIL_FIT       = 0x00000001, // fit failed to converge or was degenerate
+  ID_GALPHOT_TOO_FEW        = 0x00000002, // not enough points to fit the model
+  ID_GALPHOT_OUT_OF_RANGE   = 0x00000004, // fit minimum too far outside data range
+  ID_GALPHOT_BAD_ERROR      = 0x00000008, // invalid error (nan or inf)
+} DVOGalphotFlags;
 
 // XXX we used these names previously in markstar: replace with ID_MEAS_ARTIFACT
Index: trunk/Ohana/src/libdvo/src/dvo_catalog.c
===================================================================
--- trunk/Ohana/src/libdvo/src/dvo_catalog.c	(revision 39124)
+++ trunk/Ohana/src/libdvo/src/dvo_catalog.c	(revision 39125)
@@ -552,4 +552,5 @@
   galphot->imageID = -1;
   galphot->averef  = 0;
+  galphot->flags   = 0;
 
   galphot->photcode = 0;
Index: trunk/Ohana/src/libdvo/src/dvo_convert_PS1_V5.c
===================================================================
--- trunk/Ohana/src/libdvo/src/dvo_convert_PS1_V5.c	(revision 39124)
+++ trunk/Ohana/src/libdvo/src/dvo_convert_PS1_V5.c	(revision 39125)
@@ -1031,4 +1031,5 @@
     out[i].imageID	 = in[i].imageID;
     out[i].averef	 = in[i].averef;
+    out[i].flags	 = in[i].flags;
     out[i].photcode	 = in[i].photcode;
     out[i].modelType	 = in[i].modelType;
@@ -1065,4 +1066,5 @@
     out[i].imageID	 = in[i].imageID;
 //  out[i].averef	 = in[i].averef;
+//  out[i].flags	 = in[i].flags;
     out[i].photcode	 = in[i].photcode;
     out[i].modelType	 = in[i].modelType;
@@ -1097,4 +1099,5 @@
     out[i].imageID	 = in[i].imageID;
     out[i].averef	 = in[i].averef;
+    out[i].flags	 = in[i].flags;
     out[i].photcode	 = in[i].photcode;
     out[i].modelType	 = in[i].modelType;
Index: trunk/Ohana/src/libdvo/src/dvo_photcode_ops.c
===================================================================
--- trunk/Ohana/src/libdvo/src/dvo_photcode_ops.c	(revision 39124)
+++ trunk/Ohana/src/libdvo/src/dvo_photcode_ops.c	(revision 39125)
@@ -1944,14 +1944,15 @@
   }
 
-GALPHOT_FIELD(GAL_MAG, 	       mag)	       
-GALPHOT_FIELD(GAL_MAG_ERR,     magErr)    
-GALPHOT_FIELD(GAL_MAJ, 	       majorAxis)	       
+GALPHOT_FIELD(GAL_MAG, 	       mag) 
+GALPHOT_FIELD(GAL_MAG_ERR,     magErr) 
+GALPHOT_FIELD(GAL_MAJ, 	       majorAxis) 
 GALPHOT_FIELD(GAL_MAJ_ERR,     majorAxisErr)
-GALPHOT_FIELD(GAL_MIN, 	       minorAxis)	       
-GALPHOT_FIELD(GAL_MIN_ERR,     minorAxisErr)    
-GALPHOT_FIELD(GAL_THETA,       theta)      
-GALPHOT_FIELD(GAL_THETA_ERR,   thetaErr)  
+GALPHOT_FIELD(GAL_MIN, 	       minorAxis) 
+GALPHOT_FIELD(GAL_MIN_ERR,     minorAxisErr) 
+GALPHOT_FIELD(GAL_THETA,       theta) 
+GALPHOT_FIELD(GAL_THETA_ERR,   thetaErr) 
 GALPHOT_FIELD(GAL_INDEX,       index)      
 GALPHOT_FIELD(GAL_CHISQ,       chisq)      
 GALPHOT_FIELD(GAL_NPIX,        Npix)       
+GALPHOT_FIELD(GAL_FLAGS,       flags)       
 GALPHOT_FIELD(GAL_TYPE,        modelType)       
