Index: /branches/eam_branches/ipp-20110213/Ohana/src/dvomerge/src/dvoverify.c
===================================================================
--- /branches/eam_branches/ipp-20110213/Ohana/src/dvomerge/src/dvoverify.c	(revision 31064)
+++ /branches/eam_branches/ipp-20110213/Ohana/src/dvomerge/src/dvoverify.c	(revision 31065)
@@ -13,5 +13,6 @@
 # define DEBUG 0
 
-int VERBOSE;
+int VERBOSE = FALSE;
+int NNotSorted = 0;
 
 int main (int argc, char **argv) {
@@ -26,7 +27,20 @@
   // Catalog catalog;
 
-  VERBOSE = FALSE;
+  int CHECKSORTED;
+
   if ((N = get_argument (argc, argv, "-v"))) {
     VERBOSE = TRUE;
+    remove_argument (N, &argc, argv);
+  }
+  if ((N = get_argument (argc, argv, "-verbose"))) {
+    VERBOSE = TRUE;
+    remove_argument (N, &argc, argv);
+  }
+  if ((N = get_argument (argc, argv, "-s"))) {
+    CHECKSORTED = TRUE;
+    remove_argument (N, &argc, argv);
+  }
+  if ((N = get_argument (argc, argv, "-sorted"))) {
+    CHECKSORTED = TRUE;
     remove_argument (N, &argc, argv);
   }
@@ -50,6 +64,8 @@
 
   if (argc != 2) {
-    fprintf (stderr, "USAGE: dvoverify (catdir) [-region Rmin Rmax Dmin Dmax]\n");
-    fprintf (stderr, "  catdir : database of interest\n");
+    fprintf (stderr, "USAGE: dvoverify (catdir) [-region Rmin Rmax Dmin Dmax] [-v] [-s]\n\n");
+    fprintf (stderr, "  -v : VERBOSE\n");
+    fprintf (stderr, "  -s : checks if sorted, return error if not\n");
+    fprintf (stderr, "  (catdir) : database of interest\n");
     exit (2);
   }
@@ -89,5 +105,4 @@
   for (i = 0; i < inlist[0].Nregions; i++) {
     if (!inlist[0].regions[i][0].table) continue;
-
     if (i % 1000 == 0) fprintf (stderr, ".");
 
@@ -109,4 +124,10 @@
     if (!CheckCatalogIndexes(catdir, inlist[0].filename[i], inlist[0].regions[i])){
       Nbad ++;
+    }
+
+    // exit immediately if any file are unsorted and we require sorted tables
+    if (CHECKSORTED && NNotSorted) {
+      fprintf (stderr, "ERROR: files are not sorted\n");
+      exit (1);
     }
   }
@@ -118,4 +139,7 @@
 
   fprintf (stderr, "SUCCESS: no files are bad\n");
+  if (NNotSorted) {
+    fprintf (stderr, "NOTE: %d files are not sorted\n", NNotSorted);
+  }
   exit (0);
 }
@@ -267,4 +291,6 @@
     dvo_catalog_unlock (&catalog);
     dvo_catalog_free (&catalog);
+    NNotSorted++;
+    if (VERBOSE) fprintf (stderr, "file is not sorted: %s\n", filename);
     return TRUE;
   }
