32#include <lal/LALDatatypes.h>
33#include <lal/LALDetectors.h>
34#include <lal/LALString.h>
35#include <lal/TimeSeries.h>
36#include <lal/FrequencySeries.h>
40#include <lal/LALFrameU.h>
41#include <lal/LALFrameIO.h>
43#ifndef HAVE_LOCALTIME_R
44#define localtime_r(timep, result) memcpy((result), localtime(timep), sizeof(struct tm))
49 LALFrameUFrFile *
file;
73 char prot[FILENAME_MAX] =
"";
74 char host[FILENAME_MAX] =
"";
75 char path[FILENAME_MAX] =
"";
80 "url %s is too long",
url);
82 n = sscanf(
url,
"%[^:]://%[^/]%[^\t\n]", prot, host,
path);
92 if (strcmp(prot,
"file"))
96 if (strcmp(host,
"localhost")) {
98 char localhost[FILENAME_MAX];
100 if (strcmp(host, localhost))
149 const char *chname,
size_t pos)
185 "No LAL typecode equivalent to FrVect type STRING");
193 const char *chname,
size_t pos)
222#include "LALFrameIO_source.c"
228#include "LALFrameIO_source.c"
234#include "LALFrameIO_source.c"
240#include "LALFrameIO_source.c"
246#include "LALFrameIO_source.c"
252#include "LALFrameIO_source.c"
258#include "LALFrameIO_source.c"
264#include "LALFrameIO_source.c"
270#include "LALFrameIO_source.c"
274#define TYPE COMPLEX16
276#include "LALFrameIO_source.c"
285#include "LALFrameIO_source.c"
291#include "LALFrameIO_source.c"
297#include "LALFrameIO_source.c"
301#define TYPE COMPLEX16
303#include "LALFrameIO_source.c"
349 zone =
"Europe/Berlin";
361 zone =
"Europe/Rome";
369 setenv(
"TZ", zone, 1);
376 setenv(
"TZ", orig, 1);
381 return (
int)floor(0.5 + difftime(tloc, tutc));
386 LALFrameUFrDetector *d;
412 const char *project,
int run,
int frnum,
INT8 detectorFlags)
428 INT8 detflg = 1 << 2 * detind;
429 if ((detflg & detectorFlags))
446#define DEFINE_FR_CHAN_ADD_TS_FUNCTION(chantype, laltype, vectype, compress) \
447 int XLALFrameAdd ## laltype ## TimeSeries ## chantype ## Data(LALFrameH *frame, const laltype ## TimeSeries *series) \
449 LIGOTimeGPS frameStart; \
451 const char unitX[] = "s"; \
452 char unitY[LALUnitTextSize]; \
453 LALFrameUFrChan *channel = NULL; \
455 XLALUnitAsString(unitY, sizeof(unitY), &series->sampleUnits); \
456 XLALFrameQueryGTime(&frameStart, frame); \
457 timeOffset = XLALGPSDiff(&series->epoch, &frameStart); \
458 if (timeOffset < 0) \
459 XLAL_ERROR(XLAL_EINVAL, "Series start time %d.%09d " \
460 "is earlier than frame start time %d.%09d", \
461 series->epoch.gpsSeconds, \
462 series->epoch.gpsNanoSeconds, \
463 frameStart.gpsSeconds, \
464 frameStart.gpsNanoSeconds); \
465 channel = XLALFrameUFr ## chantype ## ChanAlloc(series->name, LAL_FRAMEU_FR_VECT_ ## vectype, series->data->length); \
468 data = XLALFrameUFrChanVectorQueryData(channel); \
471 memcpy(data, series->data->data, series->data->length * sizeof(*series->data->data)); \
472 XLALFrameUFrChanSetSampleRate(channel, 1.0/series->deltaT); \
473 XLALFrameUFrChanSetTimeOffset(channel, timeOffset); \
474 XLALFrameUFrChanVectorSetName(channel, series->name); \
475 XLALFrameUFrChanVectorSetDx(channel, series->deltaT); \
476 XLALFrameUFrChanVectorSetStartX(channel, 0.0); \
477 XLALFrameUFrChanVectorSetUnitX(channel, unitX); \
478 XLALFrameUFrChanVectorSetUnitY(channel, unitY); \
479 XLALFrameUFrChanVectorCompress(channel, LAL_FRAMEU_FR_VECT_COMPRESS_ ## compress); \
480 XLALFrameUFrameHFrChanAdd(frame, channel); \
481 XLALFrameUFrChanFree(channel); \
484 XLALFrameUFrChanFree(channel); \
485 XLAL_ERROR(XLAL_EFUNC); \
489#define DEFINE_FR_PROC_CHAN_ADD_TS_FUNCTION(laltype, vectype, compress) \
490int XLALFrameAdd ## laltype ## TimeSeriesProcData(LALFrameH *frame, const laltype ## TimeSeries *series) \
492 LIGOTimeGPS frameStart; \
495 const char unitX[] = "s"; \
496 char unitY[LALUnitTextSize]; \
497 LALFrameUFrChan *channel = NULL; \
499 XLALUnitAsString(unitY, sizeof(unitY), &series->sampleUnits); \
500 XLALFrameQueryGTime(&frameStart, frame); \
501 tRange = series->deltaT * series->data->length; \
502 timeOffset = XLALGPSDiff(&series->epoch, &frameStart); \
503 if (timeOffset < 0) \
504 XLAL_ERROR(XLAL_EINVAL, "Series start time %d.%09d " \
505 "is earlier than frame start time %d.%09d", \
506 series->epoch.gpsSeconds, \
507 series->epoch.gpsNanoSeconds, \
508 frameStart.gpsSeconds, \
509 frameStart.gpsNanoSeconds); \
510 channel = XLALFrameUFrProcChanAlloc(series->name, LAL_FRAMEU_FR_PROC_TYPE_TIME_SERIES, LAL_FRAMEU_FR_PROC_SUB_TYPE_UNKNOWN, LAL_FRAMEU_FR_VECT_ ## vectype, series->data->length); \
513 data = XLALFrameUFrChanVectorQueryData(channel); \
516 memcpy(data, series->data->data, series->data->length * sizeof(*series->data->data)); \
517 XLALFrameUFrChanSetTimeOffset(channel, timeOffset); \
518 XLALFrameUFrChanSetTRange(channel, tRange); \
519 XLALFrameUFrChanVectorSetName(channel, series->name); \
520 XLALFrameUFrChanVectorSetDx(channel, series->deltaT); \
521 XLALFrameUFrChanVectorSetStartX(channel, 0.0); \
522 XLALFrameUFrChanVectorSetUnitX(channel, unitX); \
523 XLALFrameUFrChanVectorSetUnitY(channel, unitY); \
524 XLALFrameUFrChanVectorCompress(channel, LAL_FRAMEU_FR_VECT_COMPRESS_ ## compress); \
525 XLALFrameUFrameHFrChanAdd(frame, channel); \
526 XLALFrameUFrChanFree(channel); \
529 XLALFrameUFrChanFree(channel); \
530 XLAL_ERROR(XLAL_EFUNC); \
534#define DEFINE_FR_PROC_CHAN_ADD_FS_FUNCTION(laltype, vectype, compress) \
535int XLALFrameAdd ## laltype ## FrequencySeriesProcData(LALFrameH *frame, const laltype ## FrequencySeries *series, int subtype) \
537 LIGOTimeGPS frameStart; \
539 const char unitX[] = "s^-1"; \
540 char unitY[LALUnitTextSize]; \
541 LALFrameUFrChan *channel = NULL; \
543 XLALUnitAsString(unitY, sizeof(unitY), &series->sampleUnits); \
544 XLALFrameQueryGTime(&frameStart, frame); \
545 timeOffset = XLALGPSDiff(&series->epoch, &frameStart); \
546 if (timeOffset < 0) \
547 XLAL_ERROR(XLAL_EINVAL, "Series start time %d.%09d " \
548 "is earlier than frame start time %d.%09d", \
549 series->epoch.gpsSeconds, \
550 series->epoch.gpsNanoSeconds, \
551 frameStart.gpsSeconds, \
552 frameStart.gpsNanoSeconds); \
553 channel = XLALFrameUFrProcChanAlloc(series->name, LAL_FRAMEU_FR_PROC_TYPE_FREQUENCY_SERIES, subtype, LAL_FRAMEU_FR_VECT_ ## vectype, series->data->length); \
556 data = XLALFrameUFrChanVectorQueryData(channel); \
559 memcpy(data, series->data->data, series->data->length * sizeof(*series->data->data)); \
560 XLALFrameUFrChanSetTimeOffset(channel, timeOffset); \
561 XLALFrameUFrChanVectorSetName(channel, series->name); \
562 XLALFrameUFrChanVectorSetDx(channel, series->deltaF); \
563 XLALFrameUFrChanVectorSetStartX(channel, series->f0); \
564 XLALFrameUFrChanVectorSetUnitX(channel, unitX); \
565 XLALFrameUFrChanVectorSetUnitY(channel, unitY); \
566 XLALFrameUFrChanVectorCompress(channel, LAL_FRAMEU_FR_VECT_COMPRESS_ ## compress); \
567 XLALFrameUFrameHFrChanAdd(frame, channel); \
568 XLALFrameUFrChanFree(channel); \
571 XLALFrameUFrChanFree(channel); \
572 XLAL_ERROR(XLAL_EFUNC); \
606 LALFrameUFrFile *frfile = NULL;
607 char tmpfname[FILENAME_MAX];
610 int n = snprintf(tmpfname,
sizeof(tmpfname),
"%s.tmp", fname);
611 if (n < 0 || n >= (
int)
sizeof(tmpfname))
624 rename(tmpfname, fname);
633static int charcmp(
const void *c1,
const void *c2)
635 char a = *(
const char *)c1;
636 char b = *(
const char *)c2;
637 return (
a > b) - (
a < b);
658 for (cs = chname; *cs; cs += 2) {
664 if (strlen(cs) <= 2 || !isupper(cs[0]) || !isdigit(cs[1])) {
674 detflgs |= 1 << 2 * d;
675 strncat(
site, cs, 1);
682 for (cs = s =
site; *s; ++cs)
689 for (s = desc; *s; ++s)
698 snprintf(fname, size,
"%s-%s-%d-%d.gwf", *
site ?
site :
"X", desc,
t0,
705#define DEFINE_FR_WRITE_TS_FUNCTION(laltype) \
706 int XLALFrWrite ## laltype ## TimeSeries(const laltype ## TimeSeries *series, int frnum) \
710 char fname[FILENAME_MAX]; \
712 duration = series->deltaT * series->data->length; \
713 detflgs = XLALFrameFileName(fname, sizeof(fname), series->name, &series->epoch, duration); \
714 frame = XLALFrameNew(&series->epoch, duration, "LAL", 0, frnum, detflgs); \
715 XLALFrameAdd ## laltype ## TimeSeriesProcData(frame, series); \
716 XLALFrameWrite(frame, fname); \
717 XLALFrameFree(frame); \
730#define DEFINE_FR_WRITE_FS_FUNCTION(laltype) \
731 int XLALFrWrite ## laltype ## FrequencySeries(const laltype ## FrequencySeries *series, int frnum, int subtype) \
735 char fname[FILENAME_MAX]; \
737 duration = series->deltaF > 0.0 ? 1.0 / series->deltaF : 1.0; \
738 detflgs = XLALFrameFileName(fname, sizeof(fname), series->name, &series->epoch, duration); \
739 frame = XLALFrameNew(&series->epoch, duration, "LAL", 0, frnum, detflgs); \
740 XLALFrameAdd ## laltype ## FrequencySeriesProcData(frame, series, subtype); \
741 XLALFrameWrite(frame, fname); \
755 const double duration = 16.0;
756 const char *project =
"LIGO";
759 const int detectorFlags =
761 const double srate = 16384.0;
762 double deltaT = 1.0 /
srate;
763 size_t length = duration *
srate;
772 for (j = 0; j < length; ++j)
#define XLAL_BILLION_REAL8
#define DEFINE_FR_WRITE_FS_FUNCTION(laltype)
static int XLALFrameFileName(char *fname, size_t size, const char *chname, const LIGOTimeGPS *epoch, double duration)
static int XLALLocalTime(char site, int gpssec)
#define DEFINE_FR_WRITE_TS_FUNCTION(laltype)
#define DEFINE_FR_PROC_CHAN_ADD_FS_FUNCTION(laltype, vectype, compress)
#define DEFINE_FR_PROC_CHAN_ADD_TS_FUNCTION(laltype, vectype, compress)
static LIGOTimeGPS * XLALFrameQueryGTime(LIGOTimeGPS *start, const LALFrameH *frame)
#define localtime_r(timep, result)
static int charcmp(const void *c1, const void *c2)
#define DEFINE_FR_CHAN_ADD_TS_FUNCTION(chantype, laltype, vectype, compress)
int main(int argc, char *argv[])
const LALDetector lalCachedDetectors[LAL_NUM_DETECTORS]
LIGOTimeGPS * XLALGPSTimeNow(LIGOTimeGPS *gpstime)
#define LAL_LLO_4K_DETECTOR_BIT
#define LAL_LHO_4K_DETECTOR_BIT
int gethostname(char *name, int len)
double XLALFrFileQueryDt(const LALFrFile *frfile, size_t pos)
Query a frame file for the duration of a particular frame.
struct tagLALFrFile LALFrFile
Incomplete type for a frame file structure.
LALTYPECODE XLALFrFileQueryChanType(const LALFrFile *frfile, const char *chname, size_t pos)
Query a frame file for the data type of a channel in a frame.
int XLALFrFileCksumValid(LALFrFile *frfile)
Use checksum to determine if a frame file is valid.
size_t XLALFrFileQueryNFrame(const LALFrFile *frfile)
Query a frame file for the number of frames contained in the file.
LIGOTimeGPS * XLALFrFileQueryGTime(LIGOTimeGPS *start, const LALFrFile *frfile, size_t pos)
Query a frame file for the start time of a particular frame.
LALFrFile * XLALFrFileOpenURL(const char *url)
Open frame file for reading and return a LALFrFile structure.
int XLALFrFileClose(LALFrFile *frfile)
Close a frame file described by a LALFrFile structure.
size_t XLALFrFileQueryChanVectorLength(const LALFrFile *frfile, const char *chname, size_t pos)
Query a frame file for the number of data points in a channel in a frame.
int XLALFrameAddFrDetector(LALFrameH *frame, const LALFrDetector *detector)
Adds a detector structure to a frame.
LALFrameUFrameH LALFrameH
Incomplete type for a frame header structure.
int XLALFrameAddFrHistory(LALFrameH *frame, const char *name, const char *comment)
Adds a history structure to a frame.
int XLALFrameWrite(LALFrameH *frame, const char *fname)
Write a LALFrameH frame structure to a frame file.
LALFrameH * XLALFrameNew(const LIGOTimeGPS *epoch, double duration, const char *project, int run, int frnum, INT8 detectorFlags)
Creates a new frame structure.
int XLALFrameAddREAL4TimeSeriesProcData(LALFrameH *frame, const REAL4TimeSeries *series)
Adds an REAL4TimeSeries to a frame as a FrProcData channel.
void XLALFrameFree(LALFrameH *frame)
Frees a frame structure.
size_t XLALFrameUFrTOCQueryNFrame(const LALFrameUFrTOC *toc)
Query FrTOC structure for number of FrameH structures contained.
LALFrameUFrameH * XLALFrameUFrameHAlloc(const char *name, double start1, double start2, double dt, int frnum)
Allocate memory for a new frame header FrameH structure.
LALFrameUFrDetector * XLALFrameUFrDetectorAlloc(const char *name, const char *prefix, double latitude, double longitude, double elevation, double azimuthX, double azimuthY, double altitudeX, double altitudeY, double midpointX, double midpointY, int localTime)
Allocate memory for a new detector FrDetector structure.
int XLALFrameUFrameHWrite(LALFrameUFrFile *stream, LALFrameUFrameH *frame)
Write a FrameH structure to an output FrFile stream.
int XLALFrameUFrChanVectorQueryType(const LALFrameUFrChan *channel)
Query FrChan structure for the data type of its FrVect structure.
int XLALFrameUFrameHFrDetectorAdd(LALFrameUFrameH *frame, LALFrameUFrDetector *detector)
Add a FrDetector structure to a FrameH structure.
void XLALFrameUFrTOCFree(LALFrameUFrTOC *toc)
Free a FrTOC structure.
LALFrameUFrChan * XLALFrameUFrChanRead(LALFrameUFrFile *stream, const char *name, size_t pos)
Read a channel FrChan structure from a FrFile stream.
void XLALFrameUFrameHFree(LALFrameUFrameH *frame)
Free a FrameH structure.
void XLALFrameUFrChanFree(LALFrameUFrChan *channel)
Free a FrChan structure.
void XLALFrameUFrHistoryFree(LALFrameUFrHistory *history)
Free a FrHistory structure.
LALFrameUFrHistory * XLALFrameUFrHistoryAlloc(const char *name, double gpssec, const char *comment)
Allocate memory for a new detector FrHistory structure.
LALFrameUFrTOC * XLALFrameUFrTOCRead(LALFrameUFrFile *stream)
Read the table of contents FrTOC structure for a FrFile stream.
int XLALFrameUFrameHFrHistoryAdd(LALFrameUFrameH *frame, LALFrameUFrHistory *history)
Add a FrHistory structure to a FrameH structure.
size_t XLALFrameUFrChanVectorQueryNData(const LALFrameUFrChan *channel)
Query FrChan structure for the number of points of data in its FrVect structure.
int XLALFrameUFrameHSetRun(LALFrameUFrameH *frame, int run)
Set the run number in a FrameH structure.
struct tagLALFrameUFrHistory LALFrameUFrHistory
Incomplete type for a history data FrHistory structure.
double XLALFrameUFrTOCQueryGTimeModf(double *iptr, const LALFrameUFrTOC *toc, size_t pos)
Query FrTOC structure for start time of a FrameH structure.
void XLALFrameUFrDetectorFree(LALFrameUFrDetector *detector)
Free a FrDetector structure.
LALFrameUFrFile * XLALFrameUFrFileOpen(const char *filename, const char *mode)
Open a frame file FrFile stream.
double XLALFrameUFrameHQueryGTimeModf(double *iptr, const LALFrameUFrameH *frame)
Query FrameH structure for the start time.
struct tagLALFrameUFrTOC LALFrameUFrTOC
Incomplete type for a table of contents FrTOC structure.
double XLALFrameUFrTOCQueryDt(const LALFrameUFrTOC *toc, size_t pos)
Query FrTOC structure for duration of a FrameH structure.
void XLALFrameUFrFileClose(LALFrameUFrFile *stream)
Close a FrFile stream.
int XLALFrameUFileCksumValid(LALFrameUFrFile *stream)
Use checksum to determine if FrFile stream is valid.
@ LAL_FRAMEU_FR_VECT_STRING
Id for string data type.
@ LAL_FRAMEU_FR_VECT_16C
Id for 128-bit double precision complex data type.
@ LAL_FRAMEU_FR_VECT_C
Id for 8-bit signed char data type.
@ LAL_FRAMEU_FR_VECT_4R
Id for 32-bit single precision floating point data type.
@ LAL_FRAMEU_FR_VECT_2S
Id for 16-bit signed integer data type.
@ LAL_FRAMEU_FR_VECT_8S
Id for 64-bit signed integer data type.
@ LAL_FRAMEU_FR_VECT_8U
Id for 64-bit unsigned integer data type.
@ LAL_FRAMEU_FR_VECT_4S
Id for 32-bit signed integer data type.
@ LAL_FRAMEU_FR_VECT_8C
Id for 64-bit single precision complex data type.
@ LAL_FRAMEU_FR_VECT_1U
Id for 8-bit unsigned char data type.
@ LAL_FRAMEU_FR_VECT_8R
Id for 64-bit double precision floating point data type.
@ LAL_FRAMEU_FR_VECT_4U
Id for 32-bit unsigned integer data type.
@ LAL_FRAMEU_FR_VECT_2U
Id for 16-bit unsigned integer data type.
char char * XLALStringDuplicate(const char *s)
size_t XLALStringCopy(char *dst, const char *src, size_t size)
REAL4TimeSeries * XLALCreateREAL4TimeSeries(const CHAR *name, const LIGOTimeGPS *epoch, REAL8 f0, REAL8 deltaT, const LALUnit *sampleUnits, size_t length)
void XLALDestroyREAL4TimeSeries(REAL4TimeSeries *series)
const LALUnit lalStrainUnit
time_t XLALSecondsSinceUnixEpoch(const struct tm *utc)
struct tm * XLALGPSToUTC(struct tm *utc, INT4 gpssec)
#define XLAL_ERROR_NULL(...)
#define XLAL_CHECK_NULL(assertion,...)
LIGOTimeGPS * XLALGPSSet(LIGOTimeGPS *epoch, INT4 gpssec, INT8 gpsnan)
REAL8 XLALGPSGetREAL8(const LIGOTimeGPS *epoch)
REAL8 vertexLongitudeRadians
REAL8 vertexLatitudeRadians
REAL4 yArmAltitudeRadians
REAL4 xArmAltitudeRadians