#!/usr/bin/perl
#

  my($output_file, $term_options);

  ########################################################################3
  #  Plot density as a function of radius
  #     in a sun-like star
  #     using data generated by Python port of STATSTAR
  #     from https://github.com/rasmi/ASTRC3101/tree/master/HW3
  #     thanks to Marcel Agüeros
  #

  $output_file = "./density_plot_a.ps";
  $term_options = "postscript color enhanced '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 'Density (kg/m^3) ' \n";
  printf CMDFILE "set xlabel 'Radius (m)' \n";
  printf CMDFILE "set title 'A sun-like star computed via STATSTAR ' \n";
  
  $cmd = "plot [][] 'statstar_1.dat' using (\$1*0.01):(\$6*1.0E3)   ";
  $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 -rotate 90 $psfile $giffile";
    printf "cmd is ..$cmd.. \n";
    $ret = `$cmd`;
  }

  ########################################################################3
  #  Plot pressure as a function of radius
  #     in a sun-like star
  #     using data generated by Python port of STATSTAR
  #     from https://github.com/rasmi/ASTRC3101/tree/master/HW3
  #     thanks to Marcel Agüeros
  #

  $output_file = "./pressure_plot_a.ps";
  $term_options = "postscript color enhanced '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 'Pressure (N/m^2) ' \n";
  printf CMDFILE "set xlabel 'Radius (m)' \n";
  printf CMDFILE "set title 'A sun-like star computed via STATSTAR ' \n";
  
  $cmd = "plot [][] 'statstar_1.dat' using (\$1*0.01):(\$5*0.1)   ";
  $cmd .= "   with lines ls 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 -rotate 90 $psfile $giffile";
    printf "cmd is ..$cmd.. \n";
    $ret = `$cmd`;
  }


  ########################################################################3
  #  Plot temperature as a function of radius
  #     in a sun-like star
  #     using data generated by Python port of STATSTAR
  #     from https://github.com/rasmi/ASTRC3101/tree/master/HW3
  #     thanks to Marcel Agüeros
  #

  $output_file = "./temp_plot_a.ps";
  $term_options = "postscript color enhanced '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 'Temperature (K) ' \n";
  printf CMDFILE "set xlabel 'Radius (m)' \n";
  printf CMDFILE "set title 'A sun-like star computed via STATSTAR ' \n";
  
  $cmd = "plot [][] 'statstar_1.dat' using (\$1*0.01):(\$4)   ";
  $cmd .= "   with lines ls 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`;
  }



  ########################################################################3
  #  Plot temperature as a function of radius
  #     in a sun-like star
  #     using data generated by Python port of STATSTAR
  #     from https://github.com/rasmi/ASTRC3101/tree/master/HW3
  #     thanks to Marcel Agüeros
  #  Closeup on innermost region
  #

  $output_file = "./temp_plot_b.ps";
  $term_options = "postscript color enhanced '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 'Temperature (K) ' \n";
  printf CMDFILE "set xlabel 'Radius (m)' \n";
  printf CMDFILE "set title 'A sun-like star computed via STATSTAR ' \n";
  
  $cmd = "plot [0:1.0E8][] 'statstar_1.dat' using (\$1*0.01):(\$4)   ";
  $cmd .= "   with linespoints ls 3 ps 1.5 pt 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`;
  }



  ########################################################################3
  #  Plot pressure as a function of temperature
  #     in a sun-like star
  #     using data generated by Python port of STATSTAR
  #     from https://github.com/rasmi/ASTRC3101/tree/master/HW3
  #     thanks to Marcel Agüeros
  #

  $output_file = "./press_temp_a.ps";
  $term_options = "postscript color enhanced '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 'Pressure (N/m^2) ' \n";
  printf CMDFILE "set xlabel 'Temperature (K)' \n";
  printf CMDFILE "set title 'A sun-like star computed via STATSTAR ' \n";
  
  $cmd = "plot [][] 'statstar_1.dat' using (\$4):(\$5*0.1)   ";
  $cmd .= "   with linespoints ls 2 ps 1.5 pt 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`;
  }



  ########################################################################3
  #  Plot pressure as a function of temperature
  #     in a sun-like star
  #     using data generated by Python port of STATSTAR
  #     from https://github.com/rasmi/ASTRC3101/tree/master/HW3
  #     thanks to Marcel Agüeros
  #
  #  On a log scale
  #

  $output_file = "./press_temp_b.ps";
  $term_options = "postscript color enhanced '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 bot right \n";
  printf CMDFILE "set ylabel 'Log_{10} [ Pressure (N/m^2) ] ' \n";
  printf CMDFILE "set xlabel 'Log_{10} [ Temperature (K) ]' \n";
  printf CMDFILE "set title 'A sun-like star computed via STATSTAR ' \n";
  
  $cmd = "plot [][] 'statstar_1.dat' using (log10(\$4)):(log10(\$5*0.1))   ";
  $cmd .= "   with linespoints ls 2 ps 0.5 pt 3 t '' ";
  $cmd .= " , ";
  $cmd .= "   -10.0 + 2.5*x ls 7 t 'slope 2.5' ";

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


  ########################################################################3
  #  Plot pressure as a function of temperature
  #     in a sun-like star
  #     using data generated by Python port of STATSTAR
  #     from https://github.com/rasmi/ASTRC3101/tree/master/HW3
  #     thanks to Marcel Agüeros
  #
  #  On a log scale,
  #     closeup of central region
  #

  $output_file = "./press_temp_c.ps";
  $term_options = "postscript color enhanced '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 bot right \n";
  printf CMDFILE "set ylabel 'Log_{10} [ Pressure (N/m^2) ] ' \n";
  printf CMDFILE "set xlabel 'Log_{10} [ Temperature (K) ]' \n";
  printf CMDFILE "set title 'A sun-like star computed via STATSTAR ' \n";
  
  $cmd = "plot [6.8:7.20][] 'statstar_1.dat' using (log10(\$4)):(log10(\$5*0.1))   ";
  $cmd .= "   with linespoints ls 2 ps 0.5 pt 3 t '' ";
  $cmd .= " , ";
  $cmd .= "   -1.5 + 2.5*x ls 7 t 'slope 2.5' ";

  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;
