Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "gplot.h"
- int check_x_display(){
- char *disp;
- disp = getenv("DISPLAY");
- if (disp == NULL){
- fprintf(stderr, "nu exista x server");
- return 1;
- }
- else return 0;
- }
- gplot_ctrl *gplot_init(){
- if(check_x_display()) return NULL;
- gplot_ctrl *handler;
- handler = (gplot_ctrl*) malloc (sizeof(gplot_ctrl));
- gplot_setstyle(handler, "points");
- handler -> gpcmd = popen("gnuplot", "w");
- if (handler -> gpcmd != NULL) return handler;
- else {
- free(handler);
- fprintf(stderr, "nu s-a conectat");
- return NULL;
- }
- }
- void gplot_close(gplot_ctrl *handle){
- if (pclose(handler -> gpcmd) == -1){
- fprintf(stderr,"conexiunea s-a intrerupt");
- return;
- }
- else{
- free(handler);
- handler = NULL;
- return;
- }
- }
- void gplot_setstyle(gplot_ctrl *handle, char *plot_style){
- if(strcmp(plot_style, "lines") &&
- strcmp(plot_style, "points") &&
- strcmp(plot_style, "linespoints") &&
- strcmp(plot_style, "inpulses") &&
- strcmp(plot_style, "dots") &&
- strcmp(plot_style, "steps") &&
- strcmp(plot_style, "errorbars") &&
- strcmp(plot_style, "boxes") &&
- strcmp(plot_style, "boxerrorbars")){
- fprintf(stderr, "stil de reprezentare grafic necunoscut; setare stil points");
- strcpy(handler -> pstyle, "points");
- }
- else{
- strcpy(handler -> pstyle, plot_style);
- }
- }
- void gplot_set_xlabel(gplot_ctrl *handle, char *label){
- char cmd[CP_CMD_SIZE];
- cmd = sprintf(cmd,"set xlabel \"%s\"", label);
- gplot_cmd(handler, cmd);
- }
- void gplot_set_ylabel(gplot_ctrl *handle, char *label){
- char cmd[CP_CMD_SIZE];
- cmd = sprintf(cmd,"set ylabel \"%s\"", label);
- gplot_cmd(handler, cmd);
- }
- void gplot_cmd(gplot_ctrl *handle, char cmd*,...){
- va_list ap;
- char local_cmd[GP_CMD_SIZE];
- va_start(ap, cmd);
- vsprintf(local_cmd, cmd, ap);
- va_end(ap);
- strcat(local_cmd, "\n");
- fputs(local_cmd, handle -> gpcmd);
- fflush(handler->gpcmd);
- return;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement