Пример #1
0
void calModelPar(double tm, CorrType *corr, ModelParType *mpar,
                 SourceParType *source, int *antmask)
{ double w, wdot, ha,dec, ch,sh, cd,sd, lst, p;
  int samp_id ;
  double bxcd,bycd,bzsd, freq,dt ; 
  double instr_delay, instr_phase ;
  ModelParType *par ;
  /* FILE *fp=fopen("CalModelPar.out","w"); */

  for (samp_id=0; samp_id < corr->daspar.samplers ; samp_id++)
  { static double C = 2.99796e8 ; /* velocity of light in  m/s */
    int ant_id=corr->sampler[samp_id].ant_id;
    int band=corr->sampler[samp_id].band;
    AntennaParType *ant = &corr->antenna[ant_id] ;
    int mask = 1 << ant_id ;

    if ( (antmask[0] & mask) == 0)continue ;
    //dt = tm + (corr->daspar.mjd_ref - source->mjd0)*86400 ;
    

    lst = lmst(corr->daspar.mjd_ref + tm/86400);
    
// =================================================

  double ut,tu,res,lmstime ;
  ut = corr->daspar.mjd_ref + tm/86400 ;
  tu = (ut - 51544.5) / 36525.;  /* centuries since J2000  */
  res = ut + 74.05/360. ; res = res - floor(res) ;
  lmstime = res + (((0.093104 - tu * 6.2e-6) * tu
                  + 8640184.812866) * tu + 24110.54841)/86400.0 ;
  lmstime = (lmstime - floor(lmstime))*2.0 * M_PI ;
  lst = lmstime; 
  
// =================================================

    //ha = lst - source->ra_app - dt * source->dra  ;
    ha = lst - source->ra_app;
    ch = cos(ha); sh = sin(ha) ;
    //dec = source->dec_app + dt * source->ddec ;
    dec = source->dec_app;
    cd = cos(dec) ;  sd = sin(dec) ;
    bxcd = ant->bx *cd/C ; /* sec */ 
    bycd = ant->by *cd/C ;
    bzsd = ant->bz *sd/C ;
    //freq = source->freq[band%2]*source->net_sign[band];
    freq = source->freq[0];
    instr_delay = ant->d0[0]/C ;
//    printf("lst is value inside calModelpar %lf \n", lst);
          
    //instr_phase = ant->p0[band] ;
    //instr_phase = ant->p0[0] ;
  
    /*
      w  is the net delay (sec) suffered by the signal in the sky;
      nanosec is the net delay (in nanosec) including cable delays.
      wdot is the rate of change of phase (radians/sec) due to
      change in geometry, which is communicated to the Corrnode
      in units of cycles/StaTime .
      PhaseNext is the net phase (fractional cycle times 1024) 
      corresponding to the hour angle ha
      The correction to be applied to each of these three terms
      is the negative of the corresponding terms such that
      value + correction = 0 as closely as possible
    */
  
  
    w = ch*bxcd - sh*bycd + bzsd ;  /* sec */
    par = mpar + samp_id;
    /*    fprintf(fp,"Mpar%04d [Samp %04d Fft %04d] ) set to %s %d\n",samp_id,corr->sampler[samp_id].dpc, corr->sampler[samp_id].fft_id, ant->name,band); */
    par->delay = w + instr_delay ;
    wdot = par->dd = (-7.27e-5)*( sh*bxcd  + ch*bycd ) ;
     
    par->dp = -2*M_PI *  wdot * freq ; /* radians per sec */

    if (source->mode & TransitObs) p = -par->dp * lst * 0.9972695663 ;
    /* phase varies linearly, from 0 at lst = 0  */
    else p = w * freq + instr_phase ;
   
    /*Added this line to get the instrumental phase*/
    //par->phase = instr_phase ; 

    par->phase = 2*M_PI * (1 - fmod(p,1.0)) ;  /* radians to be added */
 }
  /*  fclose(fp); */
}
Пример #2
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);
	}
    }
}