Index: /branches/eam_branches/ipp-20140610/Ohana/src/addstar/src/FilterStars.c
===================================================================
--- /branches/eam_branches/ipp-20140610/Ohana/src/addstar/src/FilterStars.c	(revision 36911)
+++ /branches/eam_branches/ipp-20140610/Ohana/src/addstar/src/FilterStars.c	(revision 36912)
@@ -99,4 +99,10 @@
       stars[N].measure.dFluxKron /= image[0].exptime;
     }
+    if (!isnan(stars[N].measure.FluxAp)) {
+      stars[N].measure.FluxAp /= image[0].exptime;
+    }
+    if (!isnan(stars[N].measure.dFluxAp)) {
+      stars[N].measure.dFluxAp /= image[0].exptime;
+    }
     
     // the external ID is supplied, but do we trust it?
Index: /branches/eam_branches/ipp-20140610/Ohana/src/addstar/src/MatchHeaders.c
===================================================================
--- /branches/eam_branches/ipp-20140610/Ohana/src/addstar/src/MatchHeaders.c	(revision 36911)
+++ /branches/eam_branches/ipp-20140610/Ohana/src/addstar/src/MatchHeaders.c	(revision 36912)
@@ -59,7 +59,10 @@
     if (!strcmp (exttype, "PS1_V3")) goto keep;
     if (!strcmp (exttype, "PS1_V4")) goto keep;
+    if (!strcmp (exttype, "PS1_V5")) goto keep;
     if (!strcmp (exttype, "PS1_SV1")) goto keep;
     if (!strcmp (exttype, "PS1_SV2")) goto keep;
-    if (!strcmp (exttype, "PS1_DV3")) {
+    if (!strcmp (exttype, "PS1_SV3")) goto keep;
+    if (!strcmp (exttype, "PS1_DV3")) goto keep;
+    if (!strcmp (exttype, "PS1_DV4")) {
       goto keep;
     }
Index: /branches/eam_branches/ipp-20140610/Ohana/src/addstar/src/ReadStarsFITS.c
===================================================================
--- /branches/eam_branches/ipp-20140610/Ohana/src/addstar/src/ReadStarsFITS.c	(revision 36911)
+++ /branches/eam_branches/ipp-20140610/Ohana/src/addstar/src/ReadStarsFITS.c	(revision 36912)
@@ -12,8 +12,11 @@
 Stars     *Convert_PS1_V3	  PROTO((FTable *table, unsigned int *nstars));
 Stars     *Convert_PS1_V4	  PROTO((FTable *table, unsigned int *nstars));
+Stars     *Convert_PS1_V5	  PROTO((FTable *table, unsigned int *nstars));
 Stars     *Convert_PS1_SV1	  PROTO((FTable *table, unsigned int *nstars));
 Stars     *Convert_PS1_SV1_Alt	  PROTO((FTable *table, unsigned int *nstars));
 Stars     *Convert_PS1_SV2	  PROTO((FTable *table, unsigned int *nstars));
+Stars     *Convert_PS1_SV3	  PROTO((FTable *table, unsigned int *nstars));
 Stars     *Convert_PS1_DV3        PROTO((FTable *table, unsigned int *nstars));
+Stars     *Convert_PS1_DV4        PROTO((FTable *table, unsigned int *nstars));
 
 // given a file with the pointer at the start of the table block and the 
@@ -73,4 +76,7 @@
     stars = Convert_PS1_V4 (&table, &Nstars);
   }
+  if (!strcmp (type, "PS1_V5")) {
+    stars = Convert_PS1_V5 (&table, &Nstars);
+  }
   if (!strcmp (type, "PS1_SV1")) {
     stars = Convert_PS1_SV1 (&table, &Nstars);
@@ -79,6 +85,12 @@
     stars = Convert_PS1_SV2 (&table, &Nstars);
   }
+  if (!strcmp (type, "PS1_SV3")) {
+    stars = Convert_PS1_SV3 (&table, &Nstars);
+  }
   if (!strcmp (type, "PS1_DV3")) {
     stars = Convert_PS1_DV3 (&table, &Nstars);
+  }
+  if (!strcmp (type, "PS1_DV4")) {
+    stars = Convert_PS1_DV4 (&table, &Nstars);
   }
   if (stars == NULL) {
@@ -724,4 +736,90 @@
 }
 
+Stars *Convert_PS1_V5 (FTable *table, unsigned int *nstars) {
+
+  off_t Nstars; 
+  unsigned int i;
+  double ZeroPt;
+  Stars *stars;
+  CMF_PS1_V5 *ps1data;
+
+  ps1data = gfits_table_get_CMF_PS1_V5 (table, &Nstars, NULL);
+  if (!ps1data) {
+    fprintf (stderr, "skipping inconsistent entry\n");
+    return (NULL);
+  }
+  ZeroPt = GetZeroPoint();
+
+  ALLOCATE (stars, Stars, Nstars);
+  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.posangle   = ToShortDegrees(ps1data[i].posangle);
+    stars[i].measure.pltscale   = ps1data[i].pltscale;
+
+    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.dM         = ps1data[i].dM;
+    stars[i].measure.dMcal      = ps1data[i].dMcal;
+    stars[i].measure.Map        = ps1data[i].Map + ZeroPt;
+    stars[i].measure.dMap       = (ps1data[i].apFlux > 0.0) ? fabs(ps1data[i].apFluxErr / ps1data[i].apFlux) : NAN;
+                        
+    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;
+                        
+    // instrumental fluxes: these fluxes are converted from counts to counts/sec in
+    // FilterStars.c
+    stars[i].measure.FluxPSF    = ps1data[i].Flux;
+    stars[i].measure.dFluxPSF   = ps1data[i].dFlux;
+    stars[i].measure.FluxKron   = ps1data[i].kronFlux;
+    stars[i].measure.dFluxKron  = ps1data[i].kronFluxErr;
+    stars[i].measure.FluxAp     = ps1data[i].apFlux;
+    stars[i].measure.dFluxAp    = ps1data[i].apFluxErr;
+
+    stars[i].measure.Sky        = ps1data[i].sky;
+    stars[i].measure.dSky       = ps1data[i].dSky;
+                        
+    stars[i].measure.psfChisq   = ps1data[i].psfChisq;
+    stars[i].measure.psfQF      = ps1data[i].psfQF;
+    stars[i].measure.psfQFperf  = ps1data[i].psfQFperf;
+
+    stars[i].measure.psfNdof    = ps1data[i].psfNdof;
+    stars[i].measure.psfNpix    = ps1data[i].psfNpix;
+    stars[i].measure.crNsigma   = ps1data[i].crNsigma;
+    stars[i].measure.extNsigma  = ps1data[i].extNsigma;
+
+    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        = ToShortPixels(ps1data[i].Mxx);
+    stars[i].measure.Mxy        = ToShortPixels(ps1data[i].Mxy);
+    stars[i].measure.Myy        = ToShortPixels(ps1data[i].Myy);
+                        
+    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; 
+
+    // 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 following fields are currently not being set anywhere: t_msec
+  }    
+  *nstars = Nstars;
+  return (stars);
+}
+
 Stars *Convert_PS1_SV1 (FTable *table, unsigned int *nstars) {
 
@@ -901,4 +999,85 @@
   }
   ZeroPt = GetZeroPoint();
+
+  ALLOCATE (stars, Stars, Nstars);
+  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.posangle   = ToShortDegrees(ps1data[i].posangle);
+    stars[i].measure.pltscale   = ps1data[i].pltscale;
+
+    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.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;
+
+    // these fluxes are converted from counts to counts/sec in FilterStars.c
+    stars[i].measure.FluxPSF    = ps1data[i].Flux;
+    stars[i].measure.dFluxPSF   = ps1data[i].dFlux;
+    stars[i].measure.FluxKron   = ps1data[i].kronFlux;
+    stars[i].measure.dFluxKron  = ps1data[i].kronFluxErr;
+
+    stars[i].measure.Sky        = ps1data[i].sky;
+    stars[i].measure.dSky       = ps1data[i].dSky;
+                        
+    stars[i].measure.psfChisq   = ps1data[i].psfChisq;
+    stars[i].measure.psfQF      = ps1data[i].psfQF;
+    stars[i].measure.psfQFperf  = ps1data[i].psfQFperf;
+
+    stars[i].measure.psfNdof    = ps1data[i].psfNdof;
+    stars[i].measure.psfNpix    = ps1data[i].psfNpix;
+    stars[i].measure.crNsigma   = ps1data[i].crNsigma;
+    stars[i].measure.extNsigma  = ps1data[i].extNsigma;
+
+    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        = ToShortPixels(ps1data[i].Mxx);
+    stars[i].measure.Mxy        = ToShortPixels(ps1data[i].Mxy);
+    stars[i].measure.Myy        = ToShortPixels(ps1data[i].Myy);
+                        
+    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; 
+
+    // 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 following fields are currently not being set anywhere: t_msec
+  }    
+  *nstars = Nstars;
+  return (stars);
+}
+
+Stars *Convert_PS1_SV3 (FTable *table, unsigned int *nstars) {
+
+  off_t Nstars; 
+  unsigned int i;
+  double ZeroPt;
+  Stars *stars;
+  CMF_PS1_SV3 *ps1data;
+
+  ps1data = gfits_table_get_CMF_PS1_SV3 (table, &Nstars, NULL);
+  if (!ps1data) {
+    fprintf (stderr, "skipping inconsistent entry\n");
+    return (NULL);
+  }
+  ZeroPt = GetZeroPoint();
+
+  fprintf (stderr, "WARNING: Convert_PS1_SV3 not yet updated to match real format\n");
 
   ALLOCATE (stars, Stars, Nstars);
@@ -1047,4 +1226,87 @@
 }
 
-
-
+Stars *Convert_PS1_DV4 (FTable *table, unsigned int *nstars) {
+
+  off_t Nstars; 
+  unsigned int i;
+  double ZeroPt;
+  Stars *stars;
+  CMF_PS1_DV4 *ps1data;
+
+  ps1data = gfits_table_get_CMF_PS1_DV4 (table, &Nstars, NULL);
+  if (!ps1data) {
+    fprintf (stderr, "skipping inconsistent entry\n");
+    return (NULL);
+  }
+  ZeroPt = GetZeroPoint();
+
+  fprintf (stderr, "WARNING: Convert_PS1_DV4 not yet updated to match real format\n");
+
+  ALLOCATE (stars, Stars, Nstars);
+  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.posangle   = ToShortDegrees(ps1data[i].posangle);
+    stars[i].measure.pltscale   = ps1data[i].pltscale;
+
+    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.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;
+                        
+    // these fluxes are converted from counts to counts/sec in FilterStars.c
+    stars[i].measure.FluxPSF    = ps1data[i].Flux;
+    stars[i].measure.dFluxPSF   = ps1data[i].dFlux;
+    stars[i].measure.FluxKron   = ps1data[i].kronFlux;
+    stars[i].measure.dFluxKron  = ps1data[i].kronFluxErr;
+
+    stars[i].measure.Sky        = ps1data[i].sky;
+    stars[i].measure.dSky       = ps1data[i].dSky;
+                        
+    stars[i].measure.psfChisq   = ps1data[i].psfChisq;
+    stars[i].measure.psfQF      = ps1data[i].psfQF;
+    stars[i].measure.psfQFperf  = ps1data[i].psfQFperf;
+    stars[i].measure.psfNdof    = ps1data[i].psfNdof;
+    stars[i].measure.psfNpix    = ps1data[i].psfNpix;
+    stars[i].measure.crNsigma   = ps1data[i].crNsigma;
+    stars[i].measure.extNsigma  = ps1data[i].extNsigma;
+
+    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        = ToShortPixels(ps1data[i].Mxx);
+    stars[i].measure.Mxy        = ToShortPixels(ps1data[i].Mxy);
+    stars[i].measure.Myy        = ToShortPixels(ps1data[i].Myy);
+                        
+    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; 
+
+    // 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 following fields are currently not being set anywhere: t_msec
+  }    
+  *nstars = Nstars;
+  return (stars);
+}
+
+
+
Index: /branches/eam_branches/ipp-20140610/Ohana/src/addstar/src/mkcmf.c
===================================================================
--- /branches/eam_branches/ipp-20140610/Ohana/src/addstar/src/mkcmf.c	(revision 36911)
+++ /branches/eam_branches/ipp-20140610/Ohana/src/addstar/src/mkcmf.c	(revision 36912)
@@ -811,6 +811,4 @@
     stars[i].dMcal = 0.05;
 
-    stars[i].dMcal = 0.05;
-
     XY_to_RD (&stars[i].RA, &stars[i].DEC, X[i], Y[i], &coords);
     stars[i].apNpix = 3.14*8.0*8.0;
@@ -870,5 +868,9 @@
       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);
+      float Moff = fSN*rnd_gauss(0.0, 1.0);
+      stars[i].M += Moff;
+      stars[i].Map += Moff;
+      stars[i].MapRaw += Moff;
+      stars[i].Mcalib += Moff;
     }
   }
Index: /branches/eam_branches/ipp-20140610/Ohana/src/addstar/test/simple.dvo
===================================================================
--- /branches/eam_branches/ipp-20140610/Ohana/src/addstar/test/simple.dvo	(revision 36911)
+++ /branches/eam_branches/ipp-20140610/Ohana/src/addstar/test/simple.dvo	(revision 36912)
@@ -34,4 +34,8 @@
 end  
 
+if (not($?NO_NOISE)) 
+  $NO_NOISE = ""
+end
+
 # create a populated catdir with a single cmf -- test each field
 macro test.fields
@@ -50,10 +54,11 @@
 
   mkinput
-  echo mkcmf test.in.txt test.cmf -date 2008/1/1 -time 01:00:00 -radec $RA $DEC -type $1
-  exec mkcmf test.in.txt test.cmf -date 2008/1/1 -time 01:00:00 -radec $RA $DEC -type $1
+  echo mkcmf test.in.txt test.cmf -date 2008/1/1 -time 01:00:00 -radec $RA $DEC -type $1 $NO_NOISE
+  exec mkcmf test.in.txt test.cmf -date 2008/1/1 -time 01:00:00 -radec $RA $DEC -type $1 $NO_NOISE
   if ($TAP_VERBOSE)
     echo exec addstar -D CATDIR catdir.test -D CAMERA simtest test.cmf -D CATFORMAT $2 -quick-airmass
     exec addstar -D CATDIR catdir.test -D CAMERA simtest test.cmf -D CATFORMAT $2 -quick-airmass
   else
+    echo addstar -D CATDIR catdir.test -D CAMERA simtest test.cmf -D CATFORMAT $2 -quick-airmass
     exec addstar -D CATDIR catdir.test -D CAMERA simtest test.cmf -D CATFORMAT $2 -quick-airmass >& tmp.log
   end
@@ -113,9 +118,17 @@
 
     # 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
+    ## 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
+    if (("$name:0" == "X_PSF_SIG") || ("$name:0" == "Y_PSF_SIG"))
+     set v1 = int(100*(v1))
+     set v2 = int(100*(v2 + 0.0001))
+    end
+    if ("$name:0" == "POSANGLE")
+     set v1 = int((0xffff/360.0)*(v1))
+     set v2 = int((0xffff/360.0)*(v2 + 0.0028))
     end
 
@@ -335,5 +348,5 @@
   Y_PSF_SIG         : yccd:err
   POSANGLE          : posangle
-  PLTSCALE          : pltscale
+  PLTSCALE          : platescale
   PSF_INST_MAG      : mag:inst  
   PSF_INST_MAG_SIG  : mag:err   
@@ -345,6 +358,6 @@
   AP_FLUX           : flux:aper:inst  
   AP_FLUX_SIG       : flux:aper:inst:err
-  CAL_PSF_MAG       : mag:rel
-  CAL_PSF_MAG_SIG   : mag:rel:err
+  CAL_PSF_MAG       : mag:cal
+  CAL_PSF_MAG_SIG   : mag:cal:err
   RA_PSF            : ra
   DEC_PSF           : dec
@@ -386,49 +399,2 @@
   N_FRAMES          : SKIP # not ingested into DVO		      
 end								      
-
-  
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
Index: /branches/eam_branches/ipp-20140610/Ohana/src/libautocode/Makefile.Targets
===================================================================
--- /branches/eam_branches/ipp-20140610/Ohana/src/libautocode/Makefile.Targets	(revision 36911)
+++ /branches/eam_branches/ipp-20140610/Ohana/src/libautocode/Makefile.Targets	(revision 36912)
@@ -80,7 +80,8 @@
 $(ASRC)/cmf-ps1-v3.$(ARCH).o \
 $(ASRC)/cmf-ps1-v4.$(ARCH).o \
-$(ASRC)/cmf-ps1-v5.$(ARCH).o \
 $(ASRC)/cmf-ps1-sv1.$(ARCH).o \
 $(ASRC)/cmf-ps1-sv2.$(ARCH).o \
+$(ASRC)/cmf-ps1-sv3.$(ARCH).o \
+$(ASRC)/cmf-ps1-dv4.$(ARCH).o \
 $(ASRC)/cmf-smpdata.$(ARCH).o \
 $(ASRC)/getstar-ps1-dev-0.$(ARCH).o \
@@ -176,7 +177,8 @@
 $(AINC)/cmf-ps1-v3.h \
 $(AINC)/cmf-ps1-v4.h \
-$(AINC)/cmf-ps1-v5.h \
 $(AINC)/cmf-ps1-sv1.h \
 $(AINC)/cmf-ps1-sv2.h \
+$(AINC)/cmf-ps1-sv3.h \
+$(AINC)/cmf-ps1-dv4.h \
 $(AINC)/cmf-smpdata.h \
 $(AINC)/getstar-ps1-dev-0.h \
Index: /branches/eam_branches/ipp-20140610/Ohana/src/libautocode/def/cmf-ps1-dv4.d
===================================================================
--- /branches/eam_branches/ipp-20140610/Ohana/src/libautocode/def/cmf-ps1-dv4.d	(revision 36912)
+++ /branches/eam_branches/ipp-20140610/Ohana/src/libautocode/def/cmf-ps1-dv4.d	(revision 36912)
@@ -0,0 +1,65 @@
+# name of structure type
+STRUCT  CMF_PS1_DV4
+EXTNAME CMF_PS1_DV4
+TYPE    BINTABLE
+SIZE    224
+
+# elements of data structure / FITS table
+FIELD detID,          IPP_IDET,          unsigned int, detection ID                     
+FIELD X,              X_PSF,             float,    x coord,               pixels
+FIELD Y,              Y_PSF,             float,    y coord,               pixels
+FIELD dX,             X_PSF_SIG,         float,    x coord error,         pixels
+FIELD dY,             Y_PSF_SIG,         float,    y coord error,         pixels
+FIELD posangle,       POSANGLE,          float,    Posangle at source,    degrees
+FIELD pltscale,       PLTSCALE,          float,    Plate Scale at source, arcsec/pixel
+FIELD M,              PSF_INST_MAG,      float,    inst mags,             mags
+FIELD dM,             PSF_INST_MAG_SIG,  float,    inst mag error,        mags
+FIELD Flux,           PSF_INST_FLUX,     float,    psf flux,	       counts
+FIELD dFlux,          PSF_INST_FLUX_SIG, float,    psf flux error,        counts      
+FIELD Map,            AP_MAG,   	 float,    standard aperture mag, mags
+FIELD MapRaw,         AP_MAG_RAW,        float,    raw aperture mag,      mags
+FIELD apRadius,       AP_MAG_RADIUS,     float,    radius used for fit,   pixels
+FIELD apFlux,         AP_FLUX,           float,    ap flux
+FIELD apFluxErr,      AP_FLUX_SIG,       float,    ap flux err
+FIELD Mpeak,          PEAK_FLUX_AS_MAG,  float,    peak flux as a mag,    mags
+FIELD Mcalib,         CAL_PSF_MAG,       float,    calibrated psf mag,    mags
+FIELD dMcal,          CAL_PSF_MAG_SIG,   float,    zero point scatter,    mags
+
+# NOTE: RA & DEC (both double) need to be on an 8-byte boundary...
+FIELD RA,             RA_PSF,            double,   PSF RA coord,          degrees
+FIELD DEC,            DEC_PSF,           double,   PSF DEC coord,         degrees
+
+FIELD sky,            SKY,               float,    sky flux,              cnts/sec
+FIELD dSky,           SKY_SIGMA,         float,    sky flux error,        cnts/sec
+FIELD psfChisq,       PSF_CHISQ,         float,    psf fit chisq
+FIELD crNsigma,       CR_NSIGMA,         float,    Nsigma deviations from PSF to CF
+FIELD extNsigma,      EXT_NSIGMA,        float,    Nsigma deviations from PSF to EXT
+FIELD fx,             PSF_MAJOR,         float,    psf fit major axis,    pixels
+FIELD fy,             PSF_MINOR,         float,    psf fit minor axis,    pixels
+FIELD df,             PSF_THETA,         float,    ellipse angle,         degrees
+FIELD psfQF,          PSF_QF,            float,    quality factor
+FIELD psfQFperf,      PSF_QF_PERFECT,    float,    quality factor perfect
+FIELD psfNdof,        PSF_NDOF,          int,      psf degrees of freedom
+FIELD psfNpix,        PSF_NPIX,          int,      psf number of pixels
+FIELD Mxx,            MOMENTS_XX,        float,    second moment X,       pixels^2
+FIELD Mxy,            MOMENTS_XY,        float,    second moment Y,       pixels^2
+FIELD Myy,            MOMENTS_YY,        float,    second moment XY,      pixels^2
+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 D_Npos,         DIFF_NPOS,         int,      diff param
+FIELD D_Fratio,       DIFF_FRATIO,       float,    diff param
+FIELD D_Nratio_bad,   DIFF_NRATIO_BAD,   float,    diff param
+FIELD D_Nratio_mask,  DIFF_NRATIO_MASK,  float,    diff param
+FIELD D_Nratio_all,   DIFF_NRATIO_ALL,   float,    diff param
+FIELD D_Rp,           DIFF_R_P,          float,    diff param
+FIELD D_SNp,          DIFF_SN_P,         float,    diff param
+FIELD D_Rm,           DIFF_R_M,          float,    diff param
+FIELD D_SNm,          DIFF_SN_M,         float,    diff param
+FIELD flags,          FLAGS,             int,      analysis flags
+FIELD flags2,         FLAGS2,            int,      analysis flags (2)
+FIELD nFrames,        N_FRAMES,          short,    images overlapping peak
+FIELD padding,        PADDING,           short,    padding for 8byte records
Index: /branches/eam_branches/ipp-20140610/Ohana/src/libautocode/def/cmf-ps1-sv3.d
===================================================================
--- /branches/eam_branches/ipp-20140610/Ohana/src/libautocode/def/cmf-ps1-sv3.d	(revision 36912)
+++ /branches/eam_branches/ipp-20140610/Ohana/src/libautocode/def/cmf-ps1-sv3.d	(revision 36912)
@@ -0,0 +1,140 @@
+# name of structure type
+STRUCT  CMF_PS1_SV3
+EXTNAME CMF_PS1_SV3
+TYPE    BINTABLE
+SIZE    208
+
+## note that this definition is inconsistent with the definition in
+## pmModules/src/objects/pmSourceIO_CMF.c.in.  The version in
+## pmSourceIO*.c creates a table with data not properly aligned with
+## the 8-byte boundaries. The structure defined by libautocode does
+## this, but has a different order of elements (and adds padding2 to
+## fix things). We have generated may files with PS1_SV1 as is, so
+## I'll leave it. But in future a PS1_SV2 should be forced to match
+## libautocode. Note that addstar knows to detect the alternate
+## version of PS1_SV1 and correctly interpret its fields.
+
+# elements of data structure / FITS table
+FIELD detID,          IPP_IDET,          unsigned int, detection ID                     
+FIELD X,              X_PSF,             float,    x coord,               pixels
+FIELD Y,              Y_PSF,             float,    y coord,               pixels
+FIELD dX,             X_PSF_SIG,         float,    x coord error,         pixels
+
+FIELD dY,             Y_PSF_SIG,         float,    y coord error,         pixels
+FIELD posangle,       POSANGLE,          float,    Posangle at source,    degrees
+FIELD pltscale,       PLTSCALE,          float,    Plate Scale at source, arcsec/pixel
+FIELD M,              PSF_INST_MAG,      float,    inst mags,             mags
+
+FIELD dM,             PSF_INST_MAG_SIG,  float,    inst mag error,        mags
+FIELD Flux,           PSF_INST_FLUX,     float,    psf flux,	       counts
+FIELD dFlux,          PSF_INST_FLUX_SIG, float,    psf flux error,        counts      
+FIELD Map,            AP_MAG,   	 float,    standard aperture mag, mags
+
+FIELD MapRaw,         AP_MAG_RAW,        float,    raw aperture mag,      mags
+FIELD apRadius,       AP_MAG_RADIUS,     float,    radius used for fit,   pixels
+FIELD apFlux,         AP_FLUX,           float,    aperture flux,         counts
+FIELD apFluxErr,      AP_FLUX_SIG,       float,    error on ap flux,      counts
+
+FIELD Mcalib,         CAL_PSF_MAG,       float,    calibrated psf mag,    mags
+FIELD dMcal,          CAL_PSF_MAG_SIG,   float,    zero point scatter,    mags
+
+# NOTE: RA & DEC (both double) need to be on an 8-byte boundary...
+FIELD RA,             RA_PSF,            double,   PSF RA coord,          degrees
+FIELD DEC,            DEC_PSF,           double,   PSF DEC coord,         degrees
+
+FIELD Mpeak,          PEAK_FLUX_AS_MAG,  float,    peak flux as a mag,    mags
+FIELD sky,            SKY,               float,    sky flux,              cnts/sec
+FIELD dSky,           SKY_SIG,           float,    sky flux error,        cnts/sec
+FIELD psfChisq,       PSF_CHISQ,         float,    psf fit chisq
+
+FIELD crNsigma,       CR_NSIGMA,         float,    Nsigma deviations from PSF to CF
+FIELD extNsigma,      EXT_NSIGMA,        float,    Nsigma deviations from PSF to EXT
+FIELD fx,             PSF_MAJOR,         float,    psf fit major axis,    pixels
+FIELD fy,             PSF_MINOR,         float,    psf fit minor axis,    pixels
+
+FIELD df,             PSF_THETA,         float,    ellipse angle,         degrees
+FIELD psfQF,          PSF_QF,            float,    quality factor
+FIELD psfQFperf,      PSF_QF_PERFECT,    float,    quality factor perfect
+FIELD psfNdof,        PSF_NDOF,          int,      psf degrees of freedom
+
+FIELD psfNpix,        PSF_NPIX,          int,      psf number of pixels
+FIELD Mxx,            MOMENTS_XX,        float,    second moment X,       pixels^2
+FIELD Mxy,            MOMENTS_XY,        float,    second moment Y,       pixels^2
+FIELD Myy,            MOMENTS_YY,        float,    second moment XY,      pixels^2
+
+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 flags,          FLAGS,             int,      analysis flags
+FIELD flags2,         FLAGS2,            int,      analysis flags (2)
+
+FIELD padding2,       PADDING2,          int,      padding for 8byte records
+FIELD nFrames,        N_FRAMES,          short,    images overlapping peak
+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
+
+# # 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 psfQF,          PSF_QF,            PSF_QF             1E      float,    quality factor
+# FIELD psfQFperf,      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
+
+      
+
Index: /branches/eam_branches/ipp-20140610/Ohana/src/libautocode/def/cmf-ps1-v5.d
===================================================================
--- /branches/eam_branches/ipp-20140610/Ohana/src/libautocode/def/cmf-ps1-v5.d	(revision 36911)
+++ /branches/eam_branches/ipp-20140610/Ohana/src/libautocode/def/cmf-ps1-v5.d	(revision 36912)
@@ -22,6 +22,11 @@
 FIELD apFlux,         AP_FLUX,           float,    aperture flux,         counts
 FIELD apFluxErr,      AP_FLUX_SIG,       float,    error on ap flux,      counts
+FIELD apNpix,         AP_NPIX,           int,      pixels used by aper,   pixels
 FIELD Mcalib,         CAL_PSF_MAG,       float,    calibrated psf mag,    mags
 FIELD dMcal,          CAL_PSF_MAG_SIG,   float,    zero point scatter,    mags
+
+# this field is in the wrong order (is between DEC and sky in cmf, but breaks byte boundary).
+# I need to move these bytes around on read (fix PS1_V5?)
+FIELD Mpeak,          PEAK_FLUX_AS_MAG,  float,    peak flux as a mag,    mags
 
 # NOTE: RA & DEC (both double) need to be on an 8-byte boundary...
@@ -29,9 +34,4 @@
 FIELD DEC,            DEC_PSF,           double,   PSF DEC coord,         degrees
 
-# this field is in the wrong order (between apFluxErr and Mcalib in cmf, but breaks byte boundary).
-# I need to move these bytes around on read (fix PS1_V5?)
-FIELD apNpix,         AP_NPIX,           int,      pixels used by aper,   pixels
-
-FIELD Mpeak,          PEAK_FLUX_AS_MAG,  float,    peak flux as a mag,    mags
 FIELD sky,            SKY,               float,    sky flux,              cnts/sec
 FIELD dSky,           SKY_SIGMA,         float,    sky flux error,        cnts/sec
Index: /branches/eam_branches/ipp-20140610/Ohana/src/libdvo/Makefile
===================================================================
--- /branches/eam_branches/ipp-20140610/Ohana/src/libdvo/Makefile	(revision 36911)
+++ /branches/eam_branches/ipp-20140610/Ohana/src/libdvo/Makefile	(revision 36912)
@@ -38,5 +38,6 @@
 $(DESTINC)/ps1_v5_defs.h \
 $(DESTINC)/ps1_ref_defs.h \
-$(DESTINC)/cmf-ps1-dv3.h
+$(DESTINC)/cmf-ps1-dv3.h \
+$(DESTINC)/cmf-ps1-v5.h
 
 INCS = $(DEFS) $(DESTINC)/dvo.h $(DESTINC)/autocode.h $(DESTINC)/dvo_util.h $(DESTINC)/dvodb.h $(DESTINC)/libdvo_astro.h $(DESTINC)/convert.h $(DESTINC)/get_graphdata.h
@@ -88,4 +89,5 @@
 $(SRC)/cmf-ps1-sv1-alt.$(ARCH).o \
 $(SRC)/cmf-ps1-dv3.$(ARCH).o \
+$(SRC)/cmf-ps1-v5.$(ARCH).o \
 $(SRC)/dvo_util.$(ARCH).o \
 $(SRC)/dbBooleanCond.$(ARCH).o		\
Index: /branches/eam_branches/ipp-20140610/Ohana/src/libdvo/include/cmf-ps1-v5.h
===================================================================
--- /branches/eam_branches/ipp-20140610/Ohana/src/libdvo/include/cmf-ps1-v5.h	(revision 36912)
+++ /branches/eam_branches/ipp-20140610/Ohana/src/libdvo/include/cmf-ps1-v5.h	(revision 36912)
@@ -0,0 +1,68 @@
+
+/** STRUCT DEFINITION **/
+typedef struct {
+  unsigned int     detID;                // detection ID                     
+  float            X;                    // x coord (pixels)
+  float            Y;                    // y coord (pixels)
+  float            dX;                   // x coord error (pixels)
+  float            dY;                   // y coord error (pixels)
+  float            posangle;             // Posangle at source (degrees)
+  float            pltscale;             // Plate Scale at source (arcsec/pixel)
+  float            M;                    // inst mags (mags)
+  float            dM;                   // inst mag error (mags)
+  float            Flux;                 // psf flux (counts)
+  float            dFlux;                // psf flux error (counts      )
+  float            Map;                  // standard aperture mag (mags)
+  float            MapRaw;               // raw aperture mag (mags)
+  float            apRadius;             // radius used for aper (pixels)
+  float            apFlux;               // aperture flux (counts)
+  float            apFluxErr;            // error on ap flux (counts)
+  int              apNpix;               // pixels used by aper (pixels)
+  float            Mcalib;               // calibrated psf mag (mags)
+  float            dMcal;                // zero point scatter (mags)
+  float            Mpeak;                // peak flux as a mag (mags)
+  double           RA;                   // PSF RA coord (degrees)
+  double           DEC;                  // PSF DEC coord (degrees)
+  float            sky;                  // sky flux (cnts/sec)
+  float            dSky;                 // sky flux error (cnts/sec)
+  float            psfChisq;             // psf fit chisq
+  float            crNsigma;             // Nsigma deviations from PSF to CF
+  float            extNsigma;            // Nsigma deviations from PSF to EXT
+  float            fx;                   // psf fit major axis (pixels)
+  float            fy;                   // psf fit minor axis (pixels)
+  float            df;                   // ellipse angle (degrees)
+  float            k;                    // extra PSF parameter (unitless)
+  float            fwhmMaj;              // true fwhm of psf (pixels)
+  float            fwhmMin;              // true fwhm (minor) (pixels)
+  float            psfQF;                // quality factor
+  float            psfQFperf;            // quality factor perfect
+  int              psfNdof;              // psf degrees of freedom
+  int              psfNpix;              // psf number of pixels
+  float            Mxx;                  // second moment X (pixels^2)
+  float            Mxy;                  // second moment Y (pixels^2)
+  float            Myy;                  // second moment XY (pixels^2)
+  float            M3c;                  // third moment cos(t) (pixels^3)
+  float            M3s;                  // third moment sin(t) (pixels^3)
+  float            M4c;                  // fourth moment cos(t) (pixels^4)
+  float            M4s;                  // fourth moment sin(t) (pixels^4)
+  float            Mr1;                  // first radial moment (pixels)
+  float            Mrh;                  // half radial moment (pixels^1/2)
+  float            kronFlux;             // kron flux (counts)
+  float            kronFluxErr;          // kron flux error (counts)
+  float            kronInner;            // kron flux 1<R<2.5 (counts)
+  float            kronOuter;            // kron flux 2.5<R<4 (counts)
+  float            skyLimitRad;          // profile to sky limit (radius)
+  float            skyLimitFlux;         // profile to sky limit (flux)
+  float            skyLimitSlope;        // profile to sky limit (slope)
+  int              flags;                // analysis flags
+  int              flags2;               // analysis flags (2)
+  short            nFrames;              // images overlapping peak
+  short            padding;              // padding for 8byte records
+} CMF_PS1_V5;
+
+CMF_PS1_V5 *gfits_table_get_CMF_PS1_V5 (FTable *table, off_t *Ndata, char *swapped);
+int      gfits_table_set_CMF_PS1_V5 (FTable *ftable, CMF_PS1_V5 *data, off_t Ndata);
+int      gfits_table_mkheader_CMF_PS1_V5 (Header *header);
+int      gfits_convert_CMF_PS1_V5 (unsigned char *data, off_t size, off_t nitems, char toStruct);
+int      Send_CMF_PS1_V5 (int device, CMF_PS1_V5 *data, int Ndata, int copy);
+int      Recv_CMF_PS1_V5 (int device, CMF_PS1_V5 **data, int *Ndata);
Index: /branches/eam_branches/ipp-20140610/Ohana/src/libdvo/include/dvo.h
===================================================================
--- /branches/eam_branches/ipp-20140610/Ohana/src/libdvo/include/dvo.h	(revision 36911)
+++ /branches/eam_branches/ipp-20140610/Ohana/src/libdvo/include/dvo.h	(revision 36912)
@@ -335,4 +335,5 @@
 // another special case : does not match byte-boundaries
 # include "cmf-ps1-dv3.h"
+# include "cmf-ps1-v5.h"
 
 typedef struct {
@@ -668,4 +669,5 @@
 float PhotCal (Measure *thisone, Average *average, SecFilt *secfilt, Measure *measure, PhotCode *code, dvoMagClassType class);
 float PhotErr (Measure *measure, dvoMagClassType class);
+float PhotCalErr (Measure *measure, dvoMagClassType class);
 
 float PhotAve (PhotCode *code, Average *average, SecFilt *secfilt, dvoMagClassType class, dvoMagSourceType source);
@@ -690,4 +692,7 @@
 float PhotFluxAve (PhotCode *code, Average *average, SecFilt *secfilt, dvoMagClassType class, dvoMagSourceType source);
 float PhotFluxRef (PhotCode *code, Average *average, SecFilt *secfilt, Measure *measure, dvoMagClassType class, dvoMagSourceType source);
+
+float PhotFluxInstErr (Measure *measure, dvoMagClassType class);
+float PhotFluxCatErr (Measure *measure, dvoMagClassType class);
 
 float PhotXm (PhotCode *code, Average *average, SecFilt *secfilt);
Index: /branches/eam_branches/ipp-20140610/Ohana/src/libdvo/src/cmf-ps1-dv3.c
===================================================================
--- /branches/eam_branches/ipp-20140610/Ohana/src/libdvo/src/cmf-ps1-dv3.c	(revision 36911)
+++ /branches/eam_branches/ipp-20140610/Ohana/src/libdvo/src/cmf-ps1-dv3.c	(revision 36912)
@@ -2,5 +2,5 @@
 
 /*** note : this file is derived from the autocode version, but is modified because
-     the forma does not match with structure byte boundaries ***/
+     the format does not match with structure byte boundaries ***/
 
 /* if we are not correctly including the ohana headers, this will fail */
Index: /branches/eam_branches/ipp-20140610/Ohana/src/libdvo/src/cmf-ps1-v5.c
===================================================================
--- /branches/eam_branches/ipp-20140610/Ohana/src/libdvo/src/cmf-ps1-v5.c	(revision 36912)
+++ /branches/eam_branches/ipp-20140610/Ohana/src/libdvo/src/cmf-ps1-v5.c	(revision 36912)
@@ -0,0 +1,395 @@
+# include "dvo.h"
+
+// this function is based on the one generated by the autocode of cmf-ps1-v5.d
+int gfits_convert_CMF_PS1_V5 (unsigned char *data, off_t size, off_t nitems, char toStruct) {
+
+  off_t i;
+  unsigned char tmp;
+
+  if (size != 232) { 
+    fprintf (stderr, "WARNING: mismatch in data types CMF_PS1_V5: "OFF_T_FMT" vs %d\n",  size,  232);
+    return (FALSE);
+  }
+
+  /* provide initial values to avoid compiler warnings for non-BYTE_SWAP arch */
+  i = tmp = 0;
+
+  // allocate a temporary output 
+  unsigned char tmpdata[64];
+
+  // move the bytes corresponding to PEAK_FLUX_AS_MAG, RA_PSF, DEC_PSF
+  if (toStruct) {
+    unsigned char *row = data;
+    for (i = 0; i < nitems; i++, row += size) {
+      memcpy  (tmpdata, &row[92], 4); // save PEAK_FLUX_AS_MAG (92-95)
+      memmove (&row[80], &row[76], 16); // move RA_PSF & DEC_PSF
+      memcpy  (&row[76], tmpdata, 4); // replace PEAK_FLUX_AS_MAG
+    }
+  }
+
+  // after we have moved around PEAK_FLUX_AS_MAG, RA_PSF, DEC_PSF, we can swap as needed for this platform
+  unsigned char *byte = data;
+
+# ifdef BYTE_SWAP
+  byte = (unsigned char *) data;
+  for (i = 0; i < nitems; i++, byte += 232) {
+    /** BYTE SWAP **/
+    SWAP_WORD (0); // IPP_IDET                     
+    SWAP_WORD (4); // X_PSF
+    SWAP_WORD (8); // Y_PSF
+    SWAP_WORD (12); // X_PSF_SIG
+    SWAP_WORD (16); // Y_PSF_SIG
+    SWAP_WORD (20); // POSANGLE
+    SWAP_WORD (24); // PLTSCALE
+    SWAP_WORD (28); // PSF_INST_MAG
+    SWAP_WORD (32); // PSF_INST_MAG_SIG
+    SWAP_WORD (36); // PSF_INST_FLUX
+    SWAP_WORD (40); // PSF_INST_FLUX_SIG
+    SWAP_WORD (44); // AP_MAG
+    SWAP_WORD (48); // AP_MAG_RAW
+    SWAP_WORD (52); // AP_MAG_RADIUS
+    SWAP_WORD (56); // AP_FLUX
+    SWAP_WORD (60); // AP_FLUX_SIG
+    SWAP_WORD (64); // AP_NPIX
+    SWAP_WORD (68); // CAL_PSF_MAG
+    SWAP_WORD (72); // CAL_PSF_MAG_SIG
+    SWAP_WORD (76); // PEAK_FLUX_AS_MAG
+    SWAP_DBLE (80); // RA_PSF
+    SWAP_DBLE (88); // DEC_PSF
+    SWAP_WORD (96); // SKY
+    SWAP_WORD (100); // SKY_SIGMA
+    SWAP_WORD (104); // PSF_CHISQ
+    SWAP_WORD (108); // CR_NSIGMA
+    SWAP_WORD (112); // EXT_NSIGMA
+    SWAP_WORD (116); // PSF_MAJOR
+    SWAP_WORD (120); // PSF_MINOR
+    SWAP_WORD (124); // PSF_THETA
+    SWAP_WORD (128); // PSF_CORE
+    SWAP_WORD (132); // PSF_FWHM_MAJ
+    SWAP_WORD (136); // PSF_FWHM_MIN
+    SWAP_WORD (140); // PSF_QF
+    SWAP_WORD (144); // PSF_QF_PERFECT
+    SWAP_WORD (148); // PSF_NDOF
+    SWAP_WORD (152); // PSF_NPIX
+    SWAP_WORD (156); // MOMENTS_XX
+    SWAP_WORD (160); // MOMENTS_XY
+    SWAP_WORD (164); // MOMENTS_YY
+    SWAP_WORD (168); // MOMENTS_M3C
+    SWAP_WORD (172); // MOMENTS_M3S
+    SWAP_WORD (176); // MOMENTS_M4C
+    SWAP_WORD (180); // MOMENTS_M4S
+    SWAP_WORD (184); // MOMENTS_R1
+    SWAP_WORD (188); // MOMENTS_RH
+    SWAP_WORD (192); // KRON_FLUX
+    SWAP_WORD (196); // KRON_FLUX_ERR
+    SWAP_WORD (200); // KRON_FLUX_INNER
+    SWAP_WORD (204); // KRON_FLUX_OUTER
+    SWAP_WORD (208); // SKY_LIMIT_RAD
+    SWAP_WORD (212); // SKY_LIMIT_FLUX
+    SWAP_WORD (216); // SKY_LIMIT_SLOPE
+    SWAP_WORD (220); // FLAGS
+    SWAP_WORD (224); // FLAGS2
+    SWAP_BYTE (228); // N_FRAMES
+    SWAP_BYTE (230); // PADDING
+  }
+# endif  
+
+  // move the bytes corresponding to PEAK_FLUX_AS_MAG, RA_PSF, DEC_PSF
+  if (!toStruct) {
+    unsigned char *row = data;
+    for (i = 0; i < nitems; i++, row += size) {
+      memcpy  (tmpdata, &row[76], 4); // save PEAK_FLUX_AS_MAG (92-95)
+      memmove (&row[76], &row[80], 16); // move RA_PSF & DEC_PSF
+      memcpy  (&row[92], tmpdata, 4); // replace PEAK_FLUX_AS_MAG
+    }
+  }
+
+  return (TRUE);
+} 
+
+// data organization (input vs output)
+//                FITS               struct
+// WORD   (0); // IPP_IDET           IPP_IDET           / 1J                  
+// WORD   (4); // X_PSF              X_PSF              / 1E                  
+// WORD   (8); // Y_PSF              Y_PSF              / 1E                  
+// WORD  (12); // X_PSF_SIG          X_PSF_SIG          / 1E                  
+// WORD  (16); // Y_PSF_SIG          Y_PSF_SIG          / 1E                  
+// WORD  (20); // POSANGLE           POSANGLE           / 1E                  
+// WORD  (24); // PLTSCALE           PLTSCALE           / 1E                  
+// WORD  (28); // PSF_INST_MAG       PSF_INST_MAG       / 1E                  
+// WORD  (32); // PSF_INST_MAG_SIG   PSF_INST_MAG_SIG   / 1E                  
+// WORD  (36); // PSF_INST_FLUX      PSF_INST_FLUX      / 1E                  
+// WORD  (40); // PSF_INST_FLUX_SIG  PSF_INST_FLUX_SIG  / 1E                  
+// WORD  (44); // AP_MAG             AP_MAG             / 1E                  
+// WORD  (48); // AP_MAG_RAW         AP_MAG_RAW         / 1E                  
+// WORD  (52); // AP_MAG_RADIUS      AP_MAG_RADIUS      / 1E                  
+// WORD  (56); // AP_FLUX            AP_FLUX            / 1E                  
+// WORD  (60); // AP_FLUX_SIG        AP_FLUX_SIG        / 1E                  
+// WORD  (64); // AP_NPIX            AP_NPIX            / 1J                  
+// WORD  (68); // CAL_PSF_MAG        CAL_PSF_MAG        / 1E                  
+// WORD  (72); // CAL_PSF_MAG_SIG    CAL_PSF_MAG_SIG    / 1E                  
+// WORD  (76); // PEAK_FLUX_AS_MAG   RA_PSF             / 1D                  
+// DBLE  (80); // RA_PSF             DEC_PSF            / 1D                  
+// DBLE  (88); // DEC_PSF            PEAK_FLUX_AS_MAG   / 1E                  
+// WORD  (96); // SKY                SKY                / 1E                  
+// WORD (100); // SKY_SIGMA          SKY_SIGMA          / 1E                  
+// WORD (104); // PSF_CHISQ          PSF_CHISQ          / 1E                  
+// WORD (108); // CR_NSIGMA          CR_NSIGMA          / 1E                  
+// WORD (112); // EXT_NSIGMA         EXT_NSIGMA         / 1E                  
+// WORD (116); // PSF_MAJOR          PSF_MAJOR          / 1E                  
+// WORD (120); // PSF_MINOR          PSF_MINOR          / 1E                  
+// WORD (124); // PSF_THETA          PSF_THETA          / 1E                  
+// WORD (128); // PSF_CORE           PSF_CORE           / 1E                  
+// WORD (132); // PSF_FWHM_MAJ       PSF_FWHM_MAJ       / 1E                  
+// WORD (136); // PSF_FWHM_MIN       PSF_FWHM_MIN       / 1E                  
+// WORD (140); // PSF_QF             PSF_QF             / 1E                  
+// WORD (144); // PSF_QF_PERFECT     PSF_QF_PERFECT     / 1E                  
+// WORD (148); // PSF_NDOF           PSF_NDOF           / 1J                  
+// WORD (152); // PSF_NPIX           PSF_NPIX           / 1J                  
+// WORD (156); // MOMENTS_XX         MOMENTS_XX         / 1E                  
+// WORD (160); // MOMENTS_XY         MOMENTS_XY         / 1E                  
+// WORD (164); // MOMENTS_YY         MOMENTS_YY         / 1E                  
+// WORD (168); // MOMENTS_M3C        MOMENTS_M3C        / 1E                  
+// WORD (172); // MOMENTS_M3S        MOMENTS_M3S        / 1E                  
+// WORD (176); // MOMENTS_M4C        MOMENTS_M4C        / 1E                  
+// WORD (180); // MOMENTS_M4S        MOMENTS_M4S        / 1E                  
+// WORD (184); // MOMENTS_R1         MOMENTS_R1         / 1E                  
+// WORD (188); // MOMENTS_RH         MOMENTS_RH         / 1E                  
+// WORD (192); // KRON_FLUX          KRON_FLUX          / 1E                  
+// WORD (196); // KRON_FLUX_ERR      KRON_FLUX_ERR      / 1E                  
+// WORD (200); // KRON_FLUX_INNER    KRON_FLUX_INNER    / 1E                  
+// WORD (204); // KRON_FLUX_OUTER    KRON_FLUX_OUTER    / 1E                  
+// WORD (208); // SKY_LIMIT_RAD      SKY_LIMIT_RAD      / 1E                  
+// WORD (212); // SKY_LIMIT_FLUX     SKY_LIMIT_FLUX     / 1E                  
+// WORD (216); // SKY_LIMIT_SLOPE    SKY_LIMIT_SLOPE    / 1E                  
+// WORD (220); // FLAGS              FLAGS              / 1J                  
+// WORD (224); // FLAGS2             FLAGS2             / 1J                  
+// BYTE (228); // N_FRAMES           N_FRAMES           / 1I                  
+// BYTE (230); // PADDING            PADDING            / 1I                  
+
+/*** add test of EXTNAME and header-defined columns? ***/
+/* return internal structure representation */
+CMF_PS1_V5 *gfits_table_get_CMF_PS1_V5 (FTable *ftable, off_t *Ndata, char *swapped) {
+
+  int Ncols;
+  CMF_PS1_V5 *data;
+
+  Ncols = ftable[0].header[0].Naxis[0];
+  if (Ncols != 232) {
+    fprintf (stderr, "ERROR: mis-match in table size: width is %d but should be %d bytes\n", Ncols, 232);
+    return NULL;
+  }
+
+  *Ndata = ftable[0].header[0].Naxis[1];
+  data = (CMF_PS1_V5 *) ftable[0].buffer;
+  if ((swapped == NULL) || (*swapped == FALSE)) {
+    if (!gfits_convert_CMF_PS1_V5 ((unsigned char *) data, sizeof (CMF_PS1_V5), *Ndata, TRUE)) {
+      return NULL;
+    }
+    gfits_table_scale_data (ftable);
+    if (swapped != NULL) *swapped = TRUE;
+  }
+  return (data);
+}
+
+int gfits_table_set_CMF_PS1_V5 (FTable *ftable, CMF_PS1_V5 *data, off_t Ndata) {
+
+  Header *header;
+
+  header = ftable[0].header;
+
+  /* create table header */
+  if (!gfits_create_table_header (header, "BINTABLE", "CMF_PS1_V5")) return (FALSE);
+
+  /* define table layout */
+  /** TABLE DEFINITION **/
+  gfits_define_bintable_column (header, "J",    "IPP_IDET",         "detection ID                     ", "",                  1.0, 0.0);
+  gfits_define_bintable_column (header, "E",    "X_PSF",            "x coord",                         "pixels",            1.0, 0.0);
+  gfits_define_bintable_column (header, "E",    "Y_PSF",            "y coord",                         "pixels",            1.0, 0.0);
+  gfits_define_bintable_column (header, "E",    "X_PSF_SIG",        "x coord error",                   "pixels",            1.0, 0.0);
+  gfits_define_bintable_column (header, "E",    "Y_PSF_SIG",        "y coord error",                   "pixels",            1.0, 0.0);
+  gfits_define_bintable_column (header, "E",    "POSANGLE",         "Posangle at source",              "degrees",           1.0, 0.0);
+  gfits_define_bintable_column (header, "E",    "PLTSCALE",         "Plate Scale at source",           "arcsec/pixel",      1.0, 0.0);
+  gfits_define_bintable_column (header, "E",    "PSF_INST_MAG",     "inst mags",                       "mags",              1.0, 0.0);
+  gfits_define_bintable_column (header, "E",    "PSF_INST_MAG_SIG", "inst mag error",                  "mags",              1.0, 0.0);
+  gfits_define_bintable_column (header, "E",    "PSF_INST_FLUX",    "psf flux",                        "counts",            1.0, 0.0);
+  gfits_define_bintable_column (header, "E",    "PSF_INST_FLUX_SIG", "psf flux error",                  "counts      ",      1.0, 0.0);
+  gfits_define_bintable_column (header, "E",    "AP_MAG",           "standard aperture mag",           "mags",              1.0, 0.0);
+  gfits_define_bintable_column (header, "E",    "AP_MAG_RAW",       "raw aperture mag",                "mags",              1.0, 0.0);
+  gfits_define_bintable_column (header, "E",    "AP_MAG_RADIUS",    "radius used for aper",            "pixels",            1.0, 0.0);
+  gfits_define_bintable_column (header, "E",    "AP_FLUX",          "aperture flux",                   "counts",            1.0, 0.0);
+  gfits_define_bintable_column (header, "E",    "AP_FLUX_SIG",      "error on ap flux",                "counts",            1.0, 0.0);
+  gfits_define_bintable_column (header, "J",    "AP_NPIX",          "pixels used by aper",             "pixels",            1.0, 0.0);
+  gfits_define_bintable_column (header, "E",    "CAL_PSF_MAG",      "calibrated psf mag",              "mags",              1.0, 0.0);
+  gfits_define_bintable_column (header, "E",    "CAL_PSF_MAG_SIG",  "zero point scatter",              "mags",              1.0, 0.0);
+  gfits_define_bintable_column (header, "D",    "RA_PSF",           "PSF RA coord",                    "degrees",           1.0, 0.0);
+  gfits_define_bintable_column (header, "D",    "DEC_PSF",          "PSF DEC coord",                   "degrees",           1.0, 0.0);
+  gfits_define_bintable_column (header, "E",    "PEAK_FLUX_AS_MAG", "peak flux as a mag",              "mags",              1.0, 0.0);
+  gfits_define_bintable_column (header, "E",    "SKY",              "sky flux",                        "cnts/sec",          1.0, 0.0);
+  gfits_define_bintable_column (header, "E",    "SKY_SIGMA",        "sky flux error",                  "cnts/sec",          1.0, 0.0);
+  gfits_define_bintable_column (header, "E",    "PSF_CHISQ",        "psf fit chisq",                   "",                  1.0, 0.0);
+  gfits_define_bintable_column (header, "E",    "CR_NSIGMA",        "Nsigma deviations from PSF to CF", "",                  1.0, 0.0);
+  gfits_define_bintable_column (header, "E",    "EXT_NSIGMA",       "Nsigma deviations from PSF to EXT", "",                  1.0, 0.0);
+  gfits_define_bintable_column (header, "E",    "PSF_MAJOR",        "psf fit major axis",              "pixels",            1.0, 0.0);
+  gfits_define_bintable_column (header, "E",    "PSF_MINOR",        "psf fit minor axis",              "pixels",            1.0, 0.0);
+  gfits_define_bintable_column (header, "E",    "PSF_THETA",        "ellipse angle",                   "degrees",           1.0, 0.0);
+  gfits_define_bintable_column (header, "E",    "PSF_CORE",         "extra PSF parameter",             "unitless",          1.0, 0.0);
+  gfits_define_bintable_column (header, "E",    "PSF_FWHM_MAJ",     "true fwhm of psf",                "pixels",            1.0, 0.0);
+  gfits_define_bintable_column (header, "E",    "PSF_FWHM_MIN",     "true fwhm (minor)",               "pixels",            1.0, 0.0);
+  gfits_define_bintable_column (header, "E",    "PSF_QF",           "quality factor",                  "",                  1.0, 0.0);
+  gfits_define_bintable_column (header, "E",    "PSF_QF_PERFECT",   "quality factor perfect",          "",                  1.0, 0.0);
+  gfits_define_bintable_column (header, "J",    "PSF_NDOF",         "psf degrees of freedom",          "",                  1.0, 0.0);
+  gfits_define_bintable_column (header, "J",    "PSF_NPIX",         "psf number of pixels",            "",                  1.0, 0.0);
+  gfits_define_bintable_column (header, "E",    "MOMENTS_XX",       "second moment X",                 "pixels^2",          1.0, 0.0);
+  gfits_define_bintable_column (header, "E",    "MOMENTS_XY",       "second moment Y",                 "pixels^2",          1.0, 0.0);
+  gfits_define_bintable_column (header, "E",    "MOMENTS_YY",       "second moment XY",                "pixels^2",          1.0, 0.0);
+  gfits_define_bintable_column (header, "E",    "MOMENTS_M3C",      "third moment cos(t)",             "pixels^3",          1.0, 0.0);
+  gfits_define_bintable_column (header, "E",    "MOMENTS_M3S",      "third moment sin(t)",             "pixels^3",          1.0, 0.0);
+  gfits_define_bintable_column (header, "E",    "MOMENTS_M4C",      "fourth moment cos(t)",            "pixels^4",          1.0, 0.0);
+  gfits_define_bintable_column (header, "E",    "MOMENTS_M4S",      "fourth moment sin(t)",            "pixels^4",          1.0, 0.0);
+  gfits_define_bintable_column (header, "E",    "MOMENTS_R1",       "first radial moment",             "pixels",            1.0, 0.0);
+  gfits_define_bintable_column (header, "E",    "MOMENTS_RH",       "half radial moment",              "pixels^1/2",        1.0, 0.0);
+  gfits_define_bintable_column (header, "E",    "KRON_FLUX",        "kron flux",                       "counts",            1.0, 0.0);
+  gfits_define_bintable_column (header, "E",    "KRON_FLUX_ERR",    "kron flux error",                 "counts",            1.0, 0.0);
+  gfits_define_bintable_column (header, "E",    "KRON_FLUX_INNER",  "kron flux 1<R<2.5",               "counts",            1.0, 0.0);
+  gfits_define_bintable_column (header, "E",    "KRON_FLUX_OUTER",  "kron flux 2.5<R<4",               "counts",            1.0, 0.0);
+  gfits_define_bintable_column (header, "E",    "SKY_LIMIT_RAD",    "profile to sky limit (radius)",   "",                  1.0, 0.0);
+  gfits_define_bintable_column (header, "E",    "SKY_LIMIT_FLUX",   "profile to sky limit (flux)",     "",                  1.0, 0.0);
+  gfits_define_bintable_column (header, "E",    "SKY_LIMIT_SLOPE",  "profile to sky limit (slope)",    "",                  1.0, 0.0);
+  gfits_define_bintable_column (header, "J",    "FLAGS",            "analysis flags",                  "",                  1.0, 0.0);
+  gfits_define_bintable_column (header, "J",    "FLAGS2",           "analysis flags (2)",              "",                  1.0, 0.0);
+  gfits_define_bintable_column (header, "I",    "N_FRAMES",         "images overlapping peak",         "",                  1.0, 0.0);
+  gfits_define_bintable_column (header, "I",    "PADDING",          "padding for 8byte records",       "",                  1.0, 0.0);
+
+  /* create table */
+  if (!gfits_create_table (header, ftable)) return (FALSE);
+
+  /* add data values */
+  if (!gfits_table_scale_data (ftable)) return (FALSE);
+  if (!gfits_convert_CMF_PS1_V5 ((unsigned char *) data, sizeof (CMF_PS1_V5), Ndata, FALSE)) return (FALSE);
+  if (!gfits_add_rows (ftable, (char *) data, Ndata, sizeof (CMF_PS1_V5))) return (FALSE);
+
+  return (TRUE);
+}
+
+int gfits_table_mkheader_CMF_PS1_V5 (Header *header) {
+
+  /* create table header */
+  if (!gfits_create_table_header (header, "BINTABLE", "CMF_PS1_V5")) return (FALSE);
+
+  /* define table layout */
+  /** TABLE DEFINITION **/
+  gfits_define_bintable_column (header, "J",    "IPP_IDET",         "detection ID                     ", "",                  1.0, 0.0);
+  gfits_define_bintable_column (header, "E",    "X_PSF",            "x coord",                         "pixels",            1.0, 0.0);
+  gfits_define_bintable_column (header, "E",    "Y_PSF",            "y coord",                         "pixels",            1.0, 0.0);
+  gfits_define_bintable_column (header, "E",    "X_PSF_SIG",        "x coord error",                   "pixels",            1.0, 0.0);
+  gfits_define_bintable_column (header, "E",    "Y_PSF_SIG",        "y coord error",                   "pixels",            1.0, 0.0);
+  gfits_define_bintable_column (header, "E",    "POSANGLE",         "Posangle at source",              "degrees",           1.0, 0.0);
+  gfits_define_bintable_column (header, "E",    "PLTSCALE",         "Plate Scale at source",           "arcsec/pixel",      1.0, 0.0);
+  gfits_define_bintable_column (header, "E",    "PSF_INST_MAG",     "inst mags",                       "mags",              1.0, 0.0);
+  gfits_define_bintable_column (header, "E",    "PSF_INST_MAG_SIG", "inst mag error",                  "mags",              1.0, 0.0);
+  gfits_define_bintable_column (header, "E",    "PSF_INST_FLUX",    "psf flux",                        "counts",            1.0, 0.0);
+  gfits_define_bintable_column (header, "E",    "PSF_INST_FLUX_SIG", "psf flux error",                  "counts      ",      1.0, 0.0);
+  gfits_define_bintable_column (header, "E",    "AP_MAG",           "standard aperture mag",           "mags",              1.0, 0.0);
+  gfits_define_bintable_column (header, "E",    "AP_MAG_RAW",       "raw aperture mag",                "mags",              1.0, 0.0);
+  gfits_define_bintable_column (header, "E",    "AP_MAG_RADIUS",    "radius used for aper",            "pixels",            1.0, 0.0);
+  gfits_define_bintable_column (header, "E",    "AP_FLUX",          "aperture flux",                   "counts",            1.0, 0.0);
+  gfits_define_bintable_column (header, "E",    "AP_FLUX_SIG",      "error on ap flux",                "counts",            1.0, 0.0);
+  gfits_define_bintable_column (header, "J",    "AP_NPIX",          "pixels used by aper",             "pixels",            1.0, 0.0);
+  gfits_define_bintable_column (header, "E",    "CAL_PSF_MAG",      "calibrated psf mag",              "mags",              1.0, 0.0);
+  gfits_define_bintable_column (header, "E",    "CAL_PSF_MAG_SIG",  "zero point scatter",              "mags",              1.0, 0.0);
+  gfits_define_bintable_column (header, "E",    "PEAK_FLUX_AS_MAG", "peak flux as a mag",              "mags",              1.0, 0.0);
+  gfits_define_bintable_column (header, "D",    "RA_PSF",           "PSF RA coord",                    "degrees",           1.0, 0.0);
+  gfits_define_bintable_column (header, "D",    "DEC_PSF",          "PSF DEC coord",                   "degrees",           1.0, 0.0);
+  gfits_define_bintable_column (header, "E",    "SKY",              "sky flux",                        "cnts/sec",          1.0, 0.0);
+  gfits_define_bintable_column (header, "E",    "SKY_SIGMA",        "sky flux error",                  "cnts/sec",          1.0, 0.0);
+  gfits_define_bintable_column (header, "E",    "PSF_CHISQ",        "psf fit chisq",                   "",                  1.0, 0.0);
+  gfits_define_bintable_column (header, "E",    "CR_NSIGMA",        "Nsigma deviations from PSF to CF", "",                  1.0, 0.0);
+  gfits_define_bintable_column (header, "E",    "EXT_NSIGMA",       "Nsigma deviations from PSF to EXT", "",                  1.0, 0.0);
+  gfits_define_bintable_column (header, "E",    "PSF_MAJOR",        "psf fit major axis",              "pixels",            1.0, 0.0);
+  gfits_define_bintable_column (header, "E",    "PSF_MINOR",        "psf fit minor axis",              "pixels",            1.0, 0.0);
+  gfits_define_bintable_column (header, "E",    "PSF_THETA",        "ellipse angle",                   "degrees",           1.0, 0.0);
+  gfits_define_bintable_column (header, "E",    "PSF_CORE",         "extra PSF parameter",             "unitless",          1.0, 0.0);
+  gfits_define_bintable_column (header, "E",    "PSF_FWHM_MAJ",     "true fwhm of psf",                "pixels",            1.0, 0.0);
+  gfits_define_bintable_column (header, "E",    "PSF_FWHM_MIN",     "true fwhm (minor)",               "pixels",            1.0, 0.0);
+  gfits_define_bintable_column (header, "E",    "PSF_QF",           "quality factor",                  "",                  1.0, 0.0);
+  gfits_define_bintable_column (header, "E",    "PSF_QF_PERFECT",   "quality factor perfect",          "",                  1.0, 0.0);
+  gfits_define_bintable_column (header, "J",    "PSF_NDOF",         "psf degrees of freedom",          "",                  1.0, 0.0);
+  gfits_define_bintable_column (header, "J",    "PSF_NPIX",         "psf number of pixels",            "",                  1.0, 0.0);
+  gfits_define_bintable_column (header, "E",    "MOMENTS_XX",       "second moment X",                 "pixels^2",          1.0, 0.0);
+  gfits_define_bintable_column (header, "E",    "MOMENTS_XY",       "second moment Y",                 "pixels^2",          1.0, 0.0);
+  gfits_define_bintable_column (header, "E",    "MOMENTS_YY",       "second moment XY",                "pixels^2",          1.0, 0.0);
+  gfits_define_bintable_column (header, "E",    "MOMENTS_M3C",      "third moment cos(t)",             "pixels^3",          1.0, 0.0);
+  gfits_define_bintable_column (header, "E",    "MOMENTS_M3S",      "third moment sin(t)",             "pixels^3",          1.0, 0.0);
+  gfits_define_bintable_column (header, "E",    "MOMENTS_M4C",      "fourth moment cos(t)",            "pixels^4",          1.0, 0.0);
+  gfits_define_bintable_column (header, "E",    "MOMENTS_M4S",      "fourth moment sin(t)",            "pixels^4",          1.0, 0.0);
+  gfits_define_bintable_column (header, "E",    "MOMENTS_R1",       "first radial moment",             "pixels",            1.0, 0.0);
+  gfits_define_bintable_column (header, "E",    "MOMENTS_RH",       "half radial moment",              "pixels^1/2",        1.0, 0.0);
+  gfits_define_bintable_column (header, "E",    "KRON_FLUX",        "kron flux",                       "counts",            1.0, 0.0);
+  gfits_define_bintable_column (header, "E",    "KRON_FLUX_ERR",    "kron flux error",                 "counts",            1.0, 0.0);
+  gfits_define_bintable_column (header, "E",    "KRON_FLUX_INNER",  "kron flux 1<R<2.5",               "counts",            1.0, 0.0);
+  gfits_define_bintable_column (header, "E",    "KRON_FLUX_OUTER",  "kron flux 2.5<R<4",               "counts",            1.0, 0.0);
+  gfits_define_bintable_column (header, "E",    "SKY_LIMIT_RAD",    "profile to sky limit (radius)",   "",                  1.0, 0.0);
+  gfits_define_bintable_column (header, "E",    "SKY_LIMIT_FLUX",   "profile to sky limit (flux)",     "",                  1.0, 0.0);
+  gfits_define_bintable_column (header, "E",    "SKY_LIMIT_SLOPE",  "profile to sky limit (slope)",    "",                  1.0, 0.0);
+  gfits_define_bintable_column (header, "J",    "FLAGS",            "analysis flags",                  "",                  1.0, 0.0);
+  gfits_define_bintable_column (header, "J",    "FLAGS2",           "analysis flags (2)",              "",                  1.0, 0.0);
+  gfits_define_bintable_column (header, "I",    "N_FRAMES",         "images overlapping peak",         "",                  1.0, 0.0);
+  gfits_define_bintable_column (header, "I",    "PADDING",          "padding for 8byte records",       "",                  1.0, 0.0);
+
+  return (TRUE);
+}
+
+int Send_CMF_PS1_V5 (int device, CMF_PS1_V5 *data, int Ndata, int copy) {
+
+  int Nwrite, Nbytes;
+  CMF_PS1_V5 *tmpdata;
+
+  Nbytes = Ndata * sizeof (CMF_PS1_V5);
+
+  if (copy) {
+    ALLOCATE (tmpdata, CMF_PS1_V5, Ndata);
+    memcpy (tmpdata, data, Nbytes);
+  } else {
+    tmpdata = data;
+  }
+
+  if (!gfits_convert_CMF_PS1_V5 ((unsigned char *) tmpdata, sizeof (CMF_PS1_V5), Ndata, FALSE)) return (FALSE);
+
+  SendCommand (device, 16, "NVALUE: %6d", Ndata);
+  SendCommand (device, 16, "NBYTES: %6d", Nbytes);
+  Nwrite = write (device, tmpdata, Nbytes);
+  if (Nwrite != Nbytes) {
+    return (FALSE);
+  }
+  
+  /* perform handshaking? */
+
+  return (TRUE);
+}
+
+int Recv_CMF_PS1_V5 (int device, CMF_PS1_V5 **data, int *Ndata) {
+
+  int ndata;
+  IOBuffer message;
+  CMF_PS1_V5 *tmpdata;
+
+  ExpectCommand (device, 16, 1.0, &message);
+  sscanf (message.buffer, "%*s %d", &ndata);
+  FreeIOBuffer (&message);
+  
+  /* what is reasonable for timeout? */
+  ExpectMessage (device, 1.0, &message);
+  
+  tmpdata = (CMF_PS1_V5 *) message.buffer;
+  if (!gfits_convert_CMF_PS1_V5 ((unsigned char *) tmpdata, sizeof (CMF_PS1_V5), ndata, TRUE)) return (FALSE);
+
+  /* double-check data length? */
+  /* perform handshaking? */
+
+  *Ndata = ndata;
+  *data = tmpdata;
+
+  return (TRUE);
+}
+
Index: /branches/eam_branches/ipp-20140610/Ohana/src/libdvo/src/dbExtractMeasures.c
===================================================================
--- /branches/eam_branches/ipp-20140610/Ohana/src/libdvo/src/dbExtractMeasures.c	(revision 36911)
+++ /branches/eam_branches/ipp-20140610/Ohana/src/libdvo/src/dbExtractMeasures.c	(revision 36912)
@@ -177,6 +177,8 @@
 	    case MAG_LEVEL_SYS:
 	    case MAG_LEVEL_REL:
+	      value.Flt = PhotErr (measure, field->magClass);  
+	      break;
 	    case MAG_LEVEL_CAL:
-	      value.Flt = PhotErr (measure, field->magClass);  
+	      value.Flt = PhotCalErr (measure, field->magClass);  
 	      break;
 	    case MAG_LEVEL_AVE:
@@ -220,5 +222,9 @@
 	  switch (field->magLevel) {
 	    case MAG_LEVEL_INST:
+	      value.Flt = PhotFluxInstErr (measure, field->magClass);  
+	      break;
 	    case MAG_LEVEL_CAT:
+	      value.Flt = PhotFluxCatErr (measure, field->magClass);  
+	      break;
 	    case MAG_LEVEL_SYS:
 	    case MAG_LEVEL_REL:
Index: /branches/eam_branches/ipp-20140610/Ohana/src/libdvo/src/dvo_photcode_ops.c
===================================================================
--- /branches/eam_branches/ipp-20140610/Ohana/src/libdvo/src/dvo_photcode_ops.c	(revision 36911)
+++ /branches/eam_branches/ipp-20140610/Ohana/src/libdvo/src/dvo_photcode_ops.c	(revision 36912)
@@ -549,4 +549,10 @@
 }
 
+float PhotCalErr (Measure *measure, dvoMagClassType class) {
+
+  float dMcal = measure[0].dMcal;
+  return (dMcal);
+}
+
 float PhotAveErr (PhotCode *code, Average *average, SecFilt *secfilt, dvoMagClassType class, dvoMagSourceType source) {
 
@@ -1113,4 +1119,89 @@
   float Foff = MagToFlux(Mcol);
   return (Fave * Foff);
+}
+
+float PhotFluxInstErr (Measure *measure, dvoMagClassType class) {
+
+  float Moff = - measure[0].dt - ZERO_POINT;
+
+  // use dFlux if we can, but use dMag if we must:
+  // dFlux = Flux * dMag
+
+  float dFinst = NAN;
+  switch (class) {
+    case MAG_CLASS_PSF:
+      if (isnan (measure[0].dFluxPSF)) {
+	float Finst = MagToFlux(measure[0].M + Moff);
+	dFinst = measure[0].dM * Finst;
+      } else {
+	dFinst = measure[0].dFluxPSF;
+      }
+      break;
+    case MAG_CLASS_KRON:
+      if (isnan (measure[0].dFluxKron)) {
+	float Finst = MagToFlux(measure[0].Mkron + Moff);
+	dFinst = measure[0].dMkron * Finst;
+      } else {
+	dFinst = measure[0].dFluxKron;
+      }
+      break;
+    case MAG_CLASS_APER:
+      if (isnan (measure[0].dFluxAp)) {
+	float Finst = MagToFlux(measure[0].Map + Moff);
+	dFinst = measure[0].dMap * Finst;
+      } else {
+	dFinst = measure[0].dFluxAp;
+      }
+      break;
+    default:
+      break;
+  }
+  return (dFinst);
+}
+
+float PhotFluxCatErr (Measure *measure, dvoMagClassType class) {
+
+  int Np = photcodes[0].hashcode[measure[0].photcode];
+  if (Np == -1) return (NAN);
+  PhotCode *code = &photcodes[0].code[Np];
+
+  // measure.M has the static ZERO_POINT (25.0) applied, but not measure.Flux
+  float Mcal = code[0].K*(measure[0].airmass - 1.000) + SCALE*code[0].C;
+  float Moff = Mcal - ZERO_POINT;
+  float Foff = MagToFlux(Mcal);
+
+  // use dFlux if we can, but use dMag if we must:
+  // dFlux = Flux * dMag
+
+  float dFcat = NAN;
+  switch (class) {
+    case MAG_CLASS_PSF:
+      if (isnan (measure[0].dFluxPSF)) {
+	float Finst = MagToFlux(measure[0].M + Moff);
+	dFcat = measure[0].dM * Finst;
+      } else {
+	dFcat = measure[0].dFluxPSF * Foff;
+      }
+      break;
+    case MAG_CLASS_KRON:
+      if (isnan (measure[0].dFluxKron)) {
+	float Finst = MagToFlux(measure[0].Mkron + Moff);
+	dFcat = measure[0].dMkron * Finst;
+      } else {
+	dFcat = measure[0].dFluxKron * Foff;
+      }
+      break;
+    case MAG_CLASS_APER:
+      if (isnan (measure[0].dFluxAp)) {
+	float Finst = MagToFlux(measure[0].Map + Moff);
+	dFcat = measure[0].dMap * Finst;
+      } else {
+	dFcat = measure[0].dFluxAp * Foff;
+      }
+      break;
+    default:
+      break;
+  }
+  return (dFcat);
 }
 
