File: gpic.trm

package info (click to toggle)
gnuplot 3.5beta6.340-5
  • links: PTS
  • area: main
  • in suites: hamm
  • size: 4,792 kB
  • ctags: 4,205
  • sloc: ansic: 41,878; asm: 539; makefile: 498; objc: 379; csh: 297; sh: 277; pascal: 194; perl: 138; lisp: 88
file content (322 lines) | stat: -rw-r--r-- 8,059 bytes parent folder | download
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
/*
 * $Id: gpic.trm,v 1.14 1997/04/10 02:34:16 drd Exp $
 */

/* GNUPLOT - gpic.trm -*-C-*- */
/*
 * Copyright (C) 1993, 1997
 *
 * Permission to use, copy, and distribute this software and its
 * documentation for any purpose with or without fee is hereby granted, 
 * provided that the above copyright notice appear in all copies and 
 * that both that copyright notice and this permission notice appear 
 * in supporting documentation.
 *
 * This software  is provided "as is" without express or implied warranty.
 * 
 * This file is included by ../term.c.
 */

/*
 * This terminal driver supports:
 *   The GPIC graphics language for groff
 *
 * AUTHOR
 *  Sigfrid Lundberg
 *
 * send your comments or suggestions to (siglun@volterra.teorekol.lu.se).
 * 
 */

/*
 * adapted to the new terminal layout by Stefan Bodewig (Dec. 1995)
 */

#ifndef GOT_DRIVER_H
#include "driver.h"
#endif

#ifdef TERM_REGISTER
register_term(gpic)
#endif

#ifdef TERM_PROTO
TERM_PUBLIC void GPIC_options __PROTO((void));
TERM_PUBLIC void GPIC_init __PROTO((void));
TERM_PUBLIC void GPIC_graphics __PROTO((void));
TERM_PUBLIC void GPIC_text __PROTO((void));
TERM_PUBLIC void GPIC_linetype __PROTO((int linetype));
TERM_PUBLIC void GPIC_move __PROTO((unsigned int x, unsigned int y));
TERM_PUBLIC void GPIC_vector __PROTO((unsigned int ux, unsigned int uy));
TERM_PUBLIC void GPIC_arrow __PROTO((unsigned int sx, unsigned int sy, unsigned int ex, unsigned int ey, TBOOLEAN head));
TERM_PUBLIC void GPIC_put_text __PROTO((unsigned int x, unsigned int y, char str[]));
TERM_PUBLIC int GPIC_justify_text __PROTO((enum JUSTIFY mode));
TERM_PUBLIC int GPIC_text_angle __PROTO((int angle));
TERM_PUBLIC void GPIC_reset __PROTO((void));
#define GPIC_DOTS_PER_INCH (300)	

/* 5 inches wide by 3 inches high (default) */
#define GPIC_XMAX (5*GPIC_DOTS_PER_INCH)  
#define GPIC_YMAX (3*GPIC_DOTS_PER_INCH)  

#define GPIC_HTIC (5*GPIC_DOTS_PER_INCH/72)
#define GPIC_VTIC (5*GPIC_DOTS_PER_INCH/72)
#define GPIC_HCHAR (GPIC_DOTS_PER_INCH*53/10/72)
#define GPIC_VCHAR (GPIC_DOTS_PER_INCH*11/72)
#endif /* TERM_PROTO */
	
#ifndef TERM_PROTO_ONLY
#ifdef TERM_BODY

#define GPIC_PTS_PER_INCH (72.27)
#define GPIC_UNIT (GPIC_PTS_PER_INCH/GPIC_DOTS_PER_INCH) /* dot size in pt */
#define GPIC_coord(x) ((float)x)/((float)GPIC_DOTS_PER_INCH)

void GPIC_close_line __PROTO((void));
static float GPIC_x, GPIC_y;
static unsigned int GPIC_ltype;
enum JUSTIFY GPIC_justify=LEFT;

/* for DOTS point style */

#define GPIC_NUMLINES 6		/* number of linetypes below */
static char *GPIC_lines[] = {
    "thickness 1.0",			/* -2 border */
    "", 		/* -1 axes */
    "",			/*  0 solid thin  */
    "dotted",
    "dashed 0.05",			/*  1 solid thick */
    "dashed 0.075",			/*  2 solid Thick */
};


static int GPIC_linecount = 0; /* number of points in line so far */


TERM_PUBLIC void GPIC_options()
{
  float x,y;
  struct value a;

  GPIC_x=0;
  GPIC_y=0;

  if (!END_OF_COMMAND) {
    x = real(const_express(&a));
    if (!END_OF_COMMAND) {
      y = real(const_express(&a));
      GPIC_x = x;
      GPIC_y = y;
    }
  }

  sprintf(term_options, "Origin is at (%f,%f)",GPIC_x,GPIC_y);

}

TERM_PUBLIC void GPIC_init()
{
  GPIC_linetype(-1);
  fprintf(outfile, ".\\\"GNUPLOT: GROFF picture using the gpic preprocessor\n");
}



TERM_PUBLIC void GPIC_graphics()
{
  register struct termentry *t = term;

  fprintf(outfile, ".PS %f %f\n",GPIC_coord(t->xmax),
	  GPIC_coord(t->ymax));
  fprintf(outfile,"x=%f; y=%f\n",GPIC_x, GPIC_y);
}


TERM_PUBLIC void GPIC_text()
{
  GPIC_close_line();
  fprintf(outfile, ".PE\n");
}

TERM_PUBLIC void GPIC_linetype(linetype)
     int linetype;
{
  if (linetype >= GPIC_NUMLINES-2)
    linetype %= (GPIC_NUMLINES-2);
  GPIC_ltype = linetype;
}

void GPIC_close_line()
{
  if(GPIC_linecount>0) {
    fprintf(outfile,"; reset linewid\n");
    GPIC_linecount = 0;
  }
}

TERM_PUBLIC void GPIC_move(x,y)
     unsigned int x,y;
{
  GPIC_close_line();
  fprintf(outfile,"move to (x+%f,y+%f)\n",GPIC_coord(x),GPIC_coord(y));
  GPIC_linecount = 1;
}


TERM_PUBLIC void GPIC_vector(ux,uy)
     unsigned int ux,uy;
{
  if(GPIC_linecount==1) {
    fprintf(outfile,"line %s to (x+%f,y+%f)",
	    GPIC_lines[GPIC_ltype+2],
	    GPIC_coord(ux),GPIC_coord(uy));
  } else {
    fprintf(outfile," \\\n");
    fprintf(outfile,"   then to (x+%f,y+%f)",GPIC_coord(ux),GPIC_coord(uy));
  }
  GPIC_linecount++;
}


TERM_PUBLIC void GPIC_arrow(sx,sy, ex,ey, head)
	unsigned int sx,sy, ex,ey;
	TBOOLEAN head;
{
  GPIC_close_line();
  if(head) {
    fprintf(outfile,"arrowhead=7; arrow from x+%f,y+%f to x+%f,y+%f\n",
	    GPIC_coord(sx),GPIC_coord(sy),GPIC_coord(ex),GPIC_coord(ey));
  } else { 
    fprintf(outfile,"line from x+%f,y+%f to x+%f,y+%f\n",
	    GPIC_coord(sx),GPIC_coord(sy),GPIC_coord(ex),GPIC_coord(ey));
  }
}


TERM_PUBLIC void GPIC_put_text(x, y, str)
	unsigned int x,y;				/* reference point of string */
	char str[];			/* the text */
{
  GPIC_close_line();
  fprintf(outfile, "\"%s\" ",str);
  switch(GPIC_justify) {
  case LEFT: {
    fprintf(outfile,"ljust ");
    break;
  }
  case CENTRE: {
    fprintf(outfile," ");
    break;
  }
  case RIGHT: {
    fprintf(outfile,"rjust ");
    break;
  }
  }
  fprintf(outfile,"at x+%f,y+%f\n",GPIC_coord(x),GPIC_coord(y));
}



TERM_PUBLIC int GPIC_justify_text(mode)
	enum JUSTIFY mode;
{
  GPIC_justify = mode;
  return (TRUE);
}

TERM_PUBLIC int GPIC_text_angle(angle)
	int angle;
{
  GPIC_close_line();
  return (FALSE);
}

TERM_PUBLIC void GPIC_reset()
{
  fflush(outfile);
}

#endif /* TERM_BODY */

#ifdef TERM_TABLE

TERM_TABLE_START(gpic_driver)
    "gpic", "GPIC -- Produce graphs in groff using the gpic preprocessor",
	   GPIC_XMAX, GPIC_YMAX, GPIC_VCHAR, GPIC_HCHAR, 
	   GPIC_VTIC, GPIC_HTIC, GPIC_options, GPIC_init, GPIC_reset, 
	   GPIC_text, null_scale, GPIC_graphics, GPIC_move, GPIC_vector, 
	   GPIC_linetype, GPIC_put_text, GPIC_text_angle, 
	   GPIC_justify_text, line_and_point, GPIC_arrow, set_font_null
TERM_TABLE_END(gpic_driver)

#undef LAST_TERM
#define LAST_TERM gpic_driver

#endif /* TERM_TABLE */
#endif /* TERM_PROTO_ONLY */

#ifdef TERM_HELP
START_HELP(gpic)
"1 gpic",
"?set terminal gpic",
"?set term gpic",
"?terminal gpic",
"?term gpic",
"?gpic",
" The `gpic` terminal driver generates GPIC graphs in the Free Software",
" Foundations's \"groff\" package.  The default size is 5 x 3 inches.  The only",
" option is the origin, which defaults to (0,0).",
"",
" Syntax:",
"       set terminal gpic {<x> <y>}",
"",
" where `x` and `y` are in inches.",
"",
" A simple graph can be formatted using",
"",
"       groff -p -mpic -Tps file.pic > file.ps.",
"",
" The output from pic can be pipe-lined into eqn, so it is possible to put",
" complex functions in a graph with the `set label` and `set {x/y}label`",
" commands.  For instance,",
"",
"       set ylab '@space 0 int from 0 to x alpha ( t ) roman d t@'",
"",
" will label the y axis with a nice integral if formatted with the command:",
"",
"       gpic filename.pic | geqn -d@@ -Tps | groff -m[macro-package] -Tps",
"           > filename.ps",
"",
" Figures made this way can be scaled to fit into a document.  The pic language",
" is easy to understand, so the graphs can be edited by hand if need be.  All",
" co-ordinates in the pic-file produced by `gnuplot` are given as x+gnuplotx",
" and y+gnuploty.  By default x and y are given the value 0.  If this line is",
" removed with an editor in a number of files, one can put several graphs in",
" one figure like this (default size is 5.0x3.0 inches):",
"",
"       .PS 8.0",
"       x=0;y=3",
"       copy \"figa.pic\"",
"       x=5;y=3",
"       copy \"figb.pic\"",
"       x=0;y=0",
"       copy \"figc.pic\"",
"       x=5;y=0",
"       copy \"figd.pic\"",
"       .PE",
"",
" This will produce an 8-inch-wide figure with four graphs in two rows on top",
" of each other.",
"",
" One can also achieve the same thing by the command",
"",
"       set terminal gpic x y",
"",
" for example, using",
"",
"       .PS 6.0",
"       copy \"trig.pic\"",
"       .PE"
END_HELP(gpic)
#endif