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

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

set usage = "$0 [ -show ] RUN BAND TAG [IDEALTAG]"

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

if ( ( $#argv < 3 ) || ( $#argv > 4 ) ) then
  echo "usage: ${usage}"; exit 1
endif

set run = "$1"; shift
set band = "$1"; shift;
set tag = "$1"; shift;
if ( $#argv > 0 ) then
  set idtag = "$1"; shift;
else 
  set idtag = ""
endif

source RUN-${run}/f${band}.parms

set input = "RUN-${run}/f${band}-${tag}"
if ( "/${idtag}" == "/" ) then
  set ideal = ""
  set output = "RUN-${run}/f${band}-${tag}"
  echo "converting ${input}.can to ${output}-grid.ps..."
  set idealOpt = ( )
else
  set ideal = "RUN-${run}/f${band}-${idtag}"
  set output = "RUN-${run}/f${band}-${tag}-${idtag}"
  echo "converting ${input}.can and ${ideal}.can to ${output}-grid.ps..."
  set idealOpt = ( "-ideal" "${ideal}" )
endif


nice -n 19 \
PZDrawCandGrids \
  -input ${input} ${idealOpt} \
  -output ${output} \
  -cellSize 5.0 \
  -refGridLine  0.05   1.00 1.00 0.00 \
  -candGridLine 0.05   0.00 1.00 0.00 \
  -matchLine    0.20   0.00 0.00 0.60 \
  -dots         0.40   0.00 0.00 0.60 \
  -maxCands 999 

if ( $?show ) then
  ghostview ${output}-grid.ps
endif

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


