#!/usr/bin/perl
#

  my($output_file, $term_options);

  # plot showing absolute B-band mag of combined light
  #    as function of mass of each component
  $output_file = "./combined_absmag_B.ps";
  $term_options = "postscript color enhanced 'Helvetica,18' size 15,11 ";

  $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 grid \n";
  printf CMDFILE "set key top right \n";
  printf CMDFILE "set ylabel 'Mass of star B (solar mass)' \n";
  printf CMDFILE "set xlabel 'Mass of star A (solar mass)' \n";


  printf CMDFILE "set title 'Combined B-band absmag, based on 1-Gyr main sequence models '\n";
  printf CMDFILE "set view map \n";
  printf CMDFILE "set pm3d at b map \n";
  printf CMDFILE "set palette rgb 33,13,10 \n";

  printf CMDFILE "set contour base \n";
  printf CMDFILE "set cntrparam level incremental 0, 1.0, 18 \n";
  printf CMDFILE "unset surface \n";
  printf CMDFILE "set table 'cont.dat' \n";

  printf CMDFILE "set output 'foobar' \n";
  printf CMDFILE "splot 'make_absmag_map.dat' using 2:7:11  t '' \n";
  printf CMDFILE "unset table \n";
  printf CMDFILE "set output '$output_file' \n";
  
  $cmd = "splot 'make_absmag_map.dat' using 2:7:11  t '' ";
#  $cmd .= " , ";
#  $cmd .= " 'cont.dat' 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`;
  }



  # plot showing absolute V-band mag of combined light
  #    as function of mass of each component
  $output_file = "./combined_absmag_V.ps";
  $term_options = "postscript color enhanced 'Helvetica,18' size 15,11 ";

  $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 grid \n";
  printf CMDFILE "set key top right \n";
  printf CMDFILE "set ylabel 'Mass of star B (solar mass)' \n";
  printf CMDFILE "set xlabel 'Mass of star A (solar mass)' \n";


  printf CMDFILE "set title 'Combined V-band absmag, based on 1-Gyr main sequence models '\n";
  printf CMDFILE "set view map \n";
  printf CMDFILE "set pm3d at b map \n";
  printf CMDFILE "set palette rgb 33,13,10 \n";

  printf CMDFILE "set contour base \n";
  printf CMDFILE "set cntrparam level incremental 0, 1.0, 18 \n";
  printf CMDFILE "unset surface \n";
  printf CMDFILE "set table 'cont.dat' \n";

  printf CMDFILE "set output 'foobar' \n";
  printf CMDFILE "splot 'make_absmag_map.dat' using 2:7:12  t '' \n";
  printf CMDFILE "unset table \n";
  printf CMDFILE "set output '$output_file' \n";
  
  $cmd = "splot 'make_absmag_map.dat' using 2:7:12  t '' ";
#  $cmd .= " , ";
#  $cmd .= " 'cont.dat' 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`;
  }



  # plot showing B-V color of combined light
  #    as function of mass of each component
  $output_file = "./combined_BminusV.ps";
  $term_options = "postscript color enhanced 'Helvetica,18' size 15,11 ";

  $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 grid \n";
  printf CMDFILE "set key top right \n";
  printf CMDFILE "set ylabel 'Mass of star B (solar mass)' \n";
  printf CMDFILE "set xlabel 'Mass of star A (solar mass)' \n";


  printf CMDFILE "set title 'Combined (B-V), based on 1-Gyr main sequence models '\n";
  printf CMDFILE "set view map \n";
  printf CMDFILE "set pm3d at b map \n";
  printf CMDFILE "set palette rgb 33,13,10 \n";

  printf CMDFILE "set contour base \n";
  printf CMDFILE "set cntrparam level incremental 0.0, 0.1, 1.7 \n";
  printf CMDFILE "unset surface \n";
  printf CMDFILE "set table 'cont.dat' \n";

  printf CMDFILE "set output 'foobar' \n";
  printf CMDFILE "splot 'make_absmag_map.dat' using 2:7:13  t '' \n";
  printf CMDFILE "unset table \n";
  printf CMDFILE "set output '$output_file' \n";
  
  $cmd = "splot 'make_absmag_map.dat' using 2:7:13  t '' ";
#  $cmd .= " , ";
#  $cmd .= " 'cont.dat' 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`;
  }




