Loading [MathJax]/extensions/TeX/AMSsymbols.js
LALMetaIO 4.0.6.1-b246709
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
LIGOLwXML.c
Go to the documentation of this file.
1/*
2* Copyright (C) 2007 Andres C. Rodriguez, Sukanta Bose, Alexander Dietz, Duncan Brown, Jolien Creighton, Kipp Cannon, Lisa M. Goggin, Patrick Brady, Robert Adam Mercer, Saikat Ray-Majumder, Anand Sengupta, Stephen Fairhurst, Xavier Siemens, Sean Seader, Thomas Cokelaer
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 *
22 * File Name: LIGOLwXML.c
23 *
24 * Author: Brown, D. A.
25 *
26 *-----------------------------------------------------------------------
27 */
28
29/**
30 * \author Brown, D. A.
31 * \file
32 * \ingroup lalmetaio_general
33 *
34 * \brief Routines to write LIGO metadata database structures to LIGO lightweight XML files.
35 *
36 * ### Description ###
37 *
38 * The routine \c XLALCreateLIGOLwXMLFileName creates a name for a LIGO lightweight XML file that is in accordance with the specifications of document T050017.
39 *
40 * ### Algorithm ###
41 *
42 * None.
43 *
44 * ### Uses ###
45 *
46 * <tt>fopen()</tt>
47 * <tt>XLALFilePrintf()</tt>
48 * <tt>fclose()</tt>
49 *
50 * ### Notes ###
51 *
52 */
53
54
55#include <lal/FileIO.h>
56#include <lal/LALMalloc.h>
57#include <lal/LIGOLwXML.h>
58#include <lal/XLALError.h>
59#include <LIGOLwXMLHeaders.h>
60
61
62/**
63 * Open an XML file for writing. The return value is a pointer to a new
64 * LIGOLwXMLStream file handle or NULL on failure.
65 */
68 const char *path
69)
70{
71 LIGOLwXMLStream *new;
72
73 /* malloc a new XML file handle */
74
75 new = XLALMalloc( sizeof( *new ) );
76 if ( ! new )
78
79 /* fopen() the underlying C file */
80
81 new->fp = XLALFileOpen( path, "w" );
82 if ( ! new->fp )
83 {
84 XLALFree(new);
86 }
87
88 /* write the XML header */
89
90 if ( XLALFilePuts( LAL_LIGOLW_XML_HEADER, new->fp ) < 0 )
91 {
92 XLALFileClose( new->fp );
93 XLALFree( new );
95 }
96
97 /* done */
98
99 return new;
100}
101
102
103/**
104 * Close an XML stream. On failure the stream is left in an undefined
105 * state, and has not been free()'ed. Sorry.
106 */
107
108int
110 LIGOLwXMLStream *xml
111)
112{
113 if ( xml )
114 {
115 if ( XLALFilePuts( LAL_LIGOLW_XML_FOOTER, xml->fp ) < 0 )
116 /* can't write XML footer */
118 if ( XLALFileClose( xml->fp ) )
119 /* fclose() on the underlying C file failed */
121 }
122
123 XLALFree( xml );
124
125 return 0;
126}
127
128/**
129 * Creates a XML filename accordingly to document T050017
130 */
131
133 char* filename,
134 size_t size,
135 const char* dataSource,
136 const char* dataDescription,
137 const LIGOTimeGPS* gpsStartTime,
138 const LIGOTimeGPS* gpsEndTime,
139 const char* extension
140)
141{
142 INT4 gpsDuration;
143
144 /* check input structures */
145 if (!filename || !dataSource || !dataDescription ||
146 !gpsStartTime || !gpsEndTime || !extension)
148
149 /* check the correctnes of the input strings */
150 if ( strchr(dataSource, '-') || strchr(dataDescription, '-'))
151 {
152 filename = NULL;
153 XLALPrintError("the input character strings contain invalid"
154 " dashes ('-').");
156 }
157
158 /* calculate the GPS duration */
159 gpsDuration = gpsEndTime->gpsSeconds - gpsStartTime->gpsSeconds;
160 if (gpsEndTime->gpsNanoSeconds > 0) ++gpsDuration;
161
162 /* and here put it all together */
163 snprintf( filename, size, "%s-%s-%d-%d.%s",
164 dataSource, dataDescription, gpsStartTime->gpsSeconds,
165 gpsDuration, extension );
166
167 /* return success */
168 return 0;
169}
int XLALCloseLIGOLwXMLFile(LIGOLwXMLStream *xml)
Close an XML stream.
Definition: LIGOLwXML.c:109
LIGOLwXMLStream * XLALOpenLIGOLwXMLFile(const char *path)
Open an XML file for writing.
Definition: LIGOLwXML.c:67
int XLALCreateLIGODataFileName(char *filename, size_t size, const char *dataSource, const char *dataDescription, const LIGOTimeGPS *gpsStartTime, const LIGOTimeGPS *gpsEndTime, const char *extension)
Creates a XML filename accordingly to document T050017.
Definition: LIGOLwXML.c:132
This header provides provides #defines for the common elements of LIGO light weight XML files.
#define LAL_LIGOLW_XML_FOOTER
#define LAL_LIGOLW_XML_HEADER
int XLALFileClose(LALFILE *file)
LALFILE * XLALFileOpen(const char *path, const char *mode)
int XLALFilePuts(const char *s, LALFILE *file)
int32_t INT4
void * XLALMalloc(size_t n)
void XLALFree(void *p)
#define XLAL_ERROR_NULL(...)
#define XLAL_ERROR(...)
int XLALPrintError(const char *fmt,...) _LAL_GCC_PRINTF_FORMAT_(1
XLAL_EFAULT
XLAL_EFUNC
XLAL_EIO
XLAL_EINVAL
path
filename
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