1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149
|
#!/opt/local/bin/gawk -f
# Usage: histogramm.awk <input file>
#
# Read a number of positive integers and print (and plot) a
# distribution.
#
BEGIN{
minimum = 2000000000;
maximum = 0;
maxcount = 0;
compress = 7;
ignore_low_limit=0;
all_int_keys = 1;
for(i=0; i< ARGC; i++)
{
if(ARGV[i] == "--ignore-lower-limit")
{
ignore_low_limit = ARGV[i+1];
ARGV[i] = "";
ARGV[i+1] = "";
}
}
}
/^\#/{
print "Skipping comment";
next;
}
/[A-Za-z0-9]+/{
if(0+$1 < ignore_low_limit)
{
next;
}
if(int($1) != $1)
{
all_int_keys = 0;
}
array[$1]++;
if(array[$1] > maxcount)
{
maxcount = array[$1]
}
if(0+$1 < minimum)
{
minimum = 0+$1;
}
if(0+$1 > maximum)
{
maximum = 0+$1;
}
}
function line(val, res,limit,i)
{
res = "";
limit = val *60 / maxcount;
for(i=0; i<limit; i++)
{
res = res "#";
}
return res;
}
END{
sum = 0;
if(! all_int_keys)
{
j = 1;
for (i in array)
{
ind[j] = i; # index value becomes element value
j++;
}
n = asort(ind); # index values are now sorted
for (i = 1; i <= n; i++)
{
curr = 0+array[ind[i]];
printf "%8.4f: %4d ", ind[i], curr;
print line(curr);
sum+=curr;
}
l1 = sum/3;
c1 = 0;
c2 = 0;
l2 = sum*2/3;
sum = 0;
for(i=minimum; i<=maximum; i++)
{
curr = 0+array[i];
sum += curr;
if(sum >= l1 &&!c1)
{
c1 = i;
}
if(sum >= l2 &&!c2)
{
c2 = i;
}
}
}
else
{
for(i=minimum; i<=maximum; i++)
{
curr = 0+array[i];
printf "%4d: %4d ", i, curr;
print line(curr);
sum+=curr;
if(!curr)
{
for(j=i; !array[j]&&(j<maximum); j++);
# print j, i, j-i, compress
if(j-i >= compress)
{
print ".\n.";
i=j-2;
}
}
}
l1 = sum/3;
c1 = 0;
c2 = 0;
l2 = sum*2/3;
sum = 0;
for(i=minimum; i<=maximum; i++)
{
curr = 0+array[i];
sum += curr;
if(sum >= l1 &&!c1)
{
c1 = i;
}
if(sum >= l2 &&!c2)
{
c2 = i;
}
}
}
printf "Suggested partition: %d-%d, %d-%d, %d-%d\n",
minimum,c1,c1, c2,c2,maximum;
printf "some_limit=%d, many_limit=%d\n",c1,c2;
}
|