#!/usr/bin/perl
# 

$hot_star = "./bb_lam_12000.dat";
$cool_star = "./bb_lam_5000.dat";
$filter = "./bess-b.pass";


# plot showing unperturbed filter only
$title = "An unperturbed filter ";
$cmdfile = "make_plots_a.gnu";
$psfile = "make_plots_a.ps";
open(CMDFILE, ">$cmdfile") || die("can't open $cmdfile");
printf CMDFILE "set output '$psfile' \n";
printf CMDFILE "set term postscript color \n";
printf CMDFILE "set grid \n";
printf CMDFILE "set key top left \n";
printf CMDFILE "set xlabel 'Wavelength (nm)' \n";
printf CMDFILE "set ylabel 'Filter transmission / Stellar flambda'  \n";
printf CMDFILE "set title '$title'  \n";
printf CMDFILE "plot [100:1000][0.0:1.3] ";
#printf CMDFILE " '$hot_star' using (\$2*1E9):(\$3/1.0E15) ";
#printf CMDFILE "     with lines t 'star T = 12000 K' lt 3 lw 2  ";
#printf CMDFILE ", ";
#printf CMDFILE " '$cool_star' using (\$2*1E9):(\$3*80/1.0E15) ";
#printf CMDFILE "     with lines t 'star T = 5000 K' lt 1 lw 2  ";
#printf CMDFILE ", ";
printf CMDFILE " '$filter' using ((\$1*0.1)):(\$2) ";
printf CMDFILE "     with linespoints t 'filter' lt -1 pt 6 ps 0.4 lw 3  ";
#printf CMDFILE ", ";
#printf CMDFILE "  145 t '' lt 2 lw 3 ";
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`;



# plot showing unperturbed filter and hot star only
$title = "An unperturbed filter observes a hot star";
$cmdfile = "make_plots_b.gnu";
$psfile = "make_plots_b.ps";
open(CMDFILE, ">$cmdfile") || die("can't open $cmdfile");
printf CMDFILE "set output '$psfile' \n";
printf CMDFILE "set term postscript color \n";
printf CMDFILE "set grid \n";
printf CMDFILE "set key top left \n";
printf CMDFILE "set xlabel 'Wavelength (nm)' \n";
printf CMDFILE "set ylabel 'Filter transmission / Stellar flambda'  \n";
printf CMDFILE "set title '$title'  \n";
printf CMDFILE "plot [100:1000][0.0:1.3] ";
printf CMDFILE " '$hot_star' using (\$2*1E9):(\$3/1.0E15) ";
printf CMDFILE "     with lines t 'star T = 12000 K' lt 3 lw 2  ";
printf CMDFILE ", ";
#printf CMDFILE " '$cool_star' using (\$2*1E9):(\$3*80/1.0E15) ";
#printf CMDFILE "     with lines t 'star T = 5000 K' lt 1 lw 2  ";
#printf CMDFILE ", ";
printf CMDFILE " '$filter' using ((\$1*0.1)):(\$2) ";
printf CMDFILE "     with linespoints t 'filter' lt -1 pt 6 ps 0.4 lw 3  ";
#printf CMDFILE ", ";
#printf CMDFILE "  145 t '' lt 2 lw 3 ";
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`;




# plot showing unperturbed filter and cool star only
$title = "An unperturbed filter observes a cool star";
$cmdfile = "make_plots_c.gnu";
$psfile = "make_plots_c.ps";
open(CMDFILE, ">$cmdfile") || die("can't open $cmdfile");
printf CMDFILE "set output '$psfile' \n";
printf CMDFILE "set term postscript color \n";
printf CMDFILE "set grid \n";
printf CMDFILE "set key top left \n";
printf CMDFILE "set xlabel 'Wavelength (nm)' \n";
printf CMDFILE "set ylabel 'Filter transmission / Stellar flambda'  \n";
printf CMDFILE "set title '$title'  \n";
printf CMDFILE "plot [100:1000][0.0:1.3] ";
#printf CMDFILE " '$hot_star' using (\$2*1E9):(\$3/1.0E15) ";
#printf CMDFILE "     with lines t 'star T = 12000 K' lt 3 lw 2  ";
#printf CMDFILE ", ";
printf CMDFILE " '$cool_star' using (\$2*1E9):(\$3*80/1.0E15) ";
printf CMDFILE "     with lines t 'star T = 5000 K' lt 1 lw 2  ";
printf CMDFILE ", ";
printf CMDFILE " '$filter' using ((\$1*0.1)):(\$2) ";
printf CMDFILE "     with linespoints t 'filter' lt -1 pt 6 ps 0.4 lw 3  ";
#printf CMDFILE ", ";
#printf CMDFILE "  145 t '' lt 2 lw 3 ";
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`;



# plot showing unperturbed filter and perturbed filter only
$title = "A filter transmission curve slides to the red ";
$cmdfile = "make_plots_d.gnu";
$psfile = "make_plots_d.ps";
open(CMDFILE, ">$cmdfile") || die("can't open $cmdfile");
printf CMDFILE "set output '$psfile' \n";
printf CMDFILE "set term postscript color \n";
printf CMDFILE "set grid \n";
printf CMDFILE "set key top left \n";
printf CMDFILE "set xlabel 'Wavelength (nm)' \n";
printf CMDFILE "set ylabel 'Filter transmission / Stellar flambda'  \n";
printf CMDFILE "set title '$title'  \n";
printf CMDFILE "plot [100:1000][0.0:1.3] ";
#printf CMDFILE " '$hot_star' using (\$2*1E9):(\$3/1.0E15) ";
#printf CMDFILE "     with lines t 'star T = 12000 K' lt 3 lw 2  ";
#printf CMDFILE ", ";
#printf CMDFILE " '$cool_star' using (\$2*1E9):(\$3*80/1.0E15) ";
#printf CMDFILE "     with lines t 'star T = 5000 K' lt 1 lw 2  ";
#printf CMDFILE ", ";
printf CMDFILE " '$filter' using ((\$1*0.1)):(\$2) ";
printf CMDFILE "     with linespoints t 'original filter'  lt -1 pt 6 ps 0.4 lw 3  ";
printf CMDFILE ", ";
printf CMDFILE " '$filter' using ((\$1*0.1)+20):(\$2) ";
printf CMDFILE "     with lines t 'perturbed filter'  lt -1 lw 1  ";
#printf CMDFILE "  145 t '' lt 2 lw 3 ";
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`;




# plot showing perturbed filter and hot star only
$title = "The perturbed filter observes a hot star";
$cmdfile = "make_plots_e.gnu";
$psfile = "make_plots_e.ps";
open(CMDFILE, ">$cmdfile") || die("can't open $cmdfile");
printf CMDFILE "set output '$psfile' \n";
printf CMDFILE "set term postscript color \n";
printf CMDFILE "set grid \n";
printf CMDFILE "set key top left \n";
printf CMDFILE "set xlabel 'Wavelength (nm)' \n";
printf CMDFILE "set ylabel 'Filter transmission / Stellar flambda'  \n";
printf CMDFILE "set title '$title'  \n";
printf CMDFILE "plot [100:1000][0.0:1.3] ";
printf CMDFILE " '$hot_star' using (\$2*1E9):(\$3/1.0E15) ";
printf CMDFILE "     with lines t 'star T = 12000 K' lt 3 lw 2  ";
printf CMDFILE ", ";
#printf CMDFILE " '$cool_star' using (\$2*1E9):(\$3*80/1.0E15) ";
#printf CMDFILE "     with lines t 'star T = 5000 K' lt 1 lw 2  ";
#printf CMDFILE ", ";
printf CMDFILE " '$filter' using ((\$1*0.1)+20):(\$2) ";
printf CMDFILE "     with lines t 'perturbed filter' lt -1 lw 1  ";
#printf CMDFILE ", ";
#printf CMDFILE "  145 t '' lt 2 lw 3 ";
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`;



# plot showing perturbed filter and cool star only
$title = "The perturbed filter observes a cool star";
$cmdfile = "make_plots_f.gnu";
$psfile = "make_plots_f.ps";
open(CMDFILE, ">$cmdfile") || die("can't open $cmdfile");
printf CMDFILE "set output '$psfile' \n";
printf CMDFILE "set term postscript color \n";
printf CMDFILE "set grid \n";
printf CMDFILE "set key top left \n";
printf CMDFILE "set xlabel 'Wavelength (nm)' \n";
printf CMDFILE "set ylabel 'Filter transmission / Stellar flambda'  \n";
printf CMDFILE "set title '$title'  \n";
printf CMDFILE "plot [100:1000][0.0:1.3] ";
#printf CMDFILE " '$hot_star' using (\$2*1E9):(\$3/1.0E15) ";
#printf CMDFILE "     with lines t 'star T = 12000 K' lt 3 lw 2  ";
#printf CMDFILE ", ";
printf CMDFILE " '$cool_star' using (\$2*1E9):(\$3*80/1.0E15) ";
printf CMDFILE "     with lines t 'star T = 5000 K' lt 1 lw 2  ";
printf CMDFILE ", ";
printf CMDFILE " '$filter' using ((\$1*0.1)+20):(\$2) ";
printf CMDFILE "     with lines t 'perturbed filter' lt -1 lw 1  ";
#printf CMDFILE ", ";
#printf CMDFILE "  145 t '' lt 2 lw 3 ";
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;
