#!/usr/bin/perl
#

  
  my($output_file, $term_options);

  # Spectra of several stars in the near-UV
  $output_file = "spec_near_uv.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 "set key top right \n";
  printf CMDFILE "set ylabel 'Flux per unit wavelength (arb scale)' \n";
  printf CMDFILE "set xlabel 'Wavelength (Angstroms) ' \n";
  printf CMDFILE "set title 'Stellar spectra in near-UV '\n";
  
  $cmd = "plot [2500:3500][] './ukb3v_dat' using (\$1):(-5+\$2*2)  ";
  $cmd .= "     with lines lt 1 lc 3 lw 3 t 'B3V' ";
  $cmd .= " , ";
  $cmd .= "                  './ukg5v_dat' using (\$1):(\$2*12)  ";
  $cmd .= "     with lines lt 1 lc 2 lw 3 t 'G5V' ";


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


  # Spectra of several stars in the blue optical
  $output_file = "spec_blue_opt.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 "set key top left \n";
  printf CMDFILE "set ylabel 'Flux per unit wavelength (arb scale)' \n";
  printf CMDFILE "set xlabel 'Wavelength (Angstroms) ' \n";
  printf CMDFILE "set title 'Stellar spectra in blue optical '\n";
  
  $cmd = "plot [4000:5000][] './ukb3v_dat' using (\$1):(0+\$2*3)  ";
  $cmd .= "     with lines lt 1 lc 3 lw 3 t 'B3V' ";
  $cmd .= " , ";
  $cmd .= "                  './ukg5v_dat' using (\$1):(\$2*10)  ";
  $cmd .= "     with lines lt 1 lc 2 lw 3 t 'G5V' ";

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



  # Spectra of several stars in the red optical
  $output_file = "spec_red_opt.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 "set key top right \n";
  printf CMDFILE "set ylabel 'Flux per unit wavelength (arb scale)' \n";
  printf CMDFILE "set xlabel 'Wavelength (Angstroms) ' \n";
  printf CMDFILE "set title 'Stellar spectra in red optical '\n";
  
  $cmd = "plot [6000:7200][] './ukb3v_dat' using (\$1):(0+\$2*4)  ";
  $cmd .= "     with lines lt 1 lc 3 lw 3 t 'B3V' ";
  $cmd .= " , ";
  $cmd .= "                  './ukg5v_dat' using (\$1):(\$2*3)  ";
  $cmd .= "     with lines lt 1 lc 2 lw 3 t 'G5V' ";

  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;
