#!/usr/bin/perl
#

  
  my($output_file, $term_options);

  # HR diagram using isochrones from Dartmouth
  # http://stellar.dartmouth.edu/models/webtools.html
  $output_file = "dartmouth_example_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";
  printf CMDFILE "set grid \n";
  printf CMDFILE "unset key \n";
  printf CMDFILE "set ylabel 'absolute V magnitude'  \n";
  printf CMDFILE "set xlabel '(V-I) color ' \n";
  printf CMDFILE "set title 'Dartmouth isochrone for 1 Gyr, [Fe/H] = -1.5 ' \n ";
  
  $cmd = "plot [-0.2:2.0][15:-3]  ";
  $cmd .= "   './iso_age_1gyr.dat' using (\$8-\$10):(\$8) ";
  $cmd .= "       with points pt 3 ps 1.0 lc rgbcolor \"red\" ";


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


  # HR diagram using isochrones from Dartmouth
  # http://stellar.dartmouth.edu/models/webtools.html
  #  
  # Show differences in AGE, at a fixed metallicity
  $output_file = "dartmouth_age_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";
  printf CMDFILE "set grid \n";
  printf CMDFILE "set key bot left \n";
  printf CMDFILE "set ylabel 'absolute V magnitude'  \n";
  printf CMDFILE "set xlabel '(V-I) color ' \n";
  printf CMDFILE "set title 'Dartmouth isochrones for [Fe/H] = -1.5 ' \n ";
  
  $cmd = "plot [0.3:2.0][15:-3]  ";
  $cmd .= "   './iso_age_8gyr_fe-15.dat' using (\$8-\$10):(\$8) ";
  $cmd .= "       with lines lt 1 lc rgbcolor \"red\" lw 2 t '8 Gyr' ";
  $cmd .= " , ";
  $cmd .= "   './iso_age_9gyr_fe-15.dat' using (\$8-\$10):(\$8) ";
  $cmd .= "       with lines lt 1 lc rgbcolor \"green\"  lw 3 t '9 Gyr'";
  $cmd .= " , ";
  $cmd .= "   './iso_age_10gyr_fe-15.dat' using (\$8-\$10):(\$8) ";
  $cmd .= "       with lines lt 1 lc rgbcolor \"blue\" lw 2 t '10 Gyr'";
  $cmd .= " , ";
  $cmd .= "   './iso_age_11gyr_fe-15.dat' using (\$8-\$10):(\$8) ";
  $cmd .= "       with lines lt 1 lc rgbcolor \"cyan\"  lw 3 t '11 Gyr'";
  $cmd .= " , ";
  $cmd .= "   './iso_age_12gyr_fe-15.dat' using (\$8-\$10):(\$8) ";
  $cmd .= "       with lines lt 1  lc rgbcolor \"brown\" lw 2  t '12 Gyr'";
  $cmd .= " , ";
  $cmd .= "   './iso_age_13gyr_fe-15.dat' using (\$8-\$10):(\$8) ";
  $cmd .= "       with lines lt 1 lc rgbcolor \"black\"  t '13 Gyr'";


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


  # HR diagram using isochrones from Dartmouth
  # http://stellar.dartmouth.edu/models/webtools.html
  #  
  # Show differences in AGE, at a fixed metallicity
  #   zoom into MSTO
  $output_file = "dartmouth_age_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";
  printf CMDFILE "set grid \n";
  printf CMDFILE "set key bot left \n";
  printf CMDFILE "set ylabel 'absolute V magnitude'  \n";
  printf CMDFILE "set xlabel '(V-I) color ' \n";
  printf CMDFILE "set title 'Dartmouth isochrones for [Fe/H] = -1.5 and different ages ' \n ";
  
  $cmd = "plot [0.4:0.9][6:1]  ";
  $cmd .= "   './iso_age_8gyr_fe-15.dat' using (\$8-\$10):(\$8) ";
  $cmd .= "       with lines lt 1 lc rgbcolor \"red\" lw 3 t '8 Gyr' ";
  $cmd .= " , ";
  $cmd .= "   './iso_age_9gyr_fe-15.dat' using (\$8-\$10):(\$8) ";
  $cmd .= "       with linespoints lt 1 pt 3 ps 0.8 lc rgbcolor \"green\"  lw 4 t '9 Gyr'";
  $cmd .= " , ";
  $cmd .= "   './iso_age_10gyr_fe-15.dat' using (\$8-\$10):(\$8) ";
  $cmd .= "       with lines lt 1 lc rgbcolor \"blue\" lw 3 t '10 Gyr'";
  $cmd .= " , ";
  $cmd .= "   './iso_age_11gyr_fe-15.dat' using (\$8-\$10):(\$8) ";
  $cmd .= "       with linespoints lt 1 pt 6 ps 0.8 lc rgbcolor \"cyan\"  lw 4 t '11 Gyr'";
  $cmd .= " , ";
  $cmd .= "   './iso_age_12gyr_fe-15.dat' using (\$8-\$10):(\$8) ";
  $cmd .= "       with lines lt 1  lc rgbcolor \"brown\" lw 3  t '12 Gyr'";
  $cmd .= " , ";
  $cmd .= "   './iso_age_13gyr_fe-15.dat' using (\$8-\$10):(\$8) ";
  $cmd .= "       with linespoints lt 1 pt 4 ps 0.4 lc rgbcolor \"black\" lw 3 t '13 Gyr'";


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



  # HR diagram using isochrones from Dartmouth
  # http://stellar.dartmouth.edu/models/webtools.html
  #  
  # Show differences in METALLICITY, at a fixed age
  $output_file = "dartmouth_metal_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";
  printf CMDFILE "set grid \n";
  printf CMDFILE "set key bot left \n";
  printf CMDFILE "set ylabel 'absolute V magnitude'  \n";
  printf CMDFILE "set xlabel '(V-I) color ' \n";
  printf CMDFILE "set title 'Dartmouth isochrones for 10 Gyr and different metallicity ' \n ";
  
  $cmd = "plot [0.3:2.0][15:-3]  ";
  $cmd .= "   './iso_age_10gyr_fe-20.dat' using (\$8-\$10):(\$8) ";
  $cmd .= "       with lines lt 1 lc rgbcolor \"red\" lw 2 t '[Fe/H] -2.0' ";
  $cmd .= " , ";
  $cmd .= "   './iso_age_10gyr_fe-15.dat' using (\$8-\$10):(\$8) ";
  $cmd .= "       with lines lt 1 lc rgbcolor \"green\"  lw 3 t '[Fe/H] -1.5'";
  $cmd .= " , ";
  $cmd .= "   './iso_age_10gyr_fe-10.dat' using (\$8-\$10):(\$8) ";
  $cmd .= "       with lines lt 1 lc rgbcolor \"blue\" lw 2 t '[Fe/H] -1.0'";
  $cmd .= " , ";
  $cmd .= "   './iso_age_10gyr_fe-05.dat' using (\$8-\$10):(\$8) ";
  $cmd .= "       with lines lt 1 lc rgbcolor \"cyan\"  lw 3 t '[Fe/H] -0.5'";
  $cmd .= " , ";
  $cmd .= "   './iso_age_10gyr_fe+00.dat' using (\$8-\$10):(\$8) ";
  $cmd .= "       with lines lt 1  lc rgbcolor \"brown\" lw 2  t '[Fe/H] \ 0.0' ";
  $cmd .= " , ";
  $cmd .= "   './iso_age_10gyr_fe+05.dat' using (\$8-\$10):(\$8) ";
  $cmd .= "       with lines lt 1 lc rgbcolor \"black\"  t '[Fe/H] +0.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 -flatten -background white -rotate 90 $psfile $giffile";
    printf "cmd is ..$cmd.. \n";
    $ret = `$cmd`;
  }



  # HR diagram using isochrones from Dartmouth
  # http://stellar.dartmouth.edu/models/webtools.html
  #  
  # Show differences in METALLICITY, at a fixed age
  #    zoom in on MSTO
  $output_file = "dartmouth_metal_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";
  printf CMDFILE "set grid \n";
#  printf CMDFILE "set key at 0.535,4.59  \n";
  printf CMDFILE "set key top left  \n";
  printf CMDFILE "set ylabel 'absolute V magnitude'  \n";
  printf CMDFILE "set xlabel '(V-I) color ' \n";
  printf CMDFILE "set title 'Dartmouth isochrones for 10 Gyr and different metallicity ' \n ";
  
  $cmd = "plot [0.4:1.1][6:1]  ";
  $cmd .= "   './iso_age_10gyr_fe-20.dat' using (\$8-\$10):(\$8) ";
  $cmd .= "       with lines lt 1 lc rgbcolor \"red\" lw 3 t '[Fe/H] -2.0' ";
  $cmd .= " , ";
  $cmd .= "   './iso_age_10gyr_fe-15.dat' using (\$8-\$10):(\$8) ";
  $cmd .= "       with linespoints pt 3 ps 0.8 lt 1 lc rgbcolor \"green\"  lw 3 t '[Fe/H] -1.5'";
  $cmd .= " , ";
  $cmd .= "   './iso_age_10gyr_fe-10.dat' using (\$8-\$10):(\$8) ";
  $cmd .= "       with lines lt 1 lc rgbcolor \"blue\" lw 3 t '[Fe/H] -1.0'";
  $cmd .= " , ";
  $cmd .= "   './iso_age_10gyr_fe-05.dat' using (\$8-\$10):(\$8) ";
  $cmd .= "       with linespoints pt 6 ps 0.8 lt 1 lc rgbcolor \"cyan\"  lw 3 t '[Fe/H] -0.5'";
  $cmd .= " , ";
  $cmd .= "   './iso_age_10gyr_fe+00.dat' using (\$8-\$10):(\$8) ";
  $cmd .= "       with lines lt 1  lc rgbcolor \"brown\" lw 3  t '[Fe/H] \ 0.0' ";
  $cmd .= " , ";
  $cmd .= "   './iso_age_10gyr_fe+05.dat' using (\$8-\$10):(\$8) ";
  $cmd .= "       with linespoints pt 4 ps 0.5 lt 1 lc rgbcolor \"black\" lw 2 t '[Fe/H] +0.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 -flatten -background white -rotate 90 $psfile $giffile";
    printf "cmd is ..$cmd.. \n";
    $ret = `$cmd`;
  }






exit 0;
