#!/usr/bin/perl
#

  
  my($output_file, $term_options);

  # Compare spectra of Sun and two solar twins
  #   over range 5510 - 5540 Angstroms
  $output_file = "solar_twins_a.ps";
  $term_options = "postscript color enhanced '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 "unset key \n";
  printf CMDFILE "set ylabel 'Intensity (arbitrary scale)'  \n";
  printf CMDFILE "set xlabel 'Rest Wavelength (Angstroms) ' \n";
  printf CMDFILE "set title 'Sun (bottom) and solar twins HD 183658 (mid), HD 78760 (top)'\n";
  
  $cmd = "plot [5510:5540][]  ";
  $cmd .= "   './hd183658_elodie.dat' using (\$1*0.99975):(\$2) ";
  $cmd .= "       with lines lw 2 lc rgbcolor \"red\" ";
  $cmd .= " , ";
  $cmd .= "   './hd78860_elodie.dat' using (\$1*1.00012):(8000+(\$2*3)) ";
  $cmd .= "       with lines lw 2 lc rgbcolor \"blue\" ";
  $cmd .= " , ";
  $cmd .= "   './bass_solar_5450.dat' using (\$1*1):(\$2*0.80) ";
  $cmd .= "       with lines lw 2 lc rgbcolor \"black\" ";

  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;
    $giffile = $psfile;
    $giffile =~ s/.ps/.png/;
    $cmd = "convert -flatten -background white -rotate 90 $psfile $giffile";
    printf "cmd is ..$cmd.. \n";
    $ret = `$cmd`;
  }


  # Compare spectra of Sun and two solar twins
  #   over range 5525 - 5538 Angstroms
  $output_file = "solar_twins_b.ps";
  $term_options = "postscript color enhanced '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 "unset key \n";
  printf CMDFILE "set ylabel 'Intensity (arbitrary scale)'  \n";
  printf CMDFILE "set xlabel 'Rest Wavelength (Angstroms) ' \n";
  printf CMDFILE "set title 'Sun (bottom) and solar twins HD 183658 (mid), HD 78760 (top)'\n";
  
  $cmd = "plot [5525:5538][]  ";
  $cmd .= "   './hd183658_elodie.dat' using (\$1*0.99974):(\$2) ";
  $cmd .= "       with lines lw 2 lc rgbcolor \"red\" ";
  $cmd .= " , ";
  $cmd .= "   './hd78860_elodie.dat' using (\$1*1.00012):(8000+(\$2*3)) ";
  $cmd .= "       with lines lw 2 lc rgbcolor \"blue\" ";
  $cmd .= " , ";
  $cmd .= "   './bass_solar_5450.dat' using (\$1*1):(\$2*0.80) ";
  $cmd .= "       with lines lw 2 lc rgbcolor \"black\" ";

  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;
    $giffile = $psfile;
    $giffile =~ s/.ps/.png/;
    $cmd = "convert -flatten -background white -rotate 90 $psfile $giffile";
    printf "cmd is ..$cmd.. \n";
    $ret = `$cmd`;
  }





exit 0;
