| 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) */ |
| 77 |
|
|
| 78 |
|
extern char *strcpy(), *strcat(), *stradd(), *tailtrunc(), *filetrunc(), |
| 79 |
|
*filename(), *libname(), *fullname(), *malloc(); |
| 78 |
– |
extern double atof(); |
| 80 |
|
extern float *matchlamp(); |
| 81 |
|
|
| 82 |
|
|
| 154 |
|
case 'o': /* output file name */ |
| 155 |
|
outfile = argv[++i]; |
| 156 |
|
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; |
| 157 |
|
case 'i': /* illum */ |
| 158 |
|
illumrad = atof(argv[++i]); |
| 159 |
|
if (illumrad < MINDIM) |
| 160 |
|
illumrad = MINDIM; |
| 161 |
|
break; |
| 162 |
< |
case 't': /* select lamp type */ |
| 162 |
> |
case 't': /* override lamp type */ |
| 163 |
|
lamptype = argv[++i]; |
| 164 |
|
break; |
| 165 |
+ |
case 'u': /* default lamp type */ |
| 166 |
+ |
deflamp = argv[++i]; |
| 167 |
+ |
break; |
| 168 |
|
case 'c': /* default lamp color */ |
| 169 |
|
defcolor[0] = atof(argv[++i]); |
| 170 |
|
defcolor[1] = atof(argv[++i]); |
| 181 |
|
} |
| 182 |
|
gargc = i; |
| 183 |
|
gargv = argv; |
| 184 |
< |
/* 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 |
< |
} |
| 184 |
> |
initlamps(); /* get lamp data (if needed) */ |
| 185 |
|
/* convert ies file(s) */ |
| 186 |
|
if (outfile != NULL) { |
| 187 |
|
if (i == argc) |
| 208 |
|
} |
| 209 |
|
|
| 210 |
|
|
| 211 |
+ |
initlamps() /* set up lamps */ |
| 212 |
+ |
{ |
| 213 |
+ |
float *lcol; |
| 214 |
+ |
int status; |
| 215 |
+ |
|
| 216 |
+ |
if (lamptype != NULL && !strcmp(lamptype, default_name) && |
| 217 |
+ |
deflamp == NULL) |
| 218 |
+ |
return; /* no need for data */ |
| 219 |
+ |
/* else load file */ |
| 220 |
+ |
if ((status = loadlamps(lampdat)) < 0) |
| 221 |
+ |
exit(1); |
| 222 |
+ |
if (status == 0) { |
| 223 |
+ |
fprintf(stderr, "%s: warning - no lamp data\n", lampdat); |
| 224 |
+ |
lamptype = default_name; |
| 225 |
+ |
return; |
| 226 |
+ |
} |
| 227 |
+ |
if (deflamp != NULL) { /* match default type */ |
| 228 |
+ |
if ((lcol = matchlamp(deflamp)) == NULL) |
| 229 |
+ |
fprintf(stderr, |
| 230 |
+ |
"%s: warning - unknown default lamp type\n", |
| 231 |
+ |
deflamp); |
| 232 |
+ |
else |
| 233 |
+ |
copycolor(defcolor, lcol); |
| 234 |
+ |
} |
| 235 |
+ |
if (lamptype != NULL) { /* match selected type */ |
| 236 |
+ |
if (strcmp(lamptype, default_name)) { |
| 237 |
+ |
if ((lcol = matchlamp(lamptype)) == NULL) { |
| 238 |
+ |
fprintf(stderr, |
| 239 |
+ |
"%s: warning - unknown lamp type\n", |
| 240 |
+ |
lamptype); |
| 241 |
+ |
lamptype = default_name; |
| 242 |
+ |
} else |
| 243 |
+ |
copycolor(defcolor, lcol); |
| 244 |
+ |
} |
| 245 |
+ |
freelamps(); /* all done with data */ |
| 246 |
+ |
} |
| 247 |
+ |
/* else keep lamp data */ |
| 248 |
+ |
} |
| 249 |
+ |
|
| 250 |
+ |
|
| 251 |
|
char * |
| 252 |
|
stradd(dst, src, sep) /* add a string at dst */ |
| 253 |
|
register char *dst, *src; |
| 274 |
|
else if (abspath(fname)) |
| 275 |
|
strcpy(stradd(path, fname, 0), suffix); |
| 276 |
|
else |
| 277 |
< |
libname(stradd(path, libdir, '/'), fname, suffix); |
| 277 |
> |
libname(stradd(path, libdir, DIRSEP), fname, suffix); |
| 278 |
|
|
| 279 |
|
return(path); |
| 280 |
|
} |
| 287 |
|
if (abspath(fname)) |
| 288 |
|
strcpy(stradd(path, fname, 0), suffix); |
| 289 |
|
else |
| 290 |
< |
strcpy(stradd(stradd(path, prefdir, '/'), fname, 0), suffix); |
| 290 |
> |
strcpy(stradd(stradd(path, prefdir, DIRSEP), fname, 0), suffix); |
| 291 |
|
|
| 292 |
|
return(path); |
| 293 |
|
} |
| 300 |
|
register char *cp; |
| 301 |
|
|
| 302 |
|
for (cp = path; *path; path++) |
| 303 |
< |
if (*path == '/') |
| 303 |
> |
if (ISDIRSEP(*path)) |
| 304 |
|
cp = path+1; |
| 305 |
|
return(cp); |
| 306 |
|
} |
| 313 |
|
register char *p1, *p2; |
| 314 |
|
|
| 315 |
|
for (p1 = p2 = path; *p2; p2++) |
| 316 |
< |
if (*p2 == '/') |
| 316 |
> |
if (ISDIRSEP(*p2)) |
| 317 |
|
p1 = p2; |
| 318 |
|
*p1 = '\0'; |
| 319 |
|
return(path); |
| 447 |
|
datin = in; |
| 448 |
|
strcpy(tltname, dfltname); |
| 449 |
|
} else { |
| 450 |
< |
if (tltspec[0] == '/') |
| 450 |
> |
if (ISDIRSEP(tltspec[0])) |
| 451 |
|
strcpy(buf, tltspec); |
| 452 |
|
else |
| 453 |
< |
strcpy(stradd(buf, dir, '/'), tltspec); |
| 453 |
> |
strcpy(stradd(buf, dir, DIRSEP), tltspec); |
| 454 |
|
if ((datin = fopen(buf, "r")) == NULL) { |
| 455 |
|
perror(buf); |
| 456 |
|
return(-1); |
| 540 |
|
perror(buf); |
| 541 |
|
return(-1); |
| 542 |
|
} |
| 543 |
< |
if (cvdata(in, datout, 2, nangles, 1./683., bounds) != 0) { |
| 543 |
> |
if (cvdata(in, datout, 2, nangles, 1./WHTEFFICACY, bounds) != 0) { |
| 544 |
|
fprintf(stderr, "dosource: bad distribution data\n"); |
| 545 |
|
fclose(datout); |
| 546 |
|
unlink(fullname(buf,name,T_DST)); |
| 685 |
|
shp->area = shp->w * shp->l; |
| 686 |
|
break; |
| 687 |
|
case DISK: |
| 688 |
+ |
case SPHERE: |
| 689 |
|
shp->area = PI/4. * shp->w * shp->w; |
| 690 |
|
break; |
| 661 |
– |
case SPHERE: |
| 662 |
– |
shp->area = PI * shp->w * shp->w; |
| 663 |
– |
break; |
| 691 |
|
} |
| 692 |
|
return(0); |
| 693 |
|
} |
| 796 |
|
int ndim, npts[]; |
| 797 |
|
double mult, lim[][2]; |
| 798 |
|
{ |
| 799 |
< |
register double *pt[4]; |
| 799 |
> |
double *pt[4]; |
| 800 |
|
register int i, j; |
| 801 |
|
double val; |
| 802 |
|
int total; |