From 9cc921633e1aed58c90b3dd8c8039e8d5103c202 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Est=C3=A9vez?= Date: Sun, 19 Nov 2017 13:06:46 +0100 Subject: [PATCH] pos2nmea: handle properly positions W and S This fixes a bug where positions west of Greenwich or south of the equator are not converted correctly to the format used in NMEA. --- rs92/pos2nmea.pl | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/rs92/pos2nmea.pl b/rs92/pos2nmea.pl index 007e381..0e2ee37 100755 --- a/rs92/pos2nmea.pl +++ b/rs92/pos2nmea.pl @@ -34,6 +34,7 @@ my $line; my $hms; my $lat; my $lon; my $alt; +my $sign; my $NS; my $EW; my $cs; my $str; @@ -59,12 +60,12 @@ while ($line = <$fpi>) { #print STDERR $line; ## oder: nur Zeile mit Koordinaten ausgeben $hms = $1*10000+$2*100+$3; - $lat = $4*100+$5*60; - if ($4 < 0) { $NS="S"; $lat *= -1; } - else { $NS="N"; } - $lon = $6*100+$7*60; - if ($6 < 0) { $EW="W"; $lon *= -1; } - else { $EW="E"; } + if ($4 < 0) { $NS="S"; $sign *= -1; } + else { $NS="N"; $sign = 1} + $lat = $sign*$4*100+$5*60; + if ($6 < 0) { $EW="W"; $sign = -1; } + else { $EW="E"; $sign = 1; } + $lon = $sign*$6*100+$7*60; $alt = $8; if ($line =~ /(\d\d\d\d)-(\d\d)-(\d\d).*/) {