#! /bin/bash
# Last edited on 2010-06-16 21:36:50 by stolfi

file="$1"; shift;

tmp="/tmp/$$"

cat ${file} \
  | tr ' ' '\012' \
  | sed -e '/^$/d' \
  | tail --lines=+4 \
  | gawk 'BEGIN{split("",p);n=0} /^[0-9]/{p[n]=$1;n++;if(n>=2){print p[0],p[1];n=0}}' \
  > ${tmp}.dat

gnuplot <<EOF
  set term png truecolor rounded size 640,600 medium \
    xffffff x000000 x404040 \
    xff0000 x007700 x0055ff
  set output "${file%.*}-plot.png"
  set xrange [0:66000]
  set yrange [0:66000]
  plot \
    "${tmp}.dat" using 1:2 with points lt 1 pt 7, \
    x with lines lt 2
  quit
EOF

rm -f ${tmp}.dat    
