# cty2geo.pl - converting WL_CTY.DAT to CTY.GEO coordinate file for VOACAP # # Copyright OH6BG 30 July 2006 # Note! Made for use in Windows environment. *nix users may hack this to their needs. # # Use at your own risk! system("cls"); print "Convert WL_CTY.DAT to CTY.GEO (c) 2006 OH6BG, oh6bg\@sral.fi.\n"; print "-" x 80; print "\nAvailable CTY files (*.dat):\n"; system("dir *.dat"); do { print "\nFile: "; chomp($foo = ); $infile = $foo; } while ($foo eq "" || $foo =~ /\s+/); $outfile = "cty.geo"; open(OUT, ">$outfile") || die "cannot open the file: $!"; open(IN, $infile) || die "cannot open the file: $!"; print OUT "The country list CTY.GEO from WL_CTY.DAT by AD1C.\n"; print OUT "|======CALL AND COUNTRY=================| LATITUDE|LONGITUDE|\n"; # massage CTY lines while () { # ignore some lines next if (/^\s+$/); next if (/^[ #]/); @line = split/:/; # [0] country $country = $line[0]; # [4] latitude, [5] longitude $ladeg = $line[4]; $lodeg = $line[5]; ($ladegrees, $laminutes) = decimal2dm($ladeg); ($lodegrees, $lominutes) = decimal2dm($lodeg); $laminutes = int($laminutes + .5); $lominutes = int($lominutes + .5); if ($laminutes < 10) { $laminutes = "0" . $laminutes; } if ($lominutes < 10) { $lominutes = "0" . $lominutes; } if ($ladeg < 0) { $lat = abs($ladegrees) . " " . $laminutes . " S"; } else { $lat = $ladegrees . " " . $laminutes . " N"; } if ($lodeg < 0) { $lon = abs($lodegrees) . " " . $lominutes . " E"; } else { $lon = $lodegrees . " " . $lominutes . " W"; } # [7] prefix $prefix = substr($line[7],2,6); # rearrange and print printf OUT "%-6s %-22s %20s %9s\n", $prefix, $country, $lat, $lon; } close IN; close OUT; print "\nConversion of " . uc($infile) . " to CTY.GEO completed.\n"; sub decimal2dm { my ($decimal) = @_; my $degrees = int($decimal); my $minutes = abs($decimal - $degrees) * 60; return ($degrees, $minutes); } # THE END.