#! /bin/csh -fe
# Last edited on 2003-11-20 22:59:17 by stolfi

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

set usage = "$0 RUN BAND OLDTAG NEWTAG MAXCANDS"

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

set run = "$1"; shift
set band = "$1"; shift
source RUN-${run}/f${band}.parms
set oldTag = "$1"; shift
set newTag = "$1"; shift
set maxCands = "$1"; shift

set extraLength = 0.0
set minLength = 1.0  
set skipGeoDist = 0.0
set blurFactor = 3.0
set simpleMatchOpt = ( "-simpleMatch" )

echo "band = ${band} oldTag = ${oldTag} newTag = ${newTag} maxCands = ${maxCands}"
echo "step = ${step}"
echo "minLength = ${minLength}"
echo "maxGeoShift = ${maxGeoShift}"
echo "critGeoDist = ${critGeoDist}"
echo "maxGeoDist = ${maxGeoDist}"
echo "skipGeoDist = ${skipGeoDist}"
echo "maxDrawCands = ${maxDrawCands}"
echo "candDrawStep = ${candDrawStep}"
echo "extraLength = ${extraLength}"
echo "simpleMatchOpt = ${simpleMatchOpt}"

set input = "RUN-${run}/f${band}-${oldTag}"
set output = "RUN-${run}/f${band}-${newTag}"
set funcplot = "RUN-${run}/f${band}-${oldTag}-${newTag}-opt"

echo "${input}.can -> ${output}.can"

nice -n 19 \
  PZRefineCandsGeometry \
    -input ${input} -maxCands ${maxCands} \
    -chainDir '.' -chainPrefix f \
    -band ${band} -step ${step} \
    -output ${output} \
    -maxShift ${maxGeoShift} \
    -maxDist ${maxGeoDist} \
    -critDist  ${critGeoDist} \
    -skipDist  ${skipGeoDist} \
    -minLength ${minLength} \
    -blurFactor ${blurFactor} \
    -extraLength ${extraLength} \
    ${simpleMatchOpt} \
    -maxEvals 100 \
    -displace 0.0
    
#     \
#     -plotFunction \
#     -draw -epsFormat
 
echo "wrote ${output}.can"

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

