Index: /branches/eam_branches/ipp-20101103/Ohana/src/dvomerge/Makefile
===================================================================
--- /branches/eam_branches/ipp-20101103/Ohana/src/dvomerge/Makefile	(revision 29793)
+++ /branches/eam_branches/ipp-20101103/Ohana/src/dvomerge/Makefile	(revision 29794)
@@ -27,4 +27,5 @@
 $(SRC)/dvomergeCreate.$(ARCH).o \
 $(SRC)/dvomergeContinue.$(ARCH).o \
+$(SRC)/dvomergeContinue_threaded.$(ARCH).o \
 $(SRC)/dvomergeFromList.$(ARCH).o \
 $(SRC)/dvo_image_merge_dbs.$(ARCH).o \
Index: /branches/eam_branches/ipp-20101103/Ohana/src/dvomerge/include/dvomerge.h
===================================================================
--- /branches/eam_branches/ipp-20101103/Ohana/src/dvomerge/include/dvomerge.h	(revision 29793)
+++ /branches/eam_branches/ipp-20101103/Ohana/src/dvomerge/include/dvomerge.h	(revision 29794)
@@ -28,4 +28,5 @@
 float  RADIUS;
 int    SKY_DEPTH;
+int    NTHREADS;
 char   *ALTERNATE_PHOTCODE_FILE;
 
@@ -68,5 +69,5 @@
 SkyList   *SkyTablePopulatedList_old  PROTO((SkyTable *sky, off_t Ns, off_t Ne));
 
-int        LoadCatalog            PROTO((Catalog *catalog, SkyRegion *region, char *filename, char *mode));
+int        LoadCatalog            PROTO((Catalog *catalog, SkyRegion *region, char *filename, char *mode, int Nsecfilt));
 
 int        merge_catalogs_new     PROTO((SkyRegion *region, Catalog *output, Catalog *input, int *secflitMap));
@@ -112,2 +113,3 @@
 int 	   dvomergeContinue       PROTO((int argc, char **argv));
 int        dvomergeFromList       PROTO((int argc, char **argv));
+int 	   dvomergeContinue_threaded PROTO((int argc, char **argv));
Index: /branches/eam_branches/ipp-20101103/Ohana/src/dvomerge/src/LoadCatalog.c
===================================================================
--- /branches/eam_branches/ipp-20101103/Ohana/src/dvomerge/src/LoadCatalog.c	(revision 29793)
+++ /branches/eam_branches/ipp-20101103/Ohana/src/dvomerge/src/LoadCatalog.c	(revision 29794)
@@ -1,9 +1,9 @@
 # include "dvomerge.h"
 
-int LoadCatalog (Catalog *catalog, SkyRegion *region, char *filename, char *mode) {
+int LoadCatalog (Catalog *catalog, SkyRegion *region, char *filename, char *mode, int Nsecfilt) {
 
     // set the parameters which guide catalog open/load/create
     catalog[0].filename  = filename;
-    catalog[0].Nsecfilt  = GetPhotcodeNsecfilt ();
+    catalog[0].Nsecfilt  = Nsecfilt;
 
     // always load all of the data (if any exists)
Index: /branches/eam_branches/ipp-20101103/Ohana/src/dvomerge/src/args.c
===================================================================
--- /branches/eam_branches/ipp-20101103/Ohana/src/dvomerge/src/args.c	(revision 29793)
+++ /branches/eam_branches/ipp-20101103/Ohana/src/dvomerge/src/args.c	(revision 29794)
@@ -15,4 +15,11 @@
     remove_argument (N, argc, argv);
     ALTERNATE_PHOTCODE_FILE = strdup(argv[N]);
+    remove_argument (N, argc, argv);
+  }
+
+  NTHREADS = 0;
+  if ((N = get_argument (*argc, argv, "-threads"))) {
+    remove_argument (N, argc, argv);
+    NTHREADS = MAX(0, atoi(argv[N]));
     remove_argument (N, argc, argv);
   }
Index: /branches/eam_branches/ipp-20101103/Ohana/src/dvomerge/src/dvoconvert.c
===================================================================
--- /branches/eam_branches/ipp-20101103/Ohana/src/dvomerge/src/dvoconvert.c	(revision 29793)
+++ /branches/eam_branches/ipp-20101103/Ohana/src/dvomerge/src/dvoconvert.c	(revision 29794)
@@ -6,5 +6,5 @@
   char filename[256], *input, *output;
 
-  int depth;
+  int depth, Nsecfilt;
   off_t i, j, Ns, Ne;
   SkyTable *outsky, *insky;
@@ -32,4 +32,6 @@
       exit (1);
     }
+    Nsecfilt = GetPhotcodeNsecfilt();
+
     // save the photcodes in the output catdir
     sprintf (filename, "%s/Photcodes.dat", output);
@@ -67,5 +69,5 @@
 
     // load / create output catalog
-    LoadCatalog (&outcatalog, &outsky[0].regions[i], outsky[0].filename[i], "w");
+    LoadCatalog (&outcatalog, &outsky[0].regions[i], outsky[0].filename[i], "w", Nsecfilt);
 
     // combine only tables at equal or larger depth
@@ -77,5 +79,5 @@
 
       // load input catalog
-      LoadCatalog (&incatalog, inlist[0].regions[j], inlist[0].filename[j], "r");
+      LoadCatalog (&incatalog, inlist[0].regions[j], inlist[0].filename[j], "r", Nsecfilt);
 
       // skip empty input catalogs
Index: /branches/eam_branches/ipp-20101103/Ohana/src/dvomerge/src/dvomerge.c
===================================================================
--- /branches/eam_branches/ipp-20101103/Ohana/src/dvomerge/src/dvomerge.c	(revision 29793)
+++ /branches/eam_branches/ipp-20101103/Ohana/src/dvomerge/src/dvomerge.c	(revision 29794)
@@ -18,5 +18,11 @@
   }
   if (argc == 4) dvomergeUpdate (argc, argv);
-  if (argc == 5) dvomergeContinue (argc, argv);
+  if (argc == 5) {
+    if (NTHREADS) {
+      dvomergeContinue_threaded (argc, argv);
+    } else {
+      dvomergeContinue (argc, argv);
+    }
+  }
   dvomerge_usage();
   exit (2); // cannot reach here.
Index: /branches/eam_branches/ipp-20101103/Ohana/src/dvomerge/src/dvomergeContinue.c
===================================================================
--- /branches/eam_branches/ipp-20101103/Ohana/src/dvomerge/src/dvomergeContinue.c	(revision 29793)
+++ /branches/eam_branches/ipp-20101103/Ohana/src/dvomerge/src/dvomergeContinue.c	(revision 29794)
@@ -13,4 +13,9 @@
   PhotCodeData *outputPhotcodes;
   int *secfiltMap = NULL;
+  int NsecfiltInput, NsecfiltOutput;
+
+  double dtime;
+  struct timeval start, stop;
+  gettimeofday (&start, NULL);
 
   if (strcasecmp (argv[2], "into")) dvomerge_usage();
@@ -32,4 +37,5 @@
   }	
   inputPhotcodes = GetPhotcodeTable();
+  NsecfiltInput = GetPhotcodeNsecfilt();
 
   // since we are merging the input db into the output db, the output defines the photcode
@@ -42,4 +48,5 @@
 
     outputPhotcodes = GetPhotcodeTable();
+    NsecfiltOutput = GetPhotcodeNsecfilt();
 
     secfiltMap = GetSecFiltMap(outputPhotcodes, inputPhotcodes);
@@ -51,4 +58,6 @@
     fprintf(stderr, "%s not found using photcodes from %s/Photcodes.dat\n", filename, input);
     outputPhotcodes = inputPhotcodes;
+    NsecfiltOutput = NsecfiltInput;
+
     if (!check_dir_access (output, VERBOSE)) {
       fprintf (stderr, "error creating output database directory %s\n", output);
@@ -87,4 +96,7 @@
   depth = inlist[0].regions[Ns][0].depth;
   
+  // XXX test: are we using the table (if so, if it is NULL, we should get errors)
+  SetPhotcodeTable(NULL);
+
   // loop over the populated input regions
   for (i = 0; i < inlist[0].Nregions; i++) {
@@ -92,7 +104,6 @@
     if (VERBOSE) fprintf (stderr, "input: %s\n", inlist[0].regions[i][0].name);
 
-    SetPhotcodeTable(inputPhotcodes);
     // load / create output catalog (if catalog does not exist, it will be created)
-    LoadCatalog (&incatalog, &inlist[0].regions[i][0], inlist[0].filename[i], "r");
+    LoadCatalog (&incatalog, &inlist[0].regions[i][0], inlist[0].filename[i], "r", NsecfiltInput);
     // skip empty input catalogs
     if (!incatalog.Naves_disk) {
@@ -113,6 +124,5 @@
 
       // load input catalog
-      SetPhotcodeTable(outputPhotcodes);
-      LoadCatalog (&outcatalog, outlist[0].regions[j], outlist[0].filename[j], "w");
+      LoadCatalog (&outcatalog, outlist[0].regions[j], outlist[0].filename[j], "w", NsecfiltOutput);
 
       dvo_update_image_IDs (&IDmap, &incatalog);
@@ -148,4 +158,8 @@
   }
 
+  gettimeofday (&stop, NULL);
+  dtime = DTIME (stop, start);
+  fprintf (stderr, "SUCCESS: elapsed time %9.4f sec\n", dtime);
+
   exit (0);
 }
Index: /branches/eam_branches/ipp-20101103/Ohana/src/dvomerge/src/dvomergeCreate.c
===================================================================
--- /branches/eam_branches/ipp-20101103/Ohana/src/dvomerge/src/dvomergeCreate.c	(revision 29793)
+++ /branches/eam_branches/ipp-20101103/Ohana/src/dvomerge/src/dvomergeCreate.c	(revision 29794)
@@ -15,4 +15,5 @@
   char *input1, *input2, *output;
   IDmapType IDmap1, IDmap2;
+  int NsecfiltInput1, NsecfiltInput2, NsecfiltOutput;
 
   if (strcasecmp (argv[2], "and")) dvomerge_usage();
@@ -39,4 +40,5 @@
   }
   input1Photcodes = GetPhotcodeTable();
+  NsecfiltInput1 = GetPhotcodeNsecfilt();
 
   // Read the input2 photcodes
@@ -48,4 +50,5 @@
   }
   input2Photcodes = GetPhotcodeTable();
+  NsecfiltInput2 = GetPhotcodeNsecfilt();
 
   if (ALTERNATE_PHOTCODE_FILE) {
@@ -60,4 +63,5 @@
     }
     outputPhotcodes = GetPhotcodeTable();
+    NsecfiltOutput = GetPhotcodeNsecfilt();
 
     secfiltMap1 = GetSecFiltMap(outputPhotcodes, input1Photcodes);
@@ -74,4 +78,5 @@
     outputPhotcodes = input1Photcodes;
     codesFilename = filename1;
+    NsecfiltOutput = NsecfiltInput1;
     // secfitMap1 can remain NULL since input1 defines the set of codes
   }
@@ -84,6 +89,9 @@
   }
 
+  // trigger any dependencies, if any
+  SetPhotcodeTable(NULL);
+
   // save the output photcodes in the output catdir
-  SetPhotcodeTable(outputPhotcodes);
+  // SetPhotcodeTable(outputPhotcodes);
   sprintf (filename, "%s/Photcodes.dat", output);
   if (!check_file_access (filename, TRUE, TRUE, VERBOSE)) {
@@ -121,13 +129,13 @@
     if (VERBOSE) fprintf (stderr, "output: %s\n", outsky[0].regions[i].name);
 
-    if (outputPhotcodes) {
-        SetPhotcodeTable(outputPhotcodes);
-    }
+    // if (outputPhotcodes) {
+    //     SetPhotcodeTable(outputPhotcodes);
+    // }
     // load / create output catalog
-    LoadCatalog (&outcatalog, &outsky[0].regions[i], outsky[0].filename[i], "w");
-
-    if (input1Photcodes) {
-        SetPhotcodeTable(input1Photcodes);
-    }
+    LoadCatalog (&outcatalog, &outsky[0].regions[i], outsky[0].filename[i], "w", NsecfiltOutput);
+
+    // if (input1Photcodes) {
+    // SetPhotcodeTable(input1Photcodes);
+    // }
     // combine only tables at equal or larger depth
       
@@ -138,5 +146,5 @@
 
       // load input catalog (1)
-      LoadCatalog (&incatalog, inlist[0].regions[j], inlist[0].filename[j], "r");
+      LoadCatalog (&incatalog, inlist[0].regions[j], inlist[0].filename[j], "r", NsecfiltInput1);
 
       // skip empty input catalogs
@@ -153,7 +161,7 @@
     SkyListFree (inlist);
 
-    if (input2Photcodes) {
-      SetPhotcodeTable(input2Photcodes);
-    }
+    // if (input2Photcodes) {
+    //   SetPhotcodeTable(input2Photcodes);
+    // }
 
     // load in all of the tables from input2 for this region
@@ -163,5 +171,5 @@
 
       // load input catalog (2)
-      LoadCatalog (&incatalog, inlist[0].regions[j], inlist[0].filename[j], "r");
+      LoadCatalog (&incatalog, inlist[0].regions[j], inlist[0].filename[j], "r", NsecfiltInput2);
 
       // skip empty input catalogs
Index: /branches/eam_branches/ipp-20101103/Ohana/src/dvomerge/src/dvomergeFromList.c
===================================================================
--- /branches/eam_branches/ipp-20101103/Ohana/src/dvomerge/src/dvomergeFromList.c	(revision 29793)
+++ /branches/eam_branches/ipp-20101103/Ohana/src/dvomerge/src/dvomergeFromList.c	(revision 29794)
@@ -12,4 +12,5 @@
   char *listname, **list, inputfile[256], outputfile[256];
   int Nlist, NLIST;
+  int NsecfiltInput, NsecfiltOutput;
 
   if (strcasecmp (argv[2], "into")) dvomerge_usage();
@@ -56,4 +57,5 @@
   }	
   inputPhotcodes = GetPhotcodeTable();
+  NsecfiltInput = GetPhotcodeNsecfilt();
 
   // since we are merging the input db into the output db, the output defines the photcode
@@ -66,4 +68,5 @@
 
     outputPhotcodes = GetPhotcodeTable();
+    NsecfiltOutput = GetPhotcodeNsecfilt();
 
     secfiltMap = GetSecFiltMap(outputPhotcodes, inputPhotcodes);
@@ -75,4 +78,6 @@
     fprintf(stderr, "%s not found using photcodes from %s/Photcodes.dat\n", filename, input);
     outputPhotcodes = inputPhotcodes;
+    NsecfiltOutput = NsecfiltInput;
+
     if (!check_dir_access (output, VERBOSE)) {
       fprintf (stderr, "error creating output database directory %s\n", output);
@@ -89,4 +94,6 @@
   dvomergeImagesGetMap (&IDmap, input, output);
 
+  SetPhotcodeTable(NULL);
+
   // loop over the populated input regions
   for (i = 0; i < Nlist; i++) {
@@ -96,6 +103,5 @@
     sprintf (outputfile, "%s/%s", output, list[i]);
 
-    SetPhotcodeTable(inputPhotcodes);
-    LoadCatalog (&incatalog, NULL, inputfile, "r");
+    LoadCatalog (&incatalog, NULL, inputfile, "r", NsecfiltInput);
 
     // skip empty input catalogs
@@ -115,6 +121,6 @@
 
     // load input catalog
-    SetPhotcodeTable(outputPhotcodes);
-    LoadCatalog (&outcatalog, NULL, outputfile, "w");
+    // SetPhotcodeTable(outputPhotcodes);
+    LoadCatalog (&outcatalog, NULL, outputfile, "w", NsecfiltOutput);
 
     if (outcatalog.Naverage == 0) {
Index: /branches/eam_branches/ipp-20101103/Ohana/src/dvomerge/src/dvomergeUpdate.c
===================================================================
--- /branches/eam_branches/ipp-20101103/Ohana/src/dvomerge/src/dvomergeUpdate.c	(revision 29793)
+++ /branches/eam_branches/ipp-20101103/Ohana/src/dvomerge/src/dvomergeUpdate.c	(revision 29794)
@@ -13,4 +13,5 @@
   PhotCodeData *outputPhotcodes;
   int *secfiltMap = NULL;
+  int NsecfiltInput, NsecfiltOutput;
 
   if (strcasecmp (argv[2], "into")) dvomerge_usage();
@@ -31,4 +32,5 @@
   }	
   inputPhotcodes = GetPhotcodeTable();
+  NsecfiltInput = GetPhotcodeNsecfilt();
 
   // since we are merging the input db into the output db, the output defines the photcode
@@ -41,4 +43,5 @@
 
     outputPhotcodes = GetPhotcodeTable();
+    NsecfiltOutput = GetPhotcodeNsecfilt();
 
     secfiltMap = GetSecFiltMap(outputPhotcodes, inputPhotcodes);
@@ -50,4 +53,6 @@
     fprintf(stderr, "%s not found using photcodes from %s/Photcodes.dat\n", filename, input);
     outputPhotcodes = inputPhotcodes;
+    NsecfiltOutput = NsecfiltInput;
+
     if (!check_dir_access (output, VERBOSE)) {
       fprintf (stderr, "error creating output database directory %s\n", output);
@@ -85,4 +90,6 @@
   depth = inlist[0].regions[Ns][0].depth;
   
+  SetPhotcodeTable(NULL);
+
   // loop over the populated input regions
   for (i = 0; i < inlist[0].Nregions; i++) {
@@ -90,7 +97,7 @@
     if (VERBOSE) fprintf (stderr, "input: %s\n", inlist[0].regions[i][0].name);
 
-    SetPhotcodeTable(inputPhotcodes);
+    // SetPhotcodeTable(inputPhotcodes);
     // load / create output catalog (if catalog does not exist, it will be created)
-    LoadCatalog (&incatalog, &inlist[0].regions[i][0], inlist[0].filename[i], "r");
+    LoadCatalog (&incatalog, &inlist[0].regions[i][0], inlist[0].filename[i], "r", NsecfiltInput);
     // skip empty input catalogs
     if (!incatalog.Naves_disk) {
@@ -111,6 +118,6 @@
 
       // load input catalog
-      SetPhotcodeTable(outputPhotcodes);
-      LoadCatalog (&outcatalog, outlist[0].regions[j], outlist[0].filename[j], "w");
+      // SetPhotcodeTable(outputPhotcodes);
+      LoadCatalog (&outcatalog, outlist[0].regions[j], outlist[0].filename[j], "w", NsecfiltOutput);
 
       dvo_update_image_IDs (&IDmap, &incatalog);
Index: /branches/eam_branches/ipp-20101103/Ohana/src/dvomerge/src/help.c
===================================================================
--- /branches/eam_branches/ipp-20101103/Ohana/src/dvomerge/src/help.c	(revision 29793)
+++ /branches/eam_branches/ipp-20101103/Ohana/src/dvomerge/src/help.c	(revision 29794)
@@ -19,5 +19,5 @@
 void dvosecfilt_usage(void) {
 
-  fprintf (stderr, "USAGE: dvosecfilt (input) -photcodes (photcodes.txt)\n");
+  fprintf (stderr, "USAGE: dvosecfilt (catdir) (Nsecfilt)\n");
 
   exit (2);
@@ -80,7 +80,8 @@
 
   fprintf (stderr, "USAGE\n");
-  fprintf (stderr, "  dvosecfilt (input) (Nsecfilt)\n\n");
+  fprintf (stderr, "  dvosecfilt (catdir) (Nsecfilt)\n\n");
 
-  fprintf (stderr, "  change number of secfilt entries in photcode table (updates secfilt tables only)\n");
+  fprintf (stderr, "  change number of secfilt entries in photcode table (updates secfilt tables (cps), NSECFILT in cpt files)\n");
+  fprintf (stderr, "  NOTE: the user must change the photcode table to reflect the change (use photcode-table -export / -import)\n");
  
   fprintf (stderr, "  optional flags:\n");
