| 1 |
#! /bin/sh |
| 2 |
# This is a shell archive, meaning: |
| 3 |
# 1. Remove everything above the #! /bin/sh line. |
| 4 |
# 2. Save the resulting text in a file. |
| 5 |
# 3. Execute the file with /bin/sh (not csh) to create the files: |
| 6 |
# README |
| 7 |
# Makefile |
| 8 |
# grafig.1 |
| 9 |
# object.h |
| 10 |
# grafig.c |
| 11 |
# This archive created: Wed Mar 15 16:57:30 1989 |
| 12 |
export PATH; PATH=/bin:$PATH |
| 13 |
if test -f 'README' |
| 14 |
then |
| 15 |
echo shar: will not over-write existing file "'README'" |
| 16 |
else |
| 17 |
cat << \SHAR_EOF > 'README' |
| 18 |
GraFig 0.0 is a "trial balloon" program which creates very simple |
| 19 |
graphs from numerical data. It is completely rigid in its operation, |
| 20 |
with NO options or features. I am distributing it for several reasons: |
| 21 |
|
| 22 |
1) To find out whether there is a need for a fancier |
| 23 |
version of such a program in the user community. |
| 24 |
|
| 25 |
2) To find out what the important features of such |
| 26 |
a program would be. |
| 27 |
|
| 28 |
3) To demonstrate how easy it is to write a small |
| 29 |
program which produces graphics in the form of Fig code. |
| 30 |
(GraFig 0.0 took only several hours to write). |
| 31 |
|
| 32 |
I am interested in hearing back from ANY user who is interested in |
| 33 |
this program, even (especially) if you cannot use it because of lack |
| 34 |
of features. I am considering development of a much fancier tool |
| 35 |
for the analysis/plotting of data, with an interactive graphical |
| 36 |
interface. |
| 37 |
|
| 38 |
Please note: the output of GraFig can be edited using any of the |
| 39 |
existing versions of Fig, so you can do a lot of pretty-ing up |
| 40 |
of the graphs by hand. This program is meant to be minimal, in |
| 41 |
order to get design suggestions for a more mature version. |
| 42 |
------- |
| 43 |
Update 3/15/89 |
| 44 |
|
| 45 |
The GnuTeX version of the GnuPlot numerical plotting program can now |
| 46 |
generate Fig code. Thus, it has many features one would want in a more |
| 47 |
mature version of GraFig. GnuTeX is available via anonymous TFP |
| 48 |
from duke.cs.duke.edu. For more information about GnuTeX, contact |
| 49 |
David Kotz ([email protected]). |
| 50 |
SHAR_EOF |
| 51 |
fi # end of overwriting check |
| 52 |
if test -f 'Makefile' |
| 53 |
then |
| 54 |
echo shar: will not over-write existing file "'Makefile'" |
| 55 |
else |
| 56 |
cat << \SHAR_EOF > 'Makefile' |
| 57 |
SHAR = ../../shar/shar |
| 58 |
SHARFILES = README Makefile grafig.1 object.h grafig.c |
| 59 |
|
| 60 |
grafig: object.h grafig.c |
| 61 |
cc -O -o grafig grafig.c -lm |
| 62 |
|
| 63 |
|
| 64 |
shar: ${SHARFILES} |
| 65 |
${SHAR} ${SHARFILES} >../grafig.shar |
| 66 |
SHAR_EOF |
| 67 |
fi # end of overwriting check |
| 68 |
if test -f 'grafig.1' |
| 69 |
then |
| 70 |
echo shar: will not over-write existing file "'grafig.1'" |
| 71 |
else |
| 72 |
cat << \SHAR_EOF > 'grafig.1' |
| 73 |
.TH GRAFIG 1 "1 Februrary 1989" |
| 74 |
|
| 75 |
.SH NAME |
| 76 |
grafig \- generates numerical graphs in Fig code |
| 77 |
|
| 78 |
.SH SYNOPSIS |
| 79 |
.B grafig <data_stream >fig_code |
| 80 |
|
| 81 |
.SH DESCRIPTION |
| 82 |
.I Grafig |
| 83 |
transforms a stream of data points on its standard input to |
| 84 |
a numerical graph on its standard output. |
| 85 |
The input is in the form of pairs of numbers representing |
| 86 |
x and y coordinates, seperated by white space. |
| 87 |
Thus, the set of points {(x1, y1), (x2, y2), ...} could represented |
| 88 |
by the input file |
| 89 |
.sp |
| 90 |
x1 y1 |
| 91 |
.br |
| 92 |
x2 y2 |
| 93 |
... |
| 94 |
.sp |
| 95 |
The output is in the form of |
| 96 |
.I Fig |
| 97 |
code, which can be viewed and edited with the fig(1) graphics editor, |
| 98 |
and can be incorporated into TeX(1) troff(1), or PostScript documents |
| 99 |
using the TransFig(1) translation package. |
| 100 |
.PP |
| 101 |
This early version of grafig takes NO options or flags. |
| 102 |
The output has only one possible form. |
| 103 |
|
| 104 |
.SH "SEE ALSO" |
| 105 |
fig(1), |
| 106 |
tex(1), |
| 107 |
transfig(1), |
| 108 |
troff(1), |
| 109 |
.SH AUTHOR |
| 110 |
Micah Beck ([email protected]) |
| 111 |
SHAR_EOF |
| 112 |
fi # end of overwriting check |
| 113 |
if test -f 'object.h' |
| 114 |
then |
| 115 |
echo shar: will not over-write existing file "'object.h'" |
| 116 |
else |
| 117 |
cat << \SHAR_EOF > 'object.h' |
| 118 |
/* |
| 119 |
* FIG : Facility for Interactive Generation of figures |
| 120 |
* |
| 121 |
* (c) copy right 1985 by Supoj Sutanthavibul ([email protected]) |
| 122 |
* January 1985. |
| 123 |
* 1st revision : Aug 1985. |
| 124 |
* 2nd revision : Feb 1988. |
| 125 |
* |
| 126 |
* %W% %G% |
| 127 |
*/ |
| 128 |
#define DEFAULT (-1) |
| 129 |
|
| 130 |
typedef struct f_pattern { |
| 131 |
int w, h; |
| 132 |
int *p; |
| 133 |
} |
| 134 |
F_pattern; |
| 135 |
|
| 136 |
typedef struct f_pen { |
| 137 |
int x, y; |
| 138 |
int *p; |
| 139 |
} |
| 140 |
F_pen; |
| 141 |
|
| 142 |
typedef struct f_point { |
| 143 |
int x, y; |
| 144 |
struct f_point *next; |
| 145 |
} |
| 146 |
F_point; |
| 147 |
|
| 148 |
typedef struct f_pos { |
| 149 |
int x, y; |
| 150 |
} |
| 151 |
F_pos; |
| 152 |
|
| 153 |
typedef struct f_arrow { |
| 154 |
int type; |
| 155 |
int style; |
| 156 |
double thickness; |
| 157 |
double wid; |
| 158 |
double ht; |
| 159 |
} |
| 160 |
F_arrow; |
| 161 |
|
| 162 |
typedef struct f_ellipse { |
| 163 |
int type; |
| 164 |
#define T_ELLIPSE_BY_RAD 1 |
| 165 |
#define T_ELLIPSE_BY_DIA 2 |
| 166 |
#define T_CIRCLE_BY_RAD 3 |
| 167 |
#define T_CIRCLE_BY_DIA 4 |
| 168 |
int style; |
| 169 |
int thickness; |
| 170 |
int color; |
| 171 |
#define BLACK 0 |
| 172 |
int depth; |
| 173 |
int direction; |
| 174 |
double style_val; |
| 175 |
double angle; |
| 176 |
struct f_pen *pen; |
| 177 |
struct f_pattern *area_fill; |
| 178 |
#define UNFILLED (F_pattern *)0 |
| 179 |
#define BLACK_FILL (F_pattern *)1 |
| 180 |
#define DARK_GRAY_FILL (F_pattern *)2 |
| 181 |
#define MED_GRAY_FILL (F_pattern *)3 |
| 182 |
#define LIGHT_GRAY_FILL (F_pattern *)4 |
| 183 |
#define WHITE_FILL (F_pattern *)4 |
| 184 |
struct f_pos center; |
| 185 |
struct f_pos radiuses; |
| 186 |
struct f_pos start; |
| 187 |
struct f_pos end; |
| 188 |
struct f_ellipse *next; |
| 189 |
} |
| 190 |
F_ellipse; |
| 191 |
|
| 192 |
typedef struct f_arc { |
| 193 |
int type; |
| 194 |
#define T_3_POINTS_ARC 1 |
| 195 |
int style; |
| 196 |
int thickness; |
| 197 |
int color; |
| 198 |
int depth; |
| 199 |
struct f_pen *pen; |
| 200 |
struct f_pattern *area_fill; |
| 201 |
double style_val; |
| 202 |
int direction; |
| 203 |
struct f_arrow *for_arrow; |
| 204 |
struct f_arrow *back_arrow; |
| 205 |
struct {double x, y;} center; |
| 206 |
struct f_pos point[3]; |
| 207 |
struct f_arc *next; |
| 208 |
} |
| 209 |
F_arc; |
| 210 |
|
| 211 |
typedef struct f_line { |
| 212 |
int type; |
| 213 |
#define T_POLYLINE 1 |
| 214 |
#define T_BOX 2 |
| 215 |
#define T_POLYGON 3 |
| 216 |
int style; |
| 217 |
int thickness; |
| 218 |
int color; |
| 219 |
int depth; |
| 220 |
double style_val; |
| 221 |
struct f_pen *pen; |
| 222 |
struct f_pattern *area_fill; |
| 223 |
struct f_arrow *for_arrow; |
| 224 |
struct f_arrow *back_arrow; |
| 225 |
struct f_point *points; |
| 226 |
struct f_line *next; |
| 227 |
} |
| 228 |
F_line; |
| 229 |
|
| 230 |
typedef struct f_text { |
| 231 |
int type; |
| 232 |
#define T_LEFT_JUSTIFIED 0 |
| 233 |
#define T_CENTER_JUSTIFIED 1 |
| 234 |
#define T_RIGHT_JUSTIFIED 2 |
| 235 |
int font; |
| 236 |
#define DEFAULT_FONT 0 |
| 237 |
#define ROMAN_FONT 1 |
| 238 |
#define BOLD_FONT 2 |
| 239 |
#define ITALIC_FONT 3 |
| 240 |
#define MODERN_FONT 4 |
| 241 |
#define TYPEWRITER_FONT 5 |
| 242 |
int size; /* point size */ |
| 243 |
int color; |
| 244 |
int depth; |
| 245 |
double angle; /* in radian */ |
| 246 |
int style; |
| 247 |
#define PLAIN 1 |
| 248 |
#define ITALIC 2 |
| 249 |
#define BOLD 4 |
| 250 |
#define OUTLINE 8 |
| 251 |
#define SHADOW 16 |
| 252 |
int height; /* pixels */ |
| 253 |
int length; /* pixels */ |
| 254 |
int base_x; |
| 255 |
int base_y; |
| 256 |
struct f_pen *pen; |
| 257 |
char *cstring; |
| 258 |
struct f_text *next; |
| 259 |
} |
| 260 |
F_text; |
| 261 |
|
| 262 |
typedef struct f_control { |
| 263 |
double lx, ly, rx, ry; |
| 264 |
struct f_control *next; |
| 265 |
} |
| 266 |
F_control; |
| 267 |
|
| 268 |
#define int_spline(s) (s->type & 0x2) |
| 269 |
#define normal_spline(s) (!(s->type & 0x2)) |
| 270 |
#define closed_spline(s) (s->type & 0x1) |
| 271 |
#define open_spline(s) (!(s->type & 0x1)) |
| 272 |
|
| 273 |
typedef struct f_spline { |
| 274 |
int type; |
| 275 |
#define T_OPEN_NORMAL 0 |
| 276 |
#define T_CLOSED_NORMAL 1 |
| 277 |
#define T_OPEN_INTERPOLATED 2 |
| 278 |
#define T_CLOSED_INTERPOLATED 3 |
| 279 |
int style; |
| 280 |
int thickness; |
| 281 |
int color; |
| 282 |
int depth; |
| 283 |
double style_val; |
| 284 |
struct f_pen *pen; |
| 285 |
struct f_pattern *area_fill; |
| 286 |
struct f_arrow *for_arrow; |
| 287 |
struct f_arrow *back_arrow; |
| 288 |
/* |
| 289 |
For T_OPEN_NORMAL and T_CLOSED_NORMAL points |
| 290 |
are control points while they are knots for |
| 291 |
T_OPEN_INTERPOLATED and T_CLOSED_INTERPOLTED |
| 292 |
whose control points are stored in controls. |
| 293 |
*/ |
| 294 |
struct f_point *points; |
| 295 |
struct f_control *controls; |
| 296 |
struct f_spline *next; |
| 297 |
} |
| 298 |
F_spline; |
| 299 |
|
| 300 |
typedef struct f_compound { |
| 301 |
struct f_pos nwcorner; |
| 302 |
struct f_pos secorner; |
| 303 |
struct f_line *lines; |
| 304 |
struct f_ellipse *ellipses; |
| 305 |
struct f_spline *splines; |
| 306 |
struct f_text *texts; |
| 307 |
struct f_arc *arcs; |
| 308 |
struct f_compound *compounds; |
| 309 |
struct f_compound *next; |
| 310 |
} |
| 311 |
F_compound; |
| 312 |
|
| 313 |
#define ARROW_SIZE sizeof(struct f_arrow) |
| 314 |
#define POINT_SIZE sizeof(struct f_point) |
| 315 |
#define CONTROL_SIZE sizeof(struct f_control) |
| 316 |
#define ELLOBJ_SIZE sizeof(struct f_ellipse) |
| 317 |
#define ARCOBJ_SIZE sizeof(struct f_arc) |
| 318 |
#define LINOBJ_SIZE sizeof(struct f_line) |
| 319 |
#define TEXOBJ_SIZE sizeof(struct f_text) |
| 320 |
#define SPLOBJ_SIZE sizeof(struct f_spline) |
| 321 |
#define COMOBJ_SIZE sizeof(struct f_compound) |
| 322 |
|
| 323 |
/********************** object codes **********************/ |
| 324 |
|
| 325 |
#define O_ELLIPSE 1 |
| 326 |
#define O_POLYLINE 2 |
| 327 |
#define O_SPLINE 3 |
| 328 |
#define O_TEXT 4 |
| 329 |
#define O_ARC 5 |
| 330 |
#define O_COMPOUND 6 |
| 331 |
#define O_END_COMPOUND (-O_COMPOUND) |
| 332 |
#define O_ALL_OBJECT 99 |
| 333 |
|
| 334 |
/************ object styles (except for f_text) ************/ |
| 335 |
|
| 336 |
#define SOLID_LINE 0 |
| 337 |
#define DASH_LINE 1 |
| 338 |
#define DOTTED_LINE 2 |
| 339 |
|
| 340 |
#define CLOSED_PATH 0 |
| 341 |
#define OPEN_PATH 1 |
| 342 |
SHAR_EOF |
| 343 |
fi # end of overwriting check |
| 344 |
if test -f 'grafig.c' |
| 345 |
then |
| 346 |
echo shar: will not over-write existing file "'grafig.c'" |
| 347 |
else |
| 348 |
cat << \SHAR_EOF > 'grafig.c' |
| 349 |
/* |
| 350 |
* GraFig 0.0 - Generates Numerical Graphs in Fig Code |
| 351 |
* |
| 352 |
* Author: Micah Beck |
| 353 |
* (email: [email protected]) |
| 354 |
* Dept. of Computer Science |
| 355 |
* Cornell University |
| 356 |
* |
| 357 |
* Version 0.0: February 1, 1989 |
| 358 |
*/ |
| 359 |
#include <stdio.h> |
| 360 |
#include "object.h" |
| 361 |
|
| 362 |
#define FIG_MAGIC "#FIG 1.4" |
| 363 |
#define RES 80 |
| 364 |
#define COORD_SYS 2 |
| 365 |
|
| 366 |
#define MAX_DATA 1000 |
| 367 |
|
| 368 |
#define MARK_SIZE .05 |
| 369 |
#define TIC_SIZE .1 |
| 370 |
#define NUM_OFF_X .5 |
| 371 |
#define NUM_OFF_Y .25 |
| 372 |
|
| 373 |
#define orig_x 1.0 |
| 374 |
#define orig_y 9.0 |
| 375 |
#define length_x 5.0 |
| 376 |
#define length_y 5.0 |
| 377 |
|
| 378 |
extern double pow(), floor(), log10(); |
| 379 |
|
| 380 |
struct datapt {double x, y} dataset[MAX_DATA], *datasort[MAX_DATA]; |
| 381 |
|
| 382 |
main(argc,argv) |
| 383 |
int argc; |
| 384 |
char **argv; |
| 385 |
{ |
| 386 |
int i, c, data_size, datacmp(); |
| 387 |
double tic(); |
| 388 |
double max_x, max_y, min_x, min_y; |
| 389 |
double dx, dy; |
| 390 |
double tic_x, tic_y, w; |
| 391 |
|
| 392 |
/* read data */ |
| 393 |
for (data_size=0, c=2; data_size<MAX_DATA-1 && c == 2; data_size++) |
| 394 |
c = scanf("%lf %lf", &dataset[data_size].x, &dataset[data_size].y); |
| 395 |
|
| 396 |
if (c == EOF) |
| 397 |
--data_size; |
| 398 |
else |
| 399 |
if (c != 2) |
| 400 |
error("bad data format"); |
| 401 |
else |
| 402 |
error("data set truncated"); |
| 403 |
|
| 404 |
if (data_size == 0) error("no data!"); |
| 405 |
|
| 406 |
/* calculate maxima */ |
| 407 |
max_x = max_y = dataset[0].x; |
| 408 |
for (i=1; i<data_size; i++) { |
| 409 |
if (max_x < dataset[i].x) max_x = dataset[i].x; |
| 410 |
if (max_y < dataset[i].y) max_y = dataset[i].y; |
| 411 |
} |
| 412 |
|
| 413 |
/* calculate scaling factors */ |
| 414 |
dx = length_x / max_x; |
| 415 |
dy = length_y / max_y; |
| 416 |
|
| 417 |
/* print FIG header */ |
| 418 |
printf("%s\n", FIG_MAGIC); |
| 419 |
printf("%d %d\n", RES, COORD_SYS); |
| 420 |
|
| 421 |
/* draw axes */ |
| 422 |
fig_comment("Graph Axes"); |
| 423 |
fig_line(orig_x, orig_y, orig_x+length_x, orig_y); |
| 424 |
fig_line(orig_x, orig_y, orig_x, orig_y-length_y); |
| 425 |
|
| 426 |
/* plot data points */ |
| 427 |
fig_comment("Data Points"); |
| 428 |
for (i=0; i<data_size; i++) { |
| 429 |
|
| 430 |
dataset[i].x = orig_x + (dataset[i].x * dx); |
| 431 |
dataset[i].y = orig_y - (dataset[i].y * dy); |
| 432 |
|
| 433 |
fig_line(dataset[i].x-MARK_SIZE, dataset[i].y, |
| 434 |
dataset[i].x+MARK_SIZE, dataset[i].y); |
| 435 |
fig_line(dataset[i].x, dataset[i].y-MARK_SIZE, |
| 436 |
dataset[i].x, dataset[i].y+MARK_SIZE); |
| 437 |
} |
| 438 |
|
| 439 |
fig_comment("Data Curve"); |
| 440 |
qsort((char *)dataset, data_size, sizeof(struct datapt), datacmp); |
| 441 |
fig_plot(dataset, data_size); |
| 442 |
|
| 443 |
/* draw tic marks with numbering */ |
| 444 |
fig_comment("Axis Numbering"); |
| 445 |
tic_x = tic(max_x); |
| 446 |
tic_y = tic(max_y); |
| 447 |
|
| 448 |
for (i=1; (i*tic_x)<=max_x; i++) { |
| 449 |
w = orig_x + i*tic_x*dx; |
| 450 |
fig_line(w, orig_y, w, orig_y+TIC_SIZE); |
| 451 |
fig_number(w, orig_y+NUM_OFF_Y, i*tic_x); |
| 452 |
} |
| 453 |
for (i=1; (i*tic_y)<=max_y; i++) { |
| 454 |
w = orig_y - i*tic_y* dy; |
| 455 |
fig_line(orig_x, w, orig_x-TIC_SIZE, w); |
| 456 |
fig_number(orig_x-NUM_OFF_X, w, i*tic_y); |
| 457 |
} |
| 458 |
} |
| 459 |
|
| 460 |
error(s) |
| 461 |
char *s; |
| 462 |
{ |
| 463 |
fprintf(stderr, "grafig: %s\n", s); |
| 464 |
exit(1); |
| 465 |
} |
| 466 |
|
| 467 |
double tic(r) |
| 468 |
double r; |
| 469 |
{ |
| 470 |
double t; |
| 471 |
|
| 472 |
t = pow(10.0, floor(log10(r))); |
| 473 |
if (2*t>r) return t/10; |
| 474 |
else return t; |
| 475 |
} |
| 476 |
|
| 477 |
datacmp(a, b) |
| 478 |
struct datapt *a, *b; |
| 479 |
{ |
| 480 |
if (a->x < b->x) return -1; |
| 481 |
if (a->x > b->x) return 1; |
| 482 |
return 0; |
| 483 |
} |
| 484 |
|
| 485 |
/* |
| 486 |
* Fig Code Generating Routines |
| 487 |
*/ |
| 488 |
fig_comment(str) |
| 489 |
char *str; |
| 490 |
{ |
| 491 |
printf("#\n# %s\n#\n", str); |
| 492 |
} |
| 493 |
|
| 494 |
fig_line(ax, ay, bx, by) |
| 495 |
double ax, ay, bx, by; |
| 496 |
{ |
| 497 |
printf("%d %d %d %d %d %d %d %d %6.3f %d %d\n", |
| 498 |
O_POLYLINE, T_POLYLINE, |
| 499 |
SOLID_LINE, 1, DEFAULT, DEFAULT, DEFAULT, DEFAULT, 0.0, |
| 500 |
0, 0); |
| 501 |
printf("%.0f %.0f %.0f %.0f 9999 9999\n", |
| 502 |
ax*RES, ay*RES, bx*RES, by*RES); |
| 503 |
} |
| 504 |
|
| 505 |
fig_plot(dp, ds) |
| 506 |
struct datapt *dp; |
| 507 |
int ds; |
| 508 |
{ |
| 509 |
int i; |
| 510 |
|
| 511 |
printf("%d %d %d %d %d %d %d %d %6.3f %d %d\n", |
| 512 |
O_POLYLINE, T_POLYLINE, |
| 513 |
SOLID_LINE, 1, DEFAULT, DEFAULT, DEFAULT, DEFAULT, 0.0, |
| 514 |
0, 0); |
| 515 |
for (i=0; i<ds; i++) |
| 516 |
printf("%.0f %.0f ", dp[i].x*RES, dp[i].y*RES); |
| 517 |
|
| 518 |
printf("9999 9999\n"); |
| 519 |
} |
| 520 |
|
| 521 |
fig_number(x, y, num) |
| 522 |
double x, y, num; |
| 523 |
{ |
| 524 |
char buf[10]; |
| 525 |
|
| 526 |
sprintf(buf, "%6lg", num); |
| 527 |
printf("%d %d %d %d %d %d %d %6.3f %d %d %d %.0lf %.0lf %s\01\n", |
| 528 |
O_TEXT, T_LEFT_JUSTIFIED, |
| 529 |
DEFAULT, DEFAULT, DEFAULT, DEFAULT, DEFAULT, 0.0, DEFAULT, |
| 530 |
16, 8*strlen(buf), x*RES, y*RES, buf); |
| 531 |
} |
| 532 |
SHAR_EOF |
| 533 |
fi # end of overwriting check |
| 534 |
# End of shell archive |
| 535 |
exit 0 |