#! /bin/csh -fe 
# Last edited on 1999-11-16 21:23:48 by hcgl

set usage = "$0 [-eps] [-title STRING] YREF YFAC MATCHPLTFILE NONMATCHPLTFILE PSFILE"

# Displays the data generated by PZPlotMatchCost (the PLTFILEs) as Postscript 
# or on the screen.  The vertical axis is scaled to YREF*YFAC (plus a tad).

echo "=== begin $0 ======"

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

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

set yRef = "$1"; shift
set yFac = "$1"; shift
set mtc = "$1"; set mtc = "${mtc:r}"; shift
set nom = "$1"; set nom = "${nom:r}"; shift
set psfile = "$1"; shift;

echo "yRef = ${yRef} yFac = ${yFac}"
echo "${mtc}.plt ${nom}.plt -> ${psfile}"

if ( $postscript ) then
  set settrm = 'set terminal postscript eps color "TimesRoman" 22'
  set setout = 'set output "'"${psfile}"'"'
  set pause = ""
  set setsiz = 'set size 1,1'
  echo "writing ${psfile}"
else
  set settrm = 'set terminal X11'
  set setout = ""
  set setsiz = 'set size 1,1'
  set pause = "pause 60"
endif

gnuplot <<EOF
${settrm}
${setout}
${setsiz}
set yrange [0:(1.2*${yRef}*${yFac})]
set ylabel "rms curv. diff. (pixels^-1)"
set xlabel "chain length (pixels)"
set title "${title}"
plot \
  "$nom.plt" using 7:9 title "non-matching ${nom}" with linespoints, \
  "$mtc.plt" using 7:9 title "matching ${mtc}"     with linespoints, \
  (${yRef}) title "xi = ${yRef}" with lines
${pause}
quit
EOF

if ( $postscript ) then
  ghostview -openwindows "${psfile}" &
endif

echo "=== end $0 ======"