#!/usr/bin/perl
#

  
  ###############################################################
  #  Make a plot showing 1-D "SBF" at 1 Mpc
  #
  # get the arguments
  $output_file = "sbf_a_1.ps";
  $term_options = "postscript enhanced color '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 style fill solid 0.4 \n";
  printf CMDFILE "set key top right \n";
  printf CMDFILE "set label 1 at 60,1.1 'Distance = 1 Mpc' \n";
  printf CMDFILE "set xlabel 'Pixel number' \n";
  printf CMDFILE "set ylabel 'Intensity' \n";
  printf CMDFILE "set title 'A one-dimensional illustration of surface brightness fluctuations ' \n";
  
  $cmd = "plot [0:100][0:1.2] './sbf_10_1.out' using (\$1):(\$2) ";
  $cmd .= "  with boxes lc 1 lw 2  t ''  ";
  $cmd .= " , ";
  $cmd .= " 0.1 with lines lc -1 lt 1 t '' ";
#  $cmd .= "  with linespoints lc 3 pt 5 lw 2 t 'NGC5447'  ";

  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 plot showing 1-D "SBF" at 10 Mpc
  #
  # get the arguments
  $output_file = "sbf_a_2.ps";
  $term_options = "postscript enhanced color '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 style fill solid 0.4 \n";
  printf CMDFILE "set key top right \n";
  printf CMDFILE "set label 1 at 60,1.1 'Distance = 10 Mpc' \n";
  printf CMDFILE "set xlabel 'Pixel number' \n";
  printf CMDFILE "set ylabel 'Intensity' \n";
  printf CMDFILE "set title 'A one-dimensional illustration of surface brightness fluctuations ' \n";
  
  $cmd = "plot [0:100][0:1.2] './sbf_10_10.out' using (\$1):(\$2/10) ";
  $cmd .= "  with boxes lc 1 lw 2  t ''  ";
  $cmd .= " , ";
  $cmd .= " 0.1 with lines lc -1 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 plot showing 1-D "SBF" at 100 Mpc
  #
  # get the arguments
  $output_file = "sbf_a_3.ps";
  $term_options = "postscript enhanced color '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 style fill solid 0.4 \n";
  printf CMDFILE "set label 1 at 60,1.1 'Distance = 100 Mpc' \n";
  printf CMDFILE "set key top right \n";
  printf CMDFILE "set xlabel 'Pixel number' \n";
  printf CMDFILE "set ylabel 'Intensity' \n";
  printf CMDFILE "set title 'A one-dimensional illustration of surface brightness fluctuations ' \n";
  
  $cmd = "plot [0:100][0:1.2] './sbf_10_100.out' using (\$1):(\$2/100) ";
  $cmd .= "  with boxes lc 1 lw 2  t ''  ";
  $cmd .= " , ";
  $cmd .= " 0.1 with lines lc -1 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 plot showing 1-D "SBF" at 1000 Mpc
  #
  # get the arguments
  $output_file = "sbf_a_4.ps";
  $term_options = "postscript enhanced color '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 style fill solid 0.4 \n";
  printf CMDFILE "set key top right \n";
  printf CMDFILE "set label 1 at 60,1.1 'Distance = 1,000 Mpc' \n";
  printf CMDFILE "set xlabel 'Pixel number' \n";
  printf CMDFILE "set ylabel 'Intensity' \n";
  printf CMDFILE "set title 'A one-dimensional illustration of surface brightness fluctuations ' \n";
  
  $cmd = "plot [0:100][0:1.2] './sbf_10_1000.out' using (\$1):(\$2/1000) ";
  $cmd .= "  with boxes lc 1 lw 2  t ''  ";
  $cmd .= " , ";
  $cmd .= " 0.1 with lines lc -1 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 plot showing 1-D "SBF" at 10000 Mpc
  #
  # get the arguments
  $output_file = "sbf_a_5.ps";
  $term_options = "postscript enhanced color '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 style fill solid 0.4 \n";
  printf CMDFILE "set key top right \n";
  printf CMDFILE "set label 1 at 60,1.1 'Distance = 10,000 Mpc' \n";
  printf CMDFILE "set xlabel 'Pixel number' \n";
  printf CMDFILE "set ylabel 'Intensity' \n";
  printf CMDFILE "set title 'A one-dimensional illustration of surface brightness fluctuations ' \n";
  
  $cmd = "plot [0:100][0:1.2] './sbf_10_10000.out' using (\$1):(\$2/10000) ";
  $cmd .= "  with boxes lc 1 lw 2  t ''  ";
  $cmd .= " , ";
  $cmd .= " 0.1 with lines lc -1 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 plot showing 1-D "SBF" at 1 Mpc
  #
  # get the arguments
  $output_file = "sbf_a_1.ps";
  $term_options = "postscript enhanced color '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 style fill solid 0.4 \n";
  printf CMDFILE "set key top right \n";
  printf CMDFILE "set label 1 at 60,1.1 'Distance = 1 Mpc' \n";
  printf CMDFILE "set xlabel 'Pixel number' \n";
  printf CMDFILE "set ylabel 'Intensity' \n";
  printf CMDFILE "set title 'A one-dimensional illustration of surface brightness fluctuations ' \n";
  
  $cmd = "plot [0:100][0:1.2] './sbf_10_1.out' using (\$1):(\$2) ";
  $cmd .= "  with boxes lc 1 lw 2  t ''  ";
  $cmd .= " , ";
  $cmd .= " 0.1 with lines lc -1 lt 1 t '' ";
#  $cmd .= "  with linespoints lc 3 pt 5 lw 2 t 'NGC5447'  ";

  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/.gif/;
    $cmd = "convert -rotate 90 $psfile $giffile";
    printf "cmd is ..$cmd.. \n";
    $ret = `$cmd`;
  }


  ###############################################################
  #  Make a plot showing 1-D "SBF" at 10 Mpc
  #
  # get the arguments
  $output_file = "sbf_a_2.ps";
  $term_options = "postscript enhanced color '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 style fill solid 0.4 \n";
  printf CMDFILE "set key top right \n";
  printf CMDFILE "set label 1 at 60,1.1 'Distance = 10 Mpc' \n";
  printf CMDFILE "set xlabel 'Pixel number' \n";
  printf CMDFILE "set ylabel 'Intensity' \n";
  printf CMDFILE "set title 'A one-dimensional illustration of surface brightness fluctuations ' \n";
  
  $cmd = "plot [0:100][0:1.2] './sbf_10_10.out' using (\$1):(\$2/10) ";
  $cmd .= "  with boxes lc 1 lw 2  t ''  ";
  $cmd .= " , ";
  $cmd .= " 0.1 with lines lc -1 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/.gif/;
    $cmd = "convert -rotate 90 $psfile $giffile";
    printf "cmd is ..$cmd.. \n";
    $ret = `$cmd`;
  }


  ###############################################################
  #  Make a plot showing 1-D "SBF" at 100 Mpc
  #
  # get the arguments
  $output_file = "sbf_a_3.ps";
  $term_options = "postscript enhanced color '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 style fill solid 0.4 \n";
  printf CMDFILE "set label 1 at 60,1.1 'Distance = 100 Mpc' \n";
  printf CMDFILE "set key top right \n";
  printf CMDFILE "set xlabel 'Pixel number' \n";
  printf CMDFILE "set ylabel 'Intensity' \n";
  printf CMDFILE "set title 'A one-dimensional illustration of surface brightness fluctuations ' \n";
  
  $cmd = "plot [0:100][0:1.2] './sbf_10_100.out' using (\$1):(\$2/100) ";
  $cmd .= "  with boxes lc 1 lw 2  t ''  ";
  $cmd .= " , ";
  $cmd .= " 0.1 with lines lc -1 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/.gif/;
    $cmd = "convert -rotate 90 $psfile $giffile";
    printf "cmd is ..$cmd.. \n";
    $ret = `$cmd`;
  }


  ###############################################################
  #  Make a plot showing 1-D "SBF" at 1000 Mpc
  #
  # get the arguments
  $output_file = "sbf_a_4.ps";
  $term_options = "postscript enhanced color '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 style fill solid 0.4 \n";
  printf CMDFILE "set key top right \n";
  printf CMDFILE "set label 1 at 60,1.1 'Distance = 1,000 Mpc' \n";
  printf CMDFILE "set xlabel 'Pixel number' \n";
  printf CMDFILE "set ylabel 'Intensity' \n";
  printf CMDFILE "set title 'A one-dimensional illustration of surface brightness fluctuations ' \n";
  
  $cmd = "plot [0:100][0:1.2] './sbf_10_1000.out' using (\$1):(\$2/1000) ";
  $cmd .= "  with boxes lc 1 lw 2  t ''  ";
  $cmd .= " , ";
  $cmd .= " 0.1 with lines lc -1 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/.gif/;
    $cmd = "convert -rotate 90 $psfile $giffile";
    printf "cmd is ..$cmd.. \n";
    $ret = `$cmd`;
  }


  ###############################################################
  #  Make a plot showing 1-D "SBF" at 10000 Mpc
  #
  # get the arguments
  $output_file = "sbf_a_5.ps";
  $term_options = "postscript enhanced color '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 style fill solid 0.4 \n";
  printf CMDFILE "set key top right \n";
  printf CMDFILE "set label 1 at 60,1.1 'Distance = 10,000 Mpc' \n";
  printf CMDFILE "set xlabel 'Pixel number' \n";
  printf CMDFILE "set ylabel 'Intensity' \n";
  printf CMDFILE "set title 'A one-dimensional illustration of surface brightness fluctuations ' \n";
  
  $cmd = "plot [0:100][0:1.2] './sbf_10_10000.out' using (\$1):(\$2/10000) ";
  $cmd .= "  with boxes lc 1 lw 2  t ''  ";
  $cmd .= " , ";
  $cmd .= " 0.1 with lines lc -1 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/.gif/;
    $cmd = "convert -rotate 90 $psfile $giffile";
    printf "cmd is ..$cmd.. \n";
    $ret = `$cmd`;
  }


  ###############################################################
  #  Make a plot showing relative size of fluctuations 
  #
  # get the arguments
  $output_file = "sbf_b_1.ps";
  $term_options = "postscript enhanced color 'Helvetica,18' size 15,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";
  printf CMDFILE "set grid \n";
  printf CMDFILE "set style fill solid 0.4 \n";
  printf CMDFILE "set key outside top right \n";
  printf CMDFILE "set xlabel 'Pixel number' \n";
  printf CMDFILE "set ylabel 'Fractional difference from average value' \n";
  printf CMDFILE "set title 'A one-dimensional illustration of surface brightness fluctuations ' \n";
  
  $cmd = "plot [0:100][-2:10] './sbf_10_1.out' using (\$1):(\$4) ";
  $cmd .= "  with linespoints lc 1 lw 2  t '1 Mpc'  ";
  $cmd .= " , ";
  $cmd .= "  './sbf_10_10.out' using (\$1):(\$4) ";
  $cmd .= "  with linespoints lc 2 lw 2  t '10 Mpc'  ";
  $cmd .= " , ";
  $cmd .= "  './sbf_10_100.out' using (\$1):(\$4) ";
  $cmd .= "  with linespoints lc 3 lw 2  t '100 Mpc'  ";
  $cmd .= " , ";
  $cmd .= "  './sbf_10_1000.out' using (\$1):(\$4) ";
  $cmd .= "  with linespoints lc 4 lw 2  t '1000 Mpc'  ";
  $cmd .= " , ";
  $cmd .= "  './sbf_10_10000.out' using (\$1):(\$4) ";
  $cmd .= "  with linespoints lc 5 lw 2  t '10000 Mpc'  ";

  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 plot showing relative size of fluctuations 
  #
  # get the arguments
  $output_file = "sbf_b_1.ps";
  $term_options = "postscript enhanced color 'Helvetica,18' size 15,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";
  printf CMDFILE "set grid \n";
  printf CMDFILE "set style fill solid 0.4 \n";
  printf CMDFILE "set key outside top right \n";
  printf CMDFILE "set xlabel 'Pixel number' \n";
  printf CMDFILE "set ylabel 'Fractional difference from average value' \n";
  printf CMDFILE "set title 'A one-dimensional illustration of surface brightness fluctuations ' \n";
  
  $cmd = "plot [0:100][-2:10] './sbf_10_1.out' using (\$1):(\$4) ";
  $cmd .= "  with linespoints lc 1 lw 2  t '1 Mpc'  ";
  $cmd .= " , ";
  $cmd .= "  './sbf_10_10.out' using (\$1):(\$4) ";
  $cmd .= "  with linespoints lc 2 lw 2  t '10 Mpc'  ";
  $cmd .= " , ";
  $cmd .= "  './sbf_10_100.out' using (\$1):(\$4) ";
  $cmd .= "  with linespoints lc 3 lw 2  t '100 Mpc'  ";
  $cmd .= " , ";
  $cmd .= "  './sbf_10_1000.out' using (\$1):(\$4) ";
  $cmd .= "  with linespoints lc 4 lw 2  t '1000 Mpc'  ";
  $cmd .= " , ";
  $cmd .= "  './sbf_10_10000.out' using (\$1):(\$4) ";
  $cmd .= "  with linespoints lc 5 lw 2  t '10000 Mpc'  ";

  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 plot showing relative size of fluctuations 
  #     Zoom in
  #
  # get the arguments
  $output_file = "sbf_b_2.ps";
  $term_options = "postscript enhanced color 'Helvetica,18' size 15,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";
  printf CMDFILE "set grid \n";
  printf CMDFILE "set style fill solid 0.4 \n";
  printf CMDFILE "set key outside top right \n";
  printf CMDFILE "set xlabel 'Pixel number' \n";
  printf CMDFILE "set ylabel 'Fractional difference from average value' \n";
  printf CMDFILE "set title 'A one-dimensional illustration of surface brightness fluctuations ' \n";
  
  $cmd = "plot [0:100][-1.5:1.5] './sbf_10_1.out' using (\$1):(\$4) ";
  $cmd .= "  with linespoints lc 1 lw 1  t '1 Mpc'  ";
  $cmd .= " , ";
  $cmd .= "  './sbf_10_10.out' using (\$1):(\$4) ";
  $cmd .= "  with linespoints lc 2 lw 2  t '10 Mpc'  ";
  $cmd .= " , ";
  $cmd .= "  './sbf_10_100.out' using (\$1):(\$4) ";
  $cmd .= "  with linespoints lc 3 lw 2  t '100 Mpc'  ";
  $cmd .= " , ";
  $cmd .= "  './sbf_10_1000.out' using (\$1):(\$4) ";
  $cmd .= "  with linespoints lc 4 lw 2  t '1000 Mpc'  ";
  $cmd .= " , ";
  $cmd .= "  './sbf_10_10000.out' using (\$1):(\$4) ";
  $cmd .= "  with linespoints lc 5 lw 1  t '10000 Mpc'  ";

  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 plot showing stdev of fractional size of fluctuations
  #     from the mean as function of distance
  #
  # get the arguments
  $output_file = "sbf_c.ps";
  $term_options = "postscript enhanced color '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 style fill solid 0.4 \n";
  printf CMDFILE "set key top right \n";
  printf CMDFILE "set xlabel 'Distance of galaxy' \n";
  printf CMDFILE "set logscale x \n";
  printf CMDFILE "set logscale y \n";
  printf CMDFILE "set ylabel 'RMS of fractional difference from average value' \n";
  printf CMDFILE "set title 'A one-dimensional illustration of surface brightness fluctuations ' \n";
  
  $cmd = "plot [0.7:2.0e4][1e-2:5] './sbf_stats.out' using (\$2):(\$14) ";
  $cmd .= "  with points lc 1 lw 2 pt 4 ps 2 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;
  
  ###############################################################
  #  Make a plot showing spectrum of late-type galaxy M33
  #
  # get the arguments
  $output_file = "spec_m33.ps";
  $term_options = "postscript enhanced color '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 xlabel 'Wavelength (Angstroms) ' \n";
  printf CMDFILE "set ylabel 'Intensity (arbitrary scale) ' \n";
  printf CMDFILE "set title 'Spectrum of galaxy B \n";
  
  $cmd = "plot [3500:8000][] 'm33_spec.dat' using (\$1):(\$2) ";
  $cmd .= "  with lines lc 3 lw 2 t ''  ";
#  $cmd .= " , ";
#  $cmd .= " 'm101_prof_inten.dat' using (\$1):(\$4) index 1 ";
#  $cmd .= "  with linespoints lc 3 pt 5 lw 2 t 'NGC5447'  ";

  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);


  ###############################################################
  #  Make a plot showing logarithmic intensity as function of radius
  #    for two galaxies
  #
  # get the arguments
  $output_file = "prof_log.ps";
  $term_options = "postscript enhanced color '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 logscale y \n";
  printf CMDFILE "set xlabel 'Distance from center (arcsec) ' \n";
  printf CMDFILE "set ylabel 'Surface brightness (arbitrary scale) ' \n";
  printf CMDFILE "set title 'Radial profiles of two galaxies -- logarithmic surface brightness' \n";
  
  $cmd = "plot [0:250][] 'ngc4365_prof.dat' using (\$1):(\$2) ";
  $cmd .= "  with linespoints lc 1 pt 1 lw 2 t 'NGC4365'  ";
  $cmd .= " , ";
  $cmd .= " 'm101_prof_inten.dat' using (\$1):(\$4) index 1 ";
  $cmd .= "  with linespoints lc 3 pt 5 lw 2 t 'NGC5447'  ";
  $cmd .= " , ";
  #$cmd .= " 50*exp(-x*0.01) lc -1 lt 2 lw 2 t '{/Symbol m} = K e^{-r/R_0} ' ";
  $cmd .= " 50*exp(-x*0.01) lc -1 lt 2 lw 2 t '' ";
  $cmd .= " , ";
  #$cmd .= " 10*exp(-(x/10)*0.25) lc 5 lt 1 lw 2 t '{/Symbol m} = K e^{(-r/R_1)^{0.25}} ' ";
  $cmd .= " 10*exp(-(x/10)*0.25) lc 5 lt 1 lw 2 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 plot showing logarithmic scales on both axes
  #    for two galaxies
  #
  # get the arguments
  $output_file = "prof_log_log.ps";
  $term_options = "postscript enhanced color '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 logscale y \n";
  printf CMDFILE "set logscale x \n";
  printf CMDFILE "set xlabel 'Distance from center (arcsec) ' \n";
  printf CMDFILE "set ylabel 'Surface brightness (arbitrary scale) ' \n";
  printf CMDFILE "set title 'Radial profiles of two galaxies -- logarithmic on both axes' \n";
  
  $cmd = "plot [1:250][] 'ngc4365_prof.dat' using (\$1):(\$2) ";
  $cmd .= "  with linespoints lc 1 pt 1 lw 2 t 'NGC4365'  ";
  $cmd .= " , ";
  $cmd .= " 'm101_prof_inten.dat' using (\$1):(\$4) index 1 ";
  $cmd .= "  with linespoints lc 3 pt 5 lw 2 t 'NGC5447'  ";
  $cmd .= " , ";
  #$cmd .= " 500*(x**-1.5) lc -1 lt 2 t '{/Symbol m} = C r^{-a} ' ";
  $cmd .= " 50*exp(-x*0.01) lc -1 lt 2 lw 2 t '' ";
  $cmd .= " , ";
  #$cmd .= " 10*exp(-(x/10)*0.25) lc 5 lt 1 lw 2 t '' ";
  $cmd .= " 10*exp(-(x/10)*0.25) lc 5 lt 1 lw 2 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;
