LALPulsar  6.1.0.1-89842e6
GetEarthTimes.c
Go to the documentation of this file.
1 /*
2 * Copyright (C) 2007 Jolien Creighton, Teviet Creighton
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with with program; see the file COPYING. If not, write to the
16 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
17 * MA 02110-1301 USA
18 */
19 
20 #include <math.h>
21 #include <lal/XLALError.h>
22 #include <lal/LALStdlib.h>
23 #include <lal/LALConstants.h>
24 #include <lal/Date.h>
25 #include <lal/GetEarthTimes.h>
26 
27 #define NEQUINOXES 29
28 /** Define a list of GPS times of autumnal equinoxes (1992 to 2020). */
29 static const INT4 equinoxes[NEQUINOXES] = {
30  401222588, 432778929, 464336350, 495893590, 527450411, 559007772,
31  590564232, 622121473, 653678833, 685235053, 716792113, 748349233,
32  779905813, 811462993, 843019393, 874576273, 906133453, 937689493,
33  969246553, 1000803853, 1032360553, 1063917853, 1095474553,
34  1127031613, 1158589273, 1190145733, 1221702853, 1253260213,
35  1284816613
36 };
37 
38 
39 /**
40  * This function takes a GPS time from
41  * <tt>tepoch</tt> and uses it to assign
42  * <tt>tAutumn</tt> and <tt>tMidnight</tt>, which are
43  * REAL8 representations of the time in seconds from
44  * <tt>tepoch</tt> to the next autumnal equinox or sidereal midnight,
45  * respectively.
46  *
47  * ### Algorithm ###
48  *
49  * The routine first computes the Greenwich mean sidereal time at
50  * <tt>tepoch</tt> using XLALGreenwichMeanSiderealTime(). The next sidereal
51  * midnight (at the Prime Meridian) is simply 86400 seconds minus that
52  * sidereal time.
53  *
54  * Next the routine computes the time of the next autumnal equinox. The
55  * module contains an internal list of GPS times of autumnal equinoxes
56  * from 1992 to 2020, given to the nearest minute.
57  * If the specified time <tt>tepoch</tt> is after the 2020 autumnal
58  * equinox, or more than a year before the 1992 equinox, then the next
59  * equinox is extrapolated assuming exact periods of length
60  * \ref LAL_YRSID_SI.
61  *
62  * It is up to the user to
63  * choose a <tt>tepoch</tt> that is close to the actual times that
64  * are being considered. This is important, since many computations use
65  * a REAL8 time variable whose origin is the time
66  * <tt>tepoch</tt>. If this is too far from the times of interest,
67  * the REAL8 time variables may suffer loss of precision.
68  *
69  * ### Uses ###
70  *
71  * \code
72  * XLALGreenwichMeanSiderealTime()
73  * \endcode
74  */
75 int
76 XLALGetEarthTimes( const LIGOTimeGPS *tepoch, REAL8 *tMidnight, REAL8 *tAutumn )
77 {
78  LIGOTimeGPS epoch; /* local copy of times->epoch */
79  REAL8 t; /* time as a floating-point number (s) */
80 
81  /* Make sure the parameters exist. */
82  XLAL_CHECK( tepoch != NULL, XLAL_EFAULT );
83  XLAL_CHECK( tAutumn != NULL, XLAL_EFAULT );
84  XLAL_CHECK( tMidnight != NULL, XLAL_EFAULT );
85  epoch = *tepoch;
86 
87  /* Find the next sidereal midnight. */
88  t = fmod( XLALGreenwichMeanSiderealTime( &epoch ), LAL_TWOPI ) * 86400.0 / LAL_TWOPI;
90  *tMidnight = 86400.0 - t;
91 
92  /* Find the next autumnal equinox. */
93  while ( epoch.gpsNanoSeconds > 0 ) {
94  epoch.gpsSeconds += 1;
95  epoch.gpsNanoSeconds -= 1000000000;
96  }
97  if ( equinoxes[0] - epoch.gpsSeconds > LAL_YRSID_SI ) {
98  t = ( REAL8 )( equinoxes[0] - epoch.gpsSeconds )
99  - ( 1.0e-9 ) * epoch.gpsNanoSeconds;
100  *tAutumn = fmod( t, LAL_YRSID_SI );
101  } else {
102  UINT4 i = 0; /* index over equinox list */
103  while ( i < NEQUINOXES && equinoxes[i] <= epoch.gpsSeconds ) {
104  i++;
105  }
106  if ( i == NEQUINOXES ) {
107  t = ( REAL8 )( equinoxes[i - 1] - epoch.gpsSeconds )
108  - ( 1.0e-9 ) * epoch.gpsNanoSeconds;
109  *tAutumn = fmod( t, LAL_YRSID_SI ) + LAL_YRSID_SI;
110  } else
111  *tAutumn = ( REAL8 )( equinoxes[i] - epoch.gpsSeconds )
112  - ( 1.0e-9 ) * epoch.gpsNanoSeconds;
113  }
114 
115  /* Done. */
116  return XLAL_SUCCESS;
117 }
#define NEQUINOXES
Definition: GetEarthTimes.c:27
static const INT4 equinoxes[NEQUINOXES]
Define a list of GPS times of autumnal equinoxes (1992 to 2020).
Definition: GetEarthTimes.c:29
int XLALGetEarthTimes(const LIGOTimeGPS *tepoch, REAL8 *tMidnight, REAL8 *tAutumn)
This function takes a GPS time from tepoch and uses it to assign tAutumn and tMidnight,...
Definition: GetEarthTimes.c:76
#define LAL_YRSID_SI
#define LAL_TWOPI
double REAL8
uint32_t UINT4
int32_t INT4
#define XLAL_CHECK(assertion,...)
#define XLAL_IS_REAL8_FAIL_NAN(val)
XLAL_SUCCESS
XLAL_EFAULT
XLAL_ETIME
REAL8 XLALGreenwichMeanSiderealTime(const LIGOTimeGPS *gpstime)
enum @1 epoch