Annotation of OpenXM_contrib/pari/src/graph/plotgnuplot.c, Revision 1.1.1.1
1.1 maekawa 1: /*******************************************************************/
2: /* */
3: /* HI-RES PLOT. GNUPLOT INTERFACE */
4: /* */
5: /* copyright Babe Cool */
6: /* (C) Ilya Zakharevich */
7: /* */
8: /*******************************************************************/
9: /* $Id: plotgnuplot.c,v 1.1.1.1 1999/09/16 13:47:42 karim Exp $ */
10: # include "pari.h"
11: #include "rect.h"
12: #define croak(str) err(talker,str)
13: #define SET_OPTIONS_FROM_STRING
14: #define GNUPLOT_OUTLINE_STDOUT
15: #define DONT_POLLUTE_INIT
16: #include "Gnuplot.h"
17:
18: #ifdef __EMX__
19: # define DEF_TERM "pm"
20: #else
21: # define DEF_TERM (getenv("DISPLAY") ? "X11" : "dumb")
22: #endif
23:
24: void
25: rectdraw0(long *w, long *x, long *y, long lw, long do_free)
26: {
27: long *ptx,*pty;
28: long i,j,x0,y0;
29: long good;
30: int point_type = -1, line_type = 0;
31: PariRect *e;
32: RectObj *p1;
33:
34: PARI_get_plot(0);
35:
36: #if 0
37: graphics(); /* Switch on terminal. */
38: #else
39: term_start_plot(); /* Switch on terminal. */
40: #endif
41: linetype(line_type); /* X does not work otherwise. */
42: setpointsize(pointsize);
43: for(i=0;i<lw;i++)
44: {
45: e=rectgraph[w[i]]; p1=RHead(e); x0=x[i]; y0=y[i];
46: while(p1)
47: {
48: switch(RoType(p1))
49: {
50: case ROt_PT:
51: point(RoPTx(p1)+x0, w_height - 1 - RoPTy(p1) - y0, point_type);
52: break;
53: case ROt_LN:
54: move(RoLNx1(p1)+x0, w_height - 1 - RoLNy1(p1) - y0);
55: vector(RoLNx2(p1)+x0, w_height - 1 - RoLNy2(p1) - y0);
56: break;
57: case ROt_BX:
58: move(RoBXx1(p1)+x0, w_height - 1 - RoBXy1(p1) - y0);
59: vector(RoBXx2(p1)+x0, w_height - 1 - RoBXy1(p1) - y0);
60: vector(RoBXx2(p1)+x0, w_height - 1 - RoBXy2(p1) - y0);
61: vector(RoBXx1(p1)+x0, w_height - 1 - RoBXy2(p1) - y0);
62: vector(RoBXx1(p1)+x0, w_height - 1 - RoBXy1(p1) - y0);
63: break;
64: case ROt_MP:
65: ptx=RoMPxs(p1);
66: pty=RoMPys(p1);
67: for(j=0;j<RoMPcnt(p1);j++)
68: {
69: point(ptx[j]+x0, w_height - 1 - pty[j] - y0, point_type);
70: }
71: break;
72: case ROt_ML:
73: ptx=RoMLxs(p1);
74: pty=RoMLys(p1);
75: j = 0;
76: if (ptx[j]+x0 < 0 || ptx[j]+x0 >= w_width
77: || pty[j] + y0 < 0 || pty[j] + y0 >= w_height) {
78: good = 0;
79: } else {
80: move(ptx[j]+x0, w_height - 1 - pty[j] - y0);
81: good = 1;
82: }
83: for(j=1;j<RoMLcnt(p1);j++)
84: {
85: if (good) {
86: if (ptx[j]+x0 < 0 || ptx[j]+x0 >= w_width
87: || pty[j] + y0 < 0 || pty[j] + y0 >= w_height) {
88: good = 0;
89: } else {
90: vector(ptx[j]+x0, w_height - 1 - pty[j] - y0);
91: }
92: } else {
93: if (ptx[j]+x0 < 0 || ptx[j]+x0 >= w_width
94: || pty[j] + y0 < 0 || pty[j] + y0 >= w_height) {
95: } else {
96: move(ptx[j]+x0, w_height - 1 - pty[j] - y0);
97: good = 1;
98: }
99: }
100: }
101: break;
102: case ROt_ST:
103: if (RoSTx(p1)+x0 < 0 || RoSTx(p1)+x0+RoSTl(p1)-1 >= w_width
104: || RoSTy(p1) + y0 < 0 || RoSTy(p1) + y0 >= w_height) {
105: } else {
106: put_text(RoSTx(p1)+x0,
107: w_height - 1 - RoSTy(p1) - y0 + (f_height - 1)/2,
108: RoSTs(p1));
109: }
110: break;
111: case ROt_PTT:
112: point_type = RoPTTpen(p1);
113: break;
114: case ROt_PTS:
115: pointsize = RoPTSsize(p1);
116: setpointsize(pointsize);
117: break;
118: case ROt_LNT:
119: linetype(RoLNTpen(p1));
120: break;
121: default: break;
122: }
123: p1=RoNext(p1);
124: }
125: }
126: #if 0
127: text(); /* Reset terminal */
128: #else
129: term_end_plot(); /* Reset terminal. */
130: #endif
131: }
132:
133: void
134: PARI_get_plot(long fatal)
135: {
136: if (pari_plot.init) {
137: return;
138: }
139: setup_gpshim();
140: term_set( DEF_TERM );
141: }
142:
143:
144: long
145: term_set(char *s)
146: {
147: char *t, *size = NULL;
148: double x, y;
149:
150: if (*s == 0)
151: s = pari_plot.name;
152: t = s;
153: if (t[1] == '\0' && t[0] == '?') {
154: list_terms();
155: return 1;
156: }
157: while (*t && !(*t == ' ' || *t == '\t' || *t == '\n' || *t == '='))
158: t++;
159: if ((t-s) > PLOT_NAME_LEN)
160: err(talker,"too long name \"%s\"for terminal", s);
161: if (*pari_plot.name
162: && (strlen(pari_plot.name) != t - s /* Why this? */
163: || (strncmp(pari_plot.name, s, t-s) != 0)) )
164: reset();
165: strncpy(pari_plot.name,s,t-s);
166: pari_plot.name[t-s] = '\0';
167:
168: if (!termset( pari_plot.name ))
169: err(talker,"error setting terminal \"%s\"", pari_plot.name);
170:
171: if (*t == '=') {
172: size = ++t;
173: x = atof(size);
174: while (*t && !(*t == ' ' || *t == '\t' || *t == '\n' || *t == ','))
175: t++;
176: if (*t != ',')
177: err(talker, "Terminal size directive without ','");
178: y = atof(++t);
179: while (*t && !(*t == ' ' || *t == '\t' || *t == '\n'))
180: t++;
181: plotsizes_scale(x*(1 + 1e-6)/termprop(xmax),
182: y*(1 + 1e-6)/termprop(ymax)); /* Later - truncated! */
183: } else {
184: plotsizes_scale(1,1);
185: }
186:
187: /* *Needed*, say, by gif output: */
188: set_options_from(t);
189:
190: #if 0
191: gptable_init(); /* Init terminal. */
192: #else
193: term_init();
194: #endif
195:
196: setpointsize(pointsize);
197:
198: w_width = scaled_xmax();
199: w_height = scaled_ymax();
200: f_height = termprop(v_char);
201: f_width = termprop(h_char);
202: h_unit = termprop(h_tic);
203: v_unit = termprop(v_tic);
204: pari_plot.init = 1;
205:
206: return 1;
207: }
208:
209: long
210: plot_outfile_set(char *s) {
211: int normal = (strcmp(s,"-") == 0);
212:
213: setup_gpshim();
214: /* Delegate all the hard work to term_set_output() */
215:
216: if (normal)
217: term_set_output(NULL);
218: else { /* term_set_output() needs
219: a malloced string */
220: char *s1 = (char*) malloc(strlen(s) + 1);
221:
222: strcpy(s1,s);
223: term_set_output(s1);
224: }
225: return 1;
226: }
227:
228: void
229: set_pointsize(double d)
230: {
231: pointsize = d;
232: if (pari_plot.init)
233: setpointsize(d);
234: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>