32 int main(
int argc,
char **argv )
39 long double mjdtt = 0.;
54 if ( beg.tm_yday != 0 && beg.tm_hour != 0 && beg.tm_min != 0 && beg.tm_sec != 0 ) {
57 if ( fin.tm_yday != 0 && fin.tm_hour != 0 && fin.tm_min != 0 && fin.tm_sec != 0 ) {
62 if ( !sprintf( outputfile,
"%s/te405_%d-%d.dat",
63 inputParams.
outputpath, beg.tm_year + 1900, fin.tm_year + 1900 ) ) {
64 fprintf( stderr,
"Error... problem creating output file name!\n" );
67 }
else if ( inputParams.
et ==
TT2TDB ) {
68 if ( !sprintf( outputfile,
"%s/tdb_%d-%d.dat",
69 inputParams.
outputpath, beg.tm_year + 1900, fin.tm_year + 1900 ) ) {
70 fprintf( stderr,
"Error... problem creating output file name!\n" );
76 if ( (
fp = fopen( outputfile,
"w" ) ) == NULL ) {
77 fprintf( stderr,
"Error... can't open output file: %s!\n", outputfile );
84 fprintf( stdout,
"Creating ephemeris file from %lf to %lf, with %.2lf second\
89 fprintf(
fp,
"# Build information for %s\n", argv[0] );
93 fprintf(
fp,
"#\n# Ephemeris creation command:-\n#\t" );
94 for (
INT4 k = 0;
k < argc;
k++ ) {
101 fprintf(
fp,
"#\n# Time correction ephemeris file %s from TEMPO2 \
102 (http://www.atnf.csiro.au/research/pulsar/tempo2/)\n", efile + 1 );
104 fprintf(
fp,
"#\n# This file consists of a header line containing:\n" );
105 fprintf(
fp,
"#\tGPS start time, GPS end time, interval between entries \
106 (secs), no. of entries\n" );
107 fprintf(
fp,
"# Each entry consists of:\n" );
109 fprintf(
fp,
"# with entries calculated at the Terrestrial Time in MJD via \
111 # TT(MJD) = 44244 + (GPS + 51.184)/86400\n" );
116 for (
i = 0;
i < ne;
i++ ) {
128 else if ( inputParams.
et ==
TT2TDB ) {
131 fprintf( stderr,
"Error... unknown ephemeris type!\n" );
159 char args[] =
"ht:o:s:i:e:";
165 fprintf( stderr,
"Error... no input parameters given! Try again!!!\n" );
172 inputParams->
startT = 883180814.;
173 inputParams->
endT = 1072569615.;
179 int option_index = 0;
189 if ( long_options[option_index].
flag ) {
192 fprintf( stderr,
"Error passing option %s with argument %s\n",
194 #if __GNUC__ >= 7 && !defined __INTEL_COMPILER
217 fprintf( stderr,
"Unknown error while parsing options\n" );
221 if ( ( tempo2path = getenv(
"TEMPO2" ) ) == NULL ) {
222 fprintf( stderr,
"Error... TEMPO2 environment variable not set!\n" );
227 if ( !strcmp( inputParams->
ephemtype,
"TEMPO" ) ||
228 !strcmp( inputParams->
ephemtype,
"TDB" ) ) {
233 fprintf( stdout,
"Using TEMPO-style TT to TDB conversion file: %s\n",
238 else if ( !strcmp( inputParams->
ephemtype,
"TEMPO2" ) ||
239 !strcmp( inputParams->
ephemtype,
"TCB" ) ) {
244 fprintf( stdout,
"Using TEMPO2-style TT to te405 conversion file: %s\n",
251 fprintf( stderr,
"Error... unrecognised ephemeris type %s given.\n",
264 static int tdbnrl = -1;
266 double jda, jdb, tdbd1, tdbd2,
t[2];
268 double dna, dt1,
temp,
pc[18],
tc, twot;
269 static double buf[16];
286 tdt = mjd_tt + 2400000.5;
287 if ( tdt - (
int )tdt >= 0.5 ) {
288 jda = (
int )tdt + 0.5;
289 jdb = tdt - (
int )tdt - 0.5;
291 jda = (
int )tdt - 0.5;
292 jdb = tdt - (
int )tdt + 0.5;
294 nr = (
int )( ( jda - tdbd1 ) / tdbdt ) + 2;
295 if ( nr < 1 || tdt > tdbd2 ) {
296 printf(
"ERROR [CLK4]: Date %.10f out of range of TDB-TDT \
297 table\n", (
double )tdt );
300 if ( nr != tdbnrl ) {
303 for (
j = 0;
j < nr - 1;
j++ )
304 for (
k = 0;
k < tdbncf;
k++ ) {
308 t[0] = ( ( jda - ( ( nr - 2 ) * tdbdt + tdbd1 ) ) + jdb ) / tdbdt;
319 dt1 = (
int )(
t[0] );
329 for (
k = np + 1;
k <= tdbncf;
k++ ) {
330 pc[
k - 1] = twot *
pc[
k - 2] -
pc[
k - 3];
335 for (
j = tdbncf;
j >= 1;
j-- ) {
336 ctatv = ctatv +
pc[
j - 1] * buf[
j - 1];
362 char asChar[
sizeof(
int )];
367 if ( intcnv.asChar[0] == 1 ) {
374 for (
i = 0; fname[
i];
i++ ) {
375 if ( fname[
i] ==
' ' ) {
380 if ( (
c_fileptr = fopen( fname,
"rb" ) ) == NULL ) {
381 fprintf( stderr,
"Error: Unable to open filename %s\n", fname );
397 char asChar[
sizeof(
int )];
402 for (
i =
sizeof(
int ) -1;
i >= 0;
i-- ) {
406 for (
i = 0;
i < (
int )
sizeof(
int );
i++ ) {
418 char asChar[
sizeof( double )];
423 for (
i =
sizeof(
double ) -1;
i >= 0;
i-- ) {
427 for (
i = 0;
i < (
int )
sizeof(
double );
i++ ) {
431 return dblcnv.asDouble;
438 ret =
a - (
int )(
a /
p ) *
p;
452 if ( (
f = fopen( fname,
"r" ) ) == NULL ) {
453 fprintf( stderr,
"Error... opening time ephemeris file '%s'\n",
459 rc = fread( buf, 1, 252,
f );
460 rc = fread( buf, 1, 12,
f );
464 rc = fread( &ncon, 1, 4,
f );
472 fprintf( stderr,
"Cannot understand format of time ephemeris file '%s'!\n",
492 rc = fread( &double_in, 8, 1,
f );
503 fprintf( stderr,
"Error... problem reading header from time ephemeris file \
520 if (
ifte.
f != NULL ) {
545 for (
i = 0;
i <
n;
i++ ) {
576 for (
i = 0;
i <
n;
i++ ) {
578 dwords[0] = dwords[7];
581 dwords[1] = dwords[6];
584 dwords[2] = dwords[5];
587 dwords[3] = dwords[4];
602 double whole0, whole1, frac0, frac1;
608 whole0 = floor( JDeph0 - 0.5 );
609 frac0 = JDeph0 - 0.5 - whole0;
610 whole1 = floor( JDeph1 );
611 frac1 = JDeph1 - whole1;
612 whole0 += whole1 + 0.5;
614 whole1 = floor( frac0 );
615 frac1 = frac0 - whole1;
622 fprintf( stderr,
"Error: Requested JD=%lf is less than start JD=%lf\n",
639 fprintf( stderr,
"Error reading time ephemeris" );
643 if ( (
int )nread < ncoeff ) {
644 fprintf( stderr,
"Error reading time ephemeris: Only read %zd coefficients,\
645 wanted %d!\n", nread, ncoeff );
664 double *DeltaT,
double *DeltaTDot )
674 double DeltaT, DeltaTDot;
731 const double coef[],
const double t[2],
const int ncf,
732 const int ncm,
const int na,
const int ifl,
double posvel[] )
734 double dna, dt1,
temp,
tc, vfac, temp1;
748 tc = 2.0 * ( modf(
temp, &temp1 ) + dt1 ) - 1.0;
755 if (
tc != iinfo->
pc[1] ) {
765 if ( iinfo->
np < ncf ) {
766 pc_ptr = iinfo->
pc + iinfo->
np;
768 for (
i = ncf - iinfo->
np;
i;
i--, pc_ptr++ ) {
769 *pc_ptr = iinfo->
twot * pc_ptr[-1] - pc_ptr[-2];
775 for (
i = 0;
i < ncm; ++
i ) {
776 const double *coeff_ptr = coef + ncf * (
i +
l * ncm + 1 );
777 const double *pc_ptr2 = iinfo->
pc + ncf;
780 for (
j = ncf;
j;
j-- ) {
781 posvel[
i] += ( *--pc_ptr2 ) * ( *--coeff_ptr );
792 vfac = ( dna + dna ) /
t[1];
794 if ( iinfo->
nv < ncf ) {
795 double *vc_ptr = iinfo->
vc + iinfo->
nv;
796 const double *pc_ptr2 = iinfo->
pc + iinfo->
nv - 1;
798 for (
i = ncf - iinfo->
nv;
i;
i--, vc_ptr++, pc_ptr2++ ) {
799 *vc_ptr = iinfo->
twot * vc_ptr[-1] + *pc_ptr2 + *pc_ptr2 - vc_ptr[-2];
805 for (
i = 0;
i < ncm; ++
i ) {
807 const double *coeff_ptr = coef + ncf * (
i +
l * ncm + 1 );
808 const double *vc_ptr = iinfo->
vc + ncf;
810 for (
j = ncf;
j;
j-- ) {
811 tval += ( *--vc_ptr ) * ( *--coeff_ptr );
813 posvel[
i + ncm] = tval * vfac;
const LALVCSInfo lalPulsarVCSInfo
VCS and build information for LALPulsar.
int LALgetopt_long(int argc, char *const *argv, const char *options, const struct LALoption *long_options, int *opt_index)
#define required_argument
ParConversion pc[NUM_PARS]
Initialise conversion structure with most allowed TEMPO2 parameter names and conversion functions (co...
void IFTE_init(const char fname[MAXFNAME])
double FB_deltaT(long double mjd_tt, char fname[MAXFNAME])
int main(int argc, char **argv)
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 IFTswapDoubles(double *dbl, int N)
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)
void IFTE_get_DeltaT_DeltaTDot(double Teph0, double Teph1, double *DeltaT, double *DeltaTDot)
char char * XLALStringDuplicate(const char *s)
struct tm * XLALGPSToUTC(struct tm *utc, INT4 gpssec)
p
RUN ANALYSIS SCRIPT ###.
struct IFTE_interpolation_info iinfo
const char *const vcsDate
const char *const vcsAuthor