File Coverage

lib/Astro/Montenbruck/Time/DeltaT.pm
Criterion Covered Total %
statement 35 36 97.2
branch 7 10 70.0
condition 6 6 100.0
subroutine 8 8 100.0
pod 1 1 100.0
total 57 61 93.4


line stmt bran cond sub pod time code
1             package Astro::Montenbruck::Time::DeltaT;
2              
3 1     1   137810 use strict;
  1         5  
  1         25  
4 1     1   4 use warnings;
  1         1  
  1         23  
5              
6 1     1   4 use Exporter qw/import/;
  1         2  
  1         20  
7 1     1   400 use Readonly;
  1         3138  
  1         47  
8              
9 1     1   352 use Astro::Montenbruck::Time qw/cal2jd jd2cal/;
  1         2  
  1         59  
10 1     1   6 use Astro::Montenbruck::MathUtils qw/polynome/;
  1         2  
  1         511  
11              
12             our @EXPORT_OK = qw/delta_t/;
13             our $VERSION = 0.01;
14              
15             Readonly::Hash our %HISTORICAL => (
16             # From J.Meeus, Astronomical Algorithms, 2 edition
17             1620 => 121.0,
18             1622 => 112.0,
19             1624 => 103.0,
20             1626 => 95.0,
21             1628 => 88.0,
22             1630 => 82.0,
23             1632 => 77.0,
24             1634 => 72.0,
25             1636 => 68.0,
26             1638 => 63.0,
27             1640 => 60.0,
28             1642 => 56.0,
29             1644 => 53.0,
30             1646 => 51.0,
31             1648 => 48.0,
32             1650 => 46.0,
33             1652 => 44.0,
34             1654 => 42.0,
35             1656 => 40.0,
36             1658 => 38.0,
37             1660 => 35.0,
38             1662 => 33.0,
39             1664 => 31.0,
40             1666 => 29.0,
41             1668 => 26.0,
42             1670 => 24.0,
43             1672 => 22.0,
44             1674 => 20.0,
45             1676 => 19.0,
46             1678 => 16.0,
47             1680 => 14.0,
48             1682 => 12.0,
49             1684 => 11.0,
50             1686 => 10.0,
51             1688 => 9.0,
52             1690 => 8.0,
53             1692 => 7.0,
54             1694 => 7.0,
55             1696 => 7.0,
56             1698 => 7.0,
57             1700 => 7.0,
58             1702 => 7.0,
59             1704 => 8.0,
60             1706 => 8.0,
61             1708 => 9.0,
62             1710 => 9.0,
63             1712 => 9.0,
64             1714 => 9.0,
65             1716 => 9.0,
66             1718 => 10.0,
67             1720 => 10.0,
68             1722 => 10.0,
69             1724 => 10.0,
70             1726 => 10.0,
71             1728 => 10.0,
72             1730 => 10.0,
73             1732 => 10.0,
74             1734 => 11.0,
75             1736 => 11.0,
76             1738 => 11.0,
77             1740 => 11.0,
78             1742 => 11.0,
79             1744 => 12.0,
80             1746 => 12.0,
81             1748 => 12.0,
82             1750 => 12.0,
83             1752 => 13.0,
84             1754 => 13.0,
85             1756 => 13.0,
86             1758 => 14.0,
87             1760 => 14.0,
88             1762 => 14.0,
89             1764 => 14.0,
90             1766 => 15.0,
91             1768 => 15.0,
92             1770 => 15.0,
93             1772 => 15.0,
94             1774 => 15.0,
95             1776 => 16.0,
96             1778 => 16.0,
97             1780 => 16.0,
98             1782 => 16.0,
99             1784 => 16.0,
100             1786 => 16.0,
101             1788 => 16.0,
102             1790 => 16.0,
103             1792 => 15.0,
104             1794 => 15.0,
105             1796 => 14.0,
106             1798 => 13.0,
107             1800 => 13.1,
108             1802 => 12.5,
109             1804 => 12.2,
110             1806 => 12.0,
111             1808 => 12.0,
112             1810 => 12.0,
113             1812 => 12.0,
114             1814 => 12.0,
115             1816 => 12.0,
116             1818 => 11.9,
117             1820 => 11.6,
118             1822 => 11.0,
119             1824 => 10.2,
120             1826 => 9.2,
121             1828 => 8.2,
122             1830 => 7.1,
123             1832 => 6.2,
124             1834 => 5.6,
125             1836 => 5.4,
126             1838 => 5.3,
127             1840 => 5.4,
128             1842 => 5.6,
129             1844 => 5.9,
130             1846 => 6.2,
131             1848 => 6.5,
132             1850 => 6.8,
133             1852 => 7.1,
134             1854 => 7.3,
135             1856 => 7.5,
136             1858 => 7.6,
137             1860 => 7.7,
138             1862 => 7.3,
139             1864 => 6.2,
140             1866 => 5.2,
141             1868 => 2.7,
142             1870 => 1.4,
143             1872 => -1.2,
144             1874 => -2.8,
145             1876 => -3.8,
146             1878 => -4.8,
147             1880 => -5.5,
148             1882 => -5.3,
149             1884 => -5.6,
150             1886 => -5.7,
151             1888 => -5.9,
152             1890 => -6.0,
153             1892 => -6.3,
154             1894 => -6.5,
155             1896 => -6.2,
156             1898 => -4.7,
157             1900 => -2.8,
158             1902 => -0.1,
159             1904 => 2.6,
160             1906 => 5.3,
161             1908 => 7.7,
162             1910 => 10.4,
163             1912 => 13.3,
164             1914 => 16.0,
165             1916 => 18.2,
166             1918 => 20.2,
167             1920 => 21.1,
168             1922 => 22.4,
169             1924 => 23.5,
170             1926 => 23.8,
171             1928 => 24.3,
172             1930 => 24.0,
173             1932 => 23.9,
174             1934 => 23.9,
175             1936 => 23.7,
176             1938 => 24.0,
177             1940 => 24.3,
178             1942 => 25.3,
179             1944 => 26.2,
180             1946 => 27.3,
181             1948 => 28.2,
182             1950 => 29.1,
183             1952 => 30.0,
184             1954 => 30.7,
185             1956 => 31.4,
186             1958 => 32.2,
187             1960 => 33.1,
188             1962 => 34.0,
189             1964 => 35.0,
190             1966 => 36.5,
191             1968 => 38.3,
192             1970 => 40.2,
193             1972 => 42.2,
194             1974 => 44.5,
195             1976 => 46.5,
196             1978 => 48.5,
197             1980 => 50.5,
198             1982 => 52.2,
199             1984 => 53.8,
200             1986 => 54.9,
201             1988 => 55.8,
202             1990 => 56.9,
203             1992 => 58.3,
204             1994 => 60.0,
205             1996 => 61.6,
206             1998 => 63.0,
207              
208             # From http://www.staff.science.uu.nl/~gent0113/deltat/deltat_modern.htm
209             2000 => 63.8,
210             2002 => 63.3,
211             2004 => 64.6,
212             2006 => 64.9,
213             2008 => 65.5,
214             2010 => 66.1,
215             2012 => 68.0,
216             2014 => 69.0,
217             2016 => 70.0
218             );
219              
220             Readonly our $TAB_SINCE => 1620;
221             Readonly our $TAB_UNTIL => 2016;
222              
223             sub _interpolate {
224 1     1   19 my ( $jd, $ye ) = @_;
225              
226             # For a historical range from 1620 to a recent year, we interpolate from a
227             # table of observed values. Outside that range we use formulae.
228              
229             # Last value in the table
230 1 50       3 if ( $ye == $TAB_UNTIL ) {
231 0         0 return $HISTORICAL{$TAB_UNTIL};
232             }
233              
234             # 1620 - 20xx
235 1 50       10 my $y0 =
236             $ye % 2 == 0 ? $ye : $ye - 1; # there are only even numbers in the table
237 1         2 my $y1 = $y0 + 2;
238 1         6 my $d0 = $HISTORICAL{$y0};
239 1         11 my $d1 = $HISTORICAL{$y1};
240 1         8 my $j0 = cal2jd( $y0, 1, 1 );
241 1         6 my $j1 = cal2jd( $y1, 1, 1 );
242              
243             # simple linear interpolation between two values
244 1         5 ( ( $jd - $j0 ) * ( $d1 - $d0 ) / ( $j1 - $j0 ) ) + $d0;
245             }
246              
247             sub delta_t {
248 4     4 1 1111 my $jd = shift;
249              
250 4         14 my ($ye) = jd2cal($jd);
251              
252 4 100 100     15 return _interpolate($jd, $ye) if $ye >= $TAB_SINCE && $ye <= $TAB_UNTIL;
253 3         25 my $t = ($ye - 2000) / 100.0;
254 3 50       7 return polynome( $t, 2177.0, 497.0, 44.1 ) if $ye < 948;
255              
256 3         9 my $dt = polynome( $t, 102.0, 102.0, 25.3 );
257 3 100 100     17 $dt += 0.37 * ( $ye - 2100 ) if $ye > $TAB_UNTIL && $ye < 2100;
258 3         21 $dt
259             }
260              
261             1;
262              
263             __END__
264              
265             =pod
266              
267             =encoding UTF-8
268              
269             =head1 NAME
270              
271             Astro::Montenbruck::Time::DeltaT - difference between I<UT> and I<TDT>.
272              
273             =head1 VERSION
274              
275             Version 0.01
276              
277              
278             =head1 DESCRIPTION
279              
280             B<Delta-T> indicates the difference between I<UT> and I<TDT>
281             (I<Terrestrial Dynamic Time>), which used to be called I<Ephemeris time> in the
282             last century. While I<UT> is not a uniform time scale (it is occasionally
283             adjusted, due to irregularities in the Earth's rotation), I<TDT> is a uniform
284             time scale which is needed as an argument for mathematical theories of celestial
285             movements.
286              
287             Formulae used by L</delta_t( $jd )> subroutine, are based on NASA Technical
288             Publication I<"Five Millennium Canon of Solar Eclipses: -1999 to +3000">.
289             They are valid for any time during the interval 2000 B.C. to 3000 A.D. See
290             L<NASA Eclipse web site|http://eclipse.gsfc.nasa.gov/SEcat5/deltatpoly.html">.
291              
292             =head1 EXPORT
293              
294             =over
295              
296             =item * L</delta_t( $jd )>
297              
298             =back
299              
300             =head1 SUBROUTINES
301              
302             =head2 delta_t( $jd )
303              
304             Returns approximate Delta-T in seconds for a given Julian Day.
305             C<Delta-T = ET - UT>
306              
307             For a historical range from 1620 to recent years, we interpolate from a
308             table of observed values. Outside that range we use formulae from
309             I<Astronomical Algorithms> by I<J.Meeus>, second edition.
310              
311             =head3 Arguments
312              
313             =over
314              
315             =item * B<$jd> — Standard Julian Date.
316              
317             =back
318              
319             =head3 Returns
320              
321             Delta-T in seconds
322              
323             =cut