Skip to content

Commit

Permalink
Merge pull request #58 from mhvk/leap-second-access
Browse files Browse the repository at this point in the history
Leap second access following pattern from Astropy
  • Loading branch information
eteq authored Dec 5, 2019
2 parents 0bbed26 + a1a2de9 commit 631dc43
Show file tree
Hide file tree
Showing 8 changed files with 374 additions and 43 deletions.
9 changes: 5 additions & 4 deletions src/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ tcgtt.c tdbtcb.c tdbtt.c tf2a.c tf2d.c tpors.c tporv.c tpsts.c \
tpstv.c tpxes.c tpxev.c tr.c trxp.c trxpv.c tttai.c \
tttcg.c tttdb.c ttut1.c ut1tai.c ut1tt.c ut1utc.c utctai.c utcut1.c \
xy06.c xys00a.c xys00b.c xys06a.c zp.c zpv.c zr.c \
erfaversion.c
erfaversion.c erfadatextra.c

include_HEADERS = erfa.h erfam.h erfaextra.h
include_HEADERS = erfa.h erfam.h erfaextra.h erfadatextra.h

## Version info is in current : revision : age form
## A library supports interfaces from current downto current - age
Expand All @@ -44,8 +44,9 @@ liberfa_la_LDFLAGS = -version-info $(VI_ALL)


## Check program
TESTS = t_erfa_c
check_PROGRAMS = t_erfa_c
TESTS = t_erfa_c t_erfa_c_extra
check_PROGRAMS = t_erfa_c t_erfa_c_extra
t_erfa_c_SOURCES = t_erfa_c.c
t_erfa_c_extra_SOURCES = t_erfa_c_extra.c
AM_CPPFLAGS = -I$(top_srcdir)
LDADD = $(top_builddir)/src/liberfa.la
42 changes: 23 additions & 19 deletions src/dat.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "erfa.h"
#include "erfadatextra.h"

int eraDat(int iy, int im, int id, double fd, double *deltat)
/*
Expand Down Expand Up @@ -144,10 +145,7 @@ int eraDat(int iy, int im, int id, double fd, double *deltat)
enum { NERA1 = (int) (sizeof drift / sizeof (double) / 2) };

/* Dates and Delta(AT)s */
static const struct {
int iyear, month;
double delat;
} changes[] = {
static const eraLEAPSECOND _changes[] = {
{ 1960, 1, 1.4178180 },
{ 1961, 1, 1.4228180 },
{ 1961, 8, 1.3728180 },
Expand Down Expand Up @@ -193,7 +191,13 @@ int eraDat(int iy, int im, int id, double fd, double *deltat)
};

/* Number of Delta(AT) changes */
enum { NDAT = (int) (sizeof changes / sizeof changes[0]) };
enum { _NDAT = (int) (sizeof _changes / sizeof _changes[0]) };

/* Get/initialise leap-second if needed */
int NDAT;
eraLEAPSECOND *changes;

NDAT = eraDatini(_changes, _NDAT, &changes);

/* Miscellaneous local variables */
int j, i, m;
Expand Down Expand Up @@ -243,15 +247,15 @@ int eraDat(int iy, int im, int id, double fd, double *deltat)

}
/*----------------------------------------------------------------------
**
**
**
**
** Copyright (C) 2013-2019, NumFOCUS Foundation.
** All rights reserved.
**
**
** This library is derived, with permission, from the International
** Astronomical Union's "Standards of Fundamental Astronomy" library,
** available from http://www.iausofa.org.
**
**
** The ERFA version is intended to retain identical functionality to
** the SOFA library, but made distinct through different function and
** file names, as set out in the SOFA license conditions. The SOFA
Expand All @@ -260,36 +264,36 @@ int eraDat(int iy, int im, int id, double fd, double *deltat)
** state. The ERFA version is not subject to this restriction and
** therefore can be included in distributions which do not support the
** concept of "read only" software.
**
**
** Although the intent is to replicate the SOFA API (other than
** replacement of prefix names) and results (with the exception of
** bugs; any that are discovered will be fixed), SOFA is not
** responsible for any errors found in this version of the library.
**
**
** If you wish to acknowledge the SOFA heritage, please acknowledge
** that you are using a library derived from SOFA, rather than SOFA
** itself.
**
**
**
**
** TERMS AND CONDITIONS
**
**
** Redistribution and use in source and binary forms, with or without
** modification, are permitted provided that the following conditions
** are met:
**
**
** 1 Redistributions of source code must retain the above copyright
** notice, this list of conditions and the following disclaimer.
**
**
** 2 Redistributions in binary form must reproduce the above copyright
** notice, this list of conditions and the following disclaimer in
** the documentation and/or other materials provided with the
** distribution.
**
**
** 3 Neither the name of the Standards Of Fundamental Astronomy Board,
** the International Astronomical Union nor the names of its
** contributors may be used to endorse or promote products derived
** from this software without specific prior written permission.
**
**
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
Expand All @@ -302,5 +306,5 @@ int eraDat(int iy, int im, int id, double fd, double *deltat)
** LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
** ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
** POSSIBILITY OF SUCH DAMAGE.
**
**
*/
93 changes: 93 additions & 0 deletions src/erfadatextra.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
/*
** Copyright (C) 2019, NumFOCUS Foundation.
**
** Licensed under a 3-clause BSD style license - see LICENSE
**
** This file is NOT derived from SOFA sources.
**
** The eraGetLeapSeconds and eraSetLeapSeconds functions are used as an
** experimental interface for getting and setting the leap second table in
** astropy 4.0. They will be supported as long as astropy 4.0 is supported
** (until 2021), but not necessarily beyond. Comments and ideas about the
** best way to keep the leap second tables up to date for all users of erfa
** are welcome (https://github.com/liberfa/erfa).
**
** The eraDatini function is used internally in dat.c; it is strictly an
** implementation detail and should not be used elsewhere.
*/
#include "erfa.h"
#include "erfaextra.h"

static eraLEAPSECOND *changes;
static int NDAT = -1;


int eraGetLeapSeconds(eraLEAPSECOND **leapseconds)
/*
** Get the current leap second table.
**
** Returned:
** leapseconds eraLEAPSECOND* Array of year, month, TAI minus UTC
**
** Returned (function value):
** int NDAT Number of entries/status
** >0 = number of entries
** -1 = internal error
*/
{
if (NDAT <= 0) {
double delat;
int stat = eraDat(2000, 1, 1, 0., &delat);
if (stat != 0 || NDAT <= 0) {
return -1;
}
}
*leapseconds = changes;
return NDAT;
}

void eraSetLeapSeconds(eraLEAPSECOND *leapseconds, int count)
/*
** Set the current leap second table.
**
** Given:
** leapseconds eraLEAPSECOND* Array of year, month, TAI minus UTC
** count int Number of entries. If <= 0, causes
** a reset of the table to the built-in
** version.
**
** Notes:
** *No* sanity checks are performed.
*/
{
changes = leapseconds;
NDAT = count;
}

int eraDatini(const eraLEAPSECOND *builtin, int n_builtin,
eraLEAPSECOND **leapseconds)
/*
** Get the leap second table, initializing it to the built-in version
** if necessary.
**
** This function is for internal use in dat.c only and should
** not be used elsewhere.
**
** Given:
** builtin eraLEAPSECOND Array of year, month, TAI minus UTC
** n_builtin int Number of entries of the table.
**
** Returned:
** leapseconds eraLEAPSECOND* Current array, set to the builtin one
** if not yet initialized.
**
** Returned (function value):
** int NDAT Number of entries
*/
{
if (NDAT <= 0) {
eraSetLeapSeconds((eraLEAPSECOND *)builtin, n_builtin);
}
*leapseconds = changes;
return NDAT;
}
18 changes: 18 additions & 0 deletions src/erfadatextra.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/*
** Copyright (C) 2019, NumFOCUS Foundation.
**
** Licensed under a 3-clause BSD style license - see LICENSE
**
** This file is NOT derived from SOFA sources.
**
*/

/*
** Get the leap second table, initializing it to the built-in version
** if necessary.
**
** This function is for internal use in dat.c only and should
** not be used elsewhere.
*/
int eraDatini(const eraLEAPSECOND *builtin, int n_builtin,
eraLEAPSECOND **leapseconds);
42 changes: 29 additions & 13 deletions src/erfaextra.h
Original file line number Diff line number Diff line change
@@ -1,9 +1,20 @@
/*
** Copyright (C) 2016-2017, NumFOCUS Foundation.
** Copyright (C) 2016-2019, NumFOCUS Foundation.
**
** Licensed under a 3-clause BSD style license - see LICENSE
**
** This file is NOT derived from SOFA sources
** This file is NOT derived from SOFA sources.
**
** The functions here provide an interface to ERFA and SOFA version
** information, and for updating the leap second table.
**
** The eraGetLeapSeconds and eraSetLeapSeconds functions are used as an
** experimental interface for getting and setting the leap second table in
** astropy 4.0. They will be supported as long as astropy 4.0 is supported
** (until 2021), but not necessarily beyond. Comments and ideas about the
** best way to keep the leap second tables up to date for all users of erfa
** are welcome (https://github.com/liberfa/erfa).
**
*/


Expand All @@ -15,45 +26,50 @@ extern "C" {
#endif


/*
/*
** Returns the package version
** as defined in configure.ac
** in string format
*/
const char* eraVersion();
const char* eraVersion(void);

/*
/*
** Returns the package major version
** as defined in configure.ac
** as integer
*/
int eraVersionMajor();
int eraVersionMajor(void);

/*
/*
** Returns the package minor version
** as defined in configure.ac
** as integer
*/
int eraVersionMinor();
int eraVersionMinor(void);

/*
/*
** Returns the package micro version
** as defined in configure.ac
** as integer
*/
int eraVersionMicro();
int eraVersionMicro(void);

/*
/*
** Returns the orresponding SOFA version
** as defined in configure.ac
** in string format
*/
const char* eraSofaVersion();
const char* eraSofaVersion(void);


/*
** Get and set leap seconds (not supported by SOFA; EXPERIMENTAL)
*/
int eraGetLeapSeconds(eraLEAPSECOND **leapseconds);
void eraSetLeapSeconds(eraLEAPSECOND *leapseconds, int count);

#ifdef __cplusplus
}
#endif

#endif /* _ERFA_EXTRA_H */

6 changes: 6 additions & 0 deletions src/erfam.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,12 @@ typedef struct {
double pv[2][3]; /* barycentric PV of the body (au, au/day) */
} eraLDBODY;

/* Leap second definition */
typedef struct {
int iyear, month;
double delat;
} eraLEAPSECOND;

/* Pi */
#define ERFA_DPI (3.141592653589793238462643)

Expand Down
27 changes: 20 additions & 7 deletions src/erfaversion.c
Original file line number Diff line number Diff line change
@@ -1,38 +1,51 @@
/*
** Copyright (C) 2016-2017, NumFOCUS Foundation.
**
** Licensed under a 3-clause BSD style license - see LICENSE
** Licensed under a 3-clause BSD style license - see LICENSE
**
** This file is NOT derived from SOFA sources
*/

/* Define to the version of this package. */
#define PACKAGE_VERSION "1.6.0"

/* Define to the major version of this package. */
#define PACKAGE_VERSION_MAJOR 1

/* Define to the micro version of this package. */
#define PACKAGE_VERSION_MICRO 0

/* Define to the minor version of this package. */
#define PACKAGE_VERSION_MINOR 6

/* Define to the version of SOFA */
#define SOFA_VERSION "20190722"

#ifdef HAVE_CONFIG_H
#include <config.h>
#endif /* HAVE_CONFIG_H */


const char* eraVersion() {
const char* eraVersion(void) {
return PACKAGE_VERSION;
}


int eraVersionMajor() {
int eraVersionMajor(void) {
return PACKAGE_VERSION_MAJOR;
}


int eraVersionMinor() {
int eraVersionMinor(void) {
return PACKAGE_VERSION_MINOR;
}


int eraVersionMicro() {
int eraVersionMicro(void) {
return PACKAGE_VERSION_MICRO;
}


const char* eraSofaVersion() {
const char* eraSofaVersion(void) {
return SOFA_VERSION;
}

Loading

0 comments on commit 631dc43

Please sign in to comment.