Index: /branches/eam_branches/ipp-20140717/Ohana/src/dvopsps/include/dvopsps.h
===================================================================
--- /branches/eam_branches/ipp-20140717/Ohana/src/dvopsps/include/dvopsps.h	(revision 37175)
+++ /branches/eam_branches/ipp-20140717/Ohana/src/dvopsps/include/dvopsps.h	(revision 37176)
@@ -9,19 +9,26 @@
 
 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;
   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 +85,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: /branches/eam_branches/ipp-20140717/Ohana/src/dvopsps/src/DetectionOps.c
===================================================================
--- /branches/eam_branches/ipp-20140717/Ohana/src/dvopsps/src/DetectionOps.c	(revision 37175)
+++ /branches/eam_branches/ipp-20140717/Ohana/src/dvopsps/src/DetectionOps.c	(revision 37176)
@@ -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,24 @@
  
   // 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(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 +71,47 @@
   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].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 (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 +161,24 @@
 
   // 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, "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 +186,91 @@
 
   // 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);
   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     ;
     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, "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 (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: /branches/eam_branches/ipp-20140717/Ohana/src/dvopsps/src/insert_detections_dvopsps.c
===================================================================
--- /branches/eam_branches/ipp-20140717/Ohana/src/dvopsps/src/insert_detections_dvopsps.c	(revision 37175)
+++ /branches/eam_branches/ipp-20140717/Ohana/src/dvopsps/src/insert_detections_dvopsps.c	(revision 37176)
@@ -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: /branches/eam_branches/ipp-20140717/Ohana/src/dvopsps/src/insert_detections_dvopsps_catalog.c
===================================================================
--- /branches/eam_branches/ipp-20140717/Ohana/src/dvopsps/src/insert_detections_dvopsps_catalog.c	(revision 37175)
+++ /branches/eam_branches/ipp-20140717/Ohana/src/dvopsps/src/insert_detections_dvopsps_catalog.c	(revision 37176)
@@ -47,25 +47,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");
     }
@@ -143,5 +125,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 +179,10 @@
   }
 
-  // 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, ");
+  PrintIOBuffer (buffer, "ra, dec_, raErr, decErr, zp, telluricExt, airmass, expTime, Mpsf, dMpsf, Mkron, dMkron, Map, dMap, flags) VALUES \n");
+
+  return TRUE;
+}
+
 int insert_detections_mysql_commit (IOBuffer *buffer, MYSQL *mysql) {
 
@@ -270,2 +219,77 @@
   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
+
+  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;
+}
+
+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;	       // ippObID
+  detection->ippDetectID  = measure->detID;   // ippDetectID
+  detection->imageID      = measure->imageID; // imageID
+
+  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:
+  detection->Mpsf   = (measure->FluxPSF  > 0.0) ? zp - 2.5*log10(measure->FluxPSF)  : NAN;
+  detection->Mkron  = (measure->FluxKron > 0.0) ? zp - 2.5*log10(measure->FluxKron) : NAN;
+  detection->Map    = (measure->FluxAp   > 0.0) ? zp - 2.5*log10(measure->FluxAp)   : NAN;
+
+  detection->dMpsf  = (measure->FluxPSF  > 0.0) ? measure->dFluxPSF / measure->FluxPSF : NAN;
+  detection->dMkron = (measure->FluxKron > 0.0) ? measure->dFluxKron/ measure->FluxKron: NAN;
+  detection->dMap   = (measure->FluxAp   > 0.0) ? measure->dFluxAp  / measure->FluxAp  : NAN;
+
+  detection->flags  = measure->dbFlags;  // flags
+
+  return TRUE;
+}
+
Index: /branches/eam_branches/ipp-20140717/Ohana/src/dvopsps/src/insert_objects_dvopsps_catalog.c
===================================================================
--- /branches/eam_branches/ipp-20140717/Ohana/src/dvopsps/src/insert_objects_dvopsps_catalog.c	(revision 37175)
+++ /branches/eam_branches/ipp-20140717/Ohana/src/dvopsps/src/insert_objects_dvopsps_catalog.c	(revision 37176)
@@ -90,20 +90,20 @@
   // Only send the necessary fields (eg, do not sent parallax and pm)
   PrintIOBuffer (&buffer, "CREATE TABLE %s_cpt ("
-		 "EXT_ID      BIGINT"
-		 "OBJ_ID      INT,  "      
-		 "CAT_ID      INT,  "      
-		 "DVO_REGION  INT"
-		 "FLAGS       INT,  "       
-		 "RA_STK      DOUBLE,  "          
-		 "DEC_STK     DOUBLE,  "         
+		 "EXT_ID      BIGINT, "
+		 "OBJ_ID      INT,    "      
+		 "CAT_ID      INT,    "      
+		 "DVO_REGION  INT,    "
+		 "RA_STK      DOUBLE, "          
+		 "DEC_STK     DOUBLE, "         
 		 "RA_STK_ERR  FLOAT,  "      
 		 "DEC_STK_ERR FLOAT,  "     
-		 "RA_MEAN     DOUBLE,  "          
-		 "DEC_MEAN    DOUBLE,  "         
+		 "RA_MEAN     DOUBLE, "          
+		 "DEC_MEAN    DOUBLE, "         
 		 "RA_ERR      FLOAT,  "      
 		 "DEC_ERR     FLOAT,  "     
 		 "CHISQ_POS   FLOAT,  "   
 		 "CHISQ_PM    FLOAT,  "    
-		 "CHISQ_PAP   FLOAT,  "   
+		 "CHISQ_PAR   FLOAT,  "   
+		 "FLAGS       INT     "       
 		 ")\n", basename);
 
@@ -153,22 +153,20 @@
 
   PrintIOBuffer (&buffer, "CREATE TABLE %s_cps ("
-		 "MAG       FLOAT,  "             
-		 "MAG_ERR   FLOAT,  "         
-		 "MAG_STDEV FLOAT,  "         
-		 "MAG_MIN   FLOAT,  "         
-		 "MAG_MAX   FLOAT,  "         
-		 "NUSED     SMALLINT,  "           
-
+		 "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,  "    
-
-		 "FLAGS INT,  "           
+		 "NCODE          SMALLINT,  "           
+		 "FLAGS          INT  "           
 		 ")\n", basename);
 
@@ -194,20 +192,20 @@
 
   PrintIOBuffer (ave_buffer, "INSERT INTO %s_cpt ("
-		 "EXT_ID"
-		 "OBJ_ID, "      
-		 "CAT_ID, "      
-		 "DVO_REGION, "
-		 "FLAGS, "       
-		 "RA_STK, "          
-		 "DEC_STK, "         
-		 "RA_STK_ERR, "      
+		 "EXT_ID,      "
+		 "OBJ_ID,      "      
+		 "CAT_ID,      "      
+		 "DVO_REGION,  "
+		 "RA_STK,      "          
+		 "DEC_STK,     "         
+		 "RA_STK_ERR,  "      
 		 "DEC_STK_ERR, "     
-		 "RA_MEAN, "          
-		 "DEC_MEAN, "         
-		 "RA_ERR, "      
-		 "DEC_ERR, "     
-		 "CHISQ_POS, "   
-		 "CHISQ_PM, "    
-		 "CHISQ_PAP, "   
+		 "RA_MEAN,     "          
+		 "DEC_MEAN,    "         
+		 "RA_ERR,      "      
+		 "DEC_ERR,     "     
+		 "CHISQ_POS,   "   
+		 "CHISQ_PM,    "    
+		 "CHISQ_PAR,   "   
+		 "FLAGS        "       
 		 ") VALUES \n", basename);
 
@@ -234,5 +232,6 @@
 		 "NUSED_AP, "           
 
-		 "FLAGS, "           
+		 "NCODE, "           
+		 "FLAGS "           
 		 ") VALUES \n", basename);
   return TRUE;
@@ -249,11 +248,10 @@
 // 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, "%lu, ", average->extID);          
+  PrintIOBuffer (ave_buffer, "%u,  ", average->objID);          
+  PrintIOBuffer (ave_buffer, "%u,  ", average->catID);          
 
   int dvoRegion = 1;
   PrintIOBuffer (ave_buffer, "%u, ",  dvoRegion);          
-  PrintIOBuffer (ave_buffer, "%u, ",  average->flags);          
 
   PRINT_FLOAT(ave_buffer, average->Rstk,     "%.8f, ");  // 0.036 mas precision 
@@ -270,4 +268,6 @@
   PRINT_FLOAT(ave_buffer, average->ChiSqPM,  "%.4f, ");
   PRINT_FLOAT(ave_buffer, average->ChiSqPar, "%.4f, ");
+
+  PrintIOBuffer (ave_buffer, "%u ",  average->flags);          
 
   PrintIOBuffer (ave_buffer, "),\n");
@@ -323,6 +323,7 @@
     PRINT_FLOAT(sec_buffer, meanApMagStd,  "%.6f, "); // umag precision
     PrintIOBuffer (sec_buffer, "%hd,  ", secfilt->NusedAp);        
-
-    PrintIOBuffer (sec_buffer, "%u,   ", secfilt->flags);       
+    PrintIOBuffer (sec_buffer, "%hd,  ", secfilt->Ncode);        
+    PrintIOBuffer (sec_buffer, "%u    ", secfilt->flags);       
+
     PrintIOBuffer (sec_buffer, "),\n");
     secfilt ++;
