#!/usr/bin/perl
#

  
  my($output_file, $term_options);

  # HR diagram of M15, based on 
  #   Feuillet et al., PASP 126, 733 (2014)
  $output_file = "m15_hr.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 'apparent V magnitude (corr for ext)'  \n";
  printf CMDFILE "set xlabel '(V-I) color (corr for ext)' \n";
  printf CMDFILE "set title 'M15 photometry from Feuillet et al., PASP 126, 733 (2014)'\n";
  
  $cmd = "plot [-0.5:2.0][23:12]  ";
#  $cmd = "plot [][]  ";
  $cmd .= "   './m15_feuillet.dat' using (-0.24+(\$10-\$12)):(-0.59+\$10) ";
  $cmd .= "       with points pt 3 ps 0.1 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 of NGC 6293, based on 
  #   Lee and Carney, AJ 132, 2171 (2006)
  $output_file = "ngc6293_hr.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 'apparent V magnitude (corr for ext)'  \n";
  printf CMDFILE "set xlabel '(V-I) color (corr for ext)' \n";
  printf CMDFILE "set title 'NGC 6293 photometry from Lee and Carney (2006)'\n";
  
  $cmd = "plot [-0.5:2.0][23:12]  ";
#  $cmd = "plot [][]  ";
#  $cmd .= "   './m15_feuillet.dat' using (-0.24+(\$10-\$12)):(-0.59+\$10) ";
#  $cmd .= "       with points pt 3 ps 0.1 lc rgbcolor \"red\" ";
  $cmd .= "   './ngc6293_lee.dat' using (-0.54+(\$11-\$12)):(-1.32+\$11) ";
  $cmd .= "       with points pt 3 ps 0.1 lc rgbcolor \"blue\" ";


  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 of NGC 6293, based on 
  #   Lee and Carney, AJ 132, 2171 (2006)
  #   no correction for extinction
  $output_file = "ngc6293_hr_nocor.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 'apparent V magnitude '  \n";
  printf CMDFILE "set xlabel '(V-I) color' \n";
  printf CMDFILE "set title 'NGC 6293 photometry from Lee and Carney (2006)'\n";
  
  $cmd = "plot [-0.5:2.0][23:12]  ";
#  $cmd = "plot [][]  ";
#  $cmd .= "   './m15_feuillet.dat' using (-0.24+(\$10-\$12)):(-0.59+\$10) ";
#  $cmd .= "       with points pt 3 ps 0.1 lc rgbcolor \"red\" ";
  $cmd .= "   './ngc6293_lee.dat' using (0.00+(\$11-\$12)):(0.0+\$11) ";
  $cmd .= "       with points pt 3 ps 0.1 lc rgbcolor \"blue\" ";


  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 of NGC 6541, based on 
  #   Lee and Carney, AJ 132, 2171 (2006)
  $output_file = "ngc6541_hr.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 'apparent V magnitude (corr for ext)'  \n";
  printf CMDFILE "set xlabel '(V-I) color (corr for ext)' \n";
  printf CMDFILE "set title 'NGC 6451 photometry from Lee and Carney (2006)'\n";
  
  $cmd = "plot [-0.5:2.0][23:12]  ";
#  $cmd = "plot [][]  ";
#  $cmd .= "   './m15_feuillet.dat' using (-0.24+(\$10-\$12)):(-0.59+\$10) ";
#  $cmd .= "       with points pt 3 ps 0.1 lc rgbcolor \"red\" ";
  $cmd .= "   './ngc6293_lee.dat' using (-0.19+(\$11-\$12)):(-0.46+\$11) ";
  $cmd .= "       with points pt 3 ps 0.1 lc rgbcolor \"black\" ";


  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 of M15 and NGC 6293, based on 
  #   Lee and Carney, AJ 132, 2171 (2006)
  $output_file = "m15_ngc6293_hr.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 'apparent V magnitude (corr for ext)'  \n";
  printf CMDFILE "set xlabel '(V-I) color (corr for ext)' \n";
  printf CMDFILE "set title 'M15 and NGC 6293 '\n";
  
  $cmd = "plot [-0.5:2.0][23:12]  ";
  $cmd .= "   './m15_feuillet.dat' using (-0.24+(\$10-\$12)):(-0.59+\$10) ";
  $cmd .= "       with points pt 3 ps 0.1 lc rgbcolor \"red\" ";
  $cmd .= " , ";
  $cmd .= "   './ngc6293_lee.dat' using (-0.54+(\$11-\$12)):(-1.32+\$11) ";
  $cmd .= "       with points pt 3 ps 0.1 lc rgbcolor \"blue\" ";


  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 of M15 and NGC 6293, based on 
  #   Lee and Carney, AJ 132, 2171 (2006)
  #   closeup around MSTO 
  $output_file = "m15_ngc6293_hr_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 'apparent V magnitude (corr for ext)'  \n";
  printf CMDFILE "set xlabel '(V-I) color (corr for ext)' \n";
  printf CMDFILE "set title 'M15 and NGC 6293 '\n";
  
  $cmd = "plot [0.2:0.8][19.5:17.0]  ";
  $cmd .= "   './m15_feuillet.dat' using (-0.24+(\$10-\$12)):(-0.59+\$10) ";
  $cmd .= "       with points pt 6 ps 0.2 lc rgbcolor \"red\" ";
#  $cmd .= " , ";
#  $cmd .= "   './ngc6293_lee.dat' using (-0.54+(\$11-\$12)):(-1.32+\$11) ";
#  $cmd .= "       with points pt 3 ps 0.4 lw 2 lc rgbcolor \"blue\" ";


  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 of M55, based on 
  #   Sariya, Yadav and Bellini, A&A 543, A87 (2012)
  $output_file = "m55_hr.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 'apparent V magnitude (corr for ext) '  \n";
  printf CMDFILE "set xlabel '(V-I) (corr for ext) color ' \n";
  printf CMDFILE "set title 'M55 photometry from Sariya, Yadav and Bellini (2012)'\n";
  
  $cmd = "plot [-0.5:2.0][23:12]  ";
#  $cmd = "plot [][]  ";
#  $cmd .= "   './m15_feuillet.dat' using (-0.24+(\$10-\$12)):(-0.59+\$10) ";
#  $cmd .= "       with points pt 3 ps 0.1 lc rgbcolor \"red\" ";
  $cmd .= "   './m55_sariya_vi.dat' using (-0.11+(\$1-\$3)):(-0.265+\$1) ";
  $cmd .= "       with points pt 3 ps 0.1 lc rgbcolor \"black\" ";


  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 of M55 and NGC 6293, based on 
  #   Sariya, Yadav and Bellini, A&A 543, A87 (2012)
  # and
  #   Lee and Carney, AJ 132, 2171 (2006)
  #   no correction for extinction
  $output_file = "m55_ngc6293_hr_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 'apparent V magnitude (corr for ext)'  \n";
#  printf CMDFILE "set xlabel '(V-I) color (corr for ext)' \n";
  printf CMDFILE "set ylabel 'apparent V magnitude '  \n";
  printf CMDFILE "set xlabel '(V-I) color'  \n";
  printf CMDFILE "set title 'M55 (black) and NGC 6293 (red) '\n";
  
  $cmd = "plot [-0.2:2.0][22.0:12.0]  ";
  $cmd .= "   './m55_sariya_vi.dat' using (0.00+(\$1-\$2)):(0.00+\$1) ";
  $cmd .= "       with points pt 6 ps 0.2 lc rgbcolor \"black\" ";
  $cmd .= " , ";
#  $cmd .= "   './ngc6293_lee.dat' using (-0.54+(\$11-\$12)):(-1.32+\$11) ";
  $cmd .= "   './ngc6293_lee.dat' using (0.00+(\$11-\$12)):(0.00+\$11) ";
  $cmd .= "       with points pt 3 ps 0.2 lw 2 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 of M55 and NGC 6293, based on 
  #   Sariya, Yadav and Bellini, A&A 543, A87 (2012)
  # and
  #   Lee and Carney, AJ 132, 2171 (2006)
  #   no correction for extinction
  #   closeup on MSTO 
  $output_file = "m55_ngc6293_hr_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 "unset key \n";
#  printf CMDFILE "set ylabel 'apparent V magnitude (corr for ext)'  \n";
#  printf CMDFILE "set xlabel '(V-I) color (corr for ext)' \n";
  printf CMDFILE "set ylabel 'apparent V magnitude '  \n";
  printf CMDFILE "set xlabel '(V-I) color'  \n";
  printf CMDFILE "set title 'M55 (black) and NGC 6293 (red) '\n";
  
  $cmd = "plot [0.5:1.5][21.0:17.0]  ";
  $cmd .= "   './m55_sariya_vi.dat' using (0.00+(\$1-\$2)):(0.00+\$1) ";
  $cmd .= "       with points pt 6 ps 0.2 lc rgbcolor \"black\" ";
  $cmd .= " , ";
#  $cmd .= "   './ngc6293_lee.dat' using (-0.54+(\$11-\$12)):(-1.32+\$11) ";
  $cmd .= "   './ngc6293_lee.dat' using (0.00+(\$11-\$12)):(0.00+\$11) ";
  $cmd .= "       with points pt 3 ps 0.2 lw 2 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 of M55 and NGC 6293, based on 
  #   Sariya, Yadav and Bellini, A&A 543, A87 (2012)
  # and
  #   Lee and Carney, AJ 132, 2171 (2006)
  #   INCLUDE correction for extinction
  $output_file = "m55_ngc6293_hr_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";
  printf CMDFILE "set grid \n";
  printf CMDFILE "unset key \n";
  printf CMDFILE "set ylabel 'apparent V magnitude (corr for ext)'  \n";
  printf CMDFILE "set xlabel '(V-I) color (corr for ext)' \n";
#  printf CMDFILE "set ylabel 'apparent V magnitude '  \n";
#  printf CMDFILE "set xlabel '(V-I) color'  \n";
  printf CMDFILE "set title 'M55 (black) and NGC 6293 (red) '\n";
  
  $cmd = "plot [-0.2:2.0][22.0:12.0]  ";
  $cmd .= "   './m55_sariya_vi.dat' using (-0.11+(\$1-\$2)):(-0.265+\$1) ";
  $cmd .= "       with points pt 6 ps 0.2 lc rgbcolor \"black\" ";
  $cmd .= " , ";
  $cmd .= "   './ngc6293_lee.dat' using (-0.55+(\$11-\$12)):(-1.326+\$11) ";
#  $cmd .= "   './ngc6293_lee.dat' using (0.00+(\$11-\$12)):(0.00+\$11) ";
  $cmd .= "       with points pt 3 ps 0.2 lw 2 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 of M55 and NGC 6293, based on 
  #   Sariya, Yadav and Bellini, A&A 543, A87 (2012)
  # and
  #   Lee and Carney, AJ 132, 2171 (2006)
  #   INCLUDE correction for extinction
  #   closeup around MSTO
  $output_file = "m55_ngc6293_hr_d.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 'apparent V magnitude (corr for ext)'  \n";
  printf CMDFILE "set xlabel '(V-I) color (corr for ext)' \n";
#  printf CMDFILE "set ylabel 'apparent V magnitude '  \n";
#  printf CMDFILE "set xlabel '(V-I) color'  \n";
  printf CMDFILE "set title 'M55 (black) and NGC 6293 (red) '\n";
  
  $cmd = "plot [0.2:1.0][20.0:16.5]  ";
  $cmd .= "   './m55_sariya_vi.dat' using (-0.11+(\$1-\$2)):(-0.265+\$1) ";
  $cmd .= "       with points pt 6 ps 0.2 lc rgbcolor \"black\" ";
  $cmd .= " , ";
  $cmd .= "   './ngc6293_lee.dat' using (-0.55+(\$11-\$12)):(-1.326+\$11) ";
#  $cmd .= "   './ngc6293_lee.dat' using (0.00+(\$11-\$12)):(0.00+\$11) ";
  $cmd .= "       with points pt 3 ps 0.2 lw 2 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`;
  }






exit 0;
