#! /bin/bash
# Last edited on 2004-09-26 16:22:27 by stolfi

cmd=${0##*/}
usage="${cmd} {FMT} < {INFILE}.flo > {OUTFILE}.{FMT}"

# Reads from standard input a list of records of the form
#   
#   {COUNT} {FIRST} {LAST} {DIFF} {WORD}
#   
# writes a scatterplot in format {FMT} ("eps" or "png") showing 
# {COUNT} in the H axis and {DIFF} in the V axis.

function error()
{ 
  echo "${cmd}: $1" >&2; 
  echo "usage: ${usage}" >&2; 
  echo "(unknown)";
  exit 1;
}

if [ $# != 1 ]; then
  error "wrong number of parameters";
fi

fmt="$1"; shift;

# Working files:
flofile="/tmp/$$.flo"
pltfile="/tmp/$$.{fmt}"

# Save input data
cat > ${flofile}

# Choose plotting options appropriate for format
if [ ".${fmt}" == ".eps" ]; then
  term='postscript eps mono "TimesRoman" 14'
  size='1.0,(2*5/7)'
elif [ ".${fmt}" == ".png" ]; then
  term='png medium color'
  size='1.0,(2*0.666667)'
else 
  error "bad plot format ${fmt}"
fi

gnuplot <<EOF
set term ${term}
set size ${size}
set output "${pltfile}"
set logscale x
set xrange [+0.95:+51000]
set yrange [-1000:+50000]
plot "${flofile}" using (column(1)):(column(4)) with points
quit
EOF

cat ${pltfile} 

/bin/rm -f ${flofile} ${pltfile}