-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathgnuplot_i.hpp
447 lines (351 loc) · 12.7 KB
/
gnuplot_i.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
/*----------------------------------------------------------------------------
E.S.O.
-----------------------------------------------------------------------------
File name : gnuplot_i.h
Author : N. Devillard
Created on : Fri Sept 26 1997
Software : ANSI C under Solaris Unix
Part of ECLIPSE library for Adonis
Description : C interface to gnuplot
gnuplot is a freely available, command-driven graphical display tool for
Unix. It compiles and works quite well on a number of Unix flavours as
well as other operating systems. The following module enables sending
display requests to gnuplot through simple C calls.
---------------------------------------------------------------------------*/
/*
$Id: gnuplot_i.h,v 1.2 2000/04/18 12:31:17 ndevilla Exp $
$Author: ndevilla $
$Date: 2000/04/18 12:31:17 $
$Revision: 1.2 $
*/
#ifndef _GNUPLOT_PIPES_H_
#define _GNUPLOT_PIPES_H_
/*---------------------------------------------------------------------------
Includes
---------------------------------------------------------------------------*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <stdarg.h>
#define GP_MAX_TMP_FILES 64
#define GP_TMP_NAME_SIZE 512
#define GP_CMD_SIZE 1024
/*---------------------------------------------------------------------------
New Types
---------------------------------------------------------------------------*/
/*
* This structure holds all necessary information to talk to a gnuplot
* session.
*/
typedef struct _GNUPLOT_CTRL_ {
/* command file handling */
FILE * gnucmd ;
/* Plotting options */
int nplots ; /* Number of active plots at the moment */
char pstyle[32] ; /* Current plotting style */
/* temporary files opened */
char to_delete[GP_MAX_TMP_FILES][GP_TMP_NAME_SIZE] ;
int ntmp ;
} gnuplot_ctrl ;
#ifndef _ECLIPSE_TYPES_H_
/*
* dpoint is convenient to store signals which have definition both on x and
* y axis.
*/
typedef struct _DPOINT_ {
double x ;
double y ;
} dpoint ;
#endif
extern "C" {
/*---------------------------------------------------------------------------
Function ANSI C prototypes
---------------------------------------------------------------------------*/
/*-------------------------------------------------------------------------*/
/**
@name check_X_display
@memo Checks out if the DISPLAY environment variable is set.
@param activate int flag
@return int 1 if the variable is set, 0 otherwise.
@doc
This function checks out the DISPLAY environment variable to see if
it exists. It does not check if the display is actually correctly
configured. If you do not want to activate this check (e.g. on
systems that do not support this kind of display mechanism), pass a
0 integer as the activate flag. Any other value will activate it.
*/
/*--------------------------------------------------------------------------*/
int check_X_display(int activate);
/*-------------------------------------------------------------------------*/
/**
@name gnuplot_get_program_path
@memo Find out where a command lives in your PATH.
@param pname Name of the program to look for.
@return pointer to statically allocated character string.
@doc
This is the C equivalent to the 'which' command in Unix. It parses
out your PATH environment variable to find out where a command
lives. The returned character string is statically allocated within
this function, i.e. there is no need to free it. Beware that the
contents of this string will change from one call to the next,
though (as all static variables in a function).
The input character string must be the name of a command without
prefixing path of any kind, i.e. only the command name. The returned
string is the path in which a command matching the same name was
found.
Examples (assuming there is a prog named 'hello' in the cwd):
\begin{itemize}
\item gnuplot_get_program_path("hello") returns "."
\item gnuplot_get_program_path("ls") returns "/bin"
\item gnuplot_get_program_path("csh") returns "/usr/bin"
\item gnuplot_get_program_path("/bin/ls") returns NULL
\end{itemize}
*/
/*-------------------------------------------------------------------------*/
char * gnuplot_get_program_path(char * pname);
/*-------------------------------------------------------------------------*/
/**
@name gnuplot_init
@memo Opens up a gnuplot session, ready to receive commands.
@return Newly allocated gnuplot control structure.
@doc
This opens up a new gnuplot session, ready for input. The struct
controlling a gnuplot session should remain opaque and only be
accessed through the provided functions.
*/
/*--------------------------------------------------------------------------*/
gnuplot_ctrl * gnuplot_init(void);
/*-------------------------------------------------------------------------*/
/**
@name gnuplot_close
@memo Closes a gnuplot session previously opened by gnuplot_init()
@param handle Gnuplot session control handle.
@return void
@doc
Kills the child PID and deletes all opened temporary files.
It is mandatory to call this function to close the handle, otherwise
temporary files are not cleaned and child process might survive.
*/
/*--------------------------------------------------------------------------*/
void gnuplot_close(gnuplot_ctrl * handle);
/*-------------------------------------------------------------------------*/
/**
@name gnuplot_cmd
@memo Sends a command to an active gnuplot session.
@param handle Gnuplot session control handle
@param cmd Command to send, same as a printf statement.
@return void
@doc
This sends a string to an active gnuplot session, to be executed.
There is strictly no way to know if the command has been
successfully executed or not.
The command syntax is the same as printf.
Examples:
\begin{itemize}
\item gnuplot_cmd(g, "plot %d*x", 23.0);
\item gnuplot_cmd(g, "plot %g * cos(%g * x)", 32.0, -3.0);
\end{itemize}
*/
/*--------------------------------------------------------------------------*/
void gnuplot_cmd(gnuplot_ctrl * handle, char * cmd, ...);
/*-------------------------------------------------------------------------*/
/**
@name gnuplot_setstyle
@memo Change the plotting style of a gnuplot session.
@param h Gnuplot session control handle
@param plot_style Plotting-style to use (character string)
@return void
@doc
The provided plotting style is a character string. It must be one of
the following:
\begin{itemize}
\item {\it lines}
\item {\it points}
\item {\it linespoints}
\item {\it impulses}
\item {\it dots}
\item {\it steps}
\item {\it errorbars}
\item {\it boxes}
\item {\it boxeserrorbars}
\end{itemize}
*/
/*--------------------------------------------------------------------------*/
void gnuplot_setstyle(gnuplot_ctrl * h, char * plot_style);
/*-------------------------------------------------------------------------*/
/**
@name gnuplot_resetplot
@memo Resets a gnuplot session (next plot will erase previous ones).
@param h Gnuplot session control handle.
@return void
@doc
Resets a gnuplot session, i.e. the next plot will erase all previous
ones.
*/
/*--------------------------------------------------------------------------*/
void gnuplot_resetplot(gnuplot_ctrl * h);
/*-------------------------------------------------------------------------*/
/**
@name gnuplot_plot1d_var1
@memo Plots a 2d graph from a list of doubles.
@param handle Gnuplot session control handle.
@param d Pointer to a list of doubles.
@param n_point Number of doubles in the list.
@param title Title of the plot.
@return void
@doc
Plots out a 2d graph from a list of doubles. The x-coordinate is the
index of the double in the list, the y coordinate is the double in
the list.
Example:
\begin{verbatim}
gnuplot_ctrl *h ;
double d[50] ;
int i ;
h = gnuplot_init() ;
for (i=0 ; i<50 ; i++) {
d[i] = (double)(i*i) ;
}
gnuplot_plot1d_var1(h, d, 50, "parabola") ;
sleep(2) ;
gnuplot_close(h) ;
\end{verbatim}
*/
/*--------------------------------------------------------------------------*/
void gnuplot_plot1d_var1(
gnuplot_ctrl * handle,
double * d,
int n_point,
char * title
) ;
/*-------------------------------------------------------------------------*/
/**
@name gnuplot_plot1d_var2
@memo Plot a 2d graph from a list of dpoint.
@param handle Gnuplot session control handle.
@param d Pointer to a list of doubles.
@param n_points Number of doubles in the list.
@param title Title of the plot.
@return void
@doc
Plots out a 2d graph from a list of dpoints. A dpoint is a struct
containing two fields x and y (doubles) which are plotted as they
are on the gnuplot session.
\begin{verbatim}
gnuplot_ctrl *h ;
dpoint d[50] ;
int i ;
h = gnuplot_init() ;
for (i=0 ; i<50 ; i++) {
d[i].x = (double)(i)/10.0 ;
d[i].y = d[i].x * d[i].x ;
}
gnuplot_plot1d_var2(h, d, 50, "parabola") ;
sleep(2) ;
gnuplot_close(h) ;
\end{verbatim}
*/
/*--------------------------------------------------------------------------*/
void gnuplot_plot1d_var2(
gnuplot_ctrl * handle,
dpoint * d,
int n_points,
char * title
) ;
/*-------------------------------------------------------------------------*/
/**
@name gnuplot_plot1d_var2v
@memo Plot a 2d graph from a list of pairs of points.
@param handle Gnuplot session control handle.
@param x list of x values
@param y list of y values
@param n_points Number of doubles in the list.
@param title Title of the plot.
@return void
@doc
Plots out a 2d graph from a list of pairs of points.
\begin{verbatim}
gnuplot_ctrl *h ;
double x[50];
double y[50];
int j ;
h = gnuplot_init() ;
for (j=0 ; j<50 ; j++) {
x[0+j*2] = (double)(i)/10.0 ;
y[1+j*2] = x[0j] * x[j] ;
}
gnuplot_plot1d_var2v(h, x, y, 50, "parabola") ;
sleep(2) ;
gnuplot_close(h) ;
\end{verbatim}
*/
/*-------------------------------------------------------------------------*/
void gnuplot_plot1d_var2v (
gnuplot_ctrl * handle,
double * x,
double * y,
int n_points,
char * title
);
/*-------------------------------------------------------------------------*/
/**
@name gnuplot_plot_slope
@memo Plot a slope on a gnuplot session.
@param handle Gnuplot session control handle.
@param a Slope.
@param b Intercept.
@param title Title of the plot.
@return void
@doc
Plot a slope on a gnuplot session. The provided slope has an
equation of the form:
\begin{verbatim}
y = ax+b
\end{verbatim}
Example:
\begin{verbatim}
gnuplot_ctrl * h ;
double a, b ;
h = gnuplot_init() ;
gnuplot_plot_slope(h, 1.0, 0.0, "unity slope") ;
sleep(2) ;
gnuplot_close(h) ;
\end{verbatim}
*/
/*--------------------------------------------------------------------------*/
void gnuplot_plot_slope(
gnuplot_ctrl * handle,
double a,
double b,
char * title
) ;
/*-------------------------------------------------------------------------*/
/**
@name gnuplot_plot_equation
@memo Plot a curve of given equation y=f(x).
@param h Gnuplot session control handle.
@param equation Equation to plot.
@param title Title of the plot.
@return void
@doc
Plots out a curve of given equation. The general form of the
equation is y=f(x), you only provide the f(x) side of the equation.
Example:
\begin{verbatim}
gnuplot_ctrl *h ;
char eq[80] ;
h = gnuplot_init() ;
strcpy(eq, "sin(x) * cos(2*x)") ;
gnuplot_plot_equation(h, eq, "sine wave", normal) ;
gnuplot_close(h) ;
\end{verbatim}
*/
/*--------------------------------------------------------------------------*/
void gnuplot_plot_equation(
gnuplot_ctrl * h,
char * equation,
char * title
) ;
}
#endif