ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/util/rad.c
Revision: 2.42
Committed: Fri Dec 23 09:20:06 1994 UTC (29 years, 3 months ago) by greg
Content type: text/plain
Branch: MAIN
Changes since 2.41: +1 -1 lines
Log Message:
reduced -dj maximum to .65 (was .7)

File Contents

# Content
1 /* Copyright (c) 1994 Regents of the University of California */
2
3 #ifndef lint
4 static char SCCSid[] = "$SunId$ LBL";
5 #endif
6
7 /*
8 * Executive program for oconv, rpict and pfilt
9 */
10
11 #include "standard.h"
12 #include "paths.h"
13 #include <ctype.h>
14 #include <sys/types.h>
15
16
17 typedef struct {
18 char *name; /* variable name */
19 short nick; /* # characters required for nickname */
20 short nass; /* # assignments made */
21 char *value; /* assigned value(s) */
22 int (*fixval)(); /* assignment checking function */
23 } VARIABLE;
24
25 int onevalue(), catvalues(), boolvalue(),
26 qualvalue(), fltvalue(), intvalue();
27
28 /* variables */
29 #define OBJECT 0 /* object files */
30 #define SCENE 1 /* scene files */
31 #define MATERIAL 2 /* material files */
32 #define ILLUM 3 /* mkillum input files */
33 #define MKILLUM 4 /* mkillum options */
34 #define RENDER 5 /* rendering options */
35 #define OCONV 6 /* oconv options */
36 #define PFILT 7 /* pfilt options */
37 #define VIEW 8 /* view(s) for picture(s) */
38 #define ZONE 9 /* simulation zone */
39 #define QUALITY 10 /* desired rendering quality */
40 #define OCTREE 11 /* octree file name */
41 #define PICTURE 12 /* picture file name */
42 #define AMBFILE 13 /* ambient file name */
43 #define OPTFILE 14 /* rendering options file */
44 #define EXPOSURE 15 /* picture exposure setting */
45 #define RESOLUTION 16 /* maximum picture resolution */
46 #define UP 17 /* view up (X, Y or Z) */
47 #define INDIRECT 18 /* indirection in lighting */
48 #define DETAIL 19 /* level of scene detail */
49 #define PENUMBRAS 20 /* shadow penumbras are desired */
50 #define VARIABILITY 21 /* level of light variability */
51 #define REPORT 22 /* report frequency and errfile */
52 /* total number of variables */
53 #define NVARS 23
54
55 VARIABLE vv[NVARS] = { /* variable-value pairs */
56 {"objects", 3, 0, NULL, catvalues},
57 {"scene", 3, 0, NULL, catvalues},
58 {"materials", 3, 0, NULL, catvalues},
59 {"illum", 3, 0, NULL, catvalues},
60 {"mkillum", 3, 0, NULL, catvalues},
61 {"render", 3, 0, NULL, catvalues},
62 {"oconv", 3, 0, NULL, catvalues},
63 {"pfilt", 2, 0, NULL, catvalues},
64 {"view", 2, 0, NULL, NULL},
65 {"ZONE", 2, 0, NULL, onevalue},
66 {"QUALITY", 3, 0, NULL, qualvalue},
67 {"OCTREE", 3, 0, NULL, onevalue},
68 {"PICTURE", 3, 0, NULL, onevalue},
69 {"AMBFILE", 3, 0, NULL, onevalue},
70 {"OPTFILE", 3, 0, NULL, onevalue},
71 {"EXPOSURE", 3, 0, NULL, fltvalue},
72 {"RESOLUTION", 3, 0, NULL, onevalue},
73 {"UP", 2, 0, NULL, onevalue},
74 {"INDIRECT", 3, 0, NULL, intvalue},
75 {"DETAIL", 3, 0, NULL, qualvalue},
76 {"PENUMBRAS", 3, 0, NULL, boolvalue},
77 {"VARIABILITY", 3, 0, NULL, qualvalue},
78 {"REPORT", 3, 0, NULL, onevalue},
79 };
80
81 VARIABLE *matchvar();
82 char *nvalue();
83
84 #define UPPER(c) ((c)&~0x20) /* ASCII trick */
85
86 #define vnam(vc) (vv[vc].name)
87 #define vdef(vc) (vv[vc].nass)
88 #define vval(vc) (vv[vc].value)
89 #define vint(vc) atoi(vval(vc))
90 #define vlet(vc) UPPER(vval(vc)[0])
91 #define vscale vlet
92 #define vbool(vc) (vlet(vc)=='T')
93
94 #define HIGH 'H'
95 #define MEDIUM 'M'
96 #define LOW 'L'
97
98 /* overture calculation file */
99 #ifdef NIX
100 char overfile[] = "overture.raw";
101 #else
102 char overfile[] = "/dev/null";
103 #endif
104
105 extern time_t fdate(), time();
106
107 time_t scenedate; /* date of latest scene or object file */
108 time_t octreedate; /* date of octree */
109 time_t matdate; /* date of latest material file */
110 time_t illumdate; /* date of last illum file */
111
112 char *oct0name; /* name of pre-mkillum octree */
113 time_t oct0date; /* date of pre-mkillum octree */
114 char *oct1name; /* name of post-mkillum octree */
115 time_t oct1date; /* date of post-mkillum octree (>= matdate) */
116
117 int nowarn = 0; /* no warnings */
118 int explicate = 0; /* explicate variables */
119 int silent = 0; /* do work silently */
120 int touchonly = 0; /* touch files only */
121 int noaction = 0; /* don't do anything */
122 int sayview = 0; /* print view out */
123 char *rvdevice = NULL; /* rview output device */
124 char *viewselect = NULL; /* specific view only */
125
126 int overture = 0; /* overture calculation needed */
127
128 char *progname; /* global argv[0] */
129 char *rifname; /* global rad input file name */
130
131 char radname[MAXPATH]; /* root Radiance file name */
132
133
134 main(argc, argv)
135 int argc;
136 char *argv[];
137 {
138 char ropts[512];
139 char popts[64];
140 int i;
141
142 progname = argv[0];
143 /* get options */
144 for (i = 1; i < argc && argv[i][0] == '-'; i++)
145 switch (argv[i][1]) {
146 case 's':
147 silent++;
148 break;
149 case 'n':
150 noaction++;
151 break;
152 case 't':
153 touchonly++;
154 break;
155 case 'e':
156 explicate++;
157 break;
158 case 'o':
159 rvdevice = argv[++i];
160 break;
161 case 'V':
162 sayview++;
163 break;
164 case 'v':
165 viewselect = argv[++i];
166 break;
167 case 'w':
168 nowarn++;
169 break;
170 default:
171 goto userr;
172 }
173 if (i >= argc)
174 goto userr;
175 rifname = argv[i];
176 /* assign Radiance root file name */
177 rootname(radname, rifname);
178 /* load variable values */
179 load(rifname);
180 /* get any additional assignments */
181 for (i++; i < argc; i++)
182 setvariable(argv[i]);
183 /* check assignments */
184 checkvalues();
185 /* check files and dates */
186 checkfiles();
187 /* set default values as necessary */
188 setdefaults();
189 /* print all values if requested */
190 if (explicate)
191 printvals();
192 /* build octree (and run mkillum) */
193 oconv();
194 /* check date on ambient file */
195 checkambfile();
196 /* run simulation */
197 renderopts(ropts, popts);
198 xferopts(ropts);
199 if (rvdevice != NULL)
200 rview(ropts, popts);
201 else
202 rpict(ropts, popts);
203 exit(0);
204 userr:
205 fprintf(stderr,
206 "Usage: %s [-s][-n][-t][-e][-V][-v view][-o dev] rfile [VAR=value ..]\n",
207 progname);
208 exit(1);
209 }
210
211
212 rootname(rn, fn) /* remove tail from end of fn */
213 register char *rn, *fn;
214 {
215 char *tp, *dp;
216
217 for (tp = NULL, dp = rn; *rn = *fn++; rn++)
218 if (ISDIRSEP(*rn))
219 dp = rn;
220 else if (*rn == '.')
221 tp = rn;
222 if (tp != NULL && tp > dp)
223 *tp = '\0';
224 }
225
226
227 #define NOCHAR 127 /* constant for character to delete */
228
229
230 load(rfname) /* load Radiance simulation file */
231 char *rfname;
232 {
233 FILE *fp;
234 char buf[512];
235 register char *cp;
236
237 if (rfname == NULL)
238 fp = stdin;
239 else if ((fp = fopen(rfname, "r")) == NULL)
240 syserr(rfname);
241 while (fgetline(buf, sizeof(buf), fp) != NULL) {
242 for (cp = buf; *cp; cp++) {
243 switch (*cp) {
244 case '\\':
245 *cp++ = NOCHAR;
246 continue;
247 case '#':
248 *cp = '\0';
249 break;
250 default:
251 continue;
252 }
253 break;
254 }
255 setvariable(buf);
256 }
257 fclose(fp);
258 }
259
260
261 setvariable(ass) /* assign variable according to string */
262 register char *ass;
263 {
264 char varname[32];
265 int n;
266 register char *cp;
267 register VARIABLE *vp;
268 register int i;
269
270 while (isspace(*ass)) /* skip leading space */
271 ass++;
272 cp = varname; /* extract name */
273 while (cp < varname+sizeof(varname)-1
274 && *ass && !isspace(*ass) && *ass != '=')
275 *cp++ = *ass++;
276 *cp = '\0';
277 if (!varname[0])
278 return; /* no variable name! */
279 /* trim value */
280 while (isspace(*ass) || *ass == '=')
281 ass++;
282 for (n = strlen(ass); n > 0; n--)
283 if (!isspace(ass[n-1]))
284 break;
285 if (!n && !nowarn) {
286 fprintf(stderr, "%s: warning - missing value for variable '%s'\n",
287 progname, varname);
288 return;
289 }
290 /* match variable from list */
291 vp = matchvar(varname);
292 if (vp == NULL) {
293 fprintf(stderr, "%s: unknown variable '%s'\n",
294 progname, varname);
295 exit(1);
296 }
297 /* assign new value */
298 if (i = vp->nass) {
299 cp = vp->value;
300 while (i--)
301 while (*cp++)
302 ;
303 i = cp - vp->value;
304 vp->value = realloc(vp->value, i+n+1);
305 } else
306 vp->value = malloc(n+1);
307 if (vp->value == NULL)
308 syserr(progname);
309 cp = vp->value+i; /* copy value, squeezing spaces */
310 *cp = *ass;
311 for (i = 1; i <= n; i++) {
312 if (ass[i] == NOCHAR)
313 continue;
314 if (isspace(*cp))
315 while (isspace(ass[i]))
316 i++;
317 *++cp = ass[i];
318 }
319 if (isspace(*cp)) /* remove trailing space */
320 *cp = '\0';
321 vp->nass++;
322 }
323
324
325 VARIABLE *
326 matchvar(nam) /* match a variable by its name */
327 char *nam;
328 {
329 int n = strlen(nam);
330 register int i;
331
332 for (i = 0; i < NVARS; i++)
333 if (n >= vv[i].nick && !strncmp(nam, vv[i].name, n))
334 return(vv+i);
335 return(NULL);
336 }
337
338
339 char *
340 nvalue(vp, n) /* return nth variable value */
341 VARIABLE *vp;
342 register int n;
343 {
344 register char *cp;
345
346 if (vp == NULL | n < 0 | n >= vp->nass)
347 return(NULL);
348 cp = vp->value;
349 while (n--)
350 while (*cp++)
351 ;
352 return(cp);
353 }
354
355
356 checkvalues() /* check assignments */
357 {
358 register int i;
359
360 for (i = 0; i < NVARS; i++)
361 if (vv[i].fixval != NULL)
362 (*vv[i].fixval)(vv+i);
363 }
364
365
366 onevalue(vp) /* only one assignment for this variable */
367 register VARIABLE *vp;
368 {
369 if (vp->nass < 2)
370 return;
371 if (!nowarn)
372 fprintf(stderr,
373 "%s: warning - multiple assignment of variable '%s'\n",
374 progname, vp->name);
375 do
376 vp->value += strlen(vp->value)+1;
377 while (--vp->nass > 1);
378 }
379
380
381 catvalues(vp) /* concatenate variable values */
382 register VARIABLE *vp;
383 {
384 register char *cp;
385
386 if (vp->nass < 2)
387 return;
388 for (cp = vp->value; vp->nass > 1; vp->nass--) {
389 while (*cp)
390 cp++;
391 *cp++ = ' ';
392 }
393 }
394
395
396 int
397 badmatch(tv, cv) /* case insensitive truncated comparison */
398 register char *tv, *cv;
399 {
400 if (!*tv) return(1); /* null string cannot match */
401 do
402 if (UPPER(*tv) != *cv++)
403 return(1);
404 while (*++tv);
405 return(0); /* OK */
406 }
407
408
409 boolvalue(vp) /* check boolean for legal values */
410 register VARIABLE *vp;
411 {
412 if (!vp->nass) return;
413 onevalue(vp);
414 switch (UPPER(vp->value[0])) {
415 case 'T':
416 if (badmatch(vp->value, "TRUE")) break;
417 return;
418 case 'F':
419 if (badmatch(vp->value, "FALSE")) break;
420 return;
421 }
422 fprintf(stderr, "%s: illegal value for boolean variable '%s'\n",
423 progname, vp->name);
424 exit(1);
425 }
426
427
428 qualvalue(vp) /* check qualitative var. for legal values */
429 register VARIABLE *vp;
430 {
431 if (!vp->nass) return;
432 onevalue(vp);
433 switch (UPPER(vp->value[0])) {
434 case 'L':
435 if (badmatch(vp->value, "LOW")) break;
436 return;
437 case 'M':
438 if (badmatch(vp->value, "MEDIUM")) break;
439 return;
440 case 'H':
441 if (badmatch(vp->value, "HIGH")) break;
442 return;
443 }
444 fprintf(stderr, "%s: illegal value for qualitative variable '%s'\n",
445 progname, vp->name);
446 exit(1);
447 }
448
449
450 intvalue(vp) /* check integer variable for legal values */
451 register VARIABLE *vp;
452 {
453 if (!vp->nass) return;
454 onevalue(vp);
455 if (isint(vp->value)) return;
456 fprintf(stderr, "%s: illegal value for integer variable '%s'\n",
457 progname, vp->name);
458 exit(1);
459 }
460
461
462 fltvalue(vp) /* check float variable for legal values */
463 register VARIABLE *vp;
464 {
465 if (!vp->nass) return;
466 onevalue(vp);
467 if (isflt(vp->value)) return;
468 fprintf(stderr, "%s: illegal value for real variable '%s'\n",
469 progname, vp->name);
470 exit(1);
471 }
472
473
474 time_t
475 checklast(fnames) /* check files and find most recent */
476 register char *fnames;
477 {
478 char thisfile[MAXPATH];
479 time_t thisdate, lastdate = 0;
480 register char *cp;
481
482 if (fnames == NULL)
483 return(0);
484 while (*fnames) {
485 while (isspace(*fnames)) fnames++;
486 cp = thisfile;
487 while (*fnames && !isspace(*fnames))
488 *cp++ = *fnames++;
489 *cp = '\0';
490 if (!(thisdate = fdate(thisfile)))
491 syserr(thisfile);
492 if (thisdate > lastdate)
493 lastdate = thisdate;
494 }
495 return(lastdate);
496 }
497
498
499 char *
500 newfname(orig, pred) /* create modified file name */
501 char *orig;
502 int pred;
503 {
504 extern char *rindex();
505 register char *cp;
506 register int n;
507 int suffix;
508
509 n = 0; cp = orig; suffix = -1; /* suffix position, length */
510 while (*cp) {
511 if (*cp == '.') suffix = n;
512 else if (ISDIRSEP(*cp)) suffix = -1;
513 cp++; n++;
514 }
515 if (suffix == -1) suffix = n;
516 if ((cp = bmalloc(n+2)) == NULL)
517 syserr(progname);
518 strncpy(cp, orig, suffix);
519 cp[suffix] = pred; /* root name + pred + suffix */
520 strcpy(cp+suffix+1, orig+suffix);
521 return(cp);
522 }
523
524
525 checkfiles() /* check for existence and modified times */
526 {
527 time_t objdate;
528
529 if (!vdef(OCTREE)) {
530 if ((vval(OCTREE) = bmalloc(strlen(radname)+5)) == NULL)
531 syserr(progname);
532 sprintf(vval(OCTREE), "%s.oct", radname);
533 vdef(OCTREE)++;
534 }
535 octreedate = fdate(vval(OCTREE));
536 if (vdef(ILLUM)) { /* illum requires secondary octrees */
537 oct0name = newfname(vval(OCTREE), '0');
538 oct1name = newfname(vval(OCTREE), '1');
539 oct0date = fdate(oct0name);
540 oct1date = fdate(oct1name);
541 } else
542 oct0name = oct1name = vval(OCTREE);
543 if ((scenedate = checklast(vval(SCENE))) &&
544 (objdate = checklast(vval(OBJECT))) > scenedate)
545 scenedate = objdate;
546 illumdate = checklast(vval(ILLUM));
547 if (!octreedate & !scenedate & !illumdate) {
548 fprintf(stderr, "%s: need '%s' or '%s' or '%s'\n", progname,
549 vnam(OCTREE), vnam(SCENE), vnam(ILLUM));
550 exit(1);
551 }
552 matdate = checklast(vval(MATERIAL));
553 }
554
555
556 getoctcube(org, sizp) /* get octree bounding cube */
557 double org[3], *sizp;
558 {
559 extern FILE *popen();
560 static double oorg[3], osiz = 0.;
561 double min[3], max[3];
562 char buf[512];
563 FILE *fp;
564 register int i;
565
566 if (osiz <= FTINY)
567 if (noaction && fdate(oct1name) <
568 (scenedate>illumdate?scenedate:illumdate)) {
569 /* run getbbox */
570 sprintf(buf, "getbbox -w -h %s",
571 vdef(SCENE) ? vval(SCENE) : vval(ILLUM));
572 if ((fp = popen(buf, "r")) == NULL)
573 syserr("getbbox");
574 if (fscanf(fp, "%lf %lf %lf %lf %lf %lf",
575 &min[0], &max[0], &min[1], &max[1],
576 &min[2], &max[2]) != 6) {
577 fprintf(stderr,
578 "%s: error reading bounding box from getbbox\n",
579 progname);
580 exit(1);
581 }
582 for (i = 0; i < 3; i++)
583 if (max[i] - min[i] > osiz)
584 osiz = max[i] - min[i];
585 for (i = 0; i < 3; i++)
586 oorg[i] = (max[i]+min[i]-osiz)*.5;
587 pclose(fp);
588 } else { /* from octree */
589 oconv(); /* does nothing if done already */
590 sprintf(buf, "getinfo -d < %s", oct1name);
591 if ((fp = popen(buf, "r")) == NULL)
592 syserr("getinfo");
593 if (fscanf(fp, "%lf %lf %lf %lf", &oorg[0], &oorg[1],
594 &oorg[2], &osiz) != 4) {
595 fprintf(stderr,
596 "%s: error reading bounding cube from getinfo\n",
597 progname);
598 exit(1);
599 }
600 pclose(fp);
601 }
602 org[0] = oorg[0]; org[1] = oorg[1]; org[2] = oorg[2]; *sizp = osiz;
603 }
604
605
606 setdefaults() /* set default values for unassigned var's */
607 {
608 double org[3], size;
609 char buf[128];
610
611 if (!vdef(ZONE)) {
612 getoctcube(org, &size);
613 sprintf(buf, "E %g %g %g %g %g %g", org[0], org[0]+size,
614 org[1], org[1]+size, org[2], org[2]+size);
615 vval(ZONE) = savqstr(buf);
616 vdef(ZONE)++;
617 }
618 if (!vdef(INDIRECT)) {
619 vval(INDIRECT) = "0";
620 vdef(INDIRECT)++;
621 }
622 if (!vdef(QUALITY)) {
623 vval(QUALITY) = "L";
624 vdef(QUALITY)++;
625 }
626 if (!vdef(RESOLUTION)) {
627 vval(RESOLUTION) = "512";
628 vdef(RESOLUTION)++;
629 }
630 if (!vdef(PICTURE)) {
631 vval(PICTURE) = radname;
632 vdef(PICTURE)++;
633 }
634 if (!vdef(VIEW)) {
635 vval(VIEW) = "X";
636 vdef(VIEW)++;
637 }
638 if (!vdef(DETAIL)) {
639 vval(DETAIL) = "M";
640 vdef(DETAIL)++;
641 }
642 if (!vdef(PENUMBRAS)) {
643 vval(PENUMBRAS) = "F";
644 vdef(PENUMBRAS)++;
645 }
646 if (!vdef(VARIABILITY)) {
647 vval(VARIABILITY) = "L";
648 vdef(VARIABILITY)++;
649 }
650 }
651
652
653 printvals() /* print variable values */
654 {
655 int i, j, clipline;
656 register char *cp;
657 register int k;
658
659 for (i = 0; i < NVARS; i++) /* print each variable */
660 for (j = 0; j < vdef(i); j++) { /* print each assignment */
661 fputs(vnam(i), stdout);
662 fputs("= ", stdout);
663 k = clipline = ( vv[i].fixval == catvalues ? 64 : 320 )
664 - strlen(vnam(i)) ;
665 cp = nvalue(vv+i, j);
666 while (*cp) {
667 putchar(*cp++);
668 if (--k <= 0) { /* line too long */
669 while (*cp && !isspace(*cp))
670 putchar(*cp++); /* finish this word */
671 if (*cp) { /* start new line */
672 putchar('\n');
673 fputs(vnam(i), stdout);
674 putchar('=');
675 k = clipline;
676 }
677 }
678 }
679 putchar('\n');
680 }
681 fflush(stdout);
682 }
683
684
685 oconv() /* run oconv and mkillum if necessary */
686 {
687 static char illumtmp[] = "ilXXXXXX";
688 char combuf[512], ocopts[64], mkopts[64];
689
690 oconvopts(ocopts); /* get options */
691 if (octreedate < scenedate) { /* check date on original octree */
692 if (touchonly && octreedate)
693 touch(vval(OCTREE));
694 else { /* build command */
695 if (vdef(MATERIAL))
696 sprintf(combuf, "oconv%s %s %s > %s", ocopts,
697 vval(MATERIAL), vval(SCENE),
698 vval(OCTREE));
699 else
700 sprintf(combuf, "oconv%s %s > %s", ocopts,
701 vval(SCENE), vval(OCTREE));
702
703 if (runcom(combuf)) { /* run it */
704 fprintf(stderr,
705 "%s: error generating octree\n\t%s removed\n",
706 progname, vval(OCTREE));
707 unlink(vval(OCTREE));
708 exit(1);
709 }
710 }
711 octreedate = time((time_t *)NULL);
712 if (octreedate < scenedate) /* in case clock is off */
713 octreedate = scenedate;
714 }
715 if (oct1name == vval(OCTREE)) /* no mkillum? */
716 oct1date = octreedate > matdate ? octreedate : matdate;
717 if (oct1date >= octreedate & oct1date >= matdate
718 & oct1date >= illumdate) /* all done */
719 return;
720 /* make octree0 */
721 if (oct0date < scenedate | oct0date < illumdate) {
722 if (touchonly && oct0date)
723 touch(oct0name);
724 else { /* build command */
725 if (octreedate)
726 sprintf(combuf, "oconv%s -i %s %s > %s", ocopts,
727 vval(OCTREE), vval(ILLUM), oct0name);
728 else if (vdef(MATERIAL))
729 sprintf(combuf, "oconv%s %s %s > %s", ocopts,
730 vval(MATERIAL), vval(ILLUM), oct0name);
731 else
732 sprintf(combuf, "oconv%s %s > %s", ocopts,
733 vval(ILLUM), oct0name);
734 if (runcom(combuf)) { /* run it */
735 fprintf(stderr,
736 "%s: error generating octree\n\t%s removed\n",
737 progname, oct0name);
738 unlink(oct0name);
739 exit(1);
740 }
741 }
742 oct0date = time((time_t *)NULL);
743 if (oct0date < octreedate) /* in case clock is off */
744 oct0date = octreedate;
745 if (oct0date < illumdate) /* ditto */
746 oct0date = illumdate;
747 }
748 if (touchonly && oct1date)
749 touch(oct1name);
750 else {
751 mkillumopts(mkopts); /* build mkillum command */
752 mktemp(illumtmp);
753 sprintf(combuf, "mkillum%s %s \"<\" %s > %s", mkopts,
754 oct0name, vval(ILLUM), illumtmp);
755 if (runcom(combuf)) { /* run it */
756 fprintf(stderr, "%s: error running mkillum\n",
757 progname);
758 unlink(illumtmp);
759 exit(1);
760 }
761 /* make octree1 (frozen) */
762 if (octreedate)
763 sprintf(combuf, "oconv%s -f -i %s %s > %s", ocopts,
764 vval(OCTREE), illumtmp, oct1name);
765 else if (vdef(MATERIAL))
766 sprintf(combuf, "oconv%s -f %s %s > %s", ocopts,
767 vval(MATERIAL), illumtmp, oct1name);
768 else
769 sprintf(combuf, "oconv%s -f %s > %s", ocopts,
770 illumtmp, oct1name);
771 if (runcom(combuf)) { /* run it */
772 fprintf(stderr,
773 "%s: error generating octree\n\t%s removed\n",
774 progname, oct1name);
775 unlink(oct1name);
776 exit(1);
777 }
778 rmfile(illumtmp);
779 }
780 oct1date = time((time_t *)NULL);
781 if (oct1date < oct0date) /* in case clock is off */
782 oct1date = oct0date;
783 }
784
785
786 char *
787 addarg(op, arg) /* add argument and advance pointer */
788 register char *op, *arg;
789 {
790 *op = ' ';
791 while (*++op = *arg++)
792 ;
793 return(op);
794 }
795
796
797 oconvopts(oo) /* get oconv options */
798 register char *oo;
799 {
800 /* BEWARE: This may be called via setdefaults(), so no assumptions */
801
802 *oo = '\0';
803 if (vdef(OCONV))
804 addarg(oo, vval(OCONV));
805 }
806
807
808 mkillumopts(mo) /* get mkillum options */
809 register char *mo;
810 {
811 /* BEWARE: This may be called via setdefaults(), so no assumptions */
812
813 *mo = '\0';
814 if (vdef(MKILLUM))
815 addarg(mo, vval(MKILLUM));
816 }
817
818
819 checkambfile() /* check date on ambient file */
820 {
821 time_t afdate;
822
823 if (!vdef(AMBFILE))
824 return;
825 if (!(afdate = fdate(vval(AMBFILE))))
826 return;
827 if (oct1date > afdate)
828 if (touchonly)
829 touch(vval(AMBFILE));
830 else
831 rmfile(vval(AMBFILE));
832 }
833
834
835 double
836 ambval() /* compute ambient value */
837 {
838 if (vdef(EXPOSURE)) {
839 if (vval(EXPOSURE)[0] == '+' || vval(EXPOSURE)[0] == '-')
840 return(.5/pow(2.,atof(vval(EXPOSURE))));
841 return(.5/atof(vval(EXPOSURE)));
842 }
843 if (vlet(ZONE) == 'E')
844 return(10.);
845 if (vlet(ZONE) == 'I')
846 return(.01);
847 badvalue(ZONE);
848 }
849
850
851 renderopts(op, po) /* set rendering options */
852 char *op, *po;
853 {
854 switch(vscale(QUALITY)) {
855 case LOW:
856 lowqopts(op, po);
857 break;
858 case MEDIUM:
859 medqopts(op, po);
860 break;
861 case HIGH:
862 hiqopts(op, po);
863 break;
864 }
865 }
866
867
868 lowqopts(op, po) /* low quality rendering options */
869 register char *op;
870 char *po;
871 {
872 double d, org[3], siz[3];
873
874 *op = '\0';
875 *po = '\0';
876 if (sscanf(vval(ZONE), "%*s %lf %lf %lf %lf %lf %lf", &org[0],
877 &siz[0], &org[1], &siz[1], &org[2], &siz[2]) != 6)
878 badvalue(ZONE);
879 siz[0] -= org[0]; siz[1] -= org[1]; siz[2] -= org[2];
880 if (siz[0] <= FTINY | siz[1] <= FTINY | siz[2] <= FTINY)
881 badvalue(ZONE);
882 getoctcube(org, &d);
883 d *= 3./(siz[0]+siz[1]+siz[2]);
884 switch (vscale(DETAIL)) {
885 case LOW:
886 po = addarg(po, "-ps 16");
887 op = addarg(op, "-dp 64");
888 sprintf(op, " -ar %d", (int)(4*d));
889 op += strlen(op);
890 break;
891 case MEDIUM:
892 po = addarg(po, "-ps 8");
893 op = addarg(op, "-dp 128");
894 sprintf(op, " -ar %d", (int)(8*d));
895 op += strlen(op);
896 break;
897 case HIGH:
898 po = addarg(po, "-ps 4");
899 op = addarg(op, "-dp 256");
900 sprintf(op, " -ar %d", (int)(16*d));
901 op += strlen(op);
902 break;
903 }
904 po = addarg(po, "-pt .16");
905 if (vbool(PENUMBRAS))
906 op = addarg(op, "-ds .4");
907 else
908 op = addarg(op, "-ds 0");
909 op = addarg(op, "-dt .2 -dc .25 -dr 0 -sj 0 -st .5");
910 if (vdef(AMBFILE)) {
911 sprintf(op, " -af %s", vval(AMBFILE));
912 op += strlen(op);
913 } else
914 overture = 0;
915 switch (vscale(VARIABILITY)) {
916 case LOW:
917 op = addarg(op, "-aa .4 -ad 64");
918 break;
919 case MEDIUM:
920 op = addarg(op, "-aa .3 -ad 128");
921 break;
922 case HIGH:
923 op = addarg(op, "-aa .25 -ad 256");
924 break;
925 }
926 op = addarg(op, "-as 0");
927 d = ambval();
928 sprintf(op, " -av %.2g %.2g %.2g", d, d, d);
929 op += strlen(op);
930 op = addarg(op, "-lr 3 -lw .02");
931 if (vdef(RENDER))
932 op = addarg(op, vval(RENDER));
933 }
934
935
936 medqopts(op, po) /* medium quality rendering options */
937 register char *op;
938 char *po;
939 {
940 double d, org[3], siz[3];
941
942 *op = '\0';
943 *po = '\0';
944 if (sscanf(vval(ZONE), "%*s %lf %lf %lf %lf %lf %lf", &org[0],
945 &siz[0], &org[1], &siz[1], &org[2], &siz[2]) != 6)
946 badvalue(ZONE);
947 siz[0] -= org[0]; siz[1] -= org[1]; siz[2] -= org[2];
948 if (siz[0] <= FTINY | siz[1] <= FTINY | siz[2] <= FTINY)
949 badvalue(ZONE);
950 getoctcube(org, &d);
951 d *= 3./(siz[0]+siz[1]+siz[2]);
952 switch (vscale(DETAIL)) {
953 case LOW:
954 po = addarg(po, vbool(PENUMBRAS) ? "-ps 4" : "-ps 8");
955 op = addarg(op, "-dp 256");
956 sprintf(op, " -ar %d", (int)(8*d));
957 op += strlen(op);
958 break;
959 case MEDIUM:
960 po = addarg(po, vbool(PENUMBRAS) ? "-ps 3" : "-ps 6");
961 op = addarg(op, "-dp 512");
962 sprintf(op, " -ar %d", (int)(16*d));
963 op += strlen(op);
964 break;
965 case HIGH:
966 po = addarg(po, vbool(PENUMBRAS) ? "-ps 2" : "-ps 4");
967 op = addarg(op, "-dp 1024");
968 sprintf(op, " -ar %d", (int)(32*d));
969 op += strlen(op);
970 break;
971 }
972 po = addarg(po, "-pt .08");
973 if (vbool(PENUMBRAS))
974 op = addarg(op, "-ds .2 -dj .5");
975 else
976 op = addarg(op, "-ds .3");
977 op = addarg(op, "-dt .1 -dc .5 -dr 1 -sj .7 -st .1");
978 if (overture = vint(INDIRECT)) {
979 sprintf(op, " -ab %d", overture);
980 op += strlen(op);
981 }
982 if (vdef(AMBFILE)) {
983 sprintf(op, " -af %s", vval(AMBFILE));
984 op += strlen(op);
985 } else
986 overture = 0;
987 switch (vscale(VARIABILITY)) {
988 case LOW:
989 op = addarg(op, "-aa .25 -ad 196 -as 0");
990 break;
991 case MEDIUM:
992 op = addarg(op, "-aa .2 -ad 400 -as 64");
993 break;
994 case HIGH:
995 op = addarg(op, "-aa .15 -ad 768 -as 196");
996 break;
997 }
998 d = ambval();
999 sprintf(op, " -av %.2g %.2g %.2g", d, d, d);
1000 op += strlen(op);
1001 op = addarg(op, "-lr 6 -lw .002");
1002 if (vdef(RENDER))
1003 op = addarg(op, vval(RENDER));
1004 }
1005
1006
1007 hiqopts(op, po) /* high quality rendering options */
1008 register char *op;
1009 char *po;
1010 {
1011 double d, org[3], siz[3];
1012
1013 *op = '\0';
1014 *po = '\0';
1015 if (sscanf(vval(ZONE), "%*s %lf %lf %lf %lf %lf %lf", &org[0],
1016 &siz[0], &org[1], &siz[1], &org[2], &siz[2]) != 6)
1017 badvalue(ZONE);
1018 siz[0] -= org[0]; siz[1] -= org[1]; siz[2] -= org[2];
1019 if (siz[0] <= FTINY | siz[1] <= FTINY | siz[2] <= FTINY)
1020 badvalue(ZONE);
1021 getoctcube(org, &d);
1022 d *= 3./(siz[0]+siz[1]+siz[2]);
1023 switch (vscale(DETAIL)) {
1024 case LOW:
1025 po = addarg(po, vbool(PENUMBRAS) ? "-ps 1" : "-ps 8");
1026 op = addarg(op, "-dp 1024");
1027 sprintf(op, " -ar %d", (int)(16*d));
1028 op += strlen(op);
1029 break;
1030 case MEDIUM:
1031 po = addarg(po, vbool(PENUMBRAS) ? "-ps 1" : "-ps 5");
1032 op = addarg(op, "-dp 2048");
1033 sprintf(op, " -ar %d", (int)(32*d));
1034 op += strlen(op);
1035 break;
1036 case HIGH:
1037 po = addarg(po, vbool(PENUMBRAS) ? "-ps 1" : "-ps 3");
1038 op = addarg(op, "-dp 4096");
1039 sprintf(op, " -ar %d", (int)(64*d));
1040 op += strlen(op);
1041 break;
1042 }
1043 po = addarg(po, "-pt .04");
1044 if (vbool(PENUMBRAS))
1045 op = addarg(op, "-ds .1 -dj .65");
1046 else
1047 op = addarg(op, "-ds .2");
1048 op = addarg(op, "-dt .05 -dc .75 -dr 3 -sj 1 -st .01");
1049 sprintf(op, " -ab %d", overture=vint(INDIRECT)+1);
1050 op += strlen(op);
1051 if (vdef(AMBFILE)) {
1052 sprintf(op, " -af %s", vval(AMBFILE));
1053 op += strlen(op);
1054 } else
1055 overture = 0;
1056 switch (vscale(VARIABILITY)) {
1057 case LOW:
1058 op = addarg(op, "-aa .15 -ad 256 -as 0");
1059 break;
1060 case MEDIUM:
1061 op = addarg(op, "-aa .125 -ad 512 -as 256");
1062 break;
1063 case HIGH:
1064 op = addarg(op, "-aa .08 -ad 1024 -as 512");
1065 break;
1066 }
1067 d = ambval();
1068 sprintf(op, " -av %.2g %.2g %.2g", d, d, d);
1069 op += strlen(op);
1070 op = addarg(op, "-lr 12 -lw .0005");
1071 if (vdef(RENDER))
1072 op = addarg(op, vval(RENDER));
1073 }
1074
1075
1076 xferopts(ro) /* transfer options if indicated */
1077 char *ro;
1078 {
1079 int fd, n;
1080 register char *cp;
1081
1082 n = strlen(ro);
1083 if (n < 2)
1084 return;
1085 if (vdef(OPTFILE)) {
1086 for (cp = ro; cp[1]; cp++)
1087 if (isspace(cp[1]) && cp[2] == '-' && isalpha(cp[3]))
1088 *cp = '\n';
1089 else
1090 *cp = cp[1];
1091 *cp = '\n';
1092 fd = open(vval(OPTFILE), O_WRONLY|O_CREAT|O_TRUNC, 0666);
1093 if (fd < 0 || write(fd, ro, n) != n || close(fd) < 0)
1094 syserr(vval(OPTFILE));
1095 sprintf(ro, " @%s", vval(OPTFILE));
1096 }
1097 #ifdef MSDOS
1098 else if (n > 50) {
1099 setenv("ROPT", ro+1);
1100 strcpy(ro, " $ROPT");
1101 }
1102 #endif
1103 }
1104
1105
1106 pfiltopts(po) /* get pfilt options */
1107 register char *po;
1108 {
1109 *po = '\0';
1110 if (vdef(EXPOSURE)) {
1111 po = addarg(po, "-1 -e");
1112 po = addarg(po, vval(EXPOSURE));
1113 }
1114 switch (vscale(QUALITY)) {
1115 case MEDIUM:
1116 po = addarg(po, "-r 1");
1117 break;
1118 case HIGH:
1119 po = addarg(po, "-m .25");
1120 break;
1121 }
1122 if (vdef(PFILT))
1123 po = addarg(po, vval(PFILT));
1124 }
1125
1126
1127 matchword(s1, s2) /* match white-delimited words */
1128 register char *s1, *s2;
1129 {
1130 while (isspace(*s1)) s1++;
1131 while (isspace(*s2)) s2++;
1132 while (*s1 && !isspace(*s1))
1133 if (*s1++ != *s2++)
1134 return(0);
1135 return(!*s2 || isspace(*s2));
1136 }
1137
1138
1139 char *
1140 specview(vs) /* get proper view spec from vs */
1141 register char *vs;
1142 {
1143 static char vup[7][12] = {"-vu 0 0 -1","-vu 0 -1 0","-vu -1 0 0",
1144 "-vu 0 0 1", "-vu 1 0 0","-vu 0 1 0","-vu 0 0 1"};
1145 static char viewopts[128];
1146 register char *cp;
1147 int xpos, ypos, zpos, viewtype, upax;
1148 register int i;
1149 double cent[3], dim[3], mult, d;
1150
1151 if (vs == NULL || *vs == '-')
1152 return(vs);
1153 upax = 0; /* get the up vector */
1154 if (vdef(UP)) {
1155 if (vval(UP)[0] == '-' || vval(UP)[0] == '+')
1156 upax = 1-'X'+UPPER(vval(UP)[1]);
1157 else
1158 upax = 1-'X'+vlet(UP);
1159 if (upax < 1 | upax > 3)
1160 badvalue(UP);
1161 if (vval(UP)[0] == '-')
1162 upax = -upax;
1163 }
1164 /* check standard view names */
1165 xpos = ypos = zpos = 0;
1166 if (*vs == 'X') {
1167 xpos = 1; vs++;
1168 } else if (*vs == 'x') {
1169 xpos = -1; vs++;
1170 }
1171 if (*vs == 'Y') {
1172 ypos = 1; vs++;
1173 } else if (*vs == 'y') {
1174 ypos = -1; vs++;
1175 }
1176 if (*vs == 'Z') {
1177 zpos = 1; vs++;
1178 } else if (*vs == 'z') {
1179 zpos = -1; vs++;
1180 }
1181 viewtype = 'v';
1182 if (*vs == 'v' | *vs == 'l' | *vs == 'a' | *vs == 'h')
1183 viewtype = *vs++;
1184 cp = viewopts;
1185 if ((!*vs || isspace(*vs)) && (xpos|ypos|zpos)) { /* got one! */
1186 *cp++ = '-'; *cp++ = 'v'; *cp++ = 't'; *cp++ = viewtype;
1187 if (sscanf(vval(ZONE), "%*s %lf %lf %lf %lf %lf %lf",
1188 &cent[0], &dim[0], &cent[1], &dim[1],
1189 &cent[2], &dim[2]) != 6)
1190 badvalue(ZONE);
1191 for (i = 0; i < 3; i++) {
1192 dim[i] -= cent[i];
1193 if (dim[i] <= FTINY)
1194 badvalue(ZONE);
1195 cent[i] += .5*dim[i];
1196 }
1197 mult = vlet(ZONE)=='E' ? 2. : .45 ;
1198 sprintf(cp, " -vp %.2g %.2g %.2g -vd %.2g %.2g %.2g",
1199 cent[0]+xpos*mult*dim[0],
1200 cent[1]+ypos*mult*dim[1],
1201 cent[2]+zpos*mult*dim[2],
1202 -xpos*dim[0], -ypos*dim[1], -zpos*dim[2]);
1203 cp += strlen(cp);
1204 /* redirect up axis if necessary */
1205 switch (upax) {
1206 case 3: /* plus or minus Z axis */
1207 case -3:
1208 case 0:
1209 if (!(xpos|ypos))
1210 upax = 2;
1211 break;
1212 case 2: /* plus or minus Y axis */
1213 case -2:
1214 if (!(xpos|zpos))
1215 upax = 1;
1216 break;
1217 case 1: /* plus or minus X axis */
1218 case -1:
1219 if (!(ypos|zpos))
1220 upax = 3;
1221 break;
1222 }
1223 cp = addarg(cp, vup[upax+3]);
1224 switch (viewtype) {
1225 case 'v':
1226 cp = addarg(cp, "-vh 45 -vv 45");
1227 break;
1228 case 'l':
1229 d = sqrt(dim[0]*dim[0]+dim[1]*dim[1]+dim[2]*dim[2]);
1230 sprintf(cp, " -vh %.2g -vv %.2g", d, d);
1231 cp += strlen(cp);
1232 break;
1233 case 'a':
1234 case 'h':
1235 cp = addarg(cp, "-vh 180 -vv 180");
1236 break;
1237 }
1238 } else {
1239 while (!isspace(*vs)) /* else skip id */
1240 if (!*vs++)
1241 return(NULL);
1242 if (upax) { /* specify up vector */
1243 strcpy(cp, vup[upax+3]);
1244 cp += strlen(cp);
1245 }
1246 }
1247 if (cp == viewopts) /* append any additional options */
1248 vs++; /* skip prefixed space if unneeded */
1249 strcpy(cp, vs);
1250 #ifdef MSDOS
1251 if (strlen(viewopts) > 40) {
1252 setenv("VIEW", viewopts);
1253 return("$VIEW");
1254 }
1255 #endif
1256 return(viewopts);
1257 }
1258
1259
1260 char *
1261 getview(n, vn) /* get view n, or NULL if none */
1262 int n;
1263 char *vn; /* returned view name */
1264 {
1265 register char *mv;
1266
1267 if (viewselect != NULL) { /* command-line selected */
1268 if (n) /* only do one */
1269 return(NULL);
1270 if (viewselect[0] == '-') { /* already specified */
1271 if (vn != NULL) *vn = '\0';
1272 return(viewselect);
1273 }
1274 if (vn != NULL) {
1275 for (mv = viewselect; *mv && !isspace(*mv);
1276 *vn++ = *mv++)
1277 ;
1278 *vn = '\0';
1279 }
1280 /* view number? */
1281 if (isint(viewselect))
1282 return(specview(nvalue(vv+VIEW, atoi(viewselect)-1)));
1283 /* check list */
1284 while ((mv = nvalue(vv+VIEW, n++)) != NULL)
1285 if (matchword(viewselect, mv))
1286 return(specview(mv));
1287 return(specview(viewselect)); /* standard view? */
1288 }
1289 mv = nvalue(vv+VIEW, n); /* use view n */
1290 if (vn != NULL & mv != NULL) {
1291 register char *mv2 = mv;
1292 if (*mv2 != '-')
1293 while (*mv2 && !isspace(*mv2))
1294 *vn++ = *mv2++;
1295 *vn = '\0';
1296 }
1297 return(specview(mv));
1298 }
1299
1300
1301 printview(vopts) /* print out selected view */
1302 register char *vopts;
1303 {
1304 extern char *atos(), *getenv();
1305 char buf[256];
1306 FILE *fp;
1307 register char *cp;
1308
1309 if (vopts == NULL)
1310 return(-1);
1311 fputs("VIEW=", stdout);
1312 do {
1313 if (matchword(vopts, "-vf")) { /* expand view file */
1314 vopts = sskip(vopts);
1315 if (!*atos(buf, sizeof(buf), vopts))
1316 return(-1);
1317 if ((fp = fopen(buf, "r")) == NULL)
1318 return(-1);
1319 for (buf[sizeof(buf)-2] = '\n';
1320 fgets(buf, sizeof(buf), fp) != NULL &&
1321 buf[0] != '\n';
1322 buf[sizeof(buf)-2] = '\n') {
1323 if (buf[sizeof(buf)-2] != '\n') {
1324 ungetc(buf[sizeof(buf)-2], fp);
1325 buf[sizeof(buf)-2] = '\0';
1326 }
1327 if (matchword(buf, "VIEW=") ||
1328 matchword(buf, "rview")) {
1329 for (cp = sskip(buf); *cp && *cp != '\n'; cp++)
1330 putchar(*cp);
1331 }
1332 }
1333 fclose(fp);
1334 vopts = sskip(vopts);
1335 } else {
1336 while (isspace(*vopts))
1337 vopts++;
1338 putchar(' ');
1339 #ifdef MSDOS
1340 if (*vopts == '$') { /* expand env. var. */
1341 if (!*atos(buf, sizeof(buf), vopts+1))
1342 return(-1);
1343 if ((cp = getenv(buf)) == NULL)
1344 return(-1);
1345 fputs(cp, stdout);
1346 vopts = sskip(vopts);
1347 } else
1348 #endif
1349 while (*vopts && !isspace(*vopts))
1350 putchar(*vopts++);
1351 }
1352 } while (*vopts++);
1353 putchar('\n');
1354 return(0);
1355 }
1356
1357
1358 rview(opts, po) /* run rview with first view */
1359 char *opts, *po;
1360 {
1361 char *vw;
1362 char combuf[512];
1363 /* build command */
1364 if (touchonly || (vw = getview(0, NULL)) == NULL)
1365 return;
1366 if (sayview)
1367 printview(vw);
1368 sprintf(combuf, "rview %s%s%s -R %s ", vw, po, opts, rifname);
1369 if (rvdevice != NULL)
1370 sprintf(combuf+strlen(combuf), "-o %s ", rvdevice);
1371 if (vdef(EXPOSURE))
1372 sprintf(combuf+strlen(combuf), "-pe %s ", vval(EXPOSURE));
1373 strcat(combuf, oct1name);
1374 if (runcom(combuf)) { /* run it */
1375 fprintf(stderr, "%s: error running rview\n", progname);
1376 exit(1);
1377 }
1378 }
1379
1380
1381 rpict(opts, po) /* run rpict and pfilt for each view */
1382 char *opts, *po;
1383 {
1384 char combuf[1024];
1385 char rawfile[MAXPATH], picfile[MAXPATH], rep[MAXPATH+16], res[32];
1386 char pfopts[128];
1387 char vs[32], *vw;
1388 int vn, mult;
1389 time_t rfdt, pfdt;
1390 /* get pfilt options */
1391 pfiltopts(pfopts);
1392 /* get resolution, reporting */
1393 switch (vscale(QUALITY)) {
1394 case LOW:
1395 mult = 1;
1396 break;
1397 case MEDIUM:
1398 mult = 2;
1399 break;
1400 case HIGH:
1401 mult = 3;
1402 break;
1403 }
1404 {
1405 int xres, yres;
1406 double aspect;
1407 int n;
1408 n = sscanf(vval(RESOLUTION), "%d %d %lf", &xres, &yres, &aspect);
1409 if (n == 3)
1410 sprintf(res, "-x %d -y %d -pa %.3f",
1411 mult*xres, mult*yres, aspect);
1412 else if (n) {
1413 if (n == 1) yres = xres;
1414 sprintf(res, "-x %d -y %d", mult*xres, mult*yres);
1415 } else
1416 badvalue(RESOLUTION);
1417 }
1418 rep[0] = '\0';
1419 if (vdef(REPORT)) {
1420 double minutes;
1421 int n;
1422 n = sscanf(vval(REPORT), "%lf %s", &minutes, rawfile);
1423 if (n == 2)
1424 sprintf(rep, " -t %d -e %s", (int)(minutes*60), rawfile);
1425 else if (n == 1)
1426 sprintf(rep, " -t %d", (int)(minutes*60));
1427 else
1428 badvalue(REPORT);
1429 }
1430 /* do each view */
1431 vn = 0;
1432 while ((vw = getview(vn++, vs)) != NULL) {
1433 if (sayview)
1434 printview(vw);
1435 if (!vs[0])
1436 sprintf(vs, "%d", vn);
1437 sprintf(picfile, "%s_%s.pic", vval(PICTURE), vs);
1438 /* check date on picture */
1439 pfdt = fdate(picfile);
1440 if (pfdt >= oct1date)
1441 continue;
1442 /* get raw file name */
1443 sprintf(rawfile, "%s_%s.raw", vval(PICTURE), vs);
1444 rfdt = fdate(rawfile);
1445 if (touchonly) { /* update times only */
1446 if (rfdt) {
1447 if (rfdt < oct1date)
1448 touch(rawfile);
1449 } else if (pfdt && pfdt < oct1date)
1450 touch(picfile);
1451 continue;
1452 }
1453 /* build rpict command */
1454 if (rfdt >= oct1date) /* recover */
1455 sprintf(combuf, "rpict%s%s%s -ro %s %s",
1456 rep, po, opts, rawfile, oct1name);
1457 else {
1458 if (overture) { /* run overture calculation */
1459 sprintf(combuf,
1460 "rpict%s %s%s -x 64 -y 64 -ps 1 %s > %s",
1461 rep, vw, opts,
1462 oct1name, overfile);
1463 if (runcom(combuf)) {
1464 fprintf(stderr,
1465 "%s: error in overture for view %s\n",
1466 progname, vs);
1467 exit(1);
1468 }
1469 #ifdef NIX
1470 rmfile(overfile);
1471 #endif
1472 }
1473 sprintf(combuf, "rpict%s %s %s%s%s %s > %s",
1474 rep, vw, res, po, opts,
1475 oct1name, rawfile);
1476 }
1477 if (runcom(combuf)) { /* run rpict */
1478 fprintf(stderr, "%s: error rendering view %s\n",
1479 progname, vs);
1480 exit(1);
1481 }
1482 /* build pfilt command */
1483 if (mult > 1)
1484 sprintf(combuf, "pfilt%s -x /%d -y /%d %s > %s",
1485 pfopts, mult, mult, rawfile, picfile);
1486 else
1487 sprintf(combuf, "pfilt%s %s > %s", pfopts,
1488 rawfile, picfile);
1489 if (runcom(combuf)) { /* run pfilt */
1490 fprintf(stderr,
1491 "%s: error filtering view %s\n\t%s removed\n",
1492 progname, vs, picfile);
1493 unlink(picfile);
1494 exit(1);
1495 }
1496 /* remove raw file */
1497 rmfile(rawfile);
1498 }
1499 }
1500
1501
1502 touch(fn) /* update a file */
1503 char *fn;
1504 {
1505 if (!silent)
1506 printf("\ttouch %s\n", fn);
1507 if (noaction)
1508 return(0);
1509 #ifdef notused
1510 if (access(fn, F_OK) == -1) /* create it */
1511 if (close(open(fn, O_WRONLY|O_CREAT, 0666)) == -1)
1512 return(-1);
1513 #endif
1514 return(setfdate(fn, time((time_t *)NULL)));
1515 }
1516
1517
1518 runcom(cs) /* run command */
1519 char *cs;
1520 {
1521 if (!silent) /* echo it */
1522 printf("\t%s\n", cs);
1523 if (noaction)
1524 return(0);
1525 fflush(stdout); /* flush output and pass to shell */
1526 return(system(cs));
1527 }
1528
1529
1530 rmfile(fn) /* remove a file */
1531 char *fn;
1532 {
1533 if (!silent)
1534 #ifdef MSDOS
1535 printf("\tdel %s\n", fn);
1536 #else
1537 printf("\trm -f %s\n", fn);
1538 #endif
1539 if (noaction)
1540 return(0);
1541 return(unlink(fn));
1542 }
1543
1544
1545 #ifdef MSDOS
1546 setenv(vname, value) /* set an environment variable */
1547 char *vname, *value;
1548 {
1549 register char *evp;
1550
1551 evp = bmalloc(strlen(vname)+strlen(value)+2);
1552 if (evp == NULL)
1553 syserr(progname);
1554 sprintf(evp, "%s=%s", vname, value);
1555 if (putenv(evp) != 0) {
1556 fprintf(stderr, "%s: out of environment space\n", progname);
1557 exit(1);
1558 }
1559 if (!silent)
1560 printf("set %s\n", evp);
1561 }
1562 #endif
1563
1564
1565 badvalue(vc) /* report bad variable value and exit */
1566 int vc;
1567 {
1568 fprintf(stderr, "%s: bad value for variable '%s'\n",
1569 progname, vnam(vc));
1570 exit(1);
1571 }
1572
1573
1574 syserr(s) /* report a system error and exit */
1575 char *s;
1576 {
1577 perror(s);
1578 exit(1);
1579 }