Loading [MathJax]/extensions/TeX/AMSsymbols.js
LALPulsar 7.1.1.1-b246709
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
VelocityTest.c
Go to the documentation of this file.
1/*
2* Copyright (C) 2007 Badri Krishnan, Jolien Creighton, Alicia Sintes Olives
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: TestVelocity.c
23 *
24 * Authors: Krishnan, B., Sintes, A.M.,
25 *
26 *
27 * History: Created by Badri Krishnan May 24, 2003
28 *
29 *
30 *-----------------------------------------------------------------------
31 */
32
33/*
34 * 1. An author and Id block
35 */
36
37/**
38 * \author Krishnan, B., Sintes, A.M.
39 * \file
40 * \ingroup Velocity_h
41 * \brief Tests the calculation of the averaged velocity of a given detector.
42 *
43 * ### Program TestVelocity.c ###
44 *
45 *
46 * ### Usage ###
47 *
48 * \code
49 * TestVelocity [-d debuglevel] [-a accuracy]
50 * \endcode
51 *
52 * ### Description ###
53 *
54 * This program computes the averaged velocity of the GEO600 detector
55 * between the times 730000044 and 730003644 with a default accuracy of 0.01.
56 * The two ephemeris files (e.g., for data taken in 2003, <tt>sun03.dat</tt> and
57 * <tt>earth03.dat</tt>) are assumed to be in the directory
58 * <tt>lal/packages/pulsar/test/</tt>.
59 *
60 * The <b>-d</b> option sets the debug level to the specified value
61 * \c debuglevel. The <b>-a</b> flag tells the program which accuracy to use.
62 *
63 * ### Uses ###
64 *
65 * \code
66 * LALAvgDetectorVel()
67 * LALPrintError()
68 * LALMalloc()
69 * LALFree()
70 * LALCheckMemoryLeaks()
71 * \endcode
72 *
73 */
74
75/* #include "./Velocity.h" */
76#include <lal/Velocity.h>
77
78/* Error codes and messages */
79
80/**\name Error Codes */ /** @{ */
81#define TESTVELOCITYC_ENORM 0
82#define TESTVELOCITYC_ESUB 1
83#define TESTVELOCITYC_EARG 2
84#define TESTVELOCITYC_EBAD 3
85#define TESTVELOCITYC_EFILE 4
86
87#define TESTVELOCITYC_MSGENORM "Normal exit"
88#define TESTVELOCITYC_MSGESUB "Subroutine failed"
89#define TESTVELOCITYC_MSGEARG "Error parsing arguments"
90#define TESTVELOCITYC_MSGEBAD "Bad argument values"
91#define TESTVELOCITYC_MSGEFILE "Could not create output file"
92/** @} */
93
94/** \cond DONT_DOXYGEN */
95
96/* Default parameters. */
97
98
99/* #define T0SEC 714153733 */
100#define T0SEC 730000044
101#define T0NSEC 0
102#define TBASE 3600.0
103#define ACCURACY 0.01
104
105/* Locations of the earth and sun ephemeris data */
106
107#define EARTHDATAFILE TEST_PKG_DATA_DIR "earth00-40-DE405.dat.gz";
108#define SUNDATAFILE TEST_PKG_DATA_DIR "sun00-40-DE405.dat.gz";
109
110char EARTHDATA[] = EARTHDATAFILE;
111char SUNDATA[] = SUNDATAFILE;
112
113/* Usage format string. */
114#define USAGE "Usage: %s [-d debuglevel] [-a accuracy]\n"
115
116/*********************************************************************/
117/* Macros for printing errors & testing subroutines (from Creighton) */
118/*********************************************************************/
119
120#define ERROR( code, msg, statement ) \
121do { \
122 if ( lalDebugLevel & LALERROR ) \
123 XLALPrintError( "Error[0] %d: program %s, file %s, line %d, %s\n" \
124 " %s %s\n", (code), *argv, __FILE__, \
125 __LINE__, "$Id$", statement ? statement : \
126 "", (msg) ); \
127} while (0)
128
129#define INFO( statement ) \
130do { \
131 if ( lalDebugLevel & LALINFO ) \
132 XLALPrintError( "Info[0]: program %s, file %s, line %d, %s\n" \
133 " %s\n", *argv, __FILE__, __LINE__, \
134 "$Id$", (statement) ); \
135} while (0)
136
137#define SUB( func, statusptr ) \
138do { \
139 if ( (func), (statusptr)->statusCode ) { \
140 ERROR( TESTVELOCITYC_ESUB, TESTVELOCITYC_MSGESUB, \
141 "Function call \"" #func "\" failed:" ); \
142 return TESTVELOCITYC_ESUB; \
143 } \
144} while (0)
145/******************************************************************/
146
147/* >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< */
148/* vvvvvvvvvvvvvvvvvvvvvvvvvvvvvv------------------------------------ */
149int main( int argc, char *argv[] )
150{
151
152 static LALStatus status;
153 static VelocityPar velPar;
154 static REAL8 vel[3];
155 static REAL8 pos[3];
156 static EphemerisData *edat = NULL;
157 LIGOTimeGPS tGPS;
158 INT4 arg; /* Argument counter */
159 REAL8 vTol = 0.01 ;
160 /* INT4 c, errflg=0;*/
161 /* LALoptarg = NULL; */
162 /* ------------------------------------------------------- */
163
164
165 /* default values */
167 velPar.startTime.gpsSeconds = T0SEC;
168 velPar.startTime.gpsNanoSeconds = T0NSEC;
169 velPar.tBase = TBASE;
170 velPar.vTol = ACCURACY;
171
172 /********************************************************/
173 /* Parse argument list. i stores the current position. */
174 /********************************************************/
175 arg = 1;
176 while ( arg < argc ) {
177 /* Parse debuglevel option. */
178 if ( !strcmp( argv[arg], "-d" ) ) {
179 if ( argc > arg + 1 ) {
180 arg++;
181 } else {
183 XLALPrintError( USAGE, *argv );
184 return TESTVELOCITYC_EARG;
185 }
186 }
187 /* Parse accuracy option. */
188 else if ( !strcmp( argv[arg], "-a" ) ) {
189 if ( argc > arg + 1 ) {
190 arg++;
191 vTol = atof( argv[arg++] );
192 velPar.vTol = vTol;
193 } else {
195 XLALPrintError( USAGE, *argv );
196 return TESTVELOCITYC_EARG;
197 }
198 }
199 /* Unrecognized option. */
200 else {
202 XLALPrintError( USAGE, *argv );
203 return TESTVELOCITYC_EARG;
204 }
205 } /* End of argument parsing loop. */
206 /******************************************************************/
207
208 /* read in ephemeris data */
209 XLAL_CHECK_MAIN( ( edat = XLALInitBarycenter( EARTHDATA, SUNDATA ) ) != NULL, XLAL_EFUNC );
210
211 /* fill in ephemeris data in velPar */
212 velPar.edat = edat;
213
214
215 tGPS.gpsSeconds = T0SEC;
216 tGPS.gpsNanoSeconds = T0NSEC;
217
218
219 SUB( LALDetectorVel( &status, vel, &tGPS, velPar.detector, velPar.edat ), &status );
220
221 printf( "Detector velocity at %d = %g, %g, %g \n", T0SEC, vel[0], vel[1], vel[2] );
222
223 SUB( LALDetectorPos( &status, vel, &tGPS, velPar.detector, velPar.edat ), &status );
224
225 printf( "Detector position at %d = %g, %g, %g \n", T0SEC, vel[0], vel[1], vel[2] );
226
227 SUB( LALAvgDetectorVel( &status, vel, &velPar ), &status );
228
229 printf( "Avg. detector velocity in a interval of %g from %d = %g, %g, %g \n", TBASE, T0SEC, vel[0], vel[1], vel[2] );
230
231 SUB( LALAvgDetectorPos( &status, pos, &velPar ), &status );
232
233 printf( "Avg. detector position in a interval of %g from %d = %g, %g, %g \n", TBASE, T0SEC, pos[0], pos[1], pos[2] );
234
237
238 //INFO(TESTVELOCITYC_MSGENORM);
239 return TESTVELOCITYC_ENORM;
240}
241
242/* >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< */
243
244/** \endcond */
LALDetectorIndexGEO600DIFF
#define SUB(func, statusptr)
#define ERROR(code, msg, statement)
void LALCheckMemoryLeaks(void)
#define ACCURACY
#define TESTVELOCITYC_EARG
Definition: VelocityTest.c:83
#define TESTVELOCITYC_ENORM
Definition: VelocityTest.c:81
#define TESTVELOCITYC_MSGEARG
Definition: VelocityTest.c:89
int main(int argc, char **argv)
const LALDetector lalCachedDetectors[LAL_NUM_DETECTORS]
EphemerisData * XLALInitBarycenter(const CHAR *earthEphemerisFile, const CHAR *sunEphemerisFile)
XLAL interface to reading ephemeris files 'earth' and 'sun', and return ephemeris-data in old backwar...
void XLALDestroyEphemerisData(EphemerisData *edat)
Destructor for EphemerisData struct, NULL robust.
double REAL8
int32_t INT4
void LALDetectorVel(LALStatus *status, REAL8 v[3], LIGOTimeGPS *time0, LALDetector detector, EphemerisData *edat)
This function finds the velocity of a given detector at a given time.
Definition: Velocity.c:200
void LALDetectorPos(LALStatus *status, REAL8 x[3], LIGOTimeGPS *time0, LALDetector detector, EphemerisData *edat)
This finds velocity of a given detector at a given time.
Definition: Velocity.c:258
void LALAvgDetectorVel(LALStatus *status, REAL8 v[3], VelocityPar *in)
This function outputs the average velocity REAL8 v[3] of the detector during a time interval.
Definition: Velocity.c:34
void LALAvgDetectorPos(LALStatus *status, REAL8 x[3], VelocityPar *in)
Given a detector and a time interval, this function outputs the average position of the detector duri...
Definition: Velocity.c:95
#define XLAL_CHECK_MAIN(assertion,...)
int XLALPrintError(const char *fmt,...) _LAL_GCC_PRINTF_FORMAT_(1
XLAL_EFUNC
pos
This structure contains all information about the center-of-mass positions of the Earth and Sun,...
INT4 gpsNanoSeconds
This structure stores the parameters required by XLALBarycenter() to calculate Earth velocity at a gi...
Definition: Velocity.h:84
EphemerisData * edat
ephemeris data pointer from XLALInitBarycenter()
Definition: Velocity.h:86
LALDetector detector
the detector
Definition: Velocity.h:85
REAL8 tBase
duration of interval
Definition: Velocity.h:88
LIGOTimeGPS startTime
start of time interval
Definition: Velocity.h:87
REAL8 vTol
fractional accuracy required for velocity (redundant for average velocity calculation)
Definition: Velocity.h:89