TestDelay.c

Go to the documentation of this file.
00001 /*
00002 *  Copyright (C) 2007 David Chin, Jolien Creighton
00003 *
00004 *  This program is free software; you can redistribute it and/or modify
00005 *  it under the terms of the GNU General Public License as published by
00006 *  the Free Software Foundation; either version 2 of the License, or
00007 *  (at your option) any later version.
00008 *
00009 *  This program is distributed in the hope that it will be useful,
00010 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012 *  GNU General Public License for more details.
00013 *
00014 *  You should have received a copy of the GNU General Public License
00015 *  along with with program; see the file COPYING. If not, write to the
00016 *  Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston,
00017 *  MA  02111-1307  USA
00018 */
00019 
00020 /*
00021 <lalVerbatim file="TestDelayCV">
00022 
00023 Author: Chin, David <dwchin@umich.edu> +1-734-730-1274
00024 $Id: TestDelay.c,v 1.14 2007/06/08 14:41:43 bema Exp $
00025 
00026 </lalVerbatim>
00027 */
00028 
00029 /*
00030 <lalLaTeX>
00031 
00032 
00033 \subsection{Program \texttt{TestDelay.c}}
00034 \label{ss:TestDelay.c}
00035 
00036 Tests \verb@TimeDelay@ code.
00037 
00038 
00039 \subsubsection*{Usage}
00040 
00041 \begin{verbatim}
00042 TestDelay
00043 \end{verbatim}
00044 
00045 
00046 \subsubsection*{Description}
00047 
00048 This program does zero-th order tests for \texttt{LALTimeDelay()}. 
00049 
00050 
00051 \subsubsection*{Exit codes}
00052 
00053 </lalLaTeX>
00054 */
00055 
00056 /*
00057 <lalErrorTable>
00058 */
00059 
00060 /*
00061 </lalErrorTable>
00062 */
00063 
00064 #include <math.h>
00065 #include <stdlib.h>
00066 #include <errno.h>
00067 /* Darwin doesn't have values.h; the machine constants are defined in
00068  * float.h */
00069 /* #include <values.h> */
00070 #include <lal/LALStdlib.h>
00071 #include <lal/Date.h>
00072 #include <lal/TimeDelay.h>
00073 #include <lal/SkyCoordinates.h>
00074 #include <lal/DetectorSite.h>
00075 
00076 
00077 NRCSID( LALTESTDELAYC, "$Id: TestDelay.c,v 1.14 2007/06/08 14:41:43 bema Exp $" );
00078 
00079 /* This should already be defined as X_EPS in /usr/include/values.h ;
00080  * in Darwin, it's defined as DBL_EPSILON in /usr/include/float.h */
00081 #define DOUBLE_EPSILON 1.0536712127723507013e-08
00082 
00083 
00084 int lalDebugLevel = 0;
00085 
00086 int main(int argc, char **argv)
00087 {
00088   static LALStatus stat;
00089   LALFrDetector    frdet1;     /* Framelib detector info */
00090   LALFrDetector    frdet2;
00091   LALDetector      detector1;
00092   LALDetector      detector2;
00093   LIGOTimeGPS      gps;
00094   SkyPosition      source;
00095   REAL8            delay;
00096   REAL8            difference;
00097   DetTimeAndASource     det1_and_source;
00098   /* TwoDetsTimeAndASource dets_and_source; */
00099   LALPlaceAndGPS        det1_and_gps;
00100   /* LALPlaceAndGPS        det2_and_gps; */
00101 
00102   if (argc > 1)
00103     lalDebugLevel = atoi(argv[1]);
00104 
00105   /*
00106    * Set up a source that will be used in both LALTimeDelay() and
00107    * LALTimeDelayFromEarthCenter().
00108    * Simple source at (RA=0, Dec=0)
00109    */
00110   source.longitude = 0.;
00111   source.latitude  = 0.;
00112   source.system    = COORDINATESYSTEM_EQUATORIAL;
00113 
00114   /*
00115    * Now, setup two detectors. One at (0.E, 0.N) and the other at (90.E,
00116    * 0.N)
00117    */
00118   strcpy(frdet1.name, "TEST IFO 1");
00119   frdet1.vertexLongitudeRadians = 0.;
00120   frdet1.vertexLatitudeRadians  = 0.;
00121   frdet1.vertexElevation        = 0.;
00122   frdet1.xArmAltitudeRadians    = 0.;
00123   frdet1.xArmAzimuthRadians     = 0.;
00124   frdet1.yArmAltitudeRadians    = LAL_PI_2;
00125   frdet1.yArmAzimuthRadians     = 0.;
00126 
00127   LALCreateDetector(&stat, &detector1, &frdet1, LALDETECTORTYPE_IFODIFF);
00128   if (stat.statusCode && lalDebugLevel > 0)
00129     {
00130       fprintf(stderr, "TestDelay: LALCreateDetector failed, line %i, %s\n",
00131               __LINE__, LALTESTDELAYC);
00132       REPORTSTATUS(&stat);
00133       return stat.statusCode;
00134     }
00135   if (lalDebugLevel > 2)
00136     REPORTSTATUS(&stat);
00137 
00138   /*
00139    * Expect the location vector to be (R, 0, 0): R = radius of Earth
00140    *                                                 at Equator
00141    * tolerance, 1.e-04
00142    */
00143   if (fabs(detector1.location[0] - LAL_REARTH_SI)/LAL_REARTH_SI > 1.e-4 ||
00144       detector1.location[1] != 0.                         ||
00145       detector1.location[2] != 0.)
00146     {
00147       fprintf(stderr, "TestDelay: LALCreateDetector output is wrong, line %i, %s\n",
00148               __LINE__, LALTESTDELAYC);
00149       fprintf(stderr, "Got Det #1 location: (% 16.8e, % 16.8e, % 16.8e)\n",
00150               (float)detector1.location[0], (float)detector1.location[1],
00151               (float)detector1.location[2]);
00152       fprintf(stderr, "Expected:            (% 16.8e, % 16.8e, % 16.8e)\n",
00153               (float)LAL_REARTH_SI, 0., 0.);
00154 
00155       return(1);
00156     }
00157 
00158   if (lalDebugLevel > 2)
00159     printf("Det #1 location: (%7.4e, %7.4e, %7.4e)\n",
00160            detector1.location[0], detector1.location[1],
00161            detector1.location[2]);
00162     
00163 
00164   strcpy(frdet2.name, "TEST IFO 2");
00165   frdet2.vertexLongitudeRadians = LAL_PI_2;
00166   frdet2.vertexLatitudeRadians  = 0.;
00167   frdet2.vertexElevation        = 0.;
00168   frdet2.xArmAltitudeRadians    = 0.;
00169   frdet2.xArmAzimuthRadians     = 0.;
00170   frdet2.yArmAltitudeRadians    = 0.;
00171   frdet2.yArmAzimuthRadians     = LAL_PI_2;
00172 
00173   LALCreateDetector(&stat, &detector2, &frdet2, LALDETECTORTYPE_IFODIFF);
00174   if (stat.statusCode && lalDebugLevel > 0)
00175     {
00176       fprintf(stderr, "TestDelay: LALCreateDetector failed, line %i, %s\n",
00177               __LINE__, LALTESTDELAYC);
00178       REPORTSTATUS(&stat);
00179       return stat.statusCode;
00180     }  
00181   if (lalDebugLevel > 2)
00182     REPORTSTATUS(&stat);
00183 
00184   /*
00185    * Set a GPS time that's close to 0h GMST1. (Found this by trial and
00186    * error.) 
00187    */
00188   gps.gpsSeconds     = 60858;
00189   gps.gpsNanoSeconds = 0;
00190 
00191   det1_and_gps.p_detector = &detector1;
00192   det1_and_gps.p_gps      = &gps;
00193 
00194   det1_and_source.p_det_and_time = &det1_and_gps;
00195   det1_and_source.p_source       = &source;
00196 
00197   LALTimeDelayFromEarthCenter(&stat, &delay, &det1_and_source);
00198   if (stat.statusCode && lalDebugLevel > 0)
00199     {
00200       fprintf(stderr,
00201               "TestDelay: LALTimeDelayFromEarthCenter() failed, line %i, %s\n",
00202               __LINE__, LALTESTDELAYC);
00203       REPORTSTATUS(&stat);
00204       return stat.statusCode;
00205     }
00206   if (lalDebugLevel > 2)
00207     REPORTSTATUS(&stat);
00208 
00209   /*
00210    * Expect delay to be roughly c/R, where c=speed of light,
00211    *                                       R=radius of Earth at
00212    *                                         Equator
00213    */
00214   /*
00215     printf("Time delay from Earth center = %18.13e sec\n", delay);
00216     printf("R/c = %18.13e sec\n", (REAL8)LAL_REARTH_SI / (REAL8)LAL_C_SI);
00217 
00218     printf("Diff = %18.13e\n", delay + (REAL8)LAL_REARTH_SI / (REAL8)LAL_C_SI);
00219     printf("X_EPS = %18.13e\n", (float)X_EPS);
00220     printf("H_PREC = %18.13e\n", (float)H_PREC);
00221   */
00222 
00223   if (lalDebugLevel > 2)
00224     {
00225       printf("delay      = %20.14e\n", delay);
00226       printf("Rearth / c = %20.14e\n", (REAL8)LAL_REARTH_SI /
00227              (REAL8)LAL_C_SI);
00228     }
00229 
00230   difference = fabs(delay) - (REAL8)LAL_REARTH_SI / (REAL8)LAL_C_SI;
00231 
00232   if (difference < DOUBLE_EPSILON)
00233     {
00234       return 0;
00235     }
00236   else
00237     {
00238       fprintf(stderr, "ERROR: computed delay differs from expected delay by amount greater than DOUBLE_EPSILON (% 14.8e); difference = % 14.8e\n", 
00239               DOUBLE_EPSILON, difference);
00240       return 1;
00241     }
00242 }

Generated on Sat Aug 30 03:13:23 2008 for LAL by  doxygen 1.5.2