12 |
|
|
13 |
|
#include "ray.h" |
14 |
|
|
15 |
+ |
#ifndef NIX |
16 |
|
#ifdef BSD |
17 |
|
#include <sys/time.h> |
18 |
|
#include <sys/resource.h> |
19 |
+ |
#else |
20 |
+ |
#include <sys/types.h> |
21 |
+ |
#include <sys/times.h> |
22 |
+ |
#include <limits.h> |
23 |
+ |
extern time_t time(); |
24 |
|
#endif |
25 |
+ |
#else |
26 |
+ |
extern unsigned long time(); |
27 |
+ |
#endif |
28 |
|
|
29 |
|
#include <signal.h> |
30 |
|
|
86 |
|
|
87 |
|
double pctdone = 0.0; /* percentage done */ |
88 |
|
|
89 |
< |
long tlastrept = 0L; /* time at last report */ |
89 |
> |
unsigned long tlastrept = 0L; /* time at last report */ |
90 |
|
|
91 |
< |
extern long time(); |
83 |
< |
extern long tstart; /* starting time */ |
91 |
> |
extern unsigned long tstart; /* starting time */ |
92 |
|
|
93 |
|
extern unsigned long nrays; /* number of rays traced */ |
94 |
|
|
102 |
|
|
103 |
|
double pixvalue(); |
104 |
|
|
105 |
+ |
#ifdef NIX |
106 |
+ |
#define file_exists(f) (access(f,F_OK)==0) |
107 |
+ |
#else |
108 |
+ |
#include <sys/types.h> |
109 |
+ |
#include <sys/stat.h> |
110 |
+ |
int |
111 |
+ |
file_exists(fname) /* ordinary file exists? */ |
112 |
+ |
char *fname; |
113 |
+ |
{ |
114 |
+ |
struct stat sbuf; |
115 |
+ |
if (stat(fname, &sbuf) < 0) return(0); |
116 |
+ |
return((sbuf.st_mode & S_IFREG) != 0); |
117 |
+ |
} |
118 |
+ |
#endif |
119 |
|
|
120 |
+ |
|
121 |
|
quit(code) /* quit program */ |
122 |
|
int code; |
123 |
|
{ |
129 |
|
} |
130 |
|
|
131 |
|
|
132 |
< |
#ifdef BSD |
132 |
> |
#ifndef NIX |
133 |
|
report() /* report progress */ |
134 |
|
{ |
135 |
+ |
char hostname[128]; |
136 |
+ |
double u, s; |
137 |
+ |
#ifdef BSD |
138 |
|
struct rusage rubuf; |
139 |
< |
double t; |
139 |
> |
#else |
140 |
> |
struct tms tbuf; |
141 |
> |
#endif |
142 |
|
|
143 |
+ |
tlastrept = time((unsigned long *)NULL); |
144 |
+ |
#ifdef BSD |
145 |
|
getrusage(RUSAGE_SELF, &rubuf); |
146 |
< |
t = (rubuf.ru_utime.tv_usec + rubuf.ru_stime.tv_usec) / 1e6; |
147 |
< |
t += rubuf.ru_utime.tv_sec + rubuf.ru_stime.tv_sec; |
146 |
> |
u = rubuf.ru_utime.tv_sec + rubuf.ru_utime.tv_usec/1e6; |
147 |
> |
s = rubuf.ru_stime.tv_sec + rubuf.ru_stime.tv_usec/1e6; |
148 |
|
getrusage(RUSAGE_CHILDREN, &rubuf); |
149 |
< |
t += (rubuf.ru_utime.tv_usec + rubuf.ru_stime.tv_usec) / 1e6; |
150 |
< |
t += rubuf.ru_utime.tv_sec + rubuf.ru_stime.tv_sec; |
149 |
> |
u += rubuf.ru_utime.tv_sec + rubuf.ru_utime.tv_usec/1e6; |
150 |
> |
s += rubuf.ru_stime.tv_sec + rubuf.ru_stime.tv_usec/1e6; |
151 |
> |
#else |
152 |
> |
times(&tbuf); |
153 |
> |
u = ( tbuf.tms_utime + tbuf.tms_cutime ) / CLK_TCK; |
154 |
> |
s = ( tbuf.tms_stime + tbuf.tms_cstime ) / CLK_TCK; |
155 |
> |
#endif |
156 |
> |
gethostname(hostname, sizeof(hostname)); |
157 |
|
|
158 |
< |
sprintf(errmsg, "%lu rays, %4.2f%% done after %5.4f CPU hours\n", |
159 |
< |
nrays, pctdone, t/3600.0); |
158 |
> |
sprintf(errmsg, |
159 |
> |
"%lu rays, %4.2f%% after %.3fu %.3fs %.3fr hours on %s\n", |
160 |
> |
nrays, pctdone, u/3600., s/3600., |
161 |
> |
(tlastrept-tstart)/3600., hostname); |
162 |
|
eputs(errmsg); |
125 |
– |
tlastrept = time((long *)0); |
163 |
|
} |
164 |
|
#else |
165 |
|
report() /* report progress */ |
166 |
|
{ |
167 |
< |
tlastrept = time((long *)0); |
168 |
< |
sprintf(errmsg, "%lu rays, %4.2f%% done after %5.4f hours\n", |
167 |
> |
tlastrept = time((unsigned long *)NULL); |
168 |
> |
sprintf(errmsg, "%lu rays, %4.2f%% after %5.4f hours\n", |
169 |
|
nrays, pctdone, (tlastrept-tstart)/3600.0); |
170 |
|
eputs(errmsg); |
171 |
|
signal(SIGCONT, report); |
190 |
|
{ |
191 |
|
extern char *rindex(), *strncpy(), *strcat(), *strcpy(); |
192 |
|
char fbuf[128], fbuf2[128]; |
193 |
+ |
int npicts; |
194 |
|
register char *cp; |
195 |
|
RESOLU rs; |
196 |
|
double pa; |
227 |
|
cp--; |
228 |
|
strcpy(cp, RFTEMPLATE); |
229 |
|
prvr = mktemp(fbuf2); |
230 |
< |
if (rename(fbuf, prvr) < 0 && errno != ENOENT) { |
231 |
< |
sprintf(errmsg, |
230 |
> |
if (rename(fbuf, prvr) < 0) |
231 |
> |
if (errno == ENOENT) { /* ghost file */ |
232 |
> |
sprintf(errmsg, |
233 |
> |
"new output file \"%s\"", |
234 |
> |
fbuf); |
235 |
> |
error(WARNING, errmsg); |
236 |
> |
prvr = NULL; |
237 |
> |
} else { /* serious error */ |
238 |
> |
sprintf(errmsg, |
239 |
|
"cannot rename \"%s\" to \"%s\"", |
240 |
|
fbuf, prvr); |
241 |
< |
error(SYSTEM, errmsg); |
242 |
< |
} |
241 |
> |
error(SYSTEM, errmsg); |
242 |
> |
} |
243 |
|
} |
244 |
|
} |
245 |
< |
/* render sequence */ |
245 |
> |
npicts = 0; /* render sequence */ |
246 |
|
do { |
247 |
|
if (seq && nextview(stdin) == EOF) |
248 |
|
break; |
249 |
+ |
pctdone = 0.0; |
250 |
|
if (pout != NULL) { |
251 |
|
sprintf(fbuf, pout, seq); |
252 |
+ |
if (file_exists(fbuf)) { |
253 |
+ |
if (prvr != NULL || !strcmp(fbuf, pout)) { |
254 |
+ |
sprintf(errmsg, |
255 |
+ |
"output file \"%s\" exists", |
256 |
+ |
fbuf); |
257 |
+ |
error(USER, errmsg); |
258 |
+ |
} |
259 |
+ |
continue; /* don't clobber */ |
260 |
+ |
} |
261 |
|
if (freopen(fbuf, "w", stdout) == NULL) { |
262 |
|
sprintf(errmsg, |
263 |
|
"cannot open output file \"%s\"", fbuf); |
305 |
|
cp = NULL; |
306 |
|
render(cp, prvr); |
307 |
|
prvr = NULL; |
308 |
+ |
npicts++; |
309 |
|
} while (seq++); |
310 |
+ |
/* check that we did something */ |
311 |
+ |
if (npicts == 0) |
312 |
+ |
error(WARNING, "no output produced"); |
313 |
|
} |
314 |
|
|
315 |
|
|
355 |
|
sampdens[i] = hstep; |
356 |
|
} else |
357 |
|
sampdens = NULL; |
358 |
< |
/* open z file */ |
358 |
> |
/* open z-file */ |
359 |
|
if (zfile != NULL) { |
360 |
|
if ((zfd = open(zfile, O_WRONLY|O_CREAT, 0666)) == -1) { |
361 |
< |
sprintf(errmsg, "cannot open z file \"%s\"", zfile); |
361 |
> |
sprintf(errmsg, "cannot open z-file \"%s\"", zfile); |
362 |
|
error(SYSTEM, errmsg); |
363 |
|
} |
364 |
|
#ifdef MSDOS |
380 |
|
i = salvage(oldfile); |
381 |
|
if (zfd != -1 && i > 0 && |
382 |
|
lseek(zfd, (long)i*hres*sizeof(float), 0) == -1) |
383 |
< |
error(SYSTEM, "z file seek error in render"); |
383 |
> |
error(SYSTEM, "z-file seek error in render"); |
384 |
|
pctdone = 100.0*i/vres; |
385 |
|
if (ralrm > 0) /* report init stats */ |
386 |
|
report(); |
424 |
|
goto writerr; |
425 |
|
/* record progress */ |
426 |
|
pctdone = 100.0*(vres-1-ypos)/vres; |
427 |
< |
if (ralrm > 0 && time((long *)0) >= tlastrept+ralrm) |
427 |
> |
if (ralrm > 0 && time((unsigned long *)NULL) >= tlastrept+ralrm) |
428 |
|
report(); |
429 |
|
#ifndef BSD |
430 |
|
else |
629 |
|
getheader(fp, NULL, NULL); |
630 |
|
/* get picture size */ |
631 |
|
if (!fscnresolu(&x, &y, fp)) { |
632 |
< |
sprintf(errmsg, "bad recover file \"%s\"", oldfile); |
632 |
> |
sprintf(errmsg, "bad recover file \"%s\" - not removed", |
633 |
> |
oldfile); |
634 |
|
error(WARNING, errmsg); |
635 |
|
fclose(fp); |
636 |
|
return(0); |