#!/usr/bin/perl
#
# MWR 1/13/2006 

$debug = 1;

# create subsamples based on the i-band magnitude




# graph plot of solar spectrum in linear units vs. wavelength
$data = "./ukg5v_dat";
$title = "Spectrum of the Sun (linear units, vs. wavelength)";
$cmdfile = "./make_plot.gnu";
$psfile = "./make_plot_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 logscale x \n";
#printf CMDFILE "set logscale y \n";
printf CMDFILE "set key top right \n";
printf CMDFILE "set xlabel 'Wavelength (nm)'  \n";
printf CMDFILE "set ylabel 'Flux per unit wavelength' \n";
printf CMDFILE "set title '$title'  \n";
printf CMDFILE "plot [][] ";
printf CMDFILE "  '$data' using (\$1*0.1):(\$2) ";
printf CMDFILE "            t '' pt 1 ps 0.5 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`;


# graph plot of solar spectrum in logarithmic units vs. wavelength
$data = "./ukg5v_dat";
$title = "Spectrum of the Sun (log units, vs. wavelength)";
$cmdfile = "./make_plot.gnu";
$psfile = "./make_plot_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 logscale x \n";
printf CMDFILE "set logscale y \n";
printf CMDFILE "set key top right \n";
printf CMDFILE "set xlabel 'Wavelength (nm)'  \n";
printf CMDFILE "set ylabel 'Flux per unit wavelength' \n";
printf CMDFILE "set title '$title'  \n";
printf CMDFILE "plot [][] ";
printf CMDFILE "  '$data' using (\$1*0.1):(\$2) ";
printf CMDFILE "            t '' pt 1 ps 0.5 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`;



# graph plot of solar spectrum in logarithmic units vs. frequency
$h = 6.626E-34;
$c = 2.9979E8;

$data = "./ukg5v_dat";
$title = "Spectrum of the Sun (log units, vs. frequency)";
$cmdfile = "./make_plot.gnu";
$psfile = "./make_plot_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 logscale x \n";
printf CMDFILE "set logscale y \n";
printf CMDFILE "set key top right \n";
printf CMDFILE "set xlabel 'Frequency (Hz)'  \n";
printf CMDFILE "set ylabel 'Flux per unit wavelength' \n";
printf CMDFILE "set title '$title'  \n";
printf CMDFILE "plot [][] ";
printf CMDFILE "  '$data' using (($c)/(\$1*1E-10)):(\$2) ";
printf CMDFILE "            t '' pt 1 ps 0.5 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;
