#!/usr/bin/perl
#

  my($output_file, $term_options);

  ########################################################################
  # plot of log(luminosity) vs. log(period) for Cepheids in LMC
  #     I-band only
  $output_file = "./lmc_ceph_pl_i.ps";
  $term_options = "postscript enhanced color '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";

  #  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 'Log_{10} [I-band luminosity (solar units) ]' \n";
  printf CMDFILE "set xlabel 'Log_{10} [Period (days) ]' \n";
  printf CMDFILE "set title 'Cepheids in the LMC, I-band '\n";
  
  $cmd =  "plot [0.2:1.5][2.4:4.0] './lmc_ceph_corr_fund.dat' using ";
  $cmd .= "     (log10(\$5)):(log10(\$13)) ";
#  $cmd .= "     5:13 ";
  $cmd .= "     with points ls 1 ps 0.8 pt 6 ";
  $cmd .= "    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 of log(luminosity) vs. log(period) for Cepheids in LMC
  #     I-band only
  #     this includes a line for visual comparison

  $output_file = "./lmc_ceph_pl_i_line.ps";
  $term_options = "postscript enhanced color '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";

  #  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 'black' lw 3  \n"; 

  printf CMDFILE "set grid \n";
  printf CMDFILE "set key top left \n";
  printf CMDFILE "set ylabel 'Log_{10} [I-band luminosity (solar units) ]' \n";
  printf CMDFILE "set xlabel 'Log_{10} [Period (days) ]' \n";
  printf CMDFILE "set title 'Cepheids in the LMC, I-band '\n";
  
  $cmd =  "plot [0.2:1.5][2.4:4.0] './lmc_ceph_corr_fund.dat' using ";
  $cmd .= "     (log10(\$5)):(log10(\$13)) ";
#  $cmd .= "     5:13 ";
  $cmd .= "     with points ls 1 ps 0.8 pt 6 ";
  $cmd .= "    t '' ";
  $cmd .= " , ";
  $cmd .= "  2.25+1.2*x ls 6 t 'slope = 1.2' ";


  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;
