#!/usr/local/bin/perl -w =head1 DESCRIPTION Script to convert a simple list of waypoints to gpsman format. Input is a whitespace-separated list of "name lat long" with decimal coordinates, assumed to be using WGS84 =head1 USAGE perl -w to-gpsman.pl [ options ] simple-waypoints.txt options: -u Convert names to upper case. -p subdef Perl subroutine to calculate a prefix for the name. The subroutine is given the entire line. =head1 EXAMPLES perl -w to-gpsman.pl -p 'sub {return "V"}' wp.txt perl -w to-gpsman.pl -p 'sub {return /tree/ ? "T" : "X"}' wp.txt =head1 RECENT CHANGES Added -t option, to force the script to expect tab-separated data. This allows the waypoint names to contain spaces. Without -t, the program expects the input fields to be separated by whitespace. =cut use Getopt::Std; my %opts = (); &getopts('p:tu', \%opts); my $prefix_subr = $opts{p} ? eval $opts{p} : undef; my $upper = $opts{u}; my $expect_tabs = $opts{t}; ##$datum = "NAD83"; ##$pre = "V"; $pre = ""; $min_x = -999; $max_x = 999; $min_y = -999; $max_y = 999; #$symbol="anchor"; $symbol="tree"; $myname = $0; $i = rindex($myname,"/"); $i = ($i== -1) ? 0 : $i+1; $myname = substr($myname,$i); print <) { chomp; s/^\s+|\s+$//g; #printf(":%s:\n", $_); next if /^$|^#/; $pre = &$prefix_subr($_) if $prefix_subr; @f = split $split_pat; ($name, $y, $x) = @f; $name =~ s/:$//; $x =~ s/^W/-/ || $x =~ s/^E//; $y =~ s/^S/-/ || $y =~ s/^N//; next unless abs($x) < $max_x and abs($y) < $max_y and abs($x) > $min_x and abs($y) > $min_y; $x =~ s/-/W/ || $x =~ s/^/E/; $y =~ s/^-/S/ || $y =~ s/^/N/; my $wpname = $pre . $name; $wpname = uc( $wpname ) if $upper; print join("\t", $wpname, $name, $y, $x, "symbol=$symbol"), "\n"; }