27 #include <sys/types.h>
30 #include <lal/Units.h>
31 #include <lal/Sequence.h>
78 if ( constraints && constraints->
detector ) {
95 for (
UINT4 i = 0;
i < numFiles;
i ++ ) {
100 UINT4 mprev_version = 0;
102 REAL8 mprev_nsamples = 0;
103 UINT2 mprev_windowspec = 0;
106 if ( (
fp = fopen( fname,
"rb" ) ) == NULL ) {
107 XLALPrintError(
"ERROR: Failed to open matched file '%s'\n\n", fname );
123 while ( ftell(
fp ) < file_len ) {
128 UINT2 this_windowspec;
129 CHAR *this_comment = NULL;
134 if ( ( this_filepos = ftell(
fp ) ) == -1 ) {
142 if (
read_sft_header_from_fp(
fp, &this_header, &this_version, &this_crc, &this_windowspec, &endian, &this_comment, &this_nsamples ) != 0 ) {
143 XLALPrintError(
"ERROR: File-block '%s:%ld' is not a valid SFT!\n\n", fname, ftell(
fp ) );
152 if ( !mfirst_block ) {
153 if ( !
consistent_mSFT_header( mprev_header, mprev_version, mprev_nsamples, mprev_windowspec, this_header, this_version, this_nsamples, this_windowspec ) ) {
154 XLALPrintError(
"ERROR: merged SFT-file '%s' contains inconsistent SFT-blocks!\n\n", fname );
163 mprev_header = this_header;
164 mprev_version = this_version;
165 mprev_nsamples = this_nsamples;
166 mprev_windowspec = this_windowspec;
168 want_this_block =
TRUE;
172 if ( strncmp( constraints->
detector, this_header.
name, 2 ) ) {
173 want_this_block =
FALSE;
178 want_this_block =
FALSE;
182 want_this_block =
FALSE;
187 if ( want_this_block ) {
216 if (
desc->locator ) {
219 if ( (
desc->locator == NULL ) || (
desc->locator->fname == NULL ) ) {
226 strcpy(
desc->locator->fname, fname );
227 desc->locator->offset = this_filepos;
231 desc->header = this_header;
232 desc->comment = this_comment;
233 desc->numBins = this_nsamples;
234 desc->version = this_version;
235 desc->crc64 = this_crc;
242 mfirst_block =
FALSE;
245 if ( ftell(
fp ) + (
long )this_nsamples * 8 >= file_len ) {
250 if ( fseek(
fp, this_nsamples * 8, SEEK_CUR ) == -1 ) {
251 XLALPrintError(
"ERROR: Failed to skip DATA field for SFT '%s': %s\n", fname, strerror( errno ) );
279 if ( constraints && constraints->
timestamps ) {
305 first_header = this_header;
308 if ( this_header.
deltaF != first_header.deltaF ) {
311 file_pattern, this_header.
deltaF, first_header.deltaF );
333 if ( catalog ->
data ) {
335 for (
i = 0;
i < catalog->
length;
i ++ ) {
337 if (
ptr->locator ) {
338 if (
ptr->locator->fname ) {
343 if (
ptr->comment ) {
348 if (
ptr->header.data ) {
388 UINT4 numIFOsMax = 3;
394 UINT4 **sftLocationInCatalog;
397 UINT4 *numSFTsPerIFO;
400 for (
UINT4 X = 0; X < numIFOsMax; X++ ) {
410 for (
UINT4 k = 0;
k < numSFTsTotal;
k++ ) {
416 for ( X = 0; ( X < numIFOs ) && strncmp(
name, ifolist[X], 3 ); X++ )
421 sftLocationInCatalog[X][ numSFTsPerIFO[X] ] =
k;
428 if ( numIFOs >= numIFOsMax ) {
429 numIFOsMaxNew = numIFOsMax + 3;
436 for (
UINT4 Y = numIFOsMax; Y < numIFOsMaxNew; Y++ ) {
441 numIFOsMax = numIFOsMaxNew;
445 strncpy( ifolist[numIFOs],
name, 3 );
446 sftLocationInCatalog[X][0] =
k;
447 numSFTsPerIFO[numIFOs] = 1;
461 for (
UINT4 X = 0; X < numIFOs; X++ ) {
466 for (
UINT4 k = 0;
k < numSFTsPerIFO[X];
k++ ) {
467 UINT4 location = sftLocationInCatalog[X][
k];
474 for (
UINT4 X = 0; X < numIFOsMax; X ++ ) {
476 XLALFree( sftLocationInCatalog[X] );
604 static CHAR ret[512];
610 snprintf( ret,
sizeof( ret ),
"%s : %ld", locator->
fname, locator->
offset );
656 if ( iStart <= iEnd ) {
657 slice->
length = iEnd - iStart + 1;
658 slice->
data = &catalog->
data[iStart];
709 if ( catalog == NULL ) {
710 catalog =
XLALCalloc( 1,
sizeof( *catalog ) );
724 desc->window_type =
"unknown";
732 catalog->
length = new_length;
781 if ( ( save_fp = ftell(
fp ) ) == -1 ) {
785 if ( fseek(
fp, 0, SEEK_END ) == -1 ) {
791 if ( fseek(
fp, save_fp, SEEK_SET ) == -1 ) {
801 if ( fstat( fileno(
fp ), &st ) ) {
816 if ( ( header1.
name[0] != header2.
name[0] ) || ( header1.
name[1] != header2.
name[1] ) ) {
817 XLALPrintError(
"\nInvalid merged SFT: non-identical detectors\n\n" );
822 if ( version1 != version2 ) {
823 XLALPrintError(
"\nInvalid merged SFT: non-identical version-numbers\n\n" );
829 XLALPrintError(
"\nInvalid merged SFT: non-increasing GPS epochs \n\n" );
835 XLALPrintError(
"\nInvalid merged SFT: non-identical time baselines\n\n" );
840 if ( header1.
f0 != header2.
f0 ) {
841 XLALPrintError(
"\nInvalid merged SFT: non-identical start-frequencies\n\n" );
846 if ( nsamples1 != nsamples2 ) {
847 XLALPrintError(
"\nInvalid merged SFT: non-identical number of frequency-bins\n\n" );
852 if ( windowspec1 != windowspec2 ) {
853 XLALPrintError(
"\nInvalid merged SFT: non-identical window specifications\n\n" );
872 el = &( list->
data[0] );
873 for (
i = 0;
i < list->
length;
i++, el++ ) {
#define GPS2REAL8(gps)
convert GPS-time to REAL8
Internal SFT types and functions.
#define SFTFILEIO_REALLOC_BLOCKSIZE
size of blocks allocated for SFT data.
LIGOTimeGPSVector * timestamps
#define LAL_GPS_PRINT(gps)
#define XLAL_LAST_ELEM(x)
#define XLAL_INIT_DECL(var,...)
void * XLALCalloc(size_t m, size_t n)
void * XLALRealloc(void *p, size_t n)
int parse_sft_windowspec(const UINT2 windowspec, const char **window_type, REAL8 *window_param)
Parse an SFT 2-byte 'windowspec' into a window name 'window_type' and possible parameter 'window_para...
static BOOLEAN consistent_mSFT_header(SFTtype header1, UINT4 version1, UINT4 nsamples1, UINT2 windowspec1, SFTtype header2, UINT4 version2, UINT4 nsamples2, UINT2 windowspec2)
void XLALDestroySFTCatalog(SFTCatalog *catalog)
Free an 'SFT-catalogue'.
void XLALDestroyMultiSFTCatalogView(MultiSFTCatalogView *multiView)
Destroys a MultiSFTCatalogView, without freeing the original catalog that the 'view' was referring to...
CHAR * XLALGetChannelPrefix(const CHAR *name)
Find the valid CW detector prefix.
SFTCatalog * XLALMultiAddToFakeSFTCatalog(SFTCatalog *catalog, const LALStringVector *detectors, const MultiLIGOTimeGPSVector *timestamps)
Multi-detector and multi-timestamp wrapper of XLALAddToFakeSFTCatalog().
SFTCatalog * XLALReturnSFTCatalogTimeslice(const SFTCatalog *catalog, const LIGOTimeGPS *minStartGPS, const LIGOTimeGPS *maxStartGPS)
int XLALCheckCRCSFTCatalog(BOOLEAN *crc_check, SFTCatalog *catalog)
This function reads in the SFTs in the catalog and validates their CRC64 checksums.
MultiSFTCatalogView * XLALGetMultiSFTCatalogView(const SFTCatalog *catalog)
Return a MultiSFTCatalogView generated from an input SFTCatalog.
int XLALFindTimesliceBounds(UINT4 *iStart, UINT4 *iEnd, const LIGOTimeGPSVector *timestamps, const LIGOTimeGPS *minStartGPS, const LIGOTimeGPS *maxStartGPS)
LALStringVector * XLALFindFiles(const CHAR *globstring)
Returns a list of filenames matching the input argument, which may be one of the following:
LALStringVector * XLALListIFOsInCatalog(const SFTCatalog *catalog)
Return a sorted string vector listing the unique IFOs in the given catalog.
static long get_file_len(FILE *fp)
SFTCatalog * XLALAddToFakeSFTCatalog(SFTCatalog *catalog, const CHAR *detector, const LIGOTimeGPSVector *timestamps)
Create a 'fake' SFT catalog which contains only detector and timestamp information.
int read_sft_header_from_fp(FILE *fp, SFTtype *header, UINT4 *version, UINT8 *crc64, UINT2 *SFTwindowspec, BOOLEAN *swapEndian, CHAR **SFTcomment, UINT4 *numBins)
SFTCatalog * XLALSFTdataFind(const CHAR *file_pattern, const SFTConstraints *constraints)
Find the list of SFTs matching the file_pattern and satisfying the given constraints,...
const CHAR * XLALshowSFTLocator(const struct tagSFTLocator *locator)
Mostly for debugging purposes: provide a user-API to allow inspecting the SFT-locator [which is an OP...
FILE * fopen_SFTLocator(const struct tagSFTLocator *locator)
Open an "SFT" defined by the SFT-locator, return a FILE-pointer to the beginning of this SFT.
int XLALCWGPSinRange(const LIGOTimeGPS gps, const LIGOTimeGPS *minGPS, const LIGOTimeGPS *maxGPS)
Defines the official CW convention for whether a GPS time is 'within' a given range,...
int compareDetNameCatalogs(const void *ptr1, const void *ptr2)
BOOLEAN has_valid_crc64(FILE *fp)
Check the SFT-block starting at fp for valid crc64 checksum.
int XLALSFTCatalogTimeslice(SFTCatalog *slice, const SFTCatalog *catalog, const LIGOTimeGPS *minStartGPS, const LIGOTimeGPS *maxStartGPS)
Set a SFT catalog 'slice' to a timeslice of a larger SFT catalog 'catalog', with entries restricted t...
int compareSFTdesc(const void *ptr1, const void *ptr2)
static BOOLEAN timestamp_in_list(LIGOTimeGPS timestamp, LIGOTimeGPSVector *list)
INT4 XLALCountIFOsInCatalog(const SFTCatalog *catalog)
Count the number of the unique IFOs in the given catalog.
BOOLEAN XLALIsValidCWDetector(const CHAR *name)
Determine if 'name' is a valid detector name or prefix.
void XLALDestroyCOMPLEX8Sequence(COMPLEX8Sequence *sequence)
LALStringVector * XLALAppendString2Vector(LALStringVector *vect, const CHAR *string)
void XLALDestroyStringVector(LALStringVector *vect)
int XLALSortStringVector(LALStringVector *strings)
INT4 XLALFindStringInVector(const char *needle, const LALStringVector *haystack)
const LALUnit lalDimensionlessUnit
#define XLAL_ERROR_NULL(...)
#define XLAL_CHECK(assertion,...)
int XLALPrintError(const char *fmt,...) _LAL_GCC_PRINTF_FORMAT_(1
#define XLAL_CHECK_NULL(assertion,...)
int XLALGPSCmp(const LIGOTimeGPS *t0, const LIGOTimeGPS *t1)
LALDetector detectors[LAL_NUM_DETECTORS]
A vector of 'timestamps' of type LIGOTimeGPS.
REAL8 deltaT
'length' of each timestamp (e.g.
LIGOTimeGPS * data
array of timestamps
UINT4 length
number of timestamps
A collection of (multi-IFO) LIGOTimeGPSVector time-stamps vectors.
A multi-SFT-catalogue "view": a multi-IFO vector of SFT-catalogs.
SFTCatalog * data
array of SFT-catalog pointers
UINT4 length
number of detectors
An "SFT-catalogue": a vector of SFTdescriptors, as returned by XLALSFTdataFind()
SFTDescriptor * data
array of data-entries describing matched SFTs
UINT4 length
number of SFTs in catalog
'Constraints' for SFT-matching: which detector, within which time-stretch and which timestamps exactl...
CHAR * detector
2-char channel-prefix describing the detector (eg 'H1', 'H2', 'L1', 'G1' etc)
LIGOTimeGPSVector * timestamps
list of timestamps
LIGOTimeGPS * maxStartTime
only include SFTs whose epoch is < maxStartTime
LIGOTimeGPS * minStartTime
only include SFTs whose epoch is >= minStartTime
A 'descriptor' of an SFT: basically containing the header-info plus an opaque description of where ex...
SFTtype header
SFT-header info.
struct tagSFTLocator * locator
internal description of where to find this SFT [opaque!]