Loading [MathJax]/extensions/TeX/AMSsymbols.js
LALFrame 3.0.7.1-b246709
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
dump.c
Go to the documentation of this file.
1/*
2* Copyright (C) 2007 Duncan Brown, Jolien Creighton, Robert Adam Mercer
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 * @defgroup lalfr_dump lalfr-dump
22 * @ingroup lalframe_programs
23 *
24 * @brief Prints channel and detector metadata from frame files
25 *
26 * ### Synopsis
27 *
28 * lalfr-dump [file ...]
29 *
30 * ### Description
31 *
32 * The `lalfr-dump` utility dumps information about the contents of each `file`
33 * to the standard output. The `file` operands are processed in command-line
34 * order. If `file` is a single dash (`-`) or absent, `lalfr-dump` reads from
35 * the standard input. Content dumped includes the detector structures
36 * contained and information about the data channels present.
37 *
38 * ### Example
39 *
40 * The command:
41 *
42 * lalfr-dump file.gwf
43 *
44 * outputs information about the detector structures and channels con tained in
45 * the `file.gwf`.
46 *
47 * @sa @ref lalfr_print
48 */
49
50#include <math.h>
51#include <stdio.h>
52#include <stdlib.h>
53#include <string.h>
54#include <lal/LALFrameU.h>
55
56#define FAILURE(...) do { fprintf(stderr, __VA_ARGS__); exit(1); } while (0)
57
58int quotelvl = 0;
59int indent(int);
60#define indent indent(quotelvl)
61
62int dumpdetector(LALFrameUFrFile * frfile, size_t det);
63int dumpframe(LALFrameUFrFile * frfile, size_t pos);
64int dumpchannel(LALFrameUFrChan * channel, size_t chan, const char *chantype);
65const char *typestr(int type);
66const char *compressstr(int type);
67
68int main(int argc, char *argv[])
69{
70 char stdio[] = "-";
71 char *defaultfilev[1] = { stdio };
72 int filec = (argc == 1 ? 1 : argc - 1);
73 char **filev = (argc == 1 ? defaultfilev : &argv[1]);
74 int f;
75
76 for (f = 0; f < filec; ++f) {
77 char *fname = filev[f];
78 LALFrameUFrFile *frfile = NULL;
79 LALFrameUFrTOC *toc = NULL;
80 size_t nframe = 0;
81 size_t ndet = 0;
82 size_t det = 0;
83 size_t pos = 0;
84
85 frfile = XLALFrameUFrFileOpen(fname, "r");
86 if (!frfile)
87 FAILURE("file %s not found\n", fname);
88
89 if (f > 0)
90 printf("\n");
91 if (filec > 1)
92 printf("==> %s <==\n", fname);
93
94 toc = XLALFrameUFrTOCRead(frfile);
95 if (!toc)
96 FAILURE("no TOC found\n");
97
98 /* loop over detectors in file */
100 for (det = 0; det < ndet; ++det)
101 dumpdetector(frfile, det);
102
103 /* loop over frames in file */
104 nframe = XLALFrameUFrTOCQueryNFrame(toc);
105 if ((int)(nframe) <= 0)
106 FAILURE("no frames found\n");
107 for (pos = 0; pos < nframe; ++pos)
108 dumpframe(frfile, pos);
109
111 XLALFrameUFrFileClose(frfile);
112 }
113
114 return 0;
115}
116
117int dumpdetector(LALFrameUFrFile * frfile, size_t det)
118{
119 LALFrameUFrTOC *toc;
120 LALFrameUFrDetector *detector;
121 const char *name;
122 const char *prefix;
123 /*
124 * double longitude;
125 * double latitude;
126 * double elevation;
127 * double azimuthx;
128 * double azimuthy;
129 * double altitudex;
130 * double altitudey;
131 * double midpointx;
132 * double midpointy;
133 */
134 int loctime;
135
136 if (!frfile)
137 return -1;
138
139 toc = XLALFrameUFrTOCRead(frfile);
141 detector = XLALFrameUFrDetectorRead(frfile, name);
142 if (!detector) {
143 --quotelvl;
144 return -1;
145 }
146
148 prefix = XLALFrameUFrDetectorQueryPrefix(detector);
149 loctime = XLALFrameUFrDetectorQueryLocalTime(detector);
150 /*
151 * longitude = XLALFrameUFrDetectorQueryLongitude(detector);
152 * latitude = XLALFrameUFrDetectorQueryLatitude(detector);
153 * elevation = XLALFrameUFrDetectorQueryElevation(detector);
154 * azimuthx = XLALFrameUFrDetectorQueryArmXAzimuth(detector);
155 * altitudex = XLALFrameUFrDetectorQueryArmXAltitude(detector);
156 * midpointx = XLALFrameUFrDetectorQueryArmXMidpoint(detector);
157 * azimuthy = XLALFrameUFrDetectorQueryArmYAzimuth(detector);
158 * altitudey = XLALFrameUFrDetectorQueryArmYAltitude(detector);
159 * midpointy = XLALFrameUFrDetectorQueryArmYMidpoint(detector);
160 */
161
162 indent;
163 printf("FrDetector %zu %s (%s): local time = %d\n", det, name, prefix,
164 loctime);
165
167 XLALFrameUFrDetectorFree(detector);
168 return 0;
169}
170
171int dumpframe(LALFrameUFrFile * frfile, size_t pos)
172{
173 LALFrameUFrameH *frame;
174 LALFrameUFrTOC *toc;
175 const char *name;
176 int run;
177 int frnum;
178 int dq;
179 double tip;
180 double tfp;
181 int leaps;
182 double dt;
183 size_t nadc;
184 size_t nsim;
185 size_t nproc;
186 size_t adc;
187 size_t sim;
188 size_t proc;
189
190 if (!frfile)
191 return -1;
192
193 /* read frame */
194 frame = XLALFrameUFrameHRead(frfile, pos);
195 if (!frame)
196 FAILURE("unable to open frame %zu\n", pos);
197
198 /* get frame metadata */
200 run = XLALFrameUFrameHQueryRun(frame);
201 frnum = XLALFrameUFrameHQueryFrame(frame);
203 tfp = XLALFrameUFrameHQueryGTimeModf(&tip, frame);
204 leaps = XLALFrameUFrameHQueryULeapS(frame);
206
207 /* print frame metadata */
208 indent;
209 printf("FrameH %zu", pos);
210 if (name && *name)
211 printf(" %s", name);
212 printf(" run %d, frame %d", run, frnum);
213 printf(": dq = %d, ", dq);
214 if (tfp == 0.0)
215 printf("t0 = %d s, ", (int)tip);
216 else
217 printf("t0 = %f s, ", tip + tfp);
218 printf("dt = %g s, ", dt);
219 printf("TAI-UTC = %d\n", leaps);
220
221 /* get channel counts */
222 toc = XLALFrameUFrTOCRead(frfile);
223 nadc = XLALFrameUFrTOCQueryAdcN(toc);
224 nsim = XLALFrameUFrTOCQuerySimN(toc);
225 nproc = XLALFrameUFrTOCQueryProcN(toc);
226
227 /* print adc channel info */
228 for (adc = 0; adc < nadc; ++adc) {
229 LALFrameUFrChan *channel;
231 channel = XLALFrameUFrChanRead(frfile, name, pos);
232 dumpchannel(channel, adc, "Adc");
234 }
235
236 /* print sim channel info */
237 for (sim = 0; sim < nsim; ++sim) {
238 LALFrameUFrChan *channel;
240 channel = XLALFrameUFrChanRead(frfile, name, pos);
241 dumpchannel(channel, sim, "Sim");
243 }
244
245 /* print proc channel info */
246 for (proc = 0; proc < nproc; ++proc) {
247 LALFrameUFrChan *channel;
249 channel = XLALFrameUFrChanRead(frfile, name, pos);
250 dumpchannel(channel, proc, "Proc");
252 }
253
256 return 0;
257}
258
259int dumpchannel(LALFrameUFrChan * channel, size_t chan, const char *chantype)
260{
261 const char *channame;
262 double toffset;
263 const char *vectname;
264 int compress;
265 size_t nbytes;
266 size_t ndata;
267 int type;
268 size_t ndim;
269 size_t dim;
270 const char *unity;
271
272 if (!channel)
273 return -1;
274
275 ++quotelvl;
276
279
287
288 /* print channel information */
289 indent;
290 printf("Fr%sData %zu %s", chantype, chan, channame);
291 if (toffset > 0.0)
292 printf(", offset = %g s", toffset);
293 if (strcmp(channame, vectname))
294 printf(", FrVect %s", vectname);
295 printf(": ");
296 if (nbytes / 1073741824)
297 printf("%2gGi", floor(0.5 + nbytes / 1073741824.0));
298 else if (nbytes / 1048576)
299 printf("%2gMi", floor(0.5 + nbytes / 1048576.0));
300 else if (nbytes / 1024)
301 printf("%2gKi", floor(0.5 + nbytes / 1024.0));
302 else
303 printf("%zuB", nbytes);
304 printf(" (%s)", compressstr(compress));
305 printf(", %zu %s pts", ndata, typestr(type));
306 if (unity && *unity)
307 printf(", yunits = %s", unity);
308 if (ndim == 1) {
309 double dx;
310 double x0;
311 const char *unitx;
315 printf(", x0 = %g, dx = %g", x0, dx);
316 if (unitx && *unitx)
317 printf(", xunits = %s", unitx);
318 printf("\n");
319 } else {
320 printf(", %zu dim\n", ndim);
321 ++quotelvl;
322 for (dim = 0; dim < ndim; ++dim) {
323 size_t nx;
324 double dx;
325 double x0;
326 const char *unitx;
327
332 indent;
333 printf("nx[%zu] = %zu", dim, nx);
334 printf(", x0[%zu] = %g", dim, x0);
335 printf(", dx[%zu] = %g", dim, dx);
336 if (unitx && *unitx)
337 printf(", xunits[%zu] = %s", dim, unitx);
338 printf("\n");
339 }
340 --quotelvl;
341 }
342 --quotelvl;
343 return 0;
344}
345
346const char *typestr(int type)
347{
348 switch (type) {
350 return "char";
352 return "int16_t";
354 return "int32_t";
356 return "int64_t";
358 return "uint8_t";
360 return "uint16_t";
362 return "uint32_t";
364 return "uint64_t";
366 return "float";
368 return "double";
370 return "float complex";
372 return "double complex";
374 return "string";
375 default:
376 break;
377 }
378 return "unknown";
379}
380
381const char *compressstr(int compress)
382{
383 switch (compress) {
385 return "RAW";
387 return "GZIP compression";
389 return "DIFF_GZIP compression";
391 return "ZERO_SUPPRESS_WORD_2 compression";
393 return "ZERO_SUPPRESS_WORD_4 compression";
394 default:
395 break;
396 }
397 return "unknown compression";
398}
399
400/* output quote formatting */
401#undef indent
402int indent(int n)
403{
404 const char *tab = " ";
405 switch (n) {
406 default:
407 case 3:
408 fputs(tab, stdout);
409#if __GNUC__ >= 7 && !defined __INTEL_COMPILER
410 __attribute__ ((fallthrough));
411#endif
412 case 2:
413 fputs(tab, stdout);
414 fputs(tab, stdout);
415 fputs("... ", stdout);
416 break;
417 case 1:
418 fputs(tab, stdout);
419 fputs("- ", stdout);
420 break;
421 case 0:
422 fputs("- ", stdout);
423 break;
424 }
425 return 0;
426}
const char *const name
int main(int argc, char *argv[])
Definition: dump.c:68
int dumpdetector(LALFrameUFrFile *frfile, size_t det)
Definition: dump.c:117
const char * compressstr(int type)
Definition: dump.c:381
const char * typestr(int type)
Definition: dump.c:346
#define indent
Definition: dump.c:60
#define FAILURE(...)
Definition: dump.c:56
int dumpframe(LALFrameUFrFile *frfile, size_t pos)
Definition: dump.c:171
int quotelvl
Definition: dump.c:58
int dumpchannel(LALFrameUFrChan *channel, size_t chan, const char *chantype)
Definition: dump.c:259
#define __attribute__(x)
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
int XLALFrameUFrChanVectorQueryCompress(const LALFrameUFrChan *channel)
Query FrChan structure for the compression scheme of its FrVect structure.
Definition: LALFrameU.c:350
size_t XLALFrameUFrTOCQueryNFrame(const LALFrameUFrTOC *toc)
Query FrTOC structure for number of FrameH structures contained.
Definition: LALFrameU.c:150
int XLALFrameUFrChanVectorQueryType(const LALFrameUFrChan *channel)
Query FrChan structure for the data type of its FrVect structure.
Definition: LALFrameU.c:355
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
size_t XLALFrameUFrChanVectorQueryNDim(const LALFrameUFrChan *channel)
Query FrChan structure for the number of dimensions of the multi-dimensional data in its FrVect struc...
Definition: LALFrameU.c:375
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
size_t XLALFrameUFrChanVectorQueryNx(const LALFrameUFrChan *channel, size_t dim)
Query FrChan structure for the number of points in the dim dimension of the multi-dimensional data in...
Definition: LALFrameU.c:380
double XLALFrameUFrameHQueryDt(const LALFrameUFrameH *frame)
Query FrameH structure for the duration.
Definition: LALFrameU.c:270
int XLALFrameUFrameHQueryULeapS(const LALFrameUFrameH *frame)
Query FrameH structure for the number of leap seconds.
Definition: LALFrameU.c:265
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
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
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
const char * XLALFrameUFrChanVectorQueryUnitY(const LALFrameUFrChan *channel)
Query FrChan structure for sample units of the data in the FrVect structure.
Definition: LALFrameU.c:400
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
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
LALFrameUFrFile * XLALFrameUFrFileOpen(const char *filename, const char *mode)
Open a frame file FrFile stream.
Definition: LALFrameU.c:130
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
int XLALFrameUFrDetectorQueryLocalTime(const LALFrameUFrDetector *detector)
Query FrDetector structure for the local time offset at the detector.
Definition: LALFrameU.c:503
void XLALFrameUFrFileClose(LALFrameUFrFile *stream)
Close a FrFile stream.
Definition: LALFrameU.c:125
size_t XLALFrameUFrTOCQueryAdcN(const LALFrameUFrTOC *toc)
Query FrTOC structure for number of FrAdcData structures.
Definition: LALFrameU.c:165
int XLALFrameUFrameHQueryDataQuality(const LALFrameUFrameH *frame)
Query FrameH structure for the data quality word.
Definition: LALFrameU.c:255
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
const char * XLALFrameUFrDetectorQueryName(const LALFrameUFrDetector *detector)
Query FrDetector structure for the detector name.
Definition: LALFrameU.c:448
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
@ LAL_FRAMEU_FR_VECT_COMPRESS_DIFF_GZIP
Id for gzip compression of differential values.
Definition: LALFrameU.h:122
@ LAL_FRAMEU_FR_VECT_COMPRESS_ZERO_SUPPRESS_WORD_2
Id for differentiation and zero suppression for 2-byte word integer types only.
Definition: LALFrameU.h:126
@ LAL_FRAMEU_FR_VECT_COMPRESS_RAW
Id for uncompressed raw values.
Definition: LALFrameU.h:116
@ LAL_FRAMEU_FR_VECT_COMPRESS_GZIP
Id for gzip compression.
Definition: LALFrameU.h:119
@ LAL_FRAMEU_FR_VECT_COMPRESS_ZERO_SUPPRESS_WORD_4
Id for differentiation and zero suppression for 4-byte word (integer or floating-point).
Definition: LALFrameU.h:130
@ LAL_FRAMEU_FR_VECT_STRING
Id for string data type.
Definition: LALFrameU.h:166
@ LAL_FRAMEU_FR_VECT_16C
Id for 128-bit double precision complex data type.
Definition: LALFrameU.h:163
@ LAL_FRAMEU_FR_VECT_C
Id for 8-bit signed char data type.
Definition: LALFrameU.h:142
@ LAL_FRAMEU_FR_VECT_4R
Id for 32-bit single precision floating point data type.
Definition: LALFrameU.h:151
@ LAL_FRAMEU_FR_VECT_2S
Id for 16-bit signed integer data type.
Definition: LALFrameU.h:145
@ LAL_FRAMEU_FR_VECT_8S
Id for 64-bit signed integer data type.
Definition: LALFrameU.h:157
@ LAL_FRAMEU_FR_VECT_8U
Id for 64-bit unsigned integer data type.
Definition: LALFrameU.h:175
@ LAL_FRAMEU_FR_VECT_4S
Id for 32-bit signed integer data type.
Definition: LALFrameU.h:154
@ LAL_FRAMEU_FR_VECT_8C
Id for 64-bit single precision complex data type.
Definition: LALFrameU.h:160
@ LAL_FRAMEU_FR_VECT_1U
Id for 8-bit unsigned char data type.
Definition: LALFrameU.h:178
@ LAL_FRAMEU_FR_VECT_8R
Id for 64-bit double precision floating point data type.
Definition: LALFrameU.h:148
@ LAL_FRAMEU_FR_VECT_4U
Id for 32-bit unsigned integer data type.
Definition: LALFrameU.h:172
@ LAL_FRAMEU_FR_VECT_2U
Id for 16-bit unsigned integer data type.
Definition: LALFrameU.h:169
double dt
Definition: stream.c:110
char * channel
Definition: stream.c:108