Index: /branches/eam_branches/ipp-20140610/Ohana/src/addstar/include/addstar.h
===================================================================
--- /branches/eam_branches/ipp-20140610/Ohana/src/addstar/include/addstar.h	(revision 36919)
+++ /branches/eam_branches/ipp-20140610/Ohana/src/addstar/include/addstar.h	(revision 36920)
@@ -41,6 +41,7 @@
 
 typedef struct {
-  Average average;
-  Measure measure;
+  Average  average;
+  Measure  measure;
+  Lensing *lensing; // optionally carry out the lensing measurements
   int found;
 } Stars;
Index: /branches/eam_branches/ipp-20140610/Ohana/src/addstar/src/ReadStarsFITS.c
===================================================================
--- /branches/eam_branches/ipp-20140610/Ohana/src/addstar/src/ReadStarsFITS.c	(revision 36919)
+++ /branches/eam_branches/ipp-20140610/Ohana/src/addstar/src/ReadStarsFITS.c	(revision 36920)
@@ -13,4 +13,5 @@
 Stars     *Convert_PS1_V4	  PROTO((FTable *table, unsigned int *nstars));
 Stars     *Convert_PS1_V5	  PROTO((FTable *table, unsigned int *nstars));
+Stars     *Convert_PS1_V5_Lensing 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));
@@ -77,5 +78,9 @@
   }
   if (!strcmp (type, "PS1_V5")) {
-    stars = Convert_PS1_V5 (&table, &Nstars);
+    if (table.header[0].Naxis[0] == 296) {
+      stars = Convert_PS1_V5_Lensing (&table, &Nstars);
+    } else {
+      stars = Convert_PS1_V5 (&table, &Nstars);
+    }
   }
   if (!strcmp (type, "PS1_SV1")) {
@@ -822,4 +827,128 @@
 }
 
+Stars *Convert_PS1_V5_Lensing (FTable *table, unsigned int *nstars) {
+
+  off_t Nstars; 
+  unsigned int i;
+  double ZeroPt;
+  Stars *stars;
+  CMF_PS1_V5_Lensing *ps1data;
+
+  ps1data = gfits_table_get_CMF_PS1_V5_Lensing (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; 
+
+    ALLOCATE (stars[i].lensing, Lensing, 1);
+    stars[i].lensing->X11_sm_obj  = ps1data[i].X11_sm_obj;
+    stars[i].lensing->X12_sm_obj  = ps1data[i].X12_sm_obj;
+    stars[i].lensing->X22_sm_obj  = ps1data[i].X22_sm_obj;
+    stars[i].lensing->E1_sm_obj   = ps1data[i].E1_sm_obj;
+    stars[i].lensing->E2_sm_obj   = ps1data[i].E2_sm_obj;
+
+    stars[i].lensing->X11_sh_obj  = ps1data[i].X11_sh_obj;
+    stars[i].lensing->X12_sh_obj  = ps1data[i].X12_sh_obj;
+    stars[i].lensing->X22_sh_obj  = ps1data[i].X22_sh_obj;
+    stars[i].lensing->E1_sh_obj   = ps1data[i].E1_sh_obj;
+    stars[i].lensing->E2_sh_obj   = ps1data[i].E2_sh_obj;
+
+    stars[i].lensing->X11_sm_psf  = ps1data[i].X11_sm_psf;
+    stars[i].lensing->X12_sm_psf  = ps1data[i].X12_sm_psf;
+    stars[i].lensing->X22_sm_psf  = ps1data[i].X22_sm_psf;
+    stars[i].lensing->E1_sm_psf   = ps1data[i].E1_sm_psf;
+    stars[i].lensing->E2_sm_psf   = ps1data[i].E2_sm_psf;
+
+    stars[i].lensing->X11_sh_psf  = ps1data[i].X11_sh_psf;
+    stars[i].lensing->X12_sh_psf  = ps1data[i].X12_sh_psf;
+    stars[i].lensing->X22_sh_psf  = ps1data[i].X22_sh_psf;
+    stars[i].lensing->E1_sh_psf   = ps1data[i].E1_sh_psf;
+    stars[i].lensing->E2_sh_psf   = ps1data[i].E2_sh_psf;
+
+    // stars[i].lensing->F_ApR5    = ps1data[i].F_ApR5;
+    // stars[i].lensing->dF_ApR5   = ps1data[i].dF_ApR5;
+    // stars[i].lensing->sF_ApR5   = ps1data[i].sF_ApR5;
+    // stars[i].lensing->fF_ApR5   = ps1data[i].fF_ApR5;
+    // 
+    // stars[i].lensing->F_ApR6    = ps1data[i].F_ApR6;
+    // stars[i].lensing->dF_ApR6   = ps1data[i].dF_ApR6;
+    // stars[i].lensing->sF_ApR6   = ps1data[i].sF_ApR6;
+    // stars[i].lensing->fF_ApR6   = ps1data[i].fF_ApR6;
+
+    // this is may optionally be replaced by the internal sequence (see FilterStars.c)
+    stars[i].lensing->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) {
 
Index: /branches/eam_branches/ipp-20140610/Ohana/src/addstar/src/StarOps.c
===================================================================
--- /branches/eam_branches/ipp-20140610/Ohana/src/addstar/src/StarOps.c	(revision 36919)
+++ /branches/eam_branches/ipp-20140610/Ohana/src/addstar/src/StarOps.c	(revision 36920)
@@ -8,4 +8,5 @@
     star[0].found = -1; // found == -1 -> not yet found (use enums?)
 
+    star[0].lensing = NULL; // we only populate this if needed
     return TRUE;
 }
Index: /branches/eam_branches/ipp-20140610/Ohana/src/libautocode/def/cmf-ps1-v5-lensing.d
===================================================================
--- /branches/eam_branches/ipp-20140610/Ohana/src/libautocode/def/cmf-ps1-v5-lensing.d	(revision 36920)
+++ /branches/eam_branches/ipp-20140610/Ohana/src/libautocode/def/cmf-ps1-v5-lensing.d	(revision 36920)
@@ -0,0 +1,100 @@
+# name of structure type
+STRUCT  CMF_PS1_V5
+EXTNAME CMF_PS1_V5
+TYPE    BINTABLE
+SIZE    312
+
+# 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 aper,  pixels
+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...
+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 k,              PSF_CORE,          float,    extra PSF parameter,   unitless
+FIELD fwhmMaj,        PSF_FWHM_MAJ,      float,    true fwhm of psf,      pixels
+FIELD fwhmMin,        PSF_FWHM_MIN,      float,    true fwhm (minor),     pixels
+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 X11_sm_obj,     X11_SM_OBJ,        float,    lensing smear
+FIELD X12_sm_obj,     X12_SM_OBJ,        float,    lensing smear
+FIELD X22_sm_obj,     X22_SM_OBJ,        float,    lensing smear
+FIELD E1_sm_obj,      E1_SM_OBJ,         float,    lensing smear
+FIELD E2_sm_obj,      E2_SM_OBJ,         float,    lensing smear
+
+FIELD X11_sh_obj,     X11_SH_OBJ,        float,    lensing shear
+FIELD X12_sh_obj,     X12_SH_OBJ,        float,    lensing shear
+FIELD X22_sh_obj,     X22_SH_OBJ,        float,    lensing shear
+FIELD E1_sh_obj,      E1_SH_OBJ,         float,    lensing shear
+FIELD E2_sh_obj,      E2_SH_OBJ,         float,    lensing shear
+
+FIELD X11_sm_psf,     X11_SM_PSF,        float,    lensing smear
+FIELD X12_sm_psf,     X12_SM_PSF,        float,    lensing smear
+FIELD X22_sm_psf,     X22_SM_PSF,        float,    lensing smear
+FIELD E1_sm_psf,      E1_SM_PSF,         float,    lensing smear
+FIELD E2_sm_psf,      E2_SM_PSF,         float,    lensing smear
+
+FIELD X11_sh_psf,     X11_SH_PSF,        float,    lensing shear
+FIELD X12_sh_psf,     X12_SH_PSF,        float,    lensing shear
+FIELD X22_sh_psf,     X22_SH_PSF,        float,    lensing shear
+FIELD E1_sh_psf,      E1_SH_PSF,         float,    lensing shear
+FIELD E2_sh_psf,      E2_SH_PSF,         float,    lensing shear
+
+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 skyLimitRad,    SKY_LIMIT_RAD,     float,    profile to sky limit (radius)
+FIELD skyLimitFlux,   SKY_LIMIT_FLUX,    float,    profile to sky limit (flux)
+FIELD skyLimitSlope,  SKY_LIMIT_SLOPE,   float,    profile to sky limit (slope)
+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
+
+# 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
Index: /branches/eam_branches/ipp-20140610/Ohana/src/libautocode/def/lensing.d
===================================================================
--- /branches/eam_branches/ipp-20140610/Ohana/src/libautocode/def/lensing.d	(revision 36919)
+++ /branches/eam_branches/ipp-20140610/Ohana/src/libautocode/def/lensing.d	(revision 36920)
@@ -34,8 +34,8 @@
 FIELD fF_ApR5,       FLUX_FIL_AP_R5, float,          Flux inside r = 5
 
-FIELD  F_ApR6,       FLUX_AP_R6,     float,          Flux inside r = 5
-FIELD dF_ApR6,       FLUX_ERR_AP_R6, float,          Flux inside r = 5
-FIELD sF_ApR6,       FLUX_AP_R6,     float,          Flux inside r = 5
-FIELD fF_ApR6,       FLUX_AP_R6,     float,          Flux inside r = 5
+FIELD  F_ApR6,       FLUX_AP_R6,     float,          Flux inside r = 6
+FIELD dF_ApR6,       FLUX_ERR_AP_R6, float,          Flux inside r = 6
+FIELD sF_ApR6,       FLUX_STD_R6,    float,          Flux inside r = 6
+FIELD fF_ApR6,       FLUX_AP_R6,     float,          Flux inside r = 6
 
 FIELD   detID,          DET_ID,       unsigned int,   detection ID
