#! /bin/csh -f
# Last edited on 2001-11-08 14:56:51 by stolfi

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

set usage = "${cmd:t} RUN BAND FOUNDFILE IDEALFILE MINLEN"

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

set run = "$1"; shift;
set band = "$1"; shift;
set foundfile = "$1"; shift
set idealfile = "$1"; shift
set minLength = "$1"; shift

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

echo "band = ${band} comparing ${foundfile} to ${idealfile} ..."

set rundir = results/${run}

set parmsfile = "${rundir}/f${band}.parms"

if ( ! ( -r ${parmsfile} ) ) then
  echo "${parmsfile} not found"; exit 1
endif

source ${parmsfile}

set blurFactor = 3.0;

set maxCompShift = `gawk -v step=${step} 'BEGIN{printf "%.3f", 3.0*step;}'`
set minCompOverlap = `gawk -v bd=${band} -v bf=${blurFactor} 'BEGIN{printf "%.3f", 1.0*bd;}'`
set minIdealLength = "${minLength}"

echo "step = ${step}"

echo "maxCompShift = ${maxCompShift}"
echo "minCompOverlap = ${minCompOverlap}"
echo "minIdealLength = ${minIdealLength}"
echo "blurFactor = ${blurFactor}"

echo "candDrawStep = ${candDrawStep}"

set drawEvery = ${candDrawStep}
echo "drawEvery = ${drawEvery}"

set fname = "${rundir}/${foundfile:r}"
set rname = "${rundir}/${idealfile:r}"

set goodname = "${rundir}/${foundfile}-good"
set bogsname = "${rundir}/${foundfile}-bogus"

set missname = "${rundir}/${idealfile}-missed"

nice PZCompCands @M3stackdump \
  -found "${fname}" \
  -ideal "${rname}" \
  -step ${step} \
  -minIdealLength ${minIdealLength} \
  -blurFactor ${blurFactor} \
  -maxCompShift ${maxCompShift} \
  -minCompOverlap ${minCompOverlap} \
  -good    "${goodname}" \
  -bogus   "${bogsname}" \
  -missing "${missname}" \
  -printChainPairs
  
#  \
#   -printMatches \
#   -printCurvePairs

set prefix = "f"

# nice  PZDrawCands \
#   -input ${goodname} \
#   -chainPrefix ${prefix} -chainDir . \
#   -band ${band} \
#   -output ${goodname} \
#   -maxCands 80 \
#   -drawEvery ${drawEvery}
# 
# ghostview ${bogsname}.ps &

# nice  PZDrawCands \
#   -input ${bogsname} \
#   -chainPrefix ${prefix} \
#   -band ${band} \
#   -output ${bogsname} \
#   -maxCands 80 \
#   -drawEvery ${drawEvery}
# 
# ghostview ${bogsname}.ps &

nice  PZDrawCands \
  -input ${missname} \
  -chainPrefix ${prefix} \
  -band ${band} \
  -output ${missname} \
  -maxCands 80 \
  -drawEvery ${drawEvery}
  
ghostview ${missname}.ps &

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