Index: trunk/Ohana/src/dvosplit/src/dvosplit.c
===================================================================
--- trunk/Ohana/src/dvosplit/src/dvosplit.c	(revision 15743)
+++ trunk/Ohana/src/dvosplit/src/dvosplit.c	(revision 15746)
@@ -61,4 +61,7 @@
     // split_missings (&incatalog, outlist, outcatalogs, avelinks); 
 
+    free (avelinks[0].outref);
+    free (avelinks[0].outcat);
+
     dvo_catalog_unlock (&incatalog);
 
@@ -72,10 +75,9 @@
       outlist[0].regions[j][0].table = TRUE;
     }
-
   }
 
   // save sky table copy
   sprintf (filename, "%s/SkyTable.fits", CATDIR);
-  check_file_access (filename, FALSE, VERBOSE);
+  check_file_access (filename, TRUE, VERBOSE);
   if (!SkyTableSave (sky, filename)) {
     fprintf (stderr, "ERROR: failed to save sky table for %s\n", CATDIR);
Index: trunk/Ohana/src/dvosplit/src/split_averages.c
===================================================================
--- trunk/Ohana/src/dvosplit/src/split_averages.c	(revision 15743)
+++ trunk/Ohana/src/dvosplit/src/split_averages.c	(revision 15746)
@@ -1,4 +1,5 @@
 # include "dvosplit.h"
 # define NROWS 100000 /* ~10MB per block for measures */
+# define DNOUT 1000
 
 AveLinks *split_averages (Catalog *incatalog, SkyList *outlist, Catalog *outcatalogs) {
@@ -6,9 +7,10 @@
   double inR, inD;
   int n, block, ave, cat, averef, Nblocks, Ncat, Nout, Nsecfilt;
-  int *outref, *outcat;
+  int *outref, *outcat, *outmem;
   AveLinks *avelinks;
 
   ALLOCATE (outref, int, incatalog[0].Naves_disk);
   ALLOCATE (outcat, int, incatalog[0].Naves_disk);
+  ALLOCATE (outmem, int, outlist[0].Nregions);
 
   Nsecfilt = GetPhotcodeNsecfilt ();
@@ -17,6 +19,7 @@
   // contains primary photcodes, which will increase Nsecfilt by one.
   for (cat = 0; cat < outlist[0].Nregions; cat++) {
-    REALLOCATE (outcatalogs[cat].average, Average, NROWS);
-    REALLOCATE (outcatalogs[cat].secfilt, SecFilt, NROWS*(Nsecfilt + 1));
+    outmem[cat] = DNOUT;
+    REALLOCATE (outcatalogs[cat].average, Average, outmem[cat]);
+    REALLOCATE (outcatalogs[cat].secfilt, SecFilt, outmem[cat]*(Nsecfilt + 1));
   }
 
@@ -29,6 +32,9 @@
     // read up to NROWS at a time
     dvo_catalog_load_segment (incatalog, VERBOSE, block*NROWS, NROWS);
+    fprintf (stderr, "splitting %s (averages) .. %d of %d\n", incatalog[0].filename, block, Nblocks);
+
     assert (block*NROWS == incatalog[0].Naves_off);
 
+    // distribute data to the output catalogs
     for (ave = 0; ave < incatalog[0].Naverage; ave++) {
       averef = ave + incatalog[0].Naves_off;
@@ -67,5 +73,12 @@
 	outcatalogs[Ncat].Nsecf_mem++;
       }
+
+      if (outcatalogs[Ncat].Naverage >= outmem[Ncat]) {
+	outmem[Ncat] += DNOUT;
+	REALLOCATE (outcatalogs[Ncat].average, Average, outmem[Ncat]);
+	REALLOCATE (outcatalogs[Ncat].secfilt, SecFilt, outmem[Ncat]*(Nsecfilt + 1));
+      }
     }
+    dvo_catalog_free_data (incatalog);
 
     // double check the values of Naverage, Nsecf_mem?
@@ -75,9 +88,8 @@
       outcatalogs[cat].catflags = LOAD_AVES | LOAD_SECF;
 
-      fprintf (stderr, "secfilt: %d %d %d %d\n", outcatalogs[cat].Nsecf_mem, outcatalogs[cat].Nsecf_disk, outcatalogs[cat].Nsecf_off, outcatalogs[cat].Naverage, outcatalogs[cat].Nsecfilt);
       dvo_catalog_save (&outcatalogs[cat], VERBOSE);
-      fprintf (stderr, "secfilt: %d %d %d %d\n", outcatalogs[cat].Nsecf_mem, outcatalogs[cat].Nsecf_disk, outcatalogs[cat].Nsecf_off, outcatalogs[cat].Naverage, outcatalogs[cat].Nsecfilt);
+      // fprintf (stderr, "secfilt: %d %d %d %d\n", outcatalogs[cat].Nsecf_mem, outcatalogs[cat].Nsecf_disk, outcatalogs[cat].Nsecf_off, outcatalogs[cat].Naverage, outcatalogs[cat].Nsecfilt);
 
-      // XXX I need to advance the pointers and free the current data
+      // advance the pointers and free the current data
       // XXX these should be done within save segment:
       outcatalogs[cat].Naves_disk += outcatalogs[cat].Naverage;
@@ -92,8 +104,15 @@
   }
 
+  for (cat = 0; cat < outlist[0].Nregions; cat++) {
+    dvo_catalog_free_data (&outcatalogs[cat]);
+  }
+
+  free (outmem);
+
   ALLOCATE (avelinks, AveLinks, 1);
   avelinks[0].outref = outref;
   avelinks[0].outcat = outcat;
 
+
   return (avelinks);
 }
Index: trunk/Ohana/src/dvosplit/src/split_measures.c
===================================================================
--- trunk/Ohana/src/dvosplit/src/split_measures.c	(revision 15743)
+++ trunk/Ohana/src/dvosplit/src/split_measures.c	(revision 15746)
@@ -1,16 +1,19 @@
 # include "dvosplit.h"
 # define NROWS 100000 /* ~10MB per row for measures */
+# define DNOUT 1000
 
 int split_measures (Catalog *incatalog, SkyList *outlist, Catalog *outcatalogs, AveLinks *avelinks) {
 
   int block, meas, cat, Nblocks, Ncat, Nout, averef;
-  int *outref, *outcat;
+  int *outref, *outcat, *outmem;
 
   outref = avelinks->outref;
   outcat = avelinks->outcat;
+  ALLOCATE (outmem, int, outlist[0].Nregions);
 
   // allocate enough space for the output buffer
   for (cat = 0; cat < outlist[0].Nregions; cat++) {
-    REALLOCATE (outcatalogs[cat].measure, Measure, NROWS);
+    outmem[cat] = DNOUT;
+    REALLOCATE (outcatalogs[cat].measure, Measure, outmem[cat]);
   }
 
@@ -23,4 +26,7 @@
     // read up to NROWS at a time
     dvo_catalog_load_segment (incatalog, VERBOSE, block*NROWS, NROWS);
+    fprintf (stderr, "splitting %s (measures) .. %d of %d\n", incatalog[0].filename, block, Nblocks);
+
+    assert (block*NROWS == incatalog[0].Nmeas_off);
 
     for (meas = 0; meas < incatalog[0].Nmeasure; meas++) {
@@ -33,5 +39,11 @@
       outcatalogs[Ncat].measure[Nout].averef = outref[averef];
       outcatalogs[Ncat].Nmeasure++;
+
+      if (outcatalogs[Ncat].Nmeasure >= outmem[Ncat]) {
+	outmem[Ncat] += DNOUT;
+	REALLOCATE (outcatalogs[Ncat].measure, Measure, outmem[Ncat]);
+      }
     }
+    dvo_catalog_free_data (incatalog);
 
     for (cat = 0; cat < outlist[0].Nregions; cat++) {
@@ -45,4 +57,11 @@
     }
   }
+
+  for (cat = 0; cat < outlist[0].Nregions; cat++) {
+    dvo_catalog_free_data (&outcatalogs[cat]);
+  }
+
+  free (outmem);
+
   return (TRUE);
 }
