--- ray/src/util/rpiece.c 1993/08/06 17:19:52 2.25 +++ ray/src/util/rpiece.c 1997/07/29 11:27:49 2.35 @@ -1,4 +1,4 @@ -/* Copyright (c) 1993 Regents of the University of California */ +/* Copyright (c) 1995 Regents of the University of California */ #ifndef lint static char SCCSid[] = "$SunId$ LBL"; @@ -39,7 +39,7 @@ char *argv[]; #endif #endif /* protection from SYSV signals(!) */ -#if defined(sgi) || defined(hpux) +#if defined(sgi) #define guard_io() sighold(SIGALRM) #define unguard() sigrelse(SIGALRM) #endif @@ -47,6 +47,11 @@ char *argv[]; #define guard_io() 0 #define unguard() 0 #endif + +#ifndef linux +extern char *sys_errlist[]; +#endif + /* rpict command */ char *rpargv[128] = {"rpict", "-S", "1"}; int rpargc = 3; @@ -69,6 +74,7 @@ int nforked = 0; char *progname; int verbose = 0; +unsigned timelim = 0; int rvrlim = -1; extern long lseek(), ftell(); @@ -118,8 +124,13 @@ char *argv[]; case 'p': /* pixel aspect ratio? */ if (argv[i][2] != 'a' || argv[i][3]) break; - pixaspect = atof(argv[i+1]); + pixaspect = atof(argv[++i]); continue; + case 'T': /* time limit (hours) */ + if (argv[i][2]) + break; + timelim = atof(argv[++i])*3600. + .5; + break; case 'x': /* overall x resolution */ if (argv[i][2]) break; @@ -148,7 +159,8 @@ char *argv[]; case 'F': /* syncronization file */ if (argv[i][2]) break; - if ((syncfp = fopen(argv[++i],"r+")) == NULL) { + if ((syncfp = + fdopen(open(argv[++i],O_RDWR|O_CREAT,0666),"r+")) == NULL) { fprintf(stderr, "%s: cannot open\n", argv[i]); exit(1); @@ -189,7 +201,8 @@ int ltyp; fls.l_type = ltyp; if (fcntl(fd, F_SETLKW, &fls) < 0) { - fprintf(stderr, "%s: cannot lock/unlock file\n", progname); + fprintf(stderr, "%s: cannot lock/unlock file: %s\n", + progname, sys_errlist[errno]); exit(1); } } @@ -230,7 +243,8 @@ char **av; dolock(outfd, F_WRLCK); if ((fp = fdopen(dup(outfd), "w")) == NULL) goto filerr; - printargs(ac, av, fp); /* write header */ + newheader("RADIANCE", fp); /* create header */ + printargs(ac, av, fp); fprintf(fp, "SOFTWARE= %s\n", VersionID); fputs(VIEWSTR, fp); fprintview(&ourview, fp); @@ -276,6 +290,8 @@ char **av; exit(1); } signal(SIGALRM, onalrm); + if (timelim) + alarm(timelim); return; filerr: fprintf(stderr, "%s: i/o error on file \"%s\"\n", progname, outfile); @@ -321,10 +337,7 @@ int *xp, *yp; sflock(F_UNLCK); /* release sync file */ return(1); } - if (scanf("%d %d", xp, yp) == 2) /* use stdin */ - return(1); - fprintf(stderr, "%s: input format error\n", progname); - exit(cleanup(1)); + return(scanf("%d %d", xp, yp) == 2); /* use stdin */ } @@ -344,6 +357,10 @@ register int *xp, *yp; return(0); /* only check if asked */ if (pdone == NULL) /* first call */ pdone = calloc(hmult*vmult, sizeof(char)); + if (pdone == NULL) { + fprintf(stderr, "%s: out of memory\n", progname); + exit(1); + } if (readpos != -1) /* mark what's been done */ fseek(syncfp, readpos, 0); while (fscanf(syncfp, "%d %d", xp, yp) == 2) @@ -402,6 +419,11 @@ rpiece() /* render picture piece by piece */ pview.horiz = ourview.horiz / hmult; pview.vert = ourview.vert / vmult; break; + case VT_CYL: + pview.horiz = ourview.horiz / hmult; + pview.vert = 2.*180./PI*atan( + tan(PI/180./2.*ourview.vert)/vmult ); + break; case VT_HEM: pview.horiz = 2.*180./PI*asin( sin(PI/180./2.*ourview.horiz)/hmult ); @@ -415,8 +437,8 @@ rpiece() /* render picture piece by piece */ } /* render each piece */ while (nextpiece(&xorg, &yorg)) { - pview.hoff = ourview.hoff + xorg - 0.5*(hmult-1); - pview.voff = ourview.voff + yorg - 0.5*(vmult-1); + pview.hoff = ourview.hoff*hmult + xorg - 0.5*(hmult-1); + pview.voff = ourview.voff*vmult + yorg - 0.5*(vmult-1); fputs(VIEWSTR, torp); fprintview(&pview, torp); putc('\n', torp); @@ -484,29 +506,35 @@ int xpos, ypos; /* lock file section so NFS doesn't mess up */ fls.l_whence = 0; fls.l_type = F_WRLCK; - fcntl(outfd, F_SETLKW, &fls); + if (fcntl(outfd, F_SETLKW, &fls) < 0) + filerr("lock"); #endif /* write new piece to file */ if (lseek(outfd, fls.l_start, 0) == -1) - goto seekerr; + filerr("seek"); if (hmult == 1) { if (writebuf(outfd, (char *)pbuf, vr*hr*sizeof(COLR)) != vr*hr*sizeof(COLR)) - goto writerr; + filerr("write"); } else for (y = 0; y < vr; y++) { if (writebuf(outfd, (char *)(pbuf+y*hr), hr*sizeof(COLR)) != hr*sizeof(COLR)) - goto writerr; + filerr("write"); if (y < vr-1 && lseek(outfd, (long)(hmult-1)*hr*sizeof(COLR), 1) == -1) - goto seekerr; + filerr("seek"); } #if NFS fls.l_type = F_UNLCK; /* release lock */ - fcntl(outfd, F_SETLKW, &fls); + if (fcntl(outfd, F_SETLKW, &fls) < 0) + filerr("lock"); #endif + if (verbose) { /* notify caller */ + printf("%d %d done\n", xpos, ypos); + fflush(stdout); + } if (syncfp != NULL) { /* record what's been done */ sflock(F_WRLCK); fseek(syncfp, 0L, 2); /* append index */ @@ -515,18 +543,17 @@ int xpos, ypos; /*** Unlock not necessary, since sflock(F_UNLCK); _exit() or nextpiece() is next ***/ } - if (verbose) { /* notify caller */ - printf("%d %d done\n", xpos, ypos); - fflush(stdout); - } if (pid == -1) /* didn't fork or fork failed */ return(0); _exit(0); /* else exit child process (releasing locks) */ -seekerr: - fprintf(stderr, "%s: seek error on file \"%s\"\n", progname, outfile); - _exit(1); -writerr: - fprintf(stderr, "%s: write error on file \"%s\"\n", progname, outfile); +} + + +filerr(t) /* report file error and exit */ +char *t; +{ + fprintf(stderr, "%s: %s error on file \"%s\": %s\n", + progname, t, outfile, sys_errlist[errno]); _exit(1); }