32#include <lal/LALStdlib.h>
33#include <lal/LALgetopt.h>
34#include <lal/LALConstants.h>
42#define UNUSED __attribute__ ((unused))
47#define MAX_DATE_STRING_LENGTH 256
50#define LHO_LONGITUDE_RAD_E (LAL_PI*(-119.0+(24.0+27.5657/60.0)/60.0)/180.0)
51#define LLO_LONGITUDE_RAD_E (LAL_PI*(-90.0+(46.0+27.2654/60.0)/60.0)/180.0)
55 while ( s && *s && isspace( *s ) )
67 while ( *s && isdigit( *s ) )
81char *
parse_options(
char *buf,
int buflen,
int argc,
char **argv );
107int main(
int argc,
char *argv[] )
122 perror(
"parse options" );
137 gps_sec = atoi( arg );
140 unix_sec = atoi( arg );
144 fprintf( stderr,
"internal error: unrecognized epoch\n" );
166 if ( strstr( arg,
":59:60" ) )
174 fprintf( stderr,
"could not parse date string: %s\n", arg );
184 arg = fgets( buf,
sizeof( buf ) - 1,
fp );
201 printf(
"GPS Time = " );
202 printf(
"%d\n", gps_sec );
206 printf(
"UNIX Time = " );
208 printf(
"%d", (
int)unix_sec );
212 printf(
" + 1 leap second" );
219 fprintf( stderr,
"internal error: unrecognized epoch\n" );
227 char date_string[256];
236 tp = gmtime( &unix_sec );
238 tp = localtime( &unix_sec );
245 strftime( date_string,
sizeof( date_string ), fmt, tp );
260 printf(
"Coordinated Universal Time: " );
271 printf(
"Local Time: " );
309 fprintf( stderr,
"internal error: unrecognized site\n" );
322 printf(
"Julian Day (UTC) = " );
323 printf(
"%.6f\n", jd );
334 printf(
"Modified Julian Day (UTC) = " );
335 printf(
"%.6f\n", mjd );
344 printf(
"Leap Seconds (TAI-UTC) = " );
345 printf(
"%d\n",
leaps );
351 double sidereal_time_hrs;
352 double sidereal_time_min;
353 double sidereal_time_sec;
354 while ( sidereal_time_rad >= 2.0 *
LAL_PI )
355 sidereal_time_rad -= 2.0 *
LAL_PI;
356 while ( sidereal_time_rad < 0 )
357 sidereal_time_rad += 2.0 *
LAL_PI;
361 sidereal_time_hrs = 12.0 * sidereal_time_rad /
LAL_PI;
362 sidereal_time_min = 60.0 * modf( sidereal_time_hrs, &sidereal_time_hrs );
363 sidereal_time_sec = 60.0 * modf( sidereal_time_min, &sidereal_time_min );
364 sidereal_time_sec = floor( sidereal_time_sec + 0.5 );
366 printf(
"Sidereal Time (HH:MM:SS) = " );
367 printf(
"%02.0f:%02.0f:%02d\n", sidereal_time_hrs, sidereal_time_min, (
int)sidereal_time_sec );
371 printf(
"Sidereal Time (radians) = " );
372 printf(
"%.6f\n", sidereal_time_rad );
375 fprintf( stderr,
"internal error: unrecognized sidereal time format\n" );
389 printf(
"Greenwich Mean " );
397 double sidereal_time_rad;
403 printf(
"LHO Local " );
410 double sidereal_time_rad;
416 printf(
"LLO Local " );
434 fprintf( stderr,
"internal error: unrecognized site\n" );
465 int save_epoch =
epoch;
485 fprintf( stderr,
"internal error: unrecognized output type\n" );
510 if ( utc.tm_sec == 60 )
528 tp = gmtime( &unix_sec );
539#define MAX_ENV_SIZE 1024
543 static int first = 1;
544 static char *tz_env_orig = NULL;
548 tz_env_orig = getenv(
"TZ" );
552 setenv(
"TZ", zone, 1 );
556 setenv(
"TZ", tz_env_orig, 1 );
563 static int first = 1;
564 static char tz_equals_string[] =
"TZ=";
565 static char tz_string[] =
"TZ";
567 static char *tz_env_orig = NULL;
572 tz_env_orig = getenv(
"TZ" );
577 strncpy( tz_env,
"TZ=",
sizeof( tz_env ) - 1 );
578 strncat( tz_env, zone,
sizeof( tz_env ) - strlen( tz_env ) - 1 );
585 strncpy( tz_env,
"TZ=",
sizeof( tz_env ) - 1 );
586 strncat( tz_env, tz_env_orig,
sizeof( tz_env ) - strlen( tz_env ) - 1 );
591 putenv( tz_equals_string );
593 strcpy( tz_equals_string,
"" );
622 const char *
name =
"Name:\n\t%s\n\n";
623 const char *synopsis =
"Synopsis:\n\t%s [OPTIONS] DATE_STRING\n\t%s [OPTIONS] TIMER_SECONDS\n\n";
625 Convert between various representations of time.\n\n";
626 const char *
options =
"Options:\n\n\
628 output a date string [default when input is timer seconds]\n\
630 -fFORMAT, --format=FORMAT\n\
631 output format for date string [see date(1)]\n\
634 use GPS epoch for timer (1980-01-06 00:00:00 UTC) [default]\n\
637 output date string in ISO 8601 format\n\
639 -j, --jd, --julian-day\n\
640 output Julian day (in UTC time system)\n\
642 -l, --leap-seconds\n\
643 output number of leap seconds (TAI-UTC)\n\
646 date strings formatted for local time (current TZ setting)\
648 -m, --mjd, --modified-julian-day\n\
649 output modified Julian day (in UTC time system)\n\
652 output RFC-2822 compliant date string\n\
654 -s, --sidereal-time[= HMS|RAD]\n\
655 print Greenwich mean sidreal time [default format HH:MM:SS]\n\
658 read from standard input\n\
661 output timer seconds [default when input is a date string]\n\
664 date strings formatted for Coordinated Universal Time [default]\n\
667 use Unix epoch for timer (1970-01-01 00:00:00 UTC)\n\
670 set time zone to TZ (use with --local)\n\
672 -ZSITE, --site=SITE\n\
673 set site to SITE which is [valid sites: LHO | LLO]\n\
675 --help display this help and exit\n\
678 output version information and exit\n\n";
679 const char *environment =
"Environment Variables:\n\
680 TZ The timezone to use when parsing or displaying dates.\n\n";
681 const char *examples =
"Examples:\n\
682 Get current time in GPS seconds:\n\
686 Get local time corresponding to GPS time 800000000 in RFC 2822 format:\n\
688 %s --rfc-2822 --local 800000000\n\
690 Find the local sidereal time at LHO three hours ago:\n\
692 %s --sidereal-time --site=LHO 3 hours ago\n\
694 Get the Julian day(UTC) of Y2K (UTC is default unless --local is used):\n\
696 %s --julian-day Jan 1, 2000\n\
698 Find out all about now:\n\
706 fprintf( stdout,
"%s", environment );
740 char args[] =
"+df:GhIjlLmRsSuUvVW:z:Z:";
745 int option_index = 0;
756 if ( ! long_options[option_index].
flag )
758 fprintf( stderr,
"error parsing option %s with argument %s\n",
815 fprintf( stderr,
"expect \"HMS\" (hours:minutes:seconds)" );
816 fprintf( stderr,
"or \"RAD\" (radians)\n" );
859 fprintf( stderr,
"expect either \"LHO\" or \"LLO\"\n" );
867 fprintf( stderr,
"unknown error while parsing options\n" );
875 c = fgets( buf, buflen,
fp );
883 strncat( buf + len, argv[
LALoptind], buflen - len );
887 fprintf( stderr,
"error: line too long\n" );
890 strncat( buf + len,
" ", buflen - len );
893 fprintf( stderr,
"error: line too long\n" );
const LALVCSInfoList lalVCSInfoList
NULL-terminated list of VCS and build information for LAL and its dependencies
int LALgetopt_long_only(int argc, char *const *argv, const char *options, const struct LALoption *long_options, int *opt_index)
#define required_argument
#define optional_argument
static const struct leaps_table leaps[]
time_t get_date(const char *p, const time_t *now)
#define LAL_PI
Archimedes's constant, pi.
int XLALOutputVCSInfo(FILE *fp, const LALVCSInfoList vcs_list, const int verbose, const char *prefix)
Output VCS and build information, as generated by XLALVCSInfoString(), to a file pointer fp.
REAL8 XLALConvertCivilTimeToJD(const struct tm *civil)
Returns the Julian Day (JD) corresponding to the civil date and time given in a broken down time stru...
INT4 XLALUTCToGPS(const struct tm *utc)
Returns the GPS seconds since the GPS epoch for a specified UTC time structure.
int XLALLeapSeconds(INT4 gpssec)
Returns the leap seconds TAI-UTC at a given GPS second.
time_t XLALSecondsSinceUnixEpoch(const struct tm *utc)
Compute Unix epoch time: seconds since 1970 January 1 0h UTC (POSIX:2001 definition of Unix Epoch).
struct tm * XLALGPSToUTC(struct tm *utc, INT4 gpssec)
Returns a pointer to a tm structure representing the time specified in seconds since the GPS epoch.
REAL8 XLALConvertCivilTimeToMJD(const struct tm *civil)
Returns the Modified Julian Day MJD corresponding to the civil date and time given in a broken down t...
XLALErrorHandlerType * XLALSetErrorHandler(XLALErrorHandlerType *newHandler)
Sets the error handler to a new handler and returns the old handler.
void XLALExitErrorHandler(const char *func, const char *file, int line, int errnum)
The XLAL error handler that calls exit.
REAL8 XLALGreenwichMeanSiderealTime(const LIGOTimeGPS *gpstime)
Convenience wrapper, calling XLALGreenwichSiderealTime() with the equation of equinoxes set to 0.
Epoch relative to GPS epoch, see LIGOTimeGPS type for more details.
INT4 gpsSeconds
Seconds since 0h UTC 6 Jan 1980.
INT4 gpsNanoSeconds
Residual nanoseconds.
void usage(const char *program, int exitcode)
static const char * skip_space(const char *s)
int main(int argc, char *argv[])
static void output_leaps(int gps_sec)
int unix_to_gps(time_t unix_sec)
static void output_jd(int gps_sec)
static void output_secs(int gps_sec)
static void output_date_site(int gps_sec)
static void output_date_utc(int gps_sec)
void set_zone(const char *zone)
static void output_date(int gps_sec)
static void output_lho_date(int gps_sec)
static int is_blank(const char *s)
#define LHO_LONGITUDE_RAD_E
static void output_local_sidereal_time_llo(int gps_sec)
static void output_gmst(int gps_sec)
const char * utc_unix_date_format
static void output_sidereal_time(double sidereal_time_rad)
static void output_mjd(int gps_sec)
static void output_sidereal_time_site(int gps_sec)
const char * unix_date_format
static void output_llo_date(int gps_sec)
time_t gps_to_unix(int gps_sec, int *leap)
const char * iso_8601_format
static void output_local_sidereal_time_lho(int gps_sec)
char * parse_options(char *buf, int buflen, int argc, char **argv)
static int is_integer(const char *s)
static void output_date_local(int gps_sec)
#define LLO_LONGITUDE_RAD_E
void output(int gps_sec, int output_type)
const char * output_date_format
const char * rfc_822_format