27#include <lal/LALStdlib.h>
28#include <lal/LALString.h>
32#define P_tmpdir "/tmp"
36#if ((__GNUC__ * 100) + __GNUC_MINOR__) >= 402
37#define GCC_DIAG_STR(s) #s
38#define GCC_DIAG_JOINSTR(x,y) GCC_DIAG_STR(x ## y)
39# define GCC_DIAG_DO_PRAGMA(x) _Pragma (#x)
40# define GCC_DIAG_PRAGMA(x) GCC_DIAG_DO_PRAGMA(GCC diagnostic x)
41# if ((__GNUC__ * 100) + __GNUC_MINOR__) >= 406
42# define GCC_DIAG_OFF(x) GCC_DIAG_PRAGMA(push) \
43 GCC_DIAG_PRAGMA(ignored GCC_DIAG_JOINSTR(-W,x))
44# define GCC_DIAG_ON(x) GCC_DIAG_PRAGMA(pop)
46# define GCC_DIAG_OFF(x) GCC_DIAG_PRAGMA(ignored GCC_DIAG_JOINSTR(-W,x))
47# define GCC_DIAG_ON(x) GCC_DIAG_PRAGMA(warning GCC_DIAG_JOINSTR(-W,x))
50# define GCC_DIAG_OFF(x)
51# define GCC_DIAG_ON(x)
59#define CHAR FRAMEC_CHAR
60#include <framecppc/FrameC.h>
61#include <framecppc/FrameH.h>
62#include <framecppc/Stream.h>
63#include <framecppc/FrTOC.h>
70#define tagLALFrameUFrameH frame_h
71#define tagLALFrameUFrChan fr_chan
72#define tagLALFrameUFrTOC fr_toc_t_
73#define tagLALFrameUFrHistory fr_history
75#ifndef FRAMEC_HANDLES_STDIO_STDOUT
81#define FRFILE(stream) ((stream)->handle)
83#define tagLALFrameUFrFile fr_file
84#define FRFILE(stream) (stream)
87#include <lal/LALFrameU.h>
97#define CALL_FRAMEC_FUNCTION_RETVAL(retval, err, f, ...) \
99 FrameCError *error = NULL; \
100 retval = f(&error, __VA_ARGS__); \
102 XLAL_PRINT_ERROR("FrameC function %s() failed with code %d: %s", #f, (error)->s_errno, (error)->s_message); \
111#define CALL_FRAMEC_FUNCTION(err, f, ...) \
113 FrameCError *error = NULL; \
114 f(&error, __VA_ARGS__); \
116 XLAL_PRINT_ERROR("FrameC function %s() failed with code %d: %s", #f, (error)->s_errno, (error)->s_message); \
125#define TRY_FRAMEC_FUNCTION(f, ...) \
128 CALL_FRAMEC_FUNCTION(err, f, __VA_ARGS__); \
130 XLAL_ERROR(XLAL_EFUNC); \
136#define TRY_FRAMEC_FUNCTION_VAL(retval, errval, f, ...) \
139 CALL_FRAMEC_FUNCTION(err, f, __VA_ARGS__); \
141 XLAL_ERROR_VAL(errval, XLAL_EFUNC); \
147#define TRY_FRAMEC_FUNCTION_INT(f, ...) \
151 CALL_FRAMEC_FUNCTION_RETVAL(retval, err, f, __VA_ARGS__); \
153 XLAL_ERROR(XLAL_EFUNC); \
159#define TRY_FRAMEC_FUNCTION_PTR(f, ...) \
163 CALL_FRAMEC_FUNCTION_RETVAL(retval, err, f, __VA_ARGS__); \
165 XLAL_ERROR_NULL(XLAL_EFUNC); \
171#define TRY_FRAMEC_FUNCTION_VOID(f, ...) \
174 CALL_FRAMEC_FUNCTION(err, f, __VA_ARGS__); \
176 XLAL_ERROR_VOID(XLAL_EFUNC); \
185#ifndef FRAMEC_HANDLES_STDIO_STDOUT
197 while (fwrite(buf, 1, fread(buf, 1,
sizeof(buf), stream->tmpfp), stdout) ==
sizeof(buf)) ;
198 fclose(stream->tmpfp);
209 char tmpfname[L_tmpnam + 1] =
"";
210 LALFrameUFrFile *stream;
214 stream->mode = FRAMEC_FILE_MODE_INPUT;
215 else if (*mode ==
'w')
216 stream->mode = FRAMEC_FILE_MODE_OUTPUT;
224 snprintf(tmpfname, L_tmpnam,
"%s/tmp.lal.XXXXXX",
P_tmpdir);
225 if (stream->mode == FRAMEC_FILE_MODE_INPUT) {
228 stream->tmpfp = fdopen(mkstemp(tmpfname),
"w");
229 while (fwrite(buf, 1, fread(buf, 1,
sizeof(buf), stdin), stream->tmpfp) ==
sizeof(buf)) ;
230 fclose(stream->tmpfp);
231 stream->tmpfp = NULL;
233 stream->tmpfp = fdopen(mkstemp(tmpfname),
"r");
265 m = FRAMEC_FILE_MODE_INPUT;
266 else if (*mode ==
'w')
267 m = FRAMEC_FILE_MODE_OUTPUT;
271 if (filename == NULL)
299 fr_toc_nframe_t nframe;
305 fr_toc_nframe_t nframe;
309 CALL_FRAMEC_FUNCTION(err, FrameCFrTOCQuery, toc, FR_TOC_FIELD_NFRAME, &nframe, FR_TOC_FIELD_LAST);
310 if (err || nframe <= pos)
312 gtime =
LALCalloc(nframe,
sizeof(*gtime));
315 CALL_FRAMEC_FUNCTION(err, FrameCFrTOCQuery, toc, FR_TOC_FIELD_GTIME, gtime, nframe, FR_TOC_FIELD_LAST);
327 fr_toc_nframe_t nframe;
331 CALL_FRAMEC_FUNCTION(err, FrameCFrTOCQuery, toc, FR_TOC_FIELD_NFRAME, &nframe, FR_TOC_FIELD_LAST);
332 if (err || nframe <= pos)
338 retval = err ? -1.0 :
dt[pos];
352 fr_toc_adc_name_t *
names;
377 fr_toc_sim_name_t *
names;
402 fr_toc_proc_name_t *
names;
407 if (err || n <= proc)
420 fr_toc_detector_n_t n;
427 fr_toc_detector_name_t *
names;
428 fr_toc_detector_n_t n;
431 CALL_FRAMEC_FUNCTION(err, FrameCFrTOCQuery, toc, FR_TOC_FIELD_DETECTOR_N, &n, FR_TOC_FIELD_LAST);
456 frame_h_gtime_t gtime;
459 fp1 = modf(start1, &ip1);
460 fp2 = modf(start2, &ip2);
461 fp = modf(fp1 + fp2, &ip);
469 gtime.nan = floor(0.5 + 1e9 *
fp);
470 if (gtime.nan >= 1000000000) {
471 gtime.nan -= 1000000000;
526 frame_h_frame_t frnum;
532 frame_h_data_quality_t dq;
533 TRY_FRAMEC_FUNCTION_VAL(dq, -1, FrameCFrameHQuery, frame, FRAME_H_FIELD_DATA_QUALITY, &dq, FRAME_H_FIELD_LAST);
538 frame_h_gtime_t start;
541 start.nan)),
XLAL_REAL8_FAIL_NAN, FrameCFrameHQuery, frame, FRAME_H_FIELD_GTIME, &start, FRAME_H_FIELD_LAST);
546 frame_h_uleaps_t uleaps;
547 TRY_FRAMEC_FUNCTION_VAL(uleaps, -1, FrameCFrameHQuery, frame, FRAME_H_FIELD_ULEAPS, &uleaps, FRAME_H_FIELD_LAST);
560 frame_h_run_t run_ = run;
592 return FR_PROC_TYPE_UNKNOWN;
594 return FR_PROC_TYPE_TIME_SERIES;
596 return FR_PROC_TYPE_FREQUENCY_SERIES;
598 return FR_PROC_TYPE_OTHER_1D_SERIES;
600 return FR_PROC_TYPE_TIME_FREQUENCY;
602 return FR_PROC_TYPE_WAVELET;
605 return Fr_PROC_TYPE_MULTI_DIMENSIONAL;
615 return FR_PROC_SUB_TYPE_UNKNOWN;
617 return FR_PROC_SUB_TYPE_DFT;
619 return FR_PROC_SUB_TYPE_AMPLITUDE_SPECTRAL_DENSITY;
621 return FR_PROC_SUB_TYPE_POWER_SPECTRAL_DENSITY;
623 return FR_PROC_SUB_TYPE_CROSS_SPECTRAL_DENSITY;
625 return FR_PROC_SUB_TYPE_COHERENCE;
627 return FR_PROC_SUB_TYPE_TRANSFER_FUNCTION;
649 fr_chan_time_offset_t offset;
657 fr_chan_sample_rate_t
srate = sampleRate;
663 fr_chan_time_offset_t offset = timeOffset;
669 fr_chan_t_range_t
dt = tRange;
740 fr_vect_compress_t compress;
742 FR_VECT_FIELD_COMPRESS, &compress, FR_VECT_FIELD_LAST);
760 fr_vect_nbytes_t nbytes;
766 fr_vect_ndata_t ndata;
783 if (err || ndim <= dim)
789 retval = err ? (size_t) (-1) : nx[dim];
801 if (err || ndim <= dim)
807 retval = err ? -1.0 : dx[dim];
815 fr_vect_startx_t *startX;
819 if (err || ndim <= dim)
821 startX =
LALCalloc(ndim,
sizeof(*startX));
825 retval = err ? -1.0 : startX[dim];
834 fr_vect_unit_x_t *unitX;
838 if (err || ndim <= dim)
844 retval = err ? NULL : unitX[dim];
852 fr_vect_unit_y_t unitY;
866 (fr_vect_unit_y_t) (unit), 1, FR_VECT_FIELD_LAST);
873 fr_vect_dx_t dx_ = dx;
879 fr_vect_startx_t x0_ = x0;
885 fr_vect_unit_x_t unit_ = unit;
907 fr_detector_prefix_t prefix;
908 LALFrameUFrDetector *detector;
910 detector =
LALCalloc(1,
sizeof(*detector));
914 if (err || !detector->handle) {
920 FR_DETECTOR_FIELD_PREFIX, &prefix, FR_DETECTOR_FIELD_LAST);
925 memcpy(detector->prefix, prefix.prefix, 2);
930 const char *prefix,
double latitude,
double longitude,
double elevation,
931 double azimuthX,
double azimuthY,
double altitudeX,
double altitudeY,
double midpointX,
double midpointY,
int localTime)
933 LALFrameUFrDetector *detector;
935 detector =
LALCalloc(1,
sizeof(*detector));
939 memcpy(detector->prefix, prefix, 2);
941 name, prefix, latitude, longitude, elevation, azimuthX, azimuthY,
942 altitudeX, altitudeY, midpointX, midpointY, localTime);
943 if (err || !detector->handle) {
953 fr_detector_name_t
name;
955 detector->handle, FR_DETECTOR_FIELD_NAME, &
name, FR_DETECTOR_FIELD_LAST);
961 return detector->prefix;
966 fr_detector_longitude_t longitude;
968 detector->handle, FR_DETECTOR_FIELD_LONGITUDE, &longitude, FR_DETECTOR_FIELD_LAST);
973 fr_detector_latitude_t latitude;
975 detector->handle, FR_DETECTOR_FIELD_LATITUDE, &latitude, FR_DETECTOR_FIELD_LAST);
980 fr_detector_elevation_t elevation;
982 detector->handle, FR_DETECTOR_FIELD_ELEVATION, &elevation, FR_DETECTOR_FIELD_LAST);
987 fr_detector_arm_x_azimuth_t armXazimuth;
989 detector->handle, FR_DETECTOR_FIELD_ARM_X_AZIMUTH, &armXazimuth, FR_DETECTOR_FIELD_LAST);
994 fr_detector_arm_y_azimuth_t armYazimuth;
996 detector->handle, FR_DETECTOR_FIELD_ARM_Y_AZIMUTH, &armYazimuth, FR_DETECTOR_FIELD_LAST);
1001 fr_detector_arm_x_altitude_t armXaltitude;
1003 detector->handle, FR_DETECTOR_FIELD_ARM_X_ALTITUDE, &armXaltitude, FR_DETECTOR_FIELD_LAST);
1008 fr_detector_arm_y_altitude_t armYaltitude;
1010 detector->handle, FR_DETECTOR_FIELD_ARM_Y_ALTITUDE, &armYaltitude, FR_DETECTOR_FIELD_LAST);
1015 fr_detector_arm_x_midpoint_t armXmidpoint;
1017 detector->handle, FR_DETECTOR_FIELD_ARM_X_MIDPOINT, &armXmidpoint, FR_DETECTOR_FIELD_LAST);
1022 fr_detector_arm_y_midpoint_t armYmidpoint;
1024 detector->handle, FR_DETECTOR_FIELD_ARM_Y_MIDPOINT, &armYmidpoint, FR_DETECTOR_FIELD_LAST);
1029 fr_detector_localtime_t localTime;
1031 detector->handle, FR_DETECTOR_FIELD_LOCAL_TIME, &localTime, FR_DETECTOR_FIELD_LAST);
const char * XLALFrameUFrChanVectorQueryName_FrameC_(const LALFrameUFrChan *channel)
double XLALFrameUFrDetectorQueryArmXAzimuth_FrameC_(const LALFrameUFrDetector *detector)
const char * XLALFrameUFrTOCQuerySimName_FrameC_(const LALFrameUFrTOC *toc, size_t sim)
int XLALFrameUFrChanSetTimeOffset_FrameC_(LALFrameUFrChan *channel, double timeOffset)
LALFrameUFrChan * XLALFrameUFrProcChanAlloc_FrameC_(const char *name, int type, int subtype, int dtype, size_t ndata)
LALFrameUFrTOC * XLALFrameUFrTOCRead_FrameC_(LALFrameUFrFile *stream)
int XLALFrameUFrameHQueryRun_FrameC_(const LALFrameUFrameH *frame)
int XLALFrameUFrameHWrite_FrameC_(LALFrameUFrFile *stream, LALFrameUFrameH *frame)
size_t XLALFrameUFrChanVectorQueryNBytes_FrameC_(const LALFrameUFrChan *channel)
int XLALFrameUFrChanVectorSetName_FrameC_(LALFrameUFrChan *channel, const char *name)
int XLALFrameUFrameHFrDetectorAdd_FrameC_(LALFrameUFrameH *frame, LALFrameUFrDetector *detector)
const char * XLALFrameUFrChanVectorQueryUnitY_FrameC_(const LALFrameUFrChan *channel)
LALFrameUFrameH * XLALFrameUFrameHAlloc_FrameC_(const char *name, double start1, double start2, double dt, int frnum)
const char * XLALFrameUFrDetectorQueryPrefix_FrameC_(const LALFrameUFrDetector *detector)
int XLALFrameUFrChanSetSampleRate_FrameC_(LALFrameUFrChan *channel, double sampleRate)
LALFrameUFrChan * XLALFrameUFrSimChanAlloc_FrameC_(const char *name, int dtype, size_t ndata)
void XLALFrameUFrHistoryFree_FrameC_(LALFrameUFrHistory *history)
double XLALFrameUFrDetectorQueryElevation_FrameC_(const LALFrameUFrDetector *detector)
#define TRY_FRAMEC_FUNCTION_PTR(f,...)
int XLALFrameUFrameHQueryFrame_FrameC_(const LALFrameUFrameH *frame)
#define TRY_FRAMEC_FUNCTION_VOID(f,...)
int XLALFrameUFrChanVectorExpand_FrameC_(LALFrameUFrChan *channel)
void XLALFrameUFrameHFree_FrameC_(LALFrameUFrameH *frame)
size_t XLALFrameUFrTOCQueryAdcN_FrameC_(const LALFrameUFrTOC *toc)
const char * XLALFrameUFrTOCQueryAdcName_FrameC_(const LALFrameUFrTOC *toc, size_t adc)
double XLALFrameUFrDetectorQueryArmYAzimuth_FrameC_(const LALFrameUFrDetector *detector)
void XLALFrameUFrDetectorFree_FrameC_(LALFrameUFrDetector *detector)
size_t XLALFrameUFrTOCQueryDetectorN_FrameC_(const LALFrameUFrTOC *toc)
double XLALFrameUFrDetectorQueryLatitude_FrameC_(const LALFrameUFrDetector *detector)
int XLALFrameUFrChanSetTRange_FrameC_(LALFrameUFrChan *channel, double tRange)
int XLALFrameUFrChanVectorSetUnitY_FrameC_(LALFrameUFrChan *channel, const char *unit)
const char * XLALFrameUFrTOCQueryDetectorName_FrameC_(const LALFrameUFrTOC *toc, size_t det)
double XLALFrameUFrDetectorQueryArmXMidpoint_FrameC_(const LALFrameUFrDetector *detector)
#define CALL_FRAMEC_FUNCTION_RETVAL(retval, err, f,...)
LALFrameUFrChan * XLALFrameUFrAdcChanAlloc_FrameC_(const char *name, int dtype, size_t ndata)
double XLALFrameUFrameHQueryGTimeModf_FrameC_(double *iptr, const LALFrameUFrameH *frame)
size_t XLALFrameUFrTOCQuerySimN_FrameC_(const LALFrameUFrTOC *toc)
const char * XLALFrameUFrChanVectorQueryUnitX_FrameC_(const LALFrameUFrChan *channel, size_t dim)
double XLALFrameUFrameHQueryDt_FrameC_(const LALFrameUFrameH *frame)
const char * XLALFrameUFrChanQueryName_FrameC_(const LALFrameUFrChan *channel)
size_t XLALFrameUFrChanVectorQueryNx_FrameC_(const LALFrameUFrChan *channel, size_t dim)
size_t XLALFrameUFrTOCQueryNFrame_FrameC_(const LALFrameUFrTOC *toc)
void XLALFrameUFrFileClose_FrameC_(LALFrameUFrFile *stream)
#define TRY_FRAMEC_FUNCTION_VAL(retval, errval, f,...)
const char * XLALFrameUFrDetectorQueryName_FrameC_(const LALFrameUFrDetector *detector)
double XLALFrameUFrChanVectorQueryStartX_FrameC_(const LALFrameUFrChan *channel, size_t dim)
LALFrameUFrFile * XLALFrameUFrFileOpen_FrameC_(const char *filename, const char *mode)
int XLALFrameUFileCksumValid_FrameC_(LALFrameUFrFile *stream)
size_t XLALFrameUFrTOCQueryProcN_FrameC_(const LALFrameUFrTOC *toc)
double XLALFrameUFrDetectorQueryLongitude_FrameC_(const LALFrameUFrDetector *detector)
#define TRY_FRAMEC_FUNCTION_INT(f,...)
int XLALFrameUFrChanVectorSetUnitX_FrameC_(LALFrameUFrChan *channel, const char *unit)
static fr_proc_type_t XLALFrProcType(int type)
size_t XLALFrameUFrChanVectorQueryNDim_FrameC_(const LALFrameUFrChan *channel)
static fr_proc_sub_type_t XLALFrProcSubType(int subtype)
int XLALFrameUFrameHQueryULeapS_FrameC_(const LALFrameUFrameH *frame)
int XLALFrameUFrChanVectorSetStartX_FrameC_(LALFrameUFrChan *channel, double x0)
double XLALFrameUFrTOCQueryGTimeModf_FrameC_(double *iptr, const LALFrameUFrTOC *toc, size_t pos)
int XLALFrameUFrChanVectorCompress_FrameC_(LALFrameUFrChan *channel, int compressLevel)
void XLALFrameUFrChanFree_FrameC_(LALFrameUFrChan *channel)
double XLALFrameUFrDetectorQueryArmXAltitude_FrameC_(const LALFrameUFrDetector *detector)
int XLALFrameUFrChanVectorAlloc_FrameC_(LALFrameUFrChan *channel, int dtype, size_t ndata)
LALFrameUFrameH * XLALFrameUFrameHRead_FrameC_(LALFrameUFrFile *stream, int pos)
int XLALFrameUFrChanVectorQueryType_FrameC_(const LALFrameUFrChan *channel)
LALFrameUFrChan * XLALFrameUFrChanRead_FrameC_(LALFrameUFrFile *stream, const char *name, size_t pos)
int XLALFrameUFrameHQueryDataQuality_FrameC_(const LALFrameUFrameH *frame)
double XLALFrameUFrDetectorQueryArmYMidpoint_FrameC_(const LALFrameUFrDetector *detector)
#define TRY_FRAMEC_FUNCTION(f,...)
LALFrameUFrHistory * XLALFrameUFrHistoryAlloc_FrameC_(const char *name, double gpssec, const char *comment)
#define CALL_FRAMEC_FUNCTION(err, f,...)
int XLALFrameUFrChanVectorQueryCompress_FrameC_(const LALFrameUFrChan *channel)
double XLALFrameUFrChanVectorQueryDx_FrameC_(const LALFrameUFrChan *channel, size_t dim)
void XLALFrameUFrTOCFree_FrameC_(LALFrameUFrTOC *toc)
double XLALFrameUFrChanQueryTimeOffset_FrameC_(const LALFrameUFrChan *channel)
void * XLALFrameUFrChanVectorQueryData_FrameC_(const LALFrameUFrChan *channel)
const char * XLALFrameUFrameHQueryName_FrameC_(const LALFrameUFrameH *frame)
LALFrameUFrDetector * XLALFrameUFrDetectorAlloc_FrameC_(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)
int XLALFrameUFrDetectorQueryLocalTime_FrameC_(const LALFrameUFrDetector *detector)
double XLALFrameUFrDetectorQueryArmYAltitude_FrameC_(const LALFrameUFrDetector *detector)
int XLALFrameUFrameHSetRun_FrameC_(LALFrameUFrameH *frame, int run)
int XLALFrameUFrChanVectorSetDx_FrameC_(LALFrameUFrChan *channel, double dx)
size_t XLALFrameUFrChanVectorQueryNData_FrameC_(const LALFrameUFrChan *channel)
int XLALFrameUFrameHFrHistoryAdd_FrameC_(LALFrameUFrameH *frame, LALFrameUFrHistory *history)
double XLALFrameUFrTOCQueryDt_FrameC_(const LALFrameUFrTOC *toc, size_t pos)
const char * XLALFrameUFrTOCQueryProcName_FrameC_(const LALFrameUFrTOC *toc, size_t proc)
LALFrameUFrDetector * XLALFrameUFrDetectorRead_FrameC_(LALFrameUFrFile *stream, const char *name)
int XLALFrameUFrameHFrChanAdd_FrameC_(LALFrameUFrameH *frame, LALFrameUFrChan *channel)
struct tagLALFrameUFrameH LALFrameUFrameH
Incomplete type for a frame header FrameH structure.
struct tagLALFrameUFrHistory LALFrameUFrHistory
Incomplete type for a history data FrHistory structure.
struct tagLALFrameUFrTOC LALFrameUFrTOC
Incomplete type for a table of contents FrTOC structure.
#define XLAL_ERROR_VOID(...)
#define XLAL_ERROR_REAL8(...)
#define XLAL_ERROR_NULL(...)
#define XLAL_REAL8_FAIL_NAN
#define XLAL_PRINT_WARNING(...)
LIGOTimeGPS * XLALGPSSet(LIGOTimeGPS *epoch, INT4 gpssec, INT8 gpsnan)
REAL8 XLALGPSModf(REAL8 *iptr, const LIGOTimeGPS *epoch)
Incomplete type for a detector data FrDetector structure.
Incomplete type for a frame file FrFile stream.