LALBarycenterTest.c

Go to the documentation of this file.
00001 /*
00002 *  Copyright (C) 2007 Curt Cutler, David Chin, Jolien Creighton, Reinhard Prix, Teviet 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 /****************************** <lalVerbatim file="LALBarycenterTestCV">
00021 Author: Cutler, C.
00022 $Id: LALBarycenterTest.c,v 1.11 2007/06/08 14:41:52 bema Exp $
00023 ******************************* </lalVerbatim> */
00024 
00025 /* <lalLaTeX>
00026 
00027 \subsection{Program \texttt{LALBarycenterTest.c}}
00028 \label{ss:LALBarycenterTest.c}
00029 
00030 Tests the routine \verb@LALBarycenter()@.  Exercises some of the error
00031 conditions and makes sure that they work.
00032 
00033 \subsubsection*{Usage}
00034 \begin{verbatim}
00035 LALBarycenterTest 
00036 \end{verbatim}
00037 
00038 \subsubsection*{Description}
00039 
00040 This program demonstrates the use of \verb@LALBarycenter.c@.
00041 The two ephemeris files specified in the \verb@EphemerisFilenames@
00042 structure (e.g., for data taken in 1998, \verb@sun98.dat@ and \verb@earth98.dat@)
00043 are assumed to be in the same directory as the program as
00044 the test program. 
00045 
00046 \subsubsection*{Exit codes}
00047 \input{LALBarycenterTestCE}
00048 
00049 \subsubsection*{Uses}
00050 \begin{verbatim}
00051 lalDebugLevel
00052 LALMalloc()
00053 LALFree()
00054 LALBarycenterInit()
00055 LALBarycenterEarth()
00056 LALBarycenter()
00057 LALCheckMemoryLeaks()
00058 \end{verbatim}
00059 
00060 \subsubsection*{Notes}
00061 
00062 \vfill{\footnotesize\input{LALBarycenterTestCV}}
00063 
00064 </lalLaTeX> */
00065 
00066 #include <lal/LALBarycenter.h>
00067 #include <lal/LALInitBarycenter.h>
00068 #include <lal/DetectorSite.h>
00069 #include <lal/Date.h>
00070 
00071 NRCSID(LALBARYCENTERTESTC,"$Id: LALBarycenterTest.c,v 1.11 2007/06/08 14:41:52 bema Exp $");
00072 
00073 /***************************** <lalErrTable file="LALBarycenterTestCE"> */
00074 #define LALBARYCENTERTESTC_ENOM 0
00075 #define LALBARYCENTERTESTC_EOPEN 1
00076 #define LALBARYCENTERTESTC_EOUTOFRANGEE  4
00077 #define LALBARYCENTERTESTC_EOUTOFRANGES  8
00078 #define LALBARYCENTERTESTC_EBADSOURCEPOS 16
00079 #define LALBARYCENTERTESTC_EEPHFILE 32
00080 
00081 #define LALBARYCENTERTESTC_MSGENOM "Nominal exit"
00082 #define LALBARYCENTERTESTC_MSGEOPEN "Error checking failed to catch missing ephemeris file."
00083 #define LALBARYCENTERTESTC_MSGEOUTOFRANGEE "Failed to catch that tgps not in range of earth.dat file"
00084 #define LALBARYCENTERTESTC_MSGEOUTOFRANGES "Failed to catch that tgps not in range of sun.dat file"  
00085 #define LALBARYCENTERTESTC_MSGEBADSOURCEPOS "Failed to catch bad source position"
00086 #define LALBARYCENTERTESTC_MSGEEPHFILE "Failed to catch error reading ephemeris file."
00087 
00088 
00089 /***************************** </lalErrTable> */
00090 
00091 /*
00092   int lalDebugLevel=0;
00093 */
00094   INT4 lalDebugLevel=7;
00095 
00096 BarycenterInput baryinput;
00097 EmissionTime  emit;  
00098 LIGOTimeGPS tGPS;
00099 EarthState earth;
00100 
00101 INT4 t2000 = 630720013; /* gps time at Jan 1, 2000 00:00:00 UTC */
00102 INT4 t1998 = 630720013-730*86400-1;/* gps at Jan 1,1998 00:00:00 UTC*/
00103 
00104 int
00105 main( void )
00106 {
00107   static LALStatus stat;
00108   
00109   INT4 i,k; /*dummy indices*/
00110   EphemerisData *edat = NULL;
00111   LALLeapSecFormatAndAcc lsfas = {LALLEAPSEC_GPSUTC, LALLEAPSEC_STRICT};
00112   INT4 tmpLeap; /* need this because Date pkg defines leap seconds as
00113                    INT4, while EphemerisData defines it to be INT2. This won't
00114                    cause problems before, oh, I don't know, the Earth has been 
00115                    destroyed in nuclear holocaust. -- dwchin 2004-02-29 */
00116 
00117   char eEphFileBad[] = "earth47.dat";
00118   char eEphFile[] = "earth98.dat";
00119   char sEphFile[] = "sun98.dat";
00120   
00121   
00122   REAL8 alpha,delta;  /* RA and DEC (radians) in 
00123                          ICRS realization of J2000 coords.*/
00124 
00125 #if 0 /* Parallax is not treated yet. */
00126   REAL8 dInv; /* 1/(Dist. to Source), in units 1/sec */
00127 #endif
00128 
00129   edat = (EphemerisData *)LALMalloc(sizeof(EphemerisData));    
00130 
00131 #define DEBUG 1 /*rem non-zero is TRUE */
00132 #if (DEBUG)
00133 
00134 /* Checking response if data files not present */
00135 
00136   (*edat).ephiles.earthEphemeris = eEphFileBad;
00137   (*edat).ephiles.sunEphemeris = sEphFile;
00138   (*edat).leap = 12;
00139   LALInitBarycenter(&stat, edat);  
00140 
00141   if ( stat.statusCode != LALINITBARYCENTERH_EOPEN)
00142     {
00143       printf( "Got error code %d and message '%s', but expected error code %d\n",
00144           stat.statusCode, stat.statusDescription, LALINITBARYCENTERH_EOPEN);
00145       return LALBARYCENTERTESTC_EOPEN;
00146     }
00147 
00148 /* Checking response if data files somehow corrupted --to be fixed!
00149 
00150   (*edat).ephiles.earthEphemeris = "earth98.dat";
00151   (*edat).ephiles.sunEphemeris = "sun98_corrupt.dat";
00152   (*edat).leap = 12;
00153   LALInitBarycenter(&stat, edat);  
00154 
00155       if ( stat.statusCode != LALINITBARYCENTERH_EEPHFILE
00156         || strcmp(stat.statusDescription, LALINITBARYCENTERH_MSGEEPHFILE) )
00157     {
00158       printf( "Got error code %d and message %s\n",
00159           stat.statusCode, stat.statusDescription );
00160       printf( "Expected error code %d and message %s\n",
00161            LALINITBARYCENTERH_EEPHFILE, LALINITBARYCENTERH_MSGEEPHFILE);
00162       return LALBARYCENTERTESTC_EEPHFILE;
00163     }
00164 */
00165 #endif
00166 
00167 /*Now inputting kosher ephemeris. files and leap sec, to illustrate
00168   proper usage. The real, serious TEST of the code is a script written
00169   by Rejean Dupuis comparing LALBarycenter to TEMPO for thousands
00170   of source positions and times. */
00171 
00172   (*edat).ephiles.earthEphemeris = eEphFile;
00173   (*edat).ephiles.sunEphemeris = sEphFile;
00174 
00175 /* Next give the number of leap secs added from start of GPS epoch to
00176    tgps. It's perfectly OK to instead give the number of leap
00177    sec from start of GPS epoch to, say, Jan. 2 in year that contains
00178    tgps. Currently have to specify leap by hand. This will be
00179    replaced by a leap sec function being written by D. Chin.
00180    Use: leap = 11 for 1997, leap = 12 for 1998, leap = 13 for 1999,
00181    leap = 13 for 2000, leap = 13 for 2001, leap = 13 for 2002. 
00182    Yes, really: the last time it changed was end of 1998, and it's
00183    not changing at end of 2001.
00184 */ 
00185 
00186   (*edat).leap = 12;
00187   
00188   LALInitBarycenter(&stat, edat);
00189   printf("stat.statusCode = %d\n",stat.statusCode); 
00190   REPORTSTATUS(&stat);
00191 
00192  /* The routines using LALBarycenter package, the code above, leading 
00193     up LALInitBarycenter call, should be near top of main. The idea is
00194     that ephemeris data is read into RAM once, at the beginning.
00195  
00196     NOTE that the only part of the piece of the LALDetector structure
00197     baryinput.site that has to be filled in by the driver code is 
00198     the 3-vector: baryinput.site.location[] .
00199 
00200     NOTE that the driver code that calls LALInitBarycenter must
00201     LALFree(edat->ephemE) and LALFree(edat->ephemS).
00202     The driver code that calls LALBarycenter must LALFree(edat).
00203  */   
00204 
00205   
00206   { /*Now getting coords. for detector. Cached options are:
00207       LALDetectorIndexLHODIFF, LALDetectorIndexLLODIFF,
00208       LALDetectorIndexVIRGODIFF, LALDetectorIndexGEO600DIFF,
00209       LALDetectorIndexTAMA300DIFF,LALDetectorIndexCIT40DIFF */
00210      
00211   LALDetector cachedDetector;
00212   cachedDetector = lalCachedDetectors[LALDetectorIndexGEO600DIFF];
00213   baryinput.site.location[0]=cachedDetector.location[0]/LAL_C_SI;
00214   baryinput.site.location[1]=cachedDetector.location[1]/LAL_C_SI;
00215   baryinput.site.location[2]=cachedDetector.location[2]/LAL_C_SI;
00216   }  
00217 
00218 #if (DEBUG)
00219 /* Checking error messages when the timestamp is not within the 
00220    1-yr ephemeris files 
00221 */
00222     tGPS.gpsSeconds = t1998+5.e7;
00223     tGPS.gpsNanoSeconds = 0;
00224     LALBarycenterEarth(&stat, &earth, &tGPS, edat);
00225       if ( stat.statusCode != LALBARYCENTERH_EOUTOFRANGEE
00226         || strcmp(stat.statusDescription, LALBARYCENTERH_MSGEOUTOFRANGEE) )
00227     {
00228       printf( "Got error code %d and message %s\n",
00229           stat.statusCode, stat.statusDescription );
00230       printf( "Expected error code %d and message %s\n",
00231            LALBARYCENTERH_EOUTOFRANGEE, LALBARYCENTERH_MSGEOUTOFRANGEE);
00232       return LALBARYCENTERTESTC_EOUTOFRANGEE;
00233     }
00234 
00235 /* next try calling for bad choice of RA,DEC (e.g., something 
00236 sensible in degrees, but radians)*/
00237 
00238       tGPS.gpsSeconds = t1998+3600;
00239       tGPS.gpsNanoSeconds = 0;
00240     
00241     LALBarycenterEarth(&stat, &earth, &tGPS, edat);
00242 
00243       
00244     baryinput.alpha= 120.e0;
00245     baryinput.delta=60.e0;
00246     baryinput.dInv=0.e0;
00247 
00248     LALBarycenter(&stat, &emit, &baryinput, &earth);
00249       if ( stat.statusCode != LALBARYCENTERH_EBADSOURCEPOS
00250         || strcmp(stat.statusDescription,LALBARYCENTERH_MSGEBADSOURCEPOS) )
00251     {
00252       printf( "Got error code %d and message %s\n",
00253           stat.statusCode, stat.statusDescription );
00254       printf( "Expected error code %d and message %s\n",
00255            LALBARYCENTERH_EBADSOURCEPOS, LALBARYCENTERH_MSGEBADSOURCEPOS);
00256       return LALBARYCENTERTESTC_EBADSOURCEPOS;
00257     }
00258 
00259 #endif
00260 /* Now running program w/o errors, to illustrate proper use. */
00261 
00262 /*First: outer loop over pulse arrival times; LALBarycenterEarth
00263     called ONCE per arrival time */
00264   
00265   for (i=0;i < 10; i++){
00266     
00267     /*GPS time(sec) =  tGPS.gpsSeconds + 1.e-9*tGPS.gpsNanoSeconds  */ 
00268           
00269     tGPS.gpsSeconds = t1998;
00270     tGPS.gpsSeconds +=i*3600*50;  
00271     tGPS.gpsNanoSeconds = 0;
00272 
00273     /* addition by dwchin - 2004-02-29 */
00274     LALLeapSecs(&stat, &tmpLeap, &tGPS, &lsfas);
00275     edat->leap = (INT2)tmpLeap;
00276 
00277     LALBarycenterEarth(&stat, &earth, &tGPS, edat);
00278     REPORTSTATUS(&stat);
00279 
00280 /*Next: inner loop over different sky positions, for each arrival time;
00281      LALBarycenter called ONCE per sky position (or ONCE per detector) */
00282     
00283     for (k=0;k<3;k++){
00284       
00285       alpha=(LAL_PI/12.0)*(14.e0 + 51.e0/60.e0 + 
00286                            +38.56024702e0/3.6e3) + LAL_PI*k/10.e0;
00287       delta=(LAL_PI/180.e0)*(12.e0+ 19.e0/60.e0
00288                              +59.1434800e0/3.6e3); 
00289       
00290       baryinput.alpha = alpha;
00291       baryinput.delta = delta;
00292       baryinput.dInv = 0.e0;      
00293 
00294       baryinput.tgps.gpsSeconds = tGPS.gpsSeconds;
00295       baryinput.tgps.gpsNanoSeconds = tGPS.gpsNanoSeconds;
00296       
00297       LALBarycenter(&stat, &emit, &baryinput, &earth);
00298       REPORTSTATUS(&stat);
00299       
00300       printf("%d %d %d %25.17e %25.17e\n", k, 
00301              tGPS.gpsSeconds,  tGPS.gpsNanoSeconds,
00302              (emit.deltaT + tGPS.gpsSeconds + tGPS.gpsNanoSeconds*1.e-9), 
00303              emit.tDot);
00304 
00305       printf("%d %d %25.17e\n",
00306              emit.te.gpsSeconds, emit.te.gpsNanoSeconds, emit.deltaT);
00307 
00308       printf("%25.17e %25.17e %25.17e\n",
00309              emit.rDetector[0],emit.rDetector[1],emit.rDetector[2]);
00310 
00311       printf("%25.17e %25.17e %25.17e\n",
00312              emit.vDetector[0],emit.vDetector[1],emit.vDetector[2]);
00313     }    
00314   }
00315   LALFree(edat->ephemE);
00316   LALFree(edat->ephemS);
00317   LALFree(edat);
00318   LALCheckMemoryLeaks();
00319   return 0;
00320 }
00321 
00322 
00323 
00324 

Generated on Tue Oct 14 02:31:54 2008 for LAL by  doxygen 1.5.2