Index: /branches/eam_branches/ipp-20150616/Ohana/src/libdvo/src/dvo_catalog_split.c
===================================================================
--- /branches/eam_branches/ipp-20150616/Ohana/src/libdvo/src/dvo_catalog_split.c	(revision 38493)
+++ /branches/eam_branches/ipp-20150616/Ohana/src/libdvo/src/dvo_catalog_split.c	(revision 38494)
@@ -1,4 +1,4 @@
 # include <dvo.h>
-# define OHANA_MEMCHECK 0
+# define OHANA_MEMCHECK 1
 
 // return options: 
@@ -92,5 +92,5 @@
   Matrix matrix;
   
-  if (OHANA_MEMCHECK) ohana_memcheck_func (TRUE);
+  // if (OHANA_MEMCHECK) ohana_memcheck (TRUE);
   
   /* rewind file pointers and truncate (file is still open) */
@@ -128,5 +128,5 @@
   int isCompressed = output_is_compressed (start, Nrows, Ntotal, catalog->catcompress);
 
-  if (OHANA_MEMCHECK) ohana_memcheck_func (TRUE);
+  // if (OHANA_MEMCHECK) ohana_memcheck (TRUE);
 
   if (isCompressed) {
@@ -149,5 +149,5 @@
   }
 
-  if (OHANA_MEMCHECK) ohana_memcheck_func (TRUE);
+  // if (OHANA_MEMCHECK) ohana_memcheck (TRUE);
 
   // write the table data
@@ -169,5 +169,31 @@
   fullsize += outtable->datasize + outtable->header->datasize;
 
-  if (OHANA_MEMCHECK) ohana_memcheck_func (TRUE);
+  // XXX test of repeated failure
+  {
+    Matrix myMatrix;
+
+    // write the PHU matrix; this is probably a NOP, do I have to keep it in?
+    gfits_create_matrix (&catalog->header, &myMatrix);
+
+    int niter;
+    for (niter = 0; niter < 5; niter ++) {
+      char name[1024];
+      snprintf (name, 1024, "%s.v.%d", catalog->filename, niter);
+      FILE *f = fopen (name, "w");
+
+      myAssert (gfits_fwrite_header  (f, &catalog->header), "failed to write header");
+      myAssert (gfits_fwrite_matrix  (f, &myMatrix), "failed to write matrix");
+      myAssert (gfits_fwrite_Theader (f, outtable->header), "can't write table header");
+      myAssert (gfits_fwrite_table (f, outtable), "can't write table data");
+      myAssert (!fflush (f), "failed to flush");
+      myAssert (!fclose (f), "failed to close");
+      int fd = fileno(f);
+      myAssert (fsync(fd), "failed to sync");
+      fprintf (stderr, "wrote to %s\n", name);
+    }
+    gfits_free_matrix (&myMatrix);
+  }
+
+  // if (OHANA_MEMCHECK) ohana_memcheck (TRUE);
 
   // since we init'ed the structures above, these operations are safe whether or not we compressed the table
