#!/usr/bin/perl
#

#######################################################
# Make a graph showing spectra of several stars

  # get the arguments
  $title = "Stellar spectra";
  $output_file = "./spec_cont_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";

  #  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 'Intensity (arbitrary scale)' \n";
  printf CMDFILE "set xlabel 'Wavelength (Angstroms) ' \n";


  printf CMDFILE "set title '$title' \n";
  
  $cmd = "plot [2000:14000] './ukb0v_dat'  ";
  $cmd = $cmd . " using (\$1):(0.6*\$2)  with lines lt 3  t 'B0V' ";
  $cmd = $cmd . " , ";
  $cmd = $cmd . "    './uka0v_dat'  ";
  $cmd = $cmd . " using (\$1):(5.0*\$2)  with lines lt 4  t 'A0V' ";
  $cmd = $cmd . " , ";
  $cmd = $cmd . "    './ukg5v_dat'  ";
  $cmd = $cmd . " using (\$1):(10.0*\$2)  with lines lt 2  t 'G5V' ";
  $cmd = $cmd . " , ";
  $cmd = $cmd . "    './ukk3v_dat'  ";
  $cmd = $cmd . " using (\$1):(8.0*\$2)  with lines lt 1  t 'K3V' ";
  $cmd = $cmd . " , ";
  $cmd = $cmd . "    './ukm2v_dat'  ";
  $cmd = $cmd . " using (\$1):(5.0*\$2)  with lines lt -1  t 'M2V' ";





  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`;
  }


#######################################################
# Make a graph showing low-res of a sun-like star

  # get the arguments
  $title = "Low-res spectrum of a sun-like star ";
  $output_file = "./spec_lowres_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";

  #  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 'Intensity (arbitrary scale)' \n";
  printf CMDFILE "set xlabel 'Wavelength (Angstroms) ' \n";

  printf CMDFILE "set obj 1 rect from 5000,0.35 to 5010,0.70 fs solid 0.15 lt 3  \n";
  


  printf CMDFILE "set title '$title' \n";
  
  $cmd = "plot [4000:6000] './ukg5v_dat'  ";
  $cmd = $cmd . " using (\$1):(0.6*\$2)  with lines lt 1 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`;
  }


#######################################################
# Make a graph showing high-res of the Sun

  # get the arguments
  $title = "High-res spectrum of the Sun ";
  $output_file = "./spec_highres_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";

  #  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 'Intensity (arbitrary scale)' \n";
  printf CMDFILE "set xlabel 'Wavelength (Angstroms) ' \n";

  printf CMDFILE "set title '$title' \n";
  
  $cmd = "plot [5000:5010] './bass_solar_5000.dat'  ";
  $cmd = $cmd . " using 1:2  with lines lt 1 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`;
  }





exit 0;
