#!/usr/bin/perl # Andrew Daviel, April 2005 # Convert Garmin GPS TSV-exported track files to Fig # e.g. track2fig 7100 9280 -123.176 49.281 <27mar05.tsv > 27mar05a.fig # can overlay worldmap-generated maps from e.g. # worldmap -latlon -s 180000 -p 50,2,2,5,1,3,3,2,5,2,1 49.2 49.4 -123.3 -123 |ps2fig > map.fig $quiet = 0 ; $line_style = 0 ; $thickness = 1 ; $pen_color = 4 ; # red $fill_color = 7 ; $pdepth = 50 ; $pen_style = -1 ; $area_fill = -1 ; $style_val = '0.000' ; $join_style = 0 ; $cap_style = 0 ; $radius = -1 ; $radius1 = 10 ; $forward_arrow = 0 ; $backward_arrow = 0 ; $maxcol = 5 ; $xscale = shift ; unless ($xscale) { die "Usage: $0 [] [] [] [] []\n" ; } $scale2 = 1200/100 ; $scale2 = 1200 ; $yscale = shift ; unless ($yscale) { $yscale = $xscale ; } $yoff = shift ; $xoff = shift ; $mindxy = shift ; $radius0 = shift ; unless ($radius0) { $radius0 = 4000 ; } $radius1 = int ($xscale / $radius0) ; unless ($radius1>0) { $radius1 = 1 ; } print<) { chomp ; if (/^Waypoint/) { ($header,$name,$date,$type,$position,$altitude,$depth,$prox,$temp,$dmode,$color,$sym,$fac,$city,$state,$country,$mdate,$link,$cat) = split(/\t/) ; #Header Name Description Type Position Altitude Depth Proximity Temperature Display Mode Color Symbol Facility City State Country Date Modified Link Categories #Waypoint 01 SAND H 09-AUG-04 13:13 User Waypoint N49 05.800 W123 19.450 7 ft Symbol & Name Unknown Waypoint if ($position =~ /([NS])([\d]+)[\s]([\d\.]+)[\s]([EW])([\d]+)[\s]([\d\.]+)/) { $nq = $1 ; $nd = $2 ; $nm = $3 ; $eq = $4 ; $ed = $5 ; $em = $6 ; $ndg = sprintf("%.6f",$nd + $nm/60) ; if ($nq eq 'S') { $ndg = -$ndg ; } $edg = sprintf("%.6f",$ed + $em/60) ; if ($eq eq 'W') { $edg = -$edg ; } $x = $xscale * ($edg - $xoff) / 180 ; $y = $yscale * ($ndg - $yoff) / 180 ; # from worldmap.c if ($xmax eq '') { $xmax = $xmin = $x ; } if ($ymax eq '') { $ymax = $ymin = $y ; } if ($x>$xmax) { $xmax = $x ; } if ($y>$ymax) { $ymax = $y ; } if ($x<$xmin) { $xmin = $x ; } if ($y<$ymin) { $ymin = $y ; } $x = int($x * $scale2 + 0.5 ) ; $y = int($y * -$scale2 + 0.5 ) ; # from ps2fig if ($mindxy eq '' or $x0 eq '' or ((abs($y0-$y) > $mindxy) and (abs($x0-$x) > $mindxy))) { # circle print "#$name\n#$position $altitude\n#$date\n" ; $x2 = $x + $radius1 ; print "1 3 $line_style $thickness $pen_color" ; print " $fill_color $pdepth $pen_style $area_fill $angle 1 0.000 " ; print "$x $y $radius1 $radius1 $x $y $x2 $y \n" ; } } } elsif (/^Trackpoint/) { ($type,$position,$time,$altitude,$depth,$length,$dtime,$speed,$course) = split(/\t/) ; if ($position =~ /([NS])([\d]+)[\s]([\d\.]+)[\s]([EW])([\d]+)[\s]([\d\.]+)/) { $nq = $1 ; $nd = $2 ; $nm = $3 ; $eq = $4 ; $ed = $5 ; $em = $6 ; $ndg = sprintf("%.6f",$nd + $nm/60) ; if ($nq eq 'S') { $ndg = -$ndg ; } $edg = sprintf("%.6f",$ed + $em/60) ; if ($eq eq 'W') { $edg = -$edg ; } $x = $xscale * ($edg - $xoff) / 180 ; $y = $yscale * ($ndg - $yoff) / 180 ; # from worldmap.c if ($xmax eq '') { $xmax = $xmin = $x ; } if ($ymax eq '') { $ymax = $ymin = $y ; } if ($x>$xmax) { $xmax = $x ; } if ($y>$ymax) { $ymax = $y ; } if ($x<$xmin) { $xmin = $x ; } if ($y<$ymin) { $ymin = $y ; } $x = int($x * $scale2 + 0.5 ) ; $y = int($y * -$scale2 + 0.5 ) ; # from ps2fig if ($mindxy eq '' or $x0 eq '' or ((abs($y0-$y) > $mindxy) and (abs($x0-$x) > $mindxy))) { push (@x,$x) ; push(@y,$y) ; $x0 = $x ; $y0 = $y ; } } } elsif (/^Datum/) { ($type,$datum) = split(/\t/) ; } elsif (/^Track/) { ($type,$trackname,$start,$elapsed,$length,$avspeed,$link) = split(/\t/) ; unless ($quiet) { print STDERR "$type $trackname $start\n" ; } if (@x) { $N = @x ; print "#$trackname0 $start0\n" ; print "2 1 $line_style $thickness $pen_color" ; print " $fill_color $pdepth $pen_style $area_fill $style_val $join_style" ; print " $cap_style $radius $forward_arrow $backward_arrow " ; print "$N\n" ; for ($i=0;$i<$N;$i++) { if ($col > $maxcol) { print "\n\t" ; $col = 0 ; } print " $x[$i] $y[$i]" ; $col++ ; } print "\n" ; undef(@x) ; undef(@y) ; } $trackname0 = $trackname ; $start0 = $start ; } elsif (/^Header/) { # header } elsif (/^Grid/) { ($type,$grid) = split(/\t/) ; } else { #print "Unknown: $_\n" ; } } #Track ACTIVE LOG 7/30/2004 7:26:56 PM 00:23:39 9.26 nm 23 kt #Trackpoint N49 15.338 W123 14.164 7/30/2004 7:26:56 PM 97.7 m #Trackpoint N49 15.258 W123 14.441 7/30/2004 7:27:37 PM 82.3 m 0.198 nm 00:00:41 17 kt 246° true if (@x) { $N = @x ; print "#$trackname0 $start0\n" ; print "2 1 $line_style $thickness $pen_color" ; print " $fill_color $pdepth $pen_style $area_fill $style_val $join_style" ; print " $cap_style $radius $forward_arrow $backward_arrow " ; print "$N\n\t" ; $col = 0; for ($i=0;$i<$N;$i++) { if ($col > $maxcol) { print "\n\t" ; $col = 0 ; } print "$x[$i] $y[$i]\n" ; $col+= 2 ; } } $dx = $xmax-$xmin ; $dy = $ymax-$ymin ; print STDERR "x $xmin - $xmax : $dx\ny $ymin - $ymax : $dy\n" ;