1 |
< |
/* Copyright (c) 1990 Regents of the University of California */ |
1 |
> |
/* Copyright (c) 1992 Regents of the University of California */ |
2 |
|
|
3 |
|
#ifndef lint |
4 |
|
static char SCCSid[] = "$SunId$ LBL"; |
12 |
|
|
13 |
|
#include <stdio.h> |
14 |
|
#include <ctype.h> |
15 |
+ |
#include "color.h" |
16 |
+ |
#include "paths.h" |
17 |
|
|
18 |
|
#define PI 3.14159265358979323846 |
19 |
|
/* floating comparisons */ |
36 |
|
/* string lengths */ |
37 |
|
#define MAXLINE 132 |
38 |
|
#define MAXWORD 76 |
37 |
– |
#define MAXPATH 128 |
39 |
|
/* file types */ |
40 |
|
#define T_RAD ".rad" |
41 |
|
#define T_DST ".dat" |
49 |
|
|
50 |
|
#define F_M .3048 /* feet to meters */ |
51 |
|
|
52 |
< |
#define abspath(p) ((p)[0] == '/' || (p)[0] == '.') |
52 |
> |
#define abspath(p) (ISDIRSEP((p)[0]) || (p)[0] == '.') |
53 |
|
|
54 |
+ |
static char default_name[] = "default"; |
55 |
+ |
|
56 |
|
char *libdir = NULL; /* library directory location */ |
57 |
|
char *prefdir = NULL; /* subdirectory */ |
58 |
|
char *lampdat = "lamp.tab"; /* lamp data file */ |
59 |
|
|
60 |
|
double meters2out = 1.0; /* conversion from meters to output */ |
61 |
|
char *lamptype = NULL; /* selected lamp type */ |
62 |
< |
float *lampcolor = NULL; /* pointer to lamp color */ |
62 |
> |
char *deflamp = NULL; /* default lamp type */ |
63 |
|
float defcolor[3] = {1.,1.,1.}; /* default lamp color */ |
64 |
+ |
float *lampcolor = defcolor; /* pointer to current lamp color */ |
65 |
|
double multiplier = 1.0; /* multiplier for all light sources */ |
66 |
|
char units[64] = "meters"; /* output units */ |
63 |
– |
double minaspect = 0.0; /* minimum allowed aspect ratio */ |
64 |
– |
int maxemitters = 1; /* maximum emitters per hemisphere */ |
67 |
|
double illumrad = 0.0; /* radius for illum sphere */ |
68 |
|
|
69 |
|
typedef struct { |
70 |
|
int type; /* RECT, DISK, SPHERE */ |
71 |
|
double w, l, h; /* width, length, height */ |
72 |
< |
double area; /* effective radiating area */ |
72 |
> |
double area; /* max. projected area */ |
73 |
|
} SHAPE; /* a source shape */ |
74 |
|
|
75 |
|
int gargc; /* global argc (minus filenames) */ |
76 |
|
char **gargv; /* global argv */ |
77 |
|
|
78 |
|
extern char *strcpy(), *strcat(), *stradd(), *tailtrunc(), *filetrunc(), |
79 |
< |
*filename(), *libname(), *fullname(), *malloc(); |
80 |
< |
extern double atof(); |
79 |
> |
*filename(), *libname(), *fullname(), *malloc(), |
80 |
> |
*getword(), *atos(); |
81 |
|
extern float *matchlamp(); |
82 |
|
|
83 |
+ |
#define scnint(fp,ip) cvtint(ip,getword(fp)) |
84 |
+ |
#define scnflt(fp,rp) cvtflt(rp,getword(fp)) |
85 |
+ |
#define isint isflt /* IES allows real as integer */ |
86 |
|
|
87 |
+ |
|
88 |
|
main(argc, argv) |
89 |
|
int argc; |
90 |
|
char *argv[]; |
159 |
|
case 'o': /* output file name */ |
160 |
|
outfile = argv[++i]; |
161 |
|
break; |
156 |
– |
case 's': /* square emitters */ |
157 |
– |
minaspect = .6; |
158 |
– |
if (argv[i][2] == '/') { |
159 |
– |
maxemitters = atoi(argv[i]+3); |
160 |
– |
if (maxemitters < 1) |
161 |
– |
goto badopt; |
162 |
– |
} |
163 |
– |
break; |
162 |
|
case 'i': /* illum */ |
163 |
|
illumrad = atof(argv[++i]); |
164 |
|
if (illumrad < MINDIM) |
165 |
|
illumrad = MINDIM; |
166 |
|
break; |
167 |
< |
case 't': /* select lamp type */ |
167 |
> |
case 't': /* override lamp type */ |
168 |
|
lamptype = argv[++i]; |
169 |
|
break; |
170 |
+ |
case 'u': /* default lamp type */ |
171 |
+ |
deflamp = argv[++i]; |
172 |
+ |
break; |
173 |
|
case 'c': /* default lamp color */ |
174 |
|
defcolor[0] = atof(argv[++i]); |
175 |
|
defcolor[1] = atof(argv[++i]); |
186 |
|
} |
187 |
|
gargc = i; |
188 |
|
gargv = argv; |
189 |
< |
/* get lamp data */ |
189 |
< |
if ((status = loadlamps(lampdat)) < 0) |
190 |
< |
exit(1); |
191 |
< |
if (status == 0 || (lamptype != NULL && |
192 |
< |
(lampcolor = matchlamp(lamptype)) == NULL)) { |
193 |
< |
lampcolor = defcolor; |
194 |
< |
fprintf(stderr, "%s: warning - no lamp data\n", argv[0]); |
195 |
< |
} |
189 |
> |
initlamps(); /* get lamp data (if needed) */ |
190 |
|
/* convert ies file(s) */ |
191 |
|
if (outfile != NULL) { |
192 |
|
if (i == argc) |
213 |
|
} |
214 |
|
|
215 |
|
|
216 |
+ |
initlamps() /* set up lamps */ |
217 |
+ |
{ |
218 |
+ |
float *lcol; |
219 |
+ |
int status; |
220 |
+ |
|
221 |
+ |
if (lamptype != NULL && !strcmp(lamptype, default_name) && |
222 |
+ |
deflamp == NULL) |
223 |
+ |
return; /* no need for data */ |
224 |
+ |
/* else load file */ |
225 |
+ |
if ((status = loadlamps(lampdat)) < 0) |
226 |
+ |
exit(1); |
227 |
+ |
if (status == 0) { |
228 |
+ |
fprintf(stderr, "%s: warning - no lamp data\n", lampdat); |
229 |
+ |
lamptype = default_name; |
230 |
+ |
return; |
231 |
+ |
} |
232 |
+ |
if (deflamp != NULL) { /* match default type */ |
233 |
+ |
if ((lcol = matchlamp(deflamp)) == NULL) |
234 |
+ |
fprintf(stderr, |
235 |
+ |
"%s: warning - unknown default lamp type\n", |
236 |
+ |
deflamp); |
237 |
+ |
else |
238 |
+ |
copycolor(defcolor, lcol); |
239 |
+ |
} |
240 |
+ |
if (lamptype != NULL) { /* match selected type */ |
241 |
+ |
if (strcmp(lamptype, default_name)) { |
242 |
+ |
if ((lcol = matchlamp(lamptype)) == NULL) { |
243 |
+ |
fprintf(stderr, |
244 |
+ |
"%s: warning - unknown lamp type\n", |
245 |
+ |
lamptype); |
246 |
+ |
lamptype = default_name; |
247 |
+ |
} else |
248 |
+ |
copycolor(defcolor, lcol); |
249 |
+ |
} |
250 |
+ |
freelamps(); /* all done with data */ |
251 |
+ |
} |
252 |
+ |
/* else keep lamp data */ |
253 |
+ |
} |
254 |
+ |
|
255 |
+ |
|
256 |
|
char * |
257 |
|
stradd(dst, src, sep) /* add a string at dst */ |
258 |
|
register char *dst, *src; |
279 |
|
else if (abspath(fname)) |
280 |
|
strcpy(stradd(path, fname, 0), suffix); |
281 |
|
else |
282 |
< |
libname(stradd(path, libdir, '/'), fname, suffix); |
282 |
> |
libname(stradd(path, libdir, DIRSEP), fname, suffix); |
283 |
|
|
284 |
|
return(path); |
285 |
|
} |
292 |
|
if (abspath(fname)) |
293 |
|
strcpy(stradd(path, fname, 0), suffix); |
294 |
|
else |
295 |
< |
strcpy(stradd(stradd(path, prefdir, '/'), fname, 0), suffix); |
295 |
> |
strcpy(stradd(stradd(path, prefdir, DIRSEP), fname, 0), suffix); |
296 |
|
|
297 |
|
return(path); |
298 |
|
} |
305 |
|
register char *cp; |
306 |
|
|
307 |
|
for (cp = path; *path; path++) |
308 |
< |
if (*path == '/') |
308 |
> |
if (ISDIRSEP(*path)) |
309 |
|
cp = path+1; |
310 |
|
return(cp); |
311 |
|
} |
318 |
|
register char *p1, *p2; |
319 |
|
|
320 |
|
for (p1 = p2 = path; *p2; p2++) |
321 |
< |
if (*p2 == '/') |
321 |
> |
if (ISDIRSEP(*p2)) |
322 |
|
p1 = p2; |
323 |
|
*p1 = '\0'; |
324 |
|
return(path); |
412 |
|
fprintf(stderr, "%s: not in IES format\n", inpname); |
413 |
|
goto readerr; |
414 |
|
} |
415 |
< |
sscanf(buf+TLTSTRLEN, "%s", tltid); |
415 |
> |
atos(tltid, MAXWORD, buf+TLTSTRLEN); |
416 |
|
if (inpfp == stdin) |
417 |
|
buf[0] = '\0'; |
418 |
|
else |
452 |
|
datin = in; |
453 |
|
strcpy(tltname, dfltname); |
454 |
|
} else { |
455 |
< |
if (tltspec[0] == '/') |
455 |
> |
if (ISDIRSEP(tltspec[0])) |
456 |
|
strcpy(buf, tltspec); |
457 |
|
else |
458 |
< |
strcpy(stradd(buf, dir, '/'), tltspec); |
458 |
> |
strcpy(stradd(buf, dir, DIRSEP), tltspec); |
459 |
|
if ((datin = fopen(buf, "r")) == NULL) { |
460 |
|
perror(buf); |
461 |
|
return(-1); |
469 |
|
fclose(datin); |
470 |
|
return(-1); |
471 |
|
} |
472 |
< |
if (fscanf(datin, "%d %d", &tlt_type, &nangles) != 2 |
472 |
> |
if (!scnint(datin,&tlt_type) || !scnint(datin,&nangles) |
473 |
|
|| cvdata(datin,datout,1,&nangles,1.,minmax) != 0) { |
474 |
|
fprintf(stderr, "%s: data format error\n", tltspec); |
475 |
|
fclose(datout); |
521 |
|
int nangles[2], pmtype, unitype; |
522 |
|
double d1; |
523 |
|
|
524 |
< |
if (fscanf(in, "%*d %*f %lf %d %d %d %d %lf %lf %lf %lf %lf %lf", |
525 |
< |
&mult, &nangles[0], &nangles[1], &pmtype, &unitype, |
526 |
< |
&width, &length, &height, &bfactor, &pfactor, |
527 |
< |
&wattage) != 11) { |
524 |
> |
if (!isint(getword(in)) || !isflt(getword(in)) || !scnflt(in,&mult) |
525 |
> |
|| !scnint(in,&nangles[0]) || !scnint(in,&nangles[1]) |
526 |
> |
|| !scnint(in,&pmtype) || !scnint(in,&unitype) |
527 |
> |
|| !scnflt(in,&width) || !scnflt(in,&length) |
528 |
> |
|| !scnflt(in,&height) || !scnflt(in,&bfactor) |
529 |
> |
|| !scnflt(in,&pfactor) || !scnflt(in,&wattage)) { |
530 |
|
fprintf(stderr, "dosource: bad lamp specification\n"); |
531 |
|
return(-1); |
532 |
|
} |
547 |
|
perror(buf); |
548 |
|
return(-1); |
549 |
|
} |
550 |
< |
if (cvdata(in, datout, 2, nangles, 1./683., bounds) != 0) { |
550 |
> |
if (cvdata(in, datout, 2, nangles, 1./WHTEFFICACY, bounds) != 0) { |
551 |
|
fprintf(stderr, "dosource: bad distribution data\n"); |
552 |
|
fclose(datout); |
553 |
|
unlink(fullname(buf,name,T_DST)); |
563 |
|
else if (pmtype == PM_B) |
564 |
|
fprintf(out, "5 "); |
565 |
|
else if (FEQ(bounds[1][0],90.) && FEQ(bounds[1][1],270.)) |
566 |
< |
fprintf(out, "8 "); |
566 |
> |
fprintf(out, "7 "); |
567 |
|
else |
568 |
< |
fprintf(out, "6 "); |
568 |
> |
fprintf(out, "5 "); |
569 |
|
fprintf(out, "%s %s source.cal ", |
570 |
|
srcshape.type==SPHERE ? "corr" : "flatcorr", |
571 |
|
libname(buf,name,T_DST)); |
584 |
|
fprintf(out, "src_phi2 "); |
585 |
|
else |
586 |
|
fprintf(out, "src_phi "); |
587 |
< |
fprintf(out, "src_theta -my "); |
587 |
> |
fprintf(out, "src_theta "); |
588 |
|
if (FEQ(bounds[1][0],90.) && FEQ(bounds[1][1],270.)) |
589 |
|
fprintf(out, "-rz -90 "); |
590 |
|
} else |
615 |
|
lampcolor[2]/shp->area); |
616 |
|
if (doupper && dolower && shp->type != SPHERE && shp->h > MINDIM) { |
617 |
|
fprintf(fp, "\n%s glow %s_glow\n", mod, name); |
618 |
< |
fprintf(fp, "0\n0\n4 %g %g %g 0\n", |
618 |
> |
fprintf(fp, "0\n0\n4 %g %g %g -1\n", |
619 |
|
lampcolor[0]/shp->area, |
620 |
|
lampcolor[1]/shp->area, |
621 |
|
lampcolor[2]/shp->area); |
692 |
|
shp->area = shp->w * shp->l; |
693 |
|
break; |
694 |
|
case DISK: |
695 |
+ |
case SPHERE: |
696 |
|
shp->area = PI/4. * shp->w * shp->w; |
697 |
|
break; |
661 |
– |
case SPHERE: |
662 |
– |
shp->area = PI * shp->w * shp->w; |
663 |
– |
break; |
698 |
|
} |
699 |
|
return(0); |
700 |
|
} |
803 |
|
int ndim, npts[]; |
804 |
|
double mult, lim[][2]; |
805 |
|
{ |
806 |
< |
register double *pt[4]; |
806 |
> |
double *pt[4]; |
807 |
|
register int i, j; |
808 |
|
double val; |
809 |
|
int total; |
819 |
|
for (i = 0; i < ndim; i++) { |
820 |
|
pt[i] = (double *)malloc(npts[i]*sizeof(double)); |
821 |
|
for (j = 0; j < npts[i]; j++) |
822 |
< |
fscanf(in, "%lf", &pt[i][j]); |
822 |
> |
if (!scnflt(in, &pt[i][j])) |
823 |
> |
return(-1); |
824 |
|
if (lim != NULL) { |
825 |
|
lim[i][0] = pt[i][0]; |
826 |
|
lim[i][1] = pt[i][npts[i]-1]; |
851 |
|
for (i = 0; i < total; i++) { |
852 |
|
if (i%4 == 0) |
853 |
|
putc('\n', out); |
854 |
< |
if (fscanf(in, "%lf", &val) != 1) |
854 |
> |
if (!scnflt(in, &val)) |
855 |
|
return(-1); |
856 |
|
fprintf(out, "\t%g", val*mult); |
857 |
|
} |
858 |
|
putc('\n', out); |
859 |
|
return(0); |
860 |
+ |
} |
861 |
+ |
|
862 |
+ |
|
863 |
+ |
char * |
864 |
+ |
getword(fp) /* scan a word from fp */ |
865 |
+ |
register FILE *fp; |
866 |
+ |
{ |
867 |
+ |
static char word[MAXWORD]; |
868 |
+ |
register char *cp; |
869 |
+ |
register int c; |
870 |
+ |
|
871 |
+ |
while (isspace(c=getc(fp))) |
872 |
+ |
; |
873 |
+ |
for (cp = word; c != EOF && cp < word+MAXWORD-1; |
874 |
+ |
*cp++ = c, c = getc(fp)) |
875 |
+ |
if (isspace(c) || c == ',') { |
876 |
+ |
while (isspace(c)) |
877 |
+ |
c = getc(fp); |
878 |
+ |
if (c != EOF & c != ',') |
879 |
+ |
ungetc(c, fp); |
880 |
+ |
*cp = '\0'; |
881 |
+ |
return(word); |
882 |
+ |
} |
883 |
+ |
*cp = '\0'; |
884 |
+ |
return(cp > word ? word : NULL); |
885 |
+ |
} |
886 |
+ |
|
887 |
+ |
|
888 |
+ |
cvtint(ip, word) /* convert a word to an integer */ |
889 |
+ |
int *ip; |
890 |
+ |
char *word; |
891 |
+ |
{ |
892 |
+ |
if (word == NULL || !isint(word)) |
893 |
+ |
return(0); |
894 |
+ |
*ip = atoi(word); |
895 |
+ |
return(1); |
896 |
+ |
} |
897 |
+ |
|
898 |
+ |
|
899 |
+ |
cvtflt(rp, word) /* convert a word to a double */ |
900 |
+ |
double *rp; |
901 |
+ |
char *word; |
902 |
+ |
{ |
903 |
+ |
if (word == NULL || !isflt(word)) |
904 |
+ |
return(0); |
905 |
+ |
*rp = atof(word); |
906 |
+ |
return(1); |
907 |
|
} |