#!/usr/bin/perl -w
use strict;

# plot files from arduino dhttester

use Graphics::GnuplotIF qw(GnuplotIF); # gnuplot for plots

my $plot;  # gnuplot object
my $infile = "ardlog.txt";
my @time;
my @humid;
my @degc;
my @degf;
my @raw;
my @point;


open (IN, "< $infile") or die "couldn't open $infile $!\n";


while (<IN>) 
  {
   @raw = split(/\s+/); # break on whitespace   
   push @time,$raw[1]; # the field number time lives in and so on
   push @humid,$raw[3];
   push @degc,$raw[6];
   push @degf,$raw[8];  
  } # at this point, should have array for each type, first is time, and is "x"
  
  
#  print "time: @time\n";
    $plot = Graphics::GnuplotIF->new(title => "DHT22 data",
       style =>"lines", xlabel => 'Minutes', ylabel => "value") or die "couldn't get a plot $!\n";
       
    $plot->gnuplot_cmd ("set grid");
    $plot->gnuplot_cmd ("set key left bottom");
    $plot->gnuplot_set_plot_titles("Humidity","Deg C","Deg F");
    
    $plot->gnuplot_plot_xy( \@time, \@humid, \@degc,\@degf); # rewrite plot
 
#sleep(10);  
until (<>){};
close IN;
undef $plot;
print "bye!\n";
