#!/usr/bin/perl
#
# Make plots for the MACHO RR0 Lyr paper
  
  my($output_file, $term_options);


##########################################################################
# Make a plot showing composite SDSS spectrum, rest wavelength
#
# MWR 3/8/2013
#

  # get the arguments

  $output_file = "qso_rest.ps";
  $term_options = "postscript color enhanced font 'Helvetica,18' ";

  $cmdfile = "gnuplot.in";
  
  open (CMDFILE, ">$cmdfile") || die("can't open $cmdfile for writing");
  printf CMDFILE "set output '$output_file' \n";
  printf CMDFILE "set term $term_options \n";
  # printf CMDFILE "set grid \n";
  #printf CMDFILE "set nokey \n";
  printf CMDFILE "set key top right \n";
  printf CMDFILE "set label 1 'g filter' at 420,12 font \"Helvetica,18\" tc lt 3 \n";
  printf CMDFILE "set label 2 'i filter' at 700,12 font \"Helvetica,18\" tc lt 1 \n";
  printf CMDFILE "set xlabel 'Wavelength (nm)'  \n";
  printf CMDFILE "set ylabel 'Intensity of light' \n";
  printf CMDFILE "set title 'Quasar spectrum: rest wavelength '\n";
  
  $cmd = "plot [50:1000][] ";
  $cmd .= " 'sdss_qso_spec.dat' ";
  $cmd .= "    using (\$1*0.1):(\$2) with lines lt -1 lw 1 t ''  ";
  $cmd .= " , ";
  $cmd .= " 'sdss_g.pass' ";
  $cmd .= "    using (\$1*0.1):(\$2*10) with lines lt 1 lw 1 lc 3 t ''   ";
  $cmd .= " , ";
  $cmd .= " 'sdss_i.pass' ";
  $cmd .= "    using (\$1*0.1):(\$2*10) with lines lt 1 lw 1 lc 1 t ''   ";


  printf CMDFILE "$cmd \n";
  printf CMDFILE "set output \n";
  printf CMDFILE "quit \n";
  close(CMDFILE) ;
  
  $retval = `gnuplot < $cmdfile`;
  printf "retval is ..%s..\n", $retval;
  
  if ($term_options =~ /postscript/) {
    $psfile = $output_file;
    $pngfile = $psfile;
    $pngfile =~ s/.ps/.png/;
    $cmd = "convert -rotate 90 -geometry 720x504 $psfile $pngfile";
    printf "cmd is ..$cmd.. \n";
    $ret = `$cmd`;
  }



##########################################################################
# Make a plot showing composite SDSS spectrum, z = 1
#
# MWR 3/8/2013
#

  # get the arguments

  $output_file = "qso_z=1.ps";
  $term_options = "postscript color enhanced font 'Helvetica,18' ";

  $cmdfile = "gnuplot.in";
  
  open (CMDFILE, ">$cmdfile") || die("can't open $cmdfile for writing");
  printf CMDFILE "set output '$output_file' \n";
  printf CMDFILE "set term $term_options \n";
  # printf CMDFILE "set grid \n";
  #printf CMDFILE "set nokey \n";
  printf CMDFILE "set key top right \n";
  printf CMDFILE "set label 1 'g filter' at 420,12 font \"Helvetica,18\" tc lt 3 \n";
  printf CMDFILE "set label 2 'i filter' at 700,12 font \"Helvetica,18\" tc lt 1 \n";
  printf CMDFILE "set xlabel 'Wavelength (nm)'  \n";
  printf CMDFILE "set ylabel 'Intensity of light' \n";
  printf CMDFILE "set title 'Quasar spectrum: redshift z = 1 '\n";
  
  $cmd = "plot [50:1000][] ";
  $cmd .= " 'sdss_qso_z=1.dat' ";
  $cmd .= "    using (\$1*0.1):(\$2) with lines lt -1 lw 1 t ''  ";
  $cmd .= " , ";
  $cmd .= " 'sdss_g.pass' ";
  $cmd .= "    using (\$1*0.1):(\$2*10) with lines lt 1 lw 1 lc 3 t ''   ";
  $cmd .= " , ";
  $cmd .= " 'sdss_i.pass' ";
  $cmd .= "    using (\$1*0.1):(\$2*10) with lines lt 1 lw 1 lc 1 t ''   ";


  printf CMDFILE "$cmd \n";
  printf CMDFILE "set output \n";
  printf CMDFILE "quit \n";
  close(CMDFILE) ;
  
  $retval = `gnuplot < $cmdfile`;
  printf "retval is ..%s..\n", $retval;
  
  if ($term_options =~ /postscript/) {
    $psfile = $output_file;
    $pngfile = $psfile;
    $pngfile =~ s/.ps/.png/;
    $cmd = "convert -rotate 90 -geometry 720x504 $psfile $pngfile";
    printf "cmd is ..$cmd.. \n";
    $ret = `$cmd`;
  }


##########################################################################
# Make a plot showing composite SDSS spectrum, z = 2
#
# MWR 3/8/2013
#

  # get the arguments

  $output_file = "qso_z=2.ps";
  $term_options = "postscript color enhanced font 'Helvetica,18' ";

  $cmdfile = "gnuplot.in";
  
  open (CMDFILE, ">$cmdfile") || die("can't open $cmdfile for writing");
  printf CMDFILE "set output '$output_file' \n";
  printf CMDFILE "set term $term_options \n";
  # printf CMDFILE "set grid \n";
  #printf CMDFILE "set nokey \n";
  printf CMDFILE "set key top right \n";
  printf CMDFILE "set label 1 'g filter' at 420,12 font \"Helvetica,18\" tc lt 3 \n";
  printf CMDFILE "set label 2 'i filter' at 700,12 font \"Helvetica,18\" tc lt 1 \n";
  printf CMDFILE "set xlabel 'Wavelength (nm)'  \n";
  printf CMDFILE "set ylabel 'Intensity of light' \n";
  printf CMDFILE "set title 'Quasar spectrum: redshift z = 2 '\n";
  
  $cmd = "plot [50:1000][] ";
  $cmd .= " 'sdss_qso_z=2.dat' ";
  $cmd .= "    using (\$1*0.1):(\$2) with lines lt -1 lw 1 t ''  ";
  $cmd .= " , ";
  $cmd .= " 'sdss_g.pass' ";
  $cmd .= "    using (\$1*0.1):(\$2*10) with lines lt 1 lw 1 lc 3 t ''   ";
  $cmd .= " , ";
  $cmd .= " 'sdss_i.pass' ";
  $cmd .= "    using (\$1*0.1):(\$2*10) with lines lt 1 lw 1 lc 1 t ''   ";


  printf CMDFILE "$cmd \n";
  printf CMDFILE "set output \n";
  printf CMDFILE "quit \n";
  close(CMDFILE) ;
  
  $retval = `gnuplot < $cmdfile`;
  printf "retval is ..%s..\n", $retval;
  
  if ($term_options =~ /postscript/) {
    $psfile = $output_file;
    $pngfile = $psfile;
    $pngfile =~ s/.ps/.png/;
    $cmd = "convert -rotate 90 -geometry 720x504 $psfile $pngfile";
    printf "cmd is ..$cmd.. \n";
    $ret = `$cmd`;
  }



##########################################################################
# Make a plot showing composite SDSS spectrum, z = 3
#
# MWR 3/8/2013
#

  # get the arguments

  $output_file = "qso_z=3.ps";
  $term_options = "postscript color enhanced font 'Helvetica,18' ";

  $cmdfile = "gnuplot.in";
  
  open (CMDFILE, ">$cmdfile") || die("can't open $cmdfile for writing");
  printf CMDFILE "set output '$output_file' \n";
  printf CMDFILE "set term $term_options \n";
  # printf CMDFILE "set grid \n";
  #printf CMDFILE "set nokey \n";
  printf CMDFILE "set key top right \n";
  printf CMDFILE "set label 1 'g filter' at 420,12 font \"Helvetica,18\" tc lt 3 \n";
  printf CMDFILE "set label 2 'i filter' at 700,12 font \"Helvetica,18\" tc lt 1 \n";
  printf CMDFILE "set xlabel 'Wavelength (nm)'  \n";
  printf CMDFILE "set ylabel 'Intensity of light' \n";
  printf CMDFILE "set title 'Quasar spectrum: redshift z = 3 '\n";
  
  $cmd = "plot [50:1000][] ";
  $cmd .= " 'sdss_qso_z=3.dat' ";
  $cmd .= "    using (\$1*0.1):(\$2) with lines lt -1 lw 1 t ''  ";
  $cmd .= " , ";
  $cmd .= " 'sdss_g.pass' ";
  $cmd .= "    using (\$1*0.1):(\$2*10) with lines lt 1 lw 1 lc 3 t ''   ";
  $cmd .= " , ";
  $cmd .= " 'sdss_i.pass' ";
  $cmd .= "    using (\$1*0.1):(\$2*10) with lines lt 1 lw 1 lc 1 t ''   ";


  printf CMDFILE "$cmd \n";
  printf CMDFILE "set output \n";
  printf CMDFILE "quit \n";
  close(CMDFILE) ;
  
  $retval = `gnuplot < $cmdfile`;
  printf "retval is ..%s..\n", $retval;
  
  if ($term_options =~ /postscript/) {
    $psfile = $output_file;
    $pngfile = $psfile;
    $pngfile =~ s/.ps/.png/;
    $cmd = "convert -rotate 90 -geometry 720x504 $psfile $pngfile";
    printf "cmd is ..$cmd.. \n";
    $ret = `$cmd`;
  }





##########################################################################
# Make a plot showing composite SDSS spectrum, z = 4
#
# MWR 3/8/2013
#

  # get the arguments

  $output_file = "qso_z=4.ps";
  $term_options = "postscript color enhanced font 'Helvetica,18' ";

  $cmdfile = "gnuplot.in";
  
  open (CMDFILE, ">$cmdfile") || die("can't open $cmdfile for writing");
  printf CMDFILE "set output '$output_file' \n";
  printf CMDFILE "set term $term_options \n";
  # printf CMDFILE "set grid \n";
  #printf CMDFILE "set nokey \n";
  printf CMDFILE "set key top right \n";
  printf CMDFILE "set label 1 'g filter' at 420,12 font \"Helvetica,18\" tc lt 3 \n";
  printf CMDFILE "set label 2 'i filter' at 700,12 font \"Helvetica,18\" tc lt 1 \n";
  printf CMDFILE "set xlabel 'Wavelength (nm)'  \n";
  printf CMDFILE "set ylabel 'Intensity of light' \n";
  printf CMDFILE "set title 'Quasar spectrum: redshift z = 4 '\n";
  
  $cmd = "plot [50:1000][] ";
  $cmd .= " 'sdss_qso_z=4.dat' ";
  $cmd .= "    using (\$1*0.1):(\$2) with lines lt -1 lw 1 t ''  ";
  $cmd .= " , ";
  $cmd .= " 'sdss_g.pass' ";
  $cmd .= "    using (\$1*0.1):(\$2*10) with lines lt 1 lw 1 lc 3 t ''   ";
  $cmd .= " , ";
  $cmd .= " 'sdss_i.pass' ";
  $cmd .= "    using (\$1*0.1):(\$2*10) with lines lt 1 lw 1 lc 1 t ''   ";


  printf CMDFILE "$cmd \n";
  printf CMDFILE "set output \n";
  printf CMDFILE "quit \n";
  close(CMDFILE) ;
  
  $retval = `gnuplot < $cmdfile`;
  printf "retval is ..%s..\n", $retval;
  
  if ($term_options =~ /postscript/) {
    $psfile = $output_file;
    $pngfile = $psfile;
    $pngfile =~ s/.ps/.png/;
    $cmd = "convert -rotate 90 -geometry 720x504 $psfile $pngfile";
    printf "cmd is ..$cmd.. \n";
    $ret = `$cmd`;
  }






##########################################################################
# Make a plot showing composite SDSS spectrum, z = 5
#
# MWR 3/8/2013
#

  # get the arguments

  $output_file = "qso_z=5.ps";
  $term_options = "postscript color enhanced font 'Helvetica,18' ";

  $cmdfile = "gnuplot.in";
  
  open (CMDFILE, ">$cmdfile") || die("can't open $cmdfile for writing");
  printf CMDFILE "set output '$output_file' \n";
  printf CMDFILE "set term $term_options \n";
  # printf CMDFILE "set grid \n";
  #printf CMDFILE "set nokey \n";
  printf CMDFILE "set key top right \n";
  printf CMDFILE "set label 1 'g filter' at 420,12 font \"Helvetica,18\" tc lt 3 \n";
  printf CMDFILE "set label 2 'i filter' at 700,12 font \"Helvetica,18\" tc lt 1 \n";
  printf CMDFILE "set xlabel 'Wavelength (nm)'  \n";
  printf CMDFILE "set ylabel 'Intensity of light' \n";
  printf CMDFILE "set title 'Quasar spectrum: redshift z = 5 '\n";
  
  $cmd = "plot [50:1000][] ";
  $cmd .= " 'sdss_qso_z=5.dat' ";
  $cmd .= "    using (\$1*0.1):(\$2) with lines lt -1 lw 1 t ''  ";
  $cmd .= " , ";
  $cmd .= " 'sdss_g.pass' ";
  $cmd .= "    using (\$1*0.1):(\$2*10) with lines lt 1 lw 1 lc 3 t ''   ";
  $cmd .= " , ";
  $cmd .= " 'sdss_i.pass' ";
  $cmd .= "    using (\$1*0.1):(\$2*10) with lines lt 1 lw 1 lc 1 t ''   ";


  printf CMDFILE "$cmd \n";
  printf CMDFILE "set output \n";
  printf CMDFILE "quit \n";
  close(CMDFILE) ;
  
  $retval = `gnuplot < $cmdfile`;
  printf "retval is ..%s..\n", $retval;
  
  if ($term_options =~ /postscript/) {
    $psfile = $output_file;
    $pngfile = $psfile;
    $pngfile =~ s/.ps/.png/;
    $cmd = "convert -rotate 90 -geometry 720x504 $psfile $pngfile";
    printf "cmd is ..$cmd.. \n";
    $ret = `$cmd`;
  }




##########################################################################
# Make a plot showing composite SDSS spectrum, z = 6
#
# MWR 3/8/2013
#

  # get the arguments

  $output_file = "qso_z=6.ps";
  $term_options = "postscript color enhanced font 'Helvetica,18' ";

  $cmdfile = "gnuplot.in";
  
  open (CMDFILE, ">$cmdfile") || die("can't open $cmdfile for writing");
  printf CMDFILE "set output '$output_file' \n";
  printf CMDFILE "set term $term_options \n";
  # printf CMDFILE "set grid \n";
  #printf CMDFILE "set nokey \n";
  printf CMDFILE "set key top right \n";
  printf CMDFILE "set label 1 'g filter' at 420,12 font \"Helvetica,18\" tc lt 3 \n";
  printf CMDFILE "set label 2 'i filter' at 700,12 font \"Helvetica,18\" tc lt 1 \n";
  printf CMDFILE "set xlabel 'Wavelength (nm)'  \n";
  printf CMDFILE "set ylabel 'Intensity of light' \n";
  printf CMDFILE "set title 'Quasar spectrum: redshift z = 6 '\n";
  
  $cmd = "plot [50:1000][] ";
  $cmd .= " 'sdss_qso_z=6.dat' ";
  $cmd .= "    using (\$1*0.1):(\$2) with lines lt -1 lw 1 t ''  ";
  $cmd .= " , ";
  $cmd .= " 'sdss_g.pass' ";
  $cmd .= "    using (\$1*0.1):(\$2*10) with lines lt 1 lw 1 lc 3 t ''   ";
  $cmd .= " , ";
  $cmd .= " 'sdss_i.pass' ";
  $cmd .= "    using (\$1*0.1):(\$2*10) with lines lt 1 lw 1 lc 1 t ''   ";


  printf CMDFILE "$cmd \n";
  printf CMDFILE "set output \n";
  printf CMDFILE "quit \n";
  close(CMDFILE) ;
  
  $retval = `gnuplot < $cmdfile`;
  printf "retval is ..%s..\n", $retval;
  
  if ($term_options =~ /postscript/) {
    $psfile = $output_file;
    $pngfile = $psfile;
    $pngfile =~ s/.ps/.png/;
    $cmd = "convert -rotate 90 -geometry 720x504 $psfile $pngfile";
    printf "cmd is ..$cmd.. \n";
    $ret = `$cmd`;
  }









exit 0;
