LAL  7.5.0.1-08ee4f4
GPSTimeNow.c
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2007 Brown, D. A., and Kipp Cannon
3  *
4  * This program is free software; you can redistribute it and/or modify it
5  * under the terms of the GNU General Public License as published by the
6  * Free Software Foundation; either version 2 of the License, or (at your
7  * option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful, but
10  * WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
12  * Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License along
15  * with this program; if not, write to the Free Software Foundation, Inc.,
16  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17  */
18 
19 #include <config.h>
20 #include <time.h>
21 #include <string.h>
22 #include <lal/Date.h>
23 #include <lal/XLALError.h>
24 
25 #ifndef HAVE_GMTIME_R
26 #define gmtime_r(timep, result) memcpy((result), gmtime(timep), sizeof(struct tm))
27 #endif
28 
29 /**
30  * \ingroup Date_h
31  * \brief Populate the LIGOTimeGPS argument with the current system time as
32  * returned by time(2) converted to GPS seconds. Returns the address of
33  * the LIGOTimeGPS argument or NULL on error. On error, the GPS time is
34  * undefined.
35  *
36  * Bugs:
37  *
38  * This function cannot return negative GPS times. If the current system
39  * time indicates a time prior to Sun Jan 06 00:00:00 GMT 1980, this
40  * function returns NULL.
41  */
44  LIGOTimeGPS *gpstime
45  )
46 {
47  time_t ticks = time(NULL);
48  struct tm tm;
49 
50  gmtime_r(&ticks, &tm);
51  gpstime->gpsSeconds = XLALUTCToGPS(&tm);
52  gpstime->gpsNanoSeconds = 0;
53 
54  /*
55  * XLALUTCToGPS returns < 0 on error, even though of course time did not
56  * begin at GPS 0
57  */
58 
59  if(gpstime->gpsSeconds < 0)
61 
62  return gpstime;
63 }
#define gmtime_r(timep, result)
Definition: GPSTimeNow.c:26
LIGOTimeGPS * XLALGPSTimeNow(LIGOTimeGPS *gpstime)
Populate the LIGOTimeGPS argument with the current system time as returned by time(2) converted to GP...
Definition: GPSTimeNow.c:43
INT4 XLALUTCToGPS(const struct tm *utc)
Returns the GPS seconds since the GPS epoch for a specified UTC time structure.
#define XLAL_ERROR_NULL(...)
Macro to invoke a failure from a XLAL routine returning a pointer.
Definition: XLALError.h:713
@ XLAL_EFUNC
Internal function call failed bit: "or" this with existing error number.
Definition: XLALError.h:462
Epoch relative to GPS epoch, see LIGOTimeGPS type for more details.
Definition: LALDatatypes.h:458
INT4 gpsSeconds
Seconds since 0h UTC 6 Jan 1980.
Definition: LALDatatypes.h:459
INT4 gpsNanoSeconds
Residual nanoseconds.
Definition: LALDatatypes.h:460