#!/usr/bin/perl
# 
# Make some nice plots 


# graph of runs per season versus starters' OPS
$title = "AL 1995-2007, as a function of 9 main starters only";
$cmdfile = "runs_start_ops.gnu";
$psfile = "runs_start_ops.ps";
open(CMDFILE, ">$cmdfile") || die("can't open $cmdfile");
printf CMDFILE "set output '$psfile' \n";
printf CMDFILE "set term postscript color 'Helvetica' 16 \n";
printf CMDFILE "set grid \n";
printf CMDFILE "set key top left \n";
printf CMDFILE "set xlabel 'OPS of main 9 starting batters' \n";
printf CMDFILE "set ylabel 'Number of runs scored during season'  \n";
printf CMDFILE "set title '$title'  \n";
printf CMDFILE "plot [0.65:0.92][550:1070] ";
printf CMDFILE " 'put_together.out' using 5:11 ";
printf CMDFILE "     with points t '' pt 1 ps 2.4 lw 3  ";
printf CMDFILE " , ";
printf CMDFILE " -522.20+1690.89*x t 'linear fit' lt -1 ";
printf CMDFILE " \n";

printf CMDFILE "quit \n";
close(CMDFILE);

$cmd = "gnuplot $cmdfile ";
printf "cmd is ..$cmd.. \n";
$ret = `$cmd`;
$giffile = $psfile;
$giffile =~ s/.ps$/.gif/;
$cmd = "convert -rotate 90 $psfile $giffile";
printf "cmd is ..$cmd.. \n";
$ret = `$cmd`;



# graph of residuals from linear fit to (runs) vs. (OPS)
#     as a function of sigma-of-OPS
$title = "Do residuals (using main starting 9) correlate with stdev of OPS of main starting 9?";
$cmdfile = "residuals_sigma.gnu";
$psfile = "residuals_sigma.ps";
open(CMDFILE, ">$cmdfile") || die("can't open $cmdfile");
printf CMDFILE "set output '$psfile' \n";
printf CMDFILE "set term postscript color 'Helvetica' 16 \n";
printf CMDFILE "set grid \n";
printf CMDFILE "set key top left \n";
printf CMDFILE "set xlabel 'Stdev of OPS of 9 starting batters' \n";
printf CMDFILE "set ylabel 'Residuals from linear fit to runs vs. starting 9 OPS'  \n";
printf CMDFILE "set title '$title'  \n";
printf CMDFILE "plot [0.0:0.22][-200:200] ";
printf CMDFILE " 'put_together.out' using 6:12 ";
printf CMDFILE "     with points t '' pt 3 ps 1.5 lw 3  ";
printf CMDFILE " , ";
printf CMDFILE " -27.589+272.3592*x t 'linear fit' lt -1 ";
printf CMDFILE " \n";

printf CMDFILE "quit \n";
close(CMDFILE);

$cmd = "gnuplot $cmdfile ";
printf "cmd is ..$cmd.. \n";
$ret = `$cmd`;
$giffile = $psfile;
$giffile =~ s/.ps$/.gif/;
$cmd = "convert -rotate 90 $psfile $giffile";
printf "cmd is ..$cmd.. \n";
$ret = `$cmd`;



# graph of runs per season versus overall OPS
$title = "AL 1995-2007, as a function of overall team OPS";
$cmdfile = "runs_all_ops.gnu";
$psfile = "runs_all_ops.ps";
open(CMDFILE, ">$cmdfile") || die("can't open $cmdfile");
printf CMDFILE "set output '$psfile' \n";
printf CMDFILE "set term postscript color 'Helvetica' 16 \n";
printf CMDFILE "set grid \n";
printf CMDFILE "set key top left \n";
printf CMDFILE "set xlabel 'Overall OPS of entire team' \n";
printf CMDFILE "set ylabel 'Number of runs scored during season'  \n";
printf CMDFILE "set title '$title'  \n";
printf CMDFILE "plot [0.65:0.92][550:1070] ";
printf CMDFILE " 'put_together.out' using 9:11 ";
printf CMDFILE "     with points t '' pt 1 ps 2.4 lw 3  ";
printf CMDFILE " , ";
printf CMDFILE " -782.46+2058.216*x t 'linear fit' lt -1 ";
printf CMDFILE " \n";

printf CMDFILE "quit \n";
close(CMDFILE);

$cmd = "gnuplot $cmdfile ";
printf "cmd is ..$cmd.. \n";
$ret = `$cmd`;
$giffile = $psfile;
$giffile =~ s/.ps$/.gif/;
$cmd = "convert -rotate 90 $psfile $giffile";
printf "cmd is ..$cmd.. \n";
$ret = `$cmd`;



# graph of residuals from linear fit to (runs) vs. (entire team OPS)
#     as a function of sigma-of-OPS
$title = "Do residuals (using team OPS) correlate with stdev of OPS of main starting 9?";
$cmdfile = "residuals_sigma_team.gnu";
$psfile = "residuals_sigma_team.ps";
open(CMDFILE, ">$cmdfile") || die("can't open $cmdfile");
printf CMDFILE "set output '$psfile' \n";
printf CMDFILE "set term postscript color 'Helvetica' 16 \n";
printf CMDFILE "set grid \n";
printf CMDFILE "set key top left \n";
printf CMDFILE "set xlabel 'Stdev of OPS of main 9 starting batters' \n";
printf CMDFILE "set ylabel 'Residuals from linear fit to runs vs. overal team OPS'  \n";
printf CMDFILE "set title '$title'  \n";
printf CMDFILE "plot [0.0:0.22][-200:200] ";
printf CMDFILE " 'put_together.out' using 6:13 ";
printf CMDFILE "     with points t '' pt 3 ps 1.5 lw 3  ";
printf CMDFILE " , ";
printf CMDFILE " -1.811+17.713*x t 'linear fit' lt -1 ";
printf CMDFILE " \n";

printf CMDFILE "quit \n";
close(CMDFILE);

$cmd = "gnuplot $cmdfile ";
printf "cmd is ..$cmd.. \n";
$ret = `$cmd`;
$giffile = $psfile;
$giffile =~ s/.ps$/.gif/;
$cmd = "convert -rotate 90 $psfile $giffile";
printf "cmd is ..$cmd.. \n";
$ret = `$cmd`;






exit(0);
