9 double margin = MARGIN; /* extra space around edges */
10 extern double frame_ht, frame_wid, ticklen;
11 extern int just, sizeop, tick_dir;
12 extern double sizexpr, lab_up, lab_rt;
14 char graphname[50] = "Graph";
15 char graphpos[200] = "";
17 void print(void) /* arrange final output */
22 double dx, dy, xfac, yfac;
25 fclose(tfd); /* end the temp file */
29 if ((p=lookup("margin",0)) != NULL)
31 if (frame_ht < 0) /* wasn't set explicitly, so use default */
32 frame_ht = getvar(lookup("frameht", 0));
34 frame_wid = getvar(lookup("framewid", 0));
36 for (p = objlist; p; p = p->next) {
37 dprintf("print: name = <%s>, type = %d\n", p->name, p->type);
38 if (p->type == NAME) {
42 fprintf(tfd, "\t# %s %g .. %g, %g .. %g\n",
43 p->name, pt.x, pt1.x, pt.y, pt1.y);
46 ERROR "can't take log of x coord %g", pt.x FATAL;
52 ERROR "can't take log of y coord %g", pt.y FATAL;
56 if (!(p->coord & XFLAG)) {
61 if (!(p->coord & YFLAG)) {
66 if (autoticks && strcmp(p->name, dflt_coord) == 0) {
70 p->pt.x = pow(10.0, pt.x);
71 p->pt1.x = pow(10.0, pt1.x);
74 p->pt.y = pow(10.0, pt.y);
75 p->pt1.y = pow(10.0, pt1.y);
81 xfac = dx > 0 ? frame_wid/dx : frame_wid/2;
82 yfac = dy > 0 ? frame_ht/dy : frame_ht/2;
84 fprintf(tfd, "define xy_%s @ ", p->name);
86 fprintf(tfd, "\t(($1)-(%g))*%g", pt.x, xfac);
88 fprintf(tfd, "\t%g", xfac);
90 fprintf(tfd, ", (($2)-(%g))*%g @\n", pt.y, yfac);
92 fprintf(tfd, ", %g @\n", yfac);
93 fprintf(tfd, "define x_%s @ ", p->name);
95 fprintf(tfd, "\t(($1)-(%g))*%g @\n", pt.x, xfac);
97 fprintf(tfd, "\t%g @\n", xfac);
98 fprintf(tfd, "define y_%s @ ", p->name);
100 fprintf(tfd, "\t(($1)-(%g))*%g @\n", pt.y, yfac);
102 fprintf(tfd, "\t%g @\n", yfac);
107 if (codegen && autoticks && dfp)
110 if ((fd = fopen(tempfile, "r")) != NULL) {
111 while ((c = getc(fd)) != EOF)
118 void endstat(void) /* clean up after each statement */
122 lab_up = lab_rt = 0.0;
131 void graph(char *s) /* graph statement */
137 fprintf(stdout, "%s: [\n", graphname);
138 print(); /* pump out previous graph */
139 fprintf(stdout, "\n] %s\n", graphpos);
143 dprintf("into graph with <%s>\n", s);
146 while ((c = *s) == ' ' || c == '\t')
149 ERROR "no name on graph statement" WARNING;
151 ERROR "graph name %s must be capitalized", s WARNING;
152 for (p=graphname; (c = *s) != ' ' && c != '\t' && c != '\0'; )
156 dprintf("graphname = <%s>, graphpos = <%s>\n", graphname, graphpos);
161 void setup(void) /* done at each .G1 */
163 static int firstG1 = 0;
167 frame_ht = frame_wid = -1; /* reset in frame() */
168 ticklen = getvar(lookup("ticklen", 0));
171 codegen = synerr = 0;
172 strcpy(graphname, "Graph");
173 strcpy(graphpos, "");
176 void do_first(void) /* done at first .G1: definitions, etc. */
179 extern char *lib_defines;
180 static char buf[100], buf1[100]; /* static because pbstr uses them */
182 extern int getpid(void);
184 snprintf(buf, sizeof buf, "define pid /%d/\n", getpid());
187 if ((fp = fopen(lib_defines, "r")) != NULL) {
188 snprintf(buf1, sizeof buf, "copy \"%s\"\n", lib_defines);
192 fprintf(stderr, "grap warning: can't open %s\n", lib_defines);
197 void reset(void) /* done at each "graph ..." statement */
199 Obj *p, *np, *deflist;
200 extern int tlist, toffside, autodir;
202 curr_coord = dflt_coord;
204 autoticks = LEFT|BOT;
206 tside = tlist = toffside = 0;
210 for (p = objlist; p; p = np) {
212 if (p->type == DEFNAME || p->type == VARNAME) {
231 if ((tfd = fopen(tempfile, "w")) == NULL) {
232 fprintf(stderr, "grap: can't open %s\n", tempfile);