#! /bin/csh -f 
# Last edited on 2008-02-04 20:51:14 by stolfi

set usage = "$0 [-title 'TITLE'] [-keys 'TIT1 .. TITn'] FRFILE1 .. FRFILEn > EPSFILE"

# Generates a plot of vocabulary size versus sample size
# for various samples.
#
# Each file must contain records of the form SMPSIZE VOCSIZE 
# (other fields are ignored), sorted by SMPSIZE.

set title = " "
set keys = ( )
while ( ( $#argv > 0 ) && ( "/$1" =~ /-* ) ) 
  if ( ( $#argv >= 2 ) && ( "/$1" == "/-title" ) ) then
    set title = "$2"; shift; shift
  else if ( ( $#argv >= 2 ) && ( "/$1" == "/-keys" ) ) then
    set keys = ( `echo $2` ); shift; shift
  else
    echo "bad option $1"
    echo "usage: ${usage}"; exit 1
  endif
end

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

set files = ( $* )

if ( ( $#keys != 0 ) && ( $#keys != $#files ) ) then
  echo "keys don't match files"; exit 1
endif

set gfile = "/tmp/$$.gnuplot"
set psfile = "/tmp/$$.eps"

cat <<EOF > ${gfile}
set size 1.1,1.4
set term postscript eps "Courier" 28 
set output "${psfile}"
set title "${title}"
set logscale xy
set xrange [0.99:100000.1]
set yrange [0.99:100000.1]
EOF

@ lt = 1
@ pt = 1
set sep = "plot"
foreach ifile ( $files )
  if ( $#keys == 0 ) then
    set key = "${ifile:r}"; set key = "${key:t}"
  else
    set key = ${keys[1]}; set keys = ( ${keys[2-]} )
  endif
  echo "${sep}"' "'"${ifile}"'" using 1:2 title "'"${key}"'" with lines lt '"${lt}"' \' >> ${gfile}
  @ lt = $lt + 1
  @ pt = $pt + 1
  set sep = ",   "
end

cat <<EOF >> ${gfile}

quit
EOF

gnuplot < ${gfile}

cat ${psfile}

/bin/rm -f ${gfile} ${psfile}