Loading [MathJax]/extensions/TeX/AMSsymbols.js
LALFrame 3.0.7.1-8a6b96f
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
utils.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#include <stdlib.h>
21#include <string.h>
22#include <lal/LALError.h>
23#include <lal/LALFrameU.h>
24#include "utils.h"
25
26LALFrameUFrameH *framecpy(LALFrameUFrFile * frfile, size_t pos)
27{
28 LALFrameUFrameH *iframe;
29 LALFrameUFrameH *oframe;
30 iframe = XLALFrameUFrameHRead(frfile, pos);
31 oframe = framedup(iframe);
33 return oframe;
34}
35
37{
39 const char *name;
40 double tfp, tip, dt;
41 int frnum, run;
42
43 if (!frame)
44 return NULL;
45
47 tfp = XLALFrameUFrameHQueryGTimeModf(&tip, frame);
49 frnum = XLALFrameUFrameHQueryFrame(frame);
50 run = XLALFrameUFrameHQueryRun(frame);
51
52 output = XLALFrameUFrameHAlloc(name, tip, tfp, dt, frnum);
54
55 return output;
56}
57
58int copydetectors(LALFrameUFrameH * frame, LALFrameUFrFile * frfile)
59{
60 LALFrameUFrTOC *toc;
61 size_t ndet, det;
62 toc = XLALFrameUFrTOCRead(frfile);
63
64 /* loop over detectors in input file */
66 for (det = 0; det < ndet; ++det) {
67 const char *name;
68 LALFrameUFrDetector *detector;
70 detector = XLALFrameUFrDetectorRead(frfile, name);
71 copydetector(frame, detector);
73 }
74
76 return 0;
77}
78
79int copydetector(LALFrameUFrameH * frame, LALFrameUFrDetector * detector)
80{
81 const char *name;
82 const char *prefix;
83 double longitude;
84 double latitude;
85 double elevation;
86 double azimuthx;
87 double azimuthy;
88 double altitudex;
89 double altitudey;
90 double midpointx;
91 double midpointy;
92 int loctime;
93
94 LALFrameUFrDetector *detectorcopy;
95
96 if (!frame || !detector)
97 return -1;
98
100 prefix = XLALFrameUFrDetectorQueryPrefix(detector);
101 loctime = XLALFrameUFrDetectorQueryLocalTime(detector);
102 longitude = XLALFrameUFrDetectorQueryLongitude(detector);
103 latitude = XLALFrameUFrDetectorQueryLatitude(detector);
104 elevation = XLALFrameUFrDetectorQueryElevation(detector);
105 azimuthx = XLALFrameUFrDetectorQueryArmXAzimuth(detector);
106 altitudex = XLALFrameUFrDetectorQueryArmXAltitude(detector);
107 midpointx = XLALFrameUFrDetectorQueryArmXMidpoint(detector);
108 azimuthy = XLALFrameUFrDetectorQueryArmYAzimuth(detector);
109 altitudey = XLALFrameUFrDetectorQueryArmYAltitude(detector);
110 midpointy = XLALFrameUFrDetectorQueryArmYMidpoint(detector);
111
112 detectorcopy =
113 XLALFrameUFrDetectorAlloc(name, prefix, latitude, longitude,
114 elevation, azimuthx, azimuthy, altitudex, altitudey, midpointx,
115 midpointy, loctime);
116 XLALFrameUFrameHFrDetectorAdd(frame, detectorcopy);
117 XLALFrameUFrDetectorFree(detectorcopy);
118 return 0;
119}
120
121int copychannels(LALFrameUFrameH * frame, LALFrameUFrFile * frfile,
122 size_t pos, const char *match)
123{
124 LALFrameUFrTOC *toc;
125 size_t nadc, adc;
126 size_t nproc, proc;
127 size_t nsim, sim;
128
129 toc = XLALFrameUFrTOCRead(frfile);
130
131 /* loop over channels in input file */
132
133 nadc = XLALFrameUFrTOCQueryAdcN(toc);
134 for (adc = 0; adc < nadc; ++adc) {
135 const char *name;
136 LALFrameUFrChan *channel;
138 if (match && strcmp(name, match))
139 continue; /*does not match */
140 channel = XLALFrameUFrChanRead(frfile, name, pos);
143 }
144
145 nproc = XLALFrameUFrTOCQueryProcN(toc);
146 for (proc = 0; proc < nproc; ++proc) {
147 const char *name;
148 LALFrameUFrChan *channel;
150 if (match && strcmp(name, match))
151 continue; /*does not match */
152 channel = XLALFrameUFrChanRead(frfile, name, pos);
155 }
156
157 nsim = XLALFrameUFrTOCQuerySimN(toc);
158 for (sim = 0; sim < nsim; ++sim) {
159 const char *name;
160 LALFrameUFrChan *channel;
162 if (match && strcmp(name, match))
163 continue; /*does not match */
164 channel = XLALFrameUFrChanRead(frfile, name, pos);
167 }
168
170 return 0;
171}
172
173int copychannel(LALFrameUFrameH * frame, LALFrameUFrChan * channel,
174 int chantype)
175{
176 const char *channame;
177 const char *vectname;
178 int dtype;
179 size_t nbytes;
180 size_t ndata;
181 void *dataorig;
182 void *datacopy;
183 const char *unity;
184 const char *unitx;
185 double toffset;
186 double x0;
187 double dx;
188 LALFrameUFrChan *chancopy;
189
190 if (!frame || !channel)
191 return -1;
192
196
206
207 switch (chantype) {
208 case ADC_CHAN_TYPE:
209 chancopy = XLALFrameUFrAdcChanAlloc(channame, dtype, ndata);
210 break;
211 case PROC_CHAN_TYPE:
212 chancopy =
216 break;
217 case SIM_CHAN_TYPE:
218 chancopy = XLALFrameUFrSimChanAlloc(channame, dtype, ndata);
219 break;
220 default:
221 lalAbortHook("%s: unsupported chantype=%i\n", __func__, chantype);
222 return 1;
223 }
224
225 XLALFrameUFrChanSetTimeOffset(chancopy, toffset);
226
227 XLALFrameUFrChanVectorAlloc(chancopy, dtype, ndata);
228 XLALFrameUFrChanVectorSetName(chancopy, vectname);
229 XLALFrameUFrChanVectorSetUnitY(chancopy, unity);
230 XLALFrameUFrChanVectorSetUnitX(chancopy, unitx);
232 XLALFrameUFrChanVectorSetDx(chancopy, dx);
233 datacopy = XLALFrameUFrChanVectorQueryData(chancopy);
234 memcpy(datacopy, dataorig, nbytes);
235 XLALFrameUFrameHFrChanAdd(frame, chancopy);
236 XLALFrameUFrChanFree(chancopy);
237 return 0;
238}
void(* lalAbortHook)(const char *,...)
const char *const name
int XLALFrameUFrameHQueryFrame(const LALFrameUFrameH *frame)
Query FrameH structure for the frame number.
Definition: LALFrameU.c:250
const char * XLALFrameUFrTOCQuerySimName(const LALFrameUFrTOC *toc, size_t sim)
Query FrTOC structure for the name of a FrSimData structure.
Definition: LALFrameU.c:180
LALFrameUFrameH * XLALFrameUFrameHAlloc(const char *name, double start1, double start2, double dt, int frnum)
Allocate memory for a new frame header FrameH structure.
Definition: LALFrameU.c:210
LALFrameUFrDetector * XLALFrameUFrDetectorAlloc(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)
Allocate memory for a new detector FrDetector structure.
Definition: LALFrameU.c:440
double XLALFrameUFrDetectorQueryElevation(const LALFrameUFrDetector *detector)
Query FrDetector structure for the detector elevation.
Definition: LALFrameU.c:468
double XLALFrameUFrDetectorQueryLatitude(const LALFrameUFrDetector *detector)
Query FrDetector structure for the detector latitude.
Definition: LALFrameU.c:463
void * XLALFrameUFrChanVectorQueryData(const LALFrameUFrChan *channel)
Query FrChan structure for the data pointer in its FrVect structure.
Definition: LALFrameU.c:360
int XLALFrameUFrChanVectorQueryType(const LALFrameUFrChan *channel)
Query FrChan structure for the data type of its FrVect structure.
Definition: LALFrameU.c:355
int XLALFrameUFrameHFrDetectorAdd(LALFrameUFrameH *frame, LALFrameUFrDetector *detector)
Add a FrDetector structure to a FrameH structure.
Definition: LALFrameU.c:230
int XLALFrameUFrChanSetTimeOffset(LALFrameUFrChan *channel, double timeOffset)
Set the time offset in a FrChan structure.
Definition: LALFrameU.c:320
const char * XLALFrameUFrChanVectorQueryName(const LALFrameUFrChan *channel)
Query FrChan structure for the name of its FrVect structure.
Definition: LALFrameU.c:345
void XLALFrameUFrTOCFree(LALFrameUFrTOC *toc)
Free a FrTOC structure.
Definition: LALFrameU.c:140
LALFrameUFrChan * XLALFrameUFrChanRead(LALFrameUFrFile *stream, const char *name, size_t pos)
Read a channel FrChan structure from a FrFile stream.
Definition: LALFrameU.c:285
size_t XLALFrameUFrTOCQuerySimN(const LALFrameUFrTOC *toc)
Query FrTOC structure for number of FrSimData structures.
Definition: LALFrameU.c:175
void XLALFrameUFrameHFree(LALFrameUFrameH *frame)
Free a FrameH structure.
Definition: LALFrameU.c:205
void XLALFrameUFrChanFree(LALFrameUFrChan *channel)
Free a FrChan structure.
Definition: LALFrameU.c:280
int XLALFrameUFrChanVectorSetDx(LALFrameUFrChan *channel, double dx)
Set the sampling interval for the data in the FrVect structure contained in a FrChan structure.
Definition: LALFrameU.c:410
int XLALFrameUFrameHFrChanAdd(LALFrameUFrameH *frame, LALFrameUFrChan *channel)
Add a FrChan structure to a FrameH structure.
Definition: LALFrameU.c:225
const char * XLALFrameUFrDetectorQueryPrefix(const LALFrameUFrDetector *detector)
Query FrDetector structure for the detector prefix.
Definition: LALFrameU.c:453
struct tagLALFrameUFrameH LALFrameUFrameH
Incomplete type for a frame header FrameH structure.
Definition: LALFrameU.h:64
int XLALFrameUFrChanVectorExpand(LALFrameUFrChan *channel)
Expands a FrVect structure within a FrChan structure.
Definition: LALFrameU.c:340
LALFrameUFrChan * XLALFrameUFrSimChanAlloc(const char *name, int dtype, size_t ndata)
Allocate memory for a new FrChan structure of FrSimData type.
Definition: LALFrameU.c:295
int XLALFrameUFrChanVectorSetStartX(LALFrameUFrChan *channel, double x0)
Set the starting value for the domain of the data in the FrVect structure contained in a FrChan struc...
Definition: LALFrameU.c:415
double XLALFrameUFrameHQueryDt(const LALFrameUFrameH *frame)
Query FrameH structure for the duration.
Definition: LALFrameU.c:270
int XLALFrameUFrChanVectorSetUnitY(LALFrameUFrChan *channel, const char *unit)
Set the units of the data in the FrVect structure contained in a FrChan structure.
Definition: LALFrameU.c:425
double XLALFrameUFrChanQueryTimeOffset(const LALFrameUFrChan *channel)
Query FrChan structure for time offset for this channel.
Definition: LALFrameU.c:310
LALFrameUFrTOC * XLALFrameUFrTOCRead(LALFrameUFrFile *stream)
Read the table of contents FrTOC structure for a FrFile stream.
Definition: LALFrameU.c:145
LALFrameUFrChan * XLALFrameUFrAdcChanAlloc(const char *name, int dtype, size_t ndata)
Allocate memory for a new FrChan structure of FrAdcData type.
Definition: LALFrameU.c:290
LALFrameUFrameH * XLALFrameUFrameHRead(LALFrameUFrFile *stream, int pos)
Read a frame header FrameH structure from a FrFile stream.
Definition: LALFrameU.c:215
size_t XLALFrameUFrTOCQueryProcN(const LALFrameUFrTOC *toc)
Query FrTOC structure for number of FrProcData structures.
Definition: LALFrameU.c:185
int XLALFrameUFrChanVectorAlloc(LALFrameUFrChan *channel, int dtype, size_t ndata)
Allocate memory for a FrVect structure within a FrChan structure.
Definition: LALFrameU.c:330
double XLALFrameUFrChanVectorQueryDx(const LALFrameUFrChan *channel, size_t dim)
Query FrChan structure for the sampling interval in the dim dimension of the multi-dimensional data i...
Definition: LALFrameU.c:385
const char * XLALFrameUFrTOCQueryProcName(const LALFrameUFrTOC *toc, size_t proc)
Query FrTOC structure for the name of a FrProcData structure.
Definition: LALFrameU.c:190
size_t XLALFrameUFrChanVectorQueryNData(const LALFrameUFrChan *channel)
Query FrChan structure for the number of points of data in its FrVect structure.
Definition: LALFrameU.c:370
const char * XLALFrameUFrameHQueryName(const LALFrameUFrameH *frame)
Query FrameH structure for its name.
Definition: LALFrameU.c:240
double XLALFrameUFrDetectorQueryArmXMidpoint(const LALFrameUFrDetector *detector)
Query FrDetector structure for the detector x-arm midpoint.
Definition: LALFrameU.c:493
double XLALFrameUFrDetectorQueryArmXAltitude(const LALFrameUFrDetector *detector)
Query FrDetector structure for the detector x-arm altitude.
Definition: LALFrameU.c:483
int XLALFrameUFrameHSetRun(LALFrameUFrameH *frame, int run)
Set the run number in a FrameH structure.
Definition: LALFrameU.c:275
const char * XLALFrameUFrChanVectorQueryUnitY(const LALFrameUFrChan *channel)
Query FrChan structure for sample units of the data in the FrVect structure.
Definition: LALFrameU.c:400
double XLALFrameUFrDetectorQueryArmYAltitude(const LALFrameUFrDetector *detector)
Query FrDetector structure for the detector y-arm altitude.
Definition: LALFrameU.c:488
void XLALFrameUFrDetectorFree(LALFrameUFrDetector *detector)
Free a FrDetector structure.
Definition: LALFrameU.c:430
const char * XLALFrameUFrTOCQueryAdcName(const LALFrameUFrTOC *toc, size_t adc)
Query FrTOC structure for the name of a FrAdcData structure.
Definition: LALFrameU.c:170
double XLALFrameUFrDetectorQueryArmYMidpoint(const LALFrameUFrDetector *detector)
Query FrDetector structure for the detector y-arm midpoint.
Definition: LALFrameU.c:498
const char * XLALFrameUFrChanVectorQueryUnitX(const LALFrameUFrChan *channel, size_t dim)
Query FrChan structure for the units of the domain of the dim dimension of the multi-dimensional data...
Definition: LALFrameU.c:395
double XLALFrameUFrDetectorQueryLongitude(const LALFrameUFrDetector *detector)
Query FrDetector structure for the detector longitude.
Definition: LALFrameU.c:458
double XLALFrameUFrChanVectorQueryStartX(const LALFrameUFrChan *channel, size_t dim)
Query FrChan structure for the starting value of the dim dimension of the multi-dimensional data in t...
Definition: LALFrameU.c:390
double XLALFrameUFrameHQueryGTimeModf(double *iptr, const LALFrameUFrameH *frame)
Query FrameH structure for the start time.
Definition: LALFrameU.c:260
struct tagLALFrameUFrTOC LALFrameUFrTOC
Incomplete type for a table of contents FrTOC structure.
Definition: LALFrameU.h:78
LALFrameUFrChan * XLALFrameUFrProcChanAlloc(const char *name, int type, int subtype, int dtype, size_t ndata)
Allocate memory for a new FrChan structure of FrAdcData type.
Definition: LALFrameU.c:300
int XLALFrameUFrDetectorQueryLocalTime(const LALFrameUFrDetector *detector)
Query FrDetector structure for the local time offset at the detector.
Definition: LALFrameU.c:503
int XLALFrameUFrChanVectorSetName(LALFrameUFrChan *channel, const char *name)
Set the name of the FrVect structure contained in a FrChan structure.
Definition: LALFrameU.c:405
size_t XLALFrameUFrTOCQueryAdcN(const LALFrameUFrTOC *toc)
Query FrTOC structure for number of FrAdcData structures.
Definition: LALFrameU.c:165
int XLALFrameUFrameHQueryRun(const LALFrameUFrameH *frame)
Query FrameH structure for the run number.
Definition: LALFrameU.c:245
size_t XLALFrameUFrTOCQueryDetectorN(const LALFrameUFrTOC *toc)
Query FrTOC structure for number of FrDetector structures.
Definition: LALFrameU.c:195
int XLALFrameUFrChanVectorSetUnitX(LALFrameUFrChan *channel, const char *unit)
Set the units of the domain of the data in the FrVect structure contained in a FrChan structure.
Definition: LALFrameU.c:420
const char * XLALFrameUFrDetectorQueryName(const LALFrameUFrDetector *detector)
Query FrDetector structure for the detector name.
Definition: LALFrameU.c:448
double XLALFrameUFrDetectorQueryArmXAzimuth(const LALFrameUFrDetector *detector)
Query FrDetector structure for the detector x-arm azimuth.
Definition: LALFrameU.c:473
LALFrameUFrDetector * XLALFrameUFrDetectorRead(LALFrameUFrFile *stream, const char *name)
Read a detector FrDetector structure from a FrFile stream.
Definition: LALFrameU.c:435
size_t XLALFrameUFrChanVectorQueryNBytes(const LALFrameUFrChan *channel)
Query FrChan structure for the number of bytes of data in its FrVect structure.
Definition: LALFrameU.c:365
const char * XLALFrameUFrTOCQueryDetectorName(const LALFrameUFrTOC *toc, size_t det)
Query FrTOC structure for the name of a FrDetector structure.
Definition: LALFrameU.c:200
const char * XLALFrameUFrChanQueryName(const LALFrameUFrChan *channel)
Query FrChan structure for its name.
Definition: LALFrameU.c:305
double XLALFrameUFrDetectorQueryArmYAzimuth(const LALFrameUFrDetector *detector)
Query FrDetector structure for the detector y-arm azimuth.
Definition: LALFrameU.c:478
@ LAL_FRAMEU_FR_PROC_TYPE_TIME_SERIES
Id for time-series data.
Definition: LALFrameU.h:193
@ LAL_FRAMEU_FR_PROC_SUB_TYPE_UNKNOWN
Id for unknown or user-defined data.
Definition: LALFrameU.h:220
double dt
Definition: stream.c:110
char * channel
Definition: stream.c:108
void output(int gps_sec, int output_type)
int copydetector(LALFrameUFrameH *frame, LALFrameUFrDetector *detector)
Definition: utils.c:79
LALFrameUFrameH * framecpy(LALFrameUFrFile *frfile, size_t pos)
Definition: utils.c:26
int copychannel(LALFrameUFrameH *frame, LALFrameUFrChan *channel, int chantype)
Definition: utils.c:173
int copydetectors(LALFrameUFrameH *frame, LALFrameUFrFile *frfile)
Definition: utils.c:58
LALFrameUFrameH * framedup(LALFrameUFrameH *frame)
Definition: utils.c:36
int copychannels(LALFrameUFrameH *frame, LALFrameUFrFile *frfile, size_t pos, const char *match)
Definition: utils.c:121
@ ADC_CHAN_TYPE
Definition: utils.h:2
@ SIM_CHAN_TYPE
Definition: utils.h:2
@ PROC_CHAN_TYPE
Definition: utils.h:2