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




# graph of runs per season versus overall team scaled_CR
$title = "AL 1997-2007, as a function of overall team scaled CR";
$cmdfile = "runs_all_cr.gnu";
$psfile = "runs_all_cr.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 'Scaled CR of entire team' \n";
printf CMDFILE "set ylabel 'Number of runs scored during season'  \n";
printf CMDFILE "set title '$title'  \n";
printf CMDFILE "plot [500:1100][550:1070] ";
printf CMDFILE " 'put_together_cr.out' using 14:11 ";
printf CMDFILE "     with points t '' pt 1 ps 2.4 lw 3  ";
printf CMDFILE " , ";
printf CMDFILE "  204.60+0.7452*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 scaled_CR)
#     as a function of sigma-of-OPS
$title = "Do residuals (using team scaled CR) correlate with stdev of OPS of main starting 9?";
$cmdfile = "residuals_sigma_cr.gnu";
$psfile = "residuals_sigma_cr.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. overall team scaled CR'  \n";
printf CMDFILE "set title '$title'  \n";
printf CMDFILE "plot [0.0:0.22][-200:200] ";
printf CMDFILE " 'put_together_cr.out' using 6:15 ";
printf CMDFILE "     with points t '' pt 3 ps 1.5 lw 3  ";
printf CMDFILE " , ";
printf CMDFILE " 2.334-30.221*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);
