#! /bin/csh -f
# Last edited on 2003-11-20 22:57:26 by stolfi

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

set usopt = "[ -show ]"
set usage = "$0 ${usopt} RUN BAND TAG"

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

if ( $#argv != 3 ) then
  echo "usage: ${usage}"; exit 1
endif
set run = "$1"; shift;
set band = "$1"; shift;
set tag = "$1"; shift;

@ maxSegs = 5 * ( ${band} + 1 )

set fractalDim = 1.21
set sigmaCurv = 0.175
set maxCurv = `gawk -v band=${band} -v dim=${fractalDim} -v sig=${sigmaCurv} 'BEGIN{printf "%8.6f", 5*sig/exp(dim*log(band));}'`

set input = "RUN-${run}/f${band}-${tag}"
set output = "RUN-${run}/f${band}-${tag}-cvh"
echo "${input} -> ${output}-{plain,squeezed}.plt"
nice -n 19 PZCurvHistogram \
      -input ${input} \
      -maxSegs ${maxSegs} \
      -chainDir . -chainPrefix f \
      -band ${band} -extension ".fcv" \
      -maxCurv ${maxCurv} \
      -sigmaCurv ${sigmaCurv} -fractalDim ${fractalDim} \
      -output ${output}
      
# Convert to Postscript and show it:
foreach tp ( plain/"${maxCurv}" squeezed/"1.2" )
  set type = "${tp:h}"
  set maxval = "${tp:t}"
  set pltFile = "${output}-${type}.plt"
  set epsFile = "${output}-${type}.eps"
  echo "${pltFile} -> ${epsFile}"
  set title = "lambda = ${band} ${type}"
  draw-curvature-histogram \
    ${maxval} \
    "${pltFile}" \
    "${epsFile}" \
    "${title}"
  if ( $show ) then
    ghostview ${epsFile}
  endif
end

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

