| 1 |
#include "posix.H" |
| 2 |
#include <stdio.h> |
| 3 |
#include <stdlib.h> |
| 4 |
#include <unistd.h> |
| 5 |
#include <string.h> |
| 6 |
#include <errno.h> |
| 7 |
#include "aHit.H" |
| 8 |
|
| 9 |
// Generates a histogram of a hit file |
| 10 |
|
| 11 |
typedef struct { |
| 12 |
uint32 dir; |
| 13 |
uint32 estID; |
| 14 |
uint32 scfID; |
| 15 |
uint32 scfLo; |
| 16 |
uint32 scfHi; |
| 17 |
} hit_s; |
| 18 |
|
| 19 |
|
| 20 |
int |
| 21 |
main(int argc, char **argv) { |
| 22 |
|
| 23 |
if (argc < 2) { |
| 24 |
fprintf(stderr, "usage: %s ....\n", argv[0]); |
| 25 |
exit(1); |
| 26 |
} |
| 27 |
|
| 28 |
int arg = 1; |
| 29 |
|
| 30 |
// Things for reading hits |
| 31 |
// |
| 32 |
FILE *file; |
| 33 |
char b[1024]; |
| 34 |
aHit a; |
| 35 |
bool isBINARY; |
| 36 |
int histogram[10] = {0}; |
| 37 |
|
| 38 |
while (arg < argc) { |
| 39 |
|
| 40 |
// Open the file, fatally failing if we cannot do it. |
| 41 |
// |
| 42 |
errno = 0; |
| 43 |
file = fopen(argv[arg], "r"); |
| 44 |
if (file == 0L) { |
| 45 |
fprintf(stderr, "ESTmapper/filterEST-- ERROR opening '%s'\n%s\n", argv[arg], strerror(errno)); |
| 46 |
exit(1); |
| 47 |
} |
| 48 |
|
| 49 |
// Binary or ASCII input? |
| 50 |
// |
| 51 |
char x = (char)fgetc(file); |
| 52 |
ungetc(x, file); |
| 53 |
|
| 54 |
isBINARY = (x != '-'); |
| 55 |
|
| 56 |
if (isBINARY) |
| 57 |
fprintf(stderr, "reading BINARY hits from '%s'\n", argv[arg]); |
| 58 |
else |
| 59 |
fprintf(stderr, "reading ASCII hits from '%s'\n", argv[arg]); |
| 60 |
|
| 61 |
// Read hits until we run out of space |
| 62 |
// |
| 63 |
while (!feof(file)) { |
| 64 |
if (isBINARY) { |
| 65 |
ahit_readBinary(&a, file); |
| 66 |
} else { |
| 67 |
fgets(b, 1024, file); |
| 68 |
ahit_parseString(&a, b); |
| 69 |
} |
| 70 |
|
| 71 |
// Fill the histogram |
| 72 |
// |
| 73 |
int len = a._dsHi - a._dsLo; |
| 74 |
if (len < 25000) |
| 75 |
histogram[0]++; |
| 76 |
else if (len < 50000) |
| 77 |
histogram[1]++; |
| 78 |
else if (len < 100000) |
| 79 |
histogram[2]++; |
| 80 |
else if (len < 200000) |
| 81 |
histogram[3]++; |
| 82 |
else if (len < 400000) |
| 83 |
histogram[4]++; |
| 84 |
else if (len < 800000) |
| 85 |
histogram[5]++; |
| 86 |
else if (len < 1600000) |
| 87 |
histogram[6]++; |
| 88 |
else if (len < 3200000) |
| 89 |
histogram[7]++; |
| 90 |
else if (len < 6400000) |
| 91 |
histogram[8]++; |
| 92 |
else |
| 93 |
histogram[9]++; |
| 94 |
} |
| 95 |
|
| 96 |
fclose(file); |
| 97 |
|
| 98 |
arg++; |
| 99 |
} |
| 100 |
|
| 101 |
for (int i=0; i<10; i++) |
| 102 |
fprintf(stderr, "%2d] %d\n", i, histogram[i]); |
| 103 |
|
| 104 |
return(0); |
| 105 |
} |