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
ssbtodetector.c
Go to the documentation of this file.
1/*
2* Copyright (C) 2013 Matthew Pitkin
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 * \file
22 * \ingroup lalpulsar_bin_HeterodyneSearch
23 * \author Matt Pitkin
24 *
25 * \brief Program to convert an input MJD, or GPS, time at the solar system barycentre to a GPS time at a detector
26 *
27 * This code will take in an MJD time in TDB, or a GPS-style time in TDB at the solar system barycentre and convert
28 * it to a GPS time at a given detector for a given sky position. The input detectors can be any of the standard
29 * acronyms for gravitational wave detectors, but can also include several radio telescopes (these use position
30 * information from TEMPO2):
31 * - the Robert C. Byrd Greeen Bank Telescope (GBT),
32 * - the Parkes Telescope (PKS),
33 * - the Lovell Telescope at Jodrell Bank (JBO),
34 * - the Arecibo Telescope (AO),
35 * - the Effelsberg 100m Radio Telescope (EFF),
36 * - the Nancay Decimetre Radio Telescope (NRT),
37 * - the Mount Pleasant Radio Observatory, Hobart (HOB),
38 * - the Hartebeesthoek Radio Astronomy Observatory (HART),
39 * - the Very Large Array (VLA),
40 * - and the Westerbork Synthesis Radio Telescope (WSRT).
41 */
42
43#include <stdlib.h>
44#include <stdio.h>
45
46#include <lal/LALInitBarycenter.h>
47#include <lal/LALgetopt.h>
48#include <lal/GeneratePulsarSignal.h>
49#include <lal/BinaryPulsarTiming.h>
50#include <lal/SFTfileIO.h>
51#include <lal/LALString.h>
52#include <lal/TranslateAngles.h>
53
54/* define the radio telescope positions */
55typedef enum {
56 GBT = 0, /* Robert C. Byrd GBT */
57 PKS, /* Parkes */
58 JBO, /* JBO Lovell telescope */
59 AO, /* Arecibo Telescope */
60 EFF, /* Effelsberg */
61 NRT, /* Nancay */
62 HOB, /* Hobart */
63 HART, /* Hartebeesthoek */
64 VLA, /* Very Large Array */
65 WSRT, /* Westerbork */
68
69/* create some detector locations for radio telescopes - positions taken from TEMPO2 observatories.dat file */
70REAL8 scopelocations[NUMSCOPES][3] = { { 882589.65, -4924872.32, 3943729.348 }, /* GBT */
71 { -4554231.5, 2816759.1, -3454036.3 }, /* Parkes */
72 { 3822626.04, -154105.65, 5086486.04 }, /* JBO */
73 { 2390490.0, -5564764.0, 1994727.0 }, /* Arecibo Telescope */
74 { 4033949.5, 486989.4, 4900430.8 }, /* Effelsberg */
75 { 4324165.81, 165927.11, 4670132.83}, /* Nancay */
76 { -3950077.96, 2522377.31, -4311667.52 }, /* Hobart */
77 { 5085442.780, 2668263.483, -2768697.034 }, /* Hartebeesthoek */
78 { -1601192.0, -5041981.4, 3554871.4 }, /* Very Large Array */
79 { 3828445.659, 445223.600, 5064921.5677 }
80}; /* Westerbork */
81#define USAGE \
82"Usage: %s [options]\n\n"\
83" --help (-h) display this message\n"\
84" --mjd (-m) a MJD time in TDB at the solar system barycenter\n"\
85" --gps (-g) a GPS equivalent time in TDB at the solar system barycenter\n"\
86" --ra (-r) the source right ascension (e.g. 15:21:34.76)\n"\
87" --dec (-d) the source declination (e.g. -09:53:12.36)\n"\
88" --telescope (-t) a detector acronym:\n\
89 GW detectors:\n\
90 H1/H2 - LIGO Hanford,\n\
91 L1 - LIGO Livingston,\n\
92 V1 - Virgo,\n\
93 G1 - GEO600,\n\
94 T1 - TAMA300,\n\
95 Radio Telescopes:\n\
96 GBT - the Robert C. Byrd Green Bank Telescope,\n\
97 PKS - the Parkes Telescope,\n\
98 JBO - the Lovell Telescope at Jodrell Bank,\n\
99 AO - the Arecibo Telescope,\n\
100 EFF - the Effelsberg 100m Radio Telescope,\n\
101 NRT - the Nancay Decimetre Radio Telescope,\n\
102 HOB - the Mount Pleasant Radio Observatory, Hobart,\n\
103 HART - the Hartebeesthoek Radio Astronomy Observatory,\n\
104 VLA - the Very Large Array,\n\
105 WSRT - the Westerbork Synthesis Radio Telescope.\n"\
106"\n"
107
108int main( int argc, char *argv[] )
109{
110 double mjdtime = 0.;
111 char *det = NULL, *ra = NULL, *dec = NULL;
112 LIGOTimeGPS gpsin;
113 LIGOTimeGPS gpsout;
114 double gpstime = 0.;
115 char earth[1024], sun[1024];
119
120 struct LALoption long_options[] = {
121 { "help", no_argument, 0, 'h' },
122 { "telescope", required_argument, 0, 't' },
123 { "ra", required_argument, 0, 'r' },
124 { "dec", required_argument, 0, 'd' },
125 { "mjd", required_argument, 0, 'm' },
126 { "gps", required_argument, 0, 'g' },
127 { 0, 0, 0, 0 }
128 };
129
130 CHAR args[] = "ht:r:d:m:";
131 CHAR *program = argv[0];
132
133 /* get input arguments */
134 while ( 1 ) {
135 int option_index = 0;
136 int c;
137
138 c = LALgetopt_long( argc, argv, args, long_options, &option_index );
139 if ( c == -1 ) { /* end of options */
140 break;
141 }
142
143 switch ( c ) {
144 case 0: /* if option set a flag, nothing else to do */
145 if ( long_options[option_index].flag ) {
146 break;
147 } else {
148 fprintf( stderr, "Error parsing option %s with argument %s\n", long_options[option_index].name, LALoptarg );
149 }
150 break;
151 case 'h': /* help message */
152 fprintf( stderr, USAGE, program );
153 exit( 0 );
154 case 't': /* the detector */
156 break;
157 case 'r': /* the right ascension */
159 break;
160 case 'd': /* the declination */
162 break;
163 case 'm': /* the mjd time */
164 mjdtime = atof( LALoptarg );
165 break;
166 case 'g': /* the gps time */
167 gpstime = atof( LALoptarg );
168 break;
169 case '?':
170 fprintf( stderr, "Unknown error while parsing options\n" );
171 exit( 0 );
172 break;
173 default:
174 fprintf( stderr, "Unknown error while parsing options\n" );
175 exit( 0 );
176 break;
177 }
178 }
179
180 if ( mjdtime <= 0. && gpstime <= 0. ) {
181 fprintf( stderr, "Error... input MJD or GPS time is not sensible!\n" );
182 exit( 1 );
183 }
184
185 if ( mjdtime > 0. && gpstime > 0. ) {
186 fprintf( stderr, "Error... required either an input MJD to or an input GPS time!\n" );
187 exit( 1 );
188 }
189
190 if ( ra == NULL ) {
191 fprintf( stderr, "Error... no right ascension given!\n" );
192 exit( 1 );
193 }
194
195 if ( dec == NULL ) {
196 fprintf( stderr, "Error... no declination given!\n" );
197 exit( 1 );
198 }
199
200 if ( det == NULL ) {
201 fprintf( stderr, "Error... no telescope has been given!\n" );
202 exit( 1 );
203 }
204
205 /* set detector/telescope */
206 if ( !strcmp( det, "GBT" ) ) {
207 sn = GBT;
208 } else if ( !strcmp( det, "PKS" ) ) {
209 sn = PKS;
210 } else if ( !strcmp( det, "JBO" ) ) {
211 sn = JBO;
212 } else if ( !strcmp( det, "AO" ) ) {
213 sn = AO;
214 } else if ( !strcmp( det, "EFF" ) ) {
215 sn = EFF;
216 } else if ( !strcmp( det, "NRT" ) ) {
217 sn = NRT;
218 } else if ( !strcmp( det, "HOB" ) ) {
219 sn = HOB;
220 } else if ( !strcmp( det, "HART" ) ) {
221 sn = HART;
222 } else if ( !strcmp( det, "VLA" ) ) {
223 sn = VLA;
224 } else if ( !strcmp( det, "WSRT" ) ) {
225 sn = WSRT;
226 }
227
228 if ( sn != NUMSCOPES ) {
229 LALDetector *site = NULL;
230 site = ( LALDetector * )XLALMalloc( sizeof( LALDetector ) );
231 //memcpy(site->location, scopelocations[sn], 3*sizeof(REAL8));
232 site->location[0] = scopelocations[sn][0];
233 site->location[1] = scopelocations[sn][1];
234 site->location[2] = scopelocations[sn][2];
235 params.site = site;
236 } else {
237 params.site = XLALGetSiteInfo( det ); /* try a GW detector */
238 }
239
240 XLAL_CHECK_MAIN( XLALTranslateDMStoRAD( &params.pulsar.position.latitude, dec ) == XLAL_SUCCESS, XLAL_EFUNC );
241 XLAL_CHECK_MAIN( XLALTranslateHMStoRAD( &params.pulsar.position.longitude, ra ) == XLAL_SUCCESS, XLAL_EFUNC );
242 params.pulsar.position.system = COORDINATESYSTEM_EQUATORIAL;
243
244 /* get the Earth and Sun ephemeris files - note yo may have to change this for different systems */
245 char *lalpulsar_datadir = getenv( "LALPULSAR_DATADIR" );
246 if ( lalpulsar_datadir != NULL ) {
247 sprintf( earth, "%s/earth00-40-DE405.dat.gz", lalpulsar_datadir );
248 sprintf( sun, "%s/sun00-40-DE405.dat.gz", lalpulsar_datadir );
249
250 /* double check that the files exist */
251 if ( fopen( sun, "r" ) == NULL || fopen( earth, "r" ) == NULL ) {
252 fprintf( stderr, "Error... ephemeris files not, or incorrectly, defined!\n" );
253 exit( 1 );
254 }
255 } else {
256 /* let LALPulsar find the ephemeris files */
257 sprintf( earth, "earth00-40-DE405.dat.gz" );
258 sprintf( sun, "sun00-40-DE405.dat.gz" );
259 }
260
261 /* set up ephemeris files */
262 edat = XLALInitBarycenter( earth, sun );
263 params.ephemerides = edat;
264
265 /* convert MJD time to GPS format (remaining at the SSB) */
266 if ( mjdtime > 0. ) {
267 gpstime = XLALTTMJDtoGPS( mjdtime );
268 }
269
270 int ephemstart = 630720013; /* GPS time of Jan 1, 2000, 00:00:00 UTC */
271 int ephemend = 1893024018; /* GPS time of Jan 1, 2040, 00:00:00 UTC */
272
273 if ( gpstime < ephemstart || gpstime > ephemend ) {
274 fprintf( stderr, "Time (GPS %.9lf) is outside the ephemeris file ranges!\n", gpstime );
275 exit( 1 );
276 }
277
278 /* put into LIGOTimeGPS format */
279 XLALGPSSetREAL8( &gpsin, gpstime );
280
281 /* convert time at SSB to GPS time at detector */
282 if ( XLALConvertSSB2GPS( &gpsout, gpsin, &params ) != XLAL_SUCCESS ) {
283 fprintf( stderr, "Problem converting time!\n" );
284 exit( 1 );
285 }
286
287 //fprintf(stdout, "%.9lf\n", XLALGPSGetREAL8( &gpsout ) );
288 fprintf( stdout, "%d.%09d\n", gpsout.gpsSeconds, gpsout.gpsNanoSeconds );
289
290 return 0;
291}
const char * program
#define c
int LALgetopt_long(int argc, char *const *argv, const char *options, const struct LALoption *long_options, int *opt_index)
char * LALoptarg
#define no_argument
#define required_argument
REAL8 XLALTTMJDtoGPS(REAL8 MJD)
This function converts a MJD format time corrected to Terrestrial Time (TT) into an equivalent GPS ti...
const char * name
Definition: SearchTiming.c:93
#define fprintf
const double sn
int XLALConvertSSB2GPS(LIGOTimeGPS *GPSout, LIGOTimeGPS SSBin, const PulsarSignalParams *params)
Convert barycentric frame SSB time into earth-frame GPS time.
EphemerisData * XLALInitBarycenter(const CHAR *earthEphemerisFile, const CHAR *sunEphemerisFile)
XLAL interface to reading ephemeris files 'earth' and 'sun', and return ephemeris-data in old backwar...
double REAL8
char CHAR
void * XLALMalloc(size_t n)
char char * XLALStringDuplicate(const char *s)
const LALDetector * XLALGetSiteInfo(const CHAR *name)
Find the site geometry-information 'LALDetector' for given a detector name (or prefix).
Definition: SFTnaming.c:218
COORDINATESYSTEM_EQUATORIAL
int XLALTranslateHMStoRAD(REAL8 *radians, const CHAR *hms)
int XLALTranslateDMStoRAD(REAL8 *radians, const CHAR *dms)
#define XLAL_CHECK_MAIN(assertion,...)
XLAL_SUCCESS
XLAL_EFUNC
LIGOTimeGPS * XLALGPSSetREAL8(LIGOTimeGPS *epoch, REAL8 t)
int gpstime
Definition: hwinject.c:365
Scopes
Definition: ssbtodetector.c:55
@ WSRT
Definition: ssbtodetector.c:65
@ NRT
Definition: ssbtodetector.c:61
@ HART
Definition: ssbtodetector.c:63
@ AO
Definition: ssbtodetector.c:59
@ PKS
Definition: ssbtodetector.c:57
@ HOB
Definition: ssbtodetector.c:62
@ NUMSCOPES
Definition: ssbtodetector.c:66
@ EFF
Definition: ssbtodetector.c:60
@ JBO
Definition: ssbtodetector.c:58
@ GBT
Definition: ssbtodetector.c:56
@ VLA
Definition: ssbtodetector.c:64
int main(int argc, char *argv[])
REAL8 scopelocations[NUMSCOPES][3]
Definition: ssbtodetector.c:70
#define USAGE
Definition: ssbtodetector.c:81
This structure contains all information about the center-of-mass positions of the Earth and Sun,...
int * flag
INT4 gpsNanoSeconds
Input parameters to GeneratePulsarSignal(), defining the source and the time-series.
enum @4 site