12 |
|
|
13 |
|
#include "ray.h" |
14 |
|
|
15 |
+ |
#include <sys/types.h> |
16 |
+ |
|
17 |
+ |
#ifndef NIX |
18 |
|
#ifdef BSD |
19 |
|
#include <sys/time.h> |
20 |
|
#include <sys/resource.h> |
21 |
+ |
#else |
22 |
+ |
#include <sys/times.h> |
23 |
+ |
#include <sys/utsname.h> |
24 |
+ |
#include <unistd.h> |
25 |
|
#endif |
26 |
+ |
#endif |
27 |
|
|
28 |
+ |
extern time_t time(); |
29 |
+ |
|
30 |
|
#include <signal.h> |
31 |
|
|
32 |
|
#include "view.h" |
87 |
|
|
88 |
|
double pctdone = 0.0; /* percentage done */ |
89 |
|
|
90 |
< |
long tlastrept = 0L; /* time at last report */ |
90 |
> |
time_t tlastrept = 0L; /* time at last report */ |
91 |
|
|
92 |
< |
extern long time(); |
83 |
< |
extern long tstart; /* starting time */ |
92 |
> |
extern time_t tstart; /* starting time */ |
93 |
|
|
94 |
< |
extern long nrays; /* number of rays traced */ |
94 |
> |
extern unsigned long nrays; /* number of rays traced */ |
95 |
|
|
96 |
|
#define MAXDIV 16 /* maximum sample size */ |
97 |
|
|
103 |
|
|
104 |
|
double pixvalue(); |
105 |
|
|
106 |
+ |
#ifdef NIX |
107 |
+ |
#define file_exists(f) (access(f,F_OK)==0) |
108 |
+ |
#else |
109 |
+ |
#include <sys/types.h> |
110 |
+ |
#include <sys/stat.h> |
111 |
+ |
int |
112 |
+ |
file_exists(fname) /* ordinary file exists? */ |
113 |
+ |
char *fname; |
114 |
+ |
{ |
115 |
+ |
struct stat sbuf; |
116 |
+ |
if (stat(fname, &sbuf) < 0) return(0); |
117 |
+ |
return((sbuf.st_mode & S_IFREG) != 0); |
118 |
+ |
} |
119 |
+ |
#endif |
120 |
|
|
121 |
+ |
|
122 |
|
quit(code) /* quit program */ |
123 |
|
int code; |
124 |
|
{ |
130 |
|
} |
131 |
|
|
132 |
|
|
133 |
< |
#ifdef BSD |
133 |
> |
#ifndef NIX |
134 |
|
report() /* report progress */ |
135 |
|
{ |
136 |
+ |
double u, s; |
137 |
+ |
#ifdef BSD |
138 |
+ |
char hostname[257]; |
139 |
|
struct rusage rubuf; |
140 |
< |
double t; |
140 |
> |
#else |
141 |
> |
struct tms tbuf; |
142 |
> |
struct utsname nambuf; |
143 |
> |
double period; |
144 |
> |
#define hostname nambuf.sysname |
145 |
> |
#endif |
146 |
|
|
147 |
+ |
tlastrept = time((time_t *)NULL); |
148 |
+ |
#ifdef BSD |
149 |
|
getrusage(RUSAGE_SELF, &rubuf); |
150 |
< |
t = (rubuf.ru_utime.tv_usec + rubuf.ru_stime.tv_usec) / 1e6; |
151 |
< |
t += rubuf.ru_utime.tv_sec + rubuf.ru_stime.tv_sec; |
150 |
> |
u = rubuf.ru_utime.tv_sec + rubuf.ru_utime.tv_usec/1e6; |
151 |
> |
s = rubuf.ru_stime.tv_sec + rubuf.ru_stime.tv_usec/1e6; |
152 |
|
getrusage(RUSAGE_CHILDREN, &rubuf); |
153 |
< |
t += (rubuf.ru_utime.tv_usec + rubuf.ru_stime.tv_usec) / 1e6; |
154 |
< |
t += rubuf.ru_utime.tv_sec + rubuf.ru_stime.tv_sec; |
153 |
> |
u += rubuf.ru_utime.tv_sec + rubuf.ru_utime.tv_usec/1e6; |
154 |
> |
s += rubuf.ru_stime.tv_sec + rubuf.ru_stime.tv_usec/1e6; |
155 |
> |
gethostname(hostname, sizeof(hostname)); |
156 |
> |
#else |
157 |
> |
times(&tbuf); |
158 |
> |
period = 1.0 / sysconf(_SC_CLK_TCK); |
159 |
> |
u = ( tbuf.tms_utime + tbuf.tms_cutime ) * period; |
160 |
> |
s = ( tbuf.tms_stime + tbuf.tms_cstime ) * period; |
161 |
> |
uname(&nambuf); |
162 |
> |
#endif |
163 |
|
|
164 |
< |
sprintf(errmsg, "%ld rays, %4.2f%% done after %5.4f CPU hours\n", |
165 |
< |
nrays, pctdone, t/3600.0); |
164 |
> |
sprintf(errmsg, |
165 |
> |
"%lu rays, %4.2f%% after %.3fu %.3fs %.3fr hours on %s\n", |
166 |
> |
nrays, pctdone, u/3600., s/3600., |
167 |
> |
(tlastrept-tstart)/3600., hostname); |
168 |
|
eputs(errmsg); |
169 |
< |
tlastrept = time((long *)0); |
169 |
> |
#undef hostname |
170 |
|
} |
171 |
|
#else |
172 |
|
report() /* report progress */ |
173 |
|
{ |
174 |
< |
tlastrept = time((long *)0); |
175 |
< |
sprintf(errmsg, "%ld rays, %4.2f%% done after %5.4f hours\n", |
174 |
> |
tlastrept = time((time_t *)NULL); |
175 |
> |
sprintf(errmsg, "%lu rays, %4.2f%% after %5.4f hours\n", |
176 |
|
nrays, pctdone, (tlastrept-tstart)/3600.0); |
177 |
|
eputs(errmsg); |
178 |
|
signal(SIGCONT, report); |
197 |
|
{ |
198 |
|
extern char *rindex(), *strncpy(), *strcat(), *strcpy(); |
199 |
|
char fbuf[128], fbuf2[128]; |
200 |
+ |
int npicts; |
201 |
|
register char *cp; |
202 |
|
RESOLU rs; |
203 |
|
double pa; |
234 |
|
cp--; |
235 |
|
strcpy(cp, RFTEMPLATE); |
236 |
|
prvr = mktemp(fbuf2); |
237 |
< |
if (rename(fbuf, prvr) < 0 && errno != ENOENT) { |
238 |
< |
sprintf(errmsg, |
237 |
> |
if (rename(fbuf, prvr) < 0) |
238 |
> |
if (errno == ENOENT) { /* ghost file */ |
239 |
> |
sprintf(errmsg, |
240 |
> |
"new output file \"%s\"", |
241 |
> |
fbuf); |
242 |
> |
error(WARNING, errmsg); |
243 |
> |
prvr = NULL; |
244 |
> |
} else { /* serious error */ |
245 |
> |
sprintf(errmsg, |
246 |
|
"cannot rename \"%s\" to \"%s\"", |
247 |
|
fbuf, prvr); |
248 |
< |
error(SYSTEM, errmsg); |
249 |
< |
} |
248 |
> |
error(SYSTEM, errmsg); |
249 |
> |
} |
250 |
|
} |
251 |
|
} |
252 |
< |
/* render sequence */ |
252 |
> |
npicts = 0; /* render sequence */ |
253 |
|
do { |
254 |
|
if (seq && nextview(stdin) == EOF) |
255 |
|
break; |
256 |
+ |
pctdone = 0.0; |
257 |
|
if (pout != NULL) { |
258 |
|
sprintf(fbuf, pout, seq); |
259 |
+ |
if (file_exists(fbuf)) { |
260 |
+ |
if (prvr != NULL || !strcmp(fbuf, pout)) { |
261 |
+ |
sprintf(errmsg, |
262 |
+ |
"output file \"%s\" exists", |
263 |
+ |
fbuf); |
264 |
+ |
error(USER, errmsg); |
265 |
+ |
} |
266 |
+ |
continue; /* don't clobber */ |
267 |
+ |
} |
268 |
|
if (freopen(fbuf, "w", stdout) == NULL) { |
269 |
|
sprintf(errmsg, |
270 |
|
"cannot open output file \"%s\"", fbuf); |
312 |
|
cp = NULL; |
313 |
|
render(cp, prvr); |
314 |
|
prvr = NULL; |
315 |
+ |
npicts++; |
316 |
|
} while (seq++); |
317 |
+ |
/* check that we did something */ |
318 |
+ |
if (npicts == 0) |
319 |
+ |
error(WARNING, "no output produced"); |
320 |
|
} |
321 |
|
|
322 |
|
|
362 |
|
sampdens[i] = hstep; |
363 |
|
} else |
364 |
|
sampdens = NULL; |
365 |
< |
/* open z file */ |
365 |
> |
/* open z-file */ |
366 |
|
if (zfile != NULL) { |
367 |
|
if ((zfd = open(zfile, O_WRONLY|O_CREAT, 0666)) == -1) { |
368 |
< |
sprintf(errmsg, "cannot open z file \"%s\"", zfile); |
368 |
> |
sprintf(errmsg, "cannot open z-file \"%s\"", zfile); |
369 |
|
error(SYSTEM, errmsg); |
370 |
|
} |
371 |
|
#ifdef MSDOS |
387 |
|
i = salvage(oldfile); |
388 |
|
if (zfd != -1 && i > 0 && |
389 |
|
lseek(zfd, (long)i*hres*sizeof(float), 0) == -1) |
390 |
< |
error(SYSTEM, "z file seek error in render"); |
390 |
> |
error(SYSTEM, "z-file seek error in render"); |
391 |
|
pctdone = 100.0*i/vres; |
392 |
|
if (ralrm > 0) /* report init stats */ |
393 |
|
report(); |
431 |
|
goto writerr; |
432 |
|
/* record progress */ |
433 |
|
pctdone = 100.0*(vres-1-ypos)/vres; |
434 |
< |
if (ralrm > 0 && time((long *)0) >= tlastrept+ralrm) |
434 |
> |
if (ralrm > 0 && time((time_t *)NULL) >= tlastrept+ralrm) |
435 |
|
report(); |
436 |
|
#ifndef BSD |
437 |
|
else |
459 |
|
pctdone = 100.0; |
460 |
|
if (ralrm > 0) |
461 |
|
report(); |
462 |
+ |
signal(SIGCONT, SIG_DFL); |
463 |
|
return; |
464 |
|
writerr: |
465 |
|
error(SYSTEM, "write error in render"); |
636 |
|
getheader(fp, NULL, NULL); |
637 |
|
/* get picture size */ |
638 |
|
if (!fscnresolu(&x, &y, fp)) { |
639 |
< |
sprintf(errmsg, "bad recover file \"%s\"", oldfile); |
639 |
> |
sprintf(errmsg, "bad recover file \"%s\" - not removed", |
640 |
> |
oldfile); |
641 |
|
error(WARNING, errmsg); |
642 |
|
fclose(fp); |
643 |
|
return(0); |