Index: trunk/Ohana/src/addstar/src/loadgalphot_readstars.c
===================================================================
--- trunk/Ohana/src/addstar/src/loadgalphot_readstars.c	(revision 39122)
+++ 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;
 }
