Index: /branches/eam_branches/ipp-20101103/Ohana/src/dvomerge/Makefile
===================================================================
--- /branches/eam_branches/ipp-20101103/Ohana/src/dvomerge/Makefile	(revision 29788)
+++ /branches/eam_branches/ipp-20101103/Ohana/src/dvomerge/Makefile	(revision 29789)
@@ -27,4 +27,5 @@
 $(SRC)/dvomergeCreate.$(ARCH).o \
 $(SRC)/dvomergeContinue.$(ARCH).o \
+$(SRC)/dvomergeFromList.$(ARCH).o \
 $(SRC)/dvo_image_merge_dbs.$(ARCH).o \
 $(SRC)/SetSignals.$(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 29788)
+++ /branches/eam_branches/ipp-20101103/Ohana/src/dvomerge/include/dvomerge.h	(revision 29789)
@@ -111,2 +111,3 @@
 int 	   dvomergeImagesGetMap   PROTO((IDmapType *IDmap, char *input, char *output));
 int 	   dvomergeContinue       PROTO((int argc, char **argv));
+int        dvomergeFromList       PROTO((int argc, char **argv));
Index: /branches/eam_branches/ipp-20101103/Ohana/src/dvomerge/src/dvomerge.c
===================================================================
--- /branches/eam_branches/ipp-20101103/Ohana/src/dvomerge/src/dvomerge.c	(revision 29788)
+++ /branches/eam_branches/ipp-20101103/Ohana/src/dvomerge/src/dvomerge.c	(revision 29789)
@@ -10,5 +10,11 @@
   // XXX require both inputs to be sorted?
 
-  if (argc == 6) dvomergeCreate (argc, argv);
+  if (argc == 6) {
+    if (!strcasecmp (argv[2], "and")) {
+      dvomergeCreate (argc, argv);
+    } else {
+      dvomergeFromList (argc, argv);
+    }
+  }
   if (argc == 4) dvomergeUpdate (argc, argv);
   if (argc == 5) dvomergeContinue (argc, argv);
Index: /branches/eam_branches/ipp-20101103/Ohana/src/dvomerge/src/dvomergeContinue.c
===================================================================
--- /branches/eam_branches/ipp-20101103/Ohana/src/dvomerge/src/dvomergeContinue.c	(revision 29788)
+++ /branches/eam_branches/ipp-20101103/Ohana/src/dvomerge/src/dvomergeContinue.c	(revision 29789)
@@ -15,4 +15,5 @@
 
   if (strcasecmp (argv[2], "into")) dvomerge_usage();
+  if (strcasecmp (argv[4], "continue")) dvomerge_usage();
 
   input  = argv[1];
Index: /branches/eam_branches/ipp-20101103/Ohana/src/dvomerge/src/dvomergeFromList.c
===================================================================
--- /branches/eam_branches/ipp-20101103/Ohana/src/dvomerge/src/dvomergeFromList.c	(revision 29789)
+++ /branches/eam_branches/ipp-20101103/Ohana/src/dvomerge/src/dvomergeFromList.c	(revision 29789)
@@ -0,0 +1,152 @@
+# include "dvomerge.h"
+
+int dvomergeFromList (int argc, char **argv) {
+
+  off_t i, j;
+  Catalog incatalog, outcatalog;
+  char filename[256], *input, *output;
+  IDmapType IDmap;
+  PhotCodeData *inputPhotcodes;
+  PhotCodeData *outputPhotcodes;
+  int *secfiltMap = NULL;
+  char *listname, **list, inputfile[256], outputfile[256];
+  int Nlist, NLIST;
+
+  if (strcasecmp (argv[2], "into")) dvomerge_usage();
+  if (strcasecmp (argv[4], "from")) dvomerge_usage();
+
+  input  = argv[1];
+  output = argv[3];
+  listname = argv[5];
+
+  Nlist = 0;
+  NLIST = 100;
+  ALLOCATE(list, char *, NLIST);
+  for (i = 0; i < NLIST; i++) {
+    ALLOCATE(list[i], char, 256);
+    memset(list[i], 0, 256);
+  }
+  
+  FILE *listfile = fopen(listname, "r");
+  myAssert(listfile, "error opening list");
+
+  for (i = 0; fscanf (listfile, "%s", list[i]) != EOF; i++) {
+    if (i == NLIST - 1) {
+      NLIST += 100;
+      REALLOCATE(list, char *, NLIST);
+      for (j = i + 1; j < NLIST; j++) {
+	ALLOCATE(list[j], char, 256);
+	memset(list[j], 0, 256);
+      }
+    }
+  }      
+  Nlist = i;
+  fclose(listfile);
+
+  if (ALTERNATE_PHOTCODE_FILE) {
+    fprintf (stderr, "cannot specify photcodes when merging into an existing catdir\n");
+    exit (1);
+  }
+
+  SetPhotcodeTable(NULL);
+  sprintf (filename, "%s/Photcodes.dat", input);
+  if (!LoadPhotcodes (filename, NULL, FALSE)) {
+    fprintf (stderr, "error reading input database directory %s\n", input);
+    exit (1);
+  }	
+  inputPhotcodes = GetPhotcodeTable();
+
+  // since we are merging the input db into the output db, the output defines the photcode
+  // table & db layout but, this requires the output to exist.  if it does not, instead use the
+  // input.
+
+  SetPhotcodeTable(NULL);
+  sprintf (filename, "%s/Photcodes.dat", output);
+  if (LoadPhotcodes (filename, NULL, FALSE)) {
+
+    outputPhotcodes = GetPhotcodeTable();
+
+    secfiltMap = GetSecFiltMap(outputPhotcodes, inputPhotcodes);
+    if (!secfiltMap) {
+      fprintf (stderr, "failed to map input secfilt photcodes to output photcodes table\n");
+      exit (1);
+    }
+  } else {
+    fprintf(stderr, "%s not found using photcodes from %s/Photcodes.dat\n", filename, input);
+    outputPhotcodes = inputPhotcodes;
+    if (!check_dir_access (output, VERBOSE)) {
+      fprintf (stderr, "error creating output database directory %s\n", output);
+      exit (1);
+    }
+    SetPhotcodeTable(inputPhotcodes);
+    if (!SavePhotcodesFITS (filename)) {
+      fprintf (stderr, "error saving photcode table in %s/Photcodes.dat\n", output);
+      exit (1);
+    }
+  }
+
+  // XXX need to determine the mapping from the input to the output images
+  dvomergeImagesGetMap (&IDmap, input, output);
+
+  // loop over the populated input regions
+  for (i = 0; i < Nlist; i++) {
+    if (VERBOSE) fprintf (stderr, "input: %s\n", list[i]);
+
+    sprintf (inputfile,  "%s/%s", input,  list[i]);
+    sprintf (outputfile, "%s/%s", output, list[i]);
+
+    SetPhotcodeTable(inputPhotcodes);
+    LoadCatalog (&incatalog, NULL, inputfile, "r");
+
+    // skip empty input catalogs
+    if (!incatalog.Naves_disk) {
+	dvo_catalog_unlock (&incatalog);
+	dvo_catalog_free (&incatalog);
+	continue;
+    }
+
+    // combine only tables at equal depth
+      
+    SkyRegion skyregion;
+    gfits_scan (&incatalog.header, "RA0",  "%f", 1, &skyregion.Rmin);
+    gfits_scan (&incatalog.header, "RA1",  "%f", 1, &skyregion.Rmax);
+    gfits_scan (&incatalog.header, "DEC0", "%f", 1, &skyregion.Dmin);
+    gfits_scan (&incatalog.header, "DEC1", "%f", 1, &skyregion.Dmax);
+
+    // load input catalog
+    SetPhotcodeTable(outputPhotcodes);
+    LoadCatalog (&outcatalog, NULL, outputfile, "w");
+
+    if (outcatalog.Naverage == 0) {
+      gfits_modify (&outcatalog.header, "RA0",  "%f", 1, skyregion.Rmin);
+      gfits_modify (&outcatalog.header, "DEC0", "%f", 1, skyregion.Dmin);
+      gfits_modify (&outcatalog.header, "RA1",  "%f", 1, skyregion.Rmax);
+      gfits_modify (&outcatalog.header, "DEC1", "%f", 1, skyregion.Dmax);
+      gfits_modify (&outcatalog.header, "CATID", "%d", 1, incatalog.catID);
+      outcatalog.catID = incatalog.catID;
+    }
+
+    dvo_update_image_IDs (&IDmap, &incatalog);
+    merge_catalogs_old (&skyregion, &outcatalog, &incatalog, RADIUS, secfiltMap);
+    
+    outcatalog.catflags = LOAD_AVES | LOAD_MEAS | LOAD_MISS | LOAD_SECF;
+
+    // if we receive a signal which would cause us to exit, wait until the full catalog is written
+    SetProtect (TRUE);
+    if (!dvo_catalog_save (&outcatalog, VERBOSE)) {
+      fprintf (stderr, "ERROR: failed to save catalog %s\n", outputfile);
+      exit (1);
+    }
+    SetProtect (FALSE);
+    
+    fprintf (stderr, "merged %s into %s\n", inputfile, outputfile);
+
+    dvo_catalog_unlock (&outcatalog);
+    dvo_catalog_free (&outcatalog);
+    
+    dvo_catalog_unlock (&incatalog);
+    dvo_catalog_free (&incatalog);
+  }
+
+  exit (0);
+}
Index: /branches/eam_branches/ipp-20101103/Ohana/src/dvomerge/src/dvorepairFixCPT.c
===================================================================
--- /branches/eam_branches/ipp-20101103/Ohana/src/dvomerge/src/dvorepairFixCPT.c	(revision 29788)
+++ /branches/eam_branches/ipp-20101103/Ohana/src/dvomerge/src/dvorepairFixCPT.c	(revision 29789)
@@ -62,4 +62,5 @@
   }
   Nfiles = i;
+  fclose(file);
   
   for (i = 0; i < Nfiles; i++) {
Index: /branches/eam_branches/ipp-20101103/Ohana/src/dvomerge/src/help.c
===================================================================
--- /branches/eam_branches/ipp-20101103/Ohana/src/dvomerge/src/help.c	(revision 29788)
+++ /branches/eam_branches/ipp-20101103/Ohana/src/dvomerge/src/help.c	(revision 29789)
@@ -5,4 +5,5 @@
   fprintf (stderr, "   OR: dvomerge (input) into (output)\n");
   fprintf (stderr, "   OR: dvomerge (input) into (output) continue\n");
+  fprintf (stderr, "   OR: dvomerge (input) into (output) from (list)\n");
   fprintf (stderr, "   [-region Rmin Rmax Dmin Dmax]\n");
   exit (2);
@@ -36,4 +37,5 @@
   fprintf (stderr, "  dvomerge (input) into (output)\n");
   fprintf (stderr, "  dvomerge (input) into (output) continue\n\n");
+  fprintf (stderr, "  dvomerge (input) into (output) from (list)\n\n");
   fprintf (stderr, "  merge DVO databases\n");
   fprintf (stderr, "  optional flags:\n");
Index: /branches/eam_branches/ipp-20101103/Ohana/src/dvomerge/src/merge_catalogs_old.c
===================================================================
--- /branches/eam_branches/ipp-20101103/Ohana/src/dvomerge/src/merge_catalogs_old.c	(revision 29788)
+++ /branches/eam_branches/ipp-20101103/Ohana/src/dvomerge/src/merge_catalogs_old.c	(revision 29789)
@@ -28,5 +28,5 @@
   unsigned int objID, catID;
   Coords tcoords;
-
+  
   // struct timeval start, stop;
   // gettimeofday (&start, (void *) NULL);
@@ -254,5 +254,5 @@
     i++;
   }
-  // MARKTIME("find matched stars: %f sec for "OFF_T_FMT","OFF_T_FMT" stars\n", dtime, Nstars, Nave);
+  // MARKTIME("find matched stars: %f sec for "OFF_T_FMT","OFF_T_FMT" stars ("OFF_T_FMT" meas)\n", dtime, Nstars, Nave, Nmeas);
 
   /** incorporate unmatched image stars, if this star is in field of this catalog **/
