File Coverage

erfasrc/src/erfadatextra.c
Criterion Covered Total %
statement 9 16 56.2
branch 2 8 25.0
condition n/a
subroutine n/a
pod n/a
total 11 24 45.8


line stmt bran cond sub pod time code
1             /*
2             ** Copyright (C) 2019, NumFOCUS Foundation.
3             **
4             ** Licensed under a 3-clause BSD style license - see LICENSE
5             **
6             ** This file is NOT derived from SOFA sources.
7             **
8             ** The eraGetLeapSeconds and eraSetLeapSeconds functions are used as an
9             ** experimental interface for getting and setting the leap second table in
10             ** astropy 4.0. They will be supported as long as astropy 4.0 is supported
11             ** (until 2021), but not necessarily beyond. Comments and ideas about the
12             ** best way to keep the leap second tables up to date for all users of erfa
13             ** are welcome (https://github.com/liberfa/erfa).
14             **
15             ** The eraDatini function is used internally in dat.c; it is strictly an
16             ** implementation detail and should not be used elsewhere.
17             */
18             #include "erfa.h"
19             #include "erfaextra.h"
20              
21             static eraLEAPSECOND *changes;
22             static int NDAT = -1;
23              
24              
25 0           int eraGetLeapSeconds(eraLEAPSECOND **leapseconds)
26             /*
27             ** Get the current leap second table.
28             **
29             ** Returned:
30             ** leapseconds eraLEAPSECOND* Array of year, month, TAI minus UTC
31             **
32             ** Returned (function value):
33             ** int NDAT Number of entries/status
34             ** >0 = number of entries
35             ** -1 = internal error
36             */
37             {
38 0 0         if (NDAT <= 0) {
39             double delat;
40 0           int stat = eraDat(2000, 1, 1, 0., &delat);
41 0 0         if (stat != 0 || NDAT <= 0) {
    0          
42 0           return -1;
43             }
44             }
45 0           *leapseconds = changes;
46 0           return NDAT;
47             }
48              
49 3           void eraSetLeapSeconds(eraLEAPSECOND *leapseconds, int count)
50             /*
51             ** Set the current leap second table.
52             **
53             ** Given:
54             ** leapseconds eraLEAPSECOND* Array of year, month, TAI minus UTC
55             ** count int Number of entries. If <= 0, causes
56             ** a reset of the table to the built-in
57             ** version.
58             **
59             ** Notes:
60             ** *No* sanity checks are performed.
61             */
62             {
63 3           changes = leapseconds;
64 3           NDAT = count;
65 3           }
66              
67 4           int eraDatini(const eraLEAPSECOND *builtin, int n_builtin,
68             eraLEAPSECOND **leapseconds)
69             /*
70             ** Get the leap second table, initializing it to the built-in version
71             ** if necessary.
72             **
73             ** This function is for internal use in dat.c only and should
74             ** not be used elsewhere.
75             **
76             ** Given:
77             ** builtin eraLEAPSECOND Array of year, month, TAI minus UTC
78             ** n_builtin int Number of entries of the table.
79             **
80             ** Returned:
81             ** leapseconds eraLEAPSECOND* Current array, set to the builtin one
82             ** if not yet initialized.
83             **
84             ** Returned (function value):
85             ** int NDAT Number of entries
86             */
87             {
88 4 100         if (NDAT <= 0) {
89 3           eraSetLeapSeconds((eraLEAPSECOND *)builtin, n_builtin);
90             }
91 4           *leapseconds = changes;
92 4           return NDAT;
93             }