Ejemplo n.º 1
0
void gnuplot_fill_mesh(
		gnuplot_ctrl    *   handle,
	    float			*		value,
	    int                 ncells,
	    float		minval = 0,
	    float		maxval = 10
	    )
{
	float bval = minval;
	float gval = 0.3*(maxval-minval)+minval;
	float yval = 0.6*(maxval-minval)+minval;
	float rval = maxval;

	// Set the color palette
	gnuplot_cmd(handle,"set palette defined ( %f \"blue\", %f \"green\","
			" %f \"yellow\", %f \"red\" )",bval,gval,yval,rval);


	for(int i=0;i<ncells;i++)
	{
		float temp = (value[i]-minval)/(maxval-minval);
		gnuplot_color_cell(handle,temp,i+1);
	}

	gnuplot_cmd(handle,"replot");

	return;
}
Ejemplo n.º 2
0
void gnuplot_setup_mesh(
    gnuplot_ctrl    *   handle,
    cell	 *			cells,
    float	* 			xdims,
    float	*			ydims,
    int                 ncells
)
{

	// Set pm3d so that our palette actually works
	gnuplot_cmd(handle,"set pm3d");

	// Set up the plot window dimensions
	gnuplot_cmd(handle,"set xrange [%f:%f]",xdims[0],xdims[1]);
	gnuplot_cmd(handle,"set yrange [%f:%f]",ydims[0],ydims[1]);


	for(int i=0;i<ncells;i++)
	{
		gnuplot_setup_cell(handle,cells+i);
	}

	gnuplot_cmd(handle,"plot 1 lw 0");

    return ;
}
Ejemplo n.º 3
0
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
void Plotter::setOutputDevice(OutputDevice device, const std::string& file)
{
	if (!_plotter)
		return;

	bool validDevice = true;
	switch (device)
	{
	case PNG:
		gnuplot_cmd(_plotter, "set terminal png");
		break;
	case POSTSCRIPT:
		gnuplot_cmd(_plotter, "set terminal postscript");
		break;
	default:
		validDevice = false;
		break;
	}

	if (validDevice)
		gnuplot_cmd(_plotter, const_cast<char*>(std::string("set output "
		                                        + std::string("\"")
		                                        + file
		                                        + std::string("\"")).c_str()));
}
Ejemplo n.º 4
0
int plotit(){ 
char temp[50];
    gnuplot_ctrl * h ;
    h = gnuplot_init() ;
    // gnuplot_set_ylabel(h, "Temp") ;
      //  gnuplot_set_xlabel(h, "Time") ;
           gnuplot_cmd(h, "set terminal png size 900,900");
            gnuplot_cmd(h, "set output \"/tmp/Temp1.png\"");
            gnuplot_cmd(h, "set xdata time");
            gnuplot_cmd(h,"set timefmt \"%%m-%%d-%%H:%%M:%%S\"");
          // gnuplot_cmd(h,"set xrange [\"08-10-00:00\":\"08-11-23:59\"]");
            //gnuplot_cmd(h, "set grid");
            gnuplot_cmd(h, "plot \"/tmp/log1\" using 1:2 index 0 with linespoint");
       gnuplot_close(h);
    h = gnuplot_init() ;

       // gnuplot_set_ylabel(h, "Temp") ;
         //  gnuplot_set_xlabel(h, "Time") ;
              gnuplot_cmd(h, "set terminal png size 900,900");
               gnuplot_cmd(h, "set output \"/tmp/Temp2.png\"");
               gnuplot_cmd(h, "set xdata time");
               gnuplot_cmd(h,"set timefmt \"%%m-%%d-%%H:%%M:%%S\"");
             // gnuplot_cmd(h,"set xrange [\"08-10-00:00\":\"08-11-23:59\"]");
               //gnuplot_cmd(h, "set grid");
               gnuplot_cmd(h, "plot \"/tmp/log2\" using 1:2 index 0 with linespoint");
          gnuplot_close(h);
          return 0;
 ;





}
Ejemplo n.º 5
0
int gnuplot_contour_plot(gnuplot_ctrl *handle, double *x, double *y, double *z, int nx, int ny, char *title) {
    int i,j;
	int		tmpfd ;
    char    name[128] ;
    char    cmd[GP_CMD_SIZE] ;
    char    line[GP_CMD_SIZE] ;

    if (handle==NULL || x==NULL || y==NULL || (nx<1) || (ny<1)) return 1;
    if (handle->nplots > 0)
      return 1;
    /* Open one more temporary file? */
    if (handle->ntmp == GP_MAX_TMP_FILES - 1) {
        fprintf(stderr,
                "maximum # of temporary files reached (%d): cannot open more",
                GP_MAX_TMP_FILES) ;
        return 1;
    }

    /* Open temporary file for output   */
	sprintf(name, GNUPLOT_TEMPFILE, P_tmpdir);
    if ((tmpfd=mkstemp(name))==-1) {
        fprintf(stderr,"cannot create temporary file: exiting plot") ;
        return 1;
    }
    /* Store file name in array for future deletion */
    strcpy(handle->to_delete[handle->ntmp], name) ;
    handle->ntmp ++ ;

    /* Write data to this file  */
    
    for (i=0 ; i<nx; i++) {
        for (j=0 ; j<ny; j++) {
            sprintf(line, "%g %g %g\n", x[nx*i+j], y[nx*i+j], z[nx*i+j]) ;
    		write(tmpfd, line, strlen(line));
        }
        sprintf(line, "\n") ;
    	write(tmpfd, line, strlen(line));
    }
    close(tmpfd) ;

    /* Command to be sent to gnuplot    */
    gnuplot_cmd(handle,"unset surface");
    gnuplot_cmd(handle,"set contour base");
    gnuplot_cmd(handle,"set view map");
    gnuplot_cmd(handle,"set view 0,0");
    strcpy(cmd, "splot") ;
        
    if (title == NULL) {
        sprintf(line, "%s \"%s\" with %s", cmd, name, handle->pstyle) ;
    } else {
        sprintf(line, "%s \"%s\" title \"%s\" with %s", cmd, name,
                      title, handle->pstyle) ;
    }

    /* send command to gnuplot  */
    gnuplot_cmd(handle, line) ;
    handle->nplots++ ;
    return 0;
}
Ejemplo n.º 6
0
int main(int arg, char *argv[])
{
	int Npoint, dec, line, Nline, sector;
	double x0, xf;

	//socket variable
	SOCKET sock;
	const char *IP="192.168.128.3";
	init_TCP_client(&sock, IP, Port);

	int Nset=5;
	char settings[Nset];
	receive_TCP_client(&sock, settings, Nset);
	x0=(double)int_converter(settings[0]);
	xf=(double)int_converter(settings[1]);
	dec=int_converter(settings[2]);
	line=int_converter(settings[3]);
	Nline=line/2;
	sector=int_converter(settings[4]);
	Npoint=(int)(2.0*(xf-x0)*125.0/1.48/((double)dec));
	char *buff=(char *)malloc((Npoint+1)*sizeof(char));

	//gnuplot variable
	gnuplot_ctrl * h;
	double *y= (double *)malloc(Npoint*sizeof(double));
	int i,j;

	//gnuplot object
	h=gnuplot_init();
	gnuplot_setstyle(h,"lines");
	gnuplot_set_xlabel(h,"time (us)");
	gnuplot_set_ylabel(h,"signal");
	gnuplot_cmd(h,"set yrange [1:%d]",Ymax);
	gnuplot_cmd(h,"set xrange [0:%d]",Npoint-1);

	while(1)
	{
		if (receive_TCP_client(&sock, buff, Npoint+1)==1)
		{
			break;
		}	
			
		if ((int)(buff[0])==Nline)
		{
			for (i=1; i<Npoint+1 ; i++)
			{
				y[i-1]=(double)(buff[i]);
			}
			gnuplot_resetplot(h);
			gnuplot_plot_x(h, y, Npoint, "RP");
		}
	}

	usleep(30);
	close(sock);
	free(y);
	return 0;
}
Ejemplo n.º 7
0
void plotter_init(){
    handle = gnuplot_init();
    gnuplot_setstyle(handle, "lines") ;
    gnuplot_cmd(handle, "set yrange [-1.0:1.0]");
    gnuplot_cmd(handle, "set xrange [0:2205]");
    gnuplot_cmd(handle, "set title 'Microphone Input'");
    gnuplot_cmd(handle, "set xlabel 'Sample'");
    gnuplot_cmd(handle, "set ylabel 'Amplitude'");
}
Ejemplo n.º 8
0
void gnuplot_surf_atmpfile(gnuplot_ctrl * handle, char const* tmp_filename, char const* title)
{
    char const *    cmd    = (handle->nplots > 0) ? "replot" : "splot";
    title                  = (title == NULL)      ? "(none)" : title;
    gnuplot_cmd(handle, "set pm3d map"); //surf option
    gnuplot_cmd(handle, "set palette gray"); //grey level
    gnuplot_cmd(handle, "%s \"%s\" title \"%s\"", cmd, tmp_filename, title) ;
    handle->nplots++ ;
    return ;
}
Ejemplo n.º 9
0
void gnuplot_splot4d_atmpfile(gnuplot_ctrl * handle, char const* tmp_filename, char const* title)
{
    char const *    cmd    = (handle->nplots > 0) ? "replot" : "splot";
    title                  = (title == NULL)      ? "(none)" : title;
    if(handle->colSet==0)
        gnuplot_cmd(handle, "%s \"%s\" title \"%s\" with %s lc palette", cmd, tmp_filename,title, handle->pstyle) ;
    else
        gnuplot_cmd(handle, "%s \"%s\" title \"%s\" lt rgb \"%s\" with %s lc palette", cmd, tmp_filename,title, handle->col, handle->pstyle) ;
    handle->nplots++ ;
    return ;
}
Ejemplo n.º 10
0
void
PlotGraph::PlotAugmentingPath(BipartiteGraph& _bg, vector<EID>& _path){

    //get assignment size, assume the sizes of agents and tasks are identical
    size_t as_size = _bg.GetNumAgents();
    double plx[as_size];
    double ply[as_size];
/*
    //gnuplot_resetplot(g);
    gnuplot_cmd(g, (char*)"unset label");
    gnuplot_cmd(g, (char*)"set xrange [-0.25:1.25]");
    gnuplot_cmd(g, (char*)"set yrange [-0.25:%f]", as_size-1+.25);
    gnuplot_cmd(g, (char*)"set xtics 0");
    gnuplot_cmd(g, (char*)"set ytics 0");
    gnuplot_cmd(g, (char*)"set nokey");
*/
    //gnuplot_cmd(g, (char*)"set style line 2 lt 2 lc rgb \"blue\" lw 3");
    // Plot matching
    //cout<<endl<<"Set M: "<<endl;
    //DisplayData(_M);    
    bool alter = true;
    for (unsigned int i = 0; i < _path.size(); i++){
        plx[0] = _path[i].first;
        ply[0] = 0.0;
        plx[1] = _path[i].second;
        ply[1] = 1.0;

        //gnuplot_setstyle(g, (char*)"linespoints lc rgb \"#55DD99\" lw 3");
        if(alter)
          gnuplot_setstyle(g, (char*)"lines lc rgb \"#458B74\" lw 3");
        else
          gnuplot_setstyle(g, (char*)"lines lc rgb \"#7CCD7C\" lw 3");

        alter = !alter;
        gnuplot_plot_xy(g, plx, ply, 2, NULL);
    }

#ifdef SAVE_PLOTS
    stringstream ss;
    ss << setw(3) << setfill('0') << Cnt++;
    string postfix = ss.str();

    string name="save/plot"+postfix+".jpeg";
    gnuplot_cmd(g, (char*)"set terminal jpeg");
    //gnuplot_cmd(g, (char*)"set terminal jpeg small size 320,240");//bad
    gnuplot_cmd(g, (char*)"set output \"%s\"", name.c_str());
    printf("saved jpeg: \"%s\"\n", name.c_str());
#endif

    gnuplot_cmd(g, (char*)"replot");

   sleep(period);
}
Ejemplo n.º 11
0
void gnuplot_hardcopy_colour(
    gnuplot_ctrl * h,
    char * filename
)
{
    gnuplot_cmd(h, "set terminal postscript enhanced color");

    gnuplot_cmd(h, "set output \"%s\"", filename);
    gnuplot_cmd(h, "replot");

    gnuplot_cmd(h, "set terminal %s",h->term);
}
Ejemplo n.º 12
0
int main(int argc, char * argv[])
{
	gnuplot_ctrl * g = gnuplot_init();
	
	char out_cmd[1024];
	
	gnuplot_cmd(g, "set terminal png");
	gnuplot_cmd(g, "set output \"sine.png\"");
	gnuplot_plot_equation(g, "sin(x)", "Sine wave");
	gnuplot_close(g);

	return 0 ;
}
Ejemplo n.º 13
0
/*
 * 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);
}
Ejemplo n.º 14
0
/*
 * Uses gnuplot to plot the training set and the linear predictor function.
 */
static void plot_data_and_model(char* filename, linear_regression* lr)
{
    /*
     * Assume the total length of the command is 200 characters. This should probably be dynamic
     * to avoid problems with long filenames.
     */
    char command[200] = { 0 };
    sprintf(command, "f(x) = %f + %f * x\nplot '%s' with points pt 7 ps 2, f(x) with lines", lr->theta0, lr->theta1, filename);

    gnuplot_cmd(plotter, "set terminal png"); /* Plot to a png file. */
    gnuplot_cmd(plotter, "set output \"plot.png\""); /* Set the output file. */
    gnuplot_cmd(plotter, "set datafile separator comma"); /* Tell gnuplot the format of the training set file. */
    gnuplot_cmd(plotter, "unset key"); /* Remove the graph legend. */
    gnuplot_cmd(plotter, command); /* Execute the plotting command. */
}
Ejemplo n.º 15
0
void gnuplot_plot_equation(
    gnuplot_ctrl    *   h,
    char            *   equation,
    char            *   title
)
{
    char    cmd[GP_CMD_SIZE];
    char    plot_str[GP_EQ_SIZE] ;
    char    title_str[GP_TITLE_SIZE] ;

    if (title == NULL) {
        strcpy(title_str, "no title") ;
    } else {
        strcpy(title_str, title) ;
    }
    if (h->nplots > 0) {
        strcpy(plot_str, "replot") ;
    } else {
        strcpy(plot_str, "plot") ;
    }

    sprintf(cmd, "%s %s title \"%s\" with %s",
                  plot_str, equation, title_str, h->pstyle) ;
    gnuplot_cmd(h, cmd) ;
    h->nplots++ ;
    return ;
}
Ejemplo n.º 16
0
int main ()
{
   char buf[256];

#ifdef SIGPIPE
   signal (SIGPIPE, SIG_IGN);
#endif

   if (-1 == gnuplot_open (0, NULL))
     {
	fprintf (stderr, "Unable to start 0\n");
	return -1;
     }

   while (NULL != fgets (buf, sizeof(buf), stdin))
     {
	if (-1 == gnuplot_cmd (0, buf))
	  {
	     fprintf (stderr, "Unable to write cmd\n");
	     return -1;
	  }
     }
   if (-1 == gnuplot_close (0))
     {
	fprintf (stderr, "Unable to close 0\n");
	return -1;
     }

   return 0;
}
Ejemplo n.º 17
0
void gnuplot_plot_xy(
    gnuplot_ctrl    *   handle,
	double			*	x,
	double			*	y,
    int                 n,
    char            *   title
)
{
    int     i ;
	int		tmpfd ;
    char    name[128] ;
    char    cmd[GP_CMD_SIZE] ;
    char    line[GP_CMD_SIZE] ;

	if (handle==NULL || x==NULL || y==NULL || (n<1)) return ;

    /* Open one more temporary file? */
    if (handle->ntmp == GP_MAX_TMP_FILES - 1) {
        fprintf(stderr,
                "maximum # of temporary files reached (%d): cannot open more",
                GP_MAX_TMP_FILES) ;
        return ;
    }

    /* Open temporary file for output   */
	sprintf(name, "%s/gnuplot-i-XXXXXX", P_tmpdir);
    if ((tmpfd=mkstemp(name))==-1) {
        fprintf(stderr,"cannot create temporary file: exiting plot") ;
        return ;
    }
    /* Store file name in array for future deletion */
    strcpy(handle->to_delete[handle->ntmp], name) ;
    handle->ntmp ++ ;

    /* Write data to this file  */
    for (i=0 ; i<n; i++) {
        sprintf(line, "%g %g\n", x[i], y[i]) ;
		write(tmpfd, line, strlen(line));
    }
    close(tmpfd) ;

    /* Command to be sent to gnuplot    */
    if (handle->nplots > 0) {
        strcpy(cmd, "replot") ;
    } else {
        strcpy(cmd, "plot") ;
    }

    if (title == NULL) {
        sprintf(line, "%s \"%s\" with %s", cmd, name, handle->pstyle) ;
    } else {
        sprintf(line, "%s \"%s\" title \"%s\" with %s", cmd, name,
                      title, handle->pstyle) ;
    }

    /* send command to gnuplot  */
    gnuplot_cmd(handle, line) ;
    handle->nplots++ ;
    return ;
}
Ejemplo n.º 18
0
void gnuplot_matrixdouble(gnuplot_ctrl *handle, double **z, int Nr, int Ntheta)
{
	int i, j;
	FILE *fmat;
	if (handle==NULL || z==NULL || (Nr<1) || (Ntheta<1)) return;

	fmat=fopen("mat.dat","w+");

	for (i=0 ; i<Ntheta ; i++)
	{
		for (j=0 ; j<Nr ; j++)
		{
			fprintf(fmat,"%f ",z[i][j]);
		}
		fprintf(fmat,"\n");
	}
	fclose(fmat);

	//gnuplot_cmd(handle, "clear");
	//gnuplot_cmd(handle, "set pm3d map");
	//gnuplot_cmd(handle, "set palette gray");
	gnuplot_cmd(handle, "splot \"mat.dat\" matrix");

	return;
}
Ejemplo n.º 19
0
/**
 * @brief	Sets the x label of a gnuplot session.
 * @param	h Gnuplot session control handle.
 * @param	label Character string to use for X label.
 * @return	void
 *
 * Sets the x label for a gnuplot session.
 */
void gnuplot_set_xlabel(gnuplot_ctrl* h, char* label) {
    char cmd[GP_CMD_SIZE];

    sprintf(cmd, "set xlabel \"%s\"", label);
    gnuplot_cmd(h, cmd);
    return;
}
Ejemplo n.º 20
0
void gnuplot_plot_slope(
    gnuplot_ctrl    *   handle,
    double              a,
    double              b,
    char            *   title
)
{
    char    stitle[GP_TITLE_SIZE] ;
    char    cmd[GP_CMD_SIZE] ;

    if (title == NULL) {
        strcpy(stitle, "no title") ;
    } else {
        strcpy(stitle, title) ;
    }

    if (handle->nplots > 0) {
        sprintf(cmd, "replot %g * x + %g title \"%s\" with %s",
                      a, b, title, handle->pstyle) ;
    } else {
        sprintf(cmd, "plot %g * x + %g title \"%s\" with %s",
                      a, b, title, handle->pstyle) ;
    }
    gnuplot_cmd(handle, cmd) ;
    handle->nplots++ ;
    return ;
}
Ejemplo n.º 21
0
void gnuplot_setterm(gnuplot_ctrl * h, char * terminal)
{
    char cmd[64];
    strncpy(h->term, terminal,32);
    h->term[31]=0;
    sprintf(cmd,"set terminal %s",h->term);
    gnuplot_cmd(h,cmd);
}
Ejemplo n.º 22
0
void gnuplot_set_ylabel(gnuplot_ctrl * h, char * label)
{
    char    cmd[GP_CMD_SIZE] ;

    sprintf(cmd, "set ylabel \"%s\" font 'Helvetica,12'", label) ;
    gnuplot_cmd(h, cmd) ;
    return ;
}
Ejemplo n.º 23
0
/*
 * gnuplot_plot_atmpfile
 *
 * plots a tmpfile with given title and style
 */
void gnuplot_plot_atmpfile(gnuplot_ctrl *handle, char const *tmp_filename, char const *title, char const *style)
{
    char const *cmd = (handle->nplots > 0) ? "replot" : "plot";
    title = (title == NULL) ? "(none)" : title;
    gnuplot_cmd(handle, "%s \"%s\" title \"%s\" with %s",
            cmd, tmp_filename, title, style) ;
    handle->nplots++;
    return;
}
Ejemplo n.º 24
0
int gnuplot_splot_obj(gnuplot_ctrl *handle,
                      void *obj,
                      void (*getPoint)(void*,gnuplot_point*,int,int),
                      int n,
                      char *title) {
    int i;
	int		tmpfd ;
    char    name[128] ;
    char    cmd[GP_CMD_SIZE] ;
    char    line[GP_CMD_SIZE] ;

    if (handle==NULL || getPoint==NULL || (n<1)) return 1;
    if (handle->nplots > 0)
      return 1;
    /* Open one more temporary file? */
    if (handle->ntmp == GP_MAX_TMP_FILES - 1) {
        fprintf(stderr,
                "maximum # of temporary files reached (%d): cannot open more",
                GP_MAX_TMP_FILES) ;
        return 1;
    }

    /* Open temporary file for output   */
	sprintf(name, GNUPLOT_TEMPFILE, P_tmpdir);
    if ((tmpfd=mkstemp(name))==-1) {
        fprintf(stderr,"cannot create temporary file: exiting plot") ;
        return 1;
    }
    /* Store file name in array for future deletion */
    strcpy(handle->to_delete[handle->ntmp], name) ;
    handle->ntmp ++ ;

    /* Write data to this file  */
    gnuplot_point point;
    for (i=0;i<n;i++) {
        getPoint(obj,&point,i,n);
        sprintf(line, "%g %g %g\n", point.x, point.y, point.z) ;
		write(tmpfd, line, strlen(line));
    }
    close(tmpfd) ;

    /* Command to be sent to gnuplot    */
    strcpy(cmd, "splot") ;
        
    if (title == NULL) {
        sprintf(line, "%s \"%s\" with %s", cmd, name, handle->pstyle) ;
    } else {
        sprintf(line, "%s \"%s\" title \"%s\" with %s", cmd, name,
                      title, handle->pstyle) ;
    }

    /* send command to gnuplot  */
    gnuplot_cmd(handle, line) ;
    handle->nplots++ ;
    return 0;
}
Ejemplo n.º 25
0
int gnuplot_splot_grid(gnuplot_ctrl *handle, double *points, int rows, int cols, const char *title) {
    int i;
    int j;
	int		tmpfd ;
    char    name[128] ;
    char    cmd[GP_CMD_SIZE] ;
    char    line[GP_CMD_SIZE] ;

    if (handle==NULL || points==NULL || (rows<1) || (cols<1)) return 1;
    if (handle->nplots > 0)
      return 1;
    /* Open one more temporary file? */
    if (handle->ntmp == GP_MAX_TMP_FILES - 1) {
        fprintf(stderr,
                "maximum # of temporary files reached (%d): cannot open more",
                GP_MAX_TMP_FILES) ;
        return 1;
    }

    /* Open temporary file for output   */
	sprintf(name, GNUPLOT_TEMPFILE, P_tmpdir);
    if ((tmpfd=mkstemp(name))==-1) {
        fprintf(stderr,"cannot create temporary file: exiting plot") ;
        return 1;
    }
    /* Store file name in array for future deletion */
    strcpy(handle->to_delete[handle->ntmp], name) ;
    handle->ntmp ++ ;

    /* Write data to this file  */
    for (i=0 ; i<rows; i++) {
        for (j=0;j<cols;j++) {
            sprintf(line, "%d %d %g\n", i,j,points[i*cols+j]) ;
		    write(tmpfd, line, strlen(line));
        }
        strcpy(line,"\n");
        write(tmpfd, line, strlen(line));
    }
    close(tmpfd) ;

    /* Command to be sent to gnuplot    */
    strcpy(cmd, "splot") ;
        
    if (title == NULL) {
        sprintf(line, "%s \"%s\" with %s", cmd, name, handle->pstyle) ;
    } else {
        sprintf(line, "%s \"%s\" title \"%s\" with %s", cmd, name,
                      title, handle->pstyle) ;
    }

    /* send command to gnuplot  */
    gnuplot_cmd(handle, line) ;
    handle->nplots++ ;
    return 0;
}
Ejemplo n.º 26
0
void gnuplot_color_cell(
	gnuplot_ctrl	* 	handle,
	float 			 	value,
	int					icell
)
{

	// Set the line color
	gnuplot_cmd(handle,"set object %i fillcolor palette frac %f "
							"fillstyle solid border rgb \"black\" lw 1 front",icell,value);
}
Ejemplo n.º 27
0
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
void Plotter::setLowLevelCommand(const std::string& cmd)
{
	if (_plotter)
	{
		std::istringstream is(cmd);
		std::string word;
		while (is >> word)
			my_gnuplot_cmd(_plotter, "%s ", word.c_str());
		gnuplot_cmd(_plotter, "");
	}
}
Ejemplo n.º 28
0
void gnuplot_save_pdf(
		gnuplot_ctrl*			handle,
		const char*				filename)
{
	char line[128];



//	gnuplot_cmd(handle,"set term epslatex color lw 10 size 11,8.5  font 20 ");
	gnuplot_cmd(handle,"set term pdf");

	sprintf(line,"set output \"%s.tex\"",filename);

	gnuplot_cmd(handle,line);

	gnuplot_cmd(handle,"replot");

	gnuplot_cmd(handle,"set term pop");
	gnuplot_cmd(handle,"set out");
}
Ejemplo n.º 29
0
void draw_configSpace(unsigned int cs_size,double **configSpace, int delay){
	int i,j;
	if(h==0){
		h = gnuplot_init();
		gnuplot_cmd(h, "clear");
		gnuplot_cmd(h,"reset");
		gnuplot_cmd(h,"set terminal gif animate animate delay 1 ");
		gnuplot_cmd(h,"set output \"animate.gif\"");
		gnuplot_cmd(h, "set xrange [-4:4]");
		gnuplot_cmd(h, "set yrange [-4:4]");
		gnuplot_cmd(h, "set zrange [-4:4]");
		printf("initializing draw cs \n");
	}
	gnuplot_cmd(h,"splot \"-\" using 1:2:3 with points pointtype 26 ps 0.3 lt palette");
	for(i=0;i<cs_size;i++){
		gnuplot_cmd(h,"%f %f %f", configSpace[i][0], configSpace[i][1], configSpace[i][2]);	
	}
	gnuplot_cmd(h,"e");
	mysleep(delay);
}
Ejemplo n.º 30
0
void gnuplot_splot_atmpfile(gnuplot_ctrl * handle, char const* tmp_filename, char const* title)
{
    char const *    cmd    = (handle->nplots > 0) ? "replot" : "splot";
    title                  = (title == NULL)      ? "(none)" : title;
    if(handle->colSet==0)
        {
            if(handle->smooth)
                gnuplot_cmd(handle, "%s \"%s\" title \"%s\" with %s smooth bezier", cmd, tmp_filename,title, handle->pstyle) ;
            else
                gnuplot_cmd(handle, "%s \"%s\" title \"%s\" with %s", cmd, tmp_filename,title, handle->pstyle) ;
        }
    else
        {
            if(handle->smooth)
                gnuplot_cmd(handle, "%s \"%s\" title \"%s\" lt rgb \"%s\" with %s smooth bezier", cmd, tmp_filename,title, handle->col, handle->pstyle) ;
            else
                gnuplot_cmd(handle, "%s \"%s\" title \"%s\" lt rgb \"%s\" with %s", cmd, tmp_filename,title, handle->col, handle->pstyle) ;
        }
        
    handle->nplots++ ;
    return ;
}