#! /bin/csh -f
# Last edited on 2004-08-20 22:27:13 by stolfi

set usage = "$0 INFILE.data  XQUIZ XLABEL  YQUIZ YLABEL > IMAGEFILE.png"

# Plots the grades of quiz number YQUIZ against the grades of quiz number XQUIZ.
# Assumes that the input INFILE.data has one record per student, 
# containing the RA number followed by the quiz grades.

if ($#argv != 5) then
  echo "usage: ${usage}"; exit 1
endif

set infile  = "$1"; shift;
set xqz     = "$1"; shift;
set xlab    = "$1"; shift;
set yqz     = "$1"; shift;
set ylab    = "$1"; shift;

set tmpfile = "/tmp/$$.hdat"

cat ${infile} \
  | gawk -v xqz="${xqz}" -v yqz="${yqz}" \
      ' /./{ \
          xg = $(xqz+1); if (xg == "---") { next; } \
          yg = $(yqz+1); if (yg == "---") { next; } \
          printf "%5.1f %5.1f\n", xg/10, yg/10; \
        } \
      ' \
  > ${tmpfile}

gnuplot <<EOF
set terminal pbm small color;
set size ratio -1 0.40,0.5
set xlabel "${xlab}"
set ylabel "${ylab}"
set xrange [-0.1:+10.1]
set yrange [-0.1:+10.1]
plot "${tmpfile}" using 1:2 with points
quit
EOF

