ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/meta/tgraph.c
(Generate patch)

Comparing ray/src/meta/tgraph.c (file contents):
Revision 1.1 by greg, Sat Feb 22 02:07:26 2003 UTC vs.
Revision 1.5 by schorsch, Sat Nov 15 02:13:37 2003 UTC

# Line 7 | Line 7 | static const char      RCSid[] = "$Id$";
7   *   1/20/85
8   */
9  
10 #include  "tgraph.h"
11
10   #include  <ctype.h>
11 + #include  <string.h>
12 + #include  <math.h>
13  
14 + #include  "tgraph.h"
15 + #include  "plot.h"
16  
17   #define  isfloat(a)  (isdigit(a) || (a) == '-' || (a) == '.' ||  \
18                       (a) == 'E' || (a) == '+' || (a) == 'e')
19  
20  
19 extern double  log10();
21  
22 <
23 <
23 <
24 <
25 < initialize()
26 <
22 > extern void
23 > initialize(void)
24   {
25   int  i;
26  
27   for (i = 0; i < NCUR; i++)
28      usecurve[i] = 1;
29 + }
30  
33 }
31  
32 <
33 <
34 <
35 <
39 <
40 < option(s)               /* record option */
41 <
42 < char  *s;
43 <
32 > extern void
33 > option(         /* record option */
34 >        char  *s
35 > )
36   {
37   double  atof();
38   char  *sp;
39   short  userror = 0;
40   int  i;
41  
42 < if (s[0] == '-')
42 > if (s[0] == '-') {
43  
44      switch(s[1])  {
45      
# Line 91 | Line 83 | char  *s;
83            userror = *sp;
84            break;
85         }
86 < else
86 > } else {
87  
88      switch (s[1])  {
89  
# Line 110 | Line 102 | char  *s;
102               usecurve[*sp-'@'] = 1;
103            userror = *sp;
104         }
105 +    }
106  
107   if (userror)
108      error(USER, "options are [-sSYMRAD][-g][-lx][-ly][-p{dr}][-xXMIN][+xXMAX][-yYMIN][+yYMAX][-C..|+C..]");
# Line 117 | Line 110 | char  *s;
110   }
111  
112  
113 <
114 <
115 < normalize(fp, fout)                     /* get extrema from file */
116 <
117 < FILE  *fp, *fout;
125 <
113 > extern void
114 > normalize(                      /* get extrema from file */
115 >        FILE  *fp,
116 >        FILE *fout
117 > )
118   {
119   char  line[255];
120   double  x, y;
# Line 168 | Line 160 | FILE  *fp, *fout;
160  
161  
162  
163 <
164 <
165 < makeaxis(flag)          /* make and print x and y axis */
166 <
175 < int  flag;
176 <
163 > extern void
164 > makeaxis(               /* make and print x and y axis */
165 >        int  flag
166 > )
167   {
168   double  xstep, ystep, step(), pos;
169   int  xorg, yorg;
170   char   *format, stemp[32];
171  
172                                          /* set limits */
173 < if (polar)
173 > if (polar) {
174      if (xmax-xmin < ymax-ymin)                  /* null aspect for polar */
175          xmax = xmin + ymax-ymin;
176      else
177          ymax = ymin + xmax-xmin;
178 < else {
179 <    if (xmnset > -FHUGE)
178 > } else {
179 >    if (xmnset > -FHUGE) {
180         if (logx) {
181            if (xmnset > FTINY)
182               xmin = log10(xmnset);
183 <          }
194 <       else
183 >          } else
184            xmin = xmnset;
185 <    if (xmxset < FHUGE)
185 >        }
186 >    if (xmxset < FHUGE) {
187         if (logx) {
188            if (xmxset > FTINY)
189               xmax = log10(xmxset);
190 <          }
201 <       else
190 >          } else
191            xmax = xmxset;
192 <    if (ymnset > -FHUGE)
192 >        }
193 >    if (ymnset > -FHUGE) {
194         if (logy) {
195            if (ymnset > FTINY)
196               ymin = log10(ymnset);
197 <          }
208 <       else
197 >          } else
198            ymin = ymnset;
199 <    if (ymxset < FHUGE)
199 >        }
200 >    if (ymxset < FHUGE) {
201         if (logy) {
202            if (ymxset > FTINY)
203               ymax = log10(ymxset);
204 <          }
215 <       else
204 >          } else
205            ymax = ymxset;
206 +        }
207      }
208                                          /* set step */
209   if (logx) {
# Line 233 | Line 223 | int  flag;
223   xsize = xmax - xmin;
224   ysize = ymax - ymin;
225  
226 < if (polar)                             /* null aspect again */
226 > if (polar) {                           /* null aspect again */
227       if (xsize < ysize)
228          xmax = xmin + (xsize = ysize);
229       else
230          ymax = ymin + (ysize = xsize);
231 + }
232  
233   if (xmin > 0.0)
234      xorg = XBEG;
# Line 259 | Line 250 | int  flag;
250   if (flag & ORIGIN)
251      plseg(010, XBEG, yorg, XBEG+XSIZ-1, yorg);
252  
262 #if  CPM || MAC
263 if (xstep > 1.0)
264    format = "%5.0f";
265 else
266    format = "%5.3f";
267 #else
253   format = "%5g";
269 #endif
254   if (logx)
255      format = "1e%-3.0f";
256  
257   for (pos = xmin; pos < xmax+xstep/2; pos += xstep) {
258 <    if (flag & XTICS)
258 >    if (flag & XTICS) {
259         if (polar)
260            plseg(010, XCONV(pos), yorg-TSIZ/2, XCONV(pos), yorg+TSIZ/2);
261         else {
262            plseg(010, XCONV(pos), YBEG, XCONV(pos), YBEG-TSIZ);
263            plseg(010, XCONV(pos), YBEG+YSIZ-1, XCONV(pos), YBEG+YSIZ-1+TSIZ);
264            }
265 +        }
266      if (flag & XNUMS) {
267         sprintf(stemp, format, pos);
268         if (polar)
# Line 298 | Line 283 | int  flag;
283   if (flag & ORIGIN)
284      plseg(010, xorg, YBEG, xorg, YBEG+YSIZ-1);
285  
301 #if  CPM || MAC
302 if (ystep > 1.0)
303    format = "%5.0f";
304 else
305    format = "%5.3f";
306 #else
286   format = "%5g";
308 #endif
287   if (logy)
288      format = "1e%-3.0f";
289  
290   for (pos = ymin; pos < ymax+ystep/2; pos += ystep) {
291 <    if (flag & YTICS)
291 >    if (flag & YTICS) {
292         if (polar)
293            plseg(010, xorg-TSIZ/2, YCONV(pos), xorg+TSIZ/2, YCONV(pos));
294         else {
295            plseg(010, XBEG, YCONV(pos), XBEG-TSIZ, YCONV(pos));
296            plseg(010, XBEG+XSIZ-1, YCONV(pos), XBEG+XSIZ-1+TSIZ, YCONV(pos));
297            }
298 +        }
299      if (flag & YNUMS) {
300         sprintf(stemp, format, pos);
301         if (polar)
# Line 333 | Line 312 | int  flag;
312   }
313  
314  
315 <
316 < isdata(s)
317 <
318 < register char  *s;
340 <
315 > extern int
316 > isdata(
317 >        register char  *s
318 > )
319   {
320   int  commas = 0;
321  
# Line 355 | Line 333 | register char  *s;
333   }
334  
335  
336 <
337 <
338 < islabel(s)
339 <
362 < char  s[];
363 <
336 > extern int
337 > islabel(
338 >        char  *s
339 > )
340   {
341   int  i;
342  
343   i = strlen(s) - 2;
344  
345   return(i > 0 && s[0] == '"' && s[i] == '"');
346 < }
346 > }
347  
348  
373
374
349   double
350 < step(mn, mx)                    /* compute step size for axis */
351 <
352 < double  *mn, *mx;
353 <
350 > step(                   /* compute step size for axis */
351 >        double  *mn,
352 >        double  *mx
353 > )
354   {
355      static int  steps[] = {100, 50, 20, 10, 5, 2, 1};
356      int         i;
# Line 403 | Line 377 | double *mn, *mx;
377  
378  
379   double
380 < pown(x, n)              /* raise x to an integer power */
381 <
382 < double  x;
383 < int     n;
410 <
380 > pown(           /* raise x to an integer power */
381 >        double  x,
382 >        int     n
383 > )
384   {
385      register int        i;
386      double              p = 1.0;
# Line 423 | Line 396 | int    n;
396   }
397  
398  
399 <
400 <
401 < istitle(s)
402 <
430 < char  *s;
431 <
399 > extern int
400 > istitle(
401 >        char  *s
402 > )
403   {
404   char  word[32];
405  
# Line 440 | Line 411 | char  *s;
411  
412  
413  
414 <
415 < isdivlab(s)                     /* return TRUE if division label(s) */
416 <
417 < register char  *s;
447 <
414 > extern int
415 > isdivlab(                       /* return TRUE if division label(s) */
416 >        register char  *s
417 > )
418   {
419  
420   return(instr(s, "division") != NULL);
# Line 452 | Line 422 | register char  *s;
422  
423  
424  
425 <
426 < isxlabel(s)
427 <
428 < register char  *s;
459 <
425 > extern int
426 > isxlabel(
427 >        register char  *s
428 > )
429   {
430   register char  *xindex = instr(s, "x ");
431  
# Line 464 | Line 433 | register char  *s;
433   }
434  
435  
436 <
437 <
438 < isylabel(s)
439 <
471 < register char  *s;
472 <
436 > extern int
437 > isylabel(
438 >        register char  *s
439 > )
440   {
441   register char  *yindex = instr(s, "y ");
442  
# Line 478 | Line 445 | register char  *s;
445  
446  
447  
448 < char *
449 < instr(s, t)             /* return pointer to first occurrence of t in s */
450 <
451 < char  *s,
452 <      *t;
486 <
448 > extern char *
449 > instr(          /* return pointer to first occurrence of t in s */
450 >        char  *s,
451 >        char  *t
452 > )
453   {
454   register char  *pt, *ps;
455  
# Line 505 | Line 471 | char  *s,
471  
472  
473  
474 <
475 < char *
476 < snagquo(s)              /* find and return quoted string within s */
477 <
512 < register char  *s;
513 <
474 > extern char *
475 > snagquo(                /* find and return quoted string within s */
476 >        register char  *s
477 > )
478   {
479      register char  *rval = NULL;
480  
481      for ( ; *s; s++)
482 <        if (*s == '"')
482 >        if (*s == '"') {
483              if (rval == NULL)
484                  rval = s+1;
485              else {
486                  *s = '\0';
487                  return(rval);
488              }
489 +        }
490      
491      return(NULL);
492   }
493  
494  
495  
496 <
497 < getdata(s, xp, yp)                      /* get data from line */
498 <
499 < char  *s;
500 < double  *xp, *yp;
501 <
496 > extern int
497 > getdata(                        /* get data from line */
498 >        char  *s,
499 >        double  *xp,
500 >        double  *yp
501 > )
502   {
538    char  *index();
503      double  sin(), cos();
504      int  oobounds = 0;
505      double  a;
506      register char  *cp;
507      
508 <    if ((cp = index(s, ',')) != NULL)
508 >    if ((cp = strchr(s, ',')) != NULL)
509          *cp = ' ';
510  
511      if (sscanf(s, "%lf %lf", xp, yp) != 2)
# Line 552 | Line 516 | double  *xp, *yp;
516      if (*yp < ymnset || *yp > ymxset)
517          oobounds++;
518  
519 <    if (logx)
519 >    if (logx) {
520          if (*xp < FTINY)
521              oobounds++;
522          else
523              *xp = log10(*xp);
524 +        }
525  
526 <    if (logy)
526 >    if (logy) {
527          if (*yp < FTINY)
528              oobounds++;
529          else
530              *yp = log10(*yp);
531 +        }
532  
533      if (polar) {
534          a = *xp;
# Line 577 | Line 543 | double  *xp, *yp;
543  
544  
545  
546 <
547 < symout(a0, x, y, sname)                 /* output a symbol */
548 <
549 < int  a0;
550 < int  x, y;
551 < char  *sname;
552 <
546 > extern void
547 > symout(                 /* output a symbol */
548 >        int  a0,
549 >        int  x,
550 >        int  y,
551 >        char  *sname
552 > )
553   {
554  
555      pprim(PSEG, a0, x-symrad, y-symrad, x+symrad, y+symrad, sname);
# Line 591 | Line 557 | char  *sname;
557   }
558  
559  
560 <
561 < boxstring(a0, xmn, ymn, xmx, ymx, s)    /* output a string within a box */
562 <
563 < int  a0;
564 < int  xmn, ymn, xmx, ymx;
565 < char  *s;
566 <
560 > extern void
561 > boxstring(      /* output a string within a box */
562 >        int a0,
563 >        int xmn,
564 >        int ymn,
565 >        int xmx,
566 >        int ymx,
567 >        char  *s
568 > )
569   {
570      int  start;
571      long  size;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines