1 |
< |
/* Copyright (c) 1992 Regents of the University of California */ |
1 |
> |
/* Copyright (c) 1996 Regents of the University of California */ |
2 |
|
|
3 |
|
#ifndef lint |
4 |
|
static char SCCSid[] = "$SunId$ LBL"; |
12 |
|
|
13 |
|
#include <stdio.h> |
14 |
|
#include <math.h> |
15 |
+ |
#include <sys/types.h> |
16 |
|
#include <ctype.h> |
17 |
|
#include "color.h" |
18 |
|
#include "paths.h" |
109 |
|
float *lampcolor = defcolor; /* pointer to current lamp color */ |
110 |
|
double multiplier = 1.0; /* multiplier for all light sources */ |
111 |
|
char units[64] = "meters"; /* output units */ |
112 |
+ |
int out2stdout = 0; /* put out to stdout r.t. file */ |
113 |
|
int instantiate = 0; /* instantiate geometry */ |
114 |
|
double illumrad = 0.0; /* radius for illum sphere */ |
115 |
|
|
128 |
|
*filename(), *libname(), *fullname(), *malloc(), |
129 |
|
*getword(), *atos(); |
130 |
|
extern float *matchlamp(); |
131 |
+ |
extern time_t fdate(); |
132 |
|
|
133 |
|
#define scnint(fp,ip) cvtint(ip,getword(fp)) |
134 |
|
#define scnflt(fp,rp) cvtflt(rp,getword(fp)) |
206 |
|
case 'f': /* lamp data file */ |
207 |
|
lampdat = argv[++i]; |
208 |
|
break; |
209 |
< |
case 'o': /* output file name */ |
209 |
> |
case 'o': /* output file root name */ |
210 |
|
outfile = argv[++i]; |
211 |
|
break; |
212 |
+ |
case 's': /* output to stdout */ |
213 |
+ |
out2stdout = !out2stdout; |
214 |
+ |
break; |
215 |
|
case 'i': /* illum */ |
216 |
|
illumrad = atof(argv[++i]); |
217 |
|
break; |
247 |
|
exit(ies2rad(NULL, outfile) == 0 ? 0 : 1); |
248 |
|
else if (i == argc-1) |
249 |
|
exit(ies2rad(argv[i], outfile) == 0 ? 0 : 1); |
250 |
< |
else { |
251 |
< |
fprintf(stderr, "%s: single input file required\n", |
246 |
< |
argv[0]); |
247 |
< |
exit(1); |
248 |
< |
} |
250 |
> |
else |
251 |
> |
goto needsingle; |
252 |
|
} else if (i >= argc) { |
253 |
|
fprintf(stderr, "%s: missing output file specification\n", |
254 |
|
argv[0]); |
255 |
|
exit(1); |
256 |
|
} |
257 |
+ |
if (out2stdout && i != argc-1) |
258 |
+ |
goto needsingle; |
259 |
|
status = 0; |
260 |
|
for ( ; i < argc; i++) { |
261 |
|
tailtrunc(strcpy(outname,filename(argv[i]))); |
263 |
|
status = 1; |
264 |
|
} |
265 |
|
exit(status); |
266 |
+ |
needsingle: |
267 |
+ |
fprintf(stderr, "%s: single input file required\n", argv[0]); |
268 |
+ |
exit(1); |
269 |
|
} |
270 |
|
|
271 |
|
|
472 |
|
perror(inpname); |
473 |
|
return(-1); |
474 |
|
} |
475 |
< |
if ((outfp = fopen(fullname(buf,outname,T_RAD), "w")) == NULL) { |
475 |
> |
if (out2stdout) |
476 |
> |
outfp = stdout; |
477 |
> |
else if ((outfp = fopen(fullname(buf,outname,T_RAD), "w")) == NULL) { |
478 |
|
perror(buf); |
479 |
|
fclose(inpfp); |
480 |
|
return(-1); |
714 |
|
char *mod, *name; |
715 |
|
int dolower, doupper; |
716 |
|
{ |
717 |
+ |
int dosides = 0; |
718 |
|
char buf[MAXWORD]; |
719 |
|
|
720 |
|
fprintf(fp, "\n%s %s %s_light\n", mod, |
725 |
|
lampcolor[1]/shp->area, |
726 |
|
lampcolor[2]/shp->area); |
727 |
|
if (doupper && dolower && shp->type != SPHERE && shp->h > MINDIM) |
728 |
< |
if (shp->isillum) { |
718 |
< |
fprintf(fp, "\nvoid illum %s_glow\n", name); |
719 |
< |
fprintf(fp, "0\n0\n3 0 0 0\n"); |
720 |
< |
} else { |
728 |
> |
if (!shp->isillum) { |
729 |
|
fprintf(fp, "\n%s glow %s_glow\n", mod, name); |
730 |
|
fprintf(fp, "0\n0\n4 %g %g %g -1\n", |
731 |
|
lampcolor[0]/shp->area, |
732 |
|
lampcolor[1]/shp->area, |
733 |
|
lampcolor[2]/shp->area); |
734 |
+ |
dosides++; |
735 |
|
} |
736 |
|
switch (shp->type) { |
737 |
|
case RECT: |
740 |
|
putrectsrc(shp, fp, buf, name, 0); |
741 |
|
if (doupper) |
742 |
|
putrectsrc(shp, fp, buf, name, 1); |
743 |
< |
if (doupper && dolower && shp->h > MINDIM) { |
743 |
> |
if (dosides) { |
744 |
|
strcat(strcpy(buf, name), "_glow"); |
745 |
|
putsides(shp, fp, buf, name); |
746 |
|
} |
751 |
|
putdisksrc(shp, fp, buf, name, 0); |
752 |
|
if (doupper) |
753 |
|
putdisksrc(shp, fp, buf, name, 1); |
754 |
< |
if (doupper && dolower && shp->h > MINDIM) { |
754 |
> |
if (dosides) { |
755 |
|
strcat(strcpy(buf, name), "_glow"); |
756 |
|
putcyl(shp, fp, buf, name); |
757 |
|
} |
1049 |
|
strcpy(cp, "| oconv - > "); |
1050 |
|
cp += 12; |
1051 |
|
fullname(cp,outname,T_OCT); |
1052 |
< |
if (system(buf)) { /* create octree */ |
1052 |
> |
if (fdate(inpname) > fdate(outname) && |
1053 |
> |
system(buf)) { /* create octree */ |
1054 |
|
fclose(outfp); |
1055 |
|
return(-1); |
1056 |
|
} |
1064 |
|
fprintf(outfp, "0\n0\n"); |
1065 |
|
fclose(outfp); |
1066 |
|
} else { /* else append to luminaire file */ |
1057 |
– |
fclose(outfp); |
1067 |
|
if (!FEQ(meters2out, 1.0)) { /* apply scalefactor */ |
1068 |
|
sprintf(cp, "| xform -s %f ", meters2out); |
1069 |
|
cp += strlen(cp); |
1070 |
|
} |
1071 |
< |
strcpy(cp, ">> "); /* append works for DOS? */ |
1072 |
< |
cp += 3; |
1073 |
< |
fullname(cp,outname,T_RAD); |
1071 |
> |
if (!out2stdout) { |
1072 |
> |
fclose(outfp); |
1073 |
> |
strcpy(cp, ">> "); /* append works for DOS? */ |
1074 |
> |
cp += 3; |
1075 |
> |
fullname(cp,outname,T_RAD); |
1076 |
> |
} |
1077 |
|
if (system(buf)) |
1078 |
|
return(-1); |
1079 |
|
} |