Index: /branches/eam_branches/ohana.20170822/src/addstar/src/FilterStars.c
===================================================================
--- /branches/eam_branches/ohana.20170822/src/addstar/src/FilterStars.c	(revision 40243)
+++ /branches/eam_branches/ohana.20170822/src/addstar/src/FilterStars.c	(revision 40244)
@@ -73,5 +73,6 @@
     outcat->measure[N].airmass = airmass (image[0].secz, outcat->average[N].R, outcat->average[N].D, image[0].sidtime, image[0].latitude);
     outcat->measure[N].az      = azimuth (15.0*image[0].sidtime - outcat->average[N].R, outcat->average[N].D, image[0].latitude);
-    outcat->measure[N].Mcal    = image[0].McalPSF;
+    outcat->measure[N].McalPSF = image[0].McalPSF;
+    outcat->measure[N].McalAPER= image[0].McalAPER;
     outcat->measure[N].t       = image[0].tzero + 1e-4*outcat->measure[N].Yccd*image[0].trate;  /* trate is in 0.1 msec / row */
     outcat->measure[N].dt      = MTIME;
Index: /branches/eam_branches/ohana.20170822/src/addstar/src/ReadStarsUKIRT.c
===================================================================
--- /branches/eam_branches/ohana.20170822/src/addstar/src/ReadStarsUKIRT.c	(revision 40243)
+++ /branches/eam_branches/ohana.20170822/src/addstar/src/ReadStarsUKIRT.c	(revision 40244)
@@ -196,5 +196,6 @@
     catalog->measure[i].FWy       = ToShortPixels(seeing);
 
-    catalog->measure[i].Mcal      = Mcal;
+    catalog->measure[i].McalPSF   = Mcal;
+    catalog->measure[i].McalAPER  = Mcal;
 
     catalog->measure[i].detID     = i;
Index: /branches/eam_branches/ohana.20170822/src/addstar/src/SEDfit.c
===================================================================
--- /branches/eam_branches/ohana.20170822/src/addstar/src/SEDfit.c	(revision 40243)
+++ /branches/eam_branches/ohana.20170822/src/addstar/src/SEDfit.c	(revision 40244)
@@ -172,5 +172,6 @@
       outcat[0].measure[Nmeas].M         = table[0].row[minFit.row][0].mags[n] + minFit.Md;
       outcat[0].measure[Nmeas].dM        = 0.0;
-      outcat[0].measure[Nmeas].Mcal      = 0;
+      outcat[0].measure[Nmeas].McalPSF   = 0;
+      outcat[0].measure[Nmeas].McalAPER  = 0;
       outcat[0].measure[Nmeas].t         = TIMEREF;
       outcat[0].measure[Nmeas].averef    = Nave;
Index: /branches/eam_branches/ohana.20170822/src/addstar/src/find_proper.c
===================================================================
--- /branches/eam_branches/ohana.20170822/src/addstar/src/find_proper.c	(revision 40243)
+++ /branches/eam_branches/ohana.20170822/src/addstar/src/find_proper.c	(revision 40244)
@@ -104,19 +104,21 @@
 	
 	/** add measurements for this star **/
-	catalog[0].measure[Nmeas].dR  = 360000.0*(catalog[0].average[n].R - usno[N].R);
-	catalog[0].measure[Nmeas].dD  = 360000.0*(catalog[0].average[n].D - usno[N].D);
-	catalog[0].measure[Nmeas].M   = 1000.0*fabs(usno[N].r);
-	catalog[0].measure[Nmeas].Mcal= 0;    /* above measurement is exact */
-	catalog[0].measure[Nmeas].dM  = 100;  /* error in input files stored in thousandths of mag */
-	catalog[0].measure[Nmeas].t   = 0;    /* a flag: if 0, image is not in database */
-	catalog[0].measure[Nmeas].averef  = n;
-	catalog[0].measure[Nmeas].photcode = USNO_RED; 
-	catalog[0].measure[Nmeas+1].dR  = catalog[0].measure[Nmeas].dR;
-	catalog[0].measure[Nmeas+1].dD  = catalog[0].measure[Nmeas].dD;
-	catalog[0].measure[Nmeas+1].M   = 1000.0*fabs(usno[N].b);
-	catalog[0].measure[Nmeas+1].Mcal= 0;    /* above measurement is exact */
-	catalog[0].measure[Nmeas+1].dM  = 100;  /* error in input files stored in thousandths of mag */
-	catalog[0].measure[Nmeas+1].t   = 0;    /* a flag: if 0, image is not in database */
-	catalog[0].measure[Nmeas+1].averef  = n;
+	catalog[0].measure[Nmeas].dR  	     = 360000.0*(catalog[0].average[n].R - usno[N].R);
+	catalog[0].measure[Nmeas].dD  	     = 360000.0*(catalog[0].average[n].D - usno[N].D);
+	catalog[0].measure[Nmeas].M   	     = 1000.0*fabs(usno[N].r);
+	catalog[0].measure[Nmeas].McalPSF    = 0;    /* above measurement is exact */
+	catalog[0].measure[Nmeas].McalAPER   = 0;    /* above measurement is exact */
+	catalog[0].measure[Nmeas].dM         = 100;  /* error in input files stored in thousandths of mag */
+	catalog[0].measure[Nmeas].t          = 0;    /* a flag: if 0, image is not in database */
+	catalog[0].measure[Nmeas].averef     = n;
+	catalog[0].measure[Nmeas].photcode   = USNO_RED; 
+	catalog[0].measure[Nmeas+1].dR       = catalog[0].measure[Nmeas].dR;
+	catalog[0].measure[Nmeas+1].dD       = catalog[0].measure[Nmeas].dD;
+	catalog[0].measure[Nmeas+1].M        = 1000.0*fabs(usno[N].b);
+	catalog[0].measure[Nmeas+1].McalPSF  = 0;    /* above measurement is exact */
+	catalog[0].measure[Nmeas+1].McalAPER = 0;    /* above measurement is exact */
+	catalog[0].measure[Nmeas+1].dM       = 100;  /* error in input files stored in thousandths of mag */
+	catalog[0].measure[Nmeas+1].t        = 0;    /* a flag: if 0, image is not in database */
+	catalog[0].measure[Nmeas+1].averef   = n;
 	catalog[0].measure[Nmeas+1].photcode = USNO_BLUE; 
 	/* add flag in average to mark as matched with the USNO catalog */
Index: /branches/eam_branches/ohana.20170822/src/addstar/src/loadsupercos_rawdata.c
===================================================================
--- /branches/eam_branches/ohana.20170822/src/addstar/src/loadsupercos_rawdata.c	(revision 40243)
+++ /branches/eam_branches/ohana.20170822/src/addstar/src/loadsupercos_rawdata.c	(revision 40244)
@@ -86,5 +86,6 @@
 
 	// XXX fix these
-	newcat->measure[i].Mcal = 0.0;
+	newcat->measure[i].McalPSF  = 0.0;
+	newcat->measure[i].McalAPER = 0.0;
 	newcat->measure[i].dt = image[Ni].exptime;
 
Index: /branches/eam_branches/ohana.20170822/src/checkastro/src/BrightCatalog.c
===================================================================
--- /branches/eam_branches/ohana.20170822/src/checkastro/src/BrightCatalog.c	(revision 40243)
+++ /branches/eam_branches/ohana.20170822/src/checkastro/src/BrightCatalog.c	(revision 40244)
@@ -71,5 +71,6 @@
     GET_COLUMN(dD,        "DEC_OFF",  	float);
     GET_COLUMN(M,         "MAG_SYS",  	float);
-    GET_COLUMN(Mcal,      "MAG_CAL",  	float);
+    GET_COLUMN(McalPSF,   "MCAL_PSF",  	float);
+    GET_COLUMN(McalAPER,  "MCAL_APER", 	float);
     GET_COLUMN(dM,        "MAG_ERR",  	float);
     GET_COLUMN(airmass,   "AIRMASS",  	float);
@@ -95,5 +96,6 @@
       measure[i].dD        = dD[i];
       measure[i].M         = M[i];
-      measure[i].Mcal      = Mcal[i];
+      measure[i].McalPSF   = McalPSF[i];
+      measure[i].McalAPER  = McalAPER[i];
       measure[i].dM        = dM[i];
       measure[i].airmass   = airmass[i];
@@ -116,5 +118,6 @@
     free (dD      );
     free (M       );
-    free (Mcal    );
+    free (McalPSF );
+    free (McalAPER);
     free (dM      );
     free (airmass );
@@ -366,5 +369,6 @@
     float *dD        ; ALLOCATE (dD       ,  float, catalog->Nmeasure);
     float *M         ; ALLOCATE (M        ,  float, catalog->Nmeasure);
-    float *Mcal      ; ALLOCATE (Mcal     ,  float, catalog->Nmeasure);
+    float *McalPSF   ; ALLOCATE (McalPSF  ,  float, catalog->Nmeasure);
+    float *McalAPER  ; ALLOCATE (McalAPER ,  float, catalog->Nmeasure);
     float *dM        ; ALLOCATE (dM       ,  float, catalog->Nmeasure);
     float *airmass   ; ALLOCATE (airmass  ,  float, catalog->Nmeasure);
@@ -388,5 +392,6 @@
       dD[i]       = measure[i].dD       ;
       M[i]  	  = measure[i].M        ;
-      Mcal[i]     = measure[i].Mcal     ;
+      McalPSF[i]  = measure[i].McalPSF  ;
+      McalAPER[i] = measure[i].McalAPER ;
       dM[i]       = measure[i].dM       ;
       airmass[i]  = measure[i].airmass  ;
@@ -409,5 +414,6 @@
     gfits_set_bintable_column (&theader, &ftable, "DEC_OFF",  	dD,        catalog->Nmeasure);
     gfits_set_bintable_column (&theader, &ftable, "MAG_SYS",  	M,         catalog->Nmeasure);
-    gfits_set_bintable_column (&theader, &ftable, "MAG_CAL",  	Mcal,      catalog->Nmeasure);
+    gfits_set_bintable_column (&theader, &ftable, "MCAL_PSF",  	McalPSF,   catalog->Nmeasure);
+    gfits_set_bintable_column (&theader, &ftable, "MCAL_APER", 	McalAPER,  catalog->Nmeasure);
     gfits_set_bintable_column (&theader, &ftable, "MAG_ERR",  	dM,        catalog->Nmeasure);
     gfits_set_bintable_column (&theader, &ftable, "AIRMASS",  	airmass,   catalog->Nmeasure);
@@ -428,5 +434,6 @@
     free (dD      );
     free (M       );
-    free (Mcal    );
+    free (McalPSF );
+    free (McalAPER);
     free (dM      );
     free (airmass );
Index: /branches/eam_branches/ohana.20170822/src/dvolens/src/update_objects_catalog.c
===================================================================
--- /branches/eam_branches/ohana.20170822/src/dvolens/src/update_objects_catalog.c	(revision 40243)
+++ /branches/eam_branches/ohana.20170822/src/dvolens/src/update_objects_catalog.c	(revision 40244)
@@ -219,5 +219,6 @@
 
       // relphot sets measure->Mcal (setMcalOutput.c, called by setMrelFinal.c)
-      float Mcal = code[0].K*(measure[0].airmass - 1.000) + SCALE*code[0].C - measure->Mcal;
+      // XXX : I'm using McalAPER since these lens measurements are aperture-like, right?
+      float Mcal = code[0].K*(measure[0].airmass - 1.000) + SCALE*code[0].C - measure->McalAPER;
       float Fcal = 3630.8 * MagToFlux(Mcal);
 
Index: /branches/eam_branches/ohana.20170822/src/dvopsps/include/dvopsps.h
===================================================================
--- /branches/eam_branches/ohana.20170822/src/dvopsps/include/dvopsps.h	(revision 40243)
+++ /branches/eam_branches/ohana.20170822/src/dvopsps/include/dvopsps.h	(revision 40244)
@@ -19,6 +19,8 @@
   float raErr;
   float decErr;
-  float zp;
-  float zpFactor;
+  float zpPSF;
+  float zpFactorPSF;
+  float zpAPER;
+  float zpFactorAPER;
   float telluricExt;
   float airmass;
Index: /branches/eam_branches/ohana.20170822/src/dvopsps/src/DetectionOps.c
===================================================================
--- /branches/eam_branches/ohana.20170822/src/dvopsps/src/DetectionOps.c	(revision 40243)
+++ /branches/eam_branches/ohana.20170822/src/dvopsps/src/DetectionOps.c	(revision 40244)
@@ -56,6 +56,8 @@
   GET_COLUMN(raErr       , "raErr",       float);
   GET_COLUMN(decErr      , "decErr",      float);
-  GET_COLUMN(zp          , "zp",          float);
-  GET_COLUMN(zpFactor    , "zpFactor",    float);
+  GET_COLUMN(zpPSF       , "zpPSF",       float);
+  GET_COLUMN(zpFactorPSF , "zpFactorPSF", float);
+  GET_COLUMN(zpAPER      , "zpAPER",      float);
+  GET_COLUMN(zpFactorAPER, "zpFactorAPER",float);
   GET_COLUMN(telluricExt , "telluricExt", float);
   GET_COLUMN(airmass     , "airmass",     float);
@@ -84,6 +86,8 @@
     detections[i].raErr        = raErr[i];      
     detections[i].decErr       = decErr[i];     
-    detections[i].zp           = zp[i];         
-    detections[i].zpFactor     = zpFactor[i];         
+    detections[i].zpPSF        = zpPSF[i];         
+    detections[i].zpFactorPSF  = zpFactorPSF[i];         
+    detections[i].zpAPER       = zpAPER[i];         
+    detections[i].zpFactorAPER = zpFactorAPER[i];         
     detections[i].telluricExt  = telluricExt[i];      
     detections[i].airmass      = airmass[i];    
@@ -110,6 +114,8 @@
   free (raErr      );
   free (decErr     );
-  free (zp         );
-  free (zpFactor   );
+  free (zpPSF      );
+  free (zpFactorPSF);
+  free (zpAPER      );
+  free (zpFactorAPER);
   free (telluricExt);
   free (airmass    );
@@ -180,6 +186,8 @@
   gfits_define_bintable_column (&theader, "E", "raErr",       NULL, NULL, 1.0, 0.0);
   gfits_define_bintable_column (&theader, "E", "decErr",      NULL, NULL, 1.0, 0.0);
-  gfits_define_bintable_column (&theader, "E", "zp",          NULL, NULL, 1.0, 0.0);
-  gfits_define_bintable_column (&theader, "E", "zpFactor",    NULL, NULL, 1.0, 0.0);
+  gfits_define_bintable_column (&theader, "E", "zpPSF",          NULL, NULL, 1.0, 0.0);
+  gfits_define_bintable_column (&theader, "E", "zpFactorPSF",    NULL, NULL, 1.0, 0.0);
+  gfits_define_bintable_column (&theader, "E", "zpAPER",         NULL, NULL, 1.0, 0.0);
+  gfits_define_bintable_column (&theader, "E", "zpFactorAPER",   NULL, NULL, 1.0, 0.0);
   gfits_define_bintable_column (&theader, "E", "telluricExt", NULL, NULL, 1.0, 0.0);
   gfits_define_bintable_column (&theader, "E", "airmass",     NULL, NULL, 1.0, 0.0);
@@ -208,6 +216,8 @@
   float      *raErr       ; ALLOCATE (raErr       ,  float,    Ndetections);
   float      *decErr      ; ALLOCATE (decErr      ,  float,    Ndetections);
-  float      *zp          ; ALLOCATE (zp          ,  float,    Ndetections);
-  float      *zpFactor    ; ALLOCATE (zpFactor    ,  float,    Ndetections);
+  float      *zpPSF       ; ALLOCATE (zpPSF       ,  float,    Ndetections);
+  float      *zpFactorPSF ; ALLOCATE (zpFactorPSF ,  float,    Ndetections);
+  float      *zpAPER      ; ALLOCATE (zpAPER      ,  float,    Ndetections);
+  float      *zpFactorAPER; ALLOCATE (zpFactorAPER,  float,    Ndetections);
   float      *telluricExt ; ALLOCATE (telluricExt ,  float,    Ndetections);
   float      *airmass     ; ALLOCATE (airmass     ,  float,    Ndetections);
@@ -234,6 +244,8 @@
     raErr[i]       = detections[i].raErr       ;
     decErr[i]      = detections[i].decErr      ;
-    zp[i]          = detections[i].zp          ;
-    zpFactor[i]    = detections[i].zpFactor    ;
+    zpPSF[i]       = detections[i].zpPSF       ;
+    zpFactorPSF[i] = detections[i].zpFactorPSF ;
+    zpAPER[i]      = detections[i].zpAPER      ;
+    zpFactorAPER[i]= detections[i].zpFactorAPER;
     telluricExt[i] = detections[i].telluricExt ;
     airmass[i]     = detections[i].airmass     ;
@@ -260,6 +272,8 @@
   gfits_set_bintable_column (&theader, &ftable, "raErr",       raErr       , Ndetections);
   gfits_set_bintable_column (&theader, &ftable, "decErr",      decErr      , Ndetections);
-  gfits_set_bintable_column (&theader, &ftable, "zp",          zp          , Ndetections);
-  gfits_set_bintable_column (&theader, &ftable, "zpFactor",    zpFactor    , Ndetections);
+  gfits_set_bintable_column (&theader, &ftable, "zpPSF",       zpPSF       , Ndetections);
+  gfits_set_bintable_column (&theader, &ftable, "zpFactorPSF", zpFactorPSF , Ndetections);
+  gfits_set_bintable_column (&theader, &ftable, "zpAPER",      zpAPER      , Ndetections);
+  gfits_set_bintable_column (&theader, &ftable, "zpFactorAPER",zpFactorAPER, Ndetections);
   gfits_set_bintable_column (&theader, &ftable, "telluricExt", telluricExt , Ndetections);
   gfits_set_bintable_column (&theader, &ftable, "airmass",     airmass     , Ndetections);
@@ -284,6 +298,8 @@
   free (raErr       );
   free (decErr      );
-  free (zp          );
-  free (zpFactor    );
+  free (zpPSF       );
+  free (zpFactorPSF );
+  free (zpAPER      );
+  free (zpFactorAPER);
   free (telluricExt );
   free (airmass     );
Index: /branches/eam_branches/ohana.20170822/src/dvopsps/src/insert_detections_dvopsps_catalog.c
===================================================================
--- /branches/eam_branches/ohana.20170822/src/dvopsps/src/insert_detections_dvopsps_catalog.c	(revision 40243)
+++ /branches/eam_branches/ohana.20170822/src/dvopsps/src/insert_detections_dvopsps_catalog.c	(revision 40244)
@@ -183,5 +183,5 @@
 
   PrintIOBuffer (buffer, "INSERT INTO dvoDetectionFull (objID, detectID, ippObjID, ippDetectID, imageID, catID, ");
-  PrintIOBuffer (buffer, "ra, dec_, raErr, decErr, zp, zpFactor, telluricExt, airmass, expTime, ");
+  PrintIOBuffer (buffer, "ra, dec_, raErr, decErr, zpPSF, zpFactorPSF, zpAPER, zpFactorAPER, telluricExt, airmass, expTime, ");
   PrintIOBuffer (buffer, "Mpsf, dMpsf, Mkron, dMkron, Map, dMap, flags, objflags) VALUES \n");
 
@@ -254,6 +254,8 @@
   PRINT_FLOAT(buffer, detection->raErr,       "%.6f, ");
   PRINT_FLOAT(buffer, detection->decErr,      "%.6f, ");
-  PRINT_FLOAT(buffer, detection->zp,          "%.6f, ");
-  PRINT_FLOAT(buffer, detection->zpFactor,    "%.6e, ");
+  PRINT_FLOAT(buffer, detection->zpPSF,       "%.6f, ");
+  PRINT_FLOAT(buffer, detection->zpFactorPSF, "%.6e, ");
+  PRINT_FLOAT(buffer, detection->zpAPER,      "%.6f, ");
+  PRINT_FLOAT(buffer, detection->zpFactorAPER,"%.6e, ");
   PRINT_FLOAT(buffer, detection->telluricExt, "%.6f, ");
   PRINT_FLOAT(buffer, detection->airmass,     "%.6f, ");
@@ -305,4 +307,6 @@
 int assign_detection_values (Detections *detection, Measure *measure, Average *average) {
 
+  // myAbort ("check on measure->McalPSF vs McalAPER");
+
   PhotCode *code = GetPhotcodebyCode(measure->photcode);
 
@@ -311,7 +315,9 @@
   float Mflat       = isfinite(measure->Mflat) ? measure->Mflat : 0.0;
   float nominalZP   = code->C * 0.001 + code->K * (measure->airmass - 1);
-  float zp          = nominalZP - measure->Mcal - Mflat;
-  float zpFactor    = pow(10.0, -0.4*zp + 3.56);
-  float telluricExt = - measure->Mcal;
+  float zpPSF       = nominalZP - measure->McalPSF - Mflat;
+  float zpFactorPSF = pow(10.0, -0.4*zpPSF + 3.56);
+  float zpAPER      = nominalZP - measure->McalAPER - Mflat;
+  float zpFactorAPER= pow(10.0, -0.4*zpAPER + 3.56);
+  float telluricExt = - measure->McalPSF;
   float expTime     = pow(10.0, 0.4 * measure->dt);
   float airmass     = measure->airmass;
@@ -329,6 +335,8 @@
   detection->decErr	  = measure->dYccd * 0.01 * fabs(measure->pltscale); // estimate of decErr
 
-  detection->zp 	  = zp;
-  detection->zpFactor 	  = zpFactor;
+  detection->zpPSF 	  = zpPSF;
+  detection->zpFactorPSF  = zpFactorPSF;
+  detection->zpAPER 	  = zpAPER;
+  detection->zpFactorAPER = zpFactorAPER;
   detection->telluricExt  = telluricExt;
   detection->airmass      = airmass;
@@ -337,7 +345,7 @@
   // XXX clean this up with dvo_photcode_ops calls:
   // if (isfinite(measure->FluxPSF) && (measure->FluxPSF < 0.0)) 
-  detection->Mpsf  = getMagFromValueOrFlux (measure->FluxPSF,  measure->M,     zp);
-  detection->Mkron = getMagFromValueOrFlux (measure->FluxKron, measure->Mkron, zp);
-  detection->Map   = getMagFromValueOrFlux (measure->FluxAp,   measure->Map,   zp);
+  detection->Mpsf  = getMagFromValueOrFlux (measure->FluxPSF,  measure->M,     zpPSF);
+  detection->Mkron = getMagFromValueOrFlux (measure->FluxKron, measure->Mkron, zpAPER);
+  detection->Map   = getMagFromValueOrFlux (measure->FluxAp,   measure->Map,   zpAPER);
 
   detection->dMpsf  = getdMagFromValueOrFlux (measure->FluxPSF,  measure->dFluxPSF,  measure->dM);
Index: /branches/eam_branches/ohana.20170822/src/fakeastro/src/make_2mass_measures.c
===================================================================
--- /branches/eam_branches/ohana.20170822/src/fakeastro/src/make_2mass_measures.c	(revision 40243)
+++ /branches/eam_branches/ohana.20170822/src/fakeastro/src/make_2mass_measures.c	(revision 40244)
@@ -103,5 +103,6 @@
     measure[Nmeasure].airmass = 1.0;
     measure[Nmeasure].az      = 0.0; // irrelevant
-    measure[Nmeasure].Mcal    = 0.0;
+    measure[Nmeasure].McalPSF = 0.0;
+    measure[Nmeasure].McalAPER= 0.0;
     measure[Nmeasure].t       = tzero_2mass;
     measure[Nmeasure].dt      = 0.0;
Index: /branches/eam_branches/ohana.20170822/src/fakeastro/src/make_fake_stars_catalog.c
===================================================================
--- /branches/eam_branches/ohana.20170822/src/fakeastro/src/make_fake_stars_catalog.c	(revision 40243)
+++ /branches/eam_branches/ohana.20170822/src/fakeastro/src/make_fake_stars_catalog.c	(revision 40244)
@@ -175,5 +175,6 @@
 
     stars[Nstars].measure.az      = azimuth (15.0*image->sidtime - stars[Nstars].average.R, stars[Nstars].average.D, image->latitude);
-    stars[Nstars].measure.Mcal    = image->McalPSF;
+    stars[Nstars].measure.McalPSF = image->McalPSF;
+    stars[Nstars].measure.McalAPER= image->McalAPER;
     stars[Nstars].measure.t       = image->tzero + 1e-4*stars[Nstars].measure.Yccd*image->trate;  // trate is in 0.1 msec / row 
     stars[Nstars].measure.dt      = Mtime;
Index: /branches/eam_branches/ohana.20170822/src/fakeastro/src/make_gaia_measures.c
===================================================================
--- /branches/eam_branches/ohana.20170822/src/fakeastro/src/make_gaia_measures.c	(revision 40243)
+++ /branches/eam_branches/ohana.20170822/src/fakeastro/src/make_gaia_measures.c	(revision 40244)
@@ -104,5 +104,6 @@
     measure[Nmeasure].airmass = 1.0;
     measure[Nmeasure].az      = 0.0; // irrelevant
-    measure[Nmeasure].Mcal    = 0.0;
+    measure[Nmeasure].McalPSF = 0.0;
+    measure[Nmeasure].McalAPER= 0.0;
     measure[Nmeasure].t       = tzero_gaia;
     measure[Nmeasure].dt      = 0.0;
Index: /branches/eam_branches/ohana.20170822/src/markrock/src/find_slow_rocks.c
===================================================================
--- /branches/eam_branches/ohana.20170822/src/markrock/src/find_slow_rocks.c	(revision 40243)
+++ /branches/eam_branches/ohana.20170822/src/markrock/src/find_slow_rocks.c	(revision 40244)
@@ -69,5 +69,5 @@
 	RD_to_XY (&X1[j], &Y1[j], R1[j], D1[j], &catstats[0].coords);
 	T1[j] = catalog[0].measure[m+j].t;
-	M1[j] = catalog[0].measure[m+j].M - catalog[0].measure[m+j].Mcal;
+	M1[j] = catalog[0].measure[m+j].M - catalog[0].measure[m+j].McalPSF;
       }
       dt = T1[1] - T1[0];
@@ -86,5 +86,5 @@
 	  RD_to_XY (&X, &Y, R, D, &catstats[0].coords);
 	  T = catalog[0].measure[m+j].t;
-	  M = catalog[0].measure[m+j].M - catalog[0].measure[m+j].Mcal;
+	  M = catalog[0].measure[m+j].M - catalog[0].measure[m+j].McalPSF;
 	  if (T1[0] == T) continue;
 	  if (T1[1] == T) continue;
Index: /branches/eam_branches/ohana.20170822/src/opihi/dvo/gstar.c
===================================================================
--- /branches/eam_branches/ohana.20170822/src/opihi/dvo/gstar.c	(revision 40243)
+++ /branches/eam_branches/ohana.20170822/src/opihi/dvo/gstar.c	(revision 40244)
@@ -760,5 +760,6 @@
 
 	    if (FULL_OUTPUT) {
-	      gprint (GP_LOG, "%6.3f ", catalog.measure[Nv].Mcal);
+	      gprint (GP_LOG, "%6.3f ", catalog.measure[Nv].McalPSF);
+	      gprint (GP_LOG, "%6.3f ", catalog.measure[Nv].McalAPER);
 	      gprint (GP_LOG, "%6.3f ", catalog.measure[Nv].Mflat);
 	      gprint (GP_LOG, "%6.3f ", catalog.measure[Nv].Map);
Index: /branches/eam_branches/ohana.20170822/src/opihi/dvo/imdata.c
===================================================================
--- /branches/eam_branches/ohana.20170822/src/opihi/dvo/imdata.c	(revision 40243)
+++ /branches/eam_branches/ohana.20170822/src/opihi/dvo/imdata.c	(revision 40244)
@@ -183,5 +183,5 @@
 	for (i = 0; i < catalog.Nmeasure; i++) {
 	  if ((catalog.measure[i].t < start) || (catalog.measure[i].t > stop)) continue;
-	  vec[0].elements.Flt[N] = catalog.measure[i].Mcal;
+	  vec[0].elements.Flt[N] = catalog.measure[i].McalPSF;
 	  N++;
 	  CHECK_REALLOCATE (vec[0].elements.Flt, opihi_flt, NPTS, N, 1000);
Index: /branches/eam_branches/ohana.20170822/src/relastro/src/BrightCatalog.c
===================================================================
--- /branches/eam_branches/ohana.20170822/src/relastro/src/BrightCatalog.c	(revision 40243)
+++ /branches/eam_branches/ohana.20170822/src/relastro/src/BrightCatalog.c	(revision 40244)
@@ -68,5 +68,6 @@
     GET_COLUMN(D,         "DEC",  	double);
     GET_COLUMN(M,         "MAG_SYS",  	float);
-    GET_COLUMN(Mcal,      "MAG_CAL",  	float);
+    GET_COLUMN(McalPSF,   "MCAL_PSF",  	float);
+    GET_COLUMN(McalAPER,  "MCAL_APER", 	float);
     GET_COLUMN(dM,        "MAG_ERR",  	float);
     GET_COLUMN(airmass,   "AIRMASS",  	float);
@@ -94,5 +95,6 @@
       measure[i].D         = D[i];
       measure[i].M         = M[i];
-      measure[i].Mcal      = Mcal[i];
+      measure[i].McalPSF   = McalPSF[i];
+      measure[i].McalAPER  = McalAPER[i];
       measure[i].dM        = dM[i];
       measure[i].airmass   = airmass[i];
@@ -120,5 +122,6 @@
     free (D       );
     free (M       );
-    free (Mcal    );
+    free (McalPSF );
+    free (McalAPER);
     free (dM      );
     free (airmass );
@@ -385,5 +388,6 @@
     double *D         ; ALLOCATE (D        ,  double, catalog->Nmeasure);
     float  *M         ; ALLOCATE (M        ,  float,  catalog->Nmeasure);
-    float  *Mcal      ; ALLOCATE (Mcal     ,  float,  catalog->Nmeasure);
+    float  *McalPSF   ; ALLOCATE (McalPSF  ,  float,  catalog->Nmeasure);
+    float  *McalAPER  ; ALLOCATE (McalAPER ,  float,  catalog->Nmeasure);
     float  *dM        ; ALLOCATE (dM       ,  float,  catalog->Nmeasure);
     float  *airmass   ; ALLOCATE (airmass  ,  float,  catalog->Nmeasure);
@@ -408,5 +412,6 @@
       D[i]        = measure[i].D        ;
       M[i]  	  = measure[i].M        ;
-      Mcal[i]     = measure[i].Mcal     ;
+      McalPSF[i]  = measure[i].McalPSF  ;
+      McalAPER[i] = measure[i].McalAPER ;
       dM[i]       = measure[i].dM       ;
       airmass[i]  = measure[i].airmass  ;
@@ -434,5 +439,6 @@
     gfits_set_bintable_column (&theader, &ftable, "DEC",  	D,         catalog->Nmeasure);
     gfits_set_bintable_column (&theader, &ftable, "MAG_SYS",  	M,         catalog->Nmeasure);
-    gfits_set_bintable_column (&theader, &ftable, "MAG_CAL",  	Mcal,      catalog->Nmeasure);
+    gfits_set_bintable_column (&theader, &ftable, "MCAL_PSF",  	McalPSF,   catalog->Nmeasure);
+    gfits_set_bintable_column (&theader, &ftable, "MCAL_APER", 	McalAPER,  catalog->Nmeasure);
     gfits_set_bintable_column (&theader, &ftable, "MAG_ERR",  	dM,        catalog->Nmeasure);
     gfits_set_bintable_column (&theader, &ftable, "AIRMASS",  	airmass,   catalog->Nmeasure);
@@ -454,5 +460,6 @@
     free (D       );
     free (M       );
-    free (Mcal    );
+    free (McalPSF );
+    free (McalAPER);
     free (dM      );
     free (airmass );
Index: /branches/eam_branches/ohana.20170822/src/relphot/src/BrightCatalog.c
===================================================================
--- /branches/eam_branches/ohana.20170822/src/relphot/src/BrightCatalog.c	(revision 40243)
+++ /branches/eam_branches/ohana.20170822/src/relphot/src/BrightCatalog.c	(revision 40244)
@@ -66,5 +66,6 @@
     GET_COLUMN(D,         "DEC",  	double);
     GET_COLUMN(M,         "MAG_SYS",  	float);
-    GET_COLUMN(Mcal,      "MAG_CAL",  	float);
+    GET_COLUMN(McalPSF,   "MCAL_PSF",  	float);
+    GET_COLUMN(McalAPER,  "MCAL_APER", 	float);
     GET_COLUMN(Mflat,     "MAG_FLAT",  	float);
     GET_COLUMN(dM,        "MAG_ERR",  	float);
@@ -89,5 +90,6 @@
       measure[i].D         = D[i];
       measure[i].M         = M[i];
-      measure[i].Mcal      = Mcal[i];
+      measure[i].McalPSF   = McalPSF[i];
+      measure[i].McalAPER  = McalAPER[i];
       measure[i].Mflat     = Mflat[i];
       measure[i].dM        = dM[i];
@@ -110,5 +112,6 @@
     free (D       );
     free (M       );
-    free (Mcal    );
+    free (McalPSF );
+    free (McalAPER);
     free (Mflat   );
     free (dM      );
@@ -293,5 +296,6 @@
     double *D         ; ALLOCATE (D        ,  double, catalog->Nmeasure);
     float  *M         ; ALLOCATE (M        ,  float,  catalog->Nmeasure);
-    float  *Mcal      ; ALLOCATE (Mcal     ,  float,  catalog->Nmeasure);
+    float  *McalPSF   ; ALLOCATE (McalPSF  ,  float,  catalog->Nmeasure);
+    float  *McalAPER  ; ALLOCATE (McalAPER ,  float,  catalog->Nmeasure);
     float  *Mflat     ; ALLOCATE (Mflat    ,  float,  catalog->Nmeasure);
     float  *dM        ; ALLOCATE (dM       ,  float,  catalog->Nmeasure);
@@ -311,8 +315,9 @@
     MeasureTiny *measure = catalog->measure;
     for (i = 0; i < catalog->Nmeasure; i++) {
-      R[i]        = measure[i].R       ;
-      D[i]        = measure[i].D       ;
+      R[i]        = measure[i].R        ;
+      D[i]        = measure[i].D        ;
       M[i]  	  = measure[i].M        ;
-      Mcal[i]     = measure[i].Mcal     ;
+      McalPSF[i]  = measure[i].McalPSF  ;
+      McalAPER[i] = measure[i].McalAPER ;
       Mflat[i]    = measure[i].Mflat    ;
       dM[i]       = measure[i].dM       ;
@@ -334,5 +339,6 @@
     gfits_set_bintable_column (&theader, &ftable, "DEC",  	D,         catalog->Nmeasure);
     gfits_set_bintable_column (&theader, &ftable, "MAG_SYS",  	M,         catalog->Nmeasure);
-    gfits_set_bintable_column (&theader, &ftable, "MAG_CAL",  	Mcal,      catalog->Nmeasure);
+    gfits_set_bintable_column (&theader, &ftable, "MCAL_PSF",  	McalPSF,   catalog->Nmeasure);
+    gfits_set_bintable_column (&theader, &ftable, "MCAL_APER",  McalAPER,  catalog->Nmeasure);
     gfits_set_bintable_column (&theader, &ftable, "MAG_FLAT",  	Mflat,     catalog->Nmeasure);
     gfits_set_bintable_column (&theader, &ftable, "MAG_ERR",  	dM,        catalog->Nmeasure);
@@ -352,5 +358,6 @@
     free (D       );
     free (M       );
-    free (Mcal    );
+    free (McalPSF );
+    free (McalAPER);
     free (Mflat   );
     free (dM      );
Index: /branches/eam_branches/ohana.20170822/src/relphot/src/StarOps.c
===================================================================
--- /branches/eam_branches/ohana.20170822/src/relphot/src/StarOps.c	(revision 40243)
+++ /branches/eam_branches/ohana.20170822/src/relphot/src/StarOps.c	(revision 40244)
@@ -473,5 +473,4 @@
   int i;
   off_t j, k, m;
-  float Mcal, Mmos, Mgrid;
 
   MEAS_BAD = ID_MEAS_NOCAL;
@@ -484,10 +483,16 @@
       for (k = 0; k < catalog[i].averageT[j].Nmeasure; k++, m++) {
 	if (catalog[i].measureT[m].dbFlags & MEAS_BAD) continue;
-	Mcal  = getMcal  (m, i, MAG_CLASS_PSF);
-	if (isnan(Mcal)) continue;
-	Mmos  = getMmos  (m, i);
+	float McalPSF  = getMcal  (m, i, MAG_CLASS_PSF);
+	float McalAPER = getMcal  (m, i, MAG_CLASS_APER);
+	if (isnan(McalPSF)) continue;
+	float Mmos  = getMmos  (m, i);
 	if (isnan(Mmos)) continue;
-	Mgrid = getMgrid (m, i);
+	float Mgrid = getMgrid (m, i);
 	if (isnan(Mgrid)) continue;
+
+	// XXX note that this operation is setting measure->McalAPER to image->McalAPER
+	// regardless of how the average value was calculate.
+	// IF average.Mkron (e.g.) is calculated using image.McalPSF, we should store McalPSF for both
+	// of these items below
 
 	// note that measurements for which the image is not selected will not be modified
@@ -495,8 +500,9 @@
 
 	// set the output calibration
-	catalog[i].measure[m].Mcal = Mcal + Mmos + Mgrid;
+	catalog[i].measure[m].McalPSF  = McalPSF  + Mmos + Mgrid;
+	catalog[i].measure[m].McalAPER = McalAPER + Mmos + Mgrid;
 
 	if (catalog[i].measureT[m].dbFlags & ID_MEAS_PHOTOM_UBERCAL) {
-	  myAssert (isfinite(catalog[i].measure[m].Mcal), "oops, broke an ubercal mag");
+	  myAssert (isfinite(catalog[i].measure[m].McalPSF), "oops, broke an ubercal mag");
 	}
       }
@@ -560,5 +566,5 @@
       int m = catalog[i].averageT[j].measureOffset;
       for (n = 0; n < catalog[i].averageT[j].Nmeasure; n++) {
-	fprintf (fout, "meas %5d %5d | %6.3f %6.3f | %6.3f\n", m+n, catalog[i].measureT[m+n].photcode, catalog[i].measureT[m+n].M, catalog[i].measureT[m+n].Mkron, catalog[i].measureT[m+n].Mcal); 
+	fprintf (fout, "meas %5d %5d | %6.3f %6.3f | %6.3f %6.3f\n", m+n, catalog[i].measureT[m+n].photcode, catalog[i].measureT[m+n].M, catalog[i].measureT[m+n].Mkron, catalog[i].measureT[m+n].McalPSF, catalog[i].measureT[m+n].McalAPER); 
       }
     }
@@ -643,4 +649,6 @@
 // sigma of the INNER 50% mean.  it then flags any measurements which are more than
 // NSIGMA_REJECT (5) sigma of the mean
+
+// this function only operations on the PSF magnitudes
 
 # define NSIGMA_CLIP 3.0
Index: /branches/eam_branches/ohana.20170822/src/relphot/src/bcatalog.c
===================================================================
--- /branches/eam_branches/ohana.20170822/src/relphot/src/bcatalog.c	(revision 40243)
+++ /branches/eam_branches/ohana.20170822/src/relphot/src/bcatalog.c	(revision 40244)
@@ -153,10 +153,12 @@
 	if (subcatalog[0].measureT[Nmeasure].dbFlags & ID_MEAS_PHOTOM_UBERCAL) {
 	  if (!KEEP_UBERCAL) {
-	    subcatalog[0].measureT[Nmeasure].Mcal = 0.0;
+	    subcatalog[0].measureT[Nmeasure].McalPSF  = 0.0;
+	    subcatalog[0].measureT[Nmeasure].McalAPER = 0.0;
 	    subcatalog[0].measureT[Nmeasure].dbFlags &= ~ID_MEAS_PHOTOM_UBERCAL;
 	  } 
 	} else {
 	  if (getImageEntry (Nmeasure, Ncat) >= 0) {
-	    subcatalog[0].measureT[Nmeasure].Mcal = 0.0;
+	    subcatalog[0].measureT[Nmeasure].McalPSF  = 0.0;
+	    subcatalog[0].measureT[Nmeasure].McalAPER = 0.0;
 	  }
 	}
Index: /branches/eam_branches/ohana.20170822/src/relphot/src/setMrelCatalog.c
===================================================================
--- /branches/eam_branches/ohana.20170822/src/relphot/src/setMrelCatalog.c	(revision 40243)
+++ /branches/eam_branches/ohana.20170822/src/relphot/src/setMrelCatalog.c	(revision 40244)
@@ -102,4 +102,8 @@
 // 3) UBERCAL measurements can have their weight increased by a big factor to help tie down the averages
 // 4) some reference photcode of some kind can be specified as fixed and have a high weight
+
+// Although I calculate McalAPER for exposures, I am only using McalPSF for exposures
+// XXX this means that a query of the database for mag:rel:kron will be inconsistent if there
+// is any significant difference
 
 // set mean of chip measurements (selected by photcode range for now):
@@ -224,5 +228,5 @@
       // overlaps).  Msys + measure.Mcal is our best guess of the true magnitude
       Mmos = Mgrid = 0;
-      Mcal = measureT[k].Mcal; // check that this is zero for loaded REF value
+      Mcal = measureT[k].McalPSF; // check that this is zero for loaded REF value
     } else {
       // getMcal returns image[].Mcal; note the flat-field correction is stored in measure.Mflat
@@ -521,4 +525,9 @@
 // 2) select the BEST detections per filter (regardless of PRIMARY)
 // 3) apply the zero point and AB->Jy transformations
+
+// I calculate McalAPER and McalPSF independently for stacks.  I use McalAPER for Mkron
+// and Map, and McalPSF for Mpsf.  A query of the database for mag:rel:kron will be
+// inconsistent if there is any significant difference
+
 int setMrelAverageStack (Catalog *catalog, int cat, off_t ave, int Nsecfilt, FlatCorrectionTable *flatcorr) {
 
@@ -633,5 +642,5 @@
 	// overlaps).  Msys + measure.Mcal is our best guess of the true magnitude
 	Mmos = Mgrid = 0;
-	McalPSF = measure[k].Mcal; // check that this is zero for loaded REF value
+	McalPSF = measure[k].McalPSF; // check that this is zero for loaded REF value
 	McalAPER = McalPSF; // check that this is zero for loaded REF value
       } else {
@@ -791,4 +800,9 @@
 // * no grid, no mosaic, no 2MASS, no SYNTH, no Ubercal, no flatcorr
 // analysis is done on flux, not mags (as the faintest objects will be nearly insignificant)
+
+// Although I calculate McalAPER for exposures, I am only using McalPSF for exposures
+// XXX this means that a query of the database for mag:rel:kron will be inconsistent if there
+// is any significant difference
+
 int setMrelAverageForcedWarp (Catalog *catalog, int cat, off_t ave, int Nsecfilt, FlatCorrectionTable *flatcorr, SetMrelInfo *results) {
   OHANA_UNUSED_PARAM(flatcorr);
@@ -868,5 +882,5 @@
       // data for which the associated image has not been loaded (probably because of
       // overlaps).  Msys + measure.Mcal is our best guess of the true magnitude
-      Mcal = measure[k].Mcal; // check that this is zero for loaded REF value
+      Mcal = measure[k].McalPSF; // check that this is zero for loaded REF value
     } else {
       Mcal  = getMcal (meas, cat, MAG_CLASS_PSF);
Index: /branches/eam_branches/ohana.20170822/src/relphot/src/setMrelFinal.c
===================================================================
--- /branches/eam_branches/ohana.20170822/src/relphot/src/setMrelFinal.c	(revision 40243)
+++ /branches/eam_branches/ohana.20170822/src/relphot/src/setMrelFinal.c	(revision 40244)
@@ -65,10 +65,12 @@
 	  if (catalog[0].measure[m].dbFlags & ID_MEAS_PHOTOM_UBERCAL) {
 	    if (!KEEP_UBERCAL) {
-	      catalog[0].measure[m].Mcal = 0.0;
+	      catalog[0].measure[m].McalPSF  = 0.0;
+	      catalog[0].measure[m].McalAPER = 0.0;
 	      catalog[0].measure[m].dbFlags &= ~ID_MEAS_PHOTOM_UBERCAL;
 	    } 
 	  } else {
 	    if (RESET_ZEROPTS && (getImageEntry (m, 0) >= 0)) {
-	      catalog[0].measure[m].Mcal = 0.0;
+	      catalog[0].measure[m].McalPSF  = 0.0;
+	      catalog[0].measure[m].McalAPER = 0.0;
 	    }
 	  }
Index: /branches/eam_branches/ohana.20170822/src/uniphot/src/update_catalog_setphot.c
===================================================================
--- /branches/eam_branches/ohana.20170822/src/uniphot/src/update_catalog_setphot.c	(revision 40243)
+++ /branches/eam_branches/ohana.20170822/src/uniphot/src/update_catalog_setphot.c	(revision 40244)
@@ -61,8 +61,10 @@
 # endif
 
-    measure[0].Mcal = Mcal;
+    myAssert(isfinite(Mcal), "oops: ubercal made a nan");
+
+    measure[0].McalPSF  = Mcal;
+    measure[0].McalAPER = Mcal;
     measure[0].Mflat = Mflat; // in the previous version, Mcal_offset (which is added to Mflat) had a negative sign here
     measure[0].dMcal = dMcal;
-    myAssert(isfinite(measure[0].Mcal), "oops: ubercal made a nan");
 
     if (RESET) {
Index: /branches/eam_branches/ohana.20170822/src/uniphot/src/update_catalog_uniphot.c
===================================================================
--- /branches/eam_branches/ohana.20170822/src/uniphot/src/update_catalog_uniphot.c	(revision 40243)
+++ /branches/eam_branches/ohana.20170822/src/uniphot/src/update_catalog_uniphot.c	(revision 40244)
@@ -24,5 +24,6 @@
       if (code[0].type != PHOT_DEP) continue;
       if (code[0].equiv != photcode[0].code) continue;
-      catalog[0].measure[m].Mcal -= sgroup[0].M;
+      catalog[0].measure[m].McalPSF  -= sgroup[0].M;
+      catalog[0].measure[m].McalAPER -= sgroup[0].M;
       found ++;
     }
