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
sim_ringdown.c
Go to the documentation of this file.
1/*
2 * sim_ringdown.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 SimRingdownTable structure.
39 */
41 const ProcessTable *process
42)
43{
44 SimRingdownTable *new = XLALMalloc(sizeof(*new));
45
46 if(!new)
48
49 new->next = NULL;
50 memset(new->waveform, 0, sizeof(new->waveform));
51 memset(new->coordinates, 0, sizeof(new->coordinates));
52 if(process) {
53 /*new->process_id = process->process_id;*/
54 } else {
55 /*new->process_id = -1; */
56 }
57
58 return new;
59}
60
61
62/**
63 * Destroy a SimRingdownTable structure.
64 */
67)
68{
69 SimRingdownTable *next = row ? row->next : NULL;
70 XLALFree(row);
71 return next;
72}
73
74
75/**
76 * Destroy a SimRingdownTable linked list.
77 */
80)
81{
82 while(head)
84}
85
86
87/**
88 * Read the sim_ringdown table from a LIGO Light Weight XML file into a
89 * linked list of SimRingdownTable structures.
90 */
92 const char *filename
93)
94{
95 static const char table_name[] = "sim_ringdown";
96 int miostatus;
97 SimRingdownTable *head = NULL;
98 SimRingdownTable **next = &head;
99 struct MetaioParseEnvironment env;
100 struct {
101 int process_id;
102 int waveform;
103 int coordinates;
104 int geocent_start_time;
105 int geocent_start_time_ns;
106 int h_start_time;
107 int h_start_time_ns;
108 int l_start_time;
109 int l_start_time_ns;
110 int v_start_time;
111 int v_start_time_ns;
112 int start_time_gmst;
113 int longitude;
114 int latitude;
115 int distance;
116 int inclination;
117 int polarization;
118 int frequency;
119 int quality;
120 int phase;
121 int mass;
122 int spin;
123 int epsilon;
124 int amplitude;
125 int eff_dist_h;
126 int eff_dist_l;
127 int eff_dist_v;
128 int hrss;
129 int hrss_h;
130 int hrss_l;
131 int hrss_v;
132 } column_pos;
133
134 /* open the file and find table */
135
136 if(MetaioOpenFile(&env, filename)) {
137 XLALPrintError("%s(): error opening \"%s\": %s\n", __func__, filename, env.mierrmsg.data ? env.mierrmsg.data : "unknown reason");
139 }
140 if(MetaioOpenTableOnly(&env, table_name)) {
141 MetaioAbort(&env);
142 XLALPrintError("%s(): cannot find %s table: %s\n", __func__, table_name, env.mierrmsg.data ? env.mierrmsg.data : "unknown reason");
144 }
145
146 /* find columns */
147
149 column_pos.process_id = XLALLIGOLwFindColumn(&env, "process_id", METAIO_TYPE_INT_8S, 1);
150 column_pos.waveform = XLALLIGOLwFindColumn(&env, "waveform", METAIO_TYPE_LSTRING, 1);
151 column_pos.coordinates = XLALLIGOLwFindColumn(&env, "coordinates", METAIO_TYPE_LSTRING, 1);
152 column_pos.geocent_start_time = XLALLIGOLwFindColumn(&env, "geocent_start_time", METAIO_TYPE_INT_4S, 1);
153 column_pos.geocent_start_time_ns = XLALLIGOLwFindColumn(&env, "geocent_start_time_ns", METAIO_TYPE_INT_4S, 1);
154 column_pos.h_start_time = XLALLIGOLwFindColumn(&env, "h_start_time", METAIO_TYPE_INT_4S, 1);
155 column_pos.h_start_time_ns = XLALLIGOLwFindColumn(&env, "h_start_time_ns", METAIO_TYPE_INT_4S, 1);
156 column_pos.l_start_time = XLALLIGOLwFindColumn(&env, "l_start_time", METAIO_TYPE_INT_4S, 1);
157 column_pos.l_start_time_ns = XLALLIGOLwFindColumn(&env, "l_start_time_ns", METAIO_TYPE_INT_4S, 1);
158 column_pos.v_start_time = XLALLIGOLwFindColumn(&env, "v_start_time", METAIO_TYPE_INT_4S, 1);
159 column_pos.v_start_time_ns = XLALLIGOLwFindColumn(&env, "v_start_time_ns", METAIO_TYPE_INT_4S, 1);
160 column_pos.start_time_gmst = XLALLIGOLwFindColumn(&env, "start_time_gmst", METAIO_TYPE_REAL_8, 1);
161 column_pos.longitude = XLALLIGOLwFindColumn(&env, "longitude", METAIO_TYPE_REAL_4, 1);
162 column_pos.latitude = XLALLIGOLwFindColumn(&env, "latitude", METAIO_TYPE_REAL_4, 1);
163 column_pos.distance = XLALLIGOLwFindColumn(&env, "distance", METAIO_TYPE_REAL_4, 1);
164 column_pos.inclination = XLALLIGOLwFindColumn(&env, "inclination", METAIO_TYPE_REAL_4, 1);
165 column_pos.polarization = XLALLIGOLwFindColumn(&env, "polarization", METAIO_TYPE_REAL_4, 1);
166 column_pos.frequency = XLALLIGOLwFindColumn(&env, "frequency", METAIO_TYPE_REAL_4, 1);
167 column_pos.quality = XLALLIGOLwFindColumn(&env, "quality", METAIO_TYPE_REAL_4, 1);
168 column_pos.phase = XLALLIGOLwFindColumn(&env, "phase", METAIO_TYPE_REAL_4, 1);
169 column_pos.mass = XLALLIGOLwFindColumn(&env, "mass", METAIO_TYPE_REAL_4, 1);
170 column_pos.spin = XLALLIGOLwFindColumn(&env, "spin", METAIO_TYPE_REAL_4, 1);
171 column_pos.epsilon = XLALLIGOLwFindColumn(&env, "epsilon", METAIO_TYPE_REAL_4, 1);
172 column_pos.amplitude = XLALLIGOLwFindColumn(&env, "amplitude", METAIO_TYPE_REAL_4, 1);
173 column_pos.eff_dist_h = XLALLIGOLwFindColumn(&env, "eff_dist_h", METAIO_TYPE_REAL_4, 1);
174 column_pos.eff_dist_l = XLALLIGOLwFindColumn(&env, "eff_dist_l", METAIO_TYPE_REAL_4, 1);
175 column_pos.eff_dist_v = XLALLIGOLwFindColumn(&env, "eff_dist_v", METAIO_TYPE_REAL_4, 1);
176 column_pos.hrss = XLALLIGOLwFindColumn(&env, "hrss", METAIO_TYPE_REAL_4, 1);
177 column_pos.hrss_h = XLALLIGOLwFindColumn(&env, "hrss_h", METAIO_TYPE_REAL_4, 1);
178 column_pos.hrss_l = XLALLIGOLwFindColumn(&env, "hrss_l", METAIO_TYPE_REAL_4, 1);
179 column_pos.hrss_v = XLALLIGOLwFindColumn(&env, "hrss_v", METAIO_TYPE_REAL_4, 1);
180
181 /* check for failure (== a required column is missing) */
182
183 if(XLALGetBaseErrno()) {
184 MetaioAbort(&env);
185 XLALPrintError("%s(): failure reading %s table\n", __func__, table_name);
187 }
188
189 /* loop over the rows in the file */
190
191 while((miostatus = MetaioGetRow(&env)) > 0) {
192 /* create a new row */
193
195
196 if(!row) {
198 MetaioAbort(&env);
200 }
201
202 /* append to linked list */
203
204 *next = row;
205 next = &(*next)->next;
206
207 /* populate the columns */
208
209 /*row->process_id = env.ligo_lw.table.elt[column_pos.process_id].data.int_8s;*/
210 strncpy(row->waveform, env.ligo_lw.table.elt[column_pos.waveform].data.lstring.data, sizeof(row->waveform) - 1);
211 strncpy(row->coordinates, env.ligo_lw.table.elt[column_pos.coordinates].data.lstring.data, sizeof(row->coordinates) - 1);
212 XLALGPSSet(&row->geocent_start_time, env.ligo_lw.table.elt[column_pos.geocent_start_time].data.int_4s, env.ligo_lw.table.elt[column_pos.geocent_start_time_ns].data.int_4s);
213 XLALGPSSet(&row->h_start_time, env.ligo_lw.table.elt[column_pos.h_start_time].data.int_4s, env.ligo_lw.table.elt[column_pos.h_start_time_ns].data.int_4s);
214 XLALGPSSet(&row->l_start_time, env.ligo_lw.table.elt[column_pos.l_start_time].data.int_4s, env.ligo_lw.table.elt[column_pos.l_start_time_ns].data.int_4s);
215 XLALGPSSet(&row->v_start_time, env.ligo_lw.table.elt[column_pos.v_start_time].data.int_4s, env.ligo_lw.table.elt[column_pos.v_start_time_ns].data.int_4s);
216 row->start_time_gmst = env.ligo_lw.table.elt[column_pos.start_time_gmst].data.real_8;
217 row->longitude = env.ligo_lw.table.elt[column_pos.longitude].data.real_4;
218 row->latitude = env.ligo_lw.table.elt[column_pos.latitude].data.real_4;
219 row->distance = env.ligo_lw.table.elt[column_pos.distance].data.real_4;
220 row->inclination = env.ligo_lw.table.elt[column_pos.inclination].data.real_4;
221 row->polarization = env.ligo_lw.table.elt[column_pos.polarization].data.real_4;
222 row->frequency = env.ligo_lw.table.elt[column_pos.frequency].data.real_4;
223 row->quality = env.ligo_lw.table.elt[column_pos.quality].data.real_4;
224 row->phase = env.ligo_lw.table.elt[column_pos.phase].data.real_4;
225 row->mass = env.ligo_lw.table.elt[column_pos.mass].data.real_4;
226 row->spin = env.ligo_lw.table.elt[column_pos.spin].data.real_4;
227 row->epsilon = env.ligo_lw.table.elt[column_pos.epsilon].data.real_4;
228 row->amplitude = env.ligo_lw.table.elt[column_pos.amplitude].data.real_4;
229 row->eff_dist_h = env.ligo_lw.table.elt[column_pos.eff_dist_h].data.real_4;
230 row->eff_dist_l = env.ligo_lw.table.elt[column_pos.eff_dist_l].data.real_4;
231 row->eff_dist_v = env.ligo_lw.table.elt[column_pos.eff_dist_v].data.real_4;
232 row->hrss = env.ligo_lw.table.elt[column_pos.hrss].data.real_4;
233 row->hrss_h = env.ligo_lw.table.elt[column_pos.hrss_h].data.real_4;
234 row->hrss_l = env.ligo_lw.table.elt[column_pos.hrss_l].data.real_4;
235 row->hrss_v = env.ligo_lw.table.elt[column_pos.hrss_v].data.real_4;
236 }
237 if(miostatus < 0) {
239 MetaioAbort(&env);
240 XLALPrintError("%s(): I/O error parsing %s table: %s\n", __func__, table_name, env.mierrmsg.data ? env.mierrmsg.data : "unknown reason");
242 }
243
244 /* close file */
245
246 if(MetaioClose(&env)) {
248 XLALPrintError("%s(): error parsing document after %s table: %s\n", __func__, table_name, env.mierrmsg.data ? env.mierrmsg.data : "unknown reason");
250 }
251
252 /* done */
253
254 return head;
255}
256
257
258/**
259 * Write a sim_ringdown table to an XML file.
260 */
261
263 LIGOLwXMLStream *xml,
264 const SimRingdownTable *sim_ringdown
265)
266{
267 const char *row_head = "\n\t\t\t";
268
269 /* table header */
270
272 XLALFilePuts("\t<Table Name=\"sim_ringdown:table\">\n" , xml->fp);
273 XLALFilePuts("\t\t<Column Name=\"process:process_id\" Type=\"ilwd:char\"/>\n", xml->fp);
274 XLALFilePuts("\t\t<Column Name=\"waveform\" Type=\"lstring\"/>\n" , xml->fp);
275 XLALFilePuts("\t\t<Column Name=\"coordinates\" Type=\"lstring\"/>\n" , xml->fp);
276 XLALFilePuts("\t\t<Column Name=\"geocent_start_time\" Type=\"int_4s\"/>\n" , xml->fp);
277 XLALFilePuts("\t\t<Column Name=\"geocent_start_time_ns\" Type=\"int_4s\"/>\n" , xml->fp);
278 XLALFilePuts("\t\t<Column Name=\"h_start_time\" Type=\"int_4s\"/>\n" , xml->fp);
279 XLALFilePuts("\t\t<Column Name=\"h_start_time_ns\" Type=\"int_4s\"/>\n" , xml->fp);
280 XLALFilePuts("\t\t<Column Name=\"l_start_time\" Type=\"int_4s\"/>\n" , xml->fp);
281 XLALFilePuts("\t\t<Column Name=\"l_start_time_ns\" Type=\"int_4s\"/>\n" , xml->fp);
282 XLALFilePuts("\t\t<Column Name=\"v_start_time\" Type=\"int_4s\"/>\n" , xml->fp);
283 XLALFilePuts("\t\t<Column Name=\"v_start_time_ns\" Type=\"int_4s\"/>\n" , xml->fp);
284 XLALFilePuts("\t\t<Column Name=\"start_time_gmst\" Type=\"real_8\"/>\n" , xml->fp);
285 XLALFilePuts("\t\t<Column Name=\"longitude\" Type=\"real_4\"/>\n" , xml->fp);
286 XLALFilePuts("\t\t<Column Name=\"latitude\" Type=\"real_4\"/>\n" , xml->fp);
287 XLALFilePuts("\t\t<Column Name=\"distance\" Type=\"real_4\"/>\n" , xml->fp);
288 XLALFilePuts("\t\t<Column Name=\"inclination\" Type=\"real_4\"/>\n" , xml->fp);
289 XLALFilePuts("\t\t<Column Name=\"polarization\" Type=\"real_4\"/>\n" , xml->fp);
290 XLALFilePuts("\t\t<Column Name=\"frequency\" Type=\"real_4\"/>\n" , xml->fp);
291 XLALFilePuts("\t\t<Column Name=\"quality\" Type=\"real_4\"/>\n" , xml->fp);
292 XLALFilePuts("\t\t<Column Name=\"phase\" Type=\"real_4\"/>\n" , xml->fp);
293 XLALFilePuts("\t\t<Column Name=\"mass\" Type=\"real_4\"/>\n" , xml->fp);
294 XLALFilePuts("\t\t<Column Name=\"spin\" Type=\"real_4\"/>\n" , xml->fp);
295 XLALFilePuts("\t\t<Column Name=\"epsilon\" Type=\"real_4\"/>\n" , xml->fp);
296 XLALFilePuts("\t\t<Column Name=\"amplitude\" Type=\"real_4\"/>\n" , xml->fp);
297 XLALFilePuts("\t\t<Column Name=\"eff_dist_h\" Type=\"real_4\"/>\n" , xml->fp);
298 XLALFilePuts("\t\t<Column Name=\"eff_dist_l\" Type=\"real_4\"/>\n" , xml->fp);
299 XLALFilePuts("\t\t<Column Name=\"eff_dist_v\" Type=\"real_4\"/>\n" , xml->fp);
300 XLALFilePuts("\t\t<Column Name=\"hrss\" Type=\"real_4\"/>\n" , xml->fp);
301 XLALFilePuts("\t\t<Column Name=\"hrss_h\" Type=\"real_4\"/>\n" , xml->fp);
302 XLALFilePuts("\t\t<Column Name=\"hrss_l\" Type=\"real_4\"/>\n" , xml->fp);
303 XLALFilePuts("\t\t<Column Name=\"hrss_v\" Type=\"real_4\"/>\n" , xml->fp);
304 XLALFilePuts("\t\t<Column Name=\"simulation_id\" Type=\"ilwd:char\"/>\n" , xml->fp);
305 XLALFilePuts("\t\t<Stream Name=\"sim_ringdown:table\" Type=\"Local\" Delimiter=\",\">\n", xml->fp);
306 if(XLALGetBaseErrno())
308
309 /* rows */
310
311 for(; sim_ringdown; sim_ringdown = sim_ringdown->next) {
312 if(XLALFilePrintf(xml->fp, "%s%ld,\"%s\",\"%s\",%d,%d,%d,%d,%d,%d,%d,%d,%.16g,%.16g,%.16g,%.16g,%.16g,%.16g,%.16g,%.16g,%.16g,%.16g,%.16g,%.16g,%.16g,%.16g,%.16g,%.16g,%.16g,%.16g,%.16g,%.16g,%ld",
313 row_head,
314 0, /* process_id */
315 sim_ringdown->waveform,
316 sim_ringdown->coordinates,
317 sim_ringdown->geocent_start_time.gpsSeconds,
319 sim_ringdown->h_start_time.gpsSeconds,
320 sim_ringdown->h_start_time.gpsNanoSeconds,
321 sim_ringdown->l_start_time.gpsSeconds,
322 sim_ringdown->l_start_time.gpsNanoSeconds,
323 sim_ringdown->v_start_time.gpsSeconds,
324 sim_ringdown->v_start_time.gpsNanoSeconds,
325 sim_ringdown->start_time_gmst,
326 sim_ringdown->longitude,
327 sim_ringdown->latitude,
328 sim_ringdown->distance,
329 sim_ringdown->inclination,
330 sim_ringdown->polarization,
331 sim_ringdown->frequency,
332 sim_ringdown->quality,
333 sim_ringdown->phase,
334 sim_ringdown->mass,
335 sim_ringdown->spin,
336 sim_ringdown->epsilon,
337 sim_ringdown->amplitude,
338 sim_ringdown->eff_dist_h,
339 sim_ringdown->eff_dist_l,
340 sim_ringdown->eff_dist_v,
341 sim_ringdown->hrss,
342 sim_ringdown->hrss_h,
343 sim_ringdown->hrss_l,
344 sim_ringdown->hrss_v,
345 sim_ringdown->simulation_id
346 ) < 0)
348 row_head = ",\n\t\t\t";
349 }
350
351 /* table footer */
352
353 if(XLALFilePuts("\n\t\t</Stream>\n\t</Table>\n", xml->fp) < 0)
355
356 /* done */
357
358 return 0;
359}
int XLALLIGOLwFindColumn(struct MetaioParseEnvironment *env, const char *name, unsigned int type, int required)
Convenience wrapper for MetaioFindColumn(), translating to XLAL-style error reporting and printing us...
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 XLALPrintError(const char *fmt,...) _LAL_GCC_PRINTF_FORMAT_(1
int XLALClearErrno(void)
XLAL_EFUNC
XLAL_EIO
LIGOTimeGPS * XLALGPSSet(LIGOTimeGPS *epoch, INT4 gpssec, INT8 gpsnan)
filename
int XLALWriteLIGOLwXMLSimRingdownTable(LIGOLwXMLStream *xml, const SimRingdownTable *sim_ringdown)
Write a sim_ringdown table to an XML file.
Definition: sim_ringdown.c:262
void XLALDestroySimRingdownTable(SimRingdownTable *head)
Destroy a SimRingdownTable linked list.
Definition: sim_ringdown.c:78
SimRingdownTable * XLALSimRingdownTableFromLIGOLw(const char *filename)
Read the sim_ringdown table from a LIGO Light Weight XML file into a linked list of SimRingdownTable ...
Definition: sim_ringdown.c:91
SimRingdownTable * XLALCreateSimRingdownTableRow(const ProcessTable *process)
Create a SimRingdownTable structure.
Definition: sim_ringdown.c:40
SimRingdownTable * XLALDestroySimRingdownTableRow(SimRingdownTable *row)
Destroy a SimRingdownTable structure.
Definition: sim_ringdown.c:65
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
This structure contains the required information for generating a ringdown injection.
CHAR waveform[LIGOMETA_WAVEFORM_MAX]
LIGOTimeGPS h_start_time
LIGOTimeGPS v_start_time
struct tagSimRingdownTable * next
LIGOTimeGPS geocent_start_time
CHAR coordinates[LIGOMETA_COORDINATES_MAX]
LIGOTimeGPS l_start_time