#!/usr/bin/perl
#

  my($output_file, $term_options);


# Create a graph showing spectra of the three stars, small region 
#   in red portion of optical 
  
  $output_file = "solar_like_a.ps";
  $term_options = "postscript color enhanced 'Helvetica,18' size 12,8 ";

  $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 2  \n"; 
  printf CMDFILE "set style line 2 lt rgb 'sea-green' lw 2  \n"; 
  printf CMDFILE "set style line 3 lt rgb 'blue' lw 2  \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 at 6039,6300 \n";
  printf CMDFILE "set ylabel 'Flux (arbitrary scale)' \n";
  printf CMDFILE "set xlabel 'Wavelength (Angstroms)' \n";
  printf CMDFILE "set title 'Spectrum of Sun and two solar twins ' \n";
  
  $cmd = "plot [6025:6065][6000:8000]  ";
  $cmd = $cmd . "  'solar_spec.dat' using 1:(\$2*0.80) ";
  $cmd = $cmd . "    with lines ls 1 ";
  $cmd = $cmd . "    t 'Sun' ";
  $cmd = $cmd . " , ";
  $cmd = $cmd . "  'hd183658_all.dat' using (\$1*(1-0.00046)):(\$2*2.05e15) ";
  $cmd = $cmd . "    with lines ls 2 ";
  $cmd = $cmd . "    t 'HD 183658' ";
  $cmd = $cmd . " , ";
  $cmd = $cmd . "  'hd78660_all.dat' using (\$1*(1-0.00003)):(\$2*0.90) ";
  $cmd = $cmd . "    with lines ls 3 ";
  $cmd = $cmd . "    t 'HD 78660' ";

  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;
