26 #include <lal/StringInput.h>
27 #include <lal/LALConstants.h>
28 #include <lal/LALString.h>
29 #include <lal/TranslateAngles.h>
47 XLAL_CHECK ( !isspace(dms[0]),
XLAL_EINVAL,
"No initial whitespace allowed in input string '%s'\n", dms );
48 XLAL_CHECK ( dms[strlen(dms)-1] !=
':',
XLAL_EINVAL,
"No trailing colons allowed in input string '%s'\n", dms );
52 int numitems = sscanf(dms,
"%d:%d:%lf", &d, &
m, &s);
54 XLAL_CHECK ( numitems == 3 || numitems == 2 || numitems == 1,
XLAL_EINVAL,
"Angle input string '%s' not in format 'degs:mins:secs'", dms );
55 XLAL_CHECK ( d >= -360 && d <= 360,
XLAL_EDOM,
"Degrees '%d' outside of valid range of [-360,360] deg\n", d );
57 XLAL_CHECK ( s >= 0 && s < 60,
XLAL_EDOM,
"Seconds '%lf' outside of the valid range of [0, 60) secs", s );
62 if ( dms[0] ==
'-' ) {
67 (*radians) = (
LAL_PI/180.0) * ( d + (sig*
m / 60.0) + (sig*s / 3600.0) );
86 XLAL_CHECK ( hms[strlen(hms)-1] !=
':',
XLAL_EINVAL,
"No trailing colons allowed in input string '%s'\n", hms );
90 int numitems = sscanf(hms,
"%d:%d:%lf", &h, &
m, &s);
92 XLAL_CHECK_REAL8 ( numitems == 3 || numitems == 2 || numitems == 1,
XLAL_EINVAL,
"Angle input string '%s' not in format 'hours:mins:secs'\n", hms );
98 const REAL8 hour2deg = 360./24.;
100 const REAL8 hour2rad = hour2deg * deg2rad;
102 (*radians) = hour2rad * ( h + (
m / 60.0) + (s / 3600.0) );
118 INT4 hours = (
INT4) floor ( remainderH );
120 INT4 minutes = (
INT4) floor ( remainderH * 60.0 );
121 remainderH -= minutes / 60.0;
122 REAL8 seconds = remainderH * 3600.0;
123 INT4 roundedSec = (
INT4) round ( seconds * 10000000 ) / 10000000;
124 if ( roundedSec == 60 )
138 snprintf ( hms,
sizeof(hms)-1,
"%02d:%02d:%010.7f", hours, minutes, seconds );
152 CHAR sign = (radians < 0) ?
'-' :
'+';
156 INT4 degrees = (
INT4) floor ( remainderDeg );
157 remainderDeg -= degrees;
158 INT4 arcmins = (
INT4) floor ( remainderDeg * 60.0 );
159 remainderDeg -= arcmins / 60.0;
160 REAL8 arcsecs = remainderDeg * 3600.0;
161 INT4 roundedArcsecs = (
INT4) round ( arcsecs * 100000 ) / 100000;
162 if ( roundedArcsecs == 60 )
174 snprintf ( dms,
sizeof(dms)-1,
"%c%02d:%02d:%08.5f",
sign, degrees, arcmins, arcsecs );
#define LAL_PI
Archimedes's constant, pi.
#define LAL_TWOPI
2*pi is circumference of a circle divided by its radius
double REAL8
Double precision real floating-point number (8 bytes).
char CHAR
One-byte signed integer, see Headers LAL(Atomic)Datatypes.h for more details.
int32_t INT4
Four-byte signed integer.
char * XLALStringDuplicate(const char *s)
Like strdup but uses LAL allocation routines (free with LALFree).
int XLALTranslateHMStoRAD(REAL8 *radians, const CHAR *hms)
Translate a string representing an angle in the form "hours:minutes:seconds" into radians.
CHAR * XLALTranslateRADtoHMS(REAL8 radians)
Translate (longitude, right-ascencsion, RA) radians into hours:minutes:seconds (HMS) format,...
int XLALTranslateDMStoRAD(REAL8 *radians, const CHAR *dms)
Translate a string representing an angle in the form "degrees:minutes:seconds" into radians.
CHAR * XLALTranslateRADtoDMS(REAL8 radians)
Translate (latitude, declination, DEC) radians into "sign*degrees:minutes:seconds" (DMS) format,...
#define XLAL_CHECK(assertion,...)
Macro to test an assertion and invoke a failure if it is not true in a function that returns an integ...
#define XLAL_CHECK_REAL8(assertion,...)
Macro to test an assertion and invoke a failure if it is not true in a function that returns a REAL8.
#define XLAL_CHECK_NULL(assertion,...)
Macro to test an assertion and invoke a failure if it is not true in a function that returns a pointe...
@ XLAL_SUCCESS
Success return value (not an error number)
@ XLAL_EDOM
Input domain error.
@ XLAL_EINVAL
Invalid argument.