Loading [MathJax]/extensions/TeX/AMSsymbols.js
LALPulsar 7.1.1.1-b246709
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
makeMultiChFrame.c
Go to the documentation of this file.
1/*
2 * Copyright (C) 2023 Karl Wette
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/*
21 * Author: Karl Wette
22 *
23 * Read a REAL8 channel from frame files, and output new frame files with a
24 * variety of channels types, to test whether MakeSFTs can handle them.
25 */
26
27#include <stdio.h>
28
29#include <lal/LALStdlib.h>
30#include <lal/Units.h>
31#include <lal/TimeSeries.h>
32#include <lal/LALFrStream.h>
33#include <lal/VectorMath.h>
34
35int main( int argc, char *argv[] )
36{
37
38 if ( argc != 4 ) {
39 printf( "usage: %s <framecache> <channel> <outdir>\n", argv[0] );
40 return 1;
41 }
42
43 /* Open frame stream from cache */
44 LALCache *framecache = XLALCacheImport( argv[1] );
45 XLAL_CHECK_MAIN( framecache != NULL, XLAL_EFUNC );
46 LALFrStream *framestream = XLALFrStreamCacheOpen( framecache );
47 XLAL_CHECK_MAIN( framestream != NULL, XLAL_EFUNC );
48
49 /* Set up reading time series from REAL8 channel */
50 REAL8TimeSeries *time_series_REAL8 = XLALCreateREAL8TimeSeries( argv[2], NULL, 0.0, 0.0, &lalDimensionlessUnit, 0 );
51 XLAL_CHECK_MAIN( time_series_REAL8 != NULL, XLAL_EFUNC );
53 time_series_REAL8 = XLALResizeREAL8TimeSeries( time_series_REAL8, 0, 1800.0 / time_series_REAL8->deltaT );
54 XLAL_CHECK_MAIN( time_series_REAL8 != NULL, XLAL_EFUNC );
55
56 /* Until end of frame stream */
57 while ( !XLALFrStreamEnd( framestream ) ) {
58
59 /* Read next chunk of time series */
60 strcpy( time_series_REAL8->name, argv[2] );
61 XLAL_CHECK_MAIN( XLALFrStreamGetREAL8TimeSeries( time_series_REAL8, framestream ) == XLAL_SUCCESS, XLAL_EFUNC );
62
63 /* Create output frame */
64 LALFrameH *outframe = XLALFrameNew( &time_series_REAL8->epoch, 1800.0, "MultiChFrame", 1, 0, 0 );
65 XLAL_CHECK_MAIN( outframe != NULL, XLAL_EFUNC );
66
67 /* Make REAL4 copy of REAL8 time series */
68 REAL4TimeSeries *time_series_REAL4 = XLALConvertREAL8TimeSeriesToREAL4( time_series_REAL8 );
69 XLAL_CHECK_MAIN( time_series_REAL4 != NULL, XLAL_EFUNC );
70
71 /* Add Adc channels */
72 snprintf( time_series_REAL8->name, sizeof( time_series_REAL8->name ), "%c%c:AdcREAL8", argv[2][0], argv[2][1] );
74 snprintf( time_series_REAL4->name, sizeof( time_series_REAL4->name ), "%c%c:AdcREAL4", argv[2][0], argv[2][1] );
76
77 /* Scale time series */
78 XLAL_CHECK_MAIN( XLALVectorScaleREAL8( time_series_REAL8->data->data, 1.234, time_series_REAL8->data->data, time_series_REAL8->data->length ) == XLAL_SUCCESS, XLAL_EFUNC );
79 XLAL_CHECK_MAIN( XLALVectorScaleREAL4( time_series_REAL4->data->data, 1.234, time_series_REAL4->data->data, time_series_REAL4->data->length ) == XLAL_SUCCESS, XLAL_EFUNC );
80
81 /* Add Proc channels */
82 snprintf( time_series_REAL8->name, sizeof( time_series_REAL8->name ), "%c%c:ProcREAL8", argv[2][0], argv[2][1] );
84 snprintf( time_series_REAL4->name, sizeof( time_series_REAL4->name ), "%c%c:ProcREAL4", argv[2][0], argv[2][1] );
86
87 /* Scale time series */
88 XLAL_CHECK_MAIN( XLALVectorScaleREAL8( time_series_REAL8->data->data, 2.345, time_series_REAL8->data->data, time_series_REAL8->data->length ) == XLAL_SUCCESS, XLAL_EFUNC );
89 XLAL_CHECK_MAIN( XLALVectorScaleREAL4( time_series_REAL4->data->data, 2.345, time_series_REAL4->data->data, time_series_REAL4->data->length ) == XLAL_SUCCESS, XLAL_EFUNC );
90
91 /* Add Sim channels */
92 snprintf( time_series_REAL8->name, sizeof( time_series_REAL8->name ), "%c%c:SimREAL8", argv[2][0], argv[2][1] );
94 snprintf( time_series_REAL4->name, sizeof( time_series_REAL4->name ), "%c%c:SimREAL4", argv[2][0], argv[2][1] );
96
97 /* Write output frame */
98 char *fname = XLALStringAppendFmt( NULL, "%s/%c-%c%c_%s-%d-%d.gwf",
99 argv[3],
100 argv[2][0],
101 argv[2][0], argv[2][1],
102 "MultiChFrame",
103 time_series_REAL8->epoch.gpsSeconds,
104 1800 );
105 XLAL_CHECK_MAIN( fname != NULL, XLAL_EFUNC );
106 XLAL_CHECK_MAIN( XLALFrameWrite( outframe, fname ) == XLAL_SUCCESS, XLAL_EFUNC );
107
108 /* Free memory */
109 XLALDestroyREAL4TimeSeries( time_series_REAL4 );
110 XLALFree( fname );
111
112 }
113
114 /* Free memory */
115 XLALDestroyREAL8TimeSeries( time_series_REAL8 );
116 XLALFrStreamClose( framestream );
117 XLALDestroyCache( framecache );
118
120
121 return 0;
122
123}
void LALCheckMemoryLeaks(void)
void XLALDestroyCache(LALCache *cache)
LALCache * XLALCacheImport(const char *fname)
int XLALFrStreamClose(LALFrStream *stream)
int XLALFrStreamEnd(LALFrStream *stream)
LALFrStream * XLALFrStreamCacheOpen(LALCache *cache)
int XLALFrStreamGetREAL8TimeSeriesMetadata(REAL8TimeSeries *series, LALFrStream *stream)
int XLALFrStreamGetREAL8TimeSeries(REAL8TimeSeries *series, LALFrStream *stream)
int XLALFrameAddREAL8TimeSeriesSimData(LALFrameH *frame, const REAL8TimeSeries *series)
int XLALFrameAddREAL8TimeSeriesAdcData(LALFrameH *frame, const REAL8TimeSeries *series)
LALFrameUFrameH LALFrameH
int XLALFrameWrite(LALFrameH *frame, const char *fname)
int XLALFrameAddREAL4TimeSeriesAdcData(LALFrameH *frame, const REAL4TimeSeries *series)
int XLALFrameAddREAL4TimeSeriesSimData(LALFrameH *frame, const REAL4TimeSeries *series)
LALFrameH * XLALFrameNew(const LIGOTimeGPS *epoch, double duration, const char *project, int run, int frnum, INT8 detectorFlags)
int XLALFrameAddREAL4TimeSeriesProcData(LALFrameH *frame, const REAL4TimeSeries *series)
int XLALFrameAddREAL8TimeSeriesProcData(LALFrameH *frame, const REAL8TimeSeries *series)
void XLALFree(void *p)
char * XLALStringAppendFmt(char *s, const char *fmt,...) _LAL_GCC_PRINTF_FORMAT_(2
void XLALDestroyREAL8TimeSeries(REAL8TimeSeries *series)
REAL4TimeSeries * XLALConvertREAL8TimeSeriesToREAL4(const REAL8TimeSeries *series)
REAL8TimeSeries * XLALResizeREAL8TimeSeries(REAL8TimeSeries *series, int first, size_t length)
void XLALDestroyREAL4TimeSeries(REAL4TimeSeries *series)
REAL8TimeSeries * XLALCreateREAL8TimeSeries(const CHAR *name, const LIGOTimeGPS *epoch, REAL8 f0, REAL8 deltaT, const LALUnit *sampleUnits, size_t length)
const LALUnit lalDimensionlessUnit
int XLALVectorScaleREAL4(REAL4 *out, REAL4 scalar, const REAL4 *in, const UINT4 len)
int XLALVectorScaleREAL8(REAL8 *out, REAL8 scalar, const REAL8 *in, const UINT4 len)
#define XLAL_CHECK_MAIN(assertion,...)
XLAL_SUCCESS
XLAL_EFUNC
int main(int argc, char *argv[])
CHAR name[LALNameLength]
REAL4Sequence * data
REAL4 * data
REAL8Sequence * data
LIGOTimeGPS epoch
CHAR name[LALNameLength]
REAL8 * data