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
cat.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_cat lalfr-cat
22 * @ingroup lalframe_programs
23 *
24 * @brief Concatenate frame files
25 *
26 * ### Synopsis
27 *
28 * lalfr-cat [file ...]
29 *
30 * ### Description
31 *
32 * The `lalfr-cat` utility cuts reads frame files sequentially, writing them to
33 * the standard output. The file operands are processed in command-line
34 * order. If file is a single dash (`-`) or absent, `lalfr-cat` reads from the
35 * standard input.
36 *
37 * ### Example
38 *
39 * The command:
40 *
41 * lalfr-cat file1.gwf file2.gwf > file3.gwf
42 *
43 * will concatenate `file1.gwf` and `file2.gwf` to the file `file3.gwf`.
44 *
45 * The command:
46 *
47 * lalfr-cat file1.gwf - file2.gwf
48 *
49 * will output to standard output the contents of frame file `file1.gwf`, the
50 * frame file received from standard input, and the contents of `file2.gwf`.
51 *
52 * @sa @ref lalfr_split
53 */
54
55#include <stdio.h>
56#include <stdlib.h>
57#include <string.h>
58#include <lal/LALFrameU.h>
59#include "utils.h"
60
61#define FAILURE(...) do { fprintf(stderr, __VA_ARGS__); exit(99); } while (0)
62
63int main(int argc, char *argv[])
64{
65 char stdio[] = "-";
66 char *defaultfilev[1] = { stdio };
67 int filec = (argc == 1 ? 1 : argc - 1);
68 char **filev = (argc == 1 ? defaultfilev : &argv[1]);
69 LALFrameUFrFile *output;
70
71 output = XLALFrameUFrFileOpen(stdio, "w");
72 if (!output)
73 FAILURE("could not create output file\n");
74
75 while (filec-- > 0) {
76 char *fname = *filev++;
77 LALFrameUFrFile *input;
78 LALFrameUFrTOC *toc;
79 size_t nframe;
80 size_t pos;
81
82 input = XLALFrameUFrFileOpen(fname, "r");
83 if (!input)
84 FAILURE("file %s not found\n", fname);
85
86 toc = XLALFrameUFrTOCRead(input);
87 if (!toc)
88 FAILURE("no TOC found in file %s\n", fname);
89
90 nframe = XLALFrameUFrTOCQueryNFrame(toc);
91 if ((int)(nframe) <= 0)
92 FAILURE("no frames found in file %s\n", fname);
93
94 /* loop over frames in input file */
95 for (pos = 0; pos < nframe; ++pos) {
96 LALFrameUFrameH *frame;
97
98 frame = framecpy(input, pos);
99 copydetectors(frame, input);
100 copychannels(frame, input, pos, NULL);
101
104 }
105
107 }
108
110 return 0;
111}
int main(int argc, char *argv[])
Definition: cat.c:63
#define FAILURE(...)
Definition: cat.c:61
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
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