#!/usr/bin/perl
#
  
  my($output_file, $term_options);


  #####################################################################
  #  HR diagram with log(L) vs. log(T), with temp running backwards as
  #    usual 
  #
  $output_file = "gaia_hr_log_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 3  \n"; 
  printf CMDFILE "set style line 2 lt rgb 'sea-green' lw 8  \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 grid \n";
  printf CMDFILE "set key top right \n";
  printf CMDFILE "set logscale x \n";
  printf CMDFILE "set logscale y \n";
  printf CMDFILE "set ylabel 'Luminosity (solar) ' \n";
  printf CMDFILE "set xlabel 'Temperature (K) ' \n";

  printf CMDFILE "set xtics (15000, 10000, 6000, 4000) \n";


  printf CMDFILE "set title 'Nearby Stars in Gaia DR3'  \n";
  
  $cmd = "plot [12000:2500][1.0e-3:1.0e2] 'parse_gaia.out'  ";
  $cmd .= "   using 1:5 ls 1 ps 0.2 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 -background white -flatten -rotate 90 $psfile $giffile";
    printf "cmd is ..$cmd.. \n";
    $ret = `$cmd`;
  }


  #####################################################################
  #  HR diagram with log(L) vs. log(T), with temp running backwards as
  #    usual 
  #
  #  We also show line for L = T^4
  #
  $output_file = "gaia_hr_log_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 3  \n"; 
  printf CMDFILE "set style line 2 lt rgb 'sea-green' lw 8  \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 grid \n";
  printf CMDFILE "set key top right \n";
  printf CMDFILE "set logscale x \n";
  printf CMDFILE "set logscale y \n";
  printf CMDFILE "set ylabel 'Luminosity (solar) ' \n";
  printf CMDFILE "set xlabel 'Temperature (K) ' \n";

  printf CMDFILE "set xtics (15000, 10000, 6000, 4000) \n";


  printf CMDFILE "set title 'Nearby Stars in Gaia DR3'  \n";
  
  $cmd = "plot [12000:2500][1.0e-3:1.0e2] 'parse_gaia.out'  ";
  $cmd .= "   using 1:5 ls 1 ps 0.2 t '' ";
  $cmd .= " , ";
  $cmd .= "    './make_power_lines.out' index 0 ";
  $cmd .= "   using 1:2 ls 2 with lines  t 'L {/Symbol \\265} T^4' ";

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


  #####################################################################
  #  HR diagram with log(L) vs. log(T), with temp running backwards as
  #    usual 
  #
  #  We also show line for L = T^4 and L = T^7
  #
  $output_file = "gaia_hr_log_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 3  \n"; 
  printf CMDFILE "set style line 2 lt rgb 'sea-green' lw 8  \n"; 
  printf CMDFILE "set style line 3 lt rgb 'blue' lw 8  \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 grid \n";
  printf CMDFILE "set key top right \n";
  printf CMDFILE "set logscale x \n";
  printf CMDFILE "set logscale y \n";
  printf CMDFILE "set ylabel 'Luminosity (solar) ' \n";
  printf CMDFILE "set xlabel 'Temperature (K) ' \n";

  printf CMDFILE "set xtics (15000, 10000, 6000, 4000) \n";


  printf CMDFILE "set title 'Nearby Stars in Gaia DR3'  \n";
  
  $cmd = "plot [12000:2500][1.0e-3:1.0e2] 'parse_gaia.out'  ";
  $cmd .= "   using 1:5 ls 1 ps 0.1 t '' ";
  $cmd .= " , ";
  $cmd .= "    './make_power_lines.out' index 0 ";
  $cmd .= "   using 1:2 ls 2 with lines  t 'L {/Symbol \\265} T^4' ";
  $cmd .= " , ";
  $cmd .= "    './make_power_lines.out' index 1 ";
  $cmd .= "   using 1:2 ls 3 with lines  t 'L {/Symbol \\265} T^7' ";

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





exit 0;
