#!/usr/bin/perl # Output the Garmin Training Center v2 Schema (for 3.2.0 version of software) # from an input GPX file # my $file = getOpenFile("GPX File", ".gpx"); if ( $file eq "" ) { exit; } my $outfile = $file; $outfile =~ s/\.[^\.]*$/.tcx/i; open (IN, $file ) or windie("Unable to open $file"); if ( -e $outfile ) { my $rsp = Win32::MsgBox("Output file \"$outfile\" already exists. Overwrite?", 32 + 4, "File Exists"); if ( $rsp != 6 ) { exit; } } open (OUT, ">$outfile"); print OUT < New Course New Course EOF $min = 0; $sec = 0; while () { #if (/trkpt lat=\"(.*)\" lon=\"(.*)\"/) { if (/(trkpt|rtept) lat=\"(.*)\" lon=\"(.*)\"/) { printf OUT " %f %f 0.00.0Absent ", $min, $sec, $1, $2; $sec++; if ($sec == 61) { $min++; $sec=0; } } } print OUT < EOF close (OUT); close (IN); sub getOpenFile { use Tk; my ($defExtType, $defExt, $startDir) = @_; # Set up the display window $mw = MainWindow->new(); $mw->title(""); $mw->iconify(); my $types = [ [$defExtType, [$defExt] ], ['All Files', ['*']] ]; my $filename = $mw->getOpenFile(-defaultextension=>"*", -filetypes=> $types, -initialdir => $startDir, -title => "Select Input File"); $mw->destroy(); return $filename; }