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); }
static void plot_rfi(rfi * plotrfi, float top, int numint, int numchan, float T, float lof, float hif) { int ii; float period, perioderr, dy = 0.035, *temparr; float tr[6] = { -0.5, 1.0, 0.0, -0.5, 0.0, 1.0 }; char temp[40]; if (plotrfi->freq_avg == 0.0) period = 0.0; else period = 1000.0 / plotrfi->freq_avg; if (plotrfi->freq_var == 0.0) /* Why are these zero? */ perioderr = 0.0; else perioderr = 1000.0 * sqrt(plotrfi->freq_var) / (plotrfi->freq_avg * plotrfi->freq_avg); cpgsvp(0.0, 1.0, 0.0, 1.0); cpgswin(0.0, 1.0, 0.0, 1.0); cpgnice_output_2(temp, plotrfi->freq_avg, sqrt(plotrfi->freq_var), 0); cpgptxt(0.03, top - 0.6 * dy, 0.0, 0.0, temp); cpgnice_output_2(temp, period, perioderr, 0); cpgptxt(0.12, top - 0.6 * dy, 0.0, 0.0, temp); sprintf(temp, "%-5.2f", plotrfi->sigma_avg); cpgptxt(0.21, top - 0.6 * dy, 0.0, 0.0, temp); sprintf(temp, "%d", plotrfi->numobs); cpgptxt(0.27, top - 0.6 * dy, 0.0, 0.0, temp); ii = (numint > numchan) ? numint : numchan; temparr = gen_fvect(ii); for (ii = 0; ii < numchan; ii++) temparr[ii] = GET_BIT(plotrfi->chans, ii); cpgsvp(0.33, 0.64, top - dy, top); cpgswin(0.0, numchan, 0.0, 1.0); cpgimag(temparr, numchan, 1, 1, numchan, 1, 1, 0.0, 1.0, tr); cpgswin(0.0, numchan, 0.0, 1.0); cpgbox("BST", 0.0, 0, "BC", 0.0, 0); cpgswin(lof, hif, 0.0, 1.0); cpgbox("CST", 0.0, 0, "", 0.0, 0); for (ii = 0; ii < numint; ii++) temparr[ii] = GET_BIT(plotrfi->times, ii); cpgsvp(0.65, 0.96, top - dy, top); cpgswin(0.0, numint, 0.0, 1.0); cpgimag(temparr, numint, 1, 1, numint, 1, 1, 0.0, 1.0, tr); cpgswin(0.0, numint, 0.0, 1.0); cpgbox("BST", 0.0, 0, "BC", 0.0, 0); cpgswin(0.0, T, 0.0, 1.0); cpgbox("CST", 0.0, 0, "", 0.0, 0); vect_free(temparr); }
void plot_channel_data() { int samp=0; int pg_id; pg_id = cpgopen("/XSERVE"); cpgpap(8.0, 0.8); cpgask(0); cpgpage(); cpgslct(pg_id); cpgsci(3); cpgeras(); cpgsvp(0.15f, 0.95f, 0.2f, 0.8f); cpgupdt(); cpgsch(2.0); cpgswin(0, read_count, -0.1f, 0.1f); cpgbox("BC1NST",0.0,0,"BCNST",0.0,0); cpglab("Time [samples]", "Voltage [volts]", "Antenna Measurement Receiver"); cpgmove(samp, voltarray[0]); for (samp=2; samp<read_count; samp++) { cpgdraw(samp, voltarray[samp]); } return 0; }
void Cpg_Box(const char *xopt, double xtick, int nxsub, const char *yopt, double ytick, int nysub) /* void cpgbox(const char *xopt, float xtick, int nxsub, \ const char *yopt, float ytick, int nysub); Options (for parameters XOPT and YOPT): A : draw Axis (X axis is horizontal line Y=0, Y axis is vertical line X=0). B : draw bottom (X) or left (Y) edge of frame. C : draw top (X) or right (Y) edge of frame. G : draw Grid of vertical (X) or horizontal (Y) lines. I : Invert the tick marks; ie draw them outside the viewport instead of inside. L : label axis Logarithmically (see below). N : write Numeric labels in the conventional location below the viewport (X) or to the left of the viewport (Y). P : extend ("Project") major tick marks outside the box (ignored if option I is specified). M : write numeric labels in the unconventional location above the viewport (X) or to the right of the viewport (Y). T : draw major Tick marks at the major coordinate interval. S : draw minor tick marks (Subticks). V : orient numeric labels Vertically. This is only applicable to Y. The default is to write Y-labels parallel to the axis. 1 : force decimal labelling, instead of automatic choice (see PGNUMB). 2 : force exponential labelling, instead of automatic. When PGENV calls PGBOX, it sets both XOPT and YOPT according to the value of its parameter AXIS: -1: 'BC', 0: 'BCNST', 1: 'ABCNST', 2: 'ABCGNST'. */ { cpgbox(xopt, (float)xtick, nxsub, yopt, (float)ytick, nysub); return; }
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(); }
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; }
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; }
/* * Class: pulsarhunter_PgplotInterface * Method: pgbox * Signature: (Ljava/lang/String;FFLjava/lang/String;FI)V */ JNIEXPORT void JNICALL Java_pulsarhunter_PgplotInterface_pgbox (JNIEnv *env, jclass cl, jstring xopt, jfloat xtic, jint nxsub , jstring yopt, jfloat ytic, jint nysub){ char *xStr = (char*)(*env)->GetStringUTFChars(env,xopt,NULL); char *yStr = (char*)(*env)->GetStringUTFChars(env,yopt,NULL); jint strlen1 = (*env)->GetStringUTFLength(env,xopt); jint strlen2 = (*env)->GetStringUTFLength(env,yopt); cpgbox(xStr,xtic,nxsub,yStr,ytic,nysub); (*env)->ReleaseStringUTFChars(env,xopt,xStr); (*env)->ReleaseStringUTFChars(env,yopt,yStr); }
void plot_image(struct image img,struct transformation t,struct catalog c,char *filename,float mmin) { int i; float tr[]={-0.5,1.0,0.0,-0.5,0.0,1.0}; float heat_l[]={0.0,0.2,0.4,0.6,1.0}; float heat_r[]={0.0,0.5,1.0,1.0,1.0}; float heat_g[]={0.0,0.0,0.5,1.0,1.0}; float heat_b[]={0.0,0.0,0.0,0.3,1.0}; float zmin,zmax,zavg,zstd; for (i=0,zavg=0.0;i<img.naxis1*img.naxis2;i++) zavg+=img.zavg[i]; zavg/=(float) img.naxis1*img.naxis2; for (i=0,zstd=0.0;i<img.naxis1*img.naxis2;i++) zstd+=pow(img.zavg[i]-zavg,2); zstd=sqrt(zstd/(float) (img.naxis1*img.naxis2)); zmin=zavg-2*zstd; zmax=zavg+6*zstd; cpgopen("1/xs"); cpgwnad(0.0,img.naxis1,0.0,img.naxis2); cpgctab (heat_l,heat_r,heat_g,heat_b,5,1.0,0.5); cpgimag(img.zavg,img.naxis1,img.naxis2,1,img.naxis1,1,img.naxis2,zmin,zmax,tr); cpgbox("BCTSNI",0.,0,"BCTSNI",0.,0); cpgsci(3); plot_pixel_catalog(filename); cpgsci(4); plot_astrometric_catalog(t,img,mmin); cpgsci(2); for (i=0;i<c.n;i++) cpgpt1(c.x[i]+t.x0,c.y[i]+t.y0,24); cpgend(); return; }
int plot_freq_data(void) { int bin=0; printf("\nPlotting ..."); cpgask(0); cpgpage(); cpgslct(pg_id); cpgsci(1); cpgeras(); cpgsvp(0.15f, 0.95f, 0.2f, 0.8f); cpgupdt(); cpgsch(2.0); cpgswin(0, (N/2)+1, 0.0f, 0.005f); // cpgswin(80, 120, 0.0f, 0.01f); cpgbox("BC1NST",0.0,0,"BCNST",0.0,0); cpglab("Frequency [bins]", "Peak Voltage [volts]", "Antenna Measurement Receiver"); cpgmove(bin, accumFreqData[0]); for (bin=1; bin<(N/2)+1; bin++) { cpgdraw(bin, accumFreqData[bin]); } return 0; }
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); }
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(); }
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; }
int main(){ printf("\n====================================================================\n"); printf("This program is able to simulate the diffusion of heat\n"); printf("across a metal plate of size %i x %i\n", ENV_SIZE_X, ENV_SIZE_Y); printf("====================================================================\n"); //========================================================================== //--------------------------SYSTEM INITIALIZATIONS-------------------------- //========================================================================== // initialize random seed srand(time(NULL)); // force print all outputs (remove stdout buffer) setbuf(stdout, NULL); // initialize pgplot window if (!cpgopen("/XWINDOW")) errorCase(ERR_PGPLOT); cpgpap(0.0, 0.6); // set window size cpgsubp(1,3); // subdivide window into panels // heatmap cpgpanl(1,1); cpgsvp(0.0, 1.0, 0.0, 1.0); cpgswin(0, ENV_SIZE_X, 0, ENV_SIZE_Y); // flux plot cpgpanl(1,2); cpgsvp(0.08, 0.92, 0.08, 0.92); cpgswin(LINE_PLOT_X1, LINE_PLOT_X2, FLUX_PLOT_Y1, FLUX_PLOT_Y2); cpgbox("ABCINTS", 0.0, 0, "ABCINTS", 0.0, 0); cpglab("Time", "Flux", ""); // heat plot cpgpanl(1,3); cpgsvp(0.08, 0.92, 0.08, 0.92); cpgswin(LINE_PLOT_X1, LINE_PLOT_X2, LINE_PLOT_Y1, LINE_PLOT_Y2); cpgbox("ABCINTS", 0.0, 0, "ABCINTS", 0.0, 0); cpglab("Time", "Total Heat", ""); // initialize color table for pgplot display float rl[9] = {-0.5, 0.0, 0.17, 0.33, 0.50, 0.67, 0.83, 1.0, 1.7}; float rr[9] = { 0.0, 0.0, 0.0, 0.0, 0.6, 1.0, 1.0, 1.0, 1.0}; float rg[9] = { 0.0, 0.0, 0.0, 1.0, 1.0, 1.0, 0.6, 0.0, 1.0}; float rb[9] = { 0.0, 0.3, 0.8, 1.0, 0.3, 0.0, 0.0, 0.0, 1.0}; cpgctab(rl, rr, rg, rb, 512, 1.0, 0.5); cpgscr(10, 0.0, 0.0, 1.0); cpgscr(11, 1.0, 0.0, 0.0); cpgsfs(3); //========================================================================== //--------------------------VARIABLE INITIALIZATIONS------------------------ //========================================================================== // generic variables int i, j, k; // counters // simulation environment float** simEnvEven = allocateArray2D(ENV_SIZE_X, ENV_SIZE_Y); float** simEnvOdd = allocateArray2D(ENV_SIZE_X, ENV_SIZE_Y); float* simLocal = allocateArray1D(5); // mnist handwritten numbers float** mnistDatabase = readCSV("mnist_train_100.csv", 100, 785); for (i=0; i<100; i++) for (j=0; j<785; j++) mnistDatabase[i][j] = mnistDatabase[i][j]/255.0; // current location and time int x,y,z; int t, tGlobal; // student number int studentNumbRaw; int studentNumbWorking; int studentNumb[7]; // rates float rateDiff = 0.2; float delta; // flux variables float flux; float fluxTotal; float fluxAverage; float fluxHeat; float totalHeat; int x1, x2, y1, y2; // background heat float bgHeat; // tracking variables float totalHeatOld; float totalHeatPre; float tGlobalOld; float fluxOld; // pgplot variables float* plotImg = allocateArray1D(ENV_SIZE_TOTAL); float TR[6] = {0, 0, 1, ENV_SIZE_Y, -1, 0}; float plotMinBound = 0; float plotMaxBound = 1; //========================================================================== //--------------------------------SETUP------------------------------------- //========================================================================== // ask for student number printf("Please enter your student number:\n"); if (scanf("%i", &studentNumbRaw) == 0) errorCase(ERR_INVALID_INPUT); studentNumbWorking = studentNumbRaw; for (i=0; i<SN_LENGTH; i++){ studentNumb[6-i] = studentNumbWorking%10; studentNumbWorking /= 10; } printf("\nYour student number is:\n"); for (i=0; i<SN_LENGTH; i++) printf("%i", studentNumb[i]); printf("\n\n"); // set and print diffusion rate based on last digit of student number rateDiff = ((((float)(studentNumb[6]))/10.0)*0.19)+0.01; printf("Your Diffusion Rate is: \n%f\n\n", rateDiff); // set and print background heat added based on last 4 digits of student number studentNumbRaw -= 1410000; bgHeat = ((float)((studentNumbRaw%97)%10)); bgHeat += ((float)((studentNumbRaw%101)%8))*10; bgHeat /= 100; printf("Your Background Heat is: \n%f\n\n", bgHeat*100); // set and print domain for calculating flux // x1, y1 based on last four digits of student number x1 = studentNumbRaw % ENV_SIZE_X; y1 = studentNumbRaw % ENV_SIZE_Y; // x2, y2 based on last four digits of student number x2 = x1 + (studentNumbRaw % (97)); if (x2 >= ENV_SIZE_X) x2 = ENV_SIZE_X - 1; y2 = y1 + (studentNumbRaw % (29)); if (y2 >= ENV_SIZE_Y) y2 = ENV_SIZE_Y - 1; printf("Your Domain is: \n(%i, %i) X (%i, %i)\n\n", x1, y1, x2, y2); // environment initialization: // select digits and place into environment for (i=0; i<SN_LENGTH; i++){ if (studentNumb[i] == 0) z = 0; else if (studentNumb[i] == 1) z = 13; else if (studentNumb[i] == 2) z = 27; else if (studentNumb[i] == 3) z = 33; else if (studentNumb[i] == 4) z = 44; else if (studentNumb[i] == 5) z = 55; else if (studentNumb[i] == 6) z = 60; else if (studentNumb[i] == 7) z = 71; else if (studentNumb[i] == 8) z = 81; else z = 89; for (x=0; x<28; x++) for (y=0; y<28; y++) { simEnvEven[x+(i*28)+1][y+1] = mnistDatabase[z][y*28+x] + bgHeat; if (simEnvEven[x+(i*28)+1][y+1] > 1.0) simEnvEven[x+(i*28)+1][y+1] = 1.0; } } //========================================================================== //--------------------------ACTUAL CODE------------------------------------- //========================================================================== // initialize display fixBoundaryConditions(simEnvEven); copyArray2D(simEnvEven, simEnvOdd, ENV_SIZE_X, ENV_SIZE_Y); loadImage(simEnvEven, plotImg); cpgpanl(1,1); cpgsvp(0.0, 1.0, 0.0, 1.0); cpgswin(0, ENV_SIZE_X, 0, ENV_SIZE_Y); cpgimag(plotImg, ENV_SIZE_Y, ENV_SIZE_X, 1, ENV_SIZE_Y, 1, ENV_SIZE_X, plotMinBound, plotMaxBound, TR); cpgrect(x1, x2, y1, y2); // initialize trackers tGlobalOld = 0; fluxOld = 0; totalHeatOld = 0; for (x=x1; x<=x2; x++) for (y=y1; y<=y2; y++) totalHeatOld += simEnvEven[x][y]; // initial delay to visualize starting matrix for (t=0; t<500000000; t++){} t = 0; tGlobal = 0; flux = 0; fluxAverage = 0; fluxTotal = 0; while(1){ flux = 0; cpgpanl(1,1); cpgsvp(0.0, 1.0, 0.0, 1.0); cpgswin(0, ENV_SIZE_X, 0, ENV_SIZE_Y); // calculate heat changes using numeric methods fixBoundaryConditions(simEnvEven); //simEnvEven[50][15] = 100; //simEnvEven[60][15] = -10; copyArray2D(simEnvEven, simEnvOdd, ENV_SIZE_X, ENV_SIZE_Y); for (x=1; x<(ENV_SIZE_X-1); x++) for (y=1; y<(ENV_SIZE_Y-1); y++) if ((x+y)%2 == 0) { delta = rateDiff*(simEnvEven[x][y+1] - 2*simEnvEven[x][y] + simEnvEven[x][y-1]); simEnvOdd[x][y] += delta; if (INSIDE_BOX) flux += delta; delta = rateDiff*(simEnvEven[x+1][y] - 2*simEnvEven[x][y] + simEnvEven[x-1][y]); simEnvOdd[x][y] += delta; if (INSIDE_BOX) flux += delta; } for (x=1; x<(ENV_SIZE_X-1); x++) for (y=1; y<(ENV_SIZE_Y-1); y++) if ((x+y)%2 == 1) { delta = rateDiff*(simEnvOdd[x][y+1] - 2*simEnvOdd[x][y] + simEnvOdd[x][y-1]); simEnvOdd[x][y] += delta; if (INSIDE_BOX) flux += delta; delta = rateDiff*(simEnvOdd[x+1][y] - 2*simEnvOdd[x][y] + simEnvOdd[x-1][y]); simEnvOdd[x][y] += delta; if (INSIDE_BOX) flux += delta; } loadImage(simEnvOdd, plotImg); cpgimag(plotImg, ENV_SIZE_Y, ENV_SIZE_X, 1, ENV_SIZE_Y, 1, ENV_SIZE_X, plotMinBound, plotMaxBound, TR); cpgrect(x1, x2, y1, y2); fluxTotal += flux; tGlobal++; flux = 0; //simEnvOdd[50][15] = 100; //simEnvOdd[60][15] = -10; fixBoundaryConditions(simEnvOdd); for (x=1; x<(ENV_SIZE_X-1); x++) for (y=1; y<(ENV_SIZE_Y-1); y++) if ((x+y)%2 == 1) { delta = rateDiff*(simEnvOdd[x][y+1] - 2*simEnvOdd[x][y] + simEnvOdd[x][y-1]); simEnvEven[x][y] += delta; if (INSIDE_BOX) flux += delta; delta = rateDiff*(simEnvOdd[x+1][y] - 2*simEnvOdd[x][y] + simEnvOdd[x-1][y]); simEnvEven[x][y] += delta; if (INSIDE_BOX) flux += delta; } for (x=1; x<(ENV_SIZE_X-1); x++) for (y=1; y<(ENV_SIZE_Y-1); y++) if ((x+y)%2 == 0) { delta = rateDiff*(simEnvEven[x][y+1] - 2*simEnvEven[x][y] + simEnvEven[x][y-1]); simEnvEven[x][y] += delta; if (INSIDE_BOX) flux += delta; delta = rateDiff*(simEnvEven[x+1][y] - 2*simEnvEven[x][y] + simEnvEven[x-1][y]); simEnvEven[x][y] += delta; if (INSIDE_BOX) flux += delta; } loadImage(simEnvEven, plotImg); cpgimag(plotImg, ENV_SIZE_Y, ENV_SIZE_X, 1, ENV_SIZE_Y, 1, ENV_SIZE_X, plotMinBound, plotMaxBound, TR); cpgrect(x1, x2, y1, y2); fluxTotal += flux; tGlobal++; // flux line plot cpgpanl(1,2); cpgsvp(0.08, 0.92, 0.08, 0.92); cpgswin(LINE_PLOT_X1, LINE_PLOT_X2, FLUX_PLOT_Y1, FLUX_PLOT_Y2); cpgmove(tGlobalOld, fluxOld); cpgdraw(tGlobal, flux); // heat line plot totalHeat = 0; for (x=x1; x<=x2; x++) for (y=y1; y<=y2; y++) totalHeat += simEnvEven[x][y]; cpgpanl(1,3); cpgsvp(0.08, 0.92, 0.08, 0.92); cpgswin(LINE_PLOT_X1, LINE_PLOT_X2, LINE_PLOT_Y1, LINE_PLOT_Y2); cpgmove(tGlobalOld, totalHeatOld); cpgdraw(tGlobal, totalHeat); // set trackers tGlobalOld = tGlobal; totalHeatOld = totalHeat; fluxOld = flux; if (tGlobal%100 == 0) { totalHeat = 0; for (x=x1; x<=x2; x++) for (y=y1; y<=y2; y++) totalHeat += simEnvEven[x][y]; fluxAverage = fluxTotal/tGlobal; fluxHeat = totalHeat - totalHeatPre; printf("Total Heat: %f \n Current Divergence: %f \n Current Flux: %f\n\n", totalHeat, flux, fluxHeat); } totalHeatPre = 0; for (x=x1; x<=x2; x++) for (y=y1; y<=y2; y++) totalHeatPre += simEnvEven[x][y]; } }
void doPlot(pulsar *psr,int npsr,float *scale,int nScale,char *grDev,int plotUs,float fontSize,float centreMJD,int ptStyle,float ptSize,int error,float minyv,float maxyv,float minxv,float maxxv,int nOverlay,float labelsize,float fracX) { int i,j,fitFlag=2,exitFlag=0,scale1=0,scale2,count[MAX_PSR],p,xautoscale=0,k,graphics=1; int yautoscale=0,plotpre=1; int ps,pe,pi; int time=0; char xstr[1000],ystr[1000]; float px[2],py[2],pye1[2],pye2[2]; float x[MAX_PSR][MAX_OBSN],y[MAX_PSR][MAX_OBSN],yerr1[MAX_PSR][MAX_OBSN],yerr2[MAX_PSR][MAX_OBSN],tmax,tmin,tmaxy1,tminy1,tmaxy2,tminy2; float sminy[MAX_PSR],smaxy[MAX_PSR]; float minx[MAX_PSR],maxx[MAX_PSR],miny[MAX_PSR],maxy[MAX_PSR],plotx1,plotx2,ploty1,ploty2,mean; float fx[2],fy[2]; float mouseX,mouseY; char key; // float widthPap=0.0,aspectPap=0.618; float widthPap=0.0,aspectPap=1; float xx[MAX_OBSN],yy[MAX_OBSN],yyerr1[MAX_OBSN],yyerr2[MAX_OBSN]; int num=0,colour; /* Obtain a graphical PGPLOT window */ cpgbeg(0,grDev,1,1); // cpgpap(widthPap,aspectPap); cpgsch(fontSize); cpgscf(2); cpgslw(2); cpgask(0); for (p=0;p<npsr;p++) { scale2 = psr[p].nobs; /* sprintf(xstr,"MJD-%.1Lf",psr[0].param[param_pepoch].val[0]); */ if (centreMJD == -1) sprintf(xstr,"Year"); else sprintf(xstr,"MJD-%.1f",centreMJD); sprintf(ystr,"Residual (\\gmsec)"); count[p]=0; printf("points = %d\n",psr[p].nobs); for (i=0;i<psr[p].nobs;i++) { if (psr[p].obsn[i].deleted == 0 && (psr[p].param[param_start].paramSet[0]!=1 || psr[p].param[param_start].fitFlag[0]!=1 || psr[p].param[param_start].val[0] < psr[p].obsn[i].bat) && (psr[p].param[param_finish].paramSet[0]!=1 || psr[p].param[param_finish].fitFlag[0]!=1 || psr[p].param[param_finish].val[0] > psr[p].obsn[i].bat)) { /* x[p][count[p]] = (double)(psr[p].obsn[i].bat-psr[0].param[param_pepoch].val[0]); */ if (centreMJD == -1) x[p][count[p]] = calcYr(psr[p].obsn[i].bat); else x[p][count[p]] = (double)(psr[p].obsn[i].bat-centreMJD); y[p][count[p]] = (double)psr[p].obsn[i].residual*1.0e6; if (nScale>0) y[p][count[p]] *= scale[p]; count[p]++; } } /* Remove mean from the residuals and calculate error bars */ mean = findMean(y[p],psr,p,scale1,count[p]); count[p]=0; for (i=0;i<psr[p].nobs;i++) { if (psr[p].obsn[i].deleted==0 && (psr[p].param[param_start].paramSet[0]!=1 || psr[p].param[param_start].fitFlag[0]!=1 || psr[p].param[param_start].val[0] < psr[p].obsn[i].bat) && (psr[p].param[param_finish].paramSet[0]!=1 || psr[p].param[param_finish].fitFlag[0]!=1 || psr[p].param[param_finish].val[0] > psr[p].obsn[i].bat)) { psr[p].obsn[i].residual-=mean/1.0e6; y[p][count[p]]-=mean; yerr1[p][count[p]] = y[p][count[p]]-(float)psr[p].obsn[i].toaErr; yerr2[p][count[p]] = y[p][count[p]]+(float)psr[p].obsn[i].toaErr; count[p]++; } } /* Get scaling for graph */ if (minxv == maxxv) { minx[p] = findMin(x[p],psr,p,scale1,count[p]); maxx[p] = findMax(x[p],psr,p,scale1,count[p]); } else { minx[p] = minxv; maxx[p] = maxxv; } if (minyv == maxyv){ miny[p] = findMin(y[p],psr,p,scale1,count[p]); maxy[p] = findMax(y[p],psr,p,scale1,count[p]); } else { miny[p] = minyv; maxy[p] = maxyv; } sminy[p] = miny[p]/1e6; smaxy[p] = maxy[p]/1e6; } for (p=0;p<npsr;p++) { for (i=0;i<count[p];i++) { y[p][i] = (y[p][i]-miny[p])/(maxy[p]-miny[p]); yerr1[p][i] = (yerr1[p][i]-miny[p])/(maxy[p]-miny[p]); yerr2[p][i] = (yerr2[p][i]-miny[p])/(maxy[p]-miny[p]); } // maxy[p] = 1.0; // miny[p] = 0.0; } tmin = findMinVal(minx,npsr); tmax = findMaxVal(maxx,npsr); tminy2 = 0.0; //findMinVal(miny,npsr); tmaxy2 = 1.0; //findMaxVal(maxy,npsr); plotx1 = tmin-(tmax-tmin)*0.1; plotx2 = tmax+(tmax-tmin)*0.1; // ploty1 = tminy2-(tmaxy2-tminy2)*0.1; // ploty2 = tmaxy2+(tmaxy2-tminy2)*0.1; ploty1 = 0.1; ploty2 = 0.9; for (p=0;p<npsr;p++) { for (i=0;i<count[p];i++) { y[p][i]=(p)+ploty1+y[p][i]*(ploty2-ploty1); yerr1[p][i]=(p)+ploty1+yerr1[p][i]*(ploty2-ploty1); yerr2[p][i]=(p)+ploty1+yerr2[p][i]*(ploty2-ploty1); } } printf("ytick = %g\n",ploty2-ploty1); /* cpgenv(plotx1,plotx2,ploty1,ploty2+(ploty2-ploty1)*(npsr-1),0,0); */ // cpgenv(plotx1,plotx2,0,npsr+1,0,-1); if (labelsize!=-1) cpgsch(labelsize); cpgsvp(fracX,1.0,0.1,1.0); cpgswin(0,1,0,npsr); cpgbox("ABC",0.0,0,"C",0.0,0); cpgsch(fontSize); char str[1000]; for (p=0;p<npsr;p++) { cpgsch(fontSize); // cpgtext(tmax+(tmax-tmin)*0.05,p+1.5-0.5,psr[p].name); cpgtext(0,p+0.6,psr[p].name); // cpgsch(fontSize); if (plotUs==0) { sprintf(str,"%.2f",(double)((smaxy[p]-sminy[p])*psr[p].param[param_f].val[0])); cpgtext(0,p+0.4,str); // cpgtext(tmax+(tmax-tmin)*0.05,p+1.1-0.5,str); } else { sprintf(str,"%.2f\\gms",(double)((smaxy[p]-sminy[p])/1e-6)); // cpgtext(tmax+(tmax-tmin)*0.05,p+1.1-0.5,str); cpgtext(0,p+0.1,str); } cpgsch(1); px[0] = 0; // px[1] = tmax; //+(tmax-tmin)*0.03; px[1] = 1; py[0] = p; py[1] = p; cpgline(2,px,py); } if (labelsize!=-1) cpgsch(labelsize); cpgsvp(0.1,fracX,0.1,1.0); cpgswin(plotx1,plotx2,0,npsr); cpgbox("ATNSBC",0.0,0,"B",0.0,0); cpglab(xstr,"",""); cpgsch(fontSize); for (p=0;p<npsr;p++) { cpgsls(1); px[0] = plotx1; // px[1] = tmax; //+(tmax-tmin)*0.03; px[1] = plotx2; py[0] = p; py[1] = p; cpgline(2,px,py); cpgsls(4); px[0] = tmin; px[1] = tmax+(tmax-tmin)*0.03; py[0]=py[1] =(p)+ploty1+(-miny[p]/(maxy[p]-miny[p]))*(ploty2-ploty1); // py[0]=py[1] = (p)+ploty1; // py[0] = py[1] = (0-miny[p])/(maxy[p]-miny[p])/(ploty2-ploty1)+p; cpgline(2,px,py); px[0] = plotx1+0.005*(plotx2-plotx1); py[0] = p; pye1[0] = p + 5/(ploty2-ploty1); pye2[0] = p - 5/(ploty2-ploty1); cpgsls(1); cpgsch(3); // cpgerry(1,px,pye1,pye2,1); cpgsch(1); for (colour=0;colour<5;colour++) { num=0; for (i=0;i<count[p];i++) { if ((colour==0 && psr[p].obsn[i].freq<=500) || (colour==1 && psr[p].obsn[i].freq>500 && psr[p].obsn[i].freq<=1000) || (colour==2 && psr[p].obsn[i].freq>1000 && psr[p].obsn[i].freq<=1500) || (colour==3 && psr[p].obsn[i].freq>1500 && psr[p].obsn[i].freq<=3300) || (colour==4 && psr[p].obsn[i].freq>3300)) { xx[num]=x[p][i]; yy[num]=y[p][i]; yyerr1[num]=yerr1[p][i]; yyerr2[num]=yerr2[p][i]; // printf("plotting: %g\n",yy[num]); num++; } } cpgsci(colour+1); cpgsch(ptSize); cpgpt(num,xx,yy,ptStyle); if (error==1) cpgerry(num,xx,yyerr1,yyerr2,1); cpgsch(fontSize); // Plot arrow giving one period fx[0] = fx[1] = tmin-(tmax-tmin)*0.05; // fy[0] = (p+1)+0.5-(float)(1.0/psr[p].param[param_f].val[0])/2.0/(ploty2-ploty1); // fy[1] = (p+1)+0.5+(float)(1.0/psr[p].param[param_f].val[0])/2.0/(ploty2-ploty1); // fy[0] = (-(float)(1.0/psr[p].param[param_f].val[0])/2.0/1.0e6 - miny[p])/(maxy[p]-miny[p])/(ploty2-ploty1) + (p+1)+0.5; // fy[1] = ((float)(1.0/psr[p].param[param_f].val[0])/2.0/1.0e6 - miny[p])/(maxy[p]-miny[p])/(ploty2-ploty1) + (p+1)+0.5; fy[0] = (p+1)+0.5+(float)(1.0/psr[p].param[param_f].val[0])/2.0/(maxy[p]-miny[p])*1e6; fy[1] = (p+1)+0.5-(float)(1.0/psr[p].param[param_f].val[0])/2.0/(maxy[p]-miny[p])*1e6; if (fy[0] > (p+1)+1) fy[0] = (p+1)+1; if (fy[1] < (p+1)) fy[1] = (p+1); // cpgsls(1); cpgline(2,fx,fy); cpgsls(1); } cpgsci(1); } cpgend(); }
// 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; }
int main(int argc, char** argv){ float tr[6]; const float ZAP=32; const uint64_t TSIZE=18; const uint64_t zapE=64; fftwf_init_threads(); fftwf_plan_with_nthreads(omp_get_max_threads()); logmsg("Open file '%s'",argv[1]); FILE* f = fopen(argv[1],"r"); int hdr_bytes = read_header(f); const uint64_t nskip = hdr_bytes; const uint64_t nchan = nchans; logmsg("Nchan=%"PRIu64", tsamp=%f",nchan,tsamp); mjk_rand_t *random = mjk_rand_init(12345); rewind(f); FILE* of = fopen("clean.fil","w"); uint8_t hdr[nskip]; fread(hdr,1,nskip,f); fwrite(hdr,1,nskip,of); const uint64_t nsamp_per_block=round(pow(2,TSIZE)); logmsg("Tblock = %f",nsamp_per_block*tsamp); mjk_clock_t *t_all = init_clock(); start_clock(t_all); mjk_clock_t *t_read = init_clock(); mjk_clock_t *t_trns= init_clock(); mjk_clock_t *t_rms = init_clock(); mjk_clock_t *t_fft = init_clock(); mjk_clock_t *t_spec = init_clock(); const uint64_t bytes_per_block = nchan*nsamp_per_block; uint8_t *buffer = calloc(bytes_per_block,1); float **data = malloc_2df(nchan,nsamp_per_block); float **clean = malloc_2df(nchan,nsamp_per_block); float *bpass = calloc(nchan,sizeof(float)); float *ch_var=NULL; float *ch_mean=NULL; float *ch_fft_n=NULL; float *ch_fft_p=NULL; logmsg("Planning FFT - this will take a long time the first time it is run!"); start_clock(t_fft); FILE * wisfile; if(wisfile=fopen("wisdom.txt","r")){ fftwf_import_wisdom_from_file(wisfile); fclose(wisfile); } const int fftX=nsamp_per_block; const int fftY=nchan; const int fftXo=nsamp_per_block/2+1; float *X = fftwf_malloc(sizeof(float)*fftX); for (uint64_t i = 0; i < nsamp_per_block ; i++){ X[i]=i; } float *tseries = fftwf_malloc(sizeof(float)*fftX); float complex *fseries = fftwf_malloc(sizeof(float complex)*fftXo); float *pseries = fftwf_malloc(sizeof(float)*fftXo); uint8_t *mask = malloc(sizeof(uint8_t)*fftXo); fftwf_plan fft_1d = fftwf_plan_dft_r2c_1d(fftX,tseries,fseries,FFTW_MEASURE|FFTW_DESTROY_INPUT); complex float * fftd = fftwf_malloc(sizeof(complex float)*(fftXo*fftY)); fftwf_plan fft_plan = fftwf_plan_many_dft_r2c( 1,&fftX,fftY, data[0] ,&fftX,1,fftX, fftd ,&fftXo,1,fftXo, FFTW_MEASURE|FFTW_PRESERVE_INPUT); logmsg("Planning iFFT - this will take a long time the first time it is run!"); fftwf_plan ifft_plan = fftwf_plan_many_dft_c2r( 1,&fftX,fftY, fftd ,&fftXo,1,fftXo, clean[0] ,&fftX,1,fftX, FFTW_MEASURE|FFTW_PRESERVE_INPUT); if(!fft_plan){ logmsg("Error - could not do FFT plan"); exit(2); } wisfile=fopen("wisdom.txt","w"); fftwf_export_wisdom_to_file(wisfile); fclose(wisfile); stop_clock(t_fft); logmsg("T(planFFT)= %.2lfs",read_clock(t_fft)); reset_clock(t_fft); float min_var=1e9; float max_var=0; float min_fft_n=1e9; float max_fft_n=0; float min_fft_p=1e9; float max_fft_p=0; float min_mean=1e9; float max_mean=0; uint64_t nblocks=0; uint64_t totread=0; while(!feof(f)){ nblocks++; ch_var = realloc(ch_var,nchan*nblocks*sizeof(float)); ch_mean = realloc(ch_mean,nchan*nblocks*sizeof(float)); ch_fft_n = realloc(ch_fft_n,nchan*nblocks*sizeof(float)); ch_fft_p = realloc(ch_fft_p,nchan*nblocks*sizeof(float)); start_clock(t_read); uint64_t read = fread(buffer,1,bytes_per_block,f); stop_clock(t_read); if (read!=bytes_per_block){ nblocks--; break; } totread+=read; logmsg("read=%"PRIu64" bytes. T=%fs",read,totread*tsamp/(float)nchan); uint64_t offset = (nblocks-1)*nchan; start_clock(t_trns); // transpose with small blocks in order to increase cache efficiency. #define BLK 8 #pragma omp parallel for schedule(static,2) shared(buffer,data) for (uint64_t j = 0; j < nchan ; j+=BLK){ for (uint64_t i = 0; i < nsamp_per_block ; i++){ for (uint64_t k = 0; k < BLK ; k++){ data[j+k][i] = buffer[i*nchan+j+k]; } } } #pragma omp parallel for shared(data) for (uint64_t j = 0; j < nchan ; j++){ if(j<zapE || (nchan-j) < zapE){ for (uint64_t i = 0; i < nsamp_per_block ; i++){ data[j][i]=ZAP; } } } if(nblocks==1){ #pragma omp parallel for shared(data,bpass) for (uint64_t j = 0; j < nchan ; j++){ for (uint64_t i = 0; i < nsamp_per_block ; i++){ bpass[j]+=data[j][i]; } bpass[j]/=(float)nsamp_per_block; bpass[j]-=ZAP; } } #pragma omp parallel for shared(data,bpass) for (uint64_t j = 0; j < nchan ; j++){ for (uint64_t i = 0; i < nsamp_per_block ; i++){ data[j][i]-=bpass[j]; } } stop_clock(t_trns); start_clock(t_rms); #pragma omp parallel for shared(data,ch_mean,ch_var) for (uint64_t j = 0; j < nchan ; j++){ float mean=0; for (uint64_t i = 0; i < nsamp_per_block ; i++){ mean+=data[j][i]; } mean/=(float)nsamp_per_block; if(mean > ZAP+5 || mean < ZAP-5){ logmsg("ZAP ch=%"PRIu64,j); for (uint64_t i = 0; i < nsamp_per_block ; i++){ data[j][i]=ZAP; } } float ss=0; float x=0; for (uint64_t i = 0; i < nsamp_per_block ; i++){ x = data[j][i]-mean; ss+=x*x; } float var=ss/(float)nsamp_per_block; if (var > 0){ for (uint64_t i = 0; i < nsamp_per_block ; i++){ float v = (data[j][i]-mean)/sqrt(var); if(v > 3 || v < -3){ data[j][i]=mjk_rand_gauss(random)*sqrt(var)+mean; } } } ch_var[offset+j] = var; ch_mean[offset+j] = mean; } stop_clock(t_rms); for (uint64_t i = 0; i < nsamp_per_block ; i++){ tseries[i]=0; } float tmean=0; float tvar=0; float max=0; float min=1e99; //#pragma omp parallel for shared(data,tseries) // NOT THREAD SAFE for (uint64_t j = 0; j < nchan ; j++){ tmean+=ch_mean[offset+j]; tvar+=ch_var[offset+j]; for (uint64_t i = 0; i < nsamp_per_block ; i++){ tseries[i]+=data[j][i]; if(data[j][i]>max)max=data[j][i]; if(data[j][i]<min)min=data[j][i]; } } float ss=0; float mm=0; for (uint64_t i = 0; i < nsamp_per_block ; i++){ float x=tseries[i]-tmean; mm+=tseries[i]; ss+=x*x; } float rvar=ss/(float)nsamp_per_block; logmsg("var=%g tvar=%g",ss/(float)nsamp_per_block,tvar); logmsg("mean=%g tmean=%g",mm/(float)nsamp_per_block,tmean); cpgopen("3/xs"); cpgsvp(0.1,0.9,0.1,0.9); cpgswin(0,fftX,tmean-sqrt(tvar)*30,tmean+sqrt(tvar)*30); cpgbox("ABN",0,0,"ABN",0,0); cpgline(fftX,X,tseries); cpgsci(2); cpgclos(); tr[0] = 0.0 ; tr[1] = 1; tr[2] = 0; tr[3] = 0.5; tr[4] = 0; tr[5] = 1; logmsg("max=%g min=%g",max,min); cpgopen("4/xs"); cpgsvp(0.1,0.9,0.1,0.9); cpgswin(0,nsamp_per_block,0,nchan); cpgbox("ABN",0,0,"ABN",0,0); cpggray(*data,nsamp_per_block,nchan,1,nsamp_per_block,1,nchan,tmean/(float)nchan+sqrt(rvar/(float)nchan),tmean/(float)nchan-sqrt(rvar/(float)nchan),tr); cpgclos(); start_clock(t_fft); fftwf_execute(fft_1d); fftwf_execute(fft_plan); stop_clock(t_fft); { float T = sqrt(fftXo*tvar)*12; logmsg("Zap T=%.2e",T); float fx[fftXo]; float fT[fftXo]; #pragma omp parallel for shared(fseries,pseries,mask) for (uint64_t i = 0; i < fftXo ; i++){ mask[i]=1; } #pragma omp parallel for shared(fseries,pseries,mask) for (uint64_t i = 0; i < fftXo ; i++){ pseries[i]=camp(fseries[i]); fx[i]=i; float TT = T; if (i>512)TT=T/2.0; if(i>32){ fT[i]=TT; if (pseries[i] > TT) { mask[i]=0; } } else fT[i]=0; } uint64_t nmask=0; for (uint64_t i = 0; i < fftXo ; i++){ if (mask[i]==0){ nmask++; } } logmsg("masked=%d (%.2f%%)",nmask,100*nmask/(float)fftXo); cpgopen("1/xs"); cpgsvp(0.1,0.9,0.1,0.9); cpgswin(0,fftXo,0,T*10); cpgbox("ABN",0,0,"ABN",0,0); cpgline(fftXo,fx,pseries); cpgsci(2); cpgline(fftXo,fx,fT); cpgclos(); } // exit(1); start_clock(t_spec); //FILE* ff=fopen("plot","w"); #pragma omp parallel for shared(fftd,ch_mean,ch_fft_n,ch_fft_p) for (uint64_t j = 0; j < nchan ; j++){ float var = ch_var[offset+j]; float m=sqrt(var*fftXo/2.0); float T = sqrt(var*fftXo)*3; uint64_t n=0; float p=0; float complex *fftch = fftd + fftXo*j; for(uint64_t i = 1; i < fftXo; i++){ if (camp(fftch[i]) > T) { n++; p+=camp(fftch[i]); } // if(j==512)fprintf(ff,"%f ",camp(fftch[i])); if(mask[i]==0){ fftch[i]=m*(mjk_rand_gauss(random) + I*mjk_rand_gauss(random)); } // if(j==512)fprintf(ff,"%f\n",camp(fftch[i])); } ch_fft_n[offset+j]=n; ch_fft_p[offset+j]=p; } // fclose(ff); logmsg("iFFT"); fftwf_execute(ifft_plan); #pragma omp parallel for schedule(static,2) shared(buffer,clean) for (uint64_t j = 0; j < nchan ; j+=BLK){ for (uint64_t i = 0; i < nsamp_per_block ; i++){ for (uint64_t k = 0; k < BLK ; k++){ clean[j+k][i]/=(float)fftX; buffer[i*nchan+j+k] = round(clean[j+k][i]); } } if(j==512){ cpgopen("2/xs"); cpgsvp(0.1,0.9,0.1,0.9); cpgswin(0,fftX,ch_mean[j]-sqrt(ch_var[j])*10,ch_mean[j]+sqrt(ch_var[j])*10); cpgbox("ABN",0,0,"ABN",0,0); cpgline(fftX,X,data[j]); cpgsci(2); cpgline(fftX,X,clean[j]); cpgclos(); } } fwrite(buffer,1,bytes_per_block,of); for (uint64_t i = 0; i < nsamp_per_block ; i++){ tseries[i]=0; } tmean=0; tvar=0; max=0; min=1e99; //#pragma omp parallel for shared(clean,tseries) // NOT THREAD SAFE for (uint64_t j = 0; j < nchan ; j++){ tmean+=ch_mean[offset+j]; tvar+=ch_var[offset+j]; for (uint64_t i = 0; i < nsamp_per_block ; i++){ tseries[i]+=clean[j][i]; if(clean[j][i]>max)max=clean[j][i]; if(clean[j][i]<min)min=clean[j][i]; } } ss=0; mm=0; for (uint64_t i = 0; i < nsamp_per_block ; i++){ float x=tseries[i]-tmean; mm+=tseries[i]; ss+=x*x; } rvar=ss/(float)nsamp_per_block; logmsg("var=%g tvar=%g",ss/(float)nsamp_per_block,tvar); logmsg("mean=%g tmean=%g",mm/(float)nsamp_per_block,tmean); cpgopen("5/xs"); cpgsvp(0.1,0.9,0.1,0.9); cpgswin(0,fftX,tmean-sqrt(tvar)*30,tmean+sqrt(tvar)*30); cpgbox("ABN",0,0,"ABN",0,0); cpgline(fftX,X,tseries); cpgsci(2); cpgclos(); tr[0] = 0.0 ; tr[1] = 1; tr[2] = 0; tr[3] = 0.5; tr[4] = 0; tr[5] = 1; logmsg("max=%g min=%g",max,min); cpgopen("6/xs"); cpgsvp(0.1,0.9,0.1,0.9); cpgswin(0,nsamp_per_block,0,nchan); cpgbox("ABN",0,0,"ABN",0,0); cpggray(*clean,nsamp_per_block,nchan,1,nsamp_per_block,1,nchan,tmean/(float)nchan+sqrt(rvar/(float)nchan),tmean/(float)nchan-sqrt(rvar/(float)nchan),tr); cpgclos(); stop_clock(t_spec); for (uint64_t j = 0; j < nchan ; j++){ float mean=ch_mean[offset+j]; if (mean > max_mean)max_mean=mean; if (mean < min_mean)min_mean=mean; float var=ch_var[offset+j]; if (var > max_var)max_var=var; if (var < min_var)min_var=var; float fft_n=ch_fft_n[offset+j]; if (fft_n > max_fft_n)max_fft_n=fft_n; if (fft_n < min_fft_n)min_fft_n=fft_n; float fft_p=ch_fft_p[offset+j]; if (fft_p > max_fft_p)max_fft_p=fft_p; if (fft_p < min_fft_p)min_fft_p=fft_p; } } stop_clock(t_all); fclose(of); logmsg("T(all) = %.2lfs",read_clock(t_all)); logmsg("T(read) = %.2lfs",read_clock(t_read)); logmsg("T(trans)= %.2lfs",read_clock(t_trns)); logmsg("T(fft) = %.2lfs",read_clock(t_fft)); logmsg("T(fan) = %.2lfs",read_clock(t_spec)); logmsg("T(rms) = %.2lfs",read_clock(t_rms)); logmsg("T(rest) = %.2lfs",read_clock(t_all)-read_clock(t_read)-read_clock(t_trns)-read_clock(t_rms)-read_clock(t_fft)-read_clock(t_spec)); tr[0] = -tsamp*nsamp_per_block*0.5; tr[2] = tsamp*nsamp_per_block; tr[1] = 0; tr[3] = 0.5; tr[5] = 0; tr[4] = 1; cpgopen("1/xs"); cpgsvp(0.1,0.9,0.1,0.9); cpgswin(0,nblocks*tsamp*nsamp_per_block,0,nchan); cpgbox("ABN",600,10,"ABN",100,1); cpggray(ch_mean,nchan,nblocks,1,nchan,1,nblocks,max_mean,min_mean,tr); cpgclos(); cpgopen("2/xs"); cpgsvp(0.1,0.9,0.1,0.9); cpgswin(0,nblocks*tsamp*nsamp_per_block,0,nchan); cpgbox("ABN",600,10,"ABN",100,1); cpggray(ch_var,nchan,nblocks,1,nchan,1,nblocks,max_var,min_var,tr); cpgclos(); cpgopen("3/xs"); cpgsvp(0.1,0.9,0.1,0.9); cpgswin(0,nblocks*tsamp*nsamp_per_block,0,nchan); cpgbox("ABN",600,10,"ABN",100,1); cpggray(ch_fft_n,nchan,nblocks,1,nchan,1,nblocks,max_fft_n,min_fft_n,tr); cpgclos(); cpgopen("4/xs"); cpgsvp(0.1,0.9,0.1,0.9); cpgswin(0,nblocks*tsamp*nsamp_per_block,0,nchan); cpgbox("ABN",600,10,"ABN",100,1); cpggray(ch_fft_p,nchan,nblocks,1,nchan,1,nblocks,max_fft_p,min_fft_p,tr); cpgclos(); cpgopen("mean.ps/vcps"); cpgsvp(0.1,0.9,0.1,0.9); cpgswin(0,nblocks*tsamp*nsamp_per_block,0,nchan); cpgbox("ABN",600,10,"ABN",100,1); cpggray(ch_mean,nchan,nblocks,1,nchan,1,nblocks,max_mean,min_mean,tr); cpgclos(); cpgopen("var.ps/vcps"); cpgsvp(0.1,0.9,0.1,0.9); cpgswin(0,nblocks*tsamp*nsamp_per_block,0,nchan); cpgbox("ABN",600,10,"ABN",100,1); cpggray(ch_var,nchan,nblocks,1,nchan,1,nblocks,max_var,min_var,tr); cpgclos(); cpgopen("fft_n.ps/vcps"); cpgsvp(0.1,0.9,0.1,0.9); cpgswin(0,nblocks*tsamp*nsamp_per_block,0,nchan); cpgbox("ABN",600,10,"ABN",100,1); cpggray(ch_fft_n,nchan,nblocks,1,nchan,1,nblocks,max_fft_n,min_fft_n,tr); cpgclos(); cpgopen("fft_p.ps/vcps"); cpgsvp(0.1,0.9,0.1,0.9); cpgswin(0,nblocks*tsamp*nsamp_per_block,0,nchan); cpgbox("ABN",600,10,"ABN",100,1); cpggray(ch_fft_p,nchan,nblocks,1,nchan,1,nblocks,max_fft_p,min_fft_p,tr); cpgclos(); fclose(f); free(buffer); free_2df(data); return 0; }
int main() { /* Set up the lookup table. */ const int M = 2; const int K[] = {K1, K2}; const int map[] = {0, 1}; const double crval[] = {135.0, 95.0}; char text[80]; int ci, i, ilat, ilng, j, k, m, stat[K2][K1], status; float xr[361], yr[361]; double *dp, world[361][2], x[K1], xy[361][2], y[K2]; struct tabprm tab; struct prjprm prj; printf( "Testing WCSLIB inverse coordinate lookup table routines (ttab3.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); cpgwnad(-135.0f, 135.0f, -95.0f, 140.0f); cpgbox("BC", 0.0f, 0, "BC", 0.0f, 0); cpgscr(0, 0.00f, 0.00f, 0.00f); cpgscr(1, 1.00f, 1.00f, 0.00f); cpgscr(2, 1.00f, 1.00f, 1.00f); cpgscr(3, 0.50f, 0.50f, 0.80f); cpgscr(4, 0.80f, 0.50f, 0.50f); cpgscr(5, 0.80f, 0.80f, 0.80f); cpgscr(6, 0.50f, 0.50f, 0.80f); cpgscr(7, 0.80f, 0.50f, 0.50f); cpgscr(8, 0.30f, 0.50f, 0.30f); /* 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; } } /* Set up the lookup table to approximate Bonne's projection. */ for (i = 0; i < K1; i++) { x[i] = 135 - i; } for (j = 0; j < K2; j++) { y[j] = j - 95; } prjini(&prj); prj.pv[1] = 35.0; status = bonx2s(&prj, K1, K2, 1, 2, x, y, tab.coord, tab.coord+1, (int *)stat); dp = tab.coord; for (j = 0; j < K2; j++) { for (i = 0; i < K1; i++) { if (stat[j][i]) { *dp = 999.0; *(dp+1) = 999.0; } dp += 2; } } /* Draw meridians. */ ci = 1; for (ilng = -180; ilng <= 180; ilng += 15) { if (++ci > 7) ci = 2; cpgsci(ilng?ci:1); for (j = 0, ilat = -90; ilat <= 90; ilat++, j++) { world[j][0] = (double)ilng; world[j][1] = (double)ilat; } /* A fudge to account for the singularity at the poles. */ world[0][0] = 0.0; world[180][0] = 0.0; status = tabs2x(&tab, 181, 2, (double *)world, (double *)xy, (int *)stat); k = 0; for (j = 0; j < 181; j++) { if (stat[0][j]) { if (k > 1) cpgline(k, xr, yr); k = 0; continue; } xr[k] = xy[j][0]; yr[k] = xy[j][1]; k++; } cpgline(k, xr, yr); } /* Draw parallels. */ ci = 1; for (ilat = -75; ilat <= 75; ilat += 15) { if (++ci > 7) ci = 2; cpgsci(ilat?ci:1); for (j = 0, ilng = -180; ilng <= 180; ilng++, j++) { world[j][0] = (double)ilng; world[j][1] = (double)ilat; } status = tabs2x(&tab, 361, 2, (double *)world, (double *)xy, (int *)stat); k = 0; for (j = 0; j < 361; j++) { if (stat[0][j]) { if (k > 1) cpgline(k, xr, yr); k = 0; continue; } xr[k] = xy[j][0]; yr[k] = xy[j][1]; k++; } cpgline(k, xr, yr); } cpgend(); return 0; }
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; }
int main(int argc, char *argv[]) { float *x=NULL,*y=NULL,minx,maxx,miny,maxy,cx, *oparams=NULL,*nparams=NULL; float *rx=NULL,*ry=NULL,*w=NULL,*wparams=NULL,*wx=NULL,*wy=NULL,*ww=NULL; float *y_sault_fit=NULL, *x_fit=NULL, *y_new_fit=NULL, *y_reynolds_fit=NULL; float *y_stevens_fit=NULL,*y_whole_fit=NULL,*y_old_fit=NULL; int i,j,n=0,n_fit=100,new_fit_order=2,whole_fit_order=5,nr=0,nw=0; /* float extra_x[NEXTRA]={ 93, 95 }, extra_y[NEXTRA] = { 0.1223, 0.1168 }; */ float extra_x[NEXTRA]= { 93, 95 }, extra_y[NEXTRA] = { 0.1116, 0.1056 }; float extra_u[NEXTRA]= { 0.01356, 0.01399 }; float fitp_sault[NFIT_SAULT]= { -202.6259, 149.7321, -36.4943, 2.9372 }; float fitp_reynolds[NFIT_REYNOLDS]= { -30.7667, 26.4908, -7.0977, 0.605334 }; float fitp_stevens[NFIT_STEVENS]= { -1.237160, 2.005317, -0.400622 }; float fitp_old[NFIT_OLD]= { -23.839, 19.569, -4.8168, 0.35836 }; float *ratio_reynolds_fit=NULL,*ratio_stevens_fit=NULL,*ratio_sault_fit=NULL; float *ratio_new_fit=NULL; float vpx1, vpx2, vpy1, vpy2, vpy3, lx, ly, dly; char fitlabel[BUFSIZE]; /* Generate the cm fit points. */ for (cx=1.0; cx<10.0; cx+=0.1) { nr++; rx = realloc(rx, nr * sizeof(float)); ry = realloc(ry, nr * sizeof(float)); rx[nr-1] = log10f(cx * 1000); ry[nr-1] = 0.0; for (i=0; i<NFIT_REYNOLDS; i++) { ry[nr-1] += fitp_reynolds[i] * powf(rx[n-1], (float)i); } } /* Generate the 15mm fit points. */ for (cx=10.0; cx<=24.0; cx+=0.128) { n++; x = realloc(x, n * sizeof(float)); y = realloc(y, n * sizeof(float)); w = realloc(w, n * sizeof(float)); x[n-1] = log10f(cx * 1000); y[n-1] = 0.0; for (i=0; i<NFIT_REYNOLDS; i++) { y[n-1] += fitp_sault[i] * powf(x[n-1], (float)i); } w[n-1] = 1.0/0.1; } /* Do the fit. */ linfit_order(NFIT_SAULT, n, x, y, w, &oparams); for (i=0; i<NFIT_SAULT; i++) { printf("i = %d c[i] = %.4f\n", i, oparams[i]); } /* Add the 3mm flux points. */ for (i=0; i<NEXTRA; i++) { n++; x = realloc(x, n * sizeof(float)); y = realloc(y, n * sizeof(float)); w = realloc(w, n * sizeof(float)); x[n-1] = log10f(extra_x[i] * 1000); y[n-1] = log10f(extra_y[i]); w[n-1] = 1/extra_u[i]; } /* Do another fit. */ linfit_order(new_fit_order, n, x, y, w, &nparams); for (i=0; i<new_fit_order; i++) { printf("i = %d nc[i] = %.4f\n", i, nparams[i]); } /* Generate the whole range fit points. */ minx=log10f(900); maxx=log10f(100000); miny=-2; maxy=log10f(20); x_fit = malloc(n_fit * sizeof(float)); for (i=0; i<n_fit; i++) { x_fit[i] = minx + i * ((maxx - minx)/(float)n_fit); nw++; wx = realloc(wx, nw * sizeof(float)); wy = realloc(wy, nw * sizeof(float)); ww = realloc(ww, nw * sizeof(float)); wx[nw-1] = x_fit[i]; wy[nw-1] = 0.0; ww[nw-1] = 1; if (x_fit[i] < log10f(11143)) { /* Use the Reynolds fit. */ for (j=0; j<NFIT_REYNOLDS; j++) { wy[nw-1] += fitp_reynolds[j] * powf(x_fit[i], (float)j); } } else { /* Use the new fit. */ for (j=0; j<new_fit_order; j++) { wy[nw-1] += nparams[j] * powf(x_fit[i], (float)j); } } } /* Do a whole-range fit. */ linfit_order(whole_fit_order, nw, wx, wy, ww, &wparams); for (i=0; i<whole_fit_order; i++) { printf("i = %d wc[i] = %.4f\n", i, wparams[i]); } // minmax(n, x, &minx, &maxx); // minmax(n, y, &miny, &maxy); y_sault_fit = malloc(n_fit * sizeof(float)); y_reynolds_fit = malloc(n_fit * sizeof(float)); y_stevens_fit = malloc(n_fit * sizeof(float)); y_new_fit = malloc(n_fit * sizeof(float)); y_whole_fit = malloc(n_fit * sizeof(float)); y_old_fit = malloc(n_fit * sizeof(float)); ratio_reynolds_fit = malloc(n_fit * sizeof(float)); ratio_stevens_fit = malloc(n_fit * sizeof(float)); ratio_sault_fit = malloc(n_fit * sizeof(float)); ratio_new_fit = malloc(n_fit * sizeof(float)); /* minx=log10f(50); */ minx=log10f(1000); /* maxx=log10f(500000); */ maxx=log10f(110000); for (i=0; i<n_fit; i++) { x_fit[i] = minx + i * ((maxx - minx)/(float)n_fit); y_sault_fit[i] = 0.0; y_reynolds_fit[i] = 0.0; y_new_fit[i] = 0.0; y_stevens_fit[i] = 0.0; y_whole_fit[i] = 0.0; y_old_fit[i] = 0.0; for (j=0; j<NFIT_SAULT; j++) { y_sault_fit[i] += fitp_sault[j] * powf(x_fit[i], (float)j); } for (j=0; j<NFIT_REYNOLDS; j++) { y_reynolds_fit[i] += fitp_reynolds[j] * powf(x_fit[i], (float)j); } for (j=0; j<NFIT_STEVENS; j++) { y_stevens_fit[i] += fitp_stevens[j] * powf(x_fit[i], (float)j); } for (j=0; j<new_fit_order; j++) { y_new_fit[i] += nparams[j] * powf(x_fit[i], (float)j); } for (j=0; j<whole_fit_order; j++) { y_whole_fit[i] += wparams[j] * powf(x_fit[i], (float)j); } for (j=0; j<NFIT_OLD; j++) { y_old_fit[i] += fitp_old[j] * powf(x_fit[i], (float)j); } ratio_reynolds_fit[i] = powf(10, (y_reynolds_fit[i] - y_whole_fit[i])); ratio_stevens_fit[i] = powf(10, (y_stevens_fit[i] - y_whole_fit[i])); ratio_sault_fit[i] = powf(10, (y_sault_fit[i] - y_whole_fit[i])); ratio_new_fit[i] = powf(10, (y_new_fit[i] - y_whole_fit[i])); } /* cpgopen("11/xs"); */ cpgopen("1934-638_models.ps/cps"); /* cpgopen("1934-638_models.png/png"); */ cpgqvp(0, &vpx1, &vpx2, &vpy1, &vpy2); vpy3 = vpy1 + (vpy2 - vpy1) / 5.0; /* cpgsvp(vpx1, vpx2, vpy3, vpy2); */ cpgswin(minx, maxx, miny, maxy); lx = minx + (maxx - minx) / 9.0; ly = miny + (maxy - miny) / 3.0; dly = (maxy - miny) / 20.0; cpgsch(1.0); cpgbox("BCLNTS",0,0,"BCLNTS",0,0); cpglab("Frequency (MHz)", "Flux Density (Jy)", "1934-638 Model Comparison"); cpgsch(0.8); cpgpt(n, x, y, 4); /* cpgpt(nw, wx, wy, 4); */ cpgsci(2); /* cpgpt(nr, rx, ry, 4); */ cpgline(n_fit, x_fit, y_sault_fit); strcpy(fitlabel, "Sault: "); fitstring(fitp_sault, NFIT_SAULT, fitlabel); cpgtext(lx, ly, fitlabel); cpgsci(3); cpgline(n_fit, x_fit, y_new_fit); strcpy(fitlabel, "Stevens (linear): "); fitstring(nparams, new_fit_order, fitlabel); ly -= dly; cpgtext(lx, ly, fitlabel); cpgsci(4); cpgline(n_fit, x_fit, y_reynolds_fit); strcpy(fitlabel, "Reynolds: "); fitstring(fitp_reynolds, NFIT_REYNOLDS, fitlabel); ly -= dly; cpgtext(lx, ly, fitlabel); cpgsci(5); cpgline(n_fit, x_fit, y_stevens_fit); strcpy(fitlabel, "Stevens (Miriad): "); fitstring(fitp_stevens, NFIT_STEVENS, fitlabel); ly -= dly; cpgtext(lx, ly, fitlabel); cpgsci(6); cpgline(n_fit, x_fit, y_old_fit); strcpy(fitlabel, "Pre-1994: "); fitstring(fitp_old, NFIT_OLD, fitlabel); ly -= dly; cpgtext(lx, ly, fitlabel); /* cpgsci(6); */ /* cpgline(n_fit, x_fit, y_whole_fit); */ /* strcpy(fitlabel, "Stevens (New): "); */ /* fitstring(wparams, whole_fit_order, fitlabel); */ /* ly -= dly; */ /* cpgtext(lx, ly, fitlabel); */ /* cpgsvp(vpx1, vpx2, vpy1, vpy3); */ /* cpgsci(1); */ /* cpgswin(minx, maxx, 0.9, 1.1); */ /* cpgsch(1.0); */ /* cpgbox("BCLNTS",0,0,"BCMTS",0,0); */ /* cpglab("Frequency (MHz)", "Model Ratio", ""); */ /* cpgsci(2); */ /* cpgline(n_fit, x_fit, ratio_sault_fit); */ /* cpgsci(3); */ /* cpgline(n_fit, x_fit, ratio_new_fit); */ /* cpgsci(4); */ /* cpgline(n_fit, x_fit, ratio_reynolds_fit); */ /* cpgsci(5); */ /* cpgline(n_fit, x_fit, ratio_stevens_fit); */ cpgclos(); exit(0); }
void rfifind_plot(int numchan, int numint, int ptsperint, float timesigma, float freqsigma, float inttrigfrac, float chantrigfrac, float **dataavg, float **datastd, float **datapow, int *userchan, int numuserchan, int *userints, int numuserints, infodata * idata, unsigned char **bytemask, mask * oldmask, mask * newmask, rfi * rfivect, int numrfi, int rfixwin, int rfips, int xwin) /* Make the beautiful multi-page rfifind plots */ { int ii, jj, ct, loops = 1; float *freqs, *chans, *times, *ints; float *avg_chan_avg, *std_chan_avg, *pow_chan_avg; float *avg_chan_med, *std_chan_med, *pow_chan_med; float *avg_chan_std, *std_chan_std, *pow_chan_std; float *avg_int_avg, *std_int_avg, *pow_int_avg; float *avg_int_med, *std_int_med, *pow_int_med; float *avg_int_std, *std_int_std, *pow_int_std; float dataavg_avg, datastd_avg, datapow_avg; float dataavg_med, datastd_med, datapow_med; float dataavg_std, datastd_std, datapow_std; float avg_reject, std_reject, pow_reject; double inttim, T, lof, hif; inttim = ptsperint * idata->dt; T = inttim * numint; lof = idata->freq - 0.5 * idata->chan_wid; hif = lof + idata->freqband; avg_chan_avg = gen_fvect(numchan); std_chan_avg = gen_fvect(numchan); pow_chan_avg = gen_fvect(numchan); avg_int_avg = gen_fvect(numint); std_int_avg = gen_fvect(numint); pow_int_avg = gen_fvect(numint); avg_chan_med = gen_fvect(numchan); std_chan_med = gen_fvect(numchan); pow_chan_med = gen_fvect(numchan); avg_int_med = gen_fvect(numint); std_int_med = gen_fvect(numint); pow_int_med = gen_fvect(numint); avg_chan_std = gen_fvect(numchan); std_chan_std = gen_fvect(numchan); pow_chan_std = gen_fvect(numchan); avg_int_std = gen_fvect(numint); std_int_std = gen_fvect(numint); pow_int_std = gen_fvect(numint); chans = gen_fvect(numchan); freqs = gen_fvect(numchan); for (ii = 0; ii < numchan; ii++) { chans[ii] = ii; freqs[ii] = idata->freq + ii * idata->chan_wid; } ints = gen_fvect(numint); times = gen_fvect(numint); for (ii = 0; ii < numint; ii++) { ints[ii] = ii; times[ii] = 0.0 + ii * inttim; } /* Calculate the statistics of the full set */ ct = numchan * numint; calc_avgmedstd(dataavg[0], ct, 0.8, 1, &dataavg_avg, &dataavg_med, &dataavg_std); calc_avgmedstd(datastd[0], ct, 0.8, 1, &datastd_avg, &datastd_med, &datastd_std); calc_avgmedstd(datapow[0], ct, 0.5, 1, &datapow_avg, &datapow_med, &datapow_std); avg_reject = timesigma * dataavg_std; std_reject = timesigma * datastd_std; pow_reject = power_for_sigma(freqsigma, 1, ptsperint / 2); /* Calculate the channel/integration statistics vectors */ for (ii = 0; ii < numint; ii++) { calc_avgmedstd(dataavg[0] + ii * numchan, numchan, 0.8, 1, avg_int_avg + ii, avg_int_med + ii, avg_int_std + ii); calc_avgmedstd(datastd[0] + ii * numchan, numchan, 0.8, 1, std_int_avg + ii, std_int_med + ii, std_int_std + ii); calc_avgmedstd(datapow[0] + ii * numchan, numchan, 0.5, 1, pow_int_avg + ii, pow_int_med + ii, pow_int_std + ii); } for (ii = 0; ii < numchan; ii++) { calc_avgmedstd(dataavg[0] + ii, numint, 0.8, numchan, avg_chan_avg + ii, avg_chan_med + ii, avg_chan_std + ii); calc_avgmedstd(datastd[0] + ii, numint, 0.8, numchan, std_chan_avg + ii, std_chan_med + ii, std_chan_std + ii); calc_avgmedstd(datapow[0] + ii, numint, 0.5, numchan, pow_chan_avg + ii, pow_chan_med + ii, pow_chan_std + ii); /* fprintf(stderr, "%12.7g %12.7g %12.7g %12.7g %12.7g %12.7g %12.7g %12.7g %12.7g \n", avg_chan_avg[ii], avg_chan_med[ii], avg_chan_std[ii], std_chan_avg[ii], std_chan_med[ii], std_chan_std[ii], pow_chan_avg[ii], pow_chan_med[ii], pow_chan_std[ii]); */ } /* Generate the byte mask */ /* Set the channels/intervals picked by the user */ if (numuserints) for (ii = 0; ii < numuserints; ii++) if (userints[ii] >= 0 && userints[ii] < numint) for (jj = 0; jj < numchan; jj++) bytemask[userints[ii]][jj] |= USERINTS; if (numuserchan) for (ii = 0; ii < numuserchan; ii++) if (userchan[ii] >= 0 && userchan[ii] < numchan) for (jj = 0; jj < numint; jj++) bytemask[jj][userchan[ii]] |= USERCHAN; /* Compare each point in an interval (or channel) with */ /* the interval's (or channel's) median and the overall */ /* standard deviation. If the channel/integration */ /* medians are more than sigma different than the global */ /* value, set them to the global. */ { float int_med, chan_med; for (ii = 0; ii < numint; ii++) { for (jj = 0; jj < numchan; jj++) { { /* Powers */ if (datapow[ii][jj] > pow_reject) if (!(bytemask[ii][jj] & PADDING)) bytemask[ii][jj] |= BAD_POW; } { /* Averages */ if (fabs(avg_int_med[ii] - dataavg_med) > timesigma * dataavg_std) int_med = dataavg_med; else int_med = avg_int_med[ii]; if (fabs(avg_chan_med[jj] - dataavg_med) > timesigma * dataavg_std) chan_med = dataavg_med; else chan_med = avg_chan_med[jj]; if (fabs(dataavg[ii][jj] - int_med) > avg_reject || fabs(dataavg[ii][jj] - chan_med) > avg_reject) if (!(bytemask[ii][jj] & PADDING)) bytemask[ii][jj] |= BAD_AVG; } { /* Standard Deviations */ if (fabs(std_int_med[ii] - datastd_med) > timesigma * datastd_std) int_med = datastd_med; else int_med = std_int_med[ii]; if (fabs(std_chan_med[jj] - datastd_med) > timesigma * datastd_std) chan_med = datastd_med; else chan_med = std_chan_med[jj]; if (fabs(datastd[ii][jj] - int_med) > std_reject || fabs(datastd[ii][jj] - chan_med) > std_reject) if (!(bytemask[ii][jj] & PADDING)) bytemask[ii][jj] |= BAD_STD; } } } } /* Step over the intervals and channels and count how many are set "bad". */ /* For a given interval, if the number of bad channels is greater than */ /* chantrigfrac*numchan then reject the whole interval. */ /* For a given channel, if the number of bad intervals is greater than */ /* inttrigfrac*numint then reject the whole channel. */ { int badnum, trignum; /* Loop over the intervals */ trignum = (int) (numchan * chantrigfrac); for (ii = 0; ii < numint; ii++) { if (!(bytemask[ii][0] & USERINTS)) { badnum = 0; for (jj = 0; jj < numchan; jj++) if (bytemask[ii][jj] & BADDATA) badnum++; if (badnum > trignum) { userints[numuserints++] = ii; for (jj = 0; jj < numchan; jj++) bytemask[ii][jj] |= USERINTS; } } } /* Loop over the channels */ trignum = (int) (numint * inttrigfrac); for (ii = 0; ii < numchan; ii++) { if (!(bytemask[0][ii] & USERCHAN)) { badnum = 0; for (jj = 0; jj < numint; jj++) if (bytemask[jj][ii] & BADDATA) badnum++; if (badnum > trignum) { userchan[numuserchan++] = ii; for (jj = 0; jj < numint; jj++) bytemask[jj][ii] |= USERCHAN; } } } } /* Generate the New Mask */ fill_mask(timesigma, freqsigma, idata->mjd_i + idata->mjd_f, ptsperint * idata->dt, idata->freq, idata->chan_wid, numchan, numint, ptsperint, numuserchan, userchan, numuserints, userints, bytemask, newmask); /* Place the oldmask over the newmask for plotting purposes */ if (oldmask->numchan) set_oldmask_bits(oldmask, bytemask); /* * Now plot the results */ if (xwin) loops = 2; for (ct = 0; ct < loops; ct++) { /* PS/XWIN Plot Loop */ float min, max, tr[6], locut, hicut; float left, right, top, bottom; float xl, xh, yl, yh; float tt, ft, th, fh; /* thin and fat thicknesses and heights */ float lm, rm, tm, bm; /* LRTB margins */ float xarr[2], yarr[2]; char outdev[100]; int ii, mincol, maxcol, numcol; /*Set the PGPLOT device to an X-Window */ if (ct == 1) strcpy(outdev, "/XWIN"); else sprintf(outdev, "%s.ps/CPS", idata->name); /* Open and prep our device */ cpgopen(outdev); cpgpap(10.25, 8.5 / 11.0); cpgpage(); cpgiden(); cpgsch(0.7); cpgqcir(&mincol, &maxcol); numcol = maxcol - mincol + 1; for (ii = mincol; ii <= maxcol; ii++) { float color; color = (float) (maxcol - ii) / (float) numcol; cpgscr(ii, color, color, color); } /* Set thicknesses and margins */ lm = 0.04; rm = 0.04; bm = 0.08; tm = 0.05; ft = 3.0; /* This sets fat thickness = 3 x thin thickness */ tt = 0.92 / (6.0 + 4.0 * ft); ft *= tt; fh = 0.55; th = tt * 11.0 / 8.5; { /* Powers Histogram */ float *theo, *hist, *hpows, *tpows, maxhist = 0.0, maxtheo = 0.0; int numhist = 40, numtheo = 200, bin, numpows; double dtheo, dhist, spacing; /* Calculate the predicted distribution of max powers */ numpows = numint * numchan; find_min_max_arr(numpows, datapow[0], &min, &max); min = (min < 5.0) ? log10(5.0 * 0.95) : log10(min * 0.95); max = log10(max * 1.05); dhist = (max - min) / numhist; theo = gen_fvect(numtheo); tpows = gen_fvect(numtheo); hist = gen_fvect(numhist); hpows = gen_fvect(numhist); for (ii = 0; ii < numhist; ii++) { hist[ii] = 0.0; hpows[ii] = min + ii * dhist; } for (ii = 0; ii < numpows; ii++) { bin = (*(datapow[0] + ii) == 0.0) ? 0 : (log10(*(datapow[0] + ii)) - min) / dhist; if (bin < 0) bin = 0; if (bin >= numhist) bin = numhist; hist[bin] += 1.0; } for (ii = 0; ii < numhist; ii++) if (hist[ii] > maxhist) maxhist = hist[ii]; maxhist *= 1.1; dtheo = (max - min) / (double) (numtheo - 1); for (ii = 0; ii < numtheo; ii++) { tpows[ii] = min + ii * dtheo; theo[ii] = single_power_pdf(pow(10.0, tpows[ii]), ptsperint / 2) * numpows; spacing = (pow(10.0, tpows[ii] + dhist) - pow(10.0, tpows[ii])); theo[ii] *= spacing; if (theo[ii] > maxtheo) maxtheo = theo[ii]; } maxtheo *= 1.1; if (maxtheo > maxhist) maxhist = maxtheo; left = lm; right = lm + ft + tt; bottom = 0.80; top = 0.96; cpgsvp(left, right, bottom, top); xl = min; xh = max; yl = 0.0; yh = maxhist; cpgswin(xl, xh, yl, yh); cpgmtxt("L", 1.1, 0.5, 0.5, "Number"); cpgmtxt("B", 2.1, 0.5, 0.5, "Max Power"); cpgbin(numhist, hpows, hist, 0); cpgscr(maxcol, 0.5, 0.5, 0.5); cpgsci(maxcol); /* Grey */ cpgline(numtheo, tpows, theo); xarr[0] = log10(power_for_sigma(freqsigma, 1, ptsperint / 2)); xarr[1] = xarr[0]; yarr[0] = yl; yarr[1] = yh; cpgsls(4); /* Dotted line */ cpgscr(maxcol, 1.0, 0.0, 0.0); cpgsci(maxcol); /* Red */ cpgline(2, xarr, yarr); cpgsls(1); /* Solid line */ cpgsci(1); /* Default color */ cpgbox("BCLNST", 0.0, 0, "BC", 0.0, 0); vect_free(hist); vect_free(theo); vect_free(tpows); vect_free(hpows); } /* Maximum Powers */ left = lm; right = lm + ft; bottom = bm; top = bm + fh; xl = 0.0; xh = numchan; yl = 0.0; yh = T; cpgsvp(left, right, bottom, top); cpgswin(xl, xh, yl, yh); cpgscr(maxcol, 1.0, 0.0, 0.0); /* Red */ locut = 0.0; hicut = pow_reject; tr[2] = tr[4] = 0.0; tr[1] = (xh - xl) / numchan; tr[0] = xl - (tr[1] / 2); tr[5] = (yh - yl) / numint; tr[3] = yl - (tr[5] / 2); cpgimag(datapow[0], numchan, numint, 1, numchan, 1, numint, locut, hicut, tr); cpgswin(xl, xh, yl, yh); cpgbox("BNST", 0.0, 0, "BNST", 0.0, 0); cpgmtxt("B", 2.6, 0.5, 0.5, "Channel"); cpgmtxt("L", 2.1, 0.5, 0.5, "Time (s)"); xl = lof; xh = hif; yl = 0.0; yh = numint; cpgswin(xl, xh, yl, yh); cpgbox("CST", 0.0, 0, "CST", 0.0, 0); /* Max Power Label */ left = lm + ft; right = lm + ft + tt; bottom = bm + fh; top = bm + fh + th; cpgsvp(left, right, bottom, top); cpgswin(0.0, 1.0, 0.0, 1.0); cpgscr(maxcol, 1.0, 0.0, 0.0); cpgsci(maxcol); /* Red */ cpgptxt(0.5, 0.7, 0.0, 0.5, "Max"); cpgptxt(0.5, 0.3, 0.0, 0.5, "Power"); cpgsci(1); /* Default color */ /* Max Power versus Time */ left = lm + ft; right = lm + ft + tt; bottom = bm; top = bm + fh; cpgsvp(left, right, bottom, top); find_min_max_arr(numint, pow_int_med, &min, &max); xl = 0.0; xh = 1.5 * pow_reject; yl = 0.0; yh = T; cpgswin(xl, xh, yl, yh); cpgbox("BCST", 0.0, 0, "BST", 0.0, 0); cpgscr(maxcol, 1.0, 0.0, 0.0); cpgsci(maxcol); /* Red */ yarr[0] = yl; yarr[1] = yh; xarr[0] = xarr[1] = datapow_med; cpgline(2, xarr, yarr); cpgsls(4); /* Dotted line */ xarr[0] = xarr[1] = pow_reject; cpgline(2, xarr, yarr); cpgsls(1); /* Solid line */ cpgsci(1); /* Default color */ cpgline(numint, pow_int_med, times); yl = 0.0; yh = numint; cpgswin(xl, xh, yl, yh); cpgbox("", 0.0, 0, "CMST", 0.0, 0); /* cpgmtxt("R", 2.3, 0.5, 0.5, "Interval Number"); */ /* Max Power versus Channel */ left = lm; right = lm + ft; bottom = bm + fh; top = bm + fh + th; cpgsvp(left, right, bottom, top); find_min_max_arr(numchan, pow_chan_med, &min, &max); xl = 0.0; xh = numchan; yl = 0.0; yh = 1.5 * pow_reject; cpgswin(xl, xh, yl, yh); cpgbox("BST", 0.0, 0, "BCST", 0.0, 0); cpgscr(maxcol, 1.0, 0.0, 0.0); cpgsci(maxcol); /* Red */ xarr[0] = xl; xarr[1] = xh; yarr[0] = yarr[1] = datapow_med; cpgline(2, xarr, yarr); cpgsls(4); /* Dotted line */ yarr[0] = yarr[1] = pow_reject; cpgline(2, xarr, yarr); cpgsls(1); /* Solid line */ cpgsci(1); /* Default color */ cpgline(numchan, chans, pow_chan_med); xl = lof; xh = hif; cpgswin(xl, xh, yl, yh); cpgbox("CMST", 0.0, 0, "", 0.0, 0); cpgmtxt("T", 1.8, 0.5, 0.5, "Frequency (MHz)"); /* Standard Deviations */ left = lm + ft + 2.0 * tt; right = lm + 2.0 * ft + 2.0 * tt; bottom = bm; top = bm + fh; xl = 0.0; xh = numchan; yl = 0.0; yh = T; cpgsvp(left, right, bottom, top); cpgswin(xl, xh, yl, yh); cpgscr(mincol, 0.7, 1.0, 0.7); /* Light Green */ cpgscr(maxcol, 0.3, 1.0, 0.3); /* Dark Green */ locut = datastd_med - timesigma * datastd_std; hicut = datastd_med + timesigma * datastd_std; tr[2] = tr[4] = 0.0; tr[1] = (xh - xl) / numchan; tr[0] = xl - (tr[1] / 2); tr[5] = (yh - yl) / numint; tr[3] = yl - (tr[5] / 2); cpgimag(datastd[0], numchan, numint, 1, numchan, 1, numint, locut, hicut, tr); cpgswin(xl, xh, yl, yh); cpgbox("BNST", 0.0, 0, "BNST", 0.0, 0); cpgmtxt("B", 2.6, 0.5, 0.5, "Channel"); xl = lof; xh = hif; yl = 0.0; yh = numint; cpgswin(xl, xh, yl, yh); cpgbox("CST", 0.0, 0, "CST", 0.0, 0); /* Data Sigma Label */ left = lm + 2.0 * ft + 2.0 * tt; right = lm + 2.0 * ft + 3.0 * tt; bottom = bm + fh; top = bm + fh + th; cpgsvp(left, right, bottom, top); cpgswin(0.0, 1.0, 0.0, 1.0); cpgscr(maxcol, 0.0, 1.0, 0.0); cpgsci(maxcol); /* Green */ cpgptxt(0.5, 0.7, 0.0, 0.5, "Data"); cpgptxt(0.5, 0.3, 0.0, 0.5, "Sigma"); cpgsci(1); /* Default color */ /* Data Sigma versus Time */ left = lm + 2.0 * ft + 2.0 * tt; right = lm + 2.0 * ft + 3.0 * tt; bottom = bm; top = bm + fh; cpgsvp(left, right, bottom, top); xl = datastd_med - 2.0 * std_reject; xh = datastd_med + 2.0 * std_reject; yl = 0.0; yh = T; cpgswin(xl, xh, yl, yh); cpgbox("BCST", 0.0, 0, "BST", 0.0, 0); cpgscr(maxcol, 0.0, 1.0, 0.0); cpgsci(maxcol); /* Green */ yarr[0] = yl; yarr[1] = yh; xarr[0] = xarr[1] = datastd_med; cpgline(2, xarr, yarr); cpgsls(4); /* Dotted line */ xarr[0] = xarr[1] = datastd_med + std_reject; cpgline(2, xarr, yarr); xarr[0] = xarr[1] = datastd_med - std_reject; cpgline(2, xarr, yarr); cpgsls(1); /* Solid line */ cpgsci(1); /* Default color */ cpgline(numint, std_int_med, times); yl = 0.0; yh = numint; cpgswin(xl, xh, yl, yh); cpgbox("", 0.0, 0, "CMST", 0.0, 0); /* cpgmtxt("R", 2.3, 0.5, 0.5, "Interval Number"); */ /* Data Sigma versus Channel */ left = lm + ft + 2.0 * tt; right = lm + 2.0 * ft + 2.0 * tt; bottom = bm + fh; top = bm + fh + th; cpgsvp(left, right, bottom, top); xl = 0.0; xh = numchan; yl = datastd_med - 2.0 * std_reject; yh = datastd_med + 2.0 * std_reject; cpgswin(xl, xh, yl, yh); cpgbox("BST", 0.0, 0, "BCST", 0.0, 0); cpgscr(maxcol, 0.0, 1.0, 0.0); cpgsci(maxcol); /* Green */ xarr[0] = xl; xarr[1] = xh; yarr[0] = yarr[1] = datastd_med; cpgline(2, xarr, yarr); cpgsls(4); /* Dotted line */ yarr[0] = yarr[1] = datastd_med + std_reject; cpgline(2, xarr, yarr); yarr[0] = yarr[1] = datastd_med - std_reject; cpgline(2, xarr, yarr); cpgsls(1); /* Solid line */ cpgsci(1); /* Default color */ cpgline(numchan, chans, std_chan_med); xl = lof; xh = hif; cpgswin(xl, xh, yl, yh); cpgbox("CMST", 0.0, 0, "", 0.0, 0); cpgmtxt("T", 1.8, 0.5, 0.5, "Frequency (MHz)"); /* Data Mean */ left = lm + 2.0 * ft + 4.0 * tt; right = lm + 3.0 * ft + 4.0 * tt; bottom = bm; top = bm + fh; xl = 0.0; xh = numchan; yl = 0.0; yh = T; cpgsvp(left, right, bottom, top); cpgswin(xl, xh, yl, yh); cpgscr(mincol, 0.7, 0.7, 1.0); /* Light Blue */ cpgscr(maxcol, 0.3, 0.3, 1.0); /* Dark Blue */ locut = dataavg_med - timesigma * dataavg_std; hicut = dataavg_med + timesigma * dataavg_std; tr[2] = tr[4] = 0.0; tr[1] = (xh - xl) / numchan; tr[0] = xl - (tr[1] / 2); tr[5] = (yh - yl) / numint; tr[3] = yl - (tr[5] / 2); cpgimag(dataavg[0], numchan, numint, 1, numchan, 1, numint, locut, hicut, tr); cpgswin(xl, xh, yl, yh); cpgbox("BNST", 0.0, 0, "BNST", 0.0, 0); cpgmtxt("B", 2.6, 0.5, 0.5, "Channel"); xl = lof; xh = hif; yl = 0.0; yh = numint; cpgswin(xl, xh, yl, yh); cpgbox("CST", 0.0, 0, "CST", 0.0, 0); /* Data Mean Label */ left = lm + 3.0 * ft + 4.0 * tt; right = lm + 3.0 * ft + 5.0 * tt; bottom = bm + fh; top = bm + fh + th; cpgsvp(left, right, bottom, top); cpgswin(0.0, 1.0, 0.0, 1.0); cpgscr(maxcol, 0.0, 0.0, 1.0); cpgsci(maxcol); /* Blue */ cpgptxt(0.5, 0.7, 0.0, 0.5, "Data"); cpgptxt(0.5, 0.3, 0.0, 0.5, "Mean"); cpgsci(1); /* Default color */ /* Data Mean versus Time */ left = lm + 3.0 * ft + 4.0 * tt; right = lm + 3.0 * ft + 5.0 * tt; bottom = bm; top = bm + fh; cpgsvp(left, right, bottom, top); xl = dataavg_med - 2.0 * avg_reject; xh = dataavg_med + 2.0 * avg_reject; yl = 0.0; yh = T; cpgswin(xl, xh, yl, yh); cpgbox("BCST", 0.0, 0, "BST", 0.0, 0); cpgscr(maxcol, 0.0, 0.0, 1.0); cpgsci(maxcol); /* Blue */ yarr[0] = yl; yarr[1] = yh; xarr[0] = xarr[1] = dataavg_med; cpgline(2, xarr, yarr); cpgsls(4); /* Dotted line */ xarr[0] = xarr[1] = dataavg_med + avg_reject; cpgline(2, xarr, yarr); xarr[0] = xarr[1] = dataavg_med - avg_reject; cpgline(2, xarr, yarr); cpgsls(1); /* Solid line */ cpgsci(1); /* Default color */ cpgline(numint, avg_int_med, times); yl = 0.0; yh = numint; cpgswin(xl, xh, yl, yh); cpgbox("", 0.0, 0, "CMST", 0.0, 0); /* Data Mean versus Channel */ left = lm + 2.0 * ft + 4.0 * tt; right = lm + 3.0 * ft + 4.0 * tt; bottom = bm + fh; top = bm + fh + th; cpgsvp(left, right, bottom, top); xl = 0.0; xh = numchan; yl = dataavg_med - 2.0 * avg_reject; yh = dataavg_med + 2.0 * avg_reject; cpgswin(xl, xh, yl, yh); cpgbox("BST", 0.0, 0, "BCST", 0.0, 0); cpgscr(maxcol, 0.0, 0.0, 1.0); cpgsci(maxcol); /* Blue */ xarr[0] = xl; xarr[1] = xh; yarr[0] = yarr[1] = dataavg_med; cpgline(2, xarr, yarr); cpgsls(4); /* Dotted line */ yarr[0] = yarr[1] = dataavg_med + avg_reject; cpgline(2, xarr, yarr); yarr[0] = yarr[1] = dataavg_med - avg_reject; cpgline(2, xarr, yarr); cpgsls(1); /* Solid line */ cpgsci(1); /* Default color */ cpgline(numchan, chans, avg_chan_med); xl = lof; xh = hif; cpgswin(xl, xh, yl, yh); cpgbox("CMST", 0.0, 0, "", 0.0, 0); cpgmtxt("T", 1.8, 0.5, 0.5, "Frequency (MHz)"); { /* Add the Data Info area */ char out[200], out2[100]; float dy = 0.025; cpgsvp(0.0, 1.0, 0.0, 1.0); cpgswin(0.0, 1.0, 0.0, 1.0); left = lm + ft + 1.5 * tt; top = 1.0 - tm; cpgsch(1.0); sprintf(out, "%-s", idata->name); cpgptxt(0.5, 1.0 - 0.5 * tm, 0.0, 0.5, out); cpgsch(0.8); sprintf(out, "Object:"); cpgtext(left + 0.0, top - 0 * dy, out); sprintf(out, "%-s", idata->object); cpgtext(left + 0.1, top - 0 * dy, out); sprintf(out, "Telescope:"); cpgtext(left + 0.0, top - 1 * dy, out); sprintf(out, "%-s", idata->telescope); cpgtext(left + 0.1, top - 1 * dy, out); sprintf(out, "Instrument:"); cpgtext(left + 0.0, top - 2 * dy, out); sprintf(out, "%-s", idata->instrument); cpgtext(left + 0.1, top - 2 * dy, out); ra_dec_to_string(out2, idata->ra_h, idata->ra_m, idata->ra_s); sprintf(out, "RA\\dJ2000\\u"); cpgtext(left + 0.0, top - 3 * dy, out); sprintf(out, "= %-s", out2); cpgtext(left + 0.08, top - 3 * dy, out); ra_dec_to_string(out2, idata->dec_d, idata->dec_m, idata->dec_s); sprintf(out, "DEC\\dJ2000\\u"); cpgtext(left + 0.0, top - 4 * dy, out); sprintf(out, "= %-s", out2); cpgtext(left + 0.08, top - 4 * dy, out); sprintf(out, "Epoch\\dtopo\\u"); cpgtext(left + 0.0, top - 5 * dy, out); sprintf(out, "= %-.11f", idata->mjd_i + idata->mjd_f); cpgtext(left + 0.08, top - 5 * dy, out); sprintf(out, "T\\dsample\\u (s)"); cpgtext(left + 0.0, top - 6 * dy, out); sprintf(out, "= %g", idata->dt); cpgtext(left + 0.08, top - 6 * dy, out); sprintf(out, "T\\dtotal\\u (s)"); cpgtext(left + 0.0, top - 7 * dy, out); sprintf(out, "= %g", T); cpgtext(left + 0.08, top - 7 * dy, out); left = lm + ft + 7.8 * tt; sprintf(out, "Num channels"); cpgtext(left + 0.0, top - 0 * dy, out); sprintf(out, "= %-d", numchan); cpgtext(left + 0.12, top - 0 * dy, out); sprintf(out, "Pts per int"); cpgtext(left + 0.19, top - 0 * dy, out); sprintf(out, "= %-d", ptsperint); cpgtext(left + 0.29, top - 0 * dy, out); sprintf(out, "Num intervals"); cpgtext(left + 0.0, top - 1 * dy, out); sprintf(out, "= %-d", numint); cpgtext(left + 0.12, top - 1 * dy, out); sprintf(out, "Time per int"); cpgtext(left + 0.19, top - 1 * dy, out); sprintf(out, "= %-g", inttim); cpgtext(left + 0.29, top - 1 * dy, out); sprintf(out, "Power:"); cpgtext(left + 0.0, top - 2 * dy, out); sprintf(out, "median"); cpgtext(left + 0.06, top - 2 * dy, out); sprintf(out, "= %-.3f", datapow_med); cpgtext(left + 0.12, top - 2 * dy, out); sprintf(out, "\\gs"); cpgtext(left + 0.21, top - 2 * dy, out); sprintf(out, "= %-.3g", datapow_std); cpgtext(left + 0.245, top - 2 * dy, out); find_min_max_arr(numint * numchan, datapow[0], &min, &max); sprintf(out, "min"); cpgtext(left + 0.06, top - 3 * dy, out); sprintf(out, "= %-.3f", min); cpgtext(left + 0.12, top - 3 * dy, out); sprintf(out, "max"); cpgtext(left + 0.21, top - 3 * dy, out); sprintf(out, "= %-.3f", max); cpgtext(left + 0.245, top - 3 * dy, out); sprintf(out, "Sigma:"); cpgtext(left + 0.0, top - 4 * dy, out); sprintf(out, "median"); cpgtext(left + 0.06, top - 4 * dy, out); sprintf(out, "= %-.3f", datastd_med); cpgtext(left + 0.12, top - 4 * dy, out); sprintf(out, "\\gs"); cpgtext(left + 0.21, top - 4 * dy, out); sprintf(out, "= %-.3g", datastd_std); cpgtext(left + 0.245, top - 4 * dy, out); find_min_max_arr(numint * numchan, datastd[0], &min, &max); sprintf(out, "min"); cpgtext(left + 0.06, top - 5 * dy, out); sprintf(out, "= %-.3f", min); cpgtext(left + 0.12, top - 5 * dy, out); sprintf(out, "max"); cpgtext(left + 0.21, top - 5 * dy, out); sprintf(out, "= %-.3f", max); cpgtext(left + 0.245, top - 5 * dy, out); sprintf(out, "Mean:"); cpgtext(left + 0.0, top - 6 * dy, out); sprintf(out, "median"); cpgtext(left + 0.06, top - 6 * dy, out); sprintf(out, "= %-.3f", dataavg_med); cpgtext(left + 0.12, top - 6 * dy, out); sprintf(out, "\\gs"); cpgtext(left + 0.21, top - 6 * dy, out); sprintf(out, "= %-.3g", dataavg_std); cpgtext(left + 0.245, top - 6 * dy, out); find_min_max_arr(numint * numchan, dataavg[0], &min, &max); sprintf(out, "min"); cpgtext(left + 0.06, top - 7 * dy, out); sprintf(out, "= %-.3f", min); cpgtext(left + 0.12, top - 7 * dy, out); sprintf(out, "max"); cpgtext(left + 0.21, top - 7 * dy, out); sprintf(out, "= %-.3f", max); cpgtext(left + 0.245, top - 7 * dy, out); } { /* Plot the Mask */ unsigned char byte; char temp[200]; float **plotmask, rr, gg, bb, page; plotmask = gen_fmatrix(numint, numchan); for (ii = 0; ii < numint; ii++) { for (jj = 0; jj < numchan; jj++) { byte = bytemask[ii][jj]; plotmask[ii][jj] = 0.0; if (byte & PADDING) plotmask[ii][jj] = 1.0; if (byte & OLDMASK) plotmask[ii][jj] = 2.0; if (byte & USERZAP) plotmask[ii][jj] = 3.0; if (byte & BAD_POW) plotmask[ii][jj] = 4.0; else if (byte & BAD_AVG) plotmask[ii][jj] = 5.0; else if (byte & BAD_STD) plotmask[ii][jj] = 6.0; } } /* Set the colors */ numcol = 7; maxcol = mincol + numcol - 1; cpgscir(mincol, maxcol); cpgqcr(0, &rr, &gg, &bb); cpgscr(mincol + 0, rr, gg, bb); /* GOODDATA = background */ cpgscr(mincol + 1, 0.7, 0.7, 0.7); /* PADDING = light grey */ cpgscr(mincol + 2, 0.3, 0.3, 0.3); /* OLDMASK = dark grey */ cpgqcr(1, &rr, &gg, &bb); cpgscr(mincol + 3, rr, gg, bb); /* USERZAP = foreground */ cpgscr(mincol + 4, 1.0, 0.0, 0.0); /* BAD+POW = red */ cpgscr(mincol + 5, 0.0, 0.0, 1.0); /* BAD+AVG = blue */ cpgscr(mincol + 6, 0.0, 1.0, 0.0); /* BAD+STD = green */ /* Prep the image */ for (page = 0; page <= 1; page++) { xl = 0.0; xh = numchan; yl = 0.0; yh = T; locut = 0.0; hicut = 6.0; tr[2] = tr[4] = 0.0; tr[1] = (xh - xl) / numchan; tr[0] = xl - (tr[1] / 2); tr[5] = (yh - yl) / numint; tr[3] = yl - (tr[5] / 2); if (page == 0) { left = lm + 3.0 * ft + 6.0 * tt; right = lm + 4.0 * ft + 6.0 * tt; bottom = bm; top = bm + fh; } else { cpgpage(); cpgiden(); left = 0.06; right = 0.94; bottom = 0.06; top = 0.88; } cpgsvp(left, right, bottom, top); cpgswin(xl, xh, yl, yh); cpgimag(plotmask[0], numchan, numint, 1, numchan, 1, numint, locut, hicut, tr); cpgswin(xl, xh, yl, yh); cpgbox("BNST", 0.0, 0, "BNST", 0.0, 0); cpgmtxt("B", 2.6, 0.5, 0.5, "Channel"); if (page) cpgmtxt("L", 2.1, 0.5, 0.5, "Time (s)"); xl = lof; xh = hif; yl = 0.0; yh = numint; cpgswin(xl, xh, yl, yh); cpgbox("CMST", 0.0, 0, "CMST", 0.0, 0); cpgmtxt("T", 1.8, 0.5, 0.5, "Frequency (MHz)"); cpgmtxt("R", 2.3, 0.5, 0.5, "Interval Number"); /* Add the Labels */ cpgsvp(0.0, 1.0, 0.0, 1.0); cpgswin(0.0, 1.0, 0.0, 1.0); cpgsch(0.8); if (page == 0) { cpgsci(mincol + 1); cpgptxt(left, top + 0.1, 0.0, 0.0, "Padding"); cpgsci(mincol + 2); cpgptxt(left, top + 0.08, 0.0, 0.0, "Old Mask"); cpgsci(mincol + 3); cpgptxt(left, top + 0.06, 0.0, 0.0, "User Zap"); cpgsci(mincol + 4); cpgptxt(right, top + 0.1, 0.0, 1.0, "Power"); cpgsci(mincol + 6); cpgptxt(right, top + 0.08, 0.0, 1.0, "Sigma"); cpgsci(mincol + 5); cpgptxt(right, top + 0.06, 0.0, 1.0, "Mean"); cpgsci(1); } else { cpgsci(mincol + 1); cpgptxt(1.0 / 12.0, 0.955, 0.0, 0.5, "Padding"); cpgsci(mincol + 2); cpgptxt(3.0 / 12.0, 0.955, 0.0, 0.5, "Old Mask"); cpgsci(mincol + 3); cpgptxt(5.0 / 12.0, 0.955, 0.0, 0.5, "User Zap"); cpgsci(mincol + 4); cpgptxt(7.0 / 12.0, 0.955, 0.0, 0.5, "Max Power"); cpgsci(mincol + 6); cpgptxt(9.0 / 12.0, 0.955, 0.0, 0.5, "Data Sigma"); cpgsci(mincol + 5); cpgptxt(11.0 / 12.0, 0.955, 0.0, 0.5, "Data Mean"); cpgsci(1); cpgsch(0.9); sprintf(temp, "Recommended Mask for '%-s'", idata->name); cpgptxt(0.5, 0.985, 0.0, 0.5, temp); } } vect_free(plotmask[0]); vect_free(plotmask); } if (ct == 0) printf("There are %d RFI instances.\n\n", numrfi); if ((ct == 0 && rfips) || (ct == 1 && rfixwin)) { /* Plot the RFI instances */ int maxcol, mincol, numperpage = 25, numtoplot; float dy = 0.035, top = 0.95, rr, gg, bb; char temp[200]; qsort(rfivect, numrfi, sizeof(rfi), compare_rfi_freq); /* qsort(rfivect, numrfi, sizeof(rfi), compare_rfi_sigma); */ for (ii = 0; ii <= (numrfi - 1) / numperpage; ii++) { cpgpage(); cpgiden(); cpgsvp(0.0, 1.0, 0.0, 1.0); cpgswin(0.0, 1.0, 0.0, 1.0); cpgsch(0.8); sprintf(temp, "%-s", idata->name); cpgtext(0.05, 0.985, temp); cpgsch(0.6); sprintf(temp, "Freq (Hz)"); cpgptxt(0.03, 0.96, 0.0, 0.0, temp); sprintf(temp, "Period (ms)"); cpgptxt(0.12, 0.96, 0.0, 0.0, temp); sprintf(temp, "Sigma"); cpgptxt(0.21, 0.96, 0.0, 0.0, temp); sprintf(temp, "Number"); cpgptxt(0.27, 0.96, 0.0, 0.0, temp); cpgsvp(0.33, 0.64, top - dy, top); cpgswin(lof, hif, 0.0, 1.0); cpgbox("CIMST", 0.0, 0, "", 0.0, 0); cpgmtxt("T", 2.5, 0.5, 0.5, "Frequency (MHz)"); cpgsvp(0.65, 0.96, top - dy, top); cpgswin(0.0, T, 0.0, 1.0); cpgbox("CIMST", 0.0, 0, "", 0.0, 0); cpgmtxt("T", 2.5, 0.5, 0.5, "Time (s)"); cpgqcir(&mincol, &maxcol); maxcol = mincol + 1; cpgscir(mincol, maxcol); cpgqcr(0, &rr, &gg, &bb); cpgscr(mincol, rr, gg, bb); /* background */ cpgqcr(1, &rr, &gg, &bb); /* cpgscr(maxcol, rr, gg, bb); foreground */ cpgscr(maxcol, 0.5, 0.5, 0.5); /* grey */ if (ii == (numrfi - 1) / numperpage) numtoplot = numrfi % numperpage; else numtoplot = numperpage; for (jj = 0; jj < numtoplot; jj++) plot_rfi(rfivect + ii * numperpage + jj, top - jj * dy, numint, numchan, T, lof, hif); cpgsvp(0.33, 0.64, top - jj * dy, top - (jj - 1) * dy); cpgswin(0.0, numchan, 0.0, 1.0); cpgbox("BINST", 0.0, 0, "", 0.0, 0); cpgmtxt("B", 2.5, 0.5, 0.5, "Channel"); cpgsvp(0.65, 0.96, top - jj * dy, top - (jj - 1) * dy); cpgswin(0.0, numint, 0.0, 1.0); cpgbox("BINST", 0.0, 0, "", 0.0, 0); cpgmtxt("B", 2.5, 0.5, 0.5, "Interval"); } } cpgclos(); } /* Plot for loop */ /* Free our arrays */ vect_free(freqs); vect_free(chans); vect_free(times); vect_free(ints); vect_free(avg_chan_avg); vect_free(std_chan_avg); vect_free(pow_chan_avg); vect_free(avg_int_avg); vect_free(std_int_avg); vect_free(pow_int_avg); vect_free(avg_chan_med); vect_free(std_chan_med); vect_free(pow_chan_med); vect_free(avg_int_med); vect_free(std_int_med); vect_free(pow_int_med); vect_free(avg_chan_std); vect_free(std_chan_std); vect_free(pow_chan_std); vect_free(avg_int_std); vect_free(std_int_std); vect_free(pow_int_std); }
int main() { char infile[] = "pih.fits"; char devtyp[16], idents[3][80], nlcprm[1], opt[2]; int c0[] = {-1, -1, -1, -1, -1, -1, -1}; int i, ic, gcode[2], naxis[2], nkeyrec, nreject, nwcs, relax, status; float blc[2], trc[2]; double cache[257][4], grid1[1], grid2[1], nldprm[1]; struct wcsprm *wcs; nlfunc_t pgwcsl_; #if defined HAVE_CFITSIO && defined DO_CFITSIO char *header; fitsfile *fptr; #else char keyrec[81], header[28801]; int gotend, j, k; FILE *fptr; #endif /* Set line buffering in case stdout is redirected to a file, otherwise * stdout and stderr messages will be jumbled (stderr is unbuffered). */ setvbuf(stdout, NULL, _IOLBF, 0); printf("Testing WCSLIB parser for FITS image headers (tpih2.c)\n" "------------------------------------------------------\n\n"); /* Read in the FITS header, excluding COMMENT and HISTORY keyrecords. */ #if defined HAVE_CFITSIO && defined DO_CFITSIO status = 0; if (fits_open_file(&fptr, infile, READONLY, &status)) { fits_report_error(stderr, status); return 1; } if (fits_hdr2str(fptr, 1, NULL, 0, &header, &nkeyrec, &status)) { fits_report_error(stderr, status); return 1; } fits_close_file(fptr, &status); #else if ((fptr = fopen(infile, "r")) == 0x0) { printf("ERROR opening %s\n", infile); return 1; } k = 0; nkeyrec = 0; gotend = 0; for (j = 0; j < 10; j++) { for (i = 0; i < 36; i++) { if (fgets(keyrec, 81, fptr) == 0) { break; } if (strncmp(keyrec, " ", 8) == 0) continue; if (strncmp(keyrec, "COMMENT ", 8) == 0) continue; if (strncmp(keyrec, "HISTORY ", 8) == 0) continue; strncpy(header+k, keyrec, 80); k += 80; nkeyrec++; if (strncmp(keyrec, "END ", 8) == 0) { /* An END keyrecord was read, but read the rest of the block. */ gotend = 1; } } if (gotend) break; } fclose(fptr); #endif fprintf(stderr, "Found %d non-comment header keyrecords.\n", nkeyrec); relax = WCSHDR_all; if ((status = wcspih(header, nkeyrec, relax, 2, &nreject, &nwcs, &wcs))) { fprintf(stderr, "wcspih ERROR %d: %s.\n", status, wcs_errmsg[status]); } #if defined HAVE_CFITSIO && defined DO_CFITSIO free(header); #endif /* Plot setup. */ naxis[0] = 1024; naxis[1] = 1024; blc[0] = 0.5f; blc[1] = 0.5f; trc[0] = naxis[0] + 0.5f; trc[1] = naxis[1] + 0.5f; strcpy(devtyp, "/XWINDOW"); cpgbeg(0, devtyp, 1, 1); cpgvstd(); cpgwnad(0.0f, 1.0f, 0.0f, 1.0f); cpgask(1); cpgpage(); /* Annotation. */ strcpy(idents[0], "Right ascension"); strcpy(idents[1], "Declination"); opt[0] = 'G'; opt[1] = 'E'; /* Compact lettering. */ cpgsch(0.8f); /* Draw full grid lines. */ cpgsci(1); gcode[0] = 2; gcode[1] = 2; grid1[0] = 0.0; grid2[0] = 0.0; for (i = 0; i < nwcs; i++) { if ((status = wcsset(wcs+i))) { fprintf(stderr, "wcsset ERROR %d: %s.\n", status, wcs_errmsg[status]); continue; } /* Get WCSNAME out of the wcsprm struct. */ strcpy(idents[2], (wcs+i)->wcsname); printf("\n%s\n", idents[2]); /* Draw the celestial grid. The grid density is set for each world */ /* coordinate by specifying LABDEN = 1224. */ ic = -1; cpgsbox(blc, trc, idents, opt, 0, 1224, c0, gcode, 0.0, 0, grid1, 0, grid2, 0, pgwcsl_, 1, WCSLEN, 1, nlcprm, (int *)(wcs+i), nldprm, 256, &ic, cache, &status); /* Draw the frame. */ cpgbox("BC", 0.0f, 0, "BC", 0.0f, 0); cpgpage(); } status = wcsvfree(&nwcs, &wcs); return 0; }
void plothistogram(SET *p, float w, int mode, float lm, float hm) { float *x = (mode == MAG) ? p->m : p->d; int i; char t[1024]; float x1, x2, y1, y2; float *bins = NULL; float *freq = NULL; int nb; float a, b; float rms = -1; cpgsvp(0.63, 0.93, 0.07, 0.30); /* Check we have data */ if (p->n ==0) { cpgswin(0.0, 1.0, 0.0, 1.0); cpgmtxt("T",-3, 0.5, 0.5, "-- Sem Dados -- "); return; } if (mode == MAG) { nb = gomag(x, p->n, w, &bins, &freq); rms = linefit(bins, freq, nb, lm, hm, &a, &b); } else { nb = godep(x, p->n, w, &bins, &freq); } /* * Plot */ minmax(x, p->n, &x1, &x2); minmax(freq, nb, &y1, &y2); cpgswin(x1, x2, y1 - (y2-y1)*0.1, y2 * 1.2); cpgbox("BCNST", 0.0, 0, "BCMST", 0.0, 0); /* * Labels */ cpgsch(0.7); cpgmtxt("L", 2.2, 0.0, 0.0, "[H] Trocar Mag/Dep"); cpgmtxt("L", 1.0, 0.0, 0.0, "[B] Ajustar largura do bin"); if (mode == MAG) { cpgmtxt("R", 3.0, 0.5, 0.5, "Log(n) Acumulado"); cpgmtxt("B", 3.0, 0.5, 0.5, "Magnitude"); } else { cpgmtxt("R", 3.0, 0.5, 0.5, "Log(n)"); cpgmtxt("B", 3.0, 0.5, 0.5, "Profundidade (km)"); } sprintf(t,"Min: %.1f Max: %.1f",x1,x2); if (mode == MAG) { cpgmtxt("B", -1.0, 0.05, 0.0,t); } else { cpgmtxt("T", -2.0, 0.95, 1.0,t); } cpgsch(FS); /* * Plots */ cpgbin(nb, bins, freq, 1); if (mode == MAG) { cpgmove(x1, a*x1 + b); cpgdraw(x2, a*x2 + b); if ( lm >= 0.0 ) { float temp; cpgsci(2); cpgsch(1.2); temp = fabs((a*x1+b) - (a*x2+b)); cpgpt1(lm, a*lm+b -temp * 0.06, 30); cpgpt1(hm, a*hm+b -temp * 0.06, 30); cpgsci(1); cpgsch(FS); } } if (mode == MAG) { cpgsch(0.7); sprintf(t,"f(x)=%.2f\\.x+%.2f",a,b); cpgmtxt("T",-2.0, 0.9, 1.0,t); sprintf(t,"b=%.2f",fabs(a)); cpgmtxt("T",-3.2, 0.9, 1.0,t); cpgsch(FS); } cpgbbuf(); /* * Terminate */ cpgsci(1); cpgslw(1); cpgebuf(); if (bins != NULL) free(bins); if (freq != NULL) free(freq); bins = NULL; freq = NULL; return; }
void Plotter2::plot() { open(); if ((width > 0.0) && (aspect > 0.0)) { cpgpap(width, aspect); } cpgscr(0, 1.0, 1.0, 1.0); // set background color white cpgscr(1, 0.0, 0.0, 0.0); // set foreground color black for (unsigned int i = 0; i < vInfo.size(); ++i) { Plotter2ViewportInfo vi = vInfo[i]; if (vi.showViewport) { resetAttributes(vi); // setup viewport cpgsvp(vi.vpPosXMin, vi.vpPosXMax, vi.vpPosYMin, vi.vpPosYMax); cpgswin(vi.vpRangeXMin, vi.vpRangeXMax, vi.vpRangeYMin, vi.vpRangeYMax); // background color (default is transparent) if (vi.vpBColor >= 0) { cpgsci(vi.vpBColor); cpgrect(vi.vpRangeXMin, vi.vpRangeXMax, vi.vpRangeYMin, vi.vpRangeYMax); cpgsci(1); // reset foreground colour to the initial one (black) } // data for (unsigned int j = 0; j < vi.vData.size(); ++j) { resetAttributes(vi); Plotter2DataInfo di = vi.vData[j]; std::vector<float> vxdata = di.xData; int ndata = vxdata.size(); float* pxdata = new float[ndata]; float* pydata = new float[ndata]; for (int k = 0; k < ndata; ++k) { pxdata[k] = di.xData[k]; pydata[k] = di.yData[k]; } if (di.drawLine) { cpgsls(di.lineStyle); cpgslw(di.lineWidth); int colorIdx = di.lineColor; if (colorIdx < 0) { colorIdx = (j + 1) % 15 + 1; } cpgsci(colorIdx); cpgline(ndata, pxdata, pydata); } if (di.drawMarker) { cpgsch(di.markerSize); cpgsci(di.markerColor); cpgpt(ndata, pxdata, pydata, di.markerType); } delete [] pxdata; delete [] pydata; } //calculate y-range of xmasks std::vector<float> yrange = vi.getRangeY(); float yexcess = 0.1*(yrange[1] - yrange[0]); float xmaskymin = yrange[0] - yexcess; float xmaskymax = yrange[1] + yexcess; // masks for (unsigned int j = 0; j < vi.vRect.size(); ++j) { resetAttributes(vi); Plotter2RectInfo ri = vi.vRect[j]; cpgsci(ri.color); cpgsfs(ri.fill); cpgslw(ri.width); cpgshs(45.0, ri.hsep, 0.0); float* mxdata = new float[4]; float* mydata = new float[4]; mxdata[0] = ri.xmin; mxdata[1] = ri.xmax; mxdata[2] = ri.xmax; mxdata[3] = ri.xmin; mydata[0] = xmaskymin; mydata[1] = xmaskymin; mydata[2] = xmaskymax; mydata[3] = xmaskymax; cpgpoly(4, mxdata, mydata); } // arrows for (unsigned int j = 0; j < vi.vArro.size(); ++j) { resetAttributes(vi); Plotter2ArrowInfo ai = vi.vArro[j]; cpgsci(ai.color); cpgslw(ai.width); cpgsls(ai.lineStyle); cpgsch(ai.headSize); cpgsah(ai.headFillStyle, ai.headAngle, ai.headVent); cpgarro(ai.xtail, ai.ytail, ai.xhead, ai.yhead); } // arbitrary texts for (unsigned int j = 0; j < vi.vText.size(); ++j) { resetAttributes(vi); Plotter2TextInfo ti = vi.vText[j]; cpgsch(ti.size); cpgsci(ti.color); cpgstbg(ti.bgcolor); cpgptxt(ti.posx, ti.posy, ti.angle, ti.fjust, ti.text.c_str()); } // viewport outline and ticks resetAttributes(vi); cpgbox("BCTS", vi.majorTickIntervalX, vi.nMinorTickWithinMajorTicksX, "BCTSV", vi.majorTickIntervalY, vi.nMinorTickWithinMajorTicksY); // viewport numberings std::string numformatx, numformaty; if (vi.numLocationX == "b") { numformatx = "N"; } else if (vi.numLocationX == "t") { numformatx = "M"; } else if (vi.numLocationX == "") { numformatx = ""; } if (vi.numLocationY == "l") { numformaty = "NV"; } else if (vi.numLocationY == "r") { numformaty = "MV"; } else if (vi.numLocationY == "") { numformaty = ""; } cpgbox(numformatx.c_str(), vi.majorTickIntervalX * vi.nMajorTickWithinTickNumsX, 0, numformaty.c_str(), vi.majorTickIntervalY * vi.nMajorTickWithinTickNumsY, 0); float xpos, ypos; // x-label vi.getWorldCoordByWindowCoord(vi.labelXPosX, vi.labelXPosY, &xpos, &ypos); cpgsch(vi.labelXSize); cpgsci(vi.labelXColor); cpgstbg(vi.labelXBColor); //outside viewports, works ONLY with /xwindow cpgptxt(xpos, ypos, vi.labelXAngle, vi.labelXFJust, vi.labelXString.c_str()); // y-label vi.getWorldCoordByWindowCoord(vi.labelYPosX, vi.labelYPosY, &xpos, &ypos); cpgsch(vi.labelYSize); cpgsci(vi.labelYColor); cpgstbg(vi.labelYBColor); //outside viewports, works ONLY with /xwindow cpgptxt(xpos, ypos, vi.labelYAngle, vi.labelYFJust, vi.labelYString.c_str()); // title vi.getWorldCoordByWindowCoord(vi.titlePosX, vi.titlePosY, &xpos, &ypos); cpgsch(vi.titleSize); cpgsci(vi.titleColor); cpgstbg(vi.titleBColor); //outside viewports, works ONLY with /xwindow cpgptxt(xpos, ypos, vi.titleAngle, vi.titleFJust, vi.titleString.c_str()); } } close(); }
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; }
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 main() { float RES = (XMAX - XMIN)/N; //resolution int i,j,p; //************************* PGPLOT CODE *************************** cpgbeg(0,"?",1,1); cpgpage(); cpgsci(1); // axis color cpgpap(0,1); //axis limits cpgswin(XMIN,XMAX,YMIN,YMAX); cpgbox("BCN",1, 0, "BCN", 1, 0); // draw the axes cpgsci(1); //data color cpgsch(0.00000000000001); //data point size //******************* GRID ALGORITHM AND PLOTTING ******************** struct cnum z; // z = (0,0) = initial number struct cnum c; // c is a complex variable z.cx = 0; z.cy = 0; for(i=0;i<N;i++) //look at every point on grid { for(j=0;j<N;j++) { c.cx = XMIN + i*RES; //assign c = current point c.cy = YMIN + j*RES; CPRINT(c); for(p=0;p<MNI;p++) //apply MNI iterations to z { //using c = current point z = FMANDEL(z,c); if ( z.cx*z.cx + z.cy*z.cy > R) // if iteration "blows up"... { z.cx = 0; z.cy = 0; //stay at z=c=0 c.cx = 0; c.cy = 0; } } //end of interation. z = final number if (z.cx*z.cx + z.cy*z.cy < R) //if iteration hasn't blown up... { float X[1], Y[1]; X[0] = c.cx; Y[0] = c.cy; cpgpt(1,X,Y,17); // plot point c } } } printf("\n\n"); cpgend(); }
int main(int argc, char **argv) { char alt = '\0', *header, idents[3][80], *infile, keyword[16], nlcprm[1], opt[2], pgdev[16]; int c0[] = {-1, -1, -1, -1, -1, -1, -1}; int alts[27], gcode[2], hdunum = 1, hdutype, i, ic, naxes, naxis[2], nkeyrec, nreject, nwcs, stat[NWCSFIX], status; float blc[2], trc[2]; double cache[257][4], grid1[3], grid2[3], nldprm[1]; struct wcsprm *wcs; nlfunc_t pgwcsl_; fitsfile *fptr; /* Parse options. */ strcpy(pgdev, "/XWINDOW"); for (i = 1; i < argc && argv[i][0] == '-'; i++) { if (!argv[i][1]) break; switch (argv[i][1]) { case 'a': alt = toupper(argv[i][2]); break; case 'd': if (argv[i][2] == '?') { cpgldev(); return 0; } if (argv[i][2] == '/') { strncpy(pgdev+1, argv[i]+3, 15); } else { strncpy(pgdev+1, argv[i]+2, 15); } break; case 'h': hdunum = atoi(argv[i]+2); break; default: fprintf(stderr, "%s", usage); return 1; } } if (i < argc) { infile = argv[i++]; if (i < argc) { fprintf(stderr, "%s", usage); return 1; } } else { infile = "-"; } /* Check accessibility of the input file. */ if (strcmp(infile, "-") && access(infile, R_OK) == -1) { printf("wcsgrid: Cannot access %s.\n", infile); return 1; } /* Open the FITS file and move to the required HDU. */ status = 0; if (fits_open_file(&fptr, infile, READONLY, &status)) goto fitserr; if (fits_movabs_hdu(fptr, hdunum, &hdutype, &status)) goto fitserr; if (hdutype != IMAGE_HDU) { fprintf(stderr, "ERROR, HDU number %d does not contain an image array.\n", hdunum); return 1; } /* Check that we have at least two image axes. */ if (fits_read_key(fptr, TINT, "NAXIS", &naxes, NULL, &status)) { goto fitserr; } if (naxes < 2) { fprintf(stderr, "ERROR, HDU number %d does not contain a 2-D image.\n", hdunum); return 1; } else if (naxes > 2) { printf("HDU number %d contains a %d-D image array.\n", hdunum, naxes); } /* Read in the FITS header, excluding COMMENT and HISTORY keyrecords. */ if (fits_hdr2str(fptr, 1, NULL, 0, &header, &nkeyrec, &status)) { goto fitserr; } /* Interpret the WCS keywords. */ if ((status = wcspih(header, nkeyrec, WCSHDR_all, -3, &nreject, &nwcs, &wcs))) { fprintf(stderr, "wcspih ERROR %d: %s.\n", status, wcshdr_errmsg[status]); return 1; } free(header); /* Read -TAB arrays from the binary table extension (if necessary). */ if (fits_read_wcstab(fptr, wcs->nwtb, (wtbarr *)wcs->wtb, &status)) { goto fitserr; } /* Translate non-standard WCS keyvalues. */ if ((status = wcsfix(7, 0, wcs, stat))) { status = 0; for (i = 0; i < NWCSFIX; i++) { if (stat[i] > 0) { fprintf(stderr, "wcsfix ERROR %d: %s.\n", stat[i], wcsfix_errmsg[stat[i]]); /* Ignore problems with CDi_ja and DATE-OBS. */ if (!(i == CDFIX || i == DATFIX)) status = 1; } } if (status) return 1; } /* Sort out alternates. */ if (alt) { wcsidx(nwcs, &wcs, alts); if (alt == ' ') { if (alts[0] == -1) { fprintf(stderr, "WARNING, no primary coordinate representation, " "doing all.\n"); alt = '\0'; } } else if (alt < 'A' || alt > 'Z') { fprintf(stderr, "WARNING, alternate specifier \"%c\" is invalid, " "doing all.\n", alt); alt = '\0'; } else { if (alts[alt - 'A' + 1] == -1) { fprintf(stderr, "WARNING, no alternate coordinate representation " "\"%c\", doing all.\n", alt); alt = '\0'; } } } /* Get image dimensions from the header. */ sprintf(keyword, "NAXIS%d", wcs->lng + 1); fits_read_key(fptr, TINT, "NAXIS1", naxis, NULL, &status); sprintf(keyword, "NAXIS%d", wcs->lat + 1); fits_read_key(fptr, TINT, "NAXIS2", naxis+1, NULL, &status); if ((naxis[0] < 2) || (naxis[1] < 2)) { fprintf(stderr, "ERROR, HDU number %d contains degenerate image axes.\n", hdunum); return 1; } fits_close_file(fptr, &status); /* Plot setup. */ blc[0] = 0.5f; blc[1] = 0.5f; trc[0] = naxis[0] + 0.5f; trc[1] = naxis[1] + 0.5f; if (cpgbeg(0, pgdev, 1, 1) != 1) { fprintf(stderr, "ERROR, failed to open PGPLOT device %s.\n", pgdev); return 1; } cpgvstd(); cpgwnad(blc[0], trc[0], blc[0], trc[1]); cpgask(1); cpgpage(); /* Compact lettering. */ cpgsch(0.8f); /* Draw full grid lines. */ gcode[0] = 2; gcode[1] = 2; grid1[0] = 0.0; grid2[0] = 0.0; /* These are for the projection boundary. */ grid1[1] = -180.0; grid1[2] = 180.0; grid2[1] = -90.0; grid2[2] = 90.0; cpgsci(1); for (i = 0; i < nwcs; i++) { if (alt && (wcs+i)->alt[0] != alt) { continue; } if ((status = wcsset(wcs+i))) { fprintf(stderr, "wcsset ERROR %d: %s.\n", status, wcs_errmsg[status]); continue; } /* Draw the frame. */ cpgbox("BC", 0.0f, 0, "BC", 0.0f, 0); /* Axis labels; use CNAMEia in preference to CTYPEia. */ if ((wcs+i)->cname[0][0]) { strcpy(idents[0], (wcs+i)->cname[0]); } else { strcpy(idents[0], (wcs+i)->ctype[0]); } if ((wcs+i)->cname[1][0]) { strcpy(idents[1], (wcs+i)->cname[1]); } else { strcpy(idents[1], (wcs+i)->ctype[1]); } /* Title; use WCSNAME. */ strcpy(idents[2], (wcs+i)->wcsname); if (strlen(idents[2])) { printf("\n%s\n", idents[2]); } /* Formatting control for celestial coordinates. */ if (strncmp((wcs+i)->ctype[0], "RA", 2) == 0) { /* Right ascension in HMS, declination in DMS. */ opt[0] = 'G'; opt[1] = 'E'; } else { /* Other angles in decimal degrees. */ opt[0] = 'A'; opt[1] = 'B'; } /* Draw the celestial grid. The grid density is set for each world */ /* coordinate by specifying LABDEN = 1224. */ ic = -1; cpgsbox(blc, trc, idents, opt, 0, 1224, c0, gcode, 0.0, 0, grid1, 0, grid2, 0, pgwcsl_, 1, WCSLEN, 1, nlcprm, (int *)(wcs+i), nldprm, 256, &ic, cache, &status); /* Delimit the projection boundary. */ if ((wcs+i)->cel.prj.category != ZENITHAL) { /* Reset to the native coordinate graticule. */ (wcs+i)->crval[0] = (wcs+i)->cel.prj.phi0; (wcs+i)->crval[1] = (wcs+i)->cel.prj.theta0; (wcs+i)->lonpole = 999.0; (wcs+i)->latpole = 999.0; status = wcsset(wcs+i); ic = -1; cpgsbox(blc, trc, idents, opt, -1, 0, c0, gcode, 0.0, 2, grid1, 2, grid2, 0, pgwcsl_, 1, WCSLEN, 1, nlcprm, (int *)(wcs+i), nldprm, 256, &ic, cache, &status); } cpgpage(); } status = wcsvfree(&nwcs, &wcs); return 0; fitserr: fits_report_error(stderr, status); fits_close_file(fptr, &status); return 1; }
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; }
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; }