#! /bin/csh -f
# Last edited on 2001-11-10 09:57:53 by stolfi

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

set usopt = "[ -show ]"
set usage = "${cmd:t} ${usopt} BAND"

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 != 1 ) then
  echo "usage: ${usage}"; exit 1
endif
set band = "$1"; shift;

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

set curvedir = "data/multiscale"
if ( ! ( -d ${curvedir} ) ) then
  echo 'directory '"${curvedir}"'" does not exist"; exit 1
endif

@ 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 = "${curvedir}/f${band}"
set output = "${curvedir}/f${band}-cvh"
echo "${input} -> ${output}-{plain,squeezed}.plt"
nice 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 ${cmd:t} =========" 

