#! /usr/bin/env perl # $Id: lines.pl 743 2006-12-18 23:10:02Z jnieuwen $ use strict ; use warnings ; use GD::Graph::lines ; # Get the commandline parameters ; my $infile = shift @ARGV ; my $outfile = shift @ARGV ; # Init variables. my @xval = () ; my @yval = () ; my @zval = () ; my $ymax = 0 ; my $xcount = 0 ; my $sum=0 ; my $count=0 ; my @cache = () ; open (FILE,"$infile") or die "Could not open $infile\n" ; while (my $line = ) { next unless ($line =~ /O=RMC/) ; # Skip no fix lines. chomp $line ; my ($info,$time,undef,$lat,$lon,undef,undef,undef,$head,$speed,undef,undef) = split(/ /,$line) ; next if ($speed < 1) ; # Filter out standing still moments. push @cache, $speed ; if ($#cache > 59) { shift @cache ; my $y = 0 ; for (my $i=0; $i <= $#cache; $i++) { $y += $cache[$i] ; } $y = ($y / ($#cache+1)) * 3.6 ; # Convert to km/h and average over cache length. $sum += $y ; push (@yval,$y) ; push (@zval,$sum/++$count) ; $ymax = $y if ($y > $ymax) ; } } close FILE ; # Set the x values. undef @xval ; foreach my $i (@yval) { push(@xval,$xcount++/60) ; } my @data = ([@xval],[@yval],[@zval]) ; my $graph = GD::Graph::lines->new(1000,400) ; $graph->set( x_label => 'time in minutes', long_ticks => 1, y_label => 'km/h', y_min_value => 0, y_max_value => 50, y_tick_number => 10, y_label_skip => 1, x_label_skip => 300 ) or die $graph->error; my $gd = $graph->plot(\@data) or die $graph->error; open(IMG, ">$outfile") or die $!; binmode IMG; print IMG $gd->png; close IMG ;