コード例 #1
0
ファイル: tempo2pred.c プロジェクト: ARO-user/work-share
int T2Predictor_GetPlan_Ext(char *filename,
			long double mjd_start,
			long double mjd_end,
			long double step, // seconds
			long double freq, // MHz
			// remaining arguments are returned
			char *psrname, char *sitename,
			long double *phase0,
			int *nsegments,
			long double *pulse_frequencies)
{
  int iseg, ret;
  long double lastphase, phase, mjd, lastmjd;
  T2Predictor pred;

  if ((ret=T2Predictor_Read(&pred, filename)))
    return ret;
  if (psrname)
    strcpy(psrname, T2Predictor_GetPSRName(&pred));
  if (sitename)
    strcpy(sitename, T2Predictor_GetSiteName(&pred));

  *nsegments = (int)ceill((mjd_end-mjd_start)*86400.0L/step);
  *phase0 = lastphase = T2Predictor_GetPhase(&pred, mjd_start, freq);
  lastmjd = mjd_start;
  printf("SILLY UPDATE IN POLYCO: REMOVE\n");
  printf("lastmjd = %.20Lf\n",mjd_start);

  for (iseg=0; iseg < *nsegments; iseg++)
  {
    mjd = mjd_start +(iseg+1)*step/86400.0L;
    if (mjd > mjd_end)
      mjd = mjd_end;
    phase = T2Predictor_GetPhase(&pred, mjd, freq);
    pulse_frequencies[iseg] = (phase-lastphase)/(mjd-lastmjd)/86400.0L;
    lastphase = phase;
    lastmjd = mjd;
  }

  T2Predictor_Destroy(&pred);

  return 0;
}
コード例 #2
0
ファイル: ptimeD.c プロジェクト: shidai/ptimeD
int main (int argc, char *argv[])
{
	int h,i,j,k,m,z;

	//////////////////////////////////////////////////////
	char inName[128];   // name of input data file
	char fname[128];   // name of data file
	char ext[128];   // extension of new data file
	char ext0[]="D";   // default extension of new data file
	int nstokes;
	int mode = 0;  // default: creat new file ".D"
	//int pmode = 0;  // default: use predictor

	char tdisName[128];   // name of tdis file
	int tdisMode = 0;  // default: no tdis read
	int index, n;
	int indexTdis;

	double DM;
	int DMstatus = 0; 

	for (i=0;i<argc;i++)
	{
		if (strcmp(argv[i],"-f") == 0)
		{
			index = i + 1;
			n = 0;
			while ( (index + n) < argc && strcmp(argv[index+n],"-e") != 0 && strcmp(argv[index+n],"-r") != 0 && strcmp(argv[index+n],"-DM") != 0 && strcmp(argv[index+n],"-tdis") != 0)
			{
				n++;
			}
			//strcpy(fname,argv[++i]);
		}
		else if (strcmp(argv[i],"-e") == 0)
		{
			strcpy(ext,argv[++i]);
			mode = 1;  // creat new file with new extension
		}
		//else if (strcmp(argv[i],"-np") == 0)  // not use predictor
		//{
		//	pmode = 1;  
		//}
		else if (strcmp(argv[i],"-r") == 0)  // file name of tdis
		{
			indexTdis = i + 1;
		}
		else if (strcmp(argv[i],"-tdis") == 0)  // use tdis1 and tdis2
		{
			tdisMode = 1;
		}
		else if (strcmp(argv[i],"-DM") == 0)  // use input DM
		{
			DMstatus = 1;
			DM = atof(argv[++i]);
		}
	}

	T2Predictor pred;

	/////////////////////////////////////////////////////////////////////////////////
	// start to deal with different data file
	for (k = 0; k < n; k++)
	{
		// get the data file name
		strcpy(inName,argv[k+index]);
		if (mode == 0)
		{
			createNewfile(inName, fname, ext0);
			printf ("%s\n", fname);
		}
		else
		{
			createNewfile(inName, fname, ext);
			printf ("%s\n", fname);
		}

		////////////////////////////////////////////////////
	
		double freqRef;  // observing central freq at SSB
		double cfreq;  // observing central freq, e.g., 1369 MHz
		freqRef = read_obsFreqSSB (fname);
		cfreq = read_obsFreq (fname);
		//freqRef = 1369.0; // MHz

		double dm;
		if (DMstatus == 1)
		{
			dm = DM;
		}
		else
		{
			dm = readDm(fname);
		}
		printf ("DM0: %.4lf\n", dm);
	
		T2Predictor_Init(&pred);
		  
		int ret;
		if (ret=T2Predictor_ReadFits(&pred,fname))
		{
			printf("Error: unable to read predictor\n");
			exit(1);
		}

		long int imjd, smjd;
		double offs, mjd, subint_offs;
		imjd = stt_imjd(fname);
		smjd = stt_smjd(fname);
		offs = stt_offs(fname);

		double psrfreq;
		double psrfreq0;

		psrfreq0 = read_psrfreq (fname);

		////////////////////////////////////////////////
		int nphase;
		int nchn;
		int nsub;
		int npol;
	
		nchn = get_nchan(fname);	
		npol = get_npol(fname);	
		nsub = get_subint(fname);	
		nphase = get_nphase(fname);	

		//printf ("%d\n", nchn);
		////////////////////////////////////////////////

		double tdis1[nchn],tdis2[nchn],freqSSB[nchn];
		FILE *fp;

		{
			strcpy(tdisName,argv[k+indexTdis]);
			printf ("%s\n", tdisName);

			if ((fp = fopen(tdisName, "r")) == NULL)
		  {
				fprintf (stdout, "Can't open file\n");
				exit(1);
			}

			m = 0;
			while (fscanf(fp, "%lf %lf %lf", &tdis1[m],&tdis2[m],&freqSSB[m]) == 3)
			{
				//printf ("%lf\n", tdis[m]);
				m++;
			}
			  
			if (fclose (fp) != 0)
				fprintf (stderr, "Error closing\n");
		}

		////////////////////////////////////////////////////////////////////////////////

		double *p_multi, *p_multi_deDM;
		p_multi = (double *)malloc(sizeof(double)*nchn*npol*nphase);
		p_multi_deDM = (double *)malloc(sizeof(double)*nchn*npol*nphase);

		double *p_temp, *p_temp_deDM;
		p_temp = (double *)malloc(sizeof(double)*npol*nphase);
		p_temp_deDM = (double *)malloc(sizeof(double)*npol*nphase);

		double phaseShift;
		double phaseShift0;

		double freq[nchn];
		double batPsrFreq = 208.0;
		// start to derive toa from different subint
		for (h = 1; h <= nsub; h++)
		{
			subint_offs = read_offs(fname, h);
			batPsrFreq = read_batFreq(fname, h);
			mjd = imjd + (smjd + offs + subint_offs)/86400.0L;
			//printf ("mjd: %lf\n", mjd);
			
			psrfreq = T2Predictor_GetFrequency(&pred,mjd,cfreq);
		
			printf ("psr freq %.10lf %.10lf\n", batPsrFreq, psrfreq);
			// read profiles from data file
			read_prof(fname,h,p_multi,nphase);
			read_freq(fname,h,freq,nchn);

			//readfile(argv[2],&n,tt,p_multi);

			// start to derive toas for different channels
			for (i = 0; i < nchn; i++)
			{
				//psrfreq = T2Predictor_GetFrequency(&pred,mjd,freq[i]);
				phaseShift0 = 2.0*M_PI*(T2Predictor_GetPhase(&pred,mjd,freq[i])-floor(T2Predictor_GetPhase(&pred,mjd,freq[i])));
				//printf ("Chn%d\n", i);
				z = 0;
				for (nstokes = 0; nstokes < npol; nstokes++)
				{
					for (j = 0; j < nphase; j++)
					{
						p_temp[z] = p_multi[nstokes*nchn*nphase + i*nphase + j];
						//printf ("%d %lf\n", n, p_temp[n]);
						z++;
					}
				}

				// dedisperse
				if (tdisMode == 1)
				{
					phaseShift = phaseShiftDMtdis (tdis1[i], tdis2[i], psrfreq, freqSSB[i], dm, batPsrFreq);
					//phaseShift = phaseShiftDMtdis (tdis1[i], tdis2[i], psrfreq, freqSSB[i], dm, psrfreq0);
				}
				else
				{
					//printf ("%lf\n", freq[i]);
					phaseShift = phaseShiftDM (dm, freq[i], pred, mjd, freqRef, psrfreq);
				}

				//printf ("phase shift %.10lf %.10lf\n", phaseShift0, phaseShift);
				deDM (nphase, npol, p_temp, phaseShift, p_temp_deDM);

				for (nstokes = 0; nstokes < npol; nstokes++)
				{
					for (j = 0; j < nphase; j++)
					{
						p_multi_deDM[nstokes*nchn*nphase + i*nphase + j] = p_temp_deDM[j];
						//printf ("%d %lf\n", j, p_temp_deDM[j]);
					}
				}
			}
			write_prof (fname, h, p_multi_deDM, nphase);
			modify_freq (fname, h, freqRef, nchn, freqSSB);
		}

		free(p_multi);
		free(p_multi_deDM);
		free(p_temp);
		free(p_temp_deDM);

		T2Predictor_Destroy(&pred);
	}

	return 0;
}
コード例 #3
0
ファイル: ptime.c プロジェクト: PsrPtime/ptime
void processFile(char *fname,tmplStruct *tmpl,FILE *fout,int logit)
{
  pheader *header;
  ptime_observation *obs;
  toaStruct toa;
  fitsfile *fp;
  int i;
  float baselineFrac = 0.1;
  int baselineType = 1;
  int toaAlgorithm=1;
  double dPhi;
  double *offs_sub;
  double *datFreq;
  int nSub = 1;
  FILE *fout_log;
  char logFname[128];
  long double period;

  sprintf(logFname,"log.ptime.%s",fname);
  fout_log = fopen(logFname,"w");
  offs_sub = (double *)malloc(sizeof(double)*nSub);
  obs = (ptime_observation *)malloc(sizeof(ptime_observation));
  header = (pheader *)malloc(sizeof(pheader));
  fp = openFitsFile(fname);
  loadPrimaryHeader(fp,header);

  datFreq= (double *)malloc(sizeof(double)*header->nchan);
  allocateObsMemory(obs,header);
  readData(obs,header,fp);
  // Now get an array of subintegration times
  readSubintOffs(obs,offs_sub,fp);
  // Get an array of frequencies
  readDatFreq(obs,datFreq,fp,header->nchan);

  printf("offs_sub = %g\n",offs_sub[0]);
  // Calculate the period
  {
    FILE *pred_out;
    int status=0;
    long nrows,row;
    char nval[128]="UNKNOWN";
    int anynul=0;
    long double mjd0;
    long double frequency;
    char **line;
    T2Predictor pred;
    int ret;

    line = (char **)malloc(sizeof(char *));
    line[0] = (char *)malloc(sizeof(char)*1024);     


    if (!(pred_out = fopen("ptime.pred","w"))){
      printf("Unable to open file >%s<\n","ptime.pred");
    }
    fits_movnam_hdu(fp,BINARY_TBL,(char *)"T2PREDICT",1,&status);
    if (status)
      {
	printf("No predictor table in PSRFITS file\n");
	status=0;
      }
    fits_get_num_rows(fp,&nrows,&status);
    printf("NROWS = %d\n",nrows);
    for (row = 1; row <= nrows ; row++){
      fits_read_col_str(fp,1,row,1,1,nval,line,&anynul,&status);
      printf("Have read %s\n",line[0]);
      fprintf(pred_out,"%s\n",line[0]);
    }
    free(line[0]);
    free(line);

    fclose(pred_out);

    T2Predictor_Init(&pred);  // prepare the predictor                                                                                     
    if (ret=T2Predictor_Read(&pred,(char *)"ptime.pred"))
      {
	printf("Error: unable to read predictor\n");
	exit(1);
      }
    mjd0 = header->imjd + (header->smjd + header->stt_offs)/86400.0L;
    frequency = datFreq[0];  //(freq in MHz) WHAT SHOULD THIS BE SET TO!!
    period = 1.0/T2Predictor_GetFrequency(&pred,mjd0,frequency);
    if (period==-1){
      printf("Error: period returned from predictor = -1. This cannot be correct.\n");
      exit(1);
    }
    T2Predictor_Destroy(&pred);
    printf("Period = %.15Lf %.15Lf %.15Lf\n",period,mjd0,frequency);
  }

  closeFitsFile(fp);
  // Must remove a baseline
  removeBaseline(obs,header,baselineType,baselineFrac);
  printf("Here\n");
  // Now get the shift
  if (toaAlgorithm == 1)
    getTOA_alg1(obs,header,tmpl,&toa,fout_log);
  strcpy(toa.fname,fname);



  // Calculate the arrival time
  calcArrivalTime(obs,header,tmpl,&toa,offs_sub,datFreq,period,fout,fout_log);
  free(header);
  free(obs);
  free(offs_sub);
  free(datFreq);
  fclose(fout_log);
}
コード例 #4
0
ファイル: tempo2pred.c プロジェクト: ARO-user/work-share
void
T2Predictor_Copy(T2Predictor *into_t2p, const T2Predictor *from_t2p)
{
  T2Predictor_Destroy(into_t2p);
  T2Predictor_Insert(into_t2p, from_t2p);
}