Example #1
0
void
newbaseline (
    char *buf			/* whatever followed "x X NewBaseline" */
)


{


    char	*p;			/* for eliminating white space etc. */


/*
 *
 * Called from devcntrl() whenever an "x X NewBaseline" command is recognized. We
 * assume whatever is in *buf is a set of parametric equations that describe the
 * new baseline. Equations for x(t), y(t), dx/dt, and dy/dt must be written in
 * PostScript, bracketed by { and } characters, and supplied in exactly that order.
 * In particular the equation for x must come first in *buf and it ends up as the
 * last one on the stack, while the equation for dy/dt comes last (in *buf) and
 * ends up on the top of the PostScript stack. For example if *buf is given by,
 *
 *	{} {180 mul 3.1416 div cos} {pop 1} {180 mul 3.1416 div sin neg}
 *
 * text will be printed along the curve y = cos(x).
 *
 * Angles given in radians must be converted to degrees for the PostScript trig
 * functions, and things are scaled so that 1 unit maps into 1 inch. In the last
 * example the cosine curve that describes the baseline has an amplitude of 1 inch.
 * As another example of this rather confusing syntax if *buf is,
 *
 *	{} {} {pop 1} {pop 1}
 *
 * the baseline will be the 45 degree line y = x.
 *
 * When any of the four functions is used they're called with a single number on
 * the stack that's equal to the current value of the parameter t. The coordinate
 * system axes run parallel to the PostScript coordinate system that's currently
 * being used.
 *
 */


    for ( p = buf; *p; p++ )		/* eliminate trailing '\n' */
	if ( *p == '\n' )  {
	    *p = '\0';
	    break;
	}   /* End if */

    for ( p = buf; *p && (*p == ' ' || *p == ':'); p++ ) ;

    if ( *p != '\0' )  {		/* something's there */
	endtext();
	getbaseline();
	fprintf(tf, "mark resolution %s newbaseline\n", p);
	t_sf(1);
	resetpos();
    }	/* End if */

}   /* End of newbaseline */
Example #2
0
void
settext(char *buf)


{


    char	*p;


/*
 *
 * Does whatever is needed to ensure any text that follows will be set along the
 * curve described by the PostScript procedures listed in *buf. If *buf doesn't
 * contain anything useful (eg. just a newline) things are restored to whatever
 * they originally were. Doesn't work well if we try to start in the middle of a
 * line of text.
 *
 * The parametric equations needed are,
 *
 *	x = f(t)
 *	y = g(t)
 *	dx/dt = f'(t)
 *	dy/dt = g'(t)
 *
 * and must be given as proper PostScript procedures. The equation for x must come
 * first (ie. it ends up on the bottom of the stack) and the equation for dy/dt
 * must be given last (ie. it ends up on top of the stack). For example if *buf
 * is given by,
 *
 *	{} {180 mul 3.1416 div cos} {pop 1} {180 mul 3.1416 div sin neg}
 *
 * text will be set along the curve y=cos(x).
 *
 */


    endtext();
    getbaseline();

    for ( p = buf; *p && *p == ' '; p++ ) ;

    if ( *p && *p != '\n' )  {
	encoding = maxencoding + 2;
	fprintf(tf, "mark resolution %s newbaseline\n", buf);
    } else encoding = realencoding;

    fprintf(tf, "%d setdecoding\n", encoding);
    resetpos();

}   /* End of settext */
Example #3
0
void
drawtext (
    char *buf			/* whatever followed "x X DrawText */
)


{


    char	*p;			/* for eliminating white space etc. */


/*
 *
 * Called from devcntrl() whenever an "x X DrawText command is recognized. *buf
 * should contain three arguments in the following order. First comes the text we
 * want to print along the current baseline. Right now the string should be given
 * as a PostScript string using characters '(' and ')' as the delimiters. Next in
 * *buf comes a justification mode that can be the words left, right, or center.
 * Last comes a number that represents the starting value of the parameter t that's
 * given as the argument to the parametric equations that describe the current
 * baseline. For example if *buf is given by,
 *
 *	(hello world) left .5
 *
 * hello world will be printed along the path described by the current baseline
 * and left justified at whatever (x(.5), y(.5)) happens to be. Usually will be
 * preceeded by an "x X NewBaseline" call that defines the current baseline. The
 * origin of the coordinate system used by the parametric equations will be the
 * current point.
 *
 */


    for ( p = buf; *p; p++ )		/* eliminate trailing '\n' */
	if ( *p == '\n' )  {
	    *p = '\0';
	    break;
	}   /* End if */

    for ( p = buf; *p && (*p == ' ' || *p == ':'); p++ ) ;

    if ( *p != '\0' )  {		/* something's there */
	endtext();
	getbaseline();
	xymove(hpos, vpos);
	fprintf(tf, "mark %s drawfunnytext\n", p);
	resetpos();
    }	/* End if */

}   /* End of drawtext */
Example #4
0
int extractFoldData(fitsfile *fp,dSet *data,float dm,float *fx,float *fy,float *freq_y,float *time_y,float *bpass, int sub0)
{
  int n=0;
  int status=0;
  int colnum;
  int i,j,k,l;
  int initflag=0;
  float nval=0;
  float ty[data->phead.nbin];
  float **offs;    // [data->phead.nsub];
  float **dat_scl; // [data->phead.nsub];
  double f0,chanbw,tdelay;
  int bn,cdelay;
  double bintime;
  int addDelay = 0; //500;
//  float bpass[data->phead.nchan*2];
  float bpass_offs[2];
  float bpass_scl[2];
  float meanVal,rmsVal;


  // get mean/RMS of off-pulse for scaling. no longer need OFFS/DAT_SCL
  printf("sub0 = %d\n",sub0);
  if (dm < 0)
    dm = data->phead.dm;
  
  // Need to remove a baseline from each polarisation channel before summing

  // Get first frequency channel
  // Central frequency
  f0 = data->phead.freq; //-data->phead.chanbw*data->phead.nchan/2;
  //  chanbw = data->phead.bw/data->phead.nchan;
  chanbw = data->phead.chanbw;

  bintime = (double)data->phead.period/(double)data->phead.nbin;

  fits_movnam_hdu(fp,BINARY_TBL,"BANDPASS",1,&status);
  if (status) {
    printf("Unable to move to bandpass table in FITS file\n");
    exit(1);
  }
  fits_get_colnum(fp,CASEINSEN,"DAT_OFFS",&colnum,&status);  
  fits_read_col_flt(fp,colnum,1,1,2,nval,bpass_offs,&initflag,&status);
  fits_get_colnum(fp,CASEINSEN,"DAT_SCL",&colnum,&status);  
  fits_read_col_flt(fp,colnum,1,1,2,nval,bpass_scl,&initflag,&status);
  // Now read the bandpass
  fits_get_colnum(fp,CASEINSEN,"DATA",&colnum,&status);  
  // NOTE: Starting at element 2 as element 1 is junk
  fits_read_col_flt(fp,colnum,1,2,data->phead.nchan,nval,bpass,&initflag,&status);
  fits_read_col_flt(fp,colnum,1,3+data->phead.nchan,data->phead.nchan,nval,bpass+data->phead.nchan,&initflag,&status);
  for (i=0;i<data->phead.nchan*2;i++)
    {
      if (i<data->phead.nchan)
	bpass[i] = bpass[i]*bpass_scl[0] + bpass_offs[0];
      else
	bpass[i] = bpass[i]*bpass_scl[1] + bpass_offs[1];
      //      printf("bpass: %d %g %g %g %g %g \n",i,bpass[i],bpass_scl[0],bpass_scl[1],bpass_offs[0],bpass_offs[1]);
    }
  //  exit(1);

  fits_movnam_hdu(fp,BINARY_TBL,"SUBINT",1,&status);
  if (status) {
    printf("Unable to move to subint table in FITS file\n");
    exit(1);
  }
  // REMOVED: No longer need dat_scl or offs. OFFS/DAT_SCL
//  offs = (float **)malloc(sizeof(float *)*data->phead.nsub);
//  dat_scl = (float **)malloc(sizeof(float *)*data->phead.nsub);
//  for (i=0;i<data->phead.nsub;i++)
//    {
//      offs[i] = (float *)malloc(sizeof(float)*data->phead.nchan*data->phead.npol);
//      dat_scl[i] = (float *)malloc(sizeof(float)*data->phead.nchan*data->phead.npol);
//    }
//  fits_get_colnum(fp,CASEINSEN,"DAT_OFFS",&colnum,&status);
//  if (status) {
//    printf("Unable to find DAT_OFFS in the subint table in FITS file\n");
//    exit(1);
//  }
//  for (i=0;i<data->phead.nsub;i++)
//    {
//      fits_read_col_flt(fp,colnum,i+1,1,data->phead.nchan*data->phead.npol,nval,offs[i],&initflag,&status);
//      //      printf("offs = %g\n",offs[i][5]);
//      //      offs[i] =0;
//    }
//
//  fits_get_colnum(fp,CASEINSEN,"DAT_SCL",&colnum,&status);
//  if (status) {
//    printf("Unable to find DAT_SCL in the subint table in FITS file\n");
//    exit(1);
//  }
//  for (i=0;i<data->phead.nsub;i++)
//    {
//      fits_read_col_flt(fp,colnum,i+1,1,data->phead.nchan*data->phead.npol,nval,dat_scl[i],&initflag,&status);
//      //      printf("dat_scl = %g\n",dat_scl[i][5]);
//      //            dat_scl[i]=1.0;
//    }

  fits_get_colnum(fp,CASEINSEN,"DATA",&colnum,&status);
  if (status) {
    printf("Unable to find data in the subint table in FITS file\n");
    exit(1);
  }
  if (sub0==0)
    {
      for (i=0;i<data->phead.nbin;i++)
	{
	  fx[i] = i;
	  fy[i] = 0;
	}
      //
      printf("Loading %d subintegrations\n",data->phead.nsub);
      printf("Number of frequency channels = %d\n",data->phead.nchan);
      printf("Number of polarisations = %d\n",data->phead.npol);
      for (i=0;i<data->phead.nchan*data->phead.nbin;i++)
	freq_y[i] = 0;
    }
  for (i=sub0;i<data->phead.nsub;i++) // *data->phead.nbin;i++)
    {
      for (j=0;j<data->phead.nbin;j++)
	time_y[i*data->phead.nbin+j] = 0;
    } 
  for (l=sub0;l<data->phead.nsub;l++)
    {
      for (j=0;j<data->phead.npol && j < 2;j++) // Do not add cross terms!
	{
	  for (i=0;i<data->phead.nchan;i++)
	    {
	      // Must calculate the frequency of this channel
	      // ... calculate the delay caused by the DM
	      // ... dedisperse the subintegration
	      
	      //	      tdelay = 4.15e-3*dm*(pow(f0/1000.0,-2)-pow((f0+chanbw*i)/1000.0,-2));
	      tdelay = 4.15e-3*dm*(pow(f0/1000.0,-2)-pow((f0+(chanbw*i-chanbw*data->phead.nchan/2.0))/1000.0,-2));
	      cdelay = nint(-tdelay/bintime);
	      //	      if (l==0 && j==0)
	      //		printf("Have %g %g %g %d %d\n",dm,f0,f0+chanbw*i,i,cdelay);
	      fits_read_col_flt(fp,colnum,l+1,j*(data->phead.nchan*data->phead.nbin)+i*data->phead.nbin+1,data->phead.nbin,nval,ty,&initflag,&status);
	      meanVal=0;
	      //for (k=0;k<data->phead.nbin;k++)
		//{
		 // ty[k] = ((ty[k]+offs[l][j*data->phead.nchan+i])*dat_scl[l][j*data->phead.nchan+i]); //+offs[l][j*data->phead.nchan+i]);

		  /*		  if (j==0)
		    ty[k] -= bpass[i];
		  else if (j==1)
		    ty[k] -= bpass[data->phead.nchan+i];
		  else
		    {
		      ty[k] -= sqrt(bpass[data->phead.nchan+i]*bpass[i]);
		      } */
		  //meanVal+=ty[k];
	//	}

	      getbaseline(ty,data->phead.nbin,0.35,&meanVal,&rmsVal);
	      if (rmsVal == 0.0 ) rmsVal=1.0;
	      //	      printf("Val = %g\n",ty[10]);
	      for (k=0;k<data->phead.nbin;k++)
		{
		  //		  if (i==10 && l==10)
		  //		    printf("Orig value = %g\n",ty[k]);

		  //ty[k] = ((ty[k]+offs[l][j*data->phead.nchan+i])*dat_scl[l][j*data->phead.nchan+i]); //+offs[l][j*data->phead.nchan+i]);
		  ty[k] -= meanVal;
		  ty[k] /= rmsVal;
		  // Subtract bandpass
		  /*		  if (j==0)
		    ty[k] -= bpass[i];
		  else if (j==1)
		    ty[k] -= bpass[data->phead.nchan+i];
		  else
		    {
		      ty[k] -= sqrt(bpass[data->phead.nchan+i]*bpass[i]);
		      } */
		  //		  if (l==10)
		      
		  //		    printf("New value = %g\n",ty[k]);
		  bn = k-cdelay + addDelay;
		  //		  bn = nint(fmod(k-tdelay/bintime,data->phead.nbin));
		  while (bn >= data->phead.nbin)
		    bn -= data->phead.nbin;
		  while (bn < 0)
		    bn += data->phead.nbin;
		  freq_y[i*data->phead.nbin+k]+=(ty[k]); ///(float)(data->phead.npol*data->phead.nsub));
		  time_y[l*data->phead.nbin+bn]+=(ty[k]);///(float)(data->phead.npol*data->phead.nchan));
		  //		  printf("timey = %g\n",time_y[l*data->phead.nbin+bn]);
		  fy[bn]+=(ty[k]/(float)(data->phead.nchan*data->phead.npol*data->phead.nsub));
		}
	    }
	}
    }
   
  // REMOVED: OFFS/DAT_SCL table no longer needed.
  //for (i=0;i<data->phead.nsub;i++)
  //  {
  //    free(offs[i]);
  //    free(dat_scl[i]);
  //  }
  //free(offs);
  //free(dat_scl);*/
  printf("Status = %d\n",status);
}