fe43cd3394528a515b867eb2e8f69d152bd4d178
jcasper
  Mon May 6 10:01:16 2019 -0700
A few initial library additions for eventual Hi-C support, refs #18842

diff --git src/lib/obscure.c src/lib/obscure.c
index 7d260a6..49794eb 100644
--- src/lib/obscure.c
+++ src/lib/obscure.c
@@ -635,45 +635,73 @@
 sprintLongWithCommas(ascii, l);
 fprintf(f, "%s", ascii);
 }
 
 void sprintWithGreekByte(char *s, int slength, long long size)
 /* Numbers formatted with PB, TB, GB, MB, KB, B */
 {
 char *greek[] = {"B", "KB", "MB", "GB", "TB", "PB"};
 int i = 0;
 long long d = 1;
 while ((size/d) >= 1024)
     {
     ++i;
     d *= 1024;
     }
+assert(i<(sizeof(greek)/sizeof(char*)));
 double result = ((double)size)/d;
 if (result < 10)
     safef(s,slength,"%3.1f %s",((double)size)/d, greek[i]);
 else
     safef(s,slength,"%3.0f %s",((double)size)/d, greek[i]);
 }
 
 void printWithGreekByte(FILE *f, long long l)
 /* Print with formatting in gigabyte, terabyte, etc. */
 {
 char buf[32];
 sprintWithGreekByte(buf, sizeof(buf), l);
 fprintf(f, "%s", buf);
 }
 
+void sprintWithSiBaseUnit(char *s, int slength, long long size)
+/* Numbers formatted with Pb, Tb, Gb, Mb, kb, bp */
+{
+char *unit[] = {"bp", "kB", "Mb", "Gb", "Tb", "Pb"};
+int i = 0;
+long long d = 1;
+while ((size/d) >= 1000)
+    {
+    ++i;
+    d *= 1000;
+    }
+assert(i<(sizeof(unit)/sizeof(char*)));
+double result = ((double)size)/d;
+if (result < 10)
+    safef(s,slength,"%3.1f %s",((double)size)/d, unit[i]);
+else
+    safef(s,slength,"%3.0f %s",((double)size)/d, unit[i]);
+}
+
+void printWithSiBaseUnit(FILE *f, long long l)
+/* Print with formatting in megabase, kilobase, etc. */
+{
+char buf[32];
+sprintWithSiBaseUnit(buf, sizeof(buf), l);
+fprintf(f, "%s", buf);
+}
+
 void shuffleArrayOfChars(char *array, int arraySize)
 /* Shuffle array of characters of given size given number of times. */
 {
 char c;
 int i, randIx;
 
 /* Randomly permute an array using the method from Cormen, et al */
 for (i=0; i<arraySize; ++i)
     {
     randIx = i + (rand() % (arraySize - i));
     c = array[i];
     array[i] = array[randIx];
     array[randIx] = c;
     }
 }