use LWP::Simple;
use File::Temp qw(tempfile);

$typegraph = $ARGV[0];

$url1 = "http://ssds-prod.mbari.org/ssds/data/raw-data?deviceID=1780&lastNumberOfPackets=40000&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;
$GF375 = $fields[1];
$GF375com = $fields[2];
$GF48 = $fields[3];
$GF48com = $fields[4];
$datetime = $fields[6];

print $tmp_fh "$datetime $GF375 $GF375com $GF48 $GF48com\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 common GF'\n";
print PLOT "plot '$tmp_fh' using 1:4\n";

close PLOT;

#sleep 60;

#goto loop;

