=head1 DESCRIPTION Check distances of waypoints ... =cut $usage = "Usage:\n\tperl -w $0 waypoint-file name_col col1 col2 [ --dskip pattern ] [ data-file ]"; =head1 COMMAND LINE PARAMETERS perl -w ... waypoint-file name_col col1 col2 [ --dskip pattern ] [ data-file ] waypoint-file has one waypoint per line, in the format: name[tab]coord1[tab]coord2 lines beginning with "#" are ignored. data-file contains the tab-separated data; if not given, standard input is used. This file should have waypoint names in column name_col. The coordinates to be checked are at columns col1 and col2, respectively. Lines in the input which contain the pattern, given on the command line by "--dskip pattern", are ignored. =cut sub errx { print STDERR $_[0], "\n"; exit 1; } sub errp { print STDERR $_[0], "\n"; } ## ## get the command-line parameters ## $wfile = shift or &errx($usage); $name_col = shift or &errx($usage); $col1 = shift or &errx($usage); $col2 = shift or &errx($usage); $debug = 0; $dskip_pattern = qr/^Region|^\s*$/i; while (@ARGV+0 && $ARGV[0] =~ /^-/) { my $aa = $ARGV[0]; last if $aa eq '--'; if ($aa eq '--dskip') { $dskip_pattern = $ARGV[1]; shift @ARGV; shift @ARGV; } elsif ($aa eq '-d') { $debug = 1; shift @ARGV; } else { print STDERR "bad arg: $aa\n"; &errx($usage); } } # $dfile = shift or &errx($usage); ## ## read in the waypoints ## open(WFILE, "< $wfile") or &errx("cannot open $wfile: $!"); $format = "simple"; %wp = (); WPLINE: while () { #print STDERR "WPLINE: $_"; chomp; if ($format eq 'simple') { next WPLINE if /^#/; @f = split /\t/; ($name,$aaa,$bbb) = ($f[0],$f[1],$f[2]); print STDERR ":$name:", "\n" if $debug; } $wp{$name} = [ $aaa, $bbb ]; } close(WFILE); sub distance { $a = shift; $b = shift; $d = shift; $e = shift; return sqrt(($a-$d)**2 + ($b-$e)**2); } ## ## filter the tab-separated data ## $do_chomp = 1; DLINE: while (<>) { chomp if $do_chomp; @f = split "\t"; if ( defined($dskip_pattern) && $_ =~ $dskip_pattern ) { #print $_; next DLINE; } $wpname = $f[$name_col]; # project-specific <<< # $wpname =~ s/^#//; $wpname =~ s/\s+//g; $wpname =~ s/-/_/g; $wp = $wp{$wpname}; if (! ref $wp) { errp "unknown waypoint '$wpname' at row $. ****" ; next DLINE; }; $aaa = $$wp[0]; $bbb = $$wp[1]; printf STDERR "line $.: wp=$wpname, distance is %s ", $dist = distance($f[$col1], $f[$col2], $aaa, $bbb); printf STDERR " *****" if $dist > 100; print STDERR "\n"; #print join("\t", @f); #print "\n" if $do_chomp; }