Index: trunk/Ohana/src/addstar/src/ReadStarsFITS.c
===================================================================
--- trunk/Ohana/src/addstar/src/ReadStarsFITS.c	(revision 37116)
+++ trunk/Ohana/src/addstar/src/ReadStarsFITS.c	(revision 37246)
@@ -182,5 +182,4 @@
     stars[i].measure.psfNdof    = NAN_S_INT; // not provided by SMPDATA:
     stars[i].measure.psfNpix    = NAN_S_INT; // not provided by SMPDATA:
-    stars[i].measure.crNsigma   = NAN;       // not provided by SMPDATA:
     stars[i].measure.extNsigma  = NAN;	     // not provided by SMPDATA:
 
@@ -251,5 +250,4 @@
     stars[i].measure.psfNdof    = NAN_S_INT; // not provided by PS1_DEV_0:
     stars[i].measure.psfNpix    = NAN_S_INT; // not provided by PS1_DEV_0:
-    stars[i].measure.crNsigma   = NAN;       // not provided by PS1_DEV_0:
     stars[i].measure.extNsigma  = NAN;        // not provided by PS1_DEV_0:
 
@@ -323,5 +321,4 @@
     stars[i].measure.psfNdof    = NAN_S_INT; // not provided by PS1_DEV_1:
     stars[i].measure.psfNpix    = NAN_S_INT; // not provided by PS1_DEV_1:
-    stars[i].measure.crNsigma   = ps1data[i].crNsigma;
     stars[i].measure.extNsigma  = ps1data[i].extNsigma;
 
@@ -408,5 +405,4 @@
     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;
 
@@ -494,5 +490,4 @@
     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;
 
@@ -572,5 +567,4 @@
     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;
 
@@ -653,5 +647,4 @@
     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;
 
@@ -665,4 +658,5 @@
                         
     stars[i].measure.photFlags  = ps1data[i].flags;
+    stars[i].measure.photFlags2 = ps1data[i].flags2;
 
     // this is may optionally be replaced by the internal sequence (see FilterStars.c)
@@ -738,5 +732,4 @@
     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;
 
@@ -750,4 +743,5 @@
                         
     stars[i].measure.photFlags  = ps1data[i].flags;
+    stars[i].measure.photFlags2 = ps1data[i].flags2;
 
     // this is may optionally be replaced by the internal sequence (see FilterStars.c)
@@ -823,5 +817,4 @@
     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;
 
@@ -835,4 +828,5 @@
                         
     stars[i].measure.photFlags  = ps1data[i].flags;
+    stars[i].measure.photFlags2 = ps1data[i].flags2;
 
     // this is may optionally be replaced by the internal sequence (see FilterStars.c)
@@ -908,5 +902,4 @@
     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;
 
@@ -920,4 +913,5 @@
                         
     stars[i].measure.photFlags  = ps1data[i].flags;
+    stars[i].measure.photFlags2 = ps1data[i].flags2;
 
     // this is may optionally be replaced by the internal sequence (see FilterStars.c)
@@ -1038,5 +1032,4 @@
     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;
 
@@ -1050,4 +1043,5 @@
                         
     stars[i].measure.photFlags  = ps1data[i].flags;
+    stars[i].measure.photFlags2 = ps1data[i].flags2;
 
     // this is may optionally be replaced by the internal sequence (see FilterStars.c)
@@ -1120,5 +1114,4 @@
     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;
 
@@ -1132,4 +1125,5 @@
                         
     stars[i].measure.photFlags  = ps1data[i].flags;
+    stars[i].measure.photFlags2 = ps1data[i].flags2;
 
     // this is may optionally be replaced by the internal sequence (see FilterStars.c)
@@ -1202,5 +1196,4 @@
     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;
 
@@ -1214,4 +1207,5 @@
                         
     stars[i].measure.photFlags  = ps1data[i].flags;
+    stars[i].measure.photFlags2 = ps1data[i].flags2;
 
     // this is may optionally be replaced by the internal sequence (see FilterStars.c)
@@ -1284,5 +1278,4 @@
     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;
 
@@ -1296,4 +1289,5 @@
                         
     stars[i].measure.photFlags  = ps1data[i].flags;
+    stars[i].measure.photFlags2 = ps1data[i].flags2;
 
     // this is may optionally be replaced by the internal sequence (see FilterStars.c)
@@ -1365,5 +1359,4 @@
     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;
 
@@ -1377,4 +1370,5 @@
                         
     stars[i].measure.photFlags  = ps1data[i].flags;
+    stars[i].measure.photFlags2 = ps1data[i].flags2;
 
     // this is may optionally be replaced by the internal sequence (see FilterStars.c)
@@ -1451,5 +1445,4 @@
     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;
 
@@ -1463,4 +1456,5 @@
                         
     stars[i].measure.photFlags  = ps1data[i].flags;
+    stars[i].measure.photFlags2 = ps1data[i].flags2;
 
     // this is may optionally be replaced by the internal sequence (see FilterStars.c)
Index: trunk/Ohana/src/addstar/src/mkcmf.c
===================================================================
--- trunk/Ohana/src/addstar/src/mkcmf.c	(revision 37116)
+++ trunk/Ohana/src/addstar/src/mkcmf.c	(revision 37246)
@@ -31,4 +31,6 @@
 static Coords coords;
 
+static char reserved[] =  "Reserved space.  This line can be used to add a new FITS card.";
+
 int main (int argc, char **argv) {
 
@@ -305,4 +307,9 @@
   PutCoords (&coords, &header);
   gfits_modify (&header, "EXTNAME",   "%s", 1, exthead);
+
+  int i;
+  for (i = 1; i < 32; i++) {
+    gfits_modify_alt (&header, "COMMENT", "%C", i, reserved);
+  }
 
   ftable.header = &theader;
Index: trunk/Ohana/src/dvopsps/include/dvopsps.h
===================================================================
--- trunk/Ohana/src/dvopsps/include/dvopsps.h	(revision 37116)
+++ trunk/Ohana/src/dvopsps/include/dvopsps.h	(revision 37246)
@@ -9,19 +9,27 @@
 
 typedef struct {
-  int imageID;
-  unsigned int ippDetectID;
+  uint64_t objID;
   uint64_t detectID;
   uint64_t ippObjID;
-  uint64_t objID;
-  int      photcode;
-  unsigned int flags;
-  float zp;
-  float zpErr;
-  float airMass;
-  float expTime;
+  unsigned int ippDetectID;
+  int imageID;
+  int catID;
   double ra;
   double dec;
   float raErr;
   float decErr;
+  float zp;
+  float telluricExt;
+  float airmass;
+  float expTime;
+
+  float Mpsf;
+  float dMpsf;
+  float Mkron;
+  float dMkron;
+  float Map;
+  float dMap;
+
+  unsigned int flags;
 } Detections;
 
@@ -78,9 +86,10 @@
       
 int    insert_detections_mysql_commit     PROTO((IOBuffer *buffer, MYSQL *mysql));
-int    insert_detections_mysql_value      PROTO((IOBuffer *buffer, Average *average, Measure *measure));
+// int    insert_detections_mysql_value      PROTO((IOBuffer *buffer, Average *average, Measure *measure));
 int    insert_detections_mysql_init       PROTO((IOBuffer *buffer));
 
 int    insert_detections_mysql_array      PROTO((MYSQL *mysql, Detections *detections, int Ndetections));
 int    insert_detections_mysql_detvalue   PROTO((IOBuffer *buffer, Detections *detection));
+int    assign_detection_values            PROTO((Detections *detection, Measure *measure, Average *average));
 
 int    init_detections                    PROTO(());
Index: trunk/Ohana/src/dvopsps/src/DetectionOps.c
===================================================================
--- trunk/Ohana/src/dvopsps/src/DetectionOps.c	(revision 37116)
+++ trunk/Ohana/src/dvopsps/src/DetectionOps.c	(revision 37246)
@@ -1,6 +1,3 @@
 # include "dvopsps.h"
-# define BZERO_INT16 1.0*0x8000
-# define BZERO_INT32 1.0*0x80000000
-# define BZERO_INT64 1.0*0x8000000000000000
 
 # define GET_COLUMN(OUT,NAME,TYPE)					\
@@ -49,19 +46,25 @@
  
   // need to create and assign to flat-field correction
-  GET_COLUMN(imageID     , "imageID",     int);
-  GET_COLUMN(ippDetectID , "ippDetectID", int);
+  GET_COLUMN(objID       , "objID",       int64_t);
   GET_COLUMN(detectID    , "detectID",    int64_t);
   GET_COLUMN(ippObjID    , "ippObjID",    int64_t);
-  GET_COLUMN(objID       , "objID",       int64_t);
-  GET_COLUMN(photcode    , "photcode",    int);
-  GET_COLUMN(flags       , "flags",       int);
-  GET_COLUMN(zp          , "zp",          float);
-  GET_COLUMN(zpErr       , "zpErr",       float);
-  GET_COLUMN(airMass     , "airMass",     float);
-  GET_COLUMN(expTime     , "expTime",     float);
+  GET_COLUMN(ippDetectID , "ippDetectID", int);
+  GET_COLUMN(imageID     , "imageID",     int);
+  GET_COLUMN(catID       , "catID",       int);
   GET_COLUMN(ra          , "ra",          double); // XXX signed vs unsigned?
   GET_COLUMN(dec         , "dec",         double);
   GET_COLUMN(raErr       , "raErr",       float);
   GET_COLUMN(decErr      , "decErr",      float);
+  GET_COLUMN(zp          , "zp",          float);
+  GET_COLUMN(telluricExt , "telluricExt", float);
+  GET_COLUMN(airmass     , "airmass",     float);
+  GET_COLUMN(expTime     , "expTime",     float);
+  GET_COLUMN(Mpsf        , "Mpsf",        float);
+  GET_COLUMN(dMpsf       , "dMpsf",       float);
+  GET_COLUMN(Mkron       , "Mkron",       float);
+  GET_COLUMN(dMkron      , "dMkron",      float);
+  GET_COLUMN(Map         , "Map",         float);
+  GET_COLUMN(dMap        , "dMap",        float);
+  GET_COLUMN(flags       , "flags",       int);
   gfits_free_header (&theader);
   gfits_free_table  (&ftable);
@@ -69,37 +72,49 @@
   ALLOCATE (detections, Detections, Nrow);
   for (i = 0; i < Nrow; i++) {
-    detections[i].imageID      = imageID[i];    
-    detections[i].ippDetectID  = ippDetectID[i];
+    detections[i].objID        = objID[i];      
     detections[i].detectID     = detectID[i];   
     detections[i].ippObjID     = ippObjID[i];   
-    detections[i].objID        = objID[i];      
-    detections[i].photcode     = photcode[i];      
-    detections[i].flags        = flags[i];      
-    detections[i].zp           = zp[i];         
-    detections[i].zpErr        = zpErr[i];      
-    detections[i].airMass      = airMass[i];    
-    detections[i].expTime      = expTime[i];    
+    detections[i].ippDetectID  = ippDetectID[i];
+    detections[i].imageID      = imageID[i];    
+    detections[i].catID        = catID[i];    
     detections[i].ra           = ra[i];         
     detections[i].dec          = dec[i];        
     detections[i].raErr        = raErr[i];      
     detections[i].decErr       = decErr[i];     
+    detections[i].zp           = zp[i];         
+    detections[i].telluricExt  = telluricExt[i];      
+    detections[i].airmass      = airmass[i];    
+    detections[i].expTime      = expTime[i];    
+    detections[i].Mpsf         = Mpsf[i];    
+    detections[i].dMpsf        = dMpsf[i];    
+    detections[i].Mkron        = Mkron[i];    
+    detections[i].dMkron       = dMkron[i];    
+    detections[i].Map          = Map[i];    
+    detections[i].dMap         = dMap[i];    
+    detections[i].flags        = flags[i];      
   }
   fprintf (stderr, "loaded data for %lld detections\n", (long long) Nrow);
 
-  free (imageID    );
-  free (ippDetectID);
+  free (objID      );
   free (detectID   );
   free (ippObjID   );
-  free (objID      );
-  free (photcode   );
-  free (flags      );
-  free (zp         );
-  free (zpErr      );
-  free (airMass    );
-  free (expTime    );
+  free (ippDetectID);
+  free (imageID    );
+  free (catID      );
   free (ra         );
   free (dec        );
   free (raErr      );
   free (decErr     );
+  free (zp         );
+  free (telluricExt);
+  free (airmass    );
+  free (expTime    );
+  free (Mpsf       );
+  free (dMpsf      );
+  free (Mkron      );
+  free (dMkron     );
+  free (Map        );
+  free (dMap       );
+  free (flags      );
 
   gfits_free_header (&header);
@@ -149,22 +164,25 @@
 
   // XXX need to get the bzero values right
-  gfits_define_bintable_column (&theader, "J", "imageID",     NULL, NULL, 1.0, BZERO_INT32);
-  gfits_define_bintable_column (&theader, "J", "ippDetectID", NULL, NULL, 1.0, BZERO_INT32);
+  gfits_define_bintable_column (&theader, "K", "objID",       NULL, NULL, 1.0, 0);
   gfits_define_bintable_column (&theader, "K", "detectID",    NULL, NULL, 1.0, 0);
   gfits_define_bintable_column (&theader, "K", "ippObjID",    NULL, NULL, 1.0, 0);
-  gfits_define_bintable_column (&theader, "K", "objID",       NULL, NULL, 1.0, 0);
-  // gfits_define_bintable_column (&theader, "K", "detectID",    NULL, NULL, 1.0, BZERO_INT64);
-  // gfits_define_bintable_column (&theader, "K", "ippObjID",    NULL, NULL, 1.0, BZERO_INT64);
-  // gfits_define_bintable_column (&theader, "K", "objID",       NULL, NULL, 1.0, BZERO_INT64);
-  gfits_define_bintable_column (&theader, "J", "photcode",    NULL, NULL, 1.0, 0.0);
-  gfits_define_bintable_column (&theader, "J", "flags",       NULL, NULL, 1.0, BZERO_INT32);
-  gfits_define_bintable_column (&theader, "E", "zp",          NULL, NULL, 1.0, 0.0);
-  gfits_define_bintable_column (&theader, "E", "zpErr",       NULL, NULL, 1.0, 0.0);
-  gfits_define_bintable_column (&theader, "E", "airMass",     NULL, NULL, 1.0, 0.0);
-  gfits_define_bintable_column (&theader, "E", "expTime",     NULL, NULL, 1.0, 0.0);
+  gfits_define_bintable_column (&theader, "J", "ippDetectID", NULL, NULL, 1.0, FT_BZERO_INT32);
+  gfits_define_bintable_column (&theader, "J", "imageID",     NULL, NULL, 1.0, FT_BZERO_INT32);
+  gfits_define_bintable_column (&theader, "J", "catID",       NULL, NULL, 1.0, FT_BZERO_INT32);
   gfits_define_bintable_column (&theader, "D", "ra",          NULL, NULL, 1.0, 0.0);
   gfits_define_bintable_column (&theader, "D", "dec",         NULL, NULL, 1.0, 0.0);
   gfits_define_bintable_column (&theader, "E", "raErr",       NULL, NULL, 1.0, 0.0);
   gfits_define_bintable_column (&theader, "E", "decErr",      NULL, NULL, 1.0, 0.0);
+  gfits_define_bintable_column (&theader, "E", "zp",          NULL, NULL, 1.0, 0.0);
+  gfits_define_bintable_column (&theader, "E", "telluricExt", NULL, NULL, 1.0, 0.0);
+  gfits_define_bintable_column (&theader, "E", "airmass",     NULL, NULL, 1.0, 0.0);
+  gfits_define_bintable_column (&theader, "E", "expTime",     NULL, NULL, 1.0, 0.0);
+  gfits_define_bintable_column (&theader, "E", "Mpsf",        NULL, NULL, 1.0, 0.0);
+  gfits_define_bintable_column (&theader, "E", "dMpsf",       NULL, NULL, 1.0, 0.0);
+  gfits_define_bintable_column (&theader, "E", "Mkron",       NULL, NULL, 1.0, 0.0);
+  gfits_define_bintable_column (&theader, "E", "dMkron",      NULL, NULL, 1.0, 0.0);
+  gfits_define_bintable_column (&theader, "E", "Map",         NULL, NULL, 1.0, 0.0);
+  gfits_define_bintable_column (&theader, "E", "dMap",        NULL, NULL, 1.0, 0.0);
+  gfits_define_bintable_column (&theader, "J", "flags",       NULL, NULL, 1.0, FT_BZERO_INT32);
 
   // generate the output array that carries the data
@@ -172,71 +190,95 @@
 
   // create intermediate storage arrays
-   int32_t   *imageID     ; ALLOCATE (imageID     ,   int32_t, Ndetections);
-  uint32_t   *ippDetectID ; ALLOCATE (ippDetectID ,  uint32_t, Ndetections);
+  uint64_t   *objID       ; ALLOCATE (objID       ,  uint64_t, Ndetections);
   uint64_t   *detectID    ; ALLOCATE (detectID    ,  uint64_t, Ndetections);
   uint64_t   *ippObjID    ; ALLOCATE (ippObjID    ,  uint64_t, Ndetections);
-  uint64_t   *objID       ; ALLOCATE (objID       ,  uint64_t, Ndetections);
-  int        *photcode    ; ALLOCATE (photcode    ,  int,      Ndetections);
-  uint32_t   *flags       ; ALLOCATE (flags       ,  uint32_t, Ndetections);
-  float      *zp          ; ALLOCATE (zp          ,  float,    Ndetections);
-  float      *zpErr       ; ALLOCATE (zpErr       ,  float,    Ndetections);
-  float      *airMass     ; ALLOCATE (airMass     ,  float,    Ndetections);
-  float      *expTime     ; ALLOCATE (expTime     ,  float,    Ndetections);
+  uint32_t   *ippDetectID ; ALLOCATE (ippDetectID ,  uint32_t, Ndetections);
+   int32_t   *imageID     ; ALLOCATE (imageID     ,   int32_t, Ndetections);
+   int32_t   *catID       ; ALLOCATE (catID       ,   int32_t, Ndetections);
   double     *ra          ; ALLOCATE (ra          ,  double,   Ndetections);
   double     *dec         ; ALLOCATE (dec         ,  double,   Ndetections);
   float      *raErr       ; ALLOCATE (raErr       ,  float,    Ndetections);
   float      *decErr      ; ALLOCATE (decErr      ,  float,    Ndetections);
+  float      *zp          ; ALLOCATE (zp          ,  float,    Ndetections);
+  float      *telluricExt ; ALLOCATE (telluricExt ,  float,    Ndetections);
+  float      *airmass     ; ALLOCATE (airmass     ,  float,    Ndetections);
+  float      *expTime     ; ALLOCATE (expTime     ,  float,    Ndetections);
+  float      *Mpsf        ; ALLOCATE (Mpsf        ,  float,    Ndetections);
+  float      *dMpsf       ; ALLOCATE (dMpsf       ,  float,    Ndetections);
+  float      *Mkron       ; ALLOCATE (Mkron       ,  float,    Ndetections);
+  float      *dMkron      ; ALLOCATE (dMkron      ,  float,    Ndetections);
+  float      *Map         ; ALLOCATE (Map         ,  float,    Ndetections);
+  float      *dMap        ; ALLOCATE (dMap        ,  float,    Ndetections);
+  uint32_t   *flags       ; ALLOCATE (flags       ,  uint32_t, Ndetections);
 
   // assign the storage arrays
   for (i = 0; i < Ndetections; i++) {
-    imageID[i]     = detections[i].imageID     ;
-    ippDetectID[i] = detections[i].ippDetectID ;
+    objID[i]       = detections[i].objID       ;
     detectID[i]    = detections[i].detectID    ;
     ippObjID[i]    = detections[i].ippObjID    ;
-    objID[i]       = detections[i].objID       ;
-    photcode[i]    = detections[i].photcode    ;
-    flags[i]       = detections[i].flags       ;
-    zp[i]          = detections[i].zp          ;
-    zpErr[i]       = detections[i].zpErr       ;
-    airMass[i]     = detections[i].airMass     ;
-    expTime[i]     = detections[i].expTime     ;
+    ippDetectID[i] = detections[i].ippDetectID ;
+    imageID[i]     = detections[i].imageID     ;
+    catID[i]       = detections[i].catID       ;
     ra[i]          = detections[i].ra          ;
     dec[i]         = detections[i].dec         ;
     raErr[i]       = detections[i].raErr       ;
     decErr[i]      = detections[i].decErr      ;
+    zp[i]          = detections[i].zp          ;
+    telluricExt[i] = detections[i].telluricExt ;
+    airmass[i]     = detections[i].airmass     ;
+    expTime[i]     = detections[i].expTime     ;
+    Mpsf[i]        = detections[i].Mpsf        ;
+    dMpsf[i]       = detections[i].dMpsf       ;
+    Mkron[i]       = detections[i].Mkron       ;
+    dMkron[i]      = detections[i].dMkron      ;
+    Map[i]         = detections[i].Map         ;
+    dMap[i]        = detections[i].dMap        ;
+    flags[i]       = detections[i].flags       ;
   }
 
   // add the columns to the output array
-  gfits_set_bintable_column (&theader, &ftable, "imageID",     imageID     , Ndetections);
-  gfits_set_bintable_column (&theader, &ftable, "ippDetectID", ippDetectID , Ndetections);
+  gfits_set_bintable_column (&theader, &ftable, "objID",       objID       , Ndetections);
   gfits_set_bintable_column (&theader, &ftable, "detectID",    detectID    , Ndetections);
   gfits_set_bintable_column (&theader, &ftable, "ippObjID",    ippObjID    , Ndetections);
-  gfits_set_bintable_column (&theader, &ftable, "objID",       objID       , Ndetections);
-  gfits_set_bintable_column (&theader, &ftable, "photcode",    photcode    , Ndetections);
-  gfits_set_bintable_column (&theader, &ftable, "flags",       flags       , Ndetections);
-  gfits_set_bintable_column (&theader, &ftable, "zp",          zp          , Ndetections);
-  gfits_set_bintable_column (&theader, &ftable, "zpErr",       zpErr       , Ndetections);
-  gfits_set_bintable_column (&theader, &ftable, "airMass",     airMass     , Ndetections);
-  gfits_set_bintable_column (&theader, &ftable, "expTime",     expTime     , Ndetections);
+  gfits_set_bintable_column (&theader, &ftable, "ippDetectID", ippDetectID , Ndetections);
+  gfits_set_bintable_column (&theader, &ftable, "imageID",     imageID     , Ndetections);
+  gfits_set_bintable_column (&theader, &ftable, "catID",       catID       , Ndetections);
   gfits_set_bintable_column (&theader, &ftable, "ra",          ra          , Ndetections);
   gfits_set_bintable_column (&theader, &ftable, "dec",         dec         , Ndetections);
   gfits_set_bintable_column (&theader, &ftable, "raErr",       raErr       , Ndetections);
   gfits_set_bintable_column (&theader, &ftable, "decErr",      decErr      , Ndetections);
-
-  free (imageID     );
-  free (ippDetectID );
+  gfits_set_bintable_column (&theader, &ftable, "zp",          zp          , Ndetections);
+  gfits_set_bintable_column (&theader, &ftable, "telluricExt", telluricExt , Ndetections);
+  gfits_set_bintable_column (&theader, &ftable, "airmass",     airmass     , Ndetections);
+  gfits_set_bintable_column (&theader, &ftable, "expTime",     expTime     , Ndetections);
+  gfits_set_bintable_column (&theader, &ftable, "Mpsf",        Mpsf        , Ndetections);
+  gfits_set_bintable_column (&theader, &ftable, "dMpsf",       dMpsf       , Ndetections);
+  gfits_set_bintable_column (&theader, &ftable, "Mkron",       Mkron       , Ndetections);
+  gfits_set_bintable_column (&theader, &ftable, "dMkron",      dMkron      , Ndetections);
+  gfits_set_bintable_column (&theader, &ftable, "Map",         Map         , Ndetections);
+  gfits_set_bintable_column (&theader, &ftable, "dMap",        dMap        , Ndetections);
+  gfits_set_bintable_column (&theader, &ftable, "flags",       flags       , Ndetections);
+
+  free (objID       );
   free (detectID    );
   free (ippObjID    );
-  free (objID       );
-  free (photcode    );
-  free (flags       );
-  free (zp          );
-  free (zpErr       );
-  free (airMass     );
-  free (expTime     );
+  free (ippDetectID );
+  free (imageID     );
+  free (catID       );
   free (ra          );
   free (dec         );
   free (raErr       );
   free (decErr      );
+  free (zp          );
+  free (telluricExt );
+  free (airmass     );
+  free (expTime     );
+  free (Mpsf        );
+  free (dMpsf       );
+  free (Mkron       );
+  free (dMkron      );
+  free (Map         );
+  free (dMap        );
+  free (flags       );
 
   gfits_fwrite_Theader (f, &theader);
Index: trunk/Ohana/src/dvopsps/src/insert_detections_dvopsps.c
===================================================================
--- trunk/Ohana/src/dvopsps/src/insert_detections_dvopsps.c	(revision 37116)
+++ trunk/Ohana/src/dvopsps/src/insert_detections_dvopsps.c	(revision 37246)
@@ -281,24 +281,2 @@
 }
 
-# define PRINT_FLOAT(BUFFER,FIELD,FORMAT)		  \
-  if (!isfinite(FIELD)) PrintIOBuffer (BUFFER, "NULL, "); \
-  else PrintIOBuffer (BUFFER, FORMAT, FIELD); 
-
-int insert_detections_mysql_detvalue (IOBuffer *buffer, Detections *detection) {
-
-  PrintIOBuffer (buffer, "(%d, ", detection->imageID);	  // imageID
-  PrintIOBuffer (buffer, "%u, ", detection->ippDetectID); // ippDetectID
-  PrintIOBuffer (buffer, "%lu, ", detection->detectID);	  // detectID
-  PrintIOBuffer (buffer, "%lu, ", detection->ippObjID);	  // ippObjID
-  PrintIOBuffer (buffer, "%lu, ", detection->objID);	  // objID
-  PrintIOBuffer (buffer, "%u, ", detection->flags);	  // flags
-  PRINT_FLOAT(buffer, detection->zp,      "%.6f, ");
-  PRINT_FLOAT(buffer, detection->zpErr,   "%.6f, ");
-  PRINT_FLOAT(buffer, detection->airMass, "%.6f, ");
-  PRINT_FLOAT(buffer, detection->expTime, "%.6f, ");
-  PRINT_FLOAT(buffer, detection->ra,      "%.8f, ");
-  PRINT_FLOAT(buffer, detection->dec,     "%.8f, ");
-  PRINT_FLOAT(buffer, detection->raErr,   "%.6f, ");
-  PRINT_FLOAT(buffer, detection->decErr,  "%.6f),\n");
-  return TRUE;
-}
Index: trunk/Ohana/src/dvopsps/src/insert_detections_dvopsps_catalog.c
===================================================================
--- trunk/Ohana/src/dvopsps/src/insert_detections_dvopsps_catalog.c	(revision 37116)
+++ trunk/Ohana/src/dvopsps/src/insert_detections_dvopsps_catalog.c	(revision 37246)
@@ -6,4 +6,6 @@
 Detections *detections = NULL;
 
+static float ZeroPoint = 25.0;
+
 int init_detections () {
   NDETECTIONS = 1000;
@@ -15,4 +17,6 @@
 
   off_t i, j;
+
+  ZeroPoint = GetZeroPoint();
 
   int missingID = 0;
@@ -47,25 +51,7 @@
       if (measure->photcode >=  PHOTCODE_END) continue;
 
-      PhotCode *code = GetPhotcodebyCode(measure->photcode);
-
-      detections[Ndetections].imageID     = measure->imageID;    // imageID
-      detections[Ndetections].ippDetectID = measure->detID;   // ippDetectID
-      detections[Ndetections].detectID    = measure->extID;   // detectID
-      detections[Ndetections].ippObjID    = ((uint64_t)average->catID * 1000000000) + (uint64_t)average->objID; // ippObjID
-      // NOTE: this is better, but the above is the current ippToPsps value
-      // detections[Ndetections]. ((uint64_t)average->catID << 32) + (uint64_t)average->objID; // ippObjID
-      detections[Ndetections].objID	   = average->extID;   // objID
-      detections[Ndetections].photcode	   = measure->photcode;   // photcode
-      detections[Ndetections].flags 	   = measure->dbFlags;  // flags
-      detections[Ndetections].zp 	   = code->C * 0.001 + code->K * (measure->airmass - 1) - measure->Mcal;   // zp
-      detections[Ndetections].zpErr 	   = measure->dMcal;    // zpErr
-      detections[Ndetections].airMass      = measure->airmass;
-      detections[Ndetections].expTime      = pow(10.0, 0.4 * measure->dt);    // expTime
-      detections[Ndetections].ra 	   = measure->R;    // ra
-      detections[Ndetections].dec 	   = measure->D;    // dec
-      detections[Ndetections].raErr 	   = measure->dXccd * 0.01 * fabs(measure->pltscale); // estimate of raErr
-      detections[Ndetections].decErr	   = measure->dYccd * 0.01 * fabs(measure->pltscale); // estimate of decErr
-
+      assign_detection_values (&detections[Ndetections], measure, average);
       Ndetections ++;
+
       myAssert (Ndetections <= NDETECTIONS, "programming error");
     }
@@ -109,4 +95,6 @@
 
   off_t found = 0;
+
+  ZeroPoint = GetZeroPoint();
 
   INITTIME;
@@ -143,5 +131,8 @@
 
       // XXX check return status
-      if (!insert_detections_mysql_value (&buffer, &average[i], &measure[Nmeas])) {
+      Detections detection;
+      assign_detection_values (&detection, &measure[Nmeas], &average[i]);
+
+      if (!insert_detections_mysql_detvalue (&buffer, &detection)) {
 	fprintf (stderr, "failure to insert detections in mysql\n");
 	status = FALSE;
@@ -194,46 +185,11 @@
   }
 
-  // PrintIOBuffer (buffer, "INSERT INTO dvoDetectionFull (imageID, ippDetectID, detectID, ippObjID, objID, photcode, flags, zp, zpErr, airMass, expTime, ra, dec_, raErr, decErr) VALUES \n");
-  PrintIOBuffer (buffer, "INSERT INTO dvoDetectionFull (imageID, ippDetectID, detectID, ippObjID, objID, flags, zp, zpErr, airMass, expTime, ra, dec_, raErr, decErr) VALUES \n");
-
-  return TRUE;
-}
-
-# define PRINT_FLOAT(BUFFER,FIELD,FORMAT)		  \
-  if (isinf(FIELD) || isnan(FIELD)) PrintIOBuffer (BUFFER, "NULL, ");	\
-  else PrintIOBuffer (BUFFER, FORMAT, FIELD); 
-
-int insert_detections_mysql_value (IOBuffer *buffer, Average *average, Measure *measure) {
-
-  PhotCode *code = GetPhotcodebyCode(measure->photcode);
-  PrintIOBuffer (buffer, "(%d, ", measure->imageID);	  // imageID
-  PrintIOBuffer (buffer, "%u, ", measure->detID); // ippDetectID
-  PrintIOBuffer (buffer, "%lu, ", measure->extID);	  // detectID
-  PrintIOBuffer (buffer, "%lu, ", ((uint64_t)average->catID * 1000000000) + (uint64_t)average->objID);	  // ippObjID
-  // NOTE: the following is better, but the above is the current ippToPsps value
-  // ((uint64_t)average->catID << 32) + (uint64_t)average->objID, // ippObjID
-  PrintIOBuffer (buffer, "%lu, ", average->extID);	  // objID
-  // XXX PrintIOBuffer (buffer, "%d, ", measure->photcode);	  // photcode
-  PrintIOBuffer (buffer, "%u, ", measure->dbFlags);	  // flags
-
-  float zp = code->C * 0.001 + code->K * (measure->airmass - 1) - measure->Mcal;
-  float exptime = pow(10.0, 0.4 * measure->dt);
-  double ra  = measure->R;
-  double dec = measure->D;
-  double dR = measure->dXccd * 0.01 * fabs(measure->pltscale);
-  double dD = measure->dYccd * 0.01 * fabs(measure->pltscale);
-
-  PRINT_FLOAT(buffer, zp,               "%.6f, ");
-  PRINT_FLOAT(buffer, measure->dMcal,   "%.6f, ");
-  PRINT_FLOAT(buffer, measure->airmass, "%.6f, ");
-  PRINT_FLOAT(buffer, exptime,          "%.6f, ");
-  PRINT_FLOAT(buffer, ra,               "%.8f, ");
-  PRINT_FLOAT(buffer, dec,              "%.8f, ");
-  PRINT_FLOAT(buffer, dR,               "%.6f, ");
-  PRINT_FLOAT(buffer, dD,               "%.6f),\n");
-  
-  return TRUE;
-}
-    
+  PrintIOBuffer (buffer, "INSERT INTO dvoDetectionFull (objID, detectID, ippObjID, ippDetectID, imageID, catID, ");
+  PrintIOBuffer (buffer, "ra, dec_, raErr, decErr, zp, telluricExt, airmass, expTime, ");
+  PrintIOBuffer (buffer, "Mpsf, dMpsf, Mkron, dMkron, Map, dMap, flags) VALUES \n");
+
+  return TRUE;
+}
+
 int insert_detections_mysql_commit (IOBuffer *buffer, MYSQL *mysql) {
 
@@ -270,2 +226,111 @@
   return status;
 }
+
+# define PRINT_FLOAT(BUFFER,FIELD,FORMAT)		  \
+  if (!isfinite(FIELD)) PrintIOBuffer (BUFFER, "NULL, "); \
+  else PrintIOBuffer (BUFFER, FORMAT, FIELD); 
+
+int insert_detections_mysql_detvalue (IOBuffer *buffer, Detections *detection) {
+
+  PrintIOBuffer (buffer, "(%lu, ", detection->objID);	    // objID
+  PrintIOBuffer (buffer,  "%lu, ", detection->detectID);    // detectID
+  PrintIOBuffer (buffer,  "%lu, ", detection->ippObjID);    // ippObjID
+  PrintIOBuffer (buffer,  "%u,  ", detection->ippDetectID); // ippDetectID
+  PrintIOBuffer (buffer,  "%d,  ", detection->imageID);	    // imageID
+  PrintIOBuffer (buffer,  "%d,  ", detection->catID);	    // DVO Catalog ID
+
+  PRINT_FLOAT(buffer, detection->ra,          "%.8f, ");
+  PRINT_FLOAT(buffer, detection->dec,         "%.8f, ");
+  PRINT_FLOAT(buffer, detection->raErr,       "%.6f, ");
+  PRINT_FLOAT(buffer, detection->decErr,      "%.6f, ");
+  PRINT_FLOAT(buffer, detection->zp,          "%.6f, ");
+  PRINT_FLOAT(buffer, detection->telluricExt, "%.6f, ");
+  PRINT_FLOAT(buffer, detection->airmass,     "%.6f, ");
+  PRINT_FLOAT(buffer, detection->expTime,     "%.6f, ");
+
+  PRINT_FLOAT(buffer, detection->Mpsf,        "%.6f, ");
+  PRINT_FLOAT(buffer, detection->dMpsf,       "%.6f, ");
+  PRINT_FLOAT(buffer, detection->Mkron,       "%.6f, ");
+  PRINT_FLOAT(buffer, detection->dMkron,      "%.6f, ");
+  PRINT_FLOAT(buffer, detection->Map,         "%.6f, ");
+  PRINT_FLOAT(buffer, detection->dMap,        "%.6f, ");
+
+  PrintIOBuffer (buffer, "%u),\n", detection->flags);	  // flags
+  return TRUE;
+}
+
+float getMagFromValueOrFlux (float flux, float mag, float zp) {
+
+  // first, if mag is finite, use mag:
+  if (isfinite(mag)) {
+    return (zp + mag - ZeroPoint);
+  }
+
+  if (isfinite(flux) && (flux > 0.0)) {
+    fprintf (stderr, "how did we get here?\n");
+    return (zp - 2.5*log10(flux));
+  }
+
+  if (isfinite(flux) && (flux <= 0.0)) {
+    return (NAN);
+  }
+  return (NAN);
+}
+
+float getdMagFromValueOrFlux (float flux, float dflux, float dmag) {
+
+  // first, if mag is finite, use mag:
+  if (isfinite(dmag)) {
+    return (dmag);
+  }
+
+  if (isfinite(flux) && isfinite(dflux)) {
+    return (dflux / fabs(flux));
+  }
+  return (NAN);
+}
+
+int assign_detection_values (Detections *detection, Measure *measure, Average *average) {
+
+  PhotCode *code = GetPhotcodebyCode(measure->photcode);
+
+  uint64_t ippObjID = ((uint64_t)average->catID << 32) + (uint64_t)average->objID; // ippObjID
+
+  float nominalZP   = code->C * 0.001 + code->K * (measure->airmass - 1);
+  float zp          = nominalZP - measure->Mcal;
+  float telluricExt = - measure->Mcal;
+  float expTime     = pow(10.0, 0.4 * measure->dt);
+  float airmass     = measure->airmass;
+
+  detection->objID	  = average->extID;   // objID
+  detection->detectID     = measure->extID;   // detectID
+  detection->ippObjID     = ippObjID;	      // ippObjID
+  detection->ippDetectID  = measure->detID;   // ippDetectID
+  detection->imageID      = measure->imageID; // imageID
+  detection->catID        = measure->catID;   // catID
+
+  detection->ra 	  = measure->R;    // ra
+  detection->dec 	  = measure->D;    // dec
+  detection->raErr 	  = measure->dXccd * 0.01 * fabs(measure->pltscale); // estimate of raErr
+  detection->decErr	  = measure->dYccd * 0.01 * fabs(measure->pltscale); // estimate of decErr
+
+  detection->zp 	  = zp;
+  detection->telluricExt  = telluricExt;
+  detection->airmass      = airmass;
+  detection->expTime      = expTime;
+
+  // XXX clean this up with dvo_photcode_ops calls:
+  // if (isfinite(measure->FluxPSF) && (measure->FluxPSF < 0.0)) 
+  detection->Mpsf  = getMagFromValueOrFlux (measure->FluxPSF,  measure->M,     zp);
+  detection->Mkron = getMagFromValueOrFlux (measure->FluxKron, measure->Mkron, zp);
+  detection->Map   = getMagFromValueOrFlux (measure->FluxAp,   measure->Map,   zp);
+
+  detection->dMpsf  = getdMagFromValueOrFlux (measure->FluxPSF,  measure->dFluxPSF,  measure->dM);
+  detection->dMkron = getdMagFromValueOrFlux (measure->FluxKron, measure->dFluxKron, measure->dMkron);
+  detection->dMap   = getdMagFromValueOrFlux (measure->FluxAp,   measure->dFluxAp,   measure->dMap);
+
+  detection->flags  = measure->dbFlags;  // flags
+
+  return TRUE;
+}
+
Index: trunk/Ohana/src/dvopsps/src/insert_objects_dvopsps_catalog.c
===================================================================
--- trunk/Ohana/src/dvopsps/src/insert_objects_dvopsps_catalog.c	(revision 37116)
+++ trunk/Ohana/src/dvopsps/src/insert_objects_dvopsps_catalog.c	(revision 37246)
@@ -88,37 +88,47 @@
   bzero (buffer.buffer, buffer.Nalloc);
 
+  // Only send the necessary fields (eg, do not sent parallax and pm)
   PrintIOBuffer (&buffer, "CREATE TABLE %s_cpt ("
-		 "RA DOUBLE,  "          
-		 "DEC_ DOUBLE,  "         
-		 "RA_ERR FLOAT,  "      
-		 "DEC_ERR FLOAT,  "     
-		 "U_RA FLOAT,  "        
-		 "U_DEC FLOAT,  "       
-		 "V_RA_ERR FLOAT,  "    
-		 "V_DEC_ERR FLOAT,  "   
-		 "PAR FLOAT,  "         
-		 "PAR_ERR FLOAT,  "     
-		 "CHISQ_POS FLOAT,  "   
-		 "CHISQ_PM FLOAT,  "    
-		 "CHISQ_PAP FLOAT,  "   
-		 "MEAN_EPOCH INT,  "  
-		 "TIME_RANGE INT,  "  
-		 "PSF_QF FLOAT, "      
-		 "PSF_QF_PERF FLOAT,  " 
-		 "STARGAL_SEP FLOAT,  " 
-		 "NUMBER_POS SMALLINT,  "  
-		 "NMEASURE SMALLINT,  "    
-		 "NMISSING SMALLINT,  "    
-		 "NEXTEND SMALLINT,  "     
-		 "OFF_MEASURE INT,  " 
-		 "OFF_MISSING INT,  " 
-		 "OFF_EXTEND INT,  "  
-		 "FLAGS INT,  "       
-		 "PHOTFLAGS_U INT,  " 
-		 "PHOTFLAGS_L INT,  " 
-		 "OBJ_ID INT,  "      
-		 "CAT_ID INT,  "      
-		 "EXT_ID BIGINT"
+		 "EXT_ID        BIGINT,   "
+		 "OBJ_ID        INT,      "      
+		 "CAT_ID        INT,      " 
+		 "TESS_ID       TINYINT,  " 
+		 "PROJECTION_ID SMALLINT, " 
+		 "SKYCELL_ID    TINYINT,  " 
+		 "RA_STK        DOUBLE,   "          
+		 "DEC_STK       DOUBLE,   "         
+		 "RA_STK_ERR    FLOAT,    "      
+		 "DEC_STK_ERR   FLOAT,    "     
+		 "RA_MEAN       DOUBLE,   "          
+		 "DEC_MEAN      DOUBLE,   "         
+		 "RA_ERR        FLOAT,    "      
+		 "DEC_ERR       FLOAT,    "     
+		 "CHISQ_POS     FLOAT,    "   
+		 "CHISQ_PM      FLOAT,    "    
+		 "CHISQ_PAR     FLOAT,    "   
+		 "FLAGS         INT       "       
 		 ")\n", basename);
+
+// skipping these cpt fields:
+// 		 "U_RA        FLOAT,  "        
+// 		 "U_DEC       FLOAT,  "       
+// 		 "V_RA_ERR    FLOAT,  "    
+// 		 "V_DEC_ERR   FLOAT,  "   
+// 		 "PAR         FLOAT,  "         
+// 		 "PAR_ERR     FLOAT,  "     
+//		 "OFF_MEASURE INT,  " 
+//		 "OFF_MISSING INT,  " 
+//		 "OFF_EXTEND  INT,  "  
+//		 "PSF_QF      FLOAT, "      
+//		 "PSF_QF_PERF FLOAT,  " 
+//		 "STARGAL_SEP FLOAT,  " 
+//		 "NUMBER_POS  SMALLINT,  "  
+//		 "NMEASURE    SMALLINT,  "    
+//		 "NMISSING    SMALLINT,  "    
+//		 "NEXTEND     SMALLINT,  "     
+//		 "PHOTFLAGS_U INT,  " 
+//		 "PHOTFLAGS_L INT,  " 
+
+
 
   if (DEBUG) fprintf (stderr, "%s\n", buffer.buffer);
@@ -145,28 +155,23 @@
 
   PrintIOBuffer (&buffer, "CREATE TABLE %s_cps ("
-		 "MAG FLOAT,  "             
-		 "MAG_AP FLOAT,  "             
-		 "MAG_KRON FLOAT,  "        
-		 "MAG_KRON_ERR FLOAT,  "    
-		 "MAG_ERR FLOAT,  "         
-		 "MAG_CHI FLOAT,  "         
-		 "STACK_PSF_MAG FLOAT,  "        
-		 "STACK_PSF_MAG_ERR FLOAT,  "    
-		 "STACK_KRON_MAG FLOAT,  "       
-		 "STACK_KRON_MAG_ERR FLOAT,  "   
-		 "FLAGS INT,  "           
-		 "NCODE SMALLINT,  "           
-		 "NUSED SMALLINT,  "           
-		 "MAG_20 SMALLINT,  "          
-		 "MAG_80 SMALLINT,  "          
-		 "UBERCAL_DIST SMALLINT,  "    
-		 "MAG_STDEV SMALLINT,  "       
-		 "STACK_DETECT_ID BIGINT" 
+		 "MAG            FLOAT,  "             
+		 "MAG_ERR        FLOAT,  "         
+		 "MAG_STDEV      FLOAT,  "         
+		 "MAG_MIN        FLOAT,  "         
+		 "MAG_MAX        FLOAT,  "         
+		 "NUSED          SMALLINT,  "           
+		 "MAG_KRON       FLOAT,  "        
+		 "MAG_KRON_ERR   FLOAT,  "    
+		 "MAG_KRON_STDEV FLOAT,  "    
+		 "NUSED_KRON     SMALLINT,  "    
+		 "MAG_AP         FLOAT,  "             
+		 "MAG_AP_ERR     FLOAT,  "             
+		 "MAG_AP_STDEV   FLOAT,  "             
+		 "NUSED_AP       SMALLINT,  "    
+		 "NCODE          SMALLINT,  "           
+		 "NSTACK_DET     SMALLINT,  "           
+		 "PSF_QF_PERF_MAX FLOAT, "           
+		 "FLAGS          INT "           
 		 ")\n", basename);
-
- // 		 "FLUX_PSF FLOAT,  "        
- //  		 "FLUX_PSF_ERR FLOAT,  "    
- //  		 "FLUX_KRON FLOAT,  "       
- //  		 "FLUX_KRON_ERR FLOAT,  "   
 
   if (DEBUG) fprintf (stderr, "%s\n", buffer.buffer);
@@ -191,35 +196,22 @@
 
   PrintIOBuffer (ave_buffer, "INSERT INTO %s_cpt ("
-		 "RA, "          
-		 "DEC_, "         
-		 "RA_ERR, "      
-		 "DEC_ERR, "     
-		 "U_RA, "        
-		 "U_DEC, "       
-		 "V_RA_ERR, "    
-		 "V_DEC_ERR, "   
-		 "PAR, "         
-		 "PAR_ERR, "     
-		 "CHISQ_POS, "   
-		 "CHISQ_PM, "    
-		 "CHISQ_PAP, "   
-		 "MEAN_EPOCH, "  
-		 "TIME_RANGE, "  
-		 "PSF_QF, "      
-		 "PSF_QF_PERF, " 
-		 "STARGAL_SEP, " 
-		 "NUMBER_POS, "  
-		 "NMEASURE, "    
-		 "NMISSING, "    
-		 "NEXTEND, "     
-		 "OFF_MEASURE, " 
-		 "OFF_MISSING, " 
-		 "OFF_EXTEND, "  
-		 "FLAGS, "       
-		 "PHOTFLAGS_U, " 
-		 "PHOTFLAGS_L, " 
-		 "OBJ_ID, "      
-		 "CAT_ID, "      
-		 "EXT_ID"
+		 "EXT_ID,        "
+		 "OBJ_ID,        "      
+		 "CAT_ID,        "      
+		 "TESS_ID,       "      
+		 "PROJECTION_ID, "      
+		 "SKYCELL_ID,    "      
+		 "RA_STK,        "          
+		 "DEC_STK,       "         
+		 "RA_STK_ERR,    "      
+		 "DEC_STK_ERR,   "     
+		 "RA_MEAN,       "          
+		 "DEC_MEAN,      "         
+		 "RA_ERR,        "      
+		 "DEC_ERR,       "     
+		 "CHISQ_POS,     "   
+		 "CHISQ_PM,      "    
+		 "CHISQ_PAR,     "   
+		 "FLAGS          "       
 		 ") VALUES \n", basename);
 
@@ -230,21 +222,24 @@
   PrintIOBuffer (sec_buffer, "INSERT INTO %s_cps ("
 		 "MAG, "             
-		 "MAG_AP, "             
+		 "MAG_ERR, "         
+		 "MAG_STDEV, "       
+		 "MAG_MIN, "          
+		 "MAG_MAX, "          
+		 "NUSED, "           
+
 		 "MAG_KRON, "        
 		 "MAG_KRON_ERR, "    
-		 "MAG_ERR, "         
-		 "MAG_CHI, "         
-		 "STACK_PSF_MAG, "        
-		 "STACK_PSF_MAG_ERR, "    
-		 "STACK_KRON_MAG, "       
-		 "STACK_KRON_MAG_ERR, "   
-		 "FLAGS, "           
+		 "MAG_KRON_STDEV, "    
+		 "NUSED_KRON, "           
+
+		 "MAG_AP, "             
+		 "MAG_AP_ERR, "             
+		 "MAG_AP_STDEV, "             
+		 "NUSED_AP, "           
+
 		 "NCODE, "           
-		 "NUSED, "           
-		 "MAG_20, "          
-		 "MAG_80, "          
-		 "UBERCAL_DIST, "    
-		 "MAG_STDEV, "       
-		 "STACK_DETECT_ID " 
+		 "NSTACK_DET,  "           
+		 "PSF_QF_PERF_MAX, "           
+		 "FLAGS "           
 		 ") VALUES \n", basename);
   return TRUE;
@@ -261,96 +256,85 @@
 // XXX this bit could/should be autocoded...
   PrintIOBuffer (ave_buffer, " (");
+  PrintIOBuffer (ave_buffer, "%lu, ", average->extID);          
+  PrintIOBuffer (ave_buffer, "%u,  ", average->objID);          
+  PrintIOBuffer (ave_buffer, "%u,  ", average->catID);          
+
+  PrintIOBuffer (ave_buffer, "%hhd, ", average->tessID);          
+  PrintIOBuffer (ave_buffer, "%hd,  ", average->projectionID);          
+  PrintIOBuffer (ave_buffer, "%hhd, ", average->skycellID);          
+
+  PRINT_FLOAT(ave_buffer, average->Rstk,     "%.8f, ");  // 0.036 mas precision 
+  PRINT_FLOAT(ave_buffer, average->Dstk,     "%.8f, ");  // 0.036 mas precision 
+  PRINT_FLOAT(ave_buffer, average->dRstk,    "%.5f, ");  // 0.010 mas precision
+  PRINT_FLOAT(ave_buffer, average->dDstk,    "%.5f, ");  // 0.010 mas precision
+
   PRINT_FLOAT(ave_buffer, average->R,  	     "%.8f, ");  // 0.036 mas precision 
   PRINT_FLOAT(ave_buffer, average->D,  	     "%.8f, ");  // 0.036 mas precision 
   PRINT_FLOAT(ave_buffer, average->dR, 	     "%.5f, ");  // 0.010 mas precision
   PRINT_FLOAT(ave_buffer, average->dD, 	     "%.5f, ");  // 0.010 mas precision
-  PRINT_FLOAT(ave_buffer, average->uR, 	     "%.5f, ");  // 0.010 mas/yr precision
-  PRINT_FLOAT(ave_buffer, average->uD, 	     "%.5f, ");
-  PRINT_FLOAT(ave_buffer, average->duR,      "%.5f, ");
-  PRINT_FLOAT(ave_buffer, average->duD,      "%.5f, ");
-  PRINT_FLOAT(ave_buffer, average->P,        "%.5f, ");
-  PRINT_FLOAT(ave_buffer, average->dP,       "%.5f, ");
+
   PRINT_FLOAT(ave_buffer, average->ChiSqAve, "%.4f, ");
   PRINT_FLOAT(ave_buffer, average->ChiSqPM,  "%.4f, ");
   PRINT_FLOAT(ave_buffer, average->ChiSqPar, "%.4f, ");
-  PrintIOBuffer (ave_buffer, "%d, ",  average->Tmean);          
-  PrintIOBuffer (ave_buffer, "%d, ",  average->Trange);         
-  PRINT_FLOAT(ave_buffer, average->psfQF,     "%.3f, ");
-  PRINT_FLOAT(ave_buffer, average->psfQFperf, "%.3f, ");
-  PRINT_FLOAT(ave_buffer, average->stargal,   "%.3f, ");
-  PrintIOBuffer (ave_buffer, "%hu, ", average->Npos);           
-  PrintIOBuffer (ave_buffer, "%hu, ", average->Nmeasure);       
-  PrintIOBuffer (ave_buffer, "%hu, ", average->Nmissing);       
-  PrintIOBuffer (ave_buffer, "%hu, ", average->Nextend);        
-  PrintIOBuffer (ave_buffer, "%d, ",  average->measureOffset);  
-  PrintIOBuffer (ave_buffer, "%d, ",  average->missingOffset);  
-  PrintIOBuffer (ave_buffer, "%d, ",  0); // was : average->extendOffset);   
-  PrintIOBuffer (ave_buffer, "%u, ",  average->flags);          
-  PrintIOBuffer (ave_buffer, "%u, ",  average->photFlagsUpper); 
-  PrintIOBuffer (ave_buffer, "%u, ",  average->photFlagsLower); 
-  PrintIOBuffer (ave_buffer, "%u, ",  average->objID);          
-  PrintIOBuffer (ave_buffer, "%u, ",  average->catID);          
-  PrintIOBuffer (ave_buffer, "%lu",   average->extID);          
+
+  PrintIOBuffer (ave_buffer, "%u ",  average->flags);          
+
   PrintIOBuffer (ave_buffer, "),\n");
 
+  // XXX what rules for keeping or NAN-ing various mags?
   for (i = 0; i < Nsecfilt; i++) {
     float meanPSFMag    = -999.0;
     float meanPSFMagErr = -999.0;
+    float meanPSFMagStd = -999.0;
+    float meanPSFMagMin = -999.0;
+    float meanPSFMagMax = -999.0;
     if (isfinite(secfilt->dM) && isfinite(secfilt->M)) {
-      meanPSFMag = secfilt->M;
+      meanPSFMag    = secfilt->M;
       meanPSFMagErr = secfilt->dM;
+      meanPSFMagStd = secfilt->Mstdev;
+      meanPSFMagMin = secfilt->Mmin;
+      meanPSFMagMax = secfilt->Mmax;
     }
 
     float meanKronMag    = -999.0;
     float meanKronMagErr = -999.0;
+    float meanKronMagStd = -999.0;
     if (isfinite(secfilt->dMkron) && isfinite(secfilt->Mkron) && (secfilt->dMkron < 0.333)) {
-      meanKronMag = secfilt->Mkron;
+      meanKronMag    = secfilt->Mkron;
       meanKronMagErr = secfilt->dMkron;
+      meanKronMagStd = secfilt->sMkron;
     }
 
     float meanApMag    = -999.0;
-    if (isfinite(secfilt->Map)) {
-      meanApMag = secfilt->Map;
-    }
-
-    float stackPSFMag    = -999.0;
-    float stackPSFMagErr = -999.0;
-    if (isfinite(secfilt->dFpsfStk) && isfinite(secfilt->FpsfStk) && (secfilt->dFpsfStk > 0.0)) {
-      float SN = secfilt->FpsfStk / secfilt->dFpsfStk;
-      if (SN > 3.0) {
-	stackPSFMag = -2.5 * log10(secfilt->FpsfStk) + 8.9;
-	stackPSFMagErr = secfilt->dFpsfStk / secfilt->FpsfStk;
-      }
-    }
-
-    float stackKronMag    = -999.0;
-    float stackKronMagErr = -999.0;
-    if (isfinite(secfilt->dFkronStk) && isfinite(secfilt->FkronStk) && (secfilt->dFkronStk > 0.0)) {
-      float SN = secfilt->FkronStk / secfilt->dFkronStk;
-      if (SN > 3.0) {
-	stackKronMag = -2.5 * log10(secfilt->FkronStk) + 8.9;
-	stackKronMagErr = secfilt->dFkronStk / secfilt->FkronStk;
-      }
+    float meanApMagErr = -999.0;
+    float meanApMagStd = -999.0;
+    if (isfinite(secfilt->dMap) && isfinite(secfilt->Map)) {
+      meanApMag    = secfilt->Map;
+      meanApMagErr = secfilt->dMap;
+      meanApMagStd = secfilt->sMap;
     }
 
     PrintIOBuffer (sec_buffer, " (");
     PRINT_FLOAT(sec_buffer, meanPSFMag,      "%.6f, "); // umag precision
-    PRINT_FLOAT(sec_buffer, meanApMag,       "%.6f, "); // umag precision
+    PRINT_FLOAT(sec_buffer, meanPSFMagErr,   "%.6f, "); // umag precision
+    PRINT_FLOAT(sec_buffer, meanPSFMagStd,   "%.6f, "); // umag precision
+    PRINT_FLOAT(sec_buffer, meanPSFMagMin,   "%.6f, "); // umag precision
+    PRINT_FLOAT(sec_buffer, meanPSFMagMax,   "%.6f, "); // umag precision
+    PrintIOBuffer (sec_buffer, "%hd,  ", secfilt->Nused);        
+
     PRINT_FLOAT(sec_buffer, meanKronMag,     "%.6f, "); // umag precision
     PRINT_FLOAT(sec_buffer, meanKronMagErr,  "%.6f, "); // umag precision
-    PRINT_FLOAT(sec_buffer, meanPSFMagErr,   "%.6f, "); // umag precision
-    PRINT_FLOAT(sec_buffer, secfilt->Mchisq, "%.6f, ");
-    PRINT_FLOAT(sec_buffer, stackPSFMag,     "%.6f, "); // umag precision
-    PRINT_FLOAT(sec_buffer, stackPSFMagErr,  "%.6f, "); // umag precision
-    PRINT_FLOAT(sec_buffer, stackKronMag,    "%.6f, "); // umag precision
-    PRINT_FLOAT(sec_buffer, stackKronMagErr, "%.6f, "); // 0.36 umag precision
-    PrintIOBuffer (sec_buffer, "%u,   ", secfilt->flags);       
+    PRINT_FLOAT(sec_buffer, meanKronMagStd,  "%.6f, "); // umag precision
+    PrintIOBuffer (sec_buffer, "%hd,  ", secfilt->NusedKron);        
+
+    PRINT_FLOAT(sec_buffer, meanApMag,     "%.6f, "); // umag precision
+    PRINT_FLOAT(sec_buffer, meanApMagErr,  "%.6f, "); // umag precision
+    PRINT_FLOAT(sec_buffer, meanApMagStd,  "%.6f, "); // umag precision
+    PrintIOBuffer (sec_buffer, "%hd,  ", secfilt->NusedAp);        
     PrintIOBuffer (sec_buffer, "%hd,  ", secfilt->Ncode);        
-    PrintIOBuffer (sec_buffer, "%hd,  ", secfilt->Nused);        
-    PrintIOBuffer (sec_buffer, "%.6f, ", secfilt->Mmin);         
-    PrintIOBuffer (sec_buffer, "%.6f, ", secfilt->Mmax);         
-    PrintIOBuffer (sec_buffer, "%hd, ", secfilt->ubercalDist);  
-    PrintIOBuffer (sec_buffer, "%.6f, ", secfilt->Mstdev);       
-    PrintIOBuffer (sec_buffer, "%lu  ", 0L); // secfilt->stackDetectID
+    PrintIOBuffer (sec_buffer, "%hd,  ", secfilt->NstackDet);        
+
+    PRINT_FLOAT(sec_buffer, secfilt->psfQfPerfMax, "%.6f,");       
+    PrintIOBuffer (sec_buffer, "%u ", secfilt->flags);       
     PrintIOBuffer (sec_buffer, "),\n");
     secfilt ++;
Index: trunk/Ohana/src/libautocode/def/average-ps1-v5.d
===================================================================
--- trunk/Ohana/src/libautocode/def/average-ps1-v5.d	(revision 37116)
+++ trunk/Ohana/src/libautocode/def/average-ps1-v5.d	(revision 37246)
@@ -2,5 +2,5 @@
 EXTNAME      DVO_AVERAGE_PS1_V5
 TYPE         BINTABLE
-SIZE         184
+SIZE         192
 DESCRIPTION  DVO Average Object Table
 
@@ -53,4 +53,10 @@
 FIELD refColorRed,    REF_COLOR_RED,  float,   	    color of astrometry ref stars
 
+FIELD tessID,         TESS_ID,       char,	    ID of tessellation for primary skycell
+FIELD skycellID,      SKYCELL_ID,    char,    	    ID of skycell for primary skycell
+FIELD projectionID,   PROJECTION_ID, short,	    ID of projection for primary skycell
+
+FIELD dummy,          DUMMY,         int,           unassigned bytes
+
 # 'flags' was called 'code' prior to 2009.02.07
 FIELD flags,          FLAGS,       uint32_t,        average object flags (star; ghost; etc)
Index: trunk/Ohana/src/libautocode/def/average.d
===================================================================
--- trunk/Ohana/src/libautocode/def/average.d	(revision 37116)
+++ trunk/Ohana/src/libautocode/def/average.d	(revision 37246)
@@ -2,5 +2,5 @@
 EXTNAME      DVO_AVERAGE
 TYPE         BINTABLE
-SIZE         184
+SIZE         192
 DESCRIPTION  DVO Average Object Table
 
@@ -53,4 +53,10 @@
 FIELD refColorRed,    REF_COLOR_RED,  float,   	    color of astrometry ref stars
 
+FIELD tessID,         TESS_ID,       char,	    ID of tessellation for primary skycell
+FIELD skycellID,      SKYCELL_ID,    char,    	    ID of skycell for primary skycell
+FIELD projectionID,   PROJECTION_ID, short,	    ID of projection for primary skycell
+
+FIELD dummy,          DUMMY,         int,           unassigned bytes
+
 # 'flags' was called 'code' prior to 2009.02.07
 FIELD flags,          FLAGS,       uint32_t,        average object flags (star; ghost; etc)
Index: trunk/Ohana/src/libautocode/def/measure-ps1-v5.d
===================================================================
--- trunk/Ohana/src/libautocode/def/measure-ps1-v5.d	(revision 37116)
+++ trunk/Ohana/src/libautocode/def/measure-ps1-v5.d	(revision 37246)
@@ -68,5 +68,5 @@
 FIELD psfNdof,        PSF_NDOF,      int,            psf degrees of freedom
 FIELD psfNpix,        PSF_NPIX,      int,            psf number of pixels
-FIELD crNsigma,       CR_NSIGMA,     float,          Nsigma deviation towards CR
+FIELD photFlags2,     PHOT_FLAGS,    int,            flags supplied by photometry program
 FIELD extNsigma,      EXT_NSIGMA,    float,          Nsigma deviation towards EXT
 
Index: trunk/Ohana/src/libautocode/def/measure.d
===================================================================
--- trunk/Ohana/src/libautocode/def/measure.d	(revision 37116)
+++ trunk/Ohana/src/libautocode/def/measure.d	(revision 37246)
@@ -66,5 +66,5 @@
 FIELD psfNdof,        PSF_NDOF,      int,            psf degrees of freedom
 FIELD psfNpix,        PSF_NPIX,      int,            psf number of pixels
-FIELD crNsigma,       CR_NSIGMA,     float,          Nsigma deviation towards CR
+FIELD photFlags2,     PHOT_FLAGS,    int,            flags supplied by photometry program
 FIELD extNsigma,      EXT_NSIGMA,    float,          Nsigma deviation towards EXT
 
Index: trunk/Ohana/src/libautocode/def/secfilt-ps1-v5.d
===================================================================
--- trunk/Ohana/src/libautocode/def/secfilt-ps1-v5.d	(revision 37116)
+++ trunk/Ohana/src/libautocode/def/secfilt-ps1-v5.d	(revision 37246)
@@ -2,5 +2,5 @@
 EXTNAME      DVO_SECFILT_PS1_V5
 TYPE         BINTABLE
-SIZE         160
+SIZE         176
 DESCRIPTION  DVO SecFilt : Secondary Filter Data 
 
@@ -15,4 +15,8 @@
 FIELD  sMkron,        MAG_KRON_STDEV,  float,      standard deviation of kron mags,       mags
 				         
+# XXX I could add these fields to secfilt or calculate in dvopsps?
+FIELD  psfQfMax,      PSF_QF_MAX,      float,      best psfQf for this filter
+FIELD  psfQfPerfMax,  PSF_QF_PERF_MAX, float,      best psfQfPerfect for this filter
+
 # these statistics are PSF-specific      
 FIELD  Mstdev,        MAG_STDEV,         float,    standard deviation of measurements,    mags
@@ -42,4 +46,7 @@
 FIELD  dFapStk,       FLUX_AP_STK_ERR,   float,    mean flux ap error
 
+FIELD  Nstack,        NSTACK,            short,    number of measurements in band (gpc1 stack only)
+FIELD  NstackDet,     NSTACK_DET,        short,    number of stack detections in band (gpc1 stack only)
+
 FIELD  stackPrmryOff, STACK_PRIMARY_OFF,  int,     measure entry which is primary stack detection
 FIELD  stackBestOff,  STACK_BEST_OFF,     int,     measure entry which is best stack detection
@@ -66,4 +73,7 @@
 FIELD  NusedApWrp,    NUSED_AP_WRP,      short,    number of detections used in average
 
+FIELD  Nwarp,         NWARP,             short,    number of measurements in band (gpc1 warp only)
+FIELD  NwarpGood,     NWARP_GOOD,        short,    number of meas with psf_qf > 0.85 in band (gpc1 warp only)
+
 FIELD  ubercalDist,   UBERCAL_DIST,      short,    number of images from an ubercal-image
 
Index: trunk/Ohana/src/libautocode/def/secfilt.d
===================================================================
--- trunk/Ohana/src/libautocode/def/secfilt.d	(revision 37116)
+++ trunk/Ohana/src/libautocode/def/secfilt.d	(revision 37246)
@@ -2,5 +2,5 @@
 EXTNAME      DVO_SECFILT
 TYPE         BINTABLE
-SIZE         160
+SIZE         176
 DESCRIPTION  DVO SecFilt : Secondary Filter Data 
 
@@ -15,4 +15,8 @@
 FIELD  sMkron,        MAG_KRON_STDEV,  float,      standard deviation of kron mags,       mags
 
+# XXX I could add these fields to secfilt or calculate in dvopsps?
+FIELD  psfQfMax,      PSF_QF_MAX,      float,      best psfQf for this filter
+FIELD  psfQfPerfMax,  PSF_QF_PERF_MAX, float,      best psfQfPerfect for this filter
+
 # these statistics are PSF-specific      
 FIELD  Mstdev,        MAG_STDEV,       float,      standard deviation of measurements,    mags
@@ -21,8 +25,8 @@
 FIELD  Mchisq,        MAG_CHI,         float,      chisq on average mag,                  value
 
-FIELD  Ncode,         NCODE,           short,      number of detections in band
-FIELD  Nused,         NUSED,           short,      number of detections used in average
-FIELD  NusedKron,     NUSED_KRON,      short,      number of detections used in average
-FIELD  NusedAp,       NUSED_AP,        short,      number of detections used in average
+FIELD  Ncode,         NCODE,           short,      number of detections in band (gpc1 chip only)
+FIELD  Nused,         NUSED,           short,      number of detections used to calculate secfilt.M
+FIELD  NusedKron,     NUSED_KRON,      short,      number of detections used to calculate secfilt.Mkron
+FIELD  NusedAp,       NUSED_AP,        short,      number of detections used to calculate secfilt.Map
 
 FIELD  flags,         FLAGS,           uint32_t,   photometry flags
@@ -42,6 +46,9 @@
 FIELD  dFapStk,       FLUX_AP_STK_ERR,   float,    mean flux ap error
 
-FIELD  stackPrmryOff, STACK_PRIMARY_OFF,  int,     measure entry which is primary stack detection
-FIELD  stackBestOff,  STACK_BEST_OFF,     int,     measure entry which is best stack detection
+FIELD  Nstack,        NSTACK,            short,    number of measurements in band (gpc1 stack only)
+FIELD  NstackDet,     NSTACK_DET,        short,    number of stack detections in band (gpc1 stack only)
+
+FIELD  stackPrmryOff, STACK_PRIMARY_OFF, int,      measure entry which is primary stack detection
+FIELD  stackBestOff,  STACK_BEST_OFF,    int,      measure entry which is best stack detection
 
 ## *** this section is for forced-warp mean values ***
@@ -66,5 +73,8 @@
 FIELD  NusedApWrp,    NUSED_AP_WRP,      short,    number of detections used in average
 
-FIELD  ubercalDist,   UBERCAL_DIST,    short,      number of images from an ubercal-image
+FIELD  Nwarp,         NWARP,             short,    number of measurements in band (gpc1 warp only)
+FIELD  NwarpGood,     NWARP_GOOD,        short,    number of meas with psf_qf > 0.85 in band (gpc1 warp only)
+
+FIELD  ubercalDist,   UBERCAL_DIST,      short,    number of images from an ubercal-image
 
 # *** 20090206 : new fields : M_20, M_80; dropped dummy
Index: trunk/Ohana/src/libdvo/include/dvo.h
===================================================================
--- trunk/Ohana/src/libdvo/include/dvo.h	(revision 37116)
+++ trunk/Ohana/src/libdvo/include/dvo.h	(revision 37246)
@@ -464,5 +464,5 @@
 } MeasureTiny;
 
-/** STRUCT DEFINITION **/
+// alternate version of PS1_V4 (old dev version)
 typedef struct {
   double           R;                    // RA (decimal degrees )
@@ -500,5 +500,5 @@
 Average *Average_PS1_V4alt_ToInternal (Average_PS1_V4alt *in, off_t Nvalues);
 
-/** STRUCT DEFINITION **/
+// alternate version of PS1_V4 (old dev version)
 typedef struct {
   float            dR;                   // RA offset (arcsec)
@@ -556,4 +556,107 @@
 Measure *Measure_PS1_V4alt_ToInternal (Average *ave, Measure_PS1_V4alt *in, off_t Nvalues);
 
+// alternate version of PS1_V5 (old dev version)
+typedef struct {
+  float            M;                    // average mag in this band (mags)
+  float            dM;                   // formal error on average mag (mags)
+  float            Map;                  // ave aperture mag in this band (mags)
+  float            dMap;                 // ave aperture mag in this band (mags)
+  float            sMap;                 // standard deviation of ap mags (mags)
+  float            Mkron;                // ave kron mag in this band (mags)
+  float            dMkron;               // formal error on average kron mag (mags)
+  float            sMkron;               // standard deviation of kron mags (mags)
+  float            Mstdev;               // standard deviation of measurements (mags)
+  float            Mmin;                 // min accepted mag (mags)
+  float            Mmax;                 // max accepted mag (mags)
+  float            Mchisq;               // chisq on average mag (value)
+  short            Ncode;                // number of detections in band
+  short            Nused;                // number of detections used in average
+  short            NusedKron;            // number of detections used in average
+  short            NusedAp;              // number of detections used in average
+  uint32_t         flags;                // photometry flags
+  float            MpsfStk;              // magnitude from stack (primary if available)
+  float            FpsfStk;              // flux from stack (primary if available)
+  float            dFpsfStk;             // mean flux psf error
+  float            MkronStk;             // magnitude from stack (primary if available)
+  float            FkronStk;             // flux from stack (primary if available)
+  float            dFkronStk;            // mean flux kron error
+  float            MapStk;               // magnitude from stack (primary if available)
+  float            FapStk;               // flux from stack (primary if available)
+  float            dFapStk;              // mean flux ap error
+  int              stackPrmryOff;        // measure entry which is primary stack detection
+  int              stackBestOff;         // measure entry which is best stack detection
+  float            MpsfWrp;              // psf magnitude from stack (primary if available)
+  float            FpsfWrp;              // psf flux from stack (primary if available)
+  float            dFpsfWrp;             // mean flux psf error
+  float            sFpsfWrp;             // mean flux psf stdev
+  float            MkronWrp;             // kron magnitude from stack (primary if available)
+  float            FkronWrp;             // kron flux from stack (primary if available)
+  float            dFkronWrp;            // mean flux kron error
+  float            sFkronWrp;            // mean flux kron stdev
+  float            MapWrp;               // aper magnitude from stack (primary if available)
+  float            FapWrp;               // aper flux from stack (primary if available)
+  float            dFapWrp;              // mean flux ap error
+  float            sFapWrp;              // mean flux ap stdev
+  short            NusedWrp;             // number of detections used in average
+  short            NusedKronWrp;         // number of detections used in average
+  short            NusedApWrp;           // number of detections used in average
+  short            ubercalDist;          // number of images from an ubercal-image
+} SecFilt_PS1_V5alt;
+
+SecFilt_PS1_V5alt *gfits_table_get_SecFilt_PS1_V5alt (FTable *table, off_t *Ndata, char *swapped);
+int      gfits_convert_SecFilt_PS1_V5alt (SecFilt_PS1_V5alt *data, off_t size, off_t nitems);
+SecFilt *SecFilt_PS1_V5alt_ToInternal (SecFilt_PS1_V5alt *in, off_t Nvalues);
+
+// alternate version of PS1_V5alt (old dev version)
+typedef struct {
+  double           R;                    // RA (decimal degrees )
+  double           D;                    // DEC (decimal degrees )
+  float            dR;                   // RA error (arcsec)
+  float            dD;                   // DEC error (arcsec)
+  float            uR;                   // RA*cos(D) proper-motion (arcsec/year)
+  float            uD;                   // DEC proper-motion (arcsec/year)
+  float            duR;                  // RA*cos(D) p-m error (arcsec/year)
+  float            duD;                  // DEC p-m error (arcsec/year)
+  float            P;                    // parallax (arcsec)
+  float            dP;                   // parallax error (arcsec)
+  double           Rstk;                 // RA on stack (decimal degrees )
+  double           Dstk;                 // DEC on stack (decimal degrees )
+  float            dRstk;                // RA error on stack (arcsec)
+  float            dDstk;                // DEC error on stack (arcsec)
+  float            ChiSqAve;             // astrometry analysis chisq
+  float            ChiSqPM;              // astrometry analysis chisq
+  float            ChiSqPar;             // astrometry analysis chisq
+  int              Tmean;                // mean epoch (PM,PAR ref) (unix time seconds)
+  int              Trange;               // mean epoch (PM,PAR ref) (unix time seconds)
+  float            psfQF;                // psf coverage (bad masks)
+  float            psfQFperf;            // psf coverage (all masks)
+  float            stargal;              // star / galaxy separator (1/100 arcsec)
+  unsigned short   Npos;                 // number of detections used for astrometry
+  unsigned short   Nmeasure;             // number of psf measurements
+  unsigned short   Nmissing;             // number of missings
+  unsigned short   Nlensing;             // number of lensing measurements
+  unsigned short   Nlensobj;             // number of lensing measurements
+  unsigned short   Nextend;              // number of extended measurements
+  int              measureOffset;        // offset to first psf measurement
+  int              missingOffset;        // offset to first missing obs
+  int              lensingOffset;        // offset to first lensing obs
+  int              lensobjOffset;        // offset to mean lensing data
+  int              extendOffset;         // offset to extended object entry
+  int              paramsOffset;         // offset to stellar parameter data
+  float            refColorBlue;         // color of astrometry ref stars
+  float            refColorRed;          // color of astrometry ref stars
+  uint32_t         flags;                // average object flags (star; ghost; etc)
+  uint32_t         photFlagsUpper;       // upper bit of 2 bit summary of per-measure photflags
+  uint32_t         photFlagsLower;       // lower bit of 2 bit summary of per-measure photflags
+  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 for object (eg PSPS objID)
+  uint64_t         extIDgc;              // external ID for object in galactic coords
+} Average_PS1_V5alt;
+
+Average_PS1_V5alt *gfits_table_get_Average_PS1_V5alt (FTable *table, off_t *Ndata, char *swapped);
+int      gfits_convert_Average_PS1_V5alt (Average_PS1_V5alt *data, off_t size, off_t nitems);
+Average *Average_PS1_V5alt_ToInternal (Average_PS1_V5alt *in, off_t Nvalues);
+
 /* for some reason I have merged the set of tables and the file description,
    so I need to have an internal structure to point to the separate files */
Index: trunk/Ohana/src/libdvo/src/dbExtractMeasures.c
===================================================================
--- trunk/Ohana/src/libdvo/src/dbExtractMeasures.c	(revision 37116)
+++ trunk/Ohana/src/libdvo/src/dbExtractMeasures.c	(revision 37246)
@@ -646,7 +646,4 @@
     case MEAS_PSF_NPIX: /* OK */
       value.Int = measure[0].psfNpix;
-      break;
-    case MEAS_CR_NSIGMA: /* OK */
-      value.Flt = measure[0].crNsigma;
       break;
     case MEAS_EXT_NSIGMA: /* OK */
Index: trunk/Ohana/src/libdvo/src/dvo_catalog.c
===================================================================
--- trunk/Ohana/src/libdvo/src/dvo_catalog.c	(revision 37116)
+++ trunk/Ohana/src/libdvo/src/dvo_catalog.c	(revision 37246)
@@ -141,4 +141,9 @@
   average->refColorRed     = NAN;
 
+  average->tessID          = 0;
+  average->skycellID       = 0;
+  average->projectionID    = 0;
+  average->dummy           = 0;
+
   average->flags           = 0;
   average->photFlagsUpper  = 0;
@@ -173,4 +178,7 @@
   secfilt->sMkron      = NAN;
 
+  secfilt->psfQfMax     = NAN;
+  secfilt->psfQfPerfMax = NAN;
+
   secfilt->Mstdev      = NAN;
   secfilt->Mmin        = NAN;
@@ -197,4 +205,7 @@
   secfilt->dFapStk     = NAN;
 
+  secfilt->Nstack      = 0;
+  secfilt->NstackDet   = 0;
+
   secfilt->stackPrmryOff = -1;
   secfilt->stackBestOff  = -1;
@@ -218,4 +229,7 @@
   secfilt->NusedKronWrp = 0;
   secfilt->NusedApWrp   = 0;
+
+  secfilt->Nwarp        = 0;
+  secfilt->NwarpGood    = 0;
 
   secfilt->ubercalDist = 1000;
@@ -279,5 +293,4 @@
  measure->psfNdof   = 0;
  measure->psfNpix   = 0;
- measure->crNsigma  = NAN;
  measure->extNsigma = NAN;
 
@@ -302,4 +315,5 @@
  measure->dbFlags   = 0;
  measure->photFlags = 0;
+ measure->photFlags2= 0;
 }
 
Index: trunk/Ohana/src/libdvo/src/dvo_convert.c
===================================================================
--- trunk/Ohana/src/libdvo/src/dvo_convert.c	(revision 37116)
+++ trunk/Ohana/src/libdvo/src/dvo_convert.c	(revision 37246)
@@ -80,4 +80,18 @@
   }
 
+  // block to convert old tables (PS1_V5 versions made during development)
+  if (!strcmp (extname, "DVO_AVERAGE_PS1_V5") && (ftable[0].header[0].Naxis[0] == 184)) {
+    Average_PS1_V5alt *tmpAverage;
+    tmpAverage = gfits_table_get_Average_PS1_V5alt (ftable, Naverage, NULL);
+    if (!tmpAverage) {
+      fprintf (stderr, "ERROR: failed to read averages\n");
+      exit (2);
+    }
+    average = Average_PS1_V5alt_ToInternal (tmpAverage, *Naverage);
+    free (tmpAverage);
+    *format = DVO_FORMAT_PS1_V5;
+    return (average); 
+  }
+
 # define CONVERT_FORMAT(NAME, FORMAT, TYPE) \
   if (!strcmp (extname, NAME)) { \
@@ -285,4 +299,19 @@
     return (FALSE);
   }
+
+  // block to convert old tables (PS1_V5 versions made during development)
+  if (!strcmp (extname, "DVO_SECFILT_PS1_V5") && (ftable[0].header[0].Naxis[0] == 160)) {
+    SecFilt_PS1_V5alt *tmpSecFilt;
+    tmpSecFilt = gfits_table_get_SecFilt_PS1_V5alt (ftable, Nsecfilt, NULL);
+    if (!tmpSecFilt) {
+      fprintf (stderr, "ERROR: failed to read secfilts\n");
+      exit (2);
+    }
+    secfilt = SecFilt_PS1_V5alt_ToInternal (tmpSecFilt, *Nsecfilt);
+    free (tmpSecFilt);
+    *format = DVO_FORMAT_PS1_V5;
+    return (secfilt); 
+  }
+
 
 # define CONVERT_FORMAT(NAME, FORMAT, TYPE) \
Index: trunk/Ohana/src/libdvo/src/dvo_convert_PS1_DEV_1.c
===================================================================
--- trunk/Ohana/src/libdvo/src/dvo_convert_PS1_DEV_1.c	(revision 37116)
+++ trunk/Ohana/src/libdvo/src/dvo_convert_PS1_DEV_1.c	(revision 37246)
@@ -32,5 +32,4 @@
     out[i].psfQF      = in[i].psfQF;
     out[i].psfChisq   = in[i].psfChisq;
-    out[i].crNsigma   = in[i].crNsigma;
     out[i].extNsigma  = in[i].extNsigma;
     out[i].FWx 	      = in[i].FWx;
@@ -80,5 +79,4 @@
     out[i].psfQF      = in[i].psfQF;
     out[i].psfChisq   = in[i].psfChisq;
-    out[i].crNsigma   = in[i].crNsigma;
     out[i].extNsigma  = in[i].extNsigma;
     out[i].FWx 	      = in[i].FWx;
Index: trunk/Ohana/src/libdvo/src/dvo_convert_PS1_DEV_2.c
===================================================================
--- trunk/Ohana/src/libdvo/src/dvo_convert_PS1_DEV_2.c	(revision 37116)
+++ trunk/Ohana/src/libdvo/src/dvo_convert_PS1_DEV_2.c	(revision 37246)
@@ -34,5 +34,4 @@
     out[i].psfQF      = in[i].psfQF;
     out[i].psfChisq   = in[i].psfChisq;
-    out[i].crNsigma   = in[i].crNsigma;
     out[i].extNsigma  = in[i].extNsigma;
     out[i].FWx 	      = in[i].FWx;
@@ -80,5 +79,4 @@
     out[i].psfQF      = in[i].psfQF;
     out[i].psfChisq   = in[i].psfChisq;
-    out[i].crNsigma   = in[i].crNsigma;
     out[i].extNsigma  = in[i].extNsigma;
     out[i].FWx 	      = in[i].FWx;
Index: trunk/Ohana/src/libdvo/src/dvo_convert_PS1_V1.c
===================================================================
--- trunk/Ohana/src/libdvo/src/dvo_convert_PS1_V1.c	(revision 37116)
+++ trunk/Ohana/src/libdvo/src/dvo_convert_PS1_V1.c	(revision 37246)
@@ -40,5 +40,4 @@
     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;
@@ -95,5 +94,4 @@
     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;
Index: trunk/Ohana/src/libdvo/src/dvo_convert_PS1_V2.c
===================================================================
--- trunk/Ohana/src/libdvo/src/dvo_convert_PS1_V2.c	(revision 37116)
+++ trunk/Ohana/src/libdvo/src/dvo_convert_PS1_V2.c	(revision 37246)
@@ -40,5 +40,4 @@
     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;
@@ -96,5 +95,4 @@
     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;
Index: trunk/Ohana/src/libdvo/src/dvo_convert_PS1_V3.c
===================================================================
--- trunk/Ohana/src/libdvo/src/dvo_convert_PS1_V3.c	(revision 37116)
+++ trunk/Ohana/src/libdvo/src/dvo_convert_PS1_V3.c	(revision 37246)
@@ -40,5 +40,4 @@
     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;
@@ -96,5 +95,4 @@
     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;
Index: trunk/Ohana/src/libdvo/src/dvo_convert_PS1_V4.c
===================================================================
--- trunk/Ohana/src/libdvo/src/dvo_convert_PS1_V4.c	(revision 37116)
+++ trunk/Ohana/src/libdvo/src/dvo_convert_PS1_V4.c	(revision 37246)
@@ -49,5 +49,4 @@
     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;
@@ -114,5 +113,4 @@
     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;
@@ -541,5 +539,4 @@
     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;
Index: trunk/Ohana/src/libdvo/src/dvo_convert_PS1_V5.c
===================================================================
--- trunk/Ohana/src/libdvo/src/dvo_convert_PS1_V5.c	(revision 37116)
+++ trunk/Ohana/src/libdvo/src/dvo_convert_PS1_V5.c	(revision 37246)
@@ -56,5 +56,4 @@
     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;
@@ -73,4 +72,5 @@
     out[i].dbFlags    = in[i].dbFlags;
     out[i].photFlags  = in[i].photFlags;
+    out[i].photFlags2 = in[i].photFlags2;
   }
   return (out);
@@ -128,5 +128,4 @@
     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;
@@ -145,4 +144,5 @@
     out[i].dbFlags    = in[i].dbFlags;
     out[i].photFlags  = in[i].photFlags;
+    out[i].photFlags2 = in[i].photFlags2;
   }
   return (out);
@@ -203,4 +203,8 @@
     out[i].refColorRed   = in[i].refColorRed;
 
+    out[i].tessID        = in[i].tessID;
+    out[i].skycellID     = in[i].skycellID;
+    out[i].projectionID  = in[i].projectionID;
+
     out[i].flags     	 = in[i].flags;   
     out[i].photFlagsUpper = in[i].photFlagsUpper;   
@@ -223,54 +227,58 @@
 
   for (i = 0; i < Nvalues; i++) {
-    out[i].R        	 = in[i].R;      
-    out[i].D        	 = in[i].D;      
-    out[i].dR       	 = in[i].dR;
-    out[i].dD       	 = in[i].dD;
-    out[i].uR       	 = in[i].uR;
-    out[i].uD       	 = in[i].uD;
-    out[i].duR      	 = in[i].duR;
-    out[i].duD      	 = in[i].duD;
-    out[i].P        	 = in[i].P;
-    out[i].dP       	 = in[i].dP;
-
-    out[i].Rstk        	 = in[i].Rstk;      
-    out[i].Dstk        	 = in[i].Dstk;      
-    out[i].dRstk       	 = in[i].dRstk;
-    out[i].dDstk       	 = in[i].dDstk;
-
-    out[i].ChiSqAve    	 = in[i].ChiSqAve;     
-    out[i].ChiSqPM     	 = in[i].ChiSqPM;     
-    out[i].ChiSqPar   	 = in[i].ChiSqPar;     
-    out[i].Tmean    	 = in[i].Tmean;     
-    out[i].Trange   	 = in[i].Trange;     
-
-    out[i].psfQF         = in[i].psfQF;
-    out[i].psfQFperf     = in[i].psfQFperf;
-    out[i].stargal     	 = in[i].stargal;     
-    out[i].Npos       	 = in[i].Npos;     
-
-    out[i].Nmeasure      = in[i].Nmeasure;     
-    out[i].Nmissing      = in[i].Nmissing;     
-    out[i].Nlensing      = in[i].Nlensing;     
-    out[i].Nlensobj      = in[i].Nlensobj;     
-    out[i].Nextend       = in[i].Nextend;     
-
-    out[i].measureOffset = in[i].measureOffset; 
-    out[i].missingOffset = in[i].missingOffset;
-    out[i].lensingOffset = in[i].lensingOffset;
-    out[i].lensobjOffset = in[i].lensobjOffset;
-    out[i].extendOffset  = in[i].extendOffset;
-    out[i].paramsOffset  = in[i].paramsOffset;
-
-    out[i].refColorBlue  = in[i].refColorBlue;
-    out[i].refColorRed   = in[i].refColorRed;
-
-    out[i].flags     	 = in[i].flags;   
+    out[i].R        	  = in[i].R;      
+    out[i].D        	  = in[i].D;      
+    out[i].dR       	  = in[i].dR;
+    out[i].dD       	  = in[i].dD;
+    out[i].uR       	  = in[i].uR;
+    out[i].uD       	  = in[i].uD;
+    out[i].duR      	  = in[i].duR;
+    out[i].duD      	  = in[i].duD;
+    out[i].P        	  = in[i].P;
+    out[i].dP       	  = in[i].dP;
+			  
+    out[i].Rstk        	  = in[i].Rstk;      
+    out[i].Dstk        	  = in[i].Dstk;      
+    out[i].dRstk       	  = in[i].dRstk;
+    out[i].dDstk       	  = in[i].dDstk;
+			  
+    out[i].ChiSqAve    	  = in[i].ChiSqAve;     
+    out[i].ChiSqPM     	  = in[i].ChiSqPM;     
+    out[i].ChiSqPar   	  = in[i].ChiSqPar;     
+    out[i].Tmean    	  = in[i].Tmean;     
+    out[i].Trange   	  = in[i].Trange;     
+			  
+    out[i].psfQF          = in[i].psfQF;
+    out[i].psfQFperf      = in[i].psfQFperf;
+    out[i].stargal     	  = in[i].stargal;     
+    out[i].Npos       	  = in[i].Npos;     
+			  
+    out[i].Nmeasure       = in[i].Nmeasure;     
+    out[i].Nmissing       = in[i].Nmissing;     
+    out[i].Nlensing       = in[i].Nlensing;     
+    out[i].Nlensobj       = in[i].Nlensobj;     
+    out[i].Nextend        = in[i].Nextend;     
+			  
+    out[i].measureOffset  = in[i].measureOffset; 
+    out[i].missingOffset  = in[i].missingOffset;
+    out[i].lensingOffset  = in[i].lensingOffset;
+    out[i].lensobjOffset  = in[i].lensobjOffset;
+    out[i].extendOffset   = in[i].extendOffset;
+    out[i].paramsOffset   = in[i].paramsOffset;
+			  
+    out[i].refColorBlue   = in[i].refColorBlue;
+    out[i].refColorRed    = in[i].refColorRed;
+			  
+    out[i].tessID         = in[i].tessID;
+    out[i].skycellID      = in[i].skycellID;
+    out[i].projectionID   = in[i].projectionID;
+			  
+    out[i].flags     	  = in[i].flags;   
     out[i].photFlagsUpper = in[i].photFlagsUpper;   
     out[i].photFlagsLower = in[i].photFlagsLower;   
-    out[i].objID 	 = in[i].objID;
-    out[i].catID 	 = in[i].catID;
-    out[i].extID 	 = in[i].extID;
-    out[i].extIDgc 	 = in[i].extIDgc;
+    out[i].objID 	  = in[i].objID;
+    out[i].catID 	  = in[i].catID;
+    out[i].extID 	  = in[i].extID;
+    out[i].extIDgc 	  = in[i].extIDgc;
   }
   return (out);
@@ -286,72 +294,4 @@
   for (i = 0; i < Nvalues; i++) {
     dvo_secfilt_init (&out[i]);
-
-    out[i].M             = in[i].M;      
-    out[i].dM            = in[i].dM;      
-    out[i].Map           = in[i].Map;      
-    out[i].dMap          = in[i].dMap;      
-    out[i].sMap          = in[i].sMap;      
-    out[i].Mkron         = in[i].Mkron;      
-    out[i].dMkron        = in[i].dMkron;      
-
-    out[i].Mstdev        = in[i].Mstdev;      
-    out[i].Mmin          = in[i].Mmin;      
-    out[i].Mmax          = in[i].Mmax;      
-    out[i].Mchisq        = in[i].Mchisq;     
-
-    out[i].Ncode         = in[i].Ncode;
-    out[i].Nused         = in[i].Nused;
-    out[i].NusedKron     = in[i].NusedKron;
-    out[i].NusedAp       = in[i].NusedAp;
-
-    out[i].flags         = in[i].flags;     
-
-    out[i].MpsfStk       = in[i].MpsfStk;
-    out[i].FpsfStk       = in[i].FpsfStk;
-    out[i].dFpsfStk      = in[i].dFpsfStk;
-
-    out[i].MkronStk      = in[i].MkronStk;
-    out[i].FkronStk      = in[i].FkronStk;
-    out[i].dFkronStk     = in[i].dFkronStk;
-
-    out[i].MapStk        = in[i].MapStk;
-    out[i].FapStk        = in[i].FapStk;
-    out[i].dFapStk       = in[i].dFapStk;
-
-    out[i].stackPrmryOff = in[i].stackPrmryOff;      
-    out[i].stackBestOff  = in[i].stackBestOff;      
-
-    out[i].MpsfWrp       = in[i].MpsfWrp;
-    out[i].FpsfWrp       = in[i].FpsfWrp;
-    out[i].dFpsfWrp      = in[i].dFpsfWrp;
-    out[i].sFpsfWrp      = in[i].sFpsfWrp;
-
-    out[i].MkronWrp      = in[i].MkronWrp;
-    out[i].FkronWrp      = in[i].FkronWrp;
-    out[i].dFkronWrp     = in[i].dFkronWrp;
-    out[i].sFkronWrp     = in[i].sFkronWrp;
-
-    out[i].MapWrp        = in[i].MapWrp;
-    out[i].FapWrp        = in[i].FapWrp;
-    out[i].dFapWrp       = in[i].dFapWrp;
-    out[i].sFapWrp       = in[i].sFapWrp;
-
-    out[i].NusedWrp      = in[i].NusedWrp;
-    out[i].NusedKronWrp  = in[i].NusedKronWrp;
-    out[i].NusedApWrp    = in[i].NusedApWrp;
-
-    out[i].ubercalDist   = in[i].ubercalDist;      
-  }
-  return (out);
-}
-
-SecFilt_PS1_V5 *SecFiltInternalTo_PS1_V5 (SecFilt *in, off_t Nvalues) {
-
-  off_t i;
-  SecFilt_PS1_V5 *out;
-
-  ALLOCATE_ZERO (out, SecFilt_PS1_V5, Nvalues);
-
-  for (i = 0; i < Nvalues; i++) {
 
     out[i].M             = in[i].M;      
@@ -364,4 +304,7 @@
     out[i].sMkron        = in[i].sMkron;      
 
+    out[i].psfQfMax      = in[i].psfQfMax;      
+    out[i].psfQfPerfMax  = in[i].psfQfPerfMax;      
+
     out[i].Mstdev        = in[i].Mstdev;      
     out[i].Mmin          = in[i].Mmin;      
@@ -388,4 +331,7 @@
     out[i].dFapStk       = in[i].dFapStk;
 
+    out[i].Nstack        = in[i].Nstack;      
+    out[i].NstackDet     = in[i].NstackDet;      
+
     out[i].stackPrmryOff = in[i].stackPrmryOff;      
     out[i].stackBestOff  = in[i].stackBestOff;      
@@ -409,4 +355,85 @@
     out[i].NusedKronWrp  = in[i].NusedKronWrp;
     out[i].NusedApWrp    = in[i].NusedApWrp;
+
+    out[i].Nwarp         = in[i].Nwarp;      
+    out[i].NwarpGood     = in[i].NwarpGood;      
+
+    out[i].ubercalDist   = in[i].ubercalDist;      
+  }
+  return (out);
+}
+
+SecFilt_PS1_V5 *SecFiltInternalTo_PS1_V5 (SecFilt *in, off_t Nvalues) {
+
+  off_t i;
+  SecFilt_PS1_V5 *out;
+
+  ALLOCATE_ZERO (out, SecFilt_PS1_V5, Nvalues);
+
+  for (i = 0; i < Nvalues; i++) {
+
+    out[i].M             = in[i].M;      
+    out[i].dM            = in[i].dM;      
+    out[i].Map           = in[i].Map;      
+    out[i].dMap          = in[i].dMap;      
+    out[i].sMap          = in[i].sMap;      
+    out[i].Mkron         = in[i].Mkron;      
+    out[i].dMkron        = in[i].dMkron;      
+    out[i].sMkron        = in[i].sMkron;      
+
+    out[i].psfQfMax      = in[i].psfQfMax;      
+    out[i].psfQfPerfMax  = in[i].psfQfPerfMax;      
+
+    out[i].Mstdev        = in[i].Mstdev;      
+    out[i].Mmin          = in[i].Mmin;      
+    out[i].Mmax          = in[i].Mmax;      
+    out[i].Mchisq        = in[i].Mchisq;     
+
+    out[i].Ncode         = in[i].Ncode;
+    out[i].Nused         = in[i].Nused;
+    out[i].NusedKron     = in[i].NusedKron;
+    out[i].NusedAp       = in[i].NusedAp;
+
+    out[i].flags         = in[i].flags;     
+
+    out[i].MpsfStk       = in[i].MpsfStk;
+    out[i].FpsfStk       = in[i].FpsfStk;
+    out[i].dFpsfStk      = in[i].dFpsfStk;
+
+    out[i].MkronStk      = in[i].MkronStk;
+    out[i].FkronStk      = in[i].FkronStk;
+    out[i].dFkronStk     = in[i].dFkronStk;
+
+    out[i].MapStk        = in[i].MapStk;
+    out[i].FapStk        = in[i].FapStk;
+    out[i].dFapStk       = in[i].dFapStk;
+
+    out[i].Nstack        = in[i].Nstack;      
+    out[i].NstackDet     = in[i].NstackDet;      
+
+    out[i].stackPrmryOff = in[i].stackPrmryOff;      
+    out[i].stackBestOff  = in[i].stackBestOff;      
+
+    out[i].MpsfWrp       = in[i].MpsfWrp;
+    out[i].FpsfWrp       = in[i].FpsfWrp;
+    out[i].dFpsfWrp      = in[i].dFpsfWrp;
+    out[i].sFpsfWrp      = in[i].sFpsfWrp;
+
+    out[i].MkronWrp      = in[i].MkronWrp;
+    out[i].FkronWrp      = in[i].FkronWrp;
+    out[i].dFkronWrp     = in[i].dFkronWrp;
+    out[i].sFkronWrp     = in[i].sFkronWrp;
+
+    out[i].MapWrp        = in[i].MapWrp;
+    out[i].FapWrp        = in[i].FapWrp;
+    out[i].dFapWrp       = in[i].dFapWrp;
+    out[i].sFapWrp       = in[i].sFapWrp;
+
+    out[i].NusedWrp      = in[i].NusedWrp;
+    out[i].NusedKronWrp  = in[i].NusedKronWrp;
+    out[i].NusedApWrp    = in[i].NusedApWrp;
+
+    out[i].Nwarp         = in[i].Nwarp;      
+    out[i].NwarpGood     = in[i].NwarpGood;      
 
     out[i].ubercalDist   = in[i].ubercalDist;      
@@ -834,2 +861,327 @@
   return (out);
 }
+
+/*********************** old / alternate version **********************/
+
+// 'primary' is needed to conform with the API for Loneos and Elixir, but is not used
+Average *Average_PS1_V5alt_ToInternal (Average_PS1_V5alt *in, off_t Nvalues) {
+
+  off_t i;
+  Average *out;
+
+  ALLOCATE_ZERO (out, Average, Nvalues);
+
+  for (i = 0; i < Nvalues; i++) {
+    dvo_average_init (&out[i]);
+
+    out[i].R        	  = in[i].R;      
+    out[i].D        	  = in[i].D;      
+    out[i].dR       	  = in[i].dR;
+    out[i].dD       	  = in[i].dD;
+    out[i].uR       	  = in[i].uR;
+    out[i].uD       	  = in[i].uD;
+    out[i].duR      	  = in[i].duR;
+    out[i].duD      	  = in[i].duD;
+    out[i].P        	  = in[i].P;
+    out[i].dP       	  = in[i].dP;
+			  
+    out[i].Rstk        	  = in[i].Rstk;      
+    out[i].Dstk        	  = in[i].Dstk;      
+    out[i].dRstk       	  = in[i].dRstk;
+    out[i].dDstk       	  = in[i].dDstk;
+			  
+    out[i].ChiSqAve    	  = in[i].ChiSqAve;     
+    out[i].ChiSqPM    	  = in[i].ChiSqPM;     
+    out[i].ChiSqPar    	  = in[i].ChiSqPar;     
+    out[i].Tmean    	  = in[i].Tmean;     
+    out[i].Trange   	  = in[i].Trange;     
+			  
+    out[i].psfQF          = in[i].psfQF;
+    out[i].psfQFperf      = in[i].psfQFperf;
+    out[i].stargal     	  = in[i].stargal;     
+    out[i].Npos       	  = in[i].Npos;     
+			  
+    out[i].Nmeasure       = in[i].Nmeasure;     
+    out[i].Nmissing       = in[i].Nmissing;     
+    out[i].Nlensing       = in[i].Nlensing;     
+    out[i].Nlensobj       = in[i].Nlensobj;     
+    out[i].Nextend        = in[i].Nextend;     
+			  
+    out[i].measureOffset  = in[i].measureOffset; 
+    out[i].missingOffset  = in[i].missingOffset;
+    out[i].lensingOffset  = in[i].lensingOffset;
+    out[i].lensobjOffset  = in[i].lensobjOffset;
+    out[i].extendOffset   = in[i].extendOffset;
+    out[i].paramsOffset   = in[i].paramsOffset;
+			  
+    out[i].refColorBlue   = in[i].refColorBlue;
+    out[i].refColorRed    = in[i].refColorRed;
+			  
+    out[i].flags     	  = in[i].flags;   
+    out[i].photFlagsUpper = in[i].photFlagsUpper;   
+    out[i].photFlagsLower = in[i].photFlagsLower;   
+    out[i].objID 	  = in[i].objID;
+    out[i].catID 	  = in[i].catID;
+    out[i].extID 	  = in[i].extID;
+    out[i].extIDgc 	  = in[i].extIDgc;
+  }
+  return (out);
+}
+
+int gfits_convert_Average_PS1_V5alt (Average_PS1_V5alt *data, off_t size, off_t nitems) {
+
+  off_t i;
+  unsigned char *byte, tmp;
+
+  if (size != 184) { 
+    fprintf (stderr, "WARNING: mismatch in data types Average_PS1_V5alt: "OFF_T_FMT" vs %d\n",  size,  184);
+    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 += 184) {
+    /** BYTE SWAP **/
+    SWAP_DBLE (0); // RA
+    SWAP_DBLE (8); // DEC
+    SWAP_WORD (16); // RA_ERR
+    SWAP_WORD (20); // DEC_ERR
+    SWAP_WORD (24); // U_RA
+    SWAP_WORD (28); // U_DEC
+    SWAP_WORD (32); // V_RA_ERR
+    SWAP_WORD (36); // V_DEC_ERR
+    SWAP_WORD (40); // PAR
+    SWAP_WORD (44); // PAR_ERR
+    SWAP_DBLE (48); // RA_STK
+    SWAP_DBLE (56); // DEC_STK
+    SWAP_WORD (64); // RA_STK_ERR
+    SWAP_WORD (68); // DEC_STK_ERR
+    SWAP_WORD (72); // CHISQ_POS
+    SWAP_WORD (76); // CHISQ_PM
+    SWAP_WORD (80); // CHISQ_PAP
+    SWAP_WORD (84); // MEAN_EPOCH
+    SWAP_WORD (88); // TIME_RANGE
+    SWAP_WORD (92); // PSF_QF
+    SWAP_WORD (96); // PSF_QF_PERF
+    SWAP_WORD (100); // STARGAL_SEP
+    SWAP_BYTE (104); // NUMBER_POS
+    SWAP_BYTE (106); // NMEASURE
+    SWAP_BYTE (108); // NMISSING
+    SWAP_BYTE (110); // NLENSING
+    SWAP_BYTE (112); // NLENSOBJ
+    SWAP_BYTE (114); // NEXTEND
+    SWAP_WORD (116); // OFF_MEASURE
+    SWAP_WORD (120); // OFF_MISSING
+    SWAP_WORD (124); // OFF_LENSING
+    SWAP_WORD (128); // OFF_LENSOBJ
+    SWAP_WORD (132); // OFF_EXTEND
+    SWAP_WORD (136); // OFF_PARAMS
+    SWAP_WORD (140); // REF_COLOR_BLUE
+    SWAP_WORD (144); // REF_COLOR_RED
+    SWAP_WORD (148); // FLAGS
+    SWAP_WORD (152); // PHOTFLAGS_U
+    SWAP_WORD (156); // PHOTFLAGS_L
+    SWAP_WORD (160); // OBJ_ID
+    SWAP_WORD (164); // CAT_ID
+    SWAP_DBLE (168); // EXT_ID
+    SWAP_DBLE (176); // EXT_ID_GC
+  }
+# endif  
+
+  return (TRUE);
+} 
+
+/*** add test of EXTNAME and header-defined columns? ***/
+/* return internal structure representation */
+Average_PS1_V5alt *gfits_table_get_Average_PS1_V5alt (FTable *ftable, off_t *Ndata, char *swapped) {
+
+  int Ncols;
+  Average_PS1_V5alt *data;
+
+  Ncols = ftable[0].header[0].Naxis[0];
+  if (Ncols != 184) {
+    fprintf (stderr, "ERROR: mis-match in table size: width is %d but should be %d bytes\n", Ncols, 184);
+    return NULL;
+  }
+
+  *Ndata = ftable[0].header[0].Naxis[1];
+  data = (Average_PS1_V5alt *) ftable[0].buffer;
+  if ((swapped == NULL) || (*swapped == FALSE)) {
+    if (!gfits_convert_Average_PS1_V5alt (data, sizeof (Average_PS1_V5alt), *Ndata)) {
+      return NULL;
+    }
+    gfits_table_scale_data (ftable);
+    if (swapped != NULL) *swapped = TRUE;
+  }
+  return (data);
+}
+
+/****** alt secfilt **********/
+
+SecFilt *SecFilt_PS1_V5alt_ToInternal (SecFilt_PS1_V5alt *in, off_t Nvalues) {
+
+  off_t i;
+  SecFilt *out;
+
+  ALLOCATE_ZERO (out, SecFilt, Nvalues);
+
+  for (i = 0; i < Nvalues; i++) {
+    dvo_secfilt_init (&out[i]);
+
+    out[i].M             = in[i].M;      
+    out[i].dM            = in[i].dM;      
+    out[i].Map           = in[i].Map;      
+    out[i].dMap          = in[i].dMap;      
+    out[i].sMap          = in[i].sMap;      
+    out[i].Mkron         = in[i].Mkron;      
+    out[i].dMkron        = in[i].dMkron;      
+
+    out[i].Mstdev        = in[i].Mstdev;      
+    out[i].Mmin          = in[i].Mmin;      
+    out[i].Mmax          = in[i].Mmax;      
+    out[i].Mchisq        = in[i].Mchisq;     
+
+    out[i].Ncode         = in[i].Ncode;
+    out[i].Nused         = in[i].Nused;
+    out[i].NusedKron     = in[i].NusedKron;
+    out[i].NusedAp       = in[i].NusedAp;
+
+    out[i].flags         = in[i].flags;     
+
+    out[i].MpsfStk       = in[i].MpsfStk;
+    out[i].FpsfStk       = in[i].FpsfStk;
+    out[i].dFpsfStk      = in[i].dFpsfStk;
+
+    out[i].MkronStk      = in[i].MkronStk;
+    out[i].FkronStk      = in[i].FkronStk;
+    out[i].dFkronStk     = in[i].dFkronStk;
+
+    out[i].MapStk        = in[i].MapStk;
+    out[i].FapStk        = in[i].FapStk;
+    out[i].dFapStk       = in[i].dFapStk;
+
+    out[i].stackPrmryOff = in[i].stackPrmryOff;      
+    out[i].stackBestOff  = in[i].stackBestOff;      
+
+    out[i].MpsfWrp       = in[i].MpsfWrp;
+    out[i].FpsfWrp       = in[i].FpsfWrp;
+    out[i].dFpsfWrp      = in[i].dFpsfWrp;
+    out[i].sFpsfWrp      = in[i].sFpsfWrp;
+
+    out[i].MkronWrp      = in[i].MkronWrp;
+    out[i].FkronWrp      = in[i].FkronWrp;
+    out[i].dFkronWrp     = in[i].dFkronWrp;
+    out[i].sFkronWrp     = in[i].sFkronWrp;
+
+    out[i].MapWrp        = in[i].MapWrp;
+    out[i].FapWrp        = in[i].FapWrp;
+    out[i].dFapWrp       = in[i].dFapWrp;
+    out[i].sFapWrp       = in[i].sFapWrp;
+
+    out[i].NusedWrp      = in[i].NusedWrp;
+    out[i].NusedKronWrp  = in[i].NusedKronWrp;
+    out[i].NusedApWrp    = in[i].NusedApWrp;
+
+    out[i].ubercalDist   = in[i].ubercalDist;      
+  }
+  return (out);
+}
+
+int gfits_convert_SecFilt_PS1_V5alt (SecFilt_PS1_V5alt *data, off_t size, off_t nitems) {
+
+  off_t i;
+  unsigned char *byte, tmp;
+
+  if (size != 160) { 
+    fprintf (stderr, "WARNING: mismatch in data types SecFilt_PS1_V5alt: "OFF_T_FMT" vs %d\n",  size,  160);
+    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 += 160) {
+    /** BYTE SWAP **/
+    SWAP_WORD (0); // MAG
+    SWAP_WORD (4); // MAG_ERR
+    SWAP_WORD (8); // MAG_AP
+    SWAP_WORD (12); // MAG_AP_ERR
+    SWAP_WORD (16); // MAG_AP_STDEV
+    SWAP_WORD (20); // MAG_KRON
+    SWAP_WORD (24); // MAG_KRON_ERR
+    SWAP_WORD (28); // MAG_KRON_STDEV
+    SWAP_WORD (32); // MAG_STDEV
+    SWAP_WORD (36); // MAG_MIN
+    SWAP_WORD (40); // MAG_MAX
+    SWAP_WORD (44); // MAG_CHI
+    SWAP_BYTE (48); // NCODE
+    SWAP_BYTE (50); // NUSED
+    SWAP_BYTE (52); // NUSED_KRON
+    SWAP_BYTE (54); // NUSED_AP
+    SWAP_WORD (56); // FLAGS
+    SWAP_WORD (60); // MAG_PSF_STK
+    SWAP_WORD (64); // FLUX_PSF_STK
+    SWAP_WORD (68); // FLUX_PSF_STK_ERR
+    SWAP_WORD (72); // MAG_KRON_STK
+    SWAP_WORD (76); // FLUX_KRON_STK
+    SWAP_WORD (80); // FLUX_KRON_STK_ERR
+    SWAP_WORD (84); // MAG_AP_STK
+    SWAP_WORD (88); // FLUX_AP_STK
+    SWAP_WORD (92); // FLUX_AP_STK_ERR
+    SWAP_WORD (96); // STACK_PRIMARY_OFF
+    SWAP_WORD (100); // STACK_BEST_OFF
+    SWAP_WORD (104); // MAG_PSF_WRP
+    SWAP_WORD (108); // FLUX_PSF_WRP
+    SWAP_WORD (112); // FLUX_PSF_WRP_ERR
+    SWAP_WORD (116); // FLUX_PSF_WRP_STD
+    SWAP_WORD (120); // MAG_KRON_WRP
+    SWAP_WORD (124); // FLUX_KRON_WRP
+    SWAP_WORD (128); // FLUX_KRON_WRP_ERR
+    SWAP_WORD (132); // FLUX_KRON_WRP_STD
+    SWAP_WORD (136); // MAG_AP_WRP
+    SWAP_WORD (140); // FLUX_AP_WRP
+    SWAP_WORD (144); // FLUX_AP_WRP_ERR
+    SWAP_WORD (148); // FLUX_AP_WRP_STD
+    SWAP_BYTE (152); // NUSED_WRP
+    SWAP_BYTE (154); // NUSED_KRON_WRP
+    SWAP_BYTE (156); // NUSED_AP_WRP
+    SWAP_BYTE (158); // UBERCAL_DIST
+  }
+# endif  
+
+  return (TRUE);
+} 
+
+/*** add test of EXTNAME and header-defined columns? ***/
+/* return internal structure representation */
+SecFilt_PS1_V5alt *gfits_table_get_SecFilt_PS1_V5alt (FTable *ftable, off_t *Ndata, char *swapped) {
+
+  int Ncols;
+  SecFilt_PS1_V5alt *data;
+
+  Ncols = ftable[0].header[0].Naxis[0];
+  if (Ncols != 160) {
+    fprintf (stderr, "ERROR: mis-match in table size: width is %d but should be %d bytes\n", Ncols, 160);
+    return NULL;
+  }
+
+  *Ndata = ftable[0].header[0].Naxis[1];
+  data = (SecFilt_PS1_V5alt *) ftable[0].buffer;
+  if ((swapped == NULL) || (*swapped == FALSE)) {
+    if (!gfits_convert_SecFilt_PS1_V5alt (data, sizeof (SecFilt_PS1_V5alt), *Ndata)) {
+      return NULL;
+    }
+    gfits_table_scale_data (ftable);
+    if (swapped != NULL) *swapped = TRUE;
+  }
+  return (data);
+}
+
+
Index: trunk/Ohana/src/opihi/cmd.astro/cplot.c
===================================================================
--- trunk/Ohana/src/opihi/cmd.astro/cplot.c	(revision 37116)
+++ trunk/Ohana/src/opihi/cmd.astro/cplot.c	(revision 37246)
@@ -4,5 +4,5 @@
   
   double ra_prev = 0;
-  int i, kapa, Npts, status, leftside;
+  int i, kapa, Npts, status, leftside, valid, size;
   opihi_flt *x, *y, *r, *d, Rmin, Rmax, Rmid;
   Vector Xvec, Yvec, *xvec, *yvec;
@@ -11,6 +11,9 @@
   if (!style_args (&graphmode, &argc, argv, &kapa)) return FALSE;
 
-  if (argc != 3) {
+  valid  = (argc == 3);
+  valid |= (argc > 4) && !strcmp (argv[3], "where");
+  if (!valid) {
     gprint (GP_ERR, "USAGE: cplot <ra> <dec> [style]\n");
+    gprint (GP_ERR, "   OR: cplot <ra> <dec> [style] where (condition)\n");
     return (FALSE);
   }
@@ -32,4 +35,26 @@
   }
 
+  // tvec is used for logical test (truth vector)
+  Vector *tvec = NULL;
+  if (argc > 4) {
+    char *out = dvomath (argc - 4, &argv[4], &size, 1);
+    if (out == NULL) {
+      print_error ();
+      return FALSE;
+    }
+    if ((tvec = SelectVector (out, OLDVECTOR, TRUE)) == NULL) {
+      gprint (GP_ERR, " invalid logic result\n");
+      DeleteNamedVector (out);
+      free (out);
+      return (FALSE);
+    }
+  }
+
+  if (tvec && tvec[0].Nelements != yvec[0].Nelements) {
+    gprint (GP_ERR, "logic test vector not the same length as data vectors\n");
+    DeleteVector (tvec);
+    return (FALSE);
+  }
+
   SetVector (&Xvec, OPIHI_FLT, xvec[0].Nelements);
   SetVector (&Yvec, OPIHI_FLT, xvec[0].Nelements);
@@ -42,4 +67,9 @@
   Npts = 0;
   for (i = 0; i < Xvec.Nelements; i++, r++, d++) {
+    if (tvec) {
+      int skip = (tvec->type == OPIHI_FLT) ? (tvec->elements.Flt[i] == 0.0) : (tvec->elements.Int[i] == 0.0);
+      if (skip) continue;
+    }
+
     double ra = ohana_normalize_angle (*r);
     while (ra < Rmin) ra += 360.0;
@@ -88,4 +118,6 @@
   free (Yvec.elements.Ptr);
     
+  if (tvec) DeleteVector (tvec);
+
   return (TRUE);
 }
Index: trunk/Ohana/src/opihi/dvo/gstar.c
===================================================================
--- trunk/Ohana/src/opihi/dvo/gstar.c	(revision 37116)
+++ trunk/Ohana/src/opihi/dvo/gstar.c	(revision 37246)
@@ -627,5 +627,5 @@
 	      gprint (GP_LOG, "%5.3f ", catalog.measure[Nv].psfQF);
 	      gprint (GP_LOG, "%7.1f ", catalog.measure[Nv].psfChisq);
-	      gprint (GP_LOG, "%3.1f ", catalog.measure[Nv].crNsigma);
+	      // gprint (GP_LOG, "%3.1f ", catalog.measure[Nv].crNsigma);
 	      gprint (GP_LOG, "%4.1f ", catalog.measure[Nv].extNsigma);
 	      gprint (GP_LOG, "%5.1f ", FromShortDegrees(catalog.measure[Nv].theta));
Index: trunk/Ohana/src/relastro/src/UpdateObjects.c
===================================================================
--- trunk/Ohana/src/relastro/src/UpdateObjects.c	(revision 37116)
+++ trunk/Ohana/src/relastro/src/UpdateObjects.c	(revision 37246)
@@ -467,4 +467,10 @@
       catalog[i].average[j].Npos = fit.Nfit;
 
+      // XXX EAM 20140812: for a test, set average.Rstk,Dstk, etc to match R,D
+      catalog[i].average[j].Rstk  = fit.Ro; // RA in degrees
+      catalog[i].average[j].Dstk  = fit.Do; // DEC in degrees
+      catalog[i].average[j].dRstk = fit.dRo; // RA scatter in arcsec
+      catalog[i].average[j].dDstk = fit.dDo; // DEC scatter in arcsec
+
       // unset the NO_ASTROM bit (not(NO_ASTROM) == HAVE_ASTROM)
       catalog[i].average[j].flags &= ~ID_STAR_NO_ASTROM;
Index: trunk/Ohana/src/relphot/src/setMrelCatalog.c
===================================================================
--- trunk/Ohana/src/relphot/src/setMrelCatalog.c	(revision 37116)
+++ trunk/Ohana/src/relphot/src/setMrelCatalog.c	(revision 37246)
@@ -147,4 +147,7 @@
     off_t meas = measureOffset;
 
+    float psfQfMax = 0.0;
+    float psfQfPerfMax = 0.0;
+
     int Nap = 0;
     int Npsf = 0;
@@ -166,4 +169,9 @@
       // SKIP gpc1 forced-warp data
       if (isGPC1warp(measureT[k].photcode)) continue;
+
+      if (isSetMrelFinal) {
+	if (measure[k].psfQF     > psfQfMax)     psfQfMax     = measure[k].psfQF;
+	if (measure[k].psfQFperf > psfQfPerfMax) psfQfPerfMax = measure[k].psfQFperf;
+      }
 
       if (measureT[k].dbFlags & MEAS_BAD) SKIP_THIS_MEAS(Nbad); 
@@ -367,4 +375,7 @@
       secfilt[Nsec].Mmin = psfstats->min;
 
+      secfilt[Nsec].psfQfMax     = psfQfMax;
+      secfilt[Nsec].psfQfPerfMax = psfQfPerfMax;
+
       // NOTE : use the modified weight for apmags as well as psf mags
       liststats (Maplist, daplist, waplist, Nap, apstats);
@@ -457,4 +468,8 @@
   get_tess_ids(&tessID, &projectID, &skycellID, average[0].R, average[0].D);
 
+  average[0].tessID       = tessID;
+  average[0].projectionID = projectID;
+  average[0].skycellID    = skycellID;
+
   int NstackGood = 0;
   int NstackSuspect = 0;
@@ -478,4 +493,7 @@
     int isBad = FALSE;
     int isSuspect = FALSE;
+
+    int Nstack = 0; // number for this photcode
+    int NstackDet = 0; // number for this photcode
 
     off_t meas = measureOffset;
@@ -489,4 +507,7 @@
       if (!code) continue;
       if (code->equiv != thisCode) { continue; }
+
+      Nstack ++;
+      if (measure[k].photFlags2 & 0x00000004 == 0) NstackDet ++;
 
       // clear this bit for all measurements
@@ -615,4 +636,7 @@
     secfilt[Nsec].stackBestOff = k + measureOffset;
 
+    secfilt[Nsec].Nstack    = Nstack;
+    secfilt[Nsec].NstackDet = NstackDet;
+
     // this is the measurement used by secfilt[]
     measure[k].dbFlags |= ID_MEAS_STACK_PHOT_SRC;
@@ -694,4 +718,7 @@
     int Npsf = 0;
     int Nkron = 0;
+
+    int Nwarp = 0;
+    int NwarpGood = 0;
     for (k = 0; k < average[0].Nmeasure; k++, meas++) {
 
@@ -703,4 +730,7 @@
       if (!code) continue;
       if (code->equiv != thisCode) { continue; }
+
+      Nwarp ++;
+      if (measure[k].psfQFperf > 0.85) NwarpGood ++;
 
       measure[k].dbFlags &= ~ID_MEAS_WARP_USED;
@@ -799,4 +829,7 @@
     secfilt[Nsec].NusedKronWrp = Nkron;
     secfilt[Nsec].MkronWrp  = isnan(secfilt[Nsec].FkronWrp) ? NAN : 8.9 - 2.5*log10(secfilt[Nsec].FkronWrp); // 8.9 since flux is in Jy
+
+    secfilt[Nsec].Nwarp     = Nwarp;
+    secfilt[Nsec].NwarpGood = NwarpGood;
   }
   return (TRUE);
