libdspl-2.0
Библиотека алгоритмов цифровой обработки сигналов
gnuplot_create.c
1/*
2* Copyright (c) 2015-2022 Sergey Bakhurin
3* Digital Signal Processing Library [http://dsplib.org]
4*
5* This file is part of DSPL.
6*
7* is free software: you can redistribute it and/or modify
8* it under the terms of the GNU General Public License as published by
9* the Free Software Foundation, either version 3 of the License, or
10* (at your option) any later version.
11*
12* DSPL is distributed in the hope that it will be useful,
13* but WITHOUT ANY WARRANTY; without even the implied warranty of
14* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15* GNU General Public License for more details.
16*
17* You should have received a copy of the GNU General Public License
18* along with Foobar. If not, see <http://www.gnu.org/licenses/>.
19*/
20#include <stdio.h>
21#include <unistd.h>
22#include "dspl.h"
23
24
25
26
27#define GNUPLOT_NO 1
28#define GNUPLOT_WIN 3
29#define GNUPLOT_PNG 4
30
31
32#ifdef DOXYGEN_ENGLISH
115#endif
116#ifdef DOXYGEN_RUSSIAN
201#endif
202int DSPL_API gnuplot_create(int argc, char* argv[],
203 int w, int h, char* fn_png,
204 void** hplot)
205{
206 FILE* hp;
207 char str[1024] = {0};
208 int state = 0;
209 int err;
210 if(argc>1 && !argv)
211 return ERROR_ARG_PARAM;
212
213 if(argc < 2)
214 state = GNUPLOT_WIN;
215 else
216 {
217 if(!strcmp(argv[1], "--noplot"))
218 state = GNUPLOT_NO;
219 if(!strcmp(argv[1], "--plotwin"))
220 state = GNUPLOT_WIN;
221 if(!strcmp(argv[1], "--plotpng"))
222 state = GNUPLOT_PNG;
223 }
224 if(!hplot)
225 return ERROR_PTR;
226
227 switch(state)
228 {
229 case GNUPLOT_NO:
230 hp = NULL;
231
232 err = RES_OK;
233 break;
234
235 case GNUPLOT_WIN:
236 hp = popen("gnuplot -p", "w");
237 if(!hp)
239 memset(str, 0, 1024*sizeof(char));
240 sprintf(str, "set terminal wxt size %d,%d", w,h);
241 gnuplot_cmd(hp, str);
242
243 err = RES_OK;
244 break;
245
246 case GNUPLOT_PNG:
247 if(!fn_png)
248 return ERROR_GNUPLOT_FNPNG;
249 hp = popen("gnuplot -p", "w");
250 if(!hp)
252 memset(str, 0, 1024*sizeof(char));
253 sprintf(str, "set terminal pngcairo size %d,%d\
254 enhanced font 'Verdana,8'", w, h);
255
256 gnuplot_cmd(hp, str);
257
258 memset(str, 0, 1024*sizeof(char));
259 sprintf(str, "set output '%s'", fn_png);
260 gnuplot_cmd(hp, str);
261 err = RES_OK;
262 break;
263
264 default:
265 err = ERROR_GNUPLOT_TERM;
266 hp = NULL;
267 }
268 *hplot = hp;
269 return err;
270}
271
#define ERROR_GNUPLOT_TERM
Неизвестный параметра вызова программы, задающий терминал GNUPLOT. Данный параметр может принимать о...
Definition: dspl.h:590
#define ERROR_ARG_PARAM
Неверный параметр вызова программы. Данная ошибка возникает, когда производится вызов программы с нев...
Definition: dspl.h:562
#define RES_OK
Функция завершилась корректно. Ошибки отсутствуют.
Definition: dspl.h:558
#define ERROR_GNUPLOT_CREATE
Невозможно подключиться к пакету GNUPLOT. Пожалуйста проверьте, что пакет доступен.
Definition: dspl.h:588
#define ERROR_PTR
Ошибка указателя. Данная ошибка означает, что один из обязательных указателей (память под который дол...
Definition: dspl.h:610
int gnuplot_create(int argc, char *argv[], int w, int h, char *fn_png, void **hplot)
Создать график GNUPLOT.
void gnuplot_cmd(void *h, char *cmd)
Функция посылает команду cmd пакету GNUPLOT, для построения или оформления графика,...
Definition: gnuplot_cmd.c:82