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; }
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; }
void timedraw(g_ctl * ctl, tf * f, defs * d, int gravity) { char txt[500]; float *x = NULL; int i, k; x = malloc(sizeof(float) * f->current->head->npts); for (i = 0; i < f->current->head->npts; i++) x[i] = i * f->current->head->delta + f->current->head->b; pdefs *pick = d->pickRules[(int)getConfigAsNumber(config, NAME_PICK, DEFAULT_PICK)]; float FMark = pickD(pick, f->current->head); float AMark = pickR(pick, f->current->head); float *y = (d->filter && f->current->dataf != NULL) ? f->current->dataf : f->current->data; ctl_yupdate_ndb(ctl, y, f->current->head->npts, f->current->head->delta, f->current->head->b); ctl_clean(NULL); ctl_resizeview(ctl); ctl_axisfull(ctl); ctl->expand = 0; ctl_drawaxis(ctl); cpgline(f->current->head->npts, x, y); free(x); x = NULL; /* Add marks */ for(k=0; k<pick->nPhase; k++) { float value = pickO(pick, f->current->head, k); if (value != SAC_HEADER_FLOAT_UNDEFINED) { char *label = pickL(pick, f->current->head, k); mark(ctl, value - f->current->head->b, label, 2); if (label != NULL) free(label); label = NULL; } } if (d->filter) { sprintf(txt, "%s [Filtering, bandpass from %.2f to %.2f]", (gravity) ? "Gravity On" : "Gravity Off", d->hp, d->lp); } else { sprintf(txt, "%s [No Filtering]", (gravity) ? "Gravity On" : "Gravity Off"); } cpgmtxt("B", -1., 0.01, 0.0, txt); cpgmtxt("T", 3.5, 0.0, 0.0, "Click-Click to Zoom. Double Click to UnZoom. Q to go back (Quit Edit Mode)"); cpgmtxt("T", 2.5, 0.0, 0.0, "D to delete f Mark. Y/Z for marking f phase. G to enable/disable gravity."); cpgmtxt("T", 1.5, 0.0, 0.0, "F to switch filter On/Off. L for Low pass frequency (Hz). H for High pass frequency (Hz)."); }
void plot_profile(int proflen, float *profile, const char *title, const char *probtxt, const char *foldtxt, int showerr, float *errors, int showid) { int ii; float *x, overy, ymin, ymax; float errmin = 0.0, errmax = 0.0, offset, avg = 0.0, av[2]; find_min_max_arr(proflen, profile, &ymin, &ymax); if (showerr) find_min_max_arr(proflen, errors, &errmin, &errmax); overy = 0.1 * (ymax + errmax - ymin - errmin); ymax = ymax + overy + errmax; ymin = ymin - overy - errmin; x = gen_fvect(proflen); for (ii = 0; ii < proflen; ii++) x[ii] = (float) ii / (float) proflen; cpgenv(0.0, 1.00001, ymin, ymax, 0, 0); cpgscf(2); cpglab("Pulse Phase", "Counts", ""); if (showid) cpgiden(); cpgslw(5); if (showerr) { cpgbin(proflen, x, profile, 0); } else { cpgline(proflen, x, profile); } cpgslw(1); if (showerr) { offset = 0.5 / (float) proflen; for (ii = 0; ii < proflen; ii++) x[ii] += offset; cpgerrb(6, proflen, x, profile, errors, 2); cpgpt(proflen, x, profile, 5); } for (ii = 0; ii < proflen; ii++) avg += profile[ii]; avg /= proflen; cpgsls(4); x[0] = 0.0; x[1] = 1.0; av[0] = avg; av[1] = avg; cpgline(2, x, av); cpgsls(1); cpgsch(1.3); cpgmtxt("T", +2.0, 0.5, 0.5, title); cpgsch(1.0); cpgmtxt("T", +0.8, 0.5, 0.5, foldtxt); cpgmtxt("T", -1.5, 0.5, 0.5, probtxt); vect_free(x); }
void plot_spectrum(fcomplex * spect, int numspect, double lor, double dr, double T, double average) /* Plot a chunk of the Fourier power spectrum normalized by average */ /* The viewing area is left defined with the xvals as _bins_. */ { int ii; float *yvals, *xvals, maxy = 0.0; double offsetr, hir; char lab[100]; if (lor > 10000) { offsetr = floor(lor / 1000.0) * 1000.0; sprintf(lab, "Fourier Frequency - %.0f (bins)", offsetr); } else { offsetr = 0.0; sprintf(lab, "Fourier Frequency (bins)"); } lor = lor - offsetr; hir = lor + numspect * dr; xvals = (float *) malloc(sizeof(float) * numspect); yvals = (float *) malloc(sizeof(float) * numspect); for (ii = 0; ii < numspect; ii++) { xvals[ii] = lor + ii * dr; yvals[ii] = (spect[ii].r * spect[ii].r + spect[ii].i * spect[ii].i) / average; if (yvals[ii] > maxy) maxy = yvals[ii]; } maxy *= 1.1; /* Setup the plot screen for the first set of y's: */ cpgpage(); cpgvstd(); /* Draw the box for the frequency (Hz) axis */ cpgswin((lor + offsetr) / T, (hir + offsetr) / T, 0.0, maxy); cpgbox("BNST", 0.0, 0, "BCNST", 0.0, 0); cpgmtxt("B", 2.5, 0.5, 0.5, "Frequency (Hz)"); /* Draw the box for the Fourier frequency (bins) axis */ cpgswin(lor, hir, 0.0, maxy); cpgbox("CMST", 0.0, 0, "", 0.0, 0); cpgmtxt("T", 2.0, 0.5, 0.5, lab); cpgmtxt("L", 2.0, 0.5, 0.5, "Normalized Power"); /* Plot the points */ cpgline(numspect, xvals, yvals); free(xvals); free(yvals); }
void xyline2lab(int npts, float *x, float *y, float *y2, const char *xlab, const char *ylab, const char *ylab2, int id) { float xmin, xmax, ymin, ymax, ymin2, ymax2; float overy, over = 0.1; /* Determine min and max values to plot and scaling: */ find_min_max_arr(npts, x, &xmin, &xmax); find_min_max_arr(npts, y, &ymin, &ymax); find_min_max_arr(npts, y2, &ymin2, &ymax2); overy = over * (ymax - ymin); ymax += overy; ymin -= overy; overy = over * (ymax2 - ymin2); ymax2 += overy; ymin2 -= overy; /* Choose the font: */ cpgscf(2); /* Setup the plot screen for the first set of y's: */ cpgpage(); cpgvstd(); cpgswin(xmin, xmax, ymin, ymax); cpgbox("BCNST", 0.0, 0, "BNST", 0.0, 0); cpgmtxt("B", 3.0, 0.5, 0.5, xlab); cpgmtxt("L", 2.6, 0.5, 0.5, ylab); /* Plot the points for the 1st y axis: */ cpgline(npts, x, y); /* Setup the plot screen for the second set of y's: */ cpgvstd(); cpgswin(xmin, xmax, ymin2, ymax2); cpgbox("", 0.0, 0, "CMST", 0.0, 0); cpgmtxt("R", 3.0, 0.5, 0.5, ylab2); /* Plot the points for the 2nd y axis: */ cpgline(npts, x, y2); /* Add ID line if required */ if (id == 1) cpgiden(); }
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); }
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; }
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; }
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; }
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; }
// Main code int main() { /**** Count to 10 in integers ****/ // Declare integer for loop counting int i; // Loop from 0 to 10, printing at each step for(i=0; i<10; i++) { printf("i= %d\n", i); } /**** Plot a function y=f(x) ****/ // Declare arrays of N real numbers float ax[N]; // x float ay[N]; // y float aylow[N]; // lower error in y float ayhigh[N]; // upper error in y // Set minimum and maximum for x float xmin = 0.0; float xmax = 10.0; // Assigning ax with N values for x between xmin and xmax for(i=0;i<N;i++) { ax[i] = xmin + (xmax-xmin)*(float)i/(float)(N-1); } // Fill ay using function fy for(i=0;i<N;i++) { ay[i] = fy(ax[i]); } // Fill aylow and ayhigh using sqrt(y) as the error for(i=0;i<N;i++) { aylow[i] = ay[i] - sqrt(ay[i]); ayhigh[i] = ay[i] + sqrt(ay[i]); } /**** Use pgplot to plot this function ****/ // cpgbeg starts a plotting page, in this case with 2x1 panels cpgbeg(0,"?",2,1); // sets colour: 1-black, 2-red, 3-green, 4-blue cpgsci(1); // sets line style: 1-solid, 2-dashed, 3-dot-dashed, 4-dotted cpgsls(1); // sets charachter height, larger number = bigger cpgsch(2.); // cpgpage() moves to the next panel cpgpage(); // sets the axes limits in the panel cpgswin(xmin,xmax,0.,100.); // draw the axes cpgbox("BCNST", 0.0, 0, "BCNST", 0.0, 0); // label the bottom axis cpgmtxt("B",2.,.5,.5,"x"); // label the left axis cpgmtxt("L",2.5,.5,.5,"f"); // connect N points in ax and ay with a line cpgline(N,ax,ay); // cpgpage() moves to the next panel cpgpage(); // sets the axes limits in the panel cpgswin(xmin,xmax,0.,100.); // draw the axes cpgbox("BCNST", 0.0, 0, "BCNST", 0.0, 0); // label the bottom axis cpgmtxt("B",2.,.5,.5,"x"); // label the left axis cpgmtxt("L",2.5,.5,.5,"f"); // draw N points in ax and ay // 17 - filled circles, 16 - filled squares, 13 - filled triangles cpgpt(N,ax,ay,17); // draw y error bars on the points cpgerry(N,ax,aylow,ayhigh,1.0); // close all pgplot applications cpgend(); // end program return 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); }
int main() { /* Set up a 2 x 2 lookup table. */ const int M = 2; const int K[] = {K1, K2}; const int map[] = {0, 1}; const double crval[] = {0.0, 0.0}; char text[80]; int i, j, k, l, l1, l2, l3, lstep, m, stat[NP*NP], status; float array[NP][NP], clev[31], v0, v1, w; const float scl = 2.0f/(NP-1); float ltm[6]; double x[NP][NP][2], world[NP][NP][2]; struct tabprm tab; printf("Testing WCSLIB coordinate lookup table routines (ttab2.c)\n" "---------------------------------------------------------\n"); /* List status return messages. */ printf("\nList of tab status return values:\n"); for (status = 1; status <= 5; status++) { printf("%4d: %s.\n", status, tab_errmsg[status]); } printf("\n"); /* PGPLOT initialization. */ strcpy(text, "/xwindow"); cpgbeg(0, text, 1, 1); cpgvstd(); cpgsch(0.7f); /* The viewport is slightly oversized. */ cpgwnad(-0.65f, 1.65f, -0.65f, 1.65f); for (l = 0; l <= 30; l++) { clev[l] = 0.2f*(l-10); } ltm[0] = -scl*(1.0f + (NP-1)/4.0f); ltm[1] = scl; ltm[2] = 0.0f; ltm[3] = -scl*(1.0f + (NP-1)/4.0f); ltm[4] = 0.0f; ltm[5] = scl; /* Set up the lookup table. */ tab.flag = -1; if ((status = tabini(1, M, K, &tab))) { printf("tabini ERROR %d: %s.\n", status, tab_errmsg[status]); return 1; } tab.M = M; for (m = 0; m < tab.M; m++) { tab.K[m] = K[m]; tab.map[m] = map[m]; tab.crval[m] = crval[m]; for (k = 0; k < tab.K[m]; k++) { tab.index[m][k] = (double)k; } } /* Subdivide the interpolation element. */ for (i = 0; i < NP; i++) { for (j = 0; j < NP; j++) { x[i][j][0] = j*(K1-1.0)*scl - 0.5 - crval[0]; x[i][j][1] = i*(K2-1.0)*scl - 0.5 - crval[1]; } } /* The first coordinate element is static. */ tab.coord[0] = 0.0; tab.coord[2] = 0.0; tab.coord[4] = 0.0; tab.coord[6] = 0.0; /* (k1,k2) = (0,0). */ tab.coord[1] = 0.0; /* The second coordinate element varies in three of the corners. */ for (l3 = 0; l3 <= 100; l3 += 20) { /* (k1,k2) = (1,1). */ tab.coord[7] = 0.01 * l3; for (l2 = 0; l2 <= 100; l2 += 20) { /* (k1,k2) = (0,1). */ tab.coord[5] = 0.01 * l2; cpgpage(); for (l1 = 0; l1 <= 100; l1 += 2) { /* (k1,k2) = (1,0). */ tab.coord[3] = 0.01 * l1; /* Compute coordinates within the interpolation element. */ tab.flag = 0; if ((status = tabx2s(&tab, NP*NP, 2, (double *)x, (double *)world, stat))) { printf("tabx2s ERROR %d: %s.\n", status, tab_errmsg[status]); } /* Start a new plot. */ cpgbbuf(); cpgeras(); cpgsci(1); cpgslw(3); cpgbox("BCNST", 0.0f, 0, "BCNSTV", 0.0f, 0); cpgmtxt("T", 0.7f, 0.5f, 0.5f, "-TAB coordinates: " "linear interpolation / extrapolation in 2-D"); /* Draw the boundary of the interpolation element in red. */ cpgsci(2); cpgmove(-0.5f, 0.0f); cpgdraw( 1.5f, 0.0f); cpgmove( 1.0f, -0.5f); cpgdraw( 1.0f, 1.5f); cpgmove( 1.5f, 1.0f); cpgdraw(-0.5f, 1.0f); cpgmove( 0.0f, 1.5f); cpgdraw( 0.0f, -0.5f); /* Label the value of the coordinate element in each corner. */ sprintf(text, "%.1f", tab.coord[1]); cpgtext(-0.09f, -0.05f, text); sprintf(text, "%.2f", tab.coord[3]); cpgtext( 1.02f, -0.05f, text); sprintf(text, "%.1f", tab.coord[5]); cpgtext(-0.13f, 1.02f, text); sprintf(text, "%.1f", tab.coord[7]); cpgtext( 1.02f, 1.02f, text); cpgsci(1); /* Contour labelling: bottom. */ v0 = world[0][0][1]; v1 = world[0][NP-1][1]; if (v0 != v1) { lstep = (abs((int)((v1-v0)/0.2f)) < 10) ? 20 : 40; for (l = -200; l <= 300; l += lstep) { w = -0.5f + 2.0f * (l*0.01f - v0) / (v1 - v0); if (w < -0.5 || w > 1.5) continue; sprintf(text, "%4.1f", l*0.01f); cpgptxt(w+0.04f, -0.56f, 0.0f, 1.0f, text); } } /* Contour labelling: left. */ v0 = world[0][0][1]; v1 = world[NP-1][0][1]; if (v0 != v1) { lstep = (abs((int)((v1-v0)/0.2f)) < 10) ? 20 : 40; for (l = -200; l <= 300; l += lstep) { w = -0.5f + 2.0f * (l*0.01f - v0) / (v1 - v0); if (w < -0.5 || w > 1.5) continue; sprintf(text, "%4.1f", l*0.01f); cpgptxt(-0.52f, w-0.02f, 0.0f, 1.0f, text); } } /* Contour labelling: right. */ v0 = world[0][NP-1][1]; v1 = world[NP-1][NP-1][1]; if (v0 != v1) { lstep = (abs((int)((v1-v0)/0.2f)) < 10) ? 20 : 40; for (l = -200; l <= 300; l += lstep) { w = -0.5f + 2.0f * (l*0.01f - v0) / (v1 - v0); if (w < -0.5 || w > 1.5) continue; sprintf(text, "%.1f", l*0.01f); cpgptxt(1.52f, w-0.02f, 0.0f, 0.0f, text); } } /* Contour labelling: top. */ v0 = world[NP-1][0][1]; v1 = world[NP-1][NP-1][1]; if (v0 != v1) { lstep = (abs((int)((v1-v0)/0.2f)) < 10) ? 20 : 40; for (l = -200; l <= 300; l += lstep) { w = -0.5f + 2.0f * (l*0.01f - v0) / (v1 - v0); if (w < -0.5 || w > 1.5) continue; sprintf(text, "%4.1f", l*0.01f); cpgptxt(w+0.04f, 1.52f, 0.0f, 1.0f, text); } } /* Draw contours for the second coordinate element. */ for (i = 0; i < NP; i++) { for (j = 0; j < NP; j++) { array[i][j] = world[i][j][1]; } } cpgsci(4); cpgslw(2); cpgcont(array[0], NP, NP, 1, NP, 1, NP, clev, 10, ltm); cpgsci(7); cpgcont(array[0], NP, NP, 1, NP, 1, NP, clev+10, 1, ltm); cpgsci(5); cpgcont(array[0], NP, NP, 1, NP, 1, NP, clev+11, 20, ltm); cpgebuf(); } } } cpgend(); tabfree(&tab); return 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; }
main(int argc, char *argv[]) { FILE *output; int numerate,i,j,k,l,nsperdmp,nsamps,indexing,plot,indexnow; int ifchan[16],frchan[4096],ifnum,chnum,ns,sample,ntotal; float time_of_pulse, width_of_pulse, time, time_start, time_end; float series_amp[100000],series_time[100000],ampmin,ampmax; char message[80],outfile[80],filename[80],timestring[80],pgdev[80]; unsigned char c; unsigned short s; float f[8]; if (argc<2) { puts(""); puts("getpulse - make and/or plot a time series from dedispersed file\n"); puts("usage: getpulse {filename} -{options}\n"); puts("filename is the dedispersed data file\n"); puts("options:\n"); puts("-t time - time (in seconds) on which to center time series (REQUIRED)\n"); puts("-w width - width (in seconds) of time series to plot (def=1)\n"); puts("-c fchan - to only output frequency channel fchan (def=all)\n"); puts("-i ifchan - to only output IF channel ifchan (def=all)\n"); puts("-p pgdev - pgplot device (def=/xs)\n"); puts("-numerate - to precede each dump with sample number (def=time)\n"); puts("-noindex - do not precede each dump with time/number\n"); puts("-plot - PGPLOT the results\n"); puts(""); exit(0); } /* zero IF and frequency channel arrays */ for (i=0;i<16;i++) ifchan[i]=0; for (i=0;i<4096;i++) frchan[i]=0; /* default case is to read from standard input */ input=stdin; numerate=0; ampmin = 1.e6; ampmax = -1.e6; plot=0; indexnow=0; indexing=1; strcpy(pgdev,"/xs"); /* parse command line if arguments were given */ if (argc>1) { i=1; while (i<argc) { if (strings_equal(argv[i],"-i")) { i++; ifchan[atoi(argv[i])-1]=1; } else if (strings_equal(argv[i],"-c")) { i++; frchan[atoi(argv[i])-1]=1; } else if (strings_equal(argv[i],"-t")) { i++; time_of_pulse = atof(argv[i]); strcpy(timestring,argv[i]); fprintf(stderr,"centering on time %f s\n",time_of_pulse); } else if (strings_equal(argv[i],"-w")) { i++; width_of_pulse = atof(argv[i]); fprintf(stderr,"with width %f s\n",width_of_pulse); } else if (strings_equal(argv[i],"-p")) { i++; strcpy(pgdev,argv[i]); } else if (strings_equal(argv[i],"-numerate")) { numerate=1; } else if (strings_equal(argv[i],"-noindex")) { indexing=0; } else if (strings_equal(argv[i],"-plot")) { plot=1; } else if (file_exists(argv[i])) { input=open_file(argv[i],"rb"); strcpy(filename,argv[i]); } else { sprintf(message,"unknown argument (%s) passed to getpulse",argv[i]); error_message(message); } i++; } } strcat(filename,".pulse."); strcat(filename,timestring); strcpy(outfile,filename); output=fopen(outfile,"w"); time_start = time_of_pulse - width_of_pulse/2.; time_end = time_of_pulse + width_of_pulse/2.; sample = 0; /* try to read the header */ if (!read_header(input)) error_message("error reading header\n"); /* check what IF and frequency channels (if any the user has selected) */ j=0; for (i=0; i<nifs; i++) if (ifchan[i]) j++; if (j==0) for (i=0; i<nifs; i++) ifchan[i]=1; j=0; for (i=0; i<nchans; i++) if (frchan[i]) j++; if (j==0) for (i=0; i<nchans; i++) frchan[i]=1; /* number of samples to read per dump */ nsperdmp=nifs*nchans; /* initialize loop counters and flags */ ifnum=chnum=nsamps=l=0; while (!feof(input)) { /* unpack the sample(s) if necessary */ switch (nbits) { case 1: fread(&c,1,1,input); for (i=0;i<8;i++) { f[i]=c&1; c>>=1; } ns=8; break; case 4: fread(&c,1,1,input); char2ints(c,&j,&k); f[0]=(float) j; f[1]=(float) k; ns=2; break; case 8: fread(&c,nbits/8,1,input); f[0]=(float) c; ns=1; break; case 16: fread(&s,nbits/8,1,input); f[0]=(float) s; ns=1; break; case 32: fread(&f[0],nbits/8,1,input); ns=1; break; default: sprintf(message,"cannot read %d bits per sample...\n",nbits); error_message(message); break; } if (plot) { ntotal = (time_end-time_start)/tsamp; if (ntotal > 100000) { fprintf(stderr,"Too many samples to plot!\n"); plot=0; } } for (i=0; i<ns; i++) { /* time stamp or index the data */ time = (double) tsamp * (double) l; if (time > time_end) { if (plot) { indexnow=indexnow-1; cpgbeg(0,pgdev,1,1); cpgsvp(0.1,0.9,0.1,0.9); cpgswin(series_time[0],series_time[indexnow],ampmin-0.1*ampmax,ampmax+0.1*ampmax); cpgbox("bcnst",0.0,0,"bcnst",0,0.0); cpgline(indexnow,series_time,series_amp); cpgscf(2); cpgmtxt("B",2.5,0.5,0.5,"Time (s)"); cpgmtxt("L",1.8,0.5,0.5,"Amplitude"); cpgend();} exit(0); } /* print sample if it is one of the ones selected */ if (ifchan[ifnum] && frchan[chnum] && time >= time_start && time <= time_end) { if (indexing) { if (numerate) fprintf(output,"%d %f\n",l,f[i]); else fprintf(output,"%f %f\n",time,f[i]); } else { fprintf(output,"%f\n",f[i]); } if (plot) { series_amp[indexnow]=f[i]; series_time[indexnow]=time; if (f[i] < ampmin) ampmin = f[i]; if (f[i] > ampmax) ampmax = f[i]; indexnow++; } } nsamps++; chnum++; if (chnum==nchans) { chnum=0; ifnum++; if (ifnum==nifs) ifnum=0; } if ((nsamps%nsperdmp)==0) { nsamps=0; l++; } } } fclose(output); }
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; }
int closure ( const char ctypeS[9], double restfrq, double restwav, int naxisj, double crpixj, double cdeltX, double crvalX) { char ptype, sname[32], title[80], units[8], xtype, ylab[80]; int nFail = 0, restreq, stat1[NSPEC], stat2[NSPEC], status; register int j; float tmp, x[NSPEC], xmin, xmax, y[NSPEC], ymax, ymin; double cdeltS, clos[NSPEC], crvalS, dSdX, resid, residmax, spec1[NSPEC], spec2[NSPEC]; struct spcprm spc; /* Get keyvalues for the required spectral axis type. */ if ((status = spcxps(ctypeS, crvalX, restfrq, restwav, &ptype, &xtype, &restreq, &crvalS, &dSdX))) { printf("ERROR %d from spcxps() for %s.\n", status, ctypeS); return 1; } cdeltS = cdeltX * dSdX; spcini(&spc); if (ctypeS[5] == 'G') { /* KPNO MARS spectrograph grism parameters. */ spc.pv[0] = mars[0]; spc.pv[1] = mars[1]; spc.pv[2] = mars[2]; spc.pv[3] = mars[3]; spc.pv[4] = mars[4]; spc.pv[5] = mars[5]; spc.pv[6] = mars[6]; } /* Construct the axis. */ for (j = 0; j < naxisj; j++) { spec1[j] = (j+1 - crpixj)*cdeltS; } printf("%4s (CRVALk+w) range: %13.6e to %13.6e, step: %13.6e\n", ctypeS, crvalS+spec1[0], crvalS+spec1[naxisj-1], cdeltS); /* Initialize. */ spc.flag = 0; spc.crval = crvalS; spc.restfrq = restfrq; spc.restwav = restwav; strncpy(spc.type, ctypeS, 4); spc.type[4] = '\0'; strcpy(spc.code, ctypeS+5); /* Convert the first to the second. */ if ((status = spcx2s(&spc, naxisj, 1, 1, spec1, spec2, stat1))) { printf("spcx2s ERROR %d: %s.\n", status, spc_errmsg[status]); } /* Convert the second back to the first. */ if ((status = spcs2x(&spc, naxisj, 1, 1, spec2, clos, stat2))) { printf("spcs2x ERROR %d: %s.\n", status, spc_errmsg[status]); } residmax = 0.0; /* Test closure. */ for (j = 0; j < naxisj; j++) { if (stat1[j]) { printf("%s: w =%20.12e -> %s = ???, stat = %d\n", ctypeS, spec1[j], spc.type, stat1[j]); continue; } if (stat2[j]) { printf("%s: w =%20.12e -> %s =%20.12e -> w = ???, stat = %d\n", ctypeS, spec1[j], spc.type, spec2[j], stat2[j]); continue; } resid = fabs((clos[j] - spec1[j])/cdeltS); if (resid > residmax) residmax = resid; if (resid > tol) { nFail++; printf("%s: w =%20.12e -> %s =%20.12e ->\n w =%20.12e, " "resid =%20.12e\n", ctypeS, spec1[j], spc.type, spec2[j], clos[j], resid); } } printf("%s: Maximum closure residual = %.1e pixel.\n", ctypeS, residmax); /* Draw graph. */ cpgbbuf(); cpgeras(); xmin = (float)(crvalS + spec1[0]); xmax = (float)(crvalS + spec1[naxisj-1]); ymin = (float)(spec2[0]) - xmin; ymax = ymin; for (j = 0; j < naxisj; j++) { x[j] = (float)(j+1); y[j] = (float)(spec2[j] - (crvalS + spec1[j])); if (y[j] > ymax) ymax = y[j]; if (y[j] < ymin) ymin = y[j]; } j = (int)crpixj + 1; if (y[j] < 0.0) { tmp = ymin; ymin = ymax; ymax = tmp; } cpgask(0); cpgenv(1.0f, (float)naxisj, ymin, ymax, 0, -1); cpgsci(1); cpgbox("ABNTS", 0.0f, 0, "BNTS", 0.0f, 0); spctyp(ctypeS, 0x0, 0x0, sname, units, 0x0, 0x0, 0x0); sprintf(ylab, "%s - correction [%s]", sname, units); sprintf(title, "%s: CRVALk + w [%s]", ctypeS, units); cpglab("Pixel coordinate", ylab, title); cpgaxis("N", 0.0f, ymax, (float)naxisj, ymax, xmin, xmax, 0.0f, 0, -0.5f, 0.0f, 0.5f, -0.5f, 0.0f); cpgaxis("N", (float)naxisj, ymin, (float)naxisj, ymax, (float)(ymin/cdeltS), (float)(ymax/cdeltS), 0.0f, 0, 0.5f, 0.0f, 0.5f, 0.1f, 0.0f); cpgmtxt("R", 2.2f, 0.5f, 0.5f, "Pixel offset"); cpgline(naxisj, x, y); cpgsci(7); cpgpt1((float)crpixj, 0.0f, 24); cpgebuf(); printf("Type <RETURN> for next page: "); (void)getchar(); printf("\n"); return nFail; }
void main() //main code { printf("\nRUNGE-KUTTA METHOD\n\nR M Rho\n"); //printing titles for values displayed double c = 10.0; //the parameter rho(c) int n; //the integer steps, n //declare arrays float x[N]; float y[N]; float z[N]; //r,m,p as the radius, mass and density double r,m,p; //declare initial conditons for arrays x[0] = h; //first array is for r=h y[0] = (h*h*h/3)*c; //initial conditon for scaled mass (m) z[0] = c*(1-((h*h*c)/(6*gamma(c)))); //initial conditon for rho //for loop for n=0,1,...,200 for(n=0;n<N;n++) { //declared how x(n+1) relates to x(n), y(n+1) relates to y(n), z(n+1) relates to z(n) x[n+1] = x[n]+h; y[n+1] = y[n]+(h/6)*(M(x[n],y[n],z[n])+2*M2(x[n],y[n],z[n])+2*M3(x[n],y[n],z[n])+M4(x[n],y[n],z[n])); z[n+1] = z[n]+(h/6)*(rho(x[n],y[n],z[n])+2*rho2(x[n],y[n],z[n])+2*rho3(x[n],y[n],z[n])+rho4(x[n],y[n],z[n])); if(isnan(z[n+1])) { break; } //r,m,p will be declared in pg-plot r = x[n+1]; m = y[n+1]; p = z[n+1]; printf("%.2e %.2e %.2e\n",x[n+1],y[n+1],z[n+1]); //printed values for x and y respectively } //Use pg-plot to plot mass and density // cpgbeg starts a plotting page, in this case with 2x1 panels cpgbeg(0,"?",2,1); // sets colour: 1-black, 2-red, 3-green, 4-blue cpgsci(1); // sets line style: 1-solid, 2-dashed, 3-dot-dashed, 4-dotted cpgsls(1); // sets charachter height, larger number = bigger cpgsch(1.); // cpgpage() moves to the next panel cpgpage(); // sets the axes limits in the panel cpgswin(0,r,0,m); // draw the axes cpgbox("BCNST", 0.0, 0, "BCNST", 0.0, 0); // label the bottom axis cpgmtxt("B",2.,.5,.5,"radius"); // label the left axis cpgmtxt("L",2.5,.5,.5,"saclaed mass"); // connect N points in ax and ay with a line cpgline(n,x,y); // cpgpage() moves to the next panel cpgpage(); // sets the axes limits in the panel cpgswin(0,r,0,c); // draw the axes cpgbox("BCNST", 0.0, 0, "BCNST", 0.0, 0); // label the bottom axis cpgmtxt("B",2.,.5,.5,"radius"); // label the left axis cpgmtxt("L",2.5,.5,.5,"density"); // connect N points in ax and ay with a line cpgline(n,x,z); // close all pgplot applications cpgend(); // end program return; }
/* Plot help methods */ void plothelp(defs * d) { int k = 0; float where = -0.01; float how = 1.0; if (d->printout == 0) { /* Write the last action */ if (strlen(d->lastaction)) { cpgsci(14); cpgmtxt("B", 2.5, 0.5, 0.5, d->lastaction); cpgsci(1); strcpy(d->lastaction, ""); } // Commands sumary cpgsci(14); cpgsch(.65); k--; cpgmtxt("B", k--, where, how, "Only Sel Sp"); cpgmtxt("B", k--, where, how, "Names t"); cpgmtxt("B", k--, where, how, "Overlay +"); cpgmtxt("B", k--, where, how, "A Mark #"); cpgmtxt("B", k--, where, how, "View Sw m"); cpgmtxt("B", k--, where, how, "Searc Ev -"); cpgmtxt("B", k--, where, how, "Search :"); cpgmtxt("B", k--, where, how, "Print o"); cpgsci(15); cpgmtxt("B", k--, where, how, "General:"); cpgsci(14); k--; cpgmtxt("B", k--, where, how, "Post Sw s"); cpgmtxt("B", k--, where, how, "Pre Sw i"); cpgmtxt("B", k--, where, how, "Config ?"); cpgsci(15); cpgmtxt("B", k--, where, how, "Config:"); cpgsci(14); k--; cpgmtxt("B", k--, where, how, "Low l"); cpgmtxt("B", k--, where, how, "High h"); cpgmtxt("B", k--, where, how, "Filter On f"); cpgsci(15); cpgmtxt("B", k--, where, how, "Filter:"); cpgsci(14); k--; cpgmtxt("B", k--, where, how, "Max 1"); cpgmtxt("B", k--, where, how, "Min 2"); cpgmtxt("B", k--, where, how, "Clean 3"); cpgsci(15); cpgmtxt("B", k--, where, how, "All:"); cpgsci(14); k--; cpgmtxt("B", k--, where, how, "Max y|z"); cpgmtxt("B", k--, where, how, "Min x"); cpgmtxt("B", k--, where, how, "Clean c"); cpgsci(15); cpgmtxt("B", k--, where, how, "Current:"); cpgsci(14); k--; cpgmtxt("B", k--, where, how, "Update Pick u"); cpgmtxt("B", k--, where, how, "Correlate @"); cpgmtxt("B", k--, where, how, "Delete d"); cpgmtxt("B", k--, where, how, "Edit e"); cpgsci(15); cpgmtxt("B", k--, where, how, "Picking Keys:"); cpgsci(14); k--; cpgmtxt("B", k--, where, how, "Write w"); cpgmtxt("B", k--, where, how, "Reload r"); cpgmtxt("B", k--, where, how, "Quit Q"); cpgsci(15); cpgmtxt("B", k--, where, how, "IO:"); cpgsci(14); k--; cpgmtxt("B", k--, where, how, "Ampl. Zoom !"); cpgmtxt("B", k--, where, how, "+ Window *"); cpgmtxt("B", k--, where, how, "- Window /"); k--; cpgmtxt("B", k--, where, how, "Sort 0"); cpgmtxt("B", k--, where, how, "Align ."); cpgmtxt("B", k--, where, how, "Tr. per Sc. ,"); k--; cpgmtxt("B", k--, where, how, "Nex.Comp >"); cpgmtxt("B", k--, where, how, "Pre.Comp <"); k--; cpgmtxt("B", k--, where, how, "Event N,P"); cpgmtxt("B", k--, where, how, "Trace n,p"); cpgsci(15); cpgmtxt("B", k--, where, how, "Control:"); cpgsci(14); cpgsci(1); cpgsch(.65); } }
void nrpoint(float x[],float y[],float azy[],float ely[],float azmod[],float elmod[],float sig[],int ndata,int num_gauss,int flag,int ant_num,int plotflag,char *header) { FILE *fp1,*fp2,*fp3,*fp4,*fp5; float rms(float *,int); float arg, guessed_parameters,xmin,xmax,ymin,ymax,tmp,rms_fac; float alamda,chisq,ochisq,**covar,**alpha,*a; int i,*ia,itst,j,k,l,numplot,i_maxy,i_miny,MA, NPT; char ans[200],f_line[200],c; char file_n1[160],file_n2[160],file_n3[160],file_n4[160],file_n5[160]; char xtitle[60],ytitle[60],title[60],plotant[10]; FILE *fpsummary, *headerfp; char fullfilename[250]; char buffer[2048]; /* must be larger than length of header */ char *token[MAX_TOKENS]; int tokens; char rxlabelhigh[30]; char rxlabellow[30]; float xx[1600],yy[1600],yyy[1600],res[1600]; /* following for aperture efficiency 16 Nov 04, TK */ char etaCommand[130], rawfilename[256]; FILE *fpi_eta,*fpo_eta, *fph_eta; int use_beam, time_stamp; float tau_zenith,Tcmbr,Tatm,Thot,Tamb,Tcab,eta_l,delVsource,Vhot,Vsky,err,el,SB; float Frequency, TBright, VhotL, VhotH, VskyL, VskyH; float PlanetDia, WidthFwhm,fwhm_beam, EtaA, EtaB; char object[20], date[30]; /* aperture efficiecny additions end */ sprintf(file_n1,"/usr/PowerPC/common/data/rpoint/ant%d/load.fitted.dat",ant_num); sprintf(file_n2,"/usr/PowerPC/common/data/rpoint/ant%d/load.initial.dat",ant_num); sprintf(file_n3,"/usr/PowerPC/common/data/rpoint/ant%d/load.temp.dat",ant_num); sprintf(file_n4,"/usr/PowerPC/common/data/rpoint/ant%d/load.results.dat",ant_num); sprintf(file_n5,"/usr/PowerPC/common/data/rpoint/ant%d/rpoint.ant%1d",ant_num,ant_num); if ((fp1=fopen(file_n1,"w"))==NULL){ printf("nrpoint: cannot open n1 = %s\n",file_n1); exit(1); } chmod(file_n1,0666); if ((fp3=fopen(file_n3,"w"))==NULL){ printf("nrpoint: cannot open n2 (first time) = %s\n",file_n3); exit(1); } chmod(file_n3,0666); if ((fp4=fopen(file_n4,"a"))==NULL){ printf("nrpoint: cannot open n4 = %s\n",file_n4); exit(1); } chmod(file_n4,0666); if ((fp5=fopen(file_n5,"a"))==NULL){ printf("nrpoint: cannot open n5 = %s\n",file_n5); exit(1); } chmod(file_n5,0666); NPT=ndata;MA=num_gauss; /* printf("number of data = %d number of fitting components = %d flag = %d\n", NPT,MA/5,flag); */ ia=ivector(1,MA); a=vector(1,MA); covar=matrix(1,MA,1,MA); alpha=matrix(1,MA,1,MA); /* read data */ xmin=1e6;ymin=1e6; xmax=-1e6;ymax=-1e6; for (i=1;i<=NPT;i++) { xx[i-1]=x[i]; yy[i-1]=y[i]; if(xmin>=x[i]) xmin=x[i]; if(xmax<x[i]) xmax=x[i]; if(ymin>=y[i]){ymin=y[i];i_miny=i;} if(ymax<y[i]) {ymax=y[i];i_maxy=i;} /* if(i<10) printf("%d %f %f %f %f %f %f\n",i,x[i],y[i],ymin,ymax,azy[i],ely[i],sig[i]); */ fprintf(fp3,"%f %f\n",x[i],y[i]); } tmp=ymax-ymin; ymax=tmp*0.2+ymax; ymin=ymin-tmp*0.2; fclose(fp3); /* PGPLOT */ sprintf(plotant,"%d/xs",(ant_num+10)); if(plotflag){ if(cpgbeg(0,plotant,1,1)!=1) exit(1); cpgenv(xmin,xmax,ymin,ymax,0,0); cpgpt(NPT,xx,yy,2); cpgline(NPT,xx,yy); tokens = tokenize(header,token); strcpy(rxlabelhigh,token[RX_LABEL_HIGH]); strcpy(rxlabellow,token[RX_LABEL_LOW]); if (lowfreqflag == 0) { sprintf(title,"Antenna %1d High-frequency (%s) Raw data",ant_num,rxlabelhigh); } else { sprintf(title,"Antenna %1d Low-frequency (%s) Raw data",ant_num,rxlabellow); } if(flag){ sprintf(xtitle,"Antenna %ld Azoff (arcsec)",ant_num); } else { sprintf(xtitle,"Antenna %ld Eloff (arcsec)",ant_num); } sprintf(ytitle,"Intensity (Volts)"); cpglab(xtitle,ytitle,title); cpgend(); } /* initial values of parameters:::::: */ if ((fp2=fopen(file_n2,"w"))==NULL){ printf("nrpoint: cannot open n2 (second time) = %s\n",file_n2); exit(1); } chmod(file_n2,0666); if(fabs(ymax)>=fabs(ymin)) { fprintf(fp2,"%f\n",ymax-ymin); fprintf(fp2,"%f\n",x[i_maxy]); } if(fabs(ymin)>fabs(ymax)) { fprintf(fp2,"%f\n",ymin-ymax); fprintf(fp2,"%f\n",x[i_miny]); } fprintf(fp2,"%f\n",20.0); fprintf(fp2,"%f\n",0.0); fprintf(fp2,"%f\n",y[1]); fclose(fp2); if ((fp2=fopen(file_n2,"r"))==NULL){ printf("nrpoint: cannot open n2 for read = %s\n",file_n2); exit(1); } for(i=1;i<=MA;i++) { fscanf(fp2,"%f\n",&guessed_parameters); a[i]=guessed_parameters; ia[i]=i; } fclose(fp2); /* start fitting */ alamda = -1; mrqmin(x,y,sig,NPT,a,ia,MA,covar,alpha,&chisq,fgauss2,&alamda); k=1; itst=0; for (;;) { /* printf("\n%s %2d %17s %9.3e %10s %9.3e\n","Iteration #",k, "chi-squared:",chisq,"alamda:",alamda); for (i=1;i<=MA;i++) printf("%5.3e ",a[i]); printf("\n"); */ k++; ochisq=chisq; mrqmin(x,y,sig,NPT,a,ia,MA,covar,alpha,&chisq,fgauss2,&alamda); if (chisq > ochisq) itst=0; else if ((fabs(ochisq-chisq) < 0.01 && fabs(chisq) < .1) || (k>10)) {itst++;} if (itst < 4) continue; /* if ((fp2=fopen(file_n2,"w"))==NULL){ printf("cannot open %s\n",file_n2); exit(1); } */ /* for (i=1;i<=MA;i++) fprintf(fp2,"%f\n",a[i]); */ for (i=1;i<=MA;i++) fprintf(fp4,"%f ",a[i]); fprintf(fp4,"%f ",chisq); printf("%f\n ",chisq); /* fprintf(fp2,"\n"); */ fprintf(fp4,"\n\n"); /* fclose(fp2); */ for(j=1;j<=NPT;j++){ yyy[j-1]=0.0; for(k=1;k<=MA;k+=5){ arg=(x[j]-a[k+1])/a[k+2]; yyy[j-1]+=a[k]*exp(-arg*arg)+a[k+3]*x[j]+a[k+4]; } res[j-1]=y[j]-yyy[j-1]+a[5]; fprintf (fp1,"%.6f %.6f %.6f %.6f\n",x[j],y[j],yyy[j-1],res[j-1]); } fclose(fp1); alamda=0.0; mrqmin(x,y,sig,NPT,a,ia,MA,covar,alpha,&chisq,fgauss2,&alamda); rms_fac=rms(res,NPT); printf("\nUncertainties:\n"); for (i=1;i<=MA;i++) printf("%8.4e ",rms_fac*sqrt(covar[i][i])); printf("\n"); fprintf(fp4,"\nUncertainties:\n"); for (i=1;i<=MA;i++) fprintf(fp4,"%8.4e ",rms_fac*sqrt(covar[i][i])); fprintf(fp4,"\n"); printf("Generating plot....\n"); break; } fclose(fp4); if(flag){ if (lowfreqflag == 0) { sprintf(title,"Antenna %1d High-frequency (%s) AZ scan Fitted data",ant_num,rxlabelhigh); } else { sprintf(title,"Antenna %1d Low-frequency (%s) AZ scan Fitted data",ant_num,rxlabellow); } sprintf(xtitle,"Antenna %ld Azoff (arcsec)",ant_num); } else{ if (lowfreqflag == 0) { sprintf(title,"Antenna %1d High-frequency (%s) El scan Fitted data",ant_num,rxlabelhigh); } else { sprintf(title,"Antenna %1d Low-frequency (%s) El scan Fitted data",ant_num,rxlabellow); } sprintf(xtitle,"Antenna %ld Eloff (arcsec)",ant_num); } sprintf(ytitle,"Intensity (Volts)"); /* PGPLOT */ sprintf(plotant,"%d/xs",(ant_num+10)); if(plotflag){ if(cpgbeg(0,plotant,1,1)!=1) exit(1); /* These do nothing helpful: cpgeras(); cpgupdt(); */ cpgenv(xmin,xmax,ymin,ymax,0,0); cpgpt(NPT,xx,yy,2); cpgline(NPT,xx,yyy); cpgpt(NPT,xx,res,-1); cpglab(xtitle,ytitle,title); sprintf(f_line,"az= %10.4f deg",azy[i_maxy]); cpgmtxt("t",-2.5,0.05,0,f_line); sprintf(f_line,"el = %10.4f deg",ely[i_maxy]); cpgmtxt("t",-4.0,0.05,0,f_line); sprintf(f_line,"y= %10.4f",a[1]); cpgmtxt("t",-7.0,0.05,0,f_line); sprintf(f_line,"x = %10.4f arcsec",a[2]); cpgmtxt("t",-5.5,0.05,0,f_line); sprintf(f_line,"width = %10.4f",a[3]*2*0.83255); cpgmtxt("t",-8.5,0.05,0,f_line); sprintf(f_line,"chisq = %10.4e",chisq); cpgmtxt("t",-10.0,0.05,0,f_line); cpgend(); } fpsummary = fopen(summary_file_name,"r"); if (fpsummary == NULL) { fpsummary = fopen(summary_file_name,"w"); } else { fclose(fpsummary); fpsummary = fopen(summary_file_name,"a"); } if (fpsummary == NULL) { printf("Could not write to summary file = %s\n",summary_file_name); } else { #if USE_HEADER sprintf(fullfilename,"/data/engineering/rpoint/ant%d/header.dat",ant_num); headerfp = fopen(fullfilename,"r"); /* skip the first line */ fgets(buffer,sizeof(buffer),headerfp); fgets(buffer,sizeof(buffer),headerfp); fclose(headerfp); /* cut off the final carriage return */ buffer[strlen(buffer)-1] = 0; fprintf(fpsummary,"%s,",buffer); #endif if (flag == 1) { fprintf(fpsummary,"rpoint: azoff %f %f %f %f ",a[1],a[2], a[3]*2*0.83255, rms_fac*sqrt(covar[2][2])); } else { fprintf(fpsummary,"rpoint: eloff %f %f %f %f ",a[1],a[2], a[3]*2*0.83255, rms_fac*sqrt(covar[2][2])); } /* Following lines added 16 Nov 04, for aperture efficiecncy: TK */ /* create a temporary file eta_tmp and run the aperture efficiency program */ /* needed: /* 4: source - object 14: planetdia 29: temperature 37: cabin temperature 40: elcmd 91: rest freq 92: sidebandA a[1]=intensity a[2]=offset a[3]*2*0.83255=scanwidth */ printf("Computing aperture efficiency....\n"); fpi_eta=fopen("aperInput.tmp","w"); use_beam=USE_BEAM; delVsource=a[1]; WidthFwhm=a[3]*2*0.83255; sprintf(etaCommand, "nawk -F, \' (NR>=2) {print $4,$14,$29,$37,$40,$91,$92,$107}\' /data/engineering/rpoint/ant%d/header.dat > picked.tmp",ant_num); /* printf("%s\n", etaCommand); */ system(etaCommand); fph_eta=fopen("picked.tmp","r"); fscanf(fph_eta,"%s %f %f %f %f %f %f",object,&PlanetDia,&Tamb,&Tcab,&el,&Frequency,&SB); fscanf(fph_eta, "%s %f %d %f %d %f %d %f %d %f %d %f %d %f %d %f %f", rawfilename, &VhotL, &time_stamp, &VhotH, &time_stamp, &VskyL, &time_stamp, &VskyH, &time_stamp, &tau_zenith, &time_stamp, &Tatm , &time_stamp, &eta_l, &time_stamp, &Frequency, &SB); if (lowfreqflag == 0) { Vhot=VhotL; Vsky=VskyL; } else { Vhot=VhotH; Vsky=VskyH; } /* fscanf(fph_eta, "%s %f %f %f %f %f %f %f %f", rawfilename, &Thot, &tau_zenith, &eta_l, &Vhot, &Vsky, &delVsource, &WidthFwhm); */ printf("raw file name: %s\n", rawfilename); Tamb = (Tamb+Tcab)/2.0; Thot=Tamb; /* Frequency=Frequency-SB*5.0; */ /* Thot= Vhot= Vsky= delVsource= fwhm_beam=52.0; WidthFwhm= Tbright=100; TBright= */ if (object=="jupiter") TBright=TB_JUP; if (object=="saturn") TBright=TB_SAT; if (strstr(object,"jupiter")!=NULL) TBright=TB_JUP; if (strstr(object,"saturn")!=NULL) TBright=TB_SAT; err=0.0; fprintf(fpi_eta, "%s %d %s %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %d\n", rawfilename, ant_num, object, el, tau_zenith, Thot,Tamb,Tatm,eta_l,Vhot,Vsky,delVsource,fwhm_beam,Frequency, PlanetDia, WidthFwhm,TBright,err,use_beam); sprintf(etaCommand, "aperEff aperInput.tmp"); system(etaCommand); fpo_eta=fopen("aperResults.tmp","w"); /* fscanf(fpo_eta, "%f %f %f", &EtaA,&EtaB,&fwhm_beam); */ fprintf(fpo_eta,"%3.2f %3.2f %4.1f\n",EtaA,EtaB,fwhm_beam); fprintf(fpsummary,"%3.2f %3.2f %4.1f\n",EtaA,EtaB,fwhm_beam); fclose(fpsummary); fclose(fpi_eta); fclose(fpo_eta); fclose(fph_eta); /* remove("aperResults.tmp"); remove("aperInput.tmp"); */ } printf("recorded! \n"); printf("azfit %s | %10.5f %10.5f %10.5f %10.4f %10.2f +- %10.2f %8.1f %8.1f\n",header,azy[i_maxy],ely[i_maxy],a[1],a[3]*2*0.83255,a[2],rms_fac*sqrt(covar[2][2]),azmod[i_maxy],elmod[i_maxy]); if(flag==1) fprintf(fp5,"azfit %s | %10.5f %10.5f %10.5f %10.4f %10.2f +- %10.2f %8.1f %8.1f\n",header,azy[i_maxy],ely[i_maxy],a[1],a[3]*2*0.83255,a[2],rms_fac*sqrt(covar[2][2]),azmod[i_maxy],elmod[i_maxy]); else fprintf(fp5,"elfit %s | %10.5f %10.5f %10.5f %10.4f %10.2f +- %10.2f %8.1f %8.1f \n",header,azy[i_maxy],ely[i_maxy],a[1],a[3]*2*0.83255,a[2],rms_fac*sqrt(covar[2][2]),azmod[i_maxy],elmod[i_maxy]); fclose(fp5); free_matrix(alpha,1,MA,1,MA); free_matrix(covar,1,MA,1,MA); free_ivector(ia,1,MA); free_vector(a,1,MA); }
/* write text at position relative to viewport */ static void _pgmtxt (char *s, double *f, double *g, double *h, char *t) { cpgmtxt (s, (float)*f, (float)*g, (float)*h, t); }
// Process dedispersion output void* process_output(void* output_params) { OUTPUT_PARAMS* params = (OUTPUT_PARAMS *) output_params; OBSERVATION *obs = params -> obs; int i, iters = 0, ret, loop_counter = 0, pnsamp = params -> obs -> nsamp; int ppnsamp = params -> obs-> nsamp; time_t start = params -> start, beg_read; double pptimestamp = 0, ptimestamp = 0; double ppblockRate = 0, pblockRate = 0; // Initialise pg plotter #if PLOT if(cpgbeg(0, "/xwin", 1, 1) != 1) printf("Couldn't initialise PGPLOT\n"); cpgask(false); #endif printf("%d: Started output thread\n", (int) (time(NULL) - start)); FILE *fp = fopen("chanOutput.dat", "wb"); // Processing loop while (1) { // Wait input barrier ret = pthread_barrier_wait(params -> input_barrier); if (!(ret == 0 || ret == PTHREAD_BARRIER_SERIAL_THREAD)) { fprintf(stderr, "Error during input barrier synchronisation [output]\n"); exit(0); } // Process output if (loop_counter >= params -> iterations) { unsigned nsamp = ppnsamp, nchans = obs -> nchans; double timestamp = pptimestamp, blockRate = ppblockRate; beg_read = time(NULL); #if PLOT if (!obs -> folding) { // Process and plot output unsigned startChan = 0, endChan = startChan + 32, decFactor = 512; // unsigned startChan = 0, endChan = startChan + 32, decFactor = 4; float xr[nsamp / decFactor], yr[endChan - startChan][nsamp / decFactor]; float ymin = 9e12, ymax=9e-12; for (unsigned c = 0; c < endChan - startChan; c++) { // Decimate before plotting for (unsigned i = 0; i < nsamp / decFactor; i++) { unsigned index = (startChan + c) * nsamp + i * decFactor; xr[i] = i; yr[c][i] = 0; for (unsigned j = 0; j < decFactor; j++) yr[c][i] += params -> host_odata[index+j].x * params -> host_odata[index+j].x + params -> host_odata[index+j].y * params -> host_odata[index+j].y; // yr[c][i] = (yr[c][i] / decFactor) + c * 1e5; yr[c][i] = (yr[c][i] / decFactor) + c * 4; if (ymax < yr[c][i]) ymax = yr[c][i]; if (ymin > yr[c][i]) ymin = yr[c][i]; } } unsigned plotChan = 1; float *chan = (float *) malloc(nsamp * sizeof(float)); for (unsigned i = 0; i < nsamp; i++) chan[i] = params -> host_odata[plotChan * nsamp + i].x * params -> host_odata[plotChan * nsamp + i].x + params -> host_odata[plotChan * nsamp + i].y * params -> host_odata[plotChan * nsamp + i].y; fwrite(chan, sizeof(float), nsamp, fp); fflush(fp); free(chan); cpgenv(0.0, pnsamp / decFactor, ymin, ymax, 0, 1); cpgsci(7); for (unsigned i = 0; i < endChan - startChan; i++) cpgline(nsamp / decFactor, xr, yr[i]); cpgmtxt("T", 2.0, 0.0, 0.0, "Dedispersed Channel Plot"); } else { unsigned plotChannel = 15; unsigned decFactor = 256; float *xr = (float *) malloc(obs -> profile_bins / decFactor * sizeof(float)); float *yr = (float *) malloc(obs -> profile_bins / decFactor * sizeof(float)); float ymin = 9e12, ymax = 9e-12; unsigned fullProfiles = obs -> nsamp * (loop_counter - 1) / obs -> profile_bins; unsigned leftover = (obs -> nsamp * (loop_counter - 1)) % obs -> profile_bins; if (fullProfiles > 0) { // Decimate before plotting for (unsigned i = 0; i < obs -> profile_bins / decFactor; i++) { unsigned index = plotChannel * obs -> profile_bins + i * decFactor; xr[i] = i; yr[i] = 0; for (unsigned j = 0; j < decFactor; j++) yr[i] += params -> host_profile[index + j]; yr[i] = (yr[i] / decFactor); yr[i] = (i < leftover / decFactor) ? yr[i] / (fullProfiles + 1) : yr[i] / fullProfiles; if (ymax < yr[i]) ymax = yr[i]; if (ymin > yr[i]) ymin = yr[i]; } cpgenv(0.0, obs -> profile_bins / decFactor, ymin, ymax, 0, 1); cpgsci(7); cpgline(obs -> profile_bins / decFactor, xr, yr); cpgmtxt("T", 2.0, 0.0, 0.0, "Pulsar Profile"); free(xr); free(yr); } } #endif printf("%d: Processed output %d [output]: %d\n", (int) (time(NULL) - start), loop_counter, (int) (time(NULL) - beg_read)); } sleep(2); // Wait output barrier ret = pthread_barrier_wait(params -> output_barrier); if (!(ret == 0 || ret == PTHREAD_BARRIER_SERIAL_THREAD)) { fprintf(stderr, "Error during output barrier synchronisation [output]\n"); exit(0); } // Acquire rw lock if (pthread_rwlock_rdlock(params -> rw_lock)) { fprintf(stderr, "Unable to acquire rw_lock [output]\n"); exit(0); } // Update params ppnsamp = pnsamp; pnsamp = params -> obs -> nsamp; pptimestamp = ptimestamp; ptimestamp = params -> obs -> timestamp; ppblockRate = pblockRate; pblockRate = params -> obs -> blockRate; // Stopping clause if (((OUTPUT_PARAMS *) output_params) -> stop) { if (iters >= params -> iterations - 1) { // Release rw_lock if (pthread_rwlock_unlock(params -> rw_lock)) { fprintf(stderr, "Error releasing rw_lock [output]\n"); exit(0); } for(i = 0; i < params -> maxiters - params -> iterations; i++) { pthread_barrier_wait(params -> input_barrier); pthread_barrier_wait(params -> output_barrier); } break; } else iters++; } // Release rw_lock if (pthread_rwlock_unlock(params -> rw_lock)) { fprintf(stderr, "Error releasing rw_lock [output]\n"); exit(0); } loop_counter++; } printf("%d: Exited gracefully [output]\n", (int) (time(NULL) - start)); pthread_exit((void*) output_params); }
int main (int argc,char **argv) { int argPos, argNum = argc; char charBuffer [RGPBufferSIZE], panelTitle [RGPBufferSIZE], *outFile = (char *) "rgisplot"; int panelRow, panelCol, panelRowNum,panelColNum, defaultLW; DBInt dataNum, entryNum = 0; DBInt ret, mode = 0, device = 0, format = 0, layout = 0; float x0, y0, x1, y1, pWidth = -1.0, pHeight = -1.0; DBObjData *dbData; for (argPos = 1;argPos < argNum; ) { if (CMargTest (argv [argPos],"-m","--mode")) { const char *modes [] = { "interactive", "batch", (char *) NULL }; if ((argNum = CMargShiftLeft (argPos,argv,argNum)) <= argPos) { CMmsgPrint (CMmsgUsrError,"Missing mode!"); return (CMfailed); } if ((mode = CMoptLookup (modes,argv [argPos],true)) == DBFault) { CMmsgPrint (CMmsgUsrError,"Invalid mode %s",argv [argPos]); goto Usage; } if ((argNum = CMargShiftLeft (argPos,argv,argNum)) <= argPos) break; continue; } if (CMargTest (argv [argPos],"-d","--device")) { const char *devices [] = { "screen", "file", (char *) NULL }; if ((argNum = CMargShiftLeft (argPos,argv,argNum)) <= argPos) { CMmsgPrint (CMmsgUsrError,"Missing device!"); return (CMfailed); } if ((device = CMoptLookup (devices,argv [argPos],true)) == DBFault) { CMmsgPrint (CMmsgUsrError,"Invalid device %s",argv [argPos]); goto Usage; } if ((argNum = CMargShiftLeft (argPos,argv,argNum)) <= argPos) break; continue; } if (CMargTest (argv [argPos],"-p","--psize")) { if ((argNum = CMargShiftLeft (argPos,argv,argNum)) <= argPos) { CMmsgPrint (CMmsgUsrError,"Missing psize!"); return (CMfailed); } if ((argv [argPos] == (char *) NULL) || (sscanf (argv [argPos],"%f,%f",&pWidth,&pHeight) != 2)) { CMmsgPrint (CMmsgUsrError,"Invalid page size %s",argv [argPos]); goto Usage; } if ((argNum = CMargShiftLeft (argPos,argv,argNum)) <= argPos) break; continue; } if (CMargTest (argv [argPos],"-f","--format")) { const char *formats [] = { "eps", "gif", "ppm", (char *) NULL }; if ((argNum = CMargShiftLeft (argPos,argv,argNum)) <= argPos) { CMmsgPrint (CMmsgUsrError,"Missing format!"); return (CMfailed); } if ((format = CMoptLookup (formats,argv [argPos],true)) == DBFault) { CMmsgPrint (CMmsgUsrError,"Invalid format %s",argv [argPos]); goto Usage; } if ((argNum = CMargShiftLeft (argPos,argv,argNum)) <= argPos) break; continue; } if (CMargTest (argv [argPos],"-l","--layout")) { const char *layouts [] = { "portrait","landscape", (char *) NULL }; if ((argNum = CMargShiftLeft (argPos,argv,argNum)) <= argPos) { CMmsgPrint (CMmsgUsrError,"Missing layout!"); return (CMfailed); } if ((layout = CMoptLookup (layouts,argv [argPos],true)) == DBFault) { CMmsgPrint (CMmsgUsrError,"Invalid layout %s",argv [argPos]); goto Usage; } if ((argNum = CMargShiftLeft (argPos,argv,argNum)) <= argPos) break; continue; } if (CMargTest (argv [argPos],"-o","--output")) { if ((argNum = CMargShiftLeft (argPos,argv,argNum)) <= argPos) { CMmsgPrint (CMmsgUsrError,"Missing output!"); return (CMfailed); } if (argv [argPos] == (char *) NULL) { CMmsgPrint (CMmsgUsrError,"Invalid output file"); goto Usage; } outFile = argv [argPos]; if ((argNum = CMargShiftLeft (argPos,argv,argNum)) <= argPos) break; continue; } if (CMargTest (argv [argPos],"-h","--help")) { Usage: CMmsgPrint (CMmsgUsrError,"Usage: rgisPlot [-m <>] [-d <>] [-f <>] [-l <>] [-o <>] -h"); CMmsgPrint (CMmsgUsrError," -m, --mode <interactive | batch>"); CMmsgPrint (CMmsgUsrError," -d, --device <screen | file>"); CMmsgPrint (CMmsgUsrError," -p, --psize width,height"); CMmsgPrint (CMmsgUsrError," -f, --format <eps | gif>"); CMmsgPrint (CMmsgUsrError," -l, --layout <landscape | portrait>"); CMmsgPrint (CMmsgUsrError," -o, --output <filename>"); argNum = CMargShiftLeft (argPos,argv,argNum); return (DBSuccess); } if ((argv [argPos][0] == '-') && (strlen (argv [argPos]) > 1)) { CMmsgPrint (CMmsgUsrError,"Unknown option: %s!",argv [argPos]); return (CMfailed); } argPos++; } switch (device) { case 0: cpgopen ("/XWINDOW"); break; case 1: { char *formatStrings [] = { (char *) "CPS", (char *) "GIF", (char *) "PPM" }; sprintf (charBuffer,layout == 0 ? "%s/V%s" : "%s/%s", outFile, formatStrings [format]); cpgopen (charBuffer); } break; default: return (CMfailed); } cpgscrn (0,"WHITE",&ret); if ((pWidth > 0.0) && (pHeight > 0.0)) cpgpap (pWidth, pHeight / pWidth); do { RGPPrintMessage (mode,&entryNum,"Panel Layout [horizontal,vertical]:"); while (fgets (charBuffer,sizeof (charBuffer) - 1,stdin) == (char *) NULL); if (sscanf (charBuffer,"%d,%d",&panelColNum,&panelRowNum) == 2) break; else if (RGPPrintError (mode,entryNum,"Panel layout input error")) goto Stop; } while (true); RGPInitPenColors (); cpgsubp (panelColNum,panelRowNum); cpgqlw (&defaultLW); ret = DBSuccess; for (panelRow = 0;panelRow < panelRowNum;++panelRow) for (panelCol = 0;panelCol < panelColNum; ++panelCol) { cpgpanl (panelCol + 1,panelRow + 1); cpgsch (1.8); cpgvstd (); do { sprintf (charBuffer,"Panel Title [%d,%d]:",panelRow,panelCol); RGPPrintMessage (mode,&entryNum,charBuffer); if (fgets (panelTitle,sizeof (panelTitle) - 1,stdin) != (char *) NULL) { if (panelTitle [strlen (panelTitle) - 1] == '\n') panelTitle [strlen (panelTitle) - 1] = '\0'; if (strlen (panelTitle) > 0) break; } RGPPrintError (mode,entryNum,"Panel Title input error"); goto Stop; } while (true); dataNum = 0; do { RGPPrintMessage (mode,&entryNum,"Mapextent [X0,Y0,X1,Y1]:"); if (fgets (charBuffer,sizeof (charBuffer) - 1,stdin) == (char *) NULL) continue; if (sscanf (charBuffer,"%f,%f,%f,%f",&x0,&y0,&x1,&y1) == 4) break; else if (RGPPrintError (mode,entryNum,"Mapextent input error")) goto Stop; } while (true); cpgwnad (x0,x1,y0,y1); do { sprintf (charBuffer,"RiverGIS data file [%d]:",++dataNum); RGPPrintMessage (mode,&entryNum, charBuffer); if ((fgets (charBuffer,sizeof (charBuffer) - 1,stdin) != (char *) NULL) && (strlen (charBuffer) > 0) && charBuffer [0] != '\n') { if (charBuffer [strlen (charBuffer) - 1] == '\n') charBuffer [strlen (charBuffer) - 1] = '\0'; dbData = new DBObjData (); if (dbData->Read (charBuffer) != DBSuccess) { dataNum--; continue; } switch (dbData->Type ()) { case DBTypeVectorPoint: if ((ret = RGPDrawVecPoint (mode, &entryNum, dbData)) == DBFault) goto Stop; break; case DBTypeVectorLine: if ((ret = RGPDrawVecLine (mode, &entryNum, dbData)) == DBFault) goto Stop; break; case DBTypeVectorPolygon: break; case DBTypeGridContinuous: if ((ret = RGPDrawGridContinuous (mode,&entryNum,dbData)) == DBFault) goto Stop; break; case DBTypeGridDiscrete: break; case DBTypeNetwork: if ((ret = RGPDrawNetwork (mode, &entryNum, dbData)) == DBFault) goto Stop; break; default: CMmsgPrint (CMmsgUsrError,"Invalid data type"); dataNum--; break; } delete dbData; } else break; } while (true); cpgbox ("BCMTS",0.0,0,"BCNMTS",0.0,0); cpgslw (2); cpgsch (2.5); cpgmtxt ("T",1.5,0.5,0.5,panelTitle); cpgslw (defaultLW); } Stop: cpgend (); return (ret); }
void multitraceplot(defs * d) { int j, k; float start; char string[1024]; char stringaux[1024]; g_ctl **ctl = d->ctl; int color = 1; char aligChar; float x1, x2; int lastFile; pdefs *pick = d->pickRules[(int)getConfigAsNumber(config, NAME_PICK, DEFAULT_PICK)]; ctl_clean(NULL); ctl_resizeview(ctl[0]); plothelp(d); // If no traces found give warning and return if (d->nfiles <= 0) { sprintf(string, "No folders matching pattern found. Use ? to change folder pattern configuration !"); cpgmtxt("B", 0.5, 0.5, 0.5, string); return; } lastFile = ((d->offset + d->max) >= d->nfiles) ? (d->nfiles - 1) : (d->offset + d->max); // Those are used for min and max of the ALIGO mode if (d->files[d->offset].current) { x1 = pickR(pick, d->files[d->offset].current->head) + d->files[d->offset].current->reference - 2.5; x2 = pickR(pick, d->files[lastFile].current->head) + d->files[lastFile].current->reference + d->postphase; } else { x1 = 0.0; x2 = 10.0; } for (j = 0; j < d->max && (j + d->offset) < d->nfiles; j++) { /* *********************************************************** */ /* Prepare the file to plot */ /* *********************************************************** */ tf *thistrace = &d->files[j + d->offset]; if (thistrace->current == NULL) { continue; } if (d->onlyselected && !thistrace->selected) continue; if (d->filter && d->needfilter) { filtertf(thistrace, d); } float Fmark = pickD(pick, thistrace->current->head); float Amark = pickR(pick, thistrace->current->head); /* *********************************************************** */ /* Switch Aligment mode */ /* *********************************************************** */ (j == 0) ? ctl_axisbottom(ctl[j]) : ctl_axisnone(ctl[j]); switch (d->alig) { case (ALIGO): aligChar = 'O'; if (d->files[0].current->head->o != SAC_HEADER_FLOAT_UNDEFINED) { start = thistrace->current->reference - d->files[0].current->head->o; ctl_xreset_mm(ctl[j], x1 - d->files[d->offset].current->head->o, x2 - d->files[d->offset].current->head->o); } else { start = thistrace->current->reference; ctl_xreset_mm(ctl[j], x1, x2); aligChar = '!'; SACTIME *time = getTimeStructFromSAC(d->files[0].current->head); char *stime = print_time(time, TIME_ISO); sprintf(d->lastaction, "Reference is: %s", stime); stime = io_freeData(stime); time = io_freeData(time); } break; case (ALIGF): aligChar = 'F'; ctl_xreset_mm(ctl[j], -d->prephase, +d->postphase); if (Fmark != SAC_HEADER_FLOAT_UNDEFINED) { start = thistrace->current->head->b - Fmark; } else { start = thistrace->current->head->b; } break; case (ALIGA): aligChar = 'A'; ctl_xreset_mm(ctl[j], -d->prephase, +d->postphase); if (Amark != SAC_HEADER_FLOAT_UNDEFINED) { start = thistrace->current->head->b - Amark; } else { start = thistrace->current->head->b; } break; } /* *********************************************************** */ /* Plot the trace (DATA) */ /* *********************************************************** */ // Selected color color = 14; // Default trace color if (thistrace->selected == 1) color = 2; // If event Selected Color = Red // if (thistrace->current->head->d>unused25 != 1) color = 14; // If we are in the restricted mode and trace is locked Color = Gray if (d->overlay) color = j + 1; // Finally Plot plot(ctl[j], (d->filter && thistrace->current->dataf != NULL) ? thistrace->current->dataf : thistrace->current->data, thistrace->current->head->npts, thistrace->current->head->delta, start, 0, color, d->zoom); /* *********************************************************** */ /* *********************************************************** */ /* Plot MARKS & Names */ /* *********************************************************** */ for(k=0;k<pick->nPhase;k++) { if (strcmp(pick->referencePhase, pick->markPhase[k]) == 0 && d->hidephase) continue; float value = pickO(pick, thistrace->current->head, k); if (value != SAC_HEADER_FLOAT_UNDEFINED) { char *label = pickL(pick, thistrace->current->head, k); mark(ctl[j], value + start - thistrace->current->head->b, label, 2); if (label != NULL) free(label); label = NULL; } } // IF OVERLAY MODE JUST PLOT THE TRACE AND RETURN. if (d->overlay == 1) continue; // Mark the Window we perform the Min/Max Search in the trace if (d->plotsearchsize) { mark(ctl[j], Amark + start - thistrace->current->head->b + d->searchsize, "", 3); mark(ctl[j], Amark + start - thistrace->current->head->b - d->insetsearchsize, "", 3); } sprintf(string, "B: %.0f D: %.2f", thistrace->current->head->baz, thistrace->current->head->gcarc); if (d->putname >= 3) cpgmtxt("B", -2.00, 0.0, 0.0, string); else cpgmtxt("B", -0.70, 0.0, 0.0, string); // Add the name of the trace if (d->putname > 0) { float pos = 1.2; cpgsci(2); cpgmtxt("R", pos, .5, .5, thistrace->net); pos += 1.0; if (d->max <= 20) { cpgmtxt("R", pos, .5, .5, thistrace->station); pos += 1.0; } if (d->putname >= 2) { char *cmp; hdu_getValueFromChar("KCMPNM",thistrace->current->head,NULL,NULL, &cmp); cpgmtxt("R", pos, .5, .5, cmp); cmp = io_freeData(cmp); pos += 1.0; } if (d->putname >= 3) { sprintf(string, "%02d] %s", d->offset + j, thistrace->current->filename); cpgmtxt("B", -0.70, 0.0, 0.0, string); } cpgsci(1); } } // End of trace for loop // basic information on the foot ctl_resizeview(ctl[0]); // components information // green (should load and loaded) // gray (should not load) // red (should load but not loaded) // the < mark the current displayed component strcpy(stringaux,""); if (d->nfiles > 0) { cpgsci((d->files[0].z != NULL)?3:2); cpgsch(1.); cpgmtxt("B",1.25, -0.05, 1.0, (d->zne == 0)?"Z":"Z"); cpgsci((d->has3 && d->files[0].n != NULL)?3:(d->has3)?2:14); cpgmtxt("B",1.25, -0.04, 1.0, (d->zne == 1)?"N":"N"); cpgsci((d->has3 && d->files[0].e != NULL)?3:(d->has3)?2:14); cpgmtxt("B",1.25, -0.03, 1.0, (d->zne == 2)?"E":"E"); cpgsci((d->has3 && d->files[0].r != NULL)?3:(d->has3)?2:14); cpgmtxt("B",1.25, -0.02, 1.0, (d->zne == 3)?"R":"R"); cpgsci((d->has3 && d->files[0].t != NULL)?3:(d->has3)?2:14); cpgmtxt("B",1.25, -0.01, 1.0, (d->zne == 4)?"T":"T"); cpgsci(1); cpgsch(.65); int phaseid = (int)getConfigAsNumber(config, NAME_PICK, DEFAULT_PICK); cpgsci((phaseid == 1)?1:14); cpgmtxt("B", 1.25, -0.065, 1.0, PickTypesNames[1]); cpgsci((phaseid == 2)?1:14); cpgmtxt("B", 2.35, -0.065, 1.0, PickTypesNames[2]); cpgsch(1.); cpgsci(1); cpgmtxt("B", 2.0, -0.05 + d->zne * 0.01, 1.75, "\\m17"); // Reset to leave cpgsch(0.65); } sprintf(string, "[%03d-%03d/%03d] [Filter %s (%.2f to %.2f hz)]", d->offset + 1, d->offset + d->max, d->nfiles, (d->filter) ? "ON" : "OFF", d->hp, d->lp); cpgmtxt("B", 2.5, 0.0, 0.0, string); sprintf(string, "[%c] [PSw: %.1f ISw: %.1f Tr/S: %d] [%s]", aligChar, d->searchsize, d->insetsearchsize, d->max, (d->sortmode == 0) ? "DZ" : "BAZ"); cpgmtxt("B", 2.5, 1.0, 1.0, string); ctl_resizeview(ctl[d->max - 1]); sprintf(string, "%11s", (d->currentdir - 1 >= 0) ? d->glb->gl_pathv[d->currentdir - 1] : "First Directory"); cpgmtxt("T", 1.0, 0.35, 1.0, string); sprintf(string, "%11s", (d->currentdir + 1 < d->glb->gl_pathc) ? d->glb->gl_pathv[d->currentdir + 1] : "Last Directory"); cpgmtxt("T", 1.0, 0.65, 0.0, string); sprintf(string, "%11s", d->glb->gl_pathv[d->currentdir]); if (d->needsave == 1) { cpgsci(2); } else if (d->has == 1) { cpgsci(3); } else { cpgsci(7); } cpgmtxt("T", 1.0, 0.5, 0.5, string); //plot if the traces are correlated(green) or not (red) sprintf(string, "Correlated"); if (d->files->current->head->unused26 == 1){ cpgsci(3); } else{ cpgsci(2); } cpgmtxt("T", 1.0, 0.1, 0.5, string); cpgsci(1); sprintf(string, "Mag = %.1f", d->files->current->head->mag); cpgmtxt("T", 1.0, 0.9, 0.5, string); }
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); }
void oppositionPlot(void) { int i; double rasun, decsun, distsun, toporasun, topodecsun, x, y, z; double jd, lstm, trueam, alt, ha, phi, longEcliptic, latEcliptic; double objra, objdec; openPlot("opposition"); cpgpap(PLOTSIZE/0.5,0.5); cpgbbuf(); cpgsubp(2,2); cpgpanl(1,1); cpgswin(PHIMIN, PHIMAX, AMMIN, AMMAX); cpgbox("BCNTS",0.0,0,"BVCNTS",0.0,0); cpgmtxt("L",2.0,0.5,0.5,"airmass"); cpgmtxt("B",2.0,0.5,0.5,"angle from Sun"); cpgsci(2); for(i=0; i<numobs; i++) { jd = obs[i].date + 2400000.5; lstm = lst(jd,longitude_hrs); // get ecliptic coordinates slaEqecl(obs[i].ra, obs[i].dec, obs[i].date, &longEcliptic, &latEcliptic); if(fabs(latEcliptic) < 10.0/DEG_IN_RADIAN && obs[i].twilight==0) { // get position of Sun accusun(jd, lstm, latitude_deg, &rasun, &decsun, &distsun, &toporasun, &topodecsun, &x, &y, &z); // sun-object angle in degrees // takes ra in hours, dec in degrees objra = adj_time(obs[i].ra*HRS_IN_RADIAN); objdec = obs[i].dec*DEG_IN_RADIAN; phi = mysubtend(rasun, decsun, objra, objdec)*DEG_IN_RADIAN; // angle from opposition is 180-phi // FIXRANGE(phi,-180.0,180.0); //airmass takes ra, dec, in radians, returns true airmass airmass(obs[i].date, obs[i].ra, obs[i].dec, &trueam, &alt, &ha); cpgpt1(phi, trueam, -1); } } cpgsci(1); cpgptxt(0.0,3.0,0.0,0.5,"|ecliptic latitude|<10"); cpgptxt(0.0,2.5,0.0,0.5,"night"); cpgsci(3); cpgmove(-90.0,0.0); cpgdraw(-90.0,4.0); cpgmove( 90.0,0.0); cpgdraw( 90.0,4.0); cpgsci(1); cpgpanl(1,2); cpgswin(PHIMIN, PHIMAX, AMMIN, AMMAX); cpgbox("BCNTS",0.0,0,"BVCNTS",0.0,0); cpgmtxt("L",2.0,0.5,0.5,"airmass"); cpgmtxt("B",2.0,0.5,0.5,"angle from Sun"); cpgsci(2); for(i=0; i<numobs; i++) { jd = obs[i].date + 2400000.5; lstm = lst(jd,longitude_hrs); // get ecliptic coordinates slaEqecl(obs[i].ra, obs[i].dec, obs[i].date, &longEcliptic, &latEcliptic); if(fabs(latEcliptic) >= 10.0/DEG_IN_RADIAN && obs[i].twilight==0 ) { // get position of Sun accusun(jd, lstm, latitude_deg, &rasun, &decsun, &distsun, &toporasun, &topodecsun, &x, &y, &z); // sun-object angle in degrees phi = mysubtend(rasun, decsun, obs[i].ra*HRS_IN_RADIAN, obs[i].dec*DEG_IN_RADIAN)*DEG_IN_RADIAN; // angle from opposition is 180-phi FIXRANGE(phi,-180.0,180.0); airmass(obs[i].date, obs[i].ra, obs[i].dec, &trueam, &alt, &ha); cpgpt1(phi, trueam, -1); } } cpgsci(1); cpgptxt(0.0,3.0,0.0,0.5,"|ecliptic latitude|>10"); cpgptxt(0.0,2.5,0.0,0.5,"night"); cpgsci(3); cpgmove(-90.0,0.0); cpgdraw(-90.0,4.0); cpgmove( 90.0,0.0); cpgdraw( 90.0,4.0); cpgsci(1); cpgpanl(2,1); cpgswin(PHIMIN, PHIMAX, AMMIN, AMMAX); cpgbox("BCNTS",0.0,0,"BVCNTS",0.0,0); cpgmtxt("L",2.0,0.5,0.5,"airmass"); cpgmtxt("B",2.0,0.5,0.5,"angle from Sun"); cpgsci(2); for(i=0; i<numobs; i++) { jd = obs[i].date + 2400000.5; lstm = lst(jd,longitude_hrs); // get ecliptic coordinates slaEqecl(obs[i].ra, obs[i].dec, obs[i].date, &longEcliptic, &latEcliptic); if(fabs(latEcliptic) < 10.0/DEG_IN_RADIAN && obs[i].twilight==1) { // get position of Sun accusun(jd, lstm, latitude_deg, &rasun, &decsun, &distsun, &toporasun, &topodecsun, &x, &y, &z); // sun-object angle in degrees // takes ra in hours, dec in degrees objra = adj_time(obs[i].ra*HRS_IN_RADIAN); objdec = obs[i].dec*DEG_IN_RADIAN; phi = mysubtend(rasun, decsun, objra, objdec)*DEG_IN_RADIAN; // angle from opposition is 180-phi // FIXRANGE(phi,-180.0,180.0); //airmass takes ra, dec, in radians, returns true airmass airmass(obs[i].date, obs[i].ra, obs[i].dec, &trueam, &alt, &ha); cpgpt1(phi, trueam, -1); } } cpgsci(1); cpgptxt(0.0,3.0,0.0,0.5,"|ecliptic latitude|<10"); cpgptxt(0.0,2.5,0.0,0.5,"twilight"); cpgsci(3); cpgmove(-90.0,0.0); cpgdraw(-90.0,4.0); cpgmove( 90.0,0.0); cpgdraw( 90.0,4.0); cpgsci(1); cpgpanl(2,2); cpgswin(PHIMIN, PHIMAX, AMMIN, AMMAX); cpgbox("BCNTS",0.0,0,"BVCNTS",0.0,0); cpgmtxt("L",2.0,0.5,0.5,"airmass"); cpgmtxt("B",2.0,0.5,0.5,"angle from Sun"); cpgsci(2); for(i=0; i<numobs; i++) { jd = obs[i].date + 2400000.5; lstm = lst(jd,longitude_hrs); // get ecliptic coordinates slaEqecl(obs[i].ra, obs[i].dec, obs[i].date, &longEcliptic, &latEcliptic); if(fabs(latEcliptic) >= 10.0/DEG_IN_RADIAN && obs[i].twilight==1) { // get position of Sun accusun(jd, lstm, latitude_deg, &rasun, &decsun, &distsun, &toporasun, &topodecsun, &x, &y, &z); // sun-object angle in degrees phi = mysubtend(rasun, decsun, obs[i].ra*HRS_IN_RADIAN, obs[i].dec*DEG_IN_RADIAN)*DEG_IN_RADIAN; // angle from opposition is 180-phi FIXRANGE(phi,-180.0,180.0); airmass(obs[i].date, obs[i].ra, obs[i].dec, &trueam, &alt, &ha); cpgpt1(phi, trueam, -1); } } cpgsci(1); cpgptxt(0.0,3.0,0.0,0.5,"|ecliptic latitude|>10"); cpgptxt(0.0,2.5,0.0,0.5,"twilight"); cpgsci(3); cpgmove(-90.0,0.0); cpgdraw(-90.0,4.0); cpgmove( 90.0,0.0); cpgdraw( 90.0,4.0); cpgsci(1); cpgebuf(); closePlot(); }
static int plot_dataview(dataview * dv, float minval, float maxval, float charhgt) /* The return value is offsetn */ { int ii, lon, hin, offsetn = 0, tmpn; double lot, hit, offsett = 0.0; float ns[MAXDISPNUM], hiavg[MAXDISPNUM], loavg[MAXDISPNUM]; float scalemin = 0.0, scalemax = 0.0, dscale; cpgsave(); cpgbbuf(); /* Set the "Normal" plotting attributes */ cpgsls(1); cpgslw(1); cpgsch(charhgt); cpgsci(1); cpgvstd(); /* Autoscale for the maximum value */ if (maxval > 0.5 * LARGENUM) scalemax = dv->maxval; else scalemax = maxval; /* Autoscale for the minimum value */ if (minval < 0.5 * SMALLNUM) scalemin = dv->minval; else scalemin = minval; dscale = 0.1 * (scalemax - scalemin); if (maxval > 0.5 * LARGENUM) maxval = scalemax + dscale; if (minval < 0.5 * SMALLNUM) minval = scalemin - dscale; lon = dv->lon; lot = lon * idata.dt; hin = lon + dv->numsamps; hit = hin * idata.dt; /* Time Labels (top of box) */ if ((hit - lot) / hit < 0.001) { int numchar; char label[50]; offsett = 0.5 * (hit + lot); numchar = snprintf(label, 50, "Time - %.15g (s)", offsett); cpgmtxt("T", 2.5, 0.5, 0.5, label); } else { cpgmtxt("T", 2.5, 0.5, 0.5, "Time (s)"); } cpgswin(lot - offsett, hit - offsett, minval, maxval); cpgbox("CMST", 0.0, 0, "", 0.0, 0); /* Sample number labels */ if (lon > 10000000 || (double) (hin - lon) / (double) hin < 0.001) { int numchar; char label[50]; offsetn = (lon / 10000) * 10000; numchar = snprintf(label, 50, "Sample - %d", offsetn); cpgmtxt("B", 2.8, 0.5, 0.5, label); } else { cpgmtxt("B", 2.8, 0.5, 0.5, "Sample"); } cpgswin(lon - offsetn, hin - offsetn, minval, maxval); cpgbox("BNST", 0.0, 0, "BCNST", 0.0, 0); /* Plot the rawdata if required */ tmpn = lon - offsetn; if (plotstats == 0 || plotstats == 2) { if (dv->zoomlevel > 0) { for (ii = 0; ii < dv->dispnum; ii++) ns[ii] = tmpn + ii; cpgbin(dv->dispnum, ns, dv->vals, 0); } else { /* Plot the min/max values */ for (ii = 0; ii < dv->numchunks; ii++, tmpn += dv->chunklen) { cpgmove((float) tmpn, dv->mins[ii]); cpgdraw((float) tmpn, dv->maxs[ii]); } } } /* Plot the other statistics if requested */ if (plotstats == 0 || plotstats == 1) { tmpn = lon - offsetn; for (ii = 0; ii < dv->numchunks; ii++, tmpn += dv->chunklen) { ns[ii] = tmpn; hiavg[ii] = dv->avgmeds[ii] + dv->stds[ii]; loavg[ii] = dv->avgmeds[ii] - dv->stds[ii]; } if (dv->numchunks > 512) { if (plotstats == 1) { cpgline(dv->numchunks, ns, dv->mins); cpgline(dv->numchunks, ns, dv->maxs); } cpgsci(AVGMED_COLOR); cpgline(dv->numchunks, ns, dv->avgmeds); if (usemedian) cpgmtxt("T", -1.4, 0.02, 0.0, "Median"); else cpgmtxt("T", -1.4, 0.02, 0.0, "Average"); cpgsci(STDDEV_COLOR); cpgline(dv->numchunks, ns, hiavg); cpgline(dv->numchunks, ns, loavg); cpgmtxt("T", -2.6, 0.02, 0.0, "+/- 1 Std Dev"); } else { if (plotstats == 1) { cpgbin(dv->numchunks, ns, dv->mins, 0); cpgbin(dv->numchunks, ns, dv->maxs, 0); } cpgsci(AVGMED_COLOR); cpgbin(dv->numchunks, ns, dv->avgmeds, 0); if (usemedian) cpgmtxt("T", -1.4, 0.02, 0.0, "Median"); else cpgmtxt("T", -1.4, 0.02, 0.0, "Average"); cpgsci(STDDEV_COLOR); cpgbin(dv->numchunks, ns, hiavg, 0); cpgbin(dv->numchunks, ns, loavg, 0); cpgmtxt("T", -2.6, 0.02, 0.0, "+/- 1 Std Dev"); } } cpgsci(1); cpgmtxt("L", 2.5, 0.5, 0.5, "Sample Value"); cpgebuf(); cpgunsa(); return offsetn; }
static double plot_fftview(fftview * fv, float maxpow, float charhgt, float vertline, int vertline_color) /* The return value is offsetf */ { int ii; double lor, lof, hir, hif, offsetf = 0.0; float *freqs; cpgsave(); cpgbbuf(); /* Set the "Normal" plotting attributes */ cpgsls(1); cpgslw(1); cpgsch(charhgt); cpgsci(1); cpgvstd(); if (maxpow == 0.0) /* Autoscale for the maximum value */ maxpow = 1.1 * fv->maxpow; lor = fv->lor; lof = lor / T; hir = lor + fv->dr * DISPLAYNUM; hif = hir / T; offsetf = 0.0; /* Period Labels */ if (fv->zoomlevel >= 0 && lof > 1.0) { double lop, hip, offsetp = 0.0; lop = 1.0 / lof; hip = 1.0 / hif; offsetp = 0.0; if ((lop - hip) / hip < 0.001) { int numchar; char label[50]; offsetp = 0.5 * (hip + lop); numchar = snprintf(label, 50, "Period - %.15g (s)", offsetp); cpgmtxt("T", 2.5, 0.5, 0.5, label); } else { cpgmtxt("T", 2.5, 0.5, 0.5, "Period (s)"); } cpgswin(lop - offsetp, hip - offsetp, 0.0, maxpow); cpgbox("CIMST", 0.0, 0, "", 0.0, 0); } /* Frequency Labels */ if ((hif - lof) / hif < 0.001) { int numchar; char label[50]; offsetf = 0.5 * (hif + lof); numchar = snprintf(label, 50, "Frequency - %.15g (Hz)", offsetf); cpgmtxt("B", 2.8, 0.5, 0.5, label); } else { cpgmtxt("B", 2.8, 0.5, 0.5, "Frequency (Hz)"); } cpgswin(lof - offsetf, hif - offsetf, 0.0, maxpow); /* Add zapboxes if required */ if (numzaplist) { double zaplo, zaphi; cpgsave(); cpgsci(15); cpgsfs(1); for (ii = 0; ii < numzaplist; ii++) { zaplo = zaplist[ii].lobin; zaphi = zaplist[ii].hibin; if ((zaplo < hir && zaplo > lor) || (zaphi < hir && zaphi > lor)) { cpgrect(zaplo / T - offsetf, zaphi / T - offsetf, 0.0, 0.95 * maxpow); } } cpgunsa(); } /* Add a background vertical line if requested */ if (vertline != 0.0 && vertline_color != 0) { cpgsave(); cpgsci(vertline_color); cpgmove(vertline / T - offsetf, 0.0); cpgdraw(vertline / T - offsetf, maxpow); cpgunsa(); } if (fv->zoomlevel >= 0 && lof > 1.0) cpgbox("BINST", 0.0, 0, "BCNST", 0.0, 0); else cpgbox("BCINST", 0.0, 0, "BCNST", 0.0, 0); /* Plot the spectrum */ freqs = gen_fvect(DISPLAYNUM); for (ii = 0; ii < DISPLAYNUM; ii++) freqs[ii] = fv->rs[ii] / T - offsetf; if (fv->zoomlevel > 0) { /* Magnified power spectrum */ cpgline(DISPLAYNUM, freqs, fv->powers); } else { /* Down-sampled power spectrum */ for (ii = 0; ii < DISPLAYNUM; ii++) { cpgmove(freqs[ii], 0.0); cpgdraw(freqs[ii], fv->powers[ii]); } } vect_free(freqs); cpgmtxt("L", 2.5, 0.5, 0.5, "Normalized Power"); cpgebuf(); cpgunsa(); return offsetf; }