#!/bin/bash
#plot of V/F against depth and B# - use plotR for rays (useful for cones)

if [ ! -n "$1" ]; then
  echo "usage: % plotV  lrs_output_file [ maxdepth [ maxcobases ] ]"
  exit 1
fi

#strip out first four fields from cobasis lines
grep "V#" $1 | sed -n '/V#/s/V#//;s/R#//;s/B#//;s/h=//;s/f.*//p' > $1Vhist

#get maxdepth from file if not supplied
if [ ! -n "$2" ]; then
  maxd=$(grep -i "tree depth" $1 | awk '{print $NF}')
else
  maxd=$2
fi

#get maxcobases from file if not supplied
if [ ! -n "$3" ]; then
  maxB=$(tail -n 1 $1Vhist | awk '{print $3}')
else
  maxB=$3
fi

echo "$maxd $maxB"

gnuplot -persist <<EOF
set terminal postscript enhanced color
set output 'plotV.ps'
set autoscale
set xlabel "V#"
set title "V# vs height"
set ylabel "height"
set yrange [0:$maxd]
plot '$1Vhist' using 1:4

set title "V# vs B#"
set ylabel "B#"
set yrange [0:$maxB]
plot '$1Vhist' using 1:3
EOF

rm -f $1Vhist 

ps2pdf plotV.ps $1V.pdf
rm plotV.ps
