Loading [MathJax]/extensions/TeX/AMSsymbols.js
LALInspiral 5.0.3.1-b246709
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
InjectionInterfaceTest.c
Go to the documentation of this file.
1/*
2* Copyright (C) 2007 Jolien Creighton, Thomas Cokelaer
3*
4* This program is free software; you can redistribute it and/or modify
5* it under the terms of the GNU General Public License as published by
6* the Free Software Foundation; either version 2 of the License, or
7* (at your option) any later version.
8*
9* This program is distributed in the hope that it will be useful,
10* but WITHOUT ANY WARRANTY; without even the implied warranty of
11* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12* GNU General Public License for more details.
13*
14* You should have received a copy of the GNU General Public License
15* along with with program; see the file COPYING. If not, write to the
16* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
17* MA 02110-1301 USA
18*/
19
20/**
21 * \author Cokelaer, T.
22 * \file
23 *
24 * \brief Interface to generate any kind of gravitational waves signal.
25 *
26 * ### Usage ###
27 *
28 * \code
29 * \c InterfaceTest
30 * \endcode
31 *
32 * ### Description ###
33 *
34 * Right now this test file read an input xml (injection.xml) file and for
35 * each valid line it computes the approriate waveform. Those waveforms are
36 * either produce within the inject package (PPN waveform) or within the
37 * inspiral package (TaylorT[1,2,3], EOB, SpinTaylor, PadeT1).
38 *
39 * Then the function LALGeneralInspiral create the amplitude, freq and phi
40 * vectors needed for further injection including the data itself (noise, h(t))
41 *
42 * Finally, the injections are stored in a vector which is saved in "injection.dat"
43 * file.
44 *
45 * ### Uses ###
46 *
47 * \code
48 *
49 * \endcode
50 *
51 * ### Notes ###
52 *
53 */
54
55/**\name Error Codes */ /** @{ */
56#define INJECTIONINTERFACETESTC_ENORM 0
57#define INJECTIONINTERFACETESTC_ESUB 1
58#define INJECTIONINTERFACETESTC_EARG 2
59#define INJECTIONINTERFACETESTC_EVAL 3
60#define INJECTIONINTERFACETESTC_EFILE 4
61#define INJECTIONINTERFACETESTC_EMEM 5
62#define INJECTIONINTERFACETESTC_EINJECT 6
63
64#define INJECTIONINTERFACETESTC_MSGENORM "Normal exit"
65#define INJECTIONINTERFACETESTC_MSGESUB "Subroutine failed"
66#define INJECTIONINTERFACETESTC_MSGEARG "Error parsing arguments"
67#define INJECTIONINTERFACETESTC_MSGEVAL "Input argument out of valid range"
68#define INJECTIONINTERFACETESTC_MSGEFILE "Could not open file"
69#define INJECTIONINTERFACETESTC_MSGEMEM "Out of memory"
70#define INJECTIONINTERFACETESTC_MSGEINJECT "No valid injection to do ... ? "
71/** @} */
72
73/* --- the names of the files to be used --- */
74#define INJECTIONINTERFACETEST_INJECTIONXMLFILE "injection.xml"
75#define INJECTIONINTERFACETEST_INJECTIONOUTPUTFILE "injection.dat"
76
77/* --- include files --- */
78#include <stdio.h>
79#include <stdlib.h>
80#include <string.h>
81
82
83#include <lal/GenerateInspiral.h>
84#include <lal/VectorOps.h>
85#include <lal/SeqFactories.h>
86
87#include <lal/LALStdio.h>
88#include <lal/LALStdlib.h>
89#include <lal/LALError.h>
90#include <lal/LALDatatypes.h>
91#include <lal/AVFactories.h>
92
93#include <lal/LIGOMetadataTables.h>
94#include <lal/LIGOMetadataUtils.h>
95#include <lal/LIGOLwXML.h>
96#include <lal/LIGOLwXMLRead.h>
97
98#include <lal/Date.h>
99#include <lal/Units.h>
100#include <lal/FindChirp.h>
101#include <lal/PrintFTSeries.h>
102
103#define ERROR( code, msg, statement ) \
104do \
105if ( lalDebugLevel & LALERROR ) \
106{ \
107 LALPrintError( "Error[0] %d: program %s, file %s, line %d, %s\n" \
108 " %s %s\n", (code), program, __FILE__, \
109 __LINE__, "$Id$", statement ? statement : \
110 "", (msg) ); \
111} \
112while (0)
113
114#define SUB( func, statusptr ) \
115do \
116if ( (func), (statusptr)->statusCode ) \
117{ \
118 ERROR( INJECTIONINTERFACETESTC_ESUB, INJECTIONINTERFACETESTC_MSGESUB, \
119 "Function call \"" #func "\" failed:" ); \
120 exit( INJECTIONINTERFACETESTC_ESUB ); \
121} \
122while (0)
123
124#ifdef __GNUC__
125#define UNUSED __attribute__ ((unused))
126#else
127#define UNUSED
128#endif
129
131
132
133
134/* --- Main program start here --- */
135int main(int UNUSED argc, char **argv)
136{
137 /* some variables to create the data */
138 UINT4 k;
139 UINT4 numPoints = 524288 ; /* arbitrary length of the data*/
140 REAL8 sampling = 2048.;
141 static LALStatus status;
142 /* injection structure */
143 SimInspiralTable *injections = NULL;
144 SimInspiralTable *thisInj = NULL;
145 /* the data */
146 REAL4TimeSeries ts ; /* A time series to store the injection */
147 COMPLEX8FrequencySeries fs ; /* A freq series to store the psd */
148 FILE *output; /* output result*/
149 CHAR *filename;
150 UINT4 lenfile;
151
152 /* --- for debugging --- */
153 program = *argv;
154
155 /* --- Start Main part here --- */
156 /* First, we test if the injection xml file exist */
157 if ((output = fopen(INJECTIONINTERFACETEST_INJECTIONXMLFILE,"r")) == NULL){
159 exit(0);
160 }
161 else {
162 fclose(output); /*if it exist let's close it */
163 }
164
165 /* then let's start to open the output file */
166 if ((output = fopen(INJECTIONINTERFACETEST_INJECTIONOUTPUTFILE,"w")) == NULL){
168 exit(0);
169 }
170
171 /* let's allocate memory for to create some dummy data to
172 inject the waveforms */
173 memset(&ts, 0, sizeof(REAL4TimeSeries));
174 LALSCreateVector( &status, &(ts.data), numPoints);
175
176 memset( &fs, 0, sizeof(COMPLEX8FrequencySeries));
177 LALCCreateVector( &status, &(fs.data), numPoints / 2 + 1 );
178
179
180 /* --- Let's fix some variables we have to be in agreement with the xml file data --- */
181 ts.epoch.gpsSeconds = 729273600; /* gps time of the time series */
182 ts.sampleUnits = lalADCCountUnit; /* UNITY ?? */
183 ts.deltaT = 1./sampling; /* sampling */
184 ts.name[0]='H'; /* L, H, G, V or T for the detector
185 otherwise it is optimally oriented */
186
187
188 fs.deltaF = sampling / numPoints; /* idem for fs */
190
191 /* --- the psd is flat for simplicity --- */
192 for( k = 0 ; k< numPoints/2; k++){
193 fs.data->data[k] = 1;
194 }
195 /* --- and time series is zero --- */
196 for( k = 0 ; k< numPoints; k++){
197 ts.data->data[k] = 0.;
198 }
199
200
201 lenfile = strlen(INJECTIONINTERFACETEST_INJECTIONXMLFILE) + 1;
202 filename = (CHAR *) calloc (lenfile, sizeof(CHAR *));
204
205
206 /* --- read injection here --- */
208
209 /* any injection to do ? */
210 if ( !injections )
211 {
213 exit( 1 );
214 }
215 /* --- inject here --- */
217 &ts,
218 injections,
219 &fs ), &status);
220
221
222 /* --- now we save the results --- */
223 for (k = 0; k < numPoints; k++){
224 fprintf(output,"%15.12f %e\n", (float)k/sampling, ts.data->data[k]);
225 }
226 fclose(output);
227
228 SUB( LALSDestroyVector( &status, &(ts.data) ), &status );
229 SUB( LALCDestroyVector( &status, &(fs.data) ), &status );
230
231 /* --- and finally free memory --- */
232 while ( injections )
233 {
234 thisInj = injections;
235 injections = injections->next;
236 LALFree(thisInj);
237 }
238
240 return 0;
241}
void LALFindChirpInjectSignals(LALStatus *status, REAL4TimeSeries *chan, SimInspiralTable *events, COMPLEX8FrequencySeries *resp)
#define INJECTIONINTERFACETESTC_MSGEFILE
char * program
int main(int UNUSED argc, char **argv)
#define SUB(func, statusptr)
#define INJECTIONINTERFACETEST_INJECTIONXMLFILE
#define INJECTIONINTERFACETESTC_MSGEINJECT
#define ERROR(code, msg, statement)
#define INJECTIONINTERFACETESTC_EFILE
#define INJECTIONINTERFACETEST_INJECTIONOUTPUTFILE
#define INJECTIONINTERFACETESTC_EINJECT
void LALCheckMemoryLeaks(void)
#define LALFree(p)
SimInspiralTable * XLALSimInspiralTableFromLIGOLw(const char *fileName)
#define fprintf
double REAL8
char CHAR
uint32_t UINT4
const LALUnit lalADCCountUnit
void LALCCreateVector(LALStatus *, COMPLEX8Vector **, UINT4)
void LALCDestroyVector(LALStatus *, COMPLEX8Vector **)
void LALSDestroyVector(LALStatus *, REAL4Vector **)
void LALSCreateVector(LALStatus *, REAL4Vector **, UINT4)
ts
COMPLEX8Sequence * data
COMPLEX8 * data
struct tagSimInspiralTable * next
char output[FILENAME_MAX]