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
33 
114 #endif
115 #ifdef DOXYGEN_RUSSIAN
116 
199 #endif
200 int DSPL_API gnuplot_create(int argc, char* argv[],
201  int w, int h, char* fn_png,
202  void** hplot)
203 {
204  FILE* hp;
205  char str[1024] = {0};
206  int state = 0;
207  int err;
208  if(argc>1 && !argv)
209  return ERROR_ARG_PARAM;
210 
211  if(argc < 2)
212  state = GNUPLOT_WIN;
213  else
214  {
215  if(!strcmp(argv[1], "--noplot"))
216  state = GNUPLOT_NO;
217  if(!strcmp(argv[1], "--plotwin"))
218  state = GNUPLOT_WIN;
219  if(!strcmp(argv[1], "--plotpng"))
220  state = GNUPLOT_PNG;
221  }
222  if(!hplot)
223  return ERROR_PTR;
224 
225  switch(state)
226  {
227  case GNUPLOT_NO:
228  hp = NULL;
229 
230  err = RES_OK;
231  break;
232 
233  case GNUPLOT_WIN:
234  hp = popen("gnuplot -p", "w");
235  if(!hp)
236  return ERROR_GNUPLOT_CREATE;
237  memset(str, 0, 1024*sizeof(char));
238  sprintf(str, "set terminal wxt size %d,%d", w,h);
239  gnuplot_cmd(hp, str);
240 
241  err = RES_OK;
242  break;
243 
244  case GNUPLOT_PNG:
245  if(!fn_png)
246  return ERROR_GNUPLOT_FNPNG;
247  hp = popen("gnuplot -p", "w");
248  if(!hp)
249  return ERROR_GNUPLOT_CREATE;
250  memset(str, 0, 1024*sizeof(char));
251  sprintf(str, "set terminal pngcairo size %d,%d\
252  enhanced font 'Verdana,8'", w, h);
253 
254  gnuplot_cmd(hp, str);
255 
256  memset(str, 0, 1024*sizeof(char));
257  sprintf(str, "set output '%s'", fn_png);
258  gnuplot_cmd(hp, str);
259  err = RES_OK;
260  break;
261 
262  default:
263  err = ERROR_GNUPLOT_TERM;
264  hp = NULL;
265  }
266  *hplot = hp;
267  return err;
268 }
269 
#define ERROR_GNUPLOT_TERM
Неизвестный параметра вызова программы, задающий терминал GNUPLOT. Данный параметр может принимать о...
Definition: dspl.h:590
#define ERROR_PTR
Ошибка указателя. Данная ошибка означает, что один из обязательных указателей (память под который дол...
Definition: dspl.h:610
void gnuplot_cmd(void *h, char *cmd)
Функция посылает команду cmd пакету GNUPLOT, для построения или оформления графика,...
Definition: gnuplot_cmd.c:82
#define ERROR_ARG_PARAM
Неверный параметр вызова программы. Данная ошибка возникает, когда производится вызов программы с нев...
Definition: dspl.h:562
#define RES_OK
Функция завершилась корректно. Ошибки отсутствуют.
Definition: dspl.h:558
#define ERROR_GNUPLOT_CREATE
Невозможно подключиться к пакету GNUPLOT. Пожалуйста проверьте, что пакет доступен.
Definition: dspl.h:588
int gnuplot_create(int argc, char *argv[], int w, int h, char *fn_png, void **hplot)
Создать график GNUPLOT.