00001
00002
00003
00004
00005
00006 #include <stdlib.h>
00007 #include <stdio.h>
00008 #include <math.h>
00009 #include <string.h>
00010
00011 #include <lal/LALStdlib.h>
00012 #include <lal/LALBarycenter.h>
00013 #include <lal/LALInitBarycenter.h>
00014 #include <lal/SkyCoordinates.h>
00015 #include <lal/LALConstants.h>
00016
00017 #include <lal/BinaryPulsarTiming.h>
00018
00019 int main(int argc, char *argv[]){
00020 static LALStatus status;
00021
00022 char *pulsarAndPath=NULL;
00023 char *pulsarTOAFile=NULL;
00024
00025 FILE *fpin=NULL;
00026 FILE *fpout1=NULL, *fpout2=NULL, *fpout3=NULL;
00027
00028 char *telescope=NULL;
00029 char *psr=NULL;
00030 double radioFreq=0.0, rf[10000];
00031 double TOA[10000];
00032 double num1, num3;
00033 int num2;
00034 char *phaseStr=NULL;
00035 int i=0, j=0, k=0, length;
00036
00037 double PPTimeEll1[10000], PPTimeBT[10000], PPTimeDD[10000];
00038
00039
00040 const double D = 4.148808e3;
00041
00042
00043 BinaryPulsarParams params;
00044 BinaryPulsarInput input;
00045 BinaryPulsarOutput output;
00046
00047
00048 BarycenterInput baryinput;
00049 EarthState earth;
00050 EmissionTime emit;
00051 EphemerisData *edat=NULL;
00052 char earthFile[256], sunFile[256];
00053
00054 pulsarAndPath = argv[1];
00055 pulsarTOAFile = argv[2];
00056
00057 double MJD_tcorr[10000];
00058 double tcorr[10000];
00059 char date[15];
00060
00061 double f0, f1, f2, T;
00062
00063 fpin = fopen(pulsarTOAFile, "r");
00064
00065
00066 while(!feof(fpin)){
00067 fscanf(fpin, "%s%s%lf%lf%f%d%s%f", &telescope, &psr, &radioFreq, &TOA[i],
00068 &num1, &num2, &phaseStr, &num3);
00069 rf[i] = radioFreq;
00070
00071 i++;
00072 }
00073
00074 fclose(fpin);
00075
00076
00077 fpin = fopen("time_bonn.txt", "r");
00078
00079 while(!feof(fpin)){
00080 fscanf(fpin, "%lf%d%lf%s%s", &MJD_tcorr[j], &num2, &tcorr[j], &telescope,
00081 &date);
00082 j++;
00083 }
00084 length = j;
00085
00086 fclose(fpin);
00087
00088
00089 LALReadTEMPOParFile(&status, ¶ms, pulsarAndPath);
00090
00091
00092
00093 if(params.Tasc != 0.0){
00094 params.T0 = params.Tasc;
00095 params.w0 = 0.0;
00096 params.e = sqrt(params.eps1*params.eps1 + params.eps2*params.eps2);
00097 }
00098
00099
00100 fprintf(stderr, "f0 = %lf Hz, f1 = %e Hz/s, f2 = %e Hz/s^2.\n", params.f0,
00101 params.f1, params.f2);
00102 fprintf(stderr, "RA = %lf rads, DEC = %lf rads.\n", params.ra, params.dec);
00103 fprintf(stderr, "Binary model is %s.\n", params.model);
00104 fprintf(stderr, "asini = %lf light seconds, period = %lf days.\n", params.x,
00105 params.Pb);
00106 fprintf(stderr, "eps1 = %.8lf, eps2 = %.8lf.\n", params.eps1, params.eps2);
00107 fprintf(stderr, "Tasc = %lf.\n", params.Tasc);
00108
00109
00110
00111 baryinput.site.location[0] = 4033949.5/LAL_C_SI;
00112 baryinput.site.location[1] = 486989.4/LAL_C_SI;
00113 baryinput.site.location[2] = 4900430.8/LAL_C_SI;
00114
00115
00116 edat = (EphemerisData *)LALMalloc(sizeof(EphemerisData));
00117 (*edat).leap = 13;
00118 sprintf(earthFile,
00119 "/home/matthew/lscsoft/lal/packages/pulsar/test/earth00-04.dat");
00120 sprintf(sunFile,
00121 "/home/matthew/lscsoft/lal/packages/pulsar/test/sun00-04.dat");
00122 (*edat).ephiles.earthEphemeris = earthFile;
00123 (*edat).ephiles.sunEphemeris = sunFile;
00124 LALInitBarycenter(&status, edat);
00125
00126
00127
00128
00129
00130 fpout1 = fopen("deltaT.txt", "w");
00131
00132 for(j=0;j<i-1;j++){
00133 double t, DM = 9.023345;
00134 double deltaD_f2;
00135 REAL8 fe, uasc, Dt;
00136
00137 while(MJD_tcorr[k] < TOA[j])
00138 k++;
00139
00140
00141
00142 t = (TOA[j]-44244.0)*86400.0 + 13. + tcorr[k]*1.e-6;
00143
00144 deltaD_f2 = D * DM/(rf[j]*rf[j]);
00145 t -= deltaD_f2;
00146
00147
00148 baryinput.delta = params.dec + params.pmdec*(t-params.pepoch);
00149 baryinput.alpha = params.ra + params.pmra*(t-params.pepoch)/cos(baryinput.delta);
00150 baryinput.dInv = 0.0;
00151
00152 baryinput.tgps.gpsSeconds = (INT4)floor(t);
00153 baryinput.tgps.gpsNanoSeconds = (INT4)(fmod(t,1.0)*1.e9);
00154
00155
00156
00157
00158 LALBarycenterEarth(&status, &earth, &baryinput.tgps, edat);
00159 LALBarycenter(&status, &emit, &baryinput, &earth);
00160
00161
00162 input.tb = t + (double)emit.deltaT;
00163
00164 params.model = "ELL1";
00165 LALBinaryPulsarDeltaT(&status, &output, &input, ¶ms);
00166
00167 PPTimeEll1[j] = t + ((double)emit.deltaT + output.deltaT);
00168
00169 params.model = "BT";
00170 LALBinaryPulsarDeltaT(&status, &output, &input, ¶ms);
00171
00172 PPTimeBT[j] = t + ((double)emit.deltaT + output.deltaT);
00173
00174 params.model = "DD";
00175 LALBinaryPulsarDeltaT(&status, &output, &input, ¶ms);
00176
00177 PPTimeDD[j] = t + ((double)emit.deltaT + output.deltaT);
00178
00179 fprintf(fpout1, "%.9f\t%lf\t%lf\n", PPTimeEll1[j], output.deltaT,
00180 emit.deltaT);
00181 }
00182
00183 fclose(fpout1);
00184
00185 fpout1 = fopen("binaryPhaseEll1.txt", "w");
00186 fpout2 = fopen("binaryPhaseBT.txt", "w");
00187 fpout3 = fopen("binaryPhaseDD.txt", "w");
00188
00189
00190 T = PPTimeEll1[0] - params.pepoch;
00191 f0 = params.f0 + params.f1*T + 0.5*params.f2*T*T;
00192 f1 = params.f1 + params.f2*T;
00193 f2 = params.f2;
00194
00195
00196 for(j=1;j<i-1;j++){
00197 double phase1, phase2, phase3;
00198 double tt0Ell1, tt0BT, tt0DD;
00199
00200 tt0Ell1 = PPTimeEll1[j] - PPTimeEll1[0];
00201 tt0BT = PPTimeBT[j] - PPTimeBT[0];
00202 tt0DD = PPTimeDD[j] - PPTimeDD[0];
00203
00204
00205
00206 phase1 = f0*tt0Ell1 + 0.5*f1*tt0Ell1*tt0Ell1 +
00207 f2*tt0Ell1*tt0Ell1*tt0Ell1/6.0;
00208 phase1 = fmod(phase1+0.5, 1.0);
00209
00210 phase2 = f0*tt0BT + 0.5*f1*tt0BT*tt0BT + f2*tt0BT*tt0BT*tt0BT/6.0;
00211 phase2 = fmod(phase2+0.5, 1.0);
00212
00213 phase3 = f0*tt0DD + 0.5*f1*tt0DD*tt0DD + f2*tt0DD*tt0DD*tt0DD/6.0;
00214 phase3 = fmod(phase3+0.5, 1.0);
00215
00216 fprintf(fpout1, "%.9f\t%f\n", tt0Ell1, phase1);
00217 fprintf(fpout2, "%.9f\t%f\n", tt0BT, phase2);
00218 fprintf(fpout3, "%.9f\t%f\n", tt0DD, phase3);
00219 }
00220
00221 fclose(fpout1);
00222 fclose(fpout2);
00223 fclose(fpout3);
00224
00225 return 0;
00226 }