14#include <lal/LALStdlib.h>
15#include <lal/LALgetopt.h>
16#include <lal/AVFactories.h>
17#include <lal/LALBarycenter.h>
18#include <lal/LALInitBarycenter.h>
19#include <lal/LALConstants.h>
21#include <lal/LALString.h>
23#include <lal/ReadPulsarParFile.h>
24#include <lal/BinaryPulsarTiming.h>
27#define MAX_PHASE_ERR_DEGS 1.0
30"Usage: %s [options]\n\n"\
31" --help (-h) display this message\n"\
32" --verbose (-v) display all error messages\n"\
33" --par-file (-p) TEMPO2 parameter (.par) file\n"\
34" --tim-file (-t) TEMPO2 TOA (.tim) file\n"\
35" --ephem (-e) Ephemeris type (DE200, DE405 [default], or DE421)\n"\
36" --clock (-c) Clock correction file (default is none)\n"\
37" --simulated (-s) Set if the TOA file is from simulated data\n\
38 e.g. created with the TEMPO2 'fake' plugin:\n\
39 tempo2 -gr fake -f pulsar.par -ndobs 1 -nobsd 5\n\
40 -start 54832 -end 55562 -ha 8 -randha n -rms 0\n"\
45typedef struct tagInputParams {
56int main(
int argc,
char *argv[] )
62 double radioFreq = 0.0, rf[10000];
66 int i = 0,
j = 0,
k = 0,
n = 0, exceedPhaseErr = 0;
69 const double D = 2.41e-4;
85 double MJD_tcorr[10000];
102 fprintf( stderr,
"*******************************************************\n" );
103 fprintf( stderr,
"** We are assuming that the TOAs where produced with **\n" );
104 fprintf( stderr,
"** TEMPO2 and are sited at the Parkes telescope. **\n" );
105 fprintf( stderr,
"*******************************************************\n" );
107 if ( ( fpin = fopen(
par.timfile,
"r" ) ) == NULL ) {
108 fprintf( stderr,
"Error... can't open TOA file!\n" );
114 while ( !feof( fpin ) ) {
115 offset = ftell( fpin );
119 if (
fscanf( fpin,
"%s", firstchar ) != 1 ) {
122 if ( !strcmp( firstchar,
"FORMAT" ) || !strcmp( firstchar,
"MODE" ) ||
123 firstchar[0] ==
'#' || firstchar[0] ==
'C' ) {
124 if (
fscanf( fpin,
"%*[^\n]" ) == EOF ) {
129 fseek( fpin, offset, SEEK_SET );
132 if (
par.simulated ) {
133 fscanf( fpin,
"%s%lf%lf%lf%d", filestr, &radioFreq, &TOA[
i], &num1, &telescope );
135 char randstr1[256], randstr2[256], randstr3[256];
138 fscanf( fpin,
"%s%lf%lf%lf%d%s%s%s%d", filestr, &radioFreq, &TOA[
i], &num1, &telescope, randstr1, randstr2, randstr3, &randnum );
149 fprintf( stderr,
"I've read in the TOAs\n" );
153 if (
par.clock != NULL ) {
154 if ( ( fpin = fopen(
par.clock,
"r" ) ) == NULL ) {
155 fprintf( stderr,
"Error... can't open clock file for reading!\n" );
160 offset = ftell( fpin );
164 fscanf( fpin,
"%s", firstchar );
165 if ( firstchar[0] ==
'#' ) {
166 if (
fscanf( fpin,
"%*[^\n]" ) == EOF ) {
171 fseek( fpin, offset, SEEK_SET );
173 fscanf( fpin,
"%lf%lf", &MJD_tcorr[
j], &tcorr[
j] );
176 }
while ( !feof( fpin ) );
185 fprintf( stderr,
"I've read in the parameter file\n" );
189 if ( telescope != 7 ) {
190 fprintf( stderr,
"Error, TOA file not using the Parkes telescope!\n" );
200 const char *earthFile = NULL, *sunFile = NULL;
201 if (
par.ephem == NULL ) {
202 earthFile = TEST_PKG_DATA_DIR
"earth00-40-DE405.dat.gz";
203 sunFile = TEST_PKG_DATA_DIR
"sun00-40-DE405.dat.gz";
204 }
else if ( strcmp(
par.ephem,
"DE200" ) == 0 ) {
205 earthFile = TEST_PKG_DATA_DIR
"earth00-40-DE200.dat.gz";
206 sunFile = TEST_PKG_DATA_DIR
"sun00-40-DE200.dat.gz";
207 }
else if ( strcmp(
par.ephem,
"DE405" ) == 0 ) {
208 earthFile = TEST_PKG_DATA_DIR
"earth00-40-DE405.dat.gz";
209 sunFile = TEST_PKG_DATA_DIR
"sun00-40-DE405.dat.gz";
210 }
else if ( strcmp(
par.ephem,
"DE421" ) == 0 ) {
211 earthFile = TEST_PKG_DATA_DIR
"earth00-40-DE421.dat.gz";
212 sunFile = TEST_PKG_DATA_DIR
"sun00-40-DE421.dat.gz";
220 fprintf( stderr,
"I've set up the ephemeris files\n" );
224 fpout = fopen(
"pulsarPhase.txt",
"w" );
233 baryinput.
dInv = 0.0;
240 if ( units == NULL ) {
242 }
else if ( !strcmp( units,
"TDB" ) ) {
244 }
else if ( !strcmp( units,
"TCB" ) ) {
252 const char *tcFile = NULL;
254 tcFile = TEST_PKG_DATA_DIR
"te405_2000-2019.dat.gz";
256 tcFile = TEST_PKG_DATA_DIR
"tdb_2000-2019.dat.gz";
265 REAL8 *glep = NULL, *glph = NULL, *glf0 = NULL, *glf1 = NULL, *glf2 = NULL, *glf0d = NULL, *gltd = NULL;
274 glep[
j] = gleppars->
data[
j];
282 glph[
j] = glpars->
data[
j];
291 glf0[
j] = glpars->
data[
j];
300 glf1[
j] = glpars->
data[
j];
309 glf2[
j] = glpars->
data[
j];
318 glf0d[
j] = glpars->
data[
j];
327 gltd[
j] = glpars->
data[
j];
332 for (
j = 0;
j <
i;
j++ ) {
337 double phaseWave = 0., tWave = 0., phaseGlitch = 0.;
338 double taylorcoeff = 1.;
340 if (
par.clock != NULL ) {
341 while ( MJD_tcorr[
k] < TOA[
j] ) {
346 double grad = ( tcorr[
k] - tcorr[
k - 1] ) / ( MJD_tcorr[
k] - MJD_tcorr[
k - 1] );
348 t = ( TOA[
j] - 44244. ) * 86400. + ( tcorr[
k - 1] + grad * ( TOA[
j] - MJD_tcorr[
k - 1] ) );
350 t = ( TOA[
j] - 44244.0 ) * 86400.0;
369 rf[
j] = rf[
j] + rf[
j] * ( 1. - emit.
tDot );
371 deltaD_f2 = DM / (
D * rf[
j] * rf[
j] );
382 PPTime[
j] =
t + ( double )emit.
deltaT;
392 taylorcoeff /= (
REAL8 )(
n -
k );
393 f0update->
data[
k] += taylorcoeff * f0s->
data[
n] * Tupdate;
399 tt0 = PPTime[
j] - PPTime[0];
409 tWave += waveSin->
data[
k] * sin( om * (
REAL8 )(
k + 1. ) * dtWave ) + waveCos->
data[
k] * cos( om * (
REAL8 )(
k + 1. ) * dtWave );
411 phaseWave = f0s->
data[0] * tWave;
416 for (
k = 0;
k < (
INT4 )glnum;
k++ ) {
417 if ( PPTime[
j] >= glep[
k] ) {
418 REAL8 dtg = 0, expd = 1.;
419 dtg = PPTime[
j] - glep[
k];
420 if ( gltd[
k] != 0. ) {
421 expd = exp( -dtg / gltd[
k] );
425 phaseGlitch += glph[
k] + glf0[
k] * dtg + 0.5 * glf1[
k] * dtg * dtg + ( 1. / 6. ) * glf2[
k] * dtg * dtg * dtg + glf0d[
k] * gltd[
k] * ( 1. - expd );
430 phase = 0., taylorcoeff = 1.;
431 REAL8 tt0update = tt0;
433 taylorcoeff /= (
REAL8 )(
k + 1 );
434 phase += taylorcoeff * f0update->
data[
k] * tt0update;
438 phase = fmod(
phase + phaseWave + phaseGlitch + 0.5, 1.0 ) - 0.5;
458 if ( exceedPhaseErr ) {
502 char args[] =
"hp:t:e:c:sv";
514 int option_index = 0;
524 if ( long_options[option_index].
flag ) {
527 fprintf( stderr,
"Error parsing option %s with argument %s\n",
552 fprintf( stderr,
"unknown error while parsing options\n" );
555 fprintf( stderr,
"unknown error while parsing options\n" );
560 fprintf( stderr,
"Error... no .par file supplied!\n" );
565 fprintf( stderr,
"Error... no .tim file supplied!\n" );
void XLALBinaryPulsarDeltaTNew(BinaryPulsarOutput *output, BinaryPulsarInput *input, PulsarParameters *params)
function to calculate the binary system delay using new parameter structure
void LALCheckMemoryLeaks(void)
int LALgetopt_long(int argc, char *const *argv, const char *options, const struct LALoption *long_options, int *opt_index)
#define required_argument
int main(int argc, char *argv[])
#define MAX_PHASE_ERR_DEGS
void get_input_args(InputParams *pars, int argc, char *argv[])
const REAL8Vector * PulsarGetREAL8VectorParam(const PulsarParameters *pars, const CHAR *name)
Return a REAL8Vector parameter.
REAL8 PulsarGetREAL8ParamOrZero(const PulsarParameters *pars, const CHAR *name)
Return a REAL8 parameter if it exists, otherwise return zero.
int PulsarCheckParam(const PulsarParameters *pars, const CHAR *name)
Check for the existence of the parameter name in the PulsarParameters structure.
PulsarParameters * XLALReadTEMPOParFile(const CHAR *pulsarAndPath)
Read in the parameters from a TEMPO(2) parameter file into a PulsarParameters structure.
REAL8 PulsarGetREAL8Param(const PulsarParameters *pars, const CHAR *name)
Return a REAL8 parameter.
const CHAR * PulsarGetStringParam(const PulsarParameters *pars, const CHAR *name)
Return a string parameter.
void PulsarFreeParams(PulsarParameters *pars)
Function to free memory from pulsar parameters.
TimeCorrectionData * XLALInitTimeCorrections(const CHAR *timeCorrectionFile)
An XLAL interface for reading a time correction file containing a table of values for converting betw...
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 XLALDestroyTimeCorrectionData(TimeCorrectionData *tcd)
Destructor for TimeCorrectionData struct, NULL robust.
int XLALBarycenter(EmissionTime *emit, const BarycenterInput *baryinput, const EarthState *earth)
Transforms from detector arrival time in GPS (as specified in the LIGOTimeGPS structure) to pulse em...
void XLALDestroyEphemerisData(EphemerisData *edat)
Destructor for EphemerisData struct, NULL robust.
int XLALBarycenterEarthNew(EarthState *earth, const LIGOTimeGPS *tGPS, const EphemerisData *edat, const TimeCorrectionData *tdat, TimeCorrectionType ttype)
Computes the position and orientation of the Earth, at some arrival time, but unlike XLALBarycenterEa...
TimeCorrectionType
Enumerated type denoting the time system type to be produced in the solar system barycentring routine...
void * XLALCalloc(size_t m, size_t n)
char char * XLALStringDuplicate(const char *s)
REAL8Vector * XLALCreateREAL8Vector(UINT4 length)
void XLALDestroyREAL8Vector(REAL8Vector *vector)
int XLALGPSLeapSeconds(INT4 gpssec)
XLALErrorHandlerType * XLALSetErrorHandler(XLALErrorHandlerType *newHandler)
#define XLAL_ERROR_MAIN(...)
void XLALExitErrorHandler(const char *func, const char *file, int line, int errnum)
LIGOTimeGPS * XLALGPSSetREAL8(LIGOTimeGPS *epoch, REAL8 t)
REAL8 XLALGPSGetREAL8(const LIGOTimeGPS *epoch)
def phase(point, coeffs, params, ignoreintcheck=False)
structure containing the output parameters for the binary delay function
Basic output structure of LALBarycenterEarth.c.
Basic output structure produced by LALBarycenter.c.
REAL8 deltaT
(TDB) - (GPS)
LIGOTimeGPS te
pulse emission time (TDB); also sometimes called `‘arrival time (TDB) of same wavefront at SSB’'
REAL8 tDot
d(emission time in TDB)/d(arrival time in GPS)
This structure contains all information about the center-of-mass positions of the Earth and Sun,...
The PulsarParameters structure to contain a set of pulsar parameters.
This structure will contain a vector of time corrections used during conversion from TT to TDB/TCB/Te...