Loading [MathJax]/extensions/TeX/AMSsymbols.js
LALApps 10.1.0.1-b246709
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
fr_ninja.c
Go to the documentation of this file.
1/*
2 * fr_ninja.c - save numerical relativity waveforms as a frame
3 *
4 * Copyright (C) 2007,2008,2010 Adam Mercer
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with with program; see the file COPYING. If not, write to the
18 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19 * MA 02110-1301 USA
20 */
21
22#include "config.h"
23
24#include <math.h>
25#include <stdio.h>
26#include <stdlib.h>
27
28#include <lal/LALStdio.h>
29#include <lal/LALgetopt.h>
30#include <lal/AVFactories.h>
31#include <lal/ConfigFile.h>
32#include <lal/LALFrameIO.h>
33#include <lal/LALFrStream.h>
34#include <lal/LALDetectors.h>
35#include <lal/NRWaveIO.h>
36#include <lal/NRWaveInject.h>
37#include <lal/TimeSeries.h>
38#include <lal/Units.h>
39
40#include <LALAppsVCSInfo.h>
41
42/* program info */
43#define PROGRAM_NAME "lalapps_fr_ninja"
44
45/* defines */
46/* TODO: how long can a FrHistory comment string be? */
47#define HISTORY_COMMENT 512
48
49/* minimum/maximum l values */
50#define MIN_L 2
51#define MAX_L 8
52
53/* function prototypes */
54static void print_usage(FILE *ptr, CHAR *program);
55
56/* verbose flag */
57extern int vrbflg;
58
59/*
60 * main program entry point
61 */
62INT4 main(INT4 argc, CHAR **argv)
63{
64 /* status */
66
67 /* counters */
68 int c;
69 UINT4 i;
70
71 /* mode counters */
72 UINT4 l, m;
73
74 /* metadata file/directory */
75 CHAR *nrMetaFile = NULL;
76 CHAR *nrDataDir = NULL;
77 CHAR file_path[FILENAME_MAX];
78
79 /* metadata format */
80 CHAR *metadata_format = NULL;
81
82 /* metadata parsing variables */
83 LALParsedDataFile *meta_file = NULL;
84 BOOLEAN wasRead = 0;
85 CHAR field[HISTORY_COMMENT];
86 CHAR *wf_name[MAX_L+1][(2*MAX_L) + 1];
87
88 /* common metadata */
89 CHAR *md_mass_ratio = NULL;
90 CHAR *md_spin1x = NULL;
91 CHAR *md_spin1y = NULL;
92 CHAR *md_spin1z = NULL;
93 CHAR *md_spin2x = NULL;
94 CHAR *md_spin2y = NULL;
95 CHAR *md_spin2z = NULL;
96 CHAR *md_freq_start_22 = NULL;
97
98 /* NINJA1 metadata */
99 CHAR *md_simulation_details = NULL;
100 CHAR *md_nr_group = NULL;
101 CHAR *md_email = NULL;
102
103 /* NINJA2 metadata */
104 CHAR *md_waveform_name = NULL;
105 CHAR *md_initial_separation = NULL;
106 CHAR *md_eccentricity = NULL;
107 CHAR *md_number_of_cycles_22 = NULL;
108 CHAR *md_code = NULL;
109 CHAR *md_submitter_email = NULL;
110 CHAR *md_authors_emails = NULL;
111
112 /* common metadata strings */
113 CHAR str_mass_ratio[HISTORY_COMMENT];
114 CHAR str_spin1x[HISTORY_COMMENT];
115 CHAR str_spin1y[HISTORY_COMMENT];
116 CHAR str_spin1z[HISTORY_COMMENT];
117 CHAR str_spin2x[HISTORY_COMMENT];
118 CHAR str_spin2y[HISTORY_COMMENT];
119 CHAR str_spin2z[HISTORY_COMMENT];
120 CHAR str_freq_start_22[HISTORY_COMMENT];
121 CHAR str_creator[HISTORY_COMMENT];
122
123 /* NINJA1 metadata strings */
124 CHAR str_simulation_details[HISTORY_COMMENT];
125 CHAR str_nr_group[HISTORY_COMMENT];
126 CHAR str_email[HISTORY_COMMENT];
127
128 /* NINJA2 metadata strings */
129 CHAR str_waveform_name[HISTORY_COMMENT];
130 CHAR str_initial_separation[HISTORY_COMMENT];
131 CHAR str_eccentricity[HISTORY_COMMENT];
132 CHAR str_number_of_cycles_22[HISTORY_COMMENT];
133 CHAR str_code[HISTORY_COMMENT];
134 CHAR str_submitter_email[HISTORY_COMMENT];
135 CHAR str_authors_emails[HISTORY_COMMENT];
136
137 /* channel names */
138 CHAR *plus_channel[MAX_L+1][(2*MAX_L) + 1];
139 CHAR *cross_channel[MAX_L+1][(2*MAX_L) + 1];
140
141 /* waveforms */
142 UINT4 wf_length;
143 REAL4TimeVectorSeries *waveforms[MAX_L][(2*MAX_L) + 1];
144 REAL4TimeSeries *hplus[MAX_L+1][(2*MAX_L) + 1];
145 REAL4TimeSeries *hcross[MAX_L+1][(2*MAX_L) + 1];
146
147 REAL8TimeVectorSeries *waveformsREAL8[MAX_L][(2*MAX_L) + 1];
148 REAL8TimeSeries *hplusREAL8[MAX_L+1][(2*MAX_L) + 1];
149 REAL8TimeSeries *hcrossREAL8[MAX_L+1][(2*MAX_L) + 1];
150
151 /* frame variables */
152 LALFrameH *frame;
153 CHAR *frame_name = NULL;
156 INT4 detector_flags;
157
158 INT4 generatingREAL8 = 0;
159
160 /* LALgetopt arguments */
161 struct LALoption long_options[] =
162 {
163 /* options that set a flag */
164 {"verbose", no_argument, &vrbflg, 1},
165 /* options that don't set a flag */
166 {"format", required_argument, 0, 'f'},
167 {"nr-meta-file", required_argument, 0, 'm'},
168 {"nr-data-dir", required_argument, 0, 'd'},
169 {"output", required_argument, 0, 'o'},
170 {"double-precision", no_argument, 0, 'p'},
171 {"help", no_argument, 0, 'h'},
172 {"version", no_argument, 0, 'V'},
173 {0, 0, 0, 0}
174 };
175
176 /* default debug level */
178
179 /* parse the arguments */
180 while(1)
181 {
182 /* LALgetopt_long stores long option here */
183 int option_index = 0;
184 size_t LALoptarg_len;
185
186 c = LALgetopt_long_only(argc, argv, "f:m:d:o:phV", long_options, &option_index);
187
188 /* detect the end of the options */
189 if (c == -1)
190 break;
191
192 switch(c)
193 {
194 case 0:
195 /* if this option sets a flag, do nothing else for now */
196 if (long_options[option_index].flag != 0)
197 break;
198 else
199 {
200 fprintf(stderr, "Error parsing option %s with argument %s\n", long_options[option_index].name, LALoptarg);
201 exit(1);
202 }
203 break;
204
205 case 'h':
206 /* help message */
207 print_usage(stdout, argv[0]);
208 exit(0);
209 break;
210
211 case 'V':
212 /* print version information and exit */
213 fprintf(stdout, "Numerical Relativity Frame Generation\n");
214 XLALOutputVCSInfo(stderr, lalAppsVCSInfoList, 0, "%% ");
215 exit(0);
216 break;
217
218 case 'f':
219 /* create storage for the metadata format */
220 LALoptarg_len = strlen(LALoptarg) + 1;
221 metadata_format = (CHAR *)calloc(LALoptarg_len, sizeof(CHAR));
222 memcpy(metadata_format, LALoptarg, LALoptarg_len);
223 break;
224
225 case 'm':
226 /* create storage for the meta file name */
227 LALoptarg_len = strlen(LALoptarg) + 1;
228 nrMetaFile = (CHAR *)calloc(LALoptarg_len, sizeof(CHAR));
229 memcpy(nrMetaFile, LALoptarg, LALoptarg_len);
230 break;
231
232 case 'd':
233 /* create storage for the meta data directory name */
234 LALoptarg_len = strlen(LALoptarg) + 1;
235 nrDataDir = (CHAR *)calloc(LALoptarg_len, sizeof(CHAR));
236 memcpy(nrDataDir, LALoptarg, LALoptarg_len);
237 break;
238
239 case 'o':
240 /* create storage for the output frame file name */
241 LALoptarg_len = strlen(LALoptarg) + 1;
242 frame_name = (CHAR *)calloc(LALoptarg_len, sizeof(CHAR));
243 memcpy(frame_name, LALoptarg, LALoptarg_len);
244 break;
245
246 case 'p':
247 /* We're generating a double-precision frame */
248 generatingREAL8 = 1;
249 break;
250
251 case '?':
252 print_usage(stderr, argv[0]);
253 exit(1);
254 break;
255
256 default:
257 fprintf(stderr, "Unknown error while parsing arguments\n");
258 print_usage(stderr, argv[0]);
259 exit(1);
260 break;
261 }
262 }
263
264 /* check for extraneous command line arguments */
265 if (LALoptind < argc)
266 {
267 fprintf(stderr, "Extraneous command line arguments:\n");
268 while(LALoptind < argc)
269 fprintf(stderr, "%s\n", argv[LALoptind++]);
270 exit(1);
271 }
272
273 /*
274 * check validity of arguments
275 */
276
277 /* metadata format specified */
278 if (metadata_format == NULL)
279 {
280 fprintf(stderr, "warning: --format not specified, assuming NINJA1\n");
281 metadata_format = (CHAR *)calloc(7, sizeof(CHAR));
282 memcpy(metadata_format, "NINJA1", 7);
283 }
284
285 /* check for supported metadata format */
286 if (strcmp(metadata_format, "NINJA1") == 0);
287 else if (strcmp(metadata_format, "NINJA2") == 0);
288 else
289 {
290 fprintf(stderr, "Supported metadata formats are NINJA1 and NINJA2 (%s specified)\n", metadata_format);
291 exit(1);
292 }
293
294 /* meta file specified */
295 if (nrMetaFile == NULL)
296 {
297 fprintf(stderr, "--nr-meta-file must be specified\n");
298 exit(1);
299 }
300
301 /* data directory specified */
302 if (nrDataDir == NULL)
303 {
304 fprintf(stderr, "--nr-data-dir must be specified\n");
305 exit(1);
306 }
307
308 /* output frame filename specified */
309 if (frame_name == NULL)
310 {
311 fprintf(stderr, "--output must be specified\n");
312 exit(1);
313 }
314
315 /*
316 * main code
317 */
318
319 /* frame metadata */
320 /* TODO: set these to something sensible */
321 duration = 0;
322 epoch.gpsSeconds = 0;
323 epoch.gpsNanoSeconds = 0;
324 detector_flags = 0;
325
326 if (vrbflg)
327 fprintf(stdout, "reading metadata: %s\n", nrMetaFile);
328
329 /* open metadata file */
330 XLAL_CHECK ( XLALParseDataFile(&meta_file, nrMetaFile) == XLAL_SUCCESS, XLAL_EFUNC );
331
332 /*
333 * get metadata
334 */
335
336 /* common metadata */
337 XLAL_CHECK ( XLALReadConfigSTRINGVariable( &md_mass_ratio, meta_file, NULL, "mass-ratio", &wasRead) == XLAL_SUCCESS, XLAL_EFUNC );
338 XLAL_CHECK ( XLALReadConfigSTRINGVariable( &md_spin1x, meta_file, NULL, "spin1x", &wasRead) == XLAL_SUCCESS, XLAL_EFUNC );
339 XLAL_CHECK ( XLALReadConfigSTRINGVariable( &md_spin1y, meta_file, NULL, "spin1y", &wasRead) == XLAL_SUCCESS, XLAL_EFUNC );
340 XLAL_CHECK ( XLALReadConfigSTRINGVariable( &md_spin1z, meta_file, NULL, "spin1z", &wasRead) == XLAL_SUCCESS, XLAL_EFUNC );
341 XLAL_CHECK ( XLALReadConfigSTRINGVariable( &md_spin2x, meta_file, NULL, "spin2x", &wasRead) == XLAL_SUCCESS, XLAL_EFUNC );
342 XLAL_CHECK ( XLALReadConfigSTRINGVariable( &md_spin2y, meta_file, NULL, "spin2y", &wasRead) == XLAL_SUCCESS, XLAL_EFUNC );
343 XLAL_CHECK ( XLALReadConfigSTRINGVariable( &md_spin2z, meta_file, NULL, "spin2z", &wasRead) == XLAL_SUCCESS, XLAL_EFUNC );
344
345 /* format specific metadata */
346 if (strcmp(metadata_format, "NINJA1") == 0)
347 {
348 /* NINJA1 */
349 XLAL_CHECK ( XLALReadConfigSTRINGVariable( &md_simulation_details, meta_file, NULL, "simulation-details", &wasRead) == XLAL_SUCCESS, XLAL_EFUNC );
350 XLAL_CHECK ( XLALReadConfigSTRINGVariable( &md_nr_group, meta_file, NULL, "nr-group", &wasRead) == XLAL_SUCCESS, XLAL_EFUNC );
351 XLAL_CHECK ( XLALReadConfigSTRINGVariable( &md_email, meta_file, NULL, "email", &wasRead) == XLAL_SUCCESS, XLAL_EFUNC );
352 XLAL_CHECK ( XLALReadConfigSTRINGVariable( &md_freq_start_22, meta_file, NULL, "freqStart22", &wasRead) == XLAL_SUCCESS, XLAL_EFUNC );
353 }
354 else if (strcmp(metadata_format, "NINJA2") == 0)
355 {
356 /* NINJA2 */
357 XLAL_CHECK ( XLALReadConfigSTRINGVariable( &md_waveform_name, meta_file, NULL, "waveform-name", &wasRead) == XLAL_SUCCESS, XLAL_EFUNC );
358 XLAL_CHECK ( XLALReadConfigSTRINGVariable( &md_initial_separation, meta_file, NULL, "initial-separation", &wasRead) == XLAL_SUCCESS, XLAL_EFUNC );
359 XLAL_CHECK ( XLALReadConfigSTRINGVariable( &md_eccentricity, meta_file, NULL, "eccentricity", &wasRead) == XLAL_SUCCESS, XLAL_EFUNC );
360 XLAL_CHECK ( XLALReadConfigSTRINGVariable( &md_number_of_cycles_22, meta_file, NULL, "number-of-cycles-22", &wasRead) == XLAL_SUCCESS, XLAL_EFUNC );
361 XLAL_CHECK ( XLALReadConfigSTRINGVariable( &md_code, meta_file, NULL, "code", &wasRead) == XLAL_SUCCESS, XLAL_EFUNC );
362 XLAL_CHECK ( XLALReadConfigSTRINGVariable( &md_submitter_email, meta_file, NULL, "submitter-email", &wasRead) == XLAL_SUCCESS, XLAL_EFUNC );
363 XLAL_CHECK ( XLALReadConfigSTRINGVariable( &md_authors_emails, meta_file, NULL, "authors-emails", &wasRead) == XLAL_SUCCESS, XLAL_EFUNC );
364 XLAL_CHECK ( XLALReadConfigSTRINGVariable( &md_freq_start_22, meta_file, NULL, "freq-start-22", &wasRead) == XLAL_SUCCESS, XLAL_EFUNC );
365 }
366 else
367 {
368 /* unknown metadata format - should not be executed */
369 fprintf(stderr, "error: unsupported metadata format: %s\n", metadata_format);
370 exit(1);
371 }
372
373 /*
374 * set metadata strings
375 */
376
377 /* common waveform */
378 snprintf(str_mass_ratio, HISTORY_COMMENT, "mass-ratio:%s", md_mass_ratio);
379 snprintf(str_spin1x, HISTORY_COMMENT, "spin1x:%s", md_spin1x);
380 snprintf(str_spin1y, HISTORY_COMMENT, "spin1y:%s", md_spin1y);
381 snprintf(str_spin1z, HISTORY_COMMENT, "spin1z:%s", md_spin1z);
382 snprintf(str_spin2x, HISTORY_COMMENT, "spin2x:%s", md_spin2x);
383 snprintf(str_spin2y, HISTORY_COMMENT, "spin2y:%s", md_spin2y);
384 snprintf(str_spin2z, HISTORY_COMMENT, "spin2z:%s", md_spin2z);
385 snprintf(str_creator, HISTORY_COMMENT, "creator:%s(git:%s)", PROGRAM_NAME, lalAppsVCSInfo.vcsId);
386
387 /* format specific metadata */
388 if (strcmp(metadata_format, "NINJA1") == 0)
389 {
390 /* NINJA1 */
391 snprintf(str_freq_start_22, HISTORY_COMMENT, "freqStart22:%s", md_freq_start_22);
392 snprintf(str_simulation_details, HISTORY_COMMENT, "simulation-details:%s", md_simulation_details);
393 snprintf(str_nr_group, HISTORY_COMMENT, "nr-group:%s", md_nr_group);
394 snprintf(str_email, HISTORY_COMMENT, "email:%s", md_email);
395 }
396 else if (strcmp(metadata_format, "NINJA2") == 0)
397 {
398 /* NINJA2 */
399 snprintf(str_waveform_name, HISTORY_COMMENT, "waveform-name:%s", md_waveform_name);
400 snprintf(str_initial_separation, HISTORY_COMMENT, "inital-separation:%s", md_initial_separation);
401 snprintf(str_eccentricity, HISTORY_COMMENT, "eccentricity:%s", md_eccentricity);
402 snprintf(str_freq_start_22, HISTORY_COMMENT, "freq_start_22:%s", md_freq_start_22);
403 snprintf(str_number_of_cycles_22, HISTORY_COMMENT, "number-of-cycles-22:%s", md_number_of_cycles_22);
404 snprintf(str_code, HISTORY_COMMENT, "code:%s", md_code);
405 snprintf(str_submitter_email, HISTORY_COMMENT, "submitter-email:%s", md_submitter_email);
406 snprintf(str_authors_emails, HISTORY_COMMENT, "authors-emails:%s", md_authors_emails);
407 }
408 else
409 {
410 /* unknown metadata format - should not be executed */
411 fprintf(stderr, "error: unsupported metadata format: %s\n", metadata_format);
412 exit(1);
413 }
414
415 /* define frame */
416 frame = XLALFrameNew(&epoch, duration, "NR", 0, 1, detector_flags);
417
418 /*
419 * add metadata as FrHistory structures
420 */
421
422 /* common metadata */
423 XLALFrameAddFrHistory(frame, "creator", str_creator);
424 XLALFrameAddFrHistory(frame, "mass-ratio", str_mass_ratio);
425 XLALFrameAddFrHistory(frame, "spin1x", str_spin1x);
426 XLALFrameAddFrHistory(frame, "spin1y", str_spin1y);
427 XLALFrameAddFrHistory(frame, "spin1z", str_spin1z);
428 XLALFrameAddFrHistory(frame, "spin2x", str_spin2x);
429 XLALFrameAddFrHistory(frame, "spin2y", str_spin2y);
430 XLALFrameAddFrHistory(frame, "spin2z", str_spin2z);
431
432 /* format specific metadata */
433 if (strcmp(metadata_format, "NINJA1") == 0)
434 {
435 /* NINJA1 */
436 XLALFrameAddFrHistory(frame, "simulation-details", str_simulation_details);
437 XLALFrameAddFrHistory(frame, "nr-group", str_nr_group);
438 XLALFrameAddFrHistory(frame, "email", str_email);
439 XLALFrameAddFrHistory(frame, "freqStart22", str_freq_start_22);
440 }
441 else if (strcmp(metadata_format, "NINJA2") == 0)
442 {
443 /* NINJA2 */
444 XLALFrameAddFrHistory(frame, "waveform-name", str_waveform_name);
445 XLALFrameAddFrHistory(frame, "initial-separation", str_initial_separation);
446 XLALFrameAddFrHistory(frame, "eccentricity", str_eccentricity);
447 XLALFrameAddFrHistory(frame, "freq_start_22", str_freq_start_22);
448 XLALFrameAddFrHistory(frame, "number-of-cycles-22", str_number_of_cycles_22);
449 XLALFrameAddFrHistory(frame, "code", str_code);
450 XLALFrameAddFrHistory(frame, "submitter-email", str_code);
451 XLALFrameAddFrHistory(frame, "authors-emails", str_authors_emails);
452 }
453 else
454 {
455 /* unknown metadata format - should not be executed */
456 fprintf(stderr, "error: unsupported metadata format: %s\n", metadata_format);
457 exit(1);
458 }
459
460 /* loop over l & m values */
461 for (l = MIN_L; l <= MAX_L; l++)
462 {
463 for (m = (MAX_L - l); m <= MAX_L + l; m++)
464 {
465 /* ensure pointers are NULL */
466 wf_name[l][m] = NULL;
467 plus_channel[l][m] = NULL;
468 cross_channel[l][m] = NULL;
469
470 /* generate channel names */
471 plus_channel[l][m] = XLALGetNinjaChannelName("plus", l, m - MAX_L);
472 cross_channel[l][m] = XLALGetNinjaChannelName("cross", l, m - MAX_L);
473
474 if (generatingREAL8)
475 {
476 hplusREAL8[l][m] = NULL;
477 hcrossREAL8[l][m] = NULL;
478 waveformsREAL8[l][m] = NULL;
479
480 /* initilise waveform time series */
481 hplusREAL8[l][m] = XLALCreateREAL8TimeSeries(plus_channel[l][m], &epoch, 0, 0, &lalDimensionlessUnit, 0);
482 hcrossREAL8[l][m] = XLALCreateREAL8TimeSeries(cross_channel[l][m], &epoch, 0, 0, &lalDimensionlessUnit, 0);
483 }
484 else
485 {
486 hplus[l][m] = NULL;
487 hcross[l][m] = NULL;
488 waveforms[l][m] = NULL;
489
490 /* initilise waveform time series */
491 hplus[l][m] = XLALCreateREAL4TimeSeries(plus_channel[l][m], &epoch, 0, 0, &lalDimensionlessUnit, 0);
492 hcross[l][m] = XLALCreateREAL4TimeSeries(cross_channel[l][m], &epoch, 0, 0, &lalDimensionlessUnit, 0);
493 }
494
495 /* read ht-data section of metadata file */
496 snprintf(field, HISTORY_COMMENT, "%d,%d", l, m - MAX_L);
497 XLAL_CHECK ( XLALReadConfigSTRINGVariable( &wf_name[l][m], meta_file, NULL, field, &wasRead) == XLAL_SUCCESS, XLAL_EFUNC );
498
499 /* read waveform */
500 if (wf_name[l][m] != NULL)
501 {
502 /* get full path to waveform data file */
503 snprintf(file_path, FILENAME_MAX, "%s/%s", nrDataDir, wf_name[l][m]);
504
505 if (vrbflg)
506 fprintf(stdout, "reading waveform: %s\n", file_path);
507
508 /* read waveforms */
509 if (generatingREAL8)
510 {
511 LAL_CALL(LALReadNRWave_raw_real8(&status, &waveformsREAL8[l][m], file_path), &status);
512 }
513 else
514 {
515 LAL_CALL(LALReadNRWave_raw(&status, &waveforms[l][m], file_path), &status);
516 }
517 }
518
519 /* generate waveform time series from vector series */
520 /* TODO: should use pointer arithmetic here and update the data
521 * pointer in the REAL4TimeSeries to point to the appropriate
522 * location within the REAL4TimeVector Series */
523 if (generatingREAL8) {
524 if (waveformsREAL8[l][m])
525 {
526 /* get length of waveform */
527 wf_length = waveformsREAL8[l][m]->data->vectorLength;
528
529 /* allocate memory for waveform */
530 XLALResizeREAL8TimeSeries(hplusREAL8[l][m], 0, wf_length);
531 XLALResizeREAL8TimeSeries(hcrossREAL8[l][m], 0, wf_length);
532
533 /* set time spacing */
534 hplusREAL8[l][m]->deltaT = waveformsREAL8[l][m]->deltaT;
535 hcrossREAL8[l][m]->deltaT = waveformsREAL8[l][m]->deltaT;
536
537 /* copy waveforms into appropriate series */
538 for (i = 0; i < wf_length; i ++) {
539 hplusREAL8[l][m]->data->data[i] = waveformsREAL8[l][m]->data->data[i];
540 hcrossREAL8[l][m]->data->data[i] = waveformsREAL8[l][m]->data->data[wf_length + i];
541 }
542
543 /* Done with waveformsREAL8, clean up here to limit memory usage */
544 LALFree(waveformsREAL8[l][m]->data->data);
545 LALFree(waveformsREAL8[l][m]->data);
546 LALFree(waveformsREAL8[l][m]);
547 }
548 }
549 else /* REAL4 */
550 {
551 if (waveforms[l][m])
552 {
553 /* get length of waveform */
554 wf_length = waveforms[l][m]->data->vectorLength;
555
556 /* allocate memory for waveform */
557 XLALResizeREAL4TimeSeries(hplus[l][m], 0, wf_length);
558 XLALResizeREAL4TimeSeries(hcross[l][m], 0, wf_length);
559
560 /* set time spacing */
561 hplus[l][m]->deltaT = waveforms[l][m]->deltaT;
562 hcross[l][m]->deltaT = waveforms[l][m]->deltaT;
563
564 /* copy waveforms into appropriate series */
565 for (i = 0; i < wf_length; i ++) {
566 hplus[l][m]->data->data[i] = waveforms[l][m]->data->data[i];
567 hcross[l][m]->data->data[i] = waveforms[l][m]->data->data[wf_length + i];
568 }
569 }
570 }
571
572 /* add channels to frame */
573 if (generatingREAL8)
574 {
575 if ((hplusREAL8[l][m]->data->length) && (hcrossREAL8[l][m]->data->length))
576 {
577 XLALFrameAddREAL8TimeSeriesSimData(frame, hplusREAL8[l][m]);
578 XLALFrameAddREAL8TimeSeriesSimData(frame, hcrossREAL8[l][m]);
579 }
580 }
581 else
582 {
583 if ((hplus[l][m]->data->length) && (hcross[l][m]->data->length))
584 {
585 XLALFrameAddREAL4TimeSeriesSimData(frame, hplus[l][m]);
586 XLALFrameAddREAL4TimeSeriesSimData(frame, hcross[l][m]);
587 }
588 }
589 }
590 }
591
592 if (vrbflg)
593 fprintf(stdout, "writing frame: %s\n", frame_name);
594
595 /* write frame */
596 if (XLALFrameWrite(frame, frame_name) != 0 )
597 {
598 fprintf(stderr, "Error: Cannot save frame file '%s'\n", frame_name);
599 exit(1);
600 }
601
602 /*
603 * clear memory
604 */
605
606 /* strings */
607 if(nrMetaFile) free(nrMetaFile);
608 if(nrDataDir) free(nrDataDir);
609 if(frame_name) free(frame_name);
610 if(metadata_format) free(metadata_format);
611
612 /* common metadata */
613 if(md_mass_ratio) LALFree(md_mass_ratio);
614 if(md_spin1x) LALFree(md_spin1x);
615 if(md_spin1y) LALFree(md_spin1y);
616 if(md_spin1z) LALFree(md_spin1z);
617 if(md_spin2x) LALFree(md_spin2x);
618 if(md_spin2y) LALFree(md_spin2y);
619 if(md_spin2z) LALFree(md_spin2z);
620 if(md_freq_start_22) LALFree(md_freq_start_22);
621
622 /* NINJA1 metadata */
623 if(md_simulation_details) LALFree(md_simulation_details);
624 if(md_nr_group) LALFree(md_nr_group);
625 if(md_email) LALFree(md_email);
626
627 /* NINJA2 metadata */
628 if(md_waveform_name) LALFree(md_waveform_name);
629 if(md_initial_separation) LALFree(md_initial_separation);
630 if(md_eccentricity) LALFree(md_eccentricity);
631 if(md_number_of_cycles_22) LALFree(md_number_of_cycles_22);
632 if(md_code) LALFree(md_code);
633 if(md_submitter_email) LALFree(md_submitter_email);
634 if(md_authors_emails) LALFree(md_authors_emails);
635
636 /* config file */
637 if(meta_file->lines->list->data) LALFree(meta_file->lines->list->data);
638 if(meta_file->lines->list) LALFree(meta_file->lines->list);
639 if(meta_file->lines->tokens) LALFree(meta_file->lines->tokens);
640 if(meta_file->lines) LALFree(meta_file->lines);
641 if(meta_file->wasRead) LALFree(meta_file->wasRead);
642 if(meta_file) LALFree(meta_file);
643
644 /* waveforms */
645 if (generatingREAL8)
646 {
647 for (l = MIN_L; l <= MAX_L; l++)
648 {
649 for (m = (MAX_L - l); m <= MAX_L + l; m++)
650 {
651 /* channel names */
652 if (plus_channel[l][m])
653 LALFree(plus_channel[l][m]);
654
655 if (cross_channel[l][m])
656 LALFree(cross_channel[l][m]);
657
658 if (wf_name[l][m])
659 LALFree(wf_name[l][m]);
660
661 /* hplus */
662 if (hplusREAL8[l][m])
663 XLALDestroyREAL8TimeSeries(hplusREAL8[l][m]);
664
665 /* hcross */
666 if (hcrossREAL8[l][m])
667 XLALDestroyREAL8TimeSeries(hcrossREAL8[l][m]);
668 }
669 }
670 }
671 else
672 {
673 for (l = MIN_L; l <= MAX_L; l++)
674 {
675 for (m = (MAX_L - l); m <= MAX_L + l; m++)
676 {
677 /* channel names */
678 if (plus_channel[l][m])
679 LALFree(plus_channel[l][m]);
680
681 if (cross_channel[l][m])
682 LALFree(cross_channel[l][m]);
683
684 if (wf_name[l][m])
685 LALFree(wf_name[l][m]);
686
687 /* raw waveforms */
688 if (waveforms[l][m]) {
689 LALFree(waveforms[l][m]->data->data);
690 LALFree(waveforms[l][m]->data);
691 LALFree(waveforms[l][m]);
692 }
693
694 /* hplus */
695 if (hplus[l][m])
697
698 /* hcross */
699 if (hcross[l][m])
701 }
702 }
703 }
704
705 /* clear frame */
706 XLALFrameFree(frame);
707
708 /* check for memory leaks */
710
711 exit(0);
712}
713
714
715/* function to display usage information */
716static void print_usage(FILE *ptr, CHAR *program)
717{
718 fprintf(ptr,
719 "Usage: %s [options\n"\
720 "[--help display this message and exit]\n"\
721 "[--version print version information and exit]\n"\
722 "[--verbose display progress information]\n"\
723 "[--format FORMAT metadata format, defaults to NINJA1]\n"\
724 "[--double-precision generate REAL8 files, default is REAL4]\n"\
725 " --nr-meta-file FILE file containing the details of the available\n"\
726 " numerical relativity waveforms\n"\
727 " --nr-data-dir DIR directory containing the numerical relativity\n"\
728 " waveforms\n"\
729 " --output FILE name of output frame file\n", program);
730}
const char * program
int XLALReadConfigSTRINGVariable(CHAR **varp, LALParsedDataFile *cfgdata, const CHAR *secName, const CHAR *varName, BOOLEAN *wasRead)
const LALVCSInfoList lalAppsVCSInfoList
NULL-terminated list of VCS and build information for LALApps and its dependencies
const LALVCSInfo lalAppsVCSInfo
VCS and build information for LALApps.
lal_errhandler_t lal_errhandler
int LAL_ERR_EXIT(LALStatus *stat, const char *func, const char *file, const int line, volatile const char *id)
#define LAL_CALL(function, statusptr)
ProcessParamsTable * ptr
void LALCheckMemoryLeaks(void)
#define LALFree(p)
int LALgetopt_long_only(int argc, char *const *argv, const char *options, const struct LALoption *long_options, int *opt_index)
int LALoptind
char * LALoptarg
#define no_argument
#define required_argument
#define fprintf
int l
INT4 duration
Definition: blindinj.c:123
sigmaKerr data[0]
#define MIN_L
Definition: fr_ninja.c:50
#define PROGRAM_NAME
Definition: fr_ninja.c:43
static void print_usage(FILE *ptr, CHAR *program)
Definition: fr_ninja.c:716
INT4 main(INT4 argc, CHAR **argv)
Definition: fr_ninja.c:62
int vrbflg
defined in lal/lib/std/LALError.c
#define HISTORY_COMMENT
Definition: fr_ninja.c:47
#define MAX_L
Definition: fr_ninja.c:51
int XLALParseDataFile(LALParsedDataFile **cfgdata, const CHAR *fname)
unsigned char BOOLEAN
#define XLAL_INIT_DECL(var,...)
char CHAR
uint32_t UINT4
int32_t INT4
int XLALFrameAddREAL8TimeSeriesSimData(LALFrameH *frame, const REAL8TimeSeries *series)
LALFrameUFrameH LALFrameH
int XLALFrameAddFrHistory(LALFrameH *frame, const char *name, const char *comment)
int XLALFrameWrite(LALFrameH *frame, const char *fname)
int XLALFrameAddREAL4TimeSeriesSimData(LALFrameH *frame, const REAL4TimeSeries *series)
LALFrameH * XLALFrameNew(const LIGOTimeGPS *epoch, double duration, const char *project, int run, int frnum, INT8 detectorFlags)
void XLALFrameFree(LALFrameH *frame)
int XLALOutputVCSInfo(FILE *fp, const LALVCSInfoList vcs_list, const int verbose, const char *prefix)
void LALReadNRWave_raw_real8(LALStatus *status, REAL8TimeVectorSeries **out, const CHAR *filename)
void LALReadNRWave_raw(LALStatus *status, REAL4TimeVectorSeries **out, const CHAR *filename)
CHAR * XLALGetNinjaChannelName(const CHAR *polarisation, UINT4 l, INT4 m)
static const INT4 m
REAL4TimeSeries * XLALCreateREAL4TimeSeries(const CHAR *name, const LIGOTimeGPS *epoch, REAL8 f0, REAL8 deltaT, const LALUnit *sampleUnits, size_t length)
void XLALDestroyREAL8TimeSeries(REAL8TimeSeries *series)
REAL8TimeSeries * XLALResizeREAL8TimeSeries(REAL8TimeSeries *series, int first, size_t length)
void XLALDestroyREAL4TimeSeries(REAL4TimeSeries *series)
REAL8TimeSeries * XLALCreateREAL8TimeSeries(const CHAR *name, const LIGOTimeGPS *epoch, REAL8 f0, REAL8 deltaT, const LALUnit *sampleUnits, size_t length)
REAL4TimeSeries * XLALResizeREAL4TimeSeries(REAL4TimeSeries *series, int first, size_t length)
const LALUnit lalDimensionlessUnit
#define XLAL_CHECK(assertion,...)
XLAL_SUCCESS
XLAL_EFUNC
char name[LIGOMETA_SOURCE_MAX]
Definition: inspinj.c:561
static LALStatus status
Definition: inspinj.c:552
int i
Definition: inspinj.c:596
c
CHAR * data
TokenList * lines
const char *const vcsId
int * flag
CHAR ** tokens
CHARVector * list
enum @1 epoch