Index: trunk/tools/czarplot.pl
===================================================================
--- trunk/tools/czarplot.pl	(revision 28714)
+++ trunk/tools/czarplot.pl	(revision 28719)
@@ -5,10 +5,8 @@
 
 use Getopt::Long qw( GetOptions :config auto_help auto_version gnu_getopt );
-use File::Temp qw(tempfile);
 use POSIX qw/strftime/;
 
 use czartool::CzarDb;
-use czartool::Gnuplot;
-
+use czartool::Czarplot;
 
 my $czarDbName = "czardb";
@@ -19,7 +17,9 @@
 my $begin = undef;
 my $end = undef;
+my $path = undef;
 my $verbose = undef;
 my $histogram = undef;
 my $timeSeries = undef;
+my $savingToFile = undef;
 
 GetOptions (
@@ -30,4 +30,5 @@
         "begin|b=s" => \$begin,
         "end|e=s" => \$end,
+        "output|o=s" => \$path,
         "histogram|h" => \$histogram,
         "timeseries|t" => \$timeSeries,
@@ -37,24 +38,19 @@
 print "\n";
 if (!$histogram) {
-    print "* OPTIONAL: plot histogram                  -h                          (default=on)\n";
-}
+    print "* OPTIONAL: plot histogram                  -h                          (default=off)\n";}
 if (!$timeSeries) {
-    print "* OPTIONAL: plot timeseries                 -t                          (default=on)\n";
-} 
+    print "* OPTIONAL: plot timeseries                 -t                          (default=on)\n";} 
 if (!$label) {
-    print "* OPTIONAL: choose a label                  -l <labellName>             (default='all_labels')\n";
-}
+    print "* OPTIONAL: choose a label                  -l <labellName>             (default='all_labels')\n";}
 if (!$stage) {
-    print "* OPTIONAL: choose a stage                  -s <chip|cam|warp|etc>      (default=none)\n";
-}
+    print "* OPTIONAL: choose a stage                  -s <chip|cam|warp|etc>      (default=none)\n";}
 if (!$interval) {
-    print "* OPTIONAL: choose time interval in past    -i <'1 hour'|'1 day'|etc>   (default=interval since 7am this morning)\n";
-} 
+    print "* OPTIONAL: choose time interval in past    -i <'1 hour'|'1 day'|etc>   (default=interval since 7am this morning)\n";} 
 if (!$begin) {
-    print "* OPTIONAL: choose a begin time             -d <datetime>               (default=7am this morning)\n";
-} 
+    print "* OPTIONAL: choose a begin time             -d <datetime>               (default=7am this morning)\n";} 
 if (!$end) {
-    print "* OPTIONAL: choose an end time              -e <datetime>               (default=now)\n";
-} 
+    print "* OPTIONAL: choose an end time              -e <datetime>               (default=now)\n";} 
+if (!$path) {
+    print "* OPTIONAL: choose an output location       -o <path>                   (default=none)\n";} 
 
 print "\n";
@@ -62,11 +58,14 @@
 # default values
 if (!$label) {$label = "all_labels";}
-if (!$histogram && !$timeSeries) {$timeSeries = 1;}
+if (!$histogram && !$timeSeries) {$timeSeries = 1; $histogram = 1;}
 if (!$verbose) {$verbose = 0;}
 if (!$save_temps) {$save_temps = 0;}
+if (!$path) {$savingToFile = 0; $path = ".";}
+else {$savingToFile = 1;}
 
 my $czarDb = new czartool::CzarDb($czarDbName, "ippdb01", "ipp", "ipp", $verbose);
-my $gnuplot = new czartool::Gnuplot("%Y%m%d-%H%M%S", "X11", "histo.pbm");
 $czarDb->setDateFormat("%Y%m%d-%H%i%s");
+
+my $czarplot = new czartool::Czarplot($czarDb, "%Y%m%d-%H%M%S", $savingToFile ? "png" : "X11", $path, $save_temps);
 
 my @allStages = ("chip", "cam", "fake", "warp", "stack", "diff", "magic", "magicDS", "dist");
@@ -79,58 +78,5 @@
 }
 
-if ($histogram) {plotHistogram($label, $begin, $end);}
-if ($timeSeries) {plotTimeSeries($label, $stage, $begin, $end); }
+if ($timeSeries) {$czarplot->createTimeSeries($label, $stage, $begin, $end);}
+if ($histogram) {$czarplot->createHistogram($label, $begin, $end);}
 
-###########################################################################
-#
-# Plots a time series for all stages for this label
-#
-###########################################################################
-sub plotTimeSeries {
-    my ($label, $selectedStage, $beginTime, $endTime) = @_;
-
-    my ($minX, $maxX, $minY, $maxY, $timeDiff);
-    $minX = 999999999;
-    $maxX = -9999999999;
-    $minY = 999999999;
-    $maxY = -99999999;
-
-    my $stages = undef;
-
-    if (!$selectedStage) {$stages = \@allStages;}
-    else {$stages = ["$selectedStage"]};
-
-    my %gnuplotFiles;
-    foreach $stage (@{$stages}) {
-        $gnuplotFiles{$stage} = $czarDb->createTimeSeriesData($save_temps, $label, $stage, $beginTime, $endTime, \$minX, \$maxX, \$minY, \$maxY, \$timeDiff);
-    }
-
-    if (!$selectedStage) {$gnuplot->plotAllStagesTimeSeries($label, $beginTime, $endTime, $maxX, $minX, $maxY, $minY, $timeDiff, \%gnuplotFiles);}
-    else {$gnuplot->plotSingleTimeSeries($gnuplotFiles{$selectedStage}, $selectedStage, $label, $beginTime, $endTime, $maxX, $minX, $maxY, $minY, $timeDiff);}
-
-}
-
-###########################################################################
-#
-# Plots a histogram of stuff processed in provided interval and label for all stages
-#
-###########################################################################
-sub plotHistogram {
-    my ($label, $beginTime, $endTime) = @_;
-
-    my ($tempFile, $filePath) = tempfile( "/tmp/czartool_gnuplot_histogram.XXXX", UNLINK => !$save_temps);
-    my ($processed, $pending, $faults);
-
-    foreach $stage (@allStages) {
-
-        $czarDb->countProcessedPendingAndFaults($label, $stage, $beginTime, $endTime, \$processed, \$pending, \$faults);
-        print $tempFile "$stage $processed, $pending, $faults\n";
-    }
-
-    close($tempFile);
-
-    $gnuplot->plotHistogram($filePath, $label, $beginTime, $endTime);
-}
-
-
-
