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

Comparing ray/src/util/rad.c (file contents):
Revision 2.75 by greg, Thu Jan 1 19:31:46 2004 UTC vs.
Revision 2.114 by greg, Wed May 27 13:29:57 2015 UTC

# Line 22 | Line 22 | static const char      RCSid[] = "$Id$";
22   #else
23    #define DELCMD "rm -f"
24    #define RENAMECMD "mv"
25 +  #include <sys/types.h>
26 +  #include <sys/wait.h>
27 +  #include <signal.h>
28   #endif
29  
30                                  /* variables (alphabetical by name) */
# Line 33 | Line 36 | static const char      RCSid[] = "$Id$";
36   #define INDIRECT        5               /* indirection in lighting */
37   #define MATERIAL        6               /* material files */
38   #define MKILLUM         7               /* mkillum options */
39 < #define OBJECT          8               /* object files */
40 < #define OCONV           9               /* oconv options */
41 < #define OCTREE          10              /* octree file name */
42 < #define OPTFILE         11              /* rendering options file */
43 < #define PENUMBRAS       12              /* shadow penumbras are desired */
44 < #define PFILT           13              /* pfilt options */
45 < #define PICTURE         14              /* picture file root name */
46 < #define QUALITY         15              /* desired rendering quality */
47 < #define RAWFILE         16              /* raw picture file root name */
48 < #define RENDER          17              /* rendering options */
49 < #define REPORT          18              /* report frequency and errfile */
50 < #define RESOLUTION      19              /* maximum picture resolution */
51 < #define SCENE           20              /* scene files */
52 < #define UP              21              /* view up (X, Y or Z) */
53 < #define VARIABILITY     22              /* level of light variability */
54 < #define VIEWS           23              /* view(s) for picture(s) */
55 < #define ZFILE           24              /* distance file root name */
56 < #define ZONE            25              /* simulation zone */
39 > #define MKPMAP          8               /* mkpmap options */
40 > #define OBJECT          9               /* object files */
41 > #define OCONV           10              /* oconv options */
42 > #define OCTREE          11              /* octree file name */
43 > #define OPTFILE         12              /* rendering options file */
44 > #define PCMAP           13              /* caustic photon map */
45 > #define PENUMBRAS       14              /* shadow penumbras are desired */
46 > #define PFILT           15              /* pfilt options */
47 > #define PGMAP           16              /* global photon map */
48 > #define PICTURE         17              /* picture file root name */
49 > #define QUALITY         18              /* desired rendering quality */
50 > #define RAWFILE         19              /* raw picture file root name */
51 > #define RENDER          20              /* rendering options */
52 > #define REPORT          21              /* report frequency and errfile */
53 > #define RESOLUTION      22              /* maximum picture resolution */
54 > #define RPICT           23              /* rpict parameters */
55 > #define RVU             24              /* rvu parameters */
56 > #define SCENE           25              /* scene files */
57 > #define UP              26              /* view up (X, Y or Z) */
58 > #define VARIABILITY     27              /* level of light variability */
59 > #define VIEWS           28              /* view(s) for picture(s) */
60 > #define ZFILE           29              /* distance file root name */
61 > #define ZONE            30              /* simulation zone */
62                                  /* total number of variables */
63 < int NVARS = 26;
63 > int NVARS = 31;
64  
65   VARIABLE        vv[] = {                /* variable-value pairs */
66          {"AMBFILE",     3,      0,      NULL,   onevalue},
# Line 63 | Line 71 | VARIABLE       vv[] = {                /* variable-value pairs */
71          {"INDIRECT",    3,      0,      NULL,   intvalue},
72          {"materials",   3,      0,      NULL,   catvalues},
73          {"mkillum",     3,      0,      NULL,   catvalues},
74 +        {"mkpmap",      3,      0,      NULL,   catvalues},
75          {"objects",     3,      0,      NULL,   catvalues},
76          {"oconv",       3,      0,      NULL,   catvalues},
77          {"OCTREE",      3,      0,      NULL,   onevalue},
78          {"OPTFILE",     3,      0,      NULL,   onevalue},
79 +        {"PCMAP",       2,      0,      NULL,   onevalue},
80          {"PENUMBRAS",   3,      0,      NULL,   boolvalue},
81          {"pfilt",       2,      0,      NULL,   catvalues},
82 +        {"PGMAP",       2,      0,      NULL,   onevalue},
83          {"PICTURE",     3,      0,      NULL,   onevalue},
84          {"QUALITY",     3,      0,      NULL,   qualvalue},
85          {"RAWFILE",     3,      0,      NULL,   onevalue},
86          {"render",      3,      0,      NULL,   catvalues},
87          {"REPORT",      3,      0,      NULL,   onevalue},
88          {"RESOLUTION",  3,      0,      NULL,   onevalue},
89 +        {"rpict",       3,      0,      NULL,   catvalues},
90 +        {"rvu",         3,      0,      NULL,   catvalues},
91          {"scene",       3,      0,      NULL,   catvalues},
92          {"UP",          2,      0,      NULL,   onevalue},
93          {"VARIABILITY", 3,      0,      NULL,   qualvalue},
# Line 101 | Line 114 | 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 + char    *pgmapname;             /* name of global photon map */
118 + time_t  pgmapdate;              /* date of global photon map (>= oct1date) */
119 + char    *pcmapname;             /* name of caustic photon map */
120 + time_t  pcmapdate;              /* date of caustic photon map (>= oct1date) */
121 +
122   int     nowarn = 0;             /* no warnings */
123   int     explicate = 0;          /* explicate variables */
124   int     silent = 0;             /* do work silently */
# Line 110 | Line 128 | int    sayview = 0;            /* print view out */
128   char    *rvdevice = NULL;       /* rvu output device */
129   char    *viewselect = NULL;     /* specific view only */
130  
131 + #define DEF_RPICT_PATH  "rpict"         /* default rpict path */
132 +
133 +                                /* command paths */
134 + char    c_oconv[256] = "oconv";
135 + char    c_mkillum[256] = "mkillum";
136 + char    c_mkpmap[256] = "mkpmap";
137 + char    c_rvu[256] = "rvu";
138 + char    c_rpict[256] = DEF_RPICT_PATH;
139 + char    c_rpiece[] = "rpiece";
140 + char    c_pfilt[256] = "pfilt";
141 +
142   int     overture = 0;           /* overture calculation needed */
143  
144   int     children_running = 0;   /* set negative in children */
# Line 121 | Line 150 | char   radname[PATH_MAX];      /* root Radiance file name */
150  
151   #define inchild()       (children_running < 0)
152  
153 + static void rootname(char       *rn, char       *fn);
154 + static time_t checklast(char    *fnames);
155 + static char * newfname(char     *orig, int      pred);
156 + static void checkfiles(void);
157 + static void getoctcube(double   org[3], double  *sizp);
158 + static void setdefaults(void);
159 + static void oconv(void);
160 + static void mkpmap(void);
161 + static char * addarg(char       *op, char       *arg);
162 + static void oconvopts(char      *oo);
163 + static void mkillumopts(char    *mo);
164 + static void mkpmapopts(char     *mo);
165 + static void checkambfile(void);
166 + static double ambval(void);
167 + static void renderopts(char     *op, char       *po);
168 + static void lowqopts(char       *op, char       *po);
169 + static void medqopts(char       *op, char       *po);
170 + static void hiqopts(char        *op, char       *po);
171 + static void xferopts(char       *ro);
172 + static void pfiltopts(char      *po);
173 + static int matchword(char       *s1, char       *s2);
174 + static char * specview(char     *vs);
175 + static char * getview(int       n, char *vn);
176 + static int myprintview(char     *vopts, FILE    *fp);
177 + static void rvu(char    *opts, char     *po);
178 + static void rpict(char  *opts, char     *po);
179 + static int touch(char   *fn);
180 + static int runcom(char  *cs);
181 + static int rmfile(char  *fn);
182 + static int mvfile(char  *fold, char     *fnew);
183 + static int next_process(int     reserve);
184 + static void wait_process(int    all);
185 + static void finish_process(void);
186 + static void badvalue(int        vc);
187 + static void syserr(char *s);
188  
189 < main(argc, argv)
190 < int     argc;
191 < char    *argv[];
189 >
190 > int
191 > main(
192 >        int     argc,
193 >        char    *argv[]
194 > )
195   {
196          char    ropts[512];
197          char    popts[64];
# Line 169 | Line 236 | char   *argv[];
236          if (i >= argc)
237                  goto userr;
238          rifname = argv[i];
172                                /* check command-line options */
173        if ((nprocs > 1) & (viewselect != NULL))
174                nprocs = 1;
239                                  /* assign Radiance root file name */
240          rootname(radname, rifname);
241                                  /* load variable values */
# Line 194 | Line 258 | char   *argv[];
258                  printvars(stdout);
259                                  /* build octree (and run mkillum) */
260          oconv();
261 +                                /* run mkpmap if indicated */
262 +        mkpmap();
263                                  /* check date on ambient file */
264          checkambfile();
265                                  /* run simulation */
# Line 209 | Line 275 | userr:
275   "Usage: %s [-w][-s][-n|-N npr][-t][-e][-V][-v view][-o dev] rfile [VAR=value ..]\n",
276                          progname);
277          quit(1);
278 +        return 1; /* pro forma return */
279   }
280  
281  
282 < rootname(rn, fn)                /* remove tail from end of fn */
283 < register char   *rn, *fn;
282 > static void
283 > rootname(               /* remove tail from end of fn */
284 >        char    *rn,
285 >        char    *fn
286 > )
287   {
288          char    *tp, *dp;
289  
# Line 227 | Line 297 | register char  *rn, *fn;
297   }
298  
299  
300 < time_t
301 < checklast(fnames)                       /* check files and find most recent */
302 < register char   *fnames;
300 > static time_t
301 > checklast(                      /* check files and find most recent */
302 >        char    *fnames
303 > )
304   {
305          char    thisfile[PATH_MAX];
306          time_t  thisdate, lastdate = 0;
# Line 238 | Line 309 | register char  *fnames;
309                  return(0);
310          while ((fnames = nextword(thisfile, PATH_MAX, fnames)) != NULL) {
311                  if (thisfile[0] == '!' ||
312 <                                (thisfile[0] == '\\' && thisfile[1] == '!'))
312 >                                (thisfile[0] == '\\' && thisfile[1] == '!')) {
313 >                        if (!lastdate)
314 >                                lastdate = 1;
315                          continue;
316 +                }
317                  if (!(thisdate = fdate(thisfile)))
318                          syserr(thisfile);
319                  if (thisdate > lastdate)
# Line 249 | Line 323 | register char  *fnames;
323   }
324  
325  
326 < char *
327 < newfname(orig, pred)            /* create modified file name */
328 < char    *orig;
329 < int     pred;
326 > static char *
327 > newfname(               /* create modified file name */
328 >        char    *orig,
329 >        int     pred
330 > )
331   {
332 <        register char   *cp;
333 <        register int    n;
332 >        char    *cp;
333 >        int     n;
334          int     suffix;
335  
336          n = 0; cp = orig; suffix = -1;          /* suffix position, length */
# Line 274 | Line 349 | int    pred;
349   }
350  
351  
352 < checkfiles()                    /* check for existence and modified times */
352 > static void
353 > checkfiles(void)                        /* check for existence and modified times */
354   {
355 +        char    fntemp[256];
356          time_t  objdate;
357  
358          if (!vdef(OCTREE)) {
# Line 305 | Line 382 | checkfiles()                   /* check for existence and modified tim
382                                  vnam(OCTREE), vnam(SCENE), vnam(ILLUM));
383                  quit(1);
384          }
385 +        if (vdef(PGMAP)) {
386 +                if (!*sskip2(vval(PGMAP),1)) {
387 +                        fprintf(stderr, "%s: '%s' missing # photons argument\n",
388 +                                        progname, vnam(PGMAP));
389 +                        quit(1);
390 +                }
391 +                atos(fntemp, sizeof(fntemp), vval(PGMAP));
392 +                pgmapname = savqstr(fntemp);
393 +                pgmapdate = fdate(pgmapname);
394 +        }
395 +        if (vdef(PCMAP)) {
396 +                if (!*sskip2(vval(PCMAP),1)) {
397 +                        fprintf(stderr, "%s: '%s' missing # photons argument\n",
398 +                                        progname, vnam(PCMAP));
399 +                        quit(1);
400 +                }
401 +                atos(fntemp, sizeof(fntemp), vval(PCMAP));
402 +                pcmapname = savqstr(fntemp);
403 +                pcmapdate = fdate(pcmapname);
404 +        }
405          matdate = checklast(vval(MATERIAL));
406   }      
407  
408  
409 < getoctcube(org, sizp)           /* get octree bounding cube */
410 < double  org[3], *sizp;
409 > static void
410 > getoctcube(             /* get octree bounding cube */
411 >        double  org[3],
412 >        double  *sizp
413 > )
414   {
415          static double   oorg[3], osiz = 0.;
416          double  min[3], max[3];
417          char    buf[1024];
418          FILE    *fp;
419 <        register int    i;
419 >        int     i;
420  
421          if (osiz <= FTINY) {
422                  if (!nprocs && fdate(oct1name) <
# Line 359 | Line 459 | double org[3], *sizp;
459   }
460  
461  
462 < setdefaults()                   /* set default values for unassigned var's */
462 > static void
463 > setdefaults(void)                       /* set default values for unassigned var's */
464   {
465          double  org[3], lim[3], size;
466          char    buf[128];
# Line 416 | Line 517 | setdefaults()                  /* set default values for unassigned v
517   }
518  
519  
520 < oconv()                         /* run oconv and mkillum if necessary */
520 > static void
521 > oconv(void)                             /* run oconv and mkillum if necessary */
522   {
523          static char     illumtmp[] = "ilXXXXXX";
524 <        char    combuf[PATH_MAX], ocopts[64], mkopts[64];
524 >        char    combuf[PATH_MAX], ocopts[64], mkopts[1024];
525  
526          oconvopts(ocopts);              /* get options */
527          if (octreedate < scenedate) {   /* check date on original octree */
# Line 427 | Line 529 | oconv()                                /* run oconv and mkillum if necessary */
529                          touch(vval(OCTREE));
530                  else {                          /* build command */
531                          if (vdef(MATERIAL))
532 <                                sprintf(combuf, "oconv%s %s %s > %s", ocopts,
533 <                                                vval(MATERIAL), vval(SCENE),
534 <                                                vval(OCTREE));
532 >                                sprintf(combuf, "%s%s %s %s > %s", c_oconv,
533 >                                                ocopts, vval(MATERIAL),
534 >                                                vval(SCENE), vval(OCTREE));
535                          else
536 <                                sprintf(combuf, "oconv%s %s > %s", ocopts,
536 >                                sprintf(combuf, "%s%s %s > %s", c_oconv, ocopts,
537                                                  vval(SCENE), vval(OCTREE));
538                          
539                          if (runcom(combuf)) {           /* run it */
# Line 457 | Line 559 | oconv()                                /* run oconv and mkillum if necessary */
559                          touch(oct0name);
560                  else {                          /* build command */
561                          if (octreedate)
562 <                                sprintf(combuf, "oconv%s -i %s %s > %s", ocopts,
563 <                                        vval(OCTREE), vval(ILLUM), oct0name);
562 >                                sprintf(combuf, "%s%s -i %s %s > %s", c_oconv,
563 >                                        ocopts, vval(OCTREE),
564 >                                        vval(ILLUM), oct0name);
565                          else if (vdef(MATERIAL))
566 <                                sprintf(combuf, "oconv%s %s %s > %s", ocopts,
567 <                                        vval(MATERIAL), vval(ILLUM), oct0name);
465 <                        else
466 <                                sprintf(combuf, "oconv%s %s > %s", ocopts,
566 >                                sprintf(combuf, "%s%s %s %s > %s", c_oconv,
567 >                                        ocopts, vval(MATERIAL),
568                                          vval(ILLUM), oct0name);
569 +                        else
570 +                                sprintf(combuf, "%s%s %s > %s", c_oconv,
571 +                                        ocopts, vval(ILLUM), oct0name);
572                          if (runcom(combuf)) {           /* run it */
573                                  fprintf(stderr,
574                                  "%s: error generating octree\n\t%s removed\n",
# Line 484 | Line 588 | oconv()                                /* run oconv and mkillum if necessary */
588          else {
589                  mkillumopts(mkopts);            /* build mkillum command */
590                  mktemp(illumtmp);
591 <                sprintf(combuf, "mkillum%s %s \"<\" %s > %s", mkopts,
591 >                sprintf(combuf, "%s%s %s \"<\" %s > %s", c_mkillum, mkopts,
592                                  oct0name, vval(ILLUM), illumtmp);
593                  if (runcom(combuf)) {                   /* run it */
594 <                        fprintf(stderr, "%s: error running mkillum\n",
595 <                                        progname);
594 >                        fprintf(stderr, "%s: error running %s\n",
595 >                                        progname, c_mkillum);
596                          unlink(illumtmp);
597                          quit(1);
598                  }
599 +                rmfile(oct0name);
600                                                  /* make octree1 (frozen) */
601                  if (octreedate)
602 <                        sprintf(combuf, "oconv%s -f -i %s %s > %s", ocopts,
603 <                                vval(OCTREE), illumtmp, oct1name);
602 >                        sprintf(combuf, "%s%s -f -i %s %s > %s", c_oconv,
603 >                                ocopts, vval(OCTREE), illumtmp, oct1name);
604                  else if (vdef(MATERIAL))
605 <                        sprintf(combuf, "oconv%s -f %s %s > %s", ocopts,
606 <                                vval(MATERIAL), illumtmp, oct1name);
605 >                        sprintf(combuf, "%s%s -f %s %s > %s", c_oconv,
606 >                                ocopts, vval(MATERIAL), illumtmp, oct1name);
607                  else
608 <                        sprintf(combuf, "oconv%s -f %s > %s", ocopts,
608 >                        sprintf(combuf, "%s%s -f %s > %s", c_oconv, ocopts,
609                                  illumtmp, oct1name);
610                  if (runcom(combuf)) {           /* run it */
611                          fprintf(stderr,
# Line 518 | Line 623 | oconv()                                /* run oconv and mkillum if necessary */
623   }
624  
625  
626 < char *
627 < addarg(op, arg)                         /* add argument and advance pointer */
523 < register char   *op, *arg;
626 > static void
627 > mkpmap(void)                    /* run mkpmap if indicated */
628   {
629 +        char    combuf[2048], *cp;
630 +        time_t  tnow;
631 +                                /* nothing to do? */
632 +        if ((pgmapname == NULL) | (pgmapdate >= oct1date) &&
633 +                        (pcmapname == NULL) | (pcmapdate >= oct1date))
634 +                return;
635 +                                /* just update existing file dates? */
636 +        if (touchonly && (pgmapname == NULL) | (pgmapdate > 0) &&
637 +                        (pcmapname == NULL) | (pcmapdate > 0)) {
638 +                if (pgmapname != NULL)
639 +                        touch(pgmapname);
640 +                if (pcmapname != NULL)
641 +                        touch(pcmapname);
642 +        } else {                /* else need to (re)run pkpmap */
643 +                strcpy(combuf, c_mkpmap);
644 +                for (cp = combuf; *cp; cp++)
645 +                        ;
646 +                mkpmapopts(cp);
647 +                if (vdef(REPORT)) {
648 +                        char    errfile[256];
649 +                        int     n;
650 +                        double  minutes;
651 +                        n = sscanf(vval(REPORT), "%lf %s", &minutes, errfile);
652 +                        if (n == 2)
653 +                                sprintf(cp, " -t %d -e %s", (int)(minutes*60), errfile);
654 +                        else if (n == 1)
655 +                                sprintf(cp, " -t %d", (int)(minutes*60));
656 +                        else
657 +                                badvalue(REPORT);
658 +                }
659 +                if (pgmapname != NULL && pgmapdate < oct1date) {
660 +                        cp = addarg(cp, "-apg");
661 +                        addarg(cp, vval(PGMAP));
662 +                        cp = sskip(sskip(cp));  /* remove any bandwidth */
663 +                        *cp = '\0';
664 +                }
665 +                if (pcmapname != NULL && pcmapdate < oct1date) {
666 +                        cp = addarg(cp, "-apc");
667 +                        addarg(cp, vval(PCMAP));
668 +                        cp = sskip(sskip(cp));  /* remove any bandwidth */
669 +                        *cp = '\0';
670 +                }
671 +                cp = addarg(cp, oct1name);
672 +                if (runcom(combuf)) {
673 +                        fprintf(stderr, "%s: error running %s\n",
674 +                                        progname, c_mkpmap);
675 +                        if (pgmapname != NULL)
676 +                                unlink(pgmapname);
677 +                        if (pcmapname != NULL)
678 +                                unlink(pcmapname);
679 +                        quit(1);
680 +                }
681 +        }
682 +        tnow = time((time_t *)NULL);
683 +        if (pgmapname != NULL)
684 +                pgmapdate = tnow;
685 +        if (pcmapname != NULL)
686 +                pcmapdate = tnow;
687 +        oct1date = tnow;        /* trigger ambient file removal if needed */
688 + }
689 +
690 +
691 + static char *
692 + addarg(                         /* append argument and advance pointer */
693 + char    *op,
694 + char    *arg
695 + )
696 + {
697 +        while (*op)
698 +                op++;
699          *op = ' ';
700          while ( (*++op = *arg++) )
701                  ;
# Line 529 | Line 703 | register char  *op, *arg;
703   }
704  
705  
706 < oconvopts(oo)                           /* get oconv options */
707 < register char   *oo;
706 > static void
707 > oconvopts(                              /* get oconv options */
708 >        char    *oo
709 > )
710   {
711          /* BEWARE:  This may be called via setdefaults(), so no assumptions */
712  
713          *oo = '\0';
714 <        if (vdef(OCONV))
715 <                addarg(oo, vval(OCONV));
714 >        if (!vdef(OCONV))
715 >                return;
716 >        if (vval(OCONV)[0] != '-') {
717 >                atos(c_oconv, sizeof(c_oconv), vval(OCONV));
718 >                oo = addarg(oo, sskip2(vval(OCONV), 1));
719 >        } else
720 >                oo = addarg(oo, vval(OCONV));
721   }
722  
723  
724 < mkillumopts(mo)                         /* get mkillum options */
725 < register char   *mo;
724 > static void
725 > mkillumopts(                            /* get mkillum options */
726 >        char    *mo
727 > )
728   {
729          /* BEWARE:  This may be called via setdefaults(), so no assumptions */
730  
731 +        if (nprocs > 1)
732 +                sprintf(mo, " -n %d", nprocs);
733 +        else
734 +                *mo = '\0';
735 +        if (!vdef(MKILLUM))
736 +                return;
737 +        if (vval(MKILLUM)[0] != '-') {
738 +                atos(c_mkillum, sizeof(c_mkillum), vval(MKILLUM));
739 +                mo = addarg(mo, sskip2(vval(MKILLUM), 1));
740 +        } else
741 +                mo = addarg(mo, vval(MKILLUM));
742 + }
743 +
744 +
745 + static void
746 + mkpmapopts(                             /* get mkpmap options */
747 +        char    *mo
748 + )
749 + {
750 +        /* BEWARE:  This may be called via setdefaults(), so no assumptions */
751 +
752          *mo = '\0';
753 <        if (vdef(MKILLUM))
754 <                addarg(mo, vval(MKILLUM));
753 >        if (!vdef(MKPMAP))
754 >                return;
755 >        if (vval(MKPMAP)[0] != '-') {
756 >                atos(c_mkpmap, sizeof(c_mkpmap), vval(MKPMAP));
757 >                mo = addarg(mo, sskip2(vval(MKPMAP), 1));
758 >        } else
759 >                mo = addarg(mo, vval(MKPMAP));
760   }
761  
762  
763 < checkambfile()                  /* check date on ambient file */
763 > static void
764 > checkambfile(void)                      /* check date on ambient file */
765   {
766          time_t  afdate;
767  
# Line 568 | Line 778 | checkambfile()                 /* check date on ambient file */
778   }
779  
780  
781 < double
782 < ambval()                                /* compute ambient value */
781 > static double
782 > ambval(void)                            /* compute ambient value */
783   {
784          if (vdef(EXPOSURE)) {
785                  if (vval(EXPOSURE)[0] == '+' || vval(EXPOSURE)[0] == '-')
# Line 581 | Line 791 | ambval()                               /* compute ambient value */
791          if (vlet(ZONE) == 'I')
792                  return(.01);
793          badvalue(ZONE);
794 +        return 0; /* pro forma return */
795   }
796  
797  
798 < renderopts(op, po)                      /* set rendering options */
799 < char    *op, *po;
798 > static void
799 > renderopts(                     /* set rendering options */
800 >        char    *op,
801 >        char    *po
802 > )
803   {
804 +        char    pmapf[256], *bw;
805 +
806          switch(vscale(QUALITY)) {
807          case LOW:
808                  lowqopts(op, po);
# Line 598 | Line 814 | char   *op, *po;
814                  hiqopts(op, po);
815                  break;
816          }
817 +        if (vdef(PGMAP)) {
818 +                bw = sskip2(vval(PGMAP), 2);
819 +                atos(pmapf, sizeof(pmapf), vval(PGMAP));
820 +                op = addarg(addarg(op, "-ap"), pmapf);
821 +                if (atoi(bw) > 0) op = addarg(op, bw);
822 +        }
823 +        if (vdef(PCMAP)) {
824 +                bw = sskip2(vval(PCMAP), 2);
825 +                atos(pmapf, sizeof(pmapf), vval(PCMAP));
826 +                op = addarg(addarg(op, "-ap"), pmapf);
827 +                if (atoi(bw) > 0) op = addarg(op, bw);
828 +        }
829 +        if (vdef(RENDER))
830 +                op = addarg(op, vval(RENDER));
831 +        if (rvdevice != NULL) {
832 +                if (vdef(RVU))
833 +                        if (vval(RVU)[0] != '-') {
834 +                                atos(c_rvu, sizeof(c_rvu), vval(RVU));
835 +                                po = addarg(po, sskip2(vval(RVU), 1));
836 +                        } else
837 +                                po = addarg(po, vval(RVU));
838 +        } else {
839 +                if (vdef(RPICT))
840 +                        if (vval(RPICT)[0] != '-') {
841 +                                atos(c_rpict, sizeof(c_rpict), vval(RPICT));
842 +                                po = addarg(po, sskip2(vval(RPICT), 1));
843 +                        } else
844 +                                po = addarg(po, vval(RPICT));
845 +        }
846   }
847  
848  
849 < lowqopts(op, po)                        /* low quality rendering options */
850 < register char   *op;
851 < char    *po;
849 > static void
850 > lowqopts(                       /* low quality rendering options */
851 >        char    *op,
852 >        char    *po
853 > )
854   {
855          double  d, org[3], siz[3];
856  
# Line 642 | Line 889 | char   *po;
889                  op = addarg(op, "-ds .4");
890          else
891                  op = addarg(op, "-ds 0");
892 <        op = addarg(op, "-dt .2 -dc .25 -dr 0 -sj 0 -st .5");
892 >        op = addarg(op, "-dt .2 -dc .25 -dr 0 -ss 0 -st .5");
893          if (vdef(AMBFILE)) {
894                  sprintf(op, " -af %s", vval(AMBFILE));
895                  op += strlen(op);
# Line 663 | Line 910 | char   *po;
910          d = ambval();
911          sprintf(op, " -av %.2g %.2g %.2g", d, d, d);
912          op += strlen(op);
913 <        op = addarg(op, "-lr 6 -lw .01");
667 <        if (vdef(RENDER))
668 <                op = addarg(op, vval(RENDER));
913 >        op = addarg(op, "-lr 6 -lw .003");
914   }
915  
916  
917 < medqopts(op, po)                        /* medium quality rendering options */
918 < register char   *op;
919 < char    *po;
917 > static void
918 > medqopts(                       /* medium quality rendering options */
919 >        char    *op,
920 >        char    *po
921 > )
922   {
923          double  d, org[3], siz[3], asz;
924  
# Line 714 | Line 961 | char   *po;
961          }
962          po = addarg(po, "-pt .08");
963          if (vbool(PENUMBRAS))
964 <                op = addarg(op, "-ds .2 -dj .5");
964 >                op = addarg(op, "-ds .2 -dj .9");
965          else
966                  op = addarg(op, "-ds .3");
967 <        op = addarg(op, "-dt .1 -dc .5 -dr 1 -sj .7 -st .1");
967 >        op = addarg(op, "-dt .1 -dc .5 -dr 1 -ss 1 -st .1");
968          if ( (overture = vint(INDIRECT)) ) {
969                  sprintf(op, " -ab %d", overture);
970                  op += strlen(op);
# Line 741 | Line 988 | char   *po;
988          d = ambval();
989          sprintf(op, " -av %.2g %.2g %.2g", d, d, d);
990          op += strlen(op);
991 <        op = addarg(op, "-lr 8 -lw .002");
745 <        if (vdef(RENDER))
746 <                op = addarg(op, vval(RENDER));
991 >        op = addarg(op, "-lr 8 -lw 1e-4");
992   }
993  
994  
995 < hiqopts(op, po)                         /* high quality rendering options */
996 < register char   *op;
997 < char    *po;
995 > static void
996 > hiqopts(                                /* high quality rendering options */
997 >        char    *op,
998 >        char    *po
999 > )
1000   {
1001          double  d, org[3], siz[3], asz;
1002  
# Line 792 | Line 1039 | char   *po;
1039          }
1040          po = addarg(po, "-pt .04");
1041          if (vbool(PENUMBRAS))
1042 <                op = addarg(op, "-ds .1 -dj .65");
1042 >                op = addarg(op, "-ds .1 -dj .9");
1043          else
1044                  op = addarg(op, "-ds .2");
1045 <        op = addarg(op, "-dt .05 -dc .75 -dr 3 -sj 1 -st .01");
1045 >        op = addarg(op, "-dt .05 -dc .75 -dr 3 -ss 16 -st .01");
1046          sprintf(op, " -ab %d", overture=vint(INDIRECT)+1);
1047          op += strlen(op);
1048          if (vdef(AMBFILE)) {
# Line 817 | Line 1064 | char   *po;
1064          d = ambval();
1065          sprintf(op, " -av %.2g %.2g %.2g", d, d, d);
1066          op += strlen(op);
1067 <        op = addarg(op, "-lr 12 -lw .0005");
821 <        if (vdef(RENDER))
822 <                op = addarg(op, vval(RENDER));
1067 >        op = addarg(op, "-lr 12 -lw 1e-5");
1068   }
1069  
1070  
1071 < xferopts(ro)                            /* transfer options if indicated */
1072 < char    *ro;
1071 > #ifdef _WIN32
1072 > static void
1073 > setenv(                 /* set an environment variable */
1074 >        char    *vname,
1075 >        char    *value
1076 > )
1077   {
1078 +        char    *evp;
1079 +
1080 +        evp = bmalloc(strlen(vname)+strlen(value)+2);
1081 +        if (evp == NULL)
1082 +                syserr(progname);
1083 +        sprintf(evp, "%s=%s", vname, value);
1084 +        if (putenv(evp) != 0) {
1085 +                fprintf(stderr, "%s: out of environment space\n", progname);
1086 +                quit(1);
1087 +        }
1088 +        if (!silent)
1089 +                printf("set %s\n", evp);
1090 + }
1091 + #endif
1092 +
1093 +
1094 + static void
1095 + xferopts(                               /* transfer options if indicated */
1096 +        char    *ro
1097 + )
1098 + {
1099          int     fd, n;
1100 <        register char   *cp;
1100 >        char    *cp;
1101          
1102          n = strlen(ro);
1103          if (n < 2)
# Line 854 | Line 1124 | char   *ro;
1124   }
1125  
1126  
1127 < pfiltopts(po)                           /* get pfilt options */
1128 < register char   *po;
1127 > static void
1128 > pfiltopts(                              /* get pfilt options */
1129 >        char    *po
1130 > )
1131   {
1132          *po = '\0';
1133          if (vdef(EXPOSURE)) {
# Line 871 | Line 1143 | register char  *po;
1143                  break;
1144          }
1145          if (vdef(PFILT))
1146 <                po = addarg(po, vval(PFILT));
1146 >                if (vval(PFILT)[0] != '-') {
1147 >                        atos(c_pfilt, sizeof(c_pfilt), vval(PFILT));
1148 >                        po = addarg(po, sskip2(vval(PFILT), 1));
1149 >                } else
1150 >                        po = addarg(po, vval(PFILT));
1151   }
1152  
1153  
1154 < matchword(s1, s2)                       /* match white-delimited words */
1155 < register char   *s1, *s2;
1154 > static int
1155 > matchword(                      /* match white-delimited words */
1156 >        char    *s1,
1157 >        char    *s2
1158 > )
1159   {
1160          while (isspace(*s1)) s1++;
1161          while (isspace(*s2)) s2++;
# Line 887 | Line 1166 | register char  *s1, *s2;
1166   }
1167  
1168  
1169 < char *
1170 < specview(vs)                            /* get proper view spec from vs */
1171 < register char   *vs;
1169 > static char *
1170 > specview(                               /* get proper view spec from vs */
1171 >        char    *vs
1172 > )
1173   {
1174          static char     vup[7][12] = {"-vu 0 0 -1","-vu 0 -1 0","-vu -1 0 0",
1175                          "-vu 0 0 1", "-vu 1 0 0","-vu 0 1 0","-vu 0 0 1"};
1176          static char     viewopts[128];
1177 <        register char   *cp;
1177 >        char    *cp;
1178          int     xpos, ypos, zpos, viewtype, upax;
1179 <        register int    i;
1179 >        int     i;
1180          double  cent[3], dim[3], mult, d;
1181  
1182          if (vs == NULL || *vs == '-')
# Line 929 | Line 1209 | register char  *vs;
1209          } else if (*vs == 'z') {
1210                  zpos = -1; vs++;
1211          }
1212 <        viewtype = 'v';
1213 <        if((*vs == 'v') | (*vs == 'l') | (*vs == 'a') | (*vs == 'h') | (*vs == 'c'))
1212 >        switch (*vs) {
1213 >        case VT_PER:
1214 >        case VT_PAR:
1215 >        case VT_ANG:
1216 >        case VT_HEM:
1217 >        case VT_PLS:
1218 >        case VT_CYL:
1219                  viewtype = *vs++;
1220 +                break;
1221 +        default:
1222 +                viewtype = VT_PER;
1223 +                break;
1224 +        }
1225          cp = viewopts;
1226          if ((!*vs || isspace(*vs)) && (xpos|ypos|zpos)) {       /* got one! */
1227                  *cp++ = '-'; *cp++ = 'v'; *cp++ = 't'; *cp++ = viewtype;
# Line 946 | Line 1236 | register char  *vs;
1236                          cent[i] += .5*dim[i];
1237                  }
1238                  mult = vlet(ZONE)=='E' ? 2. : .45 ;
1239 <                sprintf(cp, " -vp %.2g %.2g %.2g -vd %.2g %.2g %.2g",
1239 >                sprintf(cp, " -vp %.3g %.3g %.3g -vd %.3g %.3g %.3g",
1240                                  cent[0]+xpos*mult*dim[0],
1241                                  cent[1]+ypos*mult*dim[1],
1242                                  cent[2]+zpos*mult*dim[2],
# Line 973 | Line 1263 | register char  *vs;
1263                  }
1264                  cp = addarg(cp, vup[upax+3]);
1265                  switch (viewtype) {
1266 <                case 'v':
1266 >                case VT_PER:
1267                          cp = addarg(cp, "-vh 45 -vv 45");
1268                          break;
1269 <                case 'l':
1269 >                case VT_PAR:
1270                          d = sqrt(dim[0]*dim[0]+dim[1]*dim[1]+dim[2]*dim[2]);
1271 <                        sprintf(cp, " -vh %.2g -vv %.2g", d, d);
1271 >                        sprintf(cp, " -vh %.3g -vv %.3g", d, d);
1272                          cp += strlen(cp);
1273                          break;
1274 <                case 'a':
1275 <                case 'h':
1274 >                case VT_ANG:
1275 >                case VT_HEM:
1276 >                case VT_PLS:
1277                          cp = addarg(cp, "-vh 180 -vv 180");
1278                          break;
1279 <                case 'c':
1279 >                case VT_CYL:
1280                          cp = addarg(cp, "-vh 180 -vv 90");
1281                          break;
1282                  }
# Line 993 | Line 1284 | register char  *vs;
1284                  while (!isspace(*vs))           /* else skip id */
1285                          if (!*vs++)
1286                                  return(NULL);
1287 <                if (upax) {                     /* specify up vector */
1287 >                if (upax) {                     /* prepend up vector */
1288                          strcpy(cp, vup[upax+3]);
1289                          cp += strlen(cp);
1290                  }
# Line 1011 | Line 1302 | register char  *vs;
1302   }
1303  
1304  
1305 < char *
1306 < getview(n, vn)                          /* get view n, or NULL if none */
1307 < int     n;
1308 < char    *vn;            /* returned view name */
1305 > static char *
1306 > getview(                                /* get view n, or NULL if none */
1307 >        int     n,
1308 >        char    *vn             /* returned view name */
1309 > )
1310   {
1311 <        register char   *mv;
1311 >        char    *mv;
1312  
1313          if (viewselect != NULL) {               /* command-line selected */
1314                  if (n)                          /* only do one */
1315                          return(NULL);
1316 +                                        
1317 +                if (isint(viewselect)) {        /* view number? */
1318 +                        n = atoi(viewselect)-1;
1319 +                        goto numview;
1320 +                }
1321                  if (viewselect[0] == '-') {     /* already specified */
1322 <                        if (vn != NULL) *vn = '\0';
1322 >                        if (vn != NULL)
1323 >                                strcpy(vn, "0");
1324                          return(viewselect);
1325                  }
1326                  if (vn != NULL) {
# Line 1031 | Line 1329 | char   *vn;            /* returned view name */
1329                                  ;
1330                          *vn = '\0';
1331                  }
1034                                                /* view number? */
1035                if (isint(viewselect))
1036                        return(specview(nvalue(VIEWS, atoi(viewselect)-1)));
1332                                                  /* check list */
1333                  while ((mv = nvalue(VIEWS, n++)) != NULL)
1334                          if (matchword(viewselect, mv))
1335                                  return(specview(mv));
1336 +
1337                  return(specview(viewselect));   /* standard view? */
1338          }
1339 + numview:
1340          mv = nvalue(VIEWS, n);          /* use view n */
1341 <        if ((vn != NULL) & (mv != NULL)) {
1342 <                register char   *mv2 = mv;
1343 <                if (*mv2 != '-')
1341 >        if ((vn != NULL) & (mv != NULL))
1342 >                if (*mv != '-') {
1343 >                        char    *mv2 = mv;
1344                          while (*mv2 && !isspace(*mv2))
1345                                  *vn++ = *mv2++;
1346 <                *vn = '\0';
1347 <        }
1346 >                        *vn = '\0';
1347 >                } else
1348 >                        sprintf(vn, "%d", n+1);
1349 >
1350          return(specview(mv));
1351   }
1352  
1353  
1354 < int
1355 < myprintview(vopts, fp)                  /* print out selected view */
1356 < register char   *vopts;
1357 < FILE    *fp;
1354 > static int
1355 > myprintview(                    /* print out selected view */
1356 >        char    *vopts,
1357 >        FILE    *fp
1358 > )
1359   {
1360          VIEW    vwr;
1361          char    buf[128];
1362 <        register char   *cp;
1362 >        char    *cp;
1363 > #ifdef _WIN32
1364 > /* XXX Should we allow something like this for all platforms? */
1365 > /* XXX Or is it still required at all? */
1366   again:
1367 + #endif
1368          if (vopts == NULL)
1369                  return(-1);
1370   #ifdef _WIN32
# Line 1083 | Line 1387 | again:
1387   }
1388  
1389  
1390 < rvu(opts, po)                           /* run rvu with first view */
1391 < char    *opts, *po;
1390 > static void
1391 > rvu(                            /* run rvu with first view */
1392 >        char    *opts,
1393 >        char    *po
1394 > )
1395   {
1396          char    *vw;
1397          char    combuf[PATH_MAX];
# Line 1093 | Line 1400 | char   *opts, *po;
1400                  return;
1401          if (sayview)
1402                  myprintview(vw, stdout);
1403 <        sprintf(combuf, "rvu %s%s%s -R %s ", vw, po, opts, rifname);
1403 >        sprintf(combuf, "%s %s%s%s -R %s ", c_rvu, vw, opts, po, rifname);
1404 >        if (nprocs > 1)
1405 >                sprintf(combuf+strlen(combuf), "-n %d ", nprocs);
1406          if (rvdevice != NULL)
1407                  sprintf(combuf+strlen(combuf), "-o %s ", rvdevice);
1408          if (vdef(EXPOSURE))
1409                  sprintf(combuf+strlen(combuf), "-pe %s ", vval(EXPOSURE));
1410          strcat(combuf, oct1name);
1411          if (runcom(combuf)) {           /* run it */
1412 <                fprintf(stderr, "%s: error running rvu\n", progname);
1412 >                fprintf(stderr, "%s: error running %s\n", progname, c_rvu);
1413                  quit(1);
1414          }
1415   }
1416  
1417  
1418 < rpict(opts, po)                         /* run rpict and pfilt for each view */
1419 < char    *opts, *po;
1418 > static int
1419 > syncf_done(                     /* check if an rpiece sync file is complete */
1420 >        char *sfname
1421 > )
1422   {
1423 <        char    combuf[PATH_MAX];
1423 >        FILE    *fp = fopen(sfname, "r");
1424 >        int     todo = 1;
1425 >        int     x, y;
1426 >
1427 >        if (fp == NULL)
1428 >                return(0);
1429 >        if (fscanf(fp, "%d %d", &x, &y) != 2)
1430 >                goto checked;
1431 >        todo = x*y;             /* total number of tiles */
1432 >        if (fscanf(fp, "%d %d", &x, &y) != 2 || (x != 0) | (y != 0))
1433 >                goto checked;
1434 >                                /* XXX assume no redundant tiles */
1435 >        while (fscanf(fp, "%d %d", &x, &y) == 2)
1436 >                if (!--todo)
1437 >                        break;
1438 > checked:
1439 >        fclose(fp);
1440 >        return(!todo);
1441 > }
1442 >
1443 >
1444 > static void
1445 > rpict(                          /* run rpict and pfilt for each view */
1446 >        char    *opts,
1447 >        char    *po
1448 > )
1449 > {
1450 > #define do_rpiece       (sfile[0]!='\0')
1451 >        char    combuf[5*PATH_MAX+512];
1452          char    rawfile[PATH_MAX], picfile[PATH_MAX];
1453          char    zopt[PATH_MAX+4], rep[PATH_MAX+16], res[32];
1454 <        char    rppopt[128], *pfile = NULL;
1454 >        char    rppopt[32], sfile[PATH_MAX], *pfile = NULL;
1455          char    pfopts[128];
1456          char    vs[32], *vw;
1457          int     vn, mult;
1458          FILE    *fp;
1459          time_t  rfdt, pfdt;
1460 +        int     xres, yres;
1461 +        double  aspect;
1462 +        int     n;
1463                                          /* get pfilt options */
1464          pfiltopts(pfopts);
1465                                          /* get resolution, reporting */
# Line 1132 | Line 1474 | char   *opts, *po;
1474                  mult = 3;
1475                  break;
1476          }
1477 <        {
1478 <                int     xres, yres;
1479 <                double  aspect;
1480 <                int     n;
1481 <                n = sscanf(vval(RESOLUTION), "%d %d %lf", &xres, &yres, &aspect);
1482 <                if (n == 3)
1483 <                        sprintf(res, "-x %d -y %d -pa %.3f",
1484 <                                        mult*xres, mult*yres, aspect);
1485 <                else if (n) {
1486 <                        if (n == 1) yres = xres;
1145 <                        sprintf(res, "-x %d -y %d", mult*xres, mult*yres);
1146 <                } else
1147 <                        badvalue(RESOLUTION);
1148 <        }
1477 >        n = sscanf(vval(RESOLUTION), "%d %d %lf", &xres, &yres, &aspect);
1478 >        if (n == 3)
1479 >                sprintf(res, "-x %d -y %d -pa %.3f",
1480 >                                mult*xres, mult*yres, aspect);
1481 >        else if (n) {
1482 >                aspect = 1.;
1483 >                if (n == 1) yres = xres;
1484 >                sprintf(res, "-x %d -y %d", mult*xres, mult*yres);
1485 >        } else
1486 >                badvalue(RESOLUTION);
1487          rep[0] = '\0';
1488          if (vdef(REPORT)) {
1489                  double  minutes;
1152                int     n;
1490                  n = sscanf(vval(REPORT), "%lf %s", &minutes, rawfile);
1491                  if (n == 2)
1492                          sprintf(rep, " -t %d -e %s", (int)(minutes*60), rawfile);
# Line 1159 | Line 1496 | char   *opts, *po;
1496                          badvalue(REPORT);
1497          }
1498                                          /* set up parallel rendering */
1499 <        if ((nprocs > 1) & (!vdef(ZFILE))) {
1500 <                strcpy(rppopt, "-S 1 -PP pfXXXXXX");
1501 <                pfile = rppopt+9;
1502 <                if (mktemp(pfile) == NULL)
1499 >        sfile[0] = '\0';
1500 >        if ((nprocs > 1) & !touchonly & !vdef(ZFILE) &&
1501 >                                        getview(0, vs) != NULL) {
1502 >                if (!strcmp(c_rpict, DEF_RPICT_PATH) &&
1503 >                                getview(1, NULL) == NULL) {
1504 >                        sprintf(sfile, "%s_%s_rpsync.txt",
1505 >                                vdef(RAWFILE) ? vval(RAWFILE) : vval(PICTURE),
1506 >                                        vs);
1507 >                        strcpy(rppopt, "-PP pfXXXXXX");
1508 >                } else {
1509 >                        strcpy(rppopt, "-S 1 -PP pfXXXXXX");
1510 >                }
1511 >                pfile = rppopt + strlen(rppopt) - 8;
1512 >                if (mktemp(pfile) == NULL) {
1513 >                        if (do_rpiece) {
1514 >                                fprintf(stderr, "%s: cannot create\n", pfile);
1515 >                                quit(1);
1516 >                        }
1517                          pfile = NULL;
1518 +                }
1519          }
1520          vn = 0;                                 /* do each view */
1521          while ((vw = getview(vn++, vs)) != NULL) {
1522                  if (sayview)
1523                          myprintview(vw, stdout);
1524 <                if (!vs[0])
1173 <                        sprintf(vs, "%d", vn);
1174 <                sprintf(picfile, "%s_%s.pic", vval(PICTURE), vs);
1524 >                sprintf(picfile, "%s_%s.hdr", vval(PICTURE), vs);
1525                  if (vdef(ZFILE))
1526                          sprintf(zopt, " -z %s_%s.zbf", vval(ZFILE), vs);
1527                  else
# Line 1192 | Line 1542 | char   *opts, *po;
1542                                  touch(picfile);
1543                          continue;
1544                  }
1545 <                if (next_process()) {           /* parallel running? */
1545 >                                                /* parallel running? */
1546 >                if (do_rpiece) {
1547 >                        if (rfdt < oct1date || !fdate(sfile)) {
1548 >                                int     xdiv = 8+nprocs/3, ydiv = 8+nprocs/3;
1549 >                                if (rfdt >= oct1date) {
1550 >                                        fprintf(stderr,
1551 >                "%s: partial output not created with %s\n", rawfile, c_rpiece);
1552 >                                        quit(1);
1553 >                                }
1554 >                                if (rfdt) {     /* start fresh */
1555 >                                        rmfile(rawfile);
1556 >                                        rfdt = 0;
1557 >                                }
1558 >                                if (!silent)
1559 >                                        printf("\techo %d %d > %s\n",
1560 >                                                        xdiv, ydiv, sfile);
1561 >                                if ((fp = fopen(sfile, "w")) == NULL) {
1562 >                                        fprintf(stderr, "%s: cannot create\n",
1563 >                                                        sfile);
1564 >                                        quit(1);
1565 >                                }
1566 >                                fprintf(fp, "%d %d\n", xdiv, ydiv);
1567 >                                fclose(fp);
1568 >                        }
1569 >                } else if (next_process(0)) {
1570                          if (pfile != NULL)
1571 <                                sleep(20);
1571 >                                sleep(10);
1572                          continue;
1573 <                }
1573 >                } else if (!inchild())
1574 >                        pfile = NULL;
1575                  /* XXX Remember to call finish_process() */
1576                                                  /* build rpict command */
1577 <                if (rfdt >= oct1date) {         /* recover */
1578 <                        sprintf(combuf, "rpict%s%s%s%s -ro %s %s",
1579 <                                rep, po, opts, zopt, rawfile, oct1name);
1580 <                        if (runcom(combuf))     /* run rpict */
1577 >                if (rfdt >= oct1date) {         /* already in progress */
1578 >                        if (do_rpiece) {
1579 >                                sprintf(combuf, "%s -R %s %s%s %s %s%s%s -o %s %s",
1580 >                                                c_rpiece, sfile, rppopt, rep, vw,
1581 >                                                res, opts, po, rawfile, oct1name);
1582 >                                while (next_process(1)) {
1583 >                                        sleep(10);
1584 >                                        combuf[strlen(c_rpiece)+2] = 'F';
1585 >                                }
1586 >                        } else
1587 >                                sprintf(combuf, "%s%s%s%s%s -ro %s %s", c_rpict,
1588 >                                        rep, opts, po, zopt, rawfile, oct1name);
1589 >                        if (runcom(combuf))     /* run rpict/rpiece */
1590                                  goto rperror;
1591                  } else {
1592                          if (overture) {         /* run overture calculation */
1593                                  sprintf(combuf,
1594 <                                "rpict%s %s%s -x 64 -y 64 -ps 1 %s > %s",
1595 <                                                rep, vw, opts,
1594 >                                        "%s%s %s%s -x 64 -y 64 -ps 1 %s > %s",
1595 >                                                c_rpict, rep, vw, opts,
1596                                                  oct1name, overfile);
1597 <                                if (runcom(combuf)) {
1598 <                                        fprintf(stderr,
1597 >                                if (!do_rpiece || !next_process(0)) {
1598 >                                        if (runcom(combuf)) {
1599 >                                                fprintf(stderr,
1600                                          "%s: error in overture for view %s\n",
1601 <                                                progname, vs);
1602 <                                        quit(1);
1603 <                                }
1601 >                                                        progname, vs);
1602 >                                                quit(1);
1603 >                                        }
1604   #ifndef NULL_DEVICE
1605 <                                rmfile(overfile);
1605 >                                        rmfile(overfile);
1606   #endif
1607 +                                } else if (do_rpiece)
1608 +                                        sleep(20);
1609                          }
1610 <                        sprintf(combuf, "rpict%s %s %s%s%s%s %s > %s",
1611 <                                        rep, vw, res, po, opts,
1612 <                                        zopt, oct1name, rawfile);
1613 <                        if (pfile != NULL && inchild()) {
1614 <                                                /* rpict persistent mode */
1610 >                        if (do_rpiece) {
1611 >                                sprintf(combuf, "%s -F %s %s%s %s %s%s%s -o %s %s",
1612 >                                                c_rpiece, sfile, rppopt, rep, vw,
1613 >                                                res, opts, po, rawfile, oct1name);
1614 >                                while (next_process(1))
1615 >                                        sleep(10);
1616 >                        } else {
1617 >                                sprintf(combuf, "%s%s %s %s%s%s%s %s > %s",
1618 >                                                c_rpict, rep, vw, res, opts, po,
1619 >                                                zopt, oct1name, rawfile);
1620 >                        }
1621 >                        if ((pfile != NULL) & !do_rpiece) {
1622                                  if (!silent)
1623                                          printf("\t%s\n", combuf);
1230                                sprintf(combuf, "rpict%s %s %s%s%s %s > %s",
1231                                                rep, rppopt, res, po, opts,
1232                                                oct1name, rawfile);
1624                                  fflush(stdout);
1625 +                                sprintf(combuf, "%s%s %s %s%s%s %s > %s",
1626 +                                                c_rpict, rep, rppopt, res,
1627 +                                                opts, po, oct1name, rawfile);
1628                                  fp = popen(combuf, "w");
1629                                  if (fp == NULL)
1630                                          goto rperror;
1631                                  myprintview(vw, fp);
1632                                  if (pclose(fp))
1633                                          goto rperror;
1634 <                        } else {                /* rpict normal mode */
1635 <                                if (runcom(combuf))
1636 <                                        goto rperror;
1634 >                        } else if (runcom(combuf))
1635 >                                goto rperror;
1636 >                }
1637 >                if (do_rpiece) {                /* need to finish raw, first */
1638 >                        finish_process();
1639 >                        wait_process(1);
1640 >                        if (!syncf_done(sfile)) {
1641 >                                fprintf(stderr,
1642 >                        "%s: %s did not complete rendering of view %s\n",
1643 >                                                progname, c_rpiece, vs);
1644 >                                quit(1);
1645                          }
1646                  }
1647                  if (!vdef(RAWFILE) || strcmp(vval(RAWFILE),vval(PICTURE))) {
1648                                                  /* build pfilt command */
1649 <                        if (mult > 1)
1650 <                                sprintf(combuf, "pfilt%s -x /%d -y /%d %s > %s",
1651 <                                        pfopts, mult, mult, rawfile, picfile);
1649 >                        if (do_rpiece)
1650 >                                sprintf(combuf,
1651 >                                        "%s%s -x %d -y %d -p %.3f %s > %s",
1652 >                                        c_pfilt, pfopts, xres, yres, aspect,
1653 >                                        rawfile, picfile);
1654 >                        else if (mult > 1)
1655 >                                sprintf(combuf, "%s%s -x /%d -y /%d %s > %s",
1656 >                                        c_pfilt, pfopts, mult, mult,
1657 >                                        rawfile, picfile);
1658                          else
1659 <                                sprintf(combuf, "pfilt%s %s > %s", pfopts,
1660 <                                                rawfile, picfile);
1659 >                                sprintf(combuf, "%s%s %s > %s", c_pfilt,
1660 >                                        pfopts, rawfile, picfile);
1661                          if (runcom(combuf)) {   /* run pfilt */
1662                                  fprintf(stderr,
1663                                  "%s: error filtering view %s\n\t%s removed\n",
# Line 1260 | Line 1668 | char   *opts, *po;
1668                  }
1669                                                  /* remove/rename raw file */
1670                  if (vdef(RAWFILE)) {
1671 <                        sprintf(combuf, "%s_%s.pic", vval(RAWFILE), vs);
1671 >                        sprintf(combuf, "%s_%s.hdr", vval(RAWFILE), vs);
1672                          mvfile(rawfile, combuf);
1673                  } else
1674                          rmfile(rawfile);
1675 <                finish_process();               /* exit if child */
1675 >                if (do_rpiece)                  /* done with sync file */
1676 >                        rmfile(sfile);
1677 >                else
1678 >                        finish_process();       /* exit if child */
1679          }
1680          wait_process(1);                /* wait for children to finish */
1681 <        if (pfile != NULL) {            /* clean up rpict persistent mode */
1682 <                int     pid;
1681 >        if (pfile != NULL) {            /* clean up persistent rpict */
1682 >                RT_PID  pid;
1683                  fp = fopen(pfile, "r");
1684                  if (fp != NULL) {
1685                          if (fscanf(fp, "%*s %d", &pid) != 1 ||
# Line 1281 | Line 1692 | char   *opts, *po;
1692   rperror:
1693          fprintf(stderr, "%s: error rendering view %s\n", progname, vs);
1694          quit(1);
1695 + #undef do_rpiece
1696   }
1697  
1698  
1699 < touch(fn)                       /* update a file */
1700 < char    *fn;
1699 > static int
1700 > touch(                  /* update a file */
1701 >        char    *fn
1702 > )
1703   {
1704          if (!silent)
1705                  printf("\ttouch %s\n", fn);
1706          if (!nprocs)
1707                  return(0);
1294 #ifdef notused
1295        if (access(fn, F_OK) == -1)             /* create it */
1296                if (close(open(fn, O_WRONLY|O_CREAT, 0666)) == -1)
1297                        return(-1);
1298 #endif
1708          return(setfdate(fn, time((time_t *)NULL)));
1709   }
1710  
1711  
1712 < runcom(cs)                      /* run command */
1713 < char    *cs;
1712 > static int
1713 > runcom(                 /* run command */
1714 >        char    *cs
1715 > )
1716   {
1717          if (!silent)            /* echo it */
1718                  printf("\t%s\n", cs);
1719          if (!nprocs)
1720                  return(0);
1721 <        fflush(stdout);         /* flush output and pass to shell */
1721 >        fflush(NULL);           /* flush output and pass to shell */
1722          return(system(cs));
1723   }
1724  
1725  
1726 < rmfile(fn)                      /* remove a file */
1727 < char    *fn;
1726 > static int
1727 > rmfile(                 /* remove a file */
1728 >        char    *fn
1729 > )
1730   {
1731          if (!silent)
1732                  printf("\t%s %s\n", DELCMD, fn);
# Line 1323 | Line 1736 | char   *fn;
1736   }
1737  
1738  
1739 < mvfile(fold, fnew)              /* move a file */
1740 < char    *fold, *fnew;
1739 > static int
1740 > mvfile(         /* move a file */
1741 >        char    *fold,
1742 >        char    *fnew
1743 > )
1744   {
1745          if (!silent)
1746                  printf("\t%s %s %s\n", RENAMECMD, fold, fnew);
# Line 1335 | Line 1751 | char   *fold, *fnew;
1751  
1752  
1753   #ifdef RHAS_FORK_EXEC
1754 < int
1755 < next_process()                  /* fork the next process (max. nprocs) */
1754 > static int
1755 > next_process(int reserve)               /* fork the next process */
1756   {
1757 <        int     child_pid;
1757 >        RT_PID  child_pid;
1758  
1759          if (nprocs <= 1)
1760                  return(0);              /* it's us or no one */
# Line 1347 | Line 1763 | next_process()                 /* fork the next process (max. nprocs
1763                                  progname);
1764                  quit(1);
1765          }
1766 +        if (reserve > 0 && children_running >= nprocs-reserve)
1767 +                return(0);              /* caller holding back process(es) */
1768          if (children_running >= nprocs)
1769                  wait_process(0);        /* wait for someone to finish */
1770 <        fflush(stdout);
1770 >        fflush(NULL);                   /* flush output */
1771          child_pid = fork();             /* split process */
1772          if (child_pid == 0) {           /* we're the child */
1773                  children_running = -1;
1774 +                nprocs = 1;
1775                  return(0);
1776          }
1777          if (child_pid > 0) {            /* we're the parent */
# Line 1363 | Line 1782 | next_process()                 /* fork the next process (max. nprocs
1782          return(0);
1783   }
1784  
1785 < wait_process(all)                       /* wait for process(es) to finish */
1786 < int     all;
1785 > static void
1786 > wait_process(                   /* wait for process(es) to finish */
1787 >        int     all
1788 > )
1789   {
1790 <        int     ourstatus = 0;
1791 <        int     pid, status;
1790 >        int     ourstatus = 0, status;
1791 >        RT_PID  pid;
1792  
1793          if (all)
1794                  all = children_running;
# Line 1391 | Line 1812 | int    all;
1812                  quit(ourstatus);        /* bad status from child */
1813   }
1814   #else   /* ! RHAS_FORK_EXEC */
1815 < int
1816 < next_process()
1815 > static int
1816 > next_process(int reserve)
1817   {
1818          return(0);                      /* cannot start new process */
1819   }
1820 + static void
1821   wait_process(all)
1822   int     all;
1823   {
# Line 1403 | Line 1825 | int    all;
1825   }
1826   int
1827   kill(pid, sig) /* win|unix_process.c should also wait and kill */
1828 < int pid, sig;
1828 > RT_PID pid;
1829 > int sig;
1830   {
1831          return 0;
1832   }
1833   #endif  /* ! RHAS_FORK_EXEC */
1834  
1835 < finish_process()                        /* exit a child process */
1835 > static void
1836 > finish_process(void)                    /* exit a child process */
1837   {
1838          if (!inchild())
1839                  return;                 /* in parent -- noop */
1840          exit(0);
1841   }
1842  
1419 #ifdef _WIN32
1420 setenv(vname, value)            /* set an environment variable */
1421 char    *vname, *value;
1422 {
1423        register char   *evp;
1843  
1844 <        evp = bmalloc(strlen(vname)+strlen(value)+2);
1845 <        if (evp == NULL)
1846 <                syserr(progname);
1847 <        sprintf(evp, "%s=%s", vname, value);
1429 <        if (putenv(evp) != 0) {
1430 <                fprintf(stderr, "%s: out of environment space\n", progname);
1431 <                quit(1);
1432 <        }
1433 <        if (!silent)
1434 <                printf("set %s\n", evp);
1435 < }
1436 < #endif
1437 <
1438 <
1439 < badvalue(vc)                    /* report bad variable value and exit */
1440 < int     vc;
1844 > static void
1845 > badvalue(                       /* report bad variable value and exit */
1846 >        int     vc
1847 > )
1848   {
1849          fprintf(stderr, "%s: bad value for variable '%s'\n",
1850                          progname, vnam(vc));
# Line 1445 | Line 1852 | int    vc;
1852   }
1853  
1854  
1855 < syserr(s)                       /* report a system error and exit */
1856 < char    *s;
1855 > static void
1856 > syserr(                 /* report a system error and exit */
1857 >        char    *s
1858 > )
1859   {
1860          perror(s);
1861          quit(1);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines