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
paste.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_paste lalfr-paste
22 * @ingroup lalframe_programs
23 *
24 * @brief Merge channels in corresponding frames together
25 *
26 * ### Synopsis
27 *
28 * lalfr-paste [file ...]
29 *
30 * ### Description
31 *
32 * The `lalfr-paste` utility concatenates the corresponding frames of the given
33 * input files, producing frames containing the merged channels and detector
34 * structures that are written to the standard output. If `file` is a single
35 * dash (`-`) for one of the input files, the standard input is used.
36 *
37 * ### Examples
38 *
39 * The command:
40 *
41 * lalfr-paste file1.gwf file2.gwf > file3.gwf
42 *
43 * merges the channels in the frames contained in `file1.gwf` with the channels
44 * in the frames contained in `file2.gwf` and writes the resulting set of
45 * frames to `file3.gwf`.
46 *
47 * @sa @ref lalfr_cut
48 */
49
50#include <stdio.h>
51#include <stdlib.h>
52#include <string.h>
53#include <lal/LALFrameU.h>
54#include "utils.h"
55
56#define FAILURE(...) do { fprintf(stderr, __VA_ARGS__); exit(99); } while (0)
57
58int main(int argc, char *argv[])
59{
60 char stdio[] = "-";
61 char *defaultfilev[1] = { stdio };
62 int filec = (argc == 1 ? 1 : argc - 1);
63 char **filev = (argc == 1 ? defaultfilev : &argv[1]);
64 LALFrameUFrFile *output;
65 LALFrameUFrFile **input;
66 size_t *nframe;
67 size_t nframemax = 0;
68 size_t pos;
69 int f;
70
71 output = XLALFrameUFrFileOpen(stdio, "w"); /* output to stdout */
72 if (!output)
73 FAILURE("could not create output file\n");
74
75 /* open all the input files and get number of frames in each */
76 input = calloc(filec, sizeof(*input));
77 nframe = calloc(filec, sizeof(*nframe));
78 for (f = 0; f < filec; ++f) {
79 LALFrameUFrTOC *toc;
80 char *fname = filev[f];
81
82 input[f] = XLALFrameUFrFileOpen(fname, "r");
83 if (!input[f])
84 FAILURE("file %s not found\n", fname);
85
86 toc = XLALFrameUFrTOCRead(input[f]);
87 if (!toc)
88 FAILURE("no TOC found in file %s\n", fname);
89
90 nframe[f] = XLALFrameUFrTOCQueryNFrame(toc);
91 if ((int)(nframe[f]) <= 0)
92 FAILURE("no frames found in file %s\n", fname);
93
94 if (nframe[f] > nframemax)
95 nframemax = nframe[f];
96 }
97
98 /* loop over frames */
99 for (pos = 0; pos < nframemax; ++pos) {
100 LALFrameUFrameH *frame = NULL;
101
102 /* loop over files */
103 for (f = 0; f < filec; ++f) {
104 /* check to see that file has this frame */
105 if (pos >= nframe[f])
106 continue; /* skip this file */
107
108 /* TODO: check consistency of frame times? */
109 if (frame == NULL) /* first time: duplicate frame */
110 frame = framecpy(input[f], pos);
111
112 copydetectors(frame, input[f]);
113 copychannels(frame, input[f], pos, NULL);
114 }
117 }
118
119 /* close files */
120 for (f = 0; f < filec; ++f)
121 XLALFrameUFrFileClose(input[f]);
122 free(input);
123 free(nframe);
124
126 return 0;
127}
size_t XLALFrameUFrTOCQueryNFrame(const LALFrameUFrTOC *toc)
Query FrTOC structure for number of FrameH structures contained.
Definition: LALFrameU.c:150
int XLALFrameUFrameHWrite(LALFrameUFrFile *stream, LALFrameUFrameH *frame)
Write a FrameH structure to an output FrFile stream.
Definition: LALFrameU.c:220
void XLALFrameUFrameHFree(LALFrameUFrameH *frame)
Free a FrameH structure.
Definition: LALFrameU.c:205
struct tagLALFrameUFrameH LALFrameUFrameH
Incomplete type for a frame header FrameH structure.
Definition: LALFrameU.h:64
LALFrameUFrTOC * XLALFrameUFrTOCRead(LALFrameUFrFile *stream)
Read the table of contents FrTOC structure for a FrFile stream.
Definition: LALFrameU.c:145
LALFrameUFrFile * XLALFrameUFrFileOpen(const char *filename, const char *mode)
Open a frame file FrFile stream.
Definition: LALFrameU.c:130
struct tagLALFrameUFrTOC LALFrameUFrTOC
Incomplete type for a table of contents FrTOC structure.
Definition: LALFrameU.h:78
void XLALFrameUFrFileClose(LALFrameUFrFile *stream)
Close a FrFile stream.
Definition: LALFrameU.c:125
int main(int argc, char *argv[])
Definition: paste.c:58
#define FAILURE(...)
Definition: paste.c:56
void output(int gps_sec, int output_type)
LALFrameUFrameH * framecpy(LALFrameUFrFile *frfile, size_t pos)
Definition: utils.c:26
int copydetectors(LALFrameUFrameH *frame, LALFrameUFrFile *frfile)
Definition: utils.c:58
int copychannels(LALFrameUFrameH *frame, LALFrameUFrFile *frfile, size_t pos, const char *match)
Definition: utils.c:121