Loading [MathJax]/extensions/TeX/AMSsymbols.js
LALInspiral 5.0.3.1-8a6b96f
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
BasicInjectTest.c
Go to the documentation of this file.
1/*
2* Copyright (C) 2007 Jolien Creighton, Teviet Creighton
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 * \author Creighton, T. D.
22 * \file
23 * \ingroup Inject_h
24 *
25 * \brief Injects inspiral signals into detector noise.
26 *
27 * ### Usage ###
28 *
29 * \code
30 * BasicInjectTest [-s sourcefile] [-r respfile] [-o outfile] [-e seed]
31 * [-i infile | -n sec nsec npt dt sigma] [-d debuglevel]
32 * \endcode
33 *
34 * ### Description ###
35 *
36 * This program generates inspiral waveforms with specified parameters,
37 * and injects them into ADC data. The following option flags are
38 * accepted:
39 * <ul>
40 * <li>[<tt>-s</tt>] Reads source information from the file
41 * \c sourcefile. If absent, it injects a single
42 * 1.4\f$M_\odot\f$--1.4\f$M_\odot\f$ inspiral, optimally oriented, at a distance
43 * of \f$10^{-5}\f$ solar Schwarzschild radii (\f$0.00002GM_\odot/c^2\f$).</li>
44 * <li>[<tt>-r</tt>] Reads a detector response function from the file
45 * \c respfile. If absent, it generates raw dimensionless strain.</li>
46 * <li>[<tt>-i</tt>] Reads ADC input from the file \c infile. This
47 * takes precedence over the <tt>-n</tt> option, below.</li>
48 * <li>[<tt>-n</tt>] Generates random ADC input data starting from a GPS
49 * epoch of \c sec seconds plus \c nsec nanoseconds, with
50 * \c npt data sampled at \c dt second intervals, with white
51 * Gaussian noise having standard deviation \c sigma. If neither
52 * <tt>-i</tt> (above) nor <tt>-n</tt> are given, the program assumes
53 * <tt>-n 0 0 1048576 9.765625e-4 0.0</tt>.</li>
54 * <li>[<tt>-o</tt>] Writes injected ADC data to the file
55 * \c outfile. If absent, the routines are exercised, but no output
56 * is written.</li>
57 * <li>[<tt>-d</tt>] Sets the debug level to \c debuglevel. If not
58 * specified, level 0 is assumed.</li>
59 * <li>[<tt>-r</tt>] Sets the random number seed to \c randomseed.
60 * If not specified, the seed is gerenated from the current time.</li>
61 * </ul>
62 *
63 * \par Format for \c sourcefile:
64 * The source file consists
65 * of any number of lines of data, each specifying a chirp waveform.
66 * Each line must begin with a character code (\c CHAR equal to one
67 * of <tt>'i'</tt>, <tt>'f'</tt>, or <tt>'c'</tt>), followed by 6
68 * whitespace-delimited numerical fields: the GPS epoch of the chirp
69 * (\c INT8 nanoseconds), the two binary masses (\c REAL4
70 * \f$M_\odot\f$), the distance to the source (\c REAL4 kpc), and the
71 * source's inclination and phase at coalescence (\c REAL4 degrees).
72 * The character codes have the following meanings:
73 * <ul>
74 * <li>[<tt>'i'</tt>] The epoch represents the GPS time of the start of
75 * the chirp waveform.</li>
76 * <li>[<tt>'f'</tt>] The epoch represents the GPS time of the end of
77 * the chirp waveform.</li>
78 * <li>[<tt>'c'</tt>] The epoch represents the GPS time when the
79 * binaries would coalesce in the point-mass approximation.</li>
80 * </ul>
81 * Thus a typical input line for two \f$1.4M_\odot\f$ objects at 11\,000\,kpc
82 * inclined \f$30^\circ\f$ with an initial phase of \f$45^\circ\f$, coalescing at
83 * 315\,187\,245 GPS seconds, will have the following line in the input
84 * file:
85 * \code
86 * c 315187245000000000 1.4 1.4 11000.0 30.0 45.0
87 * \endcode
88 *
89 * \par Format for \c respfile:
90 * The response function \f$R(f)\f$
91 * gives the real and imaginary components of the transformation
92 * \e from ADC output \f$o\f$ \e to tidal strain \f$h\f$ via
93 * \f$\tilde{h}(f)=R(f)\tilde{o}(f)\f$. It is inverted internally to give
94 * the detector <em>transfer function</em> \f$T(f)=1/R(f)\f$. The format
95 * \c respfile is a header specifying the GPS epoch \f$t_0\f$ at which
96 * the response was taken (\c INT8 nanoseconds), the lowest frequency
97 * \f$f_0\f$ at which the response is given (\c REAL8 Hz), and the
98 * frequency sampling interval \f$\Delta f\f$ (\c REAL8 Hz):
99 *
100 * <table><tr><td>
101 * <tt># epoch = </tt>\f$t_0\f$</td></tr>
102 * <tr><td><tt># f0 = </tt>\f$f_0\f$</td></tr>
103 * <tr><td><tt># deltaF = </tt>\f$\Delta f\f$
104 * </td></tr></table>
105 *
106 * followed by two columns of \c REAL4 data giving the real
107 * and imaginary components of \f$R(f_0+k\Delta f)\f$.
108 *
109 * \par Format for \c infile:
110 * The input file consists of a
111 * header giving the GPS epoch \f$t_0\f$ of the first time sample
112 * (\c INT8 nanoseconds) and the sampling interval \f$\Delta t\f$
113 * (\c REAL8 seconds):
114 *
115 * <table><tr><td>
116 * <tt># epoch = </tt>\f$t_0\f$</td></tr>
117 * <tr><td><tt># deltaT = </tt>\f$\Delta t\f$
118 * </td></tr></table>
119 *
120 * followed by a single column of ADC data. The ADC data
121 * should be integers in the range of an \c INT2 (from \f$-32768\f$ to
122 * \f$32767\f$), but is assumed to be written in floating-point notation in
123 * accordance with frame format.
124 *
125 * The output file \c outfile containing injected data is written in
126 * the same format.
127 *
128 */
129
130/** \name Error Codes */ /** @{ */
131#define BASICINJECTTESTC_ENORM 0 /**< Normal exit */
132#define BASICINJECTTESTC_ESUB 1 /**< Subroutine failed */
133#define BASICINJECTTESTC_EARG 2 /**< Error parsing arguments */
134#define BASICINJECTTESTC_EVAL 3 /**< Input argument out of valid range */
135#define BASICINJECTTESTC_EFILE 4 /**< Could not open file */
136#define BASICINJECTTESTC_EINPUT 5 /**< Error reading file */
137#define BASICINJECTTESTC_EMEM 6 /**< Out of memory */
138/** @} */
139
140/** \cond DONT_DOXYGEN */
141#define BASICINJECTTESTC_MSGENORM "Normal exit"
142#define BASICINJECTTESTC_MSGESUB "Subroutine failed"
143#define BASICINJECTTESTC_MSGEARG "Error parsing arguments"
144#define BASICINJECTTESTC_MSGEVAL "Input argument out of valid range"
145#define BASICINJECTTESTC_MSGEFILE "Could not open file"
146#define BASICINJECTTESTC_MSGEINPUT "Error reading file"
147#define BASICINJECTTESTC_MSGEMEM "Out of memory"
148
149
150
151#include <math.h>
152#include <stdlib.h>
153#include <lal/Date.h>
154#include <lal/LALStdio.h>
155#include <lal/LALStdlib.h>
156#include <lal/LALConstants.h>
157#include <lal/SeqFactories.h>
158#include <lal/Units.h>
159#include <lal/Random.h>
160#include <lal/VectorOps.h>
161#include <lal/SimulateCoherentGW.h>
162#include <lal/GeneratePPNInspiral.h>
163#include <lal/StreamInput.h>
164
165/* Default parameter settings. */
166#define EPOCH (0)
167#define DIST (0.00002*LAL_MRSUN_SI )
168#define M1 (1.4)
169#define M2 (1.4)
170#define INC (0.0)
171#define PHIC (0.0)
172#define SEC (0)
173#define NSEC (0)
174#define NPT (1048576)
175#define DT (1.0/1024.0)
176#define SIGMA (0.0)
177
178/* Global constants. */
179#define MSGLEN (256) /* maximum length of warning/info messages */
180#define FSTART (25.0) /* initial frequency of waveform */
181#define FSTOP (500.0) /* termination frequency of waveform */
182#define DELTAT (0.01) /* sampling interval of amplitude and phase */
183
184/* Usage format string. */
185#define USAGE "Usage: %s [-s sourcefile] [-r respfile] [-o outfile] [-e seed]\n [-i infile | -n sec nsec npt dt sigma] [-d debuglevel]\n"
186
187/* Macros for printing errors and testing subroutines. */
188#define ERROR( code, msg, statement ) \
189do \
190if ( lalDebugLevel & LALERROR ) \
191{ \
192 LALPrintError( "Error[0] %d: program %s, file %s, line %d, %s\n" \
193 " %s %s\n", (code), *argv, __FILE__, \
194 __LINE__, "$Id$", statement ? statement : \
195 "", (msg) ); \
196} \
197while (0)
198
199#define INFO( statement ) \
200do \
201if ( lalDebugLevel & LALINFO ) \
202{ \
203 LALPrintError( "Info[0]: program %s, file %s, line %d, %s\n" \
204 " %s\n", *argv, __FILE__, __LINE__, \
205 "$Id$", (statement) ); \
206} \
207while (0)
208
209#define WARNING( statement ) \
210do \
211if ( lalDebugLevel & LALWARNING ) \
212{ \
213 LALPrintError( "Warning[0]: program %s, file %s, line %d, %s\n" \
214 " %s\n", *argv, __FILE__, __LINE__, \
215 "$Id$", (statement) ); \
216} \
217while (0)
218
219#define SUB( func, statusptr ) \
220do \
221if ( (func), (statusptr)->statusCode ) \
222{ \
223 ERROR( BASICINJECTTESTC_ESUB, BASICINJECTTESTC_MSGESUB, \
224 "Function call \"" #func "\" failed:" ); \
225 return BASICINJECTTESTC_ESUB; \
226} \
227while (0)
228
229#define CHECKVAL( val, lower, upper ) \
230do \
231if ( ( (val) <= (lower) ) || ( (val) > (upper) ) ) \
232{ \
233 ERROR( BASICINJECTTESTC_EVAL, BASICINJECTTESTC_MSGEVAL, \
234 "Value of " #val " out of range:" ); \
235 LALPrintError( #val " = %f, range = (%f,%f]\n", (REAL8)(val), \
236 (REAL8)(lower), (REAL8)(upper) ); \
237 return BASICINJECTTESTC_EVAL; \
238} \
239while (0)
240
241
242int
243main(int argc, char **argv)
244{
245 /* Command-line parsing variables. */
246 int arg; /* command-line argument counter */
247 static LALStatus stat; /* status structure */
248 CHAR *sourcefile = NULL; /* name of sourcefile */
249 CHAR *respfile = NULL; /* name of respfile */
250 CHAR *infile = NULL; /* name of infile */
251 CHAR *outfile = NULL; /* name of outfile */
252 INT4 seed = 0; /* random number seed */
253 INT4 sec = SEC; /* ouput epoch.gpsSeconds */
254 INT4 nsec = NSEC; /* ouput epoch.gpsNanoSeconds */
255 INT4 npt = NPT; /* number of output points */
256 REAL8 dt = DT; /* output sampling interval */
257 REAL4 sigma = SIGMA; /* noise amplitude */
258
259 /* File reading variables. */
260 FILE *fp = NULL; /* generic file pointer */
261 BOOLEAN ok = 1; /* whether input format is correct */
262 UINT4 i; /* generic index over file lines */
263 INT8 epoch; /* epoch stored as an INT8 */
264
265 /* Other global variables. */
266 RandomParams *params = NULL; /* parameters of pseudorandom sequence */
267 DetectorResponse detector; /* the detector in question */
268 INT2TimeSeries output; /* detector ACD output */
269
270
271 /*******************************************************************
272 * PARSE ARGUMENTS (arg stores the current position) *
273 *******************************************************************/
274
275 /* Exit gracefully if no arguments were given.
276 if ( argc <= 1 ) {
277 INFO( "No testing done." );
278 return 0;
279 } */
280
281 arg = 1;
282 while ( arg < argc ) {
283 /* Parse source file option. */
284 if ( !strcmp( argv[arg], "-s" ) ) {
285 if ( argc > arg + 1 ) {
286 arg++;
287 sourcefile = argv[arg++];
288 }else{
289 ERROR( BASICINJECTTESTC_EARG, BASICINJECTTESTC_MSGEARG, 0 );
290 LALPrintError( USAGE, *argv );
292 }
293 }
294 /* Parse response file option. */
295 else if ( !strcmp( argv[arg], "-r" ) ) {
296 if ( argc > arg + 1 ) {
297 arg++;
298 respfile = argv[arg++];
299 }else{
300 ERROR( BASICINJECTTESTC_EARG, BASICINJECTTESTC_MSGEARG, 0 );
301 LALPrintError( USAGE, *argv );
303 }
304 }
305 /* Parse input file option. */
306 else if ( !strcmp( argv[arg], "-i" ) ) {
307 if ( argc > arg + 1 ) {
308 arg++;
309 infile = argv[arg++];
310 }else{
311 ERROR( BASICINJECTTESTC_EARG, BASICINJECTTESTC_MSGEARG, 0 );
312 LALPrintError( USAGE, *argv );
314 }
315 }
316 /* Parse noise output option. */
317 else if ( !strcmp( argv[arg], "-n" ) ) {
318 if ( argc > arg + 5 ) {
319 arg++;
320 sec = atoi( argv[arg++] );
321 nsec = atoi( argv[arg++] );
322 npt = atoi( argv[arg++] );
323 dt = atof( argv[arg++] );
324 sigma = atof( argv[arg++] );
325 }else{
326 ERROR( BASICINJECTTESTC_EARG, BASICINJECTTESTC_MSGEARG, 0 );
327 LALPrintError( USAGE, *argv );
329 }
330 }
331 /* Parse output file option. */
332 else if ( !strcmp( argv[arg], "-o" ) ) {
333 if ( argc > arg + 1 ) {
334 arg++;
335 outfile = argv[arg++];
336 }else{
337 ERROR( BASICINJECTTESTC_EARG, BASICINJECTTESTC_MSGEARG, 0 );
338 LALPrintError( USAGE, *argv );
340 }
341 }
342 /* Parse debug level option. */
343 else if ( !strcmp( argv[arg], "-d" ) ) {
344 if ( argc > arg + 1 ) {
345 arg++;
346 }else{
347 ERROR( BASICINJECTTESTC_EARG, BASICINJECTTESTC_MSGEARG, 0 );
348 LALPrintError( USAGE, *argv );
350 }
351 }
352 /* Parse random seed option. */
353 else if ( !strcmp( argv[arg], "-e" ) ) {
354 if ( argc > arg + 1 ) {
355 arg++;
356 seed = atoi( argv[arg++] );
357 }else{
358 ERROR( BASICINJECTTESTC_EARG, BASICINJECTTESTC_MSGEARG, 0 );
359 LALPrintError( USAGE, *argv );
361 }
362 }
363 /* Check for unrecognized options. */
364 else if ( argv[arg][0] == '-' ) {
365 ERROR( BASICINJECTTESTC_EARG, BASICINJECTTESTC_MSGEARG, 0 );
366 LALPrintError( USAGE, *argv );
368 }
369 } /* End of argument parsing loop. */
370
371 /* Check for redundant or bad argument values. */
372 CHECKVAL( npt, 0, 2147483647 );
373 CHECKVAL( dt, 0, LAL_REAL4_MAX );
374
375
376 /*******************************************************************
377 * SETUP *
378 *******************************************************************/
379
380 /* Set up output, detector, and random parameter structures. */
381 output.data = NULL;
382 detector.transfer = (COMPLEX8FrequencySeries *)
384 if ( !(detector.transfer) ) {
385 ERROR( BASICINJECTTESTC_EMEM, BASICINJECTTESTC_MSGEMEM, 0 );
387 }
388 detector.transfer->data = NULL;
389 detector.site = NULL;
390 SUB( LALCreateRandomParams( &stat, &params, seed ), &stat );
391
392 /* Set up units. */
393 output.sampleUnits = lalADCCountUnit;
394 if (XLALUnitDivide( &(detector.transfer->sampleUnits),
395 &lalADCCountUnit, &lalStrainUnit ) == NULL) {
396 return LAL_EXLAL;
397 }
398
399 /* Read response function. */
400 if ( respfile ) {
401 REAL4VectorSequence *resp = NULL; /* response as vector sequence */
402 COMPLEX8Vector *response = NULL; /* response as complex vector */
403 COMPLEX8Vector *unity = NULL; /* vector of complex 1's */
404
405 if ( ( fp = fopen( respfile, "r" ) ) == NULL ) {
406 ERROR( BASICINJECTTESTC_EFILE, BASICINJECTTESTC_MSGEFILE,
407 respfile );
409 }
410
411 /* Read header. */
412 ok &= ( fscanf( fp, "# epoch = %" LAL_INT8_FORMAT "\n", &epoch ) == 1 );
413 XLALINT8NSToGPS( &( detector.transfer->epoch ), epoch );
414 ok &= ( fscanf( fp, "# f0 = %lf\n", &( detector.transfer->f0 ) )
415 == 1 );
416 ok &= ( fscanf( fp, "# deltaF = %lf\n",
417 &( detector.transfer->deltaF ) ) == 1 );
418 if ( !ok ) {
419 ERROR( BASICINJECTTESTC_EINPUT, BASICINJECTTESTC_MSGEINPUT,
420 respfile );
422 }
423
424 /* Read and convert body to a COMPLEX8Vector. */
425 SUB( LALSReadVectorSequence( &stat, &resp, fp ), &stat );
426 fclose( fp );
427 if ( resp->vectorLength != 2 ) {
428 ERROR( BASICINJECTTESTC_EINPUT, BASICINJECTTESTC_MSGEINPUT,
429 respfile );
431 }
432 SUB( LALCCreateVector( &stat, &response, resp->length ), &stat );
433 memcpy( response->data, resp->data, 2*resp->length*sizeof(REAL4) );
434 SUB( LALSDestroyVectorSequence( &stat, &resp ), &stat );
435
436 /* Convert response function to a transfer function. */
437 SUB( LALCCreateVector( &stat, &unity, response->length ), &stat );
438 for ( i = 0; i < response->length; i++ ) {
439 unity->data[i] = 1.0;
440 }
441 SUB( LALCCreateVector( &stat, &( detector.transfer->data ),
442 response->length ), &stat );
443 SUB( LALCCVectorDivide( &stat, detector.transfer->data, unity,
444 response ), &stat );
445 SUB( LALCDestroyVector( &stat, &response ), &stat );
446 SUB( LALCDestroyVector( &stat, &unity ), &stat );
447 }
448
449 /* No response file, so generate a unit response. */
450 else {
451 XLALINT8NSToGPS( &( detector.transfer->epoch ), EPOCH );
452 detector.transfer->f0 = 0.0;
453 detector.transfer->deltaF = 1.5*FSTOP;
454 SUB( LALCCreateVector( &stat, &( detector.transfer->data ), 2 ),
455 &stat );
456 detector.transfer->data->data[0] = 1.0;
457 detector.transfer->data->data[1] = 1.0;
458 }
459
460
461 /* Read input data. */
462 if ( infile ) {
463 REAL4VectorSequence *input = NULL; /* input as vector sequence */
464 if ( ( fp = fopen( infile, "r" ) ) == NULL ) {
465 ERROR( BASICINJECTTESTC_EFILE, BASICINJECTTESTC_MSGEFILE,
466 infile );
468 }
469
470 /* Read header. */
471 ok &= ( fscanf( fp, "# epoch = %" LAL_INT8_FORMAT "\n", &epoch ) == 1 );
472 XLALINT8NSToGPS( &( output.epoch ), epoch );
473 ok &= ( fscanf( fp, "# deltaT = %lf\n", &( output.deltaT ) )
474 == 1 );
475 if ( !ok ) {
476 ERROR( BASICINJECTTESTC_EINPUT, BASICINJECTTESTC_MSGEINPUT,
477 infile );
479 }
480
481 /* Read and convert body. */
482 SUB( LALSReadVectorSequence( &stat, &input, fp ), &stat );
483 fclose( fp );
484 if ( input->vectorLength != 1 ) {
485 ERROR( BASICINJECTTESTC_EINPUT, BASICINJECTTESTC_MSGEINPUT,
486 infile );
488 }
489 SUB( LALI2CreateVector( &stat, &( output.data ), input->length ),
490 &stat );
491 for ( i = 0; i < input->length; i++ )
492 output.data->data[i] = (INT2)( input->data[i] );
493 SUB( LALSDestroyVectorSequence( &stat, &input ), &stat );
494 }
495
496 /* No input file, so generate one randomly. */
497 else {
498 output.epoch.gpsSeconds = sec;
499 output.epoch.gpsNanoSeconds = nsec;
500 output.deltaT = dt;
501 SUB( LALI2CreateVector( &stat, &( output.data ), npt ), &stat );
502 if ( sigma == 0 ) {
503 memset( output.data->data, 0, npt*sizeof(INT2) );
504 } else {
505 REAL4Vector *deviates = NULL; /* unit Gaussian deviates */
506 SUB( LALSCreateVector( &stat, &deviates, npt ), &stat );
507 SUB( LALNormalDeviates( &stat, deviates, params ), &stat );
508 for ( i = 0; i < (UINT4)( npt ); i++ )
509 output.data->data[i] = (INT2)
510 floor( sigma*deviates->data[i] + 0.5 );
511 SUB( LALSDestroyVector( &stat, &deviates ), &stat );
512 }
513 }
514
515
516 /*******************************************************************
517 * INJECTION *
518 *******************************************************************/
519
520 /* Open sourcefile. */
521 if ( sourcefile ) {
522 if ( ( fp = fopen( sourcefile, "r" ) ) == NULL ) {
523 ERROR( BASICINJECTTESTC_EFILE, BASICINJECTTESTC_MSGEFILE,
524 sourcefile );
526 }
527 }
528
529 /* For each line in the sourcefile... */
530 while ( ok ) {
531 PPNParamStruc ppnParams; /* wave generation parameters */
532 REAL4 m1, m2, dist, inc, phic; /* unconverted parameters */
533 CoherentGW waveform; /* amplitude and phase structure */
534 REAL4TimeSeries signalvec; /* GW signal */
535 REAL8 time; /* length of GW signal */
536 CHAR timeCode; /* code for signal time alignment */
537 CHAR message[MSGLEN]; /* warning/info messages */
538
539 /* Read and convert input line. */
540 if ( sourcefile ) {
541 ok &= ( fscanf( fp, "%c %" LAL_INT8_FORMAT " %f %f %f %f %f\n", &timeCode,
542 &epoch, &m1, &m2, &dist, &inc, &phic ) == 7 );
543 ppnParams.mTot = m1 + m2;
544 ppnParams.eta = m1*m2/( ppnParams.mTot*ppnParams.mTot );
545 ppnParams.d = dist*LAL_PC_SI*1000.0;
546 ppnParams.inc = inc*LAL_PI/180.0;
547 ppnParams.phi = phic*LAL_PI/180.0;
548 } else {
549 timeCode = 'i';
550 ppnParams.mTot = M1 + M2;
551 ppnParams.eta = M1*M2/( ppnParams.mTot*ppnParams.mTot );
552 ppnParams.d = DIST;
553 ppnParams.inc = INC;
554 ppnParams.phi = PHIC;
555 epoch = EPOCH;
556 }
557
558 if ( ok ) {
559 /* Set up other parameter structures. */
560 ppnParams.epoch.gpsSeconds = ppnParams.epoch.gpsNanoSeconds = 0;
561 ppnParams.position.latitude = ppnParams.position.longitude = 0.0;
563 ppnParams.psi = 0.0;
564 ppnParams.fStartIn = FSTART;
565 ppnParams.fStopIn = FSTOP;
566 ppnParams.lengthIn = 0;
567 ppnParams.ppn = NULL;
568 ppnParams.deltaT = DELTAT;
569 memset( &waveform, 0, sizeof(CoherentGW) );
570
571 /* Generate waveform at zero epoch. */
572 SUB( LALGeneratePPNInspiral( &stat, &waveform, &ppnParams ),
573 &stat );
574 snprintf( message, MSGLEN, "%d: %s", ppnParams.termCode,
575 ppnParams.termDescription );
576 INFO( message );
577 if ( ppnParams.dfdt > 2.0 ) {
578 snprintf( message, MSGLEN,
579 "Waveform sampling interval is too large:\n"
580 "\tmaximum df*dt = %f", ppnParams.dfdt );
581 WARNING( message );
582 }
583
584 /* Compute epoch for waveform. */
585 time = waveform.a->data->length*DELTAT;
586 if ( timeCode == 'f' )
587 epoch -= (INT8)( 1000000000.0*time );
588 else if ( timeCode == 'c' )
589 epoch -= (INT8)( 1000000000.0*ppnParams.tc );
590 XLALINT8NSToGPS( &( waveform.a->epoch ), epoch );
591 waveform.f->epoch = waveform.phi->epoch = waveform.a->epoch;
592
593 /* Generate and inject signal. */
594 signalvec.epoch = waveform.a->epoch;
595 signalvec.epoch.gpsSeconds -= 1;
596 signalvec.deltaT = output.deltaT/4.0;
597 signalvec.f0 = 0;
598 signalvec.data = NULL;
599 time = ( time + 2.0 )/signalvec.deltaT;
600 SUB( LALSCreateVector( &stat, &( signalvec.data ), (UINT4)time ),
601 &stat );
602 SUB( LALSimulateCoherentGW( &stat, &signalvec, &waveform,
603 &detector ), &stat );
604 SUB( LALSDestroyVectorSequence( &stat, &( waveform.a->data ) ),
605 &stat );
606 SUB( LALSDestroyVector( &stat, &( waveform.f->data ) ), &stat );
607 SUB( LALDDestroyVector( &stat, &( waveform.phi->data ) ), &stat );
608 LALFree( waveform.a );
609 LALFree( waveform.f );
610 LALFree( waveform.phi );
611 SUB( LALSDestroyVector( &stat, &( signalvec.data ) ), &stat );
612 }
613
614 /* If there is no source file, inject only one source. */
615 if ( !sourcefile )
616 ok = 0;
617 }
618
619 /* Input file is exhausted (or has a badly-formatted line ). */
620 if ( sourcefile )
621 fclose( fp );
622
623
624 /*******************************************************************
625 * CLEANUP *
626 *******************************************************************/
627
628 /* Print output file. */
629 if ( outfile ) {
630 if ( ( fp = fopen( outfile, "w" ) ) == NULL ) {
631 ERROR( BASICINJECTTESTC_EFILE, BASICINJECTTESTC_MSGEFILE,
632 outfile );
634 }
635 epoch = 1000000000LL*(INT8)( output.epoch.gpsSeconds );
636 epoch += (INT8)( output.epoch.gpsNanoSeconds );
637 fprintf( fp, "# epoch = %" LAL_INT8_FORMAT "\n", epoch );
638 fprintf( fp, "# deltaT = %23.16e\n", output.deltaT );
639 for ( i = 0; i < output.data->length; i++ )
640 fprintf( fp, "%8.1f\n", (REAL4)( output.data->data[i] ) );
641 fclose( fp );
642 }
643
644 /* Destroy remaining memory. */
645 SUB( LALDestroyRandomParams( &stat, &params ), &stat );
646 SUB( LALI2DestroyVector( &stat, &( output.data ) ), &stat );
647 SUB( LALCDestroyVector( &stat, &( detector.transfer->data ) ),
648 &stat );
649 LALFree( detector.transfer );
650
651 /* Done! */
653 INFO( BASICINJECTTESTC_MSGENORM );
655}
656/** \endcond */
#define BASICINJECTTESTC_EFILE
Could not open file.
#define BASICINJECTTESTC_ENORM
Normal exit.
#define BASICINJECTTESTC_EARG
Error parsing arguments.
#define BASICINJECTTESTC_EINPUT
Error reading file.
#define BASICINJECTTESTC_EMEM
Out of memory.
#define SUB(func, statusptr)
#define ERROR(code, msg, statement)
#define INFO(statement)
#define WARNING(statement)
#define USAGE
void LALCheckMemoryLeaks(void)
#define LALMalloc(n)
#define LALFree(p)
#define LAL_EXLAL
void LALSimulateCoherentGW(LALStatus *status, REAL4TimeSeries *output, CoherentGW *input, DetectorResponse *detector)
#define fscanf
#define fprintf
double i
const char * detector
void LALSDestroyVectorSequence(LALStatus *status, REAL4VectorSequence **vectorSequence)
void LALGeneratePPNInspiral(LALStatus *stat, CoherentGW *output, PPNParamStruc *params)
Computes a parametrized post-Newtonian inspiral waveform.
#define LAL_REAL4_MAX
#define LAL_PI
#define LAL_PC_SI
unsigned char BOOLEAN
double REAL8
int16_t INT2
int64_t INT8
char CHAR
uint32_t UINT4
int32_t INT4
float REAL4
int LALPrintError(const char *fmt,...)
#define LAL_INT8_FORMAT
void LALCreateRandomParams(LALStatus *status, RandomParams **params, INT4 seed)
void LALNormalDeviates(LALStatus *status, REAL4Vector *deviates, RandomParams *params)
void LALDestroyRandomParams(LALStatus *status, RandomParams **params)
COORDINATESYSTEM_EQUATORIAL
void LALSReadVectorSequence(LALStatus *status, REAL4VectorSequence **sequence, FILE *stream)
const LALUnit lalStrainUnit
const LALUnit lalADCCountUnit
LALUnit * XLALUnitDivide(LALUnit *output, const LALUnit *unit1, const LALUnit *unit2)
void LALCCreateVector(LALStatus *, COMPLEX8Vector **, UINT4)
void LALCDestroyVector(LALStatus *, COMPLEX8Vector **)
void LALDDestroyVector(LALStatus *, REAL8Vector **)
void LALSDestroyVector(LALStatus *, REAL4Vector **)
void LALI2CreateVector(LALStatus *, INT2Vector **, UINT4)
void LALI2DestroyVector(LALStatus *, INT2Vector **)
void LALSCreateVector(LALStatus *, REAL4Vector **, UINT4)
void LALCCVectorDivide(LALStatus *status, COMPLEX8Vector *out, const COMPLEX8Vector *in1, const COMPLEX8Vector *in2)
LIGOTimeGPS * XLALINT8NSToGPS(LIGOTimeGPS *epoch, INT8 ns)
COMPLEX8 * data
REAL4TimeVectorSeries * a
REAL8TimeSeries * phi
REAL4TimeSeries * f
INT4 gpsNanoSeconds
This structure stores the parameters for constructing a restricted post-Newtonian waveform.
REAL4 fStopIn
The requested termination frequency of the waveform, in Hz; If set to 0, the waveform will be generat...
REAL4Vector * ppn
The parameters selecting the type of post-Newtonian expansion; If ppn=NULL, a "normal" (physical) ex...
const CHAR * termDescription
The termination code description (above)
INT4 termCode
The termination condition (above) that stopped computation of the waveform.
REAL4 dfdt
The maximum value of encountered over any timestep used in generating the waveform.
LIGOTimeGPS epoch
start time of output time series
REAL4 phi
The phase at coalescence (or arbitrary reference phase for a post -Newtonian approximation),...
REAL4 psi
polarization angle (radians)
SkyPosition position
location of source on sky
REAL4 eta
The mass ratio of the binary system; Physically this parameter must lie in the range ; values outsid...
REAL8 tc
The time from the start of the waveform to coalescence (in the point-mass approximation),...
REAL4 mTot
The total mass of the binary system, in solar masses.
REAL4 fStartIn
The requested starting frequency of the waveform, in Hz.
REAL8 deltaT
The requested sampling interval of the waveform, in s.
REAL4 d
The distance to the system, in metres.
UINT4 lengthIn
The maximum number of samples in the generated waveform; If zero, the waveforms can be arbitrarily lo...
REAL4 inc
The inclination of the system to the line of sight, in radians.
REAL4Sequence * data
LIGOTimeGPS epoch
REAL4VectorSequence * data
REAL4 * data
REAL8Sequence * data
LIGOTimeGPS epoch
REAL8 longitude
REAL8 latitude
CoordinateSystem system
FILE * fp
enum @1 epoch
char output[FILENAME_MAX]
int main(int argc, char **argv)
Definition: version.c:32
char * outfile