Beispiel #1
0
void plotsection(SET *p, GRAPHCONTROL *gr, int mode) {
	float *x = (mode == LAT) ? p->y : p->x;
	float *y = p->d;
	int i;

	float x1, x2, y1, y2;

	/* Check we have data */
	if (p->n ==0) {
		cpgsvp(0.07, 0.52, 0.07, 0.30);
		cpgswin(0.0, 1.0, 0.0, 1.0);
		cpgmtxt("T",-3, 0.5, 0.5, "-- Sem Dados -- ");
		return;
	}

	x1 = x2 = x[0];
	y1 = y2 = y[0];
	for(i=0;i<p->n; i++) {
		if (x[i] < x1) x1 = x[i];
		if (x[i] > x2) x2 = x[i];
		if (y[i] < y1) y1 = y[i];
		if (y[i] > y2) y2 = y[i];
	}

	y2 = (( (int)y2 / 50 ) + 1) * 50.0;

	// Plot
	cpgsvp(0.07, 0.52, 0.07, 0.30);
	cpgswin(x1, x2, y2, 0.0);
	cpgbox("BCNST", 0.0, 0, "BCNST", 0.0, 0);
	cpgsch(0.7);
	cpgmtxt("R", 1.0, 0.0, 0.0, "[L] Trocar Lat/Lon");
	cpgmtxt("B", 3.0, 0.5, 0.5, (mode == LAT) ? "Latitude\\m94" : "Longitude\\m94");
	cpgmtxt("L", 3.0, 0.5, 0.5, "Profundidade (km)");
	(gr->printout) ? cpgsch(1.5) : (p->n > 50) ? cpgsch(FS) : cpgsch(1.0);
	cpgbbuf();

	for(i = 0; i< p->n; i++) {
		if (gr->colormode == COLORDEPTH)
			cpgsci(depthcolor(y[i]));
		else if (gr->colormode == COLORMAG)
			cpgsci(magcolor(p->m[i]));
		cpgpt1(x[i], y[i], 1);
	}
	cpgebuf();



	// Terminate
	cpgsch(FS);
	cpgsci(1);
	cpgslw(1);

	return;
}
Beispiel #2
0
int enhance(GRAPHCONTROL *c, SET *p, int i) {
	float x, y, d, m;
	int yr, mo, dy;
	char t[1024];

	x = p->x[i];
	y = p->y[i];
	d = p->d[i];
	m = p->m[i];
	yr = p->yr[i];
	mo = p->mo[i];
	dy = p->dy[i];

	float xhalfwindow = (c->xmax + c->xmin) / 2;
	float yhalfwindow = (c->ymax + c->ymin) / 2;

	// Mark the dot
	cpgsch(FS+0.5);
	if(c->colormode == COLORMAG)
		cpgsci(magcolor(m));
	else if (c->colormode == COLORDEPTH)
		cpgsci(depthcolor(d));
	else
		cpgsci(1);
	cpgpt1(x, y, -4);
	cpgsci(1);
	cpgsch(FS);

	// Info box
	if (x < xhalfwindow && y < yhalfwindow) {
		cpgsvp(0.55, 0.9, 0.7, 0.8);
	} else if (x < xhalfwindow && y > yhalfwindow) {
		cpgsvp(0.55, 0.9, 0.45, 0.55);
	} else if (x > xhalfwindow && y < yhalfwindow) {
		cpgsvp(0.12, 0.47, 0.7, 0.8);
	} else if (x > xhalfwindow && y > yhalfwindow) {
		cpgsvp(0.12, 0.47, 0.45, 0.55);
	}

	cpgswin(0.0, 1.0, 0.0, 1.0);
	cpgsci(1);
	cpgrect(0.0, 1.0, 0.0, 1.0);
	cpgsci(0);
	cpgrect(0.02, .98, 0.02, 0.98);
	cpgsci(1);

	sprintf(t,"Evento, %d (%04d/%02d/%02d)",i, yr, mo, dy);
	cpgmtxt("T", -1.0, 0.1, .0, t);
	sprintf(t,"Long. %.2f Lat. %.2f",x,y);
	cpgmtxt("T", -2.0, 0.1, .0, t);
	sprintf(t,"Prof. %.1f Mag. %.1f",d, m);
	cpgmtxt("T", -3.0, 0.1, .0, t);

	return -1;
}
Beispiel #3
0
static void plot_rfi(rfi * plotrfi, float top, int numint, int numchan,
                     float T, float lof, float hif)
{
   int ii;
   float period, perioderr, dy = 0.035, *temparr;
   float tr[6] = { -0.5, 1.0, 0.0, -0.5, 0.0, 1.0 };
   char temp[40];

   if (plotrfi->freq_avg == 0.0)
      period = 0.0;
   else
      period = 1000.0 / plotrfi->freq_avg;
   if (plotrfi->freq_var == 0.0)        /* Why are these zero? */
      perioderr = 0.0;
   else
      perioderr = 1000.0 * sqrt(plotrfi->freq_var) /
          (plotrfi->freq_avg * plotrfi->freq_avg);
   cpgsvp(0.0, 1.0, 0.0, 1.0);
   cpgswin(0.0, 1.0, 0.0, 1.0);
   cpgnice_output_2(temp, plotrfi->freq_avg, sqrt(plotrfi->freq_var), 0);
   cpgptxt(0.03, top - 0.6 * dy, 0.0, 0.0, temp);
   cpgnice_output_2(temp, period, perioderr, 0);
   cpgptxt(0.12, top - 0.6 * dy, 0.0, 0.0, temp);
   sprintf(temp, "%-5.2f", plotrfi->sigma_avg);
   cpgptxt(0.21, top - 0.6 * dy, 0.0, 0.0, temp);
   sprintf(temp, "%d", plotrfi->numobs);
   cpgptxt(0.27, top - 0.6 * dy, 0.0, 0.0, temp);
   ii = (numint > numchan) ? numint : numchan;
   temparr = gen_fvect(ii);
   for (ii = 0; ii < numchan; ii++)
      temparr[ii] = GET_BIT(plotrfi->chans, ii);
   cpgsvp(0.33, 0.64, top - dy, top);
   cpgswin(0.0, numchan, 0.0, 1.0);
   cpgimag(temparr, numchan, 1, 1, numchan, 1, 1, 0.0, 1.0, tr);
   cpgswin(0.0, numchan, 0.0, 1.0);
   cpgbox("BST", 0.0, 0, "BC", 0.0, 0);
   cpgswin(lof, hif, 0.0, 1.0);
   cpgbox("CST", 0.0, 0, "", 0.0, 0);
   for (ii = 0; ii < numint; ii++)
      temparr[ii] = GET_BIT(plotrfi->times, ii);
   cpgsvp(0.65, 0.96, top - dy, top);
   cpgswin(0.0, numint, 0.0, 1.0);
   cpgimag(temparr, numint, 1, 1, numint, 1, 1, 0.0, 1.0, tr);
   cpgswin(0.0, numint, 0.0, 1.0);
   cpgbox("BST", 0.0, 0, "BC", 0.0, 0);
   cpgswin(0.0, T, 0.0, 1.0);
   cpgbox("CST", 0.0, 0, "", 0.0, 0);
   vect_free(temparr);
}
void plot_channel_data()
{
  int samp=0;
  int pg_id;

  pg_id = cpgopen("/XSERVE");
  cpgpap(8.0, 0.8);
  cpgask(0);
  cpgpage();
  cpgslct(pg_id);
  cpgsci(3);
  cpgeras();
  cpgsvp(0.15f, 0.95f, 0.2f, 0.8f);
  cpgupdt();
  cpgsch(2.0);
  cpgswin(0, read_count, -0.1f, 0.1f);
  cpgbox("BC1NST",0.0,0,"BCNST",0.0,0);
  cpglab("Time [samples]", "Voltage [volts]", "Antenna Measurement Receiver");
  cpgmove(samp, voltarray[0]);
  for (samp=2; samp<read_count; samp++)
	 {
	   cpgdraw(samp, voltarray[samp]);
	 }
  return 0;
}
Beispiel #5
0
int plotregion::erase(){
  cpgsfs(1);
  cpgsci(0);
  cpgsvp(0.0,1.0,0.0,1.0);
  cpgswin(0.0,1.0,0.0,1.0);
  cpgrect(xmin-0.065,xmax,ymin-0.1,ymax+0.025);
  cpgsci(1);
  return (0);
}
Beispiel #6
0
int plotregion::erase(float dx1, float dx2, float dy1, float dy2){
  cpgsfs(1);
  cpgsci(0);
  cpgsvp(0.0,1.0,0.0,1.0);
  cpgswin(0.0,1.0,0.0,1.0);
  cpgrect(xmin-dx1,xmax+dx2,ymin-dy1,ymax+dy2);
  cpgsci(1);
  return (0);
}
Beispiel #7
0
int main(int argc, char** argv)
{
  if(argc!=2)
    {
      perror("Invalid arguements : SMROStats <file.lba>\n");
      exit(1);
    }

  // Get the filename from the command line
  char* filename = argv[1];

  // Get stats for input file
  struct stat file_stats;
  if(stat(filename,&file_stats))
    {
      perror("Couldn't retrieve file information.\n");
      exit(1);
    }

  // Check length of input file
  int max=1024; // No. of blocks to read. When max=1024;64MB of input used 
  if(file_stats.st_size<(BLK_SIZE*max))
    max=file_stats.st_size/BLK_SIZE;

  // Data loader
  dsp::SMROFile* loader = new dsp::SMROFile;
  loader->open( filename );
  loader->set_output( new dsp::BitSeries );
  loader->set_block_size( BLK_SIZE );

  // Convert to a dsp::TimeSeries
  dsp::SMROTwoBitCorrection* unpacker = new dsp::SMROTwoBitCorrection;
  unpacker->set_input( loader->get_output() );
  unpacker->set_output( new dsp::TimeSeries );

  // Go to work
  int count;
  for(count=0;count<max;count++)  // Load and unpack (BLK_SIZE*max) bytes
    {
      loader->operate();
      unpacker->operate();
    }
  loader->close();

  // Plot Histogram
  cpgopen("?");
  cpglab("","","SMRO Sampler Statistics");
  cpgsvp(0.1,0.9,0.1,0.9);
  dsp::TwoBitStatsPlotter* plot = new dsp::TwoBitStatsPlotter;
  plot->set_data(unpacker);
  plot->plot();
  cpgclos();

  // Free memory
  delete loader,unpacker;
}
Beispiel #8
0
static void demo3()
{
#define TWOPI (2.0*3.14159265)
#define NPOL  6
  
  int i, j, k;
  int n1[] = {3, 4, 5, 5, 6, 8};
  int n2[] = {1, 1, 1, 2, 1, 3};
  float x[10], y[10], y0;
  
  char* lab[] =  {"Fill style 1 (solid)",
		  "Fill style 2 (outline)",
		  "Fill style 3 (hatched)",
		  "Fill style 4 (cross-hatched)"};
  
/* Initialize the viewport and window. */

  cpgbbuf();
  cpgsave();
  cpgpage();
  cpgsvp(0.0, 1.0, 0.0, 1.0);
  cpgwnad(0.0, 10.0, 0.0, 10.0);
  
/* Label the graph. */

  cpgsci(1);
  cpgmtxt("T", -2.0, 0.5, 0.5, 
          "PGPLOT fill area: routines cpgpoly(), cpgcirc(), cpgrect()");
  
/* Draw assorted polygons. */

  for (k=1; k<5; k++) {
    cpgsci(1);
    y0 = 10.0 -2.0*k;
    cpgtext(0.2, y0+0.6, lab[k-1]);
    cpgsfs(k);
    for (i=0; i<NPOL; i++) {
      cpgsci(i+1);
      for (j=0; j<n1[i]; j++) {
	x[j] = i+1 + 0.5*cos(n2[i]*TWOPI*j/n1[i]);
	y[j] = y0 + 0.5*sin(n2[i]*TWOPI*j/n1[i]);
      }
      cpgpoly(n1[i], x, y);
    }
    cpgsci(7);
    cpgshs(0.0, 1.0, 0.0);
    cpgcirc(7.0, y0, 0.5);
    cpgsci(8);
    cpgshs(-45.0, 1.0, 0.0);
    cpgrect(7.8, 9.5, y0-0.5, y0+0.5);
  }
  cpgunsa();
  cpgebuf();
  return;
}
Beispiel #9
0
int dialog::update(){   // Only draws what has changed
  cpgbbuf();
  cpgsvp(0.0,1.0,0.0,1.0);
  cpgswin(0.0,1.0,0.0,1.0);
  for (int i=0;i<nbutton;i++) buttons[i].draw();
  for (int i=0;i<nradio;i++) radios[i].draw();
  for (int i=0;i<ncheck;i++) checks[i].draw();
  for (int i=0;i<nstaticText;i++) staticTexts[i].draw();
  cpgebuf();
  return(0);
}
Beispiel #10
0
void scaledep() {
	int i, d;
	char t[24];

	cpgsci(1);
	cpgmtxt("T",1.0,0.0,0.0,"Prof.:");

	cpgsvp(0.12, 0.25, 0.912, 0.922);
	cpgswin(0.0,700.0, 0.0, 2.0);

	cpgsch(0.4);
	for(i=1.0;i<700.0;i+=10.0) {
		cpgsci(depthcolor((float)i));
		cpgpt1(i,1.0,16);
	}

	cpgsci(1);

	d = 0;
	cpgsci(depthcolor((float)d));
	sprintf(t,"%.1d",d);
	cpgtext(d-25.0,2.8,t);

	d = 15;
	cpgsci(depthcolor((float)d));
	sprintf(t,"%.1d",d);
	cpgtext(d-35.0,-1.8,t);

	d = 35;
	cpgsci(depthcolor((float)d));
	sprintf(t,"%.1d",d);
	cpgtext(d-20.0,2.8,t);

	d = 70;
	cpgsci(depthcolor((float)d));
	sprintf(t,"%.1d",d);
	cpgtext(d-25,-1.8,t);

	d = 120;
	cpgsci(depthcolor((float)d));
	sprintf(t,"%.1d",d);
	cpgtext(d-50,2.8,t);

	d = 300;
	cpgsci(depthcolor((float)d));
	sprintf(t,"%.1d",d);
	cpgtext(d-50,2.8,t);

	cpgsch(FS);
	cpgsci(1);

	return;
}
Beispiel #11
0
int dialog::draw(){

  cpgbbuf();
  cpgsvp(0.0,1.0,0.0,1.0);
  cpgswin(0.0,1.0,0.0,1.0);
  for (int i=0;i<nbutton;i++) buttons[i].draw();
  for (int i=0;i<nradio;i++) radios[i].draw();
  for (int i=0;i<ncheck;i++) checks[i].draw();
  for (int i=0;i<nstaticText;i++) staticTexts[i].draw();
  cpgebuf();
  return(0);
}
Beispiel #12
0
static void demo2()
{
  static int nx = 40, ny = 40;
  int i, j, k, lw, ci, ls;
  float f[1600], fmin, fmax, alev;
  double x, y;
  static float tr[6] = {0.0, 1.0, 0.0, 0.0, 0.0, 1.0};
  
  /* Compute a suitable function. A C array is used to emulate
     a 2D fortran array f(nx,ny). */

  fmin = fmax = 0.0;
  for (j=1; j<=ny; j++) {
    for (i=1; i<=ny; i++) {
      k = (j-1)*nx + (i-1);	/* Fortran convention */
      x = tr[0] + tr[1]*i + tr[2]*j;
      y = tr[3] + tr[4]*i + tr[5]*j;
      f[k] = cos(0.3*sqrt(x*2)-0.13333*y)*cos(0.13333*x)+
	(x-y)/(double)nx;
      if (f[k] < fmin) fmin = f[k];
      if (f[k] > fmax) fmax = f[k];
    }
  }
  
  /* Clear the screen. Set up window and viewport. */
  
  cpgpage();
  cpgsvp(0.05, 0.95, 0.05, 0.95);
  cpgswin(1.0, (float) nx, 1.0, (float) ny);
  cpgbox("bcts", 0.0, 0, "bcts", 0.0, 0);
  cpgmtxt("t", 1.0, 0.0, 0.0, "Contouring using cpgcont()");
  
  /* Draw the map. cpgcont is called once for each contour, using
     different line attributes to distinguish contour levels. */
  
  cpgbbuf();
  for (i=1; i<21; i++) {
    alev = fmin + i*(fmax-fmin)/20.0;
    lw = (i%5 == 0) ? 3 : 1;
    ci = (i < 10)   ? 2 : 3;
    ls = (i < 10)   ? 2 : 1;
    cpgslw(lw);
    cpgsci(ci);
    cpgsls(ls);
    cpgcont(f, nx, ny, 1, nx, 1, ny, &alev, -1, tr);
  }
  cpgslw(1);
  cpgsls(1);
  cpgsci(1);
  cpgebuf();
  return;
}
Beispiel #13
0
int button::draw(){
cpgsvp(0.0,1.0,0.0,1.0);
cpgswin(0.0,1.0,0.0,1.0);
cpgsfs(2);

float xl, yl;
cpglen(4,label,&xl,&yl);
xmin = x-2.0*0.005; 
xmax = x + xl + 2.0 * 0.005;
ymin = y-2.0*0.005;
ymax = y+0.015 + 2.0 * 0.005;

cpgsci(1);
cpgrect(x-0.005, x+xl+0.005, y-0.005, y+0.015 + 0.005);
cpgrect(x-2.0*0.005, x+xl+2.0*0.005, y-2.0*0.005, y+0.015 + 2.0*0.005);
cpgtext(x,y,label);
 return(0);
}
Beispiel #14
0
static void plot_harmonics(double rr, int zoomlevel, fftpart * fp)
{
   int ii, hh;
   double offsetf;
   char label[20];
   fftview *harmview;

   cpgsubp(4, 4);
   for (ii = 0, hh = 2; ii < 8; ii++, hh++) {
      cpgpanl(ii % 4 + 1, ii / 4 + 1);
      harmview = get_harmonic(hh * rr, zoomlevel, fp);
      if (harmview != NULL) {
         offsetf = plot_fftview(harmview, 0.0, 2.0, hh * rr, 2);
         snprintf(label, 20, "Harmonic %d", hh);
         cpgsave();
         cpgsch(2.0);
         cpgmtxt("T", -1.8, 0.05, 0.0, label);
         cpgunsa();
         free(harmview);
      }
   }
   for (ii = 8, hh = 2; ii < 16; ii++, hh++) {
      cpgpanl(ii % 4 + 1, ii / 4 + 1);
      harmview = get_harmonic(rr / (double) hh, zoomlevel, fp);
      if (harmview != NULL) {
         offsetf = plot_fftview(harmview, 0.0, 2.0, rr / (double) hh, 2);
         snprintf(label, 20, "Harmonic 1/%d", hh);
         cpgsave();
         cpgsch(2.0);
         cpgmtxt("T", -1.8, 0.05, 0.0, label);
         cpgunsa();
         free(harmview);
      }
   }
   cpgsubp(1, 1);
   cpgpanl(1, 1);
   cpgsvp(0.0, 1.0, 0.0, 1.0);
   cpgswin(2.0, 6.0, -2.0, 2.0);
   cpgmove(2.0, 0.0);
   cpgslw(3);
   cpgdraw(6.0, 0.0);
   cpgslw(1);
}
// make a single Aitoff sky projection plot
//   using the data in ravec[field], decvec[field], and value[filter][field],
//   using the min and max data values in valmin[filter] and valmax[filter]
//   with filter=0
void plotOne(double nfields, double *value,
             double *ravec, double *decvec,
             double valmin, double valmax,
             char *label, char *title, char *plotName) {
  int nf;
  double xmin, xmax, ymin, ymax;

  // set up the plot
  openPlot(plotName);
  cpgbbuf();

  cpgpap(PLOTSIZE/0.7,0.7);

  cpgsvp(0.02,0.98,0.02,0.98);

  xmax = M_PI;      xmin = -xmax;
  ymax = 0.67*M_PI; ymin = -ymax;
  ymin -= 0.1*ymax; ymax -= 0.1*ymax;

  setupImplot(0.0, 1.0);
  cpgswin(xmin,xmax,ymin,ymax);

  // make a projected field circle for each field
  cpgsch(1.0);
  for(nf=0; nf<nfields; nf++) {
    projCircle(ravec[nf], decvec[nf], FIELD_RADIUS, 
               (value[nf]-valmin)/(valmax-valmin));
  }
  // the grids and galactic exclusion
  aitoffGrid();
  galaxy(peakL, taperL, taperB);

  cpgslw(2);
  cpgsch(2.0);
  cpgswin(0,1,0,1);
  mywedg(0.21, 0.15, 1.0, 12.0, valmin, valmax, label);
  cpgptxt(0.5,0.95,0.0,0.5,title);
  cpgslw(1);

  cpgebuf();
  closePlot();
}
Beispiel #16
0
void scalemag() {
	int i;
	char t[24];

	cpgsci(1);
	cpgmtxt("T",1.0,0.0,0.0,"Mag.:");
	cpgsvp(0.12, 0.25, 0.912, 0.922);
	cpgswin(0.0, 11.0, 0.0, 2.0);

	cpgsch(0.4);
	for(i=0.0;i<10.0;i++) {
		cpgsci(magcolor((float)i));
		sprintf(t,"%.1d",i);
		cpgtext(i+1-0.12,2.8,t);
		cpgpt1(i+1,1.0,16);
	}
	cpgsch(FS);
	cpgsci(1);

	return;
}
int plot_freq_data(void)
{
  int bin=0;

  printf("\nPlotting ...");
  cpgask(0);
  cpgpage();
  cpgslct(pg_id);
  cpgsci(1);
  cpgeras();
  cpgsvp(0.15f, 0.95f, 0.2f, 0.8f);
  cpgupdt();
  cpgsch(2.0);
  cpgswin(0, (N/2)+1, 0.0f, 0.005f);
  //  cpgswin(80, 120, 0.0f, 0.01f);
  cpgbox("BC1NST",0.0,0,"BCNST",0.0,0);
  cpglab("Frequency [bins]", "Peak Voltage [volts]", "Antenna Measurement Receiver");
  cpgmove(bin, accumFreqData[0]);
  for (bin=1; bin<(N/2)+1; bin++)
	 {
	   cpgdraw(bin, accumFreqData[bin]);
	 }
  return 0;
}
Beispiel #18
0
void plothistogram(SET *p, float w, int mode, float lm, float hm) {
	float *x = (mode == MAG) ? p->m : p->d;
	int i;
	char t[1024];

	float x1, x2, y1, y2;

	float *bins = NULL;
	float *freq = NULL;
	int nb;

	float a, b;
	float rms = -1;

	cpgsvp(0.63, 0.93, 0.07, 0.30);

	/* Check we have data */
	if (p->n ==0) {
		cpgswin(0.0, 1.0, 0.0, 1.0);
		cpgmtxt("T",-3, 0.5, 0.5, "-- Sem Dados -- ");
		return;
	}

	if (mode == MAG) {
		nb = gomag(x, p->n, w, &bins, &freq);
		rms = linefit(bins, freq, nb, lm, hm, &a, &b);
	} else {
		nb = godep(x, p->n, w, &bins, &freq);
	}

	/*
	 * Plot
	 */

	minmax(x, p->n, &x1, &x2);
	minmax(freq, nb, &y1, &y2);
	cpgswin(x1, x2, y1 - (y2-y1)*0.1, y2 * 1.2);
	cpgbox("BCNST", 0.0, 0, "BCMST", 0.0, 0);

	/*
	 * Labels
	 */
	cpgsch(0.7);
	cpgmtxt("L", 2.2, 0.0, 0.0, "[H] Trocar Mag/Dep");
	cpgmtxt("L", 1.0, 0.0, 0.0, "[B] Ajustar largura do bin");

	if (mode == MAG) {
		cpgmtxt("R", 3.0, 0.5, 0.5, "Log(n) Acumulado");
		cpgmtxt("B", 3.0, 0.5, 0.5, "Magnitude");

	} else {
		cpgmtxt("R", 3.0, 0.5, 0.5, "Log(n)");
		cpgmtxt("B", 3.0, 0.5, 0.5, "Profundidade (km)");
	}
	sprintf(t,"Min: %.1f Max: %.1f",x1,x2);
	if (mode == MAG) {
		cpgmtxt("B", -1.0, 0.05, 0.0,t);
	} else {
		cpgmtxt("T", -2.0, 0.95, 1.0,t);
	}
	cpgsch(FS);

	/*
	 * Plots
	 */
	cpgbin(nb, bins, freq, 1);

	if (mode == MAG) {
		cpgmove(x1, a*x1 + b);
		cpgdraw(x2, a*x2 + b);
		if ( lm >= 0.0 ) {
			float temp;
			
			cpgsci(2);
			cpgsch(1.2);
			temp = fabs((a*x1+b) - (a*x2+b));
			cpgpt1(lm, a*lm+b -temp * 0.06, 30);
			cpgpt1(hm, a*hm+b -temp * 0.06, 30);
			cpgsci(1);
			cpgsch(FS);
		}
	}

	if (mode == MAG) {
		cpgsch(0.7);
		sprintf(t,"f(x)=%.2f\\.x+%.2f",a,b);
		cpgmtxt("T",-2.0, 0.9, 1.0,t);

		sprintf(t,"b=%.2f",fabs(a));
		cpgmtxt("T",-3.2, 0.9, 1.0,t);
		cpgsch(FS);
	}

	cpgbbuf();

	/*
	 * Terminate
	 */
	cpgsci(1);
	cpgslw(1);

	cpgebuf();

	if (bins != NULL) free(bins);
	if (freq != NULL) free(freq);

	bins = NULL;
	freq = NULL;

	return;
}
Beispiel #19
0
void plot(GRAPHCONTROL *gr, SET *p) {
	char t[1024];

	cpgsch(FS);
	cpgsci(1);

	cpgsvp(0.07, 0.93, 0.35, 0.9);
	cpgeras();
	cpgswin(gr->xmin, gr->xmax, gr->ymin, gr->ymax);
	cpgbox("BCNST", 0.0, 0, "BCNST", 0.0, 0);

	cpgbbuf();

	cpgsch(0.8);
	float yp = 3.4;

	sprintf(t,"[n] Ano: %d/%d", p->y1, p->y2);
	cpgmtxt("T", yp, 0.0, 0.0, t);

	sprintf(t,"[m] Magnitude: %.2f/%.2f", p->m1, p->m2);
	cpgmtxt("T", yp, 0.25, 0.0, t);

	sprintf(t,"[s/0] Selecionar Regiao");
	(p->region) ? cpgsci(ON) : cpgsci(OFF);
	cpgmtxt("T", yp, 0.6, 0.0, t);
	cpgsci(1);

	cpgmtxt("T", yp, 0.85, 0.0, "[=] Salvar Print-out");


	yp -= 1.2;

	sprintf(t,"N: %ld",p->n);
	cpgmtxt("T", yp, 0.0, 0.0, t);

	sprintf(t,"[p] Profundidade(p): %.1f/%.1f",p->d1, p->d2);
	cpgmtxt("T", yp, 0.25, 0.0, t);

	sprintf(t,"Longitude: %.2f/%.2f",p->lon1, p->lon2);
	cpgmtxt("T", yp, 0.6, 0.0, t);

        cpgmtxt("T", yp, 0.85, 0.0, "[J] Definir intervalo");

	yp -= 1.2;

	sprintf(t,"Latitude: %.2f/%.2f", p->lat1, p->lat2);
	cpgmtxt("T", yp, 0.6, 0.0, t);

	sprintf(t,"[w] Zoom para todo o mapa");
	cpgmtxt("T", yp, 0.25, 0.0, t);
        
        cpgmtxt("T", yp, 0.85, 0.0, "    de ajuste");
        
	sprintf(t,"[c] Cor: %s", (gr->colormode == COLORDEPTH) ? "Profundidade" : (gr->colormode == COLORMAG) ? "Magnitude" : "Neutra");
	cpgmtxt("R", 1.0, 1.0, 1.0, t);


	(gr->hascontinents) ? cpgsci(ON) : cpgsci(OFF);
	sprintf(t,"[1] Continentes");
	cpgmtxt("R", 1.0, 0.25, 0.0, t);
	cpgsci(1);

	(gr->hasplates) ? cpgsci(ON) : cpgsci(OFF);
	sprintf(t,"[2] Placas");
	cpgmtxt("R", 1.0, 0.0, 0.0, t);
	cpgsci(1);

	// Legenda cores
	cpgsci(1);
	cpgsch(FS);

		/* Graphs */
	int i;
	if (gr->haspoints && p->n > 0) {

		int symbol = 17;
		(p->n > 50) ?  cpgsch(0.4) : cpgsch(FS);

		if (gr->colormode == COLORDEPTH)
			for(i = 0; i< p->n; i++) {
				cpgsci(depthcolor(p->d[i]));
				cpgpt1(p->x[i], p->y[i], symbol);
			}
		else if (gr->colormode == COLORMAG)
			for(i = 0; i< p->n; i++) {
				cpgsci(magcolor(p->m[i]));
				cpgpt1(p->x[i], p->y[i], symbol);
			}
		else
			cpgpt(p->n, p->x, p->y, symbol);

		cpgsci(1);
		cpgsch(FS);
	}

	if (gr->hascontinents >= 1) {
		cpgsci(1);
		cpgslw(2);
		for(i=0; i < ncontinentes; i++) {
			if (continentes[i][0] == -999 && continentes[i][1] == 999 ) {
				i++;
				cpgmove(continentes[i][0], continentes[i][1]);
				continue;
			}
			cpgdraw(continentes[i][0], continentes[i][1]);
		}

		if (gr->hascontinents >=2) {
			cpgslw(1);
			cpgsci(15);
			for(i=0; i < nborders; i++) {
				if (borders[i][0] == -999 && borders[i][1] == 999 ) {
					i++;
					cpgmove(borders[i][0], borders[i][1]);
					continue;
				}
				cpgdraw(borders[i][0], borders[i][1]);
			}
		}
	}

	if (gr->hasplates == 1) {
		cpgsci(3);
		cpgslw(3);
		for(i=0; i < nplates; i++) {
			if (plates[i][0] == -999 && plates[i][1] == 999 ) {
				i++;
				cpgmove(plates[i][0], plates[i][1]);
				continue;
			}
			if (fabs(plates[i][0] - plates[i-1][0]) > 180) {
				cpgmove(plates[i][0], plates[i][1]);
			}
			cpgdraw(plates[i][0], plates[i][1]);
		}
	}

	if (gr->colormode == COLORMAG)
		scalemag();
	else if (gr->colormode == COLORDEPTH)
		scaledep();

	cpgsci(1);
	cpgslw(1);

	cpgebuf();

	cpgsvp(0.07, 0.93, 0.35, 0.9);
	cpgswin(gr->xmin, gr->xmax, gr->ymin, gr->ymax);

	return;
}
Beispiel #20
0
// Sets the plot back to last coordinates
int plotregion::reset(){
  cpgsvp(xmin,xmax,ymin,ymax);
  cpgswin(xminworld,xmaxworld,yminworld,ymaxworld);
  return(0);
}
Beispiel #21
0
// Sets the plot coordinates
int plotregion::set(float xmn, float xmx, float ymn, float ymx){
  xminworld = xmn; yminworld = ymn; xmaxworld = xmx; ymaxworld = ymx;
  cpgsvp(xmin,xmax,ymin,ymax);
  cpgswin(xmn,xmx,ymn,ymx);
  return(0);
}
Beispiel #22
0
int main(int argc, char** argv){
	float tr[6];

	const float ZAP=32;
	const uint64_t TSIZE=18;
	const uint64_t zapE=64;
	fftwf_init_threads();
	fftwf_plan_with_nthreads(omp_get_max_threads());

	logmsg("Open file '%s'",argv[1]);
	FILE* f = fopen(argv[1],"r");

	int hdr_bytes = read_header(f);
	const uint64_t nskip = hdr_bytes;
	const uint64_t nchan = nchans;
	logmsg("Nchan=%"PRIu64", tsamp=%f",nchan,tsamp);
	mjk_rand_t *random = mjk_rand_init(12345);

	rewind(f);
	FILE* of = fopen("clean.fil","w");
	uint8_t hdr[nskip];
	fread(hdr,1,nskip,f);
	fwrite(hdr,1,nskip,of);
	const uint64_t nsamp_per_block=round(pow(2,TSIZE));

	logmsg("Tblock = %f",nsamp_per_block*tsamp);

	mjk_clock_t *t_all = init_clock();
	start_clock(t_all);

	mjk_clock_t *t_read = init_clock();
	mjk_clock_t *t_trns= init_clock();
	mjk_clock_t *t_rms = init_clock();
	mjk_clock_t *t_fft = init_clock();
	mjk_clock_t *t_spec = init_clock();

	const uint64_t bytes_per_block = nchan*nsamp_per_block;

	uint8_t *buffer = calloc(bytes_per_block,1);
	float **data = malloc_2df(nchan,nsamp_per_block);
	float **clean = malloc_2df(nchan,nsamp_per_block);
	float *bpass = calloc(nchan,sizeof(float));
	float  *ch_var=NULL;
	float  *ch_mean=NULL;
	float  *ch_fft_n=NULL;
	float  *ch_fft_p=NULL;


	logmsg("Planning FFT - this will take a long time the first time it is run!");
	start_clock(t_fft);
	FILE * wisfile;
	if(wisfile=fopen("wisdom.txt","r")){
		fftwf_import_wisdom_from_file(wisfile);
		fclose(wisfile);
	}
	const int fftX=nsamp_per_block;
	const int fftY=nchan;
	const int fftXo=nsamp_per_block/2+1;

	float *X = fftwf_malloc(sizeof(float)*fftX);

	for (uint64_t i = 0; i < nsamp_per_block ; i++){
		X[i]=i;
	}
	float *tseries = fftwf_malloc(sizeof(float)*fftX);
	float complex *fseries = fftwf_malloc(sizeof(float complex)*fftXo);
	float *pseries = fftwf_malloc(sizeof(float)*fftXo);
	uint8_t *mask = malloc(sizeof(uint8_t)*fftXo);
	fftwf_plan fft_1d = fftwf_plan_dft_r2c_1d(fftX,tseries,fseries,FFTW_MEASURE|FFTW_DESTROY_INPUT);

	complex float * fftd = fftwf_malloc(sizeof(complex float)*(fftXo*fftY));
	fftwf_plan fft_plan = fftwf_plan_many_dft_r2c(
			1,&fftX,fftY,
			data[0] ,&fftX,1,fftX,
			fftd    ,&fftXo,1,fftXo,
			FFTW_MEASURE|FFTW_PRESERVE_INPUT);
	logmsg("Planning iFFT - this will take a long time the first time it is run!");
	fftwf_plan ifft_plan = fftwf_plan_many_dft_c2r(
			1,&fftX,fftY,
			fftd ,&fftXo,1,fftXo,
			clean[0] ,&fftX,1,fftX,
			FFTW_MEASURE|FFTW_PRESERVE_INPUT);

	if(!fft_plan){
		logmsg("Error - could not do FFT plan");
		exit(2);
	}

	wisfile=fopen("wisdom.txt","w");
	fftwf_export_wisdom_to_file(wisfile);
	fclose(wisfile);
	stop_clock(t_fft);
	logmsg("T(planFFT)= %.2lfs",read_clock(t_fft));
	reset_clock(t_fft);



	float min_var=1e9;
	float max_var=0;

	float min_fft_n=1e9;
	float max_fft_n=0;


	float min_fft_p=1e9;
	float max_fft_p=0;

	float min_mean=1e9;
	float max_mean=0;
	uint64_t nblocks=0;
	uint64_t totread=0;
	while(!feof(f)){
		nblocks++;
		ch_var = realloc(ch_var,nchan*nblocks*sizeof(float));
		ch_mean = realloc(ch_mean,nchan*nblocks*sizeof(float));
		ch_fft_n = realloc(ch_fft_n,nchan*nblocks*sizeof(float));
		ch_fft_p = realloc(ch_fft_p,nchan*nblocks*sizeof(float));
		start_clock(t_read);
		uint64_t read = fread(buffer,1,bytes_per_block,f);
		stop_clock(t_read);
		if (read!=bytes_per_block){
			nblocks--;
			break;
		}
		totread+=read;
		logmsg("read=%"PRIu64" bytes. T=%fs",read,totread*tsamp/(float)nchan);
		uint64_t offset = (nblocks-1)*nchan;
		start_clock(t_trns);
		// transpose with small blocks in order to increase cache efficiency.
#define BLK 8
#pragma omp parallel for schedule(static,2) shared(buffer,data)
		for (uint64_t j = 0; j < nchan ; j+=BLK){
			for (uint64_t i = 0; i < nsamp_per_block ; i++){
				for (uint64_t k = 0; k < BLK ; k++){
					data[j+k][i] = buffer[i*nchan+j+k];
				}
			}
		}

#pragma omp parallel for shared(data)
		for (uint64_t j = 0; j < nchan ; j++){
			if(j<zapE || (nchan-j) < zapE){ 
				for (uint64_t i = 0; i < nsamp_per_block ; i++){
					data[j][i]=ZAP;
				}
			}
		}

		if(nblocks==1){
#pragma omp parallel for shared(data,bpass)
			for (uint64_t j = 0; j < nchan ; j++){
				for (uint64_t i = 0; i < nsamp_per_block ; i++){
					bpass[j]+=data[j][i];
				}
				bpass[j]/=(float)nsamp_per_block;
				bpass[j]-=ZAP;
			}
		}
#pragma omp parallel for shared(data,bpass)
		for (uint64_t j = 0; j < nchan ; j++){
			for (uint64_t i = 0; i < nsamp_per_block ; i++){
				data[j][i]-=bpass[j];
			}
		}




		stop_clock(t_trns);

		start_clock(t_rms);
#pragma omp parallel for shared(data,ch_mean,ch_var)
		for (uint64_t j = 0; j < nchan ; j++){
			float mean=0;
			for (uint64_t i = 0; i < nsamp_per_block ; i++){
				mean+=data[j][i];
			}
			mean/=(float)nsamp_per_block;
			if(mean > ZAP+5 || mean < ZAP-5){
				logmsg("ZAP ch=%"PRIu64,j);
				for (uint64_t i = 0; i < nsamp_per_block ; i++){
					data[j][i]=ZAP;
				}
			}

			float ss=0;
			float x=0;
			for (uint64_t i = 0; i < nsamp_per_block ; i++){
				x = data[j][i]-mean;
				ss+=x*x;
			}
			float var=ss/(float)nsamp_per_block;
			if (var > 0){
				for (uint64_t i = 0; i < nsamp_per_block ; i++){
					float v = (data[j][i]-mean)/sqrt(var);
					if(v > 3 || v < -3){
						data[j][i]=mjk_rand_gauss(random)*sqrt(var)+mean;
					}
				}
			}

			ch_var[offset+j] = var;
			ch_mean[offset+j] = mean;

		}
		stop_clock(t_rms);

		for (uint64_t i = 0; i < nsamp_per_block ; i++){
			tseries[i]=0;
		}

		float tmean=0;
		float tvar=0;
		float max=0;
		float min=1e99;
		//#pragma omp parallel for shared(data,tseries)
		// NOT THREAD SAFE
		for (uint64_t j = 0; j < nchan ; j++){
			tmean+=ch_mean[offset+j];
			tvar+=ch_var[offset+j];
			for (uint64_t i = 0; i < nsamp_per_block ; i++){
				tseries[i]+=data[j][i];
				if(data[j][i]>max)max=data[j][i];
				if(data[j][i]<min)min=data[j][i];
			}
		}
		float ss=0;
		float mm=0;
		for (uint64_t i = 0; i < nsamp_per_block ; i++){
			float x=tseries[i]-tmean;
			mm+=tseries[i];
			ss+=x*x;
		}
		float rvar=ss/(float)nsamp_per_block;
		logmsg("var=%g tvar=%g",ss/(float)nsamp_per_block,tvar);
		logmsg("mean=%g tmean=%g",mm/(float)nsamp_per_block,tmean);
		cpgopen("3/xs");
		cpgsvp(0.1,0.9,0.1,0.9);
		cpgswin(0,fftX,tmean-sqrt(tvar)*30,tmean+sqrt(tvar)*30);
		cpgbox("ABN",0,0,"ABN",0,0);
		cpgline(fftX,X,tseries);
		cpgsci(2);
		cpgclos();
		tr[0] = 0.0 ;
		tr[1] = 1;
		tr[2] = 0;
		tr[3] = 0.5;
		tr[4] = 0;
		tr[5] = 1;

		logmsg("max=%g min=%g",max,min);

		cpgopen("4/xs");
		cpgsvp(0.1,0.9,0.1,0.9);
		cpgswin(0,nsamp_per_block,0,nchan);
		cpgbox("ABN",0,0,"ABN",0,0);
		cpggray(*data,nsamp_per_block,nchan,1,nsamp_per_block,1,nchan,tmean/(float)nchan+sqrt(rvar/(float)nchan),tmean/(float)nchan-sqrt(rvar/(float)nchan),tr);
		cpgclos();




		start_clock(t_fft);
		fftwf_execute(fft_1d);
		fftwf_execute(fft_plan);
		stop_clock(t_fft);

		{
			float T = sqrt(fftXo*tvar)*12;
			logmsg("Zap T=%.2e",T);

			float fx[fftXo];
			float fT[fftXo];
#pragma omp parallel for shared(fseries,pseries,mask)
			for (uint64_t i = 0; i < fftXo ; i++){
				mask[i]=1;
			}
#pragma omp parallel for shared(fseries,pseries,mask)
			for (uint64_t i = 0; i < fftXo ; i++){
				pseries[i]=camp(fseries[i]);
				fx[i]=i;
				float TT = T;
				if (i>512)TT=T/2.0;
				if(i>32){
					fT[i]=TT;
					if (pseries[i] > TT) {
						mask[i]=0;
					}
				} else fT[i]=0;
			}

			uint64_t nmask=0;
			for (uint64_t i = 0; i < fftXo ; i++){
				if (mask[i]==0){
					nmask++;
				}
			}
			logmsg("masked=%d (%.2f%%)",nmask,100*nmask/(float)fftXo);
			cpgopen("1/xs");
			cpgsvp(0.1,0.9,0.1,0.9);
			cpgswin(0,fftXo,0,T*10);
			cpgbox("ABN",0,0,"ABN",0,0);
			cpgline(fftXo,fx,pseries);
			cpgsci(2);
			cpgline(fftXo,fx,fT);
			cpgclos();

		}


		//		exit(1);

		start_clock(t_spec);

		//FILE* ff=fopen("plot","w");
#pragma omp parallel for shared(fftd,ch_mean,ch_fft_n,ch_fft_p)
		for (uint64_t j = 0; j < nchan ; j++){
			float var = ch_var[offset+j];
			float m=sqrt(var*fftXo/2.0);
			float T = sqrt(var*fftXo)*3;
			uint64_t n=0;
			float p=0;
			float complex *fftch = fftd + fftXo*j;
			for(uint64_t i = 1; i < fftXo; i++){
				if (camp(fftch[i]) > T) {
					n++;
					p+=camp(fftch[i]);
				}
				//	 if(j==512)fprintf(ff,"%f ",camp(fftch[i]));
				if(mask[i]==0){
					fftch[i]=m*(mjk_rand_gauss(random) + I*mjk_rand_gauss(random)); 
				}
				//	 if(j==512)fprintf(ff,"%f\n",camp(fftch[i]));
			}
			ch_fft_n[offset+j]=n;
			ch_fft_p[offset+j]=p;
		}
		// fclose(ff);

		logmsg("iFFT");
		fftwf_execute(ifft_plan);

#pragma omp parallel for schedule(static,2) shared(buffer,clean)
		for (uint64_t j = 0; j < nchan ; j+=BLK){
			for (uint64_t i = 0; i < nsamp_per_block ; i++){
				for (uint64_t k = 0; k < BLK ; k++){
					clean[j+k][i]/=(float)fftX;
					buffer[i*nchan+j+k] = round(clean[j+k][i]);
				}
			}

			if(j==512){
				cpgopen("2/xs");
				cpgsvp(0.1,0.9,0.1,0.9);
				cpgswin(0,fftX,ch_mean[j]-sqrt(ch_var[j])*10,ch_mean[j]+sqrt(ch_var[j])*10);
				cpgbox("ABN",0,0,"ABN",0,0);
				cpgline(fftX,X,data[j]);
				cpgsci(2);
				cpgline(fftX,X,clean[j]);
				cpgclos();

			}

		}
		fwrite(buffer,1,bytes_per_block,of);


		for (uint64_t i = 0; i < nsamp_per_block ; i++){
			tseries[i]=0;
		}

		tmean=0;
		tvar=0;
		max=0;
		min=1e99;
		//#pragma omp parallel for shared(clean,tseries)
		// NOT THREAD SAFE
		for (uint64_t j = 0; j < nchan ; j++){
			tmean+=ch_mean[offset+j];
			tvar+=ch_var[offset+j];
			for (uint64_t i = 0; i < nsamp_per_block ; i++){
				tseries[i]+=clean[j][i];
				if(clean[j][i]>max)max=clean[j][i];
				if(clean[j][i]<min)min=clean[j][i];
			}
		}
		ss=0;
		mm=0;
		for (uint64_t i = 0; i < nsamp_per_block ; i++){
			float x=tseries[i]-tmean;
			mm+=tseries[i];
			ss+=x*x;
		}
		rvar=ss/(float)nsamp_per_block;
		logmsg("var=%g tvar=%g",ss/(float)nsamp_per_block,tvar);
		logmsg("mean=%g tmean=%g",mm/(float)nsamp_per_block,tmean);
		cpgopen("5/xs");
		cpgsvp(0.1,0.9,0.1,0.9);
		cpgswin(0,fftX,tmean-sqrt(tvar)*30,tmean+sqrt(tvar)*30);
		cpgbox("ABN",0,0,"ABN",0,0);
		cpgline(fftX,X,tseries);
		cpgsci(2);
		cpgclos();
		tr[0] = 0.0 ;
		tr[1] = 1;
		tr[2] = 0;
		tr[3] = 0.5;
		tr[4] = 0;
		tr[5] = 1;

		logmsg("max=%g min=%g",max,min);

		cpgopen("6/xs");
		cpgsvp(0.1,0.9,0.1,0.9);
		cpgswin(0,nsamp_per_block,0,nchan);
		cpgbox("ABN",0,0,"ABN",0,0);
		cpggray(*clean,nsamp_per_block,nchan,1,nsamp_per_block,1,nchan,tmean/(float)nchan+sqrt(rvar/(float)nchan),tmean/(float)nchan-sqrt(rvar/(float)nchan),tr);
		cpgclos();




		stop_clock(t_spec);
		for (uint64_t j = 0; j < nchan ; j++){
			float mean=ch_mean[offset+j];
			if (mean > max_mean)max_mean=mean;
			if (mean < min_mean)min_mean=mean;

			float var=ch_var[offset+j];
			if (var > max_var)max_var=var;
			if (var < min_var)min_var=var;
			float fft_n=ch_fft_n[offset+j];
			if (fft_n > max_fft_n)max_fft_n=fft_n;
			if (fft_n < min_fft_n)min_fft_n=fft_n;
			float fft_p=ch_fft_p[offset+j];
			if (fft_p > max_fft_p)max_fft_p=fft_p;
			if (fft_p < min_fft_p)min_fft_p=fft_p;

		}
	}
	stop_clock(t_all);

	fclose(of);

	logmsg("T(all)  = %.2lfs",read_clock(t_all));
	logmsg("T(read) = %.2lfs",read_clock(t_read));
	logmsg("T(trans)= %.2lfs",read_clock(t_trns));
	logmsg("T(fft)  = %.2lfs",read_clock(t_fft));
	logmsg("T(fan)  = %.2lfs",read_clock(t_spec));
	logmsg("T(rms)  = %.2lfs",read_clock(t_rms));
	logmsg("T(rest) = %.2lfs",read_clock(t_all)-read_clock(t_read)-read_clock(t_trns)-read_clock(t_rms)-read_clock(t_fft)-read_clock(t_spec));


	tr[0] = -tsamp*nsamp_per_block*0.5;
	tr[2] = tsamp*nsamp_per_block;
	tr[1] = 0;
	tr[3] = 0.5;
	tr[5] = 0;
	tr[4] = 1;




	cpgopen("1/xs");
	cpgsvp(0.1,0.9,0.1,0.9);
	cpgswin(0,nblocks*tsamp*nsamp_per_block,0,nchan);
	cpgbox("ABN",600,10,"ABN",100,1);
	cpggray(ch_mean,nchan,nblocks,1,nchan,1,nblocks,max_mean,min_mean,tr);
	cpgclos();

	cpgopen("2/xs");
	cpgsvp(0.1,0.9,0.1,0.9);
	cpgswin(0,nblocks*tsamp*nsamp_per_block,0,nchan);
	cpgbox("ABN",600,10,"ABN",100,1);
	cpggray(ch_var,nchan,nblocks,1,nchan,1,nblocks,max_var,min_var,tr);
	cpgclos();

	cpgopen("3/xs");
	cpgsvp(0.1,0.9,0.1,0.9);
	cpgswin(0,nblocks*tsamp*nsamp_per_block,0,nchan);
	cpgbox("ABN",600,10,"ABN",100,1);
	cpggray(ch_fft_n,nchan,nblocks,1,nchan,1,nblocks,max_fft_n,min_fft_n,tr);
	cpgclos();

	cpgopen("4/xs");
	cpgsvp(0.1,0.9,0.1,0.9);
	cpgswin(0,nblocks*tsamp*nsamp_per_block,0,nchan);
	cpgbox("ABN",600,10,"ABN",100,1);
	cpggray(ch_fft_p,nchan,nblocks,1,nchan,1,nblocks,max_fft_p,min_fft_p,tr);
	cpgclos();



	cpgopen("mean.ps/vcps");
	cpgsvp(0.1,0.9,0.1,0.9);
	cpgswin(0,nblocks*tsamp*nsamp_per_block,0,nchan);
	cpgbox("ABN",600,10,"ABN",100,1);
	cpggray(ch_mean,nchan,nblocks,1,nchan,1,nblocks,max_mean,min_mean,tr);
	cpgclos();

	cpgopen("var.ps/vcps");
	cpgsvp(0.1,0.9,0.1,0.9);
	cpgswin(0,nblocks*tsamp*nsamp_per_block,0,nchan);
	cpgbox("ABN",600,10,"ABN",100,1);
	cpggray(ch_var,nchan,nblocks,1,nchan,1,nblocks,max_var,min_var,tr);
	cpgclos();


	cpgopen("fft_n.ps/vcps");
	cpgsvp(0.1,0.9,0.1,0.9);
	cpgswin(0,nblocks*tsamp*nsamp_per_block,0,nchan);
	cpgbox("ABN",600,10,"ABN",100,1);
	cpggray(ch_fft_n,nchan,nblocks,1,nchan,1,nblocks,max_fft_n,min_fft_n,tr);
	cpgclos();

	cpgopen("fft_p.ps/vcps");
	cpgsvp(0.1,0.9,0.1,0.9);
	cpgswin(0,nblocks*tsamp*nsamp_per_block,0,nchan);
	cpgbox("ABN",600,10,"ABN",100,1);
	cpggray(ch_fft_p,nchan,nblocks,1,nchan,1,nblocks,max_fft_p,min_fft_p,tr);
	cpgclos();



	fclose(f);
	free(buffer);
	free_2df(data);

	return 0;

}
Beispiel #23
0
int main(int argc, char **argv) {
	float lm, hm;
	int ID;
	float x1, y1, x2, y2;
	char ch;
	char filename[1024];
	int enhanceid = -1;
	int sectionmode = LON;
	int histmode = DEP;
	float binw = 10.0;

	reset(&mainset);
	load(&mainset);

	rangeadjust(&control, &mainset, NULL, NULL, NULL, NULL);

	ID = cpgopen("/xwindow");
	resizemax(0.85);
	cpgask(0);

	/*
	 * This a bug-fix for the gmt command that outputs the borders wrapped.
	 */
	int i;
	for(i=0; i < nborders; i++)
		if (borders[i][0] != -999 && borders[i][0] > 180)
			borders[i][0] = borders[i][0] - 360.0;

	lm = hm = -1.0;
	while (ch != 'Q') {
		if (control.printout) {
			lerchar("Entre com o nome do arquivo", filename, 1000);
			if (strlen(filename) == 0) {
				strcpy(message, "Nome invalido.");
				alert(ERROR);
				control.printout = 0;
			} else {
				if (strlen(filename) < 3 || strncasecmp( &filename[strlen(filename)-3], ".ps", 3) != 0) {
					sprintf(filename,"%s.ps/cps",filename);
				} else {
					sprintf(filename,"%s/cps",filename);
				}
				cpgopen(filename);
				cpgask(0);
			}
		}

		plot(&control, &mainset);

		if (control.printout == 0 && enhanceid != -1) {
			enhanceid = enhance(&control, &mainset, enhanceid);
		}

		if (mainset.region) {
			plotsection(&mainset, &control, sectionmode);
			plothistogram(&mainset, binw, histmode, lm, hm);
		}

		if (control.printout) {
			cpgclos();
			cpgslct(ID);
			control.printout = 0;

			filename[strlen(filename) - 4] = '\0';
			sprintf(message, "Print Out saved to file %s", filename);
			alert(INFO);

			continue;
		}

		// Restore default map position
		cpgsvp(0.07, 0.93, 0.35, 0.9);
		cpgswin(control.xmin, control.xmax, control.ymin, control.ymax);
		ch = getonechar(&x1, &y1, 0);
		switch(ch) {
		case('='): {
			control.printout = 1;
			break;
		}
		case('R'): {
			reset(&mainset);
			load(&mainset);
			break;
		}

		case('B'): {
			binw = lerfloat("Entre com o valor da largura do bin?");
			break;
		}

		case('A'): {
			enhanceid = findpt(&mainset, x1, y1);
			break;
		}

		case('2'): {
			control.hasplates = (control.hasplates == 1) ? 0 : 1;
			break;
		}

		case('1'): {
			control.hascontinents++;
			if (control.hascontinents > 2) control.hascontinents = 0;
			break;
		}

		case ('W'): {
			control.xmax = 180;
			control.xmin = -180;
			control.ymax = 90;
			control.ymin = -90;
			break;
		}

		case('0'): {
			mainset.lon1 = -180;
			mainset.lon2 = 180;
			mainset.lat1 = -90;
			mainset.lat2 = 90;
			load(&mainset);
			mainset.region = 0;
			break;
		}

		case ('L'): {
			sectionmode = (sectionmode == LAT) ? LON : LAT;
			break;
		}

		case ('H'): {
			histmode = (histmode == MAG) ? DEP : MAG;
			binw = (histmode == MAG) ? 0.1 : 10.0;
			break;
		}

		case ('S'): {
			x2 = x1;
			y2 = y1;
			getonechar(&x2, &y2, 1);
			order(&x1,&x2);
			order(&y1,&y2);
			mainset.lon1 = x1;
			mainset.lon2 = x2;
			mainset.lat1 = y1;
			mainset.lat2 = y2;
			load(&mainset);
			mainset.region = 1;
			break;
		}

		case('X'): { // ZOOM
			x2 = x1;
			y2 = y1;
			getonechar(&x2, &y2, 1);
			order(&x1,&x2);
			order(&y1,&y2);
			rangeadjust(&control, &mainset, &x1, &x2, &y1, &y2);
			break;
		}

		case('C'): { // Color mode
			control.colormode ++;
			if (control.colormode>COLORMAG) control.colormode = COLORNONE;
			break;
		}

		case('N'): { /* Ano */
			int y1, y2;
			y1 = lerint("Entre com ano inicial?");
			y2 = lerint("Entre com ano final?");
			orderint(&y1,&y2);
			mainset.y1 = y1;
			mainset.y2 = y2;
			load(&mainset);
			break;
		}

		case('M'): { /* Magnitude */
			float m1, m2;
			m1 = lerfloat("Entre com a Magnitude Inicial?");
			m2 = lerfloat("Entre com a Magnitude Final?");
			order(&m1,&m2);
			mainset.m1 = m1;
			mainset.m2 = m2;
			load(&mainset);
			break;
		}

		case('J'): { /* Ajuste */
			lm = lerfloat("Entre com o menor valor de mag. para ajuste.");
			hm = lerfloat("Entre com o maior valor de mag. para ajuste.");
			if (lm == hm) {
				lm = hm = -1;
			}
			break;
		}
		case('P'): { /* Profundidade */
			float d1, d2;
			d1 = lerfloat("Entre com a Profundidade Minima?");
			d2 = lerfloat("Entre com a Profundidade Maxima?");
			order(&d1,&d2);
			mainset.d1 = d1;
			mainset.d2 = d2;
			load(&mainset);
			break;
		}

		}
	}

	cpgclos();
}
Beispiel #24
0
int dialog::manage(float * x, float * y, char * ans, int * plotno){

  int leave;
  int button = 0;
  *plotno = -1;
  *ans = ' ';
  static float lastx, lasty;

  *x=lastx;
  *y=lasty;

  leave = 0;
  while (!leave){

  // get a keypress
    cpgsvp(0.0,1.0,0.0,1.0);
    cpgswin(0.0,1.0,0.0,1.0);
    cpgcurs(x,y,ans);
    lastx=*x;
    lasty=*y;
    button = -1;
  // First of all, check if it is inside a plot
     for (int i=0;i<nplotregion;i++){
       if (plotregions[i].inside(x,y)){


         button = -1;
         *plotno = i;
	 leave = 1;
        } 
     }
  // Then check if it is inside a button
     for (int i=0;i<nbutton;i++){
       buttons[i].pressed = 0;
       if (buttons[i].inside(*x,*y)){
         button = i;
         buttons[i].pressed = 1;
	 leave = 1;
        } 
     }

  // Then radio controls
     for (int i=0;i<nradio;i++){
       if (radios[i].inside(*x,*y)){
        //  zero all in the group
        for (int j=0;j<nradio;j++) 
          if (radios[j].groupid==radios[i].groupid) {
	    radios[j].on=0;
	    radios[j].draw();
	  }
        // draw this one
	radios[i].on=1;
	  radios[i].draw();
	  leave = 0;
        } 
      }

  // Then check boxes controls
     for (int i=0;i<ncheck;i++){
       if (checks[i].inside(*x,*y)){
         checks[i].toggle();
         checks[i].draw();
	 leave=0;
        } 
     }
  // else stay in loop unless q pressed.
  }
  return(button);
}
Beispiel #25
0
int main(){
	printf("\n====================================================================\n");
	printf("This program is able to simulate the diffusion of heat\n");
	printf("across a metal plate of size %i x %i\n", ENV_SIZE_X, ENV_SIZE_Y);
	printf("====================================================================\n");

	//==========================================================================
	//--------------------------SYSTEM INITIALIZATIONS--------------------------
	//==========================================================================
	
	// initialize random seed
	srand(time(NULL));

	// force print all outputs (remove stdout buffer)
	setbuf(stdout, NULL);

	// initialize pgplot window
	if (!cpgopen("/XWINDOW"))
		errorCase(ERR_PGPLOT);

	cpgpap(0.0, 0.6);						// set window size
	cpgsubp(1,3);						// subdivide window into panels
	// heatmap
	cpgpanl(1,1);
	cpgsvp(0.0, 1.0, 0.0, 1.0);
	cpgswin(0, ENV_SIZE_X, 0, ENV_SIZE_Y);
	// flux plot
	cpgpanl(1,2);
	cpgsvp(0.08, 0.92, 0.08, 0.92);
	cpgswin(LINE_PLOT_X1, LINE_PLOT_X2, FLUX_PLOT_Y1, FLUX_PLOT_Y2);
	cpgbox("ABCINTS", 0.0, 0, "ABCINTS", 0.0, 0);
	cpglab("Time", "Flux", "");
	// heat plot
	cpgpanl(1,3);
	cpgsvp(0.08, 0.92, 0.08, 0.92);
	cpgswin(LINE_PLOT_X1, LINE_PLOT_X2, LINE_PLOT_Y1, LINE_PLOT_Y2);
	cpgbox("ABCINTS", 0.0, 0, "ABCINTS", 0.0, 0);
	cpglab("Time", "Total Heat", "");

	// initialize color table for pgplot display
  	float rl[9] = {-0.5, 0.0, 0.17, 0.33, 0.50, 0.67, 0.83, 1.0, 1.7};
  	float rr[9] = { 0.0, 0.0,  0.0,  0.0,  0.6,  1.0,  1.0, 1.0, 1.0};
  	float rg[9] = { 0.0, 0.0,  0.0,  1.0,  1.0,  1.0,  0.6, 0.0, 1.0};
  	float rb[9] = { 0.0, 0.3,  0.8,  1.0,  0.3,  0.0,  0.0, 0.0, 1.0};
  	cpgctab(rl, rr, rg, rb, 512,  1.0, 0.5);
	cpgscr(10, 0.0, 0.0, 1.0);
	cpgscr(11, 1.0, 0.0, 0.0);
	cpgsfs(3);


	//==========================================================================
	//--------------------------VARIABLE INITIALIZATIONS------------------------
	//==========================================================================

	// generic variables
	int i, j, k;						// counters

	// simulation environment
	float** simEnvEven = allocateArray2D(ENV_SIZE_X, ENV_SIZE_Y);
	float** simEnvOdd = allocateArray2D(ENV_SIZE_X, ENV_SIZE_Y);
	float* simLocal = allocateArray1D(5);

	// mnist handwritten numbers
	float** mnistDatabase = readCSV("mnist_train_100.csv", 100, 785);
	for (i=0; i<100; i++)
		for (j=0; j<785; j++)
			mnistDatabase[i][j] = mnistDatabase[i][j]/255.0;

	// current location and time
	int x,y,z;
	int t, tGlobal;

	// student number
	int studentNumbRaw;
	int studentNumbWorking;
	int studentNumb[7];

	// rates
	float rateDiff = 0.2;
	float delta;

	// flux variables
	float flux;
	float fluxTotal;
	float fluxAverage;
	float fluxHeat;
	float totalHeat;
	int x1, x2, y1, y2;

	// background heat
	float bgHeat;

	// tracking variables
	float totalHeatOld;
	float totalHeatPre;
	float tGlobalOld;
	float fluxOld;

	// pgplot variables
	float* plotImg = allocateArray1D(ENV_SIZE_TOTAL);
	float TR[6] = {0, 0, 1, ENV_SIZE_Y, -1, 0};
	float plotMinBound = 0;
	float plotMaxBound = 1;

	//==========================================================================
	//--------------------------------SETUP-------------------------------------
	//==========================================================================
	
	// ask for student number
	printf("Please enter your student number:\n");
	if (scanf("%i", &studentNumbRaw) == 0)
		errorCase(ERR_INVALID_INPUT);
	studentNumbWorking = studentNumbRaw;
	for (i=0; i<SN_LENGTH; i++){
		studentNumb[6-i] = studentNumbWorking%10;
		studentNumbWorking /= 10;
	}
	printf("\nYour student number is:\n");
	for (i=0; i<SN_LENGTH; i++)
		printf("%i", studentNumb[i]);
	printf("\n\n");

	// set and print diffusion rate based on last digit of student number
	rateDiff = ((((float)(studentNumb[6]))/10.0)*0.19)+0.01;
	printf("Your Diffusion Rate is: \n%f\n\n", rateDiff);

	// set and print background heat added based on last 4 digits of student number
	studentNumbRaw -= 1410000;
	bgHeat = ((float)((studentNumbRaw%97)%10));
	bgHeat += ((float)((studentNumbRaw%101)%8))*10;
	bgHeat /= 100;
	printf("Your Background Heat is: \n%f\n\n", bgHeat*100);

	// set and print domain for calculating flux
	// x1, y1 based on last four digits of student number
	x1 = studentNumbRaw % ENV_SIZE_X;
	y1 = studentNumbRaw % ENV_SIZE_Y;
	// x2, y2 based on last four digits of student number
	x2 = x1 + (studentNumbRaw % (97));
	if (x2 >= ENV_SIZE_X)
		x2 = ENV_SIZE_X - 1;
	y2 = y1 + (studentNumbRaw % (29));
	if (y2 >= ENV_SIZE_Y)
		y2 = ENV_SIZE_Y - 1;
	printf("Your Domain is: \n(%i, %i) X (%i, %i)\n\n", x1, y1, x2, y2);

	// environment initialization:
	// select digits and place into environment
	for (i=0; i<SN_LENGTH; i++){
		if (studentNumb[i] == 0)
			z = 0;
		else if (studentNumb[i] == 1)
			z = 13;
		else if (studentNumb[i] == 2)
			z = 27;
		else if (studentNumb[i] == 3)
			z = 33;
		else if (studentNumb[i] == 4)
			z = 44;
		else if (studentNumb[i] == 5)
			z = 55;
		else if (studentNumb[i] == 6)
			z = 60;
		else if (studentNumb[i] == 7)
			z = 71;
		else if (studentNumb[i] == 8)
			z = 81;
		else
			z = 89;

		for (x=0; x<28; x++)
			for (y=0; y<28; y++) {
				simEnvEven[x+(i*28)+1][y+1] = mnistDatabase[z][y*28+x] + bgHeat;
				if (simEnvEven[x+(i*28)+1][y+1] > 1.0)
					simEnvEven[x+(i*28)+1][y+1] = 1.0;
			}
	}


	//==========================================================================
	//--------------------------ACTUAL CODE-------------------------------------
	//==========================================================================

	// initialize display
	fixBoundaryConditions(simEnvEven);
	copyArray2D(simEnvEven, simEnvOdd, ENV_SIZE_X, ENV_SIZE_Y);
	loadImage(simEnvEven, plotImg);
	cpgpanl(1,1);
	cpgsvp(0.0, 1.0, 0.0, 1.0);
	cpgswin(0, ENV_SIZE_X, 0, ENV_SIZE_Y);
	cpgimag(plotImg, ENV_SIZE_Y, ENV_SIZE_X, 1, ENV_SIZE_Y, 1, ENV_SIZE_X, plotMinBound, plotMaxBound, TR);
	cpgrect(x1, x2, y1, y2);

	// initialize trackers
	tGlobalOld = 0;
	fluxOld = 0;
	totalHeatOld = 0;
	for (x=x1; x<=x2; x++)
		for (y=y1; y<=y2; y++)
			totalHeatOld += simEnvEven[x][y];

	// initial delay to visualize starting matrix
	for (t=0; t<500000000; t++){}
	
	t = 0;
	tGlobal = 0;
	flux = 0;
	fluxAverage = 0;
	fluxTotal = 0;
	while(1){
		flux = 0;
		cpgpanl(1,1);
		cpgsvp(0.0, 1.0, 0.0, 1.0);
		cpgswin(0, ENV_SIZE_X, 0, ENV_SIZE_Y);

		// calculate heat changes using numeric methods
		fixBoundaryConditions(simEnvEven);

		//simEnvEven[50][15] = 100;
		//simEnvEven[60][15] = -10;

		copyArray2D(simEnvEven, simEnvOdd, ENV_SIZE_X, ENV_SIZE_Y);

		for (x=1; x<(ENV_SIZE_X-1); x++)
			for (y=1; y<(ENV_SIZE_Y-1); y++)
				if ((x+y)%2 == 0) {
					delta = rateDiff*(simEnvEven[x][y+1] - 2*simEnvEven[x][y] + simEnvEven[x][y-1]);
					simEnvOdd[x][y] += delta;
					if (INSIDE_BOX)
						flux += delta;
					delta = rateDiff*(simEnvEven[x+1][y] - 2*simEnvEven[x][y] + simEnvEven[x-1][y]);
					simEnvOdd[x][y] += delta;
					if (INSIDE_BOX)
						flux += delta;
				}
		for (x=1; x<(ENV_SIZE_X-1); x++)
			for (y=1; y<(ENV_SIZE_Y-1); y++)
				if ((x+y)%2 == 1) {
					delta = rateDiff*(simEnvOdd[x][y+1] - 2*simEnvOdd[x][y] + simEnvOdd[x][y-1]);
					simEnvOdd[x][y] += delta;
					if (INSIDE_BOX)
						flux += delta;
					delta = rateDiff*(simEnvOdd[x+1][y] - 2*simEnvOdd[x][y] + simEnvOdd[x-1][y]);
					simEnvOdd[x][y] += delta;
					if (INSIDE_BOX)
						flux += delta;
				}
		loadImage(simEnvOdd, plotImg);
		cpgimag(plotImg, ENV_SIZE_Y, ENV_SIZE_X, 1, ENV_SIZE_Y, 1, ENV_SIZE_X, plotMinBound, plotMaxBound, TR);
		cpgrect(x1, x2, y1, y2);
		fluxTotal += flux;
		tGlobal++;

		flux = 0;

		//simEnvOdd[50][15] = 100;
		//simEnvOdd[60][15] = -10;

		fixBoundaryConditions(simEnvOdd);
		
		for (x=1; x<(ENV_SIZE_X-1); x++)
			for (y=1; y<(ENV_SIZE_Y-1); y++)
				if ((x+y)%2 == 1) {
					delta = rateDiff*(simEnvOdd[x][y+1] - 2*simEnvOdd[x][y] + simEnvOdd[x][y-1]);
					simEnvEven[x][y] += delta;
					if (INSIDE_BOX)
						flux += delta;
					delta = rateDiff*(simEnvOdd[x+1][y] - 2*simEnvOdd[x][y] + simEnvOdd[x-1][y]);
					simEnvEven[x][y] += delta;
					if (INSIDE_BOX)
						flux += delta;
				}
		for (x=1; x<(ENV_SIZE_X-1); x++)
			for (y=1; y<(ENV_SIZE_Y-1); y++)
				if ((x+y)%2 == 0) {
					delta = rateDiff*(simEnvEven[x][y+1] - 2*simEnvEven[x][y] + simEnvEven[x][y-1]);
					simEnvEven[x][y] += delta;
					if (INSIDE_BOX)
						flux += delta;
					delta = rateDiff*(simEnvEven[x+1][y] - 2*simEnvEven[x][y] + simEnvEven[x-1][y]);
					simEnvEven[x][y] += delta;
					if (INSIDE_BOX)
						flux += delta;
				}
		loadImage(simEnvEven, plotImg);
		cpgimag(plotImg, ENV_SIZE_Y, ENV_SIZE_X, 1, ENV_SIZE_Y, 1, ENV_SIZE_X, plotMinBound, plotMaxBound, TR);
		cpgrect(x1, x2, y1, y2);
		fluxTotal += flux;
		tGlobal++;



		// flux line plot
		cpgpanl(1,2);
		cpgsvp(0.08, 0.92, 0.08, 0.92);
		cpgswin(LINE_PLOT_X1, LINE_PLOT_X2, FLUX_PLOT_Y1, FLUX_PLOT_Y2);
		cpgmove(tGlobalOld, fluxOld);
		cpgdraw(tGlobal, flux);

		// heat line plot
		totalHeat = 0;
		for (x=x1; x<=x2; x++)
			for (y=y1; y<=y2; y++)
				totalHeat += simEnvEven[x][y];
		cpgpanl(1,3);
		cpgsvp(0.08, 0.92, 0.08, 0.92);
		cpgswin(LINE_PLOT_X1, LINE_PLOT_X2, LINE_PLOT_Y1, LINE_PLOT_Y2);
		cpgmove(tGlobalOld, totalHeatOld);
		cpgdraw(tGlobal, totalHeat);

		// set trackers
		tGlobalOld = tGlobal;
		totalHeatOld = totalHeat;
		fluxOld = flux;

		if (tGlobal%100 == 0) {
			totalHeat = 0;
			for (x=x1; x<=x2; x++)
				for (y=y1; y<=y2; y++)
					totalHeat += simEnvEven[x][y];
			fluxAverage = fluxTotal/tGlobal;
			fluxHeat = totalHeat - totalHeatPre;
			printf("Total Heat: %f \n Current Divergence: %f \n Current Flux:       %f\n\n", totalHeat, flux, fluxHeat);
		}

		totalHeatPre = 0;
		for (x=x1; x<=x2; x++)
			for (y=y1; y<=y2; y++)
				totalHeatPre += simEnvEven[x][y];
	}
}
Beispiel #26
0
void Plotter2::plot() {
    open();

    if ((width > 0.0) && (aspect > 0.0)) {
        cpgpap(width, aspect);
    }

    cpgscr(0, 1.0, 1.0, 1.0); // set background color white
    cpgscr(1, 0.0, 0.0, 0.0); // set foreground color black

    for (unsigned int i = 0; i < vInfo.size(); ++i) {
        Plotter2ViewportInfo vi = vInfo[i];

	if (vi.showViewport) {
	    resetAttributes(vi);

	    // setup viewport
            cpgsvp(vi.vpPosXMin, vi.vpPosXMax, vi.vpPosYMin, vi.vpPosYMax);
	    cpgswin(vi.vpRangeXMin, vi.vpRangeXMax, vi.vpRangeYMin, vi.vpRangeYMax);

	    // background color (default is transparent)
	    if (vi.vpBColor >= 0) {
	        cpgsci(vi.vpBColor);
	        cpgrect(vi.vpRangeXMin, vi.vpRangeXMax, vi.vpRangeYMin, vi.vpRangeYMax);
	        cpgsci(1);  // reset foreground colour to the initial one (black)
	    }

	    // data
	    for (unsigned int j = 0; j < vi.vData.size(); ++j) {
	        resetAttributes(vi);

	        Plotter2DataInfo di = vi.vData[j];
	        std::vector<float> vxdata = di.xData;
                int ndata = vxdata.size();
	        float* pxdata = new float[ndata];
	        float* pydata = new float[ndata];
	        for (int k = 0; k < ndata; ++k) {
	            pxdata[k] = di.xData[k];
	            pydata[k] = di.yData[k];
	        }

	        if (di.drawLine) {
  	            cpgsls(di.lineStyle);
	            cpgslw(di.lineWidth);
		    int colorIdx = di.lineColor;
		    if (colorIdx < 0) {
		        colorIdx = (j + 1) % 15 + 1;
		    }
	            cpgsci(colorIdx);
	            cpgline(ndata, pxdata, pydata);
	        }

	        if (di.drawMarker) {
	            cpgsch(di.markerSize);
	            cpgsci(di.markerColor);
	            cpgpt(ndata, pxdata, pydata, di.markerType);
	        }

	        delete [] pxdata;
	        delete [] pydata;
	    }

	    //calculate y-range of xmasks
	    std::vector<float> yrange = vi.getRangeY();
	    float yexcess = 0.1*(yrange[1] - yrange[0]);
	    float xmaskymin = yrange[0] - yexcess;
	    float xmaskymax = yrange[1] + yexcess;

	    // masks
	    for (unsigned int j = 0; j < vi.vRect.size(); ++j) {
	        resetAttributes(vi);

	        Plotter2RectInfo ri = vi.vRect[j];
                cpgsci(ri.color);
	        cpgsfs(ri.fill);
	        cpgslw(ri.width);
	        cpgshs(45.0, ri.hsep, 0.0);
	        float* mxdata = new float[4];
	        float* mydata = new float[4];
	        mxdata[0] = ri.xmin;
	        mxdata[1] = ri.xmax;
	        mxdata[2] = ri.xmax;
	        mxdata[3] = ri.xmin;
	        mydata[0] = xmaskymin;
	        mydata[1] = xmaskymin;
	        mydata[2] = xmaskymax;
	        mydata[3] = xmaskymax;
                cpgpoly(4, mxdata, mydata);
	    }

	    // arrows
	    for (unsigned int j = 0; j < vi.vArro.size(); ++j) {
  	        resetAttributes(vi);

		Plotter2ArrowInfo ai = vi.vArro[j];
		cpgsci(ai.color);
		cpgslw(ai.width);
                cpgsls(ai.lineStyle);
		cpgsch(ai.headSize);
		cpgsah(ai.headFillStyle, ai.headAngle, ai.headVent);
		cpgarro(ai.xtail, ai.ytail, ai.xhead, ai.yhead);
	    }

	    // arbitrary texts
	    for (unsigned int j = 0; j < vi.vText.size(); ++j) {
  	        resetAttributes(vi);

		Plotter2TextInfo ti = vi.vText[j];
		cpgsch(ti.size);
		cpgsci(ti.color);
		cpgstbg(ti.bgcolor);
		cpgptxt(ti.posx, ti.posy, ti.angle, ti.fjust, ti.text.c_str());
	    }

	    // viewport outline and ticks
	    resetAttributes(vi);

            cpgbox("BCTS",  vi.majorTickIntervalX, vi.nMinorTickWithinMajorTicksX, 
	           "BCTSV", vi.majorTickIntervalY, vi.nMinorTickWithinMajorTicksY);

	    // viewport numberings
	    std::string numformatx, numformaty;
	    if (vi.numLocationX == "b") {
	        numformatx = "N";
	    } else if (vi.numLocationX == "t") {
	        numformatx = "M";
	    } else if (vi.numLocationX == "") {
	        numformatx = "";
	    }
	    if (vi.numLocationY == "l") {
	        numformaty = "NV";
	    } else if (vi.numLocationY == "r") {
	        numformaty = "MV";
	    } else if (vi.numLocationY == "") {
	        numformaty = "";
	    }

            cpgbox(numformatx.c_str(), vi.majorTickIntervalX * vi.nMajorTickWithinTickNumsX, 0, 
	           numformaty.c_str(), vi.majorTickIntervalY * vi.nMajorTickWithinTickNumsY, 0);

	    float xpos, ypos;

	    // x-label
	    vi.getWorldCoordByWindowCoord(vi.labelXPosX, vi.labelXPosY, &xpos, &ypos);
	    cpgsch(vi.labelXSize);
            cpgsci(vi.labelXColor);
            cpgstbg(vi.labelXBColor); //outside viewports, works ONLY with /xwindow
            cpgptxt(xpos, ypos, vi.labelXAngle, vi.labelXFJust, vi.labelXString.c_str());

	    // y-label
	    vi.getWorldCoordByWindowCoord(vi.labelYPosX, vi.labelYPosY, &xpos, &ypos);
	    cpgsch(vi.labelYSize);
            cpgsci(vi.labelYColor);
            cpgstbg(vi.labelYBColor); //outside viewports, works ONLY with /xwindow
            cpgptxt(xpos, ypos, vi.labelYAngle, vi.labelYFJust, vi.labelYString.c_str());

	    // title
	    vi.getWorldCoordByWindowCoord(vi.titlePosX, vi.titlePosY, &xpos, &ypos);
	    cpgsch(vi.titleSize);
            cpgsci(vi.titleColor);
            cpgstbg(vi.titleBColor); //outside viewports, works ONLY with /xwindow
            cpgptxt(xpos, ypos, vi.titleAngle, vi.titleFJust, vi.titleString.c_str());
	}

    }

    close();
}
/*
 * Class:     pulsarhunter_PgplotInterface
 * Method:    pgsvp
 * Signature: (FFFF)V
 */
JNIEXPORT void JNICALL Java_pulsarhunter_PgplotInterface_pgsvp
(JNIEnv *env, jclass cl, jfloat xleft, jfloat xright, jfloat ybot, jfloat ytop){

	cpgsvp(xleft,xright,ybot,ytop);
}
// make six Aitoff sky projection plots
//   using the data in ravec[field], decvec[field], and value[filter][field],
//   using the min and max data values in valmin[filter] and valmax[filter]
//   with filter=0 to NFILTERS-1
void plotSix(double nfields, double **value,
             double *ravec, double *decvec,
             double *valmin, double *valmax,
             int horizontal,
             char *label, char *title, char* plotName, int mask) {

	char str[1024];
	int filt, nf;
	double xmin, xmax, ymin, ymax;

	openPlot(plotName);
	cpgbbuf();

	if(horizontal==1) 
		cpgpap(PLOTSIZE/0.5,0.5); else cpgpap(PLOTSIZE/1.0,1.0);

	cpgsvp(0.02,0.98,0.15,0.95);
	xmax = 0.9*(M_PI);      
	xmin = -xmax;
	ymax = 0.9*(0.6*M_PI);  
	ymin = -ymax;
	ymin -= 0.18*ymax;      
	ymax -= 0.18*ymax;

	setupImplot(0.0, 1.0);

	if(horizontal==1) 
		cpgsubp(3,2); 
	else 
		cpgsubp(2,3);

	cpgsch(3.0); 
	cpgslw(2);

	for(filt=0; filt<NFILTERS; filt++) {
		int thereisdata = 0;
		for(nf=0; nf<nfields; nf++) {
			if (value[filt][nf] != 0.0) {
				thereisdata = 1;
			}
		}
		
		if ( thereisdata ) {
			if(horizontal==1) 
				cpgpanl(hpanelx[filt],hpanely[filt]); 
			else 
				cpgpanl(vpanelx[filt],vpanely[filt]);

			cpgswin(xmin,xmax,ymin,ymax);
			for(nf=0; nf<nfields; nf++) {
				if ( mask == 0 ) {
					if(value[filt][nf] > 0.0)
						projCircle(ravec[nf], decvec[nf], FIELD_RADIUS, (value[filt][nf]-valmin[filt])/(valmax[filt]-valmin[filt]));
				} else if ( mask == 1) {
					if(value[filt][nf] != 0.0)
						projCircle(ravec[nf], decvec[nf], FIELD_RADIUS, (value[filt][nf]-valmin[filt])/(valmax[filt]-valmin[filt]));
				}
			}
			aitoffGrid();
			galaxy(peakL, taperL, taperB);
			sprintf(str,"%s: %s", label, filtername[filt]);
			if(valmax[filt]>valmin[filt])
				mywedg(0.2, 0.15, 1.0, 8.0, valmin[filt], valmax[filt], str);
		}
	}

	cpgsch(1.0);
	cpgsubp(1,1);
	cpgswin(0,1,0,1);
	cpgptxt(0.5,1.02,0.0,0.5,title);
	cpgslw(1);    
	cpgebuf();

	closePlot();
}
Beispiel #29
0
void rfifind_plot(int numchan, int numint, int ptsperint,
                  float timesigma, float freqsigma,
                  float inttrigfrac, float chantrigfrac,
                  float **dataavg, float **datastd, float **datapow,
                  int *userchan, int numuserchan,
                  int *userints, int numuserints,
                  infodata * idata, unsigned char **bytemask,
                  mask * oldmask, mask * newmask,
                  rfi * rfivect, int numrfi, int rfixwin, int rfips, int xwin)
/* Make the beautiful multi-page rfifind plots */
{
   int ii, jj, ct, loops = 1;
   float *freqs, *chans, *times, *ints;
   float *avg_chan_avg, *std_chan_avg, *pow_chan_avg;
   float *avg_chan_med, *std_chan_med, *pow_chan_med;
   float *avg_chan_std, *std_chan_std, *pow_chan_std;
   float *avg_int_avg, *std_int_avg, *pow_int_avg;
   float *avg_int_med, *std_int_med, *pow_int_med;
   float *avg_int_std, *std_int_std, *pow_int_std;
   float dataavg_avg, datastd_avg, datapow_avg;
   float dataavg_med, datastd_med, datapow_med;
   float dataavg_std, datastd_std, datapow_std;
   float avg_reject, std_reject, pow_reject;
   double inttim, T, lof, hif;

   inttim = ptsperint * idata->dt;
   T = inttim * numint;
   lof = idata->freq - 0.5 * idata->chan_wid;
   hif = lof + idata->freqband;
   avg_chan_avg = gen_fvect(numchan);
   std_chan_avg = gen_fvect(numchan);
   pow_chan_avg = gen_fvect(numchan);
   avg_int_avg = gen_fvect(numint);
   std_int_avg = gen_fvect(numint);
   pow_int_avg = gen_fvect(numint);
   avg_chan_med = gen_fvect(numchan);
   std_chan_med = gen_fvect(numchan);
   pow_chan_med = gen_fvect(numchan);
   avg_int_med = gen_fvect(numint);
   std_int_med = gen_fvect(numint);
   pow_int_med = gen_fvect(numint);
   avg_chan_std = gen_fvect(numchan);
   std_chan_std = gen_fvect(numchan);
   pow_chan_std = gen_fvect(numchan);
   avg_int_std = gen_fvect(numint);
   std_int_std = gen_fvect(numint);
   pow_int_std = gen_fvect(numint);
   chans = gen_fvect(numchan);
   freqs = gen_fvect(numchan);
   for (ii = 0; ii < numchan; ii++) {
      chans[ii] = ii;
      freqs[ii] = idata->freq + ii * idata->chan_wid;
   }
   ints = gen_fvect(numint);
   times = gen_fvect(numint);
   for (ii = 0; ii < numint; ii++) {
      ints[ii] = ii;
      times[ii] = 0.0 + ii * inttim;
   }

   /* Calculate the statistics of the full set */

   ct = numchan * numint;
   calc_avgmedstd(dataavg[0], ct, 0.8, 1, &dataavg_avg, &dataavg_med, &dataavg_std);
   calc_avgmedstd(datastd[0], ct, 0.8, 1, &datastd_avg, &datastd_med, &datastd_std);
   calc_avgmedstd(datapow[0], ct, 0.5, 1, &datapow_avg, &datapow_med, &datapow_std);
   avg_reject = timesigma * dataavg_std;
   std_reject = timesigma * datastd_std;
   pow_reject = power_for_sigma(freqsigma, 1, ptsperint / 2);

   /* Calculate the channel/integration statistics vectors */

   for (ii = 0; ii < numint; ii++) {
      calc_avgmedstd(dataavg[0] + ii * numchan, numchan, 0.8, 1,
                     avg_int_avg + ii, avg_int_med + ii, avg_int_std + ii);
      calc_avgmedstd(datastd[0] + ii * numchan, numchan, 0.8, 1,
                     std_int_avg + ii, std_int_med + ii, std_int_std + ii);
      calc_avgmedstd(datapow[0] + ii * numchan, numchan, 0.5, 1,
                     pow_int_avg + ii, pow_int_med + ii, pow_int_std + ii);
   }
   for (ii = 0; ii < numchan; ii++) {
      calc_avgmedstd(dataavg[0] + ii, numint, 0.8, numchan,
                     avg_chan_avg + ii, avg_chan_med + ii, avg_chan_std + ii);
      calc_avgmedstd(datastd[0] + ii, numint, 0.8, numchan,
                     std_chan_avg + ii, std_chan_med + ii, std_chan_std + ii);
      calc_avgmedstd(datapow[0] + ii, numint, 0.5, numchan,
                     pow_chan_avg + ii, pow_chan_med + ii, pow_chan_std + ii);
      /*
         fprintf(stderr, "%12.7g  %12.7g  %12.7g    %12.7g  %12.7g  %12.7g    %12.7g  %12.7g  %12.7g    \n", 
         avg_chan_avg[ii], avg_chan_med[ii], avg_chan_std[ii],
         std_chan_avg[ii], std_chan_med[ii], std_chan_std[ii],
         pow_chan_avg[ii], pow_chan_med[ii], pow_chan_std[ii]);
       */
   }

   /* Generate the byte mask */

   /* Set the channels/intervals picked by the user */
   if (numuserints)
      for (ii = 0; ii < numuserints; ii++)
         if (userints[ii] >= 0 && userints[ii] < numint)
            for (jj = 0; jj < numchan; jj++)
               bytemask[userints[ii]][jj] |= USERINTS;
   if (numuserchan)
      for (ii = 0; ii < numuserchan; ii++)
         if (userchan[ii] >= 0 && userchan[ii] < numchan)
            for (jj = 0; jj < numint; jj++)
               bytemask[jj][userchan[ii]] |= USERCHAN;

   /* Compare each point in an interval (or channel) with   */
   /* the interval's (or channel's) median and the overall  */
   /* standard deviation.  If the channel/integration       */
   /* medians are more than sigma different than the global */
   /* value, set them to the global.                        */
   {
      float int_med, chan_med;

      for (ii = 0; ii < numint; ii++) {
         for (jj = 0; jj < numchan; jj++) {
            {                   /* Powers */
               if (datapow[ii][jj] > pow_reject)
                  if (!(bytemask[ii][jj] & PADDING))
                     bytemask[ii][jj] |= BAD_POW;
            }
            {                   /* Averages */
               if (fabs(avg_int_med[ii] - dataavg_med) > timesigma * dataavg_std)
                  int_med = dataavg_med;
               else
                  int_med = avg_int_med[ii];
               if (fabs(avg_chan_med[jj] - dataavg_med) > timesigma * dataavg_std)
                  chan_med = dataavg_med;
               else
                  chan_med = avg_chan_med[jj];
               if (fabs(dataavg[ii][jj] - int_med) > avg_reject ||
                   fabs(dataavg[ii][jj] - chan_med) > avg_reject)
                  if (!(bytemask[ii][jj] & PADDING))
                     bytemask[ii][jj] |= BAD_AVG;
            }
            {                   /* Standard Deviations */
               if (fabs(std_int_med[ii] - datastd_med) > timesigma * datastd_std)
                  int_med = datastd_med;
               else
                  int_med = std_int_med[ii];
               if (fabs(std_chan_med[jj] - datastd_med) > timesigma * datastd_std)
                  chan_med = datastd_med;
               else
                  chan_med = std_chan_med[jj];
               if (fabs(datastd[ii][jj] - int_med) > std_reject ||
                   fabs(datastd[ii][jj] - chan_med) > std_reject)
                  if (!(bytemask[ii][jj] & PADDING))
                     bytemask[ii][jj] |= BAD_STD;
            }
         }
      }
   }

   /* Step over the intervals and channels and count how many are set "bad". */
   /* For a given interval, if the number of bad channels is greater than    */
   /* chantrigfrac*numchan then reject the whole interval.                   */
   /* For a given channel, if the number of bad intervals is greater than    */
   /* inttrigfrac*numint then reject the whole channel.                      */
   {
      int badnum, trignum;

      /* Loop over the intervals */
      trignum = (int) (numchan * chantrigfrac);
      for (ii = 0; ii < numint; ii++) {
         if (!(bytemask[ii][0] & USERINTS)) {
            badnum = 0;
            for (jj = 0; jj < numchan; jj++)
               if (bytemask[ii][jj] & BADDATA)
                  badnum++;
            if (badnum > trignum) {
               userints[numuserints++] = ii;
               for (jj = 0; jj < numchan; jj++)
                  bytemask[ii][jj] |= USERINTS;
            }
         }
      }

      /* Loop over the channels */
      trignum = (int) (numint * inttrigfrac);
      for (ii = 0; ii < numchan; ii++) {
         if (!(bytemask[0][ii] & USERCHAN)) {
            badnum = 0;
            for (jj = 0; jj < numint; jj++)
               if (bytemask[jj][ii] & BADDATA)
                  badnum++;
            if (badnum > trignum) {
               userchan[numuserchan++] = ii;
               for (jj = 0; jj < numint; jj++)
                  bytemask[jj][ii] |= USERCHAN;
            }
         }
      }
   }

   /* Generate the New Mask */

   fill_mask(timesigma, freqsigma, idata->mjd_i + idata->mjd_f,
             ptsperint * idata->dt, idata->freq, idata->chan_wid,
             numchan, numint, ptsperint, numuserchan, userchan,
             numuserints, userints, bytemask, newmask);

   /* Place the oldmask over the newmask for plotting purposes */

   if (oldmask->numchan)
      set_oldmask_bits(oldmask, bytemask);

   /*
    *  Now plot the results
    */

   if (xwin)
      loops = 2;
   for (ct = 0; ct < loops; ct++) {     /* PS/XWIN Plot Loop */
      float min, max, tr[6], locut, hicut;
      float left, right, top, bottom;
      float xl, xh, yl, yh;
      float tt, ft, th, fh;     /* thin and fat thicknesses and heights */
      float lm, rm, tm, bm;     /* LRTB margins */
      float xarr[2], yarr[2];
      char outdev[100];
      int ii, mincol, maxcol, numcol;

      /*Set the PGPLOT device to an X-Window */

      if (ct == 1)
         strcpy(outdev, "/XWIN");
      else
         sprintf(outdev, "%s.ps/CPS", idata->name);

      /* Open and prep our device */

      cpgopen(outdev);
      cpgpap(10.25, 8.5 / 11.0);
      cpgpage();
      cpgiden();
      cpgsch(0.7);
      cpgqcir(&mincol, &maxcol);
      numcol = maxcol - mincol + 1;
      for (ii = mincol; ii <= maxcol; ii++) {
         float color;
         color = (float) (maxcol - ii) / (float) numcol;
         cpgscr(ii, color, color, color);
      }

      /* Set thicknesses and margins */

      lm = 0.04;
      rm = 0.04;
      bm = 0.08;
      tm = 0.05;
      ft = 3.0;                 /* This sets fat thickness = 3 x thin thickness */
      tt = 0.92 / (6.0 + 4.0 * ft);
      ft *= tt;
      fh = 0.55;
      th = tt * 11.0 / 8.5;

      {                         /* Powers Histogram */
         float *theo, *hist, *hpows, *tpows, maxhist = 0.0, maxtheo = 0.0;
         int numhist = 40, numtheo = 200, bin, numpows;
         double dtheo, dhist, spacing;

         /* Calculate the predicted distribution of max powers */

         numpows = numint * numchan;
         find_min_max_arr(numpows, datapow[0], &min, &max);
         min = (min < 5.0) ? log10(5.0 * 0.95) : log10(min * 0.95);
         max = log10(max * 1.05);
         dhist = (max - min) / numhist;
         theo = gen_fvect(numtheo);
         tpows = gen_fvect(numtheo);
         hist = gen_fvect(numhist);
         hpows = gen_fvect(numhist);
         for (ii = 0; ii < numhist; ii++) {
            hist[ii] = 0.0;
            hpows[ii] = min + ii * dhist;
         }
         for (ii = 0; ii < numpows; ii++) {
            bin = (*(datapow[0] + ii) == 0.0) ? 0 :
                (log10(*(datapow[0] + ii)) - min) / dhist;
            if (bin < 0)
               bin = 0;
            if (bin >= numhist)
               bin = numhist;
            hist[bin] += 1.0;
         }
         for (ii = 0; ii < numhist; ii++)
            if (hist[ii] > maxhist)
               maxhist = hist[ii];
         maxhist *= 1.1;
         dtheo = (max - min) / (double) (numtheo - 1);
         for (ii = 0; ii < numtheo; ii++) {
            tpows[ii] = min + ii * dtheo;
            theo[ii] = single_power_pdf(pow(10.0, tpows[ii]),
                                        ptsperint / 2) * numpows;
            spacing = (pow(10.0, tpows[ii] + dhist) - pow(10.0, tpows[ii]));
            theo[ii] *= spacing;
            if (theo[ii] > maxtheo)
               maxtheo = theo[ii];
         }
         maxtheo *= 1.1;
         if (maxtheo > maxhist)
            maxhist = maxtheo;
         left = lm;
         right = lm + ft + tt;
         bottom = 0.80;
         top = 0.96;
         cpgsvp(left, right, bottom, top);
         xl = min;
         xh = max;
         yl = 0.0;
         yh = maxhist;
         cpgswin(xl, xh, yl, yh);
         cpgmtxt("L", 1.1, 0.5, 0.5, "Number");
         cpgmtxt("B", 2.1, 0.5, 0.5, "Max Power");
         cpgbin(numhist, hpows, hist, 0);
         cpgscr(maxcol, 0.5, 0.5, 0.5);
         cpgsci(maxcol);        /* Grey */
         cpgline(numtheo, tpows, theo);
         xarr[0] = log10(power_for_sigma(freqsigma, 1, ptsperint / 2));
         xarr[1] = xarr[0];
         yarr[0] = yl;
         yarr[1] = yh;
         cpgsls(4);             /* Dotted line */
         cpgscr(maxcol, 1.0, 0.0, 0.0);
         cpgsci(maxcol);        /* Red */
         cpgline(2, xarr, yarr);
         cpgsls(1);             /* Solid line */
         cpgsci(1);             /* Default color */
         cpgbox("BCLNST", 0.0, 0, "BC", 0.0, 0);
         vect_free(hist);
         vect_free(theo);
         vect_free(tpows);
         vect_free(hpows);
      }

      /* Maximum Powers */

      left = lm;
      right = lm + ft;
      bottom = bm;
      top = bm + fh;
      xl = 0.0;
      xh = numchan;
      yl = 0.0;
      yh = T;
      cpgsvp(left, right, bottom, top);
      cpgswin(xl, xh, yl, yh);
      cpgscr(maxcol, 1.0, 0.0, 0.0);    /* Red */
      locut = 0.0;
      hicut = pow_reject;
      tr[2] = tr[4] = 0.0;
      tr[1] = (xh - xl) / numchan;
      tr[0] = xl - (tr[1] / 2);
      tr[5] = (yh - yl) / numint;
      tr[3] = yl - (tr[5] / 2);
      cpgimag(datapow[0], numchan, numint, 1, numchan, 1, numint, locut, hicut, tr);
      cpgswin(xl, xh, yl, yh);
      cpgbox("BNST", 0.0, 0, "BNST", 0.0, 0);
      cpgmtxt("B", 2.6, 0.5, 0.5, "Channel");
      cpgmtxt("L", 2.1, 0.5, 0.5, "Time (s)");
      xl = lof;
      xh = hif;
      yl = 0.0;
      yh = numint;
      cpgswin(xl, xh, yl, yh);
      cpgbox("CST", 0.0, 0, "CST", 0.0, 0);

      /* Max Power Label */

      left = lm + ft;
      right = lm + ft + tt;
      bottom = bm + fh;
      top = bm + fh + th;
      cpgsvp(left, right, bottom, top);
      cpgswin(0.0, 1.0, 0.0, 1.0);
      cpgscr(maxcol, 1.0, 0.0, 0.0);
      cpgsci(maxcol);           /* Red */
      cpgptxt(0.5, 0.7, 0.0, 0.5, "Max");
      cpgptxt(0.5, 0.3, 0.0, 0.5, "Power");
      cpgsci(1);                /* Default color */

      /*  Max Power versus Time */

      left = lm + ft;
      right = lm + ft + tt;
      bottom = bm;
      top = bm + fh;
      cpgsvp(left, right, bottom, top);
      find_min_max_arr(numint, pow_int_med, &min, &max);
      xl = 0.0;
      xh = 1.5 * pow_reject;
      yl = 0.0;
      yh = T;
      cpgswin(xl, xh, yl, yh);
      cpgbox("BCST", 0.0, 0, "BST", 0.0, 0);
      cpgscr(maxcol, 1.0, 0.0, 0.0);
      cpgsci(maxcol);           /* Red */
      yarr[0] = yl;
      yarr[1] = yh;
      xarr[0] = xarr[1] = datapow_med;
      cpgline(2, xarr, yarr);
      cpgsls(4);                /* Dotted line */
      xarr[0] = xarr[1] = pow_reject;
      cpgline(2, xarr, yarr);
      cpgsls(1);                /* Solid line */
      cpgsci(1);                /* Default color */
      cpgline(numint, pow_int_med, times);
      yl = 0.0;
      yh = numint;
      cpgswin(xl, xh, yl, yh);
      cpgbox("", 0.0, 0, "CMST", 0.0, 0);
      /* cpgmtxt("R", 2.3, 0.5, 0.5, "Interval Number"); */

      /*  Max Power versus Channel */

      left = lm;
      right = lm + ft;
      bottom = bm + fh;
      top = bm + fh + th;
      cpgsvp(left, right, bottom, top);
      find_min_max_arr(numchan, pow_chan_med, &min, &max);
      xl = 0.0;
      xh = numchan;
      yl = 0.0;
      yh = 1.5 * pow_reject;
      cpgswin(xl, xh, yl, yh);
      cpgbox("BST", 0.0, 0, "BCST", 0.0, 0);
      cpgscr(maxcol, 1.0, 0.0, 0.0);
      cpgsci(maxcol);           /* Red */
      xarr[0] = xl;
      xarr[1] = xh;
      yarr[0] = yarr[1] = datapow_med;
      cpgline(2, xarr, yarr);
      cpgsls(4);                /* Dotted line */
      yarr[0] = yarr[1] = pow_reject;
      cpgline(2, xarr, yarr);
      cpgsls(1);                /* Solid line */
      cpgsci(1);                /* Default color */
      cpgline(numchan, chans, pow_chan_med);
      xl = lof;
      xh = hif;
      cpgswin(xl, xh, yl, yh);
      cpgbox("CMST", 0.0, 0, "", 0.0, 0);
      cpgmtxt("T", 1.8, 0.5, 0.5, "Frequency (MHz)");

      /* Standard Deviations */

      left = lm + ft + 2.0 * tt;
      right = lm + 2.0 * ft + 2.0 * tt;
      bottom = bm;
      top = bm + fh;
      xl = 0.0;
      xh = numchan;
      yl = 0.0;
      yh = T;
      cpgsvp(left, right, bottom, top);
      cpgswin(xl, xh, yl, yh);
      cpgscr(mincol, 0.7, 1.0, 0.7);    /* Light Green */
      cpgscr(maxcol, 0.3, 1.0, 0.3);    /* Dark Green */
      locut = datastd_med - timesigma * datastd_std;
      hicut = datastd_med + timesigma * datastd_std;
      tr[2] = tr[4] = 0.0;
      tr[1] = (xh - xl) / numchan;
      tr[0] = xl - (tr[1] / 2);
      tr[5] = (yh - yl) / numint;
      tr[3] = yl - (tr[5] / 2);
      cpgimag(datastd[0], numchan, numint, 1, numchan, 1, numint, locut, hicut, tr);
      cpgswin(xl, xh, yl, yh);
      cpgbox("BNST", 0.0, 0, "BNST", 0.0, 0);
      cpgmtxt("B", 2.6, 0.5, 0.5, "Channel");
      xl = lof;
      xh = hif;
      yl = 0.0;
      yh = numint;
      cpgswin(xl, xh, yl, yh);
      cpgbox("CST", 0.0, 0, "CST", 0.0, 0);

      /* Data Sigma Label */

      left = lm + 2.0 * ft + 2.0 * tt;
      right = lm + 2.0 * ft + 3.0 * tt;
      bottom = bm + fh;
      top = bm + fh + th;
      cpgsvp(left, right, bottom, top);
      cpgswin(0.0, 1.0, 0.0, 1.0);
      cpgscr(maxcol, 0.0, 1.0, 0.0);
      cpgsci(maxcol);           /* Green */
      cpgptxt(0.5, 0.7, 0.0, 0.5, "Data");
      cpgptxt(0.5, 0.3, 0.0, 0.5, "Sigma");
      cpgsci(1);                /* Default color */

      /*  Data Sigma versus Time */

      left = lm + 2.0 * ft + 2.0 * tt;
      right = lm + 2.0 * ft + 3.0 * tt;
      bottom = bm;
      top = bm + fh;
      cpgsvp(left, right, bottom, top);
      xl = datastd_med - 2.0 * std_reject;
      xh = datastd_med + 2.0 * std_reject;
      yl = 0.0;
      yh = T;
      cpgswin(xl, xh, yl, yh);
      cpgbox("BCST", 0.0, 0, "BST", 0.0, 0);
      cpgscr(maxcol, 0.0, 1.0, 0.0);
      cpgsci(maxcol);           /* Green */
      yarr[0] = yl;
      yarr[1] = yh;
      xarr[0] = xarr[1] = datastd_med;
      cpgline(2, xarr, yarr);
      cpgsls(4);                /* Dotted line */
      xarr[0] = xarr[1] = datastd_med + std_reject;
      cpgline(2, xarr, yarr);
      xarr[0] = xarr[1] = datastd_med - std_reject;
      cpgline(2, xarr, yarr);
      cpgsls(1);                /* Solid line */
      cpgsci(1);                /* Default color */
      cpgline(numint, std_int_med, times);
      yl = 0.0;
      yh = numint;
      cpgswin(xl, xh, yl, yh);
      cpgbox("", 0.0, 0, "CMST", 0.0, 0);
      /* cpgmtxt("R", 2.3, 0.5, 0.5, "Interval Number"); */

      /*  Data Sigma versus Channel */

      left = lm + ft + 2.0 * tt;
      right = lm + 2.0 * ft + 2.0 * tt;
      bottom = bm + fh;
      top = bm + fh + th;
      cpgsvp(left, right, bottom, top);
      xl = 0.0;
      xh = numchan;
      yl = datastd_med - 2.0 * std_reject;
      yh = datastd_med + 2.0 * std_reject;
      cpgswin(xl, xh, yl, yh);
      cpgbox("BST", 0.0, 0, "BCST", 0.0, 0);
      cpgscr(maxcol, 0.0, 1.0, 0.0);
      cpgsci(maxcol);           /* Green */
      xarr[0] = xl;
      xarr[1] = xh;
      yarr[0] = yarr[1] = datastd_med;
      cpgline(2, xarr, yarr);
      cpgsls(4);                /* Dotted line */
      yarr[0] = yarr[1] = datastd_med + std_reject;
      cpgline(2, xarr, yarr);
      yarr[0] = yarr[1] = datastd_med - std_reject;
      cpgline(2, xarr, yarr);
      cpgsls(1);                /* Solid line */
      cpgsci(1);                /* Default color */
      cpgline(numchan, chans, std_chan_med);
      xl = lof;
      xh = hif;
      cpgswin(xl, xh, yl, yh);
      cpgbox("CMST", 0.0, 0, "", 0.0, 0);
      cpgmtxt("T", 1.8, 0.5, 0.5, "Frequency (MHz)");

      /* Data Mean */

      left = lm + 2.0 * ft + 4.0 * tt;
      right = lm + 3.0 * ft + 4.0 * tt;
      bottom = bm;
      top = bm + fh;
      xl = 0.0;
      xh = numchan;
      yl = 0.0;
      yh = T;
      cpgsvp(left, right, bottom, top);
      cpgswin(xl, xh, yl, yh);
      cpgscr(mincol, 0.7, 0.7, 1.0);    /* Light Blue */
      cpgscr(maxcol, 0.3, 0.3, 1.0);    /* Dark Blue */
      locut = dataavg_med - timesigma * dataavg_std;
      hicut = dataavg_med + timesigma * dataavg_std;
      tr[2] = tr[4] = 0.0;
      tr[1] = (xh - xl) / numchan;
      tr[0] = xl - (tr[1] / 2);
      tr[5] = (yh - yl) / numint;
      tr[3] = yl - (tr[5] / 2);
      cpgimag(dataavg[0], numchan, numint, 1, numchan, 1, numint, locut, hicut, tr);
      cpgswin(xl, xh, yl, yh);
      cpgbox("BNST", 0.0, 0, "BNST", 0.0, 0);
      cpgmtxt("B", 2.6, 0.5, 0.5, "Channel");
      xl = lof;
      xh = hif;
      yl = 0.0;
      yh = numint;
      cpgswin(xl, xh, yl, yh);
      cpgbox("CST", 0.0, 0, "CST", 0.0, 0);

      /* Data Mean Label */

      left = lm + 3.0 * ft + 4.0 * tt;
      right = lm + 3.0 * ft + 5.0 * tt;
      bottom = bm + fh;
      top = bm + fh + th;
      cpgsvp(left, right, bottom, top);
      cpgswin(0.0, 1.0, 0.0, 1.0);
      cpgscr(maxcol, 0.0, 0.0, 1.0);
      cpgsci(maxcol);           /* Blue */
      cpgptxt(0.5, 0.7, 0.0, 0.5, "Data");
      cpgptxt(0.5, 0.3, 0.0, 0.5, "Mean");
      cpgsci(1);                /* Default color */

      /*  Data Mean versus Time */

      left = lm + 3.0 * ft + 4.0 * tt;
      right = lm + 3.0 * ft + 5.0 * tt;
      bottom = bm;
      top = bm + fh;
      cpgsvp(left, right, bottom, top);
      xl = dataavg_med - 2.0 * avg_reject;
      xh = dataavg_med + 2.0 * avg_reject;
      yl = 0.0;
      yh = T;
      cpgswin(xl, xh, yl, yh);
      cpgbox("BCST", 0.0, 0, "BST", 0.0, 0);
      cpgscr(maxcol, 0.0, 0.0, 1.0);
      cpgsci(maxcol);           /* Blue */
      yarr[0] = yl;
      yarr[1] = yh;
      xarr[0] = xarr[1] = dataavg_med;
      cpgline(2, xarr, yarr);
      cpgsls(4);                /* Dotted line */
      xarr[0] = xarr[1] = dataavg_med + avg_reject;
      cpgline(2, xarr, yarr);
      xarr[0] = xarr[1] = dataavg_med - avg_reject;
      cpgline(2, xarr, yarr);
      cpgsls(1);                /* Solid line */
      cpgsci(1);                /* Default color */
      cpgline(numint, avg_int_med, times);
      yl = 0.0;
      yh = numint;
      cpgswin(xl, xh, yl, yh);
      cpgbox("", 0.0, 0, "CMST", 0.0, 0);

      /*  Data Mean versus Channel */

      left = lm + 2.0 * ft + 4.0 * tt;
      right = lm + 3.0 * ft + 4.0 * tt;
      bottom = bm + fh;
      top = bm + fh + th;
      cpgsvp(left, right, bottom, top);
      xl = 0.0;
      xh = numchan;
      yl = dataavg_med - 2.0 * avg_reject;
      yh = dataavg_med + 2.0 * avg_reject;
      cpgswin(xl, xh, yl, yh);
      cpgbox("BST", 0.0, 0, "BCST", 0.0, 0);
      cpgscr(maxcol, 0.0, 0.0, 1.0);
      cpgsci(maxcol);           /* Blue */
      xarr[0] = xl;
      xarr[1] = xh;
      yarr[0] = yarr[1] = dataavg_med;
      cpgline(2, xarr, yarr);
      cpgsls(4);                /* Dotted line */
      yarr[0] = yarr[1] = dataavg_med + avg_reject;
      cpgline(2, xarr, yarr);
      yarr[0] = yarr[1] = dataavg_med - avg_reject;
      cpgline(2, xarr, yarr);
      cpgsls(1);                /* Solid line */
      cpgsci(1);                /* Default color */
      cpgline(numchan, chans, avg_chan_med);
      xl = lof;
      xh = hif;
      cpgswin(xl, xh, yl, yh);
      cpgbox("CMST", 0.0, 0, "", 0.0, 0);
      cpgmtxt("T", 1.8, 0.5, 0.5, "Frequency (MHz)");

      {                         /* Add the Data Info area */
         char out[200], out2[100];
         float dy = 0.025;

         cpgsvp(0.0, 1.0, 0.0, 1.0);
         cpgswin(0.0, 1.0, 0.0, 1.0);
         left = lm + ft + 1.5 * tt;
         top = 1.0 - tm;
         cpgsch(1.0);
         sprintf(out, "%-s", idata->name);
         cpgptxt(0.5, 1.0 - 0.5 * tm, 0.0, 0.5, out);
         cpgsch(0.8);

         sprintf(out, "Object:");
         cpgtext(left + 0.0, top - 0 * dy, out);
         sprintf(out, "%-s", idata->object);
         cpgtext(left + 0.1, top - 0 * dy, out);
         sprintf(out, "Telescope:");
         cpgtext(left + 0.0, top - 1 * dy, out);
         sprintf(out, "%-s", idata->telescope);
         cpgtext(left + 0.1, top - 1 * dy, out);
         sprintf(out, "Instrument:");
         cpgtext(left + 0.0, top - 2 * dy, out);
         sprintf(out, "%-s", idata->instrument);
         cpgtext(left + 0.1, top - 2 * dy, out);
         ra_dec_to_string(out2, idata->ra_h, idata->ra_m, idata->ra_s);
         sprintf(out, "RA\\dJ2000\\u");
         cpgtext(left + 0.0, top - 3 * dy, out);
         sprintf(out, "= %-s", out2);
         cpgtext(left + 0.08, top - 3 * dy, out);
         ra_dec_to_string(out2, idata->dec_d, idata->dec_m, idata->dec_s);
         sprintf(out, "DEC\\dJ2000\\u");
         cpgtext(left + 0.0, top - 4 * dy, out);
         sprintf(out, "= %-s", out2);
         cpgtext(left + 0.08, top - 4 * dy, out);
         sprintf(out, "Epoch\\dtopo\\u");
         cpgtext(left + 0.0, top - 5 * dy, out);
         sprintf(out, "= %-.11f", idata->mjd_i + idata->mjd_f);
         cpgtext(left + 0.08, top - 5 * dy, out);
         sprintf(out, "T\\dsample\\u (s)");
         cpgtext(left + 0.0, top - 6 * dy, out);
         sprintf(out, "= %g", idata->dt);
         cpgtext(left + 0.08, top - 6 * dy, out);
         sprintf(out, "T\\dtotal\\u (s)");
         cpgtext(left + 0.0, top - 7 * dy, out);
         sprintf(out, "= %g", T);
         cpgtext(left + 0.08, top - 7 * dy, out);

         left = lm + ft + 7.8 * tt;
         sprintf(out, "Num channels");
         cpgtext(left + 0.0, top - 0 * dy, out);
         sprintf(out, "= %-d", numchan);
         cpgtext(left + 0.12, top - 0 * dy, out);
         sprintf(out, "Pts per int");
         cpgtext(left + 0.19, top - 0 * dy, out);
         sprintf(out, "= %-d", ptsperint);
         cpgtext(left + 0.29, top - 0 * dy, out);
         sprintf(out, "Num intervals");
         cpgtext(left + 0.0, top - 1 * dy, out);
         sprintf(out, "= %-d", numint);
         cpgtext(left + 0.12, top - 1 * dy, out);
         sprintf(out, "Time per int");
         cpgtext(left + 0.19, top - 1 * dy, out);
         sprintf(out, "= %-g", inttim);
         cpgtext(left + 0.29, top - 1 * dy, out);
         sprintf(out, "Power:");
         cpgtext(left + 0.0, top - 2 * dy, out);
         sprintf(out, "median");
         cpgtext(left + 0.06, top - 2 * dy, out);
         sprintf(out, "= %-.3f", datapow_med);
         cpgtext(left + 0.12, top - 2 * dy, out);
         sprintf(out, "\\gs");
         cpgtext(left + 0.21, top - 2 * dy, out);
         sprintf(out, "= %-.3g", datapow_std);
         cpgtext(left + 0.245, top - 2 * dy, out);
         find_min_max_arr(numint * numchan, datapow[0], &min, &max);
         sprintf(out, "min");
         cpgtext(left + 0.06, top - 3 * dy, out);
         sprintf(out, "= %-.3f", min);
         cpgtext(left + 0.12, top - 3 * dy, out);
         sprintf(out, "max");
         cpgtext(left + 0.21, top - 3 * dy, out);
         sprintf(out, "= %-.3f", max);
         cpgtext(left + 0.245, top - 3 * dy, out);
         sprintf(out, "Sigma:");
         cpgtext(left + 0.0, top - 4 * dy, out);
         sprintf(out, "median");
         cpgtext(left + 0.06, top - 4 * dy, out);
         sprintf(out, "= %-.3f", datastd_med);
         cpgtext(left + 0.12, top - 4 * dy, out);
         sprintf(out, "\\gs");
         cpgtext(left + 0.21, top - 4 * dy, out);
         sprintf(out, "= %-.3g", datastd_std);
         cpgtext(left + 0.245, top - 4 * dy, out);
         find_min_max_arr(numint * numchan, datastd[0], &min, &max);
         sprintf(out, "min");
         cpgtext(left + 0.06, top - 5 * dy, out);
         sprintf(out, "= %-.3f", min);
         cpgtext(left + 0.12, top - 5 * dy, out);
         sprintf(out, "max");
         cpgtext(left + 0.21, top - 5 * dy, out);
         sprintf(out, "= %-.3f", max);
         cpgtext(left + 0.245, top - 5 * dy, out);
         sprintf(out, "Mean:");
         cpgtext(left + 0.0, top - 6 * dy, out);
         sprintf(out, "median");
         cpgtext(left + 0.06, top - 6 * dy, out);
         sprintf(out, "= %-.3f", dataavg_med);
         cpgtext(left + 0.12, top - 6 * dy, out);
         sprintf(out, "\\gs");
         cpgtext(left + 0.21, top - 6 * dy, out);
         sprintf(out, "= %-.3g", dataavg_std);
         cpgtext(left + 0.245, top - 6 * dy, out);
         find_min_max_arr(numint * numchan, dataavg[0], &min, &max);
         sprintf(out, "min");
         cpgtext(left + 0.06, top - 7 * dy, out);
         sprintf(out, "= %-.3f", min);
         cpgtext(left + 0.12, top - 7 * dy, out);
         sprintf(out, "max");
         cpgtext(left + 0.21, top - 7 * dy, out);
         sprintf(out, "= %-.3f", max);
         cpgtext(left + 0.245, top - 7 * dy, out);
      }

      {                         /* Plot the Mask */
         unsigned char byte;
         char temp[200];
         float **plotmask, rr, gg, bb, page;

         plotmask = gen_fmatrix(numint, numchan);
         for (ii = 0; ii < numint; ii++) {
            for (jj = 0; jj < numchan; jj++) {
               byte = bytemask[ii][jj];
               plotmask[ii][jj] = 0.0;
               if (byte & PADDING)
                  plotmask[ii][jj] = 1.0;
               if (byte & OLDMASK)
                  plotmask[ii][jj] = 2.0;
               if (byte & USERZAP)
                  plotmask[ii][jj] = 3.0;
               if (byte & BAD_POW)
                  plotmask[ii][jj] = 4.0;
               else if (byte & BAD_AVG)
                  plotmask[ii][jj] = 5.0;
               else if (byte & BAD_STD)
                  plotmask[ii][jj] = 6.0;
            }
         }
         /* Set the colors */
         numcol = 7;
         maxcol = mincol + numcol - 1;
         cpgscir(mincol, maxcol);
         cpgqcr(0, &rr, &gg, &bb);
         cpgscr(mincol + 0, rr, gg, bb);        /* GOODDATA = background */
         cpgscr(mincol + 1, 0.7, 0.7, 0.7);     /* PADDING  = light grey */
         cpgscr(mincol + 2, 0.3, 0.3, 0.3);     /* OLDMASK  = dark grey */
         cpgqcr(1, &rr, &gg, &bb);
         cpgscr(mincol + 3, rr, gg, bb);        /* USERZAP  = foreground */
         cpgscr(mincol + 4, 1.0, 0.0, 0.0);     /* BAD+POW  = red */
         cpgscr(mincol + 5, 0.0, 0.0, 1.0);     /* BAD+AVG  = blue */
         cpgscr(mincol + 6, 0.0, 1.0, 0.0);     /* BAD+STD  = green */
         /* Prep the image */
         for (page = 0; page <= 1; page++) {
            xl = 0.0;
            xh = numchan;
            yl = 0.0;
            yh = T;
            locut = 0.0;
            hicut = 6.0;
            tr[2] = tr[4] = 0.0;
            tr[1] = (xh - xl) / numchan;
            tr[0] = xl - (tr[1] / 2);
            tr[5] = (yh - yl) / numint;
            tr[3] = yl - (tr[5] / 2);
            if (page == 0) {
               left = lm + 3.0 * ft + 6.0 * tt;
               right = lm + 4.0 * ft + 6.0 * tt;
               bottom = bm;
               top = bm + fh;
            } else {
               cpgpage();
               cpgiden();
               left = 0.06;
               right = 0.94;
               bottom = 0.06;
               top = 0.88;
            }
            cpgsvp(left, right, bottom, top);
            cpgswin(xl, xh, yl, yh);
            cpgimag(plotmask[0], numchan, numint, 1,
                    numchan, 1, numint, locut, hicut, tr);
            cpgswin(xl, xh, yl, yh);
            cpgbox("BNST", 0.0, 0, "BNST", 0.0, 0);
            cpgmtxt("B", 2.6, 0.5, 0.5, "Channel");
            if (page)
               cpgmtxt("L", 2.1, 0.5, 0.5, "Time (s)");
            xl = lof;
            xh = hif;
            yl = 0.0;
            yh = numint;
            cpgswin(xl, xh, yl, yh);
            cpgbox("CMST", 0.0, 0, "CMST", 0.0, 0);
            cpgmtxt("T", 1.8, 0.5, 0.5, "Frequency (MHz)");
            cpgmtxt("R", 2.3, 0.5, 0.5, "Interval Number");
            /* Add the Labels */
            cpgsvp(0.0, 1.0, 0.0, 1.0);
            cpgswin(0.0, 1.0, 0.0, 1.0);
            cpgsch(0.8);
            if (page == 0) {
               cpgsci(mincol + 1);
               cpgptxt(left, top + 0.1, 0.0, 0.0, "Padding");
               cpgsci(mincol + 2);
               cpgptxt(left, top + 0.08, 0.0, 0.0, "Old Mask");
               cpgsci(mincol + 3);
               cpgptxt(left, top + 0.06, 0.0, 0.0, "User Zap");
               cpgsci(mincol + 4);
               cpgptxt(right, top + 0.1, 0.0, 1.0, "Power");
               cpgsci(mincol + 6);
               cpgptxt(right, top + 0.08, 0.0, 1.0, "Sigma");
               cpgsci(mincol + 5);
               cpgptxt(right, top + 0.06, 0.0, 1.0, "Mean");
               cpgsci(1);
            } else {
               cpgsci(mincol + 1);
               cpgptxt(1.0 / 12.0, 0.955, 0.0, 0.5, "Padding");
               cpgsci(mincol + 2);
               cpgptxt(3.0 / 12.0, 0.955, 0.0, 0.5, "Old Mask");
               cpgsci(mincol + 3);
               cpgptxt(5.0 / 12.0, 0.955, 0.0, 0.5, "User Zap");
               cpgsci(mincol + 4);
               cpgptxt(7.0 / 12.0, 0.955, 0.0, 0.5, "Max Power");
               cpgsci(mincol + 6);
               cpgptxt(9.0 / 12.0, 0.955, 0.0, 0.5, "Data Sigma");
               cpgsci(mincol + 5);
               cpgptxt(11.0 / 12.0, 0.955, 0.0, 0.5, "Data Mean");
               cpgsci(1);
               cpgsch(0.9);
               sprintf(temp, "Recommended Mask for '%-s'", idata->name);
               cpgptxt(0.5, 0.985, 0.0, 0.5, temp);
            }
         }
         vect_free(plotmask[0]);
         vect_free(plotmask);
      }

      if (ct == 0)
         printf("There are %d RFI instances.\n\n", numrfi);

      if ((ct == 0 && rfips) || (ct == 1 && rfixwin)) { /* Plot the RFI instances */
         int maxcol, mincol, numperpage = 25, numtoplot;
         float dy = 0.035, top = 0.95, rr, gg, bb;
         char temp[200];

         qsort(rfivect, numrfi, sizeof(rfi), compare_rfi_freq);
         /* qsort(rfivect, numrfi, sizeof(rfi), compare_rfi_sigma); */
         for (ii = 0; ii <= (numrfi - 1) / numperpage; ii++) {
            cpgpage();
            cpgiden();
            cpgsvp(0.0, 1.0, 0.0, 1.0);
            cpgswin(0.0, 1.0, 0.0, 1.0);
            cpgsch(0.8);
            sprintf(temp, "%-s", idata->name);
            cpgtext(0.05, 0.985, temp);
            cpgsch(0.6);
            sprintf(temp, "Freq (Hz)");
            cpgptxt(0.03, 0.96, 0.0, 0.0, temp);
            sprintf(temp, "Period (ms)");
            cpgptxt(0.12, 0.96, 0.0, 0.0, temp);
            sprintf(temp, "Sigma");
            cpgptxt(0.21, 0.96, 0.0, 0.0, temp);
            sprintf(temp, "Number");
            cpgptxt(0.27, 0.96, 0.0, 0.0, temp);
            cpgsvp(0.33, 0.64, top - dy, top);
            cpgswin(lof, hif, 0.0, 1.0);
            cpgbox("CIMST", 0.0, 0, "", 0.0, 0);
            cpgmtxt("T", 2.5, 0.5, 0.5, "Frequency (MHz)");
            cpgsvp(0.65, 0.96, top - dy, top);
            cpgswin(0.0, T, 0.0, 1.0);
            cpgbox("CIMST", 0.0, 0, "", 0.0, 0);
            cpgmtxt("T", 2.5, 0.5, 0.5, "Time (s)");
            cpgqcir(&mincol, &maxcol);
            maxcol = mincol + 1;
            cpgscir(mincol, maxcol);
            cpgqcr(0, &rr, &gg, &bb);
            cpgscr(mincol, rr, gg, bb); /* background */
            cpgqcr(1, &rr, &gg, &bb);
            /* cpgscr(maxcol, rr, gg, bb);  foreground */
            cpgscr(maxcol, 0.5, 0.5, 0.5);      /* grey */
            if (ii == (numrfi - 1) / numperpage)
               numtoplot = numrfi % numperpage;
            else
               numtoplot = numperpage;
            for (jj = 0; jj < numtoplot; jj++)
               plot_rfi(rfivect + ii * numperpage + jj,
                        top - jj * dy, numint, numchan, T, lof, hif);
            cpgsvp(0.33, 0.64, top - jj * dy, top - (jj - 1) * dy);
            cpgswin(0.0, numchan, 0.0, 1.0);
            cpgbox("BINST", 0.0, 0, "", 0.0, 0);
            cpgmtxt("B", 2.5, 0.5, 0.5, "Channel");
            cpgsvp(0.65, 0.96, top - jj * dy, top - (jj - 1) * dy);
            cpgswin(0.0, numint, 0.0, 1.0);
            cpgbox("BINST", 0.0, 0, "", 0.0, 0);
            cpgmtxt("B", 2.5, 0.5, 0.5, "Interval");
         }
      }
      cpgclos();
   }                            /* Plot for loop */

   /* Free our arrays */

   vect_free(freqs);
   vect_free(chans);
   vect_free(times);
   vect_free(ints);
   vect_free(avg_chan_avg);
   vect_free(std_chan_avg);
   vect_free(pow_chan_avg);
   vect_free(avg_int_avg);
   vect_free(std_int_avg);
   vect_free(pow_int_avg);
   vect_free(avg_chan_med);
   vect_free(std_chan_med);
   vect_free(pow_chan_med);
   vect_free(avg_int_med);
   vect_free(std_int_med);
   vect_free(pow_int_med);
   vect_free(avg_chan_std);
   vect_free(std_chan_std);
   vect_free(pow_chan_std);
   vect_free(avg_int_std);
   vect_free(std_int_std);
   vect_free(pow_int_std);
}
Beispiel #30
0
void multi_prof_plot(int proflen, int numprofs, double *profiles,
                     double *sumprof, const char *xlbl,
                     double loly, double ldy, const char *lylbl,
                     double lory, double rdy, const char *rylbl)
{
   float *x, *y, yoffset, ynorm;
   float lox = 0.0, hix = 1.0, ddx = 0.01;
   double ymin = 0.0, ymax = 0.0;
   int i, j, index;

   x = gen_fvect(proflen + 1);
   y = gen_fvect(proflen + 1);
   for (i = 0; i <= proflen; i++)
      x[i] = (float) i / (float) proflen;

   /* The multiplots... */

   /* Define the Viewport */
   cpgsvp(0.1, 0.85, 0.2, 0.9);
   /* Define the Window */
   cpgswin(lox - ddx, hix + ddx, (float) (loly - ldy),
           (float) (loly + numprofs * ldy));
   /* Define the left border */
   cpgbox("CST", 0.2, 2, "BNST", 0.0, 0);
   /* Write the left-hand label */
   cpgmtxt("L", 2.6, 0.5, 0.5, lylbl);
   /* Re-Define the Window */
   cpgswin(lox - ddx, hix + ddx, (float) (lory - rdy),
           (float) (lory + numprofs * rdy));
   /* Define the right border */
   cpgbox("", 0.2, 2, "CMST", 0.0, 0);
   /* Write the right-hand label */
   cpgmtxt("R", 3.0, 0.5, 0.5, rylbl);

   /* Plot the individual channel profiles */

   for (i = 0; i < numprofs; i++) {
      /* Determine min and max values to plot */
      index = i * proflen;
      yoffset = lory + i * rdy;
      dfind_min_max_arr(proflen, profiles + index, &ymin, &ymax);
      ynorm = 0.9 * rdy / (ymax - ymin);
      for (j = 0; j < proflen; j++)
         y[j] = (profiles[index + j] - ymin) * ynorm + yoffset;
      y[proflen] = y[0];
      cpgbin(proflen + 1, x, y, 1);
   }

   /* The summed plot... */

   /* Define the Viewport */
   cpgsvp(0.1, 0.85, 0.1, 0.2);
   /* Define the Window */
   cpgswin(lox - ddx, hix + ddx, -0.1, 1.0);
   /* Define the border */
   cpgbox("BNST", 0.2, 2, "BC", 0.0, 0);
   /* Write the bottom label */
   cpgmtxt("B", 3.0, 0.5, 0.5, xlbl);
   /* Determine min and max values to plot */
   dfind_min_max_arr(proflen, sumprof, &ymin, &ymax);
   ynorm = 0.9 / (ymax - ymin);
   for (j = 0; j < proflen; j++)
      y[j] = (sumprof[j] - ymin) * ynorm;
   y[proflen] = y[0];
   /* Plot the summed profile */
   cpgbin(proflen + 1, x, y, 1);

   /* Cleanup */
   vect_free(x);
   vect_free(y);

}