12 |
|
|
13 |
|
#include <stdio.h> |
14 |
|
#include <ctype.h> |
15 |
+ |
#include "color.h" |
16 |
|
|
17 |
|
#define PI 3.14159265358979323846 |
18 |
|
/* floating comparisons */ |
51 |
|
|
52 |
|
#define abspath(p) ((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 */ |
67 |
|
double minaspect = 0.0; /* minimum allowed aspect ratio */ |
71 |
|
typedef struct { |
72 |
|
int type; /* RECT, DISK, SPHERE */ |
73 |
|
double w, l, h; /* width, length, height */ |
74 |
< |
double area; /* effective radiating area */ |
74 |
> |
double area; /* max. projected area */ |
75 |
|
} SHAPE; /* a source shape */ |
76 |
|
|
77 |
|
int gargc; /* global argc (minus filenames) */ |
79 |
|
|
80 |
|
extern char *strcpy(), *strcat(), *stradd(), *tailtrunc(), *filetrunc(), |
81 |
|
*filename(), *libname(), *fullname(), *malloc(); |
78 |
– |
extern double atof(); |
82 |
|
extern float *matchlamp(); |
83 |
|
|
84 |
|
|
169 |
|
if (illumrad < MINDIM) |
170 |
|
illumrad = MINDIM; |
171 |
|
break; |
172 |
< |
case 't': /* select lamp type */ |
172 |
> |
case 't': /* override lamp type */ |
173 |
|
lamptype = argv[++i]; |
174 |
|
break; |
175 |
+ |
case 'u': /* default lamp type */ |
176 |
+ |
deflamp = argv[++i]; |
177 |
+ |
break; |
178 |
|
case 'c': /* default lamp color */ |
179 |
|
defcolor[0] = atof(argv[++i]); |
180 |
|
defcolor[1] = atof(argv[++i]); |
191 |
|
} |
192 |
|
gargc = i; |
193 |
|
gargv = argv; |
194 |
< |
/* 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 |
< |
} |
194 |
> |
initlamps(); /* get lamp data (if needed) */ |
195 |
|
/* convert ies file(s) */ |
196 |
|
if (outfile != NULL) { |
197 |
|
if (i == argc) |
218 |
|
} |
219 |
|
|
220 |
|
|
221 |
+ |
initlamps() /* set up lamps */ |
222 |
+ |
{ |
223 |
+ |
float *lcol; |
224 |
+ |
int status; |
225 |
+ |
|
226 |
+ |
if (lamptype != NULL && !strcmp(lamptype, default_name) && |
227 |
+ |
deflamp == NULL) |
228 |
+ |
return; /* no need for data */ |
229 |
+ |
/* else load file */ |
230 |
+ |
if ((status = loadlamps(lampdat)) < 0) |
231 |
+ |
exit(1); |
232 |
+ |
if (status == 0) { |
233 |
+ |
fprintf(stderr, "%s: warning - no lamp data\n", lampdat); |
234 |
+ |
lamptype = default_name; |
235 |
+ |
return; |
236 |
+ |
} |
237 |
+ |
if (deflamp != NULL) { /* match default type */ |
238 |
+ |
if ((lcol = matchlamp(deflamp)) == NULL) |
239 |
+ |
fprintf(stderr, |
240 |
+ |
"%s: warning - unknown default lamp type\n", |
241 |
+ |
deflamp); |
242 |
+ |
else |
243 |
+ |
copycolor(defcolor, lcol); |
244 |
+ |
} |
245 |
+ |
if (lamptype != NULL) { /* match selected type */ |
246 |
+ |
if (strcmp(lamptype, default_name)) { |
247 |
+ |
if ((lcol = matchlamp(lamptype)) == NULL) { |
248 |
+ |
fprintf(stderr, |
249 |
+ |
"%s: warning - unknown lamp type\n", |
250 |
+ |
lamptype); |
251 |
+ |
lamptype = default_name; |
252 |
+ |
} else |
253 |
+ |
copycolor(defcolor, lcol); |
254 |
+ |
} |
255 |
+ |
freelamps(); /* all done with data */ |
256 |
+ |
} |
257 |
+ |
/* else keep lamp data */ |
258 |
+ |
} |
259 |
+ |
|
260 |
+ |
|
261 |
|
char * |
262 |
|
stradd(dst, src, sep) /* add a string at dst */ |
263 |
|
register char *dst, *src; |
550 |
|
perror(buf); |
551 |
|
return(-1); |
552 |
|
} |
553 |
< |
if (cvdata(in, datout, 2, nangles, 1./683., bounds) != 0) { |
553 |
> |
if (cvdata(in, datout, 2, nangles, 1./WHTEFFICACY, bounds) != 0) { |
554 |
|
fprintf(stderr, "dosource: bad distribution data\n"); |
555 |
|
fclose(datout); |
556 |
|
unlink(fullname(buf,name,T_DST)); |
695 |
|
shp->area = shp->w * shp->l; |
696 |
|
break; |
697 |
|
case DISK: |
659 |
– |
shp->area = PI/4. * shp->w * shp->w; |
660 |
– |
break; |
698 |
|
case SPHERE: |
699 |
< |
shp->area = PI * shp->w * shp->w; |
699 |
> |
shp->area = PI/4. * shp->w * shp->w; |
700 |
|
break; |
701 |
|
} |
702 |
|
return(0); |