Esempio n. 1
0
void extra_delays(pulsar *psr,int npsr)
{  
  const char *CVS_verNum = "$Revision: 1.16 $";
  if (displayCVSversion == 1) CVSdisplayVersion("global.C","extra_delays()",CVS_verNum);

  calculate_bclt(psr,npsr);/* 3. Calculate bclt  */
  /*  shapiro_delay(psr,npsr); */ /* 1. Calculate the Shapiro delay */
  /* dm_delays(psr,npsr); */    /* 2. Extra dispersion measure delays */  
}
Esempio n. 2
0
// Only recalculate that which is likely
// to change if psr position has been altered.
void updateBatsAll(pulsar *psr, int npsr)
{
  const char *CVS_verNum = "$Revision: 1.16 $";
  if (displayCVSversion == 1) CVSdisplayVersion("global.C","updateBatsAll()",CVS_verNum);

  vectorPulsar(psr, npsr);
  calculate_bclt(psr, npsr);
  formBats(psr, npsr);
  secularMotion(psr,npsr); 
}
Esempio n. 3
0
void preProcessSimple (pulsar *psr)
{
  const char *CVS_verNum = "$Revision: 1.9 $";

  if (displayCVSversion == 1) CVSdisplayVersion("preProcessSimple.C","preProcessSimple()",CVS_verNum);

  preProcessSimple1 (psr, 0, -1);
  preProcessSimple2 (psr, 0, 0, 0, 0);
  preProcessSimple3 (psr);
}
Esempio n. 4
0
void preProcessSimple (pulsar *psr)
{
    const char *CVS_verNum = "$Id: a8e7bdafd71a550d7a893aad3c9cc43b009ccf36 $";

    if (displayCVSversion == 1) CVSdisplayVersion("preProcessSimple.C","preProcessSimple()",CVS_verNum);

    preProcessSimple1 (psr, 0, -1);
    preProcessSimple2 (psr, 0, 0, 0, 0);
    preProcessSimple3 (psr);
}
Esempio n. 5
0
void ephemeris_routines(pulsar *psr,int npsr)
{ 
  const char *CVS_verNum = "$Revision: 1.16 $";
  if (displayCVSversion == 1) CVSdisplayVersion("global.C","ephemeris_routines()",CVS_verNum);

  vectorPulsar(psr,npsr);   /* 1. Form a vector pointing at the pulsar */
  readEphemeris(psr,npsr,0);/* 2. Read the ephemeris */
  get_obsCoord(psr,npsr);   /* 3. Get Coordinate of observatory relative to Earth's centre */
  tt2tb(psr,npsr);          /* Observatory/time-dependent part of TT-TB */
  readEphemeris(psr,npsr,0);  /* Re-evaluate ephemeris with correct TB */ 
}
Esempio n. 6
0
/* ******************************************** */
void tai2ut1(pulsar *psr,int npsr)
{
    int p,i;
    const char *CVS_verNum = "$Revision: 1.6 $";

    if (displayCVSversion == 1) CVSdisplayVersion("tai2ut1.C","tai2ut1()",CVS_verNum);

    for (p=0; p<npsr; p++)
    {
        if (psr[p].t2cMethod==T2C_TEMPO)
            for (i=0; i<psr[p].nobs; i++)
            {
                if (psr[p].obsn[i].clockCorr!=0)
                {
                    /* Original TEMPO calculation */
                    /*	      psr[p].obsn[i].correctionUT1 = ut1red((double)(psr[p].obsn[i].sat+
                    				   psr[p].obsn[i].correctionUTC/SECDAY+
                    				   psr[p].obsn[i].correctionUTC_TAI/SECDAY),
                    				   psr[p].obsn[i].a1utcf);*/

                    /* redwards note, the frame of the argument to the IERS does
                    not seem to be specified. We will simply use the whatever
                     version of TT was specified, which could be out from UTC by up
                     to a couple of minutes within our lifetimes. TAI lays between
                     the two.
                     The maximum rate of change of the EOP are as follows:
                                       x, y   : 5 mas/day
                                       UT1-UTC:  4 ms/day  (excluding leap seconds!!)
                               For x & y, 1 ns is 9 mas, so no problem.
                     For UT1-UTC, 1 ns is 330 microsec, so we must have the
                     argument right to within 7000 seconds ... no problem! */

                    /* Where does the 0.0343817 come from?? See end of ut1red ... */
                    /* redwards -- it is due to tempo's internal use of A.1,
                    which differs from TAI by this many seconds */

                    /* redwards, changed ut1red to return UT1-TAI. So now we have
                    UT1-TOA = UT1-TAI + (TAI-TOA) */


                    psr[p].obsn[i].correctionUT1 =
                        ut1red((double)(psr[p].obsn[i].sat),
                               psr[p].noWarnings)
                        + getCorrection(psr[p].obsn+i,
                                        psr[p].clockFromOverride,
                                        "TAI", psr[p].noWarnings);

                }
                else
                    psr[p].obsn[i].correctionUT1 = 0.0;
            }
    }
}
Esempio n. 7
0
void formBats(pulsar *psr,int npsr)
{
  int i,p;
  //  double etatdm;
  double shapiroDelay;
  const char *CVS_verNum = "$Revision: 1.8 $";

  if (displayCVSversion == 1) CVSdisplayVersion("formBats.C","formBats()",CVS_verNum);

  logdbg("In formBats");

  for (p=0;p<npsr;p++)
    {
      for (i=0;i<psr[p].nobs;i++)
	{
	  //	  if (psr[p].obsn[i].clockCorr==0 || psr[p].obsn[i].delayCorr==0)
	  if (psr[p].obsn[i].delayCorr==0)
	    psr[p].obsn[i].bat = psr[p].obsn[i].sat;
	  else
	    {
	      /* ORIGINAL TEMPO calculation */
	      if (psr[p].calcShapiro==-1)
		shapiroDelay = 0.0;
	      else
		shapiroDelay = psr[p].obsn[i].shapiroDelaySun + psr[p].planetShapiro*
		  (psr[p].obsn[i].shapiroDelayVenus+
		   psr[p].obsn[i].shapiroDelayJupiter+psr[p].obsn[i].shapiroDelaySaturn
		   +psr[p].obsn[i].shapiroDelayUranus + psr[p].obsn[i].shapiroDelayNeptune);
	     	   //if(i==0){printf("Forming bat with sat = %.15g TT = %.15g TT_TB = %.15g trop = %.15g roemer = %.15g shap = %.15g tdis1 = %.15g tdis2 = %.15g\n",(double)psr[p].obsn[i].sat,(double)getCorrectionTT(psr[p].obsn+i),(double)psr[p].obsn[i].correctionTT_TB,(double)psr[p].obsn[i].troposphericDelay,(double)psr[p].obsn[i].roemer,(double)shapiroDelay,(double)psr[p].obsn[i].tdis1,(double)psr[p].obsn[i].tdis2);}
		     

		long double batcorr=getCorrectionTT(psr[p].obsn+i)/SECDAY
                + (psr[p].obsn[i].correctionTT_TB
                   -psr[p].obsn[i].troposphericDelay
                   +psr[p].obsn[i].roemer -
                   shapiroDelay - psr[p].obsn[i].tdis1 - psr[p].obsn[i].tdis2)/SECDAY;

                psr[p].obsn[i].batCorr = batcorr;

	      psr[p].obsn[i].bat = psr[p].obsn[i].sat + 
		getCorrectionTT(psr[p].obsn+i)/SECDAY 
		+ (psr[p].obsn[i].correctionTT_TB
		   -psr[p].obsn[i].troposphericDelay
		   +psr[p].obsn[i].roemer - 
		   shapiroDelay - psr[p].obsn[i].tdis1 - psr[p].obsn[i].tdis2)/SECDAY;

	      /* Now calculate binary barycentric arrival time (bbat) */
	      psr[p].obsn[i].bbat = psr[p].obsn[i].bat - (psr[p].obsn[i].shklovskii)/SECDAY;
	    }
	}
    }
  logdbg("Leaving formBats");
}
Esempio n. 8
0
void 
get_obsCoord_IAU2000B(double observatory_trs[3],
		      double zenith_trs[3],
		      longdouble tt_mjd, longdouble utc_mjd,
		      double observatory_crs[3],
		      double zenith_crs[3],
		      double observatory_velocity_crs[3])
{
  double trs[2][3], crs[2][3], north[3], pole_itrs[3], omega_itrs[3];
  double t2c[3][3], polarmotion[3][3];
  double dut1, dut1dot, eradot, xp, yp; 
  longdouble tt_jd = tt_mjd + (longdouble)2400000.5, ut1_jd;
  double tt_jd1 = (int)tt_jd, tt_jd2 = tt_jd-tt_jd1;
  double ut1_jd1, ut1_jd2;
  double sprime=0.0;
  double one_on_c = 1.0/SPEED_LIGHT;
  const char *CVS_verNum = "$Revision: 1.8 $";

  if (displayCVSversion == 1) CVSdisplayVersion("get_obsCoord.C","get_obsCoord_IAU2000B()",CVS_verNum);

  // Get Earth orientation parameters
  get_EOP((double)utc_mjd, &xp, &yp, &dut1, &dut1dot, 1);
  ut1_jd = utc_mjd + dut1/86400.0 + (longdouble)2400000.5;
  ut1_jd1 = (int)ut1_jd;
  ut1_jd2 = ut1_jd-ut1_jd1;

  // Stick the site position vector in
  iau_cp_(observatory_trs, trs[0]);

  // Work out site velocity in CRS... 
  // first we need to know the angular velocity vector
  iau_pom00_(&xp, &yp, &sprime, polarmotion[0]); // polar motion matrix
  north[0] = north[1] = 0.0; north[2] = 1.0; // Vector to +ve pole
  iau_rxp_(polarmotion[0], north, pole_itrs); // Spin pole in ITRS 
  eradot = 2.0*M_PI*1.00273781191135448*(1.0+dut1dot)/86400.0;
  iau_sxp_(&eradot, pole_itrs, omega_itrs); // Angular velocity in ITRS (rad/s)
  iau_pxp_(omega_itrs, trs[0], trs[1]); // Tangential velocity (m/s)

  // Get the Celestial->Terrestrial matrix
  iau_c2t00b_(&tt_jd1, &tt_jd2, &ut1_jd1, &ut1_jd2, &xp, &yp, t2c[0]);

  // Multiply the itrs position/velocity vector by its transpose (=inverse)
  // to transform trs->crs
  iau_trxpv_(t2c[0], trs[0], crs[0]);
  iau_trxp_(t2c[0], zenith_trs, zenith_crs);

  // Convert to light seconds / dimensionless units and copy to output
  iau_sxp_(&one_on_c, crs[0], observatory_crs);
  iau_sxp_(&one_on_c, crs[1], observatory_velocity_crs);
}
Esempio n. 9
0
void formBatsAll(pulsar *psr,int npsr)
{
  const char *CVS_verNum = "$Revision: 1.16 $";
  if (displayCVSversion == 1) CVSdisplayVersion("global.C","formBatsAll()",CVS_verNum);

  if (debugFlag==1) printf("Calling clock corrections\n");
  clock_corrections(psr,npsr);          /* Clock corrections  ... */  
  if (debugFlag==1) printf("Reading ephemeris routines\n");
  ephemeris_routines(psr,npsr);         /* Ephemeris routines ... */
  if (debugFlag==1) printf("Reading extra delays\n");
  extra_delays(psr,npsr);               /* Other time delays  ... */
  formBats(psr,npsr);                   /* Form Barycentric arrival times */
  secularMotion(psr,npsr); 
}
Esempio n. 10
0
void initialise(pulsar *psr,int noWarnings)
{
  int p;
  const char *CVS_verNum = "$Revision: 1.19 $";

  if (displayCVSversion == 1) CVSdisplayVersion("initialise.C","initialise()",CVS_verNum);

  // allocate space for covar arrays
  int fullSetup = 1;

  for (p=0;p<MAX_PSR;p++)
    //    if (psr[p].obsn == NULL)
      initialiseOne (psr+p, noWarnings, fullSetup);
}
Esempio n. 11
0
void clock_corrections(pulsar *psr,int npsr)
{  
  const char *CVS_verNum = "$Revision: 1.16 $";
  if (displayCVSversion == 1) CVSdisplayVersion("global.C","clock_corrections()",CVS_verNum);

  if (debugFlag==1) printf("Calling toa2utc\n");
  toa2utc(psr,npsr);        /* 1. UTC(Observatory) -> UTC(NIST) */
  if (debugFlag==1) printf("Calling tai2ut1\n");
//   utc2tai(psr,npsr);     /* 2. UTC(NIST) -> TAI              */
  tai2ut1(psr,npsr);        /* 3. TAI -> UT1                    */
//   tai2tt(psr,npsr);      /* 4. TAI -> TT                     */
  if (debugFlag==1) printf("Calling tt2tb\n");
  tt2tb(psr,npsr);          /* 5. Rough estimate of TT-TB (+-2.2 microsec) */
  if (debugFlag==1) printf("Done clock corrections\n");
}
Esempio n. 12
0
void initialise(pulsar *psr,int noWarnings)
{
    int p;
    const char *CVS_verNum = "$Id: 56cb3396b0d85a3876be0530d60f6aadde41d468 $";

    if (displayCVSversion == 1) CVSdisplayVersion("initialise.C","initialise()",CVS_verNum);

    // allocate space for covar arrays
    int fullSetup = 1;
    logdbg("Initialise");

    for (p=0;p<MAX_PSR;p++)
        //    if (psr[p].obsn == NULL)
        initialiseOne (psr+p, noWarnings, fullSetup);
}
Esempio n. 13
0
void toa2utc(pulsar *psr,int npsr)
{
  int i,p;
  const char *CVS_verNum = "$Revision: 1.7 $";

  if (displayCVSversion == 1) CVSdisplayVersion("toa2utc.C","toa2utc__1()",CVS_verNum);

  for (p=0;p<npsr;p++)
      for (i=0;i<psr[p].nobs;i++)
	{
	  if (psr[p].obsn[i].clockCorr!=0 && psr[p].obsn[i].clockCorr!=2)
	  {
	    //	    logdbg("Getting clock corrections for %d",i);
	    getClockCorrections(psr[p].obsn+i, psr[p].clockFromOverride,
				psr[p].clock, psr[p].noWarnings);
	  }
	  // else clock is presumed to be TT/TDB/TCG already
	}
}
Esempio n. 14
0
void toa2utc(pulsar *psr,int npsr)
{
  int i,j,p,found=0;
  const char *CVS_verNum = "$Revision: 1.7 $";

  if (displayCVSversion == 1) CVSdisplayVersion("toa2utc.C","toa2utc__2()",CVS_verNum);

  for (p=0;p<npsr;p++)
    {
      for (i=0;i<psr[p].nobs;i++)
	{
	  found=0;
	  /* Find correction between UTC(PKS) and UTC(NIST) (output in seconds) */
	  if (psr[p].obsn[i].clockCorr==0 || psr[p].obsn[i].clockCorr==2) /* If no clock 
									     corrections being applied 
									     or already UTC */
	    psr[p].obsn[i].correctionUTC = 0.0;   /* then set correction to zero */
	  else
	    {
	      /* Determine clock correction file list */
	      for (j=0;j<psr[p].obsn[i].nFlags;j++)
		{
		  if (strcmp(psr[p].obsn[i].flagID[j],"-c")==0)
		    {
		      psr[p].obsn[i].correctionUTC = convertTOA((double)psr[p].obsn[i].sat,
								psr[p].obsn[i].flagVal[j]);
		      found=1;
		      /* printf("Correction = %g\n",(float)psr[p].obsn[i].correctionUTC); */
		      break;
		    }
		}
	      if (found==0) /* Using old technique for determining clock correction */
		psr[p].obsn[i].correctionUTC = toa2utc_nist((double)psr[p].obsn[i].sat,
							    psr[p].OBSERVATORY_CLOCK_2_UTC_NIST); 
	    }
	  printf("Correction %.15g\n",  psr[p].obsn[i].correctionUTC);
	}
    }
}
Esempio n. 15
0
    double
getCorrection(observation *obs, const char *clockFrom_c, const char *clockTo, int warnings)
{
    observatory *site;
    DynamicArray *sequence;
    size_t ifunc;
    ClockCorrectionFunction *func;
    double correction = 0.0;
    const char *CVS_verNum = "$Id: 2ecd61c300367fd1dc527ff60a21468091473d85 $";
    char clockFrom[128];
    char currClock[128];
    strcpy(clockFrom,clockFrom_c);

    if (clockFrom[0]=='\0')
        site = getObservatory(obs->telID);

    if (displayCVSversion == 1) CVSdisplayVersion("clkcorr.C","getCorrection()",CVS_verNum);

    if (clockFrom[0]=='\0')
        strcpy(clockFrom,site->clock_name);
    strcpy(currClock,clockFrom);

    if (!strcasecmp(clockTo, clockFrom))
        return 0.0;

    /*   printf("Getting %s<->%s\n", site->clock_name, clockTo); */
    sequence = getClockCorrectionSequence(clockFrom, clockTo, obs->sat,
            warnings);

    if (sequence == NULL)
    {
        char msg[1000],msg2[1000];
        sprintf(msg,"Proceeding assuming UTC = ");
        sprintf(msg2,"%s",currClock);
        displayMsg(1,"CLK6",msg,msg2,warnings);

        if (!strcasecmp(clockTo, "UTC"))
            return 0.0;
        sequence = getClockCorrectionSequence("UTC", clockTo, obs->sat,
                warnings); 
        strcpy(currClock,"UTC");
        if (sequence == NULL)
        {
            if (warnings==0) 
                printf( "!Warning [CLK:9], no clock correction available for TOA @ MJD %.4lf!\n",
                        (double)obs->sat);
            return 0.0;
        }
    }

    for (ifunc=0; ifunc < sequence->nelem
            && strcasecmp(currClock, clockTo); ifunc++)
    {
        func = ((ClockCorrectionFunction **)sequence->data)[ifunc];
        bool backwards = strcasecmp(currClock, func->clockFrom);
        /* add correction using sign based on direction of correction */
        correction += 
            ClockCorrectionFunction_getCorrection(func, obs->sat+correction/SECDAY)
            * (backwards ? -1.0 : 1.0);
        strcpy(currClock,(backwards ? func->clockFrom : func->clockTo));
        /*     printf("--> %s\n", currClock); */
    }


    return correction;
}
Esempio n. 16
0
/* ******************************************** */
void utc2tai(pulsar *psr,int npsr)
{
  int i,j,p;
  int leap_mjd[MAX_LEAPSEC],nleap=0,nread;
  double timediff;
  /*  double a1utcf; */
  FILE *fin;
  char fname[MAX_FILELEN];
  const char *CVS_verNum = "$Revision: 1.5 $";

  if (displayCVSversion == 1) CVSdisplayVersion("utc2tai.C","utc2tai()",CVS_verNum);
  
  /* Read the leap second file and store in arrays */
  strcpy(fname,getenv(TEMPO2_ENVIRON));
  strcat(fname,LEAPSECOND_FILE);
  if (!(fin = fopen(fname,"r")))
    {
      printf("ERROR [FILE6]: Unable to open the leap second file: %s\n",LEAPSECOND_FILE);
      exit(1);
    }
  while (!feof(fin))
    {
      nread = fscanf(fin,"%d",&leap_mjd[nleap]);
      if (nread == 1) /* Read successfully */
	{
	  nleap++;
	  if (nleap > MAX_LEAPSEC)
	    {printf("ERROR [CLK3], must increase size of MAX_LEAPSEC\n"); exit(1);}
	}
    }
  fclose(fin);
  for (p=0;p<npsr;p++)
    {
      /* In 1972, when the leap second procedure was introduced, TAI = UTC+10[sec] */            

      for (i=0;i<psr[p].nobs;i++)
	{
	  if (psr[p].obsn[i].clockCorr==0)
	    {
	      psr[p].obsn[i].correctionUTC_TAI = 0.0;
	    }
	  else
	    {
	      /*	  timediff=10.0343817;  */
	      timediff = 10.0; 
	      if (psr[p].obsn[i].sat < 41317.0)
		{
		  printf("Warning: cannot calculated UTC -> TAI prior to 1972\n");
		  psr[p].obsn[i].correctionUTC_TAI = 0.0;
		  /*	      psr[p].obsn[i].a1utcf = 0.0; */
		}
	      else
		{
		  for (j=0;j<nleap;j++)
		    {
		      if (psr[p].obsn[i].sat>leap_mjd[j])
			timediff+=1.0; /* Add one second */
		    }
		  psr[p].obsn[i].correctionUTC_TAI = timediff;	   
		  /* Where is this 32.15 coming from? */
		  /* psr[p].obsn[i].correctionUTC_TAI = timediff+32.15; */
		  /*		  psr[p].obsn[i].a1utcf = timediff; */
		}
	    }
	}
    }
}
Esempio n. 17
0
void preProcess(pulsar *psr,int npsr,int argc,char **argv)
{
  int p,i,k,fitN=0,setN=0,j;
  char fitStr[10][100];
  char setStr[10][100];
  float dmvals[10000];
  float startdmmjd = 0;
  int ndm;
  longdouble setVal[10];
  FILE *fdmin;
  char newEpoch[100]="NONE";
  char selectFname[1000]="";
  char globalFname[1000]="";
  char selectPlugName[1000]="";
  char select1[100][100];
  char select2[100][100];
  char line[MAX_STRLEN];
  char hashcheck;
  double select3[100];
  double select4[100];
  int nSelect=0;
  int v5;
  char name[100];
  char dmfile[100]="";
  int setName=0;
  double last=-1;
  int tempo1=0;
  int nojump=0;
  int nofit=0;
  int modify=0;
  //trim data to match dm correction, but don't correct for dm
  int trimonly = 0;
  char modifyFname[100];
  double simulate=0;
  const char *CVS_verNum = "$Revision: 1.46 $";

  if (displayCVSversion == 1) CVSdisplayVersion("preProcess.C","preProcess()",CVS_verNum);
  
  // logmsg("PreProcess");
  logdbg("In preProcess");

  //MAX_PSR   = MAX_PSR_VAL;    /* Maximum number of pulsars to fit simultaneously  */
  //MAX_OBSN  = MAX_OBSN_VAL;
  ECLIPTIC_OBLIQUITY = ECLIPTIC_OBLIQUITY_VAL;
  //  debugFlag = 0;

  for (i=0;i<argc;i++)
    {
      if (strcmp(argv[i],"-epoch")==0)
	strcpy(newEpoch,argv[++i]);
      else if (strcmp(argv[i],"-last")==0)
	sscanf(argv[++i],"%lf",&last);
      else if (strcmp(argv[i],"-setdm")==0) 
	sscanf(argv[++i],"%s",dmfile); // Should deal with multiple pulsars
      else if (strcmp(argv[i],"-trimonly")==0)
	trimonly = 1;
      else if (strcmp(argv[i],"-tempo1")==0)
	tempo1=1;
      else if (strcmp(argv[i],"-nojump")==0)
	nojump=1;
      else if (strcmp(argv[i],"-select")==0)
	sscanf(argv[++i],"%s",selectFname);
      else if (strcmp(argv[i],"-splug")==0){
	sscanf(argv[++i],"%s",selectPlugName);
	logdbg("Splug = %s\n",selectPlugName);
	  }
      else if (strcmp(argv[i],"-global")==0){
		 forceGlobalFit=1;
		 sscanf(argv[++i],"%s",globalFname);
	  }
      else if (strcmp(argv[i],"-modify")==0)
	{
	  modify=1;
	  sscanf(argv[++i],"%s",modifyFname);
	}
       else if (strcmp(argv[i],"-name")==0)
	{
	  setName=1;
	  strcpy(name,argv[i+1]);
	}
      else if (strcmp(argv[i],"-fit")==0)
	strcpy(fitStr[fitN++],argv[i+1]);
      else if (strcmp(argv[i],"-set")==0)
	{
	  strcpy(setStr[setN],argv[i+1]);
	  sscanf(argv[i+2],"%Lf",&setVal[setN]);
	  setN++;
	}
      else if (strcmp(argv[i],"-simulate")==0)
	{
	  sscanf(argv[i+1],"%lf",&simulate);
	}
      else if (strcmp(argv[i],"-nofit")==0)
	nofit = 1;
      else if (strcmp(argv[i],"-clock")==0)
	{
	  for (p=0;p<npsr;p++)
	    strcpy(psr[p].clock,argv[i+1]);
	}
  }
  logdbg("Parsed command line");
  for (p=0;p<npsr;p++)
    {
      for (i=0;i<MAX_PARAMS;i++){
	if(psr[p].param[i].nLinkTo>0){
	  psr[p].param[i].val[0] = getParameterValue(&psr[p],i,0);
	  psr[p].param[i].prefit[0] = getParameterValue(&psr[p],i,0);
	}
      }
      if (setName==1)
	strcpy(psr[p].name,name);
      if (nojump==1)
	psr[p].nJumps=0;
      // Check using white noise model file
      if (strcmp(psr[p].whiteNoiseModelFile,"NULL")!=0)
	{
	  readWhiteNoiseModelFile(psr,p);
	}
      
      if (nofit==1)
	{
	  for (i=0;i<MAX_PARAMS;i++)
	    {
	      if (i!=param_start && i!=param_finish){
		for (k=0;k<psr[p].param[i].aSize;k++)
		  psr[p].param[i].fitFlag[k] = 0;
	      }
	    }
	  // Turn off fitting for jumps
	  for (i=0;i<=psr[p].nJumps;i++)
	    psr[p].fitJump[i]=0;
	}
      /* Select command line fitting */
      for (i=0;i<fitN;i++)
	{
	  for (j=0;j<MAX_PARAMS;j++)
	    {
	      for (k=0;k<psr[p].param[j].aSize;k++)
		{
		  if (strcasecmp(fitStr[i],psr[p].param[j].shortlabel[k])==0)
		    {
		      if (psr[p].param[j].paramSet[k]!=1)
			{
			  psr[p].param[j].paramSet[k]=1;
			  psr[p].param[j].val[k]=0.0;
			  psr[p].param[j].prefit[k]=0.0;		      
			}
		      psr[p].param[j].fitFlag[k]=1;
		    }
		}
	    }
	}
      /* Simulate global parameter */
      if (simulate!=0.0)
	{
	  for (i=0;i<psr[p].nobs;i++)
	    {
	      psr[p].obsn[i].sat += simulate/SECDAY*sin(0.003*psr[p].obsn[i].sat);
	    }
	}

      /* Set jump values if already set */
      /* MOVED FOLLOWING INTO READPARFILE.C */
      /*      for (k=1;k<=psr[p].nJumps;k++)
	{	
	  v5 = -1;
	  nread = sscanf(psr[p].jumpStr[k],"%s %s %s %s %s",str1,str2,str3,str4,str5);

	  if (strcasecmp(str1,"MJD")==0 || strcasecmp(str1,"FREQ")==0)
	    {
	      if (nread>3)
		{
		  sscanf(str4,"%lf",&(psr[p].jumpVal[k]));
		  if (sscanf(str5,"%d",&v5)==1)
		    {
		      if (v5!=1) psr[p].fitJump[k]=0;
		    }
		  else
		    psr[p].fitJump[k]=0;
		}
	    }
	  else if (strcasecmp(str1,"NAME")==0 || strcasecmp(str1,"TEL")==0 || str1[0]=='-')
	    {
	      if (nread>2)
		{
		  sscanf(str3,"%lf",&(psr[p].jumpVal[k]));
		  if (sscanf(str4,"%d",&v5)==1)
		    {
		      if (v5!=1) psr[p].fitJump[k]=0;
		    }
		  else
		    psr[p].fitJump[k]=0;
		}
	    }
	    } */
      /* Select command line parameter setting */
      for (i=0;i<setN;i++)
	{
	  if (strcasecmp(setStr[i],"NITS")==0)
	    psr[p].nits = (int)setVal[i];
	  
	  for (j=0;j<MAX_PARAMS;j++)
	    {
	      for (k=0;k<psr[p].param[j].aSize;k++)
		{
		  if (strcasecmp(setStr[i],psr[p].param[j].shortlabel[k])==0)
		    {
		      psr[p].param[j].val[k]=setVal[i];
		      psr[p].param[j].prefit[k]=setVal[i];
		      psr[p].param[j].paramSet[k]=1;
		    }
		}
	    }
	}
      preProcessSimple1 (psr + p, tempo1, last);
      /* Update period epoch if necessary */
      if (strcmp(newEpoch,"NONE")!=0)
	{	  
	  longdouble nMJD,dt;
	  longdouble earliest=-1;
	  longdouble latest=-1;
	  int okay=1;

	  //=psr[p].obsn[0].sat,latest=psr[p].obsn[0].sat;
	  for (i=0;i<psr[p].nobs;i++)
	    {
	      okay=1;
	      if (psr[p].obsn[i].deleted==1) okay=0;
	      if (psr[p].param[param_start].paramSet[0]==1 && psr[p].param[param_start].fitFlag[0]==1 &&
		  (psr[p].param[param_start].val[0] > psr[p].obsn[i].sat))
		okay=0;
	      if (psr[p].param[param_finish].paramSet[0]==1 && psr[p].param[param_finish].fitFlag[0]==1 &&
		  psr[p].param[param_finish].val[0] < psr[p].obsn[i].sat)
		okay=0;
	
	      if (okay==1)
		{
		  if (earliest==-1)
		    {
		      earliest = psr[p].obsn[i].sat;
		      latest   = psr[p].obsn[i].sat;
		    }
		  if (earliest > psr[p].obsn[i].sat) earliest = psr[p].obsn[i].sat;
		  if (latest < psr[p].obsn[i].sat) latest = psr[p].obsn[i].sat;
		}
	    }
	

	  if (strcasecmp(newEpoch,"CENTRE")==0 ||
	      strcasecmp(newEpoch,"CENTER")==0) /* Find centre of data */
	    nMJD = (int)((earliest+latest)/2.0);
	  else if (strcasecmp(newEpoch,"LEFT")==0)
	    nMJD = (int)(earliest);
	  else if (strcasecmp(newEpoch,"RIGHT")==0)
	    nMJD = (int)(latest);
	  else
	    nMJD = parse_longdouble(newEpoch);

	  dt = (nMJD - psr[p].param[param_pepoch].val[0])*86400.0;
	  printf("dt = %g\n",(double)dt);
	  psr[p].param[param_f].val[0] = psr[p].param[param_f].val[0]+
	  psr[p].param[param_f].val[1]*dt + 0.5*psr[p].param[param_f].val[2]*dt*dt;
	  psr[p].param[param_f].val[1] += psr[p].param[param_f].val[2]*dt;
	  if (psr[p].param[param_f].paramSet[3]==1)
	    {
	      psr[p].param[param_f].val[0] += 1.0/6.0*psr[p].param[param_f].val[3]*dt*dt*dt;
	      psr[p].param[param_f].val[1] += 0.5*psr[p].param[param_f].val[3]*dt*dt;
	      psr[p].param[param_f].val[2] += psr[p].param[param_f].val[3]*dt;
	    }
	      
	  psr[p].param[param_f].prefit[0] = psr[p].param[param_f].val[0];
	  psr[p].param[param_f].prefit[1] = psr[p].param[param_f].val[1];
	  psr[p].param[param_pepoch].val[0] = nMJD;
	  psr[p].param[param_pepoch].prefit[0] = nMJD;

	  /* Update position epoch */
	  dt = (nMJD - psr[p].param[param_posepoch].val[0])/365.25;
	  printf("pos dt = %g\n",(double)dt);
	  if (psr[p].param[param_pmra].paramSet[0]==1)
	    {
	      char retstr[1000];
	      printf("Updating RAJ\n");
	      psr[p].param[param_raj].val[0] = psr[p].param[param_raj].val[0]+psr[p].param[param_pmra].val[0]
		/cos(psr[p].param[param_decj].val[0])/1000.0*(M_PI/180.0)/60.0/60.0*dt; 
	      psr[p].param[param_raj].prefit[0] = psr[p].param[param_raj].val[0];
	      /* Must obtain this in hms form */
	      turn_hms(psr[p].param[param_raj].val[0]/(2.0*M_PI), retstr);
	      strcpy(psr[p].rajStrPost,retstr);
	      strcpy(psr[p].rajStrPre,retstr);
	    }

	  if (psr[p].param[param_pmdec].paramSet[0]==1)
	    {
	      char retstr[1000];
	      psr[p].param[param_decj].val[0] = psr[p].param[param_decj].val[0]+psr[p].param[param_pmdec].val[0]/1000.0*(M_PI/180.0)/60.0/60.0*dt; 
	      psr[p].param[param_decj].prefit[0] = psr[p].param[param_decj].val[0];
	      turn_dms(psr[p].param[param_decj].val[0]/(2.0*M_PI), retstr);
	      strcpy(psr[p].decjStrPost,retstr);
	      strcpy(psr[p].decjStrPre,retstr);
	    }

	  psr[p].param[param_posepoch].val[0] = nMJD;
	  psr[p].param[param_posepoch].prefit[0] = nMJD;

	  /* Update dmepoch */
	  dt = (nMJD - psr[p].param[param_dmepoch].val[0])/365.25;
	  psr[p].param[param_dm].val[0] = psr[p].param[param_dm].val[0]+
	  psr[p].param[param_dm].val[1]*dt + 0.5*psr[p].param[param_dm].val[2]*dt*dt;
	  psr[p].param[param_dmepoch].val[0] = nMJD;
	  psr[p].param[param_dmepoch].prefit[0] = nMJD;

	  /* Should update wave epoch */
	  if (psr[p].param[param_waveepoch].paramSet[0]==1)
	    {
	      printf("ERROR: Not updating the FITWAVES to new EPOCH\n");
	    }
	  if (psr[p].param[param_waveepoch_dm].paramSet[0]==1)
	    {
	      printf("ERROR: Not updating the FITWAVES(DM) to new EPOCH\n");
	    }
	  


	  /* Update binary parameters if necessary */
	  if (psr[p].param[param_pb].paramSet[0]==1 && 0 == 1)  /* Binary pulsar */
	    {
	      longdouble orbits,pb,tt0,pbdot,xpbdot,t0p,t0m=0.0;
	      int        norbits;

	      if (psr[p].param[param_pbdot].paramSet[0]==1) pbdot = psr[p].param[param_pbdot].val[0];
	      else pbdot = 0.0;

	      if (psr[p].param[param_xpbdot].paramSet[0] == 1) xpbdot = psr[p].param[param_xpbdot].val[0];
	      else xpbdot = 0.0;

	      pb = psr[p].param[param_pb].val[0]*SECDAY;
	      
	      if (psr[p].param[param_tasc].paramSet[0]==1)
		tt0 = (nMJD-psr[p].param[param_tasc].val[0])*SECDAY;
	      else
		tt0 = (nMJD-psr[p].param[param_t0].val[0])*SECDAY;
	      printf("tt0 = %.14Lf %.14Lf %.14Lf %.14Lf\n",tt0,nMJD,psr[p].param[param_t0].val[0],
		     nMJD-psr[p].param[param_t0].val[0]);

	      orbits = tt0/pb - 0.5*(pbdot+xpbdot)*(tt0/pb)*(tt0/pb);
	      norbits = (int)(orbits+0.5);
	      printf("Orbits = %.5Lf  (%d)\n",orbits,norbits);

	      if (xpbdot > 0 || pbdot > 0)
		{
		  /*		  t0p = (1.0/pb + sqrtl(1.0/(pb*pb)-2.0*(pbdot+xpbdot)*norbits/pb/pb))
		    /((pbdot+xpbdot)/pb/pb);
		    t0m = (1.0/pb - sqrtl(1.0/(pb*pb)-2.0*(pbdot+xpbdot)*norbits/pb/pb))/((pbdot+xpbdot)/pb/pb); */
		  t0p = pb/(pbdot+xpbdot)*(1.0+sqrtl(1.0-2.0*(pbdot+xpbdot)*(longdouble)norbits));
		  t0m = pb/(pbdot+xpbdot)*(1.0-sqrtl(1.0-2.0*(pbdot+xpbdot)*(longdouble)norbits));

		  if (psr[p].param[param_tasc].paramSet[0]==1)
		    {
		      t0p = psr[p].param[param_tasc].val[0]+t0p/SECDAY;
		      t0m = psr[p].param[param_tasc].val[0]+t0m/SECDAY;     
		      
		      if (fabs(t0p-psr[p].param[param_tasc].val[0]) > fabs(t0m-psr[p].param[param_tasc].val[0]))
			t0p = t0m;
		    }
		  else
		    {
		      t0p = psr[p].param[param_t0].val[0]+t0p/SECDAY;
		      t0m = psr[p].param[param_t0].val[0]+t0m/SECDAY;     
		    
		      if (fabs(t0p-psr[p].param[param_t0].val[0]) > fabs(t0m-psr[p].param[param_t0].val[0]))
			t0p = t0m;
		    }
		}
	      else
		{
		  t0p = norbits*pb;
		  if (psr[p].param[param_tasc].paramSet[0]==1)		  
		    t0p = psr[p].param[param_tasc].val[0]+t0p/SECDAY;
		  else
		    t0p = psr[p].param[param_t0].val[0]+t0p/SECDAY;
		}
	       
	      if (psr[p].param[param_tasc].paramSet[0]==1)		  
		{
		  psr[p].param[param_tasc].val[0] = t0p;
		  psr[p].param[param_tasc].prefit[0] = psr[p].param[param_tasc].val[0];
		}
	      else
		{
		  psr[p].param[param_t0].val[0] = t0p;
		  psr[p].param[param_t0].prefit[0] = psr[p].param[param_t0].val[0];
		}
	      printf("Result = %.14Lf %.14Lf\n",t0p,t0m);
	      
	      psr[p].param[param_pb].val[0] += psr[p].param[param_pbdot].val[0]*tt0/SECDAY;
	      psr[p].param[param_pb].prefit[0] = psr[p].param[param_pb].val[0];

	      psr[p].param[param_om].val[0] += psr[p].param[param_omdot].val[0]*tt0/SECDAY/365.25;
	      psr[p].param[param_om].prefit[0] = psr[p].param[param_om].val[0];

	      if (psr[p].param[param_a1dot].paramSet[0]==1)
		{
		  psr[p].param[param_a1].val[0] += psr[p].param[param_a1dot].val[0]*1.0e-12*tt0;
		  psr[p].param[param_a1].prefit[0] = psr[p].param[param_a1].val[0];
		}



	    }
	}    
      if (psr[p].param[param_pepoch].paramSet[0]==1 && psr[p].param[param_pepoch].fitFlag[0]==1)
	{printf("Warning: Cannot fit for pepoch\n"); psr[p].param[param_pepoch].fitFlag[0]=0;}
      if (psr[p].param[param_posepoch].paramSet[0]==1 && psr[p].param[param_posepoch].fitFlag[0]==1)
	{printf("Warning: Cannot fit for posepoch\n"); psr[p].param[param_posepoch].fitFlag[0]=0;}
      if (psr[p].param[param_dmepoch].paramSet[0]==1 && psr[p].param[param_dmepoch].fitFlag[0]==1)
	{printf("Warning: Cannot fit for dmepoch\n"); psr[p].param[param_dmepoch].fitFlag[0]=0;}
      if (psr[p].param[param_track].paramSet[0]==1 && psr[p].param[param_track].fitFlag[0]==1)
	{printf("Warning: Cannot fit for track\n"); psr[p].param[param_track].fitFlag[0]=0;}

      if (strlen(dmfile)>0)
	{
	  float tt;
	  fdmin = fopen(dmfile,"r");
	  ndm=0;
	  while (!feof(fdmin))
	    {
	      //check wheter a line is a comment (= starts with a hash)
	      fgets(line,MAX_STRLEN,fdmin);
	      sscanf(line,"%c",&hashcheck);
	      if (hashcheck == '#') {
		//do nothing, perhaps give a debug message
		  logdbg("preProces():skipping line in dmfile\n");
	      }
	      else if (sscanf(line,"%f %f",&tt,&dmvals[ndm])==2)
		{
		  if (ndm==0)
		    startdmmjd = tt;
		  ndm++;
		}
	    }
	  fclose(fdmin);
	}
       //Check efacs and equads
      if (psr[p].nT2efac > 0 || psr[p].nT2equad > 0 || psr[p].T2globalEfac!=1.0)
	{
	  double err;
	  printf("Updating TOA errors using T2EFAC, T2EQUAD and T2GLOBALEFAC\n");
	  for (i=0;i<psr[p].nobs;i++)
	    {
	      err = psr[p].obsn[i].toaErr;
	      for (j=0;j<psr[p].obsn[i].nFlags;j++)
		{
	//	   Check equad
		  for (k=0;k<psr[p].nT2equad;k++)
		    {
		      if (strcmp(psr[p].obsn[i].flagID[j],psr[p].T2equadFlagID[k])==0)
			{
			  if (strcmp(psr[p].obsn[i].flagVal[j],psr[p].T2equadFlagVal[k])==0)
			    err = (sqrt(pow(err,2)+pow(psr[p].T2equadVal[k],2)));
			}
		    }
	//	   Check efac
		  for (k=0;k<psr[p].nT2efac;k++)
		    {
		      if (strcmp(psr[p].obsn[i].flagID[j],psr[p].T2efacFlagID[k])==0)
			{
			  if (strcmp(psr[p].obsn[i].flagVal[j],psr[p].T2efacFlagVal[k])==0)
			    err *= psr[p].T2efacVal[k];
			}
		    }
		}
	      err *= psr[p].T2globalEfac;
	      psr[p].obsn[i].toaErr = err;
	    }
	}

      // Check TNEF and TNEQ
      if (psr[p].nTNEF > 0 || psr[p].nTNEQ > 0 || psr[p].nTNSQ > 0)
        {
          double err;
          printf("Updating TOA errors using TN parameters.\n");
          for (i=0;i<psr[p].nobs;i++)
            {
              err = psr[p].obsn[i].toaErr;
              for (j=0;j<psr[p].obsn[i].nFlags;j++)
                {
                   //Check efac
                  for (k=0;k<psr[p].nTNEF;k++)
                    {
                      if (strcmp(psr[p].obsn[i].flagID[j],psr[p].TNEFFlagID[k])==0)
                        {
                          if (strcmp(psr[p].obsn[i].flagVal[j],psr[p].TNEFFlagVal[k])==0)
                            err *= psr[p].TNEFVal[k];
                        }
                    }

                   //Check equad
                  for (k=0;k<psr[p].nTNEQ;k++)
                    {
                      if (strcmp(psr[p].obsn[i].flagID[j],psr[p].TNEQFlagID[k])==0)
                        {
                          if (strcmp(psr[p].obsn[i].flagVal[j],psr[p].TNEQFlagVal[k])==0){
				double TNEquad = pow(10.0,psr[p].TNEQVal[k]+6)*pow(10.0,psr[p].TNEQVal[k]+6);
                            	err = sqrt(err*err + TNEquad);
			  }
                        }
                    }
		//Check Squad
                  for (k=0;k<psr[p].nTNSQ;k++)
                    {
                      if (strcmp(psr[p].obsn[i].flagID[j],psr[p].TNSQFlagID[k])==0)
                        {
                          if (strcmp(psr[p].obsn[i].flagVal[j],psr[p].TNSQFlagVal[k])==0){

				double tobsval=0;
				for (int tf=0;tf<psr[p].obsn[i].nFlags;tf++){
					if(strcasecmp(psr[p].obsn[i].flagID[tf],"-tobs")==0){
						if(strcasecmp(psr[p].obsn[i].flagVal[tf],"UNKNOWN")==0){
							tobsval=1;
						}
						else{
							double tobs=atof(psr[p].obsn[i].flagVal[tf]);
							tobsval=tobs;
						}
					}		
				}
                                double TNSquad = pow(10.0,psr[p].TNSQVal[k]+6)*pow(10.0,psr[p].TNSQVal[k]+6)*tobsval;
                                err = sqrt(err*err + TNSquad);
                          }
                        }
                    }


                }
              psr[p].obsn[i].toaErr = err;
            }
  	}


      // Modify TOA flags if required
      if (modify==1)
	{
	  FILE *fin;
	  double mjd1,mjd2;
	  char flag1[MAX_STRLEN],flag2[MAX_STRLEN],flag3[MAX_STRLEN];
	  if (!(fin = fopen(modifyFname,"r")))
	    {
	      printf("Unable to open >%s< to modify the flags\n",modifyFname);
	      exit(1);
	    }
	  while (!feof(fin))
	    {
	      if (fscanf(fin,"%s %s %lf %lf %s",flag1,flag2,&mjd1,&mjd2,flag3)==5)
		{
		  for (i=0;i<psr[p].nobs;i++)
		    {
		      for (j=0;j<psr[p].obsn[i].nFlags;j++)
			{
			  if (strcmp(psr[p].obsn[i].flagID[j],flag1)==0 &&
			      strcmp(psr[p].obsn[i].flagVal[j],flag2)==0 &&
			      (double)psr[p].obsn[i].sat > mjd1 &&
			      (double)psr[p].obsn[i].sat < mjd2)
			    strcpy(psr[p].obsn[i].flagVal[j],flag3);
			}
		    }
		}
	    }
	  fclose(fin);
	}
      preProcessSimple2 (psr + p, startdmmjd, ndm, dmvals, trimonly);
      // Check for select file
      if (strlen(selectPlugName) > 0)
	{
	  char *(*entry)(int,char **,pulsar *,int *);
	  void * module;
	  char str[1000];
	  logdbg("Dealing with the select plugin"); 


	  for (int iplug=0; iplug < tempo2_plug_path_len; iplug++){
	    sprintf(str,"%s/%s_%s_splug.t2",tempo2_plug_path[iplug],
		    selectPlugName,tempo2MachineType);
	    logmsg("Looking for %s",str);
	    module = dlopen(str, RTLD_NOW); 
	    if(module==NULL){	  
	      printf("dlerror() = %s\n",dlerror());
	    } else break;
	  }
	  
	  //	  strcpy(tempo2MachineType, getenv("LOGIN_ARCH"));
	  //	  sprintf(str,"%s/plugins/%s_%s_splugt2",getenv(TEMPO2_ENVIRON),
	  //		  selectPlugName,tempo2MachineType);
	  //	  printf("Looking for %s\n",str);
	  //	  module = dlopen(str, RTLD_NOW); 
	  if(!module)  {
	    fprintf(stderr, "[error]: dlopen() failed while resolving symbols.\n" );
	    fprintf(stderr, "dlerror() = %s\n",dlerror());
	    exit(1);
	  }
	  /*
	   * Check that the plugin is compiled against the same version of tempo2.h
	   */
	  char ** pv  = (char**)dlsym(module, "plugVersionCheck");
	  if(pv!=NULL){
		  // there is a version check for this plugin
		  if(strcmp(TEMPO2_h_VER,*pv)){
			  fprintf(stderr, "[error]: Plugin version mismatch\n");
			  fprintf(stderr, " '%s' != '%s'\n",TEMPO2_h_VER,*pv);
			  fprintf(stderr, " Please recompile plugin against same tempo2 version!\n");
			  dlclose(module);
			  exit(1);
		  }
	  }


	  entry = (char*(*)(int,char **,pulsar *,int *))dlsym(module, "selectInterface");
	  if( entry == NULL ) {
	    dlclose(module);
	    fprintf(stderr, "[error]: dlerror() failed while  retrieving address.\n" ); 
	    fprintf(stderr, "dlerror() = %s\n",dlerror());
	    exit(1);
	  }
	  entry(argc,argv,psr,&npsr);
	}
      else
	{
	  if (strlen(selectFname) > 0)
	    {
	      logdbg("Using select file");
	      useSelectFile(selectFname,psr,npsr);
	      logdbg("Complete using select file");
	    }
	}
      preProcessSimple3 (psr + p);
    }

  // Now check for global parameters
  if (strlen(globalFname) > 0)
    {
      char tpar[MAX_STRLEN][MAX_FILELEN];
      char ttim[MAX_STRLEN][MAX_FILELEN];

      sprintf(tpar[0],globalFname);
      printf("Setting global parameters\n");
      readParfileGlobal(psr,npsr,tpar,ttim);
      printf("Complete setting global parameters\n");
    }
} 
Esempio n. 18
0
/* ******************************************** */
void displayParameters(int pos,char timFile[][MAX_FILELEN],char parFile[][MAX_FILELEN],pulsar *psr,int npsr)
{
  int i, ic, p;
  const char *CVS_verNum = "$Revision: 1.5 $";

  if (displayCVSversion == 1) CVSdisplayVersion("displayParameters.C","displayParameters()",CVS_verNum);
  
  printf("\n\n");
  if (pos==1) printf("Parameter values after getInputs from command line\n");
  if (pos==2) printf("Parameter values after reading of .par file\n");
  if (pos==3) printf("Parameter values after reading of .tim file\n");
  if (pos==4) printf("After obtaining correction between observatory UTC and UTC(NIST)\n");
  if (pos==5) printf("After calculating correction between UTC and TAI\n");
  if (pos==6) printf("After calculating correction between TAI and TB\n");
  if (pos==7) printf("After calculating vector pointing at pulsar\n");

  printf("\n\n");
  printf("lobal definitions:\n\n");
  printf("MAX_FREQ_DERIVATIVES = %d\n",MAX_FREQ_DERIVATIVES);
  printf("MAX_DM_DERIVATIVES   = %d\n",MAX_DM_DERIVATIVES);
  printf("MAX_FILELEN          = %d\n",MAX_FILELEN);
  printf("\n\n");
  for (p=0;p<npsr;p++)
    {
      printf("Command line inputs:\n\n");
      printf("Pulse arrival time file[0] = %s\n",timFile[0]);
      printf("Pulsar parameter file[0]   = %s\n",parFile[0]);
      
      printf("\n\n");
      printf("Pulsar Parameters:\n\n");
      printf("Pulsar name          = %s\n",psr[p].name);
      if (pos>2) /* Have .tim file data */
	{
	  printf("\n\nObservations:\n\n");
	  printf("Number of observations = %d\n",psr[p].nobs);
	  printf("--------------------------------------------------------------------------------\n");
	  printf("   #  | SAT                   | Clock corrections(s)     |\n");
	  printf("--------------------------------------------------------------------------------\n");
	  for (i=0;i<psr[p].nobs;i++)
	  {
	    printf("|%4d | %s |", i+1, print_longdouble(psr[p].obsn[i].sat).c_str());
	    for (ic=0; ic < psr[p].obsn[i].nclock_correction; ic++)
	      printf(" %-14.7g(->%s)", 
		     (double)psr[p].obsn[i].correctionsTT[ic].correction,
		     psr[p].obsn[i].correctionsTT[ic].corrects_to);
	    printf("\n");
	  }
 	  printf("--------------------------------------------------------------------------------\n");
	  printf("   #   TAI->TB   | SAT->UT1      |\n");
	  printf("--------------------------------------------------------------------------------\n");
	  for (i=0;i<psr[p].nobs;i++)
	    printf("|%4d | %-10.9g | %-16.9e |\n",
		   i+1,
		   (double)psr[p].obsn[i].correctionTT_TB,
		   (double)psr[p].obsn[i].correctionUT1);
	  printf("--------------------------------------------------------------------------------\n");
	}
      if (pos>6)  /* Ephemeris information */
	{
	  printf("\n\nEphemeris information:\n\n");
	  printf("3-vector pointing at pulsar       = (%-13.13f,%-13.13f,%13.13f)\n",
		 psr[p].posPulsar[0],psr[p].posPulsar[1],psr[p].posPulsar[2]);
	  printf("3-vector giving pulsar's velocity = (%-13.8e,%13.8e,%13.8e)\n",
		 psr[p].velPulsar[0],psr[p].velPulsar[1],psr[p].velPulsar[2]);
	}
      if (pos>7)
	{
	  printf("\n\n");
	  printf("--------------------------------------------------------------------------------------------------------------\n");
	  printf("   JD            RCS(1)   RCS(2)     RCS(3)      RCB(1)     RCB(2)     RCB(3)    RBE(1)    RBE(2)    RBE(3)\n");
	  printf("--------------------------------------------------------------------------------------------------------------\n");
	  for (i=0;i<psr[p].nobs;i++)
	    {
	      printf("%-.5f %10.5f %-10.5f %-10.5f %-10.5f %-10.5f %-10.5f %-10.5f %-10.5f %-10.5f\n",
		     (double)(psr[p].obsn[i].sat + getCorrectionTT(psr[p].obsn+i)/SECDAY +
		     psr[p].obsn[i].correctionTT_TB/SECDAY 
		     + 2400000.5),
		     (double)psr[p].obsn[i].sun_ssb[0],
		     (double)psr[p].obsn[i].sun_ssb[1],
		     (double)psr[p].obsn[i].sun_ssb[2],
		     (double)psr[p].obsn[i].earthMoonBary_ssb[0],
		     (double)psr[p].obsn[i].earthMoonBary_ssb[1],
		     (double)psr[p].obsn[i].earthMoonBary_ssb[2],
		     (double)psr[p].obsn[i].earthMoonBary_earth[0],
		     (double)psr[p].obsn[i].earthMoonBary_earth[1],
		     (double)psr[p].obsn[i].earthMoonBary_earth[2]);
	    }
	  printf("--------------------------------------------------------------------------------------------------------------\n");
	  
	  printf("\n\n");
	  printf("--------------------------------------------------------------------------------------------------------------\n");
	  printf("   JD            RCS(4)   RCS(5)     RCS(6)      RCB(4)     RCB(5)     RCB(6)    RBE(4)    RBE(5)    RBE(6)\n");
	  printf("--------------------------------------------------------------------------------------------------------------\n");
	  for (i=0;i<psr[p].nobs;i++)
	    {
	      printf("%-.5lf %10.3e %-10.3e %-10.3e %-10.3e %-10.3e %-10.3e %-10.3e %-10.3e %-10.3e\n",
		     (double)(psr[p].obsn[i].sat + 
		     getCorrectionTT(psr[p].obsn+i)/SECDAY + 
		      psr[p].obsn[i].correctionTT_TB/SECDAY 
		     + 2400000.5),
		     (double)psr[p].obsn[i].sun_ssb[3],
		     (double)psr[p].obsn[i].sun_ssb[4],
		     (double)psr[p].obsn[i].sun_ssb[5],
		     (double)psr[p].obsn[i].earthMoonBary_ssb[3],
		     (double)psr[p].obsn[i].earthMoonBary_ssb[4],
		     (double)psr[p].obsn[i].earthMoonBary_ssb[5],
		     (double)psr[p].obsn[i].earthMoonBary_earth[3],
		     (double)psr[p].obsn[i].earthMoonBary_earth[4],
		     (double)psr[p].obsn[i].earthMoonBary_earth[5]);
	    }
	  printf("--------------------------------------------------------------------------------------------------------------\n");
	  printf("MJD         OBS->EARTH1   OBS->EARTH2  OBS->EARTH3  SITEVEL1    SITEVEL2     SITEVEL3\n");
	  printf("--------------------------------------------------------------------------------------------------------------\n");

	  for (i=0;i<psr[p].nobs;i++)
	    {
	      printf("%-.5lf %12.5e %-12.5e %-12.5e %-12.5e %-12.5e %-12.5e\n",
		     (double)psr[p].obsn[i].sat + 
		     getCorrectionTT(psr[p].obsn+i)/SECDAY,
		     psr[p].obsn[i].observatory_earth[0],psr[p].obsn[i].observatory_earth[1],
		     psr[p].obsn[i].observatory_earth[2],
		     psr[p].obsn[i].siteVel[0],psr[p].obsn[i].siteVel[1],psr[p].obsn[i].siteVel[2]);
	    }
	  printf("--------------------------------------------------------------------------------------------------------------\n");

	}
      if (pos>9) /* Extra Delays */
	{
	  printf("\n\nExtra Delays:\n\n");
	  
	  printf("--------------------------------------------------------------------------------------------------------------\n"); 
	  printf("MJD          ShapiroSun          TDIS               Roemer           BAT\n");
	  printf("--------------------------------------------------------------------------------------------------------------\n");
	  for (i=0;i<psr[p].nobs;i++)
	    {
	      printf("%s %.12e %.12e %.10Lf %.10f\n",print_longdouble(psr[p].obsn[i].sat).c_str(),psr[p].obsn[i].shapiroDelaySun,
		     psr[p].obsn[i].tdis1+psr[p].obsn[i].tdis2,psr[p].obsn[i].roemer,(double)psr[p].obsn[i].bat);
	    }
	  printf("--------------------------------------------------------------------------------------------------------------\n");
    }
    }

}
Esempio n. 19
0
File: eop.C Progetto: zhuww/tempo2
void
load_EOP(DynamicArray *EOPsamples,char *eopcFile)
{
  char fname[1024], line[1024], mjd_s[1024], xp_s[1024], yp_s[1024], dut1_s[1024];
  int year;
  EOPSample newSample;
  FILE *f;
  int iline,idummy;
  int format=0;
  const char *CVS_verNum = "$Revision: 1.10 $";

  if (displayCVSversion == 1) CVSdisplayVersion("eop.C","load_EOP()",CVS_verNum);

  // init array
  DynamicArray_init(EOPsamples, sizeof(EOPSample));

  // open file
  //  sprintf(fname, "%s/%s", getenv("TEMPO2"), EOPC04_FILE);
  sprintf(fname, "%s/%s", getenv("TEMPO2"), eopcFile);
  f = fopen(fname, "r");
  if (!f)
  {
    fprintf(stderr, "Fatal Error: Unable to open file %s for reading: %s\n",
	      fname, strerror(errno));
    exit(1);
  }

  // parse file
  
  for (iline=1; fgets(line, 1024, f)!=NULL; iline++)
  {
    // ignore header lines, ancient history (pre-PSR), etc
    if (sscanf(line, "%d", &year)==1 && year > 1966 && year < 3000)
    {
      if (format==0)
	{
	  // break it up, ugly fixed format fortran I/O
	  strncpy(mjd_s, line+17, 5); mjd_s[5]='\0';
	  strncpy(xp_s, line+22, 9); xp_s[9]='\0';
	  strncpy(yp_s, line+31, 9); yp_s[9]='\0';
	  strncpy(dut1_s, line+40, 10); dut1_s[10]='\0';
	  // put into sample, in radians and seconds
	  if (sscanf(mjd_s, "%lf", &newSample.mjd)!=1 ||
	      sscanf(xp_s, "%lf", &newSample.xp)!=1 ||
	      sscanf(yp_s, "%lf", &newSample.yp)!=1 ||
	      sscanf(dut1_s, "%lf", &newSample.dut1)!=1)
	    {
	      fprintf(stderr, "Error parsing line %d of %s", iline, fname);
	      exit(1);
	    }
	}
      else if (format==1)
	{
	  if (sscanf(line,"%d %d %d %lf %lf %lf %lf",&year,&idummy,&idummy,&newSample.mjd,&newSample.xp,&newSample.yp,&newSample.dut1)!=7)
	    {
	      fprintf(stderr, "Error parsing line %d of %s", iline, fname);
	      exit(1);
	    }
	}
      newSample.xp *= M_PI/(180.0*60.0*60.0);
      newSample.yp *= M_PI/(180.0*60.0*60.0);
      DynamicArray_push_back(EOPsamples, &newSample);
    }
    else {  // Check which format we are using
      if (strstr(line,"FORMAT(2X,I4,2X,A4,I3,2X,I5,2F9.6,F10.7,2X,F10.7,2X,2F9.6)")!=NULL)
	{
	  format=0;
	  printf("Warning: using old format for $TEMPO2/eopc04_IAU2000.62-now - should update\n");
	}
      else if (strstr(line,"FORMAT(3(I4),I7,2(F11.6),2(F12.7),2(F11.6),2(F11.6),2(F11.7),2F12.6)")!=NULL)
	{
	  format=1;
	  logdbg("Using new format for $TEMPO2/eopc04_IAU2000.62-now");
	}
    }
  }
  fclose(f); 
}
Esempio n. 20
0
double DDSmodel(pulsar *psr,int p,int ipos,int param)
{
    double an;
    double pb,k;
    double rad2deg = 180.0/M_PI;
    double SUNMASS = 4.925490947e-6;
    double m2,tt0,t0,x,ecc,er,xdot,edot,dr,dth,eth,am2,ct;
    double pbdot,xpbdot,phase,u,du,gamma;
    double orbits;
    int norbits;
    double  cu,onemecu,cae,sae,ae,omega,omz,sw,cw,alpha,beta,bg,dre,drep,drepp,anhat,su;
    double sqr1me2,cume,brace,dlogbr,ds,da,a0,b0,d2bar,torb;
    double csigma,ce,cx,comega,cgamma,cm2,csi=0.0;
    double shapmax,cshapmax,sdds;
    const char *CVS_verNum = "$Id: a9d585325cc9a6e3c39f43ec069bfea3d7e7ac09 $";

    if (displayCVSversion == 1) CVSdisplayVersion("DDSmodel.C","DDSmodel()",CVS_verNum);

    dr = 0.0; /* WHAT SHOULD THESE BE SET TO? */
    dth = 0.0; 


    if (psr[p].param[param_shapmax].paramSet[0]==1) shapmax = psr[p].param[param_shapmax].val[0];
    else shapmax = 0.0;


    //if (psr[p].param[param_sini].paramSet[0]==1) si = getParameterValue(&psr[p],param_sini,0);
    //else si = 0.0;

    if (psr[p].param[param_m2].paramSet[0]==1) am2 = psr[p].param[param_m2].val[0];
    else am2 = 0.0;

    pb = psr[p].param[param_pb].val[0]*SECDAY;
    an = 2.0*M_PI/pb;
    k = psr[p].param[param_omdot].val[0]/(rad2deg*365.25*86400.0*an);

    m2 = am2*SUNMASS;
    t0 = psr[p].param[param_t0].val[0];
    ct = psr[p].obsn[ipos].bbat;    

    tt0 = (ct-t0)*SECDAY;

    if (psr[p].param[param_gamma].paramSet[0]==1)
        gamma = psr[p].param[param_gamma].val[0];
    else
        gamma = 0.0;
    a0    = 0.0; /* WHAT SHOULD THIS BE SET TO? */
    b0    = 0.0; /* WHAT SHOULD THIS BE SET TO? */

    if (psr[p].param[param_om].paramSet[0]==1) omz = psr[p].param[param_om].val[0];
    else omz = 0.0;

    if (psr[p].param[param_a1dot].paramSet[0]==1) xdot  = psr[p].param[param_a1dot].val[0];
    else xdot  = 0.0;

    if (psr[p].param[param_pbdot].paramSet[0] == 1) pbdot = psr[p].param[param_pbdot].val[0];
    else pbdot = 0.0;

    if (psr[p].param[param_edot].paramSet[0] == 1) edot = psr[p].param[param_edot].val[0];
    else edot = 0.0;

    if (psr[p].param[param_xpbdot].paramSet[0] == 1) xpbdot = psr[p].param[param_xpbdot].val[0];
    else xpbdot = 0.0;


    x = psr[p].param[param_a1].val[0]+xdot*tt0;
    ecc = psr[p].param[param_ecc].val[0]+edot*tt0;
    er = ecc*(1.0+dr);
    eth = ecc*(1.0+dth);

    orbits = tt0/pb - 0.5*(pbdot+xpbdot)*pow(tt0/pb,2);
    norbits = (int)orbits;
    if (orbits<0.0) norbits--;
    phase=2.0*M_PI*(orbits-norbits);
    /*  Compute eccentric anomaly u by iterating Kepler's equation. */
    u=phase+ecc*sin(phase)*(1.0+ecc*cos(phase));
    do {
        du=(phase-(u-ecc*sin(u)))/(1.0-ecc*cos(u));
        u=u+du;
    } while (fabs(du)>1.0e-12);

    /*  DD equations 17b, 17c, 29, and 46 through 52 */
    su=sin(u);
    cu=cos(u);
    onemecu=1.0-ecc*cu;
    cae=(cu-ecc)/onemecu;
    sae=sqrt(1.0-pow(ecc,2))*su/onemecu;
    ae=atan2(sae,cae);
    if(ae<0.0) ae=ae+2.0*M_PI;
    ae=2.0*M_PI*orbits + ae - phase;
    omega=omz/rad2deg + k*ae;
    sw=sin(omega);
    cw=cos(omega);
    alpha=x*sw;
    beta=x*sqrt(1-pow(eth,2))*cw;
    bg=beta+gamma;
    dre=alpha*(cu-er) + bg*su;
    drep=-alpha*su + bg*cu;
    drepp=-alpha*cu - bg*su;
    anhat=an/onemecu;

    /* DD equations 26, 27, 57: */
    sqr1me2=sqrt(1-pow(ecc,2));
    cume=cu-ecc;

    /* New additions for DDS model */
    sdds = 1.0 - exp(-1.0*shapmax);
    brace=onemecu-sdds*(sw*cume+sqr1me2*cw*su);
    /* **************************************** */
    dlogbr=log(brace);
    ds=-2*m2*dlogbr;
    da=a0*(sin(omega+ae) + ecc*sw) + b0*(cos(omega+ae) + ecc*cw);

    /*  Now compute d2bar, the orbital time correction in DD equation 42. */
    d2bar=dre*(1-anhat*drep+(pow(anhat,2))*(pow(drep,2) + 0.5*dre*drepp -
                0.5*ecc*su*dre*drep/onemecu)) + ds + da;
    torb=-d2bar;

    if (param==-1) return torb;

    /*  Now we need the partial derivatives. Use DD equations 62a - 62k. */
    csigma=x*(-sw*su+sqr1me2*cw*cu)/onemecu;
    ce=su*csigma-x*sw-ecc*x*cw*su/sqr1me2;
    cx=sw*cume+sqr1me2*cw*su;
    comega=x*(cw*cume-sqr1me2*sw*su);
    cgamma=su;
    //cdth=-ecc*ecc*x*cw*su/sqr1me2;
    cm2=-2*dlogbr;

    /* New additions for the DDS model */
    /*  csi=2*m2*(sw*cume+sqr1me2*cw*su)/brace;  */
    cshapmax = 2*m2*(sw*cume+sqr1me2*cw*su)/brace * (1.0-sdds);

    if (param==param_pb)
        return -csigma*an*SECDAY*tt0/(pb*SECDAY); 
    else if (param==param_a1)
        return cx;
    else if (param==param_ecc)
        return ce;
    else if (param==param_om)
        return comega;
    else if (param==param_omdot)
        return ae*comega/(an*360.0/(2.0*M_PI)*365.25*SECDAY);
    else if (param==param_t0)
        return -csigma*an*SECDAY;
    else if (param==param_pbdot)
        return 0.5*tt0*(-csigma*an*SECDAY*tt0/(pb*SECDAY));
    else if (param==param_sini)
        return csi;
    else if (param==param_gamma)
        return cgamma;
    else if (param==param_m2)
        return cm2*SUNMASS;
    else if (param==param_a1dot) /* Also known as xdot */
        return cx*tt0;
    else if (param==param_shapmax) /* New for DDS */
        return cshapmax;

    return 0.0;
}
Esempio n. 21
0
void tt2tb(pulsar *psr,int npsr)
{
  int i, p,k;
  longdouble mjd_tt, mjd_teph;
  double deltaT=0.0, obsTerm, earthVel[3];
  double deltaTDot, obsTermDot, earthVelDot[3];
  int first=1;
  const char *CVS_verNum = "$Revision: 1.11 $";

  if (displayCVSversion == 1) CVSdisplayVersion("tt2tdb.C","tt2tdb()",CVS_verNum);

  init_ifte();
  for (p=0;p<npsr;p++)
  {
    for (i=0;i<psr[p].nobs;i++)
    {
      if (psr[p].obsn[i].clockCorr==0 && strcmp(psr[p].obsn[i].telID,"STL")!=0)
	psr[p].obsn[i].correctionTT_TB = 0.0;
      else
      {
	if (strcmp(psr[p].obsn[i].telID,"STL")==0)
	  mjd_tt = psr[p].obsn[i].sat;
	else
	  mjd_tt = psr[p].obsn[i].sat + getCorrectionTT(psr[p].obsn+i)/SECDAY;
	/* Evaluate the time ephemeris and its derivative */
	if (psr[p].timeEphemeris == IF99_TIMEEPH)
	  {
	    deltaT = IF_deltaT(mjd_tt);
	  }
	if (psr[p].timeEphemeris == FB90_TIMEEPH)
	  {
	    deltaT = FB_deltaT(mjd_tt) - IFTE_TEPH0; /* FB code returns Teph-TDB not TT-TDB */
	  }
	/* Get term involving observatory position (if known) */

	/*	for (k=0;k<3;k++)
		varray[k] = -psr[p].obsn[i].earthMoonBary_earth[k+3];
		vectorsum(earthVel, 
		psr[p].obsn[i].earthMoonBary_ssb+3,
		varray);   */
	for (k=0;k<3;k++)
	  earthVel[k] = psr[p].obsn[i].earth_ssb[k+3];
	obsTerm = dotproduct(earthVel, psr[p].obsn[i].observatory_earth)
	  /  (1.0-IFTE_LC) ;
	/* both vectors were meant to be defined in Ephemeris units ...
	 This correction is neglible but worth doing so we can test with K=2*/
	if (psr[p].units == SI_UNITS)
	  obsTerm /= (double)(IFTE_K*IFTE_K); // both were in SI 
	else
	  obsTerm /= (double)IFTE_K;  // obs_earth was in SI
	//	printf("obsTerm = %g\n",(double)obsTerm);
	/* Compute Teph : Irwin & Fukushima (1999) eq 13*/	
	/* Note, DeltaT(Teph0) ~ -2x10^-14 s so is neglected */
	psr[p].obsn[i].correctionTT_Teph = IFTE_TEPH0 + obsTerm
	  + deltaT / (1.0-IFTE_LC);
	/* Compute TCB or TDB as requested */
	if (psr[p].units == TDB_UNITS)
	  {
	    psr[p].obsn[i].correctionTT_TB = 
	      psr[p].obsn[i].correctionTT_Teph - (1? 0.0 : IFTE_TEPH0); 
	  }
	else
	  {
	    psr[p].obsn[i].correctionTT_TB = 
	      IFTE_KM1 * (double)(mjd_tt-IFTE_MJD0)*86400.0/* linear drift term */
	      + IFTE_K * (psr[p].obsn[i].correctionTT_Teph-(longdouble)IFTE_TEPH0);
	  }
	/* Compute dTB/dTT for correct frequency transfer if needed */
	if (psr[p].dilateFreq==1)
	{
	  if (first==1)
	    {
	      //	      init_ifte();
	      first=0;

	    }
	  mjd_teph = mjd_tt + psr[p].obsn[i].correctionTT_Teph/86400.0;

	  deltaTDot = IFTE_DeltaTDot(2400000.0+(int)mjd_teph, 
				     0.5+(mjd_teph-(int)mjd_teph));
	  // XXX seems deltaTDot is coming out too big
	  IFTE_get_vEDot(2400000.0+(int)mjd_teph, 
			 0.5+(mjd_teph-(int)mjd_teph), earthVelDot);
	  vectorscale(earthVelDot, 1.0/86400.0);
	  obsTermDot = 
	    (dotproduct(earthVelDot, psr[p].obsn[i].observatory_earth)
	     + dotproduct(earthVel, psr[p].obsn[i].siteVel))
	    /  (1.0-IFTE_LC) ;
	  if (psr[p].units == SI_UNITS)
	    obsTerm /= (double) (IFTE_K*IFTE_K); // both were in SI 
	  else
	    obsTerm /= (double)IFTE_K;  // obs_earth was in SI
	  
	  if (psr[p].units == TDB_UNITS)	    
	    psr[p].obsn[i].einsteinRate = 
	      1.0 + obsTermDot + deltaTDot/(1.0-IFTE_LC);
	  else
	    {
	      psr[p].obsn[i].einsteinRate = 
		IFTE_K * (1.0 + obsTermDot + deltaTDot/(1.0-IFTE_LC));
	      //	  obsTermDot = 
	      //	    (dotproduct(earthVelDot, psr[p].obsn[i].observatory_earth)
	      //	     + dotproduct(earthVel, psr[p].obsn[i].siteVel))
	      //	    /  (1.0-IFTE_LC) ;

							   
	    }
// 	  if (!first) printf("%g %g %g %g %g Einstein\n", (double)mjd_tt,
// 		 deltaT, deltaTDot, obsTerm, obsTermDot);
//	  if (!first)
//	    printf("ER-1 %lg\n", psr[p].obsn[i].einsteinRate-1.0);
	}	  
      }
    }
  }
  IFTE_close_file();
}
Esempio n. 22
0
double BTXmodel(pulsar *psr,int p,int ipos,int param,int k)
{
    double torb;
    double tt0;
    double orbits;
    int i,j;
    //  double pb;     /* Orbital period (sec) */
    //  double pbdot;
    //  double xpbdot;
    double ecc;    /* Orbital eccentricity */
    double edot;
    double asini;
    double xdot;
    double omdot;
    double omega;
    double gamma;
    int    norbits;
    double phase;
    double ep,dep,bige,tt,som,com;
    double alpha,beta,sbe,cbe,q,r,s,fac;
    const char *CVS_verNum = "$Id: 83dda52b02bf8ed8c7db134e9fd4bca448298d41 $";

    if (displayCVSversion == 1) CVSdisplayVersion("BTXmodel.C","BTXmodel()",CVS_verNum);

    tt0 = (psr[p].obsn[ipos].bbat - psr[p].param[param_t0].val[0])*SECDAY;

    //  pb     = psr[p].param[param_pb].val[0] * SECDAY;
    edot   = 0.0;
    ecc    = psr[p].param[param_ecc].val[0] + edot*tt0;

    if (ecc < 0.0 || ecc > 1.0)
    {
        ld_printf("BTXmodel: problem with eccentricity = %Lg\n",psr[p].param[param_ecc].val[0]);
        exit(1);
    }

    //  if (psr[p].param[param_pbdot].paramSet[0] == 1) pbdot  = psr[p].param[param_pbdot].val[0];
    //  else pbdot=0.0;
    //  xpbdot = 0.0;
    if (psr[p].param[param_a1dot].paramSet[0] == 1) xdot = psr[p].param[param_a1dot].val[0];
    else xdot = 0.0;
    asini  = psr[p].param[param_a1].val[0] + xdot*tt0;
    if (psr[p].param[param_omdot].paramSet[0] == 1) omdot = psr[p].param[param_omdot].val[0];
    else omdot  = 0.0;
    omega  = (psr[p].param[param_om].val[0] + omdot*tt0/(SECDAY * 365.25))/(180.0/M_PI);
    if (psr[p].param[param_gamma].paramSet[0]==1) gamma = psr[p].param[param_gamma].val[0];
    else gamma  = 0.0;

    torb = 0.0;

    // Note for the BTX model we use the FB parameters
    orbits = psr[p].param[param_fb].val[0]*tt0;
    // DO CHECK FOR NFBJ
    //  printf("Not checking for NFBJ %g\n",orbits);
    fac = 1.0;
    for (j=1;j<psr[p].param[param_fb].aSize;j++)
    {
        fac = fac/(double)(j+1);
        if (psr[p].param[param_fb].paramSet[j]==1)
            orbits += fac*psr[p].param[param_fb].val[j]*powl(tt0,j+1);
    }
    // UPDATE FOR EDOT, XDOT etc.
    //  printf("Not updating EDOT, XDOT, OMEGA etc. %g\n",orbits);

    //  orbits = tt0/pb - 0.5*(pbdot+xpbdot)*pow(tt0/pb,2); 
    norbits = (int)orbits;
    if (orbits < 0.0) norbits--;

    phase = 2.0*M_PI * (orbits-norbits);

    /* Using Pat Wallace's method of solving Kepler's equation -- code based on bnrybt.f */
    ep = phase + ecc*sin(phase)*(1.0+ecc*cos(phase));

    /* This line is wrong in the original tempo: should be inside the do loop */
    /*  denom = 1.0 - ecc*cos(ep);*/

    do {
        dep = (phase - (ep-ecc*sin(ep)))/(1.0 - ecc*cos(ep));
        ep += dep;
    } while (fabs(dep) > 1.0e-12);
    bige = ep;

    tt = 1.0-ecc*ecc;
    som = sin(omega);
    com = cos(omega);

    alpha = asini*som;
    beta = asini*com*sqrt(tt);
    sbe = sin(bige);
    cbe = cos(bige);
    q = alpha * (cbe-ecc) + (beta+gamma)*sbe;
    r = -alpha*sbe + beta*cbe;
    s = 1.0/(1.0-ecc*cbe);
    //  printf("Have torb = %g %g %g %g\n",torb,q,r,s);
    torb = -q+(2*M_PI*(double)psr[p].param[param_fb].val[0])*q*r*s + torb;
    //  printf("Have torb2 = %g %g %g %g %g\n",torb,q,r,s,(double)psr[p].param[param_fb].val[0]);
    if (param==-1) return torb;
    //  if (param==param_pb)
    //    return -2.0*M_PI*r*s/pb*SECDAY*tt0/(SECDAY*pb) * SECDAY;  /* fctn(12+j) */
    if (param==param_fb)
    {
        double diff;
        tt0/=1.0e7;
        diff = 2.0*M_PI*r*s*tt0;
        for (j=1;j<=k;j++)
        {
            //	  tt0/=1.0e7;
            diff = (1.0/(double)(j+1))*tt0*diff;      
        }
        //      printf("Returning: param_fb %d %g %g %g %g\n",k,diff,(double)r,(double)s,(double)tt0);
        return diff;
    }
    else if (param==param_a1)
    {
        //      printf("Returning A1: %g\n",(som*(cbe-ecc) + com*sbe*sqrt(tt)));
        return (som*(cbe-ecc) + com*sbe*sqrt(tt));                /* fctn(9+j) */
    }
    else if (param==param_ecc)
        return -(alpha*(1.0+sbe*sbe-ecc*cbe)*tt - beta*(cbe-ecc)*sbe)*s/tt; /* fctn(10+j) */
    else if (param==param_om)
        return asini*(com*(cbe-ecc) - som*sqrt(tt)*sbe);          /* fctn(13+j) */
    else if (param==param_t0)
    {
        //      printf("Returning T0 %g\n",-2.0*M_PI*psr[p].param[param_fb].val[0]*r*s*SECDAY);
        return -2.0*M_PI*psr[p].param[param_fb].val[0]*r*s*SECDAY;                           /* fctn(11+j) */
    }
    //  else if (param==param_pbdot)
    //    return 0.5*(-2.0*M_PI*r*s/pb*SECDAY*tt0/(SECDAY*pb))*tt0; /* fctn(18+j) */
    else if (param==param_a1dot)
        return (som*(cbe-ecc) + com*sbe*sqrt(tt))*tt0;            /* fctn(24+j) */
    else if (param==param_omdot)
        return asini*(com*(cbe-ecc) - som*sqrt(tt)*sbe)*tt0;      /* fctn(14+j) */
    else if (param==param_edot)                            
        return (-(alpha*(1.0+sbe*sbe-ecc*cbe)*tt - beta*(cbe-ecc)*sbe)*s/tt)*tt0; /* fctn(25+j) */
    else if (param==param_gamma) 
        return sbe;                                               /* fctn(15+j) */
    return 0.0;
}
Esempio n. 23
0
// NOTE: DOES NOT MAKE USE OF DT_SSB
void shapiro_delay(pulsar *psr,int npsr,int p,int i,double delt,double dt_SSB)
{
    double delay,ctheta,r,rsa[3],pospos;
    int j,k;
    const char *CVS_verNum = "$Id: c84eba620ca53ecafd5c05f54366aa1e6db7373a $";

    if (displayCVSversion == 1) CVSdisplayVersion("shapiro_delay.C","shapiro_delay()",CVS_verNum);

    if ((strcmp(psr[p].obsn[i].telID,"STL_BAT")==0) || psr[p].obsn[i].delayCorr==0) /* No correction */
        //if ( psr[p].obsn[i].delayCorr==0) /* No correction */
    {
        psr[p].obsn[i].shapiroDelaySun = 0.0;
        psr[p].obsn[i].shapiroDelayJupiter = 0.0;
    }
    else
    {
        for (k=0;k<3;k++)
            psr[p].obsn[i].psrPos[k] = psr[p].posPulsar[k]+delt*psr[p].velPulsar[k];      

        pospos = sqrt(psr[p].obsn[i].psrPos[0]*psr[p].obsn[i].psrPos[0]+
                psr[p].obsn[i].psrPos[1]*psr[p].obsn[i].psrPos[1]+
                psr[p].obsn[i].psrPos[2]*psr[p].obsn[i].psrPos[2]);
        for (k=0;k<3;k++)
            psr[p].obsn[i].psrPos[k] /= pospos;

        /* Note rsa = vector from observatory to centre of Sun */
        for (j=0;j<3;j++)
        {
            /* Require vector from solar system body (e.g. Sun) to observatory at the time of the 
             * closest approach of the photon to that body */
            if (strcmp(psr[p].obsn[i].telID,"STL_FBAT")==0)
                rsa[j] = -psr[p].obsn[i].sun_ssb[j] + psr[p].obsn[i].observatory_earth[j]; 
            else
                rsa[j] = -psr[p].obsn[i].sun_ssb[j] + psr[p].obsn[i].earth_ssb[j] + psr[p].obsn[i].observatory_earth[j]; 

            /*	  rsa[j] = -psr[p].obsn[i].sun_ssb[j] + psr[p].obsn[i].earthMoonBary_ssb[j] -
                  psr[p].obsn[i].earthMoonBary_earth[j] + psr[p].obsn[i].observatory_earth[j]; */
        }
        r = sqrt(dotproduct(rsa,rsa));
        ctheta = dotproduct(psr[p].obsn[i].psrPos,rsa)/r;  
        delay = -2.0*GM_C3 * log(r/AULTSC*(1.0+ctheta));/* Note log is `ln' not `log10' */
        psr[p].obsn[i].shapiroDelaySun = delay;
        //      printf("Have %g [%g %g %g; %g %g %g]\n",(double)delay,rsa[0],rsa[1],rsa[2],
        //	     psr[p].obsn[i].observatory_earth[0],psr[p].obsn[i].observatory_earth[1],
        //	     psr[p].obsn[i].observatory_earth[2]);

        if (strcmp(psr[p].obsn[i].telID,"STL_FBAT")!=0)
        {
            /* Now calculate the Shapiro delay due to Jupiter */
            for (j=0;j<3;j++)
                rsa[j] = psr[p].obsn[i].jupiter_earth[j] + psr[p].obsn[i].observatory_earth[j];
            r = sqrt(dotproduct(rsa,rsa));
            ctheta = dotproduct(psr[p].obsn[i].psrPos,rsa)/r;  
            delay = -2.0*GMJ_C3 * log(r/AULTSC*(1.0+ctheta));  
            psr[p].obsn[i].shapiroDelayJupiter = psr[p].planetShapiro*delay;
            //	  printf("ctheta = %g\n",ctheta);
            /* Now calculate the Shapiro delay due to Saturn */
            for (j=0;j<3;j++)
                rsa[j] = psr[p].obsn[i].saturn_earth[j] + psr[p].obsn[i].observatory_earth[j];
            r = sqrt(dotproduct(rsa,rsa));
            ctheta = dotproduct(psr[p].obsn[i].psrPos,rsa)/r;  
            delay = -2.0*GMS_C3 * log(r/AULTSC*(1.0+ctheta));  
            psr[p].obsn[i].shapiroDelaySaturn = psr[p].planetShapiro*delay;

            /* Now calculate the Shapiro delay due to Venus */
            for (j=0;j<3;j++)
                rsa[j] = psr[p].obsn[i].venus_earth[j] + psr[p].obsn[i].observatory_earth[j];
            r = sqrt(dotproduct(rsa,rsa));
            ctheta = dotproduct(psr[p].obsn[i].psrPos,rsa)/r;  
            delay = -2.0*GMV_C3 * log(r/AULTSC*(1.0+ctheta));  
            psr[p].obsn[i].shapiroDelayVenus = psr[p].planetShapiro*delay;

            /* Now calculate the Shapiro delay due to Uranus */
            for (j=0;j<3;j++)
                rsa[j] = psr[p].obsn[i].uranus_earth[j] + psr[p].obsn[i].observatory_earth[j];
            r = sqrt(dotproduct(rsa,rsa));
            ctheta = dotproduct(psr[p].obsn[i].psrPos,rsa)/r;  
            delay = -2.0*GMU_C3 * log(r/AULTSC*(1.0+ctheta));  
            psr[p].obsn[i].shapiroDelayUranus = psr[p].planetShapiro*delay;

            /* Now calculate the Shapiro delay due to Neptune */
            for (j=0;j<3;j++)
                rsa[j] = psr[p].obsn[i].neptune_earth[j] + psr[p].obsn[i].observatory_earth[j];
            r = sqrt(dotproduct(rsa,rsa));
            ctheta = dotproduct(psr[p].obsn[i].psrPos,rsa)/r;  
            delay = -2.0*GMN_C3 * log(r/AULTSC*(1.0+ctheta));  
            psr[p].obsn[i].shapiroDelayNeptune = psr[p].planetShapiro*delay;
        }
        else
        {
            psr[p].obsn[i].shapiroDelayNeptune = 0.0;
            psr[p].obsn[i].shapiroDelayJupiter = 0.0;
            psr[p].obsn[i].shapiroDelaySaturn = 0.0;
            psr[p].obsn[i].shapiroDelayUranus = 0.0;
            psr[p].obsn[i].shapiroDelayVenus = 0.0;
        }
    }
    recordPrecision(&psr[p],1.0e-10,"SS. Shapiro delay","Total guess!");
}
Esempio n. 24
0
void polyco(pulsar *psr,int npsr,longdouble polyco_MJD1,longdouble polyco_MJD2,int nspan,int ncoeff,
	    longdouble maxha,char *sitename,longdouble freq,longdouble coeff[MAX_COEFF],int trueDM,char* polyco_file)
{
  longdouble tsid = 1.0L/1.002737909L;
  longdouble tmidMJD;
  double doppler,rms;
  int dspan;
  char binPhase[32];
  int    i;
  longdouble afmjd;
  longdouble val[800];
  char date[12];
  longdouble tmin[800];
  double globalParameter,utc;
  int nsets;
  const char *CVS_verNum = "$Revision: 1.8 $";

  /* buffers for three polyco outputs -- any input from the user is
   * prepended to the default file names */
  char fname1[256];
  char fname2[256];
  char fname3[256];
  strcpy(fname1,polyco_file);
  strcpy(fname2,polyco_file);
  strcpy(fname3,polyco_file);
  strcat(fname1,"polyco_new.dat");
  strcat(fname2,"newpolyco.dat");
  strcat(fname3,"polyco.tim");

  /* erase any existing files */
  fclose(fopen(fname1,"w"));
  fclose(fopen(fname2,"w"));

  /* special flag for barycenter polycos */
  bool bary = strcmp(sitename,"@")==0 || strcasecmp(sitename,"bat")==0;


  if (displayCVSversion == 1) CVSdisplayVersion("polyco.C","polyco()",CVS_verNum);

  binPhase[0]='\0';

  /* Set some defaults */
  psr[0].param[param_track].paramSet[0]=0;
  globalParameter=0; 

  // Zap the output files so we can append days to them later
  fclose(fopen("polyco_new.dat","w"));
  fclose(fopen("newpolyco.dat","w"));

  for (afmjd=polyco_MJD1; afmjd <= polyco_MJD2; afmjd+=tsid)
    {
      /* Create some arrival times spread throughout the day */
      atimfake(psr,npsr,nspan,ncoeff,maxha,sitename,freq,afmjd,tmin,&tmidMJD,&dspan,&nsets,val);
      for (i=0;i<psr[0].nobs;i++)
	{
	  psr->obsn[i].clockCorr=(!bary);
	  psr->obsn[i].delayCorr=(!bary);
	  psr->obsn[i].phaseOffset = 0.0;
	}
    /* Use reference phase TZR information unless at bary.*/
    if (strcmp(psr->tzrsite,"@")!=0) {
      psr->obsn[0].clockCorr=1;
      psr->obsn[0].delayCorr=1;
    }
    else {
      psr->obsn[0].clockCorr=0;
      psr->obsn[0].delayCorr=0;
    }
      writeTim(fname3,psr,"tempo2"); 
      formBatsAll(psr,npsr);
      formResiduals(psr,npsr,0);
      tzFit(psr,npsr,tmin,&doppler,&rms,&utc,tmidMJD,ncoeff,coeff,binPhase,nsets,afmjd,sitename,nspan,
	    freq,date,val,trueDM,polyco_file);
    }      
  if (psr->tempo1==0)
    printf("WARNING: Should probably use -tempo1 option\n");
}
Esempio n. 25
0
double DDKmodel(pulsar *psr,int p,int ipos,int param)
{
    double an;
    double pb,k;
    double rad2deg = 180.0/M_PI;
    double SUNMASS = 4.925490947e-6;
    double m2,tt0,t0,ecc,er,xdot,edot,dr,dth,eth,am2,ct;
    double pbdot,xpbdot,phase,u,du,gamma;
    double orbits;
    int norbits;
    double  cu,onemecu,cae,sae,ae,omega,omz,sw,cw,alpha,beta,bg,dre,drep,drepp,anhat,su;
    double sqr1me2,cume,brace,si,dlogbr,ds,da,a0,b0,d2bar,torb,ci;
    double csigma,ce,cx,comega,cgamma,cm2,csi;
    double sin_omega,cos_omega,ki;
    double pmra,pmdec;
    double ki_dot,sini,cosi,tani,delta_i0,delta_j0,asi;
    double cos_alpha,sin_alpha,cos_delta,sin_delta,xpr,ypr,dpara;
    double pxConv = 1.74532925199432958E-2/3600.0e3;
    const char *CVS_verNum = "$Id: 00e147dbc7b94e7ac05a8d500b2972b081ac9df1 $";

    if (displayCVSversion == 1) CVSdisplayVersion("DDKmodel.C","DDKmodel()",CVS_verNum);

    dr  = 0.0; /* WHAT SHOULD THESE BE SET TO? */
    dth = 0.0; 

    /* Obtain KOM: the longitude of the ascending node */
    sin_omega = sin(psr[p].param[param_kom].val[0]*M_PI/180.0);
    cos_omega = cos(psr[p].param[param_kom].val[0]*M_PI/180.0);

    /* ... and KIN, the inclination angle */
    ki = psr[p].param[param_kin].val[0]*M_PI/180.0;       
    si = sin(ki);
    ci = cos(ki);
    //ti = si/ci;

    /* Obtain proper motion in radians/sec */
    pmra  = psr[p].param[param_pmra].val[0]*M_PI/(180.0*3600.0e3)/(365.25*86400.0);
    pmdec = psr[p].param[param_pmdec].val[0]*M_PI/(180.0*3600.0e3)/(365.25*86400.0);

    /* Obtain parallax */
    if (psr[p].param[param_px].paramSet[0]==1)
        dpara = psr[p].param[param_px].val[0]*pxConv;
    else dpara = 0.0;

    /* Obtain vector pointing at the pulsar */
    sin_delta = psr[p].obsn[ipos].psrPos[2];
    cos_delta = cos(asin(sin_delta));
    sin_alpha = psr[p].obsn[ipos].psrPos[1]/cos_delta;
    cos_alpha = psr[p].obsn[ipos].psrPos[0]/cos_delta;

    if (psr[p].param[param_m2].paramSet[0]==1) am2 = psr[p].param[param_m2].val[0];
    else am2 = 0.0;

    pb = psr[p].param[param_pb].val[0]*SECDAY;
    an = 2.0*M_PI/pb;
    k = psr[p].param[param_omdot].val[0]/(rad2deg*365.25*86400.0*an);

    m2 = am2*SUNMASS;
    t0 = psr[p].param[param_t0].val[0];
    ct = psr[p].obsn[ipos].bbat;    

    tt0 = (ct-t0)*SECDAY;

    if (psr[p].param[param_gamma].paramSet[0]==1)
        gamma = psr[p].param[param_gamma].val[0];
    else
        gamma = 0.0;
    a0    = 0.0; /* WHAT SHOULD THIS BE SET TO? */
    b0    = 0.0; /* WHAT SHOULD THIS BE SET TO? */

    if (psr[p].param[param_om].paramSet[0]==1) omz = psr[p].param[param_om].val[0]*M_PI/180.0;
    else omz = 0.0;

    if (psr[p].param[param_a1dot].paramSet[0]==1) xdot  = psr[p].param[param_a1dot].val[0];
    else xdot  = 0.0;

    if (psr[p].param[param_pbdot].paramSet[0] == 1) pbdot = psr[p].param[param_pbdot].val[0];
    else pbdot = 0.0;

    if (psr[p].param[param_edot].paramSet[0] == 1) edot = psr[p].param[param_edot].val[0];
    else edot = 0.0;

    if (psr[p].param[param_xpbdot].paramSet[0] == 1) xpbdot = psr[p].param[param_xpbdot].val[0];
    else xpbdot = 0.0;


    asi = psr[p].param[param_a1].val[0]+xdot*tt0;
    ecc = psr[p].param[param_ecc].val[0]+edot*tt0;
    er = ecc*(1.0+dr);
    eth = ecc*(1.0+dth);

    /* Equation 10 in Kopeikin 1996 */
    ki_dot = -pmra * sin_omega + pmdec*cos_omega;
    ki    += ki_dot*tt0;
    sini = sin(ki);
    cosi = cos(ki);
    tani = sini/cosi;

    /* Equation 8 in Kopeikin 1996 */
    asi += (asi*ki_dot/tani)*tt0;
    /* Equation 9 in Kopeikin 1996 */
    omz += (pmra*cos_omega+pmdec*sin_omega)/sini*tt0;


    /* Now modify x and omega due to the annual-orbital parallax term 
     * as described in Kopeikin 1995 
     *
     * Require knowledge of the barycentric earth position vector - earth_ssb
     */

    /* Equation 15 in Kopeikin 1995 */
    delta_i0 = -psr[p].obsn[ipos].earth_ssb[0]/AULTSC*sin_alpha+
        psr[p].obsn[ipos].earth_ssb[1]/AULTSC*cos_alpha;
    /* Equation 16 in Kopeikin 1995 */
    delta_j0 = -psr[p].obsn[ipos].earth_ssb[0]/AULTSC*sin_delta*cos_alpha-
        psr[p].obsn[ipos].earth_ssb[1]/AULTSC*sin_delta*sin_alpha+
        psr[p].obsn[ipos].earth_ssb[2]/AULTSC*cos_delta;

    xpr = delta_i0*sin_omega - delta_j0*cos_omega;
    ypr = delta_i0*cos_omega + delta_j0*sin_omega;

    /* Equations 18 and 19 in Kopeikin 1995 */
    asi += asi/tani * dpara * xpr;
    si  += ci*dpara*xpr;
    omz -= 1.0/si*dpara*ypr;

    /* Continue as for the DD model now that asi and omz have been updated */
    orbits  = tt0/pb - 0.5*(pbdot+xpbdot)*pow(tt0/pb,2);
    norbits = (int)orbits;
    if (orbits<0.0) norbits--;
    phase=2.0*M_PI*(orbits-norbits);
    /*  Compute eccentric anomaly u by iterating Kepler's equation. */
    u=phase+ecc*sin(phase)*(1.0+ecc*cos(phase));
    do {
        du=(phase-(u-ecc*sin(u)))/(1.0-ecc*cos(u));
        u=u+du;
    } while (fabs(du)>1.0e-12);

    /*  DD equations 17b, 17c, 29, and 46 through 52 */
    su=sin(u);
    cu=cos(u);
    onemecu=1.0-ecc*cu;
    cae=(cu-ecc)/onemecu;
    sae=sqrt(1.0-pow(ecc,2))*su/onemecu;
    ae=atan2(sae,cae);
    if(ae<0.0) ae=ae+2.0*M_PI;
    ae=2.0*M_PI*orbits + ae - phase;
    omega=omz + k*ae;
    sw=sin(omega);
    cw=cos(omega);
    alpha=asi*sw;
    beta=asi*sqrt(1-pow(eth,2))*cw;
    bg=beta+gamma;
    dre=alpha*(cu-er) + bg*su;
    drep=-alpha*su + bg*cu;
    drepp=-alpha*cu - bg*su;
    anhat=an/onemecu;

    /* DD equations 26, 27, 57: */
    sqr1me2=sqrt(1-pow(ecc,2));
    cume=cu-ecc;
    brace=onemecu-si*(sw*cume+sqr1me2*cw*su);
    dlogbr=log(brace);
    ds=-2*m2*dlogbr;
    da=a0*(sin(omega+ae) + ecc*sw) + b0*(cos(omega+ae) + ecc*cw);

    /*  Now compute d2bar, the orbital time correction in DD equation 42. */
    d2bar=dre*(1-anhat*drep+(pow(anhat,2))*(pow(drep,2) + 0.5*dre*drepp -
                0.5*ecc*su*dre*drep/onemecu)) + ds + da;
    torb=-d2bar;

    if (param==-1) return torb;

    /*  Now we need the partial derivatives. Use DD equations 62a - 62k. */
    csigma=asi*(-sw*su+sqr1me2*cw*cu)/onemecu;
    ce=su*csigma-asi*sw-ecc*asi*cw*su/sqr1me2;
    cx=sw*cume+sqr1me2*cw*su;
    comega=asi*(cw*cume-sqr1me2*sw*su);
    cgamma=su;
    //cdth=-ecc*ecc*asi*cw*su/sqr1me2;
    cm2=-2*dlogbr;
    csi=2*m2*(sw*cume+sqr1me2*cw*su)/brace; 

    if (param==param_pb)
        return -csigma*an*SECDAY*tt0/(pb*SECDAY); 
    else if (param==param_a1)
        return cx;
    else if (param==param_ecc)
        return ce;
    else if (param==param_om)
        return comega;
    else if (param==param_omdot)
        return ae*comega/(an*360.0/(2.0*M_PI)*365.25*SECDAY);
    else if (param==param_t0)
        return -csigma*an*SECDAY;
    else if (param==param_pbdot)
        return 0.5*tt0*(-csigma*an*SECDAY*tt0/(pb*SECDAY));
    else if (param==param_sini)
        return csi;
    else if (param==param_gamma)
        return cgamma;
    else if (param==param_m2)
        return cm2*SUNMASS;
    else if (param==param_a1dot) /* Also known as xdot */
        return cx*tt0;

    /* Should calculate and return Kopeikin parameters */
    return 0;
}
Esempio n. 26
0
void get_obsCoord(pulsar *psr,int npsr)
{
  double ph,eeq[3];
  int i,j,k; 
  double prn[3][3];
  double pc,oblq,toblq;
  double siteCoord[3];
  double erad,hlt,alng,hrd,tsid,sdd,speed,sitera;
  int p;
  observatory *obs;
  const char *CVS_verNum = "$Revision: 1.8 $";

  if (displayCVSversion == 1) CVSdisplayVersion("get_obsCoord.C","get_obsCoord()",CVS_verNum);

  for (p=0;p<npsr;p++)
    {
       for (i=0;i<psr[p].nobs;i++)
	{ 
	  if (psr[p].obsn[i].delayCorr!=0)
	    {	     
	      if (strcmp(psr[p].obsn[i].telID,"STL")==0 ||
		  strcmp(psr[p].obsn[i].telID,"STL_FBAT")==0) // Satellite
		{
		  psr[p].obsn[i].siteVel[0] = 0.0;
		  psr[p].obsn[i].siteVel[1] = 0.0;
		  psr[p].obsn[i].siteVel[2] = 0.0;		  

		  // Set from the TELX, TELY, TELZ parameters
		  if (psr[p].param[param_telx].paramSet[0] == 1)
		    {
		      longdouble arg,deltaT,t0,pos;

		      if (psr[p].param[param_telEpoch].paramSet[0]==1)
			t0 = psr[p].param[param_telEpoch].val[0];
		      else
			t0 = 0.0L;

		      deltaT = (psr[p].obsn[i].sat - t0)*SECDAY;		
		      arg = deltaT;
		      pos = psr[p].param[param_telx].val[0];
		      if (psr[p].param[param_telx].paramSet[1] == 1) {
			pos += psr[p].param[param_telx].val[1]*arg;
			if (psr[p].param[param_telEpoch].paramSet[0]==0)
			  {
			    printf("ERROR: Using telescope velocity without setting telEpoch\n");
			    exit(1);
			  }
		      }
		      arg *= deltaT; if (psr[p].param[param_telx].paramSet[2] == 1) pos += (0.5*psr[p].param[param_telx].val[2]*arg);
		      arg *= deltaT; if (psr[p].param[param_telx].paramSet[3] == 1) pos += (1.0L/6.0L*psr[p].param[param_telx].val[3]*arg);
		      psr[p].obsn[i].observatory_earth[0] = (double)pos;
		      printf("Setting x to %g\n",(double)psr[p].obsn[i].observatory_earth[0]);
		    }
		  if (psr[p].param[param_tely].paramSet[0] == 1)
		    {
		      longdouble arg,deltaT,t0,pos;

		      if (psr[p].param[param_telEpoch].paramSet[0]==1)
			t0 = psr[p].param[param_telEpoch].val[0];
		      else
			t0 = 0.0L;

		      deltaT = (psr[p].obsn[i].sat - t0)*SECDAY;		
		      arg = deltaT;
		      pos = psr[p].param[param_tely].val[0];
		      if (psr[p].param[param_tely].paramSet[1] == 1) pos += psr[p].param[param_tely].val[1]*arg;
		      arg *= deltaT; if (psr[p].param[param_tely].paramSet[2] == 1) pos += (0.5*psr[p].param[param_tely].val[2]*arg);
		      arg *= deltaT; if (psr[p].param[param_tely].paramSet[3] == 1) pos += (1.0L/6.0L*psr[p].param[param_tely].val[3]*arg);
		      psr[p].obsn[i].observatory_earth[1] = (double)pos;
		      printf("Setting y to %g\n",(double)psr[p].obsn[i].observatory_earth[1]);
		    }
		  if (psr[p].param[param_telz].paramSet[0] == 1)
		    {
		      longdouble arg,deltaT,t0,pos;

		      if (psr[p].param[param_telEpoch].paramSet[0]==1)
			t0 = psr[p].param[param_telEpoch].val[0];
		      else
			t0 = 0.0L;

		      deltaT = (psr[p].obsn[i].sat - t0)*SECDAY;		
		      arg = deltaT;
		      pos = psr[p].param[param_telz].val[0];
		      if (psr[p].param[param_telz].paramSet[1] == 1) pos += psr[p].param[param_telz].val[1]*arg;
		      arg *= deltaT; if (psr[p].param[param_telz].paramSet[2] == 1) pos += (0.5*psr[p].param[param_telz].val[2]*arg);
		      arg *= deltaT; if (psr[p].param[param_telz].paramSet[3] == 1) pos += (1.0L/6.0L*psr[p].param[param_telz].val[3]*arg);
		      psr[p].obsn[i].observatory_earth[2] = (double)pos;
		      printf("Setting z to %g\n",(double)psr[p].obsn[i].observatory_earth[2]);
		    }



		  //		  printf("Setting observatory coordinates for TOA %d\n",i);
		  // Now check flags to obtain the telescope coordinates for this time
		  for (k=0;k<psr[p].obsn[i].nFlags;k++)
		    {
		      //
		      // NOTE: For a STL_FBAT setting OBSERVATORY->BAT not OBSERVATORY->EARTH
		      // The terminology is misleading
		      //
		      if (strcmp(psr[p].obsn[i].flagID[k],"-telx")==0){
			sscanf(psr[p].obsn[i].flagVal[k],"%lf",&psr[p].obsn[i].observatory_earth[0]);
			if (strcmp(psr[p].obsn[i].telID,"STL")==0) psr[p].obsn[i].observatory_earth[0]/=SPEED_LIGHT;
		      }
		      if (strcmp(psr[p].obsn[i].flagID[k],"-tely")==0){
			sscanf(psr[p].obsn[i].flagVal[k],"%lf",&psr[p].obsn[i].observatory_earth[1]);
			if (strcmp(psr[p].obsn[i].telID,"STL")==0) psr[p].obsn[i].observatory_earth[1]/=SPEED_LIGHT;
		      }
		      if (strcmp(psr[p].obsn[i].flagID[k],"-telz")==0){
			sscanf(psr[p].obsn[i].flagVal[k],"%lf",&psr[p].obsn[i].observatory_earth[2]);		      
			if (strcmp(psr[p].obsn[i].telID,"STL")==0) psr[p].obsn[i].observatory_earth[2]/=SPEED_LIGHT;
		      }
			
		    }
		}
	      else if (strcmp(psr[p].obsn[i].telID,"STL_BAT")==0) // Satellite in barycentric coordinates
		{
		  psr[p].obsn[i].siteVel[0] = 0.0;
		  psr[p].obsn[i].siteVel[1] = 0.0;
		  psr[p].obsn[i].siteVel[2] = 0.0;
		  psr[p].obsn[i].observatory_earth[0] = 0.0;
		  psr[p].obsn[i].observatory_earth[1] = 0.0;
		  psr[p].obsn[i].observatory_earth[2] = 0.0;
		  psr[p].correctTroposphere = 0;
		}
	      else
		{
		  obs = getObservatory(psr[p].obsn[i].telID);
		  // Check for override:
		  if (strcmp(psr[p].obsn[i].telID,"IMAG")==0)
		    {
		      //
		      // Must check what is happening to other parameters - such as velocities
		      //
		      for (k=0;k<psr[p].obsn[i].nFlags;k++)
			{
			  if (strcmp(psr[p].obsn[i].flagID[k],"-telx")==0){
			    sscanf(psr[p].obsn[i].flagVal[k],"%lf",&obs->x);
			  }
			  if (strcmp(psr[p].obsn[i].flagID[k],"-tely")==0){
			    sscanf(psr[p].obsn[i].flagVal[k],"%lf",&obs->y);
			  }
			  if (strcmp(psr[p].obsn[i].flagID[k],"-telz")==0){
			    sscanf(psr[p].obsn[i].flagVal[k],"%lf",&obs->z);		      
			  }
			}		
		    }
		  // New way
		  if (psr[p].t2cMethod == T2C_IAU2000B)
		    {
		      double trs[3], zenith_trs[3];
		      trs[0]=obs->x;
		      trs[1]=obs->y;
		      trs[2]=obs->z;
		      zenith_trs[0]= obs->height_grs80 
			* cos(obs->longitude_grs80) * cos(obs->latitude_grs80);
		      zenith_trs[1]= obs->height_grs80 
			* sin(obs->longitude_grs80) * cos(obs->latitude_grs80);
		      zenith_trs[2] = obs->height_grs80*sin(obs->latitude_grs80);
		      long double utc = psr[p].obsn[i].sat;
		      if (psr[p].obsn[i].clockCorr!=0 && psr[p].obsn[i].clockCorr!=2)
			utc += getCorrection(psr[p].obsn+i, 
					     psr[p].clockFromOverride,
					     "UTC", psr[p].noWarnings)/SECDAY;
		      get_obsCoord_IAU2000B(trs, zenith_trs,
					    psr[p].obsn[i].sat
					    +getCorrectionTT(psr[p].obsn+i)/SECDAY,
					    utc,
					    psr[p].obsn[i].observatory_earth,
					    psr[p].obsn[i].zenith,
					    psr[p].obsn[i].siteVel);
		    }
		  else {
		    psr[p].obsn[i].zenith[0]=psr[p].obsn[i].zenith[1]=psr[p].obsn[i].zenith[2]=0.0; // Only calc'd by IAU code
		    //	      if (	psr[p].obsn[i].zenith[2]==0.0)
		    erad = sqrt(obs->x*obs->x+obs->y*obs->y+obs->z*obs->z);//height(m)
		    hlt  = asin(obs->z/erad); // latitude
		    alng = atan2(-obs->y,obs->x); // longitude
		    hrd  = erad/(2.99792458e8*499.004786); // height (AU)
		    siteCoord[0] = hrd * cos(hlt) * 499.004786; // dist from axis (lt-sec)
		    siteCoord[1] = siteCoord[0]*tan(hlt); // z (lt-sec)
		    siteCoord[2] = alng; // longitude
		    
		    /* PC,PS equatorial and meridional components of nutations of longitude */      
		    toblq = (psr[p].obsn[i].sat+2400000.5-2451545.0)/36525.0;
		    oblq = (((1.813e-3*toblq-5.9e-4)*toblq-4.6815e1)*toblq +84381.448)/3600.0;
		    
		    pc = cos(oblq*M_PI/180.0+psr[p].obsn[i].nutations[1])*psr[p].obsn[i].nutations[0];
		    
		    /* TSID = sidereal time (lmst, timcalc -> obsite) */
		    
		    lmst(psr[p].obsn[i].sat+psr[p].obsn[i].correctionUT1/SECDAY
			 ,0.0,&tsid,&sdd);
		    tsid*=2.0*M_PI;
		    
		    /* Compute the local, true sidereal time */
		    ph = tsid+pc-siteCoord[2];  
		    /* Get X-Y-Z coordinates taking out earth rotation */
		    eeq[0] = siteCoord[0]*cos(ph); 
		    eeq[1] = siteCoord[0]*sin(ph);
		    eeq[2] = siteCoord[1];
		    
		    /* Now obtain PRN -- the precession matrix */
		    get_precessionMatrix(prn,(double)psr[p].obsn[i].sat
					 +psr[p].obsn[i].correctionUT1/SECDAY
					 ,psr[p].obsn[i].nutations[0],
					 psr[p].obsn[i].nutations[1]);
		    /* Calculate the position after precession/nutation*/
		    for (j=0;j<3;j++)
		      psr[p].obsn[i].observatory_earth[j]=prn[j][0]*eeq[0]+prn[j][1]*eeq[1]+prn[j][2]*eeq[2]; 
		    /* Rotate vector if we are working in ecliptic coordinates */
		    if (psr[p].eclCoord==1) equ2ecl(psr[p].obsn[i].observatory_earth);
		    
		    /* Calculate observatory velocity w.r.t. geocentre (1950.0)!!!! <<<<<<< */
		    speed = 2.0*M_PI*siteCoord[0]/(86400.0/1.00273);
		    sitera = 0.0;
		    if (speed>1.0e-10) sitera = atan2(psr[p].obsn[i].observatory_earth[1],
						      psr[p].obsn[i].observatory_earth[0]);
		    psr[p].obsn[i].siteVel[0] = -sin(sitera)*speed;
		    psr[p].obsn[i].siteVel[1] =  cos(sitera)*speed;
		    psr[p].obsn[i].siteVel[2] =  0.0;
		    if (psr[p].eclCoord==1) equ2ecl(psr[p].obsn[i].siteVel);
		    
		    /* Technically if using TDB these coordinates should be 
		       transformed to that frame. In practise it doesn't matter,
		       we're only talking about 0.3 ns, or 2.5e-14 in v/c */
		    
		    /* hack to transform for faked values of "K" */
		    //  	      vectorscale(psr[p].obsn[i].observatory_earth, 1.15505);
		    //  	      vectorscale(psr[p].obsn[i].siteVel, 1.15505);
		  }
		}
	    }
	  else if (i==0)
	    printf("Delay correction turned off for psr %d\n", p);
	}
    }
}
Esempio n. 27
0
double T2model(pulsar *psr,int p,int ipos,int param,int arr)
{
    double an;
    double pb,omdot;
    double rad2deg = 180.0/M_PI;
    double SUNMASS = 4.925490947e-6;
    longdouble tt0,t0,ct,t0asc;
    double m2,x,ecc,er,xdot,edot,dr,dth,eth;
    double pbdot,xpbdot,phase,u,gamma;
    double orbits;
    int    norbits;
    double cu,onemecu=0,cae,sae,ae,omega,omz,sw,cw,alpha,beta,bg,dre,drep,drepp,
           anhat,su=0;
    double sqr1me2,cume,brace,si,dlogbr,ds,da,a0,b0,d2bar,torb;
    double csigma,ce,cx,comega,cgamma,cdth,cm2,csi, ckom, ckin;
    double eps1,eps2,eps1dot,eps2dot;
    double ceps1,ceps2;
    double shapmax,cshapmax,sdds;
    int    com,com1,com2;
    int    allTerms=1;            /* = 0 to emulate BT model */
    double dpara;
    double pmra,pmdec;
    double sin_omega,cos_omega,ki;
    double mtot,m1,xk,xomdot,afac,kom;
    longdouble DK011,DK012, DK021, DK022, DK031,DK032, DK041,DK042,C,S;
    longdouble DK013, DK014, DK023, DK024, DK033, DK034, DK043, DK044;
    longdouble DAOP=longdouble(0.0), DSR=longdouble(0.0);
    longdouble DOP=longdouble(0.0); // Orbital parallax time delay
    double daop;// DAOP is the time delay due to annual orbital
    // parallax. daop is the aop distance.

    longdouble h3,h4,stig;
    longdouble lgf,TrueAnom;
    longdouble lsc, fs;
    int nharm=4;
    int mode = -1; // See ELL1Hmodel.C

    torb = 0.0;
    const char *CVS_verNum = "$Id: d5e412cf859761421154f47be2a083ae696d674f $";


    if (displayCVSversion == 1) 
        CVSdisplayVersion("T2model.C","T2model()",CVS_verNum);

    if (param==-1) 
    {
        com1 = 0;
        com2 = psr[p].nCompanion;
    }
    else
    {
        com1 = arr;
        com2 = arr+1;
    }

    //    printf("Number of companions = %d %d\n",com1,com2);

    for (com = com1; com < com2;com++)
    {      
        /* Obtain Keplerian parameters */   
        getKeplerian(&psr[p],com,&pb,&t0,&ecc,&omz,&x,&eps1,&eps2,&t0asc,
                &shapmax,&kom,&ki);
        /* Now add in the jumps */
        addKeplerianJumps(&psr[p],ipos,&torb,&x,&ecc,&omz,&pb);
        /* Parameters derived from the Keplerian parameters */
        deriveKeplerian(pb,kom,&an,&sin_omega,&cos_omega);
        /* Obtain post-Keplerian parameters */
        getPostKeplerian(&psr[p],com,an,&si,&m2,&mtot,&omdot,&gamma,&xdot,&xpbdot,
                &pbdot,&edot,&pmra,&pmdec,&dpara,&dr,&dth,&a0,&b0,
                &xomdot,&afac,&eps1dot,&eps2dot,&daop);

        /* If the beta-prime parameters are set then omdot, gamma, si, dr, er, 
           dth, a0 and b0 can be calculated from the beta-prime values
         * - see papers of Taylor, Wolszczan, Damour & Weisberg 1992 - Nature
         *                 Damour & Taylor 1992 - Phys Rev D
         */
        if (psr[p].param[param_bp].paramSet[0]==1 && 
                psr[p].param[param_bpp].paramSet[0]==1)
        {
            /*	  useBeta(psr[p]); */
            printf("Beta model not implemented yet\n");
        }

        /* If general relativity is assummed to be correct and 
         * the total system mass has been determined then the values 
         * of dr,dth,er, eth, sini, gamma and pbdot can be calculated
         */
        if (psr[p].param[param_mtot].paramSet[com]==1)
        {
            calcGR(mtot,m2,x,ecc,an,afac,(double)psr[p].param[param_f].val[0],
                    &dr,&dth,&er,&eth,&xk,&si,&gamma,&pbdot,&a0,&b0);
            omdot   = xomdot + xk; 
        }
        /* Derive parameters from the post-Keplerian parameters */
        derivePostKeplerian(mtot,m2,dr,dth,ecc,&m1,&er,&eth);
        /* Obtain delta T */
        ct  = psr[p].obsn[ipos].bbat;      
        if (psr[p].param[param_t0].paramSet[com]==1)        
            tt0 = (ct-t0)*SECDAY;
        else if( psr[p].param[param_tasc].paramSet[com]==1) 
            tt0 = (ct-t0asc)*SECDAY;
        else {
            printf("ERROR [T2] T0 or TASC needs to be set in the parameter file\n");
            exit(1);
        }
        //      logdbg("going to update Parameters");
        /* Update parameters with their time derivatives */
        updateParameters(edot,xdot,eps1dot,eps2dot,tt0,&ecc,&x,&eps1,&eps2);
        //      logdbg("updated parameters");

        /* Do some checks */
        if (ecc < 0.0 || ecc > 1.0)
        {
            displayMsg(1,"BIN2","Eccentricity of orbit < 0, setting to 0","",
                    psr[p].noWarnings);
            psr[p].param[param_ecc].val[com]=0.0;
            ecc = 0.0;
        }

        /* Obtain number of orbits in tt0 */
        orbits  = tt0/pb - 0.5*(pbdot+xpbdot)*pow(tt0/pb,2);
        norbits = (int)orbits;
        if (orbits<0.0) norbits--;

        /* Obtain phase of orbit */
        phase=2.0*M_PI*(orbits-norbits);
        //      ld_printf("Orbit phase = %.15Lf %.15g\n",psr[p].obsn[ipos].bbat,phase);
        if (psr[p].param[param_ecc].paramSet[com]==1)
        {
            //          logdbg("going to compute U");
            /* Compute eccentric anomaly u by iterating Kepler's equation */	 
            computeU(phase,ecc,&u);
            //          logdbg("computed U");
            /*  DD equations 17b and 17c */
            su=sin(u); cu=cos(u);
            onemecu=1.0-ecc*cu;
            cae=(cu-ecc)/onemecu;                         /* Equation 17b */
            sae=sqrt(1.0-pow(ecc,2))*su/onemecu;          /* Equation 17c */
            ae=atan2(sae,cae);
            if(ae<0.0) ae=ae+2.0*M_PI;
            ae=2.0*M_PI*orbits + ae - phase;
            omega=omz/rad2deg + omdot*ae;
            sw=sin(omega);
            cw=cos(omega);
            //          logdbg("In the middle of DD");
            /* DD equations 26, 27, 57: */
            sqr1me2=sqrt(1-pow(ecc,2));
            cume=cu-ecc;
            //          logdbg("going to Kopeikin");
            /* Update parameters due to proper motion - Kopeikin 1996 */
            /* And annual-orbital and orbital parallax - Kopeikin 1995 */
            if (psr[p].param[param_kin].paramSet[com]==1 && 
                    psr[p].param[param_kom].paramSet[com]==1 &&
                    (psr[p].param[param_pmra].paramSet[com]==1 || 
                     psr[p].param[param_pmdec].paramSet[com]==1))
            {
                //              logdbg("going to do KopeikinTerms");
                KopeikinTerms(&psr[p],ipos,ki,pmra,sin_omega,pmdec,cos_omega,tt0,
                        dpara,daop,si,&x,&DK011,&DK012,&DK021,&DK022,
                        &DK031,&DK032,&DK041,&DK042,&DK013,&DK014,&DK023,
                        &DK024,&DK033,&DK034,&DK043,&DK044);
                //              logdbg("did KopeikinTerms");
                C = (longdouble)(cw*(cu-er)-sqrt(1.0-pow(eth,2.0))*sw*su);
                S = (longdouble)(sw*(cu-er)+cw*sqrt(1.0-pow(eth,2.0))*su);
                DAOP = (DK011+DK012)*C-(DK021+DK022)*S;
                DSR = (DK031+DK032)*C+(DK041+DK042)*S;
                DOP = dpara/AULTSC/2.0*pow(x,2.0)*
                    ( pow( sin( ki ), -2.0 ) - 0.5 + 0.5 * pow( ecc, 2.0 ) *
                      ( 1 + pow( sw, 2.0 ) - 3.0 / pow( sin( ki ), 2.0 ) ) -
                      2.0 * ecc * ( pow( sin( ki ), -2.0 ) - pow( sw, 2.0 ) ) * 
                      cume - sqr1me2 * 2 * sw * cw * su * cume + 0.5 * 
                      ( cos( 2.0 * omega ) + pow( ecc, 2.0 ) * 
                        ( pow( sin( ki ), -2.0 ) + pow( cu, 2.0 ) ) ) *
                      cos( 2.0 * u ) );

                //	      printf("T2model: %g DAOP = %g DSR = %g DOP = %g\n",(double)psr[p].obsn[ipos].bbat,(double)DAOP,(double)DSR,(double)DOP);

                //                logdbg("DAOP is %g and DSR is %g\n", (double)DAOP, (double)DSR);
                //                logdbg("DAOP is %g, DK011 and DK021 are %f and %f\n",
                //                       (double)DAOP,(double)DK011,(double)DK021);
            }


            if (psr[p].param[param_shapmax].paramSet[com]==1)  /* DDS model */
            {
                sdds  = 1.0 - exp(-1.0*shapmax);
                brace = onemecu-sdds*(sw*cume+sqr1me2*cw*su);
            }
            else
                brace=onemecu-si*(sw*cume+sqr1me2*cw*su);

            da=a0*(sin(omega+ae) + ecc*sw) + b0*(cos(omega+ae) + 
                    ecc*cw); /* Equation 27 */

            /* DD equations 46 to 51 */	  
            alpha=x*sw;                                   /* Equation 46  */
            beta=x*sqrt(1-pow(eth,2))*cw;                 /* Equation 47  */
            bg=beta+gamma;
            dre=alpha*(cu-er) + bg*su;                    /* Equation 48  */
            drep=-alpha*su + bg*cu;                       /* Equation 49  */
            drepp=-alpha*cu - bg*su;                      /* Equation 50  */
            anhat=an/onemecu;                             /* Equation 51  */

            dlogbr=log(brace);
            ds=-2*m2*dlogbr;        /* Equation 26 */

        }
        else if (psr[p].param[param_eps1].paramSet[com]==1)  /* ELL1 model */
        {
            dre  = x*(sin(phase)-0.5*(eps1*cos(2.0*phase)-eps2*sin(2.0*phase)));
            drep = x*cos(phase);
            drepp=-x*sin(phase);
            //          logdbg("going to Kopeikin");
            /* Update parameters due to proper motion - Kopeikin 1996 */
            if (psr[p].param[param_kin].paramSet[com]==1 && 
                    psr[p].param[param_kom].paramSet[com]==1 &&
                    (psr[p].param[param_pmra].paramSet[com]==1 || 
                     psr[p].param[param_pmdec].paramSet[com]==1))
            {
                S = (sin(phase)-0.5*(eps1*cos(2.0*phase)-eps2*sin(2.0*phase)));
                C = cos(phase)+0.5*(eps2*cos(2.0*phase)+eps1*sin(2.0*phase));
                KopeikinTerms(&psr[p],ipos,ki,pmra,sin_omega,pmdec,cos_omega,tt0,
                        dpara,daop,si,&x,&DK011,&DK012,&DK021,&DK022,
                        &DK031,&DK032,&DK041,&DK042,&DK013,&DK014,&DK023,
                        &DK024,&DK033,&DK034,&DK043,&DK044);
                DAOP = (DK011+DK012)*C-(DK021+DK022)*S;
                DSR = (DK031+DK032)*C+(DK041+DK042)*S;
            }

            brace=1-si*sin(phase);
            da=a0*sin(phase)+b0*cos(phase);  

            anhat = an; ecc = 0.0;


            /* Shapiro delay */
            if ( psr[p].param[param_h3].paramSet[0] * psr[p].param[param_stig].paramSet[0] == 1 
                    || psr[p].param[param_h3].paramSet[0] * psr[p].param[param_h4].paramSet[0] == 1){

                //	    printf("Using the Friere & Wex formalism for the Shapiro delay\n");
                // Based on ELL1Hmodel.C

                //h3 = psr[p].param[param_h3].val[0];
                h3 = getParameterValue( &psr[p], param_h3, 0 );

                // Determine fw10 mode
                if( psr[p].param[param_h4].paramSet[0] == 1 ){
                    //	      h4 = psr[p].param[param_h4].val[0];
                    h4 = getParameterValue( &psr[p], param_h4, 0 );
                    // mode 2 or 3 take preference over mode 1 as they are more stable
                    if( psr[p].param[param_nharm].paramSet[0] == 1 ){
                        nharm = (int)psr[p].param[param_nharm].val[0];
                        //nharm = (int)getParameterValue( &psr[p], param_nharm, 0 );
                        if( nharm > 4 )
                            mode = 3;
                        else
                            mode = 2;
                    }
                    if( psr[p].param[param_stig].paramSet[0] == 1 ){
                        // Conflict. Unsure whether to select mode 1 or modes 2/3, so will default
                        // to the most stable one.
                        logerr("You specified both H4 and STIG - Ignoring STIG");
                        logmsg( "WARNING! You specified both H4 and STIG." );
                        logmsg( "We will ignore STIG and perform the approx. H4 fit instead." );
                        logmsg( "If you want to perform the exact fit for H3 and STIG, then " );
                        logmsg( "please remove H4 from your parameter file.");
                    }
                    // Have H3, H4, but no NHARM
                    mode = 2;
                }else{ 
                    // Have H3, but no H4
                    if( psr[p].param[param_stig].paramSet[0] == 1 ){
                        //		stig = psr[p].param[param_stig].val[0];
                        stig = getParameterValue( &psr[p], param_stig, 0 );
                        mode = 1;
                    }else{
                        mode = 0;
                        h4 = 0;
                        nharm = 3;
                    }
                }// fw10 mode determined.

                // Define sin(i) and m2 for calculation of the orbital phases etc.
                if( mode == 1 ){
                    // fw10, Eq. 22:
                    si = 2.0 * stig / ( 1.0 + pow( stig, 2.0 ) );
                    // fw10, Eq. 20:
                    m2 = h3 / pow( stig, 3.0 ); // Shapiro r, not just M2.

                    if( si > 1.0 ){
                        displayMsg(1,"BIN1",
                                "SIN I > 1.0, setting to 1: should probably use DDS model",
                                "",psr[p].noWarnings);
                        si = 1.0;
                        psr[p].param[param_sini].val[0] = longdouble(1.0);
                    }
                }else if( mode == 2 || mode == 3 ){
                    // fw10, Eq. 25:
                    si = 2.0 * h3 * h4 / ( h3 * h3 + h4 * h4 );
                    // fw10, Eq. 26:
                    m2 = pow( h3, 4.0 ) / pow( h4, 3.0 );
                    if( si > 1.0 ){
                        displayMsg(1,"BIN1",
                                "SIN I > 1.0, setting to 1: should probably use DDS model",
                                "",psr[p].noWarnings);
                        si = 1.0;
                        psr[p].param[param_sini].val[0] = longdouble(1.0);
                    }
                }else if( mode == 0 ){
                    // Cannot determine m2 and/or sini. Will have to determine the
                    // Shapiro delay based on h3 alone.
                }else{
                    printf( "This should not be possible. Go Away.\n" );
                    printf( "And tell someone about it: [email protected], e.g.\n" );
                }
                brace=1-si*sin(phase);
                dlogbr=log(brace);

                ecc = sqrt( eps1 * eps1 + eps2 * eps2 );
                TrueAnom = phase;
                //TrueAnom = 2.0 * atan2( sqrt( 1.0 + ecc ) * sin( phase / 2.0 ), 
                //                       sqrt( 1.0 - ecc ) * cos( phase / 2.0 ) );
                omega = atan2( eps1, eps2 );
                //lgf = log( 1.0 + stig * stig - 2.0 * stig * sin( TrueAnom + omega ) );

                fs = 1.0 + stig * stig - 2.0 * stig * sin( TrueAnom );
                lgf = log( fs );
                lsc = lgf + 2.0 * stig * sin( TrueAnom ) - stig * stig * cos( 2.0 * TrueAnom );

                if( mode == 0 ){
                    // mode 0: only h3 is known. 
                    ds = -4.0 / 3.0 * h3 * sin( 3.0 * TrueAnom );
                }else if( mode == 1 ){
                    ds = -2.0 *m2* lsc;
                    //ds = -2.0 * m2 * dlogbr;
                }else{ // modes 2 and 3
                    ds = calcDH( TrueAnom, h3, h4, nharm, 0 );
                }

            }
            else{
                dlogbr=log(brace);
                ds=-2*m2*dlogbr;        /* Equation 26 */
            }

        }
        else
        {
            printf("Require eccentricity set or EPS1/EPS2 parameters for companion %d\n",com+1);
            exit(1);
        }
        // printf("T2: %g %g %g %g %g %g %g\n",brace,phase,a0,b0,dlogbr,ds,m2);

        /* Now compute d2bar, the orbital time correction in DD equation 42. */
        /* Equation 52 */
        if (onemecu != 0.0)
        {
            d2bar=dre*(1-anhat*drep+allTerms*pow(anhat,2)*
                    (pow(drep,2) + 0.5*dre*drepp - 
                     0.5*ecc*su*dre*drep/onemecu)) + allTerms*(ds+da+DAOP+DSR
                     + DOP);
        }
        else
        {
            d2bar=dre*(1-anhat*drep+allTerms*pow(anhat,2)*
                    (pow(drep,2) + 0.5*dre*drepp))
                + allTerms*(ds+da+DAOP+DSR+DOP);
        }    
        //      printf("T2a: %g %g %g %g %g drepp=%g ecc=%g su =%g ome =%g ds = %g da = %g %g %g\n",(double)d2bar,(double)dre,(double)anhat,(double)drep,(double)allTerms,(double)drepp,(double)ecc,(double)su,(double)onemecu,(double)ds,(double)da,(double)DAOP,(double)DSR);
        torb-=d2bar;                                  /* Equation 42  */

        if (param==-1 && com == psr[p].nCompanion-1) return torb;
        else if (param!=-1 && com==arr)
        {
            // Now we need the partial derivatives. Use DD equations 62a - 62k.
            if (psr[p].param[param_ecc].paramSet[com]==1)
            {
                csigma=x*(-sw*su+sqr1me2*cw*cu)/onemecu;      /* Equation 62a */
                ce=su*csigma-x*sw-ecc*x*cw*su/sqr1me2;        /* Equation 62c */
                cx=sw*cume+sqr1me2*cw*su;                     /* Equation 62d */
                comega=x*(cw*cume-sqr1me2*sw*su);             /* Equation 62e */
                cgamma=su;                                    /* Equation 62g */
                cdth=-ecc*ecc*x*cw*su/sqr1me2;                /* Equation 62i */
                cm2=-2*dlogbr;                                /* Equation 62j */
                if (psr[p].param[param_shapmax].paramSet[com]==1)
                    cshapmax = 2*m2*(sw*cume+sqr1me2*cw*su)/brace * (1.0-sdds);
                else if (psr[p].param[param_sini].nLinkTo>0){
                    csi= 2*m2*(sw*cume+sqr1me2*cw*su)*cos(ki)/brace;
                }
                else
                    csi=2*m2*(sw*cume+sqr1me2*cw*su)/brace;     /* Equation 62k */
            }
            else if (psr[p].param[param_eps1].paramSet[com]==1) /* ELL1 model */
            {
                csigma = x*cos(phase);
                cx     = sin(phase);
                ceps1  = -0.5*x*cos(2*phase);
                ceps2  =  0.5*x*sin(2*phase);
                cm2    = -2*dlogbr;
                csi    = 2*m2*sin(phase)/brace;
            }

            if (param==param_pb)	         return -csigma*an*SECDAY*tt0/pb; 
            else if (param==param_a1)      return cx;
            else if (param==param_ecc)     return ce;
            else if (param==param_edot)     return ce*tt0;
            else if (param==param_om)      return comega;
            else if (param==param_omdot)   
                return ae*comega/(an*360.0/(2.0*M_PI)*365.25*SECDAY);
            else if (param==param_t0)      return -csigma*an*SECDAY;
            else if (param==param_pbdot){
                if(psr[p].param[param_pbdot].nLinkFrom>0){
                    return 0.5*tt0*(-csigma*an*SECDAY*tt0/(pb*SECDAY));
                    /*- SPEED_LIGHT/(getParameterValue(&psr[p],param_pb,0)*SECDAY*
                      (pow(getParameterValue(&psr[p],param_pmra,0)*MASYR2RADS,2)+
                      pow(getParameterValue(&psr[p],param_pmdec,0)*MASYR2RADS,2))*
                      getParameterValue(&psr[p],param_daop,0))*
                      (C*(-DK011-DK012)+S*(DK021+DK022));*/
                }
                else  return 0.5*tt0*(-csigma*an*SECDAY*tt0/(pb*SECDAY));
            }
            else if (param==param_sini)    return csi;
            else if (param==param_gamma)   return cgamma;
            else if (param==param_m2)      return cm2*SUNMASS;
            else if (param==param_a1dot)   return cx*tt0;
            else if (param==param_eps1)    return ceps1;
            else if (param==param_eps1dot) return ceps1*tt0;
            else if (param==param_eps2dot) return ceps2*tt0;
            else if (param==param_eps2)    return ceps2;
            else if (param==param_tasc)    return -csigma*an*SECDAY;
            else if (param==param_shapmax) return cshapmax;
            else if (param==param_stig){
                return( -2.0 * m2 / stig * ( 1.0 - 3.0 * lgf - ( 1.0 - stig * stig ) / fs ) 
                        + 2.0 * m2 * ( 4.0 * sin( TrueAnom ) - stig * cos( 2.0 * TrueAnom ) ) );	    
            }
            else if (param==param_h3) {
                if( mode == 0 || mode == 2)
                    return( -4.0 / 3.0 * sin( 3.0 * TrueAnom ) );
                else if( mode == 1 ){
                    return( -2.0 * lsc / pow( stig, 3.0 ) );
                    //return( 2.0 / pow( stig, 3.0 ) * 
                    //        ( lgf + 2.0 * stig * sin( TrueAnom ) - stig * stig * cos( TrueAnom ) ) );
                }else if( mode == 3 )
                    return( calcDH( TrueAnom, h3, h4, nharm, 3 ) );
                else{
                    printf( "ERROR in ELLH model in T2. This really shouldn't happen.\n" );
                }
            }else if( param == param_h4 ){
                if( mode == 2 )
                    return( cos( 4.0 * TrueAnom ) );
                else
                    return( calcDH( TrueAnom, h3, h4, nharm, 4 ) );
            }	  
            else if (param==param_kom){
                ckom = C* (DK033+DK034+DK013+DK014) + S*(DK043+DK044+DK023+DK024);
                return ckom;
            }
            else if (param==param_kin){
                ckin = C/sin(ki)*(DK043+DK044+DK023+DK024)-
                    S/sin(ki)*(DK013+DK014+DK033+DK034);
                if( psr[p].param[param_ecc].paramSet[com]== 1 )
                    ckin += dpara/AULTSC/2.0*pow( x, 2.0 ) * cos( ki ) *
                        pow( sin( ki ), -3.0 ) * 
                        ( pow( ecc, 2.0 ) * ( 3.0 - cos( 2.0 * u ) ) + 
                          4.0 * ecc * cume - 2.0 );
                if(psr[p].param[param_kin].nLinkFrom>0)
                    ckin += csi; //  * cos( ki );
                return ckin;
            }
            /* Update the binary parameter jumps */
            if (psr[p].param[param_bpjep].paramSet[arr]==1 && 
                    psr[p].obsn[ipos].bbat > psr[p].param[param_bpjep].val[arr])
            {
                if (param==param_bpjph)
                    return 1.0/psr[p].param[param_f].val[0];
                else if (param==param_bpja1) return cx;
                else if (param==param_bpjec) return ce;
                else if (param==param_bpjom) return comega;
                else if (param==param_bpjpb)
                    return -csigma*an*SECDAY*tt0/(pb*SECDAY); 
            }
            else
                return 0.0;
        }
    }
    return 0.0;
}
Esempio n. 28
0
void
compute_tropospheric_delays(pulsar *psr,int npsr)
{
  double zenith_delay_hydrostatic, zenith_delay_wet;
  double mapping_hydrostatic, mapping_wet;
  int i, p;
  observatory *obs;
  double source_elevation;
  double pressure;
  const char *CVS_verNum = "$Revision: 1.9 $";

  if (displayCVSversion == 1) CVSdisplayVersion("tropo.C","computer_tropospheric_delays()",CVS_verNum);

  // test code
#if 0
  {
    int ilat, iel;
    double lat, el, h, w;
    for (ilat=0;ilat<=11;ilat++)
    {
      lat = (ilat * 8.0)* 3.14159265358979/180.0;
      for (iel=0; iel<=100; iel++)
      {
	el = (5.0+iel*0.84) * 3.14159265358979/180.0;
	h = NMF_hydrostatic(50000.0, lat, 10000.0, el);
	w = NMF_wet(lat, el);
	printf("%.15lg %.15lg %.15lg %.15lg NMF\n",
	       el, h, w, lat);
      }
    }
    exit(1);
  }
#endif

  for (p=0;p<npsr;p++)
  {
    bool warned = false;
    for (i=0;i<psr[p].nobs;i++)
    { 
      psr[p].obsn[i].troposphericDelay = 0.0;
      if (psr[p].obsn[i].delayCorr!=0 && psr[p].correctTroposphere!=0 && psr[p].obsn[i].zenith[2]==0.0 && !warned)
      {
	logdbg( "WARNING: Tropospheric delay correction not possible with T2CMETHOD TEMPO %d %lf", i, psr[p].obsn[i].zenith[2]);
	warned = true;
      }
      else if (strcmp(psr[p].obsn[i].telID,"STL_FBAT")==0)
	{
	  logdbg("Not correcting for tropospheric delay");
	  warned=true;
	}
      else if (psr[p].obsn[i].delayCorr!=0 && psr[p].correctTroposphere!=0)
      {
	obs = getObservatory(psr[p].obsn[i].telID);
	/* Check whether the observation represents the COE */
	if (strcasecmp(obs->name,"COE")!=0)
	  {
	    // get source elevation neglecting proper motion
	    source_elevation = asin(dotproduct(psr[p].obsn[i].zenith,
					       psr[p].posPulsar)
				    / obs->height_grs80);
	    // get surface atmospheric pressure
	    pressure = 
	      getSurfaceAtmosphericPressure(obs->code, psr[p].obsn[i].sat, 
					    psr[p].noWarnings);
	    
	    // ------------------- Hydrostatic delay
	    // Zenith delay from Davies et al (Radio Sci 20 1593)
	    zenith_delay_hydrostatic = 0.02268 * pressure 
	      / (SPEED_LIGHT * (1.0-0.00266*cos(obs->latitude_grs80)
				-2.8e-7*obs->height_grs80));
	    // mapping function
	    mapping_hydrostatic = 
	      NMF_hydrostatic(psr[p].obsn[i].sat
			      + getCorrection(psr[p].obsn+i, 
					      psr[p].clockFromOverride,
					      "UTC", psr[p].noWarnings)/SECDAY,
			      obs->latitude_grs80, obs->height_grs80,
			      source_elevation);
	    // ------------------ Wet delay
	    zenith_delay_wet = 
	      getZenithWetDelay(obs->code, psr[p].obsn[i].sat, 
				psr[p].noWarnings);
	    mapping_wet = NMF_wet(obs->latitude_grs80, source_elevation);
	    
	    psr[p].obsn[i].troposphericDelay = 
	      zenith_delay_hydrostatic * mapping_hydrostatic
	      + zenith_delay_wet * mapping_wet;
	  }
	else
	  psr[p].obsn[i].troposphericDelay = 0.0;
      }
    }
  }
}
Esempio n. 29
0
void getInputs(pulsar *psr,int argc, char *argv[],char timFile[][MAX_FILELEN],
	       char parFile[][MAX_FILELEN],int *list,int *npsr,
	       int *nGlobal,int *outRes,int *writeModel,char *outputSO,
	       int *polyco, char *polyco_args, char *polyco_file,
	       int *newpar,int *onlypre,char *dcmFile,char *covarFuncFile,char* newparname)
{
  int i,p;
  int gr=0;
  int parfile_num = 0;  /* Have we got a parfile? */
  int timfile_num = 0;  /* Have we got a timfile? */
  int gotTim=0;
  *list = 0;  /* Don't list parameters */
  const char *CVS_verNum = "$Revision: 1.17 $";

  if (displayCVSversion == 1) CVSdisplayVersion("getInputs.C","getInputs()",CVS_verNum);
  //  *nGlobal=0; /* How many global parameters are we fitting? */


  if (argc==2 && strcasecmp(argv[1],"-allParTim")!=0) /* Just have .tim file name */
    {
      if (strcmp(argv[1],"-h")==0) /* Some help */
	{
	  printf("\n");
	  printf("%s\n\n",PACKAGE_STRING);
	  printf("examples: %s mytim.tim\n",argv[0]);
	  printf("          %s -f mypar.par mytim.tim\n",argv[0]);
	  printf("          %s -gr plk -f mypar.par mytim.tim\n",argv[0]);
	  printf("\n");
	  printf("Options: \n\n");

	  printf("-epoch centre     Centres the PEPOCH in the fit\n");
	  printf("-f parFile        Selects parameter file\n");
	  printf("-dcm dcmFile      Data covariance matrix file\n");
	  printf("-gr name          Uses 'name' plugin for graphical interface\n");
	  printf("-h                This help\n");
	  printf("-list             Provides listing of clock corrections and residuals etc.\n");
	  printf("-output name      Uses 'name' plugin for output format\n");
	  printf("-pred \"args\"    Creates a predictive 2D Chebyshev polynomial.\n");
	  printf("      args = \"sitename mjd1 mjd2 freq1 freq2 ntimecoeff nfreqcoeff seg_length (s)\"\n"); 
	  printf("-polyco \"args\"  Creates a TEMPO1-style polyco file.\n");
	  printf("                   args = \"mjd1 mjd2 nspan ncoeff maxha sitename freq\"\n");
      printf("-polyco_file      Specify a leading string for file outputs.\n");
	  printf("-residuals        Outputs the residuals\n");
	  printf("-allInfo          Prints out clock, Earth orientation and similar information\n");
	  printf("-reminder         Saves the command line to T2command.input for future reference.\n");
	  printf("-norescale        Do not rescale parameter uncertainties by the sqrt(red. chisq)\n");
	  printf("-displayVersion   Display detailed CVS version number of every file used.\n");
	  printf("-v                Print verson number.\n");
	  printf("\n\n");
	  printf("Available plugins\n");
	  printplugs(false);
//	  system("ls $TEMPO2/plugins/ | grep plug | sed s/\"_\"/\" \"/ | awk '{print \"  - \" $1}' | sort | uniq");
	  printf("-----------------\n");
	  exit(1);
	}	    
      strcpy(timFile[timfile_num],argv[1]);
      strcpy(parFile[parfile_num],argv[1]);
      strcpy(parFile[parfile_num]+strlen(parFile[parfile_num])-3,"par");
      timfile_num++; parfile_num++;
      (*npsr)++;
    }
  else /* Have multiple command line arguments */
    {
      for (i=1;i<argc;i++)
	{
	  if (strcmp(argv[i],"-f")==0) /* Have .par file */
	    {
	      strcpy(parFile[parfile_num],argv[++i]);
	      if (argv[i+1][0]!='-') /* Must be tim file */
		{
		  strcpy(timFile[timfile_num],argv[++i]);
		  timfile_num++;
		  gotTim=1;
		}
	      /*	      i+=2; */
	      parfile_num++;
	    }
	  else if (strcasecmp(argv[i],"-allParTim")==0)
	    {
	      FILE *pin;
	      char str[1000];

	      // Load in all available par and tim files
	      printf("Using all available .par and .tim files\n");
	      sprintf(str,"ls `ls *.par | sed s/par/tim/` | sed s/.tim/\"\"/");
	      pin = popen(str,"r");
	      while (!feof(pin))
		{
		  if (fscanf(pin,"%s",str)==1)
		    {
		      sprintf(parFile[*npsr],"%s.par",str);
		      sprintf(timFile[*npsr],"%s.tim",str);
		      (*npsr)++;
		      parfile_num++;
		      timfile_num++;
		      gotTim=1;

		    }
		}
	      pclose(pin);
	      printf("Obtained files for %d pulsars\n",*npsr);

	    }
	  else if (strcmp(argv[i],"-fitfunc")==0)
	    strcpy(psr[0].fitFunc,argv[++i]);
	  else if (strcasecmp(argv[i],"-norescale")==0)
	    {
	      for (p=0;p<MAX_PSR;p++)
		psr[p].rescaleErrChisq=0;
	    }
	  else if (strcmp(argv[i],"-gr")==0)
	    gr=1;
	  else if (strcmp(argv[i],"-dcm")==0)
	    strcpy(dcmFile,argv[++i]);
	  else if ((strcmp(argv[i],"-dcf")==0) || (strcmp(argv[i],"-chol")==0))
	    strcpy(covarFuncFile,argv[++i]);
	  else if (strcmp(argv[i],"-filter")==0)
	    {
	      strcat(psr[0].filterStr,argv[++i]);
	      strcat(psr[0].filterStr," ");
	    }
	  else if (strcmp(argv[i],"-pass")==0)
	    {
	      strcat(psr[0].passStr,argv[++i]);
	      strcat(psr[0].passStr," ");
	    }
	  else if (strcmp(argv[i],"-list")==0)
	    *list = 1;	  
	  else if (strcmp(argv[i],"-output")==0)
	      strcpy(outputSO,argv[++i]);
	  else if (strcmp(argv[i],"-residuals")==0)
	    *outRes = 1;
	  else if (strcmp(argv[i],"-del")==0)
	    strcpy(psr[0].deleteFileName,argv[++i]);	  
	  else if (strcmp(argv[i],"-model")==0)
	    *writeModel = 1;
	  else if (strcmp(argv[i],"-newpar")==0){
		 strcpy(newparname,"new.par");
	    *newpar=1;
	  }
	  else if (strcmp(argv[i],"-outpar")==0){
	    *newpar=1;
		strcpy(newparname,argv[++i]);
	  }
	  else if (strcmp(argv[i],"-pre")==0) /* Don't iterate to form post-fit residuals */
	    *onlypre = 1;
	  else if (strcmp(argv[i],"-pred")==0)
	    {
	      *polyco=2;
	      strcpy(polyco_args, argv[++i]);
	    }
	  else if (strcmp(argv[i],"-polyco")==0)
	    {
	      *polyco=1;
	      strcpy(polyco_args, argv[++i]);
	    }
	  else if (strcmp(argv[i],"-polyco_file")==0)
	    {
	      strcpy(polyco_file, argv[++i]);
	    }
	  else if (i==argc-1 && gotTim==0) /* Must be .tim file name */
	    {
	      strcpy(timFile[timfile_num],argv[i]);	    
	      //printf("Have %s\n",timFile[timfile_num]);
	      timfile_num++;
	    }
	}
      if (timfile_num==0 && *polyco==0 && gr==0)
	{
	  printf("ERROR [FILE1]: No .tim file given on command line\n"); 
	  exit(1);
	}      
      if (parfile_num==0 && gr==0)
	{
	  printf("ERROR [FILE2]: No .par file given on command line\n"); 
	  exit(1);
	}
      *npsr = parfile_num;
    }
}
Esempio n. 30
0
double ELL1model(pulsar *psr,int p,int ipos,int param)
{
    double an,x0,m2,tt0,orbits,phase,e1,e2,dre,drep,drepp,brace,dlogbr,ds,da,pb;
    double eps1,eps2,eps1dot,eps2dot,si,a0,b0;
    double d2bar,torb,Csigma,Cx,Ceps1,Ceps2,Cm2,Csi,ct,t0asc,pbdot,xpbdot,x,xdot,am2;
    int norbits;
    double SUNMASS = 4.925490947e-6;
    const char *CVS_verNum = "$Id: 20c084199c812c681ff014068b3e3d2338a7d161 $";

    if (displayCVSversion == 1) CVSdisplayVersion("ELL1model.C","ELL1model()",CVS_verNum);

    a0 = 0.0; /* WHAT SHOULD THESE BE? */
    b0 = 0.0;

    pb    = psr[p].param[param_pb].val[0]*SECDAY;

    if (psr[p].param[param_pbdot].paramSet[0] == 1) pbdot = psr[p].param[param_pbdot].val[0];
    else pbdot=0.0;

    an    = 2.0*M_PI/pb;
    if (psr[p].param[param_sini].paramSet[0]==1) si = getParameterValue(&psr[p],param_sini,0);
    else si = 0.0;

    if (si > 1.0)
    {
        displayMsg(1,"BIN1","SIN I > 1.0, setting to 1: should probably use DDS model","",psr[p].noWarnings);
        si = 1.0;
        psr[p].param[param_sini].val[0] = longdouble(1.0);
    }

    x0    = psr[p].param[param_a1].val[0];
    if (psr[p].param[param_a1dot].paramSet[0] == 1) 
        xdot  = psr[p].param[param_a1dot].val[0];
    else 
        xdot = 0.0;
    t0asc = psr[p].param[param_tasc].val[0];

    if (psr[p].param[param_m2].paramSet[0]==1) am2 = psr[p].param[param_m2].val[0];
    else am2 = 0.0;
    m2 = am2*SUNMASS;

    xpbdot = 0.0;
    eps1  = psr[p].param[param_eps1].val[0];
    eps2  = psr[p].param[param_eps2].val[0];
    if (psr[p].param[param_eps1dot].paramSet[0]==1) eps1dot = psr[p].param[param_eps1dot].val[0];
    else eps1dot=0;
    if (psr[p].param[param_eps2dot].paramSet[0]==1) eps2dot = psr[p].param[param_eps2dot].val[0];
    else eps2dot=0;

    ct = psr[p].obsn[ipos].bbat;      
    tt0 = (ct-t0asc)*SECDAY;
    // --- Changes to handle higher orbital-frequency derivatives (FB1, FB2, ...) ---                                               
    // 04/2015, H. J. Pletsch                                                                                                       
    orbits = tt0/pb;
    if (psr[p].param[param_fb].paramSet[1]==1) {
        int j;
        double fac = 1.0;
        for (j=1;j<psr[p].param[param_fb].aSize;j++) {
          double fbx;
          fac = fac/((double)(j+1));
          if (psr[p].param[param_fb].paramSet[j]==1) {
            fbx = psr[p].param[param_fb].val[j];
            orbits += fac * fbx * pow(tt0,j+1);
          }
        }
      } else {
        orbits -= 0.5*(pbdot+xpbdot)*pow(tt0/pb,2);
      }
      // --- End of changes to handle higher orbital-frequency derivatives ---                                                        

    norbits = (int)orbits;
    if (orbits<0.0) norbits = norbits-1;
    phase = 2.0*M_PI*(orbits-norbits);

    x = x0+xdot*tt0;

    e1 = eps1+eps1dot*tt0;
    e2 = eps2+eps2dot*tt0;
    dre  = x*(sin(phase)-0.5*(e1*cos(2.0*phase)-e2*sin(2.0*phase)));
    drep = x*cos(phase);
    drepp=-x*sin(phase);

    brace=1-si*sin(phase);
    dlogbr=log(brace);
    ds=-2*m2*dlogbr;

    /* NOTE: a0 and b0 are always zero -- they are not set in the original TEMPO!!!!! */
    da=a0*sin(phase)+b0*cos(phase);  

    /*  Now compute d2bar (cf. DD 52) */

    d2bar=dre*(1-an*drep+pow(an*drep,2)+0.5*pow(an,2)*dre*drepp)+ds+da;
    torb=-d2bar;

    if (param==-1) return torb;

    /* Now we need the partial derivatives. */
    Csigma   = x*cos(phase);
    Cx       = sin(phase);
    Ceps1    = -0.5*x*cos(2*phase);
    Ceps2    =  0.5*x*sin(2*phase);
    Cm2      = -2*dlogbr;
    Csi      = 2*m2*sin(phase)/brace; 

    if (param==param_pb)
        return -Csigma*an*SECDAY*tt0/(pb*SECDAY); /* Pb    */
    else if (param==param_a1)
        return Cx;
    else if (param==param_eps1)
        return Ceps1;
    else if (param==param_tasc)
        return -Csigma*an*SECDAY;
    else if (param==param_eps2)
        return Ceps2;
    else if (param==param_eps1dot)
        return Ceps1*tt0;
    else if (param==param_eps2dot)
        return Ceps2*tt0;
    else if (param==param_pbdot)
        return 0.5*tt0*(-Csigma*an*SECDAY*tt0/(pb*SECDAY));
    else if (param==param_a1dot)
        return Cx*tt0;  
    else if (param==param_sini)
        return Csi;
    else if (param==param_m2)
        return Cm2*SUNMASS;

    return 0.0;
}