root/trunk/Jgraph/jgraph.c

Revision 420, 7.7 kB (checked in by nicholas, 10 months ago)

Jgraph: my changes - ANSIfication, few minor bug fixes; works on OS X 10.5 now

Line 
1 /*
2  * $Source: /tmp_mnt/n/fs/grad1/jsp/src/jgraph/RCS/jgraph.c,v $
3  * $Revision: 8.3 $
4  * $Date: 92/11/30 11:42:21 $
5  * $Author: jsp $
6  */
7
8 #include <stdio.h>
9 #include <string.h>
10
11 #ifdef VMS
12 #include <redexp.VMS>
13 #endif
14
15 #include "jgraph.h"
16
17 int NMARKTYPES = 17;
18 int NORMALMARKTYPES = 6;
19
20 char *MARKTYPESTRS[] = { "circle", "box", "diamond", "triangle", "x", "cross",
21                          "ellipse", "general", "general_nf", "general_bez",
22                          "general_bez_nf", "postscript", "eps",
23                          "xbar", "ybar", "none", "text"};
24 char MARKTYPES[] = {     'o',      'b',   'd',       't',        'x', 'c',
25                          'e',       'g',       'G',          'Z',
26                          'B',              'p',          'E',
27                          'X',    'Y',    'n',    'l' };
28
29 int NPATTERNS = 3;
30 char *PATTERNS[] = { "solid", "stripe", "estripe" };
31 char PTYPES[] = { 's', '/', 'e' };
32
33 Label new_label()
34 {
35   Label l;
36   int i;
37
38   l = (Label) malloc (sizeof(struct label));
39   l->label = CNULL;
40   l->hj = 'c';
41   l->vj = 'b';
42   l->font = "Times-Roman";
43   l->fontsize = 9.0;
44   l->rotate = 0;
45   l->graytype = 'n';
46   for (i = 0; i < 3; i++) l->gray[i] = 0.0;
47   l->linesep = FSIG;
48
49   return l;
50 }
51
52
53 Curve new_curve(c, num)
54 Curve c;
55 int num;
56 {
57   Curve new_c;
58   int i;
59
60   new_c = (Curve) get_node(c);
61   new_c->num = num;
62   new_c->l = new_label();
63   new_c->l->vj = 't';
64   new_c->lmark = new_label();
65   new_c->lmark->hj = 'c';
66   new_c->lmark->vj = 'c';
67   new_c->clip = 0;
68   new_c->pattern = 's';
69   new_c->parg = FSIG;
70   new_c->apattern = 's';
71   new_c->aparg = FSIG;
72   new_c->ppattern = 's';
73   new_c->pparg = FSIG;
74   new_c->graytype = 'n';
75   for (i = 0; i < 3; i++) new_c->gray[i] = 0.0;
76   new_c->afilltype = 'g';
77   for (i = 0; i < 3; i++) new_c->afill[i] = 0.0;
78   new_c->pts = (Point) make_list(sizeof(struct point));
79   new_c->yepts = (Point) make_list(sizeof(struct point));
80   new_c->xepts = (Point) make_list(sizeof(struct point));
81   new_c->npts = 0;
82   new_c->gen_linetype = (Flist) make_list(sizeof(struct flist));
83   new_c->marktype = MARKTYPES[num % NORMALMARKTYPES];
84   new_c->linetype = '0';
85   new_c->linethick = 1.0;
86   new_c->marksize[0] = FSIG;
87   new_c->marksize[1] = FSIG;
88   new_c->mrotate = 0.0;
89   new_c->general_marks = (Point) make_list(sizeof(struct point));
90   new_c->filltype = 'n';
91   for (i = 0; i < 3; i++) new_c->fill[i] = 0.0;
92   new_c->pfilltype = 'n';
93   for (i = 0; i < 3; i++) new_c->pfill[i] = 0.0;
94   new_c->poly = 0;
95   new_c->rarrow = 0;
96   new_c->larrow = 0;
97   new_c->rarrows = 0;
98   new_c->larrows = 0;
99   new_c->asize[0] = FSIG;
100   new_c->asize[1] = FSIG;
101   new_c->bezier = 0;
102   new_c->postscript = CNULL;
103   new_c->postfile = 0;
104   new_c->eps = CNULL;
105   prio_insert(new_c, c, 0);
106   return new_c;
107 }
108
109 Curve new_line(c, num)
110 Curve c;
111 int num;
112 {
113   Curve new_c;
114   new_c = new_curve(c, num);
115   new_c->linetype = 's';
116   new_c->marktype = 'n';
117   return new_c;
118 }
119
120
121 Curve get_curve(c, num)
122 Curve c;
123 int num;
124 {
125   Curve new_c;
126   for(new_c = last(c); new_c != nil(c) && new_c->num > num; new_c = prev(new_c));
127   if (new_c == nil(c) || new_c->num < num) return new_curve(c, num);
128   return new_c;
129 }
130
131 Axis new_axis(is_x)
132 int is_x;
133 {
134   int i;
135   Axis a;
136
137   a = (Axis) malloc (sizeof(struct axis));
138   a->label = new_label();
139   a->label->x = FSIG;
140   a->label->y = FSIG;
141   a->label->font = "Times-Bold";
142   a->label->fontsize = 10.0;
143   a->label->rotate = FSIG;
144   a->label->hj = '0';
145   a->label->vj = '0';
146   a->size = 3.0;
147   a->max = FSIG;
148   a->min = FSIG;
149   a->pmax = FSIG;
150   a->pmin = FSIG;
151   a->hash_interval = -1.0;
152   a->log_base = 10.0;
153   a->minor_hashes = -1;
154   a->precision = -1;
155   a->hl = new_label();
156   a->hl->label = "";
157   a->hl->font = "Times-Roman";
158   a->hl->fontsize = 9.0;
159   a->hl->rotate = 0.0;
160   a->hl->hj = '0';
161   a->hl->vj = '0';
162   a->hash_format = 'f';
163   a->draw_at = FSIG;
164   a->draw_hash_marks_at = FSIG;
165   a->draw_hash_labels_at = FSIG;
166   a->draw_hash_labels = 1;
167   a->draw_axis_line = 1;
168   a->draw_hash_marks = 1;
169   a->draw_axis_label = 1;
170   a->auto_hash_labels = 1;
171   a->auto_hash_marks = 1;
172   a->start_given = 0;
173   a->hash_scale = -1.0;
174   a->grid_lines = 0;
175   a->mgrid_lines = 0;
176   a->graytype = 'n';
177   for (i = 0; i < 3; i++) a->gray[i] = 0.0;
178   a->gr_graytype = '0';
179   for (i = 0; i < 3; i++) a->gr_gray[i] = 0.0;
180   a->mgr_graytype = '0';
181   for (i = 0; i < 3; i++) a->mgr_gray[i] = 0.0;
182   a->is_x = is_x;
183   a->is_lg = 0;
184   a->hash_labels = (String) make_list (sizeof(struct string));
185   a->hash_lines = (Hash) make_list (sizeof(struct hash));
186   return a;
187 }
188
189 Legend new_legend()
190 {
191   Legend l;
192   l = (Legend) malloc (sizeof(struct legend));
193   l->linelength = FSIG;
194   l->linebreak = FSIG;
195   l->midspace = FSIG;
196   l->type = 'u';
197   l->l = new_label();
198   l->l->label = "";
199   l->l->hj = 'l';
200   l->l->vj = 'c';
201   l->l->x = FSIG;
202   l->l->y = FSIG;
203   return l;
204 }
205
206 Label new_title()
207 {
208   Label t;
209
210   t = new_label();
211   t->x = FSIG;
212   t->y = FSIG;
213   t->rotate = 0.0;
214   t->hj = 'c';
215   t->vj = 't';
216   t->fontsize = 12.0;
217   return t;
218 }
219
220 String new_string(s, num)
221 String s;
222 int num;
223 {
224   String new_s;
225
226   new_s = (String) get_node(s);
227   new_s->num = num;
228   new_s->s = new_label();
229   prio_insert(new_s, s, 0);
230   return new_s;
231 }
232
233 String get_string(s, num)
234 String s;
235 int num;
236 {
237   String new_s;
238   for(new_s = last(s); new_s != nil(s) && new_s->num > num; new_s = prev(new_s));
239   if (new_s == nil(s) || new_s->num < num) return new_string(s, num);
240   return new_s;
241 }
242
243 /*
244 Default new_default()
245 {
246   Default new_d;
247   new_d = (Default) malloc (sizeof(default));
248   new_d->rotate = FSIG;
249   new_d->fontsize = FSIG;
250   new_d->general_marks = GMNULL;
251   new_d->fill = FSIG;
252   new_d->linethick = FSIG;
253   new_d->font = CNULL;
254   new_d->hj = '!';
255   new_d->vj = '!';
256   new_d->marktype = '!';
257   new_d->linetype = '!';
258   new_d->marksize[0] = FSIG;
259   new_d->marksize[1] = FSIG;
260 }
261 */
262  
263 Graph new_graph(gs, num)
264 Graph gs;
265 int num;
266 {
267   Graph g;
268
269   g = (Graph) get_node(gs);
270   g->num = num;
271   g->xminval = 0.0;
272   g->yminval = 0.0;
273   g->xmaxval = 0.0;
274   g->ymaxval = 0.0;
275   g->x_axis = new_axis(1);
276   g->y_axis = new_axis(0);
277   g->x_translate = 0.0;
278   g->y_translate = 0.0;
279   g->curves = (Curve) make_list(sizeof(struct curve));
280   g->strings = (String) make_list(sizeof(struct string));
281   g->title = new_title();
282   g->clip = 0;
283   g->border = 0;
284   g->legend = new_legend();
285 /*  g->def = new_default(); */
286   prio_insert(g, gs, 0);
287   return g;
288 }
289
290 Graph get_graph(g, num)
291 Graph g;
292 int num;
293 {
294   Graph new_g;
295   for(new_g = last(g); new_g != nil(g) && new_g->num > num; new_g = prev(new_g));
296   if (new_g == nil(g) || new_g->num < num) return new_graph(g, num);
297   return new_g;
298 }
299
300 void new_graphs(Graphs gs)
301 {
302   Graphs newg;
303
304   newg = (Graphs) get_node(gs);
305   newg->g = (Graph) make_list(sizeof(struct graph));
306   newg->height = 0.0;
307   newg->width = 0.0;
308   newg->bb[0] = ISIG; newg->bb[1] = ISIG;
309   newg->bb[2] = ISIG; newg->bb[3] = ISIG;
310   newg->preamble = CNULL;
311   newg->epilogue = CNULL;
312   newg->prefile = 0;
313   newg->epifile = 0;
314   if (first(gs) == nil(gs)) newg->page = 1; else newg->page = last(gs)->page+1;
315   insert(newg, gs);
316 }
317
318 int main(int argc, char **argv)
319 {
320   Graphs gs;
321   int i;
322   int show, pp;
323   int landscape;
324   int comments;
325   int nfiles;
326
327 #ifdef VMS
328   IOSTREAM = stdin;     /* for token.c -hdd */
329 #endif
330   show = 0;
331   pp = 0;
332   comments = 0;
333   landscape = 0;
334   nfiles = 0;
335
336   for (i = 1; i < argc; i++) {
337     if (strcmp(argv[i], "-p") == 0) show = 1;
338     else if (strcmp(argv[i], "-comments") == 0) comments = 1;
339     else if (strcmp(argv[i], "-P") == 0) pp = 1;
340     else if (strcmp(argv[i], "-L") == 0) landscape = 1;
341     else {
342       nfiles++;
343       set_input_file(argv[i]);
344     }
345   }
346   if (nfiles == 0) set_input_file(CNULL);
347   gs = (Graphs) make_list(sizeof(struct graphs));
348   set_comment(comments);
349   new_graphs(gs);
350   edit_graphs(gs);
351   process_graphs(gs);
352   if (show) show_graphs(gs); else draw_graphs(gs, pp, landscape);
353   exit(0);
354   return 0;
355 }
356
357
Note: See TracBrowser for help on using the browser.