Index: /branches/eam_branches/ipp-20120627/Ohana/src/addstar/src/ReadStarsFITS.c
===================================================================
--- /branches/eam_branches/ipp-20120627/Ohana/src/addstar/src/ReadStarsFITS.c	(revision 34139)
+++ /branches/eam_branches/ipp-20120627/Ohana/src/addstar/src/ReadStarsFITS.c	(revision 34140)
@@ -10,5 +10,5 @@
   Header theader;
   FTable table;
-  Stars *stars;
+  Stars *stars; // Stars contains Average and Measure
   
   if (in_theader == NULL) {
@@ -89,23 +89,45 @@
     InitStar (&stars[i]);
 
-    stars[i].measure.Xccd      = smpdata[i].X;
-    stars[i].measure.Yccd      = smpdata[i].Y;
+    stars[i].measure.Xccd       = smpdata[i].X;
+    stars[i].measure.Yccd       = smpdata[i].Y;
+    stars[i].measure.dXccd    	= NAN_S_SHORT; // not provided by SMPDATA:
+    stars[i].measure.dYccd    	= NAN_S_SHORT; // not provided by SMPDATA:
+   
+    stars[i].measure.posangle 	= NAN_S_SHORT; // not provided by SMPDATA:
+    stars[i].measure.pltscale 	= NAN;         // not provided by SMPDATA:
 
     if ((smpdata[i].M >= ZeroPt) || isnan(smpdata[i].M)) {
-      stars[i].measure.M       = NAN;
-      stars[i].measure.Map     = NAN;
-    } else {
-      stars[i].measure.M       = smpdata[i].M;
-      stars[i].measure.Map     = smpdata[i].M;
-    }
-
-    stars[i].measure.dM        = smpdata[i].dM*0.001;
-
+      stars[i].measure.M        = NAN;
+      stars[i].measure.Map      = NAN;
+    } else {
+      stars[i].measure.M        = smpdata[i].M;
+      stars[i].measure.Map      = smpdata[i].M;
+    }
+    stars[i].measure.dM         = smpdata[i].dM*0.001;
+    stars[i].measure.dMcal    	= NAN; // not provided by SMPDATA:
+
+    stars[i].measure.Mkron    	= NAN; // not provided by SMPDATA:
+    stars[i].measure.dMkron   	= NAN; // not provided by SMPDATA:
+
+    stars[i].measure.Sky      	= NAN; // not provided by SMPDATA:
+    stars[i].measure.dSky     	= NAN; // not provided by SMPDATA:
+
+    stars[i].measure.psfChisq 	= NAN;	     // not provided by SMPDATA:
+    stars[i].measure.psfQual  	= NAN;	     // not provided by SMPDATA:
+    stars[i].measure.psfNdof    = NAN_S_INT; // not provided by SMPDATA:
+    stars[i].measure.psfNpix    = NAN_S_INT; // not provided by SMPDATA:
+    stars[i].measure.crNsigma   = NAN;       // not provided by SMPDATA:
+    stars[i].measure.extNsigma  = NAN;	     // not provided by SMPDATA:
+
+    stars[i].measure.FWx        = ToShortPixels (smpdata[i].fx);
+    stars[i].measure.FWy        = ToShortPixels (smpdata[i].fy);
+    stars[i].measure.theta      = ToShortDegrees (smpdata[i].df);
+
+    stars[i].measure.Mxx        = NAN_S_SHORT; // not provided by SMPDATA:
+    stars[i].measure.Mxy        = NAN_S_SHORT; // not provided by SMPDATA:
+    stars[i].measure.Myy        = NAN_S_SHORT; // not provided by SMPDATA:
+                        
     // the dophot type information gets pushed into the upper 2 bytes of photFlags
-    stars[i].measure.photFlags = (smpdata[i].dophot << 16);
-
-    stars[i].measure.FWx       = ToShortPixels (smpdata[i].fx);
-    stars[i].measure.FWy       = ToShortPixels (smpdata[i].fy);
-    stars[i].measure.theta     = ToShortDegrees (smpdata[i].df);
+    stars[i].measure.photFlags  = (smpdata[i].dophot << 16);
   }    
   *nstars = Nstars;
@@ -131,28 +153,45 @@
   for (i = 0; i < Nstars; i++) {
     InitStar (&stars[i]);
-    stars[i].measure.Xccd     = ps1data[i].X;
-    stars[i].measure.Yccd     = ps1data[i].Y;
-
-    stars[i].measure.dXccd    = ToShortPixels(ps1data[i].dX);
-    stars[i].measure.dYccd    = ToShortPixels(ps1data[i].dY);
+    stars[i].measure.Xccd     	= ps1data[i].X;
+    stars[i].measure.Yccd     	= ps1data[i].Y;
+    stars[i].measure.dXccd    	= ToShortPixels(ps1data[i].dX);
+    stars[i].measure.dYccd    	= ToShortPixels(ps1data[i].dY);
    
+    stars[i].measure.posangle 	= NAN_S_SHORT; // not provided by PS1_DEV_0:
+    stars[i].measure.pltscale 	= NAN;         // not provided by PS1_DEV_0:
+
     if ((ps1data[i].M >= 0.0) || isnan(ps1data[i].M)) {
-      stars[i].measure.M      = NAN;
-    } else {
-      stars[i].measure.M      = ps1data[i].M + ZeroPt;
-    }
-    stars[i].measure.Map      = NAN;
-    stars[i].measure.dM       = ps1data[i].dM;
-    stars[i].measure.Sky      = ps1data[i].sky;
-    stars[i].measure.dSky     = ps1data[i].dSky;
-
-    stars[i].measure.FWx      = ToShortPixels(ps1data[i].fx);
-    stars[i].measure.FWy      = ToShortPixels(ps1data[i].fy);
-    stars[i].measure.theta    = ToShortDegrees(ps1data[i].df);
-
-    stars[i].measure.psfChisq = ps1data[i].psfChisq;
-    stars[i].measure.psfQual  = ps1data[i].psfQual;
-
-    stars[i].measure.detID    = ps1data[i].detID;
+      stars[i].measure.M      	= NAN;
+    } else {
+      stars[i].measure.M      	= ps1data[i].M + ZeroPt;
+    }
+    stars[i].measure.dM       	= ps1data[i].dM;
+    stars[i].measure.dMcal    	= NAN; // not provided by PS1_DEV_0:
+    stars[i].measure.Map      	= NAN; // not provided by PS1_DEV_0:
+
+    stars[i].measure.Mkron    	= NAN; // not provided by PS1_DEV_0:
+    stars[i].measure.dMkron   	= NAN; // not provided by PS1_DEV_0:
+
+    stars[i].measure.Sky      	= ps1data[i].sky;
+    stars[i].measure.dSky     	= ps1data[i].dSky;
+
+    stars[i].measure.psfChisq 	= ps1data[i].psfChisq;
+    stars[i].measure.psfQual  	= ps1data[i].psfQual;
+    stars[i].measure.psfNdof    = NAN_S_INT; // not provided by PS1_DEV_0:
+    stars[i].measure.psfNpix    = NAN_S_INT; // not provided by PS1_DEV_0:
+    stars[i].measure.crNsigma   = NAN;       // not provided by PS1_DEV_0:
+    stars[i].measure.extNsigma  = NAN;        // not provided by PS1_DEV_0:
+
+    stars[i].measure.FWx      	= ToShortPixels(ps1data[i].fx);
+    stars[i].measure.FWy      	= ToShortPixels(ps1data[i].fy);
+    stars[i].measure.theta    	= ToShortDegrees(ps1data[i].df);
+
+    stars[i].measure.Mxx        = NAN_S_SHORT; // not provided by PS1_DEV_0:
+    stars[i].measure.Mxy        = NAN_S_SHORT; // not provided by PS1_DEV_0:
+    stars[i].measure.Myy        = NAN_S_SHORT; // not provided by PS1_DEV_0:
+                        
+    stars[i].measure.photFlags  = 0; // not provided by PS1_DEV_0:
+
+    stars[i].measure.detID      = ps1data[i].detID;
   }    
   *nstars = Nstars;
@@ -182,17 +221,31 @@
     stars[i].measure.Xccd       = ps1data[i].X;
     stars[i].measure.Yccd       = ps1data[i].Y;
-
     stars[i].measure.dXccd      = ToShortPixels(ps1data[i].dX);
     stars[i].measure.dYccd      = ToShortPixels(ps1data[i].dY);
 
+    stars[i].measure.posangle   = NAN_S_SHORT; // not provided by PS1_DEV_1:
+    stars[i].measure.pltscale   = NAN;         // not provided by PS1_DEV_1:
+
     if ((ps1data[i].M >= 0.0) || isnan(ps1data[i].M)) {
-	stars[i].measure.M      = NAN;
-    } else {
-	stars[i].measure.M      = ps1data[i].M + ZeroPt;
-    }
-    stars[i].measure.Map        = NAN;
+        stars[i].measure.M      = NAN;
+    } else {
+        stars[i].measure.M      = ps1data[i].M + ZeroPt;
+    }
     stars[i].measure.dM         = ps1data[i].dM;
+    stars[i].measure.dMcal      = NAN; // not provided by PS1_DEV_1:
+    stars[i].measure.Map        = NAN; // not provided by PS1_DEV_1:
+
+    stars[i].measure.Mkron      = NAN; // not provided by PS1_DEV_1:
+    stars[i].measure.dMkron     = NAN; // not provided by PS1_DEV_1:
+
     stars[i].measure.Sky        = ps1data[i].sky;
     stars[i].measure.dSky       = ps1data[i].dSky;
+
+    stars[i].measure.psfChisq   = ps1data[i].psfChisq;
+    stars[i].measure.psfQual    = ps1data[i].psfQual;
+    stars[i].measure.psfNdof    = NAN_S_INT; // not provided by PS1_DEV_1:
+    stars[i].measure.psfNpix    = NAN_S_INT; // not provided by PS1_DEV_1:
+    stars[i].measure.crNsigma   = ps1data[i].crNsigma;
+    stars[i].measure.extNsigma  = ps1data[i].extNsigma;
 
     stars[i].measure.FWx        = ToShortPixels(ps1data[i].fx);
@@ -200,11 +253,12 @@
     stars[i].measure.theta      = ToShortDegrees(ps1data[i].df);
 
-    stars[i].measure.psfChisq  	= ps1data[i].psfChisq;
-    stars[i].measure.psfQual   	= ps1data[i].psfQual;
-    stars[i].measure.crNsigma  	= ps1data[i].crNsigma;
-    stars[i].measure.extNsigma 	= ps1data[i].extNsigma;
-
-    stars[i].measure.detID     	= ps1data[i].detID;
+    stars[i].measure.Mxx        = NAN_S_SHORT; // not provided by PS1_DEV_1:
+    stars[i].measure.Mxy        = NAN_S_SHORT; // not provided by PS1_DEV_1:
+    stars[i].measure.Myy        = NAN_S_SHORT; // not provided by PS1_DEV_1:
+                        
     stars[i].measure.photFlags  = ps1data[i].flags;
+
+    // this is may optionally be replaced by the internal sequence (see FilterStars.c)
+    stars[i].measure.detID      = ps1data[i].detID;
   }    
   *nstars = Nstars;
@@ -252,15 +306,18 @@
 
     if ((ps1data[i].M >= 0.0) || isnan(ps1data[i].M)) {
-	stars[i].measure.M      = NAN;
-    } else {
-	stars[i].measure.M      = ps1data[i].M + ZeroPt;
+        stars[i].measure.M      = NAN;
+    } else {
+        stars[i].measure.M      = ps1data[i].M + ZeroPt;
     }
     stars[i].measure.dM         = ps1data[i].dM;
     stars[i].measure.dMcal      = ps1data[i].dMcal;
     stars[i].measure.Map        = ps1data[i].Map + ZeroPt;
-		        
+                        
+    stars[i].measure.Mkron      = NAN; // not provided by PS1_V1:
+    stars[i].measure.dMkron     = NAN; // not provided by PS1_V1:
+
     stars[i].measure.Sky        = ps1data[i].sky;
     stars[i].measure.dSky       = ps1data[i].dSky;
-		        
+                        
     stars[i].measure.psfChisq   = ps1data[i].psfChisq;
     stars[i].measure.psfQual    = ps1data[i].psfQual;
@@ -277,5 +334,5 @@
     stars[i].measure.Mxy        = ToShortPixels(ps1data[i].Mxy);
     stars[i].measure.Myy        = ToShortPixels(ps1data[i].Myy);
-		        
+                        
     stars[i].measure.photFlags  = ps1data[i].flags;
 
@@ -328,15 +385,18 @@
 
     if ((ps1data[i].M >= 0.0) || isnan(ps1data[i].M)) {
-	stars[i].measure.M      = NAN;
-    } else {
-	stars[i].measure.M      = ps1data[i].M + ZeroPt;
+        stars[i].measure.M      = NAN;
+    } else {
+        stars[i].measure.M      = ps1data[i].M + ZeroPt;
     }
     stars[i].measure.dM         = ps1data[i].dM;
     stars[i].measure.dMcal      = ps1data[i].dMcal;
     stars[i].measure.Map        = ps1data[i].Map + ZeroPt;
-		        
+                        
+    stars[i].measure.Mkron      = NAN; // not provided by PS1_V1_Alt:
+    stars[i].measure.dMkron     = NAN; // not provided by PS1_V1_Alt:
+
     stars[i].measure.Sky        = ps1data[i].sky;
     stars[i].measure.dSky       = ps1data[i].dSky;
-		        
+                        
     stars[i].measure.psfChisq   = ps1data[i].psfChisq;
     stars[i].measure.psfQual    = ps1data[i].psfQual;
@@ -353,5 +413,5 @@
     stars[i].measure.Mxy        = ToShortPixels(ps1data[i].Mxy);
     stars[i].measure.Myy        = ToShortPixels(ps1data[i].Myy);
-		        
+                        
     stars[i].measure.photFlags  = ps1data[i].flags;
 
@@ -396,15 +456,18 @@
 
     if ((ps1data[i].M >= 0.0) || isnan(ps1data[i].M)) {
-	stars[i].measure.M      = NAN;
-    } else {
-	stars[i].measure.M      = ps1data[i].M + ZeroPt;
+        stars[i].measure.M      = NAN;
+    } else {
+        stars[i].measure.M      = ps1data[i].M + ZeroPt;
     }
     stars[i].measure.dM         = ps1data[i].dM;
     stars[i].measure.dMcal      = ps1data[i].dMcal;
     stars[i].measure.Map        = ps1data[i].Map + ZeroPt;
-		        
+                        
+    stars[i].measure.Mkron      = NAN; // not provided by PS1_V2:
+    stars[i].measure.dMkron     = NAN; // not provided by PS1_V2:
+
     stars[i].measure.Sky        = ps1data[i].sky;
     stars[i].measure.dSky       = ps1data[i].dSky;
-		        
+                        
     stars[i].measure.psfChisq   = ps1data[i].psfChisq;
     stars[i].measure.psfQual    = ps1data[i].psfQual;
@@ -421,5 +484,5 @@
     stars[i].measure.Mxy        = ToShortPixels(ps1data[i].Mxy);
     stars[i].measure.Myy        = ToShortPixels(ps1data[i].Myy);
-		        
+                        
     stars[i].measure.photFlags  = ps1data[i].flags;
 
@@ -464,15 +527,18 @@
 
     if ((ps1data[i].M >= 0.0) || isnan(ps1data[i].M)) {
-	stars[i].measure.M      = NAN;
-    } else {
-	stars[i].measure.M      = ps1data[i].M + ZeroPt;
+        stars[i].measure.M      = NAN;
+    } else {
+        stars[i].measure.M      = ps1data[i].M + ZeroPt;
     }
     stars[i].measure.dM         = ps1data[i].dM;
     stars[i].measure.dMcal      = ps1data[i].dMcal;
     stars[i].measure.Map        = ps1data[i].Map + ZeroPt;
-		        
+                        
+    stars[i].measure.Mkron      = (ps1data[i].kronFlux > 0.0) ? -2.5*log10(ps1data[i].kronFlux) + ZeroPt : NAN;
+    stars[i].measure.dMkron     = (ps1data[i].kronFlux > 0.0) ? ps1data[i].kronFluxErr / ps1data[i].kronFlux : NAN;
+                        
     stars[i].measure.Sky        = ps1data[i].sky;
     stars[i].measure.dSky       = ps1data[i].dSky;
-		        
+                        
     stars[i].measure.psfChisq   = ps1data[i].psfChisq;
     stars[i].measure.psfQual    = ps1data[i].psfQual;
@@ -489,5 +555,5 @@
     stars[i].measure.Mxy        = ToShortPixels(ps1data[i].Mxy);
     stars[i].measure.Myy        = ToShortPixels(ps1data[i].Myy);
-		        
+                        
     stars[i].measure.photFlags  = ps1data[i].flags;
 
@@ -496,6 +562,9 @@
 
     // the Average fields and the following Measure fields are set in FilterStars after
-    // the image metadata is in hand:  dR, dD, Mcal, dt, airmass, az, t, imageID, extID, 
-    // averef is set in find_matches, dbFlags is zero on ingest.
+    // the image metadata is in hand:  dR, dD, Mcal, dt, airmass, az, t, imageID, extID.
+
+    // averef is set in find_matches
+
+    // dbFlags is zero on ingest.
 
     // the following fields are currently not being set anywhere: t_msec
@@ -537,15 +606,18 @@
 
     if ((ps1data[i].M >= 0.0) || isnan(ps1data[i].M)) {
-	stars[i].measure.M      = NAN;
-    } else {
-	stars[i].measure.M      = ps1data[i].M + ZeroPt;
+        stars[i].measure.M      = NAN;
+    } else {
+        stars[i].measure.M      = ps1data[i].M + ZeroPt;
     }
     stars[i].measure.dM         = ps1data[i].dM;
     stars[i].measure.dMcal      = ps1data[i].dMcal;
     stars[i].measure.Map        = ps1data[i].Map + ZeroPt;
-		        
+                        
+    stars[i].measure.Mkron      = (ps1data[i].kronFlux > 0.0) ? -2.5*log10(ps1data[i].kronFlux) + ZeroPt : NAN;
+    stars[i].measure.dMkron     = (ps1data[i].kronFlux > 0.0) ? ps1data[i].kronFluxErr / ps1data[i].kronFlux : NAN;
+
     stars[i].measure.Sky        = ps1data[i].sky;
     stars[i].measure.dSky       = ps1data[i].dSky;
-		        
+                        
     stars[i].measure.psfChisq   = ps1data[i].psfChisq;
     stars[i].measure.psfQual    = ps1data[i].psfQual;
@@ -562,5 +634,5 @@
     stars[i].measure.Mxy        = ToShortPixels(ps1data[i].Mxy);
     stars[i].measure.Myy        = ToShortPixels(ps1data[i].Myy);
-		        
+                        
     stars[i].measure.photFlags  = ps1data[i].flags;
 
@@ -607,15 +679,18 @@
 
     if ((ps1data[i].M >= 0.0) || isnan(ps1data[i].M)) {
-	stars[i].measure.M      = NAN;
-    } else {
-	stars[i].measure.M      = ps1data[i].M + ZeroPt;
+        stars[i].measure.M      = NAN;
+    } else {
+        stars[i].measure.M      = ps1data[i].M + ZeroPt;
     }
     stars[i].measure.dM         = ps1data[i].dM;
     stars[i].measure.dMcal      = ps1data[i].dMcal;
     stars[i].measure.Map        = ps1data[i].Map + ZeroPt;
-		        
+                        
+    stars[i].measure.Mkron      = (ps1data[i].kronFlux > 0.0) ? -2.5*log10(ps1data[i].kronFlux) + ZeroPt : NAN;
+    stars[i].measure.dMkron     = (ps1data[i].kronFlux > 0.0) ? ps1data[i].kronFluxErr / ps1data[i].kronFlux : NAN;
+
     stars[i].measure.Sky        = ps1data[i].sky;
     stars[i].measure.dSky       = ps1data[i].dSky;
-		        
+                        
     stars[i].measure.psfChisq   = ps1data[i].psfChisq;
     stars[i].measure.psfQual    = ps1data[i].psfQual;
@@ -632,5 +707,5 @@
     stars[i].measure.Mxy        = ToShortPixels(ps1data[i].Mxy);
     stars[i].measure.Myy        = ToShortPixels(ps1data[i].Myy);
-		        
+                        
     stars[i].measure.photFlags  = ps1data[i].flags;
 
Index: /branches/eam_branches/ipp-20120627/Ohana/src/addstar/src/mkcmf.c
===================================================================
--- /branches/eam_branches/ipp-20120627/Ohana/src/addstar/src/mkcmf.c	(revision 34139)
+++ /branches/eam_branches/ipp-20120627/Ohana/src/addstar/src/mkcmf.c	(revision 34140)
@@ -14,4 +14,5 @@
 void gauss_init (int Nbin);
 double rnd_gauss (double mean, double sigma);
+void writeStars_PS1_V3 (FTable *ftable, double *X, double *Y, double *M, unsigned int *Flag, int Nstars);
 void writeStars_PS1_V2 (FTable *ftable, double *X, double *Y, double *M, unsigned int *Flag, int Nstars);
 void writeStars_PS1_V1 (FTable *ftable, double *X, double *Y, double *M, int Nstars);
@@ -276,4 +277,8 @@
   if (!strcmp(type, "PS1_V2")) {
     writeStars_PS1_V2 (&ftable, X, Y, M, Flag, Nstars); 
+    found = TRUE;
+  }
+  if (!strcmp(type, "PS1_V3")) {
+    writeStars_PS1_V3 (&ftable, X, Y, M, Flag, Nstars); 
     found = TRUE;
   }
@@ -572,2 +577,60 @@
 }
 
+void writeStars_PS1_V3 (FTable *ftable, double *X, double *Y, double *M, unsigned int *Flag, int Nstars) {
+
+  int i;
+  CMF_PS1_V3 *stars;
+  float flux, fSN;
+
+  // XXX add gaussian-distributed noise based on counts
+  // this needs to make different output 'stars' entries depending on the desired type
+  ALLOCATE (stars, CMF_PS1_V3, Nstars);
+  gauss_init (2048);
+  for (i = 0; i < Nstars; i++) {
+    stars[i].detID = i;
+
+    flux = pow (10.0, -0.4*M[i]);
+    fSN = 1.0 / sqrt(flux);
+
+    stars[i].X = X[i];
+    stars[i].Y = Y[i];
+    stars[i].M = M[i];
+    stars[i].Map = M[i] - 0.05;
+
+    if (ADDNOISE) {
+      stars[i].X += FX * fSN * rnd_gauss(0.0, 1.0);
+      stars[i].Y += FY * fSN * rnd_gauss(0.0, 1.0);
+      stars[i].M += fSN*rnd_gauss(0.0, 1.0);
+    }
+
+    // randomly give poor PSFQF values
+    if ((BAD_PSFQF_FRAC > 0.0) && (drand48() < BAD_PSFQF_FRAC)) {
+      stars[i].psfQual   = 0.25;
+    } else {
+      stars[i].psfQual   = PSFQUAL;
+    }
+    
+    stars[i].dX = FX * fSN;
+    stars[i].dY = FY * fSN;
+    stars[i].dM = fSN;
+
+    stars[i].Mpeak     = M[i] + 1.0;
+    stars[i].sky       = SKY;
+    stars[i].dSky      = DSKY;
+    stars[i].psfChisq  = PSFCHI;
+    stars[i].crNsigma  = CRN;
+    stars[i].extNsigma = EXTN;
+    stars[i].fx        = FX;
+    stars[i].fy        = FY;
+    stars[i].df        = DF;
+    stars[i].nFrames   = 1;
+    stars[i].flags     = Flag[i];
+
+    stars[i].kronFlux  = flux * 1.25;
+    stars[i].kronFluxErr = fSN * flux * 1.25;
+  }
+
+  gfits_table_set_CMF_PS1_V3 (ftable, stars, Nstars);
+  gfits_modify (ftable->header, "EXTTYPE",   "%s", 1, "PS1_V3");
+}
+
Index: /branches/eam_branches/ipp-20120627/Ohana/src/addstar/test/simple.dvo
===================================================================
--- /branches/eam_branches/ipp-20120627/Ohana/src/addstar/test/simple.dvo	(revision 34139)
+++ /branches/eam_branches/ipp-20120627/Ohana/src/addstar/test/simple.dvo	(revision 34140)
@@ -21,4 +21,10 @@
   test.fields PS1_V2 	PS1_V3
   test.fields PS1_V3 	PS1_V3
+
+  test.fields PS1_DEV_0 PS1_V4
+  test.fields PS1_DEV_1 PS1_V4
+  test.fields PS1_V1 	PS1_V4
+  test.fields PS1_V2 	PS1_V4
+  test.fields PS1_V3 	PS1_V4
 end  
 
@@ -83,4 +89,13 @@
     sort id1 v1
     sort id2 v2
+
+    # some fields require arithmetic manipulations
+    if ("$name:0" == "KRON_FLUX") 
+     set v1 = -2.5*log(v1)
+    end
+    if ("$name:0" == "KRON_FLUX_ERR") 
+     set v1 = KRON_FLUX_ERR / KRON_FLUX
+    end
+
     set d = v1 - v2
     vstat -q d
@@ -88,4 +103,12 @@
     #echo tapOK fabs($MEAN)  < 0.001 "$name:0 vs $name:2 (MEAN)"
     #echo tapOK fabs($SIGMA) < 0.001 "$name:0 vs $name:2 (SIGMA)"
+
+    # THETA is stored to only (360/65536) deg accuracy
+    if ("$name:0" == "PSF_THETA")
+      echo $MEAN
+      tapOK {abs($MEAN)  < 0.006} "$name:0 vs $name:2 (MEAN)"
+      tapOK {abs($SIGMA) < 0.001} "$name:0 vs $name:2 (SIGMA)"
+      continue
+    end
 
     tapOK {abs($MEAN)  < 0.001} "$name:0 vs $name:2 (MEAN)"
@@ -111,4 +134,7 @@
   output stdout
 end
+
+# the following lists define fields in the cmf files which can be compared to their equivalents in DVO
+# the left column is the cmf field name, the right column is the dvo field name
 
 # list of cmf fields to test matched to mextract fields
@@ -122,5 +148,5 @@
   PSF_INST_MAG      : mag:inst
   PSF_INST_MAG_SIG  : mag:err
-  PEAK_FLUX_AS_MAG  : SKIP
+  PEAK_FLUX_AS_MAG  : SKIP # not ingested into DVO
   SKY               : sky
   SKY_SIG           : sky_err
@@ -130,5 +156,5 @@
   PSF_THETA         : THETA
   PSF_QF            : PSF_QF
-  N_FRAMES          : SKIP
+  N_FRAMES          : SKIP # not ingested into DVO
 end
 
@@ -143,5 +169,5 @@
   PSF_INST_MAG      : mag:inst
   PSF_INST_MAG_SIG  : mag:err
-  PEAK_FLUX_AS_MAG  : SKIP
+  PEAK_FLUX_AS_MAG  : SKIP # not ingested into DVO
   SKY               : sky
   SKY_SIG           : sky_err
@@ -153,5 +179,5 @@
   PSF_THETA         : THETA
   PSF_QF            : PSF_QF
-  N_FRAMES          : SKIP
+  N_FRAMES          : SKIP # not ingested into DVO
   FLAGS             : phot_flags
 end
@@ -236,15 +262,18 @@
   X_PSF_SIG         : xccd:err # FAIL
   Y_PSF_SIG         : yccd:err # FAIL
-  RA_PSF            : SKIP # astrometry is not calibrated in the cmf
-  DEC_PSF           : SKIP # astrometry is not calibrated in the cmf
   POSANGLE          : SKIP # astrometry is not calibrated in the cmf
   PLTSCALE          : SKIP # astrometry is not calibrated in the cmf
   PSF_INST_MAG      : mag:inst	
   PSF_INST_MAG_SIG  : mag:err	
-  AP_MAG_STANDARD   : mag:ap # FAIL
-  AP_MAG_RADIUS     : SKIP # no accessor
-  PEAK_FLUX_AS_MAG  : SKIP # no accessor
+  PSF_INST_FLUX     : SKIP # not ingested into DVO
+  PSF_INST_FLUX_SIG : SKIP # not ingested into DVO
+  AP_MAG_STANDARD   : mag:aperinst # FAIL
+  AP_MAG_RAW        : SKIP # not ingested into DVO
+  AP_MAG_RADIUS     : SKIP # not ingested into DVO
   CAL_PSF_MAG       : SKIP # photometry is not calibrated in the cmf
   CAL_PSF_MAG_SIG   : SKIP # photometry is not calibrated in the cmf
+  RA_PSF            : SKIP # astrometry is not calibrated in the cmf
+  DEC_PSF           : SKIP # astrometry is not calibrated in the cmf
+  PEAK_FLUX_AS_MAG  : SKIP # not ingested into DVO
   SKY               : sky	
   SKY_SIG           : sky_err	
@@ -256,10 +285,21 @@
   PSF_THETA         : THETA # FAIL
   PSF_QF            : PSF_QF	
-  PSF_NDOF          : SKIP # no accessor
-  PSF_NPIX          : SKIP # no accessor
-  MOMENTS_XX        : SKIP # no accessor
-  MOMENTS_XY        : SKIP # no accessor
-  MOMENTS_YY        : SKIP # no accessor
+  PSF_QF_PERFECT    : SKIP # not ingested into DVO
+  PSF_NDOF          : PSF_NDOF
+  PSF_NPIX          : PSF_NPIX
+  MOMENTS_XX        : MXX
+  MOMENTS_XY        : MXY
+  MOMENTS_YY        : MYY
+  MOMENTS_M3C       : SKIP # not ingested into DVO
+  MOMENTS_M3S       : SKIP # not ingested into DVO
+  MOMENTS_M4C       : SKIP # not ingested into DVO
+  MOMENTS_M4S       : SKIP # not ingested into DVO
+  MOMENTS_R1        : SKIP # not ingested into DVO
+  MOMENTS_RH        : SKIP # not ingested into DVO
+  KRON_FLUX         : mag:kroninst
+  KRON_FLUX_ERR     : mag:kronerr
+  KRON_FLUX_INNER   : SKIP # not ingested into DVO
+  KRON_FLUX_OUTER   : SKIP # not ingested into DVO
   FLAGS             : phot_flags
-  N_FRAMES          : SKIP # no accessor	
-end
+  N_FRAMES          : SKIP # not ingested into DVO
+end
Index: /branches/eam_branches/ipp-20120627/Ohana/src/libautocode/def/cmf-ps1-v1.d
===================================================================
--- /branches/eam_branches/ipp-20120627/Ohana/src/libautocode/def/cmf-ps1-v1.d	(revision 34139)
+++ /branches/eam_branches/ipp-20120627/Ohana/src/libautocode/def/cmf-ps1-v1.d	(revision 34140)
@@ -44,35 +44,2 @@
 # model shape parameters: F_major, F_minor, F_theta
 # centroid errors: sigma_X, sigma_Y, sigma_XY
-
-# IPP_IDET         1J  IPP_IDET,     	   unsigned i
-# X_PSF       	 1E  X_PSF,    	   float,        
-# Y_PSF       	 1E  Y_PSF,    	   float,        
-# X_PSF_SIG   	 1E  X_PSF_SIG,    	   float,        
-# Y_PSF_SIG   	 1E  Y_PSF_SIG,    	   float,        
-# RA_PSF      	 1E  RA_PSF,    	   float,        
-# DEC_PSF     	 1E  DEC_PSF,    	   float,        
-# POSANGLE    	 1E  POSANGLE,    	   float,        
-# PLTSCALE    	 1E  PLTSCALE,    	   float,        
-# PSF_INST_MAG	 1E  PSF_INST_MAG,     float,          
-# PSF_INST_MAG_SIG 1E  PSF_INST_MAG_SIG, float,        
-# AP_MAG_STANDARD  1E  AP_MAG_STANDARD,  float,        
-# AP_MAG_RADIUS    1E      
-# PEAK_FLUX_AS_MAG 1E  PEAK_FLUX_AS_MAG, float,        
-# CAL_PSF_MAG      1E  CAL_PSF_MAG,      float,        
-# CAL_PSF_MAG_SIG  1E  CAL_PSF_MAG_SIG,  float,        
-# SKY              1E  SKY,              float,        
-# SKY_SIGMA        1E  SKY_SIG,          float,        
-# PSF_CHISQ        1E  PSF_CHISQ,        float,        
-# CR_NSIGMA        1E  CR_NSIGMA,        float,        
-# EXT_NSIGMA       1E  EXT_NSIGMA,       float,        
-# PSF_MAJOR        1E  PSF_MAJOR,        float,        
-# PSF_MINOR        1E  PSF_MINOR,        float,        
-# PSF_THETA        1E  PSF_THETA,        float,        
-# PSF_QF           1E  PSF_QF,           float,        
-# PSF_NDOF         1J  PSF_NDOF,         int,          
-# PSF_NPIX         1J  PSF_NPIX,         int,          
-# MOMENTS_XX       1E  MOMENTS_XX,       float,        
-# MOMENTS_XY       1E  MOMENTS_XY,       float,        
-# MOMENTS_YY       1E  MOMENTS_YY,       float,        
-# N_FRAMES         1I  N_FRAMES,         short,        
-# FLAGS            1J  FLAGS,            int,          
Index: /branches/eam_branches/ipp-20120627/Ohana/src/libautocode/def/cmf-ps1-v2.d
===================================================================
--- /branches/eam_branches/ipp-20120627/Ohana/src/libautocode/def/cmf-ps1-v2.d	(revision 34139)
+++ /branches/eam_branches/ipp-20120627/Ohana/src/libautocode/def/cmf-ps1-v2.d	(revision 34140)
@@ -40,39 +40,4 @@
 FIELD padding,   PADDING,	   short,    padding for 8byte records
 
-# for an object in an image, we have three triplets that tell us about the shape:
-# second moments: Mxx, Mxy, Myy 
-# model shape parameters: F_major, F_minor, F_theta
-# centroid errors: sigma_X, sigma_Y, sigma_XY
-
-# IPP_IDET         1J  IPP_IDET,     	   unsigned i
-# X_PSF       	 1E  X_PSF,    	   float,        
-# Y_PSF       	 1E  Y_PSF,    	   float,        
-# X_PSF_SIG   	 1E  X_PSF_SIG,    	   float,        
-# Y_PSF_SIG   	 1E  Y_PSF_SIG,    	   float,        
-# RA_PSF      	 1E  RA_PSF,    	   float,        
-# DEC_PSF     	 1E  DEC_PSF,    	   float,        
-# POSANGLE    	 1E  POSANGLE,    	   float,        
-# PLTSCALE    	 1E  PLTSCALE,    	   float,        
-# PSF_INST_MAG	 1E  PSF_INST_MAG,     float,          
-# PSF_INST_MAG_SIG 1E  PSF_INST_MAG_SIG, float,        
-# AP_MAG_STANDARD  1E  AP_MAG_STANDARD,  float,        
-# AP_MAG_RADIUS    1E      
-# PEAK_FLUX_AS_MAG 1E  PEAK_FLUX_AS_MAG, float,        
-# CAL_PSF_MAG      1E  CAL_PSF_MAG,      float,        
-# CAL_PSF_MAG_SIG  1E  CAL_PSF_MAG_SIG,  float,        
-# SKY              1E  SKY,              float,        
-# SKY_SIGMA        1E  SKY_SIG,          float,        
-# PSF_CHISQ        1E  PSF_CHISQ,        float,        
-# CR_NSIGMA        1E  CR_NSIGMA,        float,        
-# EXT_NSIGMA       1E  EXT_NSIGMA,       float,        
-# PSF_MAJOR        1E  PSF_MAJOR,        float,        
-# PSF_MINOR        1E  PSF_MINOR,        float,        
-# PSF_THETA        1E  PSF_THETA,        float,        
-# PSF_QF           1E  PSF_QF,           float,        
-# PSF_NDOF         1J  PSF_NDOF,         int,          
-# PSF_NPIX         1J  PSF_NPIX,         int,          
-# MOMENTS_XX       1E  MOMENTS_XX,       float,        
-# MOMENTS_XY       1E  MOMENTS_XY,       float,        
-# MOMENTS_YY       1E  MOMENTS_YY,       float,        
-# N_FRAMES         1I  N_FRAMES,         short,        
-# FLAGS            1J  FLAGS,            int,          
+# fields added since PS1_V1:
+# RA & DEC promoted to double
Index: /branches/eam_branches/ipp-20120627/Ohana/src/libautocode/def/cmf-ps1-v3.d
===================================================================
--- /branches/eam_branches/ipp-20120627/Ohana/src/libautocode/def/cmf-ps1-v3.d	(revision 34139)
+++ /branches/eam_branches/ipp-20120627/Ohana/src/libautocode/def/cmf-ps1-v3.d	(revision 34140)
@@ -64,54 +64,18 @@
 # centroid errors: sigma_X, sigma_Y, sigma_XY
 
-# # elements of data structure / FITS table
-# FIELD detID,          IPP_IDET,          IPP_IDET           1J      unsigned int, detection ID                     
-# FIELD X,              X_PSF,             X_PSF              1E      float,    x coord,               pixels
-# FIELD Y,              Y_PSF,             Y_PSF              1E      float,    y coord,               pixels
-# FIELD dX,             X_PSF_SIG,         X_PSF_SIG          1E      float,    x coord error,         pixels
-# FIELD dY,             Y_PSF_SIG,         Y_PSF_SIG          1E      float,    y coord error,         pixels
-# FIELD posangle,       POSANGLE,          POSANGLE           1E      float,    Posangle at source,    degrees
-# FIELD pltscale,       PLTSCALE,          PLTSCALE           1E      float,    Plate Scale at source, arcsec/pixel
-# FIELD M,              PSF_INST_MAG,      PSF_INST_MAG       1E      float,    inst mags,             mags
-# FIELD dM,             PSF_INST_MAG_SIG,  PSF_INST_MAG_SIG   1E      float,    inst mag error,        mags
-# FIELD flux,           PSF_INST_FLUX,     PSF_INST_FLUX      1E      float,    psf flux,	       counts
-# FIELD flux,           PSF_INST_FLUX_SIG, PSF_INST_FLUX_SIG  1E      float,    psf flux error,        counts      
-# FIELD Map,            AP_MAG_STANDARD,   AP_MAG             1E      float,    standard aperture mag, mags
-# FIELD Map,            AP_MAG_RAW,        AP_MAG_RAW         1E      float,    raw aperture mag,      mags
-# FIELD apRadius,       AP_MAG_RADIUS,     AP_MAG_RADIUS      1E      float,    radius used for fit,   pixels
-# FIELD Mpeak,          PEAK_FLUX_AS_MAG,  PEAK_FLUX_AS_MAG   1E      float,    peak flux as a mag,    mags
-# FIELD Mcalib,         CAL_PSF_MAG,       CAL_PSF_MAG        1E      float,    calibrated psf mag,    mags
-# FIELD dMcal,          CAL_PSF_MAG_SIG,   CAL_PSF_MAG_SIG    1E      float,    zero point scatter,    mags
-# FIELD RA,             RA_PSF,            RA_PSF             1D      double,   PSF RA coord,          degrees
-# FIELD DEC,            DEC_PSF,           DEC_PSF            1D      double,   PSF DEC coord,         degrees
-# FIELD sky,            SKY,               SKY                1E      float,    sky flux,              cnts/sec
-# FIELD dSky,           SKY_SIG,           SKY_SIGMA          1E      float,    sky flux error,        cnts/sec
-# FIELD psfChisq,       PSF_CHISQ,         PSF_CHISQ          1E      float,    psf fit chisq
-# FIELD crNsigma,       CR_NSIGMA,         CR_NSIGMA          1E      float,    Nsigma deviations from PSF to CF
-# FIELD extNsigma,      EXT_NSIGMA,        EXT_NSIGMA         1E      float,    Nsigma deviations from PSF to EXT
-# FIELD fx,             PSF_MAJOR,         PSF_MAJOR          1E      float,    psf fit major axis,    pixels
-# FIELD fy,             PSF_MINOR,         PSF_MINOR          1E      float,    psf fit minor axis,    pixels
-# FIELD df,             PSF_THETA,         PSF_THETA          1E      float,    ellipse angle,         degrees
-# FIELD psfQual,        PSF_QF,            PSF_QF             1E      float,    quality factor
-# FIELD psfQualPerfect, PSF_QF_PERFECT,    PSF_QF_PERFECT     1E      float,    quality factor perfect
-# FIELD psfNdof,        PSF_NDOF,          PSF_NDOF           1J      int,      psf degrees of freedom
-# FIELD psfNpix,        PSF_NPIX,          PSF_NPIX           1J      int,      psf number of pixels
-# FIELD Mxx,            MOMENTS_XX,        MOMENTS_XX         1E      float,    second moment X,       pixels^2
-# FIELD Mxy,            MOMENTS_XY,        MOMENTS_XY         1E      float,    second moment Y,       pixels^2
-# FIELD Myy,            MOMENTS_YY,        MOMENTS_YY         1E      float,    second moment XY,      pixels^2
-# FIELD M3c,            MOMENTS_M3C,       MOMENTS_M3C        1E      float,    third moment cos(t),   pixels^3
-# FIELD M3s,            MOMENTS_M3S,       MOMENTS_M3S        1E      float,    third moment sin(t),   pixels^3
-# FIELD M4c,            MOMENTS_M4C,       MOMENTS_M4C        1E      float,    fourth moment cos(t),  pixels^4
-# FIELD M4s,            MOMENTS_M4S,       MOMENTS_M4S        1E      float,    fourth moment sin(t),  pixels^4
-# FIELD Mr1,            MOMENTS_R1,        MOMENTS_R1         1E      float,    first radial moment,   pixels
-# FIELD Mrh,            MOMENTS_RH,        MOMENTS_RH         1E      float,    half radial moment,    pixels^1/2
-# FIELD kronFlux,       KRON_FLUX,         KRON_FLUX          1E      float,    kron flux,             counts
-# FIELD kronFluxErr,    KRON_FLUX_ERR,     KRON_FLUX_ERR      1E      float,    kron flux error,       counts
-# FIELD kronInner,      KRON_FLUX_INNER,   KRON_FLUX_INNER    1E      float,    kron flux 1<R<2.5,     counts
-# FIELD kronOuter,      KRON_FLUX_OUTER,   KRON_FLUX_OUTER    1E      float,    kron flux 2.5<R<4,     counts
-# FIELD flags,          FLAGS,             FLAGS              1J      int,      analysis flags
-# FIELD flags2,         FLAGS,             FLAGS2             1J      int,      analysis flags (2)
-# FIELD nFrames,        N_FRAMES,          N_FRAMES           1I      short,    images overlapping peak
-# FIELD padding,        PADDING,           PADDING            1I      short,    padding for 8byte records
-
-      
-
+# fields added since PS1_V2:
+# FIELD Flux,           PSF_INST_FLUX,     float,    psf flux,	       counts
+# FIELD dFlux,          PSF_INST_FLUX_SIG, float,    psf flux error,        counts      
+# FIELD MapRaw,         AP_MAG_RAW,        float,    raw aperture mag,      mags
+# FIELD psfQualPerfect, PSF_QF_PERFECT,    float,    quality factor perfect
+# FIELD M3c,            MOMENTS_M3C,       float,    third moment cos(t),   pixels^3
+# FIELD M3s,            MOMENTS_M3S,       float,    third moment sin(t),   pixels^3
+# FIELD M4c,            MOMENTS_M4C,       float,    fourth moment cos(t),  pixels^4
+# FIELD M4s,            MOMENTS_M4S,       float,    fourth moment sin(t),  pixels^4
+# FIELD Mr1,            MOMENTS_R1,        float,    first radial moment,   pixels
+# FIELD Mrh,            MOMENTS_RH,        float,    half radial moment,    pixels^1/2
+# FIELD kronFlux,       KRON_FLUX,         float,    kron flux,             counts
+# FIELD kronFluxErr,    KRON_FLUX_ERR,     float,    kron flux error,       counts
+# FIELD kronInner,      KRON_FLUX_INNER,   float,    kron flux 1<R<2.5,     counts
+# FIELD kronOuter,      KRON_FLUX_OUTER,   float,    kron flux 2.5<R<4,     counts
+# FIELD flags2,         FLAGS,             int,      analysis flags (2)
Index: /branches/eam_branches/ipp-20120627/Ohana/src/libdvo/include/dvo.h
===================================================================
--- /branches/eam_branches/ipp-20120627/Ohana/src/libdvo/include/dvo.h	(revision 34139)
+++ /branches/eam_branches/ipp-20120627/Ohana/src/libdvo/include/dvo.h	(revision 34140)
@@ -449,4 +449,5 @@
 float PhotCat (Measure *measure);
 float PhotAper (Measure *measure);
+float PhotKron (Measure *measure);
 float PhotSys (Measure *measure, Average *average, SecFilt *secfilt);
 float PhotRel (Measure *measure, Average *average, SecFilt *secfilt);
@@ -456,4 +457,8 @@
 float PhotXm (PhotCode *code, Average *average, SecFilt *secfilt);
 float PhotdM (PhotCode *code, Average *average, SecFilt *secfilt);
+
+float PhotAperInst (Measure *measure);
+float PhotKronInst (Measure *measure);
+float PhotKronAve (PhotCode *code, Average *average, SecFilt *secfilt);
 
 float PhotMstdev (PhotCode *code, Average *average, SecFilt *secfilt);
Index: /branches/eam_branches/ipp-20120627/Ohana/src/libdvo/include/dvodb.h
===================================================================
--- /branches/eam_branches/ipp-20120627/Ohana/src/libdvo/include/dvodb.h	(revision 34139)
+++ /branches/eam_branches/ipp-20120627/Ohana/src/libdvo/include/dvodb.h	(revision 34140)
@@ -26,4 +26,8 @@
       MAG_CAT, 
       MAG_APER, 
+      MAG_APER_INST, 
+      MAG_KRON, 
+      MAG_KRON_INST, 
+      MAG_KRON_ERR, 
       MAG_SYS, 
       MAG_REL, 
Index: /branches/eam_branches/ipp-20120627/Ohana/src/libdvo/src/dbExtractAverages.c
===================================================================
--- /branches/eam_branches/ipp-20120627/Ohana/src/libdvo/src/dbExtractAverages.c	(revision 34139)
+++ /branches/eam_branches/ipp-20120627/Ohana/src/libdvo/src/dbExtractAverages.c	(revision 34140)
@@ -233,4 +233,8 @@
 	  break;
 
+	case MAG_KRON:
+	  value.Flt = PhotKronAve (field->photcode, average, secfilt);
+	  break;
+
 	case MAG_20:
 	  value.Flt = PhotM20 (field->photcode, average, secfilt);
Index: /branches/eam_branches/ipp-20120627/Ohana/src/libdvo/src/dbExtractMeasures.c
===================================================================
--- /branches/eam_branches/ipp-20120627/Ohana/src/libdvo/src/dbExtractMeasures.c	(revision 34139)
+++ /branches/eam_branches/ipp-20120627/Ohana/src/libdvo/src/dbExtractMeasures.c	(revision 34140)
@@ -117,5 +117,17 @@
 	  break;
 	case MAG_APER:
-	  value.Flt = PhotAper  (measure); 
+	  value.Flt = PhotAper (measure); 
+	  break;
+	case MAG_APER_INST:
+	  value.Flt = PhotAperInst (measure); 
+	  break;
+	case MAG_KRON:
+	  value.Flt = PhotKron (measure); 
+	  break;
+	case MAG_KRON_INST:
+	  value.Flt = PhotKronInst (measure); 
+	  break;
+	case MAG_KRON_ERR:
+	  value.Flt = measure[0].dMkron; 
 	  break;
 	case MAG_ERR:
Index: /branches/eam_branches/ipp-20120627/Ohana/src/libdvo/src/dbFields.c
===================================================================
--- /branches/eam_branches/ipp-20120627/Ohana/src/libdvo/src/dbFields.c	(revision 34139)
+++ /branches/eam_branches/ipp-20120627/Ohana/src/libdvo/src/dbFields.c	(revision 34140)
@@ -39,4 +39,10 @@
   if (!strcasecmp (string, "ap"))        return (MAG_APER);
   if (!strcasecmp (string, "aper"))      return (MAG_APER);
+  if (!strcasecmp (string, "aperinst"))  return (MAG_APER_INST);
+  if (!strcasecmp (string, "aper_inst")) return (MAG_APER_INST);
+  if (!strcasecmp (string, "kron"))      return (MAG_KRON);
+  if (!strcasecmp (string, "kroninst"))  return (MAG_KRON_INST);
+  if (!strcasecmp (string, "kron_inst")) return (MAG_KRON_INST);
+  if (!strcasecmp (string, "kronerr"))   return (MAG_KRON_ERR);
   if (!strcasecmp (string, "err"))       return (MAG_ERR);
   if (!strcasecmp (string, "aveerr"))    return (MAG_AVE_ERR);
Index: /branches/eam_branches/ipp-20120627/Ohana/src/libdvo/src/dvo_photcode_ops.c
===================================================================
--- /branches/eam_branches/ipp-20120627/Ohana/src/libdvo/src/dvo_photcode_ops.c	(revision 34139)
+++ /branches/eam_branches/ipp-20120627/Ohana/src/libdvo/src/dvo_photcode_ops.c	(revision 34140)
@@ -276,4 +276,57 @@
   
   return (Mcat);
+}
+
+float PhotAperInst (Measure *measure) {
+
+  int Np;
+  float Minst;
+
+  Np = photcodes[0].hashcode[measure[0].photcode];
+  if (Np == -1) return (NAN);
+
+  if (photcodes[0].code[Np].type == PHOT_REF) {
+    Minst = measure[0].Map;
+    return (Minst);
+  }
+  Minst = measure[0].Map - measure[0].dt - ZERO_POINT;
+  
+  return (Minst);
+}
+
+float PhotKron (Measure *measure) {
+
+  int Np;
+  float Mcat;
+  PhotCode *code;
+
+  Np = photcodes[0].hashcode[measure[0].photcode];
+  if (Np == -1) return (NAN);
+
+  if (photcodes[0].code[Np].type == PHOT_REF) {
+    Mcat = measure[0].Mkron;
+    return (Mcat);
+  }
+  code = &photcodes[0].code[Np];
+  Mcat = measure[0].Mkron - ZERO_POINT + code[0].K*(measure[0].airmass - 1.000) + SCALE*code[0].C;
+  
+  return (Mcat);
+}
+
+float PhotKronInst (Measure *measure) {
+
+  int Np;
+  float Minst;
+
+  Np = photcodes[0].hashcode[measure[0].photcode];
+  if (Np == -1) return (NAN);
+
+  if (photcodes[0].code[Np].type == PHOT_REF) {
+    Minst = measure[0].Mkron;
+    return (Minst);
+  }
+  Minst = measure[0].Mkron - measure[0].dt - ZERO_POINT;
+  
+  return (Minst);
 }
 
@@ -488,4 +541,16 @@
 }
 
+float PhotKronAve (PhotCode *code, Average *average, SecFilt *secfilt) {
+
+  int Ns;
+  float Mkron;
+
+  if (code == NULL) return NAN;
+
+  Ns = photcodes[0].hashNsec[code[0].code];
+  Mkron = (Ns == -1) ? NAN : secfilt[Ns].Mkron;
+  return (Mkron);
+}
+
 float PhotM20 (PhotCode *code, Average *average, SecFilt *secfilt) {
 
Index: /branches/eam_branches/ipp-20120627/Ohana/src/relphot/src/StarOps.c
===================================================================
--- /branches/eam_branches/ipp-20120627/Ohana/src/relphot/src/StarOps.c	(revision 34139)
+++ /branches/eam_branches/ipp-20120627/Ohana/src/relphot/src/StarOps.c	(revision 34140)
@@ -15,5 +15,6 @@
   double *wlist;
   double *aplist;
-  double *daplist;
+  double *kronlist;
+  double *dkronlist;
 } SetMrelInfo;
 
@@ -164,5 +165,6 @@
   SetMrelInfoInit (&results, TRUE); // allocates results->list,dlist,wlist
   ALLOCATE (results.aplist, double, Nmax);
-  ALLOCATE (results.daplist, double, Nmax);
+  ALLOCATE (results.kronlist, double, Nmax);
+  ALLOCATE (results.dkronlist, double, Nmax);
 
   for (i = 0; i < Ncatalog; i++) {
@@ -174,5 +176,6 @@
   SetMrelInfoFree (&results);
   free (results.aplist);
-  free (results.daplist);
+  free (results.kronlist);
+  free (results.dkronlist);
   return (TRUE);
 }
@@ -307,13 +310,15 @@
   float Msys, Mcal, Mmos, Mgrid;
 
-  StatType stats, apstats;
+  StatType stats, apstats, kronstats;
   liststats_setmode (&stats, STATMODE);
   liststats_setmode (&apstats, STATMODE);
-
-  double *list    = results->list;
-  double *dlist   = results->dlist;
-  double *wlist   = results->wlist;
-  double *aplist  = results->aplist;
-  double *daplist = results->daplist;
+  liststats_setmode (&kronstats, STATMODE);
+
+  double *list      = results->list;
+  double *dlist     = results->dlist;
+  double *wlist     = results->wlist;
+  double *aplist    = results->aplist;
+  double *kronlist  = results->kronlist;
+  double *dkronlist = results->dkronlist;
 
   SetMrelInfoInit (results, FALSE); // do not allocate list,dlist,wlist arrays
@@ -401,4 +406,8 @@
 	  float Map = PhotAper (&catalog[Nc].measure[m]);
 	  aplist[N] = Map - Mcal - Mmos - Mgrid;
+
+	  float Mkron = PhotKron (&catalog[Nc].measure[m]);
+	  kronlist[N] = Mkron - Mcal - Mmos - Mgrid;
+	  dkronlist[N] = catalog[Nc].measure[m].dMkron;
 
 	  // special options for PS1 data
@@ -549,7 +558,10 @@
 
 	// NOTE : use the modified weight for apmags as well as psf mags
-	liststats (aplist, daplist, wlist, N, &apstats);
-
+	liststats (aplist, dlist, wlist, N, &apstats);
 	catalog[Nc].secfilt[Nsecfilt*j+Nsec].Map  = apstats.mean; 
+
+	liststats (kronlist, dkronlist, wlist, N, &kronstats);
+	catalog[Nc].secfilt[Nsecfilt*j+Nsec].Mkron  = kronstats.mean; 
+	catalog[Nc].secfilt[Nsecfilt*j+Nsec].dMkron = kronstats.error; 
 
 	// NOTE: for 2MASS measurements, Next should be 1, as should N
