Loading [MathJax]/extensions/TeX/AMSsymbols.js
LALMetaIO 4.0.6.1-8a6b96f
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
segment.c
Go to the documentation of this file.
1/*
2 * segment.c
3 *
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License as published by the
6 * Free Software Foundation; either version 2 of the License, or (at your
7 * option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License along
15 * with with program; see the file COPYING. If not, write to the Free
16 * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17 * 02110-1301 USA
18 */
19
20#include <stdlib.h>
21#include <stdio.h>
22#include <string.h>
23
24
25#include <metaio.h>
26
27
28#include <lal/Date.h>
29#include <lal/LALMalloc.h>
30#include <lal/LIGOLwXML.h>
31#include <lal/LIGOLwXMLRead.h>
32#include <lal/LIGOMetadataTables.h>
33#include <lal/LIGOMetadataUtils.h>
34#include <lal/XLALError.h>
35
36
37/**
38 * Create a SegmentTable structure.
39 */
41 const ProcessTable *process
42)
43{
44 SegmentTable *new = XLALMalloc(sizeof(*new));
45
46 if(!new)
48
49 new->next = NULL;
50 if(process)
51 new->process_id = process->process_id;
52 else
53 new->process_id = -1;
54 new->creator_db = -1;
55 new->segment_id = -1;
56 new->segment_def_id = -1;
57 new->segment_def_cdb = -1;
58 XLALGPSSet(&new->start_time, 0, 0);
59 XLALGPSSet(&new->end_time, 0, 0);
60
61 return new;
62}
63
64
65/*
66 * Destroy a SegmentTable structure.
67 */
69 SegmentTable * row
70)
71{
72 SegmentTable *next = row ? row->next : NULL;
73 XLALFree(row);
74 return next;
75}
76
77
78/*
79 * Destroy a SegmentTable linked list.
80 */
82 SegmentTable * head
83)
84{
85 while(head)
86 head = XLALDestroySegmentTableRow(head);
87}
88
89
90/**
91 * Write a segment table to an XML file.
92 */
94 LIGOLwXMLStream *xml,
95 const SegmentTable *segment_table
96)
97{
98 const char *row_head = "\n\t\t\t";
99
100 /* table header */
101
103 XLALFilePuts("\t<Table Name=\"segment:table\">\n", xml->fp);
104 XLALFilePuts("\t\t<Column Name=\"process:process_id\" Type=\"int_8s\"/>\n", xml->fp);
105 XLALFilePuts("\t\t<Column Name=\"segment_id\" Type=\"int_8s\"/>\n", xml->fp);
106 XLALFilePuts("\t\t<Column Name=\"start_time\" Type=\"int_4s\"/>\n", xml->fp);
107 XLALFilePuts("\t\t<Column Name=\"start_time_ns\" Type=\"int_4s\"/>\n", xml->fp);
108 XLALFilePuts("\t\t<Column Name=\"end_time\" Type=\"int_4s\"/>\n", xml->fp);
109 XLALFilePuts("\t\t<Column Name=\"end_time_ns\" Type=\"int_4s\"/>\n", xml->fp);
110 XLALFilePuts("\t\t<Column Name=\"segment_definer:segment_def_id\" Type=\"int_8s\"/>\n", xml->fp);
111 XLALFilePuts("\t\t<Stream Name=\"segment:table\" Type=\"Local\" Delimiter=\",\">", xml->fp);
112 if(XLALGetBaseErrno())
114
115 /* rows */
116
117 for(; segment_table; segment_table = segment_table->next) {
118 if(XLALFilePrintf(xml->fp, "%s%ld,%ld,%d,%d,%d,%d,%ld", row_head, segment_table->process_id, segment_table->segment_id, segment_table->start_time.gpsSeconds, segment_table->start_time.gpsNanoSeconds, segment_table->end_time.gpsSeconds, segment_table->end_time.gpsNanoSeconds, segment_table->segment_def_id) < 0)
120 row_head = ",\n\t\t\t";
121 }
122
123 /* table footer */
124
125 if(XLALFilePuts("\n\t\t</Stream>\n\t</Table>\n", xml->fp) < 0)
127
128 /* done */
129
130 return 0;
131}
int XLALFilePuts(const char *s, LALFILE *file)
int XLALFilePrintf(LALFILE *file, const char *fmt,...)
void * XLALMalloc(size_t n)
void XLALFree(void *p)
#define XLAL_ERROR_NULL(...)
int XLALGetBaseErrno(void)
#define XLAL_ERROR(...)
int XLALClearErrno(void)
XLAL_EFUNC
LIGOTimeGPS * XLALGPSSet(LIGOTimeGPS *epoch, INT4 gpssec, INT8 gpsnan)
SegmentTable * XLALCreateSegmentTableRow(const ProcessTable *process)
Create a SegmentTable structure.
Definition: segment.c:40
int XLALWriteLIGOLwXMLSegmentTable(LIGOLwXMLStream *xml, const SegmentTable *segment_table)
Write a segment table to an XML file.
Definition: segment.c:93
void XLALDestroySegmentTable(SegmentTable *head)
Definition: segment.c:81
SegmentTable * XLALDestroySegmentTableRow(SegmentTable *row)
Definition: segment.c:68
This structure contains the file stream and current table type for writing to LIGO lightweight XML fi...
Definition: LIGOLwXML.h:71
LALFILE * fp
Definition: LIGOLwXML.h:72
INT4 gpsNanoSeconds
LIGOTimeGPS end_time
LIGOTimeGPS start_time
struct tagSegmentTable * next