LALPulsar  6.1.0.1-fe68b98
create_time_correction_ephemeris.h
Go to the documentation of this file.
1 /*
2 * Copyright (C) 2012 Matt 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 /* Many of these functions are (with occasional modification) taken directly
21  * from the TEMPO2 software package http://www.atnf.csiro.au/research/pulsar/tempo2/
22  * written by George Hobbs and Russell Edwards */
23 
24 #include <stdio.h>
25 #include <stdlib.h>
26 #include <math.h>
27 #include <string.h>
28 #include <time.h>
29 
30 #include <lal/Date.h>
31 #include <lal/LALString.h>
32 #include <lal/LALgetopt.h>
33 #include <lal/LALVCSInfo.h>
34 #include <lal/LALPulsarVCSInfo.h>
35 
36 /* TEMPO style time delay file */
37 #define TT2TDB_FILE "/ephemeris/TDB.1950.2050"
38 /* TEMPO2 style time delay file */
39 #define IFTEPH_FILE "/ephemeris/TIMEEPH_short.te405"
40 
41 #define MAXFNAME 512
42 
43 #define MJDEPOCH 44244.0
44 #define DAYSTOSEC 86400.0
45 #define GPS2TT 51.184
46 
47 /* macros taken from TEMPO2's ifteph.h file */
48 /* constants determined by Irwin & Fukushima */
49 #define IFTE_TEPH0 -65.564518e-6
50 
51 //This is the value used by if99 : #define IFTE_KM1 1.55051979154e-8 */
52 // However we should use the IAU value of L_B that follows from
53 // their definition of L_G: L_B = 1.55051976772e-8, K=1/(1-L_B)
54 #define IFTE_KM1 1.55051979176e-8
55 #define IFTE_K (((long double)1.0) + ((long double)IFTE_KM1))
56 
57 #define USAGE \
58 "Usage: %s [options]\n\n"\
59 " --help display this message\n"\
60 " --verbose display all error messages\n"\
61 " --ephem-type TEMPO/TDB or TEMPO2/TCB/Teph\n"\
62 " --output-path path into which to output the ascii ephemeris (the\n\
63  file name will get constructed from the ephemeris type\n\
64  and the start and end years of the input times.)\n"\
65 " --start a start GPS time\n"\
66 " --end an end GPS time\n"\
67 " --interval an interval (in seconds) between entries\n"\
68 "\n"
69 
70 typedef enum {
72  TT2TCB
74 
75 typedef struct taginputParams_t {
76  char *ephemtype; /* type of ephemeris */
77  char ephemfile[MAXFNAME]; /* path and name of binary ephemeris file */
78  char *outputpath; /* path to output ephemeris file */
79 
80  double startT; /* a start GPS time */
81  double endT; /* an end GPS time */
82  double interval; /* number of seconds between output entries */
83 
86 
87 void get_input_args( inputParams_t *inputParams, int argc, char *argv[] );
88 
89 /*** FUNCTIONS TAKEN FROM TEMPO2 *****/
90 
91 /* Fortran-equivalent functions */
92 double fortran_mod( double a, double p );
93 int open_file( char fname[MAXFNAME] );
94 double read_double( void );
95 int read_int( void );
96 void close_file( void );
97 
98 double FB_deltaT( long double mjd_tt, char fname[MAXFNAME] );
99 
100 double IF_deltaT( long double mjd_tt );
101 
102 /* functions and structures for reading in Irwin and Fukushima ephemeris file */
103 
105  double pc[18], vc[18], twot;
106  int np, nv;
107 };
108 
109 typedef struct {
110  char title[256];
111  double startJD, endJD, stepJD;
112  int ephver;
113  double L_C;
115  int reclen;
116  int irec;
117  double buf[322];
118  FILE *f;
119  struct IFTE_interpolation_info iinfo;
120  int ipt[2][3];
121 } IFTEphemeris;
122 
124 
125 void IFTE_init( const char fname[MAXFNAME] );
126 void IFTE_close_file( void );
127 static void IFTEinterp( struct IFTE_interpolation_info *iinfo,
128  const double coef[], const double t[2], const int ncf,
129  const int ncm, const int na, const int ifl,
130  double posvel[] );
131 
132 void IFTE_get_Vals( double JDeph0, double JDeph1, int kind,
133  double *res );
134 void IFTE_get_DeltaT_DeltaTDot( double Teph0, double Teph1,
135  double *DeltaT, double *DeltaTDot );
136 double IFTE_DeltaT( double Teph0, double Teph1 );
137 
138 /* functions to perform endian swapping */
139 void IFTswap8( char *dword );
140 void IFTswapDouble( double *dbl );
141 void IFTswapInts( int *word, int n );
142 void IFTswapInt( int *word );
143 void IFTswap4( char *word );
144 void IFTswap8N( char *dwords, int n );
145 void IFTswapDoubles( double *dbl, int N );
void IFTE_init(const char fname[MAXFNAME])
double FB_deltaT(long double mjd_tt, char fname[MAXFNAME])
void IFTswap8N(char *dwords, int n)
double fortran_mod(double a, double p)
void get_input_args(inputParams_t *inputParams, int argc, char *argv[])
int open_file(char fname[MAXFNAME])
void IFTswapInts(int *word, int n)
double IFTE_DeltaT(double Teph0, double Teph1)
void close_file(void)
void IFTswapDoubles(double *dbl, int N)
double read_double(void)
static void IFTEinterp(struct IFTE_interpolation_info *iinfo, const double coef[], const double t[2], const int ncf, const int ncm, const int na, const int ifl, double posvel[])
void IFTswap4(char *word)
void IFTE_close_file(void)
void IFTE_get_Vals(double JDeph0, double JDeph1, int kind, double *res)
void IFTswap8(char *dword)
double IF_deltaT(long double mjd_tt)
void IFTswapInt(int *word)
void IFTswapDouble(double *dbl)
static IFTEphemeris ifte
void IFTE_get_DeltaT_DeltaTDot(double Teph0, double Teph1, double *DeltaT, double *DeltaTDot)
static const INT4 a