#! /bin/csh -f
# Last edited on 2001-11-02 14:42:35 by stolfi

set usage = "$0 [ -show ] [ PZDRAWCANDS_OPTION ]... CANFILE FLCDIR BAND EPSNAME"

# Output is EPSNAME-pg00000.eps, EPSNAME-pg00001.eps, ...

set cmd = $0
echo "=== begin ${cmd:t} ===" 
echo "${cmd:t} $*"

set opts = ( )
unset show
unset drawEvery
while ( ( $#argv > 0 ) && ( "x$1" =~ x-* ) )
  if ( "x$1" == "x-show" ) then
    set show; shift
  else if ( ( $#argv >= 2 ) && ( "x$1" == "x-drawEvery" ) ) then
    set drawEvery = "$2"; shift; shift
  else if ( ( $#argv >= 2 ) && ( "x$1" == "x-displace" ) ) then
    set opts = ( ${opts} -displace "$2" ); shift; shift
  else if ( ( $#argv >= 3 ) && ( "x$1" == "x-tilt" ) ) then
    set opts = ( ${opts} -tilt "$2" "$3" ); shift; shift; shift
  else if ( ( $#argv >= 5 ) && ( "x$1" == "x-shift" ) ) then
    set opts = ( ${opts} -shift "$2" "$3" "$4" "$5" ); 
    shift; shift; shift; shift; shift
  else if ( ( $#argv >= 2 ) && ( "x$1" == "x-labelSize" ) ) then
    set opts = ( ${opts} -labelSize "$2" ); shift; shift
  else if ( ( $#argv >= 2 ) && ( "x$1" == "x-grid" ) ) then
    set opts = ( ${opts} -grid "$2" ); shift; shift
  else if ( ( $#argv >= 3 ) && ( "x$1" == "x-plotSize" ) ) then
    set opts = ( ${opts} -plotSize "$2" "$3" ); shift; shift; shift
  else if ( ( $#argv >= 2 ) && ( "x$1" == "x-nominalCandWidth" ) ) then
    set opts = ( ${opts} -nominalCandWidth "$2" ); shift; shift
  else if ( ( $#argv >= 2 ) && ( "x$1" == "x-drawMatchEvery" ) ) then
    set opts = ( ${opts} -drawMatchEvery "$2" ); shift; shift
  else if ( "x$1" == "x-trim" ) then
    set opts = ( ${opts} -trim ); shift
  else if ( "x$1" == "x-sampleDots" ) then
    set opts = ( ${opts} -sampleDots ); shift
  else if ( "x$1" == "x-drawMatch" ) then
    set opts = ( ${opts} -drawMatch ); shift
  else if ( "x$1" == "x-noColors" ) then
    set opts = ( ${opts} -noColors ); shift
  else if ( "x$1" == "x-noThicker" ) then
    set opts = ( ${opts} -noThicker ); shift
  else if ( "x$1" == "x-noPointers" ) then
    set opts = ( ${opts} -noPointers ); shift
  else if ( "x$1" == "x-noFrame" ) then
    set opts = ( ${opts} -noFrame ); shift
  else
    echo "*** unrecognized option $1"
    echo "usage: ${usage}"; exit 1
  endif
end

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

set canfile = "$1"; shift
set flcdir = "$1"; shift;
set band = "$1"; shift;
set epsname = "$1"; shift;

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

set path = ( \
  ${STOLFIHOME}/programs/pm3-1.1.15/THESES/hcgl/1/bin/${PLATFORM} \
  ${cmd:h} \
  ${path} \
)

if ( "/${canfile:e}" == "/" ) then
  set canfile = "${canfile}.can"
endif

if ( ! -d ${flcdir} ) then
  echo "directory ${flcdir} not found"; exit 1
endif

if ( "/${epsname:e}" != "/" ) then
  echo "EPS prefix should have no extension"; exit 1
endif

if ( ! $?drawEvery ) then
  set drawEvery = 1
endif
echo "drawEvery = ${drawEvery}"

echo "converting ${canfile} to ${epsname}-pgNNNNN.eps..."

which PZDrawCands
nice PZDrawCands \
  -input ${canfile:r} \
  -chainDir ${flcdir} -chainPrefix f \
  -band ${band} \
  -drawEvery ${drawEvery} \
  -output ${epsname} \
  -epsFormat \
  -maxCands 60 \
  ${opts}

if ( $?show ) then
  foreach f ( ${epsname}-pg[0-9][0-9][0-9][0-9][0-9].eps )
    ghostview ${f}
  end
endif

echo "=== end ${cmd:t} =========" 


