#!/usr/bin/perl
#

  
  ###############################################################
  #  Make a plot showing linear intensity as function of radius
  #
  # get the arguments
  $output_file = "prof_linear.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 nokey \n";
  printf CMDFILE "set xlabel 'Distance from center (pixels) ' \n";
  printf CMDFILE "set ylabel 'Intensity (counts per pixel) ' \n";
  printf CMDFILE "set title 'Radial profile of a galaxy -- linear intensity' \n";
  
  $cmd = "plot [][] 'concen_index.rminus2.out' using (\$2*10):(\$3) ";
  $cmd .= "  lt 1 pt 1 lw 4";

  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 intensity as function of radius
  #
  # 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 nokey \n";
  printf CMDFILE "set logscale y \n";
  printf CMDFILE "set xlabel 'Distance from center (pixels) ' \n";
  printf CMDFILE "set ylabel 'Intensity (counts per pixel) ' \n";
  printf CMDFILE "set title 'Radial profile of a galaxy -- logarithmic intensity' \n";
  
  $cmd = "plot [][0.01:1.0] 'concen_index.rminus2.out' using (\$2*10):(\$3) ";
  $cmd .= "  lt 1 pt 1 lw 4";

  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 intensity as function of 
  #  logarithmic radius
  #
  # 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 nokey \n";
  printf CMDFILE "set logscale y \n";
  printf CMDFILE "set logscale x \n";
  printf CMDFILE "set xlabel 'Distance from center (pixels) ' \n";
  printf CMDFILE "set ylabel 'Intensity (counts per pixel) ' \n";
  printf CMDFILE "set title 'Radial profile of a galaxy -- logarithmic intensity and radius ' \n";
  
  $cmd = "plot [0.9:100][0.01:1.0] 'concen_index.rminus2.out' using (\$2*10+1):(\$3) ";
  $cmd .= "  lt 1 pt 1 lw 4";

  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 cumulative integrated light
  #     in  linear intensity units as function of radius
  #
  # get the arguments
  $output_file = "prof_cum_lin.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 nokey \n";
  printf CMDFILE "set xlabel 'Distance from center (pixels) ' \n";
  printf CMDFILE "set ylabel 'Total light intensity (counts) ' \n";
  printf CMDFILE "set title 'Cumulative light integrated from center of galaxy outwards ' \n";
  
  $cmd = "plot [][] 'concen_index.rminus2.out' using (\$2*10):(\$5) ";
  $cmd .= "  lt 1 pt 1 lw 4";

  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 which illustrates Petrosian magnitudes 
  #
  # get the arguments
  $output_file = "prof_petro_a.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 nokey \n";
  printf CMDFILE "set nokey \n";
  printf CMDFILE "set xlabel 'Distance from center (pixels) ' \n";
  printf CMDFILE "set ylabel 'Light intensity (counts per pixel) ' \n";
  printf CMDFILE "set title '' \n";
  
  $cmd = "plot [][] 'concen_index.rminus2.out' using (\$2*10):(\$3) ";
  $cmd .= "  with points pt 1 lt 1 lw 4";
  $cmd .= " , ";
  $cmd .= " 'concen_index.rminus2.out.2' index 1 using (\$2*10):(\$3) ";
  $cmd .= "  with impulse lt 1  lw 10 lc -1 ";

  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 which illustrates Petrosian magnitudes 
  #
  # get the arguments
  $output_file = "prof_petro_b.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 nokey \n";
  printf CMDFILE "set xlabel 'Distance from center (pixels) ' \n";
  printf CMDFILE "set ylabel 'Light intensity (counts per pixel) ' \n";
  printf CMDFILE "set title '' \n";
  
  $cmd = "plot [][] 'concen_index.rminus2.out' using (\$2*10):(\$3) ";
  $cmd .= "  with points pt 1 lt 1 lw 4";
  $cmd .= " , ";
  $cmd .= " 'concen_index.rminus2.out.2' index 0 using (\$2*10):(\$3) ";
  $cmd .= "  with impulse lt 1  lw 0.1 lc 1 ";

  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 which illustrates Petrosian magnitudes 
  #    (This is average intensity as function of R)
  #
  # get the arguments
  $output_file = "prof_petro_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 nokey \n";
  printf CMDFILE "set xlabel 'Distance from center (pixels) ' \n";
  printf CMDFILE "set ylabel 'Average light intensity within R (counts per pixel) ' \n";
  printf CMDFILE "set title '' \n";
  
  $cmd = "plot [][] 'concen_index.rminus2.out.2' using (\$2*10):(\$5/(3.14159*(\$2*\$2))) ";
  $cmd .= "  with lines lt 1  lw 8 lc 3 ";
  $cmd .= " , ";
  $cmd .= " 'concen_index.rminus2.out.2' index 1 using (\$2*10):(\$5/(3.14159*(\$2*\$2)))";
  $cmd .= "  with impulse lt 1  lw 8 lc -1 ";


  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;
