Index: /trunk/Ohana/src/addstar/src/FilterStars.c
===================================================================
--- /trunk/Ohana/src/addstar/src/FilterStars.c	(revision 15037)
+++ /trunk/Ohana/src/addstar/src/FilterStars.c	(revision 15038)
@@ -43,4 +43,5 @@
     stars[N].Mcal    = image[0].Mcal;
     stars[N].t       = image[0].tzero + 1e-4*stars[N].Y*image[0].trate;  /* trate is in 0.1 msec / row */
+    stars[N].dt      = MTIME;
 
     stars[N].M       = MIN (stars[N].M + MTIME, NO_MAG);
Index: /trunk/Ohana/src/addstar/src/ImageOptions.c
===================================================================
--- /trunk/Ohana/src/addstar/src/ImageOptions.c	(revision 15037)
+++ /trunk/Ohana/src/addstar/src/ImageOptions.c	(revision 15038)
@@ -36,4 +36,6 @@
   }
   options[0].photcode = equivPhotcode;
+
+  options[0].imageID = 0;
   return (TRUE);
 }
Index: /trunk/Ohana/src/addstar/src/ReadStarsFITS.c
===================================================================
--- /trunk/Ohana/src/addstar/src/ReadStarsFITS.c	(revision 15037)
+++ /trunk/Ohana/src/addstar/src/ReadStarsFITS.c	(revision 15038)
@@ -176,5 +176,9 @@
     stars[i].extNsigma = ps1data[i].extNsigma;
 
-    stars[i].detID   = ps1data[i].detID;
+    stars[i].detID     = ps1data[i].detID;
+    stars[i].flags     = ps1data[i].flags;
+
+    // XXX not defined anyway
+    // stars[i].stargal   = ps1data[i].stargal;
 
     /* these are set elsewhere */
@@ -196,4 +200,5 @@
     stars[i].dt      = 0;
     stars[i].airmass = 0;
+    stars[i].az      = 0;
     stars[i].code    = 0;
     stars[i].found   = 0;
Index: /trunk/Ohana/src/addstar/src/SEDfit.c
===================================================================
--- /trunk/Ohana/src/addstar/src/SEDfit.c	(revision 15037)
+++ /trunk/Ohana/src/addstar/src/SEDfit.c	(revision 15038)
@@ -186,9 +186,9 @@
       outcat[0].measure[Nmeas].dM       = 0.0;
       outcat[0].measure[Nmeas].Mcal     = 0;
-      outcat[0].measure[Nmeas].t           = TIMEREF;
-      outcat[0].measure[Nmeas].averef      = Nave;
-      outcat[0].measure[Nmeas].photcode      = table[0].code[n];
-      outcat[0].measure[Nmeas].dophot      = 0;
-      outcat[0].measure[Nmeas].flags       = 0;
+      outcat[0].measure[Nmeas].t        = TIMEREF;
+      outcat[0].measure[Nmeas].averef   = Nave;
+      outcat[0].measure[Nmeas].photcode = table[0].code[n];
+      outcat[0].measure[Nmeas].dophot   = 0;
+      outcat[0].measure[Nmeas].dbFlags  = 0;
       outcat[0].measure[Nmeas].dt       = 0xffff;
 
Index: /trunk/Ohana/src/addstar/src/find_matches.c
===================================================================
--- /trunk/Ohana/src/addstar/src/find_matches.c	(revision 15037)
+++ /trunk/Ohana/src/addstar/src/find_matches.c	(revision 15038)
@@ -163,6 +163,4 @@
       catalog[0].measure[Nmeas].dD       = 3600.0*(catalog[0].average[n].D - stars[N].D);
 
-      /* XXX need to add dX, dY : need to load into stars[N].dX,dY */
-      /* XXX need to add stargal, Sky, dSky, qPSF, detID, imageID */
       catalog[0].measure[Nmeas].Xccd     = stars[N].X;
       catalog[0].measure[Nmeas].Yccd     = stars[N].Y;
@@ -175,7 +173,23 @@
       catalog[0].measure[Nmeas].photcode = stars[N].code;  /* photcode */
       catalog[0].measure[Nmeas].dophot   = stars[N].dophot;  
-      catalog[0].measure[Nmeas].flags    = 0;
+      catalog[0].measure[Nmeas].dbFlags  = 0;
       catalog[0].measure[Nmeas].dt       = stars[N].dt;
       catalog[0].measure[Nmeas].airmass  = stars[N].airmass;
+
+      catalog[0].measure[Nmeas].photFlags = stars[N].flags;
+      catalog[0].measure[Nmeas].qPSF      = stars[N].psfQual;
+      catalog[0].measure[Nmeas].psfProb   = stars[N].psfProb;
+      catalog[0].measure[Nmeas].crNsigma  = stars[N].crNsigma;
+      catalog[0].measure[Nmeas].extNsigma = stars[N].extNsigma;
+      catalog[0].measure[Nmeas].Sky       = stars[N].sky;
+      catalog[0].measure[Nmeas].dSky      = stars[N].dsky;
+
+      catalog[0].measure[Nmeas].stargal   = 0; // XXX not yet set
+
+      catalog[0].measure[Nmeas].detID     = stars[N].detID;
+      catalog[0].measure[Nmeas].imageID   = options.imageID;
+
+      catalog[0].measure[Nmeas].dXccd     = stars[N].dX;
+      catalog[0].measure[Nmeas].dYccd     = stars[N].dY;
 
       catalog[0].measure[Nmeas].Mgal     = stars[N].Mgal;
@@ -201,9 +215,9 @@
       /* this image star matches more than one catalog star */
       if (stars[N].found > -1) {
-	catalog[0].measure[stars[N].found].flags |= BLEND_IMAGE;
-	catalog[0].measure[Nmeas].flags |= BLEND_IMAGE;
+	catalog[0].measure[stars[N].found].dbFlags |= BLEND_IMAGE;
+	catalog[0].measure[Nmeas].dbFlags |= BLEND_IMAGE;
       } 
       if (stars[N].found == -2) { /* this image star matches a catalog star on a neighboring catalog */
-	catalog[0].measure[Nmeas].flags |= BLEND_IMAGE_NEIGHBOR;
+	catalog[0].measure[Nmeas].dbFlags |= BLEND_IMAGE_NEIGHBOR;
       } 
       if (stars[N].found == -1) { /* this image star matches only this catalog star */
@@ -212,6 +226,6 @@
       /* this catalog star matches more than one image star */
       if (catalog[0].found[n] > -1) {
-	catalog[0].measure[catalog[0].found[n]].flags |= BLEND_CATALOG;
-	catalog[0].measure[Nmeas].flags |= BLEND_CATALOG;
+	catalog[0].measure[catalog[0].found[n]].dbFlags |= BLEND_CATALOG;
+	catalog[0].measure[Nmeas].dbFlags |= BLEND_CATALOG;
       } else {
 	catalog[0].found[n] = Nmeas;
@@ -273,6 +287,4 @@
     }
 
-    /* XXX need to add dX, dY : need to load into stars[N].dX,dY */
-    /* XXX need to add stargal, Sky, dSky, qPSF, detID, imageID */
     catalog[0].measure[Nmeas].Xccd     = stars[N].X;
     catalog[0].measure[Nmeas].Yccd     = stars[N].Y;
@@ -287,7 +299,23 @@
     catalog[0].measure[Nmeas].photcode  = stars[N].code;  /* photcode */
     catalog[0].measure[Nmeas].dophot   	= stars[N].dophot;  
-    catalog[0].measure[Nmeas].flags    	= 0;
+    catalog[0].measure[Nmeas].dbFlags 	= 0;
     catalog[0].measure[Nmeas].dt    	= stars[N].dt;
     catalog[0].measure[Nmeas].airmass   = stars[N].airmass;
+
+    catalog[0].measure[Nmeas].photFlags = stars[N].flags;
+    catalog[0].measure[Nmeas].qPSF      = stars[N].psfQual;
+    catalog[0].measure[Nmeas].psfProb   = stars[N].psfProb;
+    catalog[0].measure[Nmeas].crNsigma  = stars[N].crNsigma;
+    catalog[0].measure[Nmeas].extNsigma = stars[N].extNsigma;
+    catalog[0].measure[Nmeas].Sky       = stars[N].sky;
+    catalog[0].measure[Nmeas].dSky      = stars[N].dsky;
+
+    catalog[0].measure[Nmeas].stargal   = 0; // XXX not yet set
+
+    catalog[0].measure[Nmeas].detID     = stars[N].detID;
+    catalog[0].measure[Nmeas].imageID   = options.imageID;
+
+    catalog[0].measure[Nmeas].dXccd     = stars[N].dX;
+    catalog[0].measure[Nmeas].dYccd     = stars[N].dY;
 
     catalog[0].measure[Nmeas].Mgal  	= stars[N].Mgal;
Index: /trunk/Ohana/src/addstar/src/find_matches_closest.c
===================================================================
--- /trunk/Ohana/src/addstar/src/find_matches_closest.c	(revision 15037)
+++ /trunk/Ohana/src/addstar/src/find_matches_closest.c	(revision 15038)
@@ -193,7 +193,23 @@
     catalog[0].measure[Nmeas].photcode = stars[N].code;  /* photcode */
     catalog[0].measure[Nmeas].dophot   = stars[N].dophot;  
-    catalog[0].measure[Nmeas].flags    = 0;
+    catalog[0].measure[Nmeas].dbFlags  = 0;
     catalog[0].measure[Nmeas].dt       = stars[N].dt;
     catalog[0].measure[Nmeas].airmass  = stars[N].airmass;
+
+    catalog[0].measure[Nmeas].photFlags = stars[N].flags;
+    catalog[0].measure[Nmeas].qPSF      = stars[N].psfQual;
+    catalog[0].measure[Nmeas].psfProb   = stars[N].psfProb;
+    catalog[0].measure[Nmeas].crNsigma  = stars[N].crNsigma;
+    catalog[0].measure[Nmeas].extNsigma = stars[N].extNsigma;
+    catalog[0].measure[Nmeas].Sky       = stars[N].sky;
+    catalog[0].measure[Nmeas].dSky      = stars[N].dsky;
+
+    catalog[0].measure[Nmeas].stargal   = 0;
+
+    catalog[0].measure[Nmeas].detID     = stars[N].detID;
+    catalog[0].measure[Nmeas].imageID   = options.imageID;
+
+    catalog[0].measure[Nmeas].dXccd     = stars[N].dX;
+    catalog[0].measure[Nmeas].dYccd     = stars[N].dY;
 
     catalog[0].measure[Nmeas].Mgal     = stars[N].Mgal;
@@ -270,6 +286,4 @@
     }
 
-    /* XXX need to add dX, dY : need to load into stars[N].dX,dY */
-    /* XXX need to add stargal, Sky, dSky, qPSF, detID, imageID */
     catalog[0].measure[Nmeas].Xccd     = stars[N].X;
     catalog[0].measure[Nmeas].Yccd     = stars[N].Y;
@@ -284,7 +298,23 @@
     catalog[0].measure[Nmeas].photcode = stars[N].code;  /* photcode */
     catalog[0].measure[Nmeas].dophot   = stars[N].dophot;  
-    catalog[0].measure[Nmeas].flags    = 0;
+    catalog[0].measure[Nmeas].dbFlags  = 0;
     catalog[0].measure[Nmeas].dt       = stars[N].dt;
     catalog[0].measure[Nmeas].airmass  = stars[N].airmass;
+
+    catalog[0].measure[Nmeas].photFlags = stars[N].flags;
+    catalog[0].measure[Nmeas].qPSF      = stars[N].psfQual;
+    catalog[0].measure[Nmeas].psfProb   = stars[N].psfProb;
+    catalog[0].measure[Nmeas].crNsigma  = stars[N].crNsigma;
+    catalog[0].measure[Nmeas].extNsigma = stars[N].extNsigma;
+    catalog[0].measure[Nmeas].Sky       = stars[N].sky;
+    catalog[0].measure[Nmeas].dSky      = stars[N].dsky;
+
+    catalog[0].measure[Nmeas].stargal   = 0;
+
+    catalog[0].measure[Nmeas].detID     = stars[N].detID;
+    catalog[0].measure[Nmeas].imageID   = options.imageID;
+
+    catalog[0].measure[Nmeas].dXccd     = stars[N].dX;
+    catalog[0].measure[Nmeas].dYccd     = stars[N].dY;
 
     catalog[0].measure[Nmeas].Mgal     = stars[N].Mgal;
Index: /trunk/Ohana/src/addstar/src/find_matches_refstars.c
===================================================================
--- /trunk/Ohana/src/addstar/src/find_matches_refstars.c	(revision 15037)
+++ /trunk/Ohana/src/addstar/src/find_matches_refstars.c	(revision 15038)
@@ -140,5 +140,5 @@
       catalog[0].measure[Nmeas].photcode = stars[N][0].code;
       catalog[0].measure[Nmeas].dophot   = 0;
-      catalog[0].measure[Nmeas].flags    = 0;
+      catalog[0].measure[Nmeas].dbFlags  = 0;
       catalog[0].measure[Nmeas].dt       = 0xffff;
 
@@ -149,6 +149,20 @@
       catalog[0].measure[Nmeas].theta    = NO_MAG;
 	
-      /* XXX need to add dX, dY : need to load into stars[N].dX,dY */
-      /* XXX need to add stargal, Sky, dSky, qPSF, detID, imageID */
+      catalog[0].measure[Nmeas].photFlags = 0;
+      catalog[0].measure[Nmeas].qPSF      = 0;
+      catalog[0].measure[Nmeas].psfProb   = 0;
+      catalog[0].measure[Nmeas].crNsigma  = 0;
+      catalog[0].measure[Nmeas].extNsigma = 0;
+      catalog[0].measure[Nmeas].Sky       = 0;
+      catalog[0].measure[Nmeas].dSky      = 0;
+
+      catalog[0].measure[Nmeas].stargal   = 0; // XXX not yet set
+
+      catalog[0].measure[Nmeas].detID     = 0;
+      catalog[0].measure[Nmeas].imageID   = 0;
+
+      catalog[0].measure[Nmeas].dXccd     = 0;
+      catalog[0].measure[Nmeas].dYccd     = 0;
+
       catalog[0].measure[Nmeas].Xccd     = 0.0;
       catalog[0].measure[Nmeas].Yccd     = 0.0;
@@ -168,9 +182,9 @@
       /* this image star matches more than one catalog star */
       if (stars[N][0].found > -1) {
-	catalog[0].measure[stars[N][0].found].flags |= BLEND_IMAGE;
-	catalog[0].measure[Nmeas].flags |= BLEND_IMAGE;
+	catalog[0].measure[stars[N][0].found].dbFlags |= BLEND_IMAGE;
+	catalog[0].measure[Nmeas].dbFlags |= BLEND_IMAGE;
       } 
       if (stars[N][0].found == -2) { /* this image star matches a catalog star on a neighboring catalog */
-	catalog[0].measure[Nmeas].flags |= BLEND_IMAGE_NEIGHBOR;
+	catalog[0].measure[Nmeas].dbFlags |= BLEND_IMAGE_NEIGHBOR;
       } 
       if (stars[N][0].found == -1) { /* this image star matches only this catalog star */
@@ -179,6 +193,6 @@
       /* this catalog star matches more than one image star */
       if (catalog[0].found[n] > -1) {
-	catalog[0].measure[catalog[0].found[n]].flags |= BLEND_CATALOG;
-	catalog[0].measure[Nmeas].flags |= BLEND_CATALOG;
+	catalog[0].measure[catalog[0].found[n]].dbFlags |= BLEND_CATALOG;
+	catalog[0].measure[Nmeas].dbFlags |= BLEND_CATALOG;
       } else {
 	catalog[0].found[n] = Nmeas;
@@ -254,6 +268,25 @@
     catalog[0].measure[Nmeas].photcode = stars[N][0].code;
     catalog[0].measure[Nmeas].dophot   = 0;
-    catalog[0].measure[Nmeas].flags    = 0;
+    catalog[0].measure[Nmeas].dbFlags  = 0;
     catalog[0].measure[Nmeas].dt       = 0xffff;
+
+    catalog[0].measure[Nmeas].photFlags = 0;
+    catalog[0].measure[Nmeas].qPSF      = 0;
+    catalog[0].measure[Nmeas].psfProb   = 0;
+    catalog[0].measure[Nmeas].crNsigma  = 0;
+    catalog[0].measure[Nmeas].extNsigma = 0;
+    catalog[0].measure[Nmeas].Sky       = 0;
+    catalog[0].measure[Nmeas].dSky      = 0;
+
+    catalog[0].measure[Nmeas].stargal   = 0; // XXX not yet set
+
+    catalog[0].measure[Nmeas].detID     = 0;
+    catalog[0].measure[Nmeas].imageID   = 0;
+
+    catalog[0].measure[Nmeas].dXccd     = 0;
+    catalog[0].measure[Nmeas].dYccd     = 0;
+
+    catalog[0].measure[Nmeas].Xccd     = 0.0;
+    catalog[0].measure[Nmeas].Yccd     = 0.0;
 
     catalog[0].measure[Nmeas].airmass  = 0;
@@ -263,6 +296,4 @@
     catalog[0].measure[Nmeas].theta    = NO_MAG;
 
-    /* XXX need to add dX, dY : need to load into stars[N].dX,dY */
-    /* XXX need to add stargal, Sky, dSky, qPSF, detID, imageID */
     catalog[0].measure[Nmeas].Xccd     = 0.0;
     catalog[0].measure[Nmeas].Yccd     = 0.0;
Index: /trunk/Ohana/src/addstar/src/load2mass_catalog.c
===================================================================
--- /trunk/Ohana/src/addstar/src/load2mass_catalog.c	(revision 15037)
+++ /trunk/Ohana/src/addstar/src/load2mass_catalog.c	(revision 15038)
@@ -52,9 +52,9 @@
       catalog[0].measure[Nmeas].dM       = MIN (stars[i+j].dM,  NO_ERR);
       catalog[0].measure[Nmeas].Mcal     = 0;
-      catalog[0].measure[Nmeas].t           = stars[i+j].t;
-      catalog[0].measure[Nmeas].averef      = Nave;
-      catalog[0].measure[Nmeas].photcode      = stars[i+j].code;
-      catalog[0].measure[Nmeas].dophot      = 0;
-      catalog[0].measure[Nmeas].flags       = 0;
+      catalog[0].measure[Nmeas].t        = stars[i+j].t;
+      catalog[0].measure[Nmeas].averef   = Nave;
+      catalog[0].measure[Nmeas].photcode = stars[i+j].code;
+      catalog[0].measure[Nmeas].dophot   = 0;
+      catalog[0].measure[Nmeas].dbFlags  = 0;
       catalog[0].measure[Nmeas].dt       = 0xffff;
 
Index: /trunk/Ohana/src/libautocode/def/AddstarClientOptions.d
===================================================================
--- /trunk/Ohana/src/libautocode/def/AddstarClientOptions.d	(revision 15037)
+++ /trunk/Ohana/src/libautocode/def/AddstarClientOptions.d	(revision 15038)
@@ -2,5 +2,5 @@
 EXTNAME OPTIONS
 TYPE    BINTABLE
-SIZE    72
+SIZE    76
 
 FIELD     Nsigma,           NSIGMA,               double,         match radius in terms of astrometric error 
@@ -20,2 +20,3 @@
 FIELD  	  photcode,         PHOTCODE,             int,     	  photocode of input data
 FIELD  	  timeref,          TIMEREF,              e_time,  	  time/date of input data (REFLIST only?)
+FIELD  	  imageID,          IMAGE_ID,             unsigned int,   reference to image
Index: /trunk/Ohana/src/libautocode/def/Stars.d
===================================================================
--- /trunk/Ohana/src/libautocode/def/Stars.d	(revision 15037)
+++ /trunk/Ohana/src/libautocode/def/Stars.d	(revision 15038)
@@ -2,5 +2,5 @@
 EXTNAME STARS
 TYPE    BINTABLE
-SIZE    240
+SIZE    244
 
 FIELD     X,                X,          double,    x coordinate on image,	     pixels
@@ -38,8 +38,10 @@
 FIELD     Mcal,             MCAL,       float,     image cal mag,	             mag
 FIELD     airmass,          AIRMASS,    float,     (airmass - 1),		     airmass
+FIELD     az,     	    AZ,         float,     azimuth
 FIELD     code,             CODE,       short
 FIELD     nFrames,          N_FRAMES,   short
+FIELD     flags,            FLAGS,      short
 FIELD     dophot,           DOPHOT,     char,      dophot type code
-FIELD     dummy,            DUMMY,      char[3]
+FIELD     dummy,            DUMMY,      char
 
 # XXX I'm going to need azimuth (or load from image header?)
Index: /trunk/Ohana/src/libautocode/def/autocode.c
===================================================================
--- /trunk/Ohana/src/libautocode/def/autocode.c	(revision 15037)
+++ /trunk/Ohana/src/libautocode/def/autocode.c	(revision 15038)
@@ -36,4 +36,5 @@
   if ((swapped == NULL) || (*swapped == FALSE)) {
     gfits_convert_$STRUCT (data, sizeof ($STRUCT), *Ndata);
+    gfits_table_scale_data (ftable);
     if (swapped != NULL) *swapped = TRUE;
   }
@@ -57,4 +58,5 @@
 
   /* add data values */
+  gfits_table_scale_data (ftable);
   gfits_convert_$STRUCT (data, sizeof ($STRUCT), Ndata);
   gfits_add_rows (ftable, (char *) data, Ndata, sizeof ($STRUCT));
Index: /trunk/Ohana/src/libautocode/def/image-ps1-dev-1.d
===================================================================
--- /trunk/Ohana/src/libautocode/def/image-ps1-dev-1.d	(revision 15037)
+++ /trunk/Ohana/src/libautocode/def/image-ps1-dev-1.d	(revision 15038)
@@ -48,9 +48,8 @@
 FIELD 	  code,             CODE,                 char,           image quality flag
 FIELD 	  ccdnum,           CCDNUM,               unsigned char,  CCD ID number
-FIELD 	  imageID_hi,       IMAGE_ID_HI,          unsigned int,   ID upper bytes
-FIELD 	  imageID_lo,       IMAGE_ID_LO,          unsigned int,   ID lower bytes
-# 48 bytes 
+FIELD 	  imageID,          IMAGE_ID,             unsigned int,   image ID
+# 44 bytes 
 
-FIELD 	  dummy,            DUMMY,                char[10],       unused
+FIELD 	  dummy,            DUMMY,                char[14],       unused
 FIELD 	  order,            ORDER,                short,      	  Mrel 2D polynomical order 
 FIELD 	  Mx,               MX,                   short,      	  Mrel polyterm
Index: /trunk/Ohana/src/libautocode/def/image.d
===================================================================
--- /trunk/Ohana/src/libautocode/def/image.d	(revision 15037)
+++ /trunk/Ohana/src/libautocode/def/image.d	(revision 15038)
@@ -48,9 +48,8 @@
 FIELD 	  code,             CODE,                 char,           image quality flag
 FIELD 	  ccdnum,           CCDNUM,               unsigned char,  CCD ID number
-FIELD 	  imageID_hi,       IMAGE_ID_HI,          unsigned int,   ID upper bytes
-FIELD 	  imageID_lo,       IMAGE_ID_LO,          unsigned int,   ID lower bytes
+FIELD 	  imageID,          IMAGE_ID,             unsigned int,   image ID
 # 48 bytes 
 
-FIELD 	  dummy,            DUMMY,                char[10],       unused
+FIELD 	  dummy,            DUMMY,                char[14],       unused
 FIELD 	  order,            ORDER,                short,      	  Mrel 2D polynomical order 
 FIELD 	  Mx,               MX,                   short,      	  Mrel polyterm
Index: /trunk/Ohana/src/libautocode/def/measure-ps1-dev-1.d
===================================================================
--- /trunk/Ohana/src/libautocode/def/measure-ps1-dev-1.d	(revision 15037)
+++ /trunk/Ohana/src/libautocode/def/measure-ps1-dev-1.d	(revision 15038)
@@ -2,5 +2,5 @@
 EXTNAME      DVO_MEASURE_PS1_DEV_1
 TYPE         BINTABLE
-SIZE         96
+SIZE         104
 DESCRIPTION  DVO Detection Measurement Table 
 
@@ -8,11 +8,11 @@
 FIELD dD,             D_DEC,        float,          DEC offset,               	  arcsec
 FIELD M,              MAG,          float,          catalog mag,       	       	  mag
-FIELD Mcal,           Mcal,         float,          image cal mag,	          mag
-FIELD Mgal,           Mgal,         float,          galaxy mag,			  mag
-FIELD dM,             dM,           float,          mag error,                    mag
-FIELD dt,             dt,           float,          exposure time,                2.5*log(exptime)
+FIELD Mcal,           M_CAL,        float,          image cal mag,	          mag
+FIELD Mgal,           M_GAL,        float,          galaxy mag,			  mag
+FIELD dM,             MAG_ERR,      float,          mag error,                    mag
+FIELD dt,             M_TIME,       float,          exposure time,                2.5*log(exptime)
 
 # note that with airmass = 1.0 / cos(90 - alt), we have full alt/az representation
-FIELD airmass,        airmass,      float,          (airmass - 1),		  airmass
+FIELD airmass,        AIRMASS,      float,          (airmass - 1),		  airmass
 FIELD az,             AZ,           float,          telescope azimuth
 
@@ -25,34 +25,36 @@
 FIELD dSky,           SKY_FLUX_ERR, float,          local estimate of sky flux,    counts/sec
 
-FIELD t,              t,            unsigned int,   time in seconds (UNIX)
-FIELD averef,         averef,       unsigned int,   reference to average entry      
+FIELD t,              TIME,         unsigned int,   time in seconds (UNIX)
+FIELD averef,         AVE_REF,      unsigned int,   reference to average entry      
 
 # Pan-STARRS uses a 64-bit detection ID.  keep this in two 32 bit ints for backwards compatibility?
-FIELD detID_hi,       DET_ID_HI,    unsigned int,   ID upper bytes
-FIELD detID_lo,       DET_ID_LO,    unsigned int,   ID lower bytes
+FIELD detID,          DET_ID,       unsigned int,   ID upper bytes
+FIELD imageID,        IMAGE_ID,     unsigned int,   reference to image
 
-FIELD imageID_hi,     IMAGE_ID_HI,  unsigned int,   reference to image
-FIELD imageID_lo,     IMAGE_ID_LO,  unsigned int,   reference to image
+# do we need more resolution than a short? should this be a log?
+FIELD qPSF,           PSF_QF,       float,          psf coverage/quality factor
+FIELD psfProb,        PSF_PROB,     float,          psf coverage/quality factor
+FIELD crNsigma,       CR_NSIGMA,    float,          psf coverage/quality factor
+FIELD extNsigma,      EXT_NSIGMA,   float,          psf coverage/quality factor
 
-FIELD FWx,            FWx,          short,          object fwhm major axis,       1/100 of arcsec 
-FIELD FWy,            FWy,          short,          object fwhm minor axis,       1/100 of arcsec 
-FIELD theta,          theta,        short,          angle wrt ccd X dir,          (0xffff/360) deg
-FIELD photcode,       photcode,     unsigned short, photcode
-
-FIELD flags,          flags,        unsigned short, flags for various uses  
+FIELD FWx,            FWHM_MAJOR,   short,          object fwhm major axis,       1/100 of arcsec 
+FIELD FWy,            FWHM_MINOR,   short,          object fwhm minor axis,       1/100 of arcsec 
+FIELD theta,          PSF_THETA,    short,          angle wrt ccd X dir,          (0xffff/360) deg
+FIELD photcode,       PHOTCODE,     unsigned short, photcode
 
 FIELD dXccd,          X_CCD_ERR,    short,          X coord error on chip,         pixels
 FIELD dYccd,          Y_CCD_ERR,    short,          Y coord error on chip,         pixels
 
-# do we need more resolution than a short? should this be a log?
-FIELD qPSF,           PSF_QF,       short,          psf coverage/quality factor
+FIELD dbFlags,        DB_FLAGS,     unsigned short, flags for various uses  
+FIELD photFlags,      PHOT_FLAGS,   unsigned short, flags supplied by photometry program
 
-FIELD dophot,         dophot,       char,           dophot type
-FIELD stargal,        stargal,      char,           star-galaxy separator
+FIELD stargal,        STAR_GAL,     char,           star-galaxy separator
 
-# we need extra bytes for padding purposes...
-FIELD dummy,          dummy,        char[2],        padding
+# absorb these into photFlags?
+FIELD dophot,         DOPHOT,       char,           dophot type
 
-# float : 13 x 4 = 52
+FIELD dummy,          DUMMY,        char[2],        padding
+
+# float : 17 x 4 = 68
 # int:     6 x 4 = 24
 # short:   8 x 2 = 16
Index: /trunk/Ohana/src/libautocode/def/measure.d
===================================================================
--- /trunk/Ohana/src/libautocode/def/measure.d	(revision 15037)
+++ /trunk/Ohana/src/libautocode/def/measure.d	(revision 15038)
@@ -2,5 +2,5 @@
 EXTNAME      DVO_MEASURE
 TYPE         BINTABLE
-SIZE         96
+SIZE         104
 DESCRIPTION  DVO Detection Measurement Table 
 
@@ -11,18 +11,9 @@
 FIELD Mgal,           Mgal,         float,          galaxy mag,			  mag
 FIELD dM,             dM,           float,          mag error,                    mag
-FIELD airmass,        airmass,      float,          (airmass - 1),		  airmass
 FIELD dt,             dt,           float,          exposure time,                2.5*log(exptime)
 
-FIELD t,              t,            unsigned int,   time in seconds (UNIX)
-FIELD averef,         averef,       unsigned int,   reference to average entry      
-
-FIELD FWx,            FWx,          short,          object fwhm major axis,       1/100 of arcsec 
-FIELD FWy,            FWy,          short,          object fwhm minor axis,       1/100 of arcsec 
-FIELD theta,          theta,        short,          angle wrt ccd X dir,          (0xffff/360) deg
-FIELD photcode,       photcode,     unsigned short, photcode
-
-FIELD flags,          flags,        unsigned short, flags for various uses  
-FIELD dophot,         dophot,       char,           dophot type
-FIELD stargal,        stargal,      char,           star-galaxy separator
+# note that with airmass = 1.0 / cos(90 - alt), we have full alt/az representation
+FIELD airmass,        airmass,      float,          (airmass - 1),		  airmass
+FIELD az,             AZ,           float,          telescope azimuth
 
 # new field elements needed for Pan-STARRS:
@@ -34,20 +25,32 @@
 FIELD dSky,           SKY_FLUX_ERR, float,          local estimate of sky flux,    counts/sec
 
+FIELD t,              t,            unsigned int,   time in seconds (UNIX)
+FIELD averef,         averef,       unsigned int,   reference to average entry      
+
+# Pan-STARRS uses a 64-bit detection ID.  keep this in two 32 bit ints for backwards compatibility?
+FIELD detID,          DET_ID,       unsigned int,   detection ID
+FIELD imageID,        IMAGE_ID,     unsigned int,   reference to image
+
+# do we need more resolution than a short? should this be a log?
+FIELD qPSF,           PSF_QF,       float,          psf coverage/quality factor
+FIELD psfProb,        PSF_PROB,     float,          psf coverage/quality factor
+FIELD crNsigma,       CR_NSIGMA,    float,          psf coverage/quality factor
+FIELD extNsigma,      EXT_NSIGMA,   float,          psf coverage/quality factor
+
+FIELD FWx,            FWx,          short,          object fwhm major axis,       1/100 of arcsec 
+FIELD FWy,            FWy,          short,          object fwhm minor axis,       1/100 of arcsec 
+FIELD theta,          theta,        short,          angle wrt ccd X dir,          (0xffff/360) deg
+FIELD photcode,       photcode,     unsigned short, photcode
+
 FIELD dXccd,          X_CCD_ERR,    short,          X coord error on chip,         pixels
 FIELD dYccd,          Y_CCD_ERR,    short,          Y coord error on chip,         pixels
 
-# do we need more resolution than a short? should this be a log?
-FIELD qPSF,           PSF_QF,       short,          psf coverage/quality factor
+FIELD dbFlags,        DB_FLAGS,     unsigned short, flags for various uses  
+FIELD photFlags,      PHOT_FLAGS,   unsigned short, flags supplied by photometry program
 
-# Pan-STARRS uses a 64-bit detection ID.  keep this in two 32 bit ints for backwards compatibility?
-FIELD detID_hi,       DET_ID_HI,    unsigned int,   ID upper bytes
-FIELD detID_lo,       DET_ID_LO,    unsigned int,   ID lower bytes
+FIELD stargal,        stargal,      char,           star-galaxy separator
 
-FIELD imageID_hi,     IMAGE_ID_HI,  unsigned int,   reference to image
-FIELD imageID_lo,     IMAGE_ID_LO,  unsigned int,   reference to image
+# absorb these into photFlags?
+FIELD dophot,         dophot,       char,           dophot type
 
-# note that with airmass = 1.0 / cos(90 - alt), we have full alt/az representation
-FIELD az,             AZ,           float,          telescope azimuth
-
-# we need extra bytes for padding purposes...
-FIELD dummy,          dummy,        char[2],        padding
+FIELD dummy,          DUMMY,        char[2],        padding
Index: /trunk/Ohana/src/libautocode/def/ps1_dev_1.d
===================================================================
--- /trunk/Ohana/src/libautocode/def/ps1_dev_1.d	(revision 15037)
+++ /trunk/Ohana/src/libautocode/def/ps1_dev_1.d	(revision 15038)
@@ -24,3 +24,3 @@
 FIELD psfQual, 	 PSF_QF,           float,    quality factor
 FIELD nFrames, 	 N_FRAMES,         short,    images overlapping peak
-FIELD dummy,  	 DUMMY,            short,    padding
+FIELD flags,  	 FLAGS,            short,    padding
Index: /trunk/Ohana/src/libdvo/src/dvo_convert_PS1_DEV_1.c
===================================================================
--- /trunk/Ohana/src/libdvo/src/dvo_convert_PS1_DEV_1.c	(revision 15037)
+++ /trunk/Ohana/src/libdvo/src/dvo_convert_PS1_DEV_1.c	(revision 15038)
@@ -15,30 +15,32 @@
     out[i].dD         = in[i].dD;
     out[i].M          = in[i].M;
-    out[i].dM         = in[i].dM;
     out[i].Mcal       = in[i].Mcal;
     out[i].Mgal       = in[i].Mgal;
+    out[i].dM         = in[i].dM;
+    out[i].dt         = in[i].dt;
     out[i].airmass    = in[i].airmass;
     out[i].az         = in[i].az;
-    out[i].dt         = in[i].dt;
+    out[i].Xccd       = in[i].Xccd;
+    out[i].Yccd       = in[i].Yccd;
+    out[i].Sky        = in[i].Sky;
+    out[i].dSky       = in[i].dSky;
+    out[i].t          = in[i].t;
+    out[i].averef     = in[i].averef;
+    out[i].detID      = in[i].detID;
+    out[i].imageID    = in[i].imageID;
+    out[i].qPSF       = in[i].qPSF;
+    out[i].psfProb    = in[i].psfProb;
+    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].dophot     = in[i].dophot;
     out[i].photcode   = in[i].photcode;
-    out[i].t          = in[i].t;
-    out[i].averef     = in[i].averef;
-    out[i].flags      = in[i].flags;
-    out[i].Xccd       = in[i].Xccd;
-    out[i].Yccd       = in[i].Yccd;
     out[i].dXccd      = in[i].dXccd;
     out[i].dYccd      = in[i].dYccd;
+    out[i].dbFlags    = in[i].dbFlags;
+    out[i].photFlags  = in[i].photFlags;
     out[i].stargal    = in[i].stargal;
-    out[i].Sky        = in[i].Sky;
-    out[i].dSky       = in[i].dSky;
-    out[i].qPSF       = in[i].qPSF;
-    out[i].detID_hi   = in[i].detID_hi;
-    out[i].detID_lo   = in[i].detID_lo;
-    out[i].imageID_hi = in[i].imageID_hi;
-    out[i].imageID_lo = in[i].imageID_lo;
+    out[i].dophot     = in[i].dophot;
   }
   return (out);
@@ -57,30 +59,32 @@
     out[i].dD         = in[i].dD;
     out[i].M          = in[i].M;
-    out[i].dM         = in[i].dM;
     out[i].Mcal       = in[i].Mcal;
     out[i].Mgal       = in[i].Mgal;
+    out[i].dM         = in[i].dM;
+    out[i].dt         = in[i].dt;
     out[i].airmass    = in[i].airmass;
     out[i].az         = in[i].az;
-    out[i].dt         = in[i].dt;
+    out[i].Xccd       = in[i].Xccd;
+    out[i].Yccd       = in[i].Yccd;
+    out[i].Sky        = in[i].Sky;
+    out[i].dSky       = in[i].dSky;
+    out[i].t          = in[i].t;
+    out[i].averef     = in[i].averef;
+    out[i].detID      = in[i].detID;
+    out[i].imageID    = in[i].imageID;
+    out[i].qPSF       = in[i].qPSF;
+    out[i].psfProb    = in[i].psfProb;
+    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].dophot     = in[i].dophot;
     out[i].photcode   = in[i].photcode;
-    out[i].t          = in[i].t;
-    out[i].averef     = in[i].averef;
-    out[i].flags      = in[i].flags;
-    out[i].Xccd       = in[i].Xccd;
-    out[i].Yccd       = in[i].Yccd;
     out[i].dXccd      = in[i].dXccd;
     out[i].dYccd      = in[i].dYccd;
+    out[i].dbFlags    = in[i].dbFlags;
+    out[i].photFlags  = in[i].photFlags;
     out[i].stargal    = in[i].stargal;
-    out[i].Sky        = in[i].Sky;
-    out[i].dSky       = in[i].dSky;
-    out[i].qPSF       = in[i].qPSF;
-    out[i].detID_hi   = in[i].detID_hi;
-    out[i].detID_lo   = in[i].detID_lo;
-    out[i].imageID_hi = in[i].imageID_hi;
-    out[i].imageID_lo = in[i].imageID_lo;
+    out[i].dophot     = in[i].dophot;
   }
   return (out);
@@ -221,6 +225,5 @@
     out[i].code		    = in[i].code;
     out[i].ccdnum	    = in[i].ccdnum;
-    out[i].imageID_hi	    = in[i].imageID_hi;
-    out[i].imageID_lo	    = in[i].imageID_lo;
+    out[i].imageID	    = in[i].imageID;
 
     out[i].order	    = in[i].order;
@@ -277,6 +280,5 @@
     out[i].code		    = in[i].code;
     out[i].ccdnum	    = in[i].ccdnum;
-    out[i].imageID_hi	    = in[i].imageID_hi;
-    out[i].imageID_lo	    = in[i].imageID_lo;
+    out[i].imageID	    = in[i].imageID;
 
     out[i].order	    = in[i].order;
Index: /trunk/Ohana/src/libdvo/src/dvo_convert_elixir.c
===================================================================
--- /trunk/Ohana/src/libdvo/src/dvo_convert_elixir.c	(revision 15037)
+++ /trunk/Ohana/src/libdvo/src/dvo_convert_elixir.c	(revision 15038)
@@ -25,5 +25,5 @@
     out[i].t        = in[i].t;
     out[i].averef   = in[i].averef;
-    out[i].flags    = in[i].flags;
+    out[i].dbFlags  = in[i].flags;
     
     /* these can be determined if needed / desired */
@@ -34,14 +34,17 @@
 
     /* these do not have a corresponding value */
-    out[i].stargal  = 0;
-    out[i].Sky      = 0;
-    out[i].dSky     = 0;
-    out[i].qPSF     = 0;
+    out[i].az        = 0;
+    out[i].stargal   = 0;
+    out[i].Sky       = 0;
+    out[i].dSky      = 0;
+    out[i].qPSF      = 0;
+    out[i].psfProb   = 0;
+    out[i].crNsigma  = 0;
+    out[i].extNsigma = 0;
+    out[i].photFlags = 0;
 
     /* XXX add these later */
-    out[i].detID_hi = 0;
-    out[i].detID_lo = 0;
-    out[i].imageID_hi = 0;
-    out[i].imageID_lo = 0;
+    out[i].detID = 0;
+    out[i].imageID = 0;
   }
   return (out);
@@ -72,5 +75,5 @@
     out[i].t       = in[i].t;
     out[i].averef  = in[i].averef;
-    out[i].flags   = in[i].flags;
+    out[i].flags   = in[i].dbFlags;
   }
   return (out);
@@ -232,6 +235,5 @@
 
     /* XXX add these later */
-    out[i].imageID_hi = 0;
-    out[i].imageID_lo = 0;
+    out[i].imageID = 0;
   }
   return (out);
Index: /trunk/Ohana/src/libdvo/src/dvo_convert_loneos.c
===================================================================
--- /trunk/Ohana/src/libdvo/src/dvo_convert_loneos.c	(revision 15037)
+++ /trunk/Ohana/src/libdvo/src/dvo_convert_loneos.c	(revision 15038)
@@ -10,28 +10,33 @@
 
   for (i = 0; i < Nvalues; i++) {
-    out[i].dR   = in[i].dR * 0.01;
-    out[i].dD   = in[i].dD * 0.01;
-    out[i].M    = in[i].M  * 0.001;
-    out[i].dM   = in[i].dM * 0.001;
-    out[i].Mcal = in[i].Mcal * 0.001;
-    out[i].dophot  = in[i].dophot;
+    out[i].dR        = in[i].dR * 0.01;
+    out[i].dD        = in[i].dD * 0.01;
+    out[i].M         = in[i].M  * 0.001;
+    out[i].dM        = in[i].dM * 0.001;
+    out[i].Mcal      = in[i].Mcal * 0.001;
+    out[i].dophot    = in[i].dophot;
     out[i].photcode  = in[i].source;
-    out[i].t       = in[i].t;
+    out[i].t         = in[i].t;
 
     /* flags and averef are now split */
-    out[i].averef  =  in[i].averef & 0x00ffffff;
-    out[i].flags   = (in[i].averef & 0xff000000) >> 24;
+    out[i].averef    =  in[i].averef & 0x00ffffff;
+    out[i].dbFlags   = (in[i].averef & 0xff000000) >> 24;
 
     /* these values don't exist in the Loneos format */
-    out[i].Mgal    = in[i].M;
-    out[i].dt      = 0;
-    out[i].airmass = 0;
-    out[i].FWx 	      = 0;
-    out[i].FWy 	      = 0;
-    out[i].theta      = 0;
+    out[i].Mgal     = in[i].M;
+    out[i].dt       = 0;
+    out[i].airmass  = 0;
+    out[i].az       = 0;
+    out[i].FWx 	    = 0;
+    out[i].FWy 	    = 0;
+    out[i].theta    = 0;
     out[i].stargal  = 0;
     out[i].Sky      = 0;
     out[i].dSky     = 0;
     out[i].qPSF     = 0;
+    out[i].psfProb   = 0;
+    out[i].crNsigma  = 0;
+    out[i].extNsigma = 0;
+    out[i].photFlags = 0;
 
     /* these can be determined if needed / desired */
@@ -42,8 +47,6 @@
 
     /* XXX add these later */
-    out[i].detID_hi = 0;
-    out[i].detID_lo = 0;
-    out[i].imageID_hi = 0;
-    out[i].imageID_lo = 0;
+    out[i].detID = 0;
+    out[i].imageID = 0;
   }
   return (out);
@@ -69,5 +72,5 @@
 
     /* flags and averef are merged in Loneos */
-    out[i].averef =  (in[i].averef & 0x00ffffff) | (in[i].flags << 24);
+    out[i].averef =  (in[i].averef & 0x00ffffff) | (in[i].dbFlags << 24);
   }
   return (out);
@@ -226,6 +229,5 @@
 
     /* XXX add these later */
-    out[i].imageID_hi = 0;
-    out[i].imageID_lo = 0;
+    out[i].imageID = 0;
   }
   return (out);
Index: /trunk/Ohana/src/libdvo/src/dvo_convert_panstarrs_DEV_0.c
===================================================================
--- /trunk/Ohana/src/libdvo/src/dvo_convert_panstarrs_DEV_0.c	(revision 15037)
+++ /trunk/Ohana/src/libdvo/src/dvo_convert_panstarrs_DEV_0.c	(revision 15038)
@@ -26,5 +26,5 @@
     out[i].t          = in[i].t;
     out[i].averef     = in[i].averef;
-    out[i].flags      = in[i].flags;
+    out[i].dbFlags    = in[i].flags;
     out[i].Xccd       = in[i].Xccd;
     out[i].Yccd       = in[i].Yccd;
@@ -35,8 +35,12 @@
     out[i].dSky       = in[i].dSky;
     out[i].qPSF       = in[i].qPSF;
-    out[i].detID_hi   = in[i].detID_hi;
-    out[i].detID_lo   = in[i].detID_lo;
-    out[i].imageID_hi = in[i].imageID_hi;
-    out[i].imageID_lo = in[i].imageID_lo;
+    out[i].detID      = in[i].detID_lo;
+    out[i].imageID    = in[i].imageID_lo;
+
+    // these don't have a correspondence
+    out[i].psfProb   = 0;
+    out[i].crNsigma  = 0;
+    out[i].extNsigma = 0;
+    out[i].photFlags = 0;
   }
   return (out);
@@ -68,5 +72,5 @@
     out[i].t          = in[i].t;
     out[i].averef     = in[i].averef;
-    out[i].flags      = in[i].flags;
+    out[i].flags      = in[i].dbFlags;
     out[i].Xccd       = in[i].Xccd;
     out[i].Yccd       = in[i].Yccd;
@@ -77,8 +81,8 @@
     out[i].dSky       = in[i].dSky;
     out[i].qPSF       = in[i].qPSF;
-    out[i].detID_hi   = in[i].detID_hi;
-    out[i].detID_lo   = in[i].detID_lo;
-    out[i].imageID_hi = in[i].imageID_hi;
-    out[i].imageID_lo = in[i].imageID_lo;
+    out[i].detID_hi   = 0;
+    out[i].detID_lo   = in[i].detID;
+    out[i].imageID_hi = 0;
+    out[i].imageID_lo = in[i].imageID;
   }
   return (out);
@@ -219,6 +223,5 @@
     out[i].code		    = in[i].code;
     out[i].ccdnum	    = in[i].ccdnum;
-    out[i].imageID_hi	    = in[i].imageID_hi;
-    out[i].imageID_lo	    = in[i].imageID_lo;
+    out[i].imageID	    = in[i].imageID_lo;
 
     out[i].order	    = in[i].order;
@@ -275,6 +278,6 @@
     out[i].code		    = in[i].code;
     out[i].ccdnum	    = in[i].ccdnum;
-    out[i].imageID_hi	    = in[i].imageID_hi;
-    out[i].imageID_lo	    = in[i].imageID_lo;
+    out[i].imageID_hi	    = 0;
+    out[i].imageID_lo	    = in[i].imageID;
 
     out[i].order	    = in[i].order;
Index: /trunk/Ohana/src/libdvo/src/dvo_convert_panstarrs_DEV_1.c
===================================================================
--- /trunk/Ohana/src/libdvo/src/dvo_convert_panstarrs_DEV_1.c	(revision 15037)
+++ /trunk/Ohana/src/libdvo/src/dvo_convert_panstarrs_DEV_1.c	(revision 15038)
@@ -26,5 +26,5 @@
     out[i].t          = in[i].t;
     out[i].averef     = in[i].averef;
-    out[i].flags      = in[i].flags;
+    out[i].dbFlags    = in[i].flags;
     out[i].Xccd       = in[i].Xccd;
     out[i].Yccd       = in[i].Yccd;
@@ -35,8 +35,12 @@
     out[i].dSky       = in[i].dSky;
     out[i].qPSF       = in[i].qPSF;
-    out[i].detID_hi   = in[i].detID_hi;
-    out[i].detID_lo   = in[i].detID_lo;
-    out[i].imageID_hi = in[i].imageID_hi;
-    out[i].imageID_lo = in[i].imageID_lo;
+    out[i].detID      = in[i].detID_lo;
+    out[i].imageID    = in[i].imageID_lo;
+
+    // these don't have a correspondence
+    out[i].psfProb   = 0;
+    out[i].crNsigma  = 0;
+    out[i].extNsigma = 0;
+    out[i].photFlags = 0;
   }
   return (out);
@@ -68,5 +72,5 @@
     out[i].t          = in[i].t;
     out[i].averef     = in[i].averef;
-    out[i].flags      = in[i].flags;
+    out[i].flags      = in[i].dbFlags;
     out[i].Xccd       = in[i].Xccd;
     out[i].Yccd       = in[i].Yccd;
@@ -77,8 +81,8 @@
     out[i].dSky       = in[i].dSky;
     out[i].qPSF       = in[i].qPSF;
-    out[i].detID_hi   = in[i].detID_hi;
-    out[i].detID_lo   = in[i].detID_lo;
-    out[i].imageID_hi = in[i].imageID_hi;
-    out[i].imageID_lo = in[i].imageID_lo;
+    out[i].detID_hi   = 0;
+    out[i].detID_lo   = in[i].detID;
+    out[i].imageID_hi = 0;
+    out[i].imageID_lo = in[i].imageID;
   }
   return (out);
@@ -219,6 +223,5 @@
     out[i].code		    = in[i].code;
     out[i].ccdnum	    = in[i].ccdnum;
-    out[i].imageID_hi	    = in[i].imageID_hi;
-    out[i].imageID_lo	    = in[i].imageID_lo;
+    out[i].imageID	    = in[i].imageID_lo;
 
     out[i].order	    = in[i].order;
@@ -275,6 +278,6 @@
     out[i].code		    = in[i].code;
     out[i].ccdnum	    = in[i].ccdnum;
-    out[i].imageID_hi	    = in[i].imageID_hi;
-    out[i].imageID_lo	    = in[i].imageID_lo;
+    out[i].imageID_hi	    = 0;
+    out[i].imageID_lo	    = in[i].imageID;
 
     out[i].order	    = in[i].order;
Index: /trunk/Ohana/src/libfits/include/gfitsio.h
===================================================================
--- /trunk/Ohana/src/libfits/include/gfitsio.h	(revision 15037)
+++ /trunk/Ohana/src/libfits/include/gfitsio.h	(revision 15038)
@@ -126,4 +126,6 @@
 int   gfits_add_rows               PROTO ((FTable *, char *, int, int));
 char *gfits_table_print            PROTO ((FTable *,...));
+int   gfits_table_scale_data       PROTO ((FTable *ftable));
+int   gfits_table_scale_storage    PROTO ((FTable *ftable));
 
 /******************************* Matrix functions *************/
Index: /trunk/Ohana/src/libfits/table/F_table_format.c
===================================================================
--- /trunk/Ohana/src/libfits/table/F_table_format.c	(revision 15037)
+++ /trunk/Ohana/src/libfits/table/F_table_format.c	(revision 15038)
@@ -189,3 +189,141 @@
 }
 
-    /* vsnprintf (&line[off], Nchar + 1, format, argp); */
+// apply table tzero, tscal in situ (from storage to data)
+int gfits_table_scale_data (FTable *ftable) {
+
+  int i, j, n, Nx, Ny, Nfields;
+  int off, Nchar, Nval, Nbytes, status;
+  char *line, format[64], field[16], type[16];
+  double tzero, tscale;
+  char *tmpChar;
+  short *tmpShort;
+  int *tmpInt;
+
+  off = 0;
+
+  gfits_scan (ftable[0].header, "NAXIS1",  "%d", 1, &Nx);
+  gfits_scan (ftable[0].header, "NAXIS2",  "%d", 1, &Ny);
+  gfits_scan (ftable[0].header, "TFIELDS", "%d", 1, &Nfields);
+
+  for (i = 1; i <= Nfields; i++) {
+    sprintf (field, "TFORM%d", i);
+    gfits_scan (ftable[0].header, field, "%s", 1, format);       /* get field format */
+    gfits_bintable_format (format, type, &Nval, &Nbytes); /* convert to c-style */
+    Nchar = Nval * Nbytes;
+
+    sprintf (field, "TZERO%d", i);
+    status = gfits_scan (ftable[0].header, field, "%lf", 1, &tzero);       /* get field format */
+    if (!status) {
+	off += Nchar; 
+	continue;
+    }
+
+    sprintf (field, "TSCAL%d", i);
+    status = gfits_scan (ftable[0].header, field, "%lf", 1, &tscale);       /* get field format */
+    if (!status) {
+	off += Nchar; 
+	continue;
+    }
+    if (tscale == 0.0) {
+	off += Nchar; 
+	continue;
+    }
+
+    if (!strcmp (type, "char"))   { 
+      for (j = 0; j < Ny; j++) {
+	for (n = 0; n < Nval; n++) {
+	  tmpChar = (int *)&ftable[0].buffer[j*Nx + n*Nbytes + off];
+	  *tmpChar = *tmpChar * tscale + tzero;
+	}
+      }
+    }
+    if (!strcmp (type, "short"))   { 
+      for (j = 0; j < Ny; j++) {
+	for (n = 0; n < Nval; n++) {
+	  tmpShort = (int *)&ftable[0].buffer[j*Nx + n*Nbytes + off];
+	  *tmpShort = *tmpShort * tscale + tzero;
+	}
+      }
+    }
+    if (!strcmp (type, "int"))   { 
+      for (j = 0; j < Ny; j++) {
+	for (n = 0; n < Nval; n++) {
+	  tmpInt = (int *)&ftable[0].buffer[j*Nx + n*Nbytes + off];
+	  *tmpInt = *tmpInt * tscale + tzero;
+	}
+      }
+    }
+    off += Nchar;
+  }
+  return (TRUE);
+}
+
+// apply table tzero, tscal in situ (from data to storage)
+int gfits_table_scale_storage (FTable *ftable) {
+
+  int i, j, n, Nx, Ny, Nfields;
+  int off, Nchar, Nval, Nbytes, status;
+  char *line, format[64], field[16], type[16];
+  double tzero, tscale;
+  char *tmpChar;
+  short *tmpShort;
+  int *tmpInt;
+
+  off = 0;
+
+  gfits_scan (ftable[0].header, "NAXIS1",  "%d", 1, &Nx);
+  gfits_scan (ftable[0].header, "NAXIS2",  "%d", 1, &Ny);
+  gfits_scan (ftable[0].header, "TFIELDS", "%d", 1, &Nfields);
+
+  for (i = 1; i <= Nfields; i++) {
+    sprintf (field, "TFORM%d", i);
+    gfits_scan (ftable[0].header, field, "%s", 1, format);       /* get field format */
+    gfits_bintable_format (format, type, &Nval, &Nbytes); /* convert to c-style */
+    Nchar = Nval * Nbytes;
+
+    sprintf (field, "TZERO%d", i);
+    status = gfits_scan (ftable[0].header, field, "%lf", 1, &tzero);       /* get field format */
+    if (!status) {
+	off += Nchar; 
+	continue;
+    }
+
+    sprintf (field, "TSCAL%d", i);
+    status = gfits_scan (ftable[0].header, field, "%lf", 1, &tscale);       /* get field format */
+    if (!status) {
+	off += Nchar; 
+	continue;
+    }
+    if (tscale == 0.0) {
+	off += Nchar; 
+	continue;
+    }
+
+    if (!strcmp (type, "char"))   { 
+      for (j = 0; j < Ny; j++) {
+	for (n = 0; n < Nval; n++) {
+	  tmpChar = (int *)&ftable[0].buffer[j*Nx + n*Nbytes + off];
+	  *tmpChar = (*tmpChar - tzero) / tscale;
+	}
+      }
+    }
+    if (!strcmp (type, "short"))   { 
+      for (j = 0; j < Ny; j++) {
+	for (n = 0; n < Nval; n++) {
+	  tmpShort = (int *)&ftable[0].buffer[j*Nx + n*Nbytes + off];
+	  *tmpShort = (*tmpShort - tzero) / tscale;
+	}
+      }
+    }
+    if (!strcmp (type, "int"))   { 
+      for (j = 0; j < Ny; j++) {
+	for (n = 0; n < Nval; n++) {
+	  tmpInt = (int *)&ftable[0].buffer[j*Nx + n*Nbytes + off];
+	  *tmpInt = (*tmpInt - tzero) / tscale;
+	}
+      }
+    }
+    off += Nchar;
+  }
+  return (TRUE);
+}
Index: /trunk/Ohana/src/opihi/dvo/dbExtractMeasures.c
===================================================================
--- /trunk/Ohana/src/opihi/dvo/dbExtractMeasures.c	(revision 15037)
+++ /trunk/Ohana/src/opihi/dvo/dbExtractMeasures.c	(revision 15038)
@@ -161,5 +161,5 @@
 //      break;
     case MEAS_FLAGS: /* ? */
-      value = measure[0].flags;
+      value = measure[0].dbFlags;
       break;
     case MEAS_XCCD: /* OK */
Index: /trunk/Ohana/src/opihi/dvo/gstar.c
===================================================================
--- /trunk/Ohana/src/opihi/dvo/gstar.c	(revision 15037)
+++ /trunk/Ohana/src/opihi/dvo/gstar.c	(revision 15038)
@@ -172,5 +172,5 @@
 		     Mcat, Mrel, catalog.measure[m].dM,
 		     date, catalog.measure[m].dR, catalog.measure[m].dD,
-		     catalog.measure[m].dophot, catalog.measure[m].flags,
+		     catalog.measure[m].dophot, catalog.measure[m].dbFlags,
 		     catalog.measure[m].photcode, GetPhotcodeNamebyCode (catalog.measure[m].photcode));
 	    free (date);
Index: /trunk/Ohana/src/opihi/dvo/photometry.c
===================================================================
--- /trunk/Ohana/src/opihi/dvo/photometry.c	(revision 15037)
+++ /trunk/Ohana/src/opihi/dvo/photometry.c	(revision 15038)
@@ -24,5 +24,5 @@
     if (TypeSelect && (TypeValue != GetMeasureTypeCode (&M))) continue; \
     if (iMagSelect && (PhotInst (&M) < iMagMin)) continue; \
-    if (FlagSelect && (M.flags != FlagValue)) continue; \
+    if (FlagSelect && (M.dbFlags != FlagValue)) continue; \
   }
 
@@ -688,5 +688,5 @@
       for (i = 0; i < average[0].Nm; i++) {
 	if (code[0].code != GetPhotcodeEquivCodebyCode (measure[i].photcode)) continue;
-	if (measure[i].flags & (ID_MEAS_POOR | ID_MEAS_SKIP)) continue;
+	if (measure[i].dbFlags & (ID_MEAS_POOR | ID_MEAS_SKIP)) continue;
 	value ++;
       }
@@ -698,5 +698,5 @@
 	if ((code != NULL) && (code[0].code != GetPhotcodeEquivCodebyCode (measure[i].photcode))) continue;
 	if (ErrSelect && (measure[i].dM > ErrValue)) continue;
-	if (FlagSelect && (measure[i].flags != FlagValue)) continue;
+	if (FlagSelect && (measure[i].dbFlags != FlagValue)) continue;
 	if (TypeSelect && (TypeValue != GetMeasureTypeCode (&measure[i]))) continue;
 	if (iMagSelect && (PhotInst (&measure[i]) < iMagMin)) continue;
@@ -874,5 +874,5 @@
     for (i = 0; i < average[0].Nm; i++) {
       TESTCODE (code, measure[i]);
-      if (measure[i].flags && ID_MEAS_SKIP) continue;
+      if (measure[i].dbFlags && ID_MEAS_SKIP) continue;
       Nm++;
     }
@@ -1169,5 +1169,5 @@
       break;
     case MEAS_FLAGS: /* ? */
-      value = measure[0].flags;
+      value = measure[0].dbFlags;
       break;
     case MEAS_XCCD: /* OK */
Index: /trunk/Ohana/src/opihi/dvo/pmeasure.c
===================================================================
--- /trunk/Ohana/src/opihi/dvo/pmeasure.c	(revision 15037)
+++ /trunk/Ohana/src/opihi/dvo/pmeasure.c	(revision 15038)
@@ -114,5 +114,5 @@
       for (k = 0; k < catalog.average[i].Nm; k++) {
 	if (FlagClip) {
-	  flags = catalog.measure[m+k].flags;
+	  flags = catalog.measure[m+k].dbFlags;
 	  if (!(flags & FlagChoice)) continue;
 	}
Index: /trunk/Ohana/src/relastro/src/UpdateImages.c
===================================================================
--- /trunk/Ohana/src/relastro/src/UpdateImages.c	(revision 15037)
+++ /trunk/Ohana/src/relastro/src/UpdateImages.c	(revision 15038)
@@ -35,5 +35,5 @@
       N = 0;
       for (k = 0; k < catalog[i].average[j].Nm; k++, m++) {
-	if (catalog[i].measure[m].flags & MEAS_BAD) continue;
+	if (catalog[i].measure[m].dbFlags & MEAS_BAD) continue;
 	
 	listR[N] = getMeanR (&catalog[i].measure[m], &catalog[i].average[j], &catalog[i].secfilt[j*PhotNsec]);
Index: /trunk/Ohana/src/relastro/src/UpdateObjects.c
===================================================================
--- /trunk/Ohana/src/relastro/src/UpdateObjects.c	(revision 15037)
+++ /trunk/Ohana/src/relastro/src/UpdateObjects.c	(revision 15038)
@@ -85,5 +85,5 @@
 
       for (k = 0; k < catalog[i].average[j].Nm; k++, m++) {
-	if (catalog[i].measure[m].flags & MEAS_BAD) continue;
+	if (catalog[i].measure[m].dbFlags & MEAS_BAD) continue;
 	
 	R[N] = getMeanR (&catalog[i].measure[m], &catalog[i].average[j], &catalog[i].secfilt[j*PhotNsec]);
@@ -178,5 +178,5 @@
       m = catalog[i].average[j].offset;
       for (k = 0; k < catalog[i].average[j].Nm; k++, m++) {
-	if (catalog[i].measure[m].flags & MEAS_BAD) continue;
+	if (catalog[i].measure[m].dbFlags & MEAS_BAD) continue;
 	setMeanR (fit.Ro, &catalog[i].measure[m], &catalog[i].average[j], &catalog[i].secfilt[j*PhotNsec]);
 	setMeanD (fit.Do, &catalog[i].measure[m], &catalog[i].average[j], &catalog[i].secfilt[j*PhotNsec]);
Index: /trunk/Ohana/src/relphot/src/GridOps.c
===================================================================
--- /trunk/Ohana/src/relphot/src/GridOps.c	(revision 15037)
+++ /trunk/Ohana/src/relphot/src/GridOps.c	(revision 15038)
@@ -270,5 +270,5 @@
       c = clist[i][j];
       
-      if (catalog[c].measure[m].flags & MEAS_BAD) continue;
+      if (catalog[c].measure[m].dbFlags & MEAS_BAD) continue;
       Mcal = getMcal  (m, c);
       if (Mcal == NO_MAG) continue;
@@ -321,5 +321,5 @@
       c = clist[i][j];
       
-      if (catalog[c].measure[m].flags & MEAS_BAD) {
+      if (catalog[c].measure[m].dbFlags & MEAS_BAD) {
 	Narea ++;
 	continue;
Index: /trunk/Ohana/src/relphot/src/ImageOps.c
===================================================================
--- /trunk/Ohana/src/relphot/src/ImageOps.c	(revision 15037)
+++ /trunk/Ohana/src/relphot/src/ImageOps.c	(revision 15038)
@@ -195,5 +195,5 @@
       c = clist[i][j];
       
-      if (catalog[c].measure[m].flags & MEAS_BAD) continue;
+      if (catalog[c].measure[m].dbFlags & MEAS_BAD) continue;
       Mmos  = getMmos  (m, c);
       if (Mmos == NO_MAG) continue;
Index: /trunk/Ohana/src/relphot/src/MosaicOps.c
===================================================================
--- /trunk/Ohana/src/relphot/src/MosaicOps.c	(revision 15037)
+++ /trunk/Ohana/src/relphot/src/MosaicOps.c	(revision 15038)
@@ -348,5 +348,5 @@
       if (Mcal == NO_MAG) continue;
       if (Mcal == NO_IMAGE) continue;
-      if (catalog[c].measure[m].flags & MEAS_BAD) continue;
+      if (catalog[c].measure[m].dbFlags & MEAS_BAD) continue;
       if ((Mgrid = getMgrid (m, c)) == NO_MAG) continue;
       if ((Mrel  = getMrel  (catalog, m, c)) == NO_MAG) continue;
@@ -593,5 +593,5 @@
       c = clist[i][j];
       
-      if (catalog[c].measure[m].flags & (ID_MEAS_AREA | ID_MEAS_NOCAL)) continue;
+      if (catalog[c].measure[m].dbFlags & (ID_MEAS_AREA | ID_MEAS_NOCAL)) continue;
 
       ave = catalog[c].measure[m].averef;
Index: /trunk/Ohana/src/relphot/src/StarOps.c
===================================================================
--- /trunk/Ohana/src/relphot/src/StarOps.c	(revision 15037)
+++ /trunk/Ohana/src/relphot/src/StarOps.c	(revision 15038)
@@ -51,5 +51,5 @@
       N = 0;
       for (k = 0; k < catalog[i].average[j].Nm; k++, m++) {
-	if (catalog[i].measure[m].flags & MEAS_BAD) continue;
+	if (catalog[i].measure[m].dbFlags & MEAS_BAD) continue;
 	Mcal  = getMcal  (m, i);
 	if (Mcal == NO_MAG) continue;
@@ -110,5 +110,5 @@
       m = catalog[i].average[j].offset;
       for (k = 0; k < catalog[i].average[j].Nm; k++, m++) {
-	if (catalog[i].measure[m].flags & MEAS_BAD) continue;
+	if (catalog[i].measure[m].dbFlags & MEAS_BAD) continue;
 	Mcal  = getMcal  (m, i);
 	if (Mcal == NO_MAG) continue;
@@ -158,5 +158,5 @@
       m = catalog[i].average[j].offset;
       for (k = 0; k < catalog[i].average[j].Nm; k++, m++) {
-	if (catalog[i].measure[m].flags & MEAS_BAD) continue;
+	if (catalog[i].measure[m].dbFlags & MEAS_BAD) continue;
 	Mcal  = getMcal  (m, i);
 	if (Mcal == NO_MAG) continue;
@@ -272,5 +272,5 @@
       N = 0;
       for (k = 0; k < catalog[i].average[j].Nm; k++, m++) {
-	/* if (catalog[i].measure[m].flags & MEAS_BAD) continue; */
+	/* if (catalog[i].measure[m].dbFlags & MEAS_BAD) continue; */
 	Mcal  = getMcal  (m, i);
 	if (Mcal == NO_MAG) continue;
@@ -308,5 +308,5 @@
       N = 0;
       for (k = 0; k < catalog[i].average[j].Nm; k++, m++) {
-	/* if (catalog[i].measure[m].flags & MEAS_BAD) continue; */
+	/* if (catalog[i].measure[m].dbFlags & MEAS_BAD) continue; */
 	Mcal  = getMcal  (m, i);
 	if (Mcal == NO_MAG) continue;
@@ -329,5 +329,5 @@
       for (k = 0; k < N; k++) {
 	if (fabs (list[k] - stats.median) > Ns*stats.sigma) {
-	  catalog[i].measure[ilist[k]].flags |= ID_MEAS_POOR;
+	  catalog[i].measure[ilist[k]].dbFlags |= ID_MEAS_POOR;
 	  Ndel ++;
 	}
Index: /trunk/Ohana/src/relphot/src/bcatalog.c
===================================================================
--- /trunk/Ohana/src/relphot/src/bcatalog.c	(revision 15037)
+++ /trunk/Ohana/src/relphot/src/bcatalog.c	(revision 15038)
@@ -66,13 +66,13 @@
       }
 
-      subcatalog[0].measure[Nmeasure].flags &= ~ID_MEAS_SKIP;
+      subcatalog[0].measure[Nmeasure].dbFlags &= ~ID_MEAS_SKIP;
       subcatalog[0].measure[Nmeasure]        = catalog[0].measure[offset];
       subcatalog[0].measure[Nmeasure].averef = Naverage;
       if (RESET) { 
 	subcatalog[0].measure[Nmeasure].Mcal = 0;
-	subcatalog[0].measure[Nmeasure].flags &= 0xff00;
-	subcatalog[0].measure[Nmeasure].flags &= ~ID_MEAS_POOR;
-	subcatalog[0].measure[Nmeasure].flags &= ~ID_MEAS_AREA;
-	subcatalog[0].measure[Nmeasure].flags &= ~ID_MEAS_NOCAL;
+	subcatalog[0].measure[Nmeasure].dbFlags &= 0xff00;
+	subcatalog[0].measure[Nmeasure].dbFlags &= ~ID_MEAS_POOR;
+	subcatalog[0].measure[Nmeasure].dbFlags &= ~ID_MEAS_AREA;
+	subcatalog[0].measure[Nmeasure].dbFlags &= ~ID_MEAS_NOCAL;
       }
       Nmeasure ++;
Index: /trunk/Ohana/src/relphot/src/plot_scatter.c
===================================================================
--- /trunk/Ohana/src/relphot/src/plot_scatter.c	(revision 15037)
+++ /trunk/Ohana/src/relphot/src/plot_scatter.c	(revision 15038)
@@ -27,5 +27,5 @@
 
       for (k = 0; k < catalog[i].average[j].Nm; k++, m++) {
-	if (catalog[i].measure[m].flags & MEAS_BAD) continue;
+	if (catalog[i].measure[m].dbFlags & MEAS_BAD) continue;
 	Mcal  = getMcal  (m, i);
 	if (Mcal == NO_MAG) continue;
Index: /trunk/Ohana/src/relphot/src/setExclusions.c
===================================================================
--- /trunk/Ohana/src/relphot/src/setExclusions.c	(revision 15037)
+++ /trunk/Ohana/src/relphot/src/setExclusions.c	(revision 15038)
@@ -38,10 +38,10 @@
 
       markbad:
-	catalog[i].measure[m].flags |= ID_MEAS_AREA;
+	catalog[i].measure[m].dbFlags |= ID_MEAS_AREA;
 	Narea ++;
 	continue;
 	
       mark_nocal:
-	catalog[i].measure[m].flags |= ID_MEAS_NOCAL;
+	catalog[i].measure[m].dbFlags |= ID_MEAS_NOCAL;
 	Nnocal ++;
 	continue;
Index: /trunk/Ohana/src/relphot/src/setMrelFinal.c
===================================================================
--- /trunk/Ohana/src/relphot/src/setMrelFinal.c	(revision 15037)
+++ /trunk/Ohana/src/relphot/src/setMrelFinal.c	(revision 15038)
@@ -27,9 +27,9 @@
 	
 	catalog[0].measure[m].Mcal = 0;
-	catalog[0].measure[m].flags &= 0xff00;
-	catalog[0].measure[m].flags &= ~ID_MEAS_POOR;
-	catalog[0].measure[m].flags &= ~ID_MEAS_SKIP;
-	catalog[0].measure[m].flags &= ~ID_MEAS_AREA;
-	catalog[0].measure[m].flags &= ~ID_MEAS_NOCAL;
+	catalog[0].measure[m].dbFlags &= 0xff00;
+	catalog[0].measure[m].dbFlags &= ~ID_MEAS_POOR;
+	catalog[0].measure[m].dbFlags &= ~ID_MEAS_SKIP;
+	catalog[0].measure[m].dbFlags &= ~ID_MEAS_AREA;
+	catalog[0].measure[m].dbFlags &= ~ID_MEAS_NOCAL;
       }
     }
@@ -58,5 +58,5 @@
     m = catalog[0].average[i].offset;
     for (j = 0; j < catalog[0].average[i].Nm; j++, m++) {
-      catalog[0].measure[m].flags &= ~ID_MEAS_NOCAL;
+      catalog[0].measure[m].dbFlags &= ~ID_MEAS_NOCAL;
     }
   }
@@ -88,5 +88,5 @@
 
       /* clear SKIP for all measures at first */
-      catalog[0].measure[m].flags &= ~ID_MEAS_SKIP;
+      catalog[0].measure[m].dbFlags &= ~ID_MEAS_SKIP;
 
       /** never use these measurements (wrong photcode, bad time range) */
@@ -129,5 +129,5 @@
 
     skip:
-      catalog[0].measure[m].flags |= ID_MEAS_SKIP;
+      catalog[0].measure[m].dbFlags |= ID_MEAS_SKIP;
       Nskip ++;
     }
