ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/util/ranimate.c
Revision: 2.42
Committed: Tue Oct 21 19:19:29 2003 UTC (20 years, 6 months ago) by schorsch
Content type: text/plain
Branch: MAIN
Changes since 2.41: +1 -5 lines
Log Message:
Various platform compatibility fixes.

File Contents

# Content
1 #ifndef lint
2 static const char RCSid[] = "$Id: ranimate.c,v 2.41 2003/07/27 22:12:03 schorsch Exp $";
3 #endif
4 /*
5 * Radiance animation control program
6 *
7 * The main difference between this program and ranimove is that
8 * we have many optimizations here for camera motion in static
9 * environments, calling rpict and pinterp on multiple processors,
10 * where ranimove puts its emphasis on object motion, and does
11 * not use any external programs for image generation.
12 *
13 * See the ranimate(1) man page for further details.
14 */
15
16 #include "copyright.h"
17
18 #include <ctype.h>
19 #include <sys/stat.h>
20
21 #include "standard.h"
22 #include "paths.h"
23 #include "view.h"
24 #include "vars.h"
25 #include "netproc.h"
26 /* default blur samples */
27 #ifndef DEF_NBLUR
28 #define DEF_NBLUR 5
29 #endif
30 /* default remote shell */
31 #define REMSH "rsh"
32 /* input variables (alphabetical by name) */
33 #define ANIMATE 0 /* animation command */
34 #define ARCHIVE 1 /* archiving command */
35 #define BASENAME 2 /* output image base name */
36 #define DIRECTORY 3 /* working (sub)directory */
37 #define DISKSPACE 4 /* how much disk space to use */
38 #define END 5 /* ending frame number */
39 #define EXPOSURE 6 /* how to compute exposure */
40 #define HOST 7 /* rendering host machine */
41 #define INTERP 8 /* # frames to interpolate */
42 #define MBLUR 9 /* motion blur parameters */
43 #define NEXTANIM 10 /* next animation file */
44 #define OCTREE 11 /* octree file name */
45 #define OVERSAMP 12 /* # times to oversample image */
46 #define PFILT 13 /* pfilt options */
47 #define PINTERP 14 /* pinterp options */
48 #define RENDER 15 /* rendering options */
49 #define RESOLUTION 16 /* desired final resolution */
50 #define RIF 17 /* rad input file */
51 #define RSH 18 /* remote shell script or program */
52 #define RTRACE 19 /* use rtrace with pinterp? */
53 #define START 20 /* starting frame number */
54 #define TRANSFER 21 /* frame transfer command */
55 #define VIEWFILE 22 /* animation frame views */
56
57 int NVARS = 23; /* total number of variables */
58
59 VARIABLE vv[] = { /* variable-value pairs */
60 {"ANIMATE", 2, 0, NULL, onevalue},
61 {"ARCHIVE", 2, 0, NULL, onevalue},
62 {"BASENAME", 3, 0, NULL, onevalue},
63 {"DIRECTORY", 3, 0, NULL, onevalue},
64 {"DISKSPACE", 3, 0, NULL, fltvalue},
65 {"END", 2, 0, NULL, intvalue},
66 {"EXPOSURE", 3, 0, NULL, onevalue},
67 {"host", 4, 0, NULL, NULL},
68 {"INTERPOLATE", 3, 0, NULL, intvalue},
69 {"MBLUR", 2, 0, NULL, onevalue},
70 {"NEXTANIM", 3, 0, NULL, onevalue},
71 {"OCTREE", 3, 0, NULL, onevalue},
72 {"OVERSAMPLE", 2, 0, NULL, fltvalue},
73 {"pfilt", 2, 0, NULL, catvalues},
74 {"pinterp", 2, 0, NULL, catvalues},
75 {"render", 3, 0, NULL, catvalues},
76 {"RESOLUTION", 3, 0, NULL, onevalue},
77 {"RIF", 3, 0, NULL, onevalue},
78 {"RSH", 3, 0, NULL, onevalue},
79 {"RTRACE", 2, 0, NULL, boolvalue},
80 {"START", 2, 0, NULL, intvalue},
81 {"TRANSFER", 2, 0, NULL, onevalue},
82 {"VIEWFILE", 2, 0, NULL, onevalue},
83 };
84
85 #define SFNAME "STATUS" /* status file name */
86
87 struct {
88 char host[64]; /* control host name */
89 int pid; /* control process id */
90 char cfname[128]; /* control file name */
91 int rnext; /* next frame to render */
92 int fnext; /* next frame to filter */
93 int tnext; /* next frame to transfer */
94 } astat; /* animation status */
95
96 char *progname; /* our program name */
97 char *cfname; /* our control file name */
98
99 int nowarn = 0; /* turn warnings off? */
100 int silent = 0; /* silent mode? */
101 int noaction = 0; /* take no action? */
102
103 char *remsh; /* remote shell program/script */
104 char rendopt[2048]; /* rendering options */
105 char rresopt[32]; /* rendering resolution options */
106 char fresopt[32]; /* filter resolution options */
107 int pfiltalways; /* always use pfilt? */
108
109 char arcargs[10240]; /* files to archive */
110 char *arcfirst, *arcnext; /* pointers to first and next argument */
111
112 struct pslot {
113 int pid; /* process ID (0 if empty) */
114 int fout; /* output frame number */
115 int (*rcvf)(); /* recover function */
116 } *pslot; /* process slots */
117 int npslots; /* number of process slots */
118
119 #define phostname(ps) ((ps)->hostname[0] ? (ps)->hostname : astat.host)
120
121 struct pslot *findpslot();
122
123 PSERVER *lastpserver; /* last process server with error */
124
125 VIEW *getview();
126 char *getexp(), *dirfile();
127 int getblur();
128
129 extern time_t time();
130
131
132 main(argc, argv)
133 int argc;
134 char *argv[];
135 {
136 int explicate = 0;
137 int i;
138
139 progname = argv[0]; /* get arguments */
140 for (i = 1; i < argc && argv[i][0] == '-'; i++)
141 switch (argv[i][1]) {
142 case 'e': /* print variables */
143 explicate++;
144 break;
145 case 'w': /* turn off warnings */
146 nowarn++;
147 break;
148 case 's': /* silent mode */
149 silent++;
150 break;
151 case 'n': /* take no action */
152 noaction++;
153 break;
154 default:
155 goto userr;
156 }
157 if (i != argc-1)
158 goto userr;
159 cfname = argv[i];
160 /* load variables */
161 loadvars(cfname);
162 /* check variables */
163 checkvalues();
164 /* did we get DIRECTORY? */
165 checkdir();
166 /* check status */
167 if (getastat() < 0) {
168 fprintf(stderr, "%s: exiting\n", progname);
169 quit(1);
170 }
171 /* pfilt always if options given */
172 pfiltalways = vdef(PFILT);
173 /* load RIF if any */
174 if (vdef(RIF))
175 getradfile(vval(RIF));
176 /* set defaults */
177 setdefaults();
178 /* print variables */
179 if (explicate)
180 printvars(stdout);
181 /* set up process servers */
182 sethosts();
183 /* run animation */
184 animate();
185 /* all done */
186 if (vdef(NEXTANIM)) {
187 argv[i] = vval(NEXTANIM); /* just change input file */
188 if (!silent)
189 printargs(argc, argv, stdout);
190 if ((argv[0] = getpath(progname,getenv("PATH"),X_OK)) == NULL)
191 fprintf(stderr, "%s: command not found\n", progname);
192 else
193 execv(progname, argv);
194 quit(1);
195 }
196 quit(0);
197 userr:
198 fprintf(stderr, "Usage: %s [-s][-n][-w][-e] anim_file\n", progname);
199 quit(1);
200 }
201
202
203 getastat() /* check/set animation status */
204 {
205 char sfname[256];
206 FILE *fp;
207
208 sprintf(sfname, "%s/%s", vval(DIRECTORY), SFNAME);
209 if ((fp = fopen(sfname, "r")) == NULL) {
210 if (errno != ENOENT) {
211 perror(sfname);
212 return(-1);
213 }
214 astat.rnext = astat.fnext = astat.tnext = 0;
215 goto setours;
216 }
217 if (fscanf(fp, "Control host: %s\n", astat.host) != 1)
218 goto fmterr;
219 if (fscanf(fp, "Control PID: %d\n", &astat.pid) != 1)
220 goto fmterr;
221 if (fscanf(fp, "Control file: %s\n", astat.cfname) != 1)
222 goto fmterr;
223 if (fscanf(fp, "Next render: %d\n", &astat.rnext) != 1)
224 goto fmterr;
225 if (fscanf(fp, "Next filter: %d\n", &astat.fnext) != 1)
226 goto fmterr;
227 if (fscanf(fp, "Next transfer: %d\n", &astat.tnext) != 1)
228 goto fmterr;
229 fclose(fp);
230 if (astat.pid != 0) { /* thinks it's still running */
231 if (strcmp(myhostname(), astat.host)) {
232 fprintf(stderr,
233 "%s: process %d may still be running on host %s\n",
234 progname, astat.pid, astat.host);
235 return(-1);
236 }
237 if (kill(astat.pid, 0) != -1 || errno != ESRCH) {
238 fprintf(stderr, "%s: process %d is still running\n",
239 progname, astat.pid);
240 return(-1);
241 }
242 /* assume it is dead */
243 }
244 if (strcmp(cfname, astat.cfname) && astat.pid != 0) { /* other's */
245 fprintf(stderr, "%s: unfinished job \"%s\"\n",
246 progname, astat.cfname);
247 return(-1);
248 }
249 /* check control file mods. */
250 if (!nowarn && fdate(cfname) > fdate(sfname))
251 fprintf(stderr,
252 "%s: warning - control file modified since last run\n",
253 progname);
254 setours: /* set our values */
255 strcpy(astat.host, myhostname());
256 astat.pid = getpid();
257 strcpy(astat.cfname, cfname);
258 return(0);
259 fmterr:
260 fprintf(stderr, "%s: format error in status file \"%s\"\n",
261 progname, sfname);
262 fclose(fp);
263 return(-1);
264 }
265
266
267 putastat() /* put out current status */
268 {
269 char buf[256];
270 FILE *fp;
271
272 if (noaction)
273 return;
274 sprintf(buf, "%s/%s", vval(DIRECTORY), SFNAME);
275 if ((fp = fopen(buf, "w")) == NULL) {
276 perror(buf);
277 quit(1);
278 }
279 fprintf(fp, "Control host: %s\n", astat.host);
280 fprintf(fp, "Control PID: %d\n", astat.pid);
281 fprintf(fp, "Control file: %s\n", astat.cfname);
282 fprintf(fp, "Next render: %d\n", astat.rnext);
283 fprintf(fp, "Next filter: %d\n", astat.fnext);
284 fprintf(fp, "Next transfer: %d\n", astat.tnext);
285 fclose(fp);
286 }
287
288
289 checkdir() /* make sure we have our directory */
290 {
291 struct stat stb;
292
293 if (!vdef(DIRECTORY)) {
294 fprintf(stderr, "%s: %s undefined\n",
295 progname, vnam(DIRECTORY));
296 quit(1);
297 }
298 if (stat(vval(DIRECTORY), &stb) == -1) {
299 if (errno == ENOENT && mkdir(vval(DIRECTORY), 0777) == 0)
300 return;
301 perror(vval(DIRECTORY));
302 quit(1);
303 }
304 if (!(stb.st_mode & S_IFDIR)) {
305 fprintf(stderr, "%s: not a directory\n", vval(DIRECTORY));
306 quit(1);
307 }
308 }
309
310
311 setdefaults() /* set default values */
312 {
313 extern char *atos();
314 int decades;
315 char buf[256];
316
317 if (vdef(ANIMATE)) {
318 vval(OCTREE) = NULL;
319 vdef(OCTREE) = 0;
320 } else if (!vdef(OCTREE)) {
321 fprintf(stderr, "%s: either %s or %s must be defined\n",
322 progname, vnam(OCTREE), vnam(ANIMATE));
323 quit(1);
324 }
325 if (!vdef(VIEWFILE)) {
326 fprintf(stderr, "%s: %s undefined\n", progname, vnam(VIEWFILE));
327 quit(1);
328 }
329 if (!vdef(HOST)) {
330 vval(HOST) = LHOSTNAME;
331 vdef(HOST)++;
332 }
333 if (!vdef(START)) {
334 vval(START) = "1";
335 vdef(START)++;
336 }
337 if (!vdef(END)) {
338 sprintf(buf, "%d", countviews()+vint(START)-1);
339 vval(END) = savqstr(buf);
340 vdef(END)++;
341 }
342 if (vint(END) < vint(START)) {
343 fprintf(stderr, "%s: ending frame less than starting frame\n",
344 progname);
345 quit(1);
346 }
347 if (!vdef(BASENAME)) {
348 decades = (int)log10((double)vint(END)) + 1;
349 if (decades < 3) decades = 3;
350 sprintf(buf, "%s/frame%%0%dd", vval(DIRECTORY), decades);
351 vval(BASENAME) = savqstr(buf);
352 vdef(BASENAME)++;
353 }
354 if (!vdef(RESOLUTION)) {
355 vval(RESOLUTION) = "640";
356 vdef(RESOLUTION)++;
357 }
358 if (!vdef(OVERSAMP)) {
359 vval(OVERSAMP) = "2";
360 vdef(OVERSAMP)++;
361 }
362 if (!vdef(INTERP)) {
363 vval(INTERP) = "0";
364 vdef(INTERP)++;
365 }
366 if (!vdef(MBLUR)) {
367 vval(MBLUR) = "0";
368 vdef(MBLUR)++;
369 }
370 if (!vdef(RTRACE)) {
371 vval(RTRACE) = "F";
372 vdef(RTRACE)++;
373 }
374 if (!vdef(DISKSPACE)) {
375 if (!nowarn)
376 fprintf(stderr,
377 "%s: warning - no %s setting, assuming 100 Mbytes available\n",
378 progname, vnam(DISKSPACE));
379 vval(DISKSPACE) = "100";
380 vdef(DISKSPACE)++;
381 }
382 if (!vdef(RSH)) {
383 vval(RSH) = REMSH;
384 vdef(RSH)++;
385 }
386 /* locate remote shell program */
387 atos(buf, sizeof(buf), vval(RSH));
388 if ((remsh = getpath(buf, getenv("PATH"), X_OK)) != NULL)
389 remsh = savqstr(remsh);
390 else
391 remsh = vval(RSH); /* will generate error if used */
392
393 /* append rendering options */
394 if (vdef(RENDER))
395 sprintf(rendopt+strlen(rendopt), " %s", vval(RENDER));
396 }
397
398
399 sethosts() /* set up process servers */
400 {
401 extern char *iskip();
402 char buf[256], *dir, *uname;
403 int np;
404 register char *cp;
405 int i;
406
407 npslots = 0;
408 if (noaction)
409 return;
410 for (i = 0; i < vdef(HOST); i++) { /* add each host */
411 dir = uname = NULL;
412 np = 1;
413 strcpy(cp=buf, nvalue(HOST, i)); /* copy to buffer */
414 cp = sskip(cp); /* skip host name */
415 while (isspace(*cp))
416 *cp++ = '\0';
417 if (*cp) { /* has # processes? */
418 np = atoi(cp);
419 if ((cp = iskip(cp)) == NULL || (*cp && !isspace(*cp)))
420 badvalue(HOST);
421 while (isspace(*cp))
422 cp++;
423 if (*cp) { /* has directory? */
424 dir = cp;
425 cp = sskip(cp); /* skip dir. */
426 while (isspace(*cp))
427 *cp++ = '\0';
428 if (*cp) { /* has user? */
429 uname = cp;
430 if (*sskip(cp))
431 badvalue(HOST);
432 }
433 }
434 }
435 if (addpserver(buf, dir, uname, np) == NULL) {
436 if (!nowarn)
437 fprintf(stderr,
438 "%s: cannot execute on host \"%s\"\n",
439 progname, buf);
440 } else
441 npslots += np;
442 }
443 if (npslots == 0) {
444 fprintf(stderr, "%s: no working process servers\n", progname);
445 quit(1);
446 }
447 pslot = (struct pslot *)calloc(npslots, sizeof(struct pslot));
448 if (pslot == NULL) {
449 perror("malloc");
450 quit(1);
451 }
452 }
453
454
455 getradfile(rfargs) /* run rad and get needed variables */
456 char *rfargs;
457 {
458 static short mvar[] = {OCTREE,PFILT,RESOLUTION,EXPOSURE,-1};
459 char combuf[256];
460 register int i;
461 register char *cp;
462 char *pippt;
463 /* create rad command */
464 sprintf(rendopt, " @%s/render.opt", vval(DIRECTORY));
465 sprintf(combuf,
466 "rad -v 0 -s -e -w %s OPTFILE=%s | egrep '^[ \t]*(NOMATCH",
467 rfargs, rendopt+2);
468 cp = combuf;
469 while (*cp) {
470 if (*cp == '|') pippt = cp;
471 cp++;
472 } /* match unset variables */
473 for (i = 0; mvar[i] >= 0; i++)
474 if (!vdef(mvar[i])) {
475 *cp++ = '|';
476 strcpy(cp, vnam(mvar[i]));
477 while (*cp) cp++;
478 pippt = NULL;
479 }
480 if (pippt != NULL)
481 strcpy(pippt, "> " NULL_DEVICE); /* nothing to match */
482 else {
483 sprintf(cp, ")[ \t]*=' > %s/radset.var", vval(DIRECTORY));
484 cp += 11; /* point to file name */
485 }
486 system(combuf); /* ignore exit code */
487 if (pippt == NULL) { /* load variables and remove file */
488 loadvars(cp);
489 unlink(cp);
490 }
491 }
492
493
494 animate() /* run animation */
495 {
496 int xres, yres;
497 float pa, mult;
498 int frames_batch;
499 register int i;
500 double d1, d2;
501 /* compute rpict resolution */
502 i = sscanf(vval(RESOLUTION), "%d %d %f", &xres, &yres, &pa);
503 mult = vflt(OVERSAMP);
504 if (i == 3) {
505 sprintf(rresopt, "-x %d -y %d -pa %.3f", (int)(mult*xres),
506 (int)(mult*yres), pa);
507 sprintf(fresopt, "-x %d -y %d -pa %.3f", xres, yres, pa);
508 } else if (i) {
509 if (i == 1) yres = xres;
510 sprintf(rresopt, "-x %d -y %d", (int)(mult*xres),
511 (int)(mult*yres));
512 sprintf(fresopt, "-x %d -y %d -pa 1", xres, yres);
513 } else
514 badvalue(RESOLUTION);
515 /* consistency checks */
516 if (vdef(ANIMATE)) {
517 if (vint(INTERP)) {
518 if (!nowarn)
519 fprintf(stderr,
520 "%s: resetting %s=0 for animation\n",
521 progname, vnam(INTERP));
522 vval(INTERP) = "0";
523 }
524 if (strcmp(vval(MBLUR),"0")) { /* can't handle this */
525 if (!nowarn)
526 fprintf(stderr,
527 "%s: resetting %s=0 for animation\n",
528 progname, vnam(MBLUR));
529 vval(MBLUR) = "0";
530 }
531 }
532 /* figure # frames per batch */
533 d1 = mult*xres*mult*yres*4; /* space for orig. picture */
534 if ((i=vint(INTERP)) || getblur(NULL) > 1)
535 d1 += mult*xres*mult*yres*sizeof(float); /* Z-buffer */
536 d2 = xres*yres*4; /* space for final picture */
537 frames_batch = (i+1)*(vflt(DISKSPACE)*1048576.-d1)/(d1+i*d2);
538 if (frames_batch < i+2) {
539 fprintf(stderr, "%s: insufficient disk space allocated\n",
540 progname);
541 quit(1);
542 }
543 /* initialize archive argument list */
544 i = vdef(ARCHIVE) ? strlen(vval(ARCHIVE))+132 : 132;
545 arcnext = arcfirst = arcargs + i;
546 /* initialize status file */
547 if (astat.rnext == 0)
548 astat.rnext = astat.fnext = astat.tnext = vint(START);
549 putastat();
550 /* render in batches */
551 while (astat.tnext <= vint(END)) {
552 renderframes(frames_batch);
553 filterframes();
554 transferframes();
555 }
556 /* mark status as finished */
557 astat.pid = 0;
558 putastat();
559 /* close open files */
560 getview(0);
561 getexp(0);
562 }
563
564
565 renderframes(nframes) /* render next nframes frames */
566 int nframes;
567 {
568 static char vendbuf[16];
569 VIEW *vp;
570 FILE *fp = NULL;
571 char vfname[128];
572 int lastframe;
573 register int i;
574
575 if (astat.tnext < astat.rnext) /* other work to do first */
576 return;
577 /* create batch view file */
578 if (!vdef(ANIMATE)) {
579 sprintf(vfname, "%s/anim.vf", vval(DIRECTORY));
580 if ((fp = fopen(vfname, "w")) == NULL) {
581 perror(vfname);
582 quit(1);
583 }
584 }
585 /* bound batch properly */
586 lastframe = astat.rnext + nframes - 1;
587 if ((lastframe-1) % (vint(INTERP)+1)) /* need even interval */
588 lastframe += vint(INTERP)+1 - ((lastframe-1)%(vint(INTERP)+1));
589 if (lastframe > vint(END)) /* check for end */
590 lastframe = vint(END);
591 /* render each view */
592 for (i = astat.rnext; i <= lastframe; i++) {
593 if ((vp = getview(i)) == NULL) {
594 if (!nowarn)
595 fprintf(stderr,
596 "%s: ran out of views before last frame\n",
597 progname);
598 sprintf(vval(END)=vendbuf, "%d", i-1);
599 lastframe = i - 1;
600 break;
601 }
602 if (vdef(ANIMATE)) /* animate frame */
603 animrend(i, vp);
604 else { /* else record it */
605 fputs(VIEWSTR, fp);
606 fprintview(vp, fp);
607 putc('\n', fp);
608 }
609 }
610 if (vdef(ANIMATE)) /* wait for renderings to finish */
611 bwait(0);
612 else { /* else if walk-through */
613 fclose(fp); /* close view file */
614 walkwait(astat.rnext, lastframe, vfname); /* walk it */
615 unlink(vfname); /* remove view file */
616 }
617 astat.rnext = i; /* update status */
618 putastat();
619 }
620
621
622 filterframes() /* catch up with filtering */
623 {
624 VIEW *vp;
625 register int i;
626
627 if (astat.tnext < astat.fnext) /* other work to do first */
628 return;
629 /* filter each view */
630 for (i = astat.fnext; i < astat.rnext; i++)
631 dofilt(i, 0);
632
633 bwait(0); /* wait for filter processes */
634 archive(); /* archive originals */
635 astat.fnext = i; /* update status */
636 putastat();
637 }
638
639
640 transferframes() /* catch up with picture transfers */
641 {
642 char combuf[10240], *fbase;
643 register char *cp;
644 register int i;
645
646 if (astat.tnext >= astat.fnext) /* nothing to do, yet */
647 return;
648 if (!vdef(TRANSFER)) { /* no transfer function -- leave 'em */
649 astat.tnext = astat.fnext;
650 putastat(); /* update status */
651 return;
652 }
653 strcpy(combuf, "cd "); /* start transfer command */
654 fbase = dirfile(cp = combuf+3, vval(BASENAME));
655 if (*cp) {
656 while (*++cp) ;
657 *cp++ = ';'; *cp++ = ' ';
658 } else
659 cp = combuf;
660 strcpy(cp, vval(TRANSFER));
661 while (*cp) cp++;
662 /* make argument list */
663 for (i = astat.tnext; i < astat.fnext; i++) {
664 *cp++ = ' ';
665 sprintf(cp, fbase, i);
666 while (*cp) cp++;
667 strcpy(cp, ".pic");
668 cp += 4;
669 }
670 if (runcom(combuf)) { /* transfer frames */
671 fprintf(stderr, "%s: error running transfer command\n",
672 progname);
673 quit(1);
674 }
675 astat.tnext = i; /* update status */
676 putastat();
677 }
678
679
680 animrend(frame, vp) /* start animation frame */
681 int frame;
682 VIEW *vp;
683 {
684 extern int recover();
685 char combuf[2048];
686 char fname[128];
687
688 sprintf(fname, vval(BASENAME), frame);
689 strcat(fname, ".unf");
690 if (access(fname, F_OK) == 0)
691 return;
692 sprintf(combuf, "%s %d | rpict%s%s -w0 %s > %s", vval(ANIMATE), frame,
693 rendopt, viewopt(vp), rresopt, fname);
694 bruncom(combuf, frame, recover); /* run in background */
695 }
696
697
698 walkwait(first, last, vfn) /* walk-through frames */
699 int first, last;
700 char *vfn;
701 {
702 double blurf;
703 int nblur = getblur(&blurf);
704 char combuf[2048];
705 register char *inspoint;
706 register int i;
707
708 if (!noaction && vint(INTERP)) /* create dummy frames */
709 for (i = first; i <= last; i++)
710 if (i < vint(END) && (i-1) % (vint(INTERP)+1)) {
711 sprintf(combuf, vval(BASENAME), i);
712 strcat(combuf, ".unf");
713 close(open(combuf, O_RDONLY|O_CREAT, 0666));
714 }
715 /* create command */
716 sprintf(combuf, "rpict%s%s -w0", rendopt,
717 viewopt(getview(first>1 ? first-1 : 1)));
718 inspoint = combuf;
719 while (*inspoint) inspoint++;
720 if (nblur) {
721 sprintf(inspoint, " -pm %.3f", blurf/nblur);
722 while (*inspoint) inspoint++;
723 }
724 if (nblur > 1 || vint(INTERP)) {
725 sprintf(inspoint, " -z %s.zbf", vval(BASENAME));
726 while (*inspoint) inspoint++;
727 }
728 sprintf(inspoint, " -o %s.unf %s -S %d",
729 vval(BASENAME), rresopt, first);
730 while (*inspoint) inspoint++;
731 sprintf(inspoint, " %s < %s", vval(OCTREE), vfn);
732 /* run in parallel */
733 i = (last-first+1)/(vint(INTERP)+1);
734 if (i < 1) i = 1;
735 if (pruncom(combuf, inspoint, i)) {
736 fprintf(stderr, "%s: error rendering frames %d through %d\n",
737 progname, first, last);
738 quit(1);
739 }
740 if (!noaction && vint(INTERP)) /* remove dummy frames */
741 for (i = first; i <= last; i++)
742 if (i < vint(END) && (i-1) % (vint(INTERP)+1)) {
743 sprintf(combuf, vval(BASENAME), i);
744 strcat(combuf, ".unf");
745 unlink(combuf);
746 }
747 }
748
749
750 int
751 recover(frame) /* recover the specified frame */
752 int frame;
753 {
754 static int *rfrm; /* list of recovered frames */
755 static int nrfrms = 0;
756 double blurf;
757 int nblur = getblur(&blurf);
758 char combuf[2048];
759 char fname[128];
760 register char *cp;
761 register int i;
762 /* check to see if recovered already */
763 for (i = nrfrms; i--; )
764 if (rfrm[i] == frame)
765 return(0);
766 /* build command */
767 sprintf(fname, vval(BASENAME), frame);
768 if (vdef(ANIMATE))
769 sprintf(combuf, "%s %d | rpict%s -w0",
770 vval(ANIMATE), frame, rendopt);
771 else
772 sprintf(combuf, "rpict%s -w0", rendopt);
773 cp = combuf;
774 while (*cp) cp++;
775 if (nblur) {
776 sprintf(cp, " -pm %.3f", blurf/nblur);
777 while (*cp) cp++;
778 }
779 if (nblur > 1 || vint(INTERP)) {
780 sprintf(cp, " -z %s.zbf", fname);
781 while (*cp) cp++;
782 }
783 sprintf(cp, " -ro %s.unf", fname);
784 while (*cp) cp++;
785 if (!vdef(ANIMATE)) {
786 *cp++ = ' ';
787 strcpy(cp, vval(OCTREE));
788 }
789 if (runcom(combuf)) /* run command */
790 return(1);
791 /* add frame to recovered list */
792 if (nrfrms)
793 rfrm = (int *)realloc((void *)rfrm, (nrfrms+1)*sizeof(int));
794 else
795 rfrm = (int *)malloc(sizeof(int));
796 if (rfrm == NULL) {
797 perror("malloc");
798 quit(1);
799 }
800 rfrm[nrfrms++] = frame;
801 return(0);
802 }
803
804
805 int
806 frecover(frame) /* recover filtered frame */
807 int frame;
808 {
809 if (dofilt(frame, 2) && dofilt(frame, 1))
810 return(1);
811 return(0);
812 }
813
814
815 archive() /* archive and remove renderings */
816 {
817 #define RMCOML (sizeof(rmcom)-1)
818 static char rmcom[] = "rm -f";
819 char basedir[128];
820 int dlen, alen;
821 register int j;
822
823 if (arcnext == arcfirst)
824 return; /* nothing to do */
825 dirfile(basedir, vval(BASENAME));
826 dlen = strlen(basedir);
827 if (vdef(ARCHIVE)) { /* run archive command */
828 alen = strlen(vval(ARCHIVE));
829 if (dlen) {
830 j = alen + dlen + 5;
831 strncpy(arcfirst-j, "cd ", 3);
832 strncpy(arcfirst-j+3, basedir, dlen);
833 (arcfirst-j)[dlen+3] = ';'; (arcfirst-j)[dlen+4] = ' ';
834 } else
835 j = alen;
836 strncpy(arcfirst-alen, vval(ARCHIVE), alen);
837 if (runcom(arcfirst-j)) {
838 fprintf(stderr, "%s: error running archive command\n",
839 progname);
840 quit(1);
841 }
842 }
843 if (dlen) {
844 j = RMCOML + dlen + 5;
845 strncpy(arcfirst-j, "cd ", 3);
846 strncpy(arcfirst-j+3, basedir, dlen);
847 (arcfirst-j)[dlen+3] = ';'; (arcfirst-j)[dlen+4] = ' ';
848 } else
849 j = RMCOML;
850 /* run remove command */
851 strncpy(arcfirst-RMCOML, rmcom, RMCOML);
852 runcom(arcfirst-j);
853 arcnext = arcfirst; /* reset argument list */
854 #undef RMCOML
855 }
856
857
858 int
859 dofilt(frame, rvr) /* filter frame */
860 int frame;
861 int rvr;
862 {
863 extern int frecover();
864 static int iter = 0;
865 double blurf;
866 int nblur = getblur(&blurf);
867 VIEW *vp = getview(frame);
868 char *ep = getexp(frame);
869 char fnbefore[128], fnafter[128], *fbase;
870 char combuf[1024], fname0[128], fname1[128];
871 int usepinterp, usepfilt, nora_rgbe;
872 int frseq[2];
873 /* check what is needed */
874 if (vp == NULL) {
875 fprintf(stderr,
876 "%s: unexpected error reading view for frame %d\n",
877 progname, frame);
878 quit(1);
879 }
880 if (ep == NULL) {
881 fprintf(stderr,
882 "%s: unexpected error reading exposure for frame %d\n",
883 progname, frame);
884 quit(1);
885 }
886 usepinterp = (nblur > 1);
887 usepfilt = pfiltalways | (ep==NULL);
888 if (ep != NULL && !strcmp(ep, "1"))
889 ep = "+0";
890 nora_rgbe = strcmp(vval(OVERSAMP),"1") || ep==NULL ||
891 *ep != '+' || *ep != '-' || !isint(ep);
892 /* compute rendered views */
893 frseq[0] = frame - ((frame-1) % (vint(INTERP)+1));
894 frseq[1] = frseq[0] + vint(INTERP) + 1;
895 fbase = dirfile(NULL, vval(BASENAME));
896 if (frseq[1] > vint(END))
897 frseq[1] = vint(END);
898 if (frseq[1] == frame) { /* pfilt only */
899 frseq[0] = frseq[1];
900 usepinterp = 0; /* update what's needed */
901 usepfilt |= nora_rgbe;
902 } else if (frseq[0] == frame) { /* no interpolation needed */
903 if (!rvr && frame > 1+vint(INTERP)) { /* archive previous */
904 *arcnext++ = ' ';
905 sprintf(arcnext, fbase, frame-vint(INTERP)-1);
906 while (*arcnext) arcnext++;
907 strcpy(arcnext, ".unf");
908 arcnext += 4;
909 if (usepinterp || vint(INTERP)) { /* and Z-buf */
910 *arcnext++ = ' ';
911 sprintf(arcnext, fbase, frame-vint(INTERP)-1);
912 while (*arcnext) arcnext++;
913 strcpy(arcnext, ".zbf");
914 arcnext += 4;
915 }
916 }
917 if (!usepinterp) /* update what's needed */
918 usepfilt |= nora_rgbe;
919 } else /* interpolation needed */
920 usepinterp++;
921 if (frseq[1] >= astat.rnext) /* next batch unavailable */
922 frseq[1] = frseq[0];
923 sprintf(fnbefore, vval(BASENAME), frseq[0]);
924 sprintf(fnafter, vval(BASENAME), frseq[1]);
925 if (rvr == 1 && recover(frseq[0])) /* recover before frame? */
926 return(1);
927 /* generate command */
928 if (usepinterp) { /* using pinterp */
929 if (rvr == 2 && recover(frseq[1])) /* recover after? */
930 return(1);
931 if (nblur > 1) { /* with pmblur */
932 sprintf(fname0, "%s/vw0%c", vval(DIRECTORY),
933 'a'+(iter%26));
934 sprintf(fname1, "%s/vw1%c", vval(DIRECTORY),
935 'a'+(iter%26));
936 if (!noaction) {
937 FILE *fp; /* motion blurring */
938 if ((fp = fopen(fname0, "w")) == NULL) {
939 perror(fname0); quit(1);
940 }
941 fputs(VIEWSTR, fp);
942 fprintview(vp, fp);
943 putc('\n', fp); fclose(fp);
944 if ((vp = getview(frame+1)) == NULL) {
945 fprintf(stderr,
946 "%s: unexpected error reading view for frame %d\n",
947 progname, frame+1);
948 quit(1);
949 }
950 if ((fp = fopen(fname1, "w")) == NULL) {
951 perror(fname1); quit(1);
952 }
953 fputs(VIEWSTR, fp);
954 fprintview(vp, fp);
955 putc('\n', fp); fclose(fp);
956 }
957 sprintf(combuf,
958 "(pmblur %.3f %d %s %s; rm -f %s %s) | pinterp -B -a",
959 blurf, nblur,
960 fname0, fname1, fname0, fname1);
961 iter++;
962 } else /* no blurring */
963 strcpy(combuf, "pinterp");
964 strcat(combuf, viewopt(vp));
965 if (vbool(RTRACE))
966 sprintf(combuf+strlen(combuf), " -ff -fr '%s -w0 %s'",
967 rendopt+1, vval(OCTREE));
968 if (vdef(PINTERP))
969 sprintf(combuf+strlen(combuf), " %s", vval(PINTERP));
970 if (usepfilt)
971 sprintf(combuf+strlen(combuf), " %s", rresopt);
972 else
973 sprintf(combuf+strlen(combuf), " -a %s -e %s",
974 fresopt, ep);
975 sprintf(combuf+strlen(combuf), " %s.unf %s.zbf",
976 fnbefore, fnbefore);
977 if (frseq[1] != frseq[0])
978 sprintf(combuf+strlen(combuf), " %s.unf %s.zbf",
979 fnafter, fnafter);
980 if (usepfilt) { /* also pfilt */
981 if (vdef(PFILT))
982 sprintf(combuf+strlen(combuf), " | pfilt %s",
983 vval(PFILT));
984 else
985 strcat(combuf, " | pfilt");
986 if (ep != NULL)
987 sprintf(combuf+strlen(combuf), " -1 -e %s %s",
988 ep, fresopt);
989 else
990 sprintf(combuf+strlen(combuf), " %s", fresopt);
991 }
992 } else if (usepfilt) { /* pfilt only */
993 if (rvr == 2)
994 return(1);
995 if (vdef(PFILT))
996 sprintf(combuf, "pfilt %s", vval(PFILT));
997 else
998 strcpy(combuf, "pfilt");
999 if (ep != NULL)
1000 sprintf(combuf+strlen(combuf), " -1 -e %s %s %s.unf",
1001 ep, fresopt, fnbefore);
1002 else
1003 sprintf(combuf+strlen(combuf), " %s %s.unf",
1004 fresopt, fnbefore);
1005 } else { /* else just check it */
1006 if (rvr == 2)
1007 return(1);
1008 sprintf(combuf, "ra_rgbe -e %s -r %s.unf", ep, fnbefore);
1009 }
1010 /* output file name */
1011 sprintf(fname0, vval(BASENAME), frame);
1012 sprintf(combuf+strlen(combuf), " > %s.pic", fname0);
1013 if (rvr) /* in recovery */
1014 return(runcom(combuf));
1015 bruncom(combuf, frame, frecover); /* else run in background */
1016 return(0);
1017 }
1018
1019
1020 VIEW *
1021 getview(n) /* get view number n */
1022 int n;
1023 {
1024 static FILE *viewfp = NULL; /* view file pointer */
1025 static int viewnum = 0; /* current view number */
1026 static VIEW curview = STDVIEW; /* current view */
1027 char linebuf[256];
1028
1029 if (n == 0) { /* signal to close file and clean up */
1030 if (viewfp != NULL) {
1031 fclose(viewfp);
1032 viewfp = NULL;
1033 viewnum = 0;
1034 curview = stdview;
1035 }
1036 return(NULL);
1037 }
1038 if (viewfp == NULL) { /* open file */
1039 if ((viewfp = fopen(vval(VIEWFILE), "r")) == NULL) {
1040 perror(vval(VIEWFILE));
1041 quit(1);
1042 }
1043 } else if (n > 0 && n < viewnum) { /* rewind file */
1044 if (viewnum == 1 && feof(viewfp))
1045 return(&curview); /* just one view */
1046 if (fseek(viewfp, 0L, 0) == EOF) {
1047 perror(vval(VIEWFILE));
1048 quit(1);
1049 }
1050 curview = stdview;
1051 viewnum = 0;
1052 }
1053 if (n < 0) { /* get next view */
1054 register int c = getc(viewfp);
1055 if (c == EOF)
1056 return((VIEW *)NULL); /* that's it */
1057 ungetc(c, viewfp);
1058 n = viewnum + 1;
1059 }
1060 while (n > viewnum) { /* scan to desired view */
1061 if (fgets(linebuf, sizeof(linebuf), viewfp) == NULL)
1062 return(viewnum==1 ? &curview : (VIEW *)NULL);
1063 if (isview(linebuf) && sscanview(&curview, linebuf) > 0)
1064 viewnum++;
1065 }
1066 return(&curview); /* return it */
1067 }
1068
1069
1070 int
1071 countviews() /* count views in view file */
1072 {
1073 int n;
1074
1075 if (getview(n=1) == NULL)
1076 return(0);
1077 while (getview(-1) != NULL)
1078 n++;
1079 return(n);
1080 }
1081
1082
1083 char *
1084 getexp(n) /* get exposure for nth frame */
1085 int n;
1086 {
1087 extern char *fskip();
1088 static char expval[32];
1089 static FILE *expfp = NULL;
1090 static long *exppos;
1091 static int curfrm;
1092 register char *cp;
1093
1094 if (n == 0) { /* signal to close file */
1095 if (expfp != NULL) {
1096 fclose(expfp);
1097 free((void *)exppos);
1098 expfp = NULL;
1099 }
1100 return(NULL);
1101 } else if (n > vint(END)) /* request past end (error?) */
1102 return(NULL);
1103 if (!vdef(EXPOSURE)) /* no setting (auto) */
1104 return(NULL);
1105 if (isflt(vval(EXPOSURE))) /* always the same */
1106 return(vval(EXPOSURE));
1107 if (expfp == NULL) { /* open exposure file */
1108 if ((expfp = fopen(vval(EXPOSURE), "r")) == NULL) {
1109 fprintf(stderr,
1110 "%s: cannot open exposure file \"%s\"\n",
1111 progname, vval(EXPOSURE));
1112 quit(1);
1113 }
1114 curfrm = vint(END) + 1; /* init lookup tab. */
1115 exppos = (long *)malloc(curfrm*sizeof(long *));
1116 if (exppos == NULL) {
1117 perror(progname);
1118 quit(1);
1119 }
1120 while (curfrm--)
1121 exppos[curfrm] = -1L;
1122 curfrm = 0;
1123 }
1124 /* find position in file */
1125 if (n-1 != curfrm && n != curfrm && exppos[n-1] >= 0 &&
1126 fseek(expfp, exppos[curfrm=n-1], 0) == EOF) {
1127 fprintf(stderr, "%s: seek error on exposure file\n", progname);
1128 quit(1);
1129 }
1130 while (n > curfrm) { /* read exposure */
1131 if (exppos[curfrm] < 0)
1132 exppos[curfrm] = ftell(expfp);
1133 if (fgets(expval, sizeof(expval), expfp) == NULL) {
1134 fprintf(stderr, "%s: too few exposures\n",
1135 vval(EXPOSURE));
1136 quit(1);
1137 }
1138 curfrm++;
1139 cp = fskip(expval); /* check format */
1140 if (cp != NULL)
1141 while (isspace(*cp))
1142 *cp++ = '\0';
1143 if (cp == NULL || *cp) {
1144 fprintf(stderr,
1145 "%s: exposure format error on line %d\n",
1146 vval(EXPOSURE), curfrm);
1147 quit(1);
1148 }
1149 }
1150 return(expval); /* return value */
1151 }
1152
1153
1154 struct pslot *
1155 findpslot(pid) /* find or allocate a process slot */
1156 int pid;
1157 {
1158 register struct pslot *psempty = NULL;
1159 register int i;
1160
1161 for (i = 0; i < npslots; i++) { /* look for match */
1162 if (pslot[i].pid == pid)
1163 return(pslot+i);
1164 if (psempty == NULL && pslot[i].pid == 0)
1165 psempty = pslot+i;
1166 }
1167 return(psempty); /* return emtpy slot (error if NULL) */
1168 }
1169
1170
1171 int
1172 donecom(ps, pn, status) /* clean up after finished process */
1173 PSERVER *ps;
1174 int pn;
1175 int status;
1176 {
1177 register PROC *pp;
1178 register struct pslot *psl;
1179
1180 pp = ps->proc + pn;
1181 if (pp->elen) { /* pass errors */
1182 if (ps->hostname[0])
1183 fprintf(stderr, "%s: ", ps->hostname);
1184 fprintf(stderr, "Error output from: %s\n", pp->com);
1185 fputs(pp->errs, stderr);
1186 fflush(stderr);
1187 if (ps->hostname[0])
1188 status = 1; /* because rsh doesn't return status */
1189 }
1190 lastpserver = NULL;
1191 psl = findpslot(pp->pid); /* check for bruncom() slot */
1192 if (psl->pid) {
1193 if (status) {
1194 if (psl->rcvf != NULL) /* attempt recovery */
1195 status = (*psl->rcvf)(psl->fout);
1196 if (status) {
1197 fprintf(stderr,
1198 "%s: error rendering frame %d\n",
1199 progname, psl->fout);
1200 quit(1);
1201 }
1202 lastpserver = ps;
1203 }
1204 psl->pid = 0; /* free process slot */
1205 } else if (status)
1206 lastpserver = ps;
1207 freestr(pp->com); /* free command string */
1208 return(status);
1209 }
1210
1211
1212 int
1213 serverdown() /* check status of last process server */
1214 {
1215 if (lastpserver == NULL || !lastpserver->hostname[0])
1216 return(0);
1217 if (pserverOK(lastpserver)) /* server still up? */
1218 return(0);
1219 delpserver(lastpserver); /* else delete it */
1220 if (pslist == NULL) {
1221 fprintf(stderr, "%s: all process servers are down\n",
1222 progname);
1223 quit(1);
1224 }
1225 return(1);
1226 }
1227
1228
1229 int
1230 bruncom(com, fout, rf) /* run a command in the background */
1231 char *com;
1232 int fout;
1233 int (*rf)();
1234 {
1235 int pid;
1236 register struct pslot *psl;
1237
1238 if (noaction) {
1239 if (!silent)
1240 printf("\t%s\n", com); /* echo command */
1241 return(0);
1242 }
1243 com = savestr(com); /* else start it when we can */
1244 while ((pid = startjob(NULL, com, donecom)) == -1)
1245 bwait(1);
1246 if (!silent) { /* echo command */
1247 PSERVER *ps;
1248 int psn = pid;
1249 ps = findjob(&psn);
1250 printf("\t%s\n", com);
1251 printf("\tProcess started on %s\n", phostname(ps));
1252 fflush(stdout);
1253 }
1254 psl = findpslot(pid); /* record info. in appropriate slot */
1255 psl->pid = pid;
1256 psl->fout = fout;
1257 psl->rcvf = rf;
1258 return(pid);
1259 }
1260
1261
1262 bwait(ncoms) /* wait for batch job(s) to finish */
1263 int ncoms;
1264 {
1265 int status;
1266
1267 if (noaction)
1268 return;
1269 while ((status = wait4job(NULL, -1)) != -1) {
1270 serverdown(); /* update server status */
1271 if (--ncoms == 0)
1272 break; /* done enough */
1273 }
1274 }
1275
1276
1277 int
1278 pruncom(com, ppins, maxcopies) /* run a command in parallel over network */
1279 char *com, *ppins;
1280 int maxcopies;
1281 {
1282 int retstatus = 0;
1283 int hostcopies;
1284 char buf[10240], *com1, *s;
1285 int status;
1286 int pfd;
1287 register int n;
1288 register PSERVER *ps;
1289
1290 if (!silent)
1291 printf("\t%s\n", com); /* echo command */
1292 if (noaction)
1293 return(0);
1294 fflush(stdout);
1295 /* start jobs on each server */
1296 for (ps = pslist; ps != NULL; ps = ps->next) {
1297 hostcopies = 0;
1298 if (maxcopies > 1 && ps->nprocs > 1 && ppins != NULL) {
1299 strcpy(com1=buf, com); /* build -PP command */
1300 sprintf(com1+(ppins-com), " -PP %s/%s.persist",
1301 vval(DIRECTORY), phostname(ps));
1302 unlink(com1+(ppins-com)+5);
1303 strcat(com1, ppins);
1304 } else
1305 com1 = com;
1306 while (maxcopies > 0) {
1307 s = savestr(com1);
1308 if (startjob(ps, s, donecom) != -1) {
1309 sleep(20);
1310 hostcopies++;
1311 maxcopies--;
1312 } else {
1313 freestr(s);
1314 break;
1315 }
1316 }
1317 if (!silent && hostcopies) {
1318 if (hostcopies > 1)
1319 printf("\t%d duplicate processes", hostcopies);
1320 else
1321 printf("\tProcess");
1322 printf(" started on %s\n", phostname(ps));
1323 fflush(stdout);
1324 }
1325 }
1326 /* wait for jobs to finish */
1327 while ((status = wait4job(NULL, -1)) != -1)
1328 retstatus += status && !serverdown();
1329 /* terminate parallel rpict's */
1330 for (ps = pslist; ps != NULL; ps = ps->next) {
1331 sprintf(buf, "%s/%s.persist", vval(DIRECTORY), phostname(ps));
1332 if ((pfd = open(buf, O_RDONLY)) >= 0) {
1333 n = read(pfd, buf, sizeof(buf)-1); /* get PID */
1334 buf[n] = '\0';
1335 close(pfd);
1336 for (n = 0; buf[n] && !isspace(buf[n]); n++)
1337 ;
1338 /* terminate */
1339 sprintf(buf, "kill -ALRM %d", atoi(buf+n));
1340 wait4job(ps, startjob(ps, buf, NULL));
1341 }
1342 }
1343 return(retstatus);
1344 }
1345
1346
1347 runcom(cs) /* run a command locally and wait for it */
1348 char *cs;
1349 {
1350 if (!silent) /* echo it */
1351 printf("\t%s\n", cs);
1352 if (noaction)
1353 return(0);
1354 fflush(stdout); /* flush output and pass to shell */
1355 return(system(cs));
1356 }
1357
1358
1359 rmfile(fn) /* remove a file */
1360 char *fn;
1361 {
1362 if (!silent)
1363 #ifdef _WIN32
1364 printf("\tdel %s\n", fn);
1365 #else
1366 printf("\trm -f %s\n", fn);
1367 #endif
1368 if (noaction)
1369 return(0);
1370 return(unlink(fn));
1371 }
1372
1373
1374 badvalue(vc) /* report bad variable value and exit */
1375 int vc;
1376 {
1377 fprintf(stderr, "%s: bad value for variable '%s'\n",
1378 progname, vnam(vc));
1379 quit(1);
1380 }
1381
1382
1383 char *
1384 dirfile(df, path) /* separate path into directory and file */
1385 char *df;
1386 register char *path;
1387 {
1388 register int i;
1389 int psep;
1390
1391 for (i = 0, psep = -1; path[i]; i++)
1392 if (path[i] == '/')
1393 psep = i;
1394 if (df != NULL) {
1395 if (psep == 0) {
1396 df[0] = '/';
1397 df[1] = '\0';
1398 } else if (psep > 0) {
1399 strncpy(df, path, psep);
1400 df[psep] = '\0';
1401 } else
1402 df[0] = '\0';
1403 }
1404 return(path+psep+1);
1405 }
1406
1407
1408 int
1409 getblur(double *bf) /* get # blur samples (and fraction) */
1410 {
1411 double blurf;
1412 int nblur;
1413 char *s;
1414
1415 if (!vdef(MBLUR)) {
1416 if (bf != NULL)
1417 *bf = 0.0;
1418 return(0);
1419 }
1420 blurf = atof(vval(MBLUR));
1421 if (blurf < 0.0)
1422 blurf = 0.0;
1423 if (bf != NULL)
1424 *bf = blurf;
1425 if (blurf <= FTINY)
1426 return(0);
1427 s = sskip(vval(MBLUR));
1428 if (!*s)
1429 return(DEF_NBLUR);
1430 nblur = atoi(s);
1431 if (nblur <= 0)
1432 return(1);
1433 return(nblur);
1434 }