void setup_plot_drawable( App *a ) { struct { Display *display; Drawable drawable; } xinfo; PLFLT x[3] = { 1, 3, 4 }; PLFLT y[3] = { 3, 2, 5 }; plsdev( "xcairo" ); plsetopt( "drvopt", "external_drawable" ); plinit(); #if TO_PIXMAP == 1 // Here we set up to draw to a pixmap xinfo.display = GDK_PIXMAP_XDISPLAY( a->plotwindow_pixmap ); xinfo.drawable = GDK_PIXMAP_XID( a->plotwindow_pixmap ); #else // Alternatively, we can do direct to a visible X Window xinfo.display = GDK_WINDOW_XDISPLAY( a->plotwindow->window ); xinfo.drawable = GDK_WINDOW_XID( a->plotwindow->window ); #endif pl_cmd( PLESC_DEVINIT, &xinfo ); plenv( 0, 5, 0, 5, 0, 0 ); plline( 3, x, y ); plend(); }
int plp_init(const char *driver, const char *_title, int _is_complex) { int i; if (2*NOF_INPUT_ITF > 1) { modinfo("Multiple signals are currently displayed in the same plot\n"); } plsdev(driver); plinit(); pladv(0); title = _title; is_complex = _is_complex; for (i=0;i<2*NOF_INPUT_ITF;i++) { legends[i] = (const char*) ""; } for (i=0;i<INPUT_MAX_SAMPLES;i++) { t[i] = i; } setup_legend(); xlabel = xlabel_def; ylabel = ylabel_def; plscol0a( 14, 0, 0, 0, 1); reset_axis(); return 0; }
int main(int argc, char **argv) { enum Constexpr {n_points = 1000}; double mu = 1.0; gsl_odeiv2_system sys = {ode_func, ode_jac, 2, &mu}; gsl_odeiv2_driver * d= gsl_odeiv2_driver_alloc_y_new( &sys, gsl_odeiv2_step_rk8pd, 1e-6, 1e-6, 0.0 ); int i; double t = 0.0; double t1 = 100.0; /* Initial condition: f = 0 with speed 0. */ double y[2] = {1.0, 0.0}; double dt = t1 / n_points; double datax[n_points]; double datay[n_points]; for (i = 0; i < n_points; i++) { double ti = i * dt; int status = gsl_odeiv2_driver_apply(d, &t, ti, y); if (status != GSL_SUCCESS) { fprintf(stderr, "error, return value=%d\n", status); break; } /* Get output. */ printf("%.5e %.5e %.5e\n", t, y[0], y[1]); datax[i] = y[0]; datay[i] = y[1]; } /* Cleanup. */ gsl_odeiv2_driver_free(d); /* Plot. */ if (argc > 1 && argv[1][0] == '1') { plsdev("xwin"); plinit(); plenv( gsl_stats_min(datax, 1, n_points), gsl_stats_max(datax, 1, n_points), gsl_stats_min(datay, 1, n_points), gsl_stats_max(datay, 1, n_points), 0, 1 ); plstring(n_points, datax, datay, "*"); plend(); } return EXIT_SUCCESS; }
PlPlotWidget::PlPlotWidget(QWidget *parent) : QWidget(parent) { setAttribute( Qt::WA_DeleteOnClose ); plot = new QtExtWidget( parent->width(), parent->height(), parent ); //this should fit the widget box plmkstrm( &strm );// One window = One plot widget = one stream plsdev( "extqt" ); plsetqtdev( plot ); plinit(); plot->setBackgroundColor(255,255,255,1); //resize( 400, 320 ); pladv( 0 ); unsigned int col = 255; plscolbg(col,col,col); }
int main( int argc, const char *argv[] ) { cairo_surface_t *cairoSurface; cairo_t *cairoContext; cairoSurface = cairo_ps_surface_create( "ext-cairo-test.ps", 720, 540 ); cairoContext = cairo_create( cairoSurface ); plparseopts( &argc, argv, PL_PARSE_FULL ); plsdev( "extcairo" ); plinit(); pl_cmd( PLESC_DEVINIT, cairoContext ); plenv( 0.0, 1.0, 0.0, 1.0, 1, 0 ); pllab( "x", "y", "title" ); plend(); cairo_destroy( cairoContext ); cairo_surface_destroy( cairoSurface ); exit( 0 ); }
static PyObject * pl_partialInitXw(PyObject *self, PyObject *args) { PLINT ipls; PLStream *pls; TRY (PyArg_ParseTuple(args, ":pl_partialInitXw")); ipls=0; plmkstrm(&ipls); printf(" ipls=%d\n",ipls); plgpls(&pls); /* pls points directly to a structure PLStream */ printf(" pls OK \n"); /* Partially initialize X driver. */ pllib_init(); plsdev("xwin"); pllib_devinit(); plP_esc(PLESC_DEVINIT, NULL); printf("devinit OK \n"); return Py_BuildValue("i", ipls); }
static plplot_state_type * plplot_state_alloc( const void * init_arg ) { plplot_state_type * state = util_malloc( sizeof * state ); state->stream = 0; { const arg_pack_type * arg_pack = arg_pack_safe_cast_const( init_arg ); state->filename = util_alloc_string_copy( arg_pack_iget_const_ptr( arg_pack , 0) ); state->device = util_alloc_string_copy( arg_pack_iget_const_ptr( arg_pack , 1) ); plsstrm(state->stream); plsdev(state->device); /* Can this be NULL?? */ if (strcmp(state->device , "xwin") != 0) plsfnam(state->filename); } state->logx = false; state->logy = false; state->plbox_xopt = util_alloc_string_copy( PLOT_DEFAULT_PLBOX_XOPT ); state->plbox_yopt = util_alloc_string_copy( PLOT_DEFAULT_PLBOX_YOPT ); /** This color initialization must be here - do not really understand what for. */ plscol0(WHITE, 255, 255, 255); plscol0(BLACK, 0, 0, 0); plfontld(0); //plinit(); return state; }
int main( int argc, char *argv[] ) { PLINT digmax, cur_strm, new_strm; char ver[80]; // plplot initialization // Parse and process command line arguments plMergeOpts( options, "x01c options", notes ); plparseopts( &argc, argv, PL_PARSE_FULL ); // Get version number, just for kicks plgver( ver ); fprintf( stdout, "PLplot library version: %s\n", ver ); // Initialize plplot // Divide page into 2x2 plots // Note: calling plstar replaces separate calls to plssub and plinit plstar( 2, 2 ); // Select font set as per input flag if ( fontset ) plfontld( 1 ); else plfontld( 0 ); // Set up the data // Original case xscale = 6.; yscale = 1.; xoff = 0.; yoff = 0.; // Do a plot plot1( 0 ); // Set up the data xscale = 1.; yscale = 0.0014; yoff = 0.0185; // Do a plot digmax = 5; plsyax( digmax, 0 ); plot1( 1 ); plot2(); plot3(); // // Show how to save a plot: // Open a new device, make it current, copy parameters, // and replay the plot buffer // if ( f_name ) // command line option '-save filename' { printf( "The current plot was saved in color Postscript under the name `%s'.\n", f_name ); plgstrm( &cur_strm ); // get current stream plmkstrm( &new_strm ); // create a new one plsfnam( f_name ); // file name plsdev( "psc" ); // device type plcpstrm( cur_strm, 0 ); // copy old stream parameters to new stream plreplot(); // do the save by replaying the plot buffer plend1(); // finish the device plsstrm( cur_strm ); // return to previous stream } // Let's get some user input if ( locate_mode ) { for (;; ) { if ( !plGetCursor( &gin ) ) break; if ( gin.keysym == PLK_Escape ) break; pltext(); printf( "subwin = %d, wx = %f, wy = %f, dx = %f, dy = %f\n", gin.subwindow, gin.wX, gin.wY, gin.dX, gin.dY ); printf( "keysym = 0x%02x, button = 0x%02x, string = '%s', type = 0x%02x, state = 0x%02x\n", gin.keysym, gin.button, gin.string, gin.type, gin.state ); plgra(); } } // Don't forget to call plend() to finish off! plend(); exit( 0 ); }
void canopy::plot() { double max = haz[0]; for(int i=0; i<numNodes; i++) { if(haz[i]>max) max = haz[i]; } printf("max = %lf\n", max); // PLFLT xmin =0, ymin=0, xmax=1, ymax=1, // x[6]= {0.0, 1.0, 2.0, 3.0, 4.0, 5.0}, // y[6] = {0., 1.0, 4.0, 9.1, 15.5, 25.3}; double* y = new double[numNodes]; for(int i=0; i<numNodes; i++) { y[i] = i*cellsize; } double* x = new double[numNodes]; for(int i=0; i<numNodes; i++) { //---------------FIX THIS------------------!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! //x[i] = haz[i]/max; x[i] = haz[i]; //---------------FIX THIS------------------!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! if(i%100 == 0) printf("%lf\t%lf\n",x[i], y[i]); } PLFLT xmin =0, ymin=0, xmax=0.001, ymax=1; PLINT just=0, axis=0; plstream *pls; // plplot initialization pls = new plstream(); // declare plplot object //plsdev("wxwidgets"); // sets the plot device to WX Widget which // allows for viewing and saving the plot to a file // Note that saving postscript from within widgets is buggy. // other useful values in place of wxwidgets: // xwin - X-window display to screen // ps - postscript file // psc - color postscript file // Or just comment out line to get a list of choices //plsdev("psc"); plsdev("pdf"); //cairo uses the same color scheme as on screen - black on //red on black default plsfnam("haz.pdf");// sets the names of the output file // Parse and process command line arguments. //pls->parseopts( &argc, argv, PL_PARSE_FULL ); // device and other options // can be set from the command-line: // -dev devname sets the output device to "devname" // -o output_file sets the output file name to output_file // -h gives a list of all possible options pls->init(); // start plplot object pls->env(xmin, xmax, ymin, ymax, just, axis ); //Setup window size // - just=0 sets axis so they scale indepedently // - axis=0 draw axis box, ticks, and numeric labels // see "man plenv" for details pls->lab( "haz/max", "z/h", "haz plot"); // Plot the data points - (num_points, x, y. plot_symbol) // - plot_symbol=9 sets a circle with a dot in the // middle for the plot symbol - see "man plpoin" //pls->poin( numNodes, (PLFLT*) x,(PLFLT*) y, 9 ); pls->line( numNodes, (PLFLT*) x,(PLFLT*) y); delete pls; // close plot delete x; x = NULL; delete y; y = NULL; }
/* * Plot specified x/y coordinates, x as int32_t and y as float, with an arbitrary number * of separate lines, as lines and/or points. * Output is PDF file, location specified by 'fileName'. */ int plplotLines( PlplotSetup *setup, uint32_t numSamples, /* size of ix[] and fy[] arrays */ uint32_t numLines, /* size of lineDef[] array */ int32_t *ix, /* numSamples */ LineDef *lineDef, /* numLines */ const char *graphName, const char *fileName, bool plotPoints, /* true: plot points */ bool plotLine, /* true: plot line */ bool skipTrailZeroes) /* don't plot zero Y values at end of graph */ { if(setup == NULL) { printf("***plplotLine: setup required\n"); return -1; } char tmpFile[TEMP_FN_LEN]; makeTempFile(tmpFile, TEMP_FN_LEN); PLFLT fx[numSamples]; PLFLT minX = setup->minX; PLFLT maxX = setup->maxX; PLFLT minY = setup->minY; PLFLT maxY = setup->maxY; for(uint32_t dex=0; dex<numSamples; dex++) { fx[dex] = ix[dex]; } const char *yName = ""; if(setup->yAxisName) { yName = setup->yAxisName; } const char *xName = ""; if(setup->xAxisName) { xName = setup->xAxisName; } plsdev ("psc"); /* standard: background white, foreground (axes, labels, etc.) black */ plscolbg(PLOT_WHITE); plscol0(1, PLOT_BLACK); plsfnam(tmpFile); plsdiori(1.0); // portrait plinit(); plenv(minX, maxX, minY, maxY, 0, 0); pllab(xName, yName, graphName); for(uint32_t dex=0; dex<numLines; dex++) { uint32_t thisSamples = numSamples; if(skipTrailZeroes) { while((lineDef[dex].fy[thisSamples-1] == 0.0) && (thisSamples > 0)) { thisSamples--; } if(thisSamples == 0) { printf("***plplotLines: Warning: line with all zeroes skipped\n"); continue; } } plotOneLine(thisSamples, fx, &lineDef[dex], plotPoints, plotLine); } plend(); int ourRtn = psToPdf(tmpFile, fileName); unlink(tmpFile); return ourRtn; }
/* * Plot a histogram of prebinned data. X values are int32_t's, and the corresponding * Y values - the counts for each X - are uint32_t's. */ int plplotBins( uint32_t numBins, const int32_t *x, /* numBins of X values, monotonically increasing */ const uint32_t *y, /* numBins of Y values for each associated X */ const char *graphName, const char *fileName, const char *xAxisName, /* optional */ const char *yAxisName) /* optional */ { char tmpFile[TEMP_FN_LEN]; makeTempFile(tmpFile, TEMP_FN_LEN); PLINT totalBins = numBins + 2; /* PLFLT array of sample values */ PLFLT *xf = (PLFLT *)malloc(totalBins * sizeof(PLFLT)); /* these two will have Y values of zero */ xf[0] = x[0] - 1; xf[totalBins - 1] = x[numBins-1] + 1; const int32_t *ip = x; PLFLT *op = xf + 1; for(uint32_t dex=0; dex<numBins; dex++) { *op++ = *ip++; } /* PLFLT array of bins */ PLFLT *yf = (PLFLT *)malloc(totalBins * sizeof(PLFLT)); yf[0] = 0.0; yf[totalBins - 1] = 0.0; const uint32_t *uip = y; op = yf + 1; for(uint32_t dex=0; dex<numBins; dex++) { *op++ = *uip++; } /* get max Y value */ uint32_t maxY = 0; uip = y; for(uint32_t dex=0; dex<numBins; dex++) { uint32_t currY = *uip++; if(currY > maxY) { maxY = currY; } } const char *yName = yAxisName ? yAxisName : ""; const char *xName = xAxisName ? xAxisName : ""; #if HIST_COLOR plsdev ("psc"); plscolbg(255, 255, 255); /* white background */ #else plsdev ("ps"); #endif plsfnam(tmpFile); plsdiori(1.0); // portrait plinit(); plenv(xf[0], xf[totalBins - 1], 0, maxY, 0, 0); #if HIST_COLOR /* can we alter colors of lines and the spaces inside the histograms? */ plscolbg(255, 0, 0); /* red background */ plscol0(1, 255, 0, 0); /* red foreground - no effect */ #endif pllab(xName, yName, graphName); plbin(totalBins, xf, yf, PL_BIN_CENTRED); plend(); free(xf); free(yf); int ourRtn = psToPdf(tmpFile, fileName); unlink(tmpFile); return ourRtn; }
/* * Plot a histogram showing the number of occurences of each possible * value of 'samples'. */ int plplotHist( const int32_t *samples, uint32_t numSamples, const char *graphName, const char *fileName, const char *xAxisName, /* optional */ const char *yAxisName) /* optional */ { char tmpFile[TEMP_FN_LEN]; makeTempFile(tmpFile, TEMP_FN_LEN); /* First determine the range, i.e. the number of bins */ int32_t minSamp = samples[0]; int32_t maxSamp = samples[0]; for(uint32_t dex=0; dex<numSamples; dex++) { int32_t s = samples[dex]; if(s < minSamp) { minSamp = s; } if(s > maxSamp) { maxSamp = s; } } /* When we specify PL_BIN_CENTRED, the min and max values are half the normal width */ minSamp--; maxSamp++; PLINT numBins = maxSamp - minSamp + 1; /* One array containing the sample values, x */ PLFLT *x = (PLFLT *)malloc(numBins * sizeof(PLFLT)); int32_t binNum = minSamp; for(uint32_t dex=0; dex<(uint32_t)numBins; dex++) { x[dex] = binNum++; } /* Now make and fill the bins proper */ PLFLT *y = (PLFLT *)malloc(numBins * sizeof(PLFLT)); for(uint32_t dex=0; dex<(uint32_t)numBins; dex++) { y[dex] = 0; } PLFLT maxY = 0.0; for(uint32_t dex=0; dex<numSamples; dex++) { int32_t s = samples[dex]; PLFLT *yp = y + s - minSamp; *yp += 1.0; if(*yp > maxY) { maxY = *yp; } } const char *yName = yAxisName ? yAxisName : ""; const char *xName = xAxisName ? xAxisName : ""; #if HIST_COLOR plsdev ("psc"); plscolor(1); plscolbg(255, 255, 255); /* white background */ #else plsdev ("ps"); #endif plsfnam(tmpFile); plsdiori(1.0); // portrait plinit(); plenv(minSamp, maxSamp, 0, maxY, 0, 0); #if HIST_COLOR /* can we alter colors of lines and the spaces inside the histograms? */ plscolbg(255, 0, 0); /* red background */ plscol0(1, 255, 0, 0); /* red foreground - no effect */ #endif pllab(xName, yName, graphName); plbin(numBins, x, y, PL_BIN_CENTRED); plend(); free(x); free(y); int ourRtn = psToPdf(tmpFile, fileName); unlink(tmpFile); return ourRtn; }
struct fft_average *do_fft(double *in, int max) { fftw_complex *out; double *fft_in; fftw_plan p; int i; double xmax = 0, xmin = 0, ymin = 0, ymax = 0; double average = 0; struct fft_average *avg; avg = malloc(sizeof(struct fft_average)); if (!avg) exit(1); fft_in = (double *)fftw_malloc(sizeof(double) * max); out = (fftw_complex *)fftw_malloc(sizeof(fftw_complex) * max); p = fftw_plan_dft_r2c_1d(max, fft_in, out, FFTW_PRESERVE_INPUT); for (i = 0; i < max; i++) fft_in[i] = in[i]; // memcpy(fft_in, in, sizeof(double) * max); fftw_execute(p); for (i = 0; i < max; i++) { double *d; d = out[i]; if (d[0] > xmax) xmax = d[0]; else if (d[0] < xmin) xmin = d[0]; if (d[1] > ymax) ymax = d[1]; else if (d[1] < ymin) ymin = d[1]; } plsdev("xwin"); plinit(); plenv(-1, 1, -1, 1, 0, 0); for (i = 0; i < max; i++) { PLFLT x; PLFLT y; double *d; d = out[i]; if (d[0] < 0) { x = d[0] / -xmin; avg->xavg += (d[0] / -xmin); if (i > 0) avg->xavg /= 2; } else { x = d[0] / xmax; avg->xavg += (d[0] / xmax); if (i > 0) avg->xavg /= 2; } if (d[1] < 0) { y = d[1] / -ymin; avg->yavg += (d[1] / -ymin); if (i > 0) avg->yavg /= 2; } else { y = d[1] / ymax; avg->yavg += (d[1] / ymax); if (i > 0) avg->yavg /= 2; } plpoin(1, &x, &y, 1); } plend(); fftw_destroy_plan(p); fftw_free(fft_in); fftw_free(out); return avg; }
int main() { // http://cdiac.ornl.gov/pns/current_ghg.html const double c_co2 = 390; const double c_n2o = 0.32; const double c_co = 0.1; const double c_ch4 = 1.775; const double c_o2 = 20.9e+4; const double cp=1004; /* J/kg K */ const double deltat=3600.0*4.0; /* s */ const double Ra=287; /* J/kg K */ int timesteps = 0; int ilev=0; int ilyr=0; const int nlyr=20; /* Number of Layers */ const int nlev=nlyr+1; int instabil=FALSE; int status; const double deltap=PSURF/nlyr; const double kappa=Ra/cp; double *p=calloc(nlev,sizeof(double)); double *T=calloc(nlyr,sizeof(double)); double *theta=calloc(nlev,sizeof(double)); double *plyr=calloc(nlyr,sizeof(double)); double *z=calloc(nlev,sizeof(double)); double *zlyr=calloc(nlyr,sizeof(double)); double *deltazlyr=calloc(nlyr,sizeof(double)); double *deltazlev=calloc(nlev,sizeof(double)); double *h2o=calloc(nlyr,sizeof(double)); double *o3=calloc(nlyr,sizeof(double)); double ***dtaumol; double **wgt; double *wavelength; int nbnd=0; int *nch; int iv; int iq; double *tmplev=calloc(nlev, sizeof(double)); /* temporary vector with length lev */ double *tmplyr=calloc(nlyr, sizeof(double)); /* temporary vector with length lyr */ double *eup=calloc(nlev, sizeof(double)); double *edn=calloc(nlev, sizeof(double)); double *euptmp=calloc(nlev, sizeof(double)); double *edntmp=calloc(nlev, sizeof(double)); double *edirtmp=calloc(nlev, sizeof(double)); double *enet=calloc(nlyr, sizeof(double)); double *deltaTday=calloc(nlyr, sizeof(double)); double *deltaT=calloc(nlyr, sizeof(double)); //------------- Define variables for Rodents---------------// const double gr_albedo=0.3; /* 1 */ const int mu_counterlimit = (int)(24.0 * 3600 / deltat); double* const mu_0 = calloc(mu_counterlimit, sizeof(double)); int mu_counter; // --- start mu_0 { double mu_weight = 0; for(mu_counter=0; mu_counter < mu_counterlimit; mu_counter++) { mu_0[mu_counter] = cos( 2.0*M_PI / mu_counterlimit * (mu_counter + mu_counter+1) / 2.0 ); if(mu_0[mu_counter] > 0) mu_weight += mu_0[mu_counter]; } // weight needs to be adjusted such that it is 0.5 for half of the steps (day-only) mu_weight = mu_weight / (mu_counterlimit/2.0 * 0.5); for(mu_counter=0; mu_counter < mu_counterlimit; mu_counter++) { mu_0[mu_counter] = mu_0[mu_counter] / mu_weight; printf("mu_0[%d] = %e\n", mu_counter, mu_0[mu_counter]); } mu_counter = 0; } // --- end mu_0 double* S_0; double* omega_0=calloc(nlyr,sizeof(double)); double* gassy=calloc(nlyr,sizeof(double)); double* f=calloc(nlyr,sizeof(double)); for(ilyr=0; ilyr<nlyr; ilyr++) { omega_0[ilyr] = 0.f; gassy[ilyr] = 0; //0.85f; f[ilyr] = 0; //0.8f; } { double *temp1, *temp2, *temp3; int temp4; status=read_4c_file("mstrnx.data/solar.dat", &temp1, &temp2, &temp3, &S_0, &temp4); if (status !=0) { printf("Error reading Solar.dat\n"); return EXIT_FAILURE; } free(temp1); free(temp2); free(temp3); } //--------------------- Plot color -------------------------// #ifndef _NOPLOT plscolbg (255, 255, 255); /* background color white */ plscol0 (15, 0, 0, 0); /* set color 15 to black */ plsdev ("xwin"); /* if not called, the user is asked! */ plinit (); plssub(2,2); #endif //--------------------- Calculate pressure for layers and levels -------------// for(ilev=0; ilev<nlev; ilev++) { /* Calculation of the Pressure at the Levels p[ilev] */ p[ilev]=PSURF*ilev/(nlev-1); } for(ilyr=0; ilyr<nlyr; ilyr++) { /* Calculation of the Pressure in the Layers*/ plyr[ilyr]= 0.5*(p[ilyr]+p[ilyr+1]); } //----------------------- Reading afglus ------------------------// { double *ztemp; double *ptemp; double *Ttemp; double *h2otemp; double *o3temp; int status; int ntemp; int itemp; unsigned int mintemp = 0; unsigned int mintemp2 = 0; status = read_5c_file("mstrnx.data/afglus.atm", &ztemp, &ptemp, &Ttemp, &h2otemp, &o3temp, &ntemp); if (status !=0) { printf("Error reading Temperature profile\n"); return EXIT_FAILURE; } /* for (itemp=0; itemp<ntemp; itemp++) { printf("itemp = %d, ztemp = %f, ptemp = %f, Ttemp = %f, h2otemp = %f, o3temp = %f\n", itemp, ztemp[itemp], ptemp[itemp], Ttemp[itemp], h2otemp[itemp], o3temp[itemp]); } */ //-------------------- Interpolate T, h2o and o3 to layers --------------// for (ilyr=0; ilyr<nlyr; ilyr++) { // printf("ilev = %d, searching for %f\n", ilyr, plyr[ilyr]); for (itemp=0; itemp<ntemp; itemp++) { if ( abs(ptemp[mintemp]- plyr[ilyr])>abs(ptemp[itemp]-plyr[ilyr])) { mintemp=itemp; } } if (ptemp[mintemp]<plyr[ilyr]) { mintemp2 = mintemp+1; } else { mintemp2 = mintemp-1; } // printf("\tmintemp = %d,\tp = %f\n", mintemp, ptemp[mintemp]); // printf("\tmintemp2 = %d,\tp = %f\n", mintemp2, ptemp[mintemp2]); const double weight2 = abs(ptemp[mintemp]-plyr[ilyr]); const double weight1 = abs(ptemp[mintemp2]-plyr[ilyr]); const double norm = weight1 + weight2; /* T in levels?!?! */ T[ilyr] = Ttemp[mintemp]*weight1 + Ttemp[mintemp2]*weight2; T[ilyr] /= norm; h2o[ilyr] = h2otemp[mintemp]*weight1 + h2otemp[mintemp2]*weight2; h2o[ilyr] /= norm; o3[ilyr] = o3temp[mintemp]*weight1 + o3temp[mintemp2]*weight2; o3[ilyr] /= norm; } } for (ilyr=0; ilyr<nlyr; ilyr++) { printf("ilyr = %d, plyr = %f,\tT = %f,\th2o = %f,\to3 = %f\n", ilyr, plyr[ilyr], T[ilyr], h2o[ilyr], o3[ilyr]); } /* for (ilyr=0; ilyr<nlyr; ilyr++) { printf("T[%d] = %f\n", ilyr, T[ilyr]); } for (ilyr=0; ilyr<nlyr; ilyr++) { printf("o3[%d] = %f\n", ilyr, o3[ilyr]); } for (ilyr=0; ilyr<nlyr; ilyr++) { printf("h2o[%d] = %f\n", ilyr, h2o[ilyr]); } */ //--------------------------------- Starting while-loop ----------------------------------// //----------------------------------------------------------------------------------------// while (timesteps*deltat<TIME_MAX) { // printf("\nNew time %d: T = %f\n", (int)(timesteps*deltat), T[nlyr-1]); timesteps++; for(ilev=0; ilev<nlev; ilev++) { /* Reseting edn, eup and enet */ edn[ilev] = 0; eup[ilev] = 0; if(ilev < nlyr) //enet is defined for ilyr only enet[ilev]=0; } //--------------------- Calculate z ----------------------// for (ilyr=0;ilyr<nlyr; ilyr++) { /* z for layers */ deltazlyr[ilyr]=(Ra*T[ilyr]*deltap)/(plyr[ilyr]*g); } zlyr[nlyr-1]=0; //check this one time for (ilyr=nlyr-2; ilyr >= 0; ilyr--) { zlyr[ilyr]=zlyr[ilyr+1]+deltazlyr[ilyr]; } for (ilev=0;ilev<nlev-1; ilev++) { /* z for levels */ deltazlev[ilev]=(Ra*T[ilev]*deltap)/(plyr[ilev]*g); } z[nlev-1]=0; for (ilev=nlev-2; ilev >= 0; ilev--) { z[ilev]=z[ilev+1]+deltazlev[ilev]; } //--------------------- Use k-distribution ---------------------// /* mu_0 is defined for a 8-part cycle of the earth, i.e. a timestep of 3 hours! */ if(++mu_counter == mu_counterlimit) mu_counter = 0; //calculate it every two days! if((timesteps-1) % 10 == 0) //warning, wavelength is in nm! status = ck_mstrnx (z, plyr, T, h2o, o3, nlev, /*lyrflag*/ 1, c_co2, c_n2o, c_co, c_ch4, c_o2, &dtaumol, &wgt, &wavelength, &nbnd, &nch); for(iv=0; iv<nbnd; iv++) { //printf("iv = %d, wavelength = %e, S0 = %e\n", iv, wavelength[iv], S_0[iv]); //------------- Use schwarzschild and sum edn eup --------// for(iq=0; iq<nch[iv]; iq++) { schwarzschild2(dtaumol[iv][iq], T, nlev, T[nlyr-1], edntmp, euptmp, wavelength[iv]*1e-6,wavelength[iv+1]*1e-6, tmplev, tmplyr); for(ilev=0; ilev<nlev; ilev++) { edn[ilev] += edntmp[ilev]*wgt[iv][iq]; eup[ilev] += euptmp[ilev]*wgt[iv][iq]; //printf("ilev = %d, iv = %d of %d, iq = %d of %d, wgt = %e, edntmp = %e, euptmp = %e\n", ilev, iv, nbnd, iq, nch[iv], wgt[iv][iq], edntmp[ilev], euptmp[ilev]); } //------------------- Include Rodents---------------------// if(mu_0[mu_counter] > 0) { rodents_solar(nlyr, dtaumol[iv][iq], omega_0, gassy, f, S_0[iv], mu_0[mu_counter], gr_albedo, edntmp, euptmp, edirtmp); for(ilev=0; ilev<nlev; ilev++) { edn[ilev] += (edntmp[ilev]+edirtmp[ilev])*wgt[iv][iq]; eup[ilev] += euptmp[ilev]*wgt[iv][iq]; //printf("ilev = %d, iv = %d of %d, iq = %d of %d, wgt = %e, edntmp = %e, euptmp = %e, edirtmp = %e\n", ilev, iv, nbnd, iq, nch[iv], wgt[iv][iq], edntmp[ilev], euptmp[ilev], edirtmp[ilev]); } } } } //---------------- Calculate enet -----------------------// for(ilyr=0; ilyr<nlyr-1; ilyr++) { enet[ilyr] = eup[ilyr+1] + edn[ilyr] - eup[ilyr] - edn[ilyr+1]; } for (ilev=0; ilev<nlev; ilev++) { //printf("ilev = %d, eup = %f, edn = %f\n", ilev, eup[ilev], edn[ilev]); } //---------------- Calculate temperature gain per layer -----------// for (ilyr=0; ilyr<nlyr-1; ilyr++) { deltaT[ilyr]=(enet[ilyr]*g*deltat)/((deltap*100.0)*cp); T[ilyr] +=deltaT[ilyr]; //printf("dT[ilyr] = %f\n", ilyr, deltaT[ilyr]); } //----------------Calculate Temperature gain for ground layer ---------// deltaT[nlyr-1]=((edn[nlyr-1]-eup[nlyr-1])*g*deltat)/((deltap*100.0)*cp); T[nlyr-1] += deltaT[nlyr-1]; //---------- Convert T to theta ------------// for (ilyr=0; ilyr<nlyr; ilyr++) { theta[ilyr]=pow(PSURF/plyr[ilyr], kappa)*T[ilyr]; //printf("%d %f\n", ilyr, theta[ilyr]); } //------------ Convection -------------------// instabil = FALSE; for (ilyr=0; ilyr<nlyr;ilyr++) { /* Testing for Instability */ if (theta[ilyr+1]>theta[ilyr]) { instabil = TRUE; break; } } if (instabil) { /* Convection - Sorting of Layers according to theta */ qsort (theta, nlyr, sizeof(double), sortfunc); // printf ("Konvektion :-)\n"); } for (ilyr=0; ilyr<nlyr; ilyr++) { /* Conversion from theta to T */ T[ilyr] = theta[ilyr] / (pow(PSURF/plyr[ilyr], kappa)); //printf("%d %f\n", ilyr, theta[ilyr]); } //-------------------- Print every x timestep ------------// if(timesteps % (int)(10) == 0) { printf ("timestep %d\n", timesteps); /* Printing time in readable format * In order to remove days, hours or minutes * just add // in front of the appropriate line */ int time = timesteps*deltat; printf("time "); printf("%dd = ", (int)(time / 3600 / 24)); printf("%dh = ", (int)(time / 3600 )); printf("%dmin = ", (int)(time / 60 )); printf("%ds\n", time); printf(" Tsurf=%f\n", T[nlyr-1]); for (ilyr=0; ilyr<nlyr; ilyr++) { deltaTday[ilyr]=deltaT[ilyr]*86.4/2; } plotall(nlyr, T, plyr, zlyr, deltaTday); /* for (ilyr=0; ilyr<nlyr; ilyr++) { */ /* printf("ilyr %d, z=%f, plyr=%f,theta=%f, T=%f\n", ilyr, z[ilyr], plyr[ilyr],theta[ilyr], T[ilyr]); */ /* } */ for (ilyr=0; ilyr<nlyr; ilyr++) { printf("p%f, edn%f, eup%f, enet%f\n", p[ilyr], edn[ilyr], eup[ilyr], enet[ilyr]); } printf("p%f, edn%f, eup%f\n", p[ilyr], edn[ilyr], eup[ilyr]); } } free(tmplyr); free(tmplev); //----------------- End of while-loop---------------------// printf("\nTime %d: T = %f\n", (int)(timesteps*deltat), T[nlyr-1]); for (ilyr=0; ilyr<nlyr; ilyr++) { printf("%d %f\n", ilyr, T[ilyr]); } printf("\nTsurf=%f\n", T[nlyr-1]); return 0; }
int main(int argc, char *argv[]) { int i, digmax; int xleng0 = 400, yleng0 = 300, xoff0 = 200, yoff0 = 200; int xleng1 = 400, yleng1 = 300, xoff1 = 500, yoff1 = 500; /* Select either TK or DP driver and use a small window */ /* Using DP results in a crash at the end due to some odd cleanup problems */ /* The geometry strings MUST be in writable memory */ char geometry_master[] = "500x410+100+200"; char geometry_slave[] = "500x410+650+200"; char driver[80]; /* plplot initialization */ /* Parse and process command line arguments */ (void) plparseopts(&argc, argv, PL_PARSE_FULL); plgdev(driver); printf("Demo of multiple output streams via the %s driver.\n", driver); printf("Running with the second stream as slave to the first.\n"); printf("\n"); /* Set up first stream */ plsetopt("geometry", geometry_master); plsdev(driver); plssub(2, 2); plinit(); /* Start next stream */ plsstrm(1); /* Turn off pause to make this a slave (must follow master) */ plsetopt("geometry", geometry_slave); plspause(0); plsdev(driver); plinit(); /* Set up the data & plot */ /* Original case */ plsstrm(0); xscale = 6.; yscale = 1.; xoff = 0.; yoff = 0.; plot1(); /* Set up the data & plot */ xscale = 1.; yscale = 1.e+6; plot1(); /* Set up the data & plot */ xscale = 1.; yscale = 1.e-6; digmax = 2; plsyax(digmax, 0); plot1(); /* Set up the data & plot */ xscale = 1.; yscale = 0.0014; yoff = 0.0185; digmax = 5; plsyax(digmax, 0); plot1(); /* To slave */ /* The pleop() ensures the eop indicator gets lit. */ plsstrm(1); plot4(); pleop(); /* Back to master */ plsstrm(0); plot2(); plot3(); /* To slave */ plsstrm(1); plot5(); pleop(); /* Back to master to wait for user to advance */ plsstrm(0); pleop(); /* Call plend to finish off. */ plend(); exit(0); }
template <typename T> EXPORTGTPLPLOT bool plotCurves(const std::vector<hoNDArray<T> >& x, const std::vector<hoNDArray<T> >& y, const std::string& xlabel, const std::string& ylabel, const std::string& title, const std::vector<std::string>& legend, const std::vector<std::string>& symbols, size_t xsize, size_t ysize, T xlim[2], T ylim[2], bool trueColor, bool drawLine, hoNDArray<float>& plotIm) { try { GADGET_CHECK_RETURN_FALSE(x.size()>0); GADGET_CHECK_RETURN_FALSE(y.size()>0); GADGET_CHECK_RETURN_FALSE(x.size() == y.size()); T minX = xlim[0]; T maxX = xlim[1]; T minY = ylim[0]; T maxY = ylim[1]; plsdev("mem"); hoNDArray<unsigned char> im; im.create(3, xsize, ysize); Gadgetron::clear(im); plsmem(im.get_size(1), im.get_size(2), im.begin()); plinit(); plfont(2); pladv(0); if (legend.size() == x.size()) { plvpor(0.11, 0.75, 0.1, 0.9); } else { plvpor(0.15, 0.85, 0.1, 0.9); } T spaceX = 0.01*(maxX - minX); T spaceY = 0.05*(maxY - minY); plwind(minX - spaceX, maxX + spaceX, minY - spaceY, maxY + spaceY); plcol0(15); plbox("bgcnst", 0.0, 0, "bgcnstv", 0.0, 0); // int mark[2], space[2]; //mark[0] = 4000; //space[0] = 2500; //plstyl(1, mark, space); size_t num = x.size(); size_t n; hoNDArray<double> xd, yd; // draw lines for (n = 0; n < num; n++) { size_t N = y[n].get_size(0); xd.copyFrom(x[n]); yd.copyFrom(y[n]); if (drawLine) { int c; getPlotColor(n, c); plcol0(c); pllsty(n % 8 + 1); plline(N, xd.begin(), yd.begin()); } std::string gly; if(symbols.size()>n) { gly = symbols[n]; } else getPlotGlyph(n, gly); plstring(N, xd.begin(), yd.begin(), gly.c_str()); } plcol0(15); plmtex("b", 3.2, 0.5, 0.5, xlabel.c_str()); plmtex("t", 2.0, 0.5, 0.5, title.c_str()); plmtex("l", 5.0, 0.5, 0.5, ylabel.c_str()); // draw the legend if (legend.size() == x.size()) { std::vector<PLINT> opt_array(num), text_colors(num), line_colors(num), line_styles(num), symbol_numbers(num), symbol_colors(num); std::vector<PLFLT> symbol_scales(num), line_widths(num), box_scales(num, 1); std::vector<std::string> glyphs(num); std::vector<const char*> symbols(num); PLFLT legend_width, legend_height; std::vector<const char*> legend_text(num); for (n = 0; n < num; n++) { int c; getPlotColor(n, c); getPlotGlyph(n, glyphs[n]); opt_array[n] = PL_LEGEND_SYMBOL | PL_LEGEND_LINE; text_colors[n] = 15; line_colors[n] = c; line_styles[n] = (n%8+1); line_widths[n] = 0.2; symbol_colors[n] = c; symbol_scales[n] = 0.75; symbol_numbers[n] = 1; symbols[n] = glyphs[n].c_str(); legend_text[n] = legend[n].c_str(); } pllegend(&legend_width, &legend_height, PL_LEGEND_BACKGROUND, PL_POSITION_OUTSIDE | PL_POSITION_RIGHT | PL_POSITION_TOP, 0.02, // x 0.0, // y 0.05, // plot_width 0, // bg_color 15, // bb_color 1, // bb_style 0, // nrow 0, // ncolumn num, // nlegend &opt_array[0], 0.05, // text_offset 0.35, // text_scale 1.0, // text_spacing 0.5, // text_justification &text_colors[0], (const char **)(&legend_text[0]), NULL, // box_colors NULL, // box_patterns &box_scales[0], // box_scales NULL, // box_line_widths &line_colors[0], &line_styles[0], &line_widths[0], &symbol_colors[0], &symbol_scales[0], &symbol_numbers[0], (const char **)(&symbols[0]) ); } plend(); outputPlotIm(im, trueColor, plotIm); } catch (...) { GERROR_STREAM("Errors happened in plotCurves(xlim, ylim) ... "); return false; } return true; }
bool plotNoiseStandardDeviation(const hoNDArray< std::complex<T> >& m, const std::vector<std::string>& coilStrings, const std::string& xlabel, const std::string& ylabel, const std::string& title, size_t xsize, size_t ysize, bool trueColor, hoNDArray<float>& plotIm) { try { size_t CHA = m.get_size(0); GADGET_CHECK_RETURN_FALSE(coilStrings.size() == CHA); hoNDArray<double> xd, yd, yd2; xd.create(CHA); yd.create(CHA); size_t c; for (c = 0; c < CHA; c++) { xd(c) = c+1; yd(c) = std::sqrt( std::abs(m(c, c)) ); } double maxY = Gadgetron::max(&yd); yd2 = yd; std::sort(yd2.begin(), yd2.end()); double medY = yd2(CHA / 2); // increase dot line to be 1 sigma ~= 33% double medRange = 0.33; if (maxY < medY*(1 + medRange)) { maxY = medY*(1 + medRange); } hoNDArray<unsigned char> im; im.create(3, xsize, ysize); Gadgetron::clear(im); plsdev("mem"); plsmem(im.get_size(1), im.get_size(2), im.begin()); plinit(); plfont(2); pladv(0); plvpor(0.15, 0.75, 0.1, 0.8); plwind(0, CHA+1, 0, maxY*1.05); plcol0(15); plbox("bcnst", 0.0, 0, "bcnstv", 0.0, 0); std::string gly; getPlotGlyph(0, gly); // circle plstring(CHA, xd.begin(), yd.begin(), gly.c_str()); // draw the median line pllsty(1); double px[2], py[2]; px[0] = 0; px[1] = CHA+1; py[0] = medY; py[1] = medY; plline(2, px, py); pllsty(2); py[0] = medY*(1 - medRange); py[1] = medY*(1 - medRange); plline(2, px, py); py[0] = medY*(1 + medRange); py[1] = medY*(1 + medRange); plline(2, px, py); plmtex("b", 3.2, 0.5, 0.5, xlabel.c_str()); plmtex("t", 2.0, 0.5, 0.5, title.c_str()); plmtex("l", 5.0, 0.5, 0.5, ylabel.c_str()); // draw the legend std::vector<PLINT> opt_array(CHA), text_colors(CHA), line_colors(CHA), line_styles(CHA), symbol_numbers(CHA), symbol_colors(CHA); std::vector<PLFLT> symbol_scales(CHA), line_widths(CHA), box_scales(CHA, 1); std::vector<const char*> symbols(CHA); PLFLT legend_width, legend_height; std::vector<const char*> legend_text(CHA); std::vector<std::string> legends(CHA); size_t n; for (n = 0; n < CHA; n++) { opt_array[n] = PL_LEGEND_SYMBOL; text_colors[n] = 15; line_colors[n] = 15; line_styles[n] = (n % 8 + 1); line_widths[n] = 0.2; symbol_colors[n] = 15; symbol_scales[n] = 0.75; symbol_numbers[n] = 1; symbols[n] = gly.c_str(); std::ostringstream ostr; ostr << n+1 << ":" << coilStrings[n]; legends[n] = ostr.str(); legend_text[n] = legends[n].c_str(); } pllegend(&legend_width, &legend_height, PL_LEGEND_BACKGROUND, PL_POSITION_OUTSIDE | PL_POSITION_RIGHT, 0.02, // x 0.0, // y 0.05, // plot_width 0, // bg_color 15, // bb_color 1, // bb_style 0, // nrow 0, // ncolumn CHA, // nlegend &opt_array[0], 0.05, // text_offset 0.5, // text_scale 1.0, // text_spacing 0.5, // text_justification &text_colors[0], (const char **)(&legend_text[0]), NULL, // box_colors NULL, // box_patterns &box_scales[0], // box_scales NULL, // box_line_widths &line_colors[0], &line_styles[0], &line_widths[0], &symbol_colors[0], &symbol_scales[0], &symbol_numbers[0], (const char **)(&symbols[0]) ); plend(); outputPlotIm(im, trueColor, plotIm); } catch (...) { GERROR_STREAM("Errors happened in plotNoiseStandardDeviation(...) ... "); return false; } return true; }
int main(int argc, char **argv) { SNDFILE *file1, *file2; SF_INFO info1, info2; double *in1, *in2; int min_frames, i; int like = 0, unlike = 0; int total = 0; int max1, max2; struct fft_average *avg; memset(&info1, 0, sizeof(SF_INFO)); memset(&info2, 0, sizeof(SF_INFO)); if (argc < 3) { printf("compare file1 file2"); return 1; } file1 = sf_open(argv[1], SFM_READ, &info1); if (!file1) { printf("Error opening wave file %s\n", argv[1]); exit(1); } file2 = sf_open(argv[2], SFM_READ, &info2); if (!file2) { printf("Error opening wave file %s\n", argv[2]); sf_close(file2); exit(1); } /* seconds = (float)info1.frames/(float)info1.samplerate; printf("Opened %s\n", argv[1]); printf("frames: %d\n", info1.frames); printf("samplerate: %d\n", info1.samplerate); printf("length (in seconds): %f\n", seconds); printf("channels: %d\n", info1.channels); printf("format: %x\n", info1.format); printf("sections: %d\n", info1.sections); printf("seekable: %d\n", info1.seekable); */ in1 = (double *)malloc(sizeof(double) * info1.frames); if (!in1) { printf("Failed to allocate input array\n"); sf_close(file1); sf_close(file2); return 1; } in2 = (double *)malloc(sizeof(double) * info2.frames); if (!in2) { printf("Failed to allocate input array\n"); free(in1); sf_close(file1); sf_close(file2); return 1; } normalize_wave(file1, in1, info1.frames, info1.channels); normalize_wave(file2, in2, info2.frames, info2.channels); max1 = shift_wave(in1, info1.frames); max2 = shift_wave(in2, info2.frames); // max1 = find_max(in1, info1.frames); // max2 = find_max(in2, info2.frames); /* shift_wave(in1, info1.frames); shift_wave(in2, info2.frames); */ plsdev("xwin"); plinit(); plenv(0.0f, info1.frames, -1, 1, 0, 0); for (i = 0; i < info1.frames; i++) { PLFLT x; PLFLT sample = i; if (in1[i] == -2) continue; x = in1[i]; plpoin(1, &sample, &x, 1); } plend(); plsdev("xwin"); plinit(); plenv(0.0f, info2.frames, -1, 1, 0, 0); for (i = 0; i < info2.frames; i++) { PLFLT x; PLFLT sample = i; if (in2[i] == -2) continue; x = in2[i]; plpoin(1, &sample, &x, 1); } plend(); avg = do_fft(in1, max1); printf("yavg = %f, xavg=%f\n", avg->yavg, avg->xavg); free(avg); avg = do_fft(in2, max2); printf("yavg = %f, xavg=%f\n", avg->yavg, avg->xavg); free(avg); min_frames = (info1.frames < info2.frames) ? info1.frames : info2.frames; for (i = 0; i < min_frames; i++) { double diff; if (in1[i] == -2 || in2[i] == -2) break; if (in1[i] > in2[i]) diff = in1[i] - in2[i]; else diff = in2[i] - in1[i]; if (diff <= 0.05) like++; else unlike++; total++; } printf("Minimum frames: %d\n", min_frames); printf("Total compares: %d\n", total); printf("Like: %d\n", like); printf("Unlike: %d\n", unlike); printf("Percentage alike: %f\n", ((double)like / (double)total) * 100); printf("Max1: %d\n", max1); printf("Max2: %d\n", max2); free(in1); free(in2); sf_close(file1); sf_close(file2); return 0; }