1 /* Hello, Emacs, this is -*-C-*-
2 * $Id: gnugraph.trm,v 1.24 2006/07/21 02:35:46 sfeam Exp $
5 /* GNUPLOT -- gnugraph.trm */
8 * Copyright 1993, 1998, 2004
10 * Permission to use, copy, and distribute this software and its
11 * documentation for any purpose with or without fee is hereby granted,
12 * provided that the above copyright notice appear in all copies and
13 * that both that copyright notice and this permission notice appear
14 * in supporting documentation.
16 * Permission to modify the software is granted, but not the right to
17 * distribute the complete modified source code. Modifications are to
18 * be distributed as patches to the released version. Permission to
19 * distribute binaries produced by compiling modified sources is granted,
21 * 1. distribute the corresponding source modifications from the
22 * released version in the form of a patch file along with the binaries,
23 * 2. add special version identification to distinguish your version
24 * in addition to the base release version number,
25 * 3. provide your name and address as the primary contact for the
26 * support of your modified version, and
27 * 4. retain our contact information in regard to use of the base
29 * Permission to distribute the released version of the source code along
30 * with corresponding source modifications in the form of a patch file is
31 * granted with same provisions 2 through 4 for binary distributions.
33 * This software is provided "as is" without express or implied warranty
34 * to the extent permitted by applicable law.
38 * This file is included by ../term.c.
40 * This terminal driver supports:
41 * GNU plot(5) graphics language
44 * Tony Richardson from the unixplot.trm by Colin Kelley, Thomas Williams,
45 * and Russell Lang and from post.trm by Russell Lang.
47 * send your comments or suggestions to (info-gnuplot@ames.arc.nasa.gov).
51 * adapted to the new terminal layout by Stefan Bodewig (Dec. 1995)
55 * Name changed from "unixplot" to "gnugraph" to distinguish the two different
56 * drivers. Also avoids duplications in the complete gnuplot documentation.
61 * This version of the 'unixplot' driver produces device independent
62 * output. I've chosen parameter values so that the PostScript output
63 * produced by plot2ps is 5" x 3". You can use the 'set size' command
64 * to get output up to 8.25" x 8.25", i.e. size values larger than
69 Unixplot library writes to stdout. A fix was put in place by
70 ..!arizona!naucse!jdc to let set term and set output redirect
71 stdout. All other terminals write to gpoutfile.
74 /* This is a device independent format, so the output should look
75 * look "reasonable" on any output device. I set things up there so
76 * that the output of plot2ps is 5" x 3" (standard GNUPLOT size).
77 * You can use GNUPLOT's size command to obtain plots to almost the
78 * 8.25" x 8.25" limit.
84 register_term(gnugraph)
88 TERM_PUBLIC void UP_options __PROTO((void));
89 TERM_PUBLIC void UP_init __PROTO((void));
90 TERM_PUBLIC void UP_graphics __PROTO((void));
91 TERM_PUBLIC void UP_text __PROTO((void));
92 TERM_PUBLIC void UP_linetype __PROTO((int linetype));
93 TERM_PUBLIC void UP_move __PROTO((unsigned int x, unsigned int y));
94 TERM_PUBLIC void UP_vector __PROTO((unsigned int x, unsigned int y));
95 TERM_PUBLIC void UP_put_text __PROTO((unsigned int x, unsigned int y, const char str[]));
96 TERM_PUBLIC int UP_text_angle __PROTO((int ang));
97 TERM_PUBLIC int UP_justify_text __PROTO((enum JUSTIFY mode));
98 TERM_PUBLIC void UP_reset __PROTO((void));
100 #define UP_YMAX 11565
101 /* UP_VCHAR = ((UP_FONTSIZE*UP_YMAX)/(UP_YINCHES*72))
102 = UP_FONTSIZE*UP_VFONTSC
103 UP_HCHAR = ((UP_FONTSIZE/2)*UP_XMAX)/(UP_XINCHES*72))
104 = UP_FONTSIZE*UP_HFONTSC
107 #define UP_VFONTSC 53.5
108 #define UP_VCHAR 535 /* 10 * VFONTSC */
109 #define UP_HFONTSC 27.6
110 #define UP_HCHAR 276 /* 10 * HFONTSC */
112 #define UP_VTIC (UP_YMAX/80)
113 #define UP_HTIC (UP_XMAX/80)
114 #endif /* TERM_PROTO */
116 #ifndef TERM_PROTO_ONLY
119 #define DEFAULT_GNUGRAPHFONT "Courier"
122 char up_font[MAX_ID_LEN+1] = DEFAULT_GNUGRAPHFONT;
123 int up_fontsize = 10;
125 /* plot2ps produces a 8.25" x 8.25" square. */
126 #define UP_SCREENX 32768
127 #define UP_SCREENY 32768
128 #define UP_SCRXINC 8.25
129 #define UP_SCRYINC 8.25
131 /* We want a 5" x 3" graph by default. */
134 /* UP_XMAX = (UP_SCREENX*UP_XINCHES)/UP_SCRXINC
135 UP_YMAX (UP_SCREENY*UP_YINCHES)/UP_SCRYINC */
137 #define UP_XLAST (UP_XMAX - 1)
138 #define UP_YLAST (UP_YMAX - 1)
140 /* These offsets center plot2ps output in the middle of the page. The
141 * amount of resizing that can be done is limited. */
143 * #define UP_XOFF 6454
144 * #define UP_YOFF 10601
147 /* These offsets give a 1" offset from the lower left corner. This
148 * gives a greater range of permissible values in GNUPLOT's size
153 enum JUSTIFY up_justify = LEFT;
155 #define ROTATE(angle) pl_textangle(90*angle)
157 static int handle_global; /* T.Walter 1999-05-23 */
159 /* We don't include plot.h from plotutils because of
160 * the name clash with ../plot.h.
162 extern int pl_openpl __PROTO((void));
163 extern int pl_space __PROTO((int, int, int, int));
164 extern int pl_fontname __PROTO((const char *));
165 extern int pl_fontsize __PROTO((int));
166 extern int pl_erase __PROTO((void));
167 extern int pl_linemod __PROTO((const char *));
168 extern int pl_move __PROTO((int, int));
169 extern int pl_cont __PROTO((int, int));
170 extern int pl_alabel __PROTO((int, int, const char *));
171 extern int pl_textangle __PROTO((int));
172 extern int pl_closepl __PROTO((void));
173 /* T.Walter added: */
174 extern int pl_parampl __PROTO((const char *parameter, void *value));
175 extern int pl_newpl __PROTO((const char *type, FILE *infile, FILE *outfile, FILE *errfile));
176 extern int pl_selectpl __PROTO((int handle));
177 extern int pl_deletepl __PROTO((int handle));
178 extern double pl_ffontsize __PROTO((double size));
180 /* Formats supported by GNU plotutils */
182 PL_X, PL_PNM, PL_GIF, PL_AI, PL_PS, PL_CGM, PL_FIG, PL_PCL5,
183 PL_HPGL, PL_TEK, PL_META, PL_INVALID
186 struct gen_table term_up_pt_tbl[] =
202 /* Plot type, default */
203 static int pl_plottype = PL_META;
205 /* Plot size, default */
206 static char pl_pagesize[MAX_ID_LEN+1] = "a4";
208 enum UP_id { UP_DEFAULT, UP_PAGESIZE, UP_PLOTTYPE, UP_OTHER };
210 static struct gen_table UP_opts[] =
212 { "d$efault", UP_DEFAULT },
213 { "s$ize", UP_PAGESIZE },
214 { "t$ype", UP_PLOTTYPE },
223 while (!END_OF_COMMAND) {
224 switch(lookup_table(&UP_opts[0],c_token)) {
226 strcpy(up_font, DEFAULT_GNUGRAPHFONT);
228 term->v_char = (unsigned int) (up_fontsize * UP_VFONTSC);
229 term->h_char = (unsigned int) (up_fontsize * UP_HFONTSC);
234 /* user is responsible for valid page size specification, e.g.
235 * "a4", "letter", "b5", "a4,xoffset=-5mm,yoffset=2.0cm".
236 * See GNU plotutils documentation for details. */
237 quote_str(pl_pagesize, c_token, MAX_ID_LEN);
238 /* else use default quietly */
243 pl_plottype = lookup_table(&term_up_pt_tbl[0],c_token);
244 if (pl_plottype == PL_INVALID)
245 pl_plottype = PL_META;
250 if (isstring(c_token)) {
251 quote_str(up_font, c_token, MAX_ID_LEN);
254 if (!END_OF_COMMAND) {
255 /* We have font size specified */
256 up_fontsize = (int) real(const_express(&a));
257 term->v_char = (unsigned int) (up_fontsize * UP_VFONTSC);
258 term->h_char = (unsigned int) (up_fontsize * UP_HFONTSC);
263 sprintf(term_options, "\"%s\" %d size \"%s\" type %s",
267 term_up_pt_tbl[pl_plottype].key);
274 pl_parampl ("PAGESIZE", pl_pagesize);
276 if ((handle_global = pl_newpl (term_up_pt_tbl[pl_plottype].key,
277 NULL, gpoutfile, stderr)) < 0) {
278 int_error(NO_CARET, "GNU plotutils (gnugraph) failed to create \"%s\" plotter.",
279 term_up_pt_tbl[pl_plottype].key);
282 pl_selectpl (handle_global); /* select the Plotter for use */
285 pl_space (0, 0, UP_SCREENX - 1, UP_SCREENY - 1);
286 pl_fontname (up_font);
288 /* T.Walter: Try to find the correct font size */
290 pl_fontsize (up_fontsize); too small
291 pl_fontsize (up_fontsize*10); too small
292 pl_fontsize (up_fontsize*100); too large
293 pl_fontsize (up_fontsize*0.0525*GPMIN((UP_XMAX), (UP_YMAX))); too large
294 pl_fontsize (up_fontsize/72.0*GPMIN((UP_XMAX), (UP_YMAX))); too large
295 pl_fontsize (up_fontsize/72.0*0.0525*GPMIN((UP_XMAX), (UP_YMAX))); too small
296 pl_fontsize (up_fontsize/72.0*0.0525*GPMIN((UP_SCREENX), (UP_SCREENY))); too small
297 pl_fontsize (up_fontsize/72.0*GPMIN((UP_SCREENX), (UP_SCREENY))); too large
298 pl_fontsize (up_fontsize/72.0*8*0.0525*GPMIN((UP_XMAX), (UP_YMAX))); just about too large
300 pl_fontsize (up_fontsize/72.0*0.0525*GPMIN((UP_SCREENX), (UP_SCREENY)));
304 pl_space (0, 0, UP_SCREENX - 1, UP_SCREENY - 1);
305 pl_fontname (up_font);
307 pl_fontsize(up_fontsize);
321 /* Flush here so that output will be complete. */
327 UP_linetype(int linetype)
329 /* T.Walter, 1999-05-23 */
330 static char *lt[2+5] = { "solid", "longdashed", "solid", "dotted",
331 "shortdashed", "dotdashed", "longdashed"};
339 pl_linemod(lt[linetype + 2]);
344 UP_move(unsigned int x, unsigned int y)
346 pl_move(x + UP_XOFF, y + UP_YOFF);
351 UP_vector(unsigned int x, unsigned int y)
353 pl_cont(x + UP_XOFF, y + UP_YOFF);
358 UP_put_text(unsigned int x, unsigned int y, const char str[])
360 UP_move(x, y); /* Don't adjust x and y! It's done in UP_move. */
361 switch (up_justify) {
363 pl_alabel('l', 'c', str);
366 pl_alabel('c', 'c', str);
369 pl_alabel('r', 'c', str);
376 UP_text_angle(int ang)
383 UP_justify_text(enum JUSTIFY mode)
394 /* T.Walter, 1999-05-23 */
396 pl_selectpl (0); /* default plotter */
398 if (pl_deletepl (handle_global) < 0) /* delete plotter we used above */
399 fprintf (stderr, "GNU Plotutils (gnugraph) is not able to delete Plotter\n");
403 #endif /* TERM_BODY */
407 TERM_TABLE_START(gnugraph_driver)
408 "gnugraph", "GNU plot(1) format [\042fontname\042 font_size]",
409 UP_XMAX, UP_YMAX, UP_VCHAR, UP_HCHAR,
410 UP_VTIC, UP_HTIC, UP_options, UP_init, UP_reset,
411 UP_text, null_scale, UP_graphics, UP_move, UP_vector,
412 UP_linetype, UP_put_text, UP_text_angle,
413 UP_justify_text, line_and_point, do_arrow, set_font_null
414 TERM_TABLE_END(gnugraph_driver)
417 #define LAST_TERM gnugraph_driver
419 #endif /* TERM_TABLE */
420 #endif /* TERM_PROTO_ONLY */
422 #define TERM_HELP_GNUGRAPH
425 "1 Gnugraph(GNU plotutils)",
426 "?commands set terminal gnugraph",
427 "?set terminal gnugraph",
428 "?set term gnugraph",
429 "?terminal gnugraph",
432 " The `gnugraph` driver produces device-independent output in the GNU plot",
433 " graphics language. The default size of the PostScript results generated by",
434 " \"plot2ps\" is 5 x 3 inches; this can be increased up to about 8.25 x 8.25 by",
438 " set terminal gnugraph {\"<fontname>\"} {<fontsize>}",
439 " {type <pt>} {size \"<size>\"}",
441 " which defaults to 10-point \"Courier\".",
443 " For `type`, the following options are accepted: `X`, `pnm`, `gif`, `ai`,",
444 " `ps`, `cgm`, `fig`, `pcl5`, `hpgl`, `tek`, and `meta` (default). The",
445 " `size` option (default is a4) is passed straight through to plotutils, it's",
446 " the user's responsibility to provide correct values. Details can be found",
447 " in the plotutils documentation.",
450 " set terminal gnugraph type hpgl size \"a4\"",
451 " set terminal gnugraph size \"a4,xoffset=-5mm,yoffset=2.0cm\" type pnm",
453 " There is a non-GNU version of the `gnugraph` driver which cannot be compiled",
454 " unless this version is left out."