$ std -l perl plass
[gpstools.git] / GPSTgeo.pm
blobba68f6de45b310552ef5cde0905a58a3ff41f992
1 package GPSTgeo;
3 #=======================================================================
4 # GPSTgeo.pm
5 # File ID: 6ac1a50e-fafa-11dd-a267-000475e441b9
7 # Character set: UTF-8
8 # ©opyleft 2002– Øyvind A. Holm <sunny@sunbase.org>
9 # License: GNU General Public License, see end of file for legal stuff.
10 #=======================================================================
12 use strict;
13 use warnings;
15 BEGIN {
16 use Exporter ();
17 our (@ISA, @EXPORT, @EXPORT_OK, %EXPORT_TAGS);
19 @ISA = qw(Exporter);
20 @EXPORT = qw(&ddd_to_dms);
21 %EXPORT_TAGS = ();
23 our @EXPORT_OK;
25 sub ddd_to_dms {
26 # Convert floating-point degrees into D°M'S.S" (ISO-8859-1).
27 # Necessary for import into GPSman. Based on toDMS() from
28 # gpstrans-0.39 to ensure compatibility.
29 # {{{
30 my $ddd = shift;
31 my $Neg = 0;
32 my ($Hour, $Min, $Sec) =
33 ( 0, 0, 0);
34 my $Retval = "";
36 ($ddd =~ /^\-?(\d*)(\.\d+)?$/) || return(undef);
37 length($ddd) || ($ddd = 0);
39 if ($ddd < 0.0) {
40 $ddd = 0 - $ddd;
41 $Neg = 1;
43 $Hour = int($ddd);
44 $ddd = ($ddd - $Hour) * 60.0;
45 $Min = int($ddd);
46 $Sec = ($ddd - $Min) * 60.0;
48 if ($Sec > 59.5) {
49 $Sec = 0.0;
50 $Min += 1.0;
52 if ($Min > 59.5) {
53 $Min = 0.0;
54 $Hour += 1.0;
56 $Retval = sprintf("%s%.0f\xB0%02.0f'%04.1f\"",
57 $Neg
58 ? "-"
59 : "",
60 $Hour, $Min, $Sec);
61 return $Retval;
62 # }}}
63 } # ddd_to_dms()