18 August 2013

Find, change & replace in garmin .fit file

I recently did a long ride and discovered at the end that the speed sensor had been badly configured (wheel circumference set to 6 times too large). This was leading to distorted figures in the Training Centre.  Needing to edit several lines in the .fit file i turned to perl nad this script

#!/usr/bin/env perl
use strict;
use warnings;
my $file='knokke.xml';
open my $info, $file or die "Could not open $file: $!";
open my $out, '>', "knokke_new.xml" or die "Can't write new file: $!";
while( my $line = <$info>)  {  
my $num = $1 if $line =~ /\(.*)\<\/DistanceMeters\>/;
if ( $num ) {
    my $newnum = $num / 750.5*140;
$line =~ s/$num/$newnum/;
}
print $out $line;
}
close $file;
close $out;

No comments: