126 #include <lal/LALConstants.h>
127 #include <lal/LALgetopt.h>
128 #include <lal/LALDatatypes.h>
129 #include <lal/LALDetectors.h>
130 #include <lal/TimeSeries.h>
131 #include <lal/Units.h>
132 #include <lal/Date.h>
133 #include <lal/DetResponse.h>
134 #include <lal/TimeDelay.h>
135 #include <lal/LALSimulation.h>
137 #define INVALID_EPOCH { .gpsSeconds = LAL_INT4_MAX, .gpsNanoSeconds = LAL_INT4_MAX }
164 #define TZ_PSTPDT "PST08:00:00PDT07:00:00,M3.2.0/02:00:00,M11.1.0/02:00:00"
165 #define TZ_CSTCDT "CST06:00:00CDT05:00:00,M3.2.0/02:00:00,M11.1.0/02:00:00"
166 #define TZ_CETCEST "CET-01:00:00CEST-02:00:00,M3.5.0/02:00:00,M10.5.0/03:00:00"
167 #define TZ_JST "JST-09:00:00"
169 #define TZ_LHO TZ_PSTPDT
170 #define TZ_LLO TZ_CSTCDT
171 #define TZ_GEO TZ_CETCEST
172 #define TZ_VIRGO TZ_CETCEST
173 #define TZ_KAGRA TZ_JST
174 #define TZ_TAMA TZ_JST
187 char *
sitetime(
char *
s,
size_t size, time_t * timer,
int site);
188 double strtora(
const char *
s,
int degrees);
189 double strtodec(
const char *
s,
int degrees);
190 int fputra(
double ra, FILE * fp);
191 int fputdec(
double ra, FILE * fp);
196 int main(
int argc,
char *argv[])
218 double cos2psi = cos(2.0 *
p.psi);
219 double sin2psi = sin(2.0 *
p.psi);
228 fprintf(stdout,
"# time (s)\tSTRAIN (strain)\n");
231 fprintf(stdout,
"# time (s)\t%s:STRAIN (strain)\n",
p.detector->frDetector.prefix);
250 struct tm utc = {.tm_sec = 0 };
257 strftime(
date,
sizeof(
date),
"%c %Z", &utc);
258 fputs(
"detector arrival time: GPS = ", stderr);
261 fputs(
"coordinated universal time: ", stderr);
264 fputs(
"Greenwich mean sidereal time: HH:MM:SS = ", stderr);
268 fputs(
"polarization angle: ", stderr);
273 double longitude =
p.detector->frDetector.vertexLongitudeRadians;
274 double latitude =
p.detector->frDetector.vertexLatitudeRadians;
275 double lmst_rad = gmst_rad + longitude;
276 double ha = lmst_rad -
p.ra;
277 double altitude = asin(sin(
p.dec) * sin(latitude) + cos(
p.dec) * cos(latitude) * cos(ha));
278 double azimuth = -atan2(cos(
p.dec) * sin(ha), sin(
p.dec) * cos(latitude) - cos(
p.dec) * sin(latitude) * cos(ha));
279 double fplus, fcross;
285 strftime(
date,
sizeof(
date),
"%c %Z", &utc);
286 fputs(
"geocentric arrival time: GPS = ", stderr);
289 fputs(
"coordinated universal time: ", stderr);
292 fputs(
"Greenwich mean sidereal time: HH:MM:SS = ", stderr);
296 fputs(
"right ascension: HH:MM:SS = ", stderr);
300 fputs(
"declination: DD:MM:SS = ", stderr);
304 fputs(
"polarization angle: ", stderr);
307 fputs(
"detector: ", stderr);
308 fprintf(stderr,
"%s",
p.detector->frDetector.name);
310 fputs(
"time delay from Earth center: ", stderr);
313 fputs(
"arrival time at detector: GPS = ", stderr);
316 fputs(
"local time: ", stderr);
317 fprintf(stderr,
"%s",
sitetime(tstr,
sizeof(tstr), &timer, *
p.detector->frDetector.prefix));
319 fputs(
"latitude North: DD:MM:SS = ", stderr);
323 fputs(
"longitude East: HH:MM:SS = ", stderr);
324 fputra(longitude, stderr);
327 fputs(
"local mean sidereal time: HH:MM:SS = ", stderr);
331 fputs(
"hour angle: HH:MM:SS = ", stderr);
335 fputs(
"altitude: ", stderr);
338 fputs(
"azimuth West of North: ", stderr);
341 fputs(
"detector antenna response: ", stderr);
342 fprintf(stderr,
"F+ = %g, Fx = %g", fplus, fcross);
349 char *
sitetime(
char *
s,
size_t size, time_t * timer,
int site)
351 static char tz_lho[] =
TZ_LHO;
352 static char tz_llo[] =
TZ_LLO;
353 static char tz_geo[] =
TZ_GEO;
356 static char tz_tama[] =
TZ_TAMA;
357 char *tz_orig = getenv(
"TZ");
358 char *tz_site = tz_orig;
379 fprintf(stderr,
"warning: unknown time zone - using localtime\n");
383 setenv(
"TZ", tz_site, 1);
384 strftime(
s, size,
"%c %Z", localtime(timer));
386 setenv(
"TZ", tz_orig, 1);
394 const size_t block = 1024;
406 for (
l = 0, n = 0; fgets(line,
sizeof(line),
fp); ++
l) {
412 hp = realloc(hp, bufsz *
sizeof(*hp));
413 hc = realloc(hc, bufsz *
sizeof(*hc));
415 c = sscanf(line,
"%s %le %le", n ? t1 : t0, hp + n, hc + n);
417 fprintf(stderr,
"error: format error on line %zd: %s\n",
l, line);
422 hp = realloc(hp, n *
sizeof(*hp));
423 hc = realloc(hc, n *
sizeof(*hp));
430 memcpy((*hplus)->data->data, hp, n *
sizeof(*hp));
431 memcpy((*hcross)->data->data, hc, n *
sizeof(*hc));
438 double strtora(
const char *
string,
int degrees)
440 double h = 0,
m = 0,
s = 0;
445 if (strchr(
string,
':'))
446 c = sscanf(
string,
"%lf:%lf:%lf", &h, &
m, &
s);
455 fprintf(stderr,
"error parsing option --right-ascension with argument %s\n",
string);
458 m = copysign(
m, h) / 60.0;
459 s = copysign(
s, h) / 3600.0;
463 ra = fmod(ra, 2.0 *
LAL_PI);
471 double d = 0,
m = 0,
s = 0;
476 if (strchr(
string,
':'))
477 c = sscanf(
string,
"%lf:%lf:%lf", &
d, &
m, &
s);
486 fprintf(stderr,
"error parsing option --declination with argument %s\n",
string);
489 m = copysign(
m,
d) / 60.0;
490 s = copysign(
s,
d) / 3600.0;
501 ra = fmod(ra, 2.0 *
LAL_PI);
505 m = 60.0 * modf(ra, &h);
506 s = 60.0 * modf(
m, &
s);
507 return fprintf(
fp,
"%02d:%02d:%04.1f", (
int)h, (
int)fabs(
m), fabs(
s));
516 m = 60.0 * modf(dec, &
d);
517 s = 60.0 * modf(
m, &
s);
518 return fprintf(
fp,
"%c%02d:%02d:%04.1fs", dec < 0 ?
'-' :
'+', (
int)fabs(
d), (
int)fabs(
m), fabs(
s));
524 char *ra_string = NULL;
525 char *dec_string = NULL;
526 char *psi_string = NULL;
533 .epoch = invalid_epoch,
555 char args[] =
"hvrOD:t:a:d:p:";
559 int option_index = 0;
566 if (long_options[option_index].
flag)
569 fprintf(stderr,
"error parsing option %s with argument %s\n", long_options[option_index].
name, LALoptarg);
606 fprintf(stderr,
"unknown error while parsing options\n");
610 switch (argc - LALoptind) {
614 p.fp = fopen(argv[LALoptind],
"r");
616 fprintf(stderr,
"error: could not open file %s\n", argv[LALoptind]);
622 fprintf(stderr,
"extraneous command line arguments:\n");
623 while (++LALoptind < argc)
624 fprintf(stderr,
"%s\n", argv[LALoptind]);
630 fprintf(stderr,
"error: unspecified arrival time\n");
635 p.psi = atof(psi_string);
639 fprintf(stderr,
"error: unspecified polarization angle\n");
646 fprintf(stderr,
"warning: ignoring detector for overhead injection\n");
648 fprintf(stderr,
"warning: ignoring right ascension for overhead injection\n");
650 fprintf(stderr,
"warning: ignoring declination for overhead injection\n");
654 if (
p.detector == NULL) {
655 fprintf(stderr,
"error: unspecified detector prefix\n");
656 fprintf(stderr,
"recognized detector prefixes are:\n");
665 fprintf(stderr,
"error: unspecified right ascension\n");
672 fprintf(stderr,
"error: unspecified declination\n");
687 usage: %s [options] [file]\n\
689 -h, --help print this message and exit\n\
690 -v, --verbose verbose output\n\
691 -r, --radians use radians rather than decimal degrees\n\
692 -O, --overhead signal from directly overhead\n\
693 -D PREFIX, --detector-prefix=PREFIX (required unless overhead)\n\
694 detector prefix (e.g., 'H1', 'L1', 'V1')\n\
695 -t EPOCH, --gps-time=EPOCH (required)\n\
696 time of arrival at earth geocenter (or at detector if overhead):\n\
697 this is added to the timestamp of the input data,\n\
698 which should be an waveform about time = 0\n\
699 -a RA, --right-ascension=RA (required unless overhead)\n\
700 right ascension in H:M:S format or decimal degrees\n\
701 -d DEC, --declination=DEC (required unless overhead)\n\
702 declination in D:M:S format or decimal degrees\n\
703 -p PSI, --polarization-angle=PSI (required)\n\
704 polarization angle in degrees\n\
int XLALStrToGPS(LIGOTimeGPS *t, const char *nptr, char **endptr)
void LALCheckMemoryLeaks(void)
static vector d(const double L_norm, const double J_norm, const vector roots)
Internal function that returns the coefficients "d_0", "d_2" and "d_4" from 1703.03967 corresponding ...
int LALgetopt_long_only(int argc, char *const *argv, const char *options, const struct LALoption *long_options, int *opt_index)
#define required_argument
int main(int argc, char *argv[])
double strtora(const char *s, int degrees)
double strtodec(const char *s, int degrees)
int fputdec(double ra, FILE *fp)
int usage(const char *program)
int fputra(double ra, FILE *fp)
char * sitetime(char *s, size_t size, time_t *timer, int site)
int readdata(REAL8TimeSeries **hplus, REAL8TimeSeries **hcross, FILE *fp)
struct params parseargs(int argc, char **argv)
int printparams(struct params p)
const LALDetector lalCachedDetectors[LAL_NUM_DETECTORS]
#define XLAL_EPOCH_UNIX_GPS
char * XLALGPSToStr(char *s, const LIGOTimeGPS *t)
void XLALComputeDetAMResponse(double *fplus, double *fcross, const REAL4 D[3][3], const double ra, const double dec, const double psi, const double gmst)
REAL8TimeSeries * XLALSimDetectorStrainREAL8TimeSeries(const REAL8TimeSeries *hplus, const REAL8TimeSeries *hcross, REAL8 right_ascension, REAL8 declination, REAL8 psi, const LALDetector *detector)
Transforms the waveform polarizations into a detector strain.
REAL8 XLALTimeDelayFromEarthCenter(const double detector_earthfixed_xyz_metres[3], double source_right_ascension_radians, double source_declination_radians, const LIGOTimeGPS *gpstime)
REAL8TimeSeries * XLALCreateREAL8TimeSeries(const CHAR *name, const LIGOTimeGPS *epoch, REAL8 f0, REAL8 deltaT, const LALUnit *sampleUnits, size_t length)
void XLALDestroyREAL8TimeSeries(REAL8TimeSeries *series)
const LALUnit lalStrainUnit
struct tm * XLALGPSToUTC(struct tm *utc, INT4 gpssec)
void XLALBacktraceErrorHandler(const char *func, const char *file, int line, int errnum)
XLALErrorHandlerType * XLALSetErrorHandler(XLALErrorHandlerType *newHandler)
REAL8 XLALGreenwichMeanSiderealTime(const LIGOTimeGPS *gpstime)
LIGOTimeGPS * XLALGPSAdd(LIGOTimeGPS *epoch, REAL8 dt)
LIGOTimeGPS * XLALGPSAddGPS(LIGOTimeGPS *epoch, const LIGOTimeGPS *dt)
int XLALGPSCmp(const LIGOTimeGPS *t0, const LIGOTimeGPS *t1)
REAL8 XLALGPSGetREAL8(const LIGOTimeGPS *epoch)
REAL8 XLALGPSDiff(const LIGOTimeGPS *t1, const LIGOTimeGPS *t0)
const LALDetector * detector