#!/usr/bin/perl
# 
# Make some nice plots showing various aspects of 
#   periodic signals
# MWR 4/27/2006


# first, a plot of all the measurements (flux)

# datafile with measurements
$data = "./do_analyze_2.out";

# title for all graphs

# graph of a pure sine wave
$title = "A pure sine curve ";
$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 enhanced 'Helvetica' 18 color \n";
printf CMDFILE "set grid \n";
printf CMDFILE "set key top right \n";
printf CMDFILE "set xlabel 'time (days) ' \n";
printf CMDFILE "set ylabel 'Amplitude '  \n";
printf CMDFILE "set title '$title'  \n";
printf CMDFILE "plot [-1:22][-4.0:4.0] ";
printf CMDFILE " 3*sin(x)  ";
printf CMDFILE "     with points t '3 * sin(t)' pt 7 ps 1.0 lw 2  ";
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 a pure sine wave over a long period
$title = "A pure sine curve sampled over many periods ";
$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 enhanced 'Helvetica' 18 color \n";
printf CMDFILE "set grid \n";
printf CMDFILE "set samples 1000 \n";
printf CMDFILE "set key top right \n";
printf CMDFILE "set xlabel 'time (days) ' \n";
printf CMDFILE "set ylabel 'Amplitude '  \n";
printf CMDFILE "set title '$title'  \n";
printf CMDFILE "plot [-1:100][-4.0:4.0] ";
printf CMDFILE " 3*sin(x)  ";
printf CMDFILE "     with points t '3 * sin(t)' pt 7 ps 0.8 lw 2  ";
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 a phased pure sine wave 
$title = "A phase plot of a pure sine curve ";
$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 enhanced 'Helvetica' 18 color \n";
printf CMDFILE "set grid \n";
printf CMDFILE "set samples 1000 \n";
printf CMDFILE "set key top right \n";
printf CMDFILE "set xlabel 'time (days) ' \n";
printf CMDFILE "set ylabel 'Amplitude '  \n";
printf CMDFILE "set title '$title'  \n";
printf CMDFILE "plot [-0.1:1.1][-4.0:4.0] ";
printf CMDFILE " 'sine.dat' using 2:3 ";
printf CMDFILE "     with points t 'data phased with period 6.28 days ' pt 7 ps 0.8 lw 2  ";
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 a pure sine wave phased with slightly wrong period
$title = "A phase plot with a slightly wrong period ";
$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  enhanced 'Helvetica' 18 color \n";
printf CMDFILE "set grid \n";
printf CMDFILE "set samples 1000 \n";
printf CMDFILE "set key top right \n";
printf CMDFILE "set xlabel 'time (days) ' \n";
printf CMDFILE "set ylabel 'Amplitude '  \n";
printf CMDFILE "set title '$title'  \n";
printf CMDFILE "plot [-0.1:1.1][-4.0:4.0] ";
printf CMDFILE " 'sine.dat' using 4:3 ";
printf CMDFILE "     with points t 'data phased with period 6.41 days ' pt 7 ps 0.8 lw 2  ";
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 a pure sine wave phased with very wrong period
$title = "A phase plot with a very wrong period ";
$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  enhanced 'Helvetica' 18 color \n";
printf CMDFILE "set grid \n";
printf CMDFILE "set samples 1000 \n";
printf CMDFILE "set key top right \n";
printf CMDFILE "set xlabel 'time (days) ' \n";
printf CMDFILE "set ylabel 'Amplitude '  \n";
printf CMDFILE "set title '$title'  \n";
printf CMDFILE "plot [-0.1:1.1][-4.0:4.0] ";
printf CMDFILE " 'sine.dat' using 5:3 ";
printf CMDFILE "     with points t 'data phased with period 8.98 days ' pt 7 ps 0.8 lw 2  ";
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 a ASAS 002511 from Sep19,2004 UT
$title = "ASAS 002511 on UT 2004 Sep 19 ";
$cmdfile = "asas_sep19.gnu";
$psfile = "asas_sep19.ps";
$datafile = "asas_sep19ut.dat";
open(CMDFILE, ">$cmdfile") || die("can't open $cmdfile");
printf CMDFILE "set output '$psfile' \n";
printf CMDFILE "set term postscript  enhanced 'Helvetica' 18 color \n";
printf CMDFILE "set grid \n";
printf CMDFILE "set samples 1000 \n";
printf CMDFILE "set key top right \n";
printf CMDFILE "set xlabel 'Julian Date - 2,453,200 ' \n";
printf CMDFILE "set ylabel 'unfiltered mag, shifted to V'  \n";
printf CMDFILE "set title '$title'  \n";
printf CMDFILE "plot [67.53:67.88][11.75:11.4] ";
printf CMDFILE " '$datafile' using (\$2-3200):4 ";
printf CMDFILE "     with points t '' pt 7 ps 0.6 lw 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 a ASAS 002511 from Sep19,2004 UT
#    zoomed in on two consecutive minima
$title = "ASAS 002511 on UT 2004 Sep 19 ";
$cmdfile = "asas_sep19_a.gnu";
$psfile = "asas_sep19_a.ps";
$datafile = "asas_sep19ut.dat";
open(CMDFILE, ">$cmdfile") || die("can't open $cmdfile");
printf CMDFILE "set output '$psfile' \n";
printf CMDFILE "set term postscript  enhanced 'Helvetica' 18 color \n";
printf CMDFILE "set grid \n";
printf CMDFILE "set samples 1000 \n";
printf CMDFILE "set key top right \n";
printf CMDFILE "set xlabel 'Julian Date - 2,453,200 ' \n";
printf CMDFILE "set ylabel 'unfiltered mag, shifted to V'  \n";
printf CMDFILE "set title '$title'  \n";
printf CMDFILE "plot [67.68:67.79][11.65:11.58] ";
printf CMDFILE " '$datafile' using (\$2-3200):4 ";
printf CMDFILE "     with points t '' pt 7 ps 0.6 lw 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 a ASAS 002511 from the next night, Sep20,2004 UT
#    zoomed in on two consecutive minima
$title = "ASAS 002511 on UT 2004 Sep 20 ";
$cmdfile = "asas_sep20.gnu";
$psfile = "asas_sep20.ps";
$datafile = "asas_sep20ut.dat";
open(CMDFILE, ">$cmdfile") || die("can't open $cmdfile");
printf CMDFILE "set output '$psfile' \n";
printf CMDFILE "set term postscript  enhanced 'Helvetica' 18 color \n";
printf CMDFILE "set grid \n";
printf CMDFILE "set samples 1000 \n";
printf CMDFILE "set key top right \n";
printf CMDFILE "set xlabel 'Julian Date - 2,453,200 ' \n";
printf CMDFILE "set ylabel 'unfiltered mag, shifted to V'  \n";
printf CMDFILE "set title '$title'  \n";
printf CMDFILE "plot [68.53:68.71][11.80:11.55] ";
printf CMDFILE " '$datafile' using (\$2-3200):4 ";
printf CMDFILE "     with points t '' pt 7 ps 0.6 lw 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 scattered observations of a pure sine wave
$title = "Scattered, sparse observations of a variable star ";
$cmdfile = "sparse_a.gnu";
$psfile = "sparse_a.ps";
open(CMDFILE, ">$cmdfile") || die("can't open $cmdfile");
printf CMDFILE "set output '$psfile' \n";
printf CMDFILE "set term postscript  enhanced 'Helvetica' 18 color \n";
printf CMDFILE "set grid \n";
printf CMDFILE "set samples 1000 \n";
printf CMDFILE "set key top right \n";
printf CMDFILE "set xlabel 'time (days) ' \n";
printf CMDFILE "set ylabel 'Magnitude '  \n";
printf CMDFILE "set title '$title'  \n";
printf CMDFILE "plot [-5:105][10.5:7] ";
printf CMDFILE " 'sine_sparse.dat' using 1:3 ";
printf CMDFILE "     with points t '' pt 7 ps 0.8 lw 2  ";
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 observations used in string-length example
$title = "Observations of a variable star ";
$cmdfile = "string_a.gnu";
$psfile = "string_a.ps";
open(CMDFILE, ">$cmdfile") || die("can't open $cmdfile");
printf CMDFILE "set output '$psfile' \n";
printf CMDFILE "set term postscript  enhanced 'Helvetica' 18 color \n";
printf CMDFILE "set grid \n";
printf CMDFILE "set samples 1000 \n";
printf CMDFILE "set key top right \n";
printf CMDFILE "set xlabel 'time (days) ' \n";
printf CMDFILE "set ylabel 'Magnitude '  \n";
printf CMDFILE "set title '$title'  \n";
printf CMDFILE "plot [11:19][9.8:8.1] ";
printf CMDFILE " 'string_example.dat' using 1:2 ";
printf CMDFILE "     with points t '' pt 7 ps 0.8 lw 2  ";
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;
