#!/usr/bin/perl
#

  my($output_file, $term_options);

  ########################################################################3
  #  Plot radius as a function of mass for a set of models
  #     using data generated by STATSTAR
  #     from http://www.phys.unm.edu/~gbtaylor/astr421/statstar.f
  #     thanks to Greg Taylor
  #

  $output_file = "./mass_radius.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 'Radius (solar units) ' \n";
  printf CMDFILE "set xlabel 'Mass (solar units)' \n";
  printf CMDFILE "set title 'Stellar models computed via STATSTAR ' \n";
  
  $cmd = "plot [0:12][0.5:3.8] 'statstar_models.dat' using (\$1*1.0):(\$2*1.0)   ";
  $cmd .= "   with points ls 1 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 radius as a function of mass for a set of models
  #     using data generated by STATSTAR
  #     this time on a log-log plot
  #

  $output_file = "./mass_radius_log.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 'Radius (solar units) ' \n";
  printf CMDFILE "set xlabel 'Mass (solar units)' \n";
  printf CMDFILE "set title 'Stellar models computed via STATSTAR ' \n";
  
  $cmd = "plot [][] 'statstar_models.dat' using (log(\$1)):(log(\$2))   ";
  $cmd .= "   with points ls 1 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`;
  }




exit 0;
