Index: /branches/czw_branch/20160809/psModules/src/astrom/pmAstrometryObjects.c
===================================================================
--- /branches/czw_branch/20160809/psModules/src/astrom/pmAstrometryObjects.c	(revision 39652)
+++ /branches/czw_branch/20160809/psModules/src/astrom/pmAstrometryObjects.c	(revision 39653)
@@ -252,5 +252,5 @@
         y->data.F32[i] = refStar->FP->y;
 
-        wt->data.F32[i] = 1.0;
+        wt->data.F32[i] = 1.01 - exp(-10.0*PS_SQR(refStar->magCal - rawStar->magCal)); // sigma = 0.22 mag
     }
 
@@ -657,4 +657,5 @@
     obj->Color= 0;
     obj->dMag = 0;
+    obj->magCal = 0;
 
     return (obj);
@@ -685,4 +686,5 @@
     obj->Color =  old->Color;
     obj->dMag  =  old->dMag;
+    obj->magCal =  old->magCal;
 
     return(obj);
@@ -816,9 +818,11 @@
             }
 
+	    int Npts = 10 * exp(-10.0*PS_SQR(ob1->magCal - ob2->magCal));  // sigma = 0.22 mag
+
             // accumulate bin stats
-            NP[iY][iX] ++;
-            DX[iY][iX] += dX;
-            DY[iY][iX] += dY;
-            D2[iY][iX] += PS_SQR(dX) + PS_SQR(dY);
+            NP[iY][iX] += Npts;
+            DX[iY][iX] += dX*Npts;
+            DY[iY][iX] += dY*Npts;
+            D2[iY][iX] += PS_SQR(dX*Npts) + PS_SQR(dY*Npts);
         }
     }
@@ -1079,6 +1083,8 @@
                 continue;
 
-            xHist->data.F32[xBin] += 1.0;
-            yHist->data.F32[yBin] += 1.0;
+	    int Npts = 10 * exp(-10.0*PS_SQR(ob1->magCal - ob2->magCal));  // sigma = 0.22 mag
+
+            xHist->data.F32[xBin] += Npts;
+            yHist->data.F32[yBin] += Npts;
         }
     }
Index: /branches/czw_branch/20160809/psModules/src/astrom/pmAstrometryObjects.h
===================================================================
--- /branches/czw_branch/20160809/psModules/src/astrom/pmAstrometryObjects.h	(revision 39652)
+++ /branches/czw_branch/20160809/psModules/src/astrom/pmAstrometryObjects.h	(revision 39653)
@@ -43,4 +43,5 @@
     float dMag;				///< error on object magnitude
     float SBinst;			///< surface brightness, used for Koppenhoefer correction
+    float magCal;		        ///< object calibrated magnitude in extracted filter
 }
 pmAstromObj;
Index: /branches/czw_branch/20160809/psastro/src/psastro.h
===================================================================
--- /branches/czw_branch/20160809/psastro/src/psastro.h	(revision 39652)
+++ /branches/czw_branch/20160809/psastro/src/psastro.h	(revision 39653)
@@ -70,5 +70,5 @@
 bool              psastroCorrectKH (pmConfig *config, pmFPAview *view, pmReadout *readout, psMetadata *recipe, psArray *inStars);
 
-psArray          *pmSourceToAstromObj (psArray *sources);
+psArray          *pmSourceToAstromObj (psArray *sources, float MagOffset);
 bool              psastroAstromGuess (int *nStars, pmConfig *config);
 bool              psastroAstromGuessCheck (pmConfig *config);
Index: /branches/czw_branch/20160809/psastro/src/psastroChipAstrom.c
===================================================================
--- /branches/czw_branch/20160809/psastro/src/psastroChipAstrom.c	(revision 39652)
+++ /branches/czw_branch/20160809/psastro/src/psastroChipAstrom.c	(revision 39653)
@@ -85,9 +85,9 @@
 		  for (int nn = 0; nn < refstars->n; nn++) {
 		    pmAstromObj *ref = refstars->data[nn];
-		    fprintf (outfile, "%lf %lf  %lf %lf  %lf %lf  %lf %lf\n", 
+		    fprintf (outfile, "%lf %lf  %lf %lf  %lf %lf  %lf %lf : %f %f\n", 
 			     ref->sky->r*PS_DEG_RAD, ref->sky->d*PS_DEG_RAD,
 			     ref->TP->x, ref->TP->y, 
 			     ref->FP->x, ref->FP->y, 
-			     ref->chip->x, ref->chip->y);
+			     ref->chip->x, ref->chip->y, ref->Mag, ref->magCal);
 		  }
 		  fclose (outfile);
@@ -101,9 +101,9 @@
 		  for (int nn = 0; nn < gridrawstars->n; nn++) {
 		    pmAstromObj *ref = gridrawstars->data[nn];
-		    fprintf (outfile, "%lf %lf  %lf %lf  %lf %lf  %lf %lf\n", 
+		    fprintf (outfile, "%lf %lf  %lf %lf  %lf %lf  %lf %lf : %f %f\n", 
 			     ref->sky->r*PS_DEG_RAD, ref->sky->d*PS_DEG_RAD,
 			     ref->TP->x, ref->TP->y, 
 			     ref->FP->x, ref->FP->y, 
-			     ref->chip->x, ref->chip->y);
+			     ref->chip->x, ref->chip->y, ref->Mag, ref->magCal);
 		  }
 		  fclose (outfile);
Index: /branches/czw_branch/20160809/psastro/src/psastroConvert.c
===================================================================
--- /branches/czw_branch/20160809/psastro/src/psastroConvert.c	(revision 39652)
+++ /branches/czw_branch/20160809/psastro/src/psastroConvert.c	(revision 39653)
@@ -51,4 +51,29 @@
     bool status;
 
+    // XXX I want to make this optional
+    float MagOffset = 0.0;
+    if (1) {
+      // select the input data sources
+      pmFPAfile *input = psMetadataLookupPtr (NULL, config->files, "PSASTRO.INPUT");
+      if (!input) {
+	psError(PSASTRO_ERR_CONFIG, true, "failed to find PSASTRO.INPUT\n");
+	return false;
+      }
+      pmFPA *fpa = input->fpa;
+
+      float zeropt, exptime;
+
+      // really error-out here?  or just skip?
+      if (!psastroZeroPointFromRecipe (&zeropt, &exptime, NULL, fpa, recipe)) {
+        psLogMsg ("psastro", PS_LOG_INFO, "failed to load zeropt data from recipe");
+	zeropt = 0.0;
+	exptime = 1.0;
+      }
+
+      // recipe values are given in instrumental magnitudes
+      // use the zero point and exposure time to convert to apparent mags: M_ap = M_inst + C_0 + 2.5*log(exptime)
+      MagOffset = zeropt + 2.5*log10(exptime);
+    }
+
     // PSPHOT.SOURCES carries the pmSource objects (from psphot analysis or loaded externally)
     pmDetections *detections = psMetadataLookupPtr (&status, readout->analysis, "PSPHOT.DETECTIONS");
@@ -59,5 +84,5 @@
 
     // convert the pmSource objects into pmAstromObj objects (drop !STAR and SATSTAR?)
-    psArray *inStars = pmSourceToAstromObj (sources);
+    psArray *inStars = pmSourceToAstromObj (sources, MagOffset);
 
     // apply Koppenhoefer correction if needed
@@ -175,5 +200,5 @@
 
 // select a magnitude range?
-psArray *pmSourceToAstromObj (psArray *sources) {
+psArray *pmSourceToAstromObj (psArray *sources, float MagOffset) {
 
     psArray *objects = psArrayAllocEmpty (sources->n);
@@ -211,4 +236,5 @@
         obj->dMag = source->psfMagErr;
         obj->SBinst = source->psfMag + 5.0*log10(axes.major);
+        obj->magCal = obj->Mag + MagOffset;
 
         // XXX do we have the information giving the readout and cell offset?
Index: /branches/czw_branch/20160809/psastro/src/psastroLoadRefstars.c
===================================================================
--- /branches/czw_branch/20160809/psastro/src/psastroLoadRefstars.c	(revision 39652)
+++ /branches/czw_branch/20160809/psastro/src/psastroLoadRefstars.c	(revision 39653)
@@ -265,4 +265,5 @@
             ref->Color    = 0.0;
         }
+	ref->magCal   = ref->Mag;
 
         // XXX VERY temporary hack to avoid M31 bulge
@@ -306,4 +307,5 @@
             ref->Color = 0.0;
         }
+	ref->magCal   = ref->Mag;
 
         // XXX VERY temporary hack to avoid M31 bulge
