--- cup.perl 2013/12/26 19:59:00 1.3 +++ cup.perl 2023/12/26 01:23:11 1.5 @@ -1,18 +1,14 @@ #! /usr/bin/perl -w -# $Id: cup.perl,v 1.3 2013/12/26 19:59:00 philip Exp $ +# $Id: cup.perl,v 1.5 2023/12/26 01:23:11 philip Exp $ use XML::Simple; use strict; +use Data::Dumper; -my $strips; - -my $xml = "OmLand.xml"; -if ( defined $xml ){ - $strips = XMLin($xml, KeyAttr => {strip => 'id'}); -} +my $strips = XMLin('OmLand.gpx'); open CUP, "> OmLand.cup" or die "Couldn't open OmLand.cup: $!\n"; -print CUP "name,code,country,lat,lon,elev,style,rwdir,rwlen,freq,desc,userdata,pics\n"; +#name,code,country,lat,lon,elev,style,rwdir,rwlen,freq,desc,userdata,pics #"Ahuriri",0002,NZ,4414.000S,16936.000E,756.0m,1,,,,"Mouth of Canyon Creek",, # Style is @@ -36,17 +32,76 @@ print CUP "name,code,country,lat,lon,ele my %strips; -foreach my $stripnum ( keys %{$strips->{strip}} ){ - print CUP qq["$strips->{strip}->{$stripnum}->{name}",]; - print CUP qq["$stripnum",NZ,]; - $strips->{strip}->{$stripnum}->{lat} =~ s/://; - print CUP $strips->{strip}->{$stripnum}->{lat} . ","; - $strips->{strip}->{$stripnum}->{lng} =~ s/://; - print CUP $strips->{strip}->{$stripnum}->{lng} . ","; - print CUP $strips->{strip}->{$stripnum}->{elev} . "f,3,,,,"; - if ( defined $strips->{strip}->{$stripnum}->{location} ) { - print CUP qq{"$strips->{strip}->{$stripnum}->{location}"}; +foreach my $stripnum ( sort keys %{$strips->{'wpt'}} ){ + if ( ! defined $strips->{'wpt'}->{$stripnum}->{'extensions'}->{'aip'} ) { + print CUP cupstr($stripnum); } - print CUP ",,\r\n"; } close CUP; + +exit; + +sub cupstr { + my $stripnum = shift(@_); + my $location = ""; + my $rwlen = ""; + my $rwdir = ""; + my $freq = ""; + if ( defined $strips->{'wpt'}->{$stripnum}->{'extensions'}->{'location'} ) { + $location = $strips->{'wpt'}->{$stripnum}->{'extensions'}->{'location'}; + } + if ( defined $strips->{'wpt'}->{$stripnum}->{'extensions'}->{'rwlen'} ) { + $rwlen = $strips->{'wpt'}->{$stripnum}->{'extensions'}->{'rwlen'}; + } + if ( defined $strips->{'wpt'}->{$stripnum}->{'extensions'}->{'rwdir'} ) { + $rwdir = $strips->{'wpt'}->{$stripnum}->{'extensions'}->{'rwdir'}; + } + if ( defined $strips->{'wpt'}->{$stripnum}->{'extensions'}->{'freq'} ) { + $freq = qq{"$strips->{'wpt'}->{$stripnum}->{'extensions'}->{'freq'}"}; + } + return sprintf( qq{"%s","L%s",NZ,%s,%s,%0.1fm,3,%s,%s,%s,"%s",,\r\n}, + $strips->{'wpt'}->{$stripnum}->{'desc'}, + $stripnum, + printlat($strips->{'wpt'}->{$stripnum}->{'lat'}), + printlon($strips->{'wpt'}->{$stripnum}->{'lon'}), + $strips->{'wpt'}->{$stripnum}->{'ele'}, + $rwlen, + $rwdir, + $freq, + $location); +} +sub printlat { + my $latitude = shift(@_); + my $minutes = 0; + my $degrees = 0; + my $northing = ""; + + if ($latitude < 0) { + $northing = "S"; + $latitude = 0 - $latitude; + } + else{ + $northing = "N"; + } + $degrees = int($latitude); + $minutes = ($latitude - $degrees) * 60; + return sprintf("%d%06.3f%s",$degrees,$minutes,$northing); +} + +sub printlon { + my $longitude = shift(@_); + my $minutes = 0; + my $degrees = 0; + my $westing = ""; + if ($longitude < 0) { + $westing = "W"; + $longitude = 0 - $longitude; + } + else{ + $westing = "E"; + } + $degrees = int($longitude); + $minutes = ($longitude - $degrees) * 60; + return sprintf("%d%06.3f%s",$degrees,$minutes,$westing); +} +