Index: /branches/eam_branches/ipp-20120405/Ohana/src/relphot/src/MosaicOps.c
===================================================================
--- /branches/eam_branches/ipp-20120405/Ohana/src/relphot/src/MosaicOps.c	(revision 33735)
+++ /branches/eam_branches/ipp-20120405/Ohana/src/relphot/src/MosaicOps.c	(revision 33736)
@@ -569,4 +569,6 @@
 }
 
+static int npass_output = 0;
+
 int setMmos (Catalog *catalog, int PoorImages, FlatCorrectionTable *flatcorr) {
 
@@ -627,4 +629,23 @@
     int minUbercalDist = 1000;
 
+    int testImage = FALSE;
+    testImage |= (abs(mosaic[i].start - 1323003245) < 10);
+    testImage |= (abs(mosaic[i].start - 1323003069) < 10);
+    testImage |= (abs(mosaic[i].start - 1323003125) < 10);
+    testImage |= (abs(mosaic[i].start - 1323003300) < 10);
+    testImage |= (abs(mosaic[i].start - 1323003365) < 10);
+    testImage |= (abs(mosaic[i].start - 1323003191) < 10);
+    testImage |= (abs(mosaic[i].start - 1323003014) < 10);
+    testImage |= (abs(mosaic[i].start - 1323003484) < 10);
+    testImage |= (abs(mosaic[i].start - 1323003419) < 10);
+    testImage |= (abs(mosaic[i].start - 1323002949) < 10);
+
+    FILE *fout = NULL;
+    if (testImage) {
+      char filename[64];
+      snprintf (filename, 64, "test.%05d.%02d.dat", (int) i, npass_output);
+      fout = fopen (filename, "w");
+    }
+
     // number of stars to measure the bright-end scatter
     Nbright = 0;
@@ -636,4 +657,20 @@
       c = MosaicToCatalog[i][j];
       
+      if (fout) {
+	Mcal  = getMcal  (m, c, flatcorr, catalog);
+	Mgrid = getMgrid (m, c);
+	Mrel  = getMrel  (catalog, m, c);
+	Mflat = getMflat (m, c, flatcorr, catalog);
+
+	n = catalog[c].measureT[m].averef;
+	Msys = PhotSysTiny (&catalog[c].measureT[m], &catalog[c].averageT[n], &catalog[c].secfilt[n*Nsecfilt]);
+
+	float delta = Msys - Mrel - Mcal - Mgrid + Mflat;
+
+	int isBad = (catalog[c].measureT[m].dbFlags & MEAS_BAD);
+
+	fprintf (fout, "%f %f : %f %f %f %f %f  : %f %d\n", catalog[c].averageT[n].R, catalog[c].averageT[n].D, Msys, Mrel, Mcal, Mgrid, Mflat, delta, isBad);
+      }
+
       if (catalog[c].measureT[m].dbFlags & MEAS_BAD) {
 	  Nbad ++;
@@ -689,4 +726,8 @@
     /* N_onMosaic[i] is all measurements, N is good measurements */
 
+    if (fout) {
+      fclose (fout);
+    }
+
     /* too few good measurements or too many bad measurements (skip in PoorImages run) */
     if (!PoorImages) {
@@ -696,4 +737,7 @@
 	mosaic[i].flags |= ID_IMAGE_PHOTOM_FEW;
 	Nfew ++;
+	if (testImage) {
+	  fprintf (stderr, "NOTE: *** marked test image poor : %d %d %d***\n", (int) N, (int) IMAGE_TOOFEW, (int) (IMAGE_GOOD_FRACTION*N_onMosaic[i]));
+	}
       } else {
 	mosaic[i].flags &= ~ID_IMAGE_PHOTOM_FEW;
@@ -708,4 +752,8 @@
     mosaic[i].Xm    = 100.0*log10(stats.chisq);
 
+    if (testImage) {
+      fprintf (stderr, "test image %d (%d) %f %f %d ... ", (int) i, mosaic[i].start, stats.mean, stats.error, mosaic[i].nFitPhotom);
+    }
+
     plot_setMcal (list, N, &stats, CLOUD_TOLERANCE);
 
@@ -716,4 +764,8 @@
     if (mosaic[i].Mcal < -CLOUD_TOLERANCE) {
       mosaic[i].Mcal = 0.0;
+    }
+
+    if (testImage) {
+      fprintf (stderr, "%f %f\n", mosaic[i].Mcal, mosaic[i].dMsys);
     }
 
@@ -733,4 +785,6 @@
   free (Mlist);
   free (dMlist);
+
+  npass_output ++;
 
   fprintf (stderr, "%d mosaics marked having too few measurements (Nbad: %d, Ncal: %d, Ngrid: %d, Nrel: %d, Nsys: %d)\n", Nfew, Nbad, Ncal, Ngrid, Nrel, Nsys);
Index: /branches/eam_branches/ipp-20120405/Ohana/src/relphot/src/StarOps.c
===================================================================
--- /branches/eam_branches/ipp-20120405/Ohana/src/relphot/src/StarOps.c	(revision 33735)
+++ /branches/eam_branches/ipp-20120405/Ohana/src/relphot/src/StarOps.c	(revision 33736)
@@ -376,5 +376,6 @@
 	catalog[i].secfilt[Nsecfilt*j+Nsec].M  = stats.mean;
 	catalog[i].secfilt[Nsecfilt*j+Nsec].Map = apstats.mean;
-	catalog[i].secfilt[Nsecfilt*j+Nsec].dM = MAX (stats.error, stats.sigma);
+	catalog[i].secfilt[Nsecfilt*j+Nsec].dM = stats.error;
+	catalog[i].secfilt[Nsecfilt*j+Nsec].Mstdev = 1000.0*stats.sigma; // Mstdev is in millimags (not enough space for more precision)
 	catalog[i].secfilt[Nsecfilt*j+Nsec].Xm = (stats.Nmeas > 1) ? 100.0*log10(stats.chisq) : NAN_S_SHORT;
 	catalog[i].secfilt[Nsecfilt*j+Nsec].Ncode = Ncode;
@@ -488,5 +489,6 @@
 	/* use sigma or error in dM for output? */
 	catalog[i].secfilt[Nsecfilt*j+Ns].M  = stats.mean;
-	catalog[i].secfilt[Nsecfilt*j+Ns].dM = MAX (stats.error, stats.sigma);
+	catalog[i].secfilt[Nsecfilt*j+Ns].dM = stats.error;
+	catalog[i].secfilt[Nsecfilt*j+Ns].Mstdev = 1000.0*stats.sigma; // Mstdev is in millimags (not enough space for more precision)
 	catalog[i].secfilt[Nsecfilt*j+Ns].Xm = (stats.Nmeas > 1) ? 100.0*log10(stats.chisq) : NAN_S_SHORT;
 	catalog[i].secfilt[Nsecfilt*j+Ns].Ncode = N;
Index: /branches/eam_branches/ipp-20120405/Ohana/src/relphot/src/bcatalog.c
===================================================================
--- /branches/eam_branches/ipp-20120405/Ohana/src/relphot/src/bcatalog.c	(revision 33735)
+++ /branches/eam_branches/ipp-20120405/Ohana/src/relphot/src/bcatalog.c	(revision 33736)
@@ -74,4 +74,5 @@
 	subcatalog[0].secfilt[Nsecfilt*Naverage+Nsec].Map    = NAN;
 	subcatalog[0].secfilt[Nsecfilt*Naverage+Nsec].dM     = NAN;
+	subcatalog[0].secfilt[Nsecfilt*Naverage+Nsec].Mstdev = NAN_S_SHORT;
 	subcatalog[0].secfilt[Nsecfilt*Naverage+Nsec].Xm     = NAN;
 	subcatalog[0].secfilt[Nsecfilt*Naverage+Nsec].M_20   = NAN_S_SHORT;
Index: /branches/eam_branches/ipp-20120405/Ohana/src/relphot/src/relphot_objects.c
===================================================================
--- /branches/eam_branches/ipp-20120405/Ohana/src/relphot/src/relphot_objects.c	(revision 33735)
+++ /branches/eam_branches/ipp-20120405/Ohana/src/relphot/src/relphot_objects.c	(revision 33736)
@@ -78,4 +78,5 @@
 	  catalog.secfilt[j*Nsecfilt + k].Map    = NAN;
 	  catalog.secfilt[j*Nsecfilt + k].dM   	 = NAN;
+	  catalog.secfilt[j*Nsecfilt + k].Mstdev = NAN_S_SHORT;
 	  catalog.secfilt[j*Nsecfilt + k].Xm     = NAN;
 	  catalog.secfilt[j*Nsecfilt + k].M_20 	 = NAN_S_SHORT;
Index: /branches/eam_branches/ipp-20120405/Ohana/src/relphot/src/setMrelFinal.c
===================================================================
--- /branches/eam_branches/ipp-20120405/Ohana/src/relphot/src/setMrelFinal.c	(revision 33735)
+++ /branches/eam_branches/ipp-20120405/Ohana/src/relphot/src/setMrelFinal.c	(revision 33736)
@@ -43,4 +43,5 @@
 	catalog[0].secfilt[N].Map    = NAN;
 	catalog[0].secfilt[N].dM     = NAN;
+	catalog[0].secfilt[N].Mstdev = NAN_S_SHORT;
 	catalog[0].secfilt[N].Xm     = NAN;
 	catalog[0].secfilt[N].M_20   = NAN_S_SHORT;
