LAL  7.5.0.1-89842e6
DelayTest.c
Go to the documentation of this file.
1 /*
2 * Copyright (C) 2007 David Chin, Jolien 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 Chin, David <dwchin@umich.edu> +1-734-730-1274
22  * \file
23  * \ingroup TimeDelay_h
24  *
25  * \brief Tests \c TimeDelay code.
26  *
27  * ### Usage ###
28  *
29  * \code
30  * TestDelay
31  * \endcode
32  *
33  * ### Description ###
34  *
35  * This program does zero-th order tests for XLALTimeDelayFromEarthCenter().
36  *
37  */
38 
39 #include <math.h>
40 #include <stdlib.h>
41 #include <errno.h>
42 /* Darwin doesn't have values.h; the machine constants are defined in
43  * float.h */
44 /* #include <values.h> */
45 #include <lal/LALStdlib.h>
46 #include <lal/Date.h>
47 #include <lal/TimeDelay.h>
48 #include <lal/SkyCoordinates.h>
49 #include <lal/DetectorSite.h>
50 
51 /* This should already be defined as X_EPS in /usr/include/values.h ;
52  * in Darwin, it's defined as DBL_EPSILON in /usr/include/float.h */
53 #define DOUBLE_EPSILON 1.0536712127723507013e-08
54 
55 
56 
57 int main(void)
58 {
59  LALFrDetector frdet1; /* Framelib detector info */
60  LALFrDetector frdet2;
61  LALDetector detector1;
62  LALDetector detector2;
63  LIGOTimeGPS gps;
64  SkyPosition source;
65  REAL8 delay;
66  REAL8 difference;
67 
68 
69  /*
70  * Set up a source that will be used in both LALTimeDelay() and
71  * LALTimeDelayFromEarthCenter().
72  * Simple source at (RA=0, Dec=0)
73  */
74  source.longitude = 0.;
75  source.latitude = 0.;
77 
78  /*
79  * Now, setup two detectors. One at (0.E, 0.N) and the other at (90.E,
80  * 0.N)
81  */
82  strcpy(frdet1.name, "TEST IFO 1");
83  frdet1.vertexLongitudeRadians = 0.;
84  frdet1.vertexLatitudeRadians = 0.;
85  frdet1.vertexElevation = 0.;
86  frdet1.xArmAltitudeRadians = 0.;
87  frdet1.xArmAzimuthRadians = 0.;
89  frdet1.yArmAzimuthRadians = 0.;
90 
91  if(!XLALCreateDetector(&detector1, &frdet1, LALDETECTORTYPE_IFODIFF))
92  {
93  fprintf(stderr, "TestDelay: XLALCreateDetector failed, line %i, %s\n",
94  __LINE__, "$Id$");
95  return 1;
96  }
97 
98  /*
99  * Expect the location vector to be (R, 0, 0): R = radius of Earth
100  * at Equator
101  * tolerance, 1.e-04
102  */
103  if (fabs(detector1.location[0] - LAL_REARTH_SI)/LAL_REARTH_SI > 1.e-4 ||
104  detector1.location[1] != 0. ||
105  detector1.location[2] != 0.)
106  {
107  fprintf(stderr, "TestDelay: XLALCreateDetector output is wrong, line %i, %s\n",
108  __LINE__, "$Id$");
109  fprintf(stderr, "Got Det #1 location: (% 16.8e, % 16.8e, % 16.8e)\n",
110  (float)detector1.location[0], (float)detector1.location[1],
111  (float)detector1.location[2]);
112  fprintf(stderr, "Expected: (% 16.8e, % 16.8e, % 16.8e)\n",
113  (float)LAL_REARTH_SI, 0., 0.);
114 
115  return 1;
116  }
117 
118  if (lalDebugLevel > 2)
119  printf("Det #1 location: (%7.4e, %7.4e, %7.4e)\n",
120  detector1.location[0], detector1.location[1],
121  detector1.location[2]);
122 
123 
124  strcpy(frdet2.name, "TEST IFO 2");
126  frdet2.vertexLatitudeRadians = 0.;
127  frdet2.vertexElevation = 0.;
128  frdet2.xArmAltitudeRadians = 0.;
129  frdet2.xArmAzimuthRadians = 0.;
130  frdet2.yArmAltitudeRadians = 0.;
131  frdet2.yArmAzimuthRadians = LAL_PI_2;
132 
133  if(!XLALCreateDetector(&detector2, &frdet2, LALDETECTORTYPE_IFODIFF))
134  {
135  fprintf(stderr, "TestDelay: XLALCreateDetector failed, line %i, %s\n",
136  __LINE__, "$Id$");
137  return 1;
138  }
139 
140  /*
141  * Set a GPS time that's close to 0h GMST1. (Found this by trial and
142  * error.)
143  */
144  gps.gpsSeconds = 60858;
145  gps.gpsNanoSeconds = 0;
146 
147  delay = XLALTimeDelayFromEarthCenter(detector1.location, source.longitude, source.latitude, &gps);
148  if (XLAL_IS_REAL8_FAIL_NAN(delay))
149  {
150  fprintf(stderr,
151  "TestDelay: XLALTimeDelayFromEarthCenter() failed, line %i, %s\n",
152  __LINE__, "$Id$");
153  return 1;
154  }
155 
156  /*
157  * Expect delay to be roughly c/R, where c=speed of light,
158  * R=radius of Earth at
159  * Equator
160  */
161  /*
162  printf("Time delay from Earth center = %18.13e sec\n", delay);
163  printf("R/c = %18.13e sec\n", (REAL8)LAL_REARTH_SI / (REAL8)LAL_C_SI);
164 
165  printf("Diff = %18.13e\n", delay + (REAL8)LAL_REARTH_SI / (REAL8)LAL_C_SI);
166  printf("X_EPS = %18.13e\n", (float)X_EPS);
167  printf("H_PREC = %18.13e\n", (float)H_PREC);
168  */
169 
170  if (lalDebugLevel > 2)
171  {
172  printf("delay = %20.14e\n", delay);
173  printf("Rearth / c = %20.14e\n", (REAL8)LAL_REARTH_SI /
174  (REAL8)LAL_C_SI);
175  }
176 
177  difference = fabs(delay) - (REAL8)LAL_REARTH_SI / (REAL8)LAL_C_SI;
178 
179  if (difference < DOUBLE_EPSILON)
180  {
181  return 0;
182  }
183  else
184  {
185  fprintf(stderr, "ERROR: computed delay differs from expected delay by amount greater than DOUBLE_EPSILON (% 14.8e); difference = % 14.8e\n",
186  DOUBLE_EPSILON, difference);
187  return 1;
188  }
189 }
#define DOUBLE_EPSILON
Definition: DelayTest.c:53
int main(void)
Definition: DelayTest.c:57
#define fprintf
LALDetector * XLALCreateDetector(LALDetector *detector, const LALFrDetector *frDetector, LALDetectorType type)
UNDOCUMENTED.
#define LAL_PI_2
pi/2
Definition: LALConstants.h:181
#define LAL_C_SI
Speed of light in vacuum, m s^-1.
Definition: LALConstants.h:198
#define LAL_REARTH_SI
Earth equatorial radius, m.
Definition: LALConstants.h:416
double REAL8
Double precision real floating-point number (8 bytes).
#define lalDebugLevel
Definition: LALDebugLevel.h:58
@ LALDETECTORTYPE_IFODIFF
IFO in differential mode.
Definition: LALDetectors.h:240
@ COORDINATESYSTEM_EQUATORIAL
The sky-fixed equatorial coordinate system.
double XLALTimeDelayFromEarthCenter(const double detector_earthfixed_xyz_metres[3], double source_right_ascension_radians, double source_declination_radians, const LIGOTimeGPS *gpstime)
Compute difference in arrival time of the same signal at detector and at center of Earth-fixed frame.
Definition: TimeDelay.c:83
#define XLAL_IS_REAL8_FAIL_NAN(val)
Tests if val is a XLAL REAL8 failure NaN.
Definition: XLALError.h:393
Detector structure.
Definition: LALDetectors.h:278
REAL8 location[3]
The three components, in an Earth-fixed Cartesian coordinate system, of the position vector from the ...
Definition: LALDetectors.h:279
Detector frame data structure Structure to contain the data that appears in a FrDetector structure in...
Definition: LALDetectors.h:255
REAL8 vertexLongitudeRadians
The geodetic longitude of the vertex in radians.
Definition: LALDetectors.h:258
REAL8 vertexLatitudeRadians
The geodetic latitude of the vertex in radians.
Definition: LALDetectors.h:259
REAL4 vertexElevation
The height of the vertex above the reference ellipsoid in meters.
Definition: LALDetectors.h:260
REAL4 xArmAzimuthRadians
The angle clockwise from North to the projection of the X arm (or bar's cylidrical axis) into the lo...
Definition: LALDetectors.h:262
REAL4 yArmAltitudeRadians
The angle up from the local tangent plane of the reference ellipsoid to the Y arm in radians (unused...
Definition: LALDetectors.h:263
REAL4 yArmAzimuthRadians
The angle clockwise from North to the projection of the Y arm into the local tangent plane of the re...
Definition: LALDetectors.h:264
REAL4 xArmAltitudeRadians
The angle up from the local tangent plane of the reference ellipsoid to the X arm (or bar's cylidric...
Definition: LALDetectors.h:261
CHAR name[LALNameLength]
A unique identifying string.
Definition: LALDetectors.h:256
Epoch relative to GPS epoch, see LIGOTimeGPS type for more details.
Definition: LALDatatypes.h:458
INT4 gpsSeconds
Seconds since 0h UTC 6 Jan 1980.
Definition: LALDatatypes.h:459
INT4 gpsNanoSeconds
Residual nanoseconds.
Definition: LALDatatypes.h:460
This structure stores the two spherical coordinates of a sky position; ie a generic latitude and long...
REAL8 longitude
The longitudinal coordinate (in radians), as defined above.
REAL8 latitude
The latitudinal coordinate (in radians), as defined above.
CoordinateSystem system
The coordinate system in which latitude/longitude are expressed.