Ejemplo n.º 1
0
void xyline(int npts, float *x, float *y, const char *xlab, const char *ylab, int id)
{
    float xmin, xmax, ymin, ymax;
    float overy, over = 0.1;

    /* Determine min and max values to plot and scaling: */
    find_min_max_arr(npts, x, &xmin, &xmax);
    find_min_max_arr(npts, y, &ymin, &ymax);
    overy = over * (ymax - ymin);
    ymax += overy;
    ymin -= overy;

    /* Setup the plot screen: */
    cpgenv(xmin, xmax, ymin, ymax, 0, 0);

    /* Choose the font: */
    cpgscf(2);

    /* Label the axes: */
    cpglab(xlab, ylab, "");

    /* Add ID line if required */
    if (id == 1)
        cpgiden();

    /* Plot the points: */
    cpgline(npts, x, y);

}
Ejemplo n.º 2
0
void Plotter2::resetAttributes(const Plotter2ViewportInfo& vi) {
    cpgstbg(0); // reset background colour to the initial one (white)
    cpgsci(1);  // reset foreground colour to the initial one (black)
    cpgsls(1);  // reset line style to solid
    cpgslw(1);  // reset line width to 1
    cpgscf(1);  // reset font style to normal
    cpgsch(vi.fontSizeDef);// reset font size
    cpgsfs(1);  // reset fill style (solid)
}
Ejemplo n.º 3
0
void plot_profile(int proflen, float *profile, const char *title,
                  const char *probtxt, const char *foldtxt,
                  int showerr, float *errors, int showid)
{
    int ii;
    float *x, overy, ymin, ymax;
    float errmin = 0.0, errmax = 0.0, offset, avg = 0.0, av[2];

    find_min_max_arr(proflen, profile, &ymin, &ymax);
    if (showerr)
        find_min_max_arr(proflen, errors, &errmin, &errmax);
    overy = 0.1 * (ymax + errmax - ymin - errmin);
    ymax = ymax + overy + errmax;
    ymin = ymin - overy - errmin;
    x = gen_fvect(proflen);
    for (ii = 0; ii < proflen; ii++)
        x[ii] = (float) ii / (float) proflen;
    cpgenv(0.0, 1.00001, ymin, ymax, 0, 0);
    cpgscf(2);
    cpglab("Pulse Phase", "Counts", "");
    if (showid)
        cpgiden();
    cpgslw(5);
    if (showerr) {
        cpgbin(proflen, x, profile, 0);
    } else {
        cpgline(proflen, x, profile);
    }
    cpgslw(1);
    if (showerr) {
        offset = 0.5 / (float) proflen;
        for (ii = 0; ii < proflen; ii++)
            x[ii] += offset;
        cpgerrb(6, proflen, x, profile, errors, 2);
        cpgpt(proflen, x, profile, 5);
    }
    for (ii = 0; ii < proflen; ii++)
        avg += profile[ii];
    avg /= proflen;
    cpgsls(4);
    x[0] = 0.0;
    x[1] = 1.0;
    av[0] = avg;
    av[1] = avg;
    cpgline(2, x, av);
    cpgsls(1);
    cpgsch(1.3);
    cpgmtxt("T", +2.0, 0.5, 0.5, title);
    cpgsch(1.0);
    cpgmtxt("T", +0.8, 0.5, 0.5, foldtxt);
    cpgmtxt("T", -1.5, 0.5, 0.5, probtxt);
    vect_free(x);
}
Ejemplo n.º 4
0
void xyline2lab(int npts, float *x, float *y, float *y2, const char *xlab,
                const char *ylab, const char *ylab2, int id)
{
    float xmin, xmax, ymin, ymax, ymin2, ymax2;
    float overy, over = 0.1;

    /* Determine min and max values to plot and scaling: */
    find_min_max_arr(npts, x, &xmin, &xmax);
    find_min_max_arr(npts, y, &ymin, &ymax);
    find_min_max_arr(npts, y2, &ymin2, &ymax2);
    overy = over * (ymax - ymin);
    ymax += overy;
    ymin -= overy;
    overy = over * (ymax2 - ymin2);
    ymax2 += overy;
    ymin2 -= overy;

    /* Choose the font: */
    cpgscf(2);

    /* Setup the plot screen for the first set of y's: */
    cpgpage();
    cpgvstd();
    cpgswin(xmin, xmax, ymin, ymax);
    cpgbox("BCNST", 0.0, 0, "BNST", 0.0, 0);
    cpgmtxt("B", 3.0, 0.5, 0.5, xlab);
    cpgmtxt("L", 2.6, 0.5, 0.5, ylab);

    /* Plot the points for the 1st y axis: */
    cpgline(npts, x, y);

    /* Setup the plot screen for the second set of y's: */
    cpgvstd();
    cpgswin(xmin, xmax, ymin2, ymax2);
    cpgbox("", 0.0, 0, "CMST", 0.0, 0);
    cpgmtxt("R", 3.0, 0.5, 0.5, ylab2);

    /* Plot the points for the 2nd y axis: */
    cpgline(npts, x, y2);

    /* Add ID line if required */
    if (id == 1)
        cpgiden();

}
Ejemplo n.º 5
0
void powerplot(int npts, float *freqs, float *amp, float norm, int id)
{
   float *pwr, xmin, xmax, ymin, ymax;
   float overy, over = 0.1;
   int i, ptr;

   pwr = (float *) malloc((size_t) npts * sizeof(float));
   if (!pwr) {
      printf("Error allocating 'pwr' in powerplot.  Exiting.\n\n");
      exit(EXIT_FAILURE);
   }
   /* Turn the complex amps into a power series: */
   for (i = 0; i < npts; i++) {
      ptr = i * 2;
      pwr[i] = plot_power(amp[ptr], amp[ptr + 1]) / norm;
   }

   /* Determine min and max values to plot and scaling: */
   find_min_max_arr(npts, freqs, &xmin, &xmax);
   find_min_max_arr(npts, pwr, &ymin, &ymax);
   overy = over * (ymax - ymin);
   ymax += overy;

   /* Setup the plot screen: */
   cpgenv(xmin, xmax, ymin, ymax, 0, 1);

   /* Choose the font: */
   cpgscf(2);

   /* Label the axes: */
   cpglab("Frequency", "Power", "");

   /* Add ID line if required */
   if (id == 1)
      cpgiden();

   /* Plot the points: */
   cpgline(npts, freqs, pwr);

   free(pwr);
}
/*
 * Class:     pulsarhunter_PgplotInterface
 * Method:    pgscf
 * Signature: (I)V
 */
JNIEXPORT void JNICALL Java_pulsarhunter_PgplotInterface_pgscf
  (JNIEnv *env, jclass cl , jint val){
	cpgscf(val);
}
Ejemplo n.º 7
0
void doPlot(pulsar *psr,int npsr,float *scale,int nScale,char *grDev,int plotUs,float fontSize,float centreMJD,int ptStyle,float ptSize,int error,float minyv,float maxyv,float minxv,float maxxv,int nOverlay,float labelsize,float fracX)
{
  int i,j,fitFlag=2,exitFlag=0,scale1=0,scale2,count[MAX_PSR],p,xautoscale=0,k,graphics=1;
  int yautoscale=0,plotpre=1;
  int ps,pe,pi;
  int time=0;
  char xstr[1000],ystr[1000];
  float px[2],py[2],pye1[2],pye2[2];
  float x[MAX_PSR][MAX_OBSN],y[MAX_PSR][MAX_OBSN],yerr1[MAX_PSR][MAX_OBSN],yerr2[MAX_PSR][MAX_OBSN],tmax,tmin,tmaxy1,tminy1,tmaxy2,tminy2;
  float sminy[MAX_PSR],smaxy[MAX_PSR];
  float minx[MAX_PSR],maxx[MAX_PSR],miny[MAX_PSR],maxy[MAX_PSR],plotx1,plotx2,ploty1,ploty2,mean;
  float fx[2],fy[2];
  float mouseX,mouseY;
  char key;
  //  float widthPap=0.0,aspectPap=0.618;
  float widthPap=0.0,aspectPap=1;
  float xx[MAX_OBSN],yy[MAX_OBSN],yyerr1[MAX_OBSN],yyerr2[MAX_OBSN];
  int num=0,colour;

  /* Obtain a graphical PGPLOT window */
  cpgbeg(0,grDev,1,1);
  //    cpgpap(widthPap,aspectPap);
  cpgsch(fontSize);
  cpgscf(2);
  cpgslw(2);
  cpgask(0);

  for (p=0;p<npsr;p++)
    {
      scale2 = psr[p].nobs;
      
      /*      sprintf(xstr,"MJD-%.1Lf",psr[0].param[param_pepoch].val[0]); */
      if (centreMJD == -1)
	sprintf(xstr,"Year"); 
      else
	sprintf(xstr,"MJD-%.1f",centreMJD); 

      sprintf(ystr,"Residual (\\gmsec)");
      
      count[p]=0;
      printf("points = %d\n",psr[p].nobs);
      for (i=0;i<psr[p].nobs;i++)
	{	  
	  if (psr[p].obsn[i].deleted == 0 &&
	      (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].bat) &&
	      (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].bat))
	    {
	      /* x[p][count[p]] = (double)(psr[p].obsn[i].bat-psr[0].param[param_pepoch].val[0]);	     	       */
	      if (centreMJD == -1)
		x[p][count[p]] = calcYr(psr[p].obsn[i].bat);
	      else
		x[p][count[p]] = (double)(psr[p].obsn[i].bat-centreMJD); 
	      y[p][count[p]] = (double)psr[p].obsn[i].residual*1.0e6;
	      if (nScale>0)
		y[p][count[p]] *= scale[p];
	      count[p]++;
	    }
	}
      /* Remove mean from the residuals and calculate error bars */
      mean = findMean(y[p],psr,p,scale1,count[p]);
      count[p]=0;
      for (i=0;i<psr[p].nobs;i++)
	{
	  if (psr[p].obsn[i].deleted==0   &&
	      (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].bat) &&
	      (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].bat))
	    {
	      psr[p].obsn[i].residual-=mean/1.0e6;
	      y[p][count[p]]-=mean;
	      yerr1[p][count[p]] = y[p][count[p]]-(float)psr[p].obsn[i].toaErr;
	      yerr2[p][count[p]] = y[p][count[p]]+(float)psr[p].obsn[i].toaErr;
	      count[p]++;
	    }
	}
    	  
      /* Get scaling for graph */
      if (minxv == maxxv) {
	minx[p] = findMin(x[p],psr,p,scale1,count[p]);
	maxx[p] = findMax(x[p],psr,p,scale1,count[p]);
      }
      else {
	minx[p] = minxv;
	maxx[p] = maxxv;
      }
      if (minyv == maxyv){
	miny[p] = findMin(y[p],psr,p,scale1,count[p]);
	maxy[p] = findMax(y[p],psr,p,scale1,count[p]);
      }
      else {
	miny[p] = minyv;
	maxy[p] = maxyv;
      }
      sminy[p] = miny[p]/1e6;
      smaxy[p] = maxy[p]/1e6;
    }
  for (p=0;p<npsr;p++)
    {
      for (i=0;i<count[p];i++)
	{
	  y[p][i] = (y[p][i]-miny[p])/(maxy[p]-miny[p]);
	  yerr1[p][i] = (yerr1[p][i]-miny[p])/(maxy[p]-miny[p]);
	  yerr2[p][i] = (yerr2[p][i]-miny[p])/(maxy[p]-miny[p]);
	}
      //      maxy[p] = 1.0;
      //      miny[p] = 0.0;
    }
  

  tmin = findMinVal(minx,npsr);
  tmax = findMaxVal(maxx,npsr);

  tminy2 = 0.0; //findMinVal(miny,npsr);
  tmaxy2 = 1.0; //findMaxVal(maxy,npsr);

  plotx1 = tmin-(tmax-tmin)*0.1;
  plotx2 = tmax+(tmax-tmin)*0.1;
  
  //  ploty1 = tminy2-(tmaxy2-tminy2)*0.1;
  //  ploty2 = tmaxy2+(tmaxy2-tminy2)*0.1;
	
  ploty1 = 0.1;
  ploty2 = 0.9;

  for (p=0;p<npsr;p++)
    {
      for (i=0;i<count[p];i++)
	{
	  y[p][i]=(p)+ploty1+y[p][i]*(ploty2-ploty1);
	  yerr1[p][i]=(p)+ploty1+yerr1[p][i]*(ploty2-ploty1);
	  yerr2[p][i]=(p)+ploty1+yerr2[p][i]*(ploty2-ploty1);
	}
    } 
  
  printf("ytick = %g\n",ploty2-ploty1);
      /*  cpgenv(plotx1,plotx2,ploty1,ploty2+(ploty2-ploty1)*(npsr-1),0,0); */
  //  cpgenv(plotx1,plotx2,0,npsr+1,0,-1);

  if (labelsize!=-1)
    cpgsch(labelsize);
  cpgsvp(fracX,1.0,0.1,1.0);
  cpgswin(0,1,0,npsr);
  cpgbox("ABC",0.0,0,"C",0.0,0);
  cpgsch(fontSize);
  char str[1000];
  for (p=0;p<npsr;p++)
    {
      cpgsch(fontSize);
      //      cpgtext(tmax+(tmax-tmin)*0.05,p+1.5-0.5,psr[p].name);
      cpgtext(0,p+0.6,psr[p].name);
      //      cpgsch(fontSize);
      if (plotUs==0)
	{
	  sprintf(str,"%.2f",(double)((smaxy[p]-sminy[p])*psr[p].param[param_f].val[0]));
	  cpgtext(0,p+0.4,str);
	  //	  cpgtext(tmax+(tmax-tmin)*0.05,p+1.1-0.5,str);
	}
      else
	{
	  sprintf(str,"%.2f\\gms",(double)((smaxy[p]-sminy[p])/1e-6));
	  //	  cpgtext(tmax+(tmax-tmin)*0.05,p+1.1-0.5,str);
	  cpgtext(0,p+0.1,str);
	}
      cpgsch(1);
      px[0] = 0;
      //      px[1] = tmax; //+(tmax-tmin)*0.03;
	px[1] = 1;
      py[0] = p;
      py[1] = p;
      cpgline(2,px,py);
      
    }
  if (labelsize!=-1)
    cpgsch(labelsize);

  cpgsvp(0.1,fracX,0.1,1.0);
  cpgswin(plotx1,plotx2,0,npsr);
  cpgbox("ATNSBC",0.0,0,"B",0.0,0);
  cpglab(xstr,"","");	    
  cpgsch(fontSize);

  for (p=0;p<npsr;p++)
    {
      cpgsls(1);
      px[0] = plotx1;
      //      px[1] = tmax; //+(tmax-tmin)*0.03;
      px[1] = plotx2;
      py[0] = p;
      py[1] = p;
      cpgline(2,px,py);
      cpgsls(4);
      px[0] = tmin;
      px[1] = tmax+(tmax-tmin)*0.03;

      py[0]=py[1] =(p)+ploty1+(-miny[p]/(maxy[p]-miny[p]))*(ploty2-ploty1);
      //      py[0]=py[1] = (p)+ploty1;
      //      py[0] = py[1] = (0-miny[p])/(maxy[p]-miny[p])/(ploty2-ploty1)+p;
      cpgline(2,px,py);

      px[0] = plotx1+0.005*(plotx2-plotx1);
      py[0] = p;
      pye1[0] = p + 5/(ploty2-ploty1);
      pye2[0] = p - 5/(ploty2-ploty1);
      cpgsls(1);
      cpgsch(3);
      //      cpgerry(1,px,pye1,pye2,1); 
      cpgsch(1);

      for (colour=0;colour<5;colour++)
	{
	  num=0;
	  for (i=0;i<count[p];i++)
	    {
	      if ((colour==0 && psr[p].obsn[i].freq<=500) ||
		  (colour==1 && psr[p].obsn[i].freq>500 && psr[p].obsn[i].freq<=1000) ||
		  (colour==2 && psr[p].obsn[i].freq>1000 && psr[p].obsn[i].freq<=1500) ||
		  (colour==3 && psr[p].obsn[i].freq>1500 && psr[p].obsn[i].freq<=3300) ||
		  (colour==4 && psr[p].obsn[i].freq>3300))
		{
		  xx[num]=x[p][i];
		  yy[num]=y[p][i];
		  yyerr1[num]=yerr1[p][i];
		  yyerr2[num]=yerr2[p][i];
		  //		  printf("plotting: %g\n",yy[num]);

		  num++;
		}
	    }
	  cpgsci(colour+1);
	  cpgsch(ptSize);
	  cpgpt(num,xx,yy,ptStyle);
	  if (error==1)
	    cpgerry(num,xx,yyerr1,yyerr2,1);
	  cpgsch(fontSize);
	  // Plot arrow giving one period
	  fx[0] = fx[1] = tmin-(tmax-tmin)*0.05;
	  //	  fy[0] = (p+1)+0.5-(float)(1.0/psr[p].param[param_f].val[0])/2.0/(ploty2-ploty1);
	  //	  fy[1] = (p+1)+0.5+(float)(1.0/psr[p].param[param_f].val[0])/2.0/(ploty2-ploty1);

	  //	  fy[0] = (-(float)(1.0/psr[p].param[param_f].val[0])/2.0/1.0e6 - miny[p])/(maxy[p]-miny[p])/(ploty2-ploty1) + (p+1)+0.5;
	  //	  fy[1] = ((float)(1.0/psr[p].param[param_f].val[0])/2.0/1.0e6 - miny[p])/(maxy[p]-miny[p])/(ploty2-ploty1) + (p+1)+0.5;
	  fy[0] = (p+1)+0.5+(float)(1.0/psr[p].param[param_f].val[0])/2.0/(maxy[p]-miny[p])*1e6;
	  fy[1] = (p+1)+0.5-(float)(1.0/psr[p].param[param_f].val[0])/2.0/(maxy[p]-miny[p])*1e6;
	  if (fy[0] > (p+1)+1) fy[0] = (p+1)+1;
	  if (fy[1] < (p+1)) fy[1] = (p+1);
	  
	  //	  cpgsls(1); cpgline(2,fx,fy); cpgsls(1);
	}
      cpgsci(1);
    }

  
  cpgend();
}
Ejemplo n.º 8
0
int makePlot (char *fname, char *dname, int number)
{
	FILE *fpt;
	double *on_energy;
	double *off_energy;
	double ave_on, ave_off;
	double on, off;
	int i, j;

	on_energy = (double *)malloc(sizeof(double)*number);
	off_energy = (double *)malloc(sizeof(double)*number);

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

	i = 0;
	while (fscanf(fpt, "%lf %lf", &on, &off) == 2)
	{
		on_energy[i] = on;
		off_energy[i] = off;
		i++;
	}

	if (fclose (fpt) != 0)
		fprintf (stderr, "Error closing\n");

	ave_on = 0.0;
	ave_off = 0.0;

	for (i = 0; i < number; i++)
	{
		ave_on += on_energy[i];
		ave_off += off_energy[i];
	}
	ave_on = ave_on/number;
	ave_off = ave_off/number;

	for (i = 0; i < number; i++)
	{
		on_energy[i] = on_energy[i]/ave_on;
		off_energy[i] = off_energy[i]/ave_on;
	}
	/////////////////////////////////////////////////

	float *xHis_on; // x axis of the histogram
	float *val_on;  // data value of the histogram
	float *xHis_off; // x axis of the histogram
	float *val_off;  // data value of the histogram
	int step = 100; // steps in the histogram

	//char caption[1024];
	//char text[1024];

	float max, max1, max2;

	// make histogram
	xHis_on = (float*)malloc(sizeof(float)*step);
	val_on = (float*)malloc(sizeof(float)*step);
	xHis_off = (float*)malloc(sizeof(float)*step);
	val_off = (float*)malloc(sizeof(float)*step);

	histogram (on_energy, number, xHis_on, val_on, -1.0, 4.0, step);
	histogram (off_energy, number, xHis_off, val_off, -1.0, 4.0, step);

	// plot 
	//cpgbeg(0,"/xs",1,1);
	cpgbeg(0,dname,1,1);

	cpgsch(1); // set character height
	cpgscf(1); // set character font

	// find the max
	max1 = find_max_value(step,val_off);
	max2 = find_max_value(step,val_on);
	max = (max1 >= max2 ? max1 : max2);
	//cpgenv(-5,5,0,4500,0,1); // set window and viewport and draw labeled frame
	cpgenv(-1,4,0,max+0.1*max,0,1); // set window and viewport and draw labeled frame

	//sprintf(caption, "%s", "Flux density histogram");
	cpglab("Flux (mJy)","Number","");
	cpgbin(step,xHis_on,val_on,0);
	cpgsci(2);
	cpgbin(step,xHis_off,val_off,0);
	///////////////////////////////////////////////////////
	cpgend();
	////////////////////

	free(on_energy);
	free(off_energy);
	free(xHis_on);
	free(val_on);
	free(xHis_off);
	free(val_off);

	return 0;
}
Ejemplo n.º 9
0
main(int argc, char *argv[])
{
  FILE *output;
  int numerate,i,j,k,l,nsperdmp,nsamps,indexing,plot,indexnow;
  int ifchan[16],frchan[4096],ifnum,chnum,ns,sample,ntotal;
  float time_of_pulse, width_of_pulse, time, time_start, time_end;
  float series_amp[100000],series_time[100000],ampmin,ampmax;
  char message[80],outfile[80],filename[80],timestring[80],pgdev[80];
  unsigned char c;
  unsigned short s;
  float f[8];

    if (argc<2) {
    puts("");
    puts("getpulse - make and/or plot a time series from dedispersed file\n"); 
    puts("usage: getpulse {filename} -{options}\n");
    puts("filename is the dedispersed data file\n");
    puts("options:\n");
    puts("-t time - time (in seconds) on which to center time series (REQUIRED)\n");
    puts("-w width - width (in seconds) of time series to plot (def=1)\n");
    puts("-c fchan - to only output frequency channel fchan (def=all)\n");
    puts("-i ifchan - to only output IF channel ifchan (def=all)\n");
    puts("-p pgdev - pgplot device (def=/xs)\n");
    puts("-numerate - to precede each dump with sample number (def=time)\n");
    puts("-noindex - do not precede each dump with time/number\n");
    puts("-plot - PGPLOT the results\n");
    puts("");
    exit(0);
   }

  /* zero IF and frequency channel arrays */
  for (i=0;i<16;i++)   ifchan[i]=0;
  for (i=0;i<4096;i++) frchan[i]=0;

  /* default case is to read from standard input */
  input=stdin;
  numerate=0;
  ampmin = 1.e6;
  ampmax = -1.e6;
  plot=0;
  indexnow=0;
  indexing=1;
  strcpy(pgdev,"/xs");

  /* parse command line if arguments were given */
  if (argc>1) {
    i=1;
    while (i<argc) {
        if (strings_equal(argv[i],"-i")) {
	i++;
	ifchan[atoi(argv[i])-1]=1;
      } else if (strings_equal(argv[i],"-c")) {
	i++;
	frchan[atoi(argv[i])-1]=1;
      } else if (strings_equal(argv[i],"-t")) {
        i++;
	time_of_pulse = atof(argv[i]);
        strcpy(timestring,argv[i]);
	fprintf(stderr,"centering on time %f s\n",time_of_pulse); 
      } else if (strings_equal(argv[i],"-w")) {
        i++;
        width_of_pulse = atof(argv[i]);
        fprintf(stderr,"with width %f s\n",width_of_pulse);
      } else if (strings_equal(argv[i],"-p")) {
        i++;
        strcpy(pgdev,argv[i]); 
      } else if (strings_equal(argv[i],"-numerate")) {
	numerate=1;
      } else if (strings_equal(argv[i],"-noindex")) {
	indexing=0;
      } else if (strings_equal(argv[i],"-plot")) {
	plot=1;
      } else if (file_exists(argv[i])) {
	input=open_file(argv[i],"rb");
        strcpy(filename,argv[i]);
      } else {
	sprintf(message,"unknown argument (%s) passed to getpulse",argv[i]);
	error_message(message);
      }
      i++;
    }
  }

  strcat(filename,".pulse.");
  strcat(filename,timestring);
  strcpy(outfile,filename);
  output=fopen(outfile,"w");
  time_start = time_of_pulse - width_of_pulse/2.;
  time_end = time_of_pulse + width_of_pulse/2.;
  sample = 0;
  /* try to read the header */
  if (!read_header(input)) error_message("error reading header\n");

  /* check what IF and frequency channels (if any the user has selected) */
  j=0;
  for (i=0; i<nifs; i++) if (ifchan[i]) j++;
  if (j==0) for (i=0; i<nifs; i++) ifchan[i]=1;
  j=0;
  for (i=0; i<nchans; i++) if (frchan[i]) j++;
  if (j==0) for (i=0; i<nchans; i++) frchan[i]=1;

  /* number of samples to read per dump */
  nsperdmp=nifs*nchans;
  /* initialize loop counters and flags */
  ifnum=chnum=nsamps=l=0;

  while (!feof(input)) {

    /* unpack the sample(s) if necessary */
    switch (nbits) {
    case 1:
      fread(&c,1,1,input);
      for (i=0;i<8;i++) {
	f[i]=c&1;
	c>>=1;
      }
      ns=8;
      break;
    case 4:
      fread(&c,1,1,input);
      char2ints(c,&j,&k);
      f[0]=(float) j;
      f[1]=(float) k;
      ns=2;
      break;
    case 8:
      fread(&c,nbits/8,1,input);
      f[0]=(float) c;
      ns=1;
      break;
    case 16:
      fread(&s,nbits/8,1,input);
      f[0]=(float) s;
      ns=1;
      break;
    case 32:
      fread(&f[0],nbits/8,1,input);
      ns=1;
      break;
    default:
      sprintf(message,"cannot read %d bits per sample...\n",nbits);
      error_message(message);
      break;
    }

    if (plot) {
       ntotal = (time_end-time_start)/tsamp;
       if (ntotal > 100000) {
	  fprintf(stderr,"Too many samples to plot!\n");
	  plot=0;
	}
    }
    for (i=0; i<ns; i++) {
      /* time stamp or index the data */
      time = (double) tsamp * (double) l;
      if (time > time_end) {
         if (plot) {
	       indexnow=indexnow-1;
	       cpgbeg(0,pgdev,1,1);
               cpgsvp(0.1,0.9,0.1,0.9);
               cpgswin(series_time[0],series_time[indexnow],ampmin-0.1*ampmax,ampmax+0.1*ampmax);
               cpgbox("bcnst",0.0,0,"bcnst",0,0.0);
               cpgline(indexnow,series_time,series_amp);
               cpgscf(2);
	       cpgmtxt("B",2.5,0.5,0.5,"Time (s)");
	       cpgmtxt("L",1.8,0.5,0.5,"Amplitude");
               cpgend();}
	    exit(0);
      }
      /* print sample if it is one of the ones selected */
      if (ifchan[ifnum] && frchan[chnum] && time >= time_start && time <= time_end) {
	if (indexing) {
           if (numerate) fprintf(output,"%d %f\n",l,f[i]);
           else fprintf(output,"%f %f\n",time,f[i]);
        }	
	else {
	   fprintf(output,"%f\n",f[i]);
	}
	if (plot) {
	   series_amp[indexnow]=f[i];
	   series_time[indexnow]=time;
           if (f[i] < ampmin) ampmin = f[i];
           if (f[i] > ampmax) ampmax = f[i];
           indexnow++;
	}
      } 
      nsamps++;
      chnum++;
      if (chnum==nchans) {
	chnum=0;
	ifnum++;
	if (ifnum==nifs) ifnum=0;
      }
      if ((nsamps%nsperdmp)==0) {
	nsamps=0;
	l++;
      }
      }
	}
    fclose(output);

}
Ejemplo n.º 10
0
/* set character font */
static void _pgscf (int *i)
{
   cpgscf (*i);
}