void gnuplot_plot_xy( gnuplot_ctrl * handle, double * x, double * y, int n, char * title ) { int i ; FILE* tmpfd ; char const * tmpfname; if (handle==NULL || x==NULL || y==NULL || (n<1)) return ; /* Open temporary file for output */ tmpfname = gnuplot_tmpfile(handle); tmpfd = fopen(tmpfname, "w"); if (tmpfd == NULL) { fprintf(stderr,"cannot create temporary file: exiting plot") ; return ; } /* Write data to this file */ for (i=0 ; i<n; i++) { fprintf(tmpfd, "%.18e %.18e\n", x[i], y[i]) ; } fclose(tmpfd) ; gnuplot_plot_atmpfile(handle,tmpfname,title); return ; }
/* * gnuplot_xy * plots one xdata, ydata line plot */ void gnuplot_xy(gnuplot_ctrl *handle, gsl_vector *xdata, gsl_vector *ydata, const char *title, const char *style) { // gnuplot -persist int npts = ydata->size; FILE* tmpfd ; char const * tmpfname; if (handle==NULL || (npts<1)) { printf("error!!!"); return; } /* Open temporary file for output */ tmpfname = gnuplot_tmpfile(handle); tmpfd = fopen(tmpfname, "w"); if (tmpfd == NULL) { printf("cannot create temporary file: exiting plot") ; fprintf(stderr,"cannot create temporary file: exiting plot") ; return ; } double xmin = gsl_vector_get(xdata, 0); double xmax = gsl_vector_get(xdata, 0); double ymin = gsl_vector_get(xdata, 0); double ymax = gsl_vector_get(xdata, 0); for (int i = 0; i < npts; ++i) { double xi = gsl_vector_get(xdata, i); double yi = gsl_vector_get(ydata, i); fprintf(tmpfd, "%.18e %.18e\n", xi, yi); xmin = (xmin > xi) ? xi : xmin; xmax = (xmax < xi) ? xi : xmax; ymin = (ymin > yi) ? yi : ymin; ymax = (ymax < yi) ? yi : ymax; } fclose(tmpfd); double lx = xmax - xmin; double ly = ymax - ymin; gnuplot_cmd(handle, "set xrange [%lf:%lf]", xmin-0.05*lx, xmax+0.05*lx); gnuplot_cmd(handle, "set yrange [%lf:%lf]", ymin-0.05*ly, ymax+0.05*ly); gnuplot_plot_atmpfile(handle,tmpfname,title,style); }
//JW: same as the above function but modified to allow skipping over individual //lines of data or blocks of data //ndim = # of data points in each 'block' //nskip = take only every nskipth data point //nblockskip = take only every nblockskipth data block void gnuplot_plot_xygrid( gnuplot_ctrl * handle, double * x, double * y, int n, int ndim, int nskip, int nblockskip, char * title ) { int i,k ; FILE* tmpfd ; char const * tmpfname; if (handle==NULL || x==NULL || y==NULL || (n<1)) return ; /* Open temporary file for output */ tmpfname = gnuplot_tmpfile(handle); tmpfd = fopen(tmpfname, "w"); if (tmpfd == NULL) { fprintf(stderr,"cannot create temporary file: exiting plot") ; return ; } /* Write data to this file */ k=ndim*nblockskip; for (i=0 ; i<n; i++) { if(nskip>0) { if(i%nskip==0) { fprintf(tmpfd, "%.18e %.18e\n", x[i], y[i]) ; } }else if(nblockskip>0){ if(i%k<ndim) { fprintf(tmpfd, "%.18e %.18e\n", x[i], y[i]) ; } }else{ fprintf(tmpfd, "%.18e %.18e\n", x[i], y[i]) ; } } fclose(tmpfd) ; gnuplot_plot_atmpfile(handle,tmpfname,title); return ; }