void cpgstart_x(const char *orientation) { if (cpgopen("/XWIN") <= 0) exit(EXIT_FAILURE); if (0 == strcmp(orientation, "portrait")) { cpgpap(8.5, 11.0 / 8.5); } else { cpgpap(11.0, 8.5 / 11.0); } cpgask(1); }
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; }
/** * This method will expand the graphics panel already openned to the maximun of the display area scaled by the scale value supplied. * * @param scale Porcentage (0-100) of the display width to use. */ void resizemax(float scale) { Display *disp; float ax, ay; int X, Y; /* Xlib code */ disp = XOpenDisplay(NULL); if (disp == NULL) { fprintf(stderr, "No Display.\n"); exit(-1); } else { Y = XDisplayHeightMM(disp, 0); X = XDisplayWidthMM(disp, 0) / (0.9); } XCloseDisplay(disp); /* End of Xlib code */ ay = (double) Y / (double) X; ax = X / 25.4 * scale; cpgpap(ax, ay); cpgpage(); BASIC_ASPECT = ay; }
// make a single Aitoff sky projection plot // using the data in ravec[field], decvec[field], and value[filter][field], // using the min and max data values in valmin[filter] and valmax[filter] // with filter=0 void plotOne(double nfields, double *value, double *ravec, double *decvec, double valmin, double valmax, char *label, char *title, char *plotName) { int nf; double xmin, xmax, ymin, ymax; // set up the plot openPlot(plotName); cpgbbuf(); cpgpap(PLOTSIZE/0.7,0.7); cpgsvp(0.02,0.98,0.02,0.98); xmax = M_PI; xmin = -xmax; ymax = 0.67*M_PI; ymin = -ymax; ymin -= 0.1*ymax; ymax -= 0.1*ymax; setupImplot(0.0, 1.0); cpgswin(xmin,xmax,ymin,ymax); // make a projected field circle for each field cpgsch(1.0); for(nf=0; nf<nfields; nf++) { projCircle(ravec[nf], decvec[nf], FIELD_RADIUS, (value[nf]-valmin)/(valmax-valmin)); } // the grids and galactic exclusion aitoffGrid(); galaxy(peakL, taperL, taperB); cpgslw(2); cpgsch(2.0); cpgswin(0,1,0,1); mywedg(0.21, 0.15, 1.0, 12.0, valmin, valmax, label); cpgptxt(0.5,0.95,0.0,0.5,title); cpgslw(1); cpgebuf(); closePlot(); }
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]; } }
int main(void) { int j, jj; int sleep_sec=2; char bufD[128]; int ind, Mcount; int M=50; int plan; pg_id = cpgopen("/XSERVE"); cpgpap(6.00, 0.8); timedata = fftw_malloc(sizeof(double) * (N+1)); freqdata = fftw_malloc(sizeof(fftw_complex) * (N+1)); read_count=N*M; mem_size=read_count * 2; ai_buf = (I16*)malloc(mem_size); if ((fp=fopen("SatPosData","w"))==NULL) { printf("Cannot open file. \n"); exit(1); } for (j=1; j<=max_scans; j++) { printf("\nPause %d seconds ...",sleep_sec); sleep(sleep_sec); printf("\n\nAcquisition %d\n",j); fprintf(fp,"\nAcquisition: %d\n",j); strcpy(bufD, send_command0("Apollo","GET_TIME$")); printf("Universal Time: %s",bufD); fprintf(fp, "UT: %s",bufD); printf("Satellites above local horizon:\n"); getSatInfo0(); getSatInfo1(); acquire_data(); transfer_and_scale((U16*)ai_buf, channel+1); for (k=0; k<(N/2)+1; k++) accumFreqData[k]=0; printf("Integrating ... %i %i-blocks",M,N); for (Mcount=1; Mcount<=M; Mcount++) { for (ind=0; ind<N; ind++) { timedata[ind]=voltarray[ind+(N*(Mcount-1))]; } // printf("%i ",Mcount); plan=(j==1)&(Mcount==1); if (plan) { p=fftw_plan_dft_r2c_1d(N, timedata, freqdata, FFTW_FORWARD); } fftw_execute(p); for (k=0; k<(N/2)+1; k++) { accumFreqData[k]+=(sqrt(freqdata[k][0]*freqdata[k][0]+freqdata[k][1]*freqdata[k][1])/(M*256)); } } fprintf(fp, "Bin Voltages \n"); for (jj=0; jj<=240; jj+=10) { for (k=jj; k<(jj+10); k++) fprintf(fp, "%f ", accumFreqData[k]); fprintf(fp, "\n"); } // plot_channel_data(); plot_freq_data(); } int fclose(FILE *fp); postfft(); free( ai_buf ); printf("\n\nEnd of program. "); //getch(); putchar('\n'); return 0; }
// make six Aitoff sky projection plots // using the data in ravec[field], decvec[field], and value[filter][field], // using the min and max data values in valmin[filter] and valmax[filter] // with filter=0 to NFILTERS-1 void plotSix(double nfields, double **value, double *ravec, double *decvec, double *valmin, double *valmax, int horizontal, char *label, char *title, char* plotName, int mask) { char str[1024]; int filt, nf; double xmin, xmax, ymin, ymax; openPlot(plotName); cpgbbuf(); if(horizontal==1) cpgpap(PLOTSIZE/0.5,0.5); else cpgpap(PLOTSIZE/1.0,1.0); cpgsvp(0.02,0.98,0.15,0.95); xmax = 0.9*(M_PI); xmin = -xmax; ymax = 0.9*(0.6*M_PI); ymin = -ymax; ymin -= 0.18*ymax; ymax -= 0.18*ymax; setupImplot(0.0, 1.0); if(horizontal==1) cpgsubp(3,2); else cpgsubp(2,3); cpgsch(3.0); cpgslw(2); for(filt=0; filt<NFILTERS; filt++) { int thereisdata = 0; for(nf=0; nf<nfields; nf++) { if (value[filt][nf] != 0.0) { thereisdata = 1; } } if ( thereisdata ) { if(horizontal==1) cpgpanl(hpanelx[filt],hpanely[filt]); else cpgpanl(vpanelx[filt],vpanely[filt]); cpgswin(xmin,xmax,ymin,ymax); for(nf=0; nf<nfields; nf++) { if ( mask == 0 ) { if(value[filt][nf] > 0.0) projCircle(ravec[nf], decvec[nf], FIELD_RADIUS, (value[filt][nf]-valmin[filt])/(valmax[filt]-valmin[filt])); } else if ( mask == 1) { if(value[filt][nf] != 0.0) projCircle(ravec[nf], decvec[nf], FIELD_RADIUS, (value[filt][nf]-valmin[filt])/(valmax[filt]-valmin[filt])); } } aitoffGrid(); galaxy(peakL, taperL, taperB); sprintf(str,"%s: %s", label, filtername[filt]); if(valmax[filt]>valmin[filt]) mywedg(0.2, 0.15, 1.0, 8.0, valmin[filt], valmax[filt], str); } } cpgsch(1.0); cpgsubp(1,1); cpgswin(0,1,0,1); cpgptxt(0.5,1.02,0.0,0.5,title); cpgslw(1); cpgebuf(); closePlot(); }
int main() { // printf("\n====================================================================\n"); printf("This program is able to simulate a variety of ecological\n"); printf("situations in a 2D lattice\n"); 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(20.0, 0.33); // set window size cpgsubp(3,1); // subdivide window into panels // color indexes (R, G, B) cpgscr(0, 0.0, 0.0, 0.0); // empty space, black cpgscr(1, 1.0, 1.0, 1.0); cpgscr(10, 0.0, 0.0, 0.0); // empty space, black cpgscr(11, 0.5, 0.5, 0.5); // Trophic 1, gray cpgscr(12, 0.5, 1.0, 1.0); // Trophic 2, cyan cpgscr(13, 1.0, 0.5, 0.0); // Trophic 3, orange cpgscr(14, 1.0, 0.0, 0.0); cpgscir(10,NUMB_TROPHIC+10); //========================================================================== //--------------------------VARIABLE INITIALIZATIONS------------------------ //========================================================================== // generic variables int i, j, k; // counters // simulation environment int** simEnv = allocateArray2DInt(ENV_SIZE_X, ENV_SIZE_Y); int** simEnvAge = allocateArray2DInt(ENV_SIZE_X, ENV_SIZE_Y); int* simLocal = allocateArray1DInt(5); // inputs char input; // current location and time int x,y; int tGlobal,t; int flagUpdate; // rates float predationRates[NUMB_TROPHIC-1] = RATE_PRED; float deathRates[NUMB_TROPHIC] = RATE_DEATH; //float aBirth = 0; // A+0 -> A+A // float abPred = 0; // B+A -> B+B // float bDeath = 0; // B -> 0 // int aFlag; int abFlag; int bFlag; // population counts; int popCount[NUMB_TROPHIC]; float popDens[NUMB_TROPHIC]; float popDensOld[NUMB_TROPHIC]; for (i=0; i<NUMB_TROPHIC; i++){ popCount[i] = 0; popDens[i] = 0.0; popDensOld[i] = 1.0/(float)INIT_DENSITY; } float* ageStructure = allocateArray1D(ENV_SIZE_TOTAL); // pgplot variables float* plotImg = allocateArray1D(ENV_SIZE_TOTAL); //float TR[6] = {0, 1, 0, 0, 0, 1}; float TR[6] = {0, 0, 1, ENV_SIZE_Y, -1, 0}; float plotMinBound = 0.0; float plotMaxBound = (float)NUMB_TROPHIC; //========================================================================== //--------------------------ACTUAL CODE------------------------------------- //========================================================================== // environment initialization randomizeArray2DInt(simEnv, ENV_SIZE_X, ENV_SIZE_Y, NUMB_TROPHIC); // load initial display for (i=0; i<ENV_SIZE_X; i++) for (j=0; j<ENV_SIZE_Y; j++) plotImg[i*ENV_SIZE_Y+j] = (float)(simEnv[i][j]); cpgpanl(1,1); cpgswin(0, ENV_SIZE_X-1, 0, ENV_SIZE_Y-1); cpgsvp(0.01, 0.99, 0.01, 0.99); cpgimag(plotImg, ENV_SIZE_Y, ENV_SIZE_X, 1, ENV_SIZE_Y, 1, ENV_SIZE_X, plotMinBound, plotMaxBound, TR); // Load graph labels // Population Density vs Time Plot cpgpanl(2,1); cpgsvp(0.08, 0.92, 0.08, 0.92); cpgswin(0, ENV_SIZE_X, 0, 1); cpgbox("ABCINTS", 0.0, 0, "ABCINTS", 0.0, 0); cpglab("Time", "Population Density", ""); // Phase Portrait Plot cpgpanl(3,1); cpgsvp(0.08, 0.92, 0.08, 0.92); cpgswin(0, 1, 0, 1); cpgbox("ABCINTS", 0.0, 0, "ABCINTS", 0.0, 0); cpglab("", "", "Phase Portrait"); cpgsci(11); cpglab("Population Density SpA", "", ""); cpgsci(12); cpglab("", "Population Density SpB", ""); // initial delay to visualize starting matrix for (t=0; t<500000000; t++){} tGlobal = 1; while(1){ //aFlag = 0; abFlag = 0; bFlag = 0; // run simulation for a full Monte Carlo timestep (ENV_SIZE_X*ENV_SIZE_Y) for (t=0; t<ENV_SIZE_TOTAL; t++){ ecoRun(simEnv, simEnvAge, simLocal, predationRates, deathRates); } incrementAge(simEnvAge); // plot stuffs if ((tGlobal%1) == 0){ // calculate population densities updatePopDens(simEnv, popCount, popDens); // PLOT population densities cpgpanl(2,1); cpgsvp(0.08, 0.92, 0.08, 0.92); cpgswin(0, ENV_SIZE_X, 0, 1); for (i=0; i<NUMB_TROPHIC; i++){ cpgsls(1); cpgsci(i+11); // line style and color cpgmove((tGlobal-1), popDensOld[i]); cpgdraw(tGlobal, popDens[i]); } //printArray2DInt(simEnvAge, ENV_SIZE_X, ENV_SIZE_Y); // PLOT age structure /*updateAgeStructure(simEnv, simEnvAge, ageStructure, 1); cpgpanl(3,1); cpgsvp(0.08, 0.92, 0.08, 0.92); cpgswin(0, 10, 0, (ENV_SIZE_TOTAL/10)); cpgsls(1); cpgsci(1); // line style and color cpgeras(); cpgbox("ABCINTS", 0.0, 0, "ABCINTS", 0.0, 0); cpglab("Age", "Number of Individuals", "Age Structure"); cpghist(popCount[1], ageStructure, 0, 10, 10, 1);*/ // PLOT phase portrait cpgpanl(3,1); cpgsvp(0.08, 0.92, 0.08, 0.92); cpgswin(0, 1, 0, 1); cpgsls(1); cpgsci(1); // line style and color cpgmove(popDensOld[0], popDensOld[1]); cpgdraw(popDens[0], popDens[1]); for (i=0; i<NUMB_TROPHIC; i++) popDensOld[i] = popDens[i]; } // load array and display on pgplot if ((tGlobal%1) == 0){ cpgpanl(1,1); cpgswin(0, ENV_SIZE_X, 0, ENV_SIZE_Y); cpgsvp(0.01, 0.99, 0.01, 0.99); for (i=0; i<ENV_SIZE_X; i++) for (j=0; j<ENV_SIZE_Y; j++) plotImg[i*ENV_SIZE_Y+j] = (float)(simEnv[i][j]); cpgimag(plotImg, ENV_SIZE_Y, ENV_SIZE_X, 1, ENV_SIZE_Y, 1, ENV_SIZE_X, plotMinBound, plotMaxBound, TR); } tGlobal++; //for (t=0; t<10000000; t++){} } }
static double harmonic_loop(int xid, double rr, int zoomlevel, fftpart * fp) { float inx = 0.0, iny = 0.0; double retval = 0.0; int xid2, psid, badchoice = 1; char choice; xid2 = cpgopen("/XWIN"); cpgpap(10.25, 8.5 / 11.0); cpgask(0); cpgslct(xid2); plot_harmonics(rr, zoomlevel, fp); printf(" Click on the harmonic to go it,\n" " press 'P' to print, or press 'Q' to close.\n"); while (badchoice) { cpgcurs(&inx, &iny, &choice); if (choice == 'Q' || choice == 'q') { badchoice = 0; } else if (choice == 'P' || choice == 'p') { int len, numharmbins; double offsetf; char filename[200]; fftpart *harmpart; fftview *harmview; printf(" Enter the filename to save the plot as:\n"); fgets(filename, 195, stdin); len = strlen(filename) - 1; strcpy(filename + len, "/CPS"); psid = cpgopen(filename); cpgslct(psid); cpgpap(10.25, 8.5 / 11.0); cpgiden(); cpgscr(15, 0.8, 0.8, 0.8); numharmbins = (1 << (LOGDISPLAYNUM - zoomlevel)); harmpart = get_fftpart((int) (rr - numharmbins), 2 * numharmbins); harmview = get_fftview(rr, zoomlevel, harmpart); free_fftpart(harmpart); offsetf = plot_fftview(harmview, 0.0, 1.0, rr, 2); cpgpage(); plot_harmonics(rr, zoomlevel, fp); cpgclos(); cpgslct(xid2); cpgscr(15, 0.4, 0.4, 0.4); filename[len] = '\0'; printf(" Wrote the plot to the file '%s'.\n", filename); } else if (choice == 'A' || choice == 'a') { if (iny > 1.0) retval = rr * (int) (inx); else if (iny > 0.0) retval = rr * ((int) (inx) + 4.0); else if (iny > -1.0) retval = rr / (int) (inx); else retval = rr / ((int) (inx) + 4.0); badchoice = 0; } else { printf(" Option not recognized.\n"); } }; cpgclos(); cpgslct(xid); return retval; }
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 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() { 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; //complex variables z and c introduced struct cnum c; for(i=0;i<N;i++) //look at every point on grid { for(j=0;j<N;j++) { z.cx = XMIN + i*RES; // z = current point z.cy = YMIN + j*RES; CPRINT(z); c.cx = z.cx; // keep z, feed c=z in to iteration c.cy = z.cy; for(p=0;p<MNI;p++) //apply MNI iterations to c { c = FJULIA(c); if ( c.cx*c.cx + c.cy*c.cy > R) // if iteration "blows up"... { z.cx = 0; z.cy = 0; c.cx = 0; c.cy = 0; } } if (c.cx*c.cx + c.cy*c.cy < R) //if iteration hasn't blown up... { float X[1], Y[1]; X[0] = z.cx; Y[0] = z.cy; cpgpt(1,X,Y,17); // plot point z } } } printf("\n\n"); cpgend(); }
void doPlot(pulsar *psr,int npsr,int overlay) { int i,j,fitFlag=1,exitFlag=0,scale1=0,scale2,count,p,xautoscale=1,k,graphics=1; int yautoscale=1,plotpre=1; int time=0; char xstr[1000],ystr[1000]; float x[MAX_OBSN],y[MAX_OBSN],yerr1[MAX_OBSN],yerr2[MAX_OBSN],tmax,tmin,tmaxy1,tminy1,tmaxy2,tminy2; float minx,maxx,miny,maxy,plotx1,plotx2,ploty1,ploty2,mean; float mouseX,mouseY; float fontSize=1.8; char key; float widthPap=0.0,aspectPap=0.618; /* Obtain a graphical PGPLOT window */ if (overlay==1) cpgbeg(0,"?",2,1); else cpgbeg(0,"?",2,npsr); cpgpap(widthPap,aspectPap); cpgsch(fontSize); cpgask(0); do { for (p=0;p<npsr;p++) { scale2 = psr[p].nobs; for (j=0;j<2;j++) { if (j==0) fitFlag=1; else if (j==1) fitFlag=2; ld_sprintf(xstr,"MJD-%.1Lf",psr[0].param[param_pepoch].val[0]); sprintf(ystr,"Residual (\\gmsec)"); count=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)) { if (xautoscale==1) x[count] = (double)(psr[p].obsn[i].bat-psr[p].param[param_pepoch].val[0]); else x[count] = (double)(psr[p].obsn[i].bat-psr[0].param[param_pepoch].val[0]); if (fitFlag==1) /* Get pre-fit residual */ y[count] = (double)psr[p].obsn[i].prefitResidual*1.0e6; else if (fitFlag==2) /* Post-fit residual */ y[count] = (double)psr[p].obsn[i].residual*1.0e6; count++; } } /* Remove mean from the residuals and calculate error bars */ mean = findMean(y,psr,p,scale1,count); count=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[count]-=mean; yerr1[count] = y[count]-(float)psr[p].obsn[i].toaErr; yerr2[count] = y[count]+(float)psr[p].obsn[i].toaErr; count++; } } /* Get scaling for graph */ minx = findMin(x,psr,p,scale1,count); maxx = findMax(x,psr,p,scale1,count); if (xautoscale==1) { plotx1 = minx-(maxx-minx)*0.1; plotx2 = maxx+(maxx-minx)*0.1; } else { plotx1 = tmin-(tmax-tmin)*0.1; plotx2 = tmax+(tmax-tmin)*0.1; } miny = findMin(y,psr,p,scale1,count); maxy = findMax(y,psr,p,scale1,count); if (yautoscale==1) { ploty1 = miny-(maxy-miny)*0.1; ploty2 = maxy+(maxy-miny)*0.1; } else { if (j==0) { ploty1 = tminy1-(tmaxy1-tminy1)*0.1; ploty2 = tmaxy1+(tmaxy1-tminy1)*0.1; } else { ploty1 = tminy2-(tmaxy2-tminy2)*0.1; ploty2 = tmaxy2+(tmaxy2-tminy2)*0.1; } } /* Plot the residuals */ if (plotpre==1 || j!=0) { float xx[MAX_OBSN],yy[MAX_OBSN],yyerr1[MAX_OBSN],yyerr2[MAX_OBSN]; int num=0,colour; if (overlay==0 || (overlay==1 && p==0)) { cpgenv(plotx1,plotx2,ploty1,ploty2,0,0); cpglab(xstr,ystr,psr[p].name); } for (colour=0;colour<5;colour++) { num=0; for (i=0;i<count;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[i]; yy[num]=y[i]; yyerr1[num]=yerr1[i]; yyerr2[num]=yerr2[i]; num++; } } cpgsci(colour+1); if (overlay==1) cpgsci(p+1); cpgpt(num,xx,yy,16); cpgerry(num,xx,yyerr1,yyerr2,1); } cpgsci(1); } } } printf("------------------------------\n"); printf("`a' set aspect ratio\n"); printf("`f' set font size\n"); printf("`g' set graphics device\n"); printf("`q' quit\n"); printf("`x' toggle autoscale x axis\n"); printf("`y' toggle autoscale y axis\n"); printf("`p' toggle prefit plotting\n"); printf("`r' output residuals to file\n"); if (graphics==1) { cpgcurs(&mouseX,&mouseY,&key); /* Check key press */ if (key=='q') exitFlag=1; if (key=='p') { plotpre*=-1; if (plotpre==-1) { cpgend(); if (overlay==1) cpgbeg(0,"/xs",1,1); else cpgbeg(0,"/xs",1,npsr); cpgpap(widthPap,aspectPap); cpgsch(fontSize); cpgask(0); } else { cpgend(); if (overlay==1) cpgbeg(0,"/xs",2,1); else cpgbeg(0,"/xs",2,npsr); cpgpap(widthPap,aspectPap); cpgsch(fontSize); cpgask(0); } } else if (key=='a') /* Change aspect ratio */ { printf("Please enter a new aspect ratio "); scanf("%f",&aspectPap); cpgend(); cpgbeg(0,"/xs",2,npsr); cpgpap(widthPap,aspectPap); cpgsch(fontSize); cpgask(0); } else if (key=='f') /* Change font size */ { printf("Please enter a new font size "); scanf("%f",&fontSize); cpgend(); cpgbeg(0,"/xs",2,npsr); cpgpap(widthPap,aspectPap); cpgsch(fontSize); cpgask(0); } else if (key=='g') { graphics=0; cpgend(); if (plotpre==-1) { cpgend(); if (overlay==1) cpgbeg(0,"?",1,1); else cpgbeg(0,"?",1,npsr); cpgpap(widthPap,aspectPap); cpgsch(fontSize); cpgask(0); } else { cpgend(); if (overlay==1) cpgbeg(0,"?",1,1); else cpgbeg(0,"?",2,npsr); cpgpap(widthPap,aspectPap); cpgsch(fontSize); cpgask(0); } } else if (key=='r') /* Output residuals to file */ { FILE *fout; char fname[1000]; int ii,jj; for (ii=0;ii<npsr;ii++) { sprintf(fname,"%s.res",psr[ii].name); fout = fopen(fname,"w"); /* Print header */ fprintf(fout,"#PSR %s\n",psr[ii].name); ld_fprintf(fout,"#F0 %.14Lf\n",psr[ii].param[param_f].val[0]); fprintf(fout,"#RAJ %s\n",psr[ii].rajStrPre); fprintf(fout,"#DECJ %s\n",psr[ii].decjStrPre); for (jj=0;jj<psr[ii].nobs;jj++) fprintf(fout,"%.5lf %.5lg %.5lg\n", (double)(psr[ii].obsn[jj].bat-psr[0].param[param_pepoch].val[0]), (double)(psr[ii].obsn[jj].residual),(double)(psr[ii].obsn[jj].toaErr)/1.0e6); fclose(fout); } } else if (key=='x') { xautoscale*=-1; if (xautoscale==-1) { for (k=0;k<npsr;k++) { count=0; for (i=0;i<psr[k].nobs;i++) { if (psr[k].obsn[i].deleted==0 && (psr[k].param[param_start].paramSet[0]!=1 || psr[k].param[param_start].fitFlag[0]!=1 || psr[k].param[param_start].val[0] < psr[k].obsn[i].bat) && (psr[k].param[param_finish].paramSet[0]!=1 || psr[k].param[param_finish].fitFlag[0]!=1 || psr[k].param[param_finish].val[0] > psr[k].obsn[i].bat)) {x[count] = (double)(psr[k].obsn[i].bat-psr[0].param[param_pepoch].val[0]); count++;} } minx = findMin(x,psr,k,scale1,count); maxx = findMax(x,psr,k,scale1,count); if (k==0) { tmin = minx; tmax = maxx; printf("Have1 tmin = %f, tmax = %f\n",tmin,tmax); } else { if (tmin > minx) tmin = minx; if (tmax < maxx) tmax = maxx; printf("Have2 tmin = %f, tmax = %f\n",tmin,tmax); } } } } else if (key=='y') { yautoscale*=-1; if (yautoscale==-1) { for (k=0;k<npsr;k++) { count=0; for (i=0;i<psr[k].nobs;i++) { if (psr[k].obsn[i].deleted==0 && (psr[k].param[param_start].paramSet[0]!=1 || psr[k].param[param_start].fitFlag[0]!=1 || psr[k].param[param_start].val[0] < psr[k].obsn[i].bat) && (psr[k].param[param_finish].paramSet[0]!=1 || psr[k].param[param_finish].fitFlag[0]!=1 || psr[k].param[param_finish].val[0] > psr[k].obsn[i].bat)) {y[count] = (double)psr[k].obsn[i].prefitResidual*1e6; count++;} } miny = findMin(y,psr,k,scale1,count); maxy = findMax(y,psr,k,scale1,count); if (k==0) { tminy1 = miny; tmaxy1 = maxy; } else { if (tminy1 > miny) tminy1 = miny; if (tmaxy1 < maxy) tmaxy1 = maxy; } count=0; for (i=0;i<psr[k].nobs;i++) { if (psr[k].obsn[i].deleted==0 && (psr[k].param[param_start].paramSet[0]!=1 || psr[k].param[param_start].fitFlag[0]!=1 || psr[k].param[param_start].val[0] < psr[k].obsn[i].bat) && (psr[k].param[param_finish].paramSet[0]!=1 || psr[k].param[param_finish].fitFlag[0]!=1 || psr[k].param[param_finish].val[0] > psr[k].obsn[i].bat)) {y[count] = (double)psr[k].obsn[i].residual*1e6; count++;} } miny = findMin(y,psr,k,scale1,count); maxy = findMax(y,psr,k,scale1,count); if (k==0) { tminy2 = miny; tmaxy2 = maxy; } else { if (tminy2 > miny) tminy2 = miny; if (tmaxy2 < maxy) tmaxy2 = maxy; } } printf("Have tminy2 = %g %g\n",tminy2,tmaxy2); } } else printf("Unknown key press %c\n",key); } else { graphics=1; cpgend(); if (plotpre==-1) { cpgend(); if (overlay==1) cpgbeg(0,"/xs",1,1); else cpgbeg(0,"/xs",1,npsr); cpgpap(widthPap,aspectPap); cpgsch(fontSize); cpgask(0); } else { cpgend(); if (overlay==1) cpgbeg(0,"/xs",2,1); else cpgbeg(0,"/xs",2,npsr); cpgpap(widthPap,aspectPap); cpgsch(fontSize); cpgask(0); } } } while (exitFlag==0); cpgend(); }
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(int argc, char *argv[]) { float maxpow = 0.0, inx = 0.0, iny = 0.0; double centerr, offsetf; int zoomlevel, maxzoom, minzoom, xid, psid; char *rootfilenm, inchar; fftpart *lofp; fftview *fv; if (argc == 1) { printf("\nusage: explorefft fftfilename\n\n"); exit(0); } printf("\n\n"); printf(" Interactive FFT Explorer\n"); printf(" by Scott M. Ransom\n"); printf(" October, 2001\n"); print_help(); { int hassuffix = 0; char *suffix; hassuffix = split_root_suffix(argv[1], &rootfilenm, &suffix); if (hassuffix) { if (strcmp(suffix, "fft") != 0) { printf("\nInput file ('%s') must be a FFT file ('.fft')!\n\n", argv[1]); free(suffix); exit(0); } free(suffix); } else { printf("\nInput file ('%s') must be a FFT file ('.fft')!\n\n", argv[1]); exit(0); } } /* Read the info file */ readinf(&idata, rootfilenm); if (strlen(remove_whitespace(idata.object)) > 0) { printf("Examining %s data from '%s'.\n\n", remove_whitespace(idata.object), argv[1]); } else { printf("Examining data from '%s'.\n\n", argv[1]); } N = idata.N; T = idata.dt * idata.N; #ifdef USEMMAP printf("Memory mapping the input FFT. This may take a while...\n"); mmap_file = open(argv[1], O_RDONLY); { int rt; struct stat buf; rt = fstat(mmap_file, &buf); if (rt == -1) { perror("\nError in fstat() in explorefft.c"); printf("\n"); exit(-1); } Nfft = buf.st_size / sizeof(fcomplex); } lofp = get_fftpart(0, Nfft); #else { int numamps; fftfile = chkfopen(argv[1], "rb"); Nfft = chkfilelen(fftfile, sizeof(fcomplex)); numamps = (Nfft > MAXBINS) ? (int) MAXBINS : (int) Nfft; lofp = get_fftpart(0, numamps); } #endif /* Plot the initial data */ { int initnumbins = INITIALNUMBINS; if (initnumbins > Nfft) { initnumbins = next2_to_n(Nfft) / 2; zoomlevel = LOGDISPLAYNUM - (int) (log(initnumbins) / log(2.0)); minzoom = zoomlevel; } else { zoomlevel = LOGDISPLAYNUM - LOGINITIALNUMBINS; minzoom = LOGDISPLAYNUM - LOGMAXBINS; } maxzoom = LOGDISPLAYNUM - LOGMINBINS; centerr = initnumbins / 2; } fv = get_fftview(centerr, zoomlevel, lofp); /* Prep the XWIN device for PGPLOT */ xid = cpgopen("/XWIN"); if (xid <= 0) { free(fv); #ifdef USEMMAP close(mmap_file); #else fclose(fftfile); #endif free_fftpart(lofp); exit(EXIT_FAILURE); } cpgscr(15, 0.4, 0.4, 0.4); cpgask(0); cpgpage(); offsetf = plot_fftview(fv, maxpow, 1.0, 0.0, 0); do { cpgcurs(&inx, &iny, &inchar); if (DEBUGOUT) printf("You pressed '%c'\n", inchar); switch (inchar) { case 'A': /* Zoom in */ case 'a': centerr = (inx + offsetf) * T; case 'I': case 'i': if (DEBUGOUT) printf(" Zooming in (zoomlevel = %d)...\n", zoomlevel); if (zoomlevel < maxzoom) { zoomlevel++; free(fv); fv = get_fftview(centerr, zoomlevel, lofp); cpgpage(); offsetf = plot_fftview(fv, maxpow, 1.0, 0.0, 0); } else printf(" Already at maximum zoom level (%d).\n", zoomlevel); break; case 'X': /* Zoom out */ case 'x': case 'O': case 'o': if (DEBUGOUT) printf(" Zooming out (zoomlevel = %d)...\n", zoomlevel); if (zoomlevel > minzoom) { zoomlevel--; free(fv); fv = get_fftview(centerr, zoomlevel, lofp); cpgpage(); offsetf = plot_fftview(fv, maxpow, 1.0, 0.0, 0); } else printf(" Already at minimum zoom level (%d).\n", zoomlevel); break; case '<': /* Shift left 1 full screen */ centerr -= fv->numbins + fv->numbins / 8; case ',': /* Shift left 1/8 screen */ if (DEBUGOUT) printf(" Shifting left...\n"); centerr -= fv->numbins / 8; { /* Should probably get the previous chunk from the fftfile... */ double lowestr; lowestr = 0.5 * fv->numbins; if (centerr < lowestr) centerr = lowestr; } free(fv); fv = get_fftview(centerr, zoomlevel, lofp); cpgpage(); offsetf = plot_fftview(fv, maxpow, 1.0, 0.0, 0); break; case '>': /* Shift right 1 full screen */ centerr += fv->numbins - fv->numbins / 8; case '.': /* Shift right 1/8 screen */ if (DEBUGOUT) printf(" Shifting right...\n"); centerr += fv->numbins / 8; { /* Should probably get the next chunk from the fftfile... */ double highestr; highestr = lofp->rlo + lofp->numamps - 0.5 * fv->numbins; if (centerr > highestr) centerr = highestr; } free(fv); fv = get_fftview(centerr, zoomlevel, lofp); cpgpage(); offsetf = plot_fftview(fv, maxpow, 1.0, 0.0, 0); break; case '+': /* Increase height of powers */ case '=': if (maxpow == 0.0) { printf(" Auto-scaling is off.\n"); maxpow = 1.1 * fv->maxpow; } maxpow = 3.0 / 4.0 * maxpow; cpgpage(); offsetf = plot_fftview(fv, maxpow, 1.0, 0.0, 0); break; case '-': /* Decrease height of powers */ case '_': if (maxpow == 0.0) { printf(" Auto-scaling is off.\n"); maxpow = 1.1 * fv->maxpow; } maxpow = 4.0 / 3.0 * maxpow; cpgpage(); offsetf = plot_fftview(fv, maxpow, 1.0, 0.0, 0); break; case 'S': /* Auto-scale */ case 's': if (maxpow == 0.0) break; else { printf(" Auto-scaling is on.\n"); maxpow = 0.0; cpgpage(); offsetf = plot_fftview(fv, maxpow, 1.0, 0.0, 0); break; } case 'G': /* Goto a frequency */ case 'g': { char freqstr[50]; double freq = -1.0; while (freq < 0.0) { printf(" Enter the frequency (Hz) to go to:\n"); fgets(freqstr, 50, stdin); freqstr[strlen(freqstr) - 1] = '\0'; freq = atof(freqstr); } offsetf = 0.0; centerr = freq * T; printf(" Moving to frequency %.15g.\n", freq); free(fv); fv = get_fftview(centerr, zoomlevel, lofp); cpgpage(); offsetf = plot_fftview(fv, maxpow, 1.0, centerr, 2); } break; case 'H': /* Show harmonics */ case 'h': { double retval; retval = harmonic_loop(xid, centerr, zoomlevel, lofp); if (retval > 0.0) { offsetf = 0.0; centerr = retval; free(fv); fv = get_fftview(centerr, zoomlevel, lofp); cpgpage(); offsetf = plot_fftview(fv, maxpow, 1.0, centerr, 2); } } break; case '?': /* Print help screen */ print_help(); break; case 'D': /* Show details about a selected point */ case 'd': { double newr; printf(" Searching for peak near freq = %.7g Hz...\n", (inx + offsetf)); newr = find_peak(inx + offsetf, fv, lofp); centerr = newr; free(fv); fv = get_fftview(centerr, zoomlevel, lofp); cpgpage(); offsetf = plot_fftview(fv, maxpow, 1.0, centerr, 2); } break; case 'L': /* Load a zaplist */ case 'l': { int ii, len; char filename[200]; double *lobins, *hibins; printf(" Enter the filename containing the zaplist to load:\n"); fgets(filename, 199, stdin); len = strlen(filename) - 1; filename[len] = '\0'; numzaplist = get_birdies(filename, T, 0.0, &lobins, &hibins); lenzaplist = numzaplist + 20; /* Allow some room to add more */ if (lenzaplist) free(zaplist); zaplist = (bird *) malloc(sizeof(bird) * lenzaplist); for (ii = 0; ii < numzaplist; ii++) { zaplist[ii].lobin = lobins[ii]; zaplist[ii].hibin = hibins[ii]; } vect_free(lobins); vect_free(hibins); printf("\n"); cpgpage(); offsetf = plot_fftview(fv, maxpow, 1.0, 0.0, 0); } break; case 'Z': /* Add a birdie to a zaplist */ case 'z': { int badchoice = 2; float lox, hix, loy, hiy; double rs[2]; char choice; if (numzaplist + 1 > lenzaplist) { lenzaplist += 10; zaplist = (bird *) realloc(zaplist, sizeof(bird) * lenzaplist); } cpgqwin(&lox, &hix, &loy, &hiy); printf(" Click the left mouse button on the first frequency limit.\n"); while (badchoice) { cpgcurs(&inx, &iny, &choice); if (choice == 'A' || choice == 'a') { rs[2 - badchoice] = ((double) inx + offsetf) * T; cpgsave(); cpgsci(7); cpgmove(inx, 0.0); cpgdraw(inx, hiy); cpgunsa(); badchoice--; if (badchoice == 1) printf (" Click the left mouse button on the second frequency limit.\n"); } else { printf(" Option not recognized.\n"); } }; if (rs[1] > rs[0]) { zaplist[numzaplist].lobin = rs[0]; zaplist[numzaplist].hibin = rs[1]; } else { zaplist[numzaplist].lobin = rs[1]; zaplist[numzaplist].hibin = rs[0]; } printf(" The new birdie has: f_avg = %.15g f_width = %.15g\n\n", 0.5 * (zaplist[numzaplist].hibin + zaplist[numzaplist].lobin) / T, (zaplist[numzaplist].hibin - zaplist[numzaplist].lobin) / T); numzaplist++; qsort(zaplist, numzaplist, sizeof(bird), compare_birds); cpgpage(); offsetf = plot_fftview(fv, maxpow, 1.0, 0.0, 0); } break; case 'P': /* Print the current plot */ case 'p': { int len; char filename[200]; printf(" Enter the filename to save the plot as:\n"); fgets(filename, 196, stdin); len = strlen(filename) - 1; filename[len + 0] = '/'; filename[len + 1] = 'P'; filename[len + 2] = 'S'; filename[len + 3] = '\0'; psid = cpgopen(filename); cpgslct(psid); cpgpap(10.25, 8.5 / 11.0); cpgiden(); cpgscr(15, 0.8, 0.8, 0.8); offsetf = plot_fftview(fv, maxpow, 1.0, 0.0, 0); cpgclos(); cpgslct(xid); cpgscr(15, 0.4, 0.4, 0.4); filename[len] = '\0'; printf(" Wrote the plot to the file '%s'.\n", filename); } break; case 'N': /* Changing power normalization */ case 'n': { float inx2 = 0.0, iny2 = 0.0; char choice; unsigned char badchoice = 1; printf(" Specify the type of power normalization:\n" " m,M : Median values determined locally\n" " d,D : DC frequency amplitude\n" " r,R : Raw powers (i.e. no normalization)\n" " u,U : User specified interval (the average powers)\n"); while (badchoice) { cpgcurs(&inx2, &iny2, &choice); switch (choice) { case 'M': case 'm': norm_const = 0.0; maxpow = 0.0; badchoice = 0; printf (" Using local median normalization. Autoscaling is on.\n"); break; case 'D': case 'd': norm_const = 1.0 / r0; maxpow = 0.0; badchoice = 0; printf (" Using DC frequency (%f) normalization. Autoscaling is on.\n", r0); break; case 'R': case 'r': norm_const = 1.0; maxpow = 0.0; badchoice = 0; printf (" Using raw powers (i.e. no normalization). Autoscaling is on.\n"); break; case 'U': case 'u': { char choice2; float xx = inx, yy = iny; int lor, hir, numr; double avg, var; printf (" Use the left mouse button to select a left and right boundary\n" " of a region to calculate the average power.\n"); do { cpgcurs(&xx, &yy, &choice2); } while (choice2 != 'A' && choice2 != 'a'); lor = (int) ((xx + offsetf) * T); cpgsci(7); cpgmove(xx, 0.0); cpgdraw(xx, 10.0 * fv->maxpow); do { cpgcurs(&xx, &yy, &choice2); } while (choice2 != 'A' && choice2 != 'a'); hir = (int) ((xx + offsetf) * T); cpgmove(xx, 0.0); cpgdraw(xx, 10.0 * fv->maxpow); cpgsci(1); if (lor > hir) { int tempr; tempr = hir; hir = lor; lor = tempr; } numr = hir - lor + 1; avg_var(lofp->rawpowers + lor - lofp->rlo, numr, &avg, &var); printf(" Selection has: average = %.5g\n" " std dev = %.5g\n", avg, sqrt(var)); norm_const = 1.0 / avg; maxpow = 0.0; badchoice = 0; printf (" Using %.5g as the normalization constant. Autoscaling is on.\n", avg); break; } default: printf(" Unrecognized choice '%c'.\n", choice); break; } } free(fv); fv = get_fftview(centerr, zoomlevel, lofp); cpgpage(); offsetf = plot_fftview(fv, maxpow, 1.0, 0.0, 0); } break; case 'Q': /* Quit */ case 'q': printf(" Quitting...\n"); free(fv); cpgclos(); break; default: printf(" Unrecognized option '%c'.\n", inchar); break; } } while (inchar != 'Q' && inchar != 'q'); free_fftpart(lofp); #ifdef USEMMAP close(mmap_file); #else fclose(fftfile); #endif if (lenzaplist) free(zaplist); printf("Done\n\n"); return 0; }
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(); }
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(); }
int main(int argc, char *argv[]) { float minval = SMALLNUM, maxval = LARGENUM, inx = 0, iny = 0; int centern, offsetn; int zoomlevel, maxzoom = 0, minzoom, xid, psid; char *rootfilenm, inchar; datapart *lodp; dataview *dv; basicstats *statvals; if (argc == 1) { printf("\nusage: exploredat datafilename\n\n"); exit(0); } printf("\n\n"); printf(" Interactive Data Explorer\n"); printf(" by Scott M. Ransom\n"); printf(" November, 2001\n"); print_help(); { int hassuffix = 0; char *suffix; hassuffix = split_root_suffix(argv[1], &rootfilenm, &suffix); if (hassuffix) { if (strcmp(suffix, "dat") != 0) { printf ("\nInput file ('%s') must be a single PRESTO data file ('.dat')!\n\n", argv[1]); free(suffix); exit(0); } free(suffix); } else { printf("\nInput file ('%s') must be a PRESTO data file ('.dat')!\n\n", argv[1]); exit(0); } } /* Read the info file */ readinf(&idata, rootfilenm); if (idata.object) { printf("Examining %s data from '%s'.\n\n", remove_whitespace(idata.object), argv[1]); } else { printf("Examining data from '%s'.\n\n", argv[1]); } #ifdef USEMMAP mmap_file = open(argv[1], O_RDONLY); { int rt; struct stat buf; rt = fstat(mmap_file, &buf); if (rt == -1) { perror("\nError in fstat() in exploredat.c"); printf("\n"); exit(-1); } Ndat = buf.st_size / sizeof(float); } lodp = get_datapart(0, Ndat); #else { int numsamp; datfile = chkfopen(argv[1], "rb"); Ndat = chkfilelen(datfile, sizeof(float)); numsamp = (Ndat > MAXPTS) ? (int) MAXPTS : (int) Ndat; lodp = get_datapart(0, numsamp); } #endif /* Plot the initial data */ centern = 0.5 * INITIALNUMPTS; if (centern > lodp->nn) centern = lodp->nn / 2; zoomlevel = LOGMAXDISPNUM - LOGINITIALNUMPTS; minzoom = LOGMAXDISPNUM - LOGMAXPTS; maxzoom = LOGMAXDISPNUM - LOGMINDISPNUM; dv = get_dataview(centern, zoomlevel, lodp); /* Prep the XWIN device for PGPLOT */ xid = cpgopen("/XWIN"); if (xid <= 0) { free_datapart(lodp); #ifdef USEMMAP close(mmap_file); #else fclose(datfile); #endif free(dv); exit(EXIT_FAILURE); } cpgask(0); cpgpage(); offsetn = plot_dataview(dv, minval, maxval, 1.0); do { cpgcurs(&inx, &iny, &inchar); if (DEBUGOUT) printf("You pressed '%c'\n", inchar); switch (inchar) { case ' ': /* Toggle stats and sample plotting on/off */ /* 0 = both, 1 = stats only, 2 = data only */ plotstats++; plotstats = plotstats % 3; cpgpage(); offsetn = plot_dataview(dv, minval, maxval, 1.0); break; case 'M': /* Toggle between median and average */ case 'm': usemedian = (usemedian) ? 0 : 1; free(dv); dv = get_dataview(centern, zoomlevel, lodp); cpgpage(); offsetn = plot_dataview(dv, minval, maxval, 1.0); break; case 'A': /* Zoom in */ case 'a': centern = inx + offsetn; case 'I': case 'i': if (DEBUGOUT) printf(" Zooming in (zoomlevel = %d)...\n", zoomlevel); if (zoomlevel < maxzoom) { zoomlevel++; free(dv); dv = get_dataview(centern, zoomlevel, lodp); cpgpage(); offsetn = plot_dataview(dv, minval, maxval, 1.0); } else printf(" Already at maximum zoom level (%d).\n", zoomlevel); break; case 'X': /* Zoom out */ case 'x': case 'O': case 'o': if (DEBUGOUT) printf(" Zooming out (zoomlevel = %d)...\n", zoomlevel); if (zoomlevel > minzoom) { zoomlevel--; free(dv); dv = get_dataview(centern, zoomlevel, lodp); cpgpage(); offsetn = plot_dataview(dv, minval, maxval, 1.0); } else printf(" Already at minimum zoom level (%d).\n", zoomlevel); break; case '<': /* Shift left 1 full screen */ centern -= dv->numsamps + dv->numsamps / 8; case ',': /* Shift left 1/8 screen */ if (DEBUGOUT) printf(" Shifting left...\n"); centern -= dv->numsamps / 8; { /* Should probably get the previous chunk from the datfile... */ double lowestr; lowestr = 0.5 * dv->numsamps; if (centern < lowestr) centern = lowestr; } free(dv); dv = get_dataview(centern, zoomlevel, lodp); cpgpage(); offsetn = plot_dataview(dv, minval, maxval, 1.0); break; case '>': /* Shift right 1 full screen */ centern += dv->numsamps - dv->numsamps / 8; case '.': /* Shift right 1/8 screen */ centern += dv->numsamps / 8; if (DEBUGOUT) printf(" Shifting right...\n"); { /* Should probably get the next chunk from the datfile... */ double highestr; highestr = lodp->nlo + lodp->nn - 0.5 * dv->numsamps; if (centern > highestr) centern = highestr; } free(dv); dv = get_dataview(centern, zoomlevel, lodp); cpgpage(); offsetn = plot_dataview(dv, minval, maxval, 1.0); break; case '+': /* Increase height of top edge */ { float dy; if (maxval > 0.5 * LARGENUM) { printf(" Auto-scaling of top edge is off.\n"); if (minval < 0.5 * SMALLNUM) dy = dv->maxval - dv->minval; else dy = dv->maxval - minval; maxval = dv->maxval + 0.1 * dy; } else { if (minval < 0.5 * SMALLNUM) dy = maxval - dv->minval; else dy = maxval - minval; maxval += 0.1 * dy; } cpgpage(); offsetn = plot_dataview(dv, minval, maxval, 1.0); break; } case '_': /* Decrease height of top edge */ { float dy; if (maxval > 0.5 * LARGENUM) { printf(" Auto-scaling of top edge is off.\n"); if (minval < 0.5 * SMALLNUM) dy = dv->maxval - dv->minval; else dy = dv->maxval - minval; maxval = dv->maxval - 0.1 * dy; } else { if (minval < 0.5 * SMALLNUM) dy = maxval - dv->minval; else dy = maxval - minval; maxval -= 0.1 * dy; } cpgpage(); offsetn = plot_dataview(dv, minval, maxval, 1.0); break; } case '=': /* Increase height of bottom edge */ { float dy; if (minval < 0.5 * SMALLNUM) { printf(" Auto-scaling of bottom edge is off.\n"); if (maxval > 0.5 * LARGENUM) dy = dv->maxval - dv->minval; else dy = maxval - dv->minval; minval = dv->minval + 0.1 * dy; } else { if (maxval > 0.5 * LARGENUM) dy = dv->maxval - minval; else dy = maxval - minval; minval += 0.1 * dy; } cpgpage(); offsetn = plot_dataview(dv, minval, maxval, 1.0); break; } case '-': /* Decrease height of bottom edge */ { float dy; if (minval < 0.5 * SMALLNUM) { printf(" Auto-scaling of bottom edge is off.\n"); if (maxval > 0.5 * LARGENUM) dy = dv->maxval - dv->minval; else dy = maxval - dv->minval; minval = dv->minval - 0.1 * dy; } else { if (maxval > 0.5 * LARGENUM) dy = dv->maxval - minval; else dy = maxval - minval; minval -= 0.1 * dy; } cpgpage(); offsetn = plot_dataview(dv, minval, maxval, 1.0); break; } case 'S': /* Auto-scale */ case 's': printf(" Auto-scaling is on.\n"); minval = SMALLNUM; maxval = LARGENUM; cpgpage(); offsetn = plot_dataview(dv, minval, maxval, 1.0); break; case 'G': /* Goto a time */ case 'g': { char timestr[50]; double time = -1.0; while (time < 0.0) { printf (" Enter the time (s) from the beginning of the file to go to:\n"); fgets(timestr, 50, stdin); timestr[strlen(timestr) - 1] = '\0'; time = atof(timestr); } offsetn = 0.0; centern = (int) (time / idata.dt + 0.5); printf(" Moving to time %.15g (data point %d).\n", time, centern); free(dv); dv = get_dataview(centern, zoomlevel, lodp); cpgpage(); offsetn = plot_dataview(dv, minval, maxval, 1.0); } break; case '?': /* Print help screen */ print_help(); break; case 'P': /* Print the current plot */ case 'p': { int len; char filename[200]; printf(" Enter the filename to save the plot as:\n"); fgets(filename, 195, stdin); len = strlen(filename) - 1; filename[len + 0] = '/'; filename[len + 1] = 'C'; filename[len + 2] = 'P'; filename[len + 3] = 'S'; filename[len + 4] = '\0'; psid = cpgopen(filename); cpgslct(psid); cpgpap(10.25, 8.5 / 11.0); cpgiden(); offsetn = plot_dataview(dv, minval, maxval, 1.0); cpgclos(); cpgslct(xid); filename[len] = '\0'; printf(" Wrote the plot to the file '%s'.\n", filename); } break; case 'V': /* Show the basic statistics for the current dataview */ case 'v': statvals = calc_stats(dv, lodp); printf("\n Statistics:\n" " Low sample %d\n" " Number of samples %d\n" " Low time (s) %.7g\n" " Duration of samples (s) %.7g\n" " Maximum value %.7g\n" " Minimum value %.7g\n" " Average value %.7g\n" " Median value %.7g\n" " Standard Deviation %.7g\n" " Skewness %.7g\n" " Kurtosis %.7g\n\n", dv->lon, dv->numsamps, dv->lon * idata.dt, dv->numsamps * idata.dt, statvals->max, statvals->min, statvals->average, statvals->median, statvals->stdev, statvals->skewness, statvals->kurtosis); free(statvals); break; case 'Q': /* Quit */ case 'q': printf(" Quitting...\n"); free(dv); cpgclos(); break; default: printf(" Unrecognized option '%c'.\n", inchar); break; } } while (inchar != 'Q' && inchar != 'q'); free_datapart(lodp); #ifdef USEMMAP close(mmap_file); #else fclose(datfile); #endif printf("Done\n\n"); return 0; }
/* change the size of the view surface */ static void _pgpap (double *w, double *a) { cpgpap ((float) *w, (float) *a); }