Index: /trunk/Ohana/src/dvomerge/src/ConfigInit.c
===================================================================
--- /trunk/Ohana/src/dvomerge/src/ConfigInit.c	(revision 24749)
+++ /trunk/Ohana/src/dvomerge/src/ConfigInit.c	(revision 24750)
@@ -36,9 +36,7 @@
   SetZeroPoint (ZERO_POINT);
 
-  /* XXX this does not yet write out the master photcode table */
-  sprintf (CatdirPhotcodeFile, "%s/Photcodes.dat", CATDIR);
-  if (!LoadPhotcodes (CatdirPhotcodeFile, MasterPhotcodeFile)) {
-    fprintf (stderr, "error loading photcode table %s or master file %s\n", CatdirPhotcodeFile, MasterPhotcodeFile);
-    exit (1);
+  if (RADIUS < 1e-6) {
+      fprintf (stderr, "non-sensical correlation radius %f\n", RADIUS);
+      exit (1);
   }
 
Index: /trunk/Ohana/src/dvomerge/src/dvomerge.c
===================================================================
--- /trunk/Ohana/src/dvomerge/src/dvomerge.c	(revision 24749)
+++ /trunk/Ohana/src/dvomerge/src/dvomerge.c	(revision 24750)
@@ -21,4 +21,21 @@
   input2 = argv[3];
   output = argv[5];
+
+  // the first input define the photcode table & db layout
+  sprintf (filename, "%s/Photcodes.dat", input1);
+  if (!LoadPhotcodes (filename, NULL)) {
+    fprintf (stderr, "error loading photcode table %s\n", filename);
+    exit (1);
+  }
+  // save the photcodes in the output catdir
+  sprintf (filename, "%s/Photcodes.dat", output);
+  if (!check_file_access (filename, TRUE, TRUE)) {
+    fprintf (stderr, "error creating output catdir %s\n", output);
+    exit (1);
+  }
+  if (!SavePhotcodesFITS (filename)) {
+    fprintf (stderr, "error saving photcode table %s\n", filename);
+    exit (1);
+  }
 
   // load the sky table for the existing database
@@ -86,8 +103,10 @@
 	continue;
       }
-      merge_catalogs_old (&outsky[0].regions[i], &outcatalog, &incatalog, 1.0);
+      merge_catalogs_old (&outsky[0].regions[i], &outcatalog, &incatalog, RADIUS);
       dvo_catalog_unlock (&incatalog);
       dvo_catalog_free (&incatalog);
     }
+    SkyListFree (inlist);
+
     outcatalog.catflags = LOAD_AVES | LOAD_MEAS | LOAD_MISS | LOAD_SECF;
     dvo_catalog_save (&outcatalog, VERBOSE);
Index: /trunk/Ohana/src/dvomerge/src/merge_catalogs_old.c
===================================================================
--- /trunk/Ohana/src/dvomerge/src/merge_catalogs_old.c	(revision 24749)
+++ /trunk/Ohana/src/dvomerge/src/merge_catalogs_old.c	(revision 24750)
@@ -150,4 +150,7 @@
 
     /*** a match is found, add to average, measure ***/
+    Nmatch ++;
+    n = N2[Jmin];
+    N = N1[i];
 
     /* make sure there is space for next Nmeasure entries */
@@ -158,8 +161,4 @@
     }
 
-    Nmatch ++;
-    n = N2[Jmin];
-    N = N1[i];
-
     /** add measurements for this input average object **/
     for (Nin = 0; Nin < input[0].average[N].Nmeasure; Nin ++) {
@@ -173,9 +172,9 @@
 
       Rin = input[0].average[N].R - input[0].measure[offset].dR / 3600.0;
-      Din = input[0].average[N].R - input[0].measure[offset].dR / 3600.0;
+      Din = input[0].average[N].D - input[0].measure[offset].dD / 3600.0;
 
       /** dR,dD now represent arcsec **/
       output[0].measure[Nmeas].dR       = 3600.0*(output[0].average[n].R - Rin);  // XXX update these based on choice of astromety
-      output[0].measure[Nmeas].dD       = 3600.0*(output[0].average[n].D - Rin);  // XXX update these based on choice of astromety
+      output[0].measure[Nmeas].dD       = 3600.0*(output[0].average[n].D - Din);  // XXX update these based on choice of astromety
       output[0].measure[Nmeas].dbFlags  = 0;
       output[0].measure[Nmeas].averef   = n;
@@ -319,12 +318,14 @@
   if (VERBOSE) fprintf (stderr, "Nstars, Nave, Nmeas: %d %d %d, (%d matches)\n", Nstars, Nave, Nmeas, Nmatch);
 
+  free (next_meas);
+
+  free (output[0].found);
+  free (X2);
+  free (Y2);
+  free (N2);
   free (input[0].found);
-  free (output[0].found);
   free (X1);
   free (Y1);
   free (N1);
-  free (X2);
-  free (Y2);
-  free (N2);
   return (Nmatch);
 }
