Index: /branches/eam_branches/ipp-20131211/Ohana/src/libdvo/include/dvo.h
===================================================================
--- /branches/eam_branches/ipp-20131211/Ohana/src/libdvo/include/dvo.h	(revision 36407)
+++ /branches/eam_branches/ipp-20131211/Ohana/src/libdvo/include/dvo.h	(revision 36408)
@@ -387,4 +387,61 @@
 } MeasureTiny;
 
+
+/** STRUCT DEFINITION **/
+typedef struct {
+  float            dR;                   // RA offset (arcsec)
+  float            dD;                   // DEC offset (arcsec)
+  float            M;                    // catalog mag (mag)
+  float            Mcal;                 // image cal mag (mag)
+  float            Map;                  // aperture mag (mag)
+  float            Mkron;                // kron magnitude (mag)
+  float            dMkron;               // kron magnitude error (mag)
+  float            dM;                   // mag error (mag)
+  float            dMcal;                // systematic calibration error (mag)
+  float            dt;                   // exposure time (2.5*log(exptime))
+  float            FluxPSF;              // flux from psf fit (counts/sec?)
+  float            dFluxPSF;             // error on psf flux (counts/sec?)
+  float            FluxKron;             // flux from kron ap (counts/sec?)
+  float            dFluxKron;            // error on kron flux (counts/sec?)
+  float            airmass;              // (airmass - 1) (airmass)
+  float            az;                   // telescope azimuth
+  float            Xccd;                 // X coord on chip (raw value) (pixels)
+  float            Yccd;                 // Y coord on chip (raw value) (pixels)
+  float            Sky;                  // local estimate of sky flux (counts/sec)
+  float            dSky;                 // local estimate of sky flux (counts/sec)
+  int              t;                    // time in seconds (UNIX)
+  unsigned int     averef;               // reference to average entry      
+  unsigned int     detID;                // detection ID
+  unsigned int     imageID;              // reference to DVO image ID
+  unsigned int     objID;                // unique ID for object in table
+  unsigned int     catID;                // unique ID for table in which object was first realized
+  uint64_t         extID;                // external ID (eg PSPS detID)
+  float            psfQF;                // psf coverage/quality factor
+  float            psfQFperf;            // psf coverage / quality factor (all mask bits)
+  float            psfChisq;             // psf fit chisq
+  int              psfNdof;              // psf degrees of freedom
+  int              psfNpix;              // psf number of pixels
+  float            crNsigma;             // Nsigma deviation towards CR
+  float            extNsigma;            // Nsigma deviation towards EXT
+  short            FWx;                  // object fwhm major axis (1/100 of pixels)
+  short            FWy;                  // object fwhm minor axis (1/100 of pixels )
+  short            theta;                // angle wrt ccd X dir ((0xffff/360) deg)
+  short            Mxx;                  // second moments in pixel coords (1/100 of pixels)
+  short            Mxy;                  // second moments in pixel coords (1/100 of pixels)
+  short            Myy;                  // second moments in pixel coords (1/100 of pixels)
+  unsigned short   t_msec;               // time fraction of second (milliseconds)
+  unsigned short   photcode;             // photcode
+  short            dXccd;                // X coord error on chip (1/100 of pixels)
+  short            dYccd;                // Y coord error on chip (1/100 of pixels)
+  short            dRsys;                // systematic error from astrom (1/100 of pixels)
+  short            posangle;             // position angle sky to chip ((0xffff/360) deg)
+  float            pltscale;             // plate scale (arcsec/pixel)
+  unsigned int     dbFlags;              // flags supplied by analysis in database
+  unsigned int     photFlags;            // flags supplied by photometry program
+} Measure_PS1_V4alt;
+
+Measure_PS1_V4alt *gfits_table_get_Measure_PS1_V4alt (FTable *table, off_t *Ndata, char *swapped);
+Measure *Measure_PS1_V4alt_ToInternal (Measure_PS1_V4alt *in, off_t Nvalues);
+
 /* a catalog contains this data */
 typedef struct Catalog {
Index: /branches/eam_branches/ipp-20131211/Ohana/src/libdvo/src/dvo_convert.c
===================================================================
--- /branches/eam_branches/ipp-20131211/Ohana/src/libdvo/src/dvo_convert.c	(revision 36407)
+++ /branches/eam_branches/ipp-20131211/Ohana/src/libdvo/src/dvo_convert.c	(revision 36408)
@@ -154,4 +154,19 @@
     fprintf (stderr, "EXTNAME missing for measure table\n");
     return (FALSE);
+  }
+
+  // block to convert broken tables (PS1_V4 made before the Xfix addition)
+  if (!strcmp (extname, "DVO_MEASURE_PS1_V4") && (ftable[0].header[0].Naxis[0] == 176)) {
+    fprintf (stderr, "reading alt PS1_V4 format\n");
+    Measure_PS1_V4alt *tmpMeasure;
+    tmpMeasure = gfits_table_get_Measure_PS1_V4alt (ftable, Nmeasure, NULL);
+    if (!tmpMeasure) {
+      fprintf (stderr, "ERROR: failed to read measures\n");
+      exit (2);
+    }
+    measure = Measure_PS1_V4alt_ToInternal (tmpMeasure, *Nmeasure);
+    free (tmpMeasure);
+    *format = DVO_FORMAT_PS1_V4;
+    return (measure); 
   }
 
Index: /branches/eam_branches/ipp-20131211/Ohana/src/libdvo/src/dvo_convert_PS1_V4.c
===================================================================
--- /branches/eam_branches/ipp-20131211/Ohana/src/libdvo/src/dvo_convert_PS1_V4.c	(revision 36407)
+++ /branches/eam_branches/ipp-20131211/Ohana/src/libdvo/src/dvo_convert_PS1_V4.c	(revision 36408)
@@ -481,2 +481,168 @@
   return (out);
 }
+
+/*** there are some mini dvodbs with the wrong PS1_V4 format (missing Xoff,Yoff / Xfix,Yfix) ************/
+
+Measure *Measure_PS1_V4alt_ToInternal (Measure_PS1_V4alt *in, off_t Nvalues) {
+
+  off_t i;
+  Measure *out;
+
+  ALLOCATE_ZERO (out, Measure, Nvalues);
+
+  for (i = 0; i < Nvalues; i++) {
+    dvo_measure_init (&out[i]);
+
+    out[i].dR         = in[i].dR;
+    out[i].dD         = in[i].dD;
+    out[i].M          = in[i].M;
+    out[i].Mcal       = in[i].Mcal;
+    out[i].Map        = in[i].Map;
+    out[i].Mkron      = in[i].Mkron;
+    out[i].dMkron     = in[i].dMkron;
+    out[i].dM         = in[i].dM;
+    out[i].dMcal      = in[i].dMcal;
+    out[i].dt         = in[i].dt;
+    out[i].FluxPSF    = in[i].FluxPSF;
+    out[i].dFluxPSF   = in[i].dFluxPSF;
+    out[i].FluxKron   = in[i].FluxKron;
+    out[i].dFluxKron  = in[i].dFluxKron;
+    out[i].airmass    = in[i].airmass;
+    out[i].az         = in[i].az;
+    out[i].Xccd       = in[i].Xccd;
+    out[i].Yccd       = in[i].Yccd;
+    out[i].Xfix       = in[i].Xccd;
+    out[i].Yfix       = in[i].Yccd;
+    out[i].Sky        = in[i].Sky;
+    out[i].dSky       = in[i].dSky;
+    out[i].t          = in[i].t;
+    out[i].t_msec     = in[i].t_msec;
+    out[i].averef     = in[i].averef;
+    out[i].detID      = in[i].detID;
+    out[i].imageID    = in[i].imageID;
+    out[i].objID      = in[i].objID;
+    out[i].catID      = in[i].catID;
+    out[i].extID      = in[i].extID;
+    out[i].psfQF      = in[i].psfQF;
+    out[i].psfQFperf  = in[i].psfQFperf;
+    out[i].psfChisq   = in[i].psfChisq;
+    out[i].psfNdof    = in[i].psfNdof;
+    out[i].psfNpix    = in[i].psfNpix;
+    out[i].crNsigma   = in[i].crNsigma;
+    out[i].extNsigma  = in[i].extNsigma;
+    out[i].FWx 	      = in[i].FWx;
+    out[i].FWy 	      = in[i].FWy;
+    out[i].theta      = in[i].theta;
+    out[i].Mxx 	      = in[i].Mxx;
+    out[i].Mxy 	      = in[i].Mxy;
+    out[i].Myy 	      = in[i].Myy;
+    out[i].dXccd      = in[i].dXccd;
+    out[i].dYccd      = in[i].dYccd;
+    out[i].dRsys      = in[i].dRsys;
+    out[i].posangle   = in[i].posangle;
+    out[i].pltscale   = in[i].pltscale;
+    out[i].photcode   = in[i].photcode;
+    out[i].dbFlags    = in[i].dbFlags;
+    out[i].photFlags  = in[i].photFlags;
+  }
+  return (out);
+}
+
+int gfits_convert_Measure_PS1_V4alt (Measure_PS1_V4alt *data, off_t size, off_t nitems) {
+
+  off_t i;
+  unsigned char *byte, tmp;
+
+  if (size != 176) { 
+    fprintf (stderr, "WARNING: mismatch in data types Measure_PS1_V4alt: "OFF_T_FMT" vs %d\n",  size,  176);
+    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 += 176) {
+    /** BYTE SWAP **/
+    SWAP_WORD (0); // D_RA
+    SWAP_WORD (4); // D_DEC
+    SWAP_WORD (8); // MAG
+    SWAP_WORD (12); // M_CAL
+    SWAP_WORD (16); // M_APER
+    SWAP_WORD (20); // M_KRON
+    SWAP_WORD (24); // M_KRON_ERR
+    SWAP_WORD (28); // MAG_ERR
+    SWAP_WORD (32); // MAG_CAL_ERR
+    SWAP_WORD (36); // M_TIME
+    SWAP_WORD (40); // FLUX_PSF
+    SWAP_WORD (44); // FLUX_PSF_ERR
+    SWAP_WORD (48); // FLUX_KRON
+    SWAP_WORD (52); // FLUX_KRON_ERR
+    SWAP_WORD (56); // AIRMASS
+    SWAP_WORD (60); // AZ
+    SWAP_WORD (64); // X_CCD
+    SWAP_WORD (68); // Y_CCD
+    SWAP_WORD (72); // SKY_FLUX	   
+    SWAP_WORD (76); // SKY_FLUX_ERR
+    SWAP_WORD (80); // TIME
+    SWAP_WORD (84); // AVE_REF
+    SWAP_WORD (88); // DET_ID
+    SWAP_WORD (92); // IMAGE_ID
+    SWAP_WORD (96); // OBJ_ID
+    SWAP_WORD (100); // CAT_ID
+    SWAP_DBLE (104); // EXT_ID
+    SWAP_WORD (112); // PSF_QF	      
+    SWAP_WORD (116); // PSF_QF_PERFECT 
+    SWAP_WORD (120); // PSF_CHISQ     
+    SWAP_WORD (124); // PSF_NDOF      
+    SWAP_WORD (128); // PSF_NPIX      
+    SWAP_WORD (132); // CR_NSIGMA     
+    SWAP_WORD (136); // EXT_NSIGMA    
+    SWAP_BYTE (140); // FWHM_MAJOR 
+    SWAP_BYTE (142); // FWHM_MINOR 
+    SWAP_BYTE (144); // PSF_THETA  
+    SWAP_BYTE (146); // MXX	   
+    SWAP_BYTE (148); // MXY	   
+    SWAP_BYTE (150); // MYY	   
+    SWAP_BYTE (152); // TIME_MSEC  
+    SWAP_BYTE (154); // PHOTCODE   
+    SWAP_BYTE (156); // X_CCD_ERR  
+    SWAP_BYTE (158); // Y_CCD_ERR  
+    SWAP_BYTE (160); // POS_SYS_ERR
+    SWAP_BYTE (162); // POSANGLE   
+    SWAP_WORD (164); // PLTSCALE  
+    SWAP_WORD (168); // DB_FLAGS  
+    SWAP_WORD (172); // PHOT_FLAGS
+  }
+# endif  
+
+  return (TRUE);
+} 
+
+/*** add test of EXTNAME and header-defined columns? ***/
+/* return internal structure representation */
+Measure_PS1_V4alt *gfits_table_get_Measure_PS1_V4alt (FTable *ftable, off_t *Ndata, char *swapped) {
+
+  int Ncols;
+  Measure_PS1_V4alt *data;
+
+  Ncols = ftable[0].header[0].Naxis[0];
+  if (Ncols != 176) {
+    fprintf (stderr, "ERROR: mis-match in table size: width is %d but should be %d bytes\n", Ncols, 176);
+    return NULL;
+  }
+
+  *Ndata = ftable[0].header[0].Naxis[1];
+  data = (Measure_PS1_V4alt *) ftable[0].buffer;
+  if ((swapped == NULL) || (*swapped == FALSE)) {
+    if (!gfits_convert_Measure_PS1_V4alt (data, sizeof (Measure_PS1_V4alt), *Ndata)) {
+      return NULL;
+    }
+    gfits_table_scale_data (ftable);
+    if (swapped != NULL) *swapped = TRUE;
+  }
+  return (data);
+}
+
