Index: trunk/Ohana/src/dvomerge/include/dvomerge.h
===================================================================
--- trunk/Ohana/src/dvomerge/include/dvomerge.h	(revision 39333)
+++ trunk/Ohana/src/dvomerge/include/dvomerge.h	(revision 39334)
@@ -57,4 +57,9 @@
 int    RESET_STARPAR;
 
+int    SKIP_MEASURE;
+int    SKIP_LENSING;
+int    SKIP_STARPAR;
+int    SKIP_GALPHOT;
+
 int    REPAIR_BY_OBJID;
 
Index: trunk/Ohana/src/dvomerge/src/LoadCatalog.c
===================================================================
--- trunk/Ohana/src/dvomerge/src/LoadCatalog.c	(revision 39333)
+++ trunk/Ohana/src/dvomerge/src/LoadCatalog.c	(revision 39334)
@@ -1,5 +1,3 @@
 # include "dvomerge.h"
-# define SKIP_GALPHOT 0
-# define SKIP_STARPAR 0
 
 int LoadCatalog (Catalog *catalog, SkyRegion *region, char *filename, char *mode, int Nsecfilt) {
@@ -13,17 +11,30 @@
   // XXXX TEMP HACK : skip GALPHOT
 
-  catalog[0].catflags = DVO_LOAD_AVERAGE | DVO_LOAD_MEASURE | DVO_LOAD_MISSING | DVO_LOAD_SECFILT | DVO_LOAD_LENSING | DVO_LOAD_LENSOBJ;
-# if (SKIP_GALPHOT)  
-  catalog[0].catflags = catalog[0].catflags | DVO_SKIP_GALPHOT;
-# else
-  catalog[0].catflags = catalog[0].catflags | DVO_LOAD_GALPHOT;
-# endif
+  catalog[0].catflags = DVO_LOAD_AVERAGE | DVO_LOAD_MISSING | DVO_LOAD_SECFILT | DVO_LOAD_LENSOBJ;
 
-# if (SKIP_STARPAR)  
-  catalog[0].catflags = catalog[0].catflags | DVO_SKIP_STARPAR;
-# else
-  catalog[0].catflags = catalog[0].catflags | DVO_LOAD_STARPAR;
-# endif
+  if (SKIP_MEASURE) {
+    catalog[0].catflags = catalog[0].catflags | DVO_SKIP_MEASURE;
+  } else {
+    catalog[0].catflags = catalog[0].catflags | DVO_LOAD_MEASURE;
+  }
+
+  if (SKIP_LENSING)  {
+    catalog[0].catflags = catalog[0].catflags | DVO_SKIP_LENSING;
+  } else {
+    catalog[0].catflags = catalog[0].catflags | DVO_LOAD_LENSING;
+  }
+
+  if (SKIP_STARPAR) {
+    catalog[0].catflags = catalog[0].catflags | DVO_SKIP_STARPAR;
+  } else {
+    catalog[0].catflags = catalog[0].catflags | DVO_LOAD_STARPAR;
+  }
   
+  if (SKIP_GALPHOT)  {
+    catalog[0].catflags = catalog[0].catflags | DVO_SKIP_GALPHOT;
+  } else {
+    catalog[0].catflags = catalog[0].catflags | DVO_LOAD_GALPHOT;
+  }
+
   catalog[0].catformat = dvo_catalog_catformat (CATFORMAT);  // set the default catformat from config data
   catalog[0].catmode   = dvo_catalog_catmode (CATMODE);      // set the default catmode from config data
Index: trunk/Ohana/src/dvomerge/src/args.c
===================================================================
--- trunk/Ohana/src/dvomerge/src/args.c	(revision 39333)
+++ trunk/Ohana/src/dvomerge/src/args.c	(revision 39334)
@@ -44,4 +44,26 @@
   if ((N = get_argument (*argc, argv, "-matched-tables"))) {
     MATCHED_TABLES = TRUE;
+    remove_argument (N, argc, argv);
+  }
+
+  /** allow only certain tables to be merged **/ 
+  SKIP_MEASURE = FALSE;
+  if ((N = get_argument (*argc, argv, "-skip-measure"))) {
+    SKIP_MEASURE = TRUE;
+    remove_argument (N, argc, argv);
+  }
+  SKIP_LENSING = FALSE;
+  if ((N = get_argument (*argc, argv, "-skip-lensing"))) {
+    SKIP_LENSING = TRUE;
+    remove_argument (N, argc, argv);
+  }
+  SKIP_STARPAR = FALSE;
+  if ((N = get_argument (*argc, argv, "-skip-starpar"))) {
+    SKIP_STARPAR = TRUE;
+    remove_argument (N, argc, argv);
+  }
+  SKIP_GALPHOT = FALSE;
+  if ((N = get_argument (*argc, argv, "-skip-galphot"))) {
+    SKIP_GALPHOT = TRUE;
     remove_argument (N, argc, argv);
   }
@@ -284,4 +306,26 @@
   }
 
+  /** allow only certain tables to be merged **/ 
+  SKIP_MEASURE = FALSE;
+  if ((N = get_argument (*argc, argv, "-skip-measure"))) {
+    SKIP_MEASURE = TRUE;
+    remove_argument (N, argc, argv);
+  }
+  SKIP_LENSING = FALSE;
+  if ((N = get_argument (*argc, argv, "-skip-lensing"))) {
+    SKIP_LENSING = TRUE;
+    remove_argument (N, argc, argv);
+  }
+  SKIP_STARPAR = FALSE;
+  if ((N = get_argument (*argc, argv, "-skip-starpar"))) {
+    SKIP_STARPAR = TRUE;
+    remove_argument (N, argc, argv);
+  }
+  SKIP_GALPHOT = FALSE;
+  if ((N = get_argument (*argc, argv, "-skip-galphot"))) {
+    SKIP_GALPHOT = TRUE;
+    remove_argument (N, argc, argv);
+  }
+
   /* extra error messages */
   RESET_STARPAR = FALSE;
Index: trunk/Ohana/src/dvomerge/src/build_links.c
===================================================================
--- trunk/Ohana/src/dvomerge/src/build_links.c	(revision 39333)
+++ trunk/Ohana/src/dvomerge/src/build_links.c	(revision 39334)
@@ -32,4 +32,7 @@
   off_t i, j, N;
   off_t *next_meas;
+
+  if (!measure) return NULL;
+  if (SKIP_MEASURE) return NULL;
 
   N = 0;
@@ -252,4 +255,7 @@
   off_t *next_lens;
 
+  if (!lensing) return NULL;
+  if (SKIP_LENSING) return NULL;
+
   N = 0;
 
@@ -521,4 +527,5 @@
 
   if (!starpar) return NULL;
+  if (SKIP_STARPAR) return NULL;
 
   /* fix order of StarPar (memory intensive, but fast) */
Index: trunk/Ohana/src/dvomerge/src/dvomergeUpdate_catalogs.c
===================================================================
--- trunk/Ohana/src/dvomerge/src/dvomergeUpdate_catalogs.c	(revision 39333)
+++ trunk/Ohana/src/dvomerge/src/dvomergeUpdate_catalogs.c	(revision 39334)
@@ -323,4 +323,10 @@
     if (MATCHED_TABLES)             { strextend (&command, "-matched-tables"); }
     if (MATCH_BY_EXTERN_ID)         { strextend (&command, "-match-by-extern-id"); }
+
+    if (SKIP_MEASURE)               { strextend (&command, "-skip-measure"); }
+    if (SKIP_LENSING)               { strextend (&command, "-skip-lensing"); }
+    if (SKIP_GALPHOT)               { strextend (&command, "-skip-galphot"); }
+    if (SKIP_STARPAR)               { strextend (&command, "-skip-starpar"); }
+
     if (RESET_STARPAR)              { strextend (&command, "-reset-starpar"); }
     if (ALLOW_MISSING_INPUT_IMAGES) { strextend (&command, "-allow-missing-input-images"); }
Index: trunk/Ohana/src/dvomerge/src/merge_catalogs_old.c
===================================================================
--- trunk/Ohana/src/dvomerge/src/merge_catalogs_old.c	(revision 39333)
+++ trunk/Ohana/src/dvomerge/src/merge_catalogs_old.c	(revision 39334)
@@ -113,5 +113,5 @@
 
   /* set up pointers for linked list of measure */
-  if (output[0].sorted && (output[0].Nmeasure >= output[0].Nmeasure_disk)) {
+  if (output[0].sorted) {
     // this version is only valid if we have done a full catalog load, and if the catalog
     // is sorted while processed
@@ -206,78 +206,82 @@
     // 4) average properties from the input and the output db need to be properly merged.
 
-    int Nreplace = 0;
-    if (REPLACE_TYCHO) {
-      int Minp =  input[0].average[N].measureOffset;
-      Nreplace = replace_tycho (&output[0].average[n], output[0].measure, next_meas, &input[0].average[N], &input[0].measure[Minp]);
-      if (Nreplace == 6) {
-	output[0].found_t[n] = Nmeas;
-	i++;
-	continue;
-      }
-    }
-
     /** add ALL measurements for this input average object **/
-    for (Nin = Nreplace; Nin < input[0].average[N].Nmeasure; Nin ++) {
-      offset = input[0].average[N].measureOffset + Nin;
-
-      if (REPLACE_BY_PHOTCODE) {
-	// index to first measure for this object
-	// XXX this does not support lensing, starpar, or galphot measurements
-	if (replace_match (&output[0].average[n], output[0].measure, next_meas, &input[0].average[N], &input[0].measure[offset])) {
+    if (output[0].measure && !SKIP_MEASURE) {
+
+      int Nreplace = 0;
+      if (REPLACE_TYCHO) {
+	int Minp =  input[0].average[N].measureOffset;
+	Nreplace = replace_tycho (&output[0].average[n], output[0].measure, next_meas, &input[0].average[N], &input[0].measure[Minp]);
+	if (Nreplace == 6) {
+	  output[0].found_t[n] = Nmeas;
+	  i++;
 	  continue;
+	  // XXX this is probably a bad idea: breaks other tables
 	}
       }
-      /* add to end of measurement list */
-      add_meas_link (&output[0].average[n], next_meas, Nmeas, NMEAS);
+
+      for (Nin = Nreplace; Nin < input[0].average[N].Nmeasure; Nin ++) {
+	offset = input[0].average[N].measureOffset + Nin;
+
+	if (REPLACE_BY_PHOTCODE) {
+	  // index to first measure for this object
+	  // XXX this does not support lensing, starpar, or galphot measurements
+	  if (replace_match (&output[0].average[n], output[0].measure, next_meas, &input[0].average[N], &input[0].measure[offset])) {
+	    continue;
+	  }
+	}
+	/* add to end of measurement list */
+	add_meas_link (&output[0].average[n], next_meas, Nmeas, NMEAS);
 	
-      // set the new measurements
-      output[0].measure[Nmeas] = input[0].measure[offset];
-
-      // old code: find R,D using average_in[0], the get offset relative to average_out[0].  no longer
-      // needed since we carry around R,D
-      // Rin = 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;
-      // output[0].measure[Nmeas].dR = 3600.0*(output[0].average[n].R - Rin);
-      // output[0].measure[Nmeas].dD = 3600.0*(output[0].average[n].D - Din);
-
-      output[0].measure[Nmeas].dbFlags  = 0;  // XXX why reset these?
-      output[0].measure[Nmeas].averef   = n;
-      output[0].measure[Nmeas].objID    = output[0].average[n].objID;
-      output[0].measure[Nmeas].catID    = output[0].catID;
-
-      assert (output[0].measure[Nmeas].averef < Nave);
-
-      // fprintf (stderr, "Nave : "OFF_T_FMT", Nmeas : "OFF_T_FMT", dR: %f, dD: %f, catID: %d\n",  n,  Nmeas, output[0].measure[Nmeas].dR, output[0].measure[Nmeas].dD, output[0].measure[i].catID);
-
-      float dRoff = dvoOffsetR(&output[0].measure[Nmeas], &output[0].average[n]);
-
-      // rationalize R
-      if (dRoff > +180.0*3600.0) {
-	// average on high end of boundary, move star up
-	output[0].measure[Nmeas].R += 360.0;
-	dRoff -= 360.0*3600.0;
-      }
-      if (dRoff < -180.0*3600.0) {
-	// average on low end of boundary, move star down
-	output[0].measure[Nmeas].R -= 360.0;
-	dRoff += 360.0*3600.0;
-      }
-      if (fabs(dRoff) > 10*RADIUS) {
-        // take declination into account and check again.
-        double cosD = cos(RAD_DEG*output[0].average[n].D);
-        if (fabs(dRoff*cosD) > 10*RADIUS) {
-	  fprintf (stderr, "error: %10.6f,%10.6f vs %10.6f,%10.6f (%f,%f vs %f,%f)\n", 
-		   output[0].average[n].R, output[0].average[n].D, 
-		   output[0].measure[Nmeas].R, output[0].measure[Nmeas].D,
-		   X1[i], X2[Jmin], Y1[i], Y2[Jmin]);
-	  // XXX abort on this? -- this is a bad failure...
-        }
-      }
-      output[0].average[n].Nmeasure ++;
-      Nmeas ++;
+	// set the new measurements
+	output[0].measure[Nmeas] = input[0].measure[offset];
+
+	// old code: find R,D using average_in[0], the get offset relative to average_out[0].  no longer
+	// needed since we carry around R,D
+	// Rin = 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;
+	// output[0].measure[Nmeas].dR = 3600.0*(output[0].average[n].R - Rin);
+	// output[0].measure[Nmeas].dD = 3600.0*(output[0].average[n].D - Din);
+
+	output[0].measure[Nmeas].dbFlags  = 0;  // XXX why reset these?
+	output[0].measure[Nmeas].averef   = n;
+	output[0].measure[Nmeas].objID    = output[0].average[n].objID;
+	output[0].measure[Nmeas].catID    = output[0].catID;
+
+	assert (output[0].measure[Nmeas].averef < Nave);
+
+	// fprintf (stderr, "Nave : "OFF_T_FMT", Nmeas : "OFF_T_FMT", dR: %f, dD: %f, catID: %d\n",  n,  Nmeas, output[0].measure[Nmeas].dR, output[0].measure[Nmeas].dD, output[0].measure[i].catID);
+
+	float dRoff = dvoOffsetR(&output[0].measure[Nmeas], &output[0].average[n]);
+
+	// rationalize R
+	if (dRoff > +180.0*3600.0) {
+	  // average on high end of boundary, move star up
+	  output[0].measure[Nmeas].R += 360.0;
+	  dRoff -= 360.0*3600.0;
+	}
+	if (dRoff < -180.0*3600.0) {
+	  // average on low end of boundary, move star down
+	  output[0].measure[Nmeas].R -= 360.0;
+	  dRoff += 360.0*3600.0;
+	}
+	if (fabs(dRoff) > 10*RADIUS) {
+	  // take declination into account and check again.
+	  double cosD = cos(RAD_DEG*output[0].average[n].D);
+	  if (fabs(dRoff*cosD) > 10*RADIUS) {
+	    fprintf (stderr, "error: %10.6f,%10.6f vs %10.6f,%10.6f (%f,%f vs %f,%f)\n", 
+		     output[0].average[n].R, output[0].average[n].D, 
+		     output[0].measure[Nmeas].R, output[0].measure[Nmeas].D,
+		     X1[i], X2[Jmin], Y1[i], Y2[Jmin]);
+	    // XXX abort on this? -- this is a bad failure...
+	  }
+	}
+	output[0].average[n].Nmeasure ++;
+	Nmeas ++;
+      }
     }
 
     // if lensing measurements exist, add them too
-    if (output[0].lensing) {
+    if (output[0].lensing && !SKIP_LENSING) {
       for (Nin = 0; Nin < input[0].average[N].Nlensing; Nin++) {
 	/* add to end of lensing list */
@@ -297,5 +301,5 @@
 
     // if lensing measurements exist, add them too
-    if (output[0].starpar) {
+    if (output[0].starpar && !SKIP_STARPAR) {
       for (Nin = 0; Nin < input[0].average[N].Nstarpar; Nin++) {
 	/* add to end of lensing list */
@@ -315,5 +319,5 @@
 
     // if galphot measurements exist, add them too
-    if (output[0].galphot) {
+    if (output[0].galphot && !SKIP_GALPHOT) {
       for (Nin = 0; Nin < input[0].average[N].Ngalphot; Nin++) {
 	/* add to end of galphot list */
@@ -405,5 +409,4 @@
     output[0].average[Nave].R         	   = input[0].average[N].R;
     output[0].average[Nave].D         	   = input[0].average[N].D;
-    output[0].average[Nave].measureOffset  = Nmeas;
     output[0].average[Nave].objID     	   = objID; // we create objID values in the context of the output db
     output[0].average[Nave].catID     	   = catID; // we create catID values in the context of the output db
@@ -435,30 +438,33 @@
 
     /** add measurements for this input average object **/
-    for (Nin = 0; Nin < input[0].average[N].Nmeasure; Nin ++) {
-      offset = input[0].average[N].measureOffset + Nin;
-
-      // supply the measurments from this detection
-      output[0].measure[Nmeas]           = input[0].measure[offset];
-
-      // the following measure elements cannot be set until here:
-      output[0].measure[Nmeas].dbFlags  = 0;
-      output[0].measure[Nmeas].averef   = Nave;
-      output[0].measure[Nmeas].objID    = output[0].average[Nave].objID;
-      output[0].measure[Nmeas].catID    = output[0].catID;
-
-      // as we add measurements, update Nmeasure to match
-      output[0].average[Nave].Nmeasure ++;
-
-      /* we set next[Nmeas] to -1 here, and update correctly below */
-      next_meas[Nmeas] = -1;
-      Nmeas ++;
-    }
-    int Ngroup = input[0].average[N].Nmeasure;
-    for (j = 0; j < Ngroup - 1; j++) {
-      next_meas[Nmeas - Ngroup + j] = Nmeas - Ngroup + j + 1;
+    if (output[0].measure && !SKIP_MEASURE && input[0].average[N].Nmeasure) {
+      output[0].average[Nave].measureOffset  = Nmeas;
+      for (Nin = 0; Nin < input[0].average[N].Nmeasure; Nin ++) {
+	offset = input[0].average[N].measureOffset + Nin;
+	
+	// supply the measurments from this detection
+	output[0].measure[Nmeas]           = input[0].measure[offset];
+	
+	// the following measure elements cannot be set until here:
+	output[0].measure[Nmeas].dbFlags  = 0;
+	output[0].measure[Nmeas].averef   = Nave;
+	output[0].measure[Nmeas].objID    = output[0].average[Nave].objID;
+	output[0].measure[Nmeas].catID    = output[0].catID;
+	
+	// as we add measurements, update Nmeasure to match
+	output[0].average[Nave].Nmeasure ++;
+
+	/* we set next[Nmeas] to -1 here, and update correctly below */
+	next_meas[Nmeas] = -1;
+	Nmeas ++;
+      }
+      int Ngroup = input[0].average[N].Nmeasure;
+      for (j = 0; j < Ngroup - 1; j++) {
+	next_meas[Nmeas - Ngroup + j] = Nmeas - Ngroup + j + 1;
+      }
     }
 
     /** add lensing for this input average object **/
-    if (output[0].lensing) {
+    if (output[0].lensing && !SKIP_LENSING && input[0].average[N].Nlensing) {
       output[0].average[Nave].lensingOffset  = Nlens;
       for (Nin = 0; Nin < input[0].average[N].Nlensing; Nin ++) {
@@ -486,5 +492,5 @@
 
     /** add starpar for this input average object **/
-    if (output[0].starpar) {
+    if (output[0].starpar && !SKIP_STARPAR && input[0].average[N].Nstarpar) {
       output[0].average[Nave].starparOffset  = Nstar;
       for (Nin = 0; Nin < input[0].average[N].Nstarpar; Nin ++) {
@@ -512,5 +518,5 @@
 
     /** add galphot for this input average object **/
-    if (output[0].galphot) {
+    if (output[0].galphot && !SKIP_GALPHOT && input[0].average[N].Ngalphot) {
       output[0].average[Nave].galphotOffset  = Ngalp;
       for (Nin = 0; Nin < input[0].average[N].Ngalphot; Nin ++) {
@@ -543,8 +549,8 @@
 
   REALLOCATE (output[0].average, Average, Nave);
-  REALLOCATE (output[0].measure, Measure, Nmeas);
-  REALLOCATE (output[0].lensing, Lensing, Nlens);
-  REALLOCATE (output[0].starpar, StarPar, Nstar);
-  REALLOCATE (output[0].galphot, GalPhot, Ngalp);
+  if (!SKIP_MEASURE) { REALLOCATE (output[0].measure, Measure, Nmeas); }
+  if (!SKIP_LENSING) { REALLOCATE (output[0].lensing, Lensing, Nlens); }
+  if (!SKIP_STARPAR) { REALLOCATE (output[0].starpar, StarPar, Nstar); }
+  if (!SKIP_GALPHOT) { REALLOCATE (output[0].galphot, GalPhot, Ngalp); }
  
 # define NOSORT 0
@@ -553,8 +559,8 @@
   } else {
     output[0].sorted = TRUE;
-    output[0].measure = sort_measure (output[0].average, Nave, output[0].measure, Nmeas, next_meas);
-    output[0].lensing = sort_lensing (output[0].average, Nave, output[0].lensing, Nlens, next_lens);
-    output[0].starpar = sort_starpar (output[0].average, Nave, output[0].starpar, Nstar, next_star);
-    output[0].galphot = sort_galphot (output[0].average, Nave, output[0].galphot, Ngalp, next_galp);
+    if (!SKIP_MEASURE) { output[0].measure = sort_measure (output[0].average, Nave, output[0].measure, Nmeas, next_meas); }
+    if (!SKIP_LENSING) { output[0].lensing = sort_lensing (output[0].average, Nave, output[0].lensing, Nlens, next_lens); }
+    if (!SKIP_STARPAR) { output[0].starpar = sort_starpar (output[0].average, Nave, output[0].starpar, Nstar, next_star); }
+    if (!SKIP_GALPHOT) { output[0].galphot = sort_galphot (output[0].average, Nave, output[0].galphot, Ngalp, next_galp); }
   }
 
@@ -562,8 +568,8 @@
   output[0].objID    = objID; // new max value, save on catalog close
   output[0].Naverage = Nave;
-  output[0].Nmeasure = Nmeas;
-  output[0].Nlensing = Nlens;
-  output[0].Nstarpar = Nstar;
-  output[0].Ngalphot = Ngalp;
+  if (!SKIP_MEASURE) { output[0].Nmeasure = Nmeas; }
+  if (!SKIP_LENSING) { output[0].Nlensing = Nlens; }
+  if (!SKIP_STARPAR) { output[0].Nstarpar = Nstar; }
+  if (!SKIP_GALPHOT) { output[0].Ngalphot = Ngalp; }
   output[0].Nsecfilt_mem = Nave*NsecfiltOut;
   if (VERBOSE) fprintf (stderr, "Nstars, Nave, Nmeas, Nlens, Ngalp: "OFF_T_FMT" "OFF_T_FMT" "OFF_T_FMT" "OFF_T_FMT" "OFF_T_FMT", ("OFF_T_FMT" matches)\n",  Nstars,  Nave,  Nmeas,  Nlens, Ngalp, Nmatch);
