[med-svn] [dazzdb] 01/06: New upstream version 1.0+20180115

Afif Elghraoui afif at moszumanska.debian.org
Sun Feb 4 18:48:44 UTC 2018


This is an automated email from the git hooks/post-receive script.

afif pushed a commit to branch master
in repository dazzdb.

commit eb6be9a3ec71ec159ce78d2c4cb35dd0643fd6f5
Author: Afif Elghraoui <afif at debian.org>
Date:   Sun Feb 4 13:34:39 2018 -0500

    New upstream version 1.0+20180115
---
 Catrack.c   | 251 ++++++++++++++++++++++++++++++++++------------
 DAM2fasta.c |  46 +++++----
 DB.c        | 325 ++++++++++++++++++++++++++++++++++++++++++++++--------------
 DB.h        | 208 +++++++++++++++++++++++++++++++-------
 DB2arrow.c  |  39 ++++----
 DB2fasta.c  |  39 ++++----
 DB2quiva.c  |  38 +++----
 DBdump.c    | 137 +++++++++++++------------
 DBdust.c    |  35 ++++---
 DBmv.c      |  95 ++++++++++++++++++
 DBrm.c      |  47 +++++++--
 DBshow.c    | 108 +++++++++++---------
 DBsplit.c   |  68 +++++++------
 DBstats.c   |  14 ++-
 DBtrim.c    |  60 +++++------
 DBwipe.c    |  32 ++++--
 Makefile    |   7 +-
 README.md   |  35 ++++---
 arrow2DB.c  |  17 ++--
 fasta2DAM.c |  22 ++--
 fasta2DB.c  |  62 ++++++++----
 quiva2DB.c  |  26 ++---
 simulator.c |  34 +++----
 23 files changed, 1202 insertions(+), 543 deletions(-)

diff --git a/Catrack.c b/Catrack.c
index 8ea6c38..a260627 100644
--- a/Catrack.c
+++ b/Catrack.c
@@ -12,6 +12,7 @@
 #include <stdio.h>
 #include <string.h>
 #include <unistd.h>
+#include <errno.h>
 
 #include "DB.h"
 
@@ -21,13 +22,16 @@
 #define PATHSEP "/"
 #endif
 
-static char *Usage = "[-vf] <path:db|dam> <track:name>";
+static char *Usage = "[-vfd] <path:db|dam> <track:name>";
 
 int main(int argc, char *argv[])
 { char *prefix;
   FILE *aout, *dout;
+  int   nblocks;
+  int   nfiles;
   int   VERBOSE;
   int   FORCE;
+  int   DELETE;
 
   //  Process arguments
 
@@ -39,22 +43,29 @@ int main(int argc, char *argv[])
     j = 1;
     for (i = 1; i < argc; i++)
       if (argv[i][0] == '-')
-        { ARG_FLAGS("vf") }
+        { ARG_FLAGS("vfd") }
       else
         argv[j++] = argv[i];
     argc = j;
 
     VERBOSE = flags['v'];
     FORCE   = flags['f'];
+    DELETE  = flags['d'];
 
     if (argc != 3)
       { fprintf(stderr,"Usage: %s %s\n",Prog_Name,Usage);
+        fprintf(stderr,"\n");
+        fprintf(stderr,"   -v: verbose\n");
+        fprintf(stderr,"   -d: delete individual blocks after a successful concatenation\n");
+        fprintf(stderr,"   -f: force overwrite of track if already present\n");
         exit (1);
       }
   }
 
   { char *pwd, *root;
-    int   plen;
+    int   i, plen, index, isdam;
+    FILE *dstub;
+    char *dstub_name;
 
     plen = strlen(argv[1]);
     if (strcmp(argv[1]+(plen-3),".dam") == 0)
@@ -63,20 +74,45 @@ int main(int argc, char *argv[])
       root = Root(argv[1],".db");
     pwd = PathTo(argv[1]);
     prefix = Strdup(Catenate(pwd,PATHSEP,root,"."),"Allocating track name");
+
+    dstub = fopen(Catenate(pwd,"/",root,".db"),"r");
+    isdam = 0;
+    if (dstub == NULL)
+      { dstub = fopen(Catenate(pwd,"/",root,".dam"),"r");
+        isdam = 1;
+        if (dstub == NULL)
+          { fprintf(stderr,"%s: Cannot find %s either as a .db or a .dam\n",Prog_Name,root);
+            exit (1);
+          }
+      }
+    dstub_name = Strdup(Catenate(pwd,"/",root,isdam?".dam":".db"),"Allocating db file name");
+    if (dstub_name == NULL)
+      exit (1);
+    
+    FSCANF(dstub,DB_NFILE,&nblocks)
+    
+    for (i = 0; i < nblocks; i++)
+      { char prolog[MAX_NAME], fname[MAX_NAME];
+        
+        FSCANF(dstub,DB_FDATA,&index,fname,prolog)
+      }
+    
+    FSCANF(dstub,DB_NBLOCK,&nblocks)
+
+    fclose(dstub);
+    free(dstub_name);
     free(pwd);
     free(root);
 
     aout = fopen(Catenate(prefix,argv[2],".","anno"),"r");
     if (aout != NULL && !FORCE)
       { fprintf(stderr,"%s: Track file %s%s.anno already exists!\n",Prog_Name,prefix,argv[2]);
-        fclose(aout);
         exit (1);
       }
 
     dout = fopen(Catenate(prefix,argv[2],".","data"),"r");
     if (dout != NULL && !FORCE)
       { fprintf(stderr,"%s: Track file %s%s.data already exists!\n",Prog_Name,prefix,argv[2]);
-        fclose(dout);
         exit (1);
       }
 
@@ -88,26 +124,44 @@ int main(int argc, char *argv[])
  
   { int   tracktot, tracksiz;
     int64 trackoff;
-    int   nfiles;
     char  data[1024];
     void *anno;
     FILE *lfile = NULL;
+    DAZZ_EXTRA *extra;
+    int         nextra;
+    int64       extail;
 
     anno     = NULL;
     trackoff = 0;
     tracktot = tracksiz = 0;
-    fwrite(&tracktot,sizeof(int),1,aout);
-    fwrite(&tracksiz,sizeof(int),1,aout);
+    if (fwrite(&tracktot,sizeof(int),1,aout) != 1)
+      SYSTEM_WRITE_ERROR
+    if (fwrite(&tracksiz,sizeof(int),1,aout) != 1)
+      SYSTEM_WRITE_ERROR
 
+    nextra = 0;
     nfiles = 0;
     while (1)
       { FILE *dfile, *afile;
-        int   i, size, tracklen;
+        char *dfile_name, *afile_name;
+        int   i, size, esize, tracklen;
 
-        afile = fopen(Numbered_Suffix(prefix,nfiles+1,Catenate(".",argv[2],".","anno")),"r");
+        afile_name = Strdup(Numbered_Suffix(prefix,nfiles+1,Catenate(".",argv[2],".","anno")),
+                            "Allocating .anno file name");
+        dfile_name = Strdup(Numbered_Suffix(prefix,nfiles+1,Catenate(".",argv[2],".","data")),
+                            "Allocating .data file name");
+        if (afile_name == NULL || dfile_name == NULL)
+          goto error;
+          
+
+        afile = fopen(afile_name,"r");
         if (afile == NULL)
           break;
         dfile = fopen(Numbered_Suffix(prefix,nfiles+1,Catenate(".",argv[2],".","data")),"r");
+        if (dfile == NULL && errno != ENOENT)
+          { fprintf(stderr,"%s: The file %s is corrupted\n",Prog_Name,dfile_name);
+            goto error;
+          }
 
         if (nfiles > 0)
           fclose(lfile);
@@ -118,26 +172,24 @@ int main(int argc, char *argv[])
             fflush(stderr);
           }
   
-        if (fread(&tracklen,sizeof(int),1,afile) != 1)
-          SYSTEM_ERROR
-        if (fread(&size,sizeof(int),1,afile) != 1)
-          SYSTEM_ERROR
+        FREAD(&tracklen,sizeof(int),1,afile)
+        FREAD(&size,sizeof(int),1,afile)
+        if (size == 0)
+          esize = 8;
+        else
+          esize = size;
+
         if (nfiles == 0)
           { tracksiz = size;
             if (dfile != NULL)
               { dout = Fopen(Catenate(prefix,argv[2],".","data"),"w");
                 if (dout == NULL)
-                  { fclose(afile);
-                    fclose(dfile);
-                    goto error;
-                  }
+                  goto error;
               }
             else
-              { anno = Malloc(size,"Allocating annotation record");
+              { anno = Malloc(esize,"Allocating annotation record");
                 if (anno == NULL)
-                  { fclose(afile);
-                    goto error;
-                  }
+                  goto error;
               }
           }
         else
@@ -156,67 +208,99 @@ int main(int argc, char *argv[])
             else
                escape = 0;
             if (escape)
-              { fclose(afile);
-                if (dfile != NULL) fclose(dfile);
-                if (anno != NULL) free(anno);
-                goto error;
-              }
+              goto error;
           }
   
         if (dfile != NULL)
           { int64 dlen;
 
-            if (size == 4)
+            if (esize == 4)
               { int anno4;
   
                 for (i = 0; i < tracklen; i++)
-                  { if (fread(&anno4,sizeof(int),1,afile) != 1)
-                      SYSTEM_ERROR
+                  { FREAD(&anno4,sizeof(int),1,afile)
                     anno4 += trackoff;
-                    fwrite(&anno4,sizeof(int),1,aout);
+                    FWRITE(&anno4,sizeof(int),1,aout)
                   }
-                if (fread(&anno4,sizeof(int),1,afile) != 1)
-                  SYSTEM_ERROR
+                FREAD(&anno4,sizeof(int),1,afile)
                 dlen = anno4;
               }
             else
               { int64 anno8;
   
                 for (i = 0; i < tracklen; i++)
-                  { if (fread(&anno8,sizeof(int64),1,afile) != 1)
-                      SYSTEM_ERROR
+                  { FREAD(&anno8,sizeof(int64),1,afile)
                     anno8 += trackoff;
-                    fwrite(&anno8,sizeof(int64),1,aout);
+                    FWRITE(&anno8,sizeof(int64),1,aout)
                   }
-                if (fread(&anno8,sizeof(int64),1,afile) != 1)
-                  SYSTEM_ERROR
+                FREAD(&anno8,sizeof(int64),1,afile)
                 dlen = anno8;
               }
             trackoff += dlen;
 
             for (i = 1024; i < dlen; i += 1024)
-              { if (fread(data,1024,1,dfile) != 1)
-                  SYSTEM_ERROR
-                fwrite(data,1024,1,dout);
+              { FREAD(data,1024,1,dfile)
+                FWRITE(data,1024,1,dout)
               }
             i -= 1024;
             if (i < dlen)
-              { if (fread(data,dlen-i,1,dfile) != 1)
-                  SYSTEM_ERROR
-                fwrite(data,dlen-i,1,dout);
+              { FREAD(data,dlen-i,1,dfile)
+                FWRITE(data,dlen-i,1,dout)
               }
           }
         else
           { for (i = 0; i < tracklen; i++)
-              { if (fread(anno,size,1,afile) != 1)
-                  SYSTEM_ERROR
-                fwrite(anno,size,1,aout);
+              { FREAD(anno,esize,1,afile)
+                FWRITE(anno,esize,1,aout)
+              }
+          }
+
+        FSEEKO(afile,0,SEEK_END)
+        if (dfile != NULL)
+          extail = FTELLO(afile) - (esize*(tracklen+1) + 2*sizeof(int)); 
+        else
+          extail = FTELLO(afile) - (esize*tracklen + 2*sizeof(int)); 
+        FSEEKO(afile,-extail,SEEK_END)
+
+        if (extail >= 20)
+          { if (nfiles == 0)
+              { nextra = 0;
+                while (1)
+                  if (Read_Extra(afile,afile_name,NULL))
+                    break;
+                  else
+                    nextra += 1;
+
+                extra = (DAZZ_EXTRA *) Malloc(sizeof(DAZZ_EXTRA)*(nextra+1),"Allocating extras");
+                if (extra == NULL)
+                  goto error;
+                FSEEKO(afile,-extail,SEEK_END)
+
+                for (i = 0; i < nextra; i++)
+                  { extra[i].nelem = 0;
+                    Read_Extra(afile,afile_name,extra+i);
+                  }
+              }
+
+            else
+              { for (i = 0; i < nextra; i++)
+                  if (Read_Extra(afile,afile_name,extra+i))
+                    { fprintf(stderr,"%s: File %s has fewer extras than previous .anno files\n",
+                                     Prog_Name,afile_name);
+                      goto error;
+                    }
+                if (Read_Extra(afile,afile_name,extra+nextra) == 0)
+                  { fprintf(stderr,"%s: File %s has more extras than previous .anno files\n",
+                                   Prog_Name,afile_name);
+                    goto error;
+                  }
               }
           }
   
         tracktot += tracklen;
         nfiles   += 1;
-        if (dfile != NULL) fclose(dfile);
+        if (dfile != NULL)
+          fclose(dfile);
       }
   
     if (nfiles == 0)
@@ -230,38 +314,75 @@ int main(int argc, char *argv[])
         if (dout != NULL)
           { if (tracksiz == 4)
               { int anno4 = trackoff;
-                fwrite(&anno4,sizeof(int),1,aout);
+                FWRITE(&anno4,sizeof(int),1,aout)
               }
             else
               { int64 anno8 = trackoff;
-                fwrite(&anno8,sizeof(int64),1,aout);
+                FWRITE(&anno8,sizeof(int64),1,aout)
               }
           }
-        while (fread(&byte,1,1,lfile) == 1)
-          fwrite(&byte,1,1,aout);
+
+        if (nextra == 0)
+          { while (fread(&byte,1,1,lfile) == 1)
+              FWRITE(&byte,1,1,aout)
+          }
+        else
+          { int i;
+            for (i = 0; i < nextra; i++)
+              Write_Extra(aout,extra+i);
+          }
         fclose(lfile);
 
-        rewind(aout);
-        fwrite(&tracktot,sizeof(int),1,aout);
-        fwrite(&tracksiz,sizeof(int),1,aout);
+        FSEEKO(aout,0,SEEK_SET)
+        FWRITE(&tracktot,sizeof(int),1,aout)
+        FWRITE(&tracksiz,sizeof(int),1,aout)
       }
   }
   
-  fclose(aout);
+  FCLOSE(aout);
   if (dout != NULL)
-    fclose(dout);
-  free(prefix);
+    FCLOSE(dout);
 
-  exit (0);
+  if (nfiles != nblocks)
+    { fprintf(stderr,"%s: Did not catenate all tracks of DB (nfiles %d != nblocks %d)\n",
+	             Prog_Name, nfiles, nblocks);
+      goto error;
+    }
 
-error:
-  fclose(aout);
-  unlink(Catenate(prefix,argv[2],".","anno"));
-  if (dout != NULL)
-    { fclose(dout);
-      unlink(Catenate(prefix,argv[2],".","data"));
+  if (DELETE)
+    { int   i;
+      char *name;
+
+      for (i = 1; i <= nblocks ;i++)
+        { name = Numbered_Suffix(prefix,i,Catenate(".",argv[2],".","anno"));
+          if (unlink(name) != 0)
+            fprintf(stderr,"%s: [WARNING] Couldn't delete file %s\n",Prog_Name,name);
+          if (dout != NULL)
+            { name = Numbered_Suffix(prefix,i,Catenate(".",argv[2],".","data"));
+              if (unlink(name) != 0)
+                fprintf(stderr,"%s: [WARNING] Couldn't delete file %s\n",Prog_Name,name);
+            }
+        }
     }
+
   free(prefix);
+  exit (0);
+
+error:
+  { char *name;
+
+    fclose(aout);
+    name = Catenate(prefix,argv[2],".","anno");
+    if (unlink(name) != 0)
+      fprintf(stderr,"%s: [WARNING] Couldn't delete file %s during abort\n",Prog_Name,name);
+    if (dout != NULL)
+      { fclose(dout);
+        name = Catenate(prefix,argv[2],".","data");
+        if (unlink(name) != 0)
+          fprintf(stderr,"%s: [WARNING] Couldn't delete file %s during abort\n",Prog_Name,name);
+      }
+    free(prefix);
+  }
 
   exit (1);
 }
diff --git a/DAM2fasta.c b/DAM2fasta.c
index 9c6ffff..a678825 100644
--- a/DAM2fasta.c
+++ b/DAM2fasta.c
@@ -22,8 +22,9 @@
 static char *Usage = "[-vU] [-w<int(80)>] <path:dam>";
 
 int main(int argc, char *argv[])
-{ HITS_DB    _db, *db = &_db;
+{ DAZZ_DB    _db, *db = &_db;
   FILE       *dbfile, *hdrs;
+  char       *dbfile_name, *hdrs_name;
   int         nfiles;
   int         VERBOSE, UPPER, WIDTH;
 
@@ -57,6 +58,9 @@ int main(int argc, char *argv[])
 
     if (argc != 2)
       { fprintf(stderr,"Usage: %s %s\n",Prog_Name,Usage);
+        fprintf(stderr,"\n");
+        fprintf(stderr,"      -U: Use upper case for DNA (default is lower case).\n");
+        fprintf(stderr,"      -w: Print -w bp per line (default is 80).\n");
         exit (1);
       }
   }
@@ -82,22 +86,23 @@ int main(int argc, char *argv[])
 
     pwd    = PathTo(argv[1]);
     root   = Root(argv[1],".dam");
-    dbfile = Fopen(Catenate(pwd,"/",root,".dam"),"r");
-    hdrs   = Fopen(Catenate(pwd,PATHSEP,root,".hdr"),"r");
+    dbfile_name = Strdup(Catenate(pwd,"/",root,".dam"),"Allocating db file name");
+    hdrs_name   = Strdup(Catenate(pwd,PATHSEP,root,".hdr"),"Allocating header file name");
+    dbfile = Fopen(dbfile_name,"r");
+    hdrs   = Fopen(hdrs_name,"r");
     free(pwd);
     free(root);
-    if (dbfile == NULL || hdrs == NULL)
+    if (dbfile_name == NULL || hdrs_name == NULL || dbfile == NULL || hdrs == NULL)
       exit (1);
   }
 
   //  nfiles = # of files in data base
 
-  if (fscanf(dbfile,DB_NFILE,&nfiles) != 1)
-    SYSTEM_ERROR
+  FSCANF(dbfile,DB_NFILE,&nfiles)
 
   //  For each file do:
 
-  { HITS_READ  *reads;
+  { DAZZ_READ  *reads;
     char       *read;
     int         f, first;
     char        nstring[WIDTH+1];
@@ -120,11 +125,10 @@ int main(int argc, char *argv[])
 
         //  Scan db image file line, create .fasta file for writing
 
-        if (fscanf(dbfile,DB_FDATA,&last,fname,prolog) != 3)
-          SYSTEM_ERROR
+        FSCANF(dbfile,DB_FDATA,&last,fname,prolog)
 
         if (strcmp(fname,"stdout") == 0)
-          { ofile  = stdout;
+          { ofile = stdout;
 
             if (VERBOSE)
               { fprintf(stderr,"Sending %d contigs to stdout ...\n",last-first);
@@ -147,7 +151,7 @@ int main(int argc, char *argv[])
         wpos = 0;
         for (i = first; i < last; i++)
           { int        j, len, nlen, w;
-            HITS_READ *r;
+            DAZZ_READ *r;
 
             r     = reads + i;
             len   = r->rlen;
@@ -157,9 +161,9 @@ int main(int argc, char *argv[])
                   { fprintf(ofile,"\n");
                     wpos = 0;
                   }
-                fseeko(hdrs,r->coff,SEEK_SET);
-                fgets(header,MAX_NAME,hdrs);
-                fputs(header,ofile);
+                FSEEKO(hdrs,r->coff,SEEK_SET)
+                FGETS(header,MAX_NAME,hdrs)
+                FPUTS(header,ofile)
               }
 
             if (r->fpulse != 0)
@@ -169,11 +173,11 @@ int main(int argc, char *argv[])
                   nlen = r->fpulse;
 
                 for (j = 0; j+(w = WIDTH-wpos) <= nlen; j += w)
-                  { fprintf(ofile,"%.*s\n",w,nstring);
+                  { FPRINTF(ofile,"%.*s\n",w,nstring)
                     wpos = 0;
                   }
                 if (j < nlen)
-                  { fprintf(ofile,"%.*s",nlen-j,nstring);
+                  { FPRINTF(ofile,"%.*s",nlen-j,nstring)
                     if (j == 0)
                       wpos += nlen;
                     else
@@ -184,11 +188,11 @@ int main(int argc, char *argv[])
             Load_Read(db,i,read,UPPER);
 
             for (j = 0; j+(w = WIDTH-wpos) <= len; j += w)
-              { fprintf(ofile,"%.*s\n",w,read+j);
+              { FPRINTF(ofile,"%.*s\n",w,read+j)
                 wpos = 0;
               }
             if (j < len)
-              { fprintf(ofile,"%s",read+j);
+              { FPRINTF(ofile,"%s",read+j)
                 if (j == 0)
                   wpos += len;
                 else
@@ -196,11 +200,9 @@ int main(int argc, char *argv[])
               }
           }
         if (wpos > 0)
-          fprintf(ofile,"\n");
-
+          FPRINTF(ofile,"\n")
         if (ofile != stdout)
-          fclose(ofile);
-
+          FCLOSE(ofile)
         first = last;
       }
   }
diff --git a/DB.c b/DB.c
index 69060d0..9b5c85f 100644
--- a/DB.c
+++ b/DB.c
@@ -41,6 +41,24 @@ char Ebuffer[1000];
 
 #endif
 
+int Count_Args(char *var)
+{ int   cnt, lev;
+  char *s;
+
+  cnt = 1;
+  lev = 0;
+  for (s = var; *s != '\0'; s++)
+    if (*s == ',')
+      { if (lev == 0)
+          cnt += 1;
+      }
+    else if (*s == '(')
+      lev += 1;
+    else if (*s == ')')
+      lev -= 1;
+  return (cnt);
+}
+
 void *Malloc(int64 size, char *mesg)
 { void *p;
 
@@ -382,7 +400,7 @@ void Number_Arrow(char *s)
  ********************************************************************************************/
 
 
-// Open the given database or dam, "path" into the supplied HITS_DB record "db". If the name has
+// Open the given database or dam, "path" into the supplied DAZZ_DB record "db". If the name has
 //   a part # in it then just the part is opened.  The index array is allocated (for all or
 //   just the part) and read in.
 // Return status of routine:
@@ -390,8 +408,8 @@ void Number_Arrow(char *s)
 //     0: Open of DB proceeded without mishap
 //     1: Open of DAM proceeded without mishap
 
-int Open_DB(char* path, HITS_DB *db)
-{ HITS_DB dbcopy;
+int Open_DB(char* path, DAZZ_DB *db)
+{ DAZZ_DB dbcopy;
   char   *root, *pwd, *bptr, *fptr, *cat;
   int     nreads;
   FILE   *index, *dbvis;
@@ -437,7 +455,7 @@ int Open_DB(char* path, HITS_DB *db)
 
   if ((index = Fopen(Catenate(pwd,PATHSEP,root,".idx"),"r")) == NULL)
     goto error1;
-  if (fread(db,sizeof(HITS_DB),1,index) != 1)
+  if (fread(db,sizeof(DAZZ_DB),1,index) != 1)
     { EPRINTF(EPLACE,"%s: Index file (.idx) of %s is junk\n",Prog_Name,root);
       goto error2;
     }
@@ -505,28 +523,28 @@ int Open_DB(char* path, HITS_DB *db)
 
   nreads = ulast-ufirst;
   if (part <= 0)
-    { db->reads = (HITS_READ *) Malloc(sizeof(HITS_READ)*(nreads+2),"Allocating Open_DB index");
+    { db->reads = (DAZZ_READ *) Malloc(sizeof(DAZZ_READ)*(nreads+2),"Allocating Open_DB index");
       if (db->reads == NULL)
         goto error2;
       db->reads += 1;
-      if (fread(db->reads,sizeof(HITS_READ),nreads,index) != (size_t) nreads)
+      if (fread(db->reads,sizeof(DAZZ_READ),nreads,index) != (size_t) nreads)
         { EPRINTF(EPLACE,"%s: Index file (.idx) of %s is junk\n",Prog_Name,root);
           free(db->reads-1);
           goto error2;
         }
     }
   else
-    { HITS_READ *reads;
+    { DAZZ_READ *reads;
       int        i, r, maxlen;
       int64      totlen;
 
-      reads = (HITS_READ *) Malloc(sizeof(HITS_READ)*(nreads+2),"Allocating Open_DB index");
+      reads = (DAZZ_READ *) Malloc(sizeof(DAZZ_READ)*(nreads+2),"Allocating Open_DB index");
       if (reads == NULL)
         goto error2;
       reads += 1;
 
-      fseeko(index,sizeof(HITS_READ)*ufirst,SEEK_CUR);
-      if (fread(reads,sizeof(HITS_READ),nreads,index) != (size_t) nreads)
+      fseeko(index,sizeof(DAZZ_READ)*ufirst,SEEK_CUR);
+      if (fread(reads,sizeof(DAZZ_READ),nreads,index) != (size_t) nreads)
         { EPRINTF(EPLACE,"%s: Index file (.idx) of %s is junk\n",Prog_Name,root);
           free(reads-1);
           goto error2;
@@ -580,13 +598,13 @@ error:
 //   of the current DB partition.  Reallocate smaller memory blocks for the information kept
 //   for the retained reads.
 
-void Trim_DB(HITS_DB *db)
+void Trim_DB(DAZZ_DB *db)
 { int         i, j, r;
   int         allflag, cutoff;
   int64       totlen;
   int         maxlen, nreads;
-  HITS_TRACK *record;
-  HITS_READ  *reads;
+  DAZZ_TRACK *record;
+  DAZZ_READ  *reads;
 
   if (db->trimmed) return;
 
@@ -603,7 +621,7 @@ void Trim_DB(HITS_DB *db)
 
   for (record = db->tracks; record != NULL; record = record->next)
     if (strcmp(record->name,". at qvs") == 0)
-      { uint16 *table = ((HITS_QV *) record)->table;
+      { uint16 *table = ((DAZZ_QV *) record)->table;
 
         j = 0;
         for (i = 0; i < db->nreads; i++)
@@ -675,7 +693,7 @@ void Trim_DB(HITS_DB *db)
   db->trimmed = 1;
 
   if (j < nreads)
-    { db->reads = Realloc(reads-1,sizeof(HITS_READ)*(j+2),NULL);
+    { db->reads = Realloc(reads-1,sizeof(DAZZ_READ)*(j+2),NULL);
       db->reads += 1;
     }
 }
@@ -683,12 +701,12 @@ void Trim_DB(HITS_DB *db)
 // The DB has already been trimmed, but a track over the untrimmed DB needs to be loaded.
 //   Trim the track by rereading the untrimmed DB index from the file system.
 
-static int Late_Track_Trim(HITS_DB *db, HITS_TRACK *track, int ispart)
+static int Late_Track_Trim(DAZZ_DB *db, DAZZ_TRACK *track, int ispart)
 { int         i, j, r;
   int         allflag, cutoff;
   int         ureads;
   char       *root;
-  HITS_READ   read;
+  DAZZ_READ   read;
   FILE       *indx;
 
   if (!db->trimmed) return (0);
@@ -703,7 +721,7 @@ static int Late_Track_Trim(HITS_DB *db, HITS_TRACK *track, int ispart)
 
   root = rindex(db->path,'/') + 2;
   indx = Fopen(Catenate(db->path,"","",".idx"),"r");
-  fseeko(indx,sizeof(HITS_DB) + sizeof(HITS_READ)*db->ufirst,SEEK_SET);
+  fseeko(indx,sizeof(DAZZ_DB) + sizeof(DAZZ_READ)*db->ufirst,SEEK_SET);
   if (ispart)
     ureads = ((int *) (db->reads))[-1];
   else
@@ -725,7 +743,7 @@ static int Late_Track_Trim(HITS_DB *db, HITS_TRACK *track, int ispart)
       { anno = (char *) track->anno;
         j = r = 0;
         for (i = r = 0; i < ureads; i++, r += size)
-          { if (fread(&read,sizeof(HITS_READ),1,indx) != 1)
+          { if (fread(&read,sizeof(DAZZ_READ),1,indx) != 1)
               { EPRINTF(EPLACE,"%s: Index file (.idx) of %s is junk\n",Prog_Name,root);
                 fclose(indx);
                 EXIT(1);
@@ -744,7 +762,7 @@ static int Late_Track_Trim(HITS_DB *db, HITS_TRACK *track, int ispart)
         anno4 = (int *) (track->anno);
         j = anno4[0] = 0;
         for (i = 0; i < ureads; i++)
-          { if (fread(&read,sizeof(HITS_READ),1,indx) != 1)
+          { if (fread(&read,sizeof(DAZZ_READ),1,indx) != 1)
               { EPRINTF(EPLACE,"%s: Index file (.idx) of %s is junk\n",Prog_Name,root);
                 fclose(indx);
                 EXIT(1);
@@ -764,7 +782,7 @@ static int Late_Track_Trim(HITS_DB *db, HITS_TRACK *track, int ispart)
         anno8 = (int64 *) (track->anno);
         j = anno8[0] = 0;
         for (i = 0; i < ureads; i++)
-          { if (fread(&read,sizeof(HITS_READ),1,indx) != 1)
+          { if (fread(&read,sizeof(DAZZ_READ),1,indx) != 1)
               { EPRINTF(EPLACE,"%s: Index file (.idx) of %s is junk\n",Prog_Name,root);
                 fclose(indx);
                 EXIT(1);
@@ -789,8 +807,8 @@ static int Late_Track_Trim(HITS_DB *db, HITS_TRACK *track, int ispart)
 //   and any open file pointers.  The record pointed at by db however remains (the user
 //   supplied it and so should free it).
 
-void Close_DB(HITS_DB *db)
-{ HITS_TRACK *t, *p;
+void Close_DB(DAZZ_DB *db)
+{ DAZZ_TRACK *t, *p;
 
   if (db->loaded)
     free(((char *) (db->bases)) - 1);
@@ -813,19 +831,19 @@ void Close_DB(HITS_DB *db)
 
 // Return the size in bytes of the memory occupied by a given DB
 
-int64 sizeof_DB(HITS_DB *db)
+int64 sizeof_DB(DAZZ_DB *db)
 { int64       s;
-  HITS_TRACK *t;
+  DAZZ_TRACK *t;
 
-  s = sizeof(HITS_DB)
-    + sizeof(HITS_READ)*(db->nreads+2)
+  s = sizeof(DAZZ_DB)
+    + sizeof(DAZZ_READ)*(db->nreads+2)
     + strlen(db->path)+1
     + (db->totlen+db->nreads+4);
 
   t = db->tracks;
   if (t != NULL && strcmp(t->name,". at qvs") == 0)
-    { HITS_QV *q = (HITS_QV *) t;
-      s += sizeof(HITS_QV)
+    { DAZZ_QV *q = (DAZZ_QV *) t;
+      s += sizeof(DAZZ_QV)
          + sizeof(uint16) * db->nreads
          + q->ncodes * sizeof(QVcoding)
          + 6;
@@ -833,7 +851,7 @@ int64 sizeof_DB(HITS_DB *db)
     }
 
   for (; t != NULL; t = t->next)
-    { s += sizeof(HITS_TRACK)
+    { s += sizeof(DAZZ_TRACK)
          + strlen(t->name)+1
          + t->size * (db->nreads+1);
       if (t->data != NULL)
@@ -854,14 +872,14 @@ int64 sizeof_DB(HITS_DB *db)
  *
  ********************************************************************************************/
 
-HITS_DB *Active_DB = NULL;  //  Last db/qv used by "Load_QVentry"
-HITS_QV *Active_QV;         //    Becomes invalid after closing
+DAZZ_DB *Active_DB = NULL;  //  Last db/qv used by "Load_QVentry"
+DAZZ_QV *Active_QV;         //    Becomes invalid after closing
 
-int Load_QVs(HITS_DB *db)
+int Load_QVs(DAZZ_DB *db)
 { FILE        *quiva, *istub, *indx;
   char        *root;
   uint16      *table;
-  HITS_QV     *qvtrk;
+  DAZZ_QV     *qvtrk;
   QVcoding    *coding, *nx;
   int          ncodes = 0;
 
@@ -956,7 +974,7 @@ int Load_QVs(HITS_DB *db)
             goto error;
           }
 
-        //  Carefully get the first coding scheme (its offset is most likely in a HITS_RECORD
+        //  Carefully get the first coding scheme (its offset is most likely in a DAZZ_RECORD
         //    in .idx that is *not* in memory).  Get all the other coding schemes normally and
         //    assign the tables # for each read in the block in "tables".
 
@@ -974,10 +992,10 @@ int Load_QVs(HITS_DB *db)
 
             i = n-fbeg;
             if (first < pfirst)
-              { HITS_READ read;
+              { DAZZ_READ read;
 
-                fseeko(indx,sizeof(HITS_DB) + sizeof(HITS_READ)*first,SEEK_SET);
-                if (fread(&read,sizeof(HITS_READ),1,indx) != 1)
+                fseeko(indx,sizeof(DAZZ_DB) + sizeof(DAZZ_READ)*first,SEEK_SET);
+                if (fread(&read,sizeof(DAZZ_READ),1,indx) != 1)
                   { EPRINTF(EPLACE,"%s: Index file (.idx) of %s is junk\n",Prog_Name,root);
                     ncodes = i;
                     goto error;
@@ -1050,17 +1068,17 @@ int Load_QVs(HITS_DB *db)
           }
       }
 
-    //  Allocate and fill in the HITS_QV record and add it to the front of the
+    //  Allocate and fill in the DAZZ_QV record and add it to the front of the
     //    track list
 
-    qvtrk = (HITS_QV *) Malloc(sizeof(HITS_QV),"Allocating QV pseudo-track");
+    qvtrk = (DAZZ_QV *) Malloc(sizeof(DAZZ_QV),"Allocating QV pseudo-track");
     if (qvtrk == NULL)
       goto error;
     qvtrk->name   = Strdup(". at qvs","Allocating QV pseudo-track name");
     if (qvtrk->name == NULL)
       goto error;
     qvtrk->next   = db->tracks;
-    db->tracks    = (HITS_TRACK *) qvtrk;
+    db->tracks    = (DAZZ_TRACK *) qvtrk;
     qvtrk->ncodes = ncodes;
     qvtrk->table  = table;
     qvtrk->coding = coding;
@@ -1091,16 +1109,16 @@ error:
 
 // Close the QV stream, free the QV pseudo track and all associated memory
 
-void Close_QVs(HITS_DB *db)
-{ HITS_TRACK *track;
-  HITS_QV    *qvtrk;
+void Close_QVs(DAZZ_DB *db)
+{ DAZZ_TRACK *track;
+  DAZZ_QV    *qvtrk;
   int         i;
 
   Active_DB = NULL;
 
   track = db->tracks;
   if (track != NULL && strcmp(track->name,". at qvs") == 0)
-    { qvtrk = (HITS_QV *) track;
+    { qvtrk = (DAZZ_QV *) track;
       for (i = 0; i < qvtrk->ncodes; i++)
         Free_QVcoding(qvtrk->coding+i);
       free(qvtrk->coding);
@@ -1125,7 +1143,7 @@ void Close_QVs(HITS_DB *db)
 //    -1: Track is not the right size of DB either trimmed or untrimmed
 //    -2: Could not find the track 
 
-int Check_Track(HITS_DB *db, char *track, int *kind)
+int Check_Track(DAZZ_DB *db, char *track, int *kind)
 { FILE       *afile;
   int         tracklen, size, ispart;
   int         ureads, treads;
@@ -1181,10 +1199,10 @@ int Check_Track(HITS_DB *db, char *track, int *kind)
 
 // If track is not already in the db's track list, then allocate all the storage for it,
 //   read it in from the appropriate file, add it to the track list, and return a pointer
-//   to the newly created HITS_TRACK record.  If the track does not exist or cannot be
+//   to the newly created DAZZ_TRACK record.  If the track does not exist or cannot be
 //   opened for some reason, then NULL is returned.
 
-HITS_TRACK *Load_Track(HITS_DB *db, char *track)
+DAZZ_TRACK *Load_Track(DAZZ_DB *db, char *track)
 { FILE       *afile, *dfile;
   int         tracklen, size;
   int         nreads, ispart;
@@ -1192,7 +1210,7 @@ HITS_TRACK *Load_Track(HITS_DB *db, char *track)
   void       *anno;
   void       *data;
   char       *name;
-  HITS_TRACK *record;
+  DAZZ_TRACK *record;
 
   if (track[0] == '.')
     { EPRINTF(EPLACE,"%s: Track name, '%s', cannot begin with a .\n",Prog_Name,track);
@@ -1340,7 +1358,7 @@ HITS_TRACK *Load_Track(HITS_DB *db, char *track)
 
   fclose(afile);
 
-  record = (HITS_TRACK *) Malloc(sizeof(HITS_TRACK),"Allocating Track Record");
+  record = (DAZZ_TRACK *) Malloc(sizeof(DAZZ_TRACK),"Allocating Track Record");
   if (record == NULL)
     goto error;
   record->name = Strdup(track,"Allocating Track Name");
@@ -1379,8 +1397,161 @@ error:
   EXIT (NULL);
 }
 
-void Close_Track(HITS_DB *db, char *track)
-{ HITS_TRACK *record, *prev;
+// Assumming file pointer for afile is correctly positioned at the start of a extra item,
+//   and aname is the name of the .anno file, decode the value present and places it in
+//   extra if extra->nelem == 0, otherwise reduce the value just read into extra according 
+//   according the to the directive given by 'accum'.  Leave the read poinrt at the next
+//   extra or end-of-file.
+//   Returns:
+//      1 if at the end of file,
+//      0 if item was read and folded correctly,
+//     -1 if there was a system IO or allocation error (if interactive), and
+//     -2 if the new value could not be reduced into the currenct value of extra (interactive)
+
+int Read_Extra(FILE *afile, char *aname, DAZZ_EXTRA *extra)
+{ int   vtype, nelem, accum, slen;
+  char *name;
+  void *value;
+
+#define EREAD(v,s,n,file,ret)                                                           \
+  { if (fread(v,s,n,file) != (size_t) n)                                                \
+      { if (ferror(file))                                                               \
+          fprintf(stderr,"%s: System error, read failed!\n",Prog_Name);       		\
+        else if (ret)                                                                   \
+          return (1);									\
+        else										\
+          fprintf(stderr,"%s: The file %s is corrupted\n",Prog_Name,aname);		\
+        EXIT(-1);									\
+      }                                                                                 \
+  }
+
+  EREAD(&vtype,sizeof(int),1,afile,1)
+  EREAD(&nelem,sizeof(int),1,afile,0)
+  EREAD(&accum,sizeof(int),1,afile,0)
+  EREAD(&slen,sizeof(int),1,afile,0)
+
+  if (extra == NULL)
+    { if (fseeko(afile,slen+8*nelem,SEEK_CUR) < 0)
+        { fprintf(stderr,"%s: System error, read failed!\n",Prog_Name);
+          EXIT(-1);
+        }
+      return (0);
+    }
+
+  name  = (char *) Malloc(slen+1,"Allocating extra name");
+  value = Malloc(8*nelem,"Allocating extra value");
+  if (name == NULL || value == NULL)
+    EXIT(-1);
+
+  EREAD(name,1,slen,afile,0);
+  EREAD(value,8,nelem,afile,0);
+  name[slen] = '\0';
+  
+  if (extra->nelem == 0)
+    { extra->vtype = vtype;
+      extra->nelem = nelem;
+      extra->accum = accum;
+      extra->name  = name;
+      extra->value = value;
+      return (0);
+    }
+
+  if (vtype != extra->vtype)
+    { fprintf(stderr,"%s: Type of extra %s does not agree with previous .anno block files\n",
+                     Prog_Name,name);
+      goto error;
+    }
+  if (nelem != extra->nelem)
+    { fprintf(stderr,"%s: Length of extra %s does not agree with previous .anno block files\n",
+                     Prog_Name,name);
+      goto error;
+    }
+  if (accum != extra->accum)
+    { fprintf(stderr,"%s: Reduction indicator of extra %s does not agree with",Prog_Name,name);
+      fprintf(stderr," previos .anno block files\n");
+      goto error;
+    }
+  if (strcmp(name,extra->name) != 0)
+    { fprintf(stderr,"%s: Expecting extra %s in .anno block file, not %s\n",
+                     Prog_Name,extra->name,name);
+      goto error;
+    }
+
+  if (vtype == DB_INT)
+    { int64 *ival = (int64 *) value;
+      int64 *eval = (int64 *) (extra->value);
+      int    j;
+
+      if (accum == DB_EXACT)
+        { for (j = 0; j < nelem; j++)
+            if (eval[j] != ival[j])
+              { fprintf(stderr,"%s: Value of extra %s doe not agree",Prog_Name,name);
+                fprintf(stderr," with previous .anno block files\n");
+                goto error;
+              }
+        }
+      else
+        { for (j = 0; j < nelem; j++)
+            eval[j] += ival[j];
+        }
+    }
+
+  else
+    { double *ival = (double *) value;
+      double *eval = (double *) (extra->value);
+      int     j;
+
+      if (accum == DB_EXACT)
+        { for (j = 0; j < nelem; j++)
+            if (eval[j] != ival[j])
+              { fprintf(stderr,"%s: Value of extra %s doe not agree",Prog_Name,name);
+                fprintf(stderr," with previous .anoo block files\n");
+                goto error;
+              }
+        }
+      else
+        { for (j = 0; j < nelem; j++)
+            eval[j] += ival[j];
+        }
+    }
+
+  free(value);
+  free(name);
+  return (0);
+
+error:
+  free(value);
+  free(name);
+  EXIT(1);
+}
+
+//  Write extra record to end of file afile and advance write pointer
+//  If interactive, then return non-zero on error, if bash, then print
+//  and halt if an error
+
+int Write_Extra(FILE *afile, DAZZ_EXTRA *extra)
+{ int slen; 
+
+#define EWRITE(v,s,n,file)                                                      \
+  { if (fwrite(v,s,n,file) != (size_t) n)                                       \
+      { fprintf(stderr,"%s: System error, read failed!\n",Prog_Name);           \
+        EXIT(1);								\
+      }									 	\
+  }
+
+  EWRITE(&(extra->vtype),sizeof(int),1,afile)
+  FWRITE(&(extra->nelem),sizeof(int),1,afile)
+  FWRITE(&(extra->accum),sizeof(int),1,afile)
+  slen = strlen(extra->name);
+  FWRITE(&slen,sizeof(int),1,afile)
+  FWRITE(extra->name,1,slen,afile)
+  FWRITE(extra->value,8,extra->nelem,afile)
+
+  return (0);
+}
+
+void Close_Track(DAZZ_DB *db, char *track)
+{ DAZZ_TRACK *record, *prev;
 
   prev = NULL;
   for (record = db->tracks; record != NULL; record = record->next)
@@ -1410,7 +1581,7 @@ void Close_Track(HITS_DB *db, char *track)
 // Allocate and return a buffer big enough for the largest read in 'db', leaving room
 //   for an initial delimiter character
 
-char *New_Read_Buffer(HITS_DB *db)
+char *New_Read_Buffer(DAZZ_DB *db)
 { char *read;
 
   read = (char *) Malloc(db->maxlen+4,"Allocating New Read Buffer");
@@ -1425,11 +1596,11 @@ char *New_Read_Buffer(HITS_DB *db)
 //
 // **NB**, the byte before read will be set to a delimiter character!
 
-int Load_Read(HITS_DB *db, int i, char *read, int ascii)
+int Load_Read(DAZZ_DB *db, int i, char *read, int ascii)
 { FILE      *bases  = (FILE *) db->bases;
   int64      off;
   int        len, clen;
-  HITS_READ *r = db->reads;
+  DAZZ_READ *r = db->reads;
 
   if (i >= db->nreads)
     { EPRINTF(EPLACE,"%s: Index out of bounds (Load_Read)\n",Prog_Name);
@@ -1472,14 +1643,14 @@ int Load_Read(HITS_DB *db, int i, char *read, int ascii)
 //   and as a numeric string otherwise.
 //
 
-HITS_DB *Arrow_DB = NULL;         //  Last db/arw used by "Load_Arrow"
+DAZZ_DB *Arrow_DB = NULL;         //  Last db/arw used by "Load_Arrow"
 FILE    *Arrow_File = NULL;       //    Becomes invalid after closing
 
-int Load_Arrow(HITS_DB *db, int i, char *read, int ascii)
+int Load_Arrow(DAZZ_DB *db, int i, char *read, int ascii)
 { FILE      *arrow;
   int64      off;
   int        len, clen;
-  HITS_READ *r = db->reads;
+  DAZZ_READ *r = db->reads;
 
   if (i >= db->nreads)
     { EPRINTF(EPLACE,"%s: Index out of bounds (Load_Arrow)\n",Prog_Name);
@@ -1519,12 +1690,12 @@ int Load_Arrow(HITS_DB *db, int i, char *read, int ascii)
   return (0);
 }
 
-char *Load_Subread(HITS_DB *db, int i, int beg, int end, char *read, int ascii)
+char *Load_Subread(DAZZ_DB *db, int i, int beg, int end, char *read, int ascii)
 { FILE      *bases  = (FILE *) db->bases;
   int64      off;
   int        len, clen;
   int        bbeg, bend;
-  HITS_READ *r = db->reads;
+  DAZZ_READ *r = db->reads;
 
   if (i >= db->nreads)
     { EPRINTF(EPLACE,"%s: Index out of bounds (Load_Read)\n",Prog_Name);
@@ -1578,7 +1749,7 @@ char *Load_Subread(HITS_DB *db, int i, int beg, int end, char *read, int ascii)
 
 // Allocate and return a buffer of 5 vectors big enough for the largest read in 'db'
 
-char **New_QV_Buffer(HITS_DB *db)
+char **New_QV_Buffer(DAZZ_DB *db)
 { char **entry;
   char  *qvs;
   int    i;
@@ -1595,8 +1766,8 @@ char **New_QV_Buffer(HITS_DB *db)
 // Load into entry the QV streams for the i'th read from db.  The parameter ascii applies to
 //  the DELTAG stream as described for Load_Read.
 
-int Load_QVentry(HITS_DB *db, int i, char **entry, int ascii)
-{ HITS_READ *reads;
+int Load_QVentry(DAZZ_DB *db, int i, char **entry, int ascii)
+{ DAZZ_READ *reads;
   FILE      *quiva;
   int        rlen;
 
@@ -1605,7 +1776,7 @@ int Load_QVentry(HITS_DB *db, int i, char **entry, int ascii)
         { EPRINTF(EPLACE,"%s: QV's are not loaded (Load_QVentry)\n",Prog_Name);
           EXIT(1);
         }
-      Active_QV = (HITS_QV *) db->tracks;
+      Active_QV = (DAZZ_QV *) db->tracks;
       Active_DB = db;
     }
   if (i >= db->nreads)
@@ -1655,10 +1826,10 @@ int Load_QVentry(HITS_DB *db, int i, char **entry, int ascii)
 //   non-zero then the reads are converted to ACGT ascii, otherwise the reads are left
 //   as numeric strings over 0(A), 1(C), 2(G), and 3(T).
 
-int Read_All_Sequences(HITS_DB *db, int ascii)
+int Read_All_Sequences(DAZZ_DB *db, int ascii)
 { FILE      *bases;
   int        nreads = db->nreads;
-  HITS_READ *reads = db->reads;
+  DAZZ_READ *reads = db->reads;
   void     (*translate)(char *s);
 
   char  *seq;
@@ -1713,6 +1884,16 @@ int Read_All_Sequences(HITS_DB *db, int ascii)
   return (0);
 }
 
+// For the DB or DAM "path" = "prefix/root.[db|dam]", find all the files for that DB, i.e. all
+//   those of the form "prefix/[.]root.part" and call actor with the complete path to each file
+//   pointed at by path, and the suffix of the path by extension.  The . proceeds the root
+//   name if the defined constant HIDE_FILES is set.  Always the first call is with the
+//   path "prefix/root.[db|dam]" and extension "db" or "dam".  There will always be calls for
+//   "prefix/[.]root.idx" and "prefix/[.]root.bps".  All other calls are for *tracks* and
+//   so this routine gives one a way to know all the tracks associated with a given DB.
+//   -1 is returned if the path could not be found, and 1 is returned if an error (reported
+//   to EPLACE) occured and INTERACTIVE is defined.  Otherwise a 0 is returned.
+
 int List_DB_Files(char *path, void actor(char *path, char *extension))
 { int            status, plen, rlen, dlen;
   char          *root, *pwd, *name;
@@ -1750,19 +1931,9 @@ int List_DB_Files(char *path, void actor(char *path, char *extension))
         { isdam = 1;
           break;
         }
-      if (strcasecmp(name,Catenate("","",root,".db")) == 0)
-        { strncpy(root,name,rlen);
-          break;
-        }
-      if (strcasecmp(name,Catenate("","",root,".dam")) == 0)
-        { strncpy(root,name,rlen);
-          isdam = 1;
-          break;
-        }
     }
   if (dp == NULL)
-    { EPRINTF(EPLACE,"%s: Cannot find %s (List_DB_Files)\n",Prog_Name,pwd);
-      status = -1;
+    { status = -1;
       closedir(dirp);
       goto error;
     }
diff --git a/DB.h b/DB.h
index dc281de..ff41e9f 100644
--- a/DB.h
+++ b/DB.h
@@ -12,9 +12,9 @@
  *
  ********************************************************************************************/
 
-#ifndef _HITS_DB
+#ifndef _DAZZ_DB
 
-#define _HITS_DB
+#define _DAZZ_DB
 
 #include <stdio.h>
 
@@ -74,11 +74,6 @@ extern char Ebuffer[];
 
 #endif
 
-#define SYSTEM_ERROR							\
-  { EPRINTF(EPLACE,"%s: System error, read failed!\n",Prog_Name);	\
-    exit (2);								\
-  }
-
 #define ARG_INIT(name)                  \
   Prog_Name = Strdup(name,"");          \
   for (i = 0; i < 128; i++)             \
@@ -125,6 +120,108 @@ extern char Ebuffer[];
       exit (1);                                                                         \
     }
 
+
+/*******************************************************************************************
+ *
+ *  GUARDED BATCH IO MACROS
+ *
+ ********************************************************************************************/
+
+    //  Utilitieis
+
+int Count_Args(char *arg);
+
+#define SYSTEM_READ_ERROR						\
+  { fprintf(stderr,"%s: System error, read failed!\n",Prog_Name);	\
+    exit (2);								\
+  }
+
+#define SYSTEM_WRITE_ERROR						\
+  { fprintf(stderr,"%s: System error, write failed!\n",Prog_Name);	\
+    exit (2);								\
+  }
+
+#define SYSTEM_CLOSE_ERROR						\
+  { fprintf(stderr,"%s: System error, file close failed!\n",Prog_Name);	\
+    exit (2);								\
+  }
+
+    //  Output
+
+#define FWRITE(v,s,n,file)			\
+  { if (fwrite(v,s,n,file) != (size_t) n)	\
+      SYSTEM_WRITE_ERROR			\
+  }
+
+#define FPRINTF(file,...)		\
+  { if (fprintf(file,__VA_ARGS__) < 0)	\
+      SYSTEM_WRITE_ERROR		\
+  }
+
+#define PRINTF(...)			\
+  { if (printf(__VA_ARGS__) < 0)	\
+      SYSTEM_WRITE_ERROR		\
+  }
+
+#define FPUTS(x,file)			\
+  { if (fputs(x,file) == EOF)		\
+      SYSTEM_WRITE_ERROR		\
+  }
+
+    //  Close
+
+#define FCLOSE(file)		\
+  { if (fclose(file) != 0)	\
+      SYSTEM_CLOSE_ERROR	\
+  }
+
+    //  Input
+
+#define FREAD(v,s,n,file)								\
+  { if (fread(v,s,n,file) != (size_t) n)						\
+      { if (ferror(file))								\
+          SYSTEM_READ_ERROR								\
+        else										\
+          { fprintf(stderr,"%s: The file %s is corrupted\n",Prog_Name,file ## _name);	\
+            exit (1);									\
+          }										\
+      }											\
+  }
+
+#define FSCANF(file,...)								\
+  { if (fscanf(file,__VA_ARGS__) != Count_Args(#__VA_ARGS__)-1)				\
+      { if (ferror(file))								\
+          SYSTEM_READ_ERROR								\
+        else										\
+          { fprintf(stderr,"%s: The file %s is corrupted\n",Prog_Name,file ## _name);	\
+            exit (1);									\
+          }										\
+      }											\
+  }
+
+#define FGETS(v,n,file)									\
+  { if (fgets(v,n,file) == NULL)							\
+      { if (ferror(file))								\
+          SYSTEM_READ_ERROR								\
+        else										\
+          { fprintf(stderr,"%s: The file %s is corrupted\n",Prog_Name,file ## _name);	\
+            exit (1);									\
+          }										\
+      }											\
+  }
+
+#define FSEEKO(file,p,d)	\
+  { if (fseeko(file,p,d) < 0)	\
+      SYSTEM_READ_ERROR		\
+  }
+
+#define FTELLO(file)		\
+  ( { int x = ftello(file);	\
+      if (x < 0)		\
+        SYSTEM_READ_ERROR	\
+      ; x; 			\
+  } )
+
 /*******************************************************************************************
  *
  *  UTILITIES
@@ -193,7 +290,7 @@ typedef struct
                     //  Offset (in bytes) of scaffold header string in '.hdr' file (DAM)
                     //  4 compressed shorts containing snr info if an arrow DB.
     int     flags;  //  QV of read + flags above (DB only)
-  } HITS_READ;
+  } DAZZ_READ;
 
 //  A track can be of 3 types:
 //    data == NULL: there are nreads 'anno' records of size 'size'.
@@ -208,9 +305,31 @@ typedef struct _track
     int            size;  //  Size in bytes of anno records
     void          *anno;  //  over [0,nreads]: read i annotation: int, int64, or 'size' records 
     void          *data;  //     data[anno[i] .. anno[i+1]-1] is data if data != NULL
-  } HITS_TRACK;
+  } DAZZ_TRACK;
+
+//  The tailing part of a .anno track file can contain meta-information produced by the
+//    command that produced the track.  For example, the coverage, or good/bad parameters
+//    for trimming, or even say a histogram of QV values.  Each item is an array of 'nelem'
+//    64-bit ints or floats ('vtype' = DB_INT or DB_REAL), has a 'name' string that
+//    describes it, and an indicator as to whether the values should be equal accross all
+//    block tracks, or summed accross all block tracks (by Catrack).  'value' points at the
+//    array of values
+
+#define DB_INT  0
+#define DB_REAL 1
 
-//  The information for accessing QV streams is in a HITS_QV record that is a "pseudo-track"
+#define DB_EXACT 0
+#define DB_SUM   1
+
+typedef struct
+  { int   vtype;  //  INT64 or FLOAST64
+    int   nelem;  //  >= 1
+    int   accum;  //  EXACT, SUM
+    char *name;
+    void *value;
+  } DAZZ_EXTRA;
+
+//  The information for accessing QV streams is in a DAZZ_QV record that is a "pseudo-track"
 //    named ". at qvs" and is always the first track record in the list (if present).  Since normal
 //    track names cannot begin with a . (this is enforced), this pseudo-track is never confused
 //    with a normal track.
@@ -223,11 +342,11 @@ typedef struct
     uint16        *table;   //  for i in [0,db->nreads-1]: read i should be decompressed with
                             //    scheme coding[table[i]]
     FILE          *quiva;   //  the open file pointer to the .qvs file
-  } HITS_QV;
+  } DAZZ_QV;
 
 //  The DB record holds all information about the current state of an active DB including an
-//    array of HITS_READS, one per read, and a linked list of HITS_TRACKs the first of which
-//    is always a HITS_QV pseudo-track (if the QVs have been loaded).
+//    array of DAZZ_READS, one per read, and a linked list of DAZZ_TRACKs the first of which
+//    is always a DAZZ_QV pseudo-track (if the QVs have been loaded).
 
 typedef struct
   { int         ureads;     //  Total number of reads in untrimmed DB
@@ -257,9 +376,9 @@ typedef struct
     int         loaded;     //  Are reads loaded in memory?
     void       *bases;      //  file pointer for bases file (to fetch reads from),
                             //    or memory pointer to uncompressed block of all sequences.
-    HITS_READ  *reads;      //  Array [-1..nreads] of HITS_READ
-    HITS_TRACK *tracks;     //  Linked list of loaded tracks
-  } HITS_DB; 
+    DAZZ_READ  *reads;      //  Array [-1..nreads] of DAZZ_READ
+    DAZZ_TRACK *tracks;     //  Linked list of loaded tracks
+  } DAZZ_DB; 
 
 
 /*******************************************************************************************
@@ -294,7 +413,7 @@ typedef struct
   //          contain N-separated contigs), and .fpulse the first base of the contig in the
   //          fasta entry
 
-  // Open the given database or dam, "path" into the supplied HITS_DB record "db". If the name has
+  // Open the given database or dam, "path" into the supplied DAZZ_DB record "db". If the name has
   //   a part # in it then just the part is opened.  The index array is allocated (for all or
   //   just the part) and read in.
   // Return status of routine:
@@ -302,34 +421,34 @@ typedef struct
   //     0: Open of DB proceeded without mishap
   //     1: Open of DAM proceeded without mishap
 
-int Open_DB(char *path, HITS_DB *db);
+int Open_DB(char *path, DAZZ_DB *db);
 
   // Trim the DB or part thereof and all loaded tracks according to the cutoff and all settings
   //   of the current DB partition.  Reallocate smaller memory blocks for the information kept
   //   for the retained reads.
 
-void Trim_DB(HITS_DB *db);
+void Trim_DB(DAZZ_DB *db);
 
   // Shut down an open 'db' by freeing all associated space, including tracks and QV structures,
   //   and any open file pointers.  The record pointed at by db however remains (the user
   //   supplied it and so should free it).
 
-void Close_DB(HITS_DB *db);
+void Close_DB(DAZZ_DB *db);
 
   // Return the size in bytes of the given DB
 
-int64 sizeof_DB(HITS_DB *db);
+int64 sizeof_DB(DAZZ_DB *db);
 
   // If QV pseudo track is not already in db's track list, then load it and set it up.
   //   The database must not have been trimmed yet.  -1 is returned if a .qvs file is not
   //   present, and 1 is returned if an error (reported to EPLACE) occured and INTERACTIVE
   //   is defined.  Otherwise a 0 is returned.
 
-int Load_QVs(HITS_DB *db);
+int Load_QVs(DAZZ_DB *db);
 
   // Remove the QV pseudo track, all space associated with it, and close the .qvs file.
 
-void Close_QVs(HITS_DB *db);
+void Close_QVs(DAZZ_DB *db);
 
   // Look up the file and header in the file of the indicated track.  Return:
   //     1: Track is for trimmed DB
@@ -344,28 +463,47 @@ void Close_QVs(HITS_DB *db);
 #define CUSTOM_TRACK 0
 #define   MASK_TRACK 1
 
-int Check_Track(HITS_DB *db, char *track, int *kind);
+int Check_Track(DAZZ_DB *db, char *track, int *kind);
 
   // If track is not already in the db's track list, then allocate all the storage for it,
   //   read it in from the appropriate file, add it to the track list, and return a pointer
-  //   to the newly created HITS_TRACK record.  If the track does not exist or cannot be
+  //   to the newly created DAZZ_TRACK record.  If the track does not exist or cannot be
   //   opened for some reason, then NULL is returned if INTERACTIVE is defined.  Otherwise
   //   the routine prints an error message to stderr and exits if an error occurs, and returns
   //   with NULL only if the track does not exist.
 
-HITS_TRACK *Load_Track(HITS_DB *db, char *track);
+DAZZ_TRACK *Load_Track(DAZZ_DB *db, char *track);
+
+  // Assumming file pointer for afile is correctly positioned at the start of a extra item,
+  //   and aname is the name of the .anno file, decode the value present and places it in
+  //   extra if extra->nelem == 0, otherwise reduce the value just read into extra according
+  //   according the to the directive given by 'accum'.  Leave the read poinrt at the next
+  //   extra or end-of-file.
+  //   Returns:
+  //      1 if at the end of file,
+  //      0 if item was read and folded correctly,
+  //     -1 if there was a system IO or allocation error (if interactive), and
+  //     -2 if the new value could not be reduced into the currenct value of extra (interactive)
+
+int Read_Extra(FILE *afile, char *aname, DAZZ_EXTRA *extra);
+
+//  Write extra record to end of file afile and advance write pointer
+//  If interactive, then return non-zero on error, if bash, then print
+//  and halt if an error
+
+int Write_Extra(FILE *afile, DAZZ_EXTRA *extra);
 
   // If track is on the db's track list, then it is removed and all storage associated with it
   //   is freed.
 
-void Close_Track(HITS_DB *db, char *track);
+void Close_Track(DAZZ_DB *db, char *track);
 
   // Allocate and return a buffer big enough for the largest read in 'db'.
   // **NB** free(x-1) if x is the value returned as *prefix* and suffix '\0'(4)-byte
   // are needed by the alignment algorithms.  If cannot allocate memory then return NULL
   // if INTERACTIVE is defined, or print error to stderr and exit otherwise.
 
-char *New_Read_Buffer(HITS_DB *db);
+char *New_Read_Buffer(DAZZ_DB *db);
 
   // Load into 'read' the i'th read in 'db'.  As a lower case ascii string if ascii is 1, an
   //   upper case ascii string if ascii is 2, and a numeric string over 0(A), 1(C), 2(G), and 3(T)
@@ -373,12 +511,12 @@ char *New_Read_Buffer(HITS_DB *db);
   //   for traversals in either direction.  A non-zero value is returned if an error occured
   //   and INTERACTIVE is defined.
 
-int  Load_Read(HITS_DB *db, int i, char *read, int ascii);
+int  Load_Read(DAZZ_DB *db, int i, char *read, int ascii);
 
   // Exactly the same as Load_Read, save the arrow information is loaded, not the DNA sequence,
   //   and there is only a choice between numeric (0) or ascii (1);
 
-int  Load_Arrow(HITS_DB *db, int i, char *read, int ascii);
+int  Load_Arrow(DAZZ_DB *db, int i, char *read, int ascii);
 
   // Load into 'read' the subread [beg,end] of the i'th read in 'db' and return a pointer to the
   //   the start of the subinterval (not necessarily = to read !!! ).  As a lower case ascii
@@ -387,7 +525,7 @@ int  Load_Arrow(HITS_DB *db, int i, char *read, int ascii);
   //   the string holding the substring so it has a delimeter for traversals in either direction.
   //   A NULL pointer is returned if an error occured and INTERACTIVE is defined.
 
-char *Load_Subread(HITS_DB *db, int i, int beg, int end, char *read, int ascii);
+char *Load_Subread(DAZZ_DB *db, int i, int beg, int end, char *read, int ascii);
 
   // Allocate a set of 5 vectors large enough to hold the longest QV stream that will occur
   //   in the database.  If cannot allocate memory then return NULL if INTERACTIVE is defined,
@@ -399,13 +537,13 @@ char *Load_Subread(HITS_DB *db, int i, int beg, int end, char *read, int ascii);
 #define SUB_QV  3   //  The substitution QVs
 #define MRG_QV  4   //  The merge QVs
 
-char **New_QV_Buffer(HITS_DB *db);
+char **New_QV_Buffer(DAZZ_DB *db);
 
   // Load into 'entry' the 5 QV vectors for i'th read in 'db'.  The deletion tag or characters
   //   are converted to a numeric or upper/lower case ascii string as per ascii.  Return with
   //   a zero, except when an error occurs and INTERACTIVE is defined in which case return wtih 1.
 
-int   Load_QVentry(HITS_DB *db, int i, char **entry, int ascii);
+int   Load_QVentry(DAZZ_DB *db, int i, char **entry, int ascii);
 
   // Allocate a block big enough for all the uncompressed sequences, read them into it,
   //   reset the 'off' in each read record to be its in-memory offset, and set the
@@ -415,7 +553,7 @@ int   Load_QVentry(HITS_DB *db, int i, char **entry, int ascii);
   //   Return with a zero, except when an error occurs and INTERACTIVE is defined in which
   //   case return wtih 1.
 
-int Read_All_Sequences(HITS_DB *db, int ascii);
+int Read_All_Sequences(DAZZ_DB *db, int ascii);
 
   // For the DB or DAM "path" = "prefix/root.[db|dam]", find all the files for that DB, i.e. all
   //   those of the form "prefix/[.]root.part" and call actor with the complete path to each file
@@ -429,4 +567,4 @@ int Read_All_Sequences(HITS_DB *db, int ascii);
 
 int List_DB_Files(char *path, void actor(char *path, char *extension));
 
-#endif // _HITS_DB
+#endif // _DAZZ_DB
diff --git a/DB2arrow.c b/DB2arrow.c
index 9247ab4..254c9b7 100644
--- a/DB2arrow.c
+++ b/DB2arrow.c
@@ -16,8 +16,9 @@
 static char *Usage = "[-v] [-w<int(80)>] <path:db>";
 
 int main(int argc, char *argv[])
-{ HITS_DB    _db, *db = &_db;
+{ DAZZ_DB    _db, *db = &_db;
   FILE       *dbfile;
+  char       *dbfile_name;
   int         VERBOSE, WIDTH;
 
   //  Process arguments
@@ -49,6 +50,8 @@ int main(int argc, char *argv[])
 
     if (argc != 2)
       { fprintf(stderr,"Usage: %s %s\n",Prog_Name,Usage);
+        fprintf(stderr,"\n");
+        fprintf(stderr,"      -w: Print -w bp per line (default is 80).\n");
         exit (1);
       }
   }
@@ -74,25 +77,25 @@ int main(int argc, char *argv[])
         exit (1);
       }
 
-    pwd    = PathTo(argv[1]);
-    root   = Root(argv[1],".db");
-    dbfile = Fopen(Catenate(pwd,"/",root,".db"),"r");
+    pwd         = PathTo(argv[1]);
+    root        = Root(argv[1],".db");
+    dbfile_name = Strdup(Catenate(pwd,"/",root,".db"),"Allocting db file name");
+    dbfile      = Fopen(dbfile_name,"r");
     free(pwd);
     free(root);
-    if (dbfile == NULL)
+    if (dbfile_name == NULL || dbfile == NULL)
       exit (1);
   }
 
   //  For each cell do:
 
-  { HITS_READ  *reads;
+  { DAZZ_READ  *reads;
     char        lname[MAX_NAME];
     FILE       *ofile = NULL;
     int         f, first, last, ofirst, nfiles;
     char       *read;
 
-    if (fscanf(dbfile,DB_NFILE,&nfiles) != 1)
-      SYSTEM_ERROR
+    FSCANF(dbfile,DB_NFILE,&nfiles)
 
     reads = db->reads;
     read  = New_Read_Buffer(db);
@@ -103,8 +106,7 @@ int main(int argc, char *argv[])
 
         //  Scan db image file line, create .arrow file for writing
 
-        if (fscanf(dbfile,DB_FDATA,&last,fname,prolog) != 3)
-          SYSTEM_ERROR
+        FSCANF(dbfile,DB_FDATA,&last,fname,prolog)
 
         if (f == 0 || strcmp(fname,lname) != 0)
           { if (f > 0)
@@ -113,7 +115,7 @@ int main(int argc, char *argv[])
                     fflush(stderr);
                   }
                 else
-                  fclose(ofile);
+                  FCLOSE(ofile)
               }
 
             if (strcmp(fname,"stdout") == 0)
@@ -145,7 +147,7 @@ int main(int argc, char *argv[])
           { int        j, len;
             uint64     big;
             float      snr[4];
-            HITS_READ *r;
+            DAZZ_READ *r;
 
             r     = reads + i;
             len   = r->rlen;
@@ -154,16 +156,17 @@ int main(int argc, char *argv[])
               { snr[3-j] = (big & 0xffff) / 100.;
                 big    >>= 16;
               }
-            fprintf(ofile,">%s",prolog);
-            fprintf(ofile," SN=%.2f,%.2f,%.2f,%.2f",snr[0],snr[1],snr[2],snr[3]);
-            fprintf(ofile,"\n");
+
+            FPRINTF(ofile,">%s",prolog)
+            FPRINTF(ofile," SN=%.2f,%.2f,%.2f,%.2f",snr[0],snr[1],snr[2],snr[3])
+            FPRINTF(ofile,"\n")
 
             Load_Arrow(db,i,read,1);
 
             for (j = 0; j+WIDTH < len; j += WIDTH)
-              fprintf(ofile,"%.*s\n",WIDTH,read+j);
+              FPRINTF(ofile,"%.*s\n",WIDTH,read+j)
             if (j < len)
-              fprintf(ofile,"%s\n",read+j);
+              FPRINTF(ofile,"%s\n",read+j)
           }
 
         first = last;
@@ -175,7 +178,7 @@ int main(int argc, char *argv[])
             fflush(stderr);
           }
         else
-          fclose(ofile);
+          FCLOSE(ofile)
       }
   }
 
diff --git a/DB2fasta.c b/DB2fasta.c
index eb769be..24625d3 100644
--- a/DB2fasta.c
+++ b/DB2fasta.c
@@ -16,8 +16,9 @@
 static char *Usage = "[-vU] [-w<int(80)>] <path:db>";
 
 int main(int argc, char *argv[])
-{ HITS_DB    _db, *db = &_db;
+{ DAZZ_DB    _db, *db = &_db;
   FILE       *dbfile;
+  char       *dbfile_name;
   int         VERBOSE, UPPER, WIDTH;
 
   //  Process arguments
@@ -50,6 +51,9 @@ int main(int argc, char *argv[])
 
     if (argc != 2)
       { fprintf(stderr,"Usage: %s %s\n",Prog_Name,Usage);
+        fprintf(stderr,"\n");
+        fprintf(stderr,"      -U: Use upper case for DNA (default is lower case).\n");
+        fprintf(stderr,"      -w: Print -w bp per line (default is 80).\n");
         exit (1);
       }
   }
@@ -71,25 +75,25 @@ int main(int argc, char *argv[])
         exit (1);
       }
 
-    pwd    = PathTo(argv[1]);
-    root   = Root(argv[1],".db");
-    dbfile = Fopen(Catenate(pwd,"/",root,".db"),"r");
+    pwd         = PathTo(argv[1]);
+    root        = Root(argv[1],".db");
+    dbfile_name = Strdup(Catenate(pwd,"/",root,".db"),"Allocating db file name");
+    dbfile      = Fopen(dbfile_name,"r");
     free(pwd);
     free(root);
-    if (dbfile == NULL)
+    if (dbfile_name == NULL || dbfile == NULL)
       exit (1);
   }
 
   //  For each cell do:
 
-  { HITS_READ  *reads;
+  { DAZZ_READ  *reads;
     char        lname[MAX_NAME];
     FILE       *ofile = NULL;
     int         f, first, last, ofirst, nfiles;
     char       *read;
 
-    if (fscanf(dbfile,DB_NFILE,&nfiles) != 1)
-      SYSTEM_ERROR
+    FSCANF(dbfile,DB_NFILE,&nfiles)
 
     reads = db->reads;
     read  = New_Read_Buffer(db);
@@ -100,8 +104,7 @@ int main(int argc, char *argv[])
 
         //  Scan db image file line, create .fasta file for writing
 
-        if (fscanf(dbfile,DB_FDATA,&last,fname,prolog) != 3)
-          SYSTEM_ERROR
+        FSCANF(dbfile,DB_FDATA,&last,fname,prolog)
 
         if (f == 0 || strcmp(fname,lname) != 0)
           { if (f > 0)
@@ -110,7 +113,7 @@ int main(int argc, char *argv[])
                     fflush(stderr);
                   }
                 else
-                  fclose(ofile);
+                  FCLOSE(ofile)
               }
 
             if (strcmp(fname,"stdout") == 0)
@@ -141,23 +144,23 @@ int main(int argc, char *argv[])
         for (i = first; i < last; i++)
           { int        j, len;
             int        flags, qv;
-            HITS_READ *r;
+            DAZZ_READ *r;
 
             r     = reads + i;
             len   = r->rlen;
             flags = r->flags;
             qv    = (flags & DB_QV);
-            fprintf(ofile,">%s/%d/%d_%d",prolog,r->origin,r->fpulse,r->fpulse+len);
+            FPRINTF(ofile,">%s/%d/%d_%d",prolog,r->origin,r->fpulse,r->fpulse+len)
             if (qv > 0)
-              fprintf(ofile," RQ=0.%3d",qv);
-            fprintf(ofile,"\n");
+              FPRINTF(ofile," RQ=0.%3d",qv)
+            FPRINTF(ofile,"\n")
 
             Load_Read(db,i,read,UPPER);
 
             for (j = 0; j+WIDTH < len; j += WIDTH)
-              fprintf(ofile,"%.*s\n",WIDTH,read+j);
+              FPRINTF(ofile,"%.*s\n",WIDTH,read+j)
             if (j < len)
-              fprintf(ofile,"%s\n",read+j);
+              FPRINTF(ofile,"%s\n",read+j)
           }
 
         first = last;
@@ -169,7 +172,7 @@ int main(int argc, char *argv[])
             fflush(stderr);
           }
         else
-          fclose(ofile);
+          FCLOSE(ofile)
       }
   }
 
diff --git a/DB2quiva.c b/DB2quiva.c
index 45c5cff..0590063 100644
--- a/DB2quiva.c
+++ b/DB2quiva.c
@@ -23,8 +23,9 @@
 static char *Usage = "[-vU] <path:db>";
 
 int main(int argc, char *argv[])
-{ HITS_DB    _db, *db = &_db;
+{ DAZZ_DB    _db, *db = &_db;
   FILE       *dbfile, *quiva;
+  char       *dbfile_name;
   int         VERBOSE, UPPER;
 
   //  Process arguments
@@ -47,6 +48,8 @@ int main(int argc, char *argv[])
 
     if (argc != 2)
       { fprintf(stderr,"Usage: %s %s\n",Prog_Name,Usage);
+        fprintf(stderr,"\n");
+        fprintf(stderr,"      -U: Use upper case for DNA (default is lower case).\n");
         exit (1);
       }
   }
@@ -72,27 +75,27 @@ int main(int argc, char *argv[])
         exit (1);
       }
 
-    pwd    = PathTo(argv[1]);
-    root   = Root(argv[1],".db");
-    dbfile = Fopen(Catenate(pwd,"/",root,".db"),"r");
-    quiva  = Fopen(Catenate(pwd,PATHSEP,root,".qvs"),"r");
+    pwd         = PathTo(argv[1]);
+    root        = Root(argv[1],".db");
+    dbfile_name = Strdup(Catenate(pwd,"/",root,".db"),"Allocating db file name");
+    dbfile      = Fopen(dbfile_name,"r");
+    quiva       = Fopen(Catenate(pwd,PATHSEP,root,".qvs"),"r");
     free(pwd);
     free(root);
-    if (dbfile == NULL || quiva == NULL)
+    if (dbfile_name == NULL || dbfile == NULL || quiva == NULL)
       exit (1);
   }
 
   //  For each cell do:
 
-  { HITS_READ  *reads;
+  { DAZZ_READ  *reads;
     char        lname[MAX_NAME];
     FILE       *ofile = NULL;
     int         f, first, last, ofirst, nfiles;
     QVcoding   *coding;
     char      **entry;
 
-    if (fscanf(dbfile,DB_NFILE,&nfiles) != 1)
-      SYSTEM_ERROR
+    FSCANF(dbfile,DB_NFILE,&nfiles)
 
     reads = db->reads;
     entry = New_QV_Buffer(db);
@@ -105,8 +108,7 @@ int main(int argc, char *argv[])
 
         if (reads[first].coff < 0) break;
 
-        if (fscanf(dbfile,DB_FDATA,&last,fname,prolog) != 3)
-          SYSTEM_ERROR
+        FSCANF(dbfile,DB_FDATA,&last,fname,prolog)
 
         if (f == 0 || strcmp(fname,lname) != 0)
           { if (f > 0)
@@ -115,7 +117,7 @@ int main(int argc, char *argv[])
                     fflush(stderr);
                   }
                 else
-                  fclose(ofile);
+                  FCLOSE(ofile)
               }
 
             if (strcmp(fname,"stdout") == 0)
@@ -147,16 +149,16 @@ int main(int argc, char *argv[])
 
         for (i = first; i < last; i++)
           { int        e, flags, qv, rlen;
-            HITS_READ *r;
+            DAZZ_READ *r;
 
             r     = reads + i;
             flags = r->flags;
             rlen  = r->rlen;
             qv    = (flags & DB_QV);
-            fprintf(ofile,"@%s/%d/%d_%d",prolog,r->origin,r->fpulse,r->fpulse+rlen);
+            FPRINTF(ofile,"@%s/%d/%d_%d",prolog,r->origin,r->fpulse,r->fpulse+rlen)
             if (qv > 0)
-              fprintf(ofile," RQ=0.%3d",qv);
-            fprintf(ofile,"\n");
+              FPRINTF(ofile," RQ=0.%3d",qv)
+            FPRINTF(ofile,"\n")
 
             Uncompress_Next_QVentry(quiva,entry,coding,rlen);
 
@@ -169,7 +171,7 @@ int main(int argc, char *argv[])
               }
 
             for (e = 0; e < 5; e++)
-              fprintf(ofile,"%.*s\n",rlen,entry[e]);
+              FPRINTF(ofile,"%.*s\n",rlen,entry[e])
           }
 
         first = last;
@@ -181,7 +183,7 @@ int main(int argc, char *argv[])
             fflush(stderr);
           }
         else
-          fclose(ofile);
+          FCLOSE(ofile)
       }
   }
 
diff --git a/DBdump.c b/DBdump.c
index faef253..12b0eb4 100644
--- a/DBdump.c
+++ b/DBdump.c
@@ -21,7 +21,7 @@
 #endif
 
 static char *Usage[] =
-    { "[-rhsaiqp] [-uU] [-m<track>]+",
+    { "[-rhsaiqp] [-uU] [-m<mask>]+",
       "           <path:db|dam> [ <reads:FILE> | <reads:range> ... ]"
     };
 
@@ -55,7 +55,7 @@ int next_read(File_Iterator *it)
   if (fgets(nbuffer,MAX_BUFFER,it->input) == NULL)
     { if (feof(it->input))
         return (1);
-      SYSTEM_ERROR;
+      SYSTEM_READ_ERROR;
     }
   if ((eol = index(nbuffer,'\n')) == NULL)
     { fprintf(stderr,"%s: Line %d in read list is longer than %d chars!\n",
@@ -92,13 +92,14 @@ static int prof_map[41] =
   };
 
 int main(int argc, char *argv[])
-{ HITS_DB    _db, *db = &_db;
+{ DAZZ_DB    _db, *db = &_db;
   int         Quiva_DB, Arrow_DB;
-  FILE       *hdrs = NULL;
-  int64      *qv_idx = NULL;
-  uint8      *qv_val = NULL;
-  int64      *pf_idx = NULL;
-  uint8      *pf_val = NULL;
+  FILE       *hdrs      = NULL;
+  char       *hdrs_name = NULL;
+  int64      *qv_idx    = NULL;
+  uint8      *qv_val    = NULL;
+  int64      *pf_idx    = NULL;
+  uint8      *pf_val    = NULL;
 
   int         nfiles;
   char      **flist = NULL;
@@ -115,7 +116,7 @@ int main(int argc, char *argv[])
 
   int          MMAX, MTOP;
   char       **MASK;
-  HITS_TRACK **MTRACK;
+  DAZZ_TRACK **MTRACK;
 
   //  Process arguments
 
@@ -173,14 +174,16 @@ int main(int argc, char *argv[])
         fprintf(stderr,"      -s: S # string       - sequence string\n");
         fprintf(stderr,"      -a: N # # # #        - SNR of ACGT channels (#/100)\n");
         fprintf(stderr,"          A # string       - arrow pulse-width string\n");
-        fprintf(stderr,"      -i: I # string       - intrinsic quality vector (as an ASCII string)\n");
+        fprintf(stderr,"      -i: I # string       ");
+        fprintf(stderr,"- intrinsic quality vector (as an ASCII string)\n");
         fprintf(stderr,"      -q: d # string       - Quiva deletion values (as an ASCII string)\n");
         fprintf(stderr,"          c # string       - Quiva deletion character string\n");
         fprintf(stderr,"          i # string       - Quiva insertion value string\n");
         fprintf(stderr,"          m # string       - Quiva merge value string\n");
         fprintf(stderr,"          s # string       - Quiva substitution value string\n");
         fprintf(stderr,"      -p: P # string       - repeat profile vector (as an ASCII string)\n");
-        fprintf(stderr,"      -m: Tx #n (#b #e)^#n - x'th track on command line, #n intervals all on same line\n");
+        fprintf(stderr,"      -m: Tx #n (#b #e)^#n ");
+        fprintf(stderr,"- x'th track on command line, #n intervals all on same line\n");
         fprintf(stderr,"\n");
         fprintf(stderr,"      -u: Dump entire untrimmed database.\n");
         fprintf(stderr,"      -U: Output base pairs in upper case letters\n");
@@ -211,7 +214,8 @@ int main(int argc, char *argv[])
 
         if (db->part > 0)
           *rindex(root,'.') = '\0';
-        hdrs = Fopen(Catenate(pwd,PATHSEP,root,".hdr"),"r");
+        hdrs_name = Strdup(Catenate(pwd,PATHSEP,root,".hdr"),"Allocating header file name");
+        hdrs      = Fopen(hdrs_name,"r");
         if (hdrs == NULL)
           exit (1);
         DAM = 1;
@@ -257,7 +261,7 @@ int main(int argc, char *argv[])
 
   { int i, status, kind;
 
-    MTRACK = Malloc(sizeof(HITS_TRACK *)*MTOP,"Allocation of track pointer vector");
+    MTRACK = Malloc(sizeof(DAZZ_TRACK *)*MTOP,"Allocation of track pointer vector");
     if (MTRACK == NULL)
       exit (1);
 
@@ -291,20 +295,21 @@ int main(int argc, char *argv[])
   if (!DAM)
     { char *pwd, *root;
       FILE *dstub;
+      char *dstub_name;
       int   i;
 
       root   = Root(argv[1],".db");
       pwd    = PathTo(argv[1]);
       if (db->part > 0)
         *rindex(root,'.') = '\0';
-      dstub  = Fopen(Catenate(pwd,"/",root,".db"),"r");
-      if (dstub == NULL)
+      dstub_name = Strdup(Catenate(pwd,"/",root,".db"),"Allocating db file name");
+      dstub      = Fopen(dstub_name,"r");
+      if (dstub_name == NULL || dstub == NULL)
         exit (1);
       free(pwd);
       free(root);
 
-      if (fscanf(dstub,DB_NFILE,&nfiles) != 1)
-        SYSTEM_ERROR
+      FSCANF(dstub,DB_NFILE,&nfiles)
 
       flist = (char **) Malloc(sizeof(char *)*nfiles,"Allocating file list");
       findx = (int *) Malloc(sizeof(int *)*(nfiles+1),"Allocating file index");
@@ -317,12 +322,12 @@ int main(int argc, char *argv[])
       for (i = 0; i < nfiles; i++)
         { char prolog[MAX_NAME], fname[MAX_NAME];
   
-          if (fscanf(dstub,DB_FDATA,findx+i,fname,prolog) != 3)
-            SYSTEM_ERROR
+          FSCANF(dstub,DB_FDATA,findx+i,fname,prolog)
           if ((flist[i] = Strdup(prolog,"Adding to file list")) == NULL)
             exit (1);
         }
 
+      free(dstub_name);
       fclose(dstub);
 
       //  If TRIM (the default) then "trim" prolog ranges and the DB
@@ -330,7 +335,7 @@ int main(int argc, char *argv[])
       if (TRIM)
         { int        nid, oid, lid;
           int        cutoff, allflag;
-          HITS_READ *reads;
+          DAZZ_READ *reads;
 
           reads  = db->reads - db->ufirst;
           cutoff = db->cutoff;
@@ -376,7 +381,7 @@ int main(int argc, char *argv[])
 
   if (DOIQV)
     { int         status, kind;
-      HITS_TRACK *track;
+      DAZZ_TRACK *track;
 
       status = Check_Track(db,"qual",&kind);
       if (status == -2)
@@ -394,7 +399,7 @@ int main(int argc, char *argv[])
 
   if (DOPRF)
     { int         status, kind;
-      HITS_TRACK *track;
+      DAZZ_TRACK *track;
 
       status = Check_Track(db,"prof",&kind);
       if (status == -2)
@@ -498,7 +503,7 @@ int main(int argc, char *argv[])
 
   //  Scan to count the size of things
 
-  { HITS_READ  *reads;
+  { DAZZ_READ  *reads;
     int         c, b, e, i, m;
     int         map, substr;
     int64       noreads;
@@ -549,7 +554,7 @@ int main(int argc, char *argv[])
         for (i = b; i < e; i++)
           { int         len, ten;
             int         fst, lst;
-            HITS_READ  *r;
+            DAZZ_READ  *r;
 
             r   = reads + i;
             len = r->rlen;
@@ -562,8 +567,8 @@ int main(int argc, char *argv[])
                 if (DAM)
                   { char header[MAX_NAME];
 
-                    fseeko(hdrs,r->coff,SEEK_SET);
-                    fgets(header,MAX_NAME,hdrs);
+                    FSEEKO(hdrs,r->coff,SEEK_SET)
+                    FGETS(header,MAX_NAME,hdrs)
                     header[strlen(header)-1] = '\0';
                     ten = strlen(header);
                   }
@@ -627,34 +632,34 @@ int main(int argc, char *argv[])
           }
       }
 
-    printf("+ R %lld\n",noreads);
-    printf("+ M %d\n",MTOP);
+    PRINTF("+ R %lld\n",noreads)
+    PRINTF("+ M %d\n",MTOP)
     if (DOHDR)
-      { printf("+ H %lld\n",hdrtot);
-        printf("@ H %lld\n",hdrmax);
+      { PRINTF("+ H %lld\n",hdrtot)
+        PRINTF("@ H %lld\n",hdrmax)
       }
     for (m = 0; m < MTOP; m++)
-      { printf("+ T%d %lld\n",m,trktot[m]);
-        printf("@ T%d %lld\n",m,trkmax[m]);
+      { PRINTF("+ T%d %lld\n",m,trktot[m])
+        PRINTF("@ T%d %lld\n",m,trkmax[m])
       }
     if (DOSEQ | DOQVS | DOARW)
-      { printf("+ S %lld\n",seqtot);
-        printf("@ S %lld\n",seqmax);
+      { PRINTF("+ S %lld\n",seqtot)
+        PRINTF("@ S %lld\n",seqmax)
       }
     if (DOIQV)
-      { printf("+ I %lld\n",iqvtot);
-        printf("@ I %lld\n",iqvmax);
+      { PRINTF("+ I %lld\n",iqvtot)
+        PRINTF("@ I %lld\n",iqvmax)
       }
     if (DOPRF)
-      { printf("+ P %lld\n",prftot);
-        printf("@ P %lld\n",prfmax);
+      { PRINTF("+ P %lld\n",prftot)
+        PRINTF("@ P %lld\n",prfmax)
       }
   }
 
   //  Display each read (and/or QV streams) in the active DB according to the
   //    range pairs in pts[0..reps) and according to the display options.
 
-  { HITS_READ  *reads;
+  { DAZZ_READ  *reads;
     char       *read, *arrow, **entry;
     int         c, b, e, i, m;
     int         substr;
@@ -703,7 +708,7 @@ int main(int argc, char *argv[])
           { int         len;
             int         fst, lst;
             int         flags, qv;
-            HITS_READ  *r;
+            DAZZ_READ  *r;
 
             r   = reads + i;
             len = r->rlen;
@@ -716,21 +721,21 @@ int main(int argc, char *argv[])
               { if (DAM)
                   { char header[MAX_NAME];
 
-                    fseeko(hdrs,r->coff,SEEK_SET);
-                    fgets(header,MAX_NAME,hdrs);
+                    FSEEKO(hdrs,r->coff,SEEK_SET)
+                    FGETS(header,MAX_NAME,hdrs)
                     header[strlen(header)-1] = '\0';
-                    printf("H %ld %s\n",strlen(header),header);
-                    printf("L %d %d %d\n",r->origin,r->fpulse,r->fpulse+len);
+                    PRINTF("H %ld %s\n",strlen(header),header)
+                    PRINTF("L %d %d %d\n",r->origin,r->fpulse,r->fpulse+len)
                   }
                 else
                   { while (i < findx[map-1])
                       map -= 1;
                     while (i >= findx[map])
                       map += 1;
-                    printf("H %ld %s\n",strlen(flist[map]),flist[map]);
-                    printf("L %d %d %d\n",r->origin,r->fpulse,r->fpulse+len);
+                    PRINTF("H %ld %s\n",strlen(flist[map]),flist[map])
+                    PRINTF("L %d %d %d\n",r->origin,r->fpulse,r->fpulse+len)
                     if (Quiva_DB && qv > 0)
-                      printf("Q %d\n",qv);
+                      PRINTF("Q %d\n",qv)
                     else if (Arrow_DB)
                       { int   j, snr[4];
                         int64 big;
@@ -740,7 +745,7 @@ int main(int argc, char *argv[])
                           { snr[3-j] = (big & 0xffff);
                             big    >>= 16;
                           }
-                        printf("N %d %d %d %d\n",snr[0],snr[1],snr[2],snr[3]);
+                        PRINTF("N %d %d %d %d\n",snr[0],snr[1],snr[2],snr[3])
                       }
                   }
               }
@@ -762,12 +767,12 @@ int main(int argc, char *argv[])
 
                 s = (anno[i] >> 2);
                 f = (anno[i+1] >> 2);
-                printf("T%d %lld ",m,(f-s)/2);
+                PRINTF("T%d %lld ",m,(f-s)/2)
                 if (s < f)
                   { for (j = s; j < f; j += 2)
-                      printf(" %d %d",data[j],data[j+1]);
+                      PRINTF(" %d %d",data[j],data[j+1])
                   }
-                printf("\n");
+                PRINTF("\n")
               }
 
             if (substr)
@@ -780,13 +785,13 @@ int main(int argc, char *argv[])
               }
 
             if (DOSEQ)
-              { printf("S %d ",lst-fst);
-                printf("%.*s\n",lst-fst,read+fst);
+              { PRINTF("S %d ",lst-fst)
+                PRINTF("%.*s\n",lst-fst,read+fst)
               }
 
             if (DOARW)
-              { printf("A %d ",lst-fst);
-                printf("%.*s\n",lst-fst,arrow+fst);
+              { PRINTF("A %d ",lst-fst)
+                PRINTF("%.*s\n",lst-fst,arrow+fst)
               }
 
             if (DOIQV)
@@ -794,10 +799,12 @@ int main(int argc, char *argv[])
 
                 k = qv_idx[i];
                 e = qv_idx[i+1];
-                printf("I %lld ",e-k);
+                PRINTF("I %lld ",e-k)
                 while (k < e)
-                  putchar(qv_map[qv_val[k++]]);
-                printf("\n");
+                  { if (putchar(qv_map[qv_val[k++]]) == EOF)
+                      SYSTEM_WRITE_ERROR
+                  }
+                PRINTF("\n")
               }
 
             if (DOPRF)
@@ -805,24 +812,28 @@ int main(int argc, char *argv[])
 
                 k = pf_idx[i];
                 e = pf_idx[i+1];
-                printf("P %lld ",e-k);
+                PRINTF("P %lld ",e-k)
                 while (k < e)
-                  putchar(prof_map[pf_val[k++]]);
-                printf("\n");
+                  { if (putchar(prof_map[pf_val[k++]]) == EOF)
+                      SYSTEM_WRITE_ERROR
+                  }
+                PRINTF("\n")
               }
 
             if (DOQVS)
               { int k;
 
                 for (k = 0; k < 5; k++)
-                  { printf("%c %d ",qvname[k],lst-fst);
-                    printf("%.*s\n",lst-fst,entry[k]+fst);
+                  { PRINTF("%c %d ",qvname[k],lst-fst)
+                    PRINTF("%.*s\n",lst-fst,entry[k]+fst)
                   }
               }
           }
       }
   }
 
+  FCLOSE(stdout)
+
   if (input_pts)
     { fclose(input);
       free(iter);
diff --git a/DBdust.c b/DBdust.c
index 3b75400..3f712a2 100644
--- a/DBdust.c
+++ b/DBdust.c
@@ -43,7 +43,7 @@ typedef struct _cand
   } Candidate;
 
 int main(int argc, char *argv[])
-{ HITS_DB   _db, *db = &_db;
+{ DAZZ_DB   _db, *db = &_db;
   FILE      *afile, *dfile;
   int64      indx;
   int        nreads;
@@ -95,6 +95,11 @@ int main(int argc, char *argv[])
 
     if (argc != 2)
       { fprintf(stderr,"Usage: %s %s\n",Prog_Name,Usage);
+        fprintf(stderr,"\n");
+        fprintf(stderr,"      -w: DUST algorithm window size.\n");
+        fprintf(stderr,"      -t: DUST algorithm threshold.\n");
+        fprintf(stderr,"      -m: Record only low-complexity intervals >= this size.\n");
+        fprintf(stderr,"      -b: Take into account base composition bias.\n");
         exit (1);
       }
   }
@@ -128,29 +133,29 @@ int main(int argc, char *argv[])
         dfile = Fopen(Catenate(pwd,PATHSEP,root,".dust.data"),"w");
         if (dfile == NULL || afile == NULL)
           exit (1);
-        fwrite(&(db->nreads),sizeof(int),1,afile);
-        fwrite(&size,sizeof(int),1,afile);
+        FWRITE(&(db->nreads),sizeof(int),1,afile)
+        FWRITE(&size,sizeof(int),1,afile)
         nreads = 0;
         indx = 0;
-        fwrite(&indx,sizeof(int64),1,afile);
+        FWRITE(&indx,sizeof(int64),1,afile)
       }
     else
       { dfile = Fopen(Catenate(pwd,PATHSEP,root,".dust.data"),"r+");
         if (dfile == NULL)
           exit (1);
         if (fread(&nreads,sizeof(int),1,afile) != 1)
-          SYSTEM_ERROR
+          SYSTEM_READ_ERROR
         if (nreads >= db->nreads)
           { fclose(afile);
             fclose(dfile);
             exit(0);
           }
-        fseeko(afile,0,SEEK_SET);
-        fwrite(&(db->nreads),sizeof(int),1,afile);
-        fwrite(&size,sizeof(int),1,afile);
-        fseeko(afile,0,SEEK_END);
-        fseeko(dfile,0,SEEK_END);
-        indx = ftello(dfile);
+        FSEEKO(afile,0,SEEK_SET)
+        FWRITE(&(db->nreads),sizeof(int),1,afile)
+        FWRITE(&size,sizeof(int),1,afile)
+        FSEEKO(afile,0,SEEK_END)
+        FSEEKO(dfile,0,SEEK_END)
+        indx = FTELLO(dfile);
       }
 
     free(pwd);
@@ -430,8 +435,8 @@ int main(int argc, char *argv[])
               }
           mtop  = mask + ntop;
           indx += ntop*sizeof(int);
-          fwrite(&indx,sizeof(int64),1,afile);
-          fwrite(mask1,sizeof(int),ntop,dfile);
+          FWRITE(&indx,sizeof(int64),1,afile)
+          FWRITE(mask1,sizeof(int),ntop,dfile)
         }
 
 #ifdef DEBUG
@@ -462,8 +467,8 @@ int main(int argc, char *argv[])
       }
   }
 
-  fclose(afile);
-  fclose(dfile);
+  FCLOSE(afile)
+  FCLOSE(dfile)
 
   Close_DB(db);
 
diff --git a/DBmv.c b/DBmv.c
new file mode 100644
index 0000000..b255ae2
--- /dev/null
+++ b/DBmv.c
@@ -0,0 +1,95 @@
+/********************************************************************************************
+ *
+ *  Remove a list of .db databases
+ *     Delete all the files for the given data bases <name>.db ... (there are a couple
+ *     of hidden . files for each DB, and these are removed too.)  Do not use "rm" to
+ *     remove a database.
+ *
+ *  Author:  Gene Myers
+ *  Date  :  July 2013
+ *
+ ********************************************************************************************/
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <unistd.h>
+
+#include "DB.h"
+
+static char *Usage = "[-v] <old:db|dam> <new:db|dam>";
+
+static int   VERBOSE;
+static char *nroot;
+static char *npath;
+
+  //  We assume this program uses so little code that memory allocation checks are unecessary
+
+static char *Catenate5(char *path, char *sep1, char *root, char *sep2, char *suffix)
+{ static char *cat = NULL;
+  static int   max = -1;
+  int len;
+
+  len = strlen(path) + strlen(sep1) + strlen(root) + strlen(sep2) + strlen(suffix);
+  if (len > max)
+    { max = ((int) (1.2*len)) + 100;
+      cat = (char *) realloc(cat,max+1);
+    }
+  sprintf(cat,"%s%s%s%s%s",path,sep1,root,sep2,suffix);
+  return (cat);
+}
+
+static void HANDLER(char *path, char *exten)
+{ char *r, *n;
+  
+  r = Root(path,"");
+  if (*r == '.')
+    n = Catenate5(npath,"/.",nroot,".",exten);
+  else
+    n = Catenate5(npath,"/",nroot,".",exten);
+  if (rename(path,n) != 0)
+    fprintf(stderr,"%s: [WARNING] Couldn't rename file %s\n",Prog_Name,r);
+  else if (VERBOSE)
+    fprintf(stderr,"  Moving %s to %s\n",path,n);
+  free(r);
+}
+
+int main(int argc, char *argv[])
+{
+  //  Process arguments
+
+  { int  i, j, k;
+    int  flags[128];
+
+    ARG_INIT("DBmv")
+
+    j = 1;
+    for (i = 1; i < argc; i++)
+      if (argv[i][0] == '-')
+        { ARG_FLAGS("v") }
+      else
+        argv[j++] = argv[i];
+    argc = j;
+
+    VERBOSE = flags['v'];
+
+    if (argc != 3)
+      { fprintf(stderr,"Usage: %s %s\n",Prog_Name,Usage);
+        exit (1);
+      }
+  }
+
+  if (strcmp(argv[1]+(strlen(argv[1])-4),".dam") == 0)
+    nroot = Root(argv[2],".dam");
+  else
+    nroot = Root(argv[2],".db");
+  npath = PathTo(argv[2]);
+
+printf(" From = '%s'\n",argv[1]);
+  if (List_DB_Files(argv[1],HANDLER) < 0)
+    { fprintf(stderr,"%s: Could not find database %s\n",Prog_Name,argv[1]);
+      exit (1);
+    }
+
+  exit (0);
+}
diff --git a/DBrm.c b/DBrm.c
index 6bad19b..398e046 100644
--- a/DBrm.c
+++ b/DBrm.c
@@ -17,24 +17,49 @@
 
 #include "DB.h"
 
-static char *Usage = "<path:db|dam> ... ";
+static char *Usage = "[-v] <path:db|dam> ... ";
 
-static void HANDLER(char *path, char *name)
-{ (void) name;
-  unlink(path);
+static int VERBOSE;
+
+static void HANDLER(char *path, char *exten)
+{ (void) exten;
+  if (unlink(path) != 0)
+    fprintf(stderr,"%s: [WARNING] Couldn't delete file %s\n",Prog_Name,path);
+  else if (VERBOSE)
+    fprintf(stderr,"  Deleting %s\n",path);
 }
 
 int main(int argc, char *argv[])
-{ int   i;
+{
+  //  Process arguments
+
+  { int  i, j, k;
+    int  flags[128];
+
+    ARG_INIT("DBrm")
+
+    j = 1;
+    for (i = 1; i < argc; i++)
+      if (argv[i][0] == '-')
+        { ARG_FLAGS("v") }
+      else
+        argv[j++] = argv[i];
+    argc = j;
+
+    VERBOSE = flags['v'];
 
-  Prog_Name = Strdup("DBrm","");
+    if (argc <= 1)
+      { fprintf(stderr,"Usage: %s %s\n",Prog_Name,Usage);
+        exit (1);
+      }
+  }
 
-  if (argc <= 1)
-    fprintf(stderr,"Usage: %s %s\n",Prog_Name,Usage);
+  { int i;
 
-  for (i = 1; i < argc; i++)
-    if (List_DB_Files(argv[i],HANDLER) < 0)
-      fprintf(stderr,"%s: Could not list database %s\n",Prog_Name,argv[i]);
+    for (i = 1; i < argc; i++)
+      if (List_DB_Files(argv[i],HANDLER) < 0)
+        fprintf(stderr,"%s: [WARNING] Could not find database %s\n",Prog_Name,argv[i]);
+  }
 
   exit (0);
 }
diff --git a/DBshow.c b/DBshow.c
index 5114665..a31b30d 100644
--- a/DBshow.c
+++ b/DBshow.c
@@ -26,7 +26,7 @@
 #endif
 
 static char *Usage[] =
-    { "[-unqaUQA] [-w<int(80)>] [-m<track>]+",
+    { "[-unqaUQA] [-w<int(80)>] [-m<mask>]+",
       "           <path:db|dam> [ <reads:FILE> | <reads:range> ... ]"
     };
 
@@ -60,7 +60,7 @@ int next_read(File_Iterator *it)
   if (fgets(nbuffer,MAX_BUFFER,it->input) == NULL)
     { if (feof(it->input))
         return (1);
-      SYSTEM_ERROR;
+      SYSTEM_READ_ERROR;
     }
   if ((eol = index(nbuffer,'\n')) == NULL)
     { fprintf(stderr,"%s: Line %d in read list is longer than %d chars!\n",
@@ -80,8 +80,9 @@ int next_read(File_Iterator *it)
 }
 
 int main(int argc, char *argv[])
-{ HITS_DB    _db, *db = &_db;
+{ DAZZ_DB    _db, *db = &_db;
   FILE       *hdrs = NULL;
+  char       *hdrs_name = NULL;
 
   int         nfiles;
   char      **flist = NULL;
@@ -166,6 +167,19 @@ int main(int argc, char *argv[])
     if (argc <= 1)
       { fprintf(stderr,"Usage: %s %s\n",Prog_Name,Usage[0]);
         fprintf(stderr,"       %*s %s\n",(int) strlen(Prog_Name),"",Usage[1]);
+        fprintf(stderr,"\n");
+        fprintf(stderr,"      -u: Show the untrimmed database.\n");
+        fprintf(stderr,"\n");
+        fprintf(stderr,"      -q: Show also the .quiva streams.\n");
+        fprintf(stderr,"      -a: Show also the .arrow pulse sequences.\n");
+        fprintf(stderr,"      -n: Do not show the default read DNA sequences.\n");
+        fprintf(stderr,"      -m: Show mask intervals and highlight in sequence.\n");
+        fprintf(stderr,"\n");
+        fprintf(stderr,"      -Q: Produce a .quiva file (ignore all other options but -uU.\n");
+        fprintf(stderr,"      -A: Produce a .arrow file (ignore all other options but -uw.\n");
+        fprintf(stderr,"\n");
+        fprintf(stderr,"      -U: Use upper case for DNA (default is lower case).\n");
+        fprintf(stderr,"      -w: Print -w bp per line (default is 80).\n");
         exit (1);
       }
   }
@@ -184,8 +198,9 @@ int main(int argc, char *argv[])
 
         if (db->part > 0)
           *rindex(root,'.') = '\0';
-        hdrs = Fopen(Catenate(pwd,PATHSEP,root,".hdr"),"r");
-        if (hdrs == NULL)
+        hdrs_name = Strdup(Catenate(pwd,PATHSEP,root,".hdr"),"Allocating header file name");
+        hdrs      = Fopen(hdrs_name,"r");
+        if (hdrs_name == NULL || hdrs == NULL)
           exit (1);
         DAM = 1;
         if (DOQVS || DOARR)
@@ -244,20 +259,21 @@ int main(int argc, char *argv[])
   if (!DAM)
     { char *pwd, *root;
       FILE *dstub;
+      char *dstub_name;
       int   i;
 
       root   = Root(argv[1],".db");
       pwd    = PathTo(argv[1]);
       if (db->part > 0)
         *rindex(root,'.') = '\0';
-      dstub  = Fopen(Catenate(pwd,"/",root,".db"),"r");
-      if (dstub == NULL)
+      dstub_name = Strdup(Catenate(pwd,"/",root,".db"),"Allocating db file name");
+      dstub      = Fopen(dstub_name,"r");
+      if (dstub_name == NULL || dstub == NULL)
         exit (1);
       free(pwd);
       free(root);
 
-      if (fscanf(dstub,DB_NFILE,&nfiles) != 1)
-        SYSTEM_ERROR
+      FSCANF(dstub,DB_NFILE,&nfiles)
 
       flist = (char **) Malloc(sizeof(char *)*nfiles,"Allocating file list");
       findx = (int *) Malloc(sizeof(int *)*(nfiles+1),"Allocating file index");
@@ -270,20 +286,20 @@ int main(int argc, char *argv[])
       for (i = 0; i < nfiles; i++)
         { char prolog[MAX_NAME], fname[MAX_NAME];
   
-          if (fscanf(dstub,DB_FDATA,findx+i,fname,prolog) != 3)
-            SYSTEM_ERROR
+          FSCANF(dstub,DB_FDATA,findx+i,fname,prolog)
           if ((flist[i] = Strdup(prolog,"Adding to file list")) == NULL)
             exit (1);
         }
 
       fclose(dstub);
+      free(dstub_name);
 
       //  If TRIM (the default) then "trim" prolog ranges and the DB
 
       if (TRIM)
         { int        nid, oid, lid;
           int        cutoff, allflag;
-          HITS_READ *reads;
+          DAZZ_READ *reads;
 
           reads  = db->reads - db->ufirst;
           cutoff = db->cutoff;
@@ -416,8 +432,8 @@ int main(int argc, char *argv[])
   //  Display each read (and/or QV streams) in the active DB according to the
   //    range pairs in pts[0..reps) and according to the display options.
 
-  { HITS_READ  *reads;
-    HITS_TRACK *first;
+  { DAZZ_READ  *reads;
+    DAZZ_TRACK *first;
     char       *read, *arrow, **entry;
     int         c, b, e, i;
     int         hilight, substr;
@@ -475,8 +491,8 @@ int main(int argc, char *argv[])
             int         fst, lst;
             int         flags, qv;
             float       snr[4];
-            HITS_READ  *r;
-            HITS_TRACK *track;
+            DAZZ_READ  *r;
+            DAZZ_TRACK *track;
 
             r   = reads + i;
             len = r->rlen;
@@ -504,10 +520,10 @@ int main(int argc, char *argv[])
             if (DAM)
               { char header[MAX_NAME];
 
-                fseeko(hdrs,r->coff,SEEK_SET);
-                fgets(header,MAX_NAME,hdrs);
+                FSEEKO(hdrs,r->coff,SEEK_SET)
+                FGETS(header,MAX_NAME,hdrs)
                 header[strlen(header)-1] = '\0';
-                printf("%s :: Contig %d[%d,%d]",header,r->origin,r->fpulse+fst,r->fpulse+lst);
+                PRINTF("%s :: Contig %d[%d,%d]",header,r->origin,r->fpulse+fst,r->fpulse+lst)
               }
             else
               { while (i < findx[map-1])
@@ -515,17 +531,17 @@ int main(int argc, char *argv[])
                 while (i >= findx[map])
                   map += 1;
                 if (QUIVA)
-                  printf("@%s/%d/%d_%d",flist[map],r->origin,r->fpulse+fst,r->fpulse+lst);
+                  PRINTF("@%s/%d/%d_%d",flist[map],r->origin,r->fpulse+fst,r->fpulse+lst)
                 else if (ARROW)
-                  printf(">%s",flist[map]);
+                  PRINTF(">%s",flist[map])
                 else
-                  printf(">%s/%d/%d_%d",flist[map],r->origin,r->fpulse+fst,r->fpulse+lst);
+                  PRINTF(">%s/%d/%d_%d",flist[map],r->origin,r->fpulse+fst,r->fpulse+lst)
                 if (qv > 0)
-                  printf(" RQ=0.%3d",qv);
+                  PRINTF(" RQ=0.%3d",qv)
                 if (DOARR)
-                  printf(" SN=%.2f,%.2f,%.2f,%.2f",snr[0],snr[1],snr[2],snr[3]);
+                  PRINTF(" SN=%.2f,%.2f,%.2f,%.2f",snr[0],snr[1],snr[2],snr[3])
               }
-            printf("\n");
+            PRINTF("\n")
 
             if (DOQVS)
               Load_QVentry(db,i,entry,UPPER);
@@ -554,10 +570,10 @@ int main(int argc, char *argv[])
                             if (iscase(read[m]))
                               read[m] = (char) (read[m] + hilight);
                         if (j == s)
-                          printf("> %s:",track->name);
-                        printf(" [%d,%d]",bd,ed);
+                          PRINTF("> %s:",track->name)
+                        PRINTF(" [%d,%d]",bd,ed)
                       }
-                    printf("\n");
+                    PRINTF("\n")
                   }
               }
 
@@ -565,64 +581,66 @@ int main(int argc, char *argv[])
               { int k;
 
                 for (k = 0; k < 5; k++)
-                  printf("%.*s\n",lst-fst,entry[k]+fst);
+                  PRINTF("%.*s\n",lst-fst,entry[k]+fst)
               }
             else if (ARROW)
               { int k;
     
                 for (k = fst; k+WIDTH < lst; k += WIDTH)
-                  printf("%.*s\n",WIDTH,arrow+k);
+                  PRINTF("%.*s\n",WIDTH,arrow+k)
                 if (k < lst)
-                  printf("%.*s\n",lst-k,arrow+k);
+                  PRINTF("%.*s\n",lst-k,arrow+k)
               }
             else
               { if (DOQVS)
                   { int j, k;
 
-                    printf("\n");
+                    PRINTF("\n")
                     for (j = fst; j+WIDTH < lst; j += WIDTH)
                       { if (DOSEQ)
-                          printf("%.*s\n",WIDTH,read+j);
+                          PRINTF("%.*s\n",WIDTH,read+j)
                         for (k = 0; k < 5; k++)
-                          printf("%.*s\n",WIDTH,entry[k]+j);
-                        printf("\n");
+                          PRINTF("%.*s\n",WIDTH,entry[k]+j)
+                        PRINTF("\n")
                       }
                     if (j < lst)
                       { if (DOSEQ)
-                          printf("%.*s\n",lst-j,read+j);
+                          PRINTF("%.*s\n",lst-j,read+j)
                         for (k = 0; k < 5; k++)
-                          printf("%.*s\n",lst-j,entry[k]+j);
-                        printf("\n");
+                          PRINTF("%.*s\n",lst-j,entry[k]+j)
+                        PRINTF("\n")
                       }
                   }
                 else if (DOARR)
                   { int j;
 
-                    printf("\n");
+                    PRINTF("\n")
                     for (j = fst; j+WIDTH < lst; j += WIDTH)
                       { if (DOSEQ)
-                          printf("%.*s\n",WIDTH,read+j);
-                        printf("%.*s\n\n",WIDTH,arrow+j);
+                          PRINTF("%.*s\n",WIDTH,read+j)
+                        PRINTF("%.*s\n\n",WIDTH,arrow+j)
                       }
                     if (j < lst)
                       { if (DOSEQ)
-                          printf("%.*s\n",lst-j,read+j);
-                        printf("%.*s\n\n",lst-j,arrow+j);
+                          PRINTF("%.*s\n",lst-j,read+j)
+                        PRINTF("%.*s\n\n",lst-j,arrow+j)
                       }
                   }
                 else if (DOSEQ)
                   { int j;
     
                     for (j = fst; j+WIDTH < lst; j += WIDTH)
-                      printf("%.*s\n",WIDTH,read+j);
+                      PRINTF("%.*s\n",WIDTH,read+j)
                     if (j < lst)
-                      printf("%.*s\n",lst-j,read+j);
+                      PRINTF("%.*s\n",lst-j,read+j)
                   }
               }
           }
       }
   }
 
+  FCLOSE(stdout)
+
   if (input_pts)
     { fclose(input);
       free(iter);
diff --git a/DBsplit.c b/DBsplit.c
index 9ef8b77..4d44be6 100644
--- a/DBsplit.c
+++ b/DBsplit.c
@@ -32,12 +32,13 @@
 #define PATHSEP "/"
 #endif
 
-static char *Usage = "[-af] [-x<int>] [-s<float(200.)>] <path:db|dam>";
+static char *Usage = "[-af] [-x<int>] [-s<double(200.)>] <path:db|dam>";
 
 int main(int argc, char *argv[])
-{ HITS_DB    db, dbs;
+{ DAZZ_DB    db, dbs;
   int64      dbpos;
   FILE      *dbfile, *ixfile;
+  char      *dbfile_name, *ixfile_name;
   int        status;
 
   int        FORCE;
@@ -83,6 +84,11 @@ int main(int argc, char *argv[])
 
     if (argc != 2)
       { fprintf(stderr,"Usage: %s %s\n",Prog_Name,Usage);
+        fprintf(stderr,"\n");
+        fprintf(stderr,"      -s: Target size of blocks (in Mbp).\n");
+        fprintf(stderr,"      -x: Trimmed DB has reads >= this threshold.\n");
+        fprintf(stderr,"      -a: Trimmed DB contains all reads from a well (not just longest).\n");
+        fprintf(stderr,"      -f: Force the split to occur even if already split.\n");
         exit (1);
       }
   }
@@ -105,60 +111,58 @@ int main(int argc, char *argv[])
     pwd    = PathTo(argv[1]);
     if (status)
       { root   = Root(argv[1],".dam");
-        dbfile = Fopen(Catenate(pwd,"/",root,".dam"),"r+");
+        dbfile_name = Strdup(Catenate(pwd,"/",root,".dam"),"Allocating db file name");
       }
     else
       { root   = Root(argv[1],".db");
-        dbfile = Fopen(Catenate(pwd,"/",root,".db"),"r+");
+        dbfile_name = Strdup(Catenate(pwd,"/",root,".db"),"Allocating db file name");
       }
-    ixfile = Fopen(Catenate(pwd,PATHSEP,root,".idx"),"r+");
-    if (dbfile == NULL || ixfile == NULL)
+    ixfile_name = Strdup(Catenate(pwd,PATHSEP,root,".idx"),"Allocating index file name");
+    dbfile = Fopen(dbfile_name,"r+");
+    ixfile = Fopen(ixfile_name,"r+");
+    if (dbfile_name == NULL || ixfile_name == NULL || dbfile == NULL || ixfile == NULL)
       exit (1);
     free(pwd);
     free(root);
 
-    if (fscanf(dbfile,DB_NFILE,&nfiles) != 1)
-      SYSTEM_ERROR
+    FSCANF(dbfile,DB_NFILE,&nfiles)
     for (i = 0; i < nfiles; i++)
-      if (fgets(buffer,2*MAX_NAME+100,dbfile) == NULL)
-        SYSTEM_ERROR
+      FGETS(buffer,2*MAX_NAME+100,dbfile)
 
-    if (fread(&dbs,sizeof(HITS_DB),1,ixfile) != 1)
-      SYSTEM_ERROR
+    FREAD(&dbs,sizeof(DAZZ_DB),1,ixfile)
 
     if (dbs.cutoff >= 0 && !FORCE)
       { printf("You are about to overwrite the current partition settings.  This\n");
         printf("will invalidate any tracks, overlaps, and other derivative files.\n");
         printf("Are you sure you want to proceed? [Y/N] ");
         fflush(stdout);
-        if (fgets(buffer,100,stdin) == NULL)
-          SYSTEM_ERROR
+        fgets(buffer,100,stdin);
         if (index(buffer,'n') != NULL || index(buffer,'N') != NULL)
           { printf("Aborted\n");
             fflush(stdout);
             fclose(dbfile);
+            fclose(ixfile);
             exit (1);
           }
       }
 
-    dbpos = ftello(dbfile);
-    fseeko(dbfile,dbpos,SEEK_SET);
-    fprintf(dbfile,DB_NBLOCK,0);
-    fprintf(dbfile,DB_PARAMS,SIZE,CUTOFF,ALL);
+    dbpos = FTELLO(dbfile);
+    FSEEKO(dbfile,dbpos,SEEK_SET)
+    FPRINTF(dbfile,DB_NBLOCK,0)
+    FPRINTF(dbfile,DB_PARAMS,SIZE,CUTOFF,ALL)
   }
 
-  { HITS_READ *reads  = db.reads;
+  { DAZZ_READ *reads  = db.reads;
     int        nreads = db.ureads;
     int64      totlen;
     int        nblock, ireads, treads, rlen, fno;
     int        i;
 
-
     nblock = 0;
     totlen = 0;
     ireads = 0;
     treads = 0;
-    fprintf(dbfile,DB_BDATA,0,0);
+    FPRINTF(dbfile,DB_BDATA,0,0)
     if (ALL)
       for (i = 0; i < nreads; i++)
         { rlen = reads[i].rlen;
@@ -167,7 +171,7 @@ int main(int argc, char *argv[])
               treads += 1;
               totlen += rlen;
               if (totlen >= SIZE)
-                { fprintf(dbfile,DB_BDATA,i+1,treads);
+                { FPRINTF(dbfile,DB_BDATA,i+1,treads)
                   totlen = 0;
                   ireads = 0;
                   nblock += 1;
@@ -182,7 +186,7 @@ int main(int argc, char *argv[])
               treads += 1;
               totlen += rlen;
               if (totlen >= SIZE)
-                { fprintf(dbfile,DB_BDATA,i+1,treads);
+                { FPRINTF(dbfile,DB_BDATA,i+1,treads)
                   totlen = 0;
                   ireads = 0;
                   nblock += 1;
@@ -191,26 +195,26 @@ int main(int argc, char *argv[])
         }
 
     if (ireads > 0)
-      { fprintf(dbfile,DB_BDATA,nreads,treads);
+      { FPRINTF(dbfile,DB_BDATA,nreads,treads)
         nblock += 1;
       }
     fno = fileno(dbfile);
-    if (ftruncate(fno,ftello(dbfile)) < 0)
-      SYSTEM_ERROR
+    if (ftruncate(fno,FTELLO(dbfile)) < 0)
+      SYSTEM_WRITE_ERROR
 
-    fseeko(dbfile,dbpos,SEEK_SET);
-    fprintf(dbfile,DB_NBLOCK,nblock);
+    FSEEKO(dbfile,dbpos,SEEK_SET)
+    FPRINTF(dbfile,DB_NBLOCK,nblock)
 
     dbs.cutoff = CUTOFF;
     if (ALL)
       dbs.allarr |= DB_ALL;
     dbs.treads = treads;
-    rewind(ixfile);
-    fwrite(&dbs,sizeof(HITS_DB),1,ixfile);
+    FSEEKO(ixfile,0,SEEK_SET)
+    FWRITE(&dbs,sizeof(DAZZ_DB),1,ixfile)
   }
 
-  fclose(ixfile);
-  fclose(dbfile);
+  FCLOSE(ixfile)
+  FCLOSE(dbfile)
   Close_DB(&db);
 
   exit (0);
diff --git a/DBstats.c b/DBstats.c
index 4a3badf..174c302 100644
--- a/DBstats.c
+++ b/DBstats.c
@@ -15,10 +15,10 @@
 
 #include "DB.h"
 
-static char *Usage = " [-nu] [-b<int(1000)>] [-m<track>]+ <name:db|dam>";
+static char *Usage = " [-nu] [-b<int(1000)>] [-m<mask>]+ <name:db|dam>";
 
 int main(int argc, char *argv[])
-{ HITS_DB _db, *db = &_db;
+{ DAZZ_DB _db, *db = &_db;
   int     dam;
 
   int64   ototal;
@@ -75,6 +75,12 @@ int main(int argc, char *argv[])
 
     if (argc != 2)
       { fprintf(stderr,"Usage: %s %s\n",Prog_Name,Usage);
+        fprintf(stderr,"\n");
+        fprintf(stderr,"      -u: Give stats for the untrimmed database.\n");
+        fprintf(stderr,"\n");
+        fprintf(stderr,"      -n: Do not show histogram of read lengths.\n");
+        fprintf(stderr,"      -m: Show histogram of mask intervals.\n");
+        fprintf(stderr,"      -b: Use histogram buckets of this size (default 1Kbp).\n");
         exit (1);
       }
   }
@@ -126,7 +132,7 @@ int main(int argc, char *argv[])
   { int        i;
     int64      totlen;
     int        nreads, maxlen;
-    HITS_READ *reads;
+    DAZZ_READ *reads;
 
     nreads = db->nreads;
     totlen = db->totlen;
@@ -258,7 +264,7 @@ int main(int argc, char *argv[])
 
   { int64      totlen;
     int        numint, maxlen;
-    HITS_TRACK *track;
+    DAZZ_TRACK *track;
 
     for (track = db->tracks; track != NULL; track = track->next)
       { char  *data = track->data;
diff --git a/DBtrim.c b/DBtrim.c
index 778123d..0de5ff6 100644
--- a/DBtrim.c
+++ b/DBtrim.c
@@ -25,9 +25,10 @@
 static char *Usage = "[-af] [-x<int>] <path:db|dam>";
 
 int main(int argc, char *argv[])
-{ HITS_DB    db, dbs;
+{ DAZZ_DB    db, dbs;
   int64      dbpos;
   FILE      *dbfile, *ixfile;
+  char      *dbfile_name, *ixfile_name;
   int        nblocks;
   int        status;
 
@@ -38,12 +39,10 @@ int main(int argc, char *argv[])
   { int   i, j, k;
     int   flags[128];
     char *eptr;
-    float size;
 
     ARG_INIT("DBtrim")
 
     CUTOFF = 0;
-    size   = 200;
 
     j = 1;
     for (i = 1; i < argc; i++)
@@ -65,6 +64,10 @@ int main(int argc, char *argv[])
 
     if (argc != 2)
       { fprintf(stderr,"Usage: %s %s\n",Prog_Name,Usage);
+        fprintf(stderr,"\n");
+        fprintf(stderr,"      -x: Trimmed DB has reads >= this threshold.\n");
+        fprintf(stderr,"      -a: Trimmed DB contains all reads from a well (not just longest).\n");
+        fprintf(stderr,"      -f: Force the new trim setting even if already set.\n");
         exit (1);
       }
   }
@@ -89,26 +92,25 @@ int main(int argc, char *argv[])
     pwd  = PathTo(argv[1]);
     if (status)
       { root   = Root(argv[1],".dam");
-        dbfile = Fopen(Catenate(pwd,"/",root,".dam"),"r+");
+        dbfile_name = Strdup(Catenate(pwd,"/",root,".dam"),"Allocating db file name");
       }
     else
       { root   = Root(argv[1],".db");
-        dbfile = Fopen(Catenate(pwd,"/",root,".db"),"r+");
+        dbfile_name = Strdup(Catenate(pwd,"/",root,".db"),"Allocating db file name");
       }
-    ixfile = Fopen(Catenate(pwd,PATHSEP,root,".idx"),"r+");
-    if (dbfile == NULL || ixfile == NULL)
+    ixfile_name = Strdup(Catenate(pwd,PATHSEP,root,".idx"),"Allocating index file name");
+    dbfile = Fopen(dbfile_name,"r+");
+    ixfile = Fopen(ixfile_name,"r+");
+    if (dbfile_name == NULL || ixfile_name == NULL || dbfile == NULL || ixfile == NULL)
       exit (1);
     free(pwd);
     free(root);
 
-    if (fscanf(dbfile,DB_NFILE,&nfiles) != 1)
-      SYSTEM_ERROR
+    FSCANF(dbfile,DB_NFILE,&nfiles)
     for (i = 0; i < nfiles; i++)
-      if (fgets(buffer,2*MAX_NAME+100,dbfile) == NULL)
-        SYSTEM_ERROR
+      FGETS(buffer,2*MAX_NAME+100,dbfile)
 
-    if (fread(&dbs,sizeof(HITS_DB),1,ixfile) != 1)
-      SYSTEM_ERROR
+    FREAD(&dbs,sizeof(DAZZ_DB),1,ixfile)
 
     if (dbs.cutoff >= 0)
       { if (!FORCE)
@@ -116,11 +118,11 @@ int main(int argc, char *argv[])
             printf("This will invalidate any .las files produced by daligner\n");
             printf("Are you sure you want to proceed? [Y/N] ");
             fflush(stdout);
-            if (fgets(buffer,100,stdin) == NULL)
-              SYSTEM_ERROR
+            fgets(buffer,100,stdin);
             if (index(buffer,'n') != NULL || index(buffer,'N') != NULL)
               { printf("Aborted\n");
                 fflush(stdout);
+                fclose(ixfile);
                 fclose(dbfile);
                 exit (1);
               }
@@ -131,15 +133,15 @@ int main(int argc, char *argv[])
         exit (1);
       }
 
-    fscanf(dbfile,DB_NBLOCK,&nblocks);
+    FSCANF(dbfile,DB_NBLOCK,&nblocks)
 
-    dbpos = ftello(dbfile);
-    fscanf(dbfile,DB_PARAMS,&size,&cutoff,&all);
-    fseeko(dbfile,dbpos,SEEK_SET);
-    fprintf(dbfile,DB_PARAMS,size,CUTOFF,ALL);
+    dbpos = FTELLO(dbfile);
+    FSCANF(dbfile,DB_PARAMS,&size,&cutoff,&all)
+    FSEEKO(dbfile,dbpos,SEEK_SET)
+    FPRINTF(dbfile,DB_PARAMS,size,CUTOFF,ALL)
   }
 
-  { HITS_READ *reads  = db.reads;
+  { DAZZ_READ *reads  = db.reads;
     int        uread, tread;
     int        rlen;
     int        b, u, t;
@@ -148,8 +150,8 @@ int main(int argc, char *argv[])
     t = 0;
     fprintf(dbfile,DB_BDATA,0,0);
     for (b = 0; b < nblocks; b++)
-      { dbpos = ftello(dbfile);
-        fscanf(dbfile,DB_BDATA,&uread,&tread);
+      { dbpos = FTELLO(dbfile);
+        FSCANF(dbfile,DB_BDATA,&uread,&tread)
 
         if (ALL)
           while (u < uread)
@@ -165,20 +167,20 @@ int main(int argc, char *argv[])
               u += 1;
             }
 
-        fseeko(dbfile,dbpos,SEEK_SET);
-        fprintf(dbfile,DB_BDATA,uread,t);
+        FSEEKO(dbfile,dbpos,SEEK_SET)
+        FPRINTF(dbfile,DB_BDATA,uread,t)
       }
 
     dbs.cutoff = CUTOFF;
     if (ALL)
       dbs.allarr |= DB_ALL;
     dbs.treads = t;
-    rewind(ixfile);
-    fwrite(&dbs,sizeof(HITS_DB),1,ixfile);
+    FSEEKO(ixfile,0,SEEK_SET)
+    FWRITE(&dbs,sizeof(DAZZ_DB),1,ixfile)
   }
 
-  fclose(ixfile);
-  fclose(dbfile);
+  FCLOSE(ixfile)
+  FCLOSE(dbfile)
   Close_DB(&db);
 
   exit (0);
diff --git a/DBwipe.c b/DBwipe.c
index 9730062..ed8129f 100644
--- a/DBwipe.c
+++ b/DBwipe.c
@@ -23,6 +23,7 @@
 #include <stdio.h>
 #include <string.h>
 #include <unistd.h>
+#include <errno.h>
 
 #include "DB.h"
 
@@ -35,7 +36,7 @@
 static char *Usage = "<path:db>";
 
 int main(int argc, char *argv[])
-{ HITS_DB    db;
+{ DAZZ_DB    db;
   int        status;
 
   Prog_Name = Strdup("DBwipe","Allocating Program Name");
@@ -61,26 +62,37 @@ int main(int argc, char *argv[])
 
   { char    *pwd, *root;
     FILE    *index;
+    char    *index_name;
     int      i;
 
     pwd    = PathTo(argv[1]);
     root   = Root(argv[1],".db");
-    unlink(Catenate(pwd,PATHSEP,root,".arw"));
-    unlink(Catenate(pwd,PATHSEP,root,".qvs"));
+    if (unlink(Catenate(pwd,PATHSEP,root,".arw")) < 0)
+      { if (errno != ENOENT)
+          { fprintf(stderr,"%s: [WARNING] Could not delete %s.arw\n",Prog_Name,root);
+            exit (1);
+          }
+      }
+    if (unlink(Catenate(pwd,PATHSEP,root,".qvs")) < 0)
+      { if (errno != ENOENT)
+          { fprintf(stderr,"%s: [WARNING] Could not delete %s.qvs\n",Prog_Name,root);
+            exit (1);
+          }
+      }
 
     for (i = 0; i < db.nreads; i++)
       db.reads[i].coff = -1;
     db.allarr &= ~DB_ARROW;
 
-    if ((index = Fopen(Catenate(pwd,PATHSEP,root,".idx"),"w")) == NULL)
-      { fprintf(stderr,"%s: Cannot open %s%s%s.idx\n",Prog_Name,pwd,PATHSEP,root);
-        exit (1);
-      }
+    index_name = Strdup(Catenate(pwd,PATHSEP,root,".idx"),"Allocating index file name");
+    index = Fopen(index_name,"w");
+    if (index_name == NULL || index == NULL)
+      exit (1);
 
-    fwrite(&db,sizeof(HITS_DB),1,index);
-    fwrite(db.reads,sizeof(HITS_READ),db.nreads,index);
+    FWRITE(&db,sizeof(DAZZ_DB),1,index)
+    FWRITE(db.reads,sizeof(DAZZ_READ),db.nreads,index)
 
-    fclose(index);
+    FCLOSE(index);
   }
 
   Close_DB(&db);
diff --git a/Makefile b/Makefile
index 8ed8f68..b3814ef 100644
--- a/Makefile
+++ b/Makefile
@@ -2,8 +2,8 @@ DEST_DIR = ~/bin
 
 CFLAGS = -O3 -Wall -Wextra -Wno-unused-result -fno-strict-aliasing
 
-ALL = fasta2DB DB2fasta quiva2DB DB2quiva DBsplit DBdust Catrack DBshow DBstats DBrm simulator \
-      fasta2DAM DAM2fasta DBdump rangen arrow2DB DB2arrow DBwipe DBtrim
+ALL = fasta2DB DB2fasta quiva2DB DB2quiva DBsplit DBdust Catrack DBshow DBstats DBrm DBmv \
+      simulator fasta2DAM DAM2fasta DBdump rangen arrow2DB DB2arrow DBwipe DBtrim
 
 all: $(ALL)
 
@@ -49,6 +49,9 @@ DBstats: DBstats.c DB.c DB.h QV.c QV.h
 DBrm: DBrm.c DB.c DB.h QV.c QV.h
 	gcc $(CFLAGS) -o DBrm DBrm.c DB.c QV.c -lm
 
+DBmv: DBmv.c DB.c DB.h QV.c QV.h
+	gcc $(CFLAGS) -o DBmv DBmv.c DB.c QV.c -lm
+
 simulator: simulator.c DB.c DB.h QV.c QV.h
 	gcc $(CFLAGS) -o simulator simulator.c DB.c QV.c -lm
 
diff --git a/README.md b/README.md
index 0967a17..c0c8246 100644
--- a/README.md
+++ b/README.md
@@ -259,7 +259,7 @@ should be used, and the characters per line, or line width, can be set to any po
 value with the -w option.
 
 ```
-9. DBsplit [-af] [-x<int>] [-s<int(200)>] <path:db|dam>
+9. DBsplit [-af] [-x<int>] [-s<double(200.)>] <path:db|dam>
 ```
 
 Divide the database \<path\>.db or \<path\>.dam conceptually into a series of blocks
@@ -292,7 +292,7 @@ partition itself).
 Runs the symmetric DUST algorithm over the reads in the untrimmed DB \<path\>.db or
 \<path\>.dam producing a track .\<path\>.dust[.anno,.data] that marks all intervals of low
 complexity sequence, where the scan window is of size -w, the threshold for being a
-low-complexity interval is -t, and only perfect intervals of size greater than -m are
+low-complexity interval is -t, and only low-complexity intervals of size greater than -m are
 recorded.  If the -b option is set then the definition of low complexity takes into
 account the frequency of a given base.  The command is incremental if given a DB to
 which new data has been added since it was last run on the DB, then it will extend
@@ -307,18 +307,19 @@ This permits job parallelism in block-sized chunks, and the resulting sequence o
 block tracks can then be merged into a track for the entire untrimmed DB with Catrack.
 
 ```
-12. Catrack [-vf] <path:db|dam> <track:name>
+12. Catrack [-vfd] <path:db|dam> <track:name>
 ```
 
-Find all block tracks of the form .\<path\>.#.\<track\>... and merge them into a single
+Find all block tracks of the form .\<path\>.#.\<track\>... and concatenate them into a single
 track, .\<path\>.\<track\>..., for the given DB or DAM.   The block track files must all
 encode the same kind of track data (this is checked), and the files must exist for
 block 1, 2, 3, ... up to the last block number.  If the -f option is set, then the
 concatenation takes place regardless of whether or not the single, combined track
-exists or not.
+already exists or not.  If the -d option is set then every block track is removed after
+the successful construction of the combined track.
 
 ```
-13. DBshow [-unqaUQA] [-w<int(80)>] [-m<track>]+
+13. DBshow [-unqaUQA] [-w<int(80)>] [-m<mask>]+
                       <path:db|dam> [ <reads:FILE> | <reads:range> ... ]
 ```
 
@@ -357,7 +358,7 @@ fasta2DB, quiva2D, and arrow2DB, giving one a simple way to make a DB of a subse
 the reads for testing purposes.
 
 ```
-14. DBdump [-rhsaqip] [-uU] [-m<track>]+
+14. DBdump [-rhsaqip] [-uU] [-m<mask>]+
                       <path:db|dam> [ <reads:FILE> | <reads:range> ... ]
 ```
 
@@ -371,7 +372,7 @@ which items of information are output as follows:
 subset of reads is requested).
 
 * -h requests the header information be output as the source file name on an H-line, the
-well # and pulse range on an L-line, and optionally the quality of the read if given on a Q-line.
+ If the -d option is set then every block track is removed after the successful construction of the combined track.well # and pulse range on an L-line, and optionally the quality of the read if given on a Q-line.
 
 * -s requests the sequence be output on an S-line.
 
@@ -431,7 +432,7 @@ Arrow pulse width strings are identical to that for the sequence as they are all
 the same length for any given entry.
 
 ```
-15. DBstats [-nu] [-b<int(1000)] [-m<track>]+ <path:db|dam>
+15. DBstats [-nu] [-b<int(1000)] [-m<mask>]+ <path:db|dam>
 ```
 
 Show overview statistics for all the reads in the trimmed data base \<path\>.db or
@@ -443,15 +444,23 @@ intervals along the read can be specified with the -m option in which case a sum
 and a histogram of the interval lengths is displayed.
 
 ```
-16. DBrm <path:db|dam> ...
+16. DBrm [-v] <path:db|dam> ...
 ```
 
 Delete all the files for the given data bases.  Do not use rm to remove a database, as
 there are at least two and often several secondary files for each DB including track
 files, and all of these are removed by DBrm.
+If the -v option is set then every file deleted is listed.
 
 ```
-17. DBwipe <path:db|dam> ...
+17. DBmv [-v] <old:db|dam> <new:db|dam>
+```
+
+Rename all the files for the data base old to use the new root.
+If the -v option is set then every file move is displayed.
+
+```
+18. DBwipe <path:db|dam> ...
 ```
 
 Delete any Arrow or Quiver data from the given databases.  This removes the .arw or
@@ -459,7 +468,7 @@ Delete any Arrow or Quiver data from the given databases.  This removes the .arw
 or Quiver.  Basically, converts an A-DB or Q-DB back to a simple S-DB.
 
 ```
-18.  simulator <genome:dam> [-CU] [-m<int(10000)>] [-s<int(2000)>] [-e<double(.15)]
+19.  simulator <genome:dam> [-CU] [-m<int(10000)>] [-s<int(2000)>] [-e<double(.15)]
                                   [-c<double(50.)>] [-f<double(.5)>] [-x<int(4000)>]
                                   [-w<int(80)>] [-r<int>] [-M<file>]
 ```
@@ -494,7 +503,7 @@ a read is say 's b e' then if b \< e the read is a perturbed copy of s[b,e] in t
 forward direction, and a perturbed copy s[e,b] in the reverse direction otherwise.
 
 ```
-19. rangen <genlen:double> [-U] [-b<double(.5)>] [-w<int(80)>] [-r<int>]
+20. rangen <genlen:double> [-U] [-b<double(.5)>] [-w<int(80)>] [-r<int>]
 ```
 
 Generate a random DNA sequence of length genlen*1Mbp that has an AT-bias of -b.
diff --git a/arrow2DB.c b/arrow2DB.c
index d7890e9..a313674 100644
--- a/arrow2DB.c
+++ b/arrow2DB.c
@@ -98,8 +98,8 @@ int main(int argc, char *argv[])
   FILE      *arrow, *indx;
   int64      boff;
 
-  HITS_DB    db;
-  HITS_READ *reads;
+  DAZZ_DB    db;
+  DAZZ_READ *reads;
   int        nfiles;
 
   int        VERBOSE;
@@ -145,6 +145,9 @@ int main(int argc, char *argv[])
     if ( (INFILE == NULL && ! PIPE && argc <= 2) || 
         ((INFILE != NULL || PIPE) && argc != 2))
       { fprintf(stderr,"Usage: %s %s\n",Prog_Name,Usage);
+        fprintf(stderr,"      -f: import files listed 1/line in given file.\n");
+        fprintf(stderr,"      -i: import data from stdin.\n");
+        fprintf(stderr,"        : otherwise, import sequence of specified files.\n");
         exit (1);
       }
   }
@@ -165,15 +168,15 @@ int main(int argc, char *argv[])
   indx  = Fopen(Catenate(pwd,PATHSEP,root,".idx"),"r+");
   if (indx == NULL)
     exit (1);
-  if (fread(&db,sizeof(HITS_DB),1,indx) != 1)
+  if (fread(&db,sizeof(DAZZ_DB),1,indx) != 1)
     { fprintf(stderr,"%s: %s.idx is corrupted, read failed\n",Prog_Name,root);
       exit (1);
     }
 
-  reads = (HITS_READ *) Malloc(sizeof(HITS_READ)*db.ureads,"Allocating DB index");
+  reads = (DAZZ_READ *) Malloc(sizeof(DAZZ_READ)*db.ureads,"Allocating DB index");
   if (reads == NULL)
     exit (1);
-  if (fread(reads,sizeof(HITS_READ),db.ureads,indx) != (size_t) (db.ureads))
+  if (fread(reads,sizeof(DAZZ_READ),db.ureads,indx) != (size_t) (db.ureads))
     { fprintf(stderr,"%s: %s.idx is corrupted, read failed\n",Prog_Name,root);
       exit (1);
     }
@@ -496,8 +499,8 @@ int main(int argc, char *argv[])
 
   db.allarr |= DB_ARROW;
   rewind(indx);
-  fwrite(&db,sizeof(HITS_DB),1,indx);
-  fwrite(reads,sizeof(HITS_READ),db.ureads,indx);
+  fwrite(&db,sizeof(DAZZ_DB),1,indx);
+  fwrite(reads,sizeof(DAZZ_READ),db.ureads,indx);
 
   fclose(istub);
   fclose(indx);
diff --git a/fasta2DAM.c b/fasta2DAM.c
index af6722a..f3df1fa 100644
--- a/fasta2DAM.c
+++ b/fasta2DAM.c
@@ -125,7 +125,7 @@ int main(int argc, char *argv[])
   int    ifiles, ofiles;
   char **flist;
 
-  HITS_DB db;
+  DAZZ_DB db;
   int     ureads;
   int64   offset, hdrset;
 
@@ -186,6 +186,10 @@ int main(int argc, char *argv[])
     if ( (IFILE == NULL && PIPE == NULL && argc <= 2) ||
         ((IFILE != NULL || PIPE != NULL) && argc != 2))
       { fprintf(stderr,"Usage: %s %s\n",Prog_Name,Usage);
+        fprintf(stderr,"\n");
+        fprintf(stderr,"      -f: import files listed 1/line in given file.\n");
+        fprintf(stderr,"      -i: import data from stdin, use optiona name as data source.\n");
+        fprintf(stderr,"        : otherwise, import sequence of specified files.\n");
         exit (1);
       }
   }
@@ -253,7 +257,7 @@ int main(int argc, char *argv[])
         if (bases == NULL || indx == NULL || hdrs == NULL)
           goto error;
 
-        fwrite(&db,sizeof(HITS_DB),1,indx);
+        fwrite(&db,sizeof(DAZZ_DB),1,indx);
 
         ureads  = 0;
         offset  = 0;
@@ -274,7 +278,7 @@ int main(int argc, char *argv[])
         if (bases == NULL || indx == NULL || hdrs == NULL)
           goto error;
 
-        if (fread(&db,sizeof(HITS_DB),1,indx) != 1)
+        if (fread(&db,sizeof(DAZZ_DB),1,indx) != 1)
           { fprintf(stderr,"%s: %s.idx is corrupted, read failed\n",Prog_Name,root);
             goto error;
           }
@@ -315,7 +319,7 @@ int main(int argc, char *argv[])
   { int            maxlen;
     int64          totlen, count[4];
     int            rmax;
-    HITS_READ      prec;
+    DAZZ_READ      prec;
     char          *read;
     int            append;
     int            c;
@@ -504,7 +508,7 @@ int main(int argc, char *argv[])
                   fwrite(read+pbeg,1,clen,bases);
                   offset += clen;
 
-                  fwrite(&prec,sizeof(HITS_READ),1,indx);
+                  fwrite(&prec,sizeof(DAZZ_READ),1,indx);
                 }
               hdrset += hlen;
             }
@@ -545,7 +549,7 @@ int main(int argc, char *argv[])
     { int64      totlen, dbpos, size;
       int        nblock, ireads, tfirst, rlen;
       int        ufirst, cutoff, allflag;
-      HITS_READ  record;
+      DAZZ_READ  record;
       int        i;
 
       if (VERBOSE)
@@ -587,11 +591,11 @@ int main(int argc, char *argv[])
       //    compute and record partition indices for the rest of the db from this point
       //    forward.
 
-      fseeko(indx,sizeof(HITS_DB)+sizeof(HITS_READ)*ufirst,SEEK_SET);
+      fseeko(indx,sizeof(DAZZ_DB)+sizeof(DAZZ_READ)*ufirst,SEEK_SET);
       totlen = 0;
       ireads = 0;
       for (i = ufirst; i < ureads; i++)
-        { if (fread(&record,sizeof(HITS_READ),1,indx) != 1)
+        { if (fread(&record,sizeof(DAZZ_READ),1,indx) != 1)
             { fprintf(stderr,"%s: %s.idx is corrupted, read failed\n",Prog_Name,root);
               goto error;
             }
@@ -627,7 +631,7 @@ int main(int argc, char *argv[])
   fprintf(ostub,DB_NFILE,ofiles);
 
   rewind(indx);
-  fwrite(&db,sizeof(HITS_DB),1,indx);   //  Write the finalized db record into .idx
+  fwrite(&db,sizeof(DAZZ_DB),1,indx);   //  Write the finalized db record into .idx
 
   if (istub != NULL)
     fclose(istub);
diff --git a/fasta2DB.c b/fasta2DB.c
index 98298e3..88088fb 100644
--- a/fasta2DB.c
+++ b/fasta2DB.c
@@ -125,7 +125,7 @@ int main(int argc, char *argv[])
   int    ifiles, ofiles, ocells;
   char **flist;
 
-  HITS_DB db;
+  DAZZ_DB db;
   int     ureads;
   int64   offset;
 
@@ -168,7 +168,9 @@ int main(int argc, char *argv[])
                     exit (1);
                   }
                 fclose(temp);
-                unlink(PIPE);
+                if (unlink(PIPE) != 0)
+                  fprintf(stderr,"%s: [WARNING] Could not delete temporary file %s\n",
+                                 Prog_Name,PIPE);
               }
             break;
         }
@@ -186,6 +188,10 @@ int main(int argc, char *argv[])
     if ( (IFILE == NULL && PIPE == NULL && argc <= 2) || 
         ((IFILE != NULL || PIPE != NULL) && argc != 2))
       { fprintf(stderr,"Usage: %s %s\n",Prog_Name,Usage);
+        fprintf(stderr,"\n");
+        fprintf(stderr,"      -f: import files listed 1/line in given file.\n");
+        fprintf(stderr,"      -i: import data from stdin, use optiona name as data source.\n");
+        fprintf(stderr,"        : otherwise, import sequence of specified files.\n");
         exit (1);
       }
   }
@@ -248,7 +254,7 @@ int main(int argc, char *argv[])
         if (bases == NULL || indx == NULL)
           goto error;
 
-        fwrite(&db,sizeof(HITS_DB),1,indx);
+        fwrite(&db,sizeof(DAZZ_DB),1,indx);
 
         ureads  = 0;
         offset  = 0;
@@ -264,17 +270,24 @@ int main(int argc, char *argv[])
         if (bases == NULL || indx == NULL)
           exit (1);
 
-        if (fread(&db,sizeof(HITS_DB),1,indx) != 1)
-          { fprintf(stderr,"%s: %s.idx is corrupted, read failed\n",Prog_Name,root);
+        if (fread(&db,sizeof(DAZZ_DB),1,indx) != 1)
+          { if (ferror(indx))
+              fprintf(stderr,"%s: System error, read failed\n",Prog_Name);
+            else
+              fprintf(stderr,"%s: File %s.idx is corrupted\n",Prog_Name,root);
             exit (1);
           }
-        fseeko(bases,0,SEEK_END);
-        fseeko(indx, 0,SEEK_END);
+        if (fseeko(bases,0,SEEK_END) < 0)
+          SYSTEM_READ_ERROR
+        if (fseeko(indx, 0,SEEK_END) < 0)
+          SYSTEM_READ_ERROR
 
         ureads = db.ureads;
         offset = ftello(bases);
         boff   = offset;
         ioff   = ftello(indx);
+        if (boff < 0 || ioff < 0)
+          SYSTEM_READ_ERROR
       }
 
     flist  = (char **) Malloc(sizeof(char *)*(ocells+ifiles),"Allocating file list");
@@ -282,27 +295,36 @@ int main(int argc, char *argv[])
     if (ostub == NULL || flist == NULL)
       goto error;
 
-    fprintf(ostub,DB_NFILE,ocells+ifiles);   //  Will write again with correct value at end
+    if (fprintf(ostub,DB_NFILE,ocells+ifiles) < 0)   //  Will write again with correct value at end
+      { fprintf(stderr,"%s: System error, write failed\n",Prog_Name);
+        goto error;
+      }
     ofiles = 0;
     for (i = 0; i < ocells; i++)
       { int  last;
         char prolog[MAX_NAME], fname[MAX_NAME];
 
         if (fscanf(istub,DB_FDATA,&last,fname,prolog) != 3)
-          { fprintf(stderr,"%s: %s.db is corrupted, read failed\n",Prog_Name,root);
+          { if (ferror(istub))
+              fprintf(stderr,"%s: System error, read failed\n",Prog_Name);
+            else
+              fprintf(stderr,"%s: File %s.db is corrupted\n",Prog_Name,root);
             goto error;
           }
         if (ofiles == 0 || strcmp(flist[ofiles-1],fname) != 0)
           if ((flist[ofiles++] = Strdup(fname,"Adding to file list")) == NULL)
             goto error;
-        fprintf(ostub,DB_FDATA,last,fname,prolog);
+        if (fprintf(ostub,DB_FDATA,last,fname,prolog) < 0)
+          { fprintf(stderr,"%s: System error, write failed\n",Prog_Name);
+            goto error;
+          }
       }
   }
 
   { int            maxlen;
     int64          totlen, count[4];
     int            pmax, rmax;
-    HITS_READ     *prec;
+    DAZZ_READ     *prec;
     char          *read;
     int            c;
     File_Iterator *ng = NULL;
@@ -310,7 +332,7 @@ int main(int argc, char *argv[])
     //  Buffer for reads all in the same well
 
     pmax = 100;
-    prec = (HITS_READ *) Malloc(sizeof(HITS_READ)*pmax,"Allocating record buffer");
+    prec = (DAZZ_READ *) Malloc(sizeof(DAZZ_READ)*pmax,"Allocating record buffer");
     if (prec == NULL)
       goto error;
 
@@ -366,7 +388,7 @@ int main(int argc, char *argv[])
 
         //  Get the header of the first line.  If the file is empty skip.
 
-        eof   = (fgets(read,MAX_NAME,input) == NULL);
+        eof = (fgets(read,MAX_NAME,input) == NULL);
         if (eof || strlen(read) < 1)
           { free(core);
             fclose(input);
@@ -532,7 +554,7 @@ int main(int argc, char *argv[])
                   pcnt += 1;
                   if (pcnt >= pmax)
                     { pmax = ((int) (pcnt*1.2)) + 100;
-                      prec = (HITS_READ *) realloc(prec,sizeof(HITS_READ)*pmax);
+                      prec = (DAZZ_READ *) realloc(prec,sizeof(DAZZ_READ)*pmax);
                       if (prec == NULL)
                         { fprintf(stderr,"File %s.fasta, Line %d: Out of memory",core,nline);
                           fprintf(stderr," (Allocating read records)\n");
@@ -548,7 +570,7 @@ int main(int argc, char *argv[])
                     if (prec[i].rlen > prec[x].rlen)
                       x = i;
                   prec[x].flags |= DB_BEST;
-                  fwrite(prec,sizeof(HITS_READ),pcnt,indx);
+                  fwrite(prec,sizeof(DAZZ_READ),pcnt,indx);
                   prec[0] = prec[pcnt];
                   pcnt = 1;
                 }
@@ -563,7 +585,7 @@ int main(int argc, char *argv[])
             if (prec[i].rlen > prec[x].rlen)
               x = i;
           prec[x].flags |= DB_BEST;
-          fwrite(prec,sizeof(HITS_READ),pcnt,indx);
+          fwrite(prec,sizeof(DAZZ_READ),pcnt,indx);
         }
 
         fprintf(ostub,DB_FDATA,ureads,core,prolog);
@@ -602,7 +624,7 @@ int main(int argc, char *argv[])
     { int64      totlen, dbpos, size;
       int        nblock, ireads, tfirst, rlen;
       int        ufirst, cutoff, allflag;
-      HITS_READ  record;
+      DAZZ_READ  record;
       int        i;
 
       if (VERBOSE)
@@ -644,11 +666,11 @@ int main(int argc, char *argv[])
       //    compute and record partition indices for the rest of the db from this point
       //    forward.
 
-      fseeko(indx,sizeof(HITS_DB)+sizeof(HITS_READ)*ufirst,SEEK_SET);
+      fseeko(indx,sizeof(DAZZ_DB)+sizeof(DAZZ_READ)*ufirst,SEEK_SET);
       totlen = 0;
       ireads = 0;
       for (i = ufirst; i < ureads; i++)
-        { if (fread(&record,sizeof(HITS_READ),1,indx) != 1)
+        { if (fread(&record,sizeof(DAZZ_READ),1,indx) != 1)
             { fprintf(stderr,"%s: %s.idx is corrupted, read failed\n",Prog_Name,root);
               goto error;
             }
@@ -680,7 +702,7 @@ int main(int argc, char *argv[])
     db.treads = ureads;
 
   rewind(indx);
-  fwrite(&db,sizeof(HITS_DB),1,indx);   //  Write the finalized db record into .idx
+  fwrite(&db,sizeof(DAZZ_DB),1,indx);   //  Write the finalized db record into .idx
 
   rewind(ostub);                        //  Rewrite the number of files actually added
   fprintf(ostub,DB_NFILE,ocells);
diff --git a/quiva2DB.c b/quiva2DB.c
index 55e54d6..2ef56b1 100644
--- a/quiva2DB.c
+++ b/quiva2DB.c
@@ -31,7 +31,7 @@
 #define PATHSEP "/"
 #endif
 
-static char *Usage = "[-vl] <path:db> ( -f<file> | -i | <input:quiva> ... )";
+static char *Usage = "[-v] <path:db> ( -f<file> | -i | <input:quiva> ... )";
 
 typedef struct
   { int    argc;
@@ -98,15 +98,14 @@ int main(int argc, char *argv[])
   FILE      *quiva, *indx;
   int64      coff;
 
-  HITS_DB    db;
-  HITS_READ *reads;
+  DAZZ_DB    db;
+  DAZZ_READ *reads;
   int        nfiles;
 
   FILE      *temp;
   char      *tname;
 
   int        VERBOSE;
-  int        LOSSY;
   int        PIPE;
   FILE      *INFILE;
 
@@ -139,7 +138,6 @@ int main(int argc, char *argv[])
     argc = j;
 
     VERBOSE = flags['v'];
-    LOSSY   = flags['l'];
     PIPE    = flags['i'];
 
     if (INFILE != NULL && PIPE)
@@ -150,6 +148,10 @@ int main(int argc, char *argv[])
     if ( (INFILE == NULL && ! PIPE && argc <= 2) || 
         ((INFILE != NULL || PIPE) && argc != 2))
       { fprintf(stderr,"Usage: %s %s\n",Prog_Name,Usage);
+        fprintf(stderr,"\n");
+        fprintf(stderr,"      -f: import files listed 1/line in given file.\n");
+        fprintf(stderr,"      -i: import data from stdin.\n");
+        fprintf(stderr,"        : otherwise, import sequence of specified files.\n");
         exit (1);
       }
   }
@@ -174,7 +176,7 @@ int main(int argc, char *argv[])
     { fprintf(stderr,"%s",Ebuffer);
       exit (1);
     }
-  if (fread(&db,sizeof(HITS_DB),1,indx) != 1)
+  if (fread(&db,sizeof(DAZZ_DB),1,indx) != 1)
     { fprintf(stderr,"%s: %s.idx is corrupted, read failed\n",Prog_Name,root);
       exit (1);
     }
@@ -183,12 +185,12 @@ int main(int argc, char *argv[])
       exit (1);
     }
 
-  reads = (HITS_READ *) Malloc(sizeof(HITS_READ)*db.ureads,"Allocating DB index");
+  reads = (DAZZ_READ *) Malloc(sizeof(DAZZ_READ)*db.ureads,"Allocating DB index");
   if (reads == NULL)
     { fprintf(stderr,"%s",Ebuffer);
       exit (1);
     }
-  if (fread(reads,sizeof(HITS_READ),db.ureads,indx) != (size_t) (db.ureads))
+  if (fread(reads,sizeof(DAZZ_READ),db.ureads,indx) != (size_t) (db.ureads))
     { fprintf(stderr,"%s: %s.idx is corrupted, read failed\n",Prog_Name,root);
       exit (1);
     }
@@ -406,7 +408,7 @@ int main(int argc, char *argv[])
               goto error;
             }
 
-          coding = Create_QVcoding(LOSSY);
+          coding = Create_QVcoding(0);
           if (coding == NULL)
             { fprintf(stderr,"%s",Ebuffer);
               goto error;
@@ -432,7 +434,7 @@ int main(int argc, char *argv[])
                   goto error;
                 }
               reads[i].coff = qpos;
-              s = Compress_Next_QVentry(temp,quiva,coding,LOSSY);
+              s = Compress_Next_QVentry(temp,quiva,coding,0);
               if (s < 0)
                 { fprintf(stderr,"%s",Ebuffer);
                   goto error;
@@ -478,8 +480,8 @@ int main(int argc, char *argv[])
   //  Write the db record and read index into .idx and clean up
 
   rewind(indx);
-  fwrite(&db,sizeof(HITS_DB),1,indx);
-  fwrite(reads,sizeof(HITS_READ),db.ureads,indx);
+  fwrite(&db,sizeof(DAZZ_DB),1,indx);
+  fwrite(reads,sizeof(DAZZ_READ),db.ureads,indx);
 
   fclose(istub);
   fclose(indx);
diff --git a/simulator.c b/simulator.c
index 57cd956..21dc6b7 100644
--- a/simulator.c
+++ b/simulator.c
@@ -189,10 +189,11 @@ static double sample_unorm(double x)
 //    consists of its contigs with a random sequence filling the gaps (generated according to
 //    the bp frequency in db.freq[4]).
 
-HITS_DB *load_and_fill(char *name, int *pscaffs)
-{ static HITS_DB db;
-  HITS_READ *reads;
+DAZZ_DB *load_and_fill(char *name, int *pscaffs)
+{ static DAZZ_DB db;
+  DAZZ_READ *reads;
   FILE      *bases;
+  char      *bases_name;
   char      *seq;
   int        nreads, nscaffs;
   int        i, c;
@@ -232,8 +233,9 @@ HITS_DB *load_and_fill(char *name, int *pscaffs)
   for (i = 0; i < nscaffs; i++)
     ctot += reads[i].coff+1;
 
-  bases = Fopen(Catenate(db.path,"","",".bps"),"r");
-  if (bases == NULL)
+  bases_name = Strdup(Catenate(db.path,"","",".bps"),"Allocating base-pair file name");
+  bases = Fopen(bases_name,"r");
+  if (bases_name == NULL || bases == NULL)
     exit (1);
 
   seq = (char *) Malloc(ctot+4,"Allocating space for genome");
@@ -277,14 +279,10 @@ HITS_DB *load_and_fill(char *name, int *pscaffs)
       len = reads[i].rlen;
       off = reads[i].boff;
       if (ftello(bases) != off)
-        fseeko(bases,off,SEEK_SET);
+        FSEEKO(bases,off,SEEK_SET)
       clen = COMPRESSED_LEN(len);
       if (clen > 0)
-        { if (fread(seq+u,clen,1,bases) != 1)
-            { EPRINTF(EPLACE,"%s: Read of .bps file failed\n",Prog_Name);
-              exit (1);
-            }
-        }
+        FREAD(seq+u,clen,1,bases)
       Uncompress_Read(len,seq+u);
       if (reads[i].origin == 0)
         reads[c].boff = o;
@@ -313,8 +311,8 @@ HITS_DB *load_and_fill(char *name, int *pscaffs)
 //    output as fasta entries with the PacBio-specific header format that contains the
 //    sampling interval, read length, and a read id.
 
-static void shotgun(HITS_DB *source, int nscaffs)
-{ HITS_READ *reads;
+static void shotgun(DAZZ_DB *source, int nscaffs)
+{ DAZZ_READ *reads;
   int        gleng;
   int        maxlen, nreads, qv;
   int64      totlen, totbp;
@@ -464,18 +462,18 @@ static void shotgun(HITS_DB *source, int nscaffs)
           rbeg = j;
         }
 
-      printf(">Sim/%d/%d_%d RQ=0.%d\n",nreads+1,0,elen,qv);
+      PRINTF(">Sim/%d/%d_%d RQ=0.%d\n",nreads+1,0,elen,qv)
       if (UPPER)
         Upper_Read(rbuffer);
       else
         Lower_Read(rbuffer);
       for (j = 0; j+WIDTH < elen; j += WIDTH)
-        printf("%.*s\n",WIDTH,rbuffer+j);
+        PRINTF("%.*s\n",WIDTH,rbuffer+j)
       if (j < elen)
-        printf("%s\n",rbuffer+j);
+        PRINTF("%s\n",rbuffer+j)
 
        if (MAP != NULL)
-         fprintf(MAP," %6d %9d %9d\n",scf,rbeg,rend);
+         FPRINTF(MAP," %6d %9d %9d\n",scf,rbeg,rend)
 
        totlen += elen;
        nreads += 1;
@@ -483,7 +481,7 @@ static void shotgun(HITS_DB *source, int nscaffs)
 }
 
 int main(int argc, char *argv[])
-{ HITS_DB *source;
+{ DAZZ_DB *source;
   int      nscaffs;
 
   //  Process command line

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debian-med/dazzdb.git



More information about the debian-med-commit mailing list