Index: /branches/eam_branches/ipp-20130307/Ohana/src/addstar/src/GetFileMode.c
===================================================================
--- /branches/eam_branches/ipp-20130307/Ohana/src/addstar/src/GetFileMode.c	(revision 35315)
+++ /branches/eam_branches/ipp-20130307/Ohana/src/addstar/src/GetFileMode.c	(revision 35316)
@@ -20,5 +20,8 @@
   havePHOT_VER = gfits_scan (header, "PHOT_VER", "%s", 1, ctmp);
   haveTARG_VER = gfits_scan (header, "TARG_VER", "%s", 1, ctmp);
-  if (havePHOT_VER && haveTARG_VER) return SDSS_OBJ;
+  if (havePHOT_VER && haveTARG_VER) {
+    if (VERBOSE) fprintf (stderr, "found SDSS objects\n");
+    return SDSS_OBJ;
+  }
 
   if (haveNaxis && (Naxis == 2)) {
@@ -28,6 +31,8 @@
     if ((Nx > 0) && (Ny > 0)) {
       if (haveCTYPE && !strcmp (&ctype[4], "-WRP")) {
+	if (VERBOSE) fprintf (stderr, "found MOSAIC CMP\n");
 	return MOSAIC_CMP;
       }
+      if (VERBOSE) fprintf (stderr, "found SIMPLE CMP\n");
       return SIMPLE_CMP;
     }
@@ -36,6 +41,8 @@
   if (haveNaxis && (TEXTMODE || !simple)) {
     if (haveCTYPE && !strcmp (&ctype[4], "-WRP")) {
+      if (VERBOSE) fprintf (stderr, "found MOSAIC CMP\n");
       return MOSAIC_CMP;
     }
+    if (VERBOSE) fprintf (stderr, "found SIMPLE CMP\n");
     return SIMPLE_CMP;
   }
@@ -43,21 +50,27 @@
   if (!extend && strcmp (&ctype[4], "-DIS")) {
     if (!strcmp (&ctype[4], "-WRP")) {
+      if (VERBOSE) fprintf (stderr, "found MOSAIC CMF\n");
       return MOSAIC_CMF;
     }
+    if (VERBOSE) fprintf (stderr, "found SIMPLE CMF\n");
     return SIMPLE_CMF;
   }
 
   if (!extend && !strcmp (&ctype[4], "-DIS")) {
+    if (VERBOSE) fprintf (stderr, "found MOSAIC PHU\n");
     return MOSAIC_PHU;
   }
 
   if (extend && strcmp (&ctype[4], "-DIS")) {
+    if (VERBOSE) fprintf (stderr, "found SIMPLE MEF\n");
     return SIMPLE_MEF;
   }
 
   if (extend && !strcmp (&ctype[4], "-DIS")) {
+    if (VERBOSE) fprintf (stderr, "found MOSAIC MEF\n");
     return MOSAIC_MEF;
   }
 
+  if (VERBOSE) fprintf (stderr, "extension type is unknown\n");
   return (NONE);
 }
Index: /branches/eam_branches/ipp-20130307/Ohana/src/addstar/src/MatchHeaders.c
===================================================================
--- /branches/eam_branches/ipp-20130307/Ohana/src/addstar/src/MatchHeaders.c	(revision 35315)
+++ /branches/eam_branches/ipp-20130307/Ohana/src/addstar/src/MatchHeaders.c	(revision 35316)
@@ -61,4 +61,9 @@
     if (!strcmp (exttype, "PS1_SV1")) goto keep;
     if (!strcmp (exttype, "PS1_SV2")) goto keep;
+    if (!strcmp (exttype, "PS1_DV3")) {
+      fprintf (stderr, "exttype, ..%s..\n", exttype);
+      goto keep;
+    }
+    fprintf (stderr, "exttype, ..%s..\n", exttype);
     continue;
 
Index: /branches/eam_branches/ipp-20130307/Ohana/src/addstar/src/ReadStarsFITS.c
===================================================================
--- /branches/eam_branches/ipp-20130307/Ohana/src/addstar/src/ReadStarsFITS.c	(revision 35315)
+++ /branches/eam_branches/ipp-20130307/Ohana/src/addstar/src/ReadStarsFITS.c	(revision 35316)
@@ -15,4 +15,5 @@
 Stars     *Convert_PS1_SV1_Alt	  PROTO((FTable *table, unsigned int *nstars));
 Stars     *Convert_PS1_SV2	  PROTO((FTable *table, unsigned int *nstars));
+Stars     *Convert_PS1_DV3        PROTO((FTable *table, unsigned int *nstars));
 
 // given a file with the pointer at the start of the table block and the 
@@ -78,4 +79,7 @@
     stars = Convert_PS1_SV2 (&table, &Nstars);
   }
+  if (!strcmp (type, "PS1_DV3")) {
+    stars = Convert_PS1_DV3 (&table, &Nstars);
+  }
   if (stars == NULL) {
     fprintf (stderr, "invalid table type %s\n", type);
@@ -962,3 +966,85 @@
 }
 
-
+Stars *Convert_PS1_DV3 (FTable *table, unsigned int *nstars) {
+
+  off_t Nstars; 
+  unsigned int i;
+  double ZeroPt;
+  Stars *stars;
+  CMF_PS1_DV3 *ps1data;
+
+  ps1data = gfits_table_get_CMF_PS1_DV3 (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.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-20130307/Ohana/src/libautocode/def/cmf-ps1-dv3.d
===================================================================
--- /branches/eam_branches/ipp-20130307/Ohana/src/libautocode/def/cmf-ps1-dv3.d	(revision 35316)
+++ /branches/eam_branches/ipp-20130307/Ohana/src/libautocode/def/cmf-ps1-dv3.d	(revision 35316)
@@ -0,0 +1,65 @@
+# name of structure type
+STRUCT  CMF_PS1_V3
+EXTNAME CMF_PS1_V3
+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-20130307/Ohana/src/libautocode/doc/cmf-ps1-dv3.c
===================================================================
--- /branches/eam_branches/ipp-20130307/Ohana/src/libautocode/doc/cmf-ps1-dv3.c	(revision 35316)
+++ /branches/eam_branches/ipp-20130307/Ohana/src/libautocode/doc/cmf-ps1-dv3.c	(revision 35316)
@@ -0,0 +1,302 @@
+# include "autocode.h"
+
+int gfits_convert_CMF_PS1_V3 (CMF_PS1_V3 *data, off_t size, off_t nitems) {
+
+  off_t i;
+  unsigned char *byte, tmp;
+
+  if (size != 224) { 
+    fprintf (stderr, "WARNING: mismatch in data types CMF_PS1_V3: "OFF_T_FMT" vs %d\n",  size,  224);
+    return (FALSE);
+  }
+
+  /* provide initial values to avoid compiler warnings for non-BYTE_SWAP arch */
+  i = tmp = 0;
+  byte = NULL;
+
+# ifdef BYTE_SWAP
+  byte = (unsigned char *) data;
+  for (i = 0; i < nitems; i++, byte += 224) {
+    /** 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); // PEAK_FLUX_AS_MAG
+    SWAP_WORD (68); // CAL_PSF_MAG
+    SWAP_WORD (72); // CAL_PSF_MAG_SIG
+    SWAP_DBLE (76); // RA_PSF
+    SWAP_DBLE (84); // DEC_PSF
+    SWAP_WORD (92); // SKY
+    SWAP_WORD (96); // SKY_SIGMA
+    SWAP_WORD (100); // PSF_CHISQ
+    SWAP_WORD (104); // CR_NSIGMA
+    SWAP_WORD (108); // EXT_NSIGMA
+    SWAP_WORD (112); // PSF_MAJOR
+    SWAP_WORD (116); // PSF_MINOR
+    SWAP_WORD (120); // PSF_THETA
+    SWAP_WORD (124); // PSF_QF
+    SWAP_WORD (128); // PSF_QF_PERFECT
+    SWAP_WORD (132); // PSF_NDOF
+    SWAP_WORD (136); // PSF_NPIX
+    SWAP_WORD (140); // MOMENTS_XX
+    SWAP_WORD (144); // MOMENTS_XY
+    SWAP_WORD (148); // MOMENTS_YY
+    SWAP_WORD (152); // MOMENTS_R1
+    SWAP_WORD (156); // MOMENTS_RH
+    SWAP_WORD (160); // KRON_FLUX
+    SWAP_WORD (164); // KRON_FLUX_ERR
+    SWAP_WORD (168); // KRON_FLUX_INNER
+    SWAP_WORD (172); // KRON_FLUX_OUTER
+    SWAP_WORD (176); // DIFF_NPOS
+    SWAP_WORD (180); // DIFF_FRATIO
+    SWAP_WORD (184); // DIFF_NRATIO_BAD
+    SWAP_WORD (188); // DIFF_NRATIO_MASK
+    SWAP_WORD (192); // DIFF_NRATIO_ALL
+    SWAP_WORD (196); // DIFF_R_P
+    SWAP_WORD (200); // DIFF_SN_P
+    SWAP_WORD (204); // DIFF_R_M
+    SWAP_WORD (208); // DIFF_SN_M
+    SWAP_WORD (212); // FLAGS
+    SWAP_WORD (216); // FLAGS2
+    SWAP_BYTE (220); // N_FRAMES
+    SWAP_BYTE (222); // PADDING
+  }
+# endif  
+
+  return (TRUE);
+} 
+
+/*** add test of EXTNAME and header-defined columns? ***/
+/* return internal structure representation */
+CMF_PS1_V3 *gfits_table_get_CMF_PS1_V3 (FTable *ftable, off_t *Ndata, char *swapped) {
+
+  int Ncols;
+  CMF_PS1_V3 *data;
+
+  Ncols = ftable[0].header[0].Naxis[0];
+  if (Ncols != 224) {
+    fprintf (stderr, "ERROR: mis-match in table size: width is %d but should be %d bytes\n", Ncols, 224);
+    return NULL;
+  }
+
+  *Ndata = ftable[0].header[0].Naxis[1];
+  data = (CMF_PS1_V3 *) ftable[0].buffer;
+  if ((swapped == NULL) || (*swapped == FALSE)) {
+    if (!gfits_convert_CMF_PS1_V3 (data, sizeof (CMF_PS1_V3), *Ndata)) {
+      return NULL;
+    }
+    gfits_table_scale_data (ftable);
+    if (swapped != NULL) *swapped = TRUE;
+  }
+  return (data);
+}
+
+int gfits_table_set_CMF_PS1_V3 (FTable *ftable, CMF_PS1_V3 *data, off_t Ndata) {
+
+  Header *header;
+
+  header = ftable[0].header;
+
+  /* create table header */
+  if (!gfits_create_table_header (header, "BINTABLE", "CMF_PS1_V3")) 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 fit",             "pixels",            1.0, 0.0);
+  gfits_define_bintable_column (header, "E",    "AP_FLUX",          "ap flux",                         "",                  1.0, 0.0);
+  gfits_define_bintable_column (header, "E",    "AP_FLUX_SIG",      "ap flux err",                     "",                  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",    "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",    "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_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_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, "J",    "DIFF_NPOS",        "diff param",                      "",                  1.0, 0.0);
+  gfits_define_bintable_column (header, "E",    "DIFF_FRATIO",      "diff param",                      "",                  1.0, 0.0);
+  gfits_define_bintable_column (header, "E",    "DIFF_NRATIO_BAD",  "diff param",                      "",                  1.0, 0.0);
+  gfits_define_bintable_column (header, "E",    "DIFF_NRATIO_MASK", "diff param",                      "",                  1.0, 0.0);
+  gfits_define_bintable_column (header, "E",    "DIFF_NRATIO_ALL",  "diff param",                      "",                  1.0, 0.0);
+  gfits_define_bintable_column (header, "E",    "DIFF_R_P",         "diff param",                      "",                  1.0, 0.0);
+  gfits_define_bintable_column (header, "E",    "DIFF_SN_P",        "diff param",                      "",                  1.0, 0.0);
+  gfits_define_bintable_column (header, "E",    "DIFF_R_M",         "diff param",                      "",                  1.0, 0.0);
+  gfits_define_bintable_column (header, "E",    "DIFF_SN_M",        "diff param",                      "",                  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_V3 (data, sizeof (CMF_PS1_V3), Ndata)) return (FALSE);
+  if (!gfits_add_rows (ftable, (char *) data, Ndata, sizeof (CMF_PS1_V3))) return (FALSE);
+
+  return (TRUE);
+}
+
+int gfits_table_mkheader_CMF_PS1_V3 (Header *header) {
+
+  /* create table header */
+  if (!gfits_create_table_header (header, "BINTABLE", "CMF_PS1_V3")) 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 fit",             "pixels",            1.0, 0.0);
+  gfits_define_bintable_column (header, "E",    "AP_FLUX",          "ap flux",                         "",                  1.0, 0.0);
+  gfits_define_bintable_column (header, "E",    "AP_FLUX_SIG",      "ap flux err",                     "",                  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",    "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",    "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_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_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, "J",    "DIFF_NPOS",        "diff param",                      "",                  1.0, 0.0);
+  gfits_define_bintable_column (header, "E",    "DIFF_FRATIO",      "diff param",                      "",                  1.0, 0.0);
+  gfits_define_bintable_column (header, "E",    "DIFF_NRATIO_BAD",  "diff param",                      "",                  1.0, 0.0);
+  gfits_define_bintable_column (header, "E",    "DIFF_NRATIO_MASK", "diff param",                      "",                  1.0, 0.0);
+  gfits_define_bintable_column (header, "E",    "DIFF_NRATIO_ALL",  "diff param",                      "",                  1.0, 0.0);
+  gfits_define_bintable_column (header, "E",    "DIFF_R_P",         "diff param",                      "",                  1.0, 0.0);
+  gfits_define_bintable_column (header, "E",    "DIFF_SN_P",        "diff param",                      "",                  1.0, 0.0);
+  gfits_define_bintable_column (header, "E",    "DIFF_R_M",         "diff param",                      "",                  1.0, 0.0);
+  gfits_define_bintable_column (header, "E",    "DIFF_SN_M",        "diff param",                      "",                  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_V3 (int device, CMF_PS1_V3 *data, int Ndata, int copy) {
+
+  int Nwrite, Nbytes;
+  CMF_PS1_V3 *tmpdata;
+
+  Nbytes = Ndata * sizeof (CMF_PS1_V3);
+
+  if (copy) {
+    ALLOCATE (tmpdata, CMF_PS1_V3, Ndata);
+    memcpy (tmpdata, data, Nbytes);
+  } else {
+    tmpdata = data;
+  }
+
+  if (!gfits_convert_CMF_PS1_V3 (tmpdata, sizeof (CMF_PS1_V3), Ndata)) 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_V3 (int device, CMF_PS1_V3 **data, int *Ndata) {
+
+  int ndata;
+  IOBuffer message;
+  CMF_PS1_V3 *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_V3 *) message.buffer;
+  if (!gfits_convert_CMF_PS1_V3 (tmpdata, sizeof (CMF_PS1_V3), ndata)) return (FALSE);
+
+  /* double-check data length? */
+  /* perform handshaking? */
+
+  *Ndata = ndata;
+  *data = tmpdata;
+
+  return (TRUE);
+}
Index: /branches/eam_branches/ipp-20130307/Ohana/src/libautocode/doc/cmf-ps1-dv3.h
===================================================================
--- /branches/eam_branches/ipp-20130307/Ohana/src/libautocode/doc/cmf-ps1-dv3.h	(revision 35316)
+++ /branches/eam_branches/ipp-20130307/Ohana/src/libautocode/doc/cmf-ps1-dv3.h	(revision 35316)
@@ -0,0 +1,66 @@
+
+/** 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 fit (pixels)
+  float            apFlux;               // ap flux
+  float            apFluxErr;            // ap flux err
+  float            Mpeak;                // peak flux as a mag (mags)
+  float            Mcalib;               // calibrated psf mag (mags)
+  float            dMcal;                // zero point scatter (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            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            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)
+  int              D_Npos;               // diff param
+  float            D_Fratio;             // diff param
+  float            D_Nratio_bad;         // diff param
+  float            D_Nratio_mask;        // diff param
+  float            D_Nratio_all;         // diff param
+  float            D_Rp;                 // diff param
+  float            D_SNp;                // diff param
+  float            D_Rm;                 // diff param
+  float            D_SNm;                // diff param
+  int              flags;                // analysis flags
+  int              flags2;               // analysis flags (2)
+  short            nFrames;              // images overlapping peak
+  short            padding;              // padding for 8byte records
+} CMF_PS1_V3;
+
+CMF_PS1_V3 *gfits_table_get_CMF_PS1_V3 (FTable *table, off_t *Ndata, char *swapped);
+int      gfits_table_set_CMF_PS1_V3 (FTable *ftable, CMF_PS1_V3 *data, off_t Ndata);
+int      gfits_table_mkheader_CMF_PS1_V3 (Header *header);
+int      gfits_convert_CMF_PS1_V3 (CMF_PS1_V3 *data, off_t size, off_t nitems);
+int      Send_CMF_PS1_V3 (int device, CMF_PS1_V3 *data, int Ndata, int copy);
+int      Recv_CMF_PS1_V3 (int device, CMF_PS1_V3 **data, int *Ndata);
Index: /branches/eam_branches/ipp-20130307/Ohana/src/libdvo/Makefile
===================================================================
--- /branches/eam_branches/ipp-20130307/Ohana/src/libdvo/Makefile	(revision 35315)
+++ /branches/eam_branches/ipp-20130307/Ohana/src/libdvo/Makefile	(revision 35316)
@@ -36,5 +36,6 @@
 $(DESTINC)/ps1_v3_defs.h \
 $(DESTINC)/ps1_v4_defs.h \
-$(DESTINC)/ps1_ref_defs.h
+$(DESTINC)/ps1_ref_defs.h \
+$(DESTINC)/cmf-ps1-dv3.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
@@ -84,4 +85,5 @@
 $(SRC)/cmf-ps1-v1-alt.$(ARCH).o \
 $(SRC)/cmf-ps1-sv1-alt.$(ARCH).o \
+$(SRC)/cmf-ps1-dv3.$(ARCH).o \
 $(SRC)/dvo_util.$(ARCH).o \
 $(SRC)/dbBooleanCond.$(ARCH).o		\
Index: /branches/eam_branches/ipp-20130307/Ohana/src/libdvo/include/cmf-ps1-dv3.h
===================================================================
--- /branches/eam_branches/ipp-20130307/Ohana/src/libdvo/include/cmf-ps1-dv3.h	(revision 35316)
+++ /branches/eam_branches/ipp-20130307/Ohana/src/libdvo/include/cmf-ps1-dv3.h	(revision 35316)
@@ -0,0 +1,61 @@
+
+/** 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 fit (pixels)
+  float            apFlux;               // ap flux
+  float            apFluxErr;            // ap flux err
+  float            Mpeak;                // peak flux as a mag (mags)
+  float            Mcalib;               // calibrated psf mag (mags)
+  float            dMcal;                // zero point scatter (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            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            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)
+  int              D_Npos;               // diff param
+  float            D_Fratio;             // diff param
+  float            D_Nratio_bad;         // diff param
+  float            D_Nratio_mask;        // diff param
+  float            D_Nratio_all;         // diff param
+  float            D_Rp;                 // diff param
+  float            D_SNp;                // diff param
+  float            D_Rm;                 // diff param
+  float            D_SNm;                // diff param
+  int              flags;                // analysis flags
+  int              flags2;               // analysis flags (2)
+  short            nFrames;              // images overlapping peak
+  short            padding;              // padding for 8byte records
+} CMF_PS1_DV3;
+
+CMF_PS1_DV3 *gfits_table_get_CMF_PS1_DV3 (FTable *table, off_t *Ndata, char *swapped);
Index: /branches/eam_branches/ipp-20130307/Ohana/src/libdvo/include/dvo.h
===================================================================
--- /branches/eam_branches/ipp-20130307/Ohana/src/libdvo/include/dvo.h	(revision 35315)
+++ /branches/eam_branches/ipp-20130307/Ohana/src/libdvo/include/dvo.h	(revision 35316)
@@ -288,4 +288,7 @@
 CMF_PS1_SV1 *gfits_table_get_CMF_PS1_SV1_Alt (FTable *ftable, off_t *Ndata, char *swapped);
 
+// another special case : does not match byte-boundaries
+# include "cmf-ps1-dv3.h"
+
 typedef struct {
   int Ncode;					  // number of photcodes
Index: /branches/eam_branches/ipp-20130307/Ohana/src/libdvo/src/cmf-ps1-dv3.c
===================================================================
--- /branches/eam_branches/ipp-20130307/Ohana/src/libdvo/src/cmf-ps1-dv3.c	(revision 35316)
+++ /branches/eam_branches/ipp-20130307/Ohana/src/libdvo/src/cmf-ps1-dv3.c	(revision 35316)
@@ -0,0 +1,181 @@
+# include "dvo.h"
+
+/*** note : this file is derived from the autocode version, but is modified because
+     the forma does not match with structure byte boundaries ***/
+
+/* if we are not correctly including the ohana headers, this will fail */
+# ifndef BYTE_SWAP
+# ifndef NOT_BYTE_SWAP
+# error "neither BYTE_SWAP not NOT_BYTE_SWAP is set"
+# endif
+# endif
+
+# define FT_SIZE 224
+CMF_PS1_DV3 *gfits_table_get_CMF_PS1_DV3 (FTable *ftable, off_t *Ndata, char *swapped) {
+
+  off_t i, nitems;
+  unsigned char *byte, *inbyte, *otbyte, tmp;
+  CMF_PS1_DV3 *output;
+
+  /* provide initial values to avoid compiler warnings for non-BYTE_SWAP arch */
+  i = tmp = 0;
+  byte = NULL;
+
+  // this function is a special case : it must have Nx = FT_SIZE
+  if (ftable[0].header[0].Naxis[0] != FT_SIZE) { 
+    fprintf (stderr, "ERROR: wrong format for CMF_PS1_DV3: "OFF_T_FMT" vs %d\n",  ftable[0].header[0].Naxis[0], FT_SIZE);
+    return (NULL);
+  }
+
+  *Ndata = ftable[0].header[0].Naxis[1];
+  nitems = ftable[0].header[0].Naxis[1];
+
+  if ((swapped == NULL) || (*swapped == FALSE)) {
+
+    // the byte table below is generated by libautocode/def/cmf-ps1-dv3.d.
+    // the table dv3.d matches the input FITS table layout.  
+    // the byte order in that file follows the list below.
+# ifdef BYTE_SWAP
+      // we need to do the byte swap before applying the table scaling:
+      byte = (unsigned char *) ftable[0].buffer;
+      for (i = 0; i < nitems; i++, byte += FT_SIZE) {
+        /** 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); // PEAK_FLUX_AS_MAG
+        SWAP_WORD (68); // CAL_PSF_MAG
+        SWAP_WORD (72); // CAL_PSF_MAG_SIG
+        SWAP_DBLE (76); // RA_PSF
+        SWAP_DBLE (84); // DEC_PSF
+        SWAP_WORD (92); // SKY
+        SWAP_WORD (96); // SKY_SIGMA
+        SWAP_WORD (100); // PSF_CHISQ
+        SWAP_WORD (104); // CR_NSIGMA
+        SWAP_WORD (108); // EXT_NSIGMA
+        SWAP_WORD (112); // PSF_MAJOR
+        SWAP_WORD (116); // PSF_MINOR
+        SWAP_WORD (120); // PSF_THETA
+        SWAP_WORD (124); // PSF_QF
+        SWAP_WORD (128); // PSF_QF_PERFECT
+        SWAP_WORD (132); // PSF_NDOF
+        SWAP_WORD (136); // PSF_NPIX
+        SWAP_WORD (140); // MOMENTS_XX
+        SWAP_WORD (144); // MOMENTS_XY
+        SWAP_WORD (148); // MOMENTS_YY
+        SWAP_WORD (152); // MOMENTS_R1
+        SWAP_WORD (156); // MOMENTS_RH
+        SWAP_WORD (160); // KRON_FLUX
+        SWAP_WORD (164); // KRON_FLUX_ERR
+        SWAP_WORD (168); // KRON_FLUX_INNER
+        SWAP_WORD (172); // KRON_FLUX_OUTER
+        SWAP_WORD (176); // DIFF_NPOS
+        SWAP_WORD (180); // DIFF_FRATIO
+        SWAP_WORD (184); // DIFF_NRATIO_BAD
+        SWAP_WORD (188); // DIFF_NRATIO_MASK
+        SWAP_WORD (192); // DIFF_NRATIO_ALL
+        SWAP_WORD (196); // DIFF_R_P
+        SWAP_WORD (200); // DIFF_SN_P
+        SWAP_WORD (204); // DIFF_R_M
+        SWAP_WORD (208); // DIFF_SN_M
+        SWAP_WORD (212); // FLAGS
+        SWAP_WORD (216); // FLAGS2
+        SWAP_BYTE (220); // N_FRAMES
+        SWAP_BYTE (222); // PADDING
+      }
+# endif  
+
+      gfits_table_scale_data (ftable);
+      if (swapped != NULL) *swapped = TRUE;
+  }
+
+  byte = (unsigned char *) ftable[0].buffer;
+
+  // allocate a new output data buffer
+  ALLOCATE (output, CMF_PS1_DV3, nitems);
+  inbyte = (unsigned char *) byte;
+  otbyte = (unsigned char *) output;
+
+  // the data in the input table does not line up with the output structure: copy carefully.
+  int ST_SIZE = sizeof(CMF_PS1_DV3);
+  for (i = 0; i < nitems; i++, inbyte += FT_SIZE, otbyte += ST_SIZE) {
+    memcpy (&otbyte[  0], &inbyte[  0],  76); // IPP_IDET to CAL_PSF_MAG_SIG
+    memcpy (&otbyte[ 80], &inbyte[ 76], 148); // RA_PSF to PADDING
+  }
+
+  free (ftable[0].buffer);
+  ftable[0].buffer = (char *) output;
+
+  return (output);
+} 
+
+// data organization (input vs output)
+//              FITS                       struct
+// WORD  0      IPP_IDET              0    IPP_IDET                   
+// WORD  4      X_PSF                 4    X_PSF                           
+// WORD  8      Y_PSF                 8    Y_PSF                           
+// WORD  12     X_PSF_SIG             12   X_PSF_SIG               
+// WORD  16     Y_PSF_SIG             16   Y_PSF_SIG               
+// WORD  20     POSANGLE              20   POSANGLE                
+// WORD  24     PLTSCALE              24   PLTSCALE                
+// WORD  28     PSF_INST_MAG          28   PSF_INST_MAG            
+// WORD  32     PSF_INST_MAG_SIG      32   PSF_INST_MAG_SIG        
+// WORD  36     PSF_INST_FLUX         36   PSF_INST_FLUX                   
+// WORD  40     PSF_INST_FLUX_SIG     40   PSF_INST_FLUX_SIG       
+// WORD  44     AP_MAG                44   AP_MAG                          
+// WORD  48     AP_MAG_RAW            48   AP_MAG_RAW              
+// WORD  52     AP_MAG_RADIUS         52   AP_MAG_RADIUS                   
+// WORD  56     AP_FLUX               56   AP_FLUX                         
+// WORD  60     AP_FLUX_SIG           60   AP_FLUX_SIG             
+// WORD  64     PEAK_FLUX_AS_MAG      64   PEAK_FLUX_AS_MAG        
+// WORD  68     CAL_PSF_MAG           68   CAL_PSF_MAG             
+// WORD  72     CAL_PSF_MAG_SIG       72   CAL_PSF_MAG_SIG                 
+// DBLE  76     RA_PSF                80   RA_PSF                          
+// DBLE  84     DEC_PSF               88   DEC_PSF                         
+// WORD  92     SKY                   96   SKY                     
+// WORD  96     SKY_SIGMA             100  SKY_SIGMA               
+// WORD  100    PSF_CHISQ             104  PSF_CHISQ               
+// WORD  104    CR_NSIGMA             108  CR_NSIGMA               
+// WORD  108    EXT_NSIGMA            112  EXT_NSIGMA              
+// WORD  112    PSF_MAJOR             116  PSF_MAJOR               
+// WORD  116    PSF_MINOR             120  PSF_MINOR               
+// WORD  120    PSF_THETA             124  PSF_THETA               
+// WORD  124    PSF_QF                128  PSF_QF                          
+// WORD  128    PSF_QF_PERFECT        132  PSF_QF_PERFECT                  
+// WORD  132    PSF_NDOF              136  PSF_NDOF                
+// WORD  136    PSF_NPIX              140  PSF_NPIX                
+// WORD  140    MOMENTS_XX            144  MOMENTS_XX              
+// WORD  144    MOMENTS_XY            148  MOMENTS_XY              
+// WORD  148    MOMENTS_YY            152  MOMENTS_YY              
+// WORD  152    MOMENTS_R1            156  MOMENTS_R1              
+// WORD  156    MOMENTS_RH            160  MOMENTS_RH              
+// WORD  160    KRON_FLUX             164  KRON_FLUX               
+// WORD  164    KRON_FLUX_ERR         168  KRON_FLUX_ERR                   
+// WORD  168    KRON_FLUX_INNER       172  KRON_FLUX_INNER                 
+// WORD  172    KRON_FLUX_OUTER       176  KRON_FLUX_OUTER                 
+// WORD  176    DIFF_NPOS             180  DIFF_NPOS               
+// WORD  180    DIFF_FRATIO           184  DIFF_FRATIO             
+// WORD  184    DIFF_NRATIO_BAD       188  DIFF_NRATIO_BAD                 
+// WORD  188    DIFF_NRATIO_MASK      192  DIFF_NRATIO_MASK        
+// WORD  192    DIFF_NRATIO_ALL       196  DIFF_NRATIO_ALL                 
+// WORD  196    DIFF_R_P              200  DIFF_R_P                
+// WORD  200    DIFF_SN_P             204  DIFF_SN_P               
+// WORD  204    DIFF_R_M              208  DIFF_R_M                
+// WORD  208    DIFF_SN_M             212  DIFF_SN_M               
+// WORD  212    FLAGS                 216  FLAGS                           
+// WORD  216    FLAGS2                220  FLAGS2                          
+// BYTE  220    N_FRAMES              224  N_FRAMES                
+// BYTE  222    PADDING               226  PADDING                         
Index: /branches/eam_branches/ipp-20130307/Ohana/src/opihi/cmd.data/Makefile
===================================================================
--- /branches/eam_branches/ipp-20130307/Ohana/src/opihi/cmd.data/Makefile	(revision 35315)
+++ /branches/eam_branches/ipp-20130307/Ohana/src/opihi/cmd.data/Makefile	(revision 35316)
@@ -150,4 +150,5 @@
 $(SRC)/vsmooth.$(ARCH).o	   \
 $(SRC)/vstats.$(ARCH).o		   \
+$(SRC)/xsection.$(ARCH).o          \
 $(SRC)/wd.$(ARCH).o		   \
 $(SRC)/write_vectors.$(ARCH).o	   \
Index: /branches/eam_branches/ipp-20130307/Ohana/src/opihi/cmd.data/init.c
===================================================================
--- /branches/eam_branches/ipp-20130307/Ohana/src/opihi/cmd.data/init.c	(revision 35315)
+++ /branches/eam_branches/ipp-20130307/Ohana/src/opihi/cmd.data/init.c	(revision 35316)
@@ -141,4 +141,5 @@
 int wd               PROTO((int, char **));
 int write_vectors    PROTO((int, char **));
+int xsection         PROTO((int, char **));
 int zap              PROTO((int, char **));
 int zplot            PROTO((int, char **));
@@ -299,4 +300,5 @@
   {1, "wd",           wd,               "write an image to a file"},
   {1, "write",        write_vectors,    "write vectors to datafile"},
+  {1, "xsection",     xsection,         "generate cross-section histogram for an image (or region)"},
   {1, "zap",          zap,              "assign values to pixel regions"},
   {1, "zplot",        zplot,            "plot x y with size scaled by z"},
Index: /branches/eam_branches/ipp-20130307/Ohana/src/opihi/cmd.data/xsection.c
===================================================================
--- /branches/eam_branches/ipp-20130307/Ohana/src/opihi/cmd.data/xsection.c	(revision 35316)
+++ /branches/eam_branches/ipp-20130307/Ohana/src/opihi/cmd.data/xsection.c	(revision 35316)
@@ -0,0 +1,109 @@
+# include "data.h"
+
+// take an image and accumulate a histogram in some direction
+int xsection (int argc, char **argv) {
+  
+  int i, j, N, Nbins;
+  int sx, sy, nx, ny, bin;
+  int *vecN;
+  float *V, delta;
+  Vector *vec1, *vec2;
+  Buffer *buf;
+
+ // int Quiet = FALSE;
+ // if ((N = get_argument (argc, argv, "-q"))) {
+ //   Quiet = TRUE;
+ //   remove_argument (N, &argc, argv);
+ // }
+ // if ((N = get_argument (argc, argv, "-quiet"))) {
+ //   Quiet = TRUE;
+ //   remove_argument (N, &argc, argv);
+ // }
+
+  delta = 1.0;
+  if ((N = get_argument (argc, argv, "-delta"))) {
+    remove_argument (N, &argc, argv);
+    delta = atof (argv[N]);
+    remove_argument (N, &argc, argv);
+  }
+
+  sx = sy = 0.0;
+  nx = ny = 0.0;
+  if ((N = get_argument (argc, argv, "-region"))) {
+    remove_argument (N, &argc, argv);
+    sx = atof (argv[N]);
+    remove_argument (N, &argc, argv);
+    sy = atof (argv[N]);
+    remove_argument (N, &argc, argv);
+    nx = atof (argv[N]);
+    remove_argument (N, &argc, argv);
+    ny = atof (argv[N]);
+    remove_argument (N, &argc, argv);
+  }
+
+  if (argc != 5) {
+    gprint (GP_ERR, "USAGE: xsection <buffer> <x> <y> (angle) [-region sx sy nx ny] [-delta binsize]\n");
+    return (FALSE);
+  }
+
+  if ((buf = SelectBuffer (argv[1], OLDBUFFER, TRUE)) == NULL) return (FALSE);
+  
+  int Nx = buf[0].matrix.Naxis[0];
+  int Ny = buf[0].matrix.Naxis[1];
+
+  /* if either range is set to zero, use the rest of the chip */
+  if (nx == 0) nx = Nx - sx;
+  if (ny == 0) ny = Ny - sy;
+
+  if ((sx < 0) || (sy < 0) || (sx+nx > Nx) || (sy+ny > Ny)) {
+    gprint (GP_ERR, "region out of range\n");
+    return (FALSE);
+  }
+
+
+  // center coords are center of the region
+  float Xo = sx + 0.5*nx;
+  float Yo = sy + 0.5*ny;
+
+  float angle = atof(argv[4]);
+  float secant = MAX(2.0*fabs(cos(angle*RAD_DEG)/Nx), 2.0*fabs(sin(angle*RAD_DEG)/Ny));
+  float range = 1.1 / secant;
+
+  Nbins = 2*range / delta;
+
+  if ((vec1 = SelectVector (argv[2], ANYVECTOR, TRUE)) == NULL) return (FALSE);
+  if ((vec2 = SelectVector (argv[3], ANYVECTOR, TRUE)) == NULL) return (FALSE);
+
+  ResetVector (vec1, OPIHI_FLT, Nbins + 1);
+  ResetVector (vec2, OPIHI_FLT, Nbins + 1);
+  bzero (vec1[0].elements.Flt, vec1[0].Nelements*sizeof(opihi_flt));
+  bzero (vec2[0].elements.Flt, vec2[0].Nelements*sizeof(opihi_flt));
+  
+  V = (float *)buf[0].matrix.buffer;
+
+  float dx = cos(angle*RAD_DEG);
+  float dy = sin(angle*RAD_DEG);
+
+  ALLOCATE (vecN, int, Nbins + 1);
+  memset (vecN, 0, (Nbins + 1)*sizeof(int));
+
+  for (j = sy; j < sy + ny; j++) {
+    float dY = (j - Yo);
+    for (i = sx; i < sx + nx; i++) {
+      float value = V[i*Nx + j];
+      if (!isfinite(value)) continue;
+      float dX = (i - Xo);
+      float L = (dX * dx) + (dY * dy);
+      bin = MAX (MIN (Nbins, (L / delta) + 0.5*Nbins), 0);
+      vec2[0].elements.Flt[bin] += value;
+      vecN[bin] ++;
+    }
+  }
+  for (i = 0; i < Nbins + 1; i++) {
+    vec1[0].elements.Flt[i] = (i - 0.5*Nbins)*delta;
+    vec2[0].elements.Flt[i] /= (float) vecN[i];
+  }
+  
+  return (TRUE);
+}
+
