#!/usr/bin/perl
#

  
  my($output_file, $term_options);

  # wide portion of spectrum of zeta Oph: 500 - 600 nm
  $output_file = "zeta_oph_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";

  #  revert to some oldish default colors 
  printf CMDFILE "set style line 1 lt rgb 'red' lw 2  \n"; 
  printf CMDFILE "set style line 2 lt rgb 'sea-green' lw 2  \n"; 
  printf CMDFILE "set style line 3 lt rgb 'blue' lw 2  \n"; 
  printf CMDFILE "set style line 4 lt rgb 'cyan' lw 2  \n"; 
  printf CMDFILE "set style line 5 lt rgb 'violet' lw 2  \n"; 


  

  printf CMDFILE "set grid \n";
  printf CMDFILE "set key top right \n";
  printf CMDFILE "set ylabel 'Relative intensity'  \n";
  printf CMDFILE "set xlabel 'Wavelength (nm) ' \n";
  printf CMDFILE "set title 'Spectrum of zeta Oph'\n";
  
  $cmd = "plot [480:580][]  ";
  $cmd .= "   './336481_melchiors_spectrum_t1.txt' using (\$2*0.1):3 ";
  $cmd .= "       with lines ls 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;
    $giffile = $psfile;
    $giffile =~ s/.ps/.png/;
    $cmd = "convert -flatten -background white -rotate 90 $psfile $giffile";
    printf "cmd is ..$cmd.. \n";
    $ret = `$cmd`;
  }



  # smaller portion of spectrum of zeta Oph: 540 - 550 nm
  $output_file = "zeta_oph_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";

  #  revert to some oldish default colors 
  printf CMDFILE "set style line 1 lt rgb 'red' lw 2  \n"; 
  printf CMDFILE "set style line 2 lt rgb 'sea-green' lw 2  \n"; 
  printf CMDFILE "set style line 3 lt rgb 'blue' lw 2  \n"; 
  printf CMDFILE "set style line 4 lt rgb 'cyan' lw 2  \n"; 
  printf CMDFILE "set style line 5 lt rgb 'violet' lw 2  \n"; 


  

  printf CMDFILE "set grid \n";
  printf CMDFILE "set key top right \n";
  printf CMDFILE "set ylabel 'Relative intensity'  \n";
  printf CMDFILE "set xlabel 'Wavelength (nm) ' \n";
  printf CMDFILE "set title 'Spectrum of zeta Oph'\n";
  
  $cmd = "plot [540:550][]  ";
  $cmd .= "   './336481_melchiors_spectrum_t1.txt' using (\$2*0.1):3 ";
  $cmd .= "       with lines ls 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;
    $giffile = $psfile;
    $giffile =~ s/.ps/.png/;
    $cmd = "convert -flatten -background white -rotate 90 $psfile $giffile";
    printf "cmd is ..$cmd.. \n";
    $ret = `$cmd`;
  }



  # very small portion of spectrum of zeta Oph: 544 - 545 nm
  $output_file = "zeta_oph_c.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";

  #  revert to some oldish default colors 
  printf CMDFILE "set style line 1 lt rgb 'red' lw 2  \n"; 
  printf CMDFILE "set style line 2 lt rgb 'sea-green' lw 2  \n"; 
  printf CMDFILE "set style line 3 lt rgb 'blue' lw 2  \n"; 
  printf CMDFILE "set style line 4 lt rgb 'cyan' lw 2  \n"; 
  printf CMDFILE "set style line 5 lt rgb 'violet' lw 2  \n"; 


  

  printf CMDFILE "set grid \n";
  printf CMDFILE "set key top right \n";
  printf CMDFILE "set ylabel 'Relative intensity'  \n";
  printf CMDFILE "set xlabel 'Wavelength (nm) ' \n";
  printf CMDFILE "set title 'Spectrum of zeta Oph'\n";
  
  $cmd = "plot [544:545][]  ";
  $cmd .= "   './336481_melchiors_spectrum_t1.txt' using (\$2*0.1):3 ";
  $cmd .= "       with lines ls 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;
    $giffile = $psfile;
    $giffile =~ s/.ps/.png/;
    $cmd = "convert -flatten -background white -rotate 90 $psfile $giffile";
    printf "cmd is ..$cmd.. \n";
    $ret = `$cmd`;
  }






exit 0;
