21 #include <lal/LALStdlib.h>
23 #include <lal/Segments.h>
24 #include <lal/LALString.h>
98 if ( ! start || !
end ) {
99 XLALPrintError(
"NULL LIGOTimeGPS pointer passed to %s\n", __func__ );
105 XLALPrintError(
"Inconsistent times passed to %s (%d.%09d > %d.%09d)\n",
107 end->gpsSeconds,
end->gpsNanoSeconds );
137 if ( ! start || !
end ) {
138 XLALPrintError(
"NULL LIGOTimeGPS pointer passed to %s\n", __func__ );
144 XLALPrintError(
"Inconsistent times passed to %s (%d.%09d > %d.%09d)\n",
146 end->gpsSeconds,
end->gpsNanoSeconds );
159 segptr->
start = *start;
216 const LALSeg *seg0 = pseg0;
217 const LALSeg *seg1 = pseg1;
259 XLALPrintError(
"NULL LALSegList pointer passed to %s\n", __func__ );
264 seglist->
segs = NULL;
307 XLALPrintError(
"NULL LALSegList pointer passed to %s\n", __func__ );
313 XLALPrintError(
"Passed unintialized LALSegList structure to %s\n", __func__ );
318 if ( seglist->
segs ) {
323 seglist->
segs = NULL;
384 XLALPrintError(
"NULL LALSegList pointer passed to %s\n", __func__ );
396 XLALPrintError(
"Passed unintialized LALSegList structure to %s\n", __func__ );
402 XLALPrintError(
"Invalid segment passed to %s (%d.%09d > %d.%09d)\n",
431 seglist->
segs = segptr;
446 if ( ns1 % 1000 || ns2 % 1000 ) {
449 }
else if ( seglist->
dplaces < 6 ) {
450 if ( ns1 % 1000000 || ns2 % 1000000 ) {
453 }
else if ( seglist->
dplaces < 3 ) {
463 if ( seglist->
length > 1 ) {
495 XLALPrintError(
"NULL LALSegList pointer passed to %s\n", __func__ );
501 XLALPrintError(
"Passed unintialized LALSegList structure to %s\n", __func__ );
552 XLALPrintError(
"NULL LALSegList pointer passed to %s\n", __func__ );
558 XLALPrintError(
"Passed unintialized LALSegList structure to %s\n", __func__ );
563 if ( seglist->
length <= 1 ) {
573 for ( rp = seglist->
segs+1; rp < seglist->segs+seglist->
length; rp++ ) {
592 if ( newLength < seglist->arraySize ) {
602 seglist->
segs = segptr;
645 for (
size_t i = 0; i < seglist->
length; ++i) {
719 LALSeg *l1start=NULL, *l1end=NULL, *l2start=NULL, *l2end=NULL;
724 XLALPrintError(
"NULL LALSegList pointer passed to %s\n", __func__ );
730 XLALPrintError(
"NULL LIGOTimeGPS pointer passed to %s\n", __func__ );
736 XLALPrintError(
"Passed unintialized LALSegList structure to %s\n", __func__ );
741 if ( seglist->
length == 0 ) {
758 bstart = seglist->
segs;
769 }
else if (
cmp < 0 ) {
771 bstart = seglist->
segs;
792 }
else if (
cmp < 0 ) {
818 l1start = seglist->
segs;
820 l2start = l2end = NULL;
830 }
else if (
cmp < 0 ) {
836 l1start = seglist->
segs;
838 l2start = l2end = NULL;
845 l2start = seglist->
segs;
863 segp = bsearch( (
const void *) gps, (
const void *) bstart,
874 }
else if ( seglist->
sorted ) {
878 for ( segp=l1start; segp<l1end; segp++ ) {
883 }
else if (
cmp < 0 ) {
895 for ( segp=l2start; segp<l2end; segp++ ) {
908 for ( segp=l1start; segp<l1end; segp++ ) {
917 for ( segp=l2start; segp<l2end; segp++ ) {
946 XLALPrintError(
"NULL LALSegList pointer passed to %s\n", __func__ );
952 XLALPrintError(
"NULL LIGOTimeGPS pointer passed to %s\n", __func__ );
958 XLALPrintError(
"Passed unintialized LALSegList structure to %s\n", __func__ );
963 for (i=0; i<seglist->
length; i++) {
990 if ( !start || !
end ) {
1007 if ( startNS >= endNS ) {
1008 XLALPrintError(
"%s(): zero-length or improper interval\n", __func__ );
1013 for (i=0; i<seglist->
length; i++) {
1019 if ( segEnd <= startNS || segStart >= endNS )
1023 if ( segStart < startNS )
1025 if ( segEnd > endNS )
1039 for ( i = 0; i < workspace.
length; i++ )
1084 for (
UINT4 k = 0; k < Nseg; k ++ )
1117 sprintf ( segfmt,
"%%.%df, %%.%df, %%d; ", seglist->
dplaces, seglist->
dplaces );
1120 for (
UINT4 k = 0; k < Nseg; k ++ )
1125 sprintf ( seg_buf, segfmt, t0_k, t1_k, seglist->
segs[k].
id );
1145 if( indx >= seglist->
length ){
1149 memcpy(tmp, &seglist->
segs[indx],
sizeof(
LALSeg));
static int cmp(REAL4Sequence *a, REAL4Sequence *b)
int XLALPrintError(const char *fmt,...)
double REAL8
Double precision real floating-point number (8 bytes).
int64_t INT8
Eight-byte signed integer; on some platforms this is equivalent to long int instead.
uint32_t UINT4
Four-byte unsigned integer.
int32_t INT4
Four-byte signed integer.
char * XLALStringAppend(char *s, const char *append)
Like strcat but dynamically reallocates string with LALRealloc.
LALSeg * XLALSegCreate(const LIGOTimeGPS *start, const LIGOTimeGPS *end, const INT4 id)
This function is similar to XLALSegSet() except that it allocates memory for a new segment structure ...
int XLALSegListInit(LALSegList *seglist)
This function must be called to initialize a segment list structure before that structure can be used...
int XLALSegListClear(LALSegList *seglist)
This function must be called when you are done with a segment list, in order to free memory that was ...
int XLALSegCmp(const void *pseg0, const void *pseg1)
This is designed to be usable as a comparison function for qsort() and therefore returns a negative v...
#define SEGMENTSH_INITMAGICVAL
Distinctive value set in the 'initMagic' field to provide a check that the structure was properly ini...
int XLALSegListInitSimpleSegments(LALSegList *seglist, LIGOTimeGPS startTime, UINT4 Nseg, REAL8 Tseg)
(Re-)Initialize a segment list with Nseg 'simple' segments of length 'Tseg', starting at t0 = startTi...
int XLALSegListCoalesce(LALSegList *seglist)
The function XLALSegListCoalesce() first sorts the segments in a segment list (if not already sorted)...
int XLALSegListSort(LALSegList *seglist)
This function sorts the segments in a segment list into forward time order.
int XLALSegListFree(LALSegList *seglist)
This function frees a segment list created with XLALSegListCreate().
int XLALSegListShift(LALSegList *seglist, const LIGOTimeGPS *shift)
UNDOCUMENTED.
char * XLALSegList2String(const LALSegList *seglist)
Output an (octave) formatting of 'seglist' as a string.
int XLALSegListIsInitialized(const LALSegList *seglist)
Simple method to check whether a LALSegList is in an initialized state.
int XLALSegListKeep(LALSegList *seglist, const LIGOTimeGPS *start, const LIGOTimeGPS *end)
UNDOCUMENTED.
int XLALSegListAppend(LALSegList *seglist, const LALSeg *seg)
This function appends a segment to a segment list.
LALSegList * XLALSegListCreate(void)
This function allocates memory for a new segment list structure, initializes the segment list,...
int XLALSegSet(LALSeg *seg, const LIGOTimeGPS *start, const LIGOTimeGPS *end, const INT4 id)
This function sets the start time, the end time, and the id of a segment.
LALSeg * XLALSegListGet(LALSegList *seglist, UINT4 indx)
Get a copy of the segment at indx in the internal array.
LALSeg * XLALSegListSearch(LALSegList *seglist, const LIGOTimeGPS *gps)
The function XLALSegListSearch() determines which segment in the list, if any, contains the GPS time ...
int XLALGPSInSeg(const void *pgps, const void *pseg)
This is designed to be usable as a comparison function for bsearch() and therefore returns a negative...
#define SEGMENTSH_ALLOCBLOCK
Initial number of LALSeg spaces to allocate in memory at one time; this is intended to reduce the num...
int XLALSegListRange(const LALSegList *seglist, LIGOTimeGPS *start, LIGOTimeGPS *end)
The function XLALSegListRange() returns the start and end GPS times of the segment list.
#define XLAL_ERROR_NULL(...)
Macro to invoke a failure from a XLAL routine returning a pointer.
#define XLAL_ERROR(...)
Macro to invoke a failure from a XLAL routine returning an integer.
#define XLAL_CHECK(assertion,...)
Macro to test an assertion and invoke a failure if it is not true in a function that returns an integ...
#define XLAL_CHECK_NULL(assertion,...)
Macro to test an assertion and invoke a failure if it is not true in a function that returns a pointe...
@ XLAL_ENOMEM
Memory allocation error.
@ XLAL_SUCCESS
Success return value (not an error number)
@ XLAL_EFAULT
Invalid pointer.
@ XLAL_EFUNC
Internal function call failed bit: "or" this with existing error number.
@ XLAL_EDOM
Input domain error.
@ XLAL_EINVAL
Invalid argument.
LIGOTimeGPS * XLALGPSAdd(LIGOTimeGPS *epoch, REAL8 dt)
Adds a double to a GPS time.
LIGOTimeGPS * XLALGPSAddGPS(LIGOTimeGPS *epoch, const LIGOTimeGPS *dt)
Adds two GPS times.
int XLALGPSCmp(const LIGOTimeGPS *t0, const LIGOTimeGPS *t1)
Compares two GPS times.
REAL8 XLALGPSGetREAL8(const LIGOTimeGPS *epoch)
Returns the GPS time as a REAL8.
LIGOTimeGPS * XLALINT8NSToGPS(LIGOTimeGPS *epoch, INT8 ns)
Converts nano seconds stored as an INT8 to GPS time.
INT8 XLALGPSToINT8NS(const LIGOTimeGPS *epoch)
Converts GPS time to nano seconds stored as an INT8.
Struct holding a single segment.
LIGOTimeGPS end
Ending time of the segment.
INT4 id
Identifier (segment ID, array index, etc.) for user.
LIGOTimeGPS start
Beginning time of the segment.
Struct holding a segment list.
LALSeg * lastFound
Internal record of last segment found by a search.
UINT4 length
Number of segments in this segment list.
LALSeg * segs
Pointer to array of segments (LALSeg structures)
UINT4 sorted
Flag to indicate whether segment list is sorted.
UINT4 initMagic
Internal value to help ensure list was initialized.
UINT4 dplaces
Decimal places (0,3,6,9) to format GPS times.
size_t arraySize
Size of array for which memory is allocated.
UINT4 disjoint
Flag to indicate whether segment list is disjoint.
Epoch relative to GPS epoch, see LIGOTimeGPS type for more details.
INT4 gpsSeconds
Seconds since 0h UTC 6 Jan 1980.
INT4 gpsNanoSeconds
Residual nanoseconds.