use LWP::Simple;
use File::Temp qw(tempfile);

$typegraph = $ARGV[0];

$url1 = "http://ssds-prod.mbari.org/ssds/data/raw-data?deviceID=1783&startDateTime=20170813.000000&endDateTime=20171113.120000&isi=0&noHTMLHeader=1";
#$url1 = "http://ssds-prod.mbari.org/ssds/data/raw-data?deviceID=1783&lastNumberOfPackets=16000000&isi=0&noHTMLHeader=1";

loop:;
$data = get($url1);

# remove the file when the reference goes away with UNLINK option (1 remove 0 keep)
$tmp_fh = new File::Temp( UNLINK => 0 );
#print "temp filename: $tmp_fh\n";

my @lines = split /\n/, $data;


foreach my $line (@lines) {

@fields = split /, /, $line;
$V375 = $fields[33];

$datetime = $fields[46];

print $tmp_fh "$datetime $V375\n";
}

open PLOT, "| gnuplot -p";
print PLOT "set size .75,.5\n";
print PLOT "set xdata time\n";
print PLOT "set timefmt '%Y-%m-%d %H:%M:%S'\n";
print PLOT "set xrange [*:*]\n";
print PLOT "set title '375 volt'\n";
print PLOT "plot '$tmp_fh' using 1:3\n";

close PLOT;

#sleep 60;

#goto loop;

