Skip to content

Commit

Permalink
Switch to ERFA
Browse files Browse the repository at this point in the history
Routines are now written to use ERFA natively but can be switched
to SOFA using a C define. The configure script will check for
both ERFA and SOFA.
  • Loading branch information
timj committed Jul 29, 2014
1 parent 490663f commit 2cbbdd5
Show file tree
Hide file tree
Showing 53 changed files with 464 additions and 306 deletions.
8 changes: 4 additions & 4 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ lib_LTLIBRARIES = libpal.la
libpal_la_SOURCES = $(PUBLIC_C_FILES) palOne2One.c $(PRIVATE_C_FILES)

# If we are using a non-standard location
libpal_la_CPPFLAGS = $(SOFA_CPPFLAGS)
libpal_la_LDFLAGS = $(SOFA_LDFLAGS)
libpal_la_CPPFLAGS = $(ERFA_CPPFLAGS)
libpal_la_LDFLAGS = $(ERFA_LDFLAGS)

# Force a link against SOFA and, optionally, starutil
libpal_la_LIBADD = $(SOFA_LIBADD) $(STARUTIL_LIBADD)
# Force a link against ERFA and, optionally, starutil
libpal_la_LIBADD = $(ERFA_LIBADD) $(STARUTIL_LIBADD)

# Misc files
dist_starnews_DATA = pal.news
Expand Down
15 changes: 10 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ PAL - Positional Astronomy Library

The PAL library is a partial re-implementation of Pat Wallace's popular SLALIB
library written in C using a Gnu GPL license and layered on top of the IAU's
SOFA library where appropriate. PAL attempts to stick to the SLA C API where
SOFA library (or the BSD-licensed ERFA) where appropriate.
PAL attempts to stick to the SLA C API where
possible although `palObs()` has a more C-like API than the equivalent
`slaObs()` function. In most cases it is enough to simply change the function
prefix of a routine in order to link against PAL rather than SLALIB. Routines
Expand All @@ -24,14 +25,18 @@ A simple `configure` script is provided:
make install

The tests can be run using `make check`. Use `--prefix` to specify an install location.
Given the history of the source code as a Starlink libary the default will be `/star`.
Given the history of the source code as a Starlink library the default will be `/star`.

Requirements
------------

Requires that the SOFA C library is installed. The `configure` script will abort if SOFA
can not be found. SOFA can be obtained either from <http://www.iausofa.org> or from
an unofficial github repository (with a configure script) at <https://github.com/Starlink/sofa/downloads>.
Requires that either the SOFA C library or the ERFA library variant
(which has a more permissive license than SOFA) be installed. The
`configure` script will abort if neither SOFA nor ERFA can be
found. SOFA can be obtained either from <http://www.iausofa.org> or
from an unofficial github repository (with a configure script) at
<https://github.com/Starlink/sofa/downloads>. ERFA can be downloaded
from <https://github.com/liberfa/erfa>.

Missing Functions
-----------------
Expand Down
2 changes: 1 addition & 1 deletion component.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<!-- component.xml. Generated from component.xml.in by configure. -->

<component id="pal" support="S">
<version>0.4.0</version>
<version>0.5.0</version>
<path>libext/pal</path>
<description>Positional Astronomy Library</description>
<abstract><p>
Expand Down
21 changes: 13 additions & 8 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ dnl Process this file with autoconf to produce a configure script
AC_REVISION($Revision: 27534 $)

dnl Initialisation: package name and version number
AC_INIT([pal],[0.4.0],[[email protected]])
AC_INIT([pal],[0.5.0],[[email protected]])

dnl Require autoconf-2.50 at least
AC_PREREQ([2.69])
Expand Down Expand Up @@ -43,8 +43,8 @@ dnl If we do not have Starlink we can do the test anyhow just in case
if test -n "$STARLINK"
then
AC_SUBST( STARUTIL_LIBADD, "${libdir}/libstarutil.la" )
AC_SUBST( SOFA_LIBADD, "${libdir}/libsofa_c.la" )
AC_SUBST( SOFA_LDFLAGS, "" )
AC_SUBST( ERFA_LIBADD, "${libdir}/liberfa.la" )
AC_SUBST( ERFA_LDFLAGS, "" )
AC_DEFINE( [HAVE_STAR_UTIL_H], [1], [Define to 1 if you have the <star/util.h> header file])
else
dnl AC_CHECK_HEADERS does not search $includedir
Expand All @@ -65,14 +65,19 @@ else
[AC_SUBST(STARUTIL_LIBADD, "-lstarutil")],
[AC_SUBST(STARUTIL_LIBADD, "")])

AC_CHECK_LIB([sofa_c],[iauCal2jd],
[AC_SUBST(SOFA_LIBADD, "-lsofa_c")],
[AC_MSG_ERROR(Missing SOFA library. Can not continue)])
AC_CHECK_LIB([erfa],[eraCal2jd],
[AC_SUBST(ERFA_LIBADD, "-lerfa")],
[
AC_CHECK_LIB([sofa_c],[iauCal2jd],
[AC_SUBST(ERFA_LIBADD, "-lsofa_c")
AC_DEFINE([HAVE_SOFA_H],[1],"Build with SOFA library")],
[AC_MSG_ERROR(Neither ERFA nor SOFA library located. Can not continue)])
])
LDFLAGS="$save_LDFLAGS"

dnl Ensure that we use the $prefix values
AC_SUBST( SOFA_LDFLAGS, "-L${libdir}" )
AC_SUBST( SOFA_CPPFLAGS, "-I${includedir}" )
AC_SUBST( ERFA_LDFLAGS, "-L${libdir}" )
AC_SUBST( ERFA_CPPFLAGS, "-I${includedir}" )

dnl Disable document building regardless of --without-stardocs
_star_build_docs=:
Expand Down
6 changes: 6 additions & 0 deletions pal.news
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ The Starlink Positional Astronomy Library (PAL) is a C implementation of the
SLALIB API. It is distributed under the GPL and uses the SOFA library wherever
possible.

V0.5.0

Now works with ERFA <https://github.com/liberfa/erfa>.
The configure script has been modified to first check
for ERFA and then check for SOFA.

V0.4.0

New routines ported from SLA: palRefv, palAtmdsp
Expand Down
140 changes: 140 additions & 0 deletions pal1sofa.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
/*
*+
* Name:
* pal1sofa.h
* Purpose:
* Mappings of ERFA names to SOFA names
* Language:
* Starlink ANSI C
* Type of Module:
* Include file
* Invocation:
* #include "pal1.h"
* Description:
* PAL will work with both SOFA and ERFA libraries and the
* difference is generally a change in prefix. This include
* file maps the ERFA form of functions to the SOFA form
* and includes the relevant sofa.h vs erfa.h file.
* Authors:
* TIMJ: Tim Jenness (JAC, Hawaii)
* {enter_new_authors_here}
* Notes:
* - PAL uses the ERFA form by default.
* History:
* 2014-07-29 (TIMJ):
* Initial version
* {enter_further_changes_here}
* Copyright:
* Copyright (C) 2014 Tim Jenness
* All Rights Reserved.
* Licence:
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 3 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be
* useful, but WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301, USA.
* Bugs:
* {note_any_bugs_here}
*-
*/

#ifndef PAL1SOFAHDEF
#define PAL1SOFAHDEF

#include <config.h>

# if HAVE_SOFA_H

# include "sofa.h"
# include "sofam.h"

/* Must replace ERFA with SOFA */

# define eraA2af iauA2af
# define eraA2tf iauA2tf
# define eraAf2a iauAf2a
# define eraAnp iauAnp
# define eraAnpm iauAnpm
# define eraC2s iauC2s
# define eraCal2jd iauCal2jd
# define eraD2tf iauD2tf
# define eraDat iauDat
# define eraEe06a iauEe06a
# define eraEpb iauEpb
# define eraEpb2jd iauEpb2jd
# define eraEpj iauEpj
# define eraEpj2jd iauEpj2jd
# define eraEpv00 iauEpv00
# define eraFk5hz iauFk5hz
# define eraGd2gc iauGd2gc
# define eraGmst06 iauGmst06
# define eraHfk5z iauHfk5z
# define eraIr iauIr
# define eraJd2cal iauJd2cal
# define eraNut06a iauNut06a
# define eraObl06 iauObl06
# define eraP06e iauP06e
# define eraPap iauPap
# define eraPas iauPas
# define eraPdp iauPdp
# define eraPlan94 iauPlan94
# define eraPmat06 iauPmat06
# define eraPn iauPn
# define eraPnm06a iauPnm06a
# define eraPxp iauPxp
# define eraRefco iauRefco
# define eraRm2v iauRm2v
# define eraRv2m iauRv2m
# define eraRx iauRx
# define eraRxp iauRxp
# define eraRxpv iauRxpv
# define eraRxr iauRxr
# define eraRy iauRy
# define eraRz iauRz
# define eraS2c iauS2c
# define eraSepp iauSepp
# define eraSeps iauSeps
# define eraStarpm iauStarpm
# define eraTf2a iauTf2a
# define eraTf2d iauTf2d
# define eraTr iauTr
# define eraTrxp iauTrxp

/* These are from sofam.h */

# define ERFA_WGS84 WGS84

# define ERFA_DJ00 DJ00
# define ERFA_DJY DJY
# define ERFA_DAU DAU

# else

# include "erfa.h"
# include "erfam.h"

/* No further action required */

# endif

#endif
8 changes: 4 additions & 4 deletions palAddet.c
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@
*/

#include "pal.h"
#include "sofa.h"
#include "pal1sofa.h"

void palAddet ( double rm, double dm, double eq, double *rc, double *dc ) {
double a[3]; /* The E-terms */
Expand All @@ -96,17 +96,17 @@ void palAddet ( double rm, double dm, double eq, double *rc, double *dc ) {
palEtrms( eq, a );

/* Spherical to Cartesian */
iauS2c( rm, dm, v );
eraS2c( rm, dm, v );

/* Include the E-terms */
for (i=0; i<3; i++) {
v[i] += a[i];
}

/* Cartesian to spherical */
iauC2s( v, rc, dc );
eraC2s( v, rc, dc );

/* Bring RA into conventional range */
*rc = iauAnp( *rc );
*rc = eraAnp( *rc );

}
14 changes: 7 additions & 7 deletions palAmpqk.c
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@
*/

#include "pal.h"
#include "sofa.h"
#include "pal1sofa.h"

void palAmpqk ( double ra, double da, double amprms[21], double *rm,
double *dm ){
Expand All @@ -99,30 +99,30 @@ void palAmpqk ( double ra, double da, double amprms[21], double *rm,
}

/* Apparent RA,Dec to Cartesian */
iauS2c( ra, da, p3 );
eraS2c( ra, da, p3 );

/* Precession and nutation */
iauTrxp( (double(*)[3]) &amprms[12], p3, p2 );
eraTrxp( (double(*)[3]) &amprms[12], p3, p2 );

/* Aberration */
ab1p1 = ab1 + 1.0;
for( i = 0; i < 3; i++ ) {
p1[i] = p2[i];
}
for( j = 0; j < 2; j++ ) {
p1dv = iauPdp( p1, abv );
p1dv = eraPdp( p1, abv );
p1dvp1 = 1.0 + p1dv;
w = 1.0 + p1dv / ab1p1;
for( i = 0; i < 3; i++ ) {
p1[i] = ( p1dvp1 * p2[i] - w * abv[i] ) / ab1;
}
iauPn( p1, &w, p3 );
eraPn( p1, &w, p3 );
for( i = 0; i < 3; i++ ) {
p1[i] = p3[i];
}
}

/* Mean RA,Dec */
iauC2s( p1, rm, dm );
*rm = iauAnp( *rm );
eraC2s( p1, rm, dm );
*rm = eraAnp( *rm );
}
10 changes: 5 additions & 5 deletions palCaldj.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
* djm = double * (Returned)
* Modified Julian Date (JD-2400000.5) for 0 hrs
* j = status (Returned)
* 0 = OK. See iauCal2jd for other values.
* 0 = OK. See eraCal2jd for other values.
* Description:
* Modified Julian Date to Gregorian Calendar with special
Expand All @@ -43,8 +43,8 @@
* {enter_further_changes_here}
* Notes:
* - Uses iauCal2jd
* - Unlike iauCal2jd this routine treats the years 0-100 as
* - Uses eraCal2jd
* - Unlike eraCal2jd this routine treats the years 0-100 as
* referring to the end of the 20th Century and beginning of
* the 21st Century. If this behaviour is not acceptable
* use the SOFA routine directly or palCldj.
Expand Down Expand Up @@ -82,7 +82,7 @@

#include "pal.h"
#include "palmac.h"
#include "sofa.h"
#include "pal1sofa.h"

void palCaldj ( int iy, int im, int id, double *djm, int *j ) {
int adj = 0; /* Year adjustment */
Expand All @@ -95,5 +95,5 @@ void palCaldj ( int iy, int im, int id, double *djm, int *j ) {
}
iy += adj;

*j = iauCal2jd( iy, im, id, &djm0, djm );
*j = eraCal2jd( iy, im, id, &djm0, djm );
}
6 changes: 3 additions & 3 deletions palDafin.c
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@

#include "pal.h"
#include "palmac.h"
#include "sofam.h"
#include "pal1sofa.h"

#include <math.h>

Expand Down Expand Up @@ -171,10 +171,10 @@ void palDafin ( const char *string, int *ipos, double *a, int *j ) {
jf = -3;

/* Tests for range and integrality */
} else if (jm == 0 && dint(deg) != deg) { /* Degrees */
} else if (jm == 0 && DINT(deg) != deg) { /* Degrees */
jf = -1;

} else if ( (js == 0 && dint(arcmin) != arcmin) || arcmin >= 60.0 ) { /* Arcmin */
} else if ( (js == 0 && DINT(arcmin) != arcmin) || arcmin >= 60.0 ) { /* Arcmin */
jf = -2;

} else if (arcsec >= 60.0) { /* Arcsec */
Expand Down
Loading

0 comments on commit 2cbbdd5

Please sign in to comment.