Loading [MathJax]/extensions/TeX/AMSsymbols.js
LALApps 10.1.0.1-5e288d3
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
inspfrinj.c
Go to the documentation of this file.
1/*
2* Copyright (C) 2007 Duncan Brown, Stephen Fairhurst
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: inspfrinj.c
23 *
24 * Author: Fairhurst, S. (based on inspiral.c by Brown, D.A.)
25 *
26 *
27 *-----------------------------------------------------------------------
28 */
29
30/**
31 * \file
32 * \ingroup lalapps_inspiral
33 *
34 * <dl>
35 * <dt>Name</dt><dd>
36 * \c lalapps_inspfrinj --- performs inspiral injections into frame data.</dd>
37 *
38 * <dt>Synopsis</dt><dd>
39 * \code
40 * lalapps_inspfrinj [options]
41 *
42 * [--help ]
43 * [--verbose ]
44 * [--version ]
45 * [--user-tag STRING ]
46 * [--comment STRING ]
47 *
48 * --gps-start-time SEC
49 * [--gps-start-time-ns NS ]
50 * --gps-end-time SEC
51 * [--gps-end-time-ns NS ]
52 *
53 * [--frame-cache FRAME_CACHE
54 * --channel-name CHAN ]
55 *
56 * [--ifo IFO
57 * --sample-rate SAMPLE_RATE ]
58 *
59 * --calibration-cache CAL_CACHE
60 * --calibrated-data TYPE
61 *
62 * [--num-resp-points N ]
63 *
64 * --injection-file FILE
65 * --injection-channel INJ
66 * [--inject-overhead ]
67 * [--inject-safety SEC ]
68 *
69 * [--write-raw-data ]
70 * [--write-inj-only ]
71 * [--write-raw-plus-inj ]
72 *
73 * --output-frame-length OUTPUT_LENGTH
74 * [--output-file-name OUTPUT_NAME ]
75 *
76 * \endcode</dd>
77 *
78 * <dt>Description</dt><dd>
79 *
80 * \c lalapps_frinspinj generates injections and stores them as
81 * frame files. This code is essentially a copy of those parts of
82 * \c lalapps_inspiral responsible for reading in the data and
83 * performing the injections. The injection details are either read in
84 * from frame files containin an injection channel or from the
85 * \c sim_inspiral table of a LIGO lightweight xml file or Is a
86 * \c sim_inspiral table is given, the injections are generated
87 * using LALFindChirpInjectSignals. The injection data is output to frame
88 * files. The length of the output frames is specified by
89 * <tt>output-frame-length</tt>.
90 *
91 * The code is capable of generating both calibrated and uncalibrated
92 * injections. To obtain calibrated h(t) injections the option
93 * <tt>calibrated-data</tt> must be specified (at present the code only
94 * works for real_4 data). Alternatively, if a \c CAL_CACHE is
95 * given, then uncalibrated injections will be produced using the a
96 * response function generated from the calibration data in the cache. The
97 * calibration coefficients will by default be averaged over the duration
98 * of the data. When working with uncalibrated data, the number of points
99 * used to determine the response function will have an effect, albeit
100 * minor, on the injection signals. By default, the value
101 * <tt>num-resp-points</tt> is set to 4194304. This matches the value used
102 * by \c lalapps_inspiral when working with 256 second segments and
103 * a channel sampled at 16384 Hz.
104 *
105 * If input data is given by a \c FRAME_CACHE, the code will read in
106 * this data. In this case, the sample rate and ifo will be determined
107 * from the data and channel name respectively. The output frames can
108 * contain any of the following: raw data, injection only and raw plus
109 * injection.
110 *
111 * If no input data is provided, then the \c IFO and
112 * \c SAMPLE_RATE must be given on the command line. Since no input
113 * data is read in, the output data can only contain the injection only
114 * channel.
115 *
116 * The output of \c lalapps_frinspinj is an xml file and one or several
117 * frame files. The xml file contains
118 * \c process, \c process_params, \c search_summary and
119 * \c sim_inspiral tables and is named (unless set on the command line):
120 *
121 * <tt>IFO-INSPFRINJ_USERTAG-GPSSTARTTIME-DURATION.xml</tt>\\
122 *
123 * where \c GPSSTARTTIME and \c DURATION are the start time and
124 * duration passed to the code. If <tt>--output-file-name</tt> is set to
125 * \c OUTPUT on the command line, the xml will be named
126 *
127 * <tt>OUTPUT_USERTAG-GPSSTARTTIME-DURATION.xml</tt>.\\
128 *
129 * The \c sim_inspiral table contains a list of all injections which
130 * were performed into the specified data. The length of output frame
131 * files is specified by <tt>output-frame-length</tt>. Unless otherwise set
132 * on the command line, output frames are named:
133 *
134 * <tt>IFO-INSPFRINJ_USERTAG-FRAMESTARTTIME-FRAMELENGTH.gwf</tt>\\
135 *
136 * The channels stored in the output frame are determined by which of
137 * <tt>--write-raw-data</tt>, <tt>--write-inj-only</tt> and
138 * <tt>--write-raw-plus-inj</tt> are selected. The channel names are
139 * \c CHAN, \c CHAN_INSP_INJ_ONLY and
140 * \c CHAN_RAW_PLUS_INSP_INJ. In the case where no input data is
141 * given, the single output channel name is \c IFO:STRAIN_INSP_INJ_ONLY.</dd>
142 *
143 * <dt>Options</dt><dd>
144 * <ul>
145 *
146 * <li><tt>--help</tt>: Optional. Print a help message and exit.</li>
147 *
148 * <li><tt>--verbose</tt>: Optional. Print out the author, CVS version
149 * and tag information and exit.</li>
150 *
151 * <li><tt>--version</tt>: Optional. Print out the author, CVS version and
152 * tag information and exit.
153 * </li>
154 * <li><tt>--user-tag</tt> \c USERTAG: Optional. Set the user tag
155 * for this job to be \c USERTAG. May also be specified on the command
156 * line as <tt>-userTag</tt> for LIGO database compatibility. This will
157 * affect the naming of the output file.</li>
158 *
159 * <li><tt>--comment</tt> \c string: Optional. Add \c string
160 * to the comment field in the process table. If not specified, no comment
161 * is added. </li>
162 *
163 * <li><tt>--gps-start-time</tt> <tt>GPS seconds</tt>: Required. Start
164 * time, GPS seconds.</li>
165 *
166 * <li><tt>--gps-start-time-ns</tt> <tt>GPS seconds</tt>: Optional.
167 * Start time, GPS nanoseconds. If not specified, then set to zero.</li>
168 *
169 * <li><tt>--gps-end-time</tt> <tt>GPS seconds</tt>: Required. End
170 * time, GPS seconds.</li>
171 *
172 * <li><tt>--gps-end-time-ns</tt> <tt>GPS seconds</tt>: Optional.
173 * Start time, GPS nanoseconds. If not specified, then set to zero.</li>
174 *
175 * <li><tt>--frame-cache</tt> \c FRAME_CACHE: Optional. Name of
176 * the frame cache file. If this is not specified then the code will not
177 * read in any input data. Hence it will be unable to produce the raw or
178 * raw_plus_inj frames.</li>
179 *
180 * <li><tt>--channel-name</tt> \c CHAN: Optional. Input data
181 * channel name. This must be specified if the <tt>frame-cache</tt> file
182 * is specified.
183 * </li>
184 * <li><tt>--ifo</tt> \c IFO: Optional. Set input interferometer
185 * name to \c IFO. This information is required unless a
186 * <tt>channel-name</tt> is specified (in this case the \c IFO is
187 * obtained from the channel name).</li>
188 *
189 * <li><tt>--sample-rate</tt> \c SAMPLE_RATE: Optional. Set the
190 * sample rate (in Hz) at which the injections should be produced. This is
191 * required unless a frame cache is given (in this case, the sample rate of
192 * the injections matches the input data).</li>
193 *
194 * <li><tt>--calibration-cache</tt> \c CAL_CACHE: Optional.
195 * Specify the \c CAL_CACHE to obtain the calibration information.</li>
196 *
197 * <li><tt>--calibrated-data </tt>\c TYPE: Optional. Use
198 * calibrated data as input/output. This will produce strain data
199 * injections. This option must be specified if no calibration cache is
200 * given.
201 * </li>
202 * <li><tt>--num-resp-points</tt> \c N: Optional. The number of
203 * points used to generate the response function. If generating
204 * uncalibrated injections, this can actually change slightly the injection
205 * data. If not specified, then set to default value of 4194304.
206 * </li>
207 * <li><tt>--injection-channel</tt> \c INJ: Optional. If this
208 * option is specified, the code will read in injection data from the INJ
209 * channel and add it to the raw data. Either this option or
210 * <tt>--injection-file</tt> must be specified.
211 * </li>
212 * <li><tt>--injection-file</tt> \c FILE: Optional. Read in the
213 * injection data from \c FILE. This should contain a
214 * \c sim_inspiral table with a list of injections. Either this
215 * option or <tt>--injection-channel</tt> must be specified.</li>
216 *
217 * <li><tt>--inject-overhead</tt>: Optional. Perform the injections
218 * directly overhead the interferometer and optimally oriented.</li>
219 *
220 * <li><tt>--inject-safety</tt> \c SEC: Optional. Inject signals
221 * whose end time is up to \c SEC after the gps end time.
222 * </li>
223 * <li><tt>--write-raw-data</tt>: Optional. Write out a frame
224 * containing the raw data. This can only be done if the raw data has been
225 * read in from frames.</li>
226 *
227 * <li><tt>--write-inj-only</tt>: Optional. Write out a frame
228 * containing only the injection data.</li>
229 *
230 * <li><tt>--write-raw-plus-inj</tt>: Optional. Write out a frame
231 * containing the raw data with the injections added.
232 * </li>
233 * <li><tt>--output-frame-length</tt> \c OUTPUT_LENGTH: Required.
234 * Specify the length of the output frames to be \c output_length
235 * seconds.</li>
236 *
237 * <li><tt>--output-file-name</tt> \c OUTPUT_NAME : Optional.
238 * Set the output file name. This overrides the default file naming
239 * convention given above.
240 * </li>
241 * </ul></dd>
242 *
243 * <dt>Example</dt><dd>
244 * \code
245 * lalapps_frinspinj --gps-start-time 732758030 --gps-end-time 732760078 \
246 * --frame-cache cache/L-732758022-732763688.cache --channel-name L1:LSC-AS_Q\
247 * --calibration-cache cache_files/L1-CAL-V03-729273600-734367600.cache \
248 * --injection-file HL-INJECTIONS_4096-729273613-5094000.xml \
249 * --inject-safety 50 --output-frame-length 16 \
250 * --write-raw-data --write-inj-only --write-raw-plus-inj
251 * \endcode</dd>
252 *
253 * <dt>Author</dt><dd>
254 * Steve Fairhurst</dd>
255 * </dl>
256 */
257
258#include <config.h>
259#include <stdio.h>
260#include <stdlib.h>
261#include <string.h>
262#include <sys/types.h>
263#include <sys/stat.h>
264#include <fcntl.h>
265#include <regex.h>
266#include <time.h>
267#include <math.h>
268
269#include <series.h>
270#include <lalappsfrutils.h>
271
272#include <lal/LALConfig.h>
273#include <lal/LALgetopt.h>
274#include <lal/LALStdio.h>
275#include <lal/LALStdlib.h>
276#include <lal/LALError.h>
277#include <lal/LALDatatypes.h>
278#include <lal/AVFactories.h>
279#include <lal/LALConstants.h>
280#include <lal/LALFrStream.h>
281#include <lal/Calibration.h>
282#include <lal/LALFrameIO.h>
283#include <lal/FindChirp.h>
284#include <lal/LIGOLwXML.h>
285#include <lal/LIGOLwXMLRead.h>
286#include <lal/LIGOMetadataTables.h>
287#include <lal/LIGOMetadataUtils.h>
288#include <lal/LIGOMetadataInspiralUtils.h>
289#include <lal/Date.h>
290#include <lal/Units.h>
291#include <lal/TimeSeries.h>
292
293#include <LALAppsVCSInfo.h>
294
295#define CVS_ID_STRING "$Id$"
296#define CVS_NAME_STRING "$Name$"
297#define CVS_REVISION "$Revision$"
298#define CVS_SOURCE "$Source$"
299#define CVS_DATE "$Date$"
300#define PROGRAM_NAME "inspiral"
301
302int arg_parse_check( int argc, char *argv[], ProcessParamsTable *procparams );
303
304/*
305 *
306 * variables that control program behaviour
307 *
308 */
309
310/* debugging */
311extern int vrbflg; /* verbocity of lal function */
312/* input data parameters */
313INT8 gpsStartTimeNS = 0; /* input data GPS start time ns */
314LIGOTimeGPS gpsStartTime; /* input data GPS start time */
315INT8 gpsEndTimeNS = 0; /* input data GPS end time ns */
316LIGOTimeGPS gpsEndTime; /* input data GPS end time */
317INT8 inputLengthNS = 0; /* input data length ns */
318INT4 numRespPoints = -1; /* num points for calc response */
319CHAR *fqChanName = NULL; /* name of data channel */
320CHAR *frInCacheName = NULL; /* cache file containing frames */
321CHAR *injCacheName = NULL; /* inj cache file for inj frames*/
322CHAR ifo[3]; /* two character ifo code */
323CHAR outfileName[FILENAME_MAX]; /* output file name */
324
325enum { undefined, real_4, real_8 } calData = undefined; /* cal data type*/
326/* data conditioning parameters */
327INT4 sampleRate = -1; /* sample rate of filter data */
328INT4 frameLength = -1; /* length of output frames */
329INT4 injectSafety = 0; /* safety length in injections */
330UINT4 numFiles = 0; /* number of output files needed*/
331
332CHAR *calCacheName = NULL; /* location of calibration data */
333CHAR *calFileName = NULL; /* location of calibration file */
334CHAR *injectionFile = NULL; /* name of file containing injs */
335CHAR *injChanName = NULL; /* the injection channel name */
336
337REAL4 injFlow = 0; /* injection start frequency */
338int injectOverhead = 0; /* inject h+ into detector */
341
342/* output parameters */
343CHAR *userTag = NULL; /* string the user can tag with */
344int writeRawData = 0; /* write the raw data to frame */
345int writeInjOnly = 0; /* write the inj data to frame */
346int writeRawPlusInj = 0; /* write raw plus inj to frame */
347int writeReal8Frame = 0; /* write frames as real 8 */
349/* other command line args */
350CHAR comment[LIGOMETA_COMMENT_MAX]; /* process param comment */
351
352int main( int argc, char *argv[] )
353{
354 /* lal function variables */
356
357 /* frame input data */
358 LALCache *frInCache = NULL;
359 LALFrStream *frStream = NULL;
360 FrChanIn frChan;
361 FrChanIn injChan;
362
363 /* raw input data storage */
364 REAL4TimeSeries chan;
365 REAL4TimeSeries inj;
366
367 /* structures for preconditioning */
369
370 /* output data */
371 ProcessTable *proctable;
372 ProcessParamsTable *procparams;
374 ProcessParamsTable *this_proc_param;
375 LIGOLwXMLStream *results;
376
377 /* counters and other variables */
378 const LALUnit strainPerCount = {0,{0,0,0,0,0,1,-1},{0,0,0,0,0,0,0}};
379 UINT4 k,n,j;
380 CHAR fname[FILENAME_MAX];
381 UINT4 numPoints = 0;
382 REAL8 tsLength;
383 CHAR tmpChName[LALNameLength];
384
385 /*
386 *
387 * initialization
388 *
389 */
390
391
392 /* set up inital debugging values */
395
396
397 /* create the process and process params tables */
398 proctable = (ProcessTable *) calloc( 1, sizeof(ProcessTable) );
399 XLALGPSTimeNow(&(proctable->start_time));
402 this_proc_param = procparams = (ProcessParamsTable *)
403 calloc( 1, sizeof(ProcessParamsTable) );
404 memset( comment, 0, LIGOMETA_COMMENT_MAX * sizeof(CHAR) );
405
406 /* create the search summary table */
408 calloc( 1, sizeof(SearchSummaryTable) );
409
410 /* zero out the outfileName */
411 memset( outfileName, 0, FILENAME_MAX * sizeof(CHAR) );
412
413 /* call the argument parse and check function */
414 arg_parse_check( argc, argv, procparams );
415
416 /* wind to the end of the process params table */
417 for ( this_proc_param = procparams; this_proc_param->next;
418 this_proc_param = this_proc_param->next );
419
420 /* can use LALMalloc() and LALCalloc() from here onwards */
421
422 /* fill the comment, if a user has specified on, or leave it blank */
423 if ( ! *comment )
424 {
425 snprintf( proctable->comment, LIGOMETA_COMMENT_MAX, " " );
426 snprintf( searchsumm->comment, LIGOMETA_COMMENT_MAX, " " );
427 }
428 else
429 {
430 snprintf( proctable->comment, LIGOMETA_COMMENT_MAX, "%s", comment );
431 snprintf( searchsumm->comment, LIGOMETA_COMMENT_MAX, "%s", comment );
432 }
433
434
435 /* the number of nodes for a standalone job is always 1 */
436 searchsumm->nnodes = 1;
437
438 /* initialize the raw and injection data */
439 memset( &chan, 0, sizeof(REAL4TimeSeries) );
440 memset( &inj, 0, sizeof(REAL4TimeSeries) );
441
442
443 /*
444 *
445 * read in the input data channels
446 *
447 */
448
449
450 if ( frInCacheName )
451 {
452 /* set the params of the input data time series */
453 chan.epoch = gpsStartTime;
454
455 /* open a frame cache */
456 frInCache = XLALCacheImport(frInCacheName);
457 LAL_CALL( LALFrCacheOpen( &status, &frStream, frInCache ), &status );
458
459 /* set the mode of the frame stream to fail on gaps or time errors */
461
462
463 /*
464 *
465 * Read in the raw data
466 *
467 */
468
469 /* seek to required epoch and set chan name */
470 LAL_CALL( LALFrSeek( &status, &(chan.epoch), frStream ), &status );
471 frChan.name = fqChanName;
472
473 /* determine the sample rate of the raw data */
474 LAL_CALL( LALFrGetREAL4TimeSeries( &status, &chan, &frChan, frStream ),
475 &status );
476
477 /* determine the number of points to get and create storage for the data */
478 numPoints = (UINT4) floor( ((REAL8) inputLengthNS) / (chan.deltaT * 1.0e9)
479 + 0.5 );
481 &status );
482
483 if ( vrbflg ) fprintf( stdout, "input channel %s has sample interval "
484 "(deltaT) = %e\nreading %d points from frame stream\n", fqChanName,
485 chan.deltaT, numPoints );
486
487 /* read the data channel time series from frames */
488 LAL_CALL( LALFrGetREAL4TimeSeries( &status, &chan, &frChan, frStream ),
489 &status );
490 memcpy( &(chan.sampleUnits), &lalADCCountUnit, sizeof(LALUnit) );
491
492 /* store the start and end time of the raw channel in the search summary */
493 /* FIXME: loss of precision; consider
494 searchsumm->in_start_time = searchsumm->in_end_time = chan.epoch;
495 XLALGPSAdd(&searchsumm->in_end_time, chan.deltaT * (REAL8) chan.data->length);
496 */
497 searchsumm->in_start_time = chan.epoch;
498 tsLength = XLALGPSGetREAL8( &(chan.epoch) );
499 tsLength += chan.deltaT * (REAL8) chan.data->length;
500 XLALGPSSetREAL8( &(searchsumm->in_end_time), tsLength );
501
502 if ( vrbflg ) fprintf( stdout, "read channel %s from frame stream\n"
503 "got %d points with deltaT %e\nstarting at GPS time %d sec %d ns\n",
504 chan.name, chan.data->length, chan.deltaT,
506
507 /*
508 *
509 * Read in the injection data from frames
510 *
511 */
512
513 if ( injChanName )
514 {
515 /* set the params of the input data time series */
516 inj.epoch = gpsStartTime;
517
518 if ( injCacheName )
519 {
520 /* close current frame cache */
521 LAL_CALL( LALFrClose( &status, &frStream ), &status );
522 if ( frInCacheName ) XLALDestroyCache( frInCache );
523
524 /* open injection frame cache */
525 frInCache = XLALCacheImport(injCacheName);
526 LAL_CALL( LALFrCacheOpen( &status, &frStream, frInCache ), &status );
527 }
528
529 /* seek to required epoch and set inj name */
530 LAL_CALL( LALFrSeek( &status, &(inj.epoch), frStream ), &status );
531 injChan.name = injChanName;
532
533 /* determine the sample rate of the inj data */
534 LAL_CALL( LALFrGetREAL4TimeSeries( &status, &inj, &injChan, frStream ),
535 &status );
536
537 /* determine the number of points to get, create storage for the data */
538 numPoints = (UINT4) floor( ((REAL8) inputLengthNS) /
539 (inj.deltaT * 1.0e9) + 0.5 );
541 &status );
542
543 if ( vrbflg ) fprintf( stdout, "input inj Channel %s has sample interval"
544 " (deltaT) = %e\nreading %d points from frame stream\n", fqChanName,
545 inj.deltaT, numPoints );
546
547 /* read the data inj Channel time series from frames */
548 LAL_CALL( LALFrGetREAL4TimeSeries( &status, &inj, &injChan, frStream ),
549 &status );
550 memcpy( &(inj.sampleUnits), &lalADCCountUnit, sizeof(LALUnit) );
551
552
553 if ( vrbflg ) fprintf( stdout, "read inj Channel %s from frame stream\n"
554 "got %d points with deltaT %e\nstarting at GPS time %d sec %d ns\n",
555 inj.name, inj.data->length, inj.deltaT,
557 }
558
559 /* close the frame file stream and destroy the frame cache */
560 LAL_CALL( LALFrClose( &status, &frStream ), &status );
561 if ( frInCacheName ) XLALDestroyCache( frInCache );
562 }
563
564 /*
565 *
566 * Injections from file
567 *
568 */
569
570 if ( injectionFile )
571 {
572
573 /* Create zeros on top of which to do the injections */
574
575 if ( frInCacheName )
576 {
577 inj.deltaT = chan.deltaT;
578 inj.epoch = chan.epoch;
579 inj.sampleUnits = chan.sampleUnits;
580 strcpy( inj.name, chan.name );
581 }
582 else
583 {
584 inj.deltaT = 1.0/ sampleRate;
585 inj.epoch = gpsStartTime;
587 snprintf( inj.name, LALNameLength, "%s:STRAIN", ifo );
588 searchsumm->in_start_time = gpsStartTime;
589 searchsumm->in_end_time = gpsEndTime;
590 numPoints = (UINT4) floor( ((REAL8) inputLengthNS) / (inj.deltaT * 1.0e9)
591 + 0.5 );
592 }
594 &status );
595 memset( inj.data->data, 0, numPoints * sizeof(REAL4) );
596
597
598 /*
599 *
600 * inject signals into the zero data
601 *
602 */
603
604 /* read in the injection data from XML */
606
607 if ( !injections )
608 {
609 fprintf( stderr, "error: cannot read injection file" );
610 exit( 1 );
611 }
612 else
613 {
614 /* set the injection start frequency */
615 if ( injFlow )
616 {
618 {
620 }
621 }
622
623 /* create the response function */
624 memset( &injResp, 0, sizeof(COMPLEX8FrequencySeries) );
625 LAL_CALL( LALCCreateVector( &status, &(injResp.data),
626 numRespPoints / 2 + 1 ), &status );
627 injResp.epoch = inj.epoch ;
628 injResp.deltaF = 1.0 / ( numRespPoints * inj.deltaT );
629 strcpy( injResp.name, inj.name );
630
631 if ( calFileName )
632 {
633 XLAL_ERROR(XLAL_EERR, "Calibration frames no longer supported");
634 }
635 else if ( calCacheName )
636 {
637 XLAL_ERROR(XLAL_EERR, "Calibration cache no longer supported");
638 }
639 else
640 {
641 /* generate a unity response function for h(t) */
642 if ( vrbflg ) fprintf( stdout, "setting response to unity... " );
643 injResp.sampleUnits = strainPerCount;
644 for ( k = 0; k < injResp.data->length; ++k )
645 {
646 injResp.data->data[k] = 1.0;
647 }
648 if ( vrbflg ) fprintf( stdout, "done.\n" );
649
650 }
651
652
653 /* inject the signals, preserving the channel name (Tev mangles it) */
654 snprintf( tmpChName, LALNameLength, "%s", inj.name );
655
656 /* if injectOverhead option, then set inj.name to "ZENITH".
657 * This causes no detector site to be found in the injection code so
658 * that the injection is done directly overhead (i.e. with a response
659 * function of F+ = 1; Fx = 0) */
660 if ( injectOverhead )
661 {
662 snprintf( inj.name, LALNameLength, "ZENITH" );
663 }
664
666 &injResp ), &status );
667 snprintf( inj.name, LALNameLength, "%s", tmpChName );
668
669 if ( vrbflg ) fprintf( stdout, "injected signals from %s into %s\n",
670 injectionFile, inj.name );
671
672 LAL_CALL( LALCDestroyVector( &status, &(injResp.data) ), &status );
673 }
674 }
675
676 /*
677 *
678 * Create data segments of the desired length and save them as frames
679 *
680 */
681
683 {
684 /* frame output data */
685 struct FrFile *frOutFile = NULL;
686 struct FrameH *outFrame = NULL;
688 REAL8TimeSeries real8Output;
689 UINT4 length;
690
691 memset( &output, 0, sizeof(REAL4TimeSeries) );
692 output.deltaT = inj.deltaT;
693 output.sampleUnits = inj.sampleUnits;
694 output.data = (REAL4Vector *) LALCalloc( 1, sizeof(REAL4Vector) );
695 length = numPoints / numFiles;
696 output.data->length = length;
697
698 memset( &real8Output, 0, sizeof(REAL8TimeSeries) );
699 real8Output.deltaT = output.deltaT;
700 real8Output.sampleUnits = output.sampleUnits;
701 LAL_CALL( LALDCreateVector( &status, &(real8Output.data),
702 output.data->length ), &status );
703 real8Output.data->length = output.data->length;
704
705 for ( n = 0; n < numFiles; ++n )
706 {
707 outFrame = NULL;
708 output.epoch.gpsSeconds = gpsStartTime.gpsSeconds + n * frameLength;
709 real8Output.epoch = output.epoch;
710
711 /* write the injection channel to frame */
712 if ( writeInjOnly )
713 {
714 strcpy( output.name, inj.name );
715 output.data->data = inj.data->data + n * length;
716 if ( injectionFile )
717 {
718 /* write out injection channel to INSP_INJ_ONLY */
719 outFrame = fr_add_proc_REAL4TimeSeries( outFrame, &output, "ct",
720 "INSP_INJ_ONLY" );
721 }
722 else if ( injChanName )
723 {
724 /* write out injections, preserving input frame name */
725 outFrame = fr_add_proc_REAL4TimeSeries( outFrame, &output, "ct",
726 NULL );
727 }
728 }
729
730 /* write the raw/raw plus inj data to frame */
732 {
733
734 strcpy( output.name, chan.name );
735 output.data->data = chan.data->data + n * length;
736
737 if ( !writeReal8Frame )
738 {
739 if ( writeRawData )
740 {
741 outFrame = fr_add_proc_REAL4TimeSeries( outFrame, &output, "ct",
742 NULL );
743 }
744 /* add injections into this file's data */
746
747 if ( writeRawPlusInj )
748 {
749 strcpy( output.name, chan.name );
750 outFrame = fr_add_proc_REAL4TimeSeries( outFrame, &output, "ct",
751 "PLUS_INSP_INJ" );
752 }
753 }
754 else
755 {
756 strcpy( real8Output.name, output.name );
757
758 if ( vrbflg ) fprintf( stdout,
759 "Casting data to real 8 before writing frame\n" );
760
761 for ( j = 0 ; j < output.data->length ; ++j )
762 {
763 real8Output.data->data[j] = (REAL8) ( output.data->data[j] );
764 }
765
766 if ( writeRawData )
767 {
768 outFrame = fr_add_proc_REAL8TimeSeries( outFrame, &real8Output,
769 "ct", NULL );
770 }
771
772 for ( j = 0 ; j < output.data->length ; ++j )
773 {
774 real8Output.data->data[j] += (REAL8)
775 ( inj.data->data[j + n * length] );
776 }
777
778 if ( writeRawPlusInj )
779 {
780 outFrame = fr_add_proc_REAL8TimeSeries( outFrame, &real8Output,
781 "ct", "PLUS_INSP_INJ" );
782 }
783
784 }
785
786 }
787
788 /* set the output file name */
789 if( !outfileName[0] )
790 {
791 /* output name not specified, set to IFO-INSPFRINJ-EPOCH-LENGTH.gwf */
792 snprintf( outfileName, FILENAME_MAX, "%s-INSPFRINJ", ifo );
793 }
794
795 if( userTag )
796 {
797 if(snprintf( fname, FILENAME_MAX, "%s_%s-%d-%d.gwf", outfileName,
798 userTag, output.epoch.gpsSeconds, frameLength ) >= FILENAME_MAX)
799 abort();
800 }
801 else
802 {
803 if(snprintf( fname, FILENAME_MAX, "%s-%d-%d.gwf", outfileName,
804 output.epoch.gpsSeconds, frameLength ) >= FILENAME_MAX)
805 abort();
806 }
807
808 if ( vrbflg ) fprintf( stdout, "writing frame data to %s... ", fname );
809 frOutFile = FrFileONew( fname, 3 );
810 FrameWrite( outFrame, frOutFile );
811 FrFileOEnd( frOutFile );
812 if ( vrbflg ) fprintf( stdout, "done\n" );
813 }
814
815 LALFree ( output.data );
816
817 if( real8Output.data )
818 {
819 LAL_CALL( LALDDestroyVector( &status, &(real8Output.data) ), &status );
820 }
821 }
822
823 /* free the data storage */
824 if ( vrbflg ) fprintf( stdout, "freeing memory\n" );
825 if ( chan.data )
826 {
827 LAL_CALL( LALSDestroyVector( &status, &(chan.data) ), &status );
828 }
829 if ( inj.data )
830 {
832 }
833
834
835 /* open the output xml file */
836 if( userTag && outCompress )
837 {
838 if(snprintf( fname, FILENAME_MAX, "%s_%s-%d-%d.xml.gz", outfileName,
840 gpsEndTime.gpsSeconds - gpsStartTime.gpsSeconds ) >= FILENAME_MAX)
841 abort();
842 }
843 else if( userTag && !outCompress )
844 {
845 if(snprintf( fname, FILENAME_MAX, "%s_%s-%d-%d.xml", outfileName,
847 gpsEndTime.gpsSeconds - gpsStartTime.gpsSeconds ) >= FILENAME_MAX)
848 abort();
849 }
850 else if( !userTag && outCompress )
851 {
852 if(snprintf( fname, FILENAME_MAX, "%s-%d-%d.xml.gz", outfileName,
854 gpsEndTime.gpsSeconds - gpsStartTime.gpsSeconds ) >= FILENAME_MAX)
855 abort();
856 }
857 else
858 {
859 if(snprintf( fname, FILENAME_MAX, "%s-%d-%d.xml", outfileName,
861 gpsEndTime.gpsSeconds - gpsStartTime.gpsSeconds ) >= FILENAME_MAX)
862 abort();
863 }
864
865 if ( vrbflg ) fprintf( stdout, "writing XML data to %s...\n", fname );
866 results = XLALOpenLIGOLwXMLFile( fname );
867
868 /* write the process table */
869 if ( vrbflg ) fprintf( stdout, " process table...\n" );
870 snprintf( proctable->ifos, LIGOMETA_IFOS_MAX, "%s", ifo );
871 XLALGPSTimeNow(&(proctable->end_time));
872 XLALWriteLIGOLwXMLProcessTable( results, proctable );
873 free( proctable );
874
875 /* write the process params table */
876 if ( vrbflg ) fprintf( stdout, " process_params table...\n" );
877 XLALWriteLIGOLwXMLProcessParamsTable( results, procparams );
878 XLALDestroyProcessParamsTable( procparams );
879
880 /* write the search summary table */
881 if ( vrbflg ) fprintf( stdout, " search_summary table...\n" );
883
884 /* free the search summary table */
885 free( searchsumm );
886
887 /* write the sim_inspiral table */
888 if ( injections )
889 {
890 if ( vrbflg ) fprintf( stdout, "sim_inspiral... " );
892 /* free the temporary memory containing the events */
894 }
895
896 /* close the output xml file */
897 XLALCloseLIGOLwXMLFile( results );
898 if ( vrbflg ) fprintf( stdout, "done. XML file closed\n" );
899
900 /* free the rest of the memory, check for memory leaks and exit */
901 if ( injectionFile ) free ( injectionFile );
902 if ( calCacheName ) free( calCacheName );
903 if ( calFileName ) free( calFileName );
904 if ( frInCacheName ) free( frInCacheName );
905 if ( fqChanName ) free( fqChanName );
906
907 if ( vrbflg ) fprintf( stdout, "checking memory leaks and exiting\n" );
909 exit( 0 );
910}
911
912/* ------------------------------------------------------------------------- */
913
914#define ADD_PROCESS_PARAM( pptype, format, ppvalue ) \
915 this_proc_param = this_proc_param->next = (ProcessParamsTable *) \
916calloc( 1, sizeof(ProcessParamsTable) ); \
917snprintf( this_proc_param->program, LIGOMETA_PROGRAM_MAX, "%s", \
918 PROGRAM_NAME ); \
919snprintf( this_proc_param->param, LIGOMETA_PARAM_MAX, "--%s", \
920 long_options[option_index].name ); \
921snprintf( this_proc_param->type, LIGOMETA_TYPE_MAX, "%s", pptype ); \
922snprintf( this_proc_param->value, LIGOMETA_VALUE_MAX, format, ppvalue );
923
924/*
925 *
926 * USAGE
927 *
928 */
929static void print_usage(char *program)
930{
931 fprintf(stderr,
932 "Usage: %s [options] [LIGOLW XML input files]\n" \
933 "The following options are recognized. Options not surrounded in [] are\n" \
934 "required.\n" \
935 " [--help] display this message\n"\
936 " [--verbose] print progress information\n"\
937 " [--version] print version information and exit\n"\
938 " [--user-tag] usertag set the process_params usertag to usertag\n"\
939 " [--comment] string set the process table comment to string\n"\
940 "\n"\
941 " --gps-start-time start_time GPS second of data start time\n"\
942 " [--gps-start-time-ns] start_ns GPS nanosecond of data start time\n"\
943 " --gps-end-time end_time GPS second of data end time\n"\
944 " [--gps-end-time-ns] end_ns GPS nanosecond of data end time\n"\
945 "\n"\
946 " [--frame-cache] cache frame cache with locations of data\n"\
947 " [--calibration-file] cal_file frame file containing calibration data\n"\
948 " [--calibration-cache] cal_cache file with location of calibration data\n"\
949 " [--calibrated-data] type calibrated data of type (real_4 | real_8)\n"\
950 " [--num-resp-points] N num points to determine response function (4194304)\n"\
951 " [--channel-name] chan channel from which to read data\n"\
952 "\n"\
953 " [--injection-channel] inj_chan channel from which to read inj data\n"\
954 " [--injection-cache] inj_cache cache with location of injection data\n"\
955 " [--injection-file] inj_file xml file with injection details\n"\
956 " [--inject-overhead] inject signals from overhead detector\n"\
957 " [--inject-safety] safety inject signals ending up to safety\n"
958 " seconds after end_time\n"\
959 " [--injection-start-freq] flow inject signals starting at flow (40Hz)\n"\
960 "\n"\
961 " [--write-raw-data] write out raw-data channel\n"\
962 " [--write-inj-only] write out inj-only channel\n"\
963 " [--write-raw-plus-inj] write out raw plus inj channel\n"\
964 " [--write-real8-frame] write out real 8 frames\n"\
965 "\n"\
966 " [--output-frame-length] len length of output frames\n"\
967 " [--output-file-name] out set file names to out-gpstime-length.gwf\n"\
968 " if not set, default to ifo-inspfrinj-gpstime-length.gwf\n"\
969 " [--write-compress] write compressed xml files\n"\
970 "\n"\
971 " [--ifo] ifo specify the ifo (if not reading frames)\n"\
972 " [--sample-rate] rate data sample rate (if not reading frames)\n"\
973 "\n", program );
974}
975
976int arg_parse_check( int argc, char *argv[], ProcessParamsTable *procparams )
977{
978 /* LALgetopt arguments */
979 struct LALoption long_options[] =
980 {
981 /* these options set a flag */
982 {"verbose", no_argument, &vrbflg, 1 },
983 {"write-compress", no_argument, &outCompress, 1 },
984 {"write-raw-data", no_argument, &writeRawData, 1 },
985 {"write-inj-only", no_argument, &writeInjOnly, 1 },
986 {"write-raw-plus-inj", no_argument, &writeRawPlusInj, 1 },
987 {"inject-overhead", no_argument, &injectOverhead, 1 },
988 {"write-real8-frame", no_argument, &writeReal8Frame, 1 },
989 /* these options don't set a flag */
990 {"gps-start-time", required_argument, 0, 'a'},
991 {"gps-start-time-ns", required_argument, 0, 'A'},
992 {"gps-end-time", required_argument, 0, 'b'},
993 {"gps-end-time-ns", required_argument, 0, 'B'},
994 {"channel-name", required_argument, 0, 'c'},
995 {"output-frame-length", required_argument, 0, 'd'},
996 {"output-file-name", required_argument, 0, 'f'},
997 {"help", no_argument, 0, 'h'},
998 {"dynamic-range-exponent", required_argument, 0, 'l'},
999 {"calibrated-data", required_argument, 0, 'y'},
1000 {"calibration-cache", required_argument, 0, 'p'},
1001 {"calibration-file", required_argument, 0, 'q'},
1002 {"num-resp-points", required_argument, 0, 'N'},
1003 {"sample-rate", required_argument, 0, 'r'},
1004 {"ifo", required_argument, 0, 'i'},
1005 {"comment", required_argument, 0, 's'},
1006 {"frame-cache", required_argument, 0, 'u'},
1007 {"injection-cache", required_argument, 0, 'C'},
1008 {"injection-file", required_argument, 0, 'w'},
1009 {"inject-safety", required_argument, 0, 'S'},
1010 {"injection-channel", required_argument, 0, 'I'},
1011 {"injection-start-freq", required_argument, 0, 'L'},
1012 {"user-tag", required_argument, 0, 'Z'},
1013 {"userTag", required_argument, 0, 'Z'},
1014 {"version", no_argument, 0, 'V'},
1015 {0, 0, 0, 0}
1016 };
1017 int c;
1018 ProcessParamsTable *this_proc_param = procparams;
1019
1020
1021 /*
1022 *
1023 * parse command line arguments
1024 *
1025 */
1026
1027
1028 while ( 1 )
1029 {
1030 /* LALgetopt_long stores long option here */
1031 int option_index = 0;
1032 size_t LALoptarg_len;
1033
1034 c = LALgetopt_long_only( argc, argv,
1035 "A:B:C:I:L:N:S:V:Z:"
1036 "a:b:c:d:f:hi:l:p:q:r:s:u:w:y:",
1037 long_options, &option_index );
1038
1039 /* detect the end of the options */
1040 if ( c == - 1 )
1041 {
1042 break;
1043 }
1044
1045 switch ( c )
1046 {
1047 case 0:
1048 /* if this option set a flag, do nothing else now */
1049 if ( long_options[option_index].flag != 0 )
1050 {
1051 break;
1052 }
1053 else
1054 {
1055 fprintf( stderr, "error parsing option %s with argument %s\n",
1056 long_options[option_index].name, LALoptarg );
1057 exit( 1 );
1058 }
1059 break;
1060
1061 case 'a':
1062 /* set gps start seconds */
1063 {
1064 long int gstartt = atol( LALoptarg );
1065 if ( gstartt < 441417609 )
1066 {
1067 fprintf( stderr, "invalid argument to --%s:\n"
1068 "GPS start time is prior to "
1069 "Jan 01, 1994 00:00:00 UTC:\n"
1070 "(%ld specified)\n",
1071 long_options[option_index].name, gstartt );
1072 exit( 1 );
1073 }
1074 gpsStartTimeNS += (INT8) gstartt * 1000000000LL;
1075 ADD_PROCESS_PARAM( "int", "%ld", gstartt );
1076 }
1077 break;
1078
1079 case 'A':
1080 /* set gps start nanoseconds */
1081 {
1082 long int gstarttns = atol( LALoptarg );
1083 if ( gstarttns < 0 )
1084 {
1085 fprintf( stderr, "invalid argument to --%s:\n"
1086 "GPS start time nanoseconds is negative\n",
1087 long_options[option_index].name );
1088 exit( 1 );
1089 }
1090 if ( gstarttns > 999999999 )
1091 {
1092 fprintf( stderr, "invalid argument to --%s:\n"
1093 "GPS start time nanoseconds is greater than unity:\n"
1094 "Must be <= 999999999 (%ld specified)\n",
1095 long_options[option_index].name, gstarttns );
1096 exit( 1 );
1097 }
1098 gpsStartTimeNS += (INT8) gstarttns;
1099 ADD_PROCESS_PARAM( "int", "%ld", gstarttns );
1100 }
1101 break;
1102
1103 case 'b':
1104 /* set gps end seconds */
1105 {
1106 long int gendt = atol( LALoptarg );
1107 if ( gendt < 441417609 )
1108 {
1109 fprintf( stderr, "invalid argument to --%s:\n"
1110 "GPS end time is prior to "
1111 "Jan 01, 1994 00:00:00 UTC:\n"
1112 "(%ld specified)\n",
1113 long_options[option_index].name, gendt );
1114 exit( 1 );
1115 }
1116 gpsEndTimeNS += (INT8) gendt * 1000000000LL;
1117 ADD_PROCESS_PARAM( "int", "%ld", gendt );
1118 }
1119 break;
1120
1121 case 'B':
1122 /* set gps end nanoseconds */
1123 {
1124 long int gendtns = atol( LALoptarg );
1125 if ( gendtns < 0 )
1126 {
1127 fprintf( stderr, "invalid argument to --%s:\n"
1128 "GPS end time nanoseconds is negative\n",
1129 long_options[option_index].name );
1130 exit( 1 );
1131 }
1132 else if ( gendtns > 999999999 )
1133 {
1134 fprintf( stderr, "invalid argument to --%s:\n"
1135 "GPS end time nanoseconds is greater than unity:\n"
1136 "Must be <= 999999999:\n"
1137 "(%ld specified)\n",
1138 long_options[option_index].name, gendtns );
1139 exit( 1 );
1140 }
1141 gpsEndTimeNS += (INT8) gendtns;
1142 ADD_PROCESS_PARAM( "int", "%ld", gendtns );
1143 }
1144 break;
1145
1146 case 'c':
1147 {
1148 /* create storage for the channel name and copy it */
1149 char *channamptr = NULL;
1150 LALoptarg_len = strlen( LALoptarg ) + 1;
1151 fqChanName = (CHAR *) calloc( LALoptarg_len, sizeof(CHAR) );
1152 memcpy( fqChanName, LALoptarg, LALoptarg_len );
1153 ADD_PROCESS_PARAM( "string", "%s", LALoptarg );
1154
1155 /* check that we have a proper channel name */
1156 if ( ! (channamptr = strstr( fqChanName, ":" ) ) )
1157 {
1158 fprintf( stderr, "invalid argument to --%s:\n"
1159 "channel name must be a full LIGO channel name "
1160 "e.g. L1:LSC-AS_Q\n(%s specified)\n",
1161 long_options[option_index].name, LALoptarg );
1162 exit( 1 );
1163 }
1164
1165 /* copy the first two characters to the ifo name */
1166 memset( ifo, 0, sizeof(ifo) );
1167 memcpy( ifo, LALoptarg, sizeof(ifo) - 1 );
1168 }
1169 break;
1170
1171 case 'd':
1172 /* set length of output frames */
1173 frameLength = (INT4) atoi( LALoptarg );
1174 if ( frameLength < 1 )
1175 {
1176 fprintf( stderr, "invalid argument to --%s:\n"
1177 "length of frame must be a positive integer: "
1178 "(%d specified) \n",
1179 long_options[option_index].name, frameLength );
1180 exit( 1 );
1181 }
1182 ADD_PROCESS_PARAM( "int", "%d", frameLength );
1183 break;
1184
1185 case 'f':
1186 /* set output file name */
1187 if ( snprintf( outfileName, FILENAME_MAX, "%s", LALoptarg ) < 0 )
1188 {
1189 fprintf( stderr, "invalid argument to --%s\n"
1190 "outfile name %s too long: string truncated\n",
1191 long_options[option_index].name, LALoptarg );
1192 exit( 1 );
1193 }
1194 ADD_PROCESS_PARAM( "string", "%s", LALoptarg );
1195 break;
1196
1197 case 'h':
1198 /* help message */
1199 print_usage(argv[0]);
1200 exit( 0 );
1201 break;
1202
1203 case 'p':
1204 /* create storage for the calibration frame cache name */
1205 LALoptarg_len = strlen( LALoptarg ) + 1;
1206 calCacheName = (CHAR *) calloc( LALoptarg_len, sizeof(CHAR));
1207 memcpy( calCacheName, LALoptarg, LALoptarg_len );
1208 ADD_PROCESS_PARAM( "string", "%s", LALoptarg );
1209 break;
1210
1211 case 'q':
1212 /* create storage for the calibration frame file name */
1213 LALoptarg_len = strlen( LALoptarg ) + 1;
1214 calFileName = (CHAR *) calloc( LALoptarg_len, sizeof(CHAR));
1215 memcpy( calFileName, LALoptarg, LALoptarg_len );
1216 ADD_PROCESS_PARAM( "string", "%s", LALoptarg );
1217 break;
1218
1219
1220 case 'N':
1221 /* store the number of points used in computing the response */
1222 numRespPoints = (INT4) atoi( LALoptarg );
1223 if ( numRespPoints < 2 || numRespPoints % 2 )
1224 {
1225 fprintf( stderr, "invalid argument to --%s:\n"
1226 "number of points must be an even positive integer,\n"
1227 "(%d specified) \n",
1228 long_options[option_index].name, numRespPoints );
1229 exit( 1 );
1230 }
1231 ADD_PROCESS_PARAM( "int", "%d", numRespPoints );
1232 break;
1233
1234 case 'y':
1235 /* specify which type of calibrated data */
1236 {
1237 if ( ! strcmp( "real_4", LALoptarg ) )
1238 {
1239 calData = real_4;
1240 }
1241 else if ( ! strcmp( "real_8", LALoptarg ) )
1242 {
1243 calData = real_8;
1244 fprintf( stderr, "Sorry, code not currently set up to\n"
1245 "run on real_8 data\n" );
1246 exit( 1 );
1247 }
1248 else
1249 {
1250 fprintf( stderr, "invalid argument to --%s:\n"
1251 "unknown data type specified;\n"
1252 "%s (must be one of: real_4, real_8)\n",
1253 long_options[option_index].name, LALoptarg);
1254 exit( 1 );
1255 }
1256 ADD_PROCESS_PARAM( "string", "%s", LALoptarg );
1257 }
1258 break;
1259
1260 case 'r':
1261 /* set the sample rate */
1262 sampleRate = (INT4) atoi( LALoptarg );
1263 if ( sampleRate < 1 )
1264 {
1265 fprintf( stderr, "invalid argument to --%s:\n"
1266 "sample rate must be a positive integer: "
1267 "(%d specified) \n",
1268 long_options[option_index].name, sampleRate );
1269 exit( 1 );
1270 }
1271 ADD_PROCESS_PARAM( "int", "%d", sampleRate );
1272 break;
1273
1274 case 'L':
1275 /* set the injection start frequency */
1276 injFlow = (REAL4) atof ( LALoptarg );
1277 if ( injFlow <= 0 )
1278 {
1279 fprintf( stderr, "invalide argument to --%s:\n"
1280 "injections must start at a positive frequency."
1281 "(%f specified) \n",
1282 long_options[option_index].name, injFlow );
1283 exit( 1 );
1284 }
1285 ADD_PROCESS_PARAM( "float", "%f", injFlow );
1286 break;
1287
1288 case 'i':
1289 {
1290 /* create storage for the ifo name and copy it */
1291 memset( ifo, 0, sizeof(ifo) );
1292 memcpy( ifo, LALoptarg, sizeof(ifo) - 1 );
1293 ADD_PROCESS_PARAM( "string", "%s", LALoptarg );
1294 }
1295 break;
1296
1297
1298 case 's':
1299 if ( strlen( LALoptarg ) > LIGOMETA_COMMENT_MAX - 1 )
1300 {
1301 fprintf( stderr, "invalid argument to --%s:\n"
1302 "comment must be less than %d characters\n",
1303 long_options[option_index].name, LIGOMETA_COMMENT_MAX );
1304 exit( 1 );
1305 }
1306 else
1307 {
1308 snprintf( comment, LIGOMETA_COMMENT_MAX, "%s", LALoptarg);
1309 }
1310 break;
1311
1312 case 'S':
1313 injectSafety = (INT4) atoi( LALoptarg );
1314 if ( injectSafety < 1 )
1315 {
1316 fprintf( stderr, "invalid argument to --%s:\n"
1317 "injection safety must be a positive integer: "
1318 "(%d specified) \n",
1319 long_options[option_index].name, frameLength );
1320 exit( 1 );
1321 }
1322 ADD_PROCESS_PARAM( "int", "%d", injectSafety );
1323 break;
1324
1325 case 'I':
1326 {
1327 /* create storage for the injection channel name and copy it */
1328 LALoptarg_len = strlen( LALoptarg ) + 1;
1329 injChanName = (CHAR *) calloc( LALoptarg_len, sizeof(CHAR) );
1330 memcpy( injChanName, LALoptarg, LALoptarg_len );
1331 ADD_PROCESS_PARAM( "string", "%s", LALoptarg );
1332 }
1333 break;
1334
1335 case 'u':
1336 /* create storage for the input frame cache name */
1337 LALoptarg_len = strlen( LALoptarg ) + 1;
1338 frInCacheName = (CHAR *) calloc( LALoptarg_len, sizeof(CHAR) );
1339 memcpy( frInCacheName, LALoptarg, LALoptarg_len );
1340 ADD_PROCESS_PARAM( "string", "%s", LALoptarg );
1341 break;
1342
1343 case 'C':
1344 /* create storage for the input frame cache name */
1345 LALoptarg_len = strlen( LALoptarg ) + 1;
1346 injCacheName = (CHAR *) calloc( LALoptarg_len, sizeof(CHAR) );
1347 memcpy( injCacheName, LALoptarg, LALoptarg_len );
1348 ADD_PROCESS_PARAM( "string", "%s", LALoptarg );
1349 break;
1350
1351 case 'w':
1352 /* create storage for the injection file name */
1353 LALoptarg_len = strlen( LALoptarg ) + 1;
1354 injectionFile = (CHAR *) calloc( LALoptarg_len, sizeof(CHAR));
1355 memcpy( injectionFile, LALoptarg, LALoptarg_len );
1356 ADD_PROCESS_PARAM( "string", "%s", LALoptarg );
1357 break;
1358
1359 case 'Z':
1360 /* create storage for the usertag */
1361 LALoptarg_len = strlen( LALoptarg ) + 1;
1362 userTag = (CHAR *) calloc( LALoptarg_len, sizeof(CHAR) );
1363 memcpy( userTag, LALoptarg, LALoptarg_len );
1364
1365 this_proc_param = this_proc_param->next = (ProcessParamsTable *)
1366 calloc( 1, sizeof(ProcessParamsTable) );
1367 snprintf( this_proc_param->program, LIGOMETA_PROGRAM_MAX, "%s",
1368 PROGRAM_NAME );
1369 snprintf( this_proc_param->param, LIGOMETA_PARAM_MAX, "-userTag" );
1370 snprintf( this_proc_param->type, LIGOMETA_TYPE_MAX, "string" );
1371 snprintf( this_proc_param->value, LIGOMETA_VALUE_MAX, "%s",
1372 LALoptarg );
1373 break;
1374
1375 case 'V':
1376 /* print version information and exit */
1377 fprintf( stdout, "LIGO/LSC Inspiral Injection Program\n"
1378 "Steve Fairhurst <sfairhur@gravity.phys.uwm.edu>\n");
1379 XLALOutputVCSInfo(stderr, lalAppsVCSInfoList, 0, "%% ");
1380 exit( 0 );
1381 break;
1382
1383 case '?':
1384 print_usage(argv[0]);
1385 exit( 1 );
1386 break;
1387
1388 default:
1389 fprintf( stderr, "unknown error while parsing options\n" );
1390 print_usage(argv[0]);
1391 exit( 1 );
1392 }
1393 }
1394
1395 if ( LALoptind < argc )
1396 {
1397 fprintf( stderr, "extraneous command line arguments:\n" );
1398 while ( LALoptind < argc )
1399 {
1400 fprintf ( stderr, "%s\n", argv[LALoptind++] );
1401 }
1402 exit( 1 );
1403 }
1404
1405 /* check flags and store in process_params */
1406
1407 if ( writeRawData )
1408 {
1409 this_proc_param = this_proc_param->next = (ProcessParamsTable *)
1410 calloc( 1, sizeof(ProcessParamsTable) );
1411 snprintf( this_proc_param->program, LIGOMETA_PROGRAM_MAX,
1412 "%s", PROGRAM_NAME );
1413 snprintf( this_proc_param->param, LIGOMETA_PARAM_MAX,
1414 "--write-raw-data" );
1415 snprintf( this_proc_param->type, LIGOMETA_TYPE_MAX, "string" );
1416 snprintf( this_proc_param->value, LIGOMETA_TYPE_MAX, " " );
1417 }
1418
1419 if ( writeInjOnly )
1420 {
1421 this_proc_param = this_proc_param->next = (ProcessParamsTable *)
1422 calloc( 1, sizeof(ProcessParamsTable) );
1423 snprintf( this_proc_param->program, LIGOMETA_PROGRAM_MAX,
1424 "%s", PROGRAM_NAME );
1425 snprintf( this_proc_param->param, LIGOMETA_PARAM_MAX,
1426 "--write-inj-only" );
1427 snprintf( this_proc_param->type, LIGOMETA_TYPE_MAX, "string" );
1428 snprintf( this_proc_param->value, LIGOMETA_TYPE_MAX, " " );
1429 }
1430 if ( writeRawPlusInj )
1431 {
1432 this_proc_param = this_proc_param->next = (ProcessParamsTable *)
1433 calloc( 1, sizeof(ProcessParamsTable) );
1434 snprintf( this_proc_param->program, LIGOMETA_PROGRAM_MAX,
1435 "%s", PROGRAM_NAME );
1436 snprintf( this_proc_param->param, LIGOMETA_PARAM_MAX,
1437 "--write-raw-plus-inj" );
1438 snprintf( this_proc_param->type, LIGOMETA_TYPE_MAX, "string" );
1439 snprintf( this_proc_param->value, LIGOMETA_TYPE_MAX, " " );
1440 }
1441
1442 if ( writeReal8Frame )
1443 {
1444 this_proc_param = this_proc_param->next = (ProcessParamsTable *)
1445 calloc( 1, sizeof(ProcessParamsTable) );
1446 snprintf( this_proc_param->program, LIGOMETA_PROGRAM_MAX,
1447 "%s", PROGRAM_NAME );
1448 snprintf( this_proc_param->param, LIGOMETA_PARAM_MAX,
1449 "--write-real8-frame" );
1450 snprintf( this_proc_param->type, LIGOMETA_TYPE_MAX, "string" );
1451 snprintf( this_proc_param->value, LIGOMETA_TYPE_MAX, " " );
1452 }
1453
1454 /* check inject-overhead option */
1455 if ( injectOverhead )
1456 {
1457 this_proc_param = this_proc_param->next = (ProcessParamsTable *)
1458 calloc( 1, sizeof(ProcessParamsTable) );
1459 snprintf( this_proc_param->program, LIGOMETA_PROGRAM_MAX,
1460 "%s", PROGRAM_NAME );
1461 snprintf( this_proc_param->param, LIGOMETA_PARAM_MAX,
1462 "--inject-overhead" );
1463 snprintf( this_proc_param->type, LIGOMETA_TYPE_MAX, "string" );
1464 snprintf( this_proc_param->value, LIGOMETA_TYPE_MAX, " " );
1465 }
1466
1467 /*
1468 *
1469 * check validity of arguments
1470 *
1471 */
1472
1473
1474 /* check validity of input data time */
1475
1476 /* start time specified */
1477 if ( ! gpsStartTimeNS )
1478 {
1479 fprintf( stderr, "--gps-start-time must be specified\n" );
1480 exit( 1 );
1481 }
1483
1484 /* end time specified */
1485 if ( ! gpsEndTimeNS )
1486 {
1487 fprintf( stderr, "--gps-end-time must be specified\n" );
1488 exit( 1 );
1489 }
1491
1492 /* end after start */
1494 {
1495 fprintf( stderr, "invalid gps time range: "
1496 "start time: %d, end time %d\n",
1498 exit( 1 );
1499 }
1500
1501 /* check that we have injections, either in xml or in the frames already */
1502 if ( !injectionFile && !injChanName )
1503 {
1504 fprintf( stderr,
1505 "either --injection-file or --injection-channel must be specified\n");
1506 exit( 1 );
1507 }
1508 if ( injectionFile && injChanName )
1509 {
1510 fprintf( stderr,
1511 "Only one of --injection-file and --injection-channel may be given\n");
1512 exit( 1 );
1513 }
1514
1515 /* if an injection channel has been specified, need a frame cache */
1516 if ( injChanName && !frInCacheName )
1517 {
1518 fprintf( stderr,
1519 "If --injection-channel specified, also require --frame-cache\n");
1520 exit( 1 );
1521 }
1522
1523 /* calculate the length of the data in NS */
1525
1526 /* check that the output frame length has been specified */
1527 if ( frameLength == -1 )
1528 {
1529 fprintf( stderr, "--output-frame-length must be specified\n" );
1530 exit( 1 );
1531 }
1532 /* and it divides the total time exactly */
1533 if ( inputLengthNS % ( (INT8) frameLength * 1000000000LL ) )
1534 {
1535 fprintf(stderr, "data length %d must be a multiple of frame length %d",
1536 (INT4) (inputLengthNS / 1000000000LL), frameLength);
1537 exit( 1 );
1538 }
1539 else
1540 {
1541 numFiles = (INT4) (inputLengthNS / 1000000000LL) / frameLength;
1542 }
1543
1544 /* if a frame cache has been specified, check we have everything else
1545 which is necessary */
1546 if ( frInCacheName )
1547 {
1548 /* check that a channel has been requested */
1549 if (! fqChanName )
1550 {
1551 fprintf( stderr, "--channel-name must be specified\n" );
1552 exit( 1 );
1553 }
1554 }
1555 else
1556 {
1557 /* check sample rate has been given */
1558 if ( sampleRate < 0 )
1559 {
1560 fprintf( stderr, "If --frame-cache not specified,\n"
1561 "--sample-rate must be specified\n" );
1562 exit( 1 );
1563 }
1564 /* check that neither write-raw-data or write-raw-plus-inj given */
1566 {
1567 fprintf( stderr, "Neither --write-raw-data nor --write-raw-plus-inj\n"
1568 "can be specified when --frame-cache not given\n");
1569 }
1570 }
1571
1572 /* check that have one of: calibrated-data or a calibration-cache
1573 * or a calibration frame file */
1574 if ( ! (calCacheName || calFileName) && ! calData )
1575 {
1576 fprintf( stderr, "Either --calibration-cache must be specified,\n"
1577 "or must run on --calibrated-data.\n");
1578 exit( 1 );
1579 }
1580 else if ( (calCacheName && calData) || (calFileName && calData) || (calCacheName && calFileName) )
1581 {
1582 fprintf( stderr,
1583 "Only one of --calibration-cache and --calibration and --calibrated-data\n"
1584 "should be specified\n.");
1585 exit( 1 );
1586 }
1587
1588 /* if a calibration frame file, need to know which readout point is to
1589 * be used (e.g., DARM_ERR or AS_Q) -- this is taken from a channel name */
1590 if ( calFileName && ! fqChanName )
1591 {
1592 fprintf( stderr, "--channel-name must be specified\n" );
1593 exit( 1 );
1594 }
1595
1596 /* check that we have then number of points to determine response fn */
1597 if ( numRespPoints < 0 )
1598 {
1599 if ( vrbflg ) fprintf( stdout, "--num-resp-points not specified\n"
1600 "This gives the number of points used to obtain response,\n"
1601 "Response has numRespPoints/2 + 1 points,\n"
1602 "Frequency resolution of 1/(numRespPoints * delta T).\n"
1603 "Setting it to a default value of 256 * 16384 = 4194304\n");
1604 numRespPoints = 4194304;
1605 }
1606
1607
1608 return 0;
1609}
1610
1611#undef ADD_PROCESS_PARAM
const char * program
void LALFindChirpInjectSignals(LALStatus *status, REAL4TimeSeries *chan, SimInspiralTable *events, COMPLEX8FrequencySeries *resp)
const LALVCSInfoList lalAppsVCSInfoList
NULL-terminated list of VCS and build information for LALApps and its dependencies
const LALVCSInfo lalAppsVCSIdentInfo
Identable 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)
void LALFrSeek(LALStatus *status, const LIGOTimeGPS *epoch, LALFrStream *stream)
void LALFrCacheOpen(LALStatus *status, LALFrStream **output, LALCache *cache)
void LALFrGetREAL4TimeSeries(LALStatus *status, REAL4TimeSeries *series, FrChanIn *chanin, LALFrStream *stream)
void LALFrClose(LALStatus *status, LALFrStream **stream)
int j
int k
void LALCheckMemoryLeaks(void)
#define LALCalloc(m, n)
#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
int XLALCloseLIGOLwXMLFile(LIGOLwXMLStream *xml)
LIGOLwXMLStream * XLALOpenLIGOLwXMLFile(const char *path)
int XLALWriteLIGOLwXMLProcessTable(LIGOLwXMLStream *, const ProcessTable *)
int XLALWriteLIGOLwXMLProcessParamsTable(LIGOLwXMLStream *, const ProcessParamsTable *)
int XLALWriteLIGOLwXMLSimInspiralTable(LIGOLwXMLStream *, const SimInspiralTable *)
int XLALWriteLIGOLwXMLSearchSummaryTable(LIGOLwXMLStream *, const SearchSummaryTable *)
SimInspiralTable * XLALSimInspiralTableFromLIGOLw(const char *fileName)
#define LIGOMETA_IFOS_MAX
#define LIGOMETA_COMMENT_MAX
#define LIGOMETA_TYPE_MAX
#define LIGOMETA_PROGRAM_MAX
#define LIGOMETA_VALUE_MAX
#define LIGOMETA_PARAM_MAX
void XLALDestroyProcessParamsTable(ProcessParamsTable *)
void XLALDestroySimInspiralTable(SimInspiralTable *head)
int XLALPopulateProcessTable(ProcessTable *ptable, const char *program_name, const char *cvs_revision, const char *cvs_source, const char *cvs_date, long process_id)
#define fprintf
static LALUnit strainPerCount
Definition: getresp.c:41
LIGOTimeGPS * XLALGPSTimeNow(LIGOTimeGPS *gpstime)
void XLALDestroyCache(LALCache *cache)
LALCache * XLALCacheImport(const char *fname)
double REAL8
#define XLAL_INIT_DECL(var,...)
int64_t INT8
char CHAR
uint32_t UINT4
int32_t INT4
float REAL4
LALNameLength
LAL_FR_STREAM_VERBOSE_MODE
int XLALOutputVCSInfo(FILE *fp, const LALVCSInfoList vcs_list, const int verbose, const char *prefix)
REAL4TimeSeries * XLALAddREAL4TimeSeries(REAL4TimeSeries *arg1, const REAL4TimeSeries *arg2)
const LALUnit lalADCCountUnit
void LALCCreateVector(LALStatus *, COMPLEX8Vector **, UINT4)
void LALDCreateVector(LALStatus *, REAL8Vector **, UINT4)
void LALCDestroyVector(LALStatus *, COMPLEX8Vector **)
void LALDDestroyVector(LALStatus *, REAL8Vector **)
void LALSDestroyVector(LALStatus *, REAL4Vector **)
void LALSCreateVector(LALStatus *, REAL4Vector **, UINT4)
void XLALAbortErrorHandler(const char *func, const char *file, int line, int errnum)
XLALErrorHandlerType * XLALSetErrorHandler(XLALErrorHandlerType *newHandler)
#define XLAL_ERROR(...)
XLAL_EERR
LIGOTimeGPS * XLALGPSSetREAL8(LIGOTimeGPS *epoch, REAL8 t)
REAL8 XLALGPSGetREAL8(const LIGOTimeGPS *epoch)
LIGOTimeGPS * XLALINT8NSToGPS(LIGOTimeGPS *epoch, INT8 ns)
int writeInjOnly
Definition: inspfrinj.c:345
int main(int argc, char *argv[])
Definition: inspfrinj.c:352
int writeRawPlusInj
Definition: inspfrinj.c:346
int injectOverhead
Definition: inspfrinj.c:338
CHAR outfileName[FILENAME_MAX]
Definition: inspfrinj.c:323
int writeReal8Frame
Definition: inspfrinj.c:347
int writeRawData
Definition: inspfrinj.c:344
#define PROGRAM_NAME
Definition: inspfrinj.c:300
enum @2 calData
INT8 inputLengthNS
Definition: inspfrinj.c:317
CHAR * calCacheName
Definition: inspfrinj.c:332
int outCompress
Definition: inspfrinj.c:348
SimInspiralTable * thisInj
Definition: inspfrinj.c:340
CHAR * injCacheName
Definition: inspfrinj.c:321
CHAR * injectionFile
Definition: inspfrinj.c:334
INT4 sampleRate
Definition: inspfrinj.c:327
#define ADD_PROCESS_PARAM(pptype, format, ppvalue)
Definition: inspfrinj.c:914
INT4 frameLength
Definition: inspfrinj.c:328
LIGOTimeGPS gpsStartTime
Definition: inspfrinj.c:314
@ real_4
Definition: inspfrinj.c:325
@ real_8
Definition: inspfrinj.c:325
@ undefined
Definition: inspfrinj.c:325
int vrbflg
defined in lal/lib/std/LALError.c
CHAR comment[LIGOMETA_COMMENT_MAX]
Definition: inspfrinj.c:350
CHAR ifo[3]
Definition: inspfrinj.c:322
REAL4 injFlow
Definition: inspfrinj.c:337
CHAR * fqChanName
Definition: inspfrinj.c:319
UINT4 numFiles
Definition: inspfrinj.c:330
INT8 gpsStartTimeNS
Definition: inspfrinj.c:313
static void print_usage(char *program)
Definition: inspfrinj.c:929
CHAR * frInCacheName
Definition: inspfrinj.c:320
CHAR * calFileName
Definition: inspfrinj.c:333
INT4 numRespPoints
Definition: inspfrinj.c:318
CHAR * injChanName
Definition: inspfrinj.c:335
LIGOTimeGPS gpsEndTime
Definition: inspfrinj.c:316
CHAR * userTag
Definition: inspfrinj.c:343
SimInspiralTable * injections
Definition: inspfrinj.c:339
INT4 injectSafety
Definition: inspfrinj.c:329
INT8 gpsEndTimeNS
Definition: inspfrinj.c:315
int arg_parse_check(int argc, char *argv[], ProcessParamsTable *procparams)
Definition: inspfrinj.c:976
char name[LIGOMETA_SOURCE_MAX]
Definition: inspinj.c:561
static LALStatus status
Definition: inspinj.c:552
FrameH * fr_add_proc_REAL8TimeSeries(FrameH *frame, REAL8TimeSeries *chan, const char *unit, const char *suffix)
FrameH * fr_add_proc_REAL4TimeSeries(FrameH *frame, REAL4TimeSeries *chan, const char *unit, const char *suffix)
searchsumm
c
float atol
CHAR fname[256]
Definition: spininj.c:211
CHAR name[LALNameLength]
COMPLEX8Sequence * data
COMPLEX8 * data
const CHAR * name
const char *const vcsDate
const char *const vcsStatus
const char *const vcsId
int * flag
INT4 gpsNanoSeconds
CHAR type[LIGOMETA_TYPE_MAX]
CHAR param[LIGOMETA_PARAM_MAX]
CHAR value[LIGOMETA_VALUE_MAX]
struct tagProcessParamsTable * next
CHAR program[LIGOMETA_PROGRAM_MAX]
LIGOTimeGPS start_time
CHAR ifos[LIGOMETA_IFOS_MAX]
LIGOTimeGPS end_time
CHAR comment[LIGOMETA_COMMENT_MAX]
CHAR name[LALNameLength]
REAL4Sequence * data
LALUnit sampleUnits
LIGOTimeGPS epoch
REAL4 * data
REAL8Sequence * data
LALUnit sampleUnits
LIGOTimeGPS epoch
CHAR name[LALNameLength]
REAL8 * data
struct tagSimInspiralTable * next
INT4 numPoints
Definition: tmpltbank.c:399
int output(const char *outfile, int outtype, REAL4TimeSeries *series)
Definition: view.c:603