#!/usr/bin/perl
#


  my($output_file, $term_options);

  # get the arguments
  $output_file = "temp_vs_colors.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 "set key top right \n";
  printf CMDFILE "set ylabel 'Effective Temperature' \n";
  printf CMDFILE "set xlabel 'Measured color ' \n";
  printf CMDFILE "set title 'Stellar properties from Mamajek compilation' \n";
  
  $cmd = "plot [-1.5:2.5][0:35000] './EEM_dwarf_UBVIJHK_colors_Teff.txt' ";
  $cmd .=  "   using 7:2 with points pt 3 ps 1.2 lw 3 t '(B-V)' ";
  $cmd .=  " , " ;
  $cmd .= "                './EEM_dwarf_UBVIJHK_colors_Teff.txt' ";
  $cmd .=  "   using 9:2 with points pt 6 ps 1.0 lc -1 lw 3 t '(U-B)' \n";

  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`;
  }



#####################################################################
#   Temperature of dwarf stars vs. spectral-type number
#

  my($output_file, $term_options);

  # get the arguments
  $output_file = "temp_vs_spnum.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 "set key top right \n";
  printf CMDFILE "set ylabel 'Effective Temperature' \n";
  printf CMDFILE "set xlabel 'Spectral-type numerical score' \n";
  printf CMDFILE "set title 'Stellar properties from Mamajek compilation' \n";
  
  $cmd = "plot [100:5][0:35000] './compute_temp.out' ";
  $cmd .=  "   using 5:7 with points pt 3 ps 1.2 lw 3 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 -rotate 90 $psfile $giffile";
    printf "cmd is ..$cmd.. \n";
    $ret = `$cmd`;
  }




#####################################################################
#   Spectral-type numerical score vs. (B-V) color
#

  my($output_file, $term_options);

  # get the arguments
  $output_file = "spnum_vs_color.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 "set key top right \n";
  printf CMDFILE "set ylabel 'Spectral-type numerical score' \n";
  printf CMDFILE "set xlabel '(B-V) color ' \n";
  printf CMDFILE "set title 'Stellar properties from Mamajek compilation' \n";
  
  $cmd = "plot [-1.0:2.5][] './compute_temp.out' ";
  $cmd .=  "   using 9:5 with points pt 3 ps 1.2 lw 3 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 -rotate 90 $psfile $giffile";
    printf "cmd is ..$cmd.. \n";
    $ret = `$cmd`;
  }





exit 0;
