#!/bin/csh -f

# Extract columns headed by $2 (gives comma-separated column names)
# from file $1 and produce a LaTeX file for a 2D plot of points
# showing the number of each score pair on $2-2Dhist.tex.


#  It is assumed that all scores are integral; in most cases,
# nonintegral scores will be ignored.

# An example usage is "grade2Dhist grades.txt EX1 EX1-9".

set debug = 0

set fullprogname = $0
set fullprogname = `echo $fullprogname | sed 's+^\([^/]\)+./\1+'`
set progdir = $fullprogname:h
set progname = $fullprogname:t

set histtype = `echo $progname | sed 's+grade++'`

set awkcolorder = print
if ("$histtype" == landhist) set awkcolorder = 'print $2, $1'

if ($#argv < 2) then
  echo "Usage: $progname gradesfile 2-comma-separated-colnames"
  exit 1
endif

if ($debug) echo "progname: $progname, awkcolorder: $awkcolorder"

cat $1 | stripgradestats | excol `echo "$2" | tr ',' ' '` | awk "{$awkcolorder}" | hist2D > $2-${histtype}.tex
