

gen10() {
gnuplot<<EOF
set title "$1"
set ylabel "median"
set key bottom left
set xlabel "variance"
set arrow 1 from 0,$3 to 100,$3 nohead  
set terminal postscript enhanced color eps "Helvetica" 15
set output "/tmp/$2.eps"
plot "/tmp/10.dat" title "10",\
     "/tmp/20.dat" title "20",\
     "/tmp/30.dat" title "30",\
     "/tmp/40.dat" title "40",\
     "/tmp/50.dat" title "50",\
     "/tmp/60.dat" title "60",\
     "/tmp/70.dat" title "70",\
     "/tmp/80.dat" title "80",\
     "/tmp/90.dat" title "90",\
     "/tmp/100.dat" title "100"
 
EOF
epstopdf /tmp/$2.eps

}

gen20() {
echo [$3]
gnuplot<<EOF
set title "$1"
set ylabel "median (50th percentile)"
set key bottom left
set yrange [0:100]
set xrange [0:100]
set arrow 1 from 0,$3 to 100,$3 nohead 
set xlabel "variance (75th - 25th percentile)"
set terminal postscript enhanced color eps "Helvetica" 15
set output "/tmp/$2.eps"
plot "/tmp/20.dat" title "20",\
     "/tmp/40.dat" title "40",\
     "/tmp/60.dat" title "60",\
     "/tmp/80.dat" title "80",\
     "/tmp/100.dat" title "100" 
EOF
epstopdf /tmp/$2.eps

}

name[1]=ret1
name[2]=ret2
name[3]=ret3

default[1]=71
default[2]=60
default[3]=54

rm /tmp/*.pdf
for n in 1 2 3; do
    r=${name[$n]}
    for g in pd pf; do
	echo $r $g
	rm -f /tmp/*.dat
	cat ${r}_5_100_quarts_${g}.csv  | 
        gawk -F, '/#/ {next}; 
                   $5 {split($2,tmp,"|"); 
                       Fac=20; 
                       N=int(tmp[1]/Fac+0.5) *Fac; 
                       f="/tmp/"N".dat"; 
                       print $6 - $4 "\t" $5>>f
                      }'  |
	sort -n > /tmp/dat ; gen20 "Year $n Retention - `echo $g | tr a-z A-Z`" "${r}_${g}" ${default[$n]}
    done
done


cd plots
cp /tmp/*.pdf .
pdflatex -output-directory=$HOME/tmp summary