Loading [MathJax]/extensions/TeX/AMSmath.js
LALFrame 3.0.7.1-b246709
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
LALFrStreamRead.c
Go to the documentation of this file.
1/*
2* Copyright (C) 2013 Jolien Creighton
3*
4* This program is free software; you can redistribute it and/or modify
5* it under the terms of the GNU General Public License as published by
6* the Free Software Foundation; either version 2 of the License, or
7* (at your option) any later version.
8*
9* This program is distributed in the hope that it will be useful,
10* but WITHOUT ANY WARRANTY; without even the implied warranty of
11* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12* GNU General Public License for more details.
13*
14* You should have received a copy of the GNU General Public License
15* along with with program; see the file COPYING. If not, write to the
16* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
17* MA 02110-1301 USA
18*/
19/**
20 * @addtogroup LALFrStreamRead_c
21 * @brief Provides routines for reading data from a \c LALFrStream.
22 * @details
23 * The routines described below perform either random-access or sequential
24 * reading of time-series or frequency-series data from \c LALFrStream streams.
25 * @{
26 */
27
28#include <math.h>
29
30#include <lal/LALStdlib.h>
31#include <lal/Date.h>
32#include <lal/Units.h>
33#include <lal/TimeSeries.h>
34#include <lal/FrequencySeries.h>
35#include <lal/LALFrameIO.h>
36#include <lal/LALFrStream.h>
37
38/**
39 * @brief Returns the number of data points in channel @p chname in the
40 * current frame in frame stream @p stream.
41 * @param chname String containing the name of the channel.
42 * @param stream Pointer to a \c LALFrStream structure.
43 * @returns The length of the data vector of the channel in the current frame.
44 * @retval -1 Failure.
45 */
46int XLALFrStreamGetVectorLength(const char *chname, LALFrStream * stream)
47{
48 return XLALFrFileQueryChanVectorLength(stream->file, chname, stream->pos);
49}
50
51/**
52 * @brief Returns the type code for the data type of channel @p chname in the
53 * current frame in frame stream @p stream.
54 * @param chname String containing the name of the channel.
55 * @param stream Pointer to a \c LALFrStream structure.
56 * @returns The \c LALTYPECODE value of the data type of the channel.
57 * @retval LAL_CHAR_TYPE_CODE Channel is an array of type char.
58 * @retval LAL_I2_TYPE_CODE Channel is an array of type int16_t.
59 * @retval LAL_I4_TYPE_CODE Channel is an array of type int32_t.
60 * @retval LAL_I8_TYPE_CODE Channel is an array of type int64_t.
61 * @retval LAL_UCHAR_TYPE_CODE Channel is an array of type unsigned char.
62 * @retval LAL_U2_TYPE_CODE Channel is an array of type uint16_t.
63 * @retval LAL_U4_TYPE_CODE Channel is an array of type uint32_t.
64 * @retval LAL_U8_TYPE_CODE Channel is an array of type uint64_t.
65 * @retval LAL_S_TYPE_CODE Channel is an array of type float.
66 * @retval LAL_D_TYPE_CODE Channel is an array of type double.
67 * @retval LAL_C_TYPE_CODE Channel is an array of type float complex.
68 * @retval LAL_Z_TYPE_CODE Channel is an array of type double complex.
69 * @retval -1 Failure.
70 */
72{
73 return XLALFrFileQueryChanType(stream->file, chname, stream->pos);
74}
75
76/** @cond */
77
78#define TYPE INT2
79#include "LALFrStreamReadTS_source.c"
80#undef TYPE
81
82#define TYPE INT4
83#include "LALFrStreamReadTS_source.c"
84#undef TYPE
85
86#define TYPE INT8
87#include "LALFrStreamReadTS_source.c"
88#undef TYPE
89
90#define TYPE UINT2
91#include "LALFrStreamReadTS_source.c"
92#undef TYPE
93
94#define TYPE UINT4
95#include "LALFrStreamReadTS_source.c"
96#undef TYPE
97
98#define TYPE UINT8
99#include "LALFrStreamReadTS_source.c"
100#undef TYPE
101
102#define TYPE REAL4
103#include "LALFrStreamReadTS_source.c"
104#include "LALFrStreamReadFS_source.c"
105#undef TYPE
106
107#define TYPE REAL8
108#include "LALFrStreamReadTS_source.c"
109#include "LALFrStreamReadFS_source.c"
110#undef TYPE
111
112#define TYPE COMPLEX8
113#include "LALFrStreamReadTS_source.c"
114#include "LALFrStreamReadFS_source.c"
115#undef TYPE
116
117#define TYPE COMPLEX16
118#include "LALFrStreamReadTS_source.c"
119#include "LALFrStreamReadFS_source.c"
120#undef TYPE
121
122/* scalar-to-scalar copy */
123#define COPY_S2S(dest, orig, n) \
124 do { \
125 size_t i; \
126 for (i = 0; i < n; ++i) (dest)[i] = (orig)[i]; \
127 } while (0)
128
129/* scalar-to-complex copy */
130#define COPY_S2C(dest, orig, n) \
131 do { \
132 size_t i; \
133 for (i = 0; i < n; ++i) (dest)[i].re = (orig)[i]; \
134 } while (0)
135
136/* complex-to-complex copy */
137#define COPY_C2C(dest, orig, n) \
138 do { \
139 size_t i; \
140 for (i = 0; i < n; ++i) { \
141 (dest)[i].re = (orig)[i].re; \
142 (dest)[i].im = (orig)[i].im; \
143 } \
144 } while (0)
145
146#define INPUTTS(series, desttype, origtype, promotion, stream, chname, start, duration, lengthlimit) \
147 do { \
148 origtype ## TimeSeries *origin; \
149 origin = XLALFrStreamRead##origtype##TimeSeries((stream),(chname),(start),(duration),(lengthlimit)); \
150 series = XLALCreate##desttype##TimeSeries((chname),(start),origin->f0,origin->deltaT,&origin->sampleUnits,origin->data->length); \
151 if (!origin || !series) { \
152 XLALDestroy##origtype##TimeSeries(origin); \
153 XLALDestroy##desttype##TimeSeries(series); \
154 XLAL_ERROR_NULL(XLAL_EFUNC); \
155 } \
156 COPY_##promotion(series->data->data, origin->data->data, origin->data->length); \
157 XLALDestroy##origtype##TimeSeries(origin); \
158 } while(0)
159
160#define INPUTFS(series, desttype, origtype, promotion, stream, chname, epoch) \
161 do { \
162 origtype ## FrequencySeries *origin; \
163 origin = XLALFrStreamRead##origtype##FrequencySeries((stream),(chname),(epoch)); \
164 series = XLALCreate##desttype##FrequencySeries((chname),(epoch),origin->f0,origin->deltaF,&origin->sampleUnits,origin->data->length); \
165 if (!origin || !series) { \
166 XLALDestroy##origtype##FrequencySeries(origin); \
167 XLALDestroy##desttype##FrequencySeries(series); \
168 XLAL_ERROR_NULL(XLAL_EFUNC); \
169 } \
170 COPY_##promotion(series->data->data, origin->data->data, origin->data->length); \
171 XLALDestroy##origtype##FrequencySeries(origin); \
172 } while(0)
173
174/** @endcond */
175
176
177/**
178 * @name Random-Access Time Series Reading Routines
179 *
180 * These routines allow the user to read channel data for a specified
181 * period of time. The following is an example of how to read 16 seconds of
182 * REAL8 data from channel `STRAIN` beginning at GPS time 123456789 from
183 * frame files in the current directory.
184 *
185 * @code
186 * #include <lal/LALFrStream.h>
187 * ...
188 * const char *dirname = ".";
189 * const char *pattern = "*.gwf";
190 * const char *chname = "STRAIN";
191 * LALFrStream *stream;
192 * REAL8TimeSeries *series;
193 * LIGOTimeGPS start = { 123456789 };
194 * REAL8 duration = 16.0;
195 * ...
196 * stream = XLALFrStreamOpen(dirname, pattern);
197 * series = XLALFrStreamInputREAL8TimeSeries(stream, chname, &start, duration, 0);
198 * @endcode
199 *
200 * Note that the XLALFrStreamInputREAL8TimeSeries() will convert channel data
201 * of a different datatype to REAL8 data (so, for example, if the data stored
202 * in the frame file is REAL4 data, then it is cast as REAL8 data). If this
203 * behaviour is not wanted, use XLALFrStreamReadREAL8TimeSeries() instead.
204 *
205 * @{
206 */
207
208/**
209 * @fn INT2TimeSeries *XLALFrStreamReadINT2TimeSeries(LALFrStream * stream, const char *chname, const LIGOTimeGPS * start, double duration, size_t lengthlimit)
210 * @brief Reads a time series channel from a \c LALFrStream stream with a
211 * specified start time and duration.
212 * @details
213 * This routine reads data from a specified channel from a \c LALFrStream
214 * beginning at a specified point in time and lasting a specified duration.
215 * If there is a gap in the data, this routine skips to the next contiguous
216 * set of data of the required duration.
217 * @param stream Pointer to the \c LALFrStream stream.
218 * @param chname String with the channel name to read.
219 * @param start Pointer to a LIGOTimeGPS structure specifying the start time.
220 * @param duration The duration of the data to read, in seconds.
221 * @param lengthlimit The maximum number of points to read or 0 for unlimited.
222 * @returns Pointer to a new INT2TimeSeries containing the specified data.
223 * @retval NULL Failure.
224 */
225
226/**
227 * @fn INT4TimeSeries *XLALFrStreamReadINT4TimeSeries(LALFrStream * stream, const char *chname, const LIGOTimeGPS * start, double duration, size_t lengthlimit)
228 * @brief Reads a time series channel from a \c LALFrStream stream with a
229 * specified start time and duration.
230 * @details
231 * This routine reads data from a specified channel from a \c LALFrStream
232 * beginning at a specified point in time and lasting a specified duration.
233 * If there is a gap in the data, this routine skips to the next contiguous
234 * set of data of the required duration.
235 * @param stream Pointer to the \c LALFrStream stream.
236 * @param chname String with the channel name to read.
237 * @param start Pointer to a LIGOTimeGPS structure specifying the start time.
238 * @param duration The duration of the data to read, in seconds.
239 * @param lengthlimit The maximum number of points to read or 0 for unlimited.
240 * @returns Pointer to a new INT4TimeSeries containing the specified data.
241 * @retval NULL Failure.
242 */
243
244/**
245 * @fn INT8TimeSeries *XLALFrStreamReadINT8TimeSeries(LALFrStream * stream, const char *chname, const LIGOTimeGPS * start, double duration, size_t lengthlimit)
246 * @brief Reads a time series channel from a \c LALFrStream stream with a
247 * specified start time and duration.
248 * @details
249 * This routine reads data from a specified channel from a \c LALFrStream
250 * beginning at a specified point in time and lasting a specified duration.
251 * If there is a gap in the data, this routine skips to the next contiguous
252 * set of data of the required duration.
253 * @param stream Pointer to the \c LALFrStream stream.
254 * @param chname String with the channel name to read.
255 * @param start Pointer to a LIGOTimeGPS structure specifying the start time.
256 * @param duration The duration of the data to read, in seconds.
257 * @param lengthlimit The maximum number of points to read or 0 for unlimited.
258 * @returns Pointer to a new INT8TimeSeries containing the specified data.
259 * @retval NULL Failure.
260 */
261
262/**
263 * @fn REAL8TimeSeries *XLALFrStreamReadREAL8TimeSeries(LALFrStream * stream, const char *chname, const LIGOTimeGPS * start, double duration, size_t lengthlimit)
264 * @brief Reads a time series channel from a \c LALFrStream stream with a
265 * specified start time and duration.
266 * @details
267 * This routine reads data from a specified channel from a \c LALFrStream
268 * beginning at a specified point in time and lasting a specified duration.
269 * If there is a gap in the data, this routine skips to the next contiguous
270 * set of data of the required duration.
271 * @param stream Pointer to the \c LALFrStream stream.
272 * @param chname String with the channel name to read.
273 * @param start Pointer to a LIGOTimeGPS structure specifying the start time.
274 * @param duration The duration of the data to read, in seconds.
275 * @param lengthlimit The maximum number of points to read or 0 for unlimited.
276 * @returns Pointer to a new REAL8TimeSeries containing the specified data.
277 * @retval NULL Failure.
278 */
279
280/**
281 * @fn UINT2TimeSeries *XLALFrStreamReadUINT2TimeSeries(LALFrStream * stream, const char *chname, const LIGOTimeGPS * start, double duration, size_t lengthlimit)
282 * @brief Reads a time series channel from a \c LALFrStream stream with a
283 * specified start time and duration.
284 * @details
285 * This routine reads data from a specified channel from a \c LALFrStream
286 * beginning at a specified point in time and lasting a specified duration.
287 * If there is a gap in the data, this routine skips to the next contiguous
288 * set of data of the required duration.
289 * @param stream Pointer to the \c LALFrStream stream.
290 * @param chname String with the channel name to read.
291 * @param start Pointer to a LIGOTimeGPS structure specifying the start time.
292 * @param duration The duration of the data to read, in seconds.
293 * @param lengthlimit The maximum number of points to read or 0 for unlimited.
294 * @returns Pointer to a new UINT2TimeSeries containing the specified data.
295 * @retval NULL Failure.
296 */
297
298/**
299 * @fn UINT4TimeSeries *XLALFrStreamReadUINT4TimeSeries(LALFrStream * stream, const char *chname, const LIGOTimeGPS * start, double duration, size_t lengthlimit)
300 * @brief Reads a time series channel from a \c LALFrStream stream with a
301 * specified start time and duration.
302 * @details
303 * This routine reads data from a specified channel from a \c LALFrStream
304 * beginning at a specified point in time and lasting a specified duration.
305 * If there is a gap in the data, this routine skips to the next contiguous
306 * set of data of the required duration.
307 * @param stream Pointer to the \c LALFrStream stream.
308 * @param chname String with the channel name to read.
309 * @param start Pointer to a LIGOTimeGPS structure specifying the start time.
310 * @param duration The duration of the data to read, in seconds.
311 * @param lengthlimit The maximum number of points to read or 0 for unlimited.
312 * @returns Pointer to a new UINT4TimeSeries containing the specified data.
313 * @retval NULL Failure.
314 */
315
316/**
317 * @fn UINT8TimeSeries *XLALFrStreamReadUINT8TimeSeries(LALFrStream * stream, const char *chname, const LIGOTimeGPS * start, double duration, size_t lengthlimit)
318 * @brief Reads a time series channel from a \c LALFrStream stream with a
319 * specified start time and duration.
320 * @details
321 * This routine reads data from a specified channel from a \c LALFrStream
322 * beginning at a specified point in time and lasting a specified duration.
323 * If there is a gap in the data, this routine skips to the next contiguous
324 * set of data of the required duration.
325 * @param stream Pointer to the \c LALFrStream stream.
326 * @param chname String with the channel name to read.
327 * @param start Pointer to a LIGOTimeGPS structure specifying the start time.
328 * @param duration The duration of the data to read, in seconds.
329 * @param lengthlimit The maximum number of points to read or 0 for unlimited.
330 * @returns Pointer to a new UINT8TimeSeries containing the specified data.
331 * @retval NULL Failure.
332 */
333
334/**
335 * @fn REAL4TimeSeries *XLALFrStreamReadREAL4TimeSeries(LALFrStream * stream, const char *chname, const LIGOTimeGPS * start, double duration, size_t lengthlimit)
336 * @brief Reads a time series channel from a \c LALFrStream stream with a
337 * specified start time and duration.
338 * @details
339 * This routine reads data from a specified channel from a \c LALFrStream
340 * beginning at a specified point in time and lasting a specified duration.
341 * If there is a gap in the data, this routine skips to the next contiguous
342 * set of data of the required duration.
343 * @param stream Pointer to the \c LALFrStream stream.
344 * @param chname String with the channel name to read.
345 * @param start Pointer to a LIGOTimeGPS structure specifying the start time.
346 * @param duration The duration of the data to read, in seconds.
347 * @param lengthlimit The maximum number of points to read or 0 for unlimited.
348 * @returns Pointer to a new REAL4TimeSeries containing the specified data.
349 * @retval NULL Failure.
350 */
351
352/**
353 * @fn REAL8TimeSeries *XLALFrStreamReadREAL8TimeSeries(LALFrStream * stream, const char *chname, const LIGOTimeGPS * start, double duration, size_t lengthlimit)
354 * @brief Reads a time series channel from a \c LALFrStream stream with a
355 * specified start time and duration.
356 * @details
357 * This routine reads data from a specified channel from a \c LALFrStream
358 * beginning at a specified point in time and lasting a specified duration.
359 * If there is a gap in the data, this routine skips to the next contiguous
360 * set of data of the required duration.
361 * @param stream Pointer to the \c LALFrStream stream.
362 * @param chname String with the channel name to read.
363 * @param start Pointer to a LIGOTimeGPS structure specifying the start time.
364 * @param duration The duration of the data to read, in seconds.
365 * @param lengthlimit The maximum number of points to read or 0 for unlimited.
366 * @returns Pointer to a new REAL8TimeSeries containing the specified data.
367 * @retval NULL Failure.
368 */
369
370/**
371 * @fn COMPLEX8TimeSeries *XLALFrStreamReadCOMPLEX8TimeSeries(LALFrStream * stream, const char *chname, const LIGOTimeGPS * start, double duration, size_t lengthlimit)
372 * @brief Reads a time series channel from a \c LALFrStream stream with a
373 * specified start time and duration.
374 * @details
375 * This routine reads data from a specified channel from a \c LALFrStream
376 * beginning at a specified point in time and lasting a specified duration.
377 * If there is a gap in the data, this routine skips to the next contiguous
378 * set of data of the required duration.
379 * @param stream Pointer to the \c LALFrStream stream.
380 * @param chname String with the channel name to read.
381 * @param start Pointer to a LIGOTimeGPS structure specifying the start time.
382 * @param duration The duration of the data to read, in seconds.
383 * @param lengthlimit The maximum number of points to read or 0 for unlimited.
384 * @returns Pointer to a new COMPLEX8TimeSeries containing the specified data.
385 * @retval NULL Failure.
386 */
387
388/**
389 * @fn COMPLEX16TimeSeries *XLALFrStreamReadCOMPLEX16TimeSeries(LALFrStream * stream, const char *chname, const LIGOTimeGPS * start, double duration, size_t lengthlimit)
390 * @brief Reads a time series channel from a \c LALFrStream stream with a
391 * specified start time and duration.
392 * @details
393 * This routine reads data from a specified channel from a \c LALFrStream
394 * beginning at a specified point in time and lasting a specified duration.
395 * If there is a gap in the data, this routine skips to the next contiguous
396 * set of data of the required duration.
397 * @param stream Pointer to the \c LALFrStream stream.
398 * @param chname String with the channel name to read.
399 * @param start Pointer to a LIGOTimeGPS structure specifying the start time.
400 * @param duration The duration of the data to read, in seconds.
401 * @param lengthlimit The maximum number of points to read or 0 for unlimited.
402 * @returns Pointer to a new COMPLEX16TimeSeries containing the specified data.
403 * @retval NULL Failure.
404 */
405
406/**
407 * @brief Reads a time series channel from a \c LALFrStream stream with a
408 * specified start time and duration, and performs any needed type conversion.
409 * @details
410 * This routine reads data from a specified channel from a \c LALFrStream
411 * beginning at a specified point in time and lasting a specified duration.
412 * If there is a gap in the data, this routine skips to the next contiguous
413 * set of data of the required duration. If the channel being read is not
414 * REAL8, the data is converted to type REAL8.
415 * @param stream Pointer to the \c LALFrStream stream.
416 * @param chname String with the channel name to read.
417 * @param start Pointer to a LIGOTimeGPS structure specifying the start time.
418 * @param duration The duration of the data to read, in seconds.
419 * @param lengthlimit The maximum number of points to read or 0 for unlimited.
420 * @returns Pointer to a new REAL8TimeSeries containing the specified data.
421 * @retval NULL Failure.
422 */
424 const char *chname, const LIGOTimeGPS * start, double duration,
425 size_t lengthlimit)
426{
427 REAL8TimeSeries *series;
428 LALTYPECODE typecode;
429
430 if (XLALFrStreamSeek(stream, start))
432
433 typecode = XLALFrFileQueryChanType(stream->file, chname, stream->pos);
434 switch (typecode) {
435 case LAL_I2_TYPE_CODE:
436 INPUTTS(series, REAL8, INT2, S2S, stream, chname, start, duration,
437 lengthlimit);
438 break;
439 case LAL_I4_TYPE_CODE:
440 INPUTTS(series, REAL8, INT4, S2S, stream, chname, start, duration,
441 lengthlimit);
442 break;
443 case LAL_I8_TYPE_CODE:
444 INPUTTS(series, REAL8, INT8, S2S, stream, chname, start, duration,
445 lengthlimit);
446 break;
447 case LAL_U2_TYPE_CODE:
448 INPUTTS(series, REAL8, UINT2, S2S, stream, chname, start, duration,
449 lengthlimit);
450 break;
451 case LAL_U4_TYPE_CODE:
452 INPUTTS(series, REAL8, UINT4, S2S, stream, chname, start, duration,
453 lengthlimit);
454 break;
455 case LAL_U8_TYPE_CODE:
456 INPUTTS(series, REAL8, UINT8, S2S, stream, chname, start, duration,
457 lengthlimit);
458 break;
459 case LAL_S_TYPE_CODE:
460 INPUTTS(series, REAL8, REAL4, S2S, stream, chname, start, duration,
461 lengthlimit);
462 break;
463 case LAL_D_TYPE_CODE:
464 series =
465 XLALFrStreamReadREAL8TimeSeries(stream, chname, start,
466 duration, lengthlimit);
467 if (!series)
469 break;
470 case LAL_C_TYPE_CODE:
471 case LAL_Z_TYPE_CODE:
472 XLAL_PRINT_ERROR("Cannot convert complex type to float type");
473#if __GNUC__ >= 7 && !defined __INTEL_COMPILER
474 __attribute__ ((fallthrough));
475#endif
476 default:
478 }
479 return series;
480}
481
482/**
483 * @brief Reads a time series channel from a \c LALFrStream stream with a
484 * specified start time and duration, and performs any needed type conversion.
485 * @details
486 * This routine reads data from a specified channel from a \c LALFrStream
487 * beginning at a specified point in time and lasting a specified duration.
488 * If there is a gap in the data, this routine skips to the next contiguous
489 * set of data of the required duration. If the channel being read is not
490 * COMPLEX16, the data is converted to type COMPLEX16.
491 * @param stream Pointer to the \c LALFrStream stream.
492 * @param chname String with the channel name to read.
493 * @param start Pointer to a LIGOTimeGPS structure specifying the start time.
494 * @param duration The duration of the data to read, in seconds.
495 * @param lengthlimit The maximum number of points to read or 0 for unlimited.
496 * @returns Pointer to a new COMPLEX16TimeSeries containing the specified data.
497 * @retval NULL Failure.
498 */
500 stream, const char *chname, const LIGOTimeGPS * start, double duration,
501 size_t lengthlimit)
502{
503 COMPLEX16TimeSeries *series;
504 LALTYPECODE typecode;
505
506 if (XLALFrStreamSeek(stream, start))
508
509 typecode = XLALFrFileQueryChanType(stream->file, chname, stream->pos);
510 switch (typecode) {
511 case LAL_I2_TYPE_CODE:
512 INPUTTS(series, COMPLEX16, INT2, S2S, stream, chname, start,
513 duration, lengthlimit);
514 break;
515 case LAL_I4_TYPE_CODE:
516 INPUTTS(series, COMPLEX16, INT4, S2S, stream, chname, start,
517 duration, lengthlimit);
518 break;
519 case LAL_I8_TYPE_CODE:
520 INPUTTS(series, COMPLEX16, INT8, S2S, stream, chname, start,
521 duration, lengthlimit);
522 break;
523 case LAL_U2_TYPE_CODE:
524 INPUTTS(series, COMPLEX16, UINT2, S2S, stream, chname, start,
525 duration, lengthlimit);
526 break;
527 case LAL_U4_TYPE_CODE:
528 INPUTTS(series, COMPLEX16, UINT4, S2S, stream, chname, start,
529 duration, lengthlimit);
530 break;
531 case LAL_U8_TYPE_CODE:
532 INPUTTS(series, COMPLEX16, UINT8, S2S, stream, chname, start,
533 duration, lengthlimit);
534 break;
535 case LAL_S_TYPE_CODE:
536 INPUTTS(series, COMPLEX16, REAL4, S2S, stream, chname, start,
537 duration, lengthlimit);
538 break;
539 case LAL_D_TYPE_CODE:
540 INPUTTS(series, COMPLEX16, REAL8, S2S, stream, chname, start,
541 duration, lengthlimit);
542 break;
543 case LAL_C_TYPE_CODE:
544 INPUTTS(series, COMPLEX16, COMPLEX8, S2S, stream, chname, start,
545 duration, lengthlimit);
546 break;
547 case LAL_Z_TYPE_CODE:
548 series = XLALFrStreamReadCOMPLEX16TimeSeries(stream, chname, start,
549 duration, lengthlimit);
550 if (!series)
552 break;
553 default:
555 }
556 return series;
557}
558
559/** @} */
560
561/**
562 * @name Random-Access Frequency Series Reading Routines
563 *
564 * These routines allow the user to read channel data for a specified
565 * period of time. The following is an example of how to read a frequency
566 * series REAL8 data from channel `STRAIN_PSD` beginning at GPS time 123456789
567 * from frame files in the current directory.
568 *
569 * @code
570 * #include <lal/LALFrStream.h>
571 * ...
572 * const char *dirname = ".";
573 * const char *pattern = "*.gwf";
574 * const char *chname = "STRAIN_PSD";
575 * LALFrStream *stream;
576 * REAL8FrequencySeries *series;
577 * LIGOTimeGPS start = { 123456789 };
578 * ...
579 * stream = XLALFrStreamOpen(dirname, pattern);
580 * series = XLALFrStreamInputREAL8FrequencySeries(stream, chname, &start);
581 * ...
582 * @endcode
583 *
584 * Note that the XLALFrStreamInputREAL8FrequencySeries() will convert channel
585 * data of a different datatype to REAL8 data (so, for example, if the data
586 * stored in the frame file is REAL4 data, then it is cast as REAL8 data). If
587 * this behaviour is not wanted, use XLALFrStreamReadREAL8Frequencyeries()
588 * instead.
589 * @{
590 */
591
592/**
593 * @fn REAL4FrequencySeries *XLALFrStreamReadREAL4FrequencySeries(LALFrStream * stream, const char *chname, const LIGOTimeGPS * epoch)
594 * @brief Reads a time series channel from a \c LALFrStream stream with a
595 * specified epoch.
596 * @details
597 * This routine reads data from a specified channel from a \c LALFrStream
598 * contained in a frame spanning the specified epoch.
599 * @param stream Pointer to the \c LALFrStream stream.
600 * @param chname String with the channel name to read.
601 * @param epoch Pointer to a LIGOTimeGPS structure specifying epoch.
602 * @returns Pointer to a new REAL4FrequencySeries containing the specified
603 * data.
604 * @retval NULL Failure.
605 */
606
607/**
608 * @fn REAL8FrequencySeries *XLALFrStreamReadREAL8FrequencySeries(LALFrStream * stream, const char *chname, const LIGOTimeGPS * epoch)
609 * @brief Reads a time series channel from a \c LALFrStream stream with a
610 * specified epoch.
611 * @details
612 * This routine reads data from a specified channel from a \c LALFrStream
613 * contained in a frame spanning the specified epoch.
614 * @param stream Pointer to the \c LALFrStream stream.
615 * @param chname String with the channel name to read.
616 * @param epoch Pointer to a LIGOTimeGPS structure specifying epoch.
617 * @returns Pointer to a new REAL8FrequencySeries containing the specified
618 * data.
619 * @retval NULL Failure.
620 */
621
622/**
623 * @fn COMPLEX8FrequencySeries *XLALFrStreamReadCOMPLEX8FrequencySeries(LALFrStream * stream, const char *chname, const LIGOTimeGPS * epoch)
624 * @brief Reads a time series channel from a \c LALFrStream stream with a
625 * specified epoch.
626 * @details
627 * This routine reads data from a specified channel from a \c LALFrStream
628 * contained in a frame spanning the specified epoch.
629 * @param stream Pointer to the \c LALFrStream stream.
630 * @param chname String with the channel name to read.
631 * @param epoch Pointer to a LIGOTimeGPS structure specifying epoch.
632 * @returns Pointer to a new COMPLEX8FrequencySeries containing the specified
633 * data.
634 * @retval NULL Failure.
635 */
636
637/**
638 * @fn COMPLEX16FrequencySeries *XLALFrStreamReadCOMPLEX16FrequencySeries(LALFrStream * stream, const char *chname, const LIGOTimeGPS * epoch)
639 * @brief Reads a time series channel from a \c LALFrStream stream with a
640 * specified epoch.
641 * @details
642 * This routine reads data from a specified channel from a \c LALFrStream
643 * contained in a frame spanning the specified epoch.
644 * @param stream Pointer to the \c LALFrStream stream.
645 * @param chname String with the channel name to read.
646 * @param epoch Pointer to a LIGOTimeGPS structure specifying epoch.
647 * @returns Pointer to a new COMPLEX16FrequencySeries containing the specified
648 * data.
649 * @retval NULL Failure.
650 */
651
652/**
653 * @brief Reads a time series channel from a \c LALFrStream stream with a
654 * specified epoch, and performs any needed type conversion.
655 * @details
656 * This routine reads data from a specified channel from a \c LALFrStream
657 * contained in a frame spanning the specified epoch. If the channel being
658 * read is not REAL8, the data is converted to type REAL8.
659 * @param stream Pointer to the \c LALFrStream stream.
660 * @param chname String with the channel name to read.
661 * @param epoch Pointer to a LIGOTimeGPS structure specifying epoch.
662 * @returns Pointer to a new REAL8FrequencySeries containing the specified
663 * data.
664 * @retval NULL Failure.
665 */
667 stream, const char *chname, const LIGOTimeGPS * epoch)
668{
669 REAL8FrequencySeries *series;
670 LALTYPECODE typecode;
671
672 if (XLALFrStreamSeek(stream, epoch))
674
675 typecode = XLALFrFileQueryChanType(stream->file, chname, stream->pos);
676 switch (typecode) {
677 case LAL_S_TYPE_CODE:
678 INPUTFS(series, REAL8, REAL4, S2S, stream, chname, epoch);
679 break;
680 case LAL_D_TYPE_CODE:
681 series = XLALFrStreamReadREAL8FrequencySeries(stream, chname, epoch);
682 if (!series)
684 break;
685 case LAL_C_TYPE_CODE:
686 case LAL_Z_TYPE_CODE:
687 XLAL_PRINT_ERROR("Cannot convert complex type to float type");
688#if __GNUC__ >= 7 && !defined __INTEL_COMPILER
689 __attribute__ ((fallthrough));
690#endif
691 default:
693 }
694 return series;
695}
696
697/**
698 * @brief Reads a time series channel from a \c LALFrStream stream with a
699 * specified epoch, and performs any needed type conversion.
700 * @details
701 * This routine reads data from a specified channel from a \c LALFrStream
702 * contained in a frame spanning the specified epoch. If the channel being
703 * read is not COMPLEX16, the data is converted to type COMPLEX16.
704 * @param stream Pointer to the \c LALFrStream stream.
705 * @param chname String with the channel name to read.
706 * @param epoch Pointer to a LIGOTimeGPS structure specifying epoch.
707 * @returns Pointer to a new COMPLEX16FrequencySeries containing the specified
708 * data.
709 * @retval NULL Failure.
710 */
713 const char *chname, const LIGOTimeGPS * epoch)
714{
716 LALTYPECODE typecode;
717
718 if (XLALFrStreamSeek(stream, epoch))
720
721 typecode = XLALFrFileQueryChanType(stream->file, chname, stream->pos);
722 switch (typecode) {
723 case LAL_S_TYPE_CODE:
724 INPUTFS(series, COMPLEX16, REAL4, S2S, stream, chname, epoch);
725 break;
726 case LAL_D_TYPE_CODE:
727 INPUTFS(series, COMPLEX16, REAL8, S2S, stream, chname, epoch);
728 break;
729 case LAL_C_TYPE_CODE:
730 INPUTFS(series, COMPLEX16, COMPLEX8, S2S, stream, chname, epoch);
731 break;
732 case LAL_Z_TYPE_CODE:
733 series =
735 if (!series)
737 break;
738 default:
740 }
741 return series;
742}
743
744/** @} */
745
746/**
747 * @name Sequential Time Series Reading Routines
748 *
749 * These routines are useful for reading sequential blocks of data from
750 * a \c LALFrStream stream. The following is an example of how to read
751 * REAL8 data from channel `STRAIN` in 1 second blocks starting at the
752 * beginning of a stream from frame files in the current directory.
753 *
754 * @code
755 * #include <lal/TimeSeries.h>
756 * #include <lal/LALFrStream.h>
757 * ...
758 * const char *dirname = ".";
759 * const char *pattern = "*.gwf";
760 * const char *chname = "STRAIN";
761 * LIGOTimeGPS epoch = LIGOTIMEGPSZERO; // value is unimportant
762 * LALFrStream *stream;
763 * REAL8TimeSeries *series;
764 * REAL8 duration = 1.0;
765 * ...
766 * stream = XLALFrStreamOpen(dirname, pattern);
767 *
768 * // initial values of metadata other than the name are not important
769 * series = XLALCreateREAL8TimeSeries(chname, &epoch, 0.0, 0.0, &lalDimensionlessUnit, 0);
770 *
771 * // update series metadata, particularly the sample rate deltaT
772 * XLALFrStreamGetREAL8TimeSeriesMetadata(series, stream);
773 *
774 * // allocate the required amount of data to the series
775 * series = XLALResizeREAL8TimeSeries(series, 0, duration / series->deltaT);
776 *
777 * // read data from stream one second at a time
778 * while (! XLALFrStreamEnd(stream)) {
779 * // get the next second of data
780 * XLALFrStreamGetREAL8TimeSeries(series, stream);
781 * ...
782 * }
783 * ...
784 * @endcode
785 * @{
786 */
787
788/**
789 * @fn int XLALFrStreamGetINT2TimeSeries(INT2TimeSeries * series, LALFrStream * stream)
790 * @brief Reads time series data from the current position in a \c LALFrStream stream.
791 * @details
792 * This routine is provided a time series @p series that will be populated with
793 * data read from @p stream. The channel name of the data to be read is given
794 * by `stream->name` and the amount of data to be read is given by
795 * `stream->data->length`. The remaining metadata quantities in @p stream
796 * are populated: `stream->epoch`, `stream->deltaT`, `stream->sampleUnits`.
797 * If `stream->data` is NULL or `stream->data->length` is 0, only the
798 * metadata is read; otherwise `stream->data->data` is populated with the
799 * channel data. The data begins at the current position of the stream,
800 * but if a gap is encountered, the stream skips forward until a gap-less
801 * stretch of data that is long enough is found. If this happens, the
802 * ::LAL_FR_STREAM_GAP flag is set on the LALFrStreamState state of the stream.
803 * @param[in, out] series Pointer to the time series containing the name of the channel to be read and an allocated sequence of the length of data to be read.
804 * @param stream Pointer to a \c LALFrStream stream.
805 * @retval 0 Success.
806 * @retval <0 Read error or end of stream encountered.
807 */
808
809/**
810 * @fn int XLALFrStreamGetINT4TimeSeries(INT4TimeSeries * series, LALFrStream * stream)
811 * @copydoc XLALFrStreamGetINT2TimeSeries()
812 */
813
814/**
815 * @fn int XLALFrStreamGetINT8TimeSeries(INT8TimeSeries * series, LALFrStream * stream)
816 * @copydoc XLALFrStreamGetINT2TimeSeries()
817 */
818
819/**
820 * @fn int XLALFrStreamGetUINT2TimeSeries(UINT2TimeSeries * series, LALFrStream * stream)
821 * @copydoc XLALFrStreamGetINT2TimeSeries()
822 */
823
824/**
825 * @fn int XLALFrStreamGetUINT4TimeSeries(UINT4TimeSeries * series, LALFrStream * stream)
826 * @copydoc XLALFrStreamGetINT2TimeSeries()
827 */
828
829/**
830 * @fn int XLALFrStreamGetUINT8TimeSeries(UINT8TimeSeries * series, LALFrStream * stream)
831 * @copydoc XLALFrStreamGetINT2TimeSeries()
832 */
833
834/**
835 * @fn int XLALFrStreamGetREAL4TimeSeries(REAL4TimeSeries * series, LALFrStream * stream)
836 * @copydoc XLALFrStreamGetINT2TimeSeries()
837 */
838
839/**
840 * @fn int XLALFrStreamGetREAL8TimeSeries(REAL8TimeSeries * series, LALFrStream * stream)
841 * @copydoc XLALFrStreamGetINT2TimeSeries()
842 */
843
844/**
845 * @fn int XLALFrStreamGetCOMPLEX8TimeSeries(COMPLEX8TimeSeries * series, LALFrStream * stream)
846 * @copydoc XLALFrStreamGetINT2TimeSeries()
847 */
848
849/**
850 * @fn int XLALFrStreamGetCOMPLEX16TimeSeries(COMPLEX16TimeSeries * series, LALFrStream * stream)
851 * @copydoc XLALFrStreamGetINT2TimeSeries()
852 */
853
854/**
855 * @fn int XLALFrStreamGetINT2TimeSeriesMetadata(INT2TimeSeries * series, LALFrStream * stream)
856 * @brief Reads time series metadata from the current position in a \c LALFrStream stream.
857 * @details
858 * This routine is provided a time series @p series that will be populated with
859 * metadata read from @p stream. The metadata is associated with the channel
860 * whose name is specified by by `stream->name`. The remaining metadata
861 * quantities in @p stream are populated: `stream->epoch`, `stream->deltaT`,
862 * `stream->sampleUnits`. No data is actually read by this routine.
863 * @param[in, out] series Pointer to the time series containing the name of the channel to be read and an allocated sequence of the length of data to be read.
864 * @param stream Pointer to a \c LALFrStream stream.
865 * @retval 0 Success.
866 * @retval <0 Failure.
867 */
868
869/**
870 * @fn int XLALFrStreamGetINT4TimeSeriesMetadata(INT4TimeSeries * series, LALFrStream * stream)
871 * @copydoc XLALFrStreamGetINT2TimeSeriesMetadata()
872 */
873
874/**
875 * @fn int XLALFrStreamGetINT8TimeSeriesMetadata(INT8TimeSeries * series, LALFrStream * stream)
876 * @copydoc XLALFrStreamGetINT2TimeSeriesMetadata()
877 */
878
879/**
880 * @fn int XLALFrStreamGetUINT2TimeSeriesMetadata(UINT2TimeSeries * series, LALFrStream * stream)
881 * @copydoc XLALFrStreamGetINT2TimeSeriesMetadata()
882 */
883
884/**
885 * @fn int XLALFrStreamGetUINT4TimeSeriesMetadata(UINT4TimeSeries * series, LALFrStream * stream)
886 * @copydoc XLALFrStreamGetINT2TimeSeriesMetadata()
887 */
888
889/**
890 * @fn int XLALFrStreamGetUINT8TimeSeriesMetadata(UINT8TimeSeries * series, LALFrStream * stream)
891 * @copydoc XLALFrStreamGetINT2TimeSeriesMetadata()
892 */
893
894/**
895 * @fn int XLALFrStreamGetREAL4TimeSeriesMetadata(REAL4TimeSeries * series, LALFrStream * stream)
896 * @copydoc XLALFrStreamGetINT2TimeSeriesMetadata()
897 */
898
899/**
900 * @fn int XLALFrStreamGetREAL8TimeSeriesMetadata(REAL8TimeSeries * series, LALFrStream * stream)
901 * @copydoc XLALFrStreamGetINT2TimeSeriesMetadata()
902 */
903
904/**
905 * @fn int XLALFrStreamGetCOMPLEX8TimeSeriesMetadata(COMPLEX8TimeSeries * series, LALFrStream * stream)
906 * @copydoc XLALFrStreamGetINT2TimeSeriesMetadata()
907 */
908
909/**
910 * @fn int XLALFrStreamGetCOMPLEX16TimeSeriesMetadata(COMPLEX16TimeSeries * series, LALFrStream * stream)
911 * @copydoc XLALFrStreamGetINT2TimeSeriesMetadata()
912 */
913
914/** @} */
915
916/**
917 * @name Sequential Frequency Series Reading Routines
918 *
919 * These routines are useful for reading sequential blocks of data from
920 * a \c LALFrStream stream. The following is an example of how to read
921 * REAL8 data from channel `STRAIN_PSD` in from each frame starting at the
922 * beginning of a stream from frame files in the current directory.
923 *
924 * @code
925 * #include <stdio.h>
926 * #include <lal/Sequence.h>
927 * #include <lal/LALFrStream.h>
928 * ...
929 * const char *dirname = ".";
930 * const char *pattern = "*.gwf";
931 * const char *chname = "STRAIN_PSD";
932 * LALFrStream *stream;
933 * UINT4 length;
934 * ...
935 * stream = XLALFrStreamOpen(dirname, pattern);
936 *
937 * // read frequency series from each frame in stream sequentially
938 * while (! XLALFrStreamEnd(stream)) {
939 * REAL8FrequencySeries series;
940 * snprintf(series.name, sizeof(series.name), "%s", chname);
941 * XLALFrStreamGetREAL8FrequencySeries(&series, stream);
942 * XLALFrStreamNext(stream);
943 * ...
944 * XLALDestroyREAL8Sequence(&series.data);
945 * }
946 * ...
947 * @endcode
948 * @{
949 */
950
951/**
952 * @fn int XLALFrStreamGetREAL4FrequencySeries(REAL4FrequencySeries * series, LALFrStream * stream);
953 * @brief Reads frequency series data from the current frame in a \c LALFrStream
954 * stream.
955 * @details
956 * This routine is provided a frequency series @p series that will be populated
957 * with data read from the current frame in @p stream. The channel name of
958 * the data to read is given by `series->name`. The metadata contained in
959 * @p series is over-written with the metadata of the named frequency series in
960 * @p stream, and `series->data` will be allocated and set to the frequency
961 * series data contained in the frame.
962 *
963 * @attention
964 * `series->data` is over-written by this routine; it should be unallocated
965 * prior to calling this routine.
966 *
967 * @param[in,out] series Pointer to the frequency series containing the name
968 * of the channel to be read.
969 * @param stream Pointer to a \c LALFrStream stream.
970 *
971 * @retval 0 Success.
972 * @retval <0 Failure.
973 */
974
975/**
976 * @fn int XLALFrStreamGetREAL8FrequencySeries(REAL8FrequencySeries * series, LALFrStream * stream);
977 * @copydoc XLALFrStreamGetREAL4FrequencySeries()
978 */
979
980/**
981 * @fn int XLALFrStreamGetCOMPLEX8FrequencySeries(COMPLEX8FrequencySeries * series, LALFrStream * stream);
982 * @copydoc XLALFrStreamGetREAL4FrequencySeries()
983 */
984
985/**
986 * @fn int XLALFrStreamGetCOMPLEX16FrequencySeries(COMPLEX16FrequencySeries * series, LALFrStream * stream);
987 * @copydoc XLALFrStreamGetREAL4FrequencySeries()
988 */
989
990/** @} */
991
992/** @} */
#define __attribute__(x)
LALTYPECODE
uint64_t UINT8
double complex COMPLEX16
double REAL8
int16_t INT2
int64_t INT8
uint16_t UINT2
uint32_t UINT4
float complex COMPLEX8
int32_t INT4
float REAL4
LAL_C_TYPE_CODE
LAL_U2_TYPE_CODE
LAL_Z_TYPE_CODE
LAL_S_TYPE_CODE
LAL_I2_TYPE_CODE
LAL_I8_TYPE_CODE
LAL_D_TYPE_CODE
LAL_I4_TYPE_CODE
LAL_U8_TYPE_CODE
LAL_U4_TYPE_CODE
int XLALFrStreamSeek(LALFrStream *stream, const LIGOTimeGPS *epoch)
Seeks a LALFrStream stream to data at a given time.
Definition: LALFrStream.c:542
REAL8FrequencySeries * XLALFrStreamReadREAL8FrequencySeries(LALFrStream *stream, const char *chname, const LIGOTimeGPS *epoch)
Reads a time series channel from a LALFrStream stream with a specified epoch.
LALTYPECODE XLALFrStreamGetTimeSeriesType(const char *chname, LALFrStream *stream)
Returns the type code for the data type of channel chname in the current frame in frame stream stream...
COMPLEX16TimeSeries * XLALFrStreamInputCOMPLEX16TimeSeries(LALFrStream *stream, const char *chname, const LIGOTimeGPS *start, double duration, size_t lengthlimit)
Reads a time series channel from a LALFrStream stream with a specified start time and duration,...
COMPLEX16FrequencySeries * XLALFrStreamReadCOMPLEX16FrequencySeries(LALFrStream *stream, const char *chname, const LIGOTimeGPS *epoch)
Reads a time series channel from a LALFrStream stream with a specified epoch.
REAL8FrequencySeries * XLALFrStreamInputREAL8FrequencySeries(LALFrStream *stream, const char *chname, const LIGOTimeGPS *epoch)
Reads a time series channel from a LALFrStream stream with a specified epoch, and performs any needed...
int XLALFrStreamGetVectorLength(const char *chname, LALFrStream *stream)
Returns the number of data points in channel chname in the current frame in frame stream stream.
REAL8TimeSeries * XLALFrStreamInputREAL8TimeSeries(LALFrStream *stream, const char *chname, const LIGOTimeGPS *start, double duration, size_t lengthlimit)
Reads a time series channel from a LALFrStream stream with a specified start time and duration,...
COMPLEX16TimeSeries * XLALFrStreamReadCOMPLEX16TimeSeries(LALFrStream *stream, const char *chname, const LIGOTimeGPS *start, REAL8 duration, size_t lengthlimit)
Reads a time series channel from a LALFrStream stream with a specified start time and duration.
COMPLEX16FrequencySeries * XLALFrStreamInputCOMPLEX16FrequencySeries(LALFrStream *stream, const char *chname, const LIGOTimeGPS *epoch)
Reads a time series channel from a LALFrStream stream with a specified epoch, and performs any needed...
REAL8TimeSeries * XLALFrStreamReadREAL8TimeSeries(LALFrStream *stream, const char *chname, const LIGOTimeGPS *start, REAL8 duration, size_t lengthlimit)
Reads a time series channel from a LALFrStream stream with a specified start time and duration.
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.
Definition: LALFrameIO.c:148
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.
Definition: LALFrameIO.c:192
#define XLAL_ERROR_NULL(...)
#define XLAL_PRINT_ERROR(...)
XLAL_EFUNC
XLAL_ETYPE
This structure details the state of the frame stream.
Definition: LALFrStream.h:95
LALFrFile * file
Definition: LALFrStream.h:101
enum @1 epoch