Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Adam Mercer
lalsuite
Commits
48a53a31
Verified
Commit
48a53a31
authored
Apr 10, 2020
by
Adam Mercer
Browse files
WIP: date: indent using k&r style
[ci skip]
parent
cf256faf
Pipeline
#117900
skipped
Changes
21
Pipelines
1
Expand all
Hide whitespace changes
Inline
Side-by-side
lal/lib/date/Date.h
View file @
48a53a31
...
...
@@ -83,12 +83,12 @@ extern "C"
*/
#define XLAL_EPOCH_UNIX_GPS 315964800
#define XLAL_EPOCH_J2000_0_JD 2451545.0
/**< Julian Day (UTC) of the J2000.0 epoch (2000 JAN 1 12h UTC). */
#define XLAL_EPOCH_J2000_0_TAI_UTC 32
/**< Leap seconds (TAI-UTC) on the J2000.0 epoch (2000 JAN 1 12h UTC). */
#define XLAL_EPOCH_J2000_0_GPS 630763213
/**< GPS seconds of the J2000.0 epoch (2000 JAN 1 12h UTC). */
#define XLAL_EPOCH_GPS_JD 2444244.5
/**< Julian Day (UTC) of the GPS epoch (1980 JAN 6 0h UTC) */
#define XLAL_EPOCH_GPS_TAI_UTC 19
/**< Leap seconds (TAI-UTC) on the GPS epoch (1980 JAN 6 0h UTC) */
#define XLAL_MJD_REF 2400000.5
/**< Reference Julian Day for Mean Julian Day. */
#define XLAL_EPOCH_J2000_0_JD 2451545.0
/**< Julian Day (UTC) of the J2000.0 epoch (2000 JAN 1 12h UTC). */
#define XLAL_EPOCH_J2000_0_TAI_UTC 32
/**< Leap seconds (TAI-UTC) on the J2000.0 epoch (2000 JAN 1 12h UTC). */
#define XLAL_EPOCH_J2000_0_GPS 630763213
/**< GPS seconds of the J2000.0 epoch (2000 JAN 1 12h UTC). */
#define XLAL_EPOCH_GPS_JD 2444244.5
/**< Julian Day (UTC) of the GPS epoch (1980 JAN 6 0h UTC) */
#define XLAL_EPOCH_GPS_TAI_UTC 19
/**< Leap seconds (TAI-UTC) on the GPS epoch (1980 JAN 6 0h UTC) */
#define XLAL_MJD_REF 2400000.5
/**< Reference Julian Day for Mean Julian Day. */
#define XLAL_JD_TO_MJD(jd) ((jd) - XLAL_MJD_REF)
/**< Modified Julian Day for specified civil time structure. */
/**
...
...
@@ -96,16 +96,14 @@ extern "C"
* ::LIGOTimeGPS. Its sole purpose is to aggregate these
* structures for passing to functions.
*/
#ifdef SWIG
/* SWIG interface directives */
#ifdef SWIG
/* SWIG interface directives */
SWIGLAL
(
IMMUTABLE_MEMBERS
(
tagLALPlaceAndGPS
,
p_detector
));
#endif
/* SWIG */
#endif
/* SWIG */
typedef
struct
tagLALPlaceAndGPS
{
const
LALDetector
*
p_detector
;
/**< pointer to a detector */
LIGOTimeGPS
*
p_gps
;
/**< Pointer to a GPS time structure */
}
LALPlaceAndGPS
;
tagLALPlaceAndGPS
{
const
LALDetector
*
p_detector
;
/**< pointer to a detector */
LIGOTimeGPS
*
p_gps
;
/**< Pointer to a GPS time structure */
}
LALPlaceAndGPS
;
/**
* \name Format macros for printing LIGOTimeGPS
...
...
@@ -131,19 +129,19 @@ LALPlaceAndGPS;
/* *INDENT-ON* */
/* Converts GPS time to nano seconds stored as an INT8. */
INT8
XLALGPSToINT8NS
(
const
LIGOTimeGPS
*
epoch
);
INT8
XLALGPSToINT8NS
(
const
LIGOTimeGPS
*
epoch
);
/* Converts nano seconds stored as an INT8 to GPS time. */
LIGOTimeGPS
*
XLALINT8NSToGPS
(
LIGOTimeGPS
*
epoch
,
INT8
ns
);
LIGOTimeGPS
*
XLALINT8NSToGPS
(
LIGOTimeGPS
*
epoch
,
INT8
ns
);
/* Sets GPS time given GPS integer seconds and residual nanoseconds. */
LIGOTimeGPS
*
XLALGPSSet
(
LIGOTimeGPS
*
epoch
,
INT4
gpssec
,
INT8
gpsnan
);
LIGOTimeGPS
*
XLALGPSSet
(
LIGOTimeGPS
*
epoch
,
INT4
gpssec
,
INT8
gpsnan
);
/* Sets GPS time given GPS seconds as a REAL8. */
LIGOTimeGPS
*
XLALGPSSetREAL8
(
LIGOTimeGPS
*
epoch
,
REAL8
t
);
LIGOTimeGPS
*
XLALGPSSetREAL8
(
LIGOTimeGPS
*
epoch
,
REAL8
t
);
/* Returns GPS time as a REAL8. */
REAL8
XLALGPSGetREAL8
(
const
LIGOTimeGPS
*
epoch
);
REAL8
XLALGPSGetREAL8
(
const
LIGOTimeGPS
*
epoch
);
/**
* Breaks the GPS time into REAL8 integral and fractional parts,
...
...
@@ -152,34 +150,34 @@ REAL8 XLALGPSGetREAL8( const LIGOTimeGPS *epoch );
* in the object pointed to by iptr. Like the standard C math
* library function modf().
*/
REAL8
XLALGPSModf
(
REAL8
*
iptr
,
const
LIGOTimeGPS
*
epoch
);
REAL8
XLALGPSModf
(
REAL8
*
iptr
,
const
LIGOTimeGPS
*
epoch
);
/* Adds dt to a GPS time. */
LIGOTimeGPS
*
XLALGPSAdd
(
LIGOTimeGPS
*
epoch
,
REAL8
dt
);
LIGOTimeGPS
*
XLALGPSAdd
(
LIGOTimeGPS
*
epoch
,
REAL8
dt
);
/* Adds two GPS times. */
LIGOTimeGPS
*
XLALGPSAddGPS
(
LIGOTimeGPS
*
epoch
,
const
LIGOTimeGPS
*
dt
);
LIGOTimeGPS
*
XLALGPSAddGPS
(
LIGOTimeGPS
*
epoch
,
const
LIGOTimeGPS
*
dt
);
/* Subtract a GPS time from a GPS time. Computes t1 - t0. */
LIGOTimeGPS
*
XLALGPSSubGPS
(
LIGOTimeGPS
*
t1
,
const
LIGOTimeGPS
*
t0
);
LIGOTimeGPS
*
XLALGPSSubGPS
(
LIGOTimeGPS
*
t1
,
const
LIGOTimeGPS
*
t0
);
/* Difference between two GPS times as a double. Returns t1 - t0. */
REAL8
XLALGPSDiff
(
const
LIGOTimeGPS
*
t1
,
const
LIGOTimeGPS
*
t0
);
REAL8
XLALGPSDiff
(
const
LIGOTimeGPS
*
t1
,
const
LIGOTimeGPS
*
t0
);
/* Compares two GPS times. */
int
XLALGPSCmp
(
const
LIGOTimeGPS
*
t0
,
const
LIGOTimeGPS
*
t1
);
int
XLALGPSCmp
(
const
LIGOTimeGPS
*
t0
,
const
LIGOTimeGPS
*
t1
);
/* Multiply a GPS time by a REAL8 */
LIGOTimeGPS
*
XLALGPSMultiply
(
LIGOTimeGPS
*
gps
,
REAL8
x
);
LIGOTimeGPS
*
XLALGPSMultiply
(
LIGOTimeGPS
*
gps
,
REAL8
x
);
/* Divide a GPS time by a REAL8 */
LIGOTimeGPS
*
XLALGPSDivide
(
LIGOTimeGPS
*
gps
,
REAL8
x
);
LIGOTimeGPS
*
XLALGPSDivide
(
LIGOTimeGPS
*
gps
,
REAL8
x
);
/* Parse an ASCII string into a LIGOTimeGPS structure */
int
XLALStrToGPS
(
LIGOTimeGPS
*
t
,
const
char
*
nptr
,
char
**
endptr
);
int
XLALStrToGPS
(
LIGOTimeGPS
*
t
,
const
char
*
nptr
,
char
**
endptr
);
/* Return a string containing the ASCII base 10 representation of a LIGOTimeGPS. */
char
*
XLALGPSToStr
(
char
*
,
const
LIGOTimeGPS
*
t
);
char
*
XLALGPSToStr
(
char
*
,
const
LIGOTimeGPS
*
t
);
/* *INDENT-OFF* */
#endif
/* !SWIG */
...
...
@@ -265,4 +263,4 @@ LIGOTimeGPS *XLALGreenwichSiderealTimeToGPS(
#endif
/* *INDENT-ON* */
#endif
/* _DATE_H */
#endif
/* _DATE_H */
lal/lib/date/GPSTimeNow.c
View file @
48a53a31
...
...
@@ -39,25 +39,22 @@
* time indicates a time prior to Sun Jan 06 00:00:00 GMT 1980, this
* function returns NULL.
*/
LIGOTimeGPS
*
XLALGPSTimeNow
(
LIGOTimeGPS
*
gpstime
)
LIGOTimeGPS
*
XLALGPSTimeNow
(
LIGOTimeGPS
*
gpstime
)
{
time_t
ticks
=
time
(
NULL
);
struct
tm
tm
;
time_t
ticks
=
time
(
NULL
);
struct
tm
tm
;
gmtime_r
(
&
ticks
,
&
tm
);
gpstime
->
gpsSeconds
=
XLALUTCToGPS
(
&
tm
);
gpstime
->
gpsNanoSeconds
=
0
;
gmtime_r
(
&
ticks
,
&
tm
);
gpstime
->
gpsSeconds
=
XLALUTCToGPS
(
&
tm
);
gpstime
->
gpsNanoSeconds
=
0
;
/*
* XLALUTCToGPS returns < 0 on error, even though of course time did not
* begin at GPS 0
*/
/*
* XLALUTCToGPS returns < 0 on error, even though of course time did not
* begin at GPS 0
*/
if
(
gpstime
->
gpsSeconds
<
0
)
XLAL_ERROR_NULL
(
XLAL_EFUNC
);
if
(
gpstime
->
gpsSeconds
<
0
)
XLAL_ERROR_NULL
(
XLAL_EFUNC
);
return
gpstime
;
return
gpstime
;
}
lal/lib/date/StrToGPS.c
View file @
48a53a31
...
...
@@ -35,24 +35,24 @@
static
int
isbase10
(
const
char
*
s
,
int
radix
)
{
if
(
*
s
==
radix
)
s
++
;
return
isdigit
(
*
s
);
if
(
*
s
==
radix
)
s
++
;
return
isdigit
(
*
s
);
}
static
int
isbase16
(
const
char
*
s
,
int
radix
)
{
if
(
*
s
==
'0'
)
{
if
(
*
s
==
'0'
)
{
s
++
;
if
(
*
s
==
'X'
||
*
s
==
'x'
)
{
s
++
;
if
(
*
s
==
radix
)
s
++
;
if
(
*
s
==
'X'
||
*
s
==
'x'
)
{
s
++
;
if
(
*
s
==
radix
)
s
++
;
return
isxdigit
(
*
s
);
}
return
isxdigit
(
*
s
);
}
return
0
;
}
return
0
;
}
...
...
@@ -63,202 +63,209 @@ static int isbase16(const char *s, int radix)
static
int
isdecimalexp
(
const
char
*
s
)
{
if
(
*
s
==
'E'
||
*
s
==
'e'
)
{
s
++
;
if
(
*
s
==
'+'
||
*
s
==
'-'
)
s
++
;
return
isdigit
(
*
s
);
}
return
0
;
if
(
*
s
==
'E'
||
*
s
==
'e'
)
{
s
++
;
if
(
*
s
==
'+'
||
*
s
==
'-'
)
s
++
;
return
isdigit
(
*
s
);
}
return
0
;
}
static
int
isbinaryexp
(
const
char
*
s
)
{
if
(
*
s
==
'P'
||
*
s
==
'p'
)
{
s
++
;
if
(
*
s
==
'+'
||
*
s
==
'-'
)
s
++
;
return
isdigit
(
*
s
);
}
return
0
;
if
(
*
s
==
'P'
||
*
s
==
'p'
)
{
s
++
;
if
(
*
s
==
'+'
||
*
s
==
'-'
)
s
++
;
return
isdigit
(
*
s
);
}
return
0
;
}
/**
* Parse an ASCII string into a LIGOTimeGPS structure.
*/
int
XLALStrToGPS
(
LIGOTimeGPS
*
t
,
const
char
*
nptr
,
char
**
endptr
)
int
XLALStrToGPS
(
LIGOTimeGPS
*
t
,
const
char
*
nptr
,
char
**
endptr
)
{
union
{
char
*
s
;
const
char
*
cs
;
}
pconv
;
/* this is bad */
int
olderrno
;
int
radix
;
char
*
digits
;
int
len
=
0
;
int
sign
;
int
base
;
int
radixpos
;
int
exppart
;
/* save and clear C library errno so we can check for failures */
olderrno
=
errno
;
errno
=
0
;
/* retrieve the radix character */
radix
=
localeconv
()
->
decimal_point
[
0
];
/* this is bad ... there is a reason for warnings! */
pconv
.
cs
=
nptr
;
/* consume leading white space */
while
(
isspace
(
*
(
pconv
.
cs
)))
(
pconv
.
cs
)
++
;
if
(
endptr
)
*
endptr
=
pconv
.
s
;
/* determine the sign */
if
(
*
(
pconv
.
cs
)
==
'-'
)
{
sign
=
-
1
;
(
pconv
.
cs
)
++
;
}
else
if
(
*
(
pconv
.
cs
)
==
'+'
)
{
sign
=
+
1
;
(
pconv
.
cs
)
++
;
}
else
sign
=
+
1
;
/* determine the base */
if
(
isbase16
((
pconv
.
cs
),
radix
))
{
base
=
16
;
(
pconv
.
cs
)
+=
2
;
}
else
if
(
isbase10
((
pconv
.
cs
),
radix
))
{
base
=
10
;
}
else
{
/* this isn't a recognized number */
XLALGPSSet
(
t
,
0
,
0
);
return
0
;
}
/* count the number of digits including the radix but not including
* the exponent. */
radixpos
=
-
1
;
switch
(
base
)
{
case
10
:
for
(
len
=
0
;
1
;
len
++
)
{
if
(
isdigit
((
pconv
.
cs
)[
len
]))
continue
;
if
((
pconv
.
cs
)[
len
]
==
radix
&&
radixpos
<
0
)
{
radixpos
=
len
;
continue
;
}
break
;
}
break
;
case
16
:
for
(
len
=
0
;
1
;
len
++
)
{
if
(
isxdigit
((
pconv
.
cs
)[
len
]))
continue
;
if
((
pconv
.
cs
)[
len
]
==
radix
&&
radixpos
<
0
)
{
radixpos
=
len
;
continue
;
}
break
;
}
break
;
union
{
char
*
s
;
const
char
*
cs
;
}
pconv
;
/* this is bad */
int
olderrno
;
int
radix
;
char
*
digits
;
int
len
=
0
;
int
sign
;
int
base
;
int
radixpos
;
int
exppart
;
/* save and clear C library errno so we can check for failures */
olderrno
=
errno
;
errno
=
0
;
/* retrieve the radix character */
radix
=
localeconv
()
->
decimal_point
[
0
];
/* this is bad ... there is a reason for warnings! */
pconv
.
cs
=
nptr
;
/* consume leading white space */
while
(
isspace
(
*
(
pconv
.
cs
)))
(
pconv
.
cs
)
++
;
if
(
endptr
)
*
endptr
=
pconv
.
s
;
/* determine the sign */
if
(
*
(
pconv
.
cs
)
==
'-'
)
{
sign
=
-
1
;
(
pconv
.
cs
)
++
;
}
else
if
(
*
(
pconv
.
cs
)
==
'+'
)
{
sign
=
+
1
;
(
pconv
.
cs
)
++
;
}
else
sign
=
+
1
;
/* determine the base */
if
(
isbase16
((
pconv
.
cs
),
radix
))
{
base
=
16
;
(
pconv
.
cs
)
+=
2
;
}
else
if
(
isbase10
((
pconv
.
cs
),
radix
))
{
base
=
10
;
}
else
{
/* this isn't a recognized number */
XLALGPSSet
(
t
,
0
,
0
);
return
0
;
}
/* count the number of digits including the radix but not including
* the exponent. */
radixpos
=
-
1
;
switch
(
base
)
{
case
10
:
for
(
len
=
0
;
1
;
len
++
)
{
if
(
isdigit
((
pconv
.
cs
)[
len
]))
continue
;
if
((
pconv
.
cs
)[
len
]
==
radix
&&
radixpos
<
0
)
{
radixpos
=
len
;
continue
;
}
break
;
}
break
;
/* copy the digits into a scratch space, removing the radix character
* if one was found */
if
(
radixpos
>=
0
)
{
digits
=
malloc
(
len
+
1
);
memcpy
(
digits
,
(
pconv
.
cs
),
radixpos
);
memcpy
(
digits
+
radixpos
,
(
pconv
.
cs
)
+
radixpos
+
1
,
len
-
radixpos
-
1
);
digits
[
len
-
1
]
=
'\0'
;
(
pconv
.
cs
)
+=
len
;
len
--
;
}
else
{
digits
=
malloc
(
len
+
2
);
memcpy
(
digits
,
(
pconv
.
cs
),
len
);
digits
[
len
]
=
'\0'
;
case
16
:
for
(
len
=
0
;
1
;
len
++
)
{
if
(
isxdigit
((
pconv
.
cs
)[
len
]))
continue
;
if
((
pconv
.
cs
)[
len
]
==
radix
&&
radixpos
<
0
)
{
radixpos
=
len
;
(
pconv
.
cs
)
+=
len
;
continue
;
}
break
;
}
/* check for and parse an exponent, performing an adjustment of the
* radix position */
exppart
=
1
;
switch
(
base
)
{
break
;
}
/* copy the digits into a scratch space, removing the radix character
* if one was found */
if
(
radixpos
>=
0
)
{
digits
=
malloc
(
len
+
1
);
memcpy
(
digits
,
(
pconv
.
cs
),
radixpos
);
memcpy
(
digits
+
radixpos
,
(
pconv
.
cs
)
+
radixpos
+
1
,
len
-
radixpos
-
1
);
digits
[
len
-
1
]
=
'\0'
;
(
pconv
.
cs
)
+=
len
;
len
--
;
}
else
{
digits
=
malloc
(
len
+
2
);
memcpy
(
digits
,
(
pconv
.
cs
),
len
);
digits
[
len
]
=
'\0'
;
radixpos
=
len
;
(
pconv
.
cs
)
+=
len
;
}
/* check for and parse an exponent, performing an adjustment of the
* radix position */
exppart
=
1
;
switch
(
base
)
{
case
10
:
/* exponent is the number of powers of 10 */
if
(
isdecimalexp
((
pconv
.
cs
)))
radixpos
+=
strtol
((
pconv
.
cs
)
+
1
,
&
pconv
.
s
,
10
);
break
;
case
16
:
/* exponent is the number of powers of 2 */
if
(
isbinaryexp
((
pconv
.
cs
)))
{
exppart
=
strtol
((
pconv
.
cs
)
+
1
,
&
pconv
.
s
,
10
);
radixpos
+=
exppart
/
4
;
exppart
%=
4
;
if
(
exppart
<
0
)
{
radixpos
--
;
exppart
+=
4
;
}
exppart
=
1
<<
exppart
;
}
break
;
}
/* save end of converted characters */
if
(
endptr
)
*
endptr
=
pconv
.
s
;
/* insert the radix character, padding the scratch digits with zeroes
* if needed */
if
(
radixpos
<
2
)
{
digits
=
realloc
(
digits
,
len
+
2
+
(
2
-
radixpos
));
memmove
(
digits
+
(
2
-
radixpos
)
+
1
,
digits
,
len
+
1
);
memset
(
digits
,
'0'
,
(
2
-
radixpos
)
+
1
);
if
(
radixpos
==
1
)
digits
[
1
]
=
digits
[
2
];
radixpos
=
2
;
}
else
if
(
radixpos
>
len
)
{
digits
=
realloc
(
digits
,
radixpos
+
2
);
memset
(
digits
+
len
,
'0'
,
radixpos
-
len
);
digits
[
radixpos
+
1
]
=
'\0'
;
}
else
{
memmove
(
digits
+
radixpos
+
1
,
digits
+
radixpos
,
len
-
radixpos
+
1
);
}
digits
[
radixpos
]
=
radix
;
/* parse the integer part */
XLALINT8NSToGPS
(
t
,
sign
*
strtol
(
digits
,
NULL
,
base
)
*
exppart
*
XLAL_BILLION_INT8
);
/* parse the fractional part */
if
(
errno
!=
ERANGE
)
{
switch
(
base
)
{
case
10
:
/* exponent is the number of powers of 10 */
if
(
isdecimalexp
((
pconv
.
cs
)))
radixpos
+=
strtol
((
pconv
.
cs
)
+
1
,
&
pconv
.
s
,
10
);
break
;
break
;
case
16
:
/* exponent is the number of powers of 2 */
if
(
isbinaryexp
((
pconv
.
cs
)))
{
exppart
=
strtol
((
pconv
.
cs
)
+
1
,
&
pconv
.
s
,
10
);
radixpos
+=
exppart
/
4
;
exppart
%=
4
;
if
(
exppart
<
0
)
{
radixpos
--
;
exppart
+=
4
;
}
exppart
=
1
<<
exppart
;
}
break
;
}
/* save end of converted characters */
if
(
endptr
)
*
endptr
=
pconv
.
s
;
/* insert the radix character, padding the scratch digits with zeroes
* if needed */
if
(
radixpos
<
2
)
{
digits
=
realloc
(
digits
,
len
+
2
+
(
2
-
radixpos
));
memmove
(
digits
+
(
2
-
radixpos
)
+
1
,
digits
,
len
+
1
);
memset
(
digits
,
'0'
,
(
2
-
radixpos
)
+
1
);
if
(
radixpos
==
1
)
digits
[
1
]
=
digits
[
2
];
radixpos
=
2
;
}
else
if
(
radixpos
>
len
)
{
digits
=
realloc
(
digits
,
radixpos
+
2
);
memset
(
digits
+
len
,
'0'
,
radixpos
-
len
);
digits
[
radixpos
+
1
]
=
'\0'
;
}
else
{
memmove
(
digits
+
radixpos
+
1
,
digits
+
radixpos
,
len
-
radixpos
+
1
);
}
digits
[
radixpos
]
=
radix
;
/* parse the integer part */
XLALINT8NSToGPS
(
t
,
sign
*
strtol
(
digits
,
NULL
,
base
)
*
exppart
*
XLAL_BILLION_INT8
);
/* parse the fractional part */
if
(
errno
!=
ERANGE
)
{
switch
(
base
)
{
case
10
:
break
;
case
16
:
digits
[
radixpos
-
2
]
=
'0'
;
digits
[
radixpos
-
1
]
=
'x'
;
radixpos
-=
2
;
break
;
}
XLALGPSAdd
(
t
,
sign
*
strtod
(
digits
+
radixpos
,
NULL
)
*
exppart
);
digits
[
radixpos
-
2
]
=
'0'
;
digits
[
radixpos
-
1
]
=
'x'
;
radixpos
-=
2
;
break
;
}
XLALGPSAdd
(
t
,
sign
*
strtod
(
digits
+
radixpos
,
NULL
)
*
exppart
);
}
/* free the scratch space */
free
(
digits
);
/* free the scratch space */
free
(
digits
);
/* check for failures and restore errno if there weren't any */
if
(
errno
==
ERANGE
)
XLAL_ERROR
(
XLAL_ERANGE
);
errno
=
olderrno
;
/* check for failures and restore errno if there weren't any */
if
(
errno
==
ERANGE
)
XLAL_ERROR
(
XLAL_ERANGE
);
errno
=
olderrno
;
/* success */
return
0
;
/* success */
return
0
;
}
...
...
@@ -271,63 +278,67 @@ int XLALStrToGPS(LIGOTimeGPS *t, const char *nptr, char **endptr)
* written to it; free the buffer with XLALFree(). The return value is
* the address of the string or NULL on failure.
*/
char
*
XLALGPSToStr
(
char
*
s
,
const
LIGOTimeGPS
*
t
)
char
*
XLALGPSToStr
(
char
*
s
,
const
LIGOTimeGPS
*
t
)
{
char
*
end
;
/* so we can play with it */
LIGOTimeGPS
copy
=
*
t
;
/* make sure we've got a buffer */
if
(
!
s
)
{
/* 22 = 9 digits to the right of the decimal point +
* decimal point + upto 10 digits to the left of the
* decimal point plus an optional sign + a null */
s
=
XLALMalloc
(
22
*
sizeof
(
*
s
));
if
(
!
s
)
XLAL_ERROR_NULL
(
XLAL_EFUNC
);
}
/* normalize the fractional part */
while
(
labs
(
copy
.
gpsNanoSeconds
)
>=
XLAL_BILLION_INT4
)
{
if
(
copy
.
gpsNanoSeconds
<
0
)
{
copy
.
gpsSeconds
-=
1
;
copy
.
gpsNanoSeconds
+=
XLAL_BILLION_INT4
;
}
else
{
copy
.
gpsSeconds
+=
1
;
copy
.
gpsNanoSeconds
-=
XLAL_BILLION_INT4
;
}
}
/* if both components are non-zero, make sure they have the same
* sign */