コード例 #1
0
ファイル: gnuplot_i.c プロジェクト: EQ4/FFT_Block
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 ;
}
コード例 #2
0
ファイル: gnuplot_i.c プロジェクト: jerome2echopen/Perso_C
/*the gnuplot_surf_gray function plot a rectangular surface in grey shade
  we considere a cartesian mesh, where x is Nx long, y is Ny long and 
  z is Nx*Ny long
*/
void gnuplot_surf_gray(gnuplot_ctrl *handle, double *x, double *y, double **z, int Nx, int Ny, char *title)
{
    int i, j;
    FILE* tmpfd ;
    char const * tmpfname;

    if (handle==NULL || x==NULL || y==NULL || z==NULL || (Nx<1) || (Ny<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<Nx; i++) 
    {
	for (j=0 ; j<Ny ; j++)
	{
            fprintf(tmpfd, "%.18e %.18e %.18e\n", x[i], y[j], z[i][j]);
	}
	fprintf(tmpfd, "\n");
    }
    fclose(tmpfd) ;

    gnuplot_surf_atmpfile(handle,tmpfname,title);
    return ;
}
コード例 #3
0
ファイル: gnuplot_i.c プロジェクト: E-J-W/Gridlock
//JW: same as the above function but modified to allow plotting of grid data as a mesh
//gnuplot requires empty lines between each block of data for all x values in the grid
//ndim = # of points in each dimension of the grid = # of data points in each 'block' of x values
//nskip = take only every nskipth data point
void gnuplot_plot_xyzgrid(
    gnuplot_ctrl    *   handle,
    double          *   x,
    double          *   y,
    double          *   z,
    int                 n,
    int                 ndim,
    int                 nskip,
    int                 nblockskip,
    char            *   title
)
{
    int     i,j,k ;
    FILE*   tmpfd ;
    char const * tmpfname;

    if (handle==NULL || x==NULL || y==NULL || z==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  */
    j=0;
    k=ndim*nblockskip;
    for (i=0 ; i<n; i++) {
        if(nskip>0) {
            if(i%nskip==0) {
                fprintf(tmpfd, "%.18e %.18e %.18e\n", x[i], y[i], z[i]) ;
            }  
            j++;
        }else if(nblockskip>0){
            if(i%k<ndim) {
                fprintf(tmpfd, "%.18e %.18e %.18e\n", x[i], y[i], z[i]) ;
                j++;
            }   
        }else{
            fprintf(tmpfd, "%.18e %.18e %.18e\n", x[i], y[i], z[i]) ;
            j++;
        }
        
        
        if(j>=ndim) {
            fprintf(tmpfd, "\n"); //insert blank line
            j=0;
        }
    }
    fclose(tmpfd) ;

    gnuplot_splot_atmpfile(handle,tmpfname,title);
    return ;
}
コード例 #4
0
ファイル: ex_gnuplot.c プロジェクト: aa-m-sa/ex_gnuplot_util
/*
 * 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);
}