#!/usr/bin/perl
#

  my($output_file, $term_options);

  # plot of overscan and data values for an image with "bands"
  $output_file = "band_both_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";
  printf CMDFILE "set grid \n";
  printf CMDFILE "set key top right \n";
  printf CMDFILE "set ylabel 'Row median value (ADU) ' \n";
  printf CMDFILE "set xlabel 'Row index' \n";
  printf CMDFILE "set title 'HDI wide bands, c8158t0030f '\n";

  
  $cmd = "plot [][26000:29000] 'c8158t0030_data_vec.dat' ";
  $cmd .= "            using 1:2 with lines  lw 1 t 'data' ";
  $cmd .= " , ";
  $cmd .= "          'c8158t0030_over_vec.dat' ";
  $cmd .= "            using 1:(\$2+24000) with lines lc 3 lw 2 t 'overscan + 24000' ";

  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 overscan and data values for an image with "stripes"
  $output_file = "stripe_both_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";
  printf CMDFILE "set grid \n";
  printf CMDFILE "set key top right \n";
  printf CMDFILE "set ylabel 'Row median value (ADU) ' \n";
  printf CMDFILE "set xlabel 'Row index' \n";
  printf CMDFILE "set title 'HDI narrow stripes, c8160t0077o '\n";

  
  $cmd = "plot [][] 'c8160t0077_data_vec.dat' ";
  $cmd .= "            using 1:2 with lines  lw 1 t 'data' ";
  $cmd .= " , ";
  $cmd .= "          'c8160t0077_over_vec.dat' ";
  $cmd .= "            using 1:(\$2-50) with lines lc 3 lw 2 t 'overscan - 50' ";

  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;

  # plot of overscan stdev value 
  $output_file = "overscan_stdev_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";
  printf CMDFILE "set grid \n";
  printf CMDFILE "set key top right \n";
  printf CMDFILE "set ylabel 'Overscan stdev value (ADU) ' \n";
  printf CMDFILE "set xlabel 'Image index number' \n";
  printf CMDFILE "set cblabel 'Image Quadrant (1, 2, 3, 4)' \n";
  printf CMDFILE "set title 'HDI test bias, Dec 12, 2017 '\n";

  printf CMDFILE "set palette model RGB defined (1 'red', 2 'green', 3 'blue', 4 'black') \n";
  
  $cmd = "plot [][] 'overscan_values.dat' ";
  $cmd .= "            using 8:4:9 with points pt 3 ps 0.8  palette 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;

