Index: /branches/eam_branches/ipp-20140904/Ohana/src/libdvo/src/dvo_catalog.c
===================================================================
--- /branches/eam_branches/ipp-20140904/Ohana/src/libdvo/src/dvo_catalog.c	(revision 37547)
+++ /branches/eam_branches/ipp-20140904/Ohana/src/libdvo/src/dvo_catalog.c	(revision 37548)
@@ -573,5 +573,10 @@
 
   if (catalog[0].f == (FILE *) NULL) return (2);
-  fflush (catalog[0].f);
+
+  if (fflush (catalog[0].f)) {
+    fprintf (stderr, "failed to flush file\n");
+    return FALSE;
+  }
+
   // fprintf (stderr, "unlocking: %s\n", catalog[0].filename);
 
@@ -585,13 +590,16 @@
 
   // closes f but does not set back to NULL
-  fclearlockfile (catalog[0].filename, catalog[0].f, catalog[0].lockmode, &dbstate);
+  if (!fclearlockfile (catalog[0].filename, catalog[0].f, catalog[0].lockmode, &dbstate)) {
+    fprintf (stderr, "failed to unlock or close file\n");
+    return (0);
+  }
 
   if (catalog[0].catmode == DVO_MODE_SPLIT) {
-    if (catalog[0].measure_catalog) dvo_catalog_unlock (catalog[0].measure_catalog);
-    if (catalog[0].missing_catalog) dvo_catalog_unlock (catalog[0].missing_catalog);
-    if (catalog[0].secfilt_catalog) dvo_catalog_unlock (catalog[0].secfilt_catalog);
-    if (catalog[0].lensing_catalog) dvo_catalog_unlock (catalog[0].lensing_catalog);
-    if (catalog[0].lensobj_catalog) dvo_catalog_unlock (catalog[0].lensobj_catalog);
-    if (catalog[0].starpar_catalog) dvo_catalog_unlock (catalog[0].starpar_catalog);
+    if (catalog[0].measure_catalog) { if (!dvo_catalog_unlock (catalog[0].measure_catalog)) { fprintf (stderr, "failed to unlock measures\n"); return (0); }}
+    if (catalog[0].missing_catalog) { if (!dvo_catalog_unlock (catalog[0].missing_catalog)) { fprintf (stderr, "failed to unlock missing\n"); return (0); }}
+    if (catalog[0].secfilt_catalog) { if (!dvo_catalog_unlock (catalog[0].secfilt_catalog)) { fprintf (stderr, "failed to unlock secfilt\n"); return (0); }}
+    if (catalog[0].lensing_catalog) { if (!dvo_catalog_unlock (catalog[0].lensing_catalog)) { fprintf (stderr, "failed to unlock lensing\n"); return (0); }}
+    if (catalog[0].lensobj_catalog) { if (!dvo_catalog_unlock (catalog[0].lensobj_catalog)) { fprintf (stderr, "failed to unlock lensobj\n"); return (0); }}
+    if (catalog[0].starpar_catalog) { if (!dvo_catalog_unlock (catalog[0].starpar_catalog)) { fprintf (stderr, "failed to unlock starpar\n"); return (0); }}
   }
   return (1);
Index: /branches/eam_branches/ipp-20140904/Ohana/src/libdvo/src/dvo_catalog_split.c
===================================================================
--- /branches/eam_branches/ipp-20140904/Ohana/src/libdvo/src/dvo_catalog_split.c	(revision 37547)
+++ /branches/eam_branches/ipp-20140904/Ohana/src/libdvo/src/dvo_catalog_split.c	(revision 37548)
@@ -75,6 +75,61 @@
   Matrix matrix;
 
+  // ohana_memcheck_func (TRUE);
+
+  if (0) {
+    // XXX a TEST : is the data corrupted or the file?
+    char name[1024];
+    snprintf (name, 1024, "%s.phu.v2", catalog->filename);
+    FILE *f = fopen (name, "w");
+    fwrite (catalog->header.buffer, sizeof(char), catalog->header.datasize, f);
+    // fprintf (stderr, "save %d bytes in %s (%zx)\n", (int) catalog->header.datasize, name, (size_t) catalog->header.buffer);
+    // fprintf (stderr, "first bytes are %c%c%c%c%c%c%c%c\n", 
+    // 	     catalog->header.buffer[0], catalog->header.buffer[1], catalog->header.buffer[2], catalog->header.buffer[3], 
+    // 	     catalog->header.buffer[4], catalog->header.buffer[5], catalog->header.buffer[6], catalog->header.buffer[7]);
+    fclose (f);
+  }
+  if (0) {
+    // XXX a TEST : is the data corrupted or the file?
+    char name[1024];
+    snprintf (name, 1024, "%s.phu", catalog->filename);
+    FILE *f = fopen (name, "w");
+    fwrite (catalog->header.buffer, sizeof(char), catalog->header.datasize, f);
+    // fprintf (stderr, "save %d bytes in %s (%zx)\n", (int) catalog->header.datasize, name, (size_t) catalog->header.buffer);
+    // fprintf (stderr, "first bytes are %c%c%c%c%c%c%c%c\n", 
+    // 	     catalog->header.buffer[0], catalog->header.buffer[1], catalog->header.buffer[2], catalog->header.buffer[3], 
+    // 	     catalog->header.buffer[4], catalog->header.buffer[5], catalog->header.buffer[6], catalog->header.buffer[7]);
+    fclose (f);
+  }
+# if (0)
+  {
+    // XXX a TEST : is the data corrupted or the file?
+    char name[1024];
+    snprintf (name, 1024, "%s.phu.v2", catalog->filename);
+    FILE *f = fopen (name, "w");
+    fwrite (catalog->header.buffer, sizeof(char), catalog->header.datasize, f);
+    fprintf (stderr, "save %d bytes in %s (%zx)\n", (int) catalog->header.datasize, name, (size_t) catalog->header.buffer);
+    fprintf (stderr, "first bytes are %c%c%c%c%c%c%c%c\n", 
+	     catalog->header.buffer[0], catalog->header.buffer[1], catalog->header.buffer[2], catalog->header.buffer[3], 
+	     catalog->header.buffer[4], catalog->header.buffer[5], catalog->header.buffer[6], catalog->header.buffer[7]);
+    fclose (f);
+  }
+  {
+    // XXX a TEST : is the data corrupted or the file?
+    char name[1024];
+    snprintf (name, 1024, "%s.phu.v3", catalog->filename);
+    FILE *f = fopen (name, "w");
+    fwrite (catalog->header.buffer, sizeof(char), catalog->header.datasize, f);
+    fprintf (stderr, "save %d bytes in %s (%zx)\n", (int) catalog->header.datasize, name, (size_t) catalog->header.buffer);
+    fprintf (stderr, "first bytes are %c%c%c%c%c%c%c%c\n", 
+	     catalog->header.buffer[0], catalog->header.buffer[1], catalog->header.buffer[2], catalog->header.buffer[3], 
+	     catalog->header.buffer[4], catalog->header.buffer[5], catalog->header.buffer[6], catalog->header.buffer[7]);
+    fclose (f);
+  }
+# endif
   /* rewind file pointers and truncate (file is still open) */
-  fseeko (catalog->f, 0LL, SEEK_SET);
+  if (fseeko (catalog->f, 0LL, SEEK_SET)) {
+    perror ("dvo_catalog_save_subset: ");
+    fprintf (stderr, "failed to seek to beginning\n");
+  }
 
   // write PHU header
@@ -353,4 +408,5 @@
   /*** Secfilt Table ***/
   status = dvo_catalog_open_subcat (catalog, &catalog[0].secfilt_catalog, ftable.header, "SECFILT", VERBOSE);
+  // fprintf (stderr, "secfilt header %s : %zx\n", catalog[0].secfilt_catalog[0].filename, (size_t) catalog[0].secfilt_catalog[0].header.buffer);
   if (status == DVO_CAT_OPEN_FAIL) {
     return (FALSE);
