function stats() {
>tmpstats
for i in maps/*; do
bzcat $i >tmpmap
grep 'class:[37]' tmpmap >searchmap
time=`perl -e 'print ((stat)[9]) for pop' $i`
nodes=`wc -l <tmpmap`
search=`wc -l <searchmap`
index=`grep -c 'class:[57]' tmpmap`
all213=`grep -c 131331 tmpmap`
all212=`grep -c 131330 tmpmap`
all211=`grep -c 131329 tmpmap`
allold=`grep -v 'ver:131329' tmpmap|grep -v 'ver:131330' |grep -vc 'ver:131331'`
search213=`grep -c 131331 searchmap`
search212=`grep -c 131330 searchmap`
searchold=`grep -v 'ver:131330' searchmap|grep -vc 'ver:131331'`
auto=`grep -c 'min:1' searchmap`
auto2=`grep -c 'min:' tmpmap`
#auto3=`grep -c 'min:' tmpmap`
echo $time $nodes $search $index $all213 $all212 $all211 $allold $search213 $search212 $searchold $auto $auto2 >>tmpstats
done
}

function plot() {
(cat <<EOF
set timefmt "%s"
set xdata time
#set terminal svg
#set output "tmp.svg"
set terminal postscript color solid
# set output "oft.png"
#set noautoscale y
#set autoscale ymax
EOF
echo -n "plot \"tmpstats\" using $2 title \"$3\" with lines"
while [ $# -gt 4 ] ; do
	shift 2
	echo -n ", \"tmpstats\" using $2 title \"$3\" with lines"
done
echo
) | gnuplot | gs -q -dNOPAUSE -dBATCH -sDEVICE=pnmraw -r210 -sOutputFile=- -|pnmflip -r270|pnmscale .5|pnmcrop|pnmpad -white -left 10 -right 10 -top 10 -bottom 10 |pnmtopng >$1
optipng -q $1

}

stats

plot total.png 1:2 'Total nodes' 1:5 '0.2.1.3' 1:6 '0.2.1.2' 1:7 '0.2.1.1' 1:8 '0.2.1.0 or older'
plot search.png 1:3 'Search nodes' 1:9 '0.2.1.3' 1:10 '0.2.1.2' 1:11 '0.2.1.1 or older' 1:12 'Autopromoted' 1:13 'Auto-capable' 1:4 'Index nodes'
