Index: branches/eam_branches/relphot.20200519/src/GridOps.c
===================================================================
--- branches/eam_branches/relphot.20200519/src/GridOps.c	(revision 41360)
+++ branches/eam_branches/relphot.20200519/src/GridOps.c	(revision 41387)
@@ -289,7 +289,7 @@
 
   int **gotstar, **gridmeas;
-  int i, j, k, Ngood, Nbad, Nmos, Ncal, Nrel, Nsys;
+  int i, j, k, Ngood, Nbad, Nmos, Ncal, Nrel, Nsys, Ngrp;
   double **A, **B, *Mjx, *Wjx;
-  float Msys, Mcal, Mmos, Merr, Wsys;
+  float Msys, Mcal, Mmos, Mgrp, Merr, Wsys;
   double Mj, Wj;
   
@@ -305,5 +305,5 @@
   }
 
-  Ngood = Nbad = Ncal = Nmos = Nrel = Nsys = 0;
+  Ngood = Nbad = Ncal = Nmos = Nrel = Nsys = Ngrp = 0;
 
   ALLOCATE (gotstar, int *, Ncatalog);
@@ -411,4 +411,11 @@
 	if (isnan(Mmos)) {
 	  Nmos ++;
+	  continue;
+	}
+
+	// skip mosaics marked as BAD
+	Mgrp = getMgrp  (m, c, catalog[c].measureT[m].airmass);
+	if (isnan(Mgrp)) {
+	  Ngrp ++;
 	  continue;
 	}
@@ -526,7 +533,7 @@
 void setMgrid (Catalog *catalog, FlatCorrectionTable *flatcorr) {
 
-  int i, j, m, c, n, N, Nmax, Nbad, Nmos, Ncal, Nrel, Nsys, Nfit;
+  int i, j, m, c, n, N, Nmax, Nbad, Nmos, Ngrp, Ncal, Nrel, Nsys, Nfit;
   double *list, *dlist;
-  float Msys, Mrel, Mcal, Mmos;
+  float Msys, Mrel, Mcal, Mmos, Mgrp;
 
   StatType stats;
@@ -544,5 +551,5 @@
   ALLOCATE (dlist, double, Nmax);
 
-  Nbad = Ncal = Nmos = Nrel = Nsys = Nfit = 0;
+  Nbad = Ncal = Nmos = Ngrp = Nrel = Nsys = Nfit = 0;
 
   for (i = 0; i < Ngrid; i++) {
@@ -568,4 +575,9 @@
 	continue;
       }
+      Mgrp = getMgrp  (m, c, catalog[c].measureT[m].airmass);
+      if (isnan(Mgrp)) {
+	Ngrp ++;
+	continue;
+      }
       Mrel  = getMrel  (catalog, m, c, MAG_CLASS_PSF, MAG_SRC_CHP);
       if (isnan(Mrel)) {
@@ -580,5 +592,5 @@
 	continue;
       }
-      list[N] = Msys - Mrel - Mcal - Mmos;
+      list[N] = Msys - Mrel - Mcal - Mmos - Mgrp;
       dlist[N] = MAX (catalog[c].measureT[m].dM, MIN_ERROR);
       N++;
@@ -616,5 +628,5 @@
 
   int i, j, m, c, n, N, Narea;
-  float Msys, Mrel, Mcal, Mmos;
+  float Msys, Mrel, Mcal, Mmos, Mgrp;
   double *xlist, *Mlist, *dlist, *ylist;
   Graphdata graphdata;
@@ -649,4 +661,6 @@
       Mmos  = getMmos  (m, c);
       if (isnan(Mmos)) continue;
+      Mgrp  = getMgrp  (m, c, catalog[c].measureT[m].airmass);
+      if (isnan(Mgrp)) continue;
       Mrel  = getMrel  (catalog, m, c, MAG_CLASS_PSF, MAG_SRC_CHP);
       if (isnan(Mrel)) continue;
@@ -657,6 +671,6 @@
       xlist[N] = Xmeas[c][m];
       ylist[N] = Ymeas[c][m];
-      Mlist[N] = Msys - Mrel - Mcal - Mmos;
-      dlist[N] = Msys - Mrel - Mcal - Mmos - gridM[i];
+      Mlist[N] = Msys - Mrel - Mcal - Mmos - Mgrp;
+      dlist[N] = Msys - Mrel - Mcal - Mmos - Mgrp - gridM[i];
       N++;
     }
