#!/usr/bin/perl
#

  my($output_file, $term_options);

  # Examples of classes M only, total range 2000 - 25000 Angstroms
  $output_file = "./pickle_m_only.ps";
  $term_options = "postscript color 'Helvectica,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 3  \n"; 
  printf CMDFILE "set style line 2 lt rgb 'sea-green' lw 3  \n"; 
  printf CMDFILE "set style line 3 lt rgb 'blue' lw 3  \n"; 
  printf CMDFILE "set style line 4 lt rgb 'cyan' lw 3  \n"; 
  printf CMDFILE "set style line 5 lt rgb 'violet' lw 3  \n"; 
  printf CMDFILE "set style line 6 lt rgb 'orange' lw 3  \n"; 
  printf CMDFILE "set style line 7 lt rgb 'black' lw 3  \n"; 


  printf CMDFILE "set grid \n";
  printf CMDFILE "set key top left \n";
  printf CMDFILE "set ylabel 'Intensity (arbitrary scale)' \n";
  printf CMDFILE "set xlabel 'Wavelength (Angstroms) ' \n";
  
  $cmd = "plot [][] 'ukm0v_dat' using (\$1):(\$2)  ";
  $cmd .= "   with lines  ls 1  t 'M0V' ";

  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 -rotate 90 $psfile $giffile";
    printf "cmd is ..$cmd.. \n";
    $ret = `$cmd`;
  }


  # Examples of classes M only, range 3500 - 8000 Angstroms
  $output_file = "./pickle_m_opt.ps";
  $term_options = "postscript color 'Helvectica,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 3  \n"; 
  printf CMDFILE "set style line 2 lt rgb 'sea-green' lw 3  \n"; 
  printf CMDFILE "set style line 3 lt rgb 'blue' lw 3  \n"; 
  printf CMDFILE "set style line 4 lt rgb 'cyan' lw 3  \n"; 
  printf CMDFILE "set style line 5 lt rgb 'violet' lw 3  \n"; 
  printf CMDFILE "set style line 6 lt rgb 'orange' lw 3  \n"; 
  printf CMDFILE "set style line 7 lt rgb 'black' lw 3  \n"; 


  printf CMDFILE "set grid \n";
  printf CMDFILE "set key top left \n";
  printf CMDFILE "set ylabel 'Intensity (arbitrary scale)' \n";
  printf CMDFILE "set xlabel 'Wavelength (Angstroms) ' \n";
  
  $cmd = "plot [3500:5000][] 'ukm0v_dat' using (\$1):(\$2)  ";
  $cmd .= "   with lines  ls 1  t 'M0V' ";

  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 -rotate 90 $psfile $giffile";
    printf "cmd is ..$cmd.. \n";
    $ret = `$cmd`;
  }




  # Examples of classes O through M, range 3500 - 8000 Angstroms
  $output_file = "./pickle_all.ps";
  $term_options = "postscript color 'Helvectica,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 3  \n"; 
  printf CMDFILE "set style line 2 lt rgb 'sea-green' lw 3  \n"; 
  printf CMDFILE "set style line 3 lt rgb 'blue' lw 3  \n"; 
  printf CMDFILE "set style line 4 lt rgb 'cyan' lw 3  \n"; 
  printf CMDFILE "set style line 5 lt rgb 'violet' lw 3  \n"; 
  printf CMDFILE "set style line 6 lt rgb 'orange' lw 3  \n"; 
  printf CMDFILE "set style line 7 lt rgb 'black' lw 3  \n"; 


  printf CMDFILE "set grid \n";
  printf CMDFILE "set key top right \n";
  printf CMDFILE "set ylabel 'Intensity (arbitrary scale)' \n";
  printf CMDFILE "set xlabel 'Wavelength (Angstroms) ' \n";
  
  $cmd = "plot [3500:8000][] 'uko5v_dat' using (\$1):(\$2)  ";
  $cmd .= "   with lines  ls 1  t 'O5V' ";
  $cmd .= " , ";
  $cmd .= "                  'ukb0v_dat' using (\$1):(\$2)  ";
  $cmd .= "   with lines  ls 2  t 'B0V' ";
  $cmd .= " , ";
  $cmd .= "                  'uka0v_dat' using (\$1):(\$2)  ";
  $cmd .= "   with lines  ls 3  t 'A0V' ";
  $cmd .= " , ";
  $cmd .= "                  'ukf0v_dat' using (\$1):(\$2)  ";
  $cmd .= "   with lines  ls 4  t 'F0V' ";
  $cmd .= " , ";
  $cmd .= "                  'ukg0v_dat' using (\$1):(\$2)  ";
  $cmd .= "   with lines  ls 5  t 'G0V' ";
  $cmd .= " , ";
  $cmd .= "                  'ukk0v_dat' using (\$1):(\$2)  ";
  $cmd .= "   with lines  ls 6  t 'K0V' ";
  $cmd .= " , ";
  $cmd .= "                  'ukm0v_dat' using (\$1):(\$2)  ";
  $cmd .= "   with lines  ls 7  t 'M0V' ";

  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 -rotate 90 $psfile $giffile";
    printf "cmd is ..$cmd.. \n";
    $ret = `$cmd`;
  }




  # Examples of classes O through M, range 3700 - 5000 Angstroms
  $output_file = "./pickle_blue.ps";
  $term_options = "postscript color 'Helvectica,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 3  \n"; 
  printf CMDFILE "set style line 2 lt rgb 'sea-green' lw 3  \n"; 
  printf CMDFILE "set style line 3 lt rgb 'blue' lw 3  \n"; 
  printf CMDFILE "set style line 4 lt rgb 'cyan' lw 3  \n"; 
  printf CMDFILE "set style line 5 lt rgb 'violet' lw 3  \n"; 
  printf CMDFILE "set style line 6 lt rgb 'orange' lw 3  \n"; 
  printf CMDFILE "set style line 7 lt rgb 'black' lw 3  \n"; 


  printf CMDFILE "set grid \n";
  printf CMDFILE "set key top right \n";
  printf CMDFILE "set ylabel 'Intensity (arbitrary scale)' \n";
  printf CMDFILE "set xlabel 'Wavelength (Angstroms) ' \n";
  
  $cmd = "plot [3700:5000][] 'uko5v_dat' using (\$1):(\$2*0.7)  ";
  $cmd .= "   with lines  ls 1  t 'O5V' ";
  $cmd .= " , ";
  $cmd .= "                  'ukb0v_dat' using (\$1):(\$2*0.6)  ";
  $cmd .= "   with lines  ls 2  t 'B0V' ";
  $cmd .= " , ";
  $cmd .= "                  'uka0v_dat' using (\$1):(\$2)  ";
  $cmd .= "   with lines  ls 3  t 'A0V' ";
  $cmd .= " , ";
  $cmd .= "                  'ukf0v_dat' using (\$1):(\$2)  ";
  $cmd .= "   with lines  ls 4  t 'F0V' ";
  $cmd .= " , ";
  $cmd .= "                  'ukg0v_dat' using (\$1):(\$2)  ";
  $cmd .= "   with lines  ls 5  t 'G0V' ";
  $cmd .= " , ";
  $cmd .= "                  'ukk0v_dat' using (\$1):(\$2)  ";
  $cmd .= "   with lines  ls 6  t 'K0V' ";
  $cmd .= " , ";
  $cmd .= "                  'ukm0v_dat' using (\$1):(\$2)  ";
  $cmd .= "   with lines  ls 7  t 'M0V' ";

  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 -rotate 90 $psfile $giffile";
    printf "cmd is ..$cmd.. \n";
    $ret = `$cmd`;
  }



  # Examples of classes O through M, range 3700 - 5000 Angstroms
  #   only the hot stars O through A
  $output_file = "./pickle_blue_a.ps";
  $term_options = "postscript color 'Helvectica,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 3  \n"; 
  printf CMDFILE "set style line 2 lt rgb 'sea-green' lw 3  \n"; 
  printf CMDFILE "set style line 3 lt rgb 'blue' lw 3  \n"; 
  printf CMDFILE "set style line 4 lt rgb 'cyan' lw 3  \n"; 
  printf CMDFILE "set style line 5 lt rgb 'violet' lw 3  \n"; 
  printf CMDFILE "set style line 6 lt rgb 'orange' lw 3  \n"; 
  printf CMDFILE "set style line 7 lt rgb 'black' lw 3  \n"; 


  printf CMDFILE "set grid \n";
  printf CMDFILE "set key top right \n";
  printf CMDFILE "set ylabel 'Intensity (arbitrary scale)' \n";
  printf CMDFILE "set xlabel 'Wavelength (Angstroms) ' \n";
  
  $cmd = "plot [3700:5000][] 'uko5v_dat' using (\$1):(\$2*1.0)  ";
  $cmd .= "   with lines  ls 1  t 'O5V' ";
  $cmd .= " , ";
  $cmd .= "                  'ukb0v_dat' using (\$1):(\$2*0.85)  ";
  $cmd .= "   with lines  ls 2  t 'B0V' ";
  $cmd .= " , ";
  $cmd .= "                  'uka0v_dat' using (\$1):(\$2)  ";
  $cmd .= "   with lines  ls 3  t 'A0V' ";
#  $cmd .= " , ";
#  $cmd .= "                  'ukf0v_dat' using (\$1):(\$2)  ";
#  $cmd .= "   with lines  ls 4  t 'F0V' ";
#  $cmd .= " , ";
#  $cmd .= "                  'ukg0v_dat' using (\$1):(\$2)  ";
#  $cmd .= "   with lines  ls 5  t 'G0V' ";
#  $cmd .= " , ";
#  $cmd .= "                  'ukk0v_dat' using (\$1):(\$2)  ";
#  $cmd .= "   with lines  ls 6  t 'K0V' ";
#  $cmd .= " , ";
#  $cmd .= "                  'ukm0v_dat' using (\$1):(\$2)  ";
#  $cmd .= "   with lines  ls 7  t 'M0V' ";

  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 -rotate 90 $psfile $giffile";
    printf "cmd is ..$cmd.. \n";
    $ret = `$cmd`;
  }



  # Examples of classes O through M, range 3700 - 5000 Angstroms
  #   only the cool stars F through M
  $output_file = "./pickle_blue_b.ps";
  $term_options = "postscript color 'Helvectica,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 3  \n"; 
  printf CMDFILE "set style line 2 lt rgb 'sea-green' lw 3  \n"; 
  printf CMDFILE "set style line 3 lt rgb 'blue' lw 3  \n"; 
  printf CMDFILE "set style line 4 lt rgb 'cyan' lw 3  \n"; 
  printf CMDFILE "set style line 5 lt rgb 'violet' lw 3  \n"; 
  printf CMDFILE "set style line 6 lt rgb 'orange' lw 3  \n"; 
  printf CMDFILE "set style line 7 lt rgb 'black' lw 3  \n"; 


  #printf CMDFILE "f(x) = a + b*x + c*x*x \n";
  #printf CMDFILE "fit f(x) './ukm0v_dat' using 1:2 via a, b, c \n";

  printf CMDFILE "set grid \n";
  printf CMDFILE "set key top right \n";
  printf CMDFILE "set ylabel 'Intensity (arbitrary scale)' \n";
  printf CMDFILE "set xlabel 'Wavelength (Angstroms) ' \n";
  
  $cmd = "plot [3700:5000][] 'ukf0v_dat' using (\$1):(\$2)  ";
  $cmd .= "   with lines  ls 4  t 'F0V' ";
  $cmd .= " , ";
  $cmd .= "                  'ukg0v_dat' using (\$1):(\$2)  ";
  $cmd .= "   with lines  ls 5  t 'G0V' ";
  $cmd .= " , ";
  $cmd .= "                  'ukk0v_dat' using (\$1):(\$2)  ";
  $cmd .= "   with lines  ls 6  t 'K0V' ";
  $cmd .= " , ";
  $cmd .= "                  'ukm0v_dat' using (\$1):(\$2*1.2)  ";
  $cmd .= "   with lines  ls 7  t 'M0V' ";

  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 -rotate 90 $psfile $giffile";
    printf "cmd is ..$cmd.. \n";
    $ret = `$cmd`;
  }


  # Examples of a bracketed comparison 
  $output_file = "./pickle_bracket.ps";
  $term_options = "postscript color 'Helvectica,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 3  \n"; 
  printf CMDFILE "set style line 2 lt rgb 'sea-green' lw 3  \n"; 
  printf CMDFILE "set style line 3 lt rgb 'blue' lw 3  \n"; 
  printf CMDFILE "set style line 4 lt rgb 'cyan' lw 3  \n"; 
  printf CMDFILE "set style line 5 lt rgb 'violet' lw 3  \n"; 
  printf CMDFILE "set style line 6 lt rgb 'orange' lw 3  \n"; 
  printf CMDFILE "set style line 7 lt rgb 'black' lw 3  \n"; 


  printf CMDFILE "set grid \n";
  printf CMDFILE "set key top left \n";
  printf CMDFILE "set ylabel 'Intensity (arbitrary scale)' \n";
  printf CMDFILE "set xlabel 'Wavelength (Angstroms) ' \n";
  
  $cmd = "plot [3700:5000][] 'ukk0v_dat' using (\$1):(0.3+\$2*1.5)  ";
  $cmd .= "   with lines  ls 4  t 'K0V' ";
  $cmd .= " , ";
  $cmd .= "                  'ukk7v_dat' using (\$1):(0.4+\$2*1.5)  ";
  $cmd .= "   with lines  ls 5  t 'target' ";
  $cmd .= " , ";
  $cmd .= "                  'ukm0v_dat' using (\$1):(0.0+\$2*1.5)  ";
  $cmd .= "   with lines  ls 6  t 'M0V' ";

  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 -rotate 90 $psfile $giffile";
    printf "cmd is ..$cmd.. \n";
    $ret = `$cmd`;
  }





exit 0;
