LALApps 10.1.0.1-eeff03c
gpstime.c
Go to the documentation of this file.
1/*
2* Copyright (C) 2007 Jolien 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 "config.h"
21
22#include <math.h>
23#include <lal/LALStdlib.h>
24#include <LALAppsVCSInfo.h>
25#include "gpstime.h"
26
27/* one second in nano seconds as an INT8 */
28#define I8_SEC_NS LAL_INT8_C(1000000000)
29
30/* one second in nano seconds as a REAL8 */
31#define D_SEC_NS (1e9)
32
33/* one nano seconds in seconds as a REAL8 */
34#define D_NS_SEC (1e-9)
35
36
37/* express LIGOTimeGPS as INT8 nanoseconds */
39{
40 INT8 ns;
41 ns = (INT8)(epoch->gpsSeconds) * I8_SEC_NS;
42 ns += (INT8)(epoch->gpsNanoSeconds);
43 return ns;
44}
45
46
47/* convert INT8 nanoseconds to LIGOTimeGPS epoch */
49{
50 epoch->gpsSeconds = (INT4)( ns / I8_SEC_NS );
51 epoch->gpsNanoSeconds = (INT4)( ns % I8_SEC_NS );
52 return epoch;
53}
54
55
56/* convert REAL8 seconds to INT8 nanoseconds */
58{
59 INT8 ns;
60 ns = (INT8) floor( D_SEC_NS * sec );
61 return ns;
62}
63
64
65/* convert INT8 nanoseconds to REAL8 seconds */
67{
68 REAL8 sec;
69 sec = D_NS_SEC * ns;
70 return sec;
71}
INT8 sec_to_ns(REAL8 sec)
Definition: gpstime.c:57
LIGOTimeGPS * ns_to_epoch(LIGOTimeGPS *epoch, INT8 ns)
Definition: gpstime.c:48
#define D_SEC_NS
Definition: gpstime.c:31
#define I8_SEC_NS
Definition: gpstime.c:28
REAL8 ns_to_sec(INT8 ns)
Definition: gpstime.c:66
INT8 epoch_to_ns(LIGOTimeGPS *epoch)
Definition: gpstime.c:38
#define D_NS_SEC
Definition: gpstime.c:34
double REAL8
int64_t INT8
int32_t INT4
ns
enum @1 epoch