File Coverage

blib/lib/Time/GPS.pm
Criterion Covered Total %
statement 25 30 83.3
branch 0 2 0.0
condition n/a
subroutine 9 10 90.0
pod 3 3 100.0
total 37 45 82.2


line stmt bran cond sub pod time code
1             =head1 NAME
2              
3             Time::GPS - Global Positioning System time
4              
5             =head1 SYNOPSIS
6              
7             use Time::GPS qw(gps_instant_to_mjd gps_mjd_to_instant);
8              
9             $mjd = gps_instant_to_mjd($instant);
10             $instant = gps_mjd_to_instant($mjd);
11              
12             use Time::GPS qw(gps_realisation);
13              
14             $rln = gps_realisation("");
15             $instant = $rln->to_tai($gps_instant);
16              
17             =head1 DESCRIPTION
18              
19             The Global Positioning System (GPS) includes as an integral feature the
20             dissemination of a very precise time scale. This time scale is produced
21             by atomic clocks on the satellites, and is steered to keep in step with
22             International Atomic Time (TAI). The GPS time scale is thus indirectly
23             a realisation of Terrestrial Time (TT). GPS time is one of the most
24             accurate and the most accessible realisations of TAI.
25              
26             This module represents instants on the TAI time scale as a scalar
27             number of TAI seconds since an epoch. This is an appropriate form
28             for all manner of calculations. The epoch used is that of TAI, at
29             UT2 instant 1958-01-01T00:00:00.0 as calculated by the United States
30             Naval Observatory, even though GPS did not exist then. This matches
31             the convention used by C for instants on the TAI scale and
32             by C for instants on the TT scale.
33              
34             There is also a conventional way to represent GPS time instants using
35             day-based notations associated with planetary rotation `time' scales.
36             The `day' of GPS is a nominal period of exactly 86400 GPS seconds,
37             which is slightly shorter than an actual Terran day. The start of
38             the GPS time scale, at UTC instant 1980-01-06T00:00:00.0 (TAI instant
39             1980-01-06T00:00:19.0) is assigned the label 1980-01-06T00:00:00.0
40             (MJD 44244.0). Because GPS time is not connected to Terran rotation,
41             and so has no inherent concept of a day, it is somewhat misleading to
42             use such day-based notations. Conversion between this notation and the
43             linear count of seconds is supported by this module. This notation does
44             not match the similar day-based notations used for TAI and TT.
45              
46             =cut
47              
48             package Time::GPS;
49              
50 1     1   21148 { use 5.006; }
  1         3  
  1         41  
51 1     1   6 use warnings;
  1         2  
  1         42  
52 1     1   21 use strict;
  1         6  
  1         42  
53              
54 1     1   5 use Carp qw(croak);
  1         1  
  1         78  
55 1     1   985 use Math::BigRat 0.03;
  1         83893  
  1         7  
56              
57             our $VERSION = "0.003";
58              
59 1     1   2104 use parent "Exporter";
  1         296  
  1         4  
60             our @EXPORT_OK = qw(gps_instant_to_mjd gps_mjd_to_instant gps_realisation);
61              
62             =head1 FUNCTIONS
63              
64             =over
65              
66             =item gps_instant_to_mjd(INSTANT)
67              
68             Converts from a count of seconds to a Modified Julian Date in the
69             manner conventional for GPS time. The MJD can be further converted to
70             other forms of day-based date using other modules. The input must be
71             a C object, and the result is the same type.
72              
73             =cut
74              
75 1     1   100 use constant GPS_EPOCH_MJD => Math::BigRat->new((36204*86400-19)."/86400");
  1         2  
  1         9  
76              
77             sub gps_instant_to_mjd($) {
78 4     4 1 5015 my($gps) = @_;
79 4         16 return GPS_EPOCH_MJD + ($gps / 86400);
80             }
81              
82             =item gps_mjd_to_instant(MJD)
83              
84             Converts from a Modified Julian Date, interpreted in the manner
85             conventional for GPS time, to a count of seconds. The input must be a
86             C object, and the result is the same type.
87              
88             =cut
89              
90             sub gps_mjd_to_instant($) {
91 4     4 1 4432 my($mjd) = @_;
92 4         13 return ($mjd - GPS_EPOCH_MJD) * 86400;
93             }
94              
95             =item gps_realisation(NAME)
96              
97             Looks up and returns an object representing a named realisation of
98             GPS time. The object returned is of the class C;
99             see the documentation of that class for its interface.
100              
101             Presently the only name recognised is the empty string, representing
102             GPS time itself. Other names may be recognised in the future.
103              
104             The C module is required in order to do this.
105              
106             =cut
107              
108             sub gps_realisation($) {
109 0     0 1   my($k) = @_;
110 0 0         if($k eq "") {
111 0           require Time::TAI;
112 0           return Time::TAI::tai_realisation("gps");
113             } else {
114 0           croak "no realisation TT(TAI(GPS(".uc($k)."))) known";
115             }
116             }
117              
118             =back
119              
120             =head1 SEE ALSO
121              
122             L,
123             L,
124             L,
125             L
126              
127             =head1 AUTHOR
128              
129             Andrew Main (Zefram)
130              
131             =head1 COPYRIGHT
132              
133             Copyright (C) 2006, 2009, 2010, 2012
134             Andrew Main (Zefram)
135              
136             =head1 LICENSE
137              
138             This module is free software; you can redistribute it and/or modify it
139             under the same terms as Perl itself.
140              
141             =cut
142              
143             1;