#!/usr/bin/perl
#

  
  my($output_file, $term_options);

#####################################################################3
#   Histogram of M82 image sky values
  $output_file = "m82_his.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 1563.84,0.60 \n";
  printf CMDFILE "set ylabel 'Pixel value' \n";
  printf CMDFILE "set xlabel 'Number of pixels' \n";
  printf CMDFILE "set title 'Histogram derived from image of M82 '\n";
  
  $cmd = "plot [0:1000][] 'm82.his' using (\$1):(\$2)   lt 1 pt 3 lw 4 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`;
  }



#####################################################################3
#   Histogram of M82 image sky values, with wider x-range
  $output_file = "m82_his_wide.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 1563.84,0.60 \n";
  printf CMDFILE "set ylabel 'Pixel value' \n";
  printf CMDFILE "set xlabel 'Number of pixels' \n";
  printf CMDFILE "set title 'Histogram derived from image of M82 '\n";
  
  $cmd = "plot [0:10000][] 'm82.his' using (\$1):(\$2)   lt 1 pt 3 lw 4 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`;
  }



#####################################################################3
#   Histogram of M82 image sky values, with narrow x-range
  $output_file = "m82_his_narrow.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 1563.84,0.60 \n";
  printf CMDFILE "set ylabel 'Pixel value' \n";
  printf CMDFILE "set xlabel 'Number of pixels' \n";
  printf CMDFILE "set title 'Histogram derived from image of M82 '\n";
  
  $cmd = "plot [100:300][] 'm82.his' using (\$1):(\$2)   lt 1 pt 3 lw 4 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;
