Index: /branches/eam_branches/ohana.20170809/src/dvopsps/include/dvopsps.h
===================================================================
--- /branches/eam_branches/ohana.20170809/src/dvopsps/include/dvopsps.h	(revision 40113)
+++ /branches/eam_branches/ohana.20170809/src/dvopsps/include/dvopsps.h	(revision 40114)
@@ -146,2 +146,3 @@
 Detections *DetectionsLoad        	  PROTO((char *filename, int *Ndetections));
 int         DetectionsSave        	  PROTO((char *filename, Detections *detections, int Ndetections));
+void dvopsps_client_free (void);
Index: /branches/eam_branches/ohana.20170809/src/dvopsps/src/DetectionOps.c
===================================================================
--- /branches/eam_branches/ohana.20170809/src/dvopsps/src/DetectionOps.c	(revision 40113)
+++ /branches/eam_branches/ohana.20170809/src/dvopsps/src/DetectionOps.c	(revision 40114)
@@ -151,8 +151,8 @@
   FTable ftable;
 
-  gfits_init_header (&header);
+  gfits_init_header (&header); // *** FUNC : OK
   header.extend = TRUE;
-  gfits_create_header (&header);
-  gfits_create_matrix (&header, &matrix);
+  gfits_create_header (&header); // *** FUNC : OK
+  gfits_create_matrix (&header, &matrix); // *** FUNC : OK
 
   FILE *f = fopen (filename, "w");
@@ -162,13 +162,13 @@
   }
 
-  gfits_fwrite_header  (f, &header);
-  gfits_fwrite_matrix  (f, &matrix);
-  gfits_free_header (&header);
-  gfits_free_matrix (&matrix);
-
-  gfits_create_table_header (&theader, "BINTABLE", "DETECTIONS");
+  gfits_fwrite_header  (f, &header); // *** FUNC : OK
+  gfits_fwrite_matrix  (f, &matrix); // *** FUNC : OK
+  gfits_free_header (&header); // *** FUNC : OK
+  gfits_free_matrix (&matrix); // *** FUNC : OK
+
+  gfits_create_table_header (&theader, "BINTABLE", "DETECTIONS"); // *** FUNC : OK
 
   // XXX need to get the bzero values right
-  gfits_define_bintable_column (&theader, "K", "objID",       NULL, NULL, 1.0, 0);
+  gfits_define_bintable_column (&theader, "K", "objID",       NULL, NULL, 1.0, 0); // *** FUNC : OK (also below)
   gfits_define_bintable_column (&theader, "K", "detectID",    NULL, NULL, 1.0, 0);
   gfits_define_bintable_column (&theader, "K", "ippObjID",    NULL, NULL, 1.0, 0);
@@ -195,5 +195,6 @@
 
   // generate the output array that carries the data
-  gfits_create_table (&theader, &ftable);
+  gfits_create_table (&theader, &ftable); // *** FUNC : OK
+  gfits_set_table_rows (&theader, &ftable, Ndetections); // *** FUNC : OK
 
   // create intermediate storage arrays
@@ -302,4 +303,6 @@
   gfits_free_header (&theader);
   gfits_free_table (&ftable);
+
+  fclose (f);
   return TRUE;
 }
Index: /branches/eam_branches/ohana.20170809/src/dvopsps/src/dvopsps_client.c
===================================================================
--- /branches/eam_branches/ohana.20170809/src/dvopsps/src/dvopsps_client.c	(revision 40113)
+++ /branches/eam_branches/ohana.20170809/src/dvopsps/src/dvopsps_client.c	(revision 40114)
@@ -14,5 +14,8 @@
 
   // get configuration info, args, lockfile (set CATDIR, HOST_ID, HOSTDIR, IMAGES)
-  initialize_dvopsps_client (argc, argv);
+  // initialize_dvopsps_client (argc, argv);
+
+  TIME_START = NULL;
+  TIME_END = NULL;
 
   if (!strcasecmp (argv[1], "detections")) {
@@ -36,4 +39,8 @@
   }
 
+  dvopsps_client_free ();
+
+  ohana_memcheck (TRUE);
+  ohana_memdump (TRUE);
   if (!status) exit (1);
   exit (0);
Index: /branches/eam_branches/ohana.20170809/src/dvopsps/src/initialize_dvopsps.c
===================================================================
--- /branches/eam_branches/ohana.20170809/src/dvopsps/src/initialize_dvopsps.c	(revision 40113)
+++ /branches/eam_branches/ohana.20170809/src/dvopsps/src/initialize_dvopsps.c	(revision 40114)
@@ -222,4 +222,8 @@
 void initialize_dvopsps_client (int argc, char **argv) {
 
+  TIME_START = NULL;
+  TIME_END = NULL;
+  return;
+
   int N;
   struct stat statbuffer;
@@ -231,6 +235,10 @@
   if ((N = get_argument (argc, argv, "--help"))) usage_dvopsps_client();
 
-  SetZeroPoint (25.0); // XXX is this needed?
-  args_dvopsps_client (argc, argv);
+  TIME_START = NULL;
+  TIME_END = NULL;
+
+  // SetZeroPoint (25.0); // XXX is this needed?
+  // args_dvopsps_client (argc, argv);
+  return;
 
   if (stat (CATDIR, &statbuffer)) {
@@ -256,27 +264,31 @@
   PARALLEL_SERIAL = FALSE;
 
+  DATABASE_HOST = NULL;
   if ((N = get_argument (argc, argv, "-dbhost"))) {
     remove_argument (N, &argc, argv);
     DATABASE_HOST = strcreate (argv[N]);
     remove_argument (N, &argc, argv);
-  } else usage_dvopsps_client();
-
+  } // else usage_dvopsps_client();
+
+  DATABASE_USER = NULL;
   if ((N = get_argument (argc, argv, "-dbuser"))) {
     remove_argument (N, &argc, argv);
     DATABASE_USER = strcreate (argv[N]);
     remove_argument (N, &argc, argv);
-  } else usage_dvopsps_client();
-
+  } // else usage_dvopsps_client();
+
+  DATABASE_PASS = NULL;
   if ((N = get_argument (argc, argv, "-dbpass"))) {
     remove_argument (N, &argc, argv);
     DATABASE_PASS = strcreate (argv[N]);
     remove_argument (N, &argc, argv);
-  } else usage_dvopsps_client();
-
+  } // else usage_dvopsps_client();
+
+  DATABASE_NAME = NULL;
   if ((N = get_argument (argc, argv, "-dbname"))) {
     remove_argument (N, &argc, argv);
     DATABASE_NAME = strcreate (argv[N]);
     remove_argument (N, &argc, argv);
-  } else usage_dvopsps_client();
+  } // else usage_dvopsps_client();
 
   RESULT_FILE = NULL; // only used by dvopsps_client
@@ -299,5 +311,11 @@
   UserPatch.Dmin = -90;
   UserPatch.Dmax = +90;
-  if ((N = get_argument (argc, argv, "-region"))) {
+
+  UserPatch.Rmin = 277.594177;
+  UserPatch.Rmax = 279.405823;
+  UserPatch.Dmin =  -7.400000;
+  UserPatch.Dmax =  -5.600000;
+
+  if (FALSE && (N = get_argument (argc, argv, "-region"))) {
     remove_argument (N, &argc, argv);
     UserPatch.Rmin = atof (argv[N]);
@@ -361,5 +379,5 @@
   }
 
-  HOST_ID = 0;
+  HOST_ID = 1; // XXXX was 0
   if ((N = get_argument (argc, argv, "-hostID"))) {
     remove_argument (N, &argc, argv);
@@ -375,5 +393,5 @@
     remove_argument (N, &argc, argv);
   }
-  if (!HOSTDIR) usage_dvopsps_client();
+  // XXXX TEMP REMOVE if (!HOSTDIR) usage_dvopsps_client();
 
   if ((N = get_argument (argc, argv, "-catdir"))) {
@@ -382,8 +400,24 @@
     remove_argument (N, &argc, argv);
   }
-  if (!CATDIR) usage_dvopsps_client();
-
-  if (argc != 2) usage_dvopsps_client();
+  // if (!CATDIR) usage_dvopsps_client();
+
+  // if (argc != 2) usage_dvopsps_client();
   return (TRUE);
+}
+
+void dvopsps_client_free (void) {
+
+  FREE (DATABASE_HOST);
+  FREE (DATABASE_USER);
+  FREE (DATABASE_PASS);
+  FREE (DATABASE_NAME);
+  
+  FREE (RESULT_FILE);
+  FREE (SINGLE_CPT);
+  FREE (TIME_START);
+  FREE (TIME_END);
+  
+  FREE (HOSTDIR);
+  FREE (CATDIR);
 }
 
Index: /branches/eam_branches/ohana.20170809/src/dvopsps/src/insert_detections_dvopsps.c
===================================================================
--- /branches/eam_branches/ohana.20170809/src/dvopsps/src/insert_detections_dvopsps.c	(revision 40113)
+++ /branches/eam_branches/ohana.20170809/src/dvopsps/src/insert_detections_dvopsps.c	(revision 40114)
@@ -1,110 +1,56 @@
 # include "dvopsps.h"
-# define USE_MYSQL 1
-// # define SAVE_REMOTE 1
-
-// we have two ways of writing to the mysql database:
-// SAVE_REMOTE = 0 : each client sends the detections directly to the mysql server
-// SAVE_REMOTE = 1 : each client saves the detections to disk and these are loaded by the main program and sent to the mysql server
 
 // determine the relevant catalogs, launch parallel clients if desired
 int insert_detections_dvopsps () {
 
-  SkyTable *sky = NULL;
-  SkyList *skylist = NULL;
   Catalog catalog;
-  off_t i;
-
-  // load the current sky table (layout of all SkyRegions) 
-  sky = SkyTableLoadOptimal (CATDIR, NULL, NULL, FALSE, -1, VERBOSE);
-  SkyTableSetFilenames (sky, CATDIR, "cpt");
-  
-  if (PARALLEL && !HOST_ID) {
-    int status = insert_detections_dvopsps_parallel (sky);
-    return status;
-  }
-
-  // determine the populated SkyRegions overlapping the requested area (default depth)
-  if (SINGLE_CPT) {
-      skylist = SkyRegionByCPT (sky, SINGLE_CPT);
-  } else {
-      skylist = SkyListByPatch (sky, -1, &UserPatch);
-  }
-  myAssert (skylist, "ooops!");
-
-# if (USE_MYSQL)
-  // NOTE: mysql connection happens here since each dvopsps_client makes its own connection
-  MYSQL  mysqlBase;
-  MYSQL *mysqlReal = NULL;
-  if (!HOST_ID || !SAVE_REMOTE) {
-    mysqlReal = mysql_dvopsps_connect (&mysqlBase);
-    if (!mysqlReal) {
-      fprintf (stderr, "failed to connect to mysql\n");
-      exit (1);
-    }
-  }
-# else
-  MYSQL *mysqlReal = NULL;
-# endif
-
-  if (SAVE_REMOTE && HOST_ID) {
-    init_detections ();
-  }
+
+  init_detections (); // *** FUNC : OK
 
   int status = TRUE;
-  // select measurements for each populated catalog
-  for (i = 0; i < skylist[0].Nregions; i++) {
-
-    // does this host ID match the desired location for the table?
-    if (!HostTableTestHost(skylist[0].regions[i], HOST_ID)) continue;
-
-    char localFilename[1024];
-    snprintf (localFilename, 1024, "%s/%s.cpt", HOSTDIR, skylist->regions[i]->name);
-
-    // set up the basic catalog info
-    dvo_catalog_init (&catalog, TRUE);
-    catalog.filename  = HOST_ID ? localFilename : skylist[0].filename[i];
-    catalog.catflags  = DVO_LOAD_AVERAGE | DVO_LOAD_MEASURE | DVO_LOAD_SECFILT;
-    catalog.Nsecfilt  = GetPhotcodeNsecfilt ();
-
-    if (!dvo_catalog_open (&catalog, skylist[0].regions[i], VERBOSE, "r")) {
-      fprintf (stderr, "ERROR: failure reading catalog %s\n", catalog.filename);
-      exit (1);
-    }
-    if (!catalog.Naverage_disk) {
-      if (VERBOSE) fprintf (stderr, "no data in %s, skipping\n", catalog.filename);
-      dvo_catalog_unlock (&catalog);
-      dvo_catalog_free (&catalog);
-      continue;
-    }
-
-    // NOTE: this is where the real action happens
-    if (SAVE_REMOTE && HOST_ID) {
-      if (!append_detections_dvopsps_catalog (&catalog)) {
-	fprintf (stderr, "ERROR: failure to append detections to output catalog\n");
-	status = FALSE;
-      }
-    } else {
-      if (!insert_detections_dvopsps_catalog (&catalog, mysqlReal)) {
-	fprintf (stderr, "ERROR: failure to insert detections into mysql database\n");
-	status = FALSE;
-      }
-    }
-
-    // NOTE : unlike setastrom or relphot, this program is read-only wrt dvo
+
+  char *localFilename = NULL; // XXX stops aborting if I drop this (probably affects
+			      // memory position) (FREE below @ line 40 is also required)
+
+  // set up the basic catalog info
+  dvo_catalog_init (&catalog, TRUE);  // *** FUNC : OK
+//catalog.filename  = strcreate ("/data/ipp110.0/eugene/3pi.dvo.catdirs/3pi.pv3.20170216/catdir.037/s0000/5124.14.cpt"); // *** FUNC : OK
+//catalog.filename  = strcreate ("z0/5124.14.cpt"); // *** FUNC : OK
+  catalog.filename  = strcreate ("v0/5124.14.cpt"); // *** FUNC : OK
+  catalog.catflags  = DVO_LOAD_AVERAGE | DVO_LOAD_MEASURE | DVO_LOAD_SECFILT;
+  catalog.Nsecfilt  = 9;
+
+  if (!dvo_catalog_open (&catalog, NULL, VERBOSE, "r")) { // *** FUNC
+    fprintf (stderr, "ERROR: failure reading catalog %s\n", catalog.filename);
+    exit (1);
+  }
+  if (!catalog.Naverage_disk) {
+    if (VERBOSE) fprintf (stderr, "no data in %s, skipping\n", catalog.filename);
     dvo_catalog_unlock (&catalog);
     dvo_catalog_free (&catalog);
-
-    if (!status) {
-      fprintf (stderr, "failure to insert data in mysql\n");
-      exit (2);
-    }
-  }
-
-  if (SAVE_REMOTE && HOST_ID) {
-    if (!save_detections_dvopsps ()) {
-      fprintf (stderr, "ERROR: failure to save output file with detections\n");
-      status = FALSE;
-    }
-  }
+    FREE (localFilename);
+    exit (1);
+  }
+
+  if (!append_detections_dvopsps_catalog (&catalog)) { // *** FUNC : OK
+    fprintf (stderr, "ERROR: failure to append detections to output catalog\n");
+    status = FALSE;
+  }
+    
+  dvo_catalog_unlock (&catalog); // *** FUNC
+  dvo_catalog_free (&catalog); // *** FUNC
+  FREE (localFilename);
+
+  if (!status) {
+    fprintf (stderr, "failure to insert data in mysql\n");
+    exit (2);
+  }
+
+  if (!save_detections_dvopsps ()) { // *** FUNC : OK
+    fprintf (stderr, "ERROR: failure to save output file with detections\n");
+    status = FALSE;
+  }
+
+  exit (1);
 
   return (status);
@@ -118,5 +64,5 @@
   HostTable *table = HostTableLoad (CATDIR, sky->hosts);
 
-  char uniquer[12];
+  char uniquer[16];
   int TIME = time(NULL);
   int PID = getpid();
Index: /branches/eam_branches/ohana.20170809/src/dvopsps/src/insert_detections_dvopsps_catalog.c
===================================================================
--- /branches/eam_branches/ohana.20170809/src/dvopsps/src/insert_detections_dvopsps_catalog.c	(revision 40113)
+++ /branches/eam_branches/ohana.20170809/src/dvopsps/src/insert_detections_dvopsps_catalog.c	(revision 40114)
@@ -2,7 +2,7 @@
 # define DEBUG 0
 
-int Ndetections = 0;
-int NDETECTIONS = 0;
-Detections *detections = NULL;
+static int Ndetections = 0;
+static int NDETECTIONS = 0;
+static Detections *detections = NULL;
 
 static float ZeroPoint = 25.0;
@@ -18,5 +18,5 @@
   off_t i, j;
 
-  ZeroPoint = GetZeroPoint();
+  ZeroPoint = 25.0;
 
   int missingID = 0;
@@ -31,4 +31,5 @@
   if (TIME_START) ohana_str_to_time (TIME_START, &TIME_START_SEC); // we validate this in the args.c
   if (TIME_END)   ohana_str_to_time (TIME_END,   &TIME_END_SEC);   // we validate this in the args.c
+  // XXX the above ohana_str_to_time are NOT called
 
   for (i = 0; i < catalog[0].Naverage; i++) {
@@ -41,15 +42,13 @@
     for (j = 0; j < catalog[0].average[i].Nmeasure; j++) {
 
+      myAssert (m + j < catalog[0].Nmeasure, "out of bounds");
+      myAssert (m + j >= 0, "out of bounds");
+
       Average *average = &catalog->average[i];
       Measure *measure = &catalog->measure[m + j];
 
-      // some filters -- these are the detections we skip
-      if (TIME_START && (measure->t < TIME_START_SEC)) continue;
-      if (TIME_END   && (measure->t >=  TIME_END_SEC)) continue;
-
-      if (measure->photcode < PHOTCODE_START) continue;
-      if (measure->photcode >=  PHOTCODE_END) continue;
-
-      assign_detection_values (&detections[Ndetections], measure, average);
+      if (measure->photcode < 12000) continue;
+
+      assign_detection_values (&detections[Ndetections], measure, average); // *** FUNC : OK
       Ndetections ++;
 
@@ -58,5 +57,5 @@
   }
 
-  fprintf (stderr, "write %d detections, %d missing extID\n", Ndetections, missingID);
+  fprintf (stderr, "write %d of %d detections, %d missing extID\n", Ndetections, NDETECTIONS, missingID);
   return TRUE;
 }
@@ -70,5 +69,6 @@
   int status = TRUE;
 
-  if (!DetectionsSave (RESULT_FILE, detections, Ndetections)) {
+//if (!DetectionsSave (RESULT_FILE, detections, Ndetections)) {
+  if (!DetectionsSave ("/data/ipp110.0/eugene/3pi.dvo.catdirs/3pi.pv3.20170216/catdir.037/dvopsps.09762.24244.det.dat", detections, Ndetections)) {
     fprintf (stderr, "failed to save detection file %s\n", RESULT_FILE);
     status = FALSE;
@@ -305,5 +305,8 @@
 int assign_detection_values (Detections *detection, Measure *measure, Average *average) {
 
+  return TRUE;
+
   PhotCode *code = GetPhotcodebyCode(measure->photcode);
+  myAssert (code, "oops");
 
   uint64_t ippObjID = ((uint64_t)average->catID << 32) + (uint64_t)average->objID; // ippObjID
