#!/usr/bin/perl -w

use lib '../blib/lib', '../blib/arch';

### genRand2D

use strict;
use Algorithm::RandomPointGenerator;

my $help_msg = "\nThe file supplied with the option '--histfile' should contain\n" .
               "a 2D histogram that is to be used for generating the random\n" .
               "points.  Each line of this file should show the bins of the\n" .
               "histogram along the x-axis and the different rows should correspond\n" .
               "to the bin structure along the y-direction.  Use the CSV format for\n" .
               "this file.\n" .
               "\nThe file supplied with the option '--bbfile' needs to delineate\n" .
               "the bounding box of the xy-plane for which the input histogram was\n" .
               "generated by some other tool in your application. Apart from any\n" .
               "comment lines, this file should contain EXACTLY two rows, and each\n" .
               "row with EXACTLY two numbers in it. The second number in each row\n" .
               "must be larger than the first. The two numbers in the first row are\n" .
               "for the x axis and the two number in the second row for the y axis.\n" .
               "Use the CSV format for this file also.\n\n";

die "$help_msg$!\n" if "@ARGV" eq '--help';
my %all_args = @ARGV;
die "\nYou did not supply a histogram file with the '--histfile' option.\n" .
    "Try entering `GenRand2D --help' for info regarding the options\n\n"
    unless exists $all_args{'--histfile'};
die "\nYou did not supply a bounding-box file with the '--bbfile' option.\n" .
    "Try entering `GenRand2D --help' for info regarding the options\n\n"
    unless exists $all_args{'--bbfile'};

my $generator = Algorithm::RandomPointGenerator->new(
                            input_histogram_file     => $all_args{'--histfile'},
                            bounding_box_file        => $all_args{'--bbfile'},
                            command_line_mode        => 1,
                );
$generator->read_histogram_file_for_desired_density();
$generator->read_file_for_bounding_box();
$generator->normalize_input_histogram();
$generator->set_sigmas_for_proposal_density();
$generator->metropolis_hastings();
$generator->write_generated_points_to_a_file();
print "\nYou should soon see a line plot of the histogram of the generated random points.\n";
$generator->make_output_histogram_for_generated_points();
$generator->plot_histogram_lineplot();
