| 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"; |
| 11 |
|
*/ |
| 12 |
|
|
| 13 |
|
#include <stdio.h> |
| 14 |
+ |
#include <math.h> |
| 15 |
|
#include <ctype.h> |
| 16 |
|
#include "color.h" |
| 17 |
+ |
#include "paths.h" |
| 18 |
|
|
| 19 |
|
#define PI 3.14159265358979323846 |
| 20 |
|
/* floating comparisons */ |
| 21 |
|
#define FTINY 1e-6 |
| 22 |
|
#define FEQ(a,b) ((a)<=(b)+FTINY&&(a)>=(b)-FTINY) |
| 23 |
+ |
/* keywords */ |
| 24 |
+ |
#define MAGICID "IESNA" |
| 25 |
+ |
#define LMAGICID 5 |
| 26 |
+ |
#define FIRSTREV 86 |
| 27 |
+ |
#define LASTREV 95 |
| 28 |
+ |
|
| 29 |
+ |
#define D86 0 /* keywords defined in LM-63-1986 */ |
| 30 |
+ |
|
| 31 |
+ |
#define K_TST 0 |
| 32 |
+ |
#define K_MAN 1 |
| 33 |
+ |
#define K_LMC 2 |
| 34 |
+ |
#define K_LMN 3 |
| 35 |
+ |
#define K_LPC 4 |
| 36 |
+ |
#define K_LMP 5 |
| 37 |
+ |
#define K_BAL 6 |
| 38 |
+ |
#define K_MTC 7 |
| 39 |
+ |
#define K_OTH 8 |
| 40 |
+ |
#define K_SCH 9 |
| 41 |
+ |
#define K_MOR 10 |
| 42 |
+ |
#define K_BLK 11 |
| 43 |
+ |
#define K_EBK 12 |
| 44 |
+ |
|
| 45 |
+ |
#define D91 ((1L<<13)-1) /* keywords defined in LM-63-1991 */ |
| 46 |
+ |
|
| 47 |
+ |
#define K_LMG 13 |
| 48 |
+ |
|
| 49 |
+ |
#define D95 ((1L<<14)-1) /* keywords defined in LM-63-1995 */ |
| 50 |
+ |
|
| 51 |
+ |
char k_kwd[][20] = {"TEST", "MANUFAC", "LUMCAT", "LUMINAIRE", "LAMPCAT", |
| 52 |
+ |
"LAMP", "BALLAST", "MAINTCAT", "OTHER", "SEARCH", |
| 53 |
+ |
"MORE", "BLOCK", "ENDBLOCK", "LUMINOUSGEOMETRY"}; |
| 54 |
+ |
|
| 55 |
+ |
long k_defined[] = {D86, D86, D86, D86, D86, D91, D91, D91, D91, D95}; |
| 56 |
+ |
|
| 57 |
+ |
int filerev = FIRSTREV; |
| 58 |
+ |
|
| 59 |
+ |
#define keymatch(i,s) (k_defined[filerev-FIRSTREV]&1L<<(i) &&\ |
| 60 |
+ |
k_match(k_kwd[i],s)) |
| 61 |
+ |
|
| 62 |
+ |
#define checklamp(s) (!(k_defined[filerev-FIRSTREV]&(1<<K_LMP|1<<K_LPC)) ||\ |
| 63 |
+ |
keymatch(K_LMP,s) || keymatch(K_LPC,s)) |
| 64 |
+ |
|
| 65 |
|
/* tilt specs */ |
| 66 |
|
#define TLTSTR "TILT=" |
| 67 |
|
#define TLTSTRLEN 5 |
| 79 |
|
/* string lengths */ |
| 80 |
|
#define MAXLINE 132 |
| 81 |
|
#define MAXWORD 76 |
| 38 |
– |
#define MAXPATH 128 |
| 82 |
|
/* file types */ |
| 83 |
|
#define T_RAD ".rad" |
| 84 |
|
#define T_DST ".dat" |
| 85 |
< |
#define T_TLT "+.dat" |
| 85 |
> |
#define T_TLT "%.dat" |
| 86 |
> |
#define T_OCT ".oct" |
| 87 |
|
/* shape types */ |
| 88 |
|
#define RECT 1 |
| 89 |
|
#define DISK 2 |
| 93 |
|
|
| 94 |
|
#define F_M .3048 /* feet to meters */ |
| 95 |
|
|
| 96 |
< |
#define abspath(p) ((p)[0] == '/' || (p)[0] == '.') |
| 96 |
> |
#define abspath(p) (ISDIRSEP((p)[0]) || (p)[0] == '.') |
| 97 |
|
|
| 98 |
|
static char default_name[] = "default"; |
| 99 |
|
|
| 108 |
|
float *lampcolor = defcolor; /* pointer to current lamp color */ |
| 109 |
|
double multiplier = 1.0; /* multiplier for all light sources */ |
| 110 |
|
char units[64] = "meters"; /* output units */ |
| 111 |
< |
double minaspect = 0.0; /* minimum allowed aspect ratio */ |
| 68 |
< |
int maxemitters = 1; /* maximum emitters per hemisphere */ |
| 111 |
> |
int instantiate = 0; /* instantiate geometry */ |
| 112 |
|
double illumrad = 0.0; /* radius for illum sphere */ |
| 113 |
|
|
| 114 |
|
typedef struct { |
| 115 |
+ |
int isillum; /* do as illum */ |
| 116 |
|
int type; /* RECT, DISK, SPHERE */ |
| 117 |
+ |
double mult; /* candela multiplier */ |
| 118 |
|
double w, l, h; /* width, length, height */ |
| 119 |
|
double area; /* max. projected area */ |
| 120 |
< |
} SHAPE; /* a source shape */ |
| 120 |
> |
} SRCINFO; /* a source shape (units=meters) */ |
| 121 |
|
|
| 122 |
|
int gargc; /* global argc (minus filenames) */ |
| 123 |
|
char **gargv; /* global argv */ |
| 124 |
|
|
| 125 |
|
extern char *strcpy(), *strcat(), *stradd(), *tailtrunc(), *filetrunc(), |
| 126 |
< |
*filename(), *libname(), *fullname(), *malloc(); |
| 127 |
< |
extern double atof(); |
| 126 |
> |
*filename(), *libname(), *fullname(), *malloc(), |
| 127 |
> |
*getword(), *atos(); |
| 128 |
|
extern float *matchlamp(); |
| 129 |
|
|
| 130 |
+ |
#define scnint(fp,ip) cvtint(ip,getword(fp)) |
| 131 |
+ |
#define scnflt(fp,rp) cvtflt(rp,getword(fp)) |
| 132 |
+ |
#define isint isflt /* IES allows real as integer */ |
| 133 |
|
|
| 134 |
+ |
|
| 135 |
|
main(argc, argv) |
| 136 |
|
int argc; |
| 137 |
|
char *argv[]; |
| 206 |
|
case 'o': /* output file name */ |
| 207 |
|
outfile = argv[++i]; |
| 208 |
|
break; |
| 160 |
– |
case 's': /* square emitters */ |
| 161 |
– |
minaspect = .6; |
| 162 |
– |
if (argv[i][2] == '/') { |
| 163 |
– |
maxemitters = atoi(argv[i]+3); |
| 164 |
– |
if (maxemitters < 1) |
| 165 |
– |
goto badopt; |
| 166 |
– |
} |
| 167 |
– |
break; |
| 209 |
|
case 'i': /* illum */ |
| 210 |
|
illumrad = atof(argv[++i]); |
| 170 |
– |
if (illumrad < MINDIM) |
| 171 |
– |
illumrad = MINDIM; |
| 211 |
|
break; |
| 212 |
+ |
case 'g': /* instatiate geometry? */ |
| 213 |
+ |
instantiate = !instantiate; |
| 214 |
+ |
break; |
| 215 |
|
case 't': /* override lamp type */ |
| 216 |
|
lamptype = argv[++i]; |
| 217 |
|
break; |
| 327 |
|
else if (abspath(fname)) |
| 328 |
|
strcpy(stradd(path, fname, 0), suffix); |
| 329 |
|
else |
| 330 |
< |
libname(stradd(path, libdir, '/'), fname, suffix); |
| 330 |
> |
libname(stradd(path, libdir, DIRSEP), fname, suffix); |
| 331 |
|
|
| 332 |
|
return(path); |
| 333 |
|
} |
| 340 |
|
if (abspath(fname)) |
| 341 |
|
strcpy(stradd(path, fname, 0), suffix); |
| 342 |
|
else |
| 343 |
< |
strcpy(stradd(stradd(path, prefdir, '/'), fname, 0), suffix); |
| 343 |
> |
strcpy(stradd(stradd(path, prefdir, DIRSEP), fname, 0), suffix); |
| 344 |
|
|
| 345 |
|
return(path); |
| 346 |
|
} |
| 353 |
|
register char *cp; |
| 354 |
|
|
| 355 |
|
for (cp = path; *path; path++) |
| 356 |
< |
if (*path == '/') |
| 356 |
> |
if (ISDIRSEP(*path)) |
| 357 |
|
cp = path+1; |
| 358 |
|
return(cp); |
| 359 |
|
} |
| 366 |
|
register char *p1, *p2; |
| 367 |
|
|
| 368 |
|
for (p1 = p2 = path; *p2; p2++) |
| 369 |
< |
if (*p2 == '/') |
| 369 |
> |
if (ISDIRSEP(*p2)) |
| 370 |
|
p1 = p2; |
| 371 |
+ |
if (p1 == path && ISDIRSEP(*p1)) |
| 372 |
+ |
p1++; |
| 373 |
|
*p1 = '\0'; |
| 374 |
|
return(path); |
| 375 |
|
} |
| 406 |
|
} |
| 407 |
|
|
| 408 |
|
|
| 409 |
+ |
k_match(kwd, hdl) /* header line matches keyword? */ |
| 410 |
+ |
register char *kwd, *hdl; |
| 411 |
+ |
{ |
| 412 |
+ |
if (!*hdl++ == '[') |
| 413 |
+ |
return(0); |
| 414 |
+ |
while (islower(*hdl) ? toupper(*hdl) == *kwd++ : *hdl == *kwd++) |
| 415 |
+ |
if (!*hdl++) |
| 416 |
+ |
return(0); |
| 417 |
+ |
return(!*kwd & *hdl == ']'); |
| 418 |
+ |
} |
| 419 |
+ |
|
| 420 |
+ |
|
| 421 |
+ |
char * |
| 422 |
+ |
keyargs(hdl) /* return keyword arguments */ |
| 423 |
+ |
register char *hdl; |
| 424 |
+ |
{ |
| 425 |
+ |
while (*hdl && *hdl++ != ']') |
| 426 |
+ |
; |
| 427 |
+ |
while (isspace(*hdl)) |
| 428 |
+ |
hdl++; |
| 429 |
+ |
return(hdl); |
| 430 |
+ |
} |
| 431 |
+ |
|
| 432 |
+ |
|
| 433 |
|
putheader(out) /* print header */ |
| 434 |
|
FILE *out; |
| 435 |
|
{ |
| 449 |
|
ies2rad(inpname, outname) /* convert IES file */ |
| 450 |
|
char *inpname, *outname; |
| 451 |
|
{ |
| 452 |
+ |
SRCINFO srcinfo; |
| 453 |
|
char buf[MAXLINE], tltid[MAXWORD]; |
| 454 |
+ |
char geomfile[128]; |
| 455 |
|
FILE *inpfp, *outfp; |
| 456 |
+ |
int lineno = 0; |
| 457 |
|
|
| 458 |
+ |
geomfile[0] = '\0'; |
| 459 |
+ |
srcinfo.isillum = 0; |
| 460 |
|
if (inpname == NULL) { |
| 461 |
|
inpname = "<stdin>"; |
| 462 |
|
inpfp = stdin; |
| 477 |
|
blanktrunc(buf); |
| 478 |
|
if (!buf[0]) |
| 479 |
|
continue; |
| 480 |
+ |
if (!lineno++ && !strncmp(buf, MAGICID, LMAGICID)) { |
| 481 |
+ |
filerev = atoi(buf+LMAGICID); |
| 482 |
+ |
if (filerev < FIRSTREV) |
| 483 |
+ |
filerev = FIRSTREV; |
| 484 |
+ |
else if (filerev > LASTREV) |
| 485 |
+ |
filerev = LASTREV; |
| 486 |
+ |
} |
| 487 |
|
fputs("#<", outfp); |
| 488 |
|
fputs(buf, outfp); |
| 489 |
|
putc('\n', outfp); |
| 490 |
< |
if (lampcolor == NULL) |
| 491 |
< |
lampcolor = matchlamp(buf); |
| 490 |
> |
if (lampcolor == NULL && checklamp(buf)) |
| 491 |
> |
lampcolor = matchlamp( buf[0] == '[' ? |
| 492 |
> |
keyargs(buf) : buf ); |
| 493 |
> |
if (keymatch(K_LMG, buf)) { /* geometry file */ |
| 494 |
> |
strcpy(geomfile, inpname); |
| 495 |
> |
strcpy(filename(geomfile), keyargs(buf)); |
| 496 |
> |
srcinfo.isillum = 1; |
| 497 |
> |
} |
| 498 |
|
} |
| 499 |
|
if (lampcolor == NULL) { |
| 500 |
|
fprintf(stderr, "%s: warning - no lamp type\n", inpname); |
| 501 |
+ |
fputs("# Unknown lamp type (used default)\n", outfp); |
| 502 |
|
lampcolor = defcolor; |
| 503 |
< |
} |
| 503 |
> |
} else if (lamptype == NULL) |
| 504 |
> |
fprintf(outfp,"# CIE(x,y) = (%f,%f)\n# Depreciation = %.1f%%\n", |
| 505 |
> |
lampcolor[3], lampcolor[4], 100.*lampcolor[5]); |
| 506 |
|
if (feof(inpfp)) { |
| 507 |
|
fprintf(stderr, "%s: not in IES format\n", inpname); |
| 508 |
|
goto readerr; |
| 509 |
|
} |
| 510 |
< |
sscanf(buf+TLTSTRLEN, "%s", tltid); |
| 510 |
> |
atos(tltid, MAXWORD, buf+TLTSTRLEN); |
| 511 |
|
if (inpfp == stdin) |
| 512 |
|
buf[0] = '\0'; |
| 513 |
|
else |
| 516 |
|
fprintf(stderr, "%s: bad tilt data\n", inpname); |
| 517 |
|
goto readerr; |
| 518 |
|
} |
| 519 |
< |
if (dosource(inpfp, outfp, tltid, outname) != 0) { |
| 519 |
> |
if (dosource(&srcinfo, inpfp, outfp, tltid, outname) != 0) { |
| 520 |
|
fprintf(stderr, "%s: bad luminaire data\n", inpname); |
| 521 |
|
goto readerr; |
| 522 |
|
} |
| 434 |
– |
fclose(outfp); |
| 523 |
|
fclose(inpfp); |
| 524 |
+ |
/* cvgeometry closes outfp */ |
| 525 |
+ |
if (cvgeometry(geomfile, &srcinfo, outname, outfp) != 0) { |
| 526 |
+ |
fprintf(stderr, "%s: bad geometry file\n", geomfile); |
| 527 |
+ |
return(-1); |
| 528 |
+ |
} |
| 529 |
|
return(0); |
| 530 |
|
readerr: |
| 438 |
– |
fclose(outfp); |
| 531 |
|
fclose(inpfp); |
| 532 |
+ |
fclose(outfp); |
| 533 |
|
unlink(fullname(buf,outname,T_RAD)); |
| 534 |
|
return(-1); |
| 535 |
|
} |
| 551 |
|
datin = in; |
| 552 |
|
strcpy(tltname, dfltname); |
| 553 |
|
} else { |
| 554 |
< |
if (tltspec[0] == '/') |
| 554 |
> |
if (ISDIRSEP(tltspec[0])) |
| 555 |
|
strcpy(buf, tltspec); |
| 556 |
|
else |
| 557 |
< |
strcpy(stradd(buf, dir, '/'), tltspec); |
| 557 |
> |
strcpy(stradd(buf, dir, DIRSEP), tltspec); |
| 558 |
|
if ((datin = fopen(buf, "r")) == NULL) { |
| 559 |
|
perror(buf); |
| 560 |
|
return(-1); |
| 568 |
|
fclose(datin); |
| 569 |
|
return(-1); |
| 570 |
|
} |
| 571 |
< |
if (fscanf(datin, "%d %d", &tlt_type, &nangles) != 2 |
| 571 |
> |
if (!scnint(datin,&tlt_type) || !scnint(datin,&nangles) |
| 572 |
|
|| cvdata(datin,datout,1,&nangles,1.,minmax) != 0) { |
| 573 |
|
fprintf(stderr, "%s: data format error\n", tltspec); |
| 574 |
|
fclose(datout); |
| 608 |
|
} |
| 609 |
|
|
| 610 |
|
|
| 611 |
< |
dosource(in, out, mod, name) /* create source and distribution */ |
| 611 |
> |
dosource(sinf, in, out, mod, name) /* create source and distribution */ |
| 612 |
> |
SRCINFO *sinf; |
| 613 |
|
FILE *in, *out; |
| 614 |
|
char *mod, *name; |
| 615 |
|
{ |
| 522 |
– |
SHAPE srcshape; |
| 616 |
|
char buf[MAXPATH], id[MAXWORD]; |
| 617 |
|
FILE *datout; |
| 618 |
|
double mult, bfactor, pfactor, width, length, height, wattage; |
| 620 |
|
int nangles[2], pmtype, unitype; |
| 621 |
|
double d1; |
| 622 |
|
|
| 623 |
< |
if (fscanf(in, "%*d %*f %lf %d %d %d %d %lf %lf %lf %lf %lf %lf", |
| 624 |
< |
&mult, &nangles[0], &nangles[1], &pmtype, &unitype, |
| 625 |
< |
&width, &length, &height, &bfactor, &pfactor, |
| 626 |
< |
&wattage) != 11) { |
| 623 |
> |
if (!isint(getword(in)) || !isflt(getword(in)) || !scnflt(in,&mult) |
| 624 |
> |
|| !scnint(in,&nangles[0]) || !scnint(in,&nangles[1]) |
| 625 |
> |
|| !scnint(in,&pmtype) || !scnint(in,&unitype) |
| 626 |
> |
|| !scnflt(in,&width) || !scnflt(in,&length) |
| 627 |
> |
|| !scnflt(in,&height) || !scnflt(in,&bfactor) |
| 628 |
> |
|| !scnflt(in,&pfactor) || !scnflt(in,&wattage)) { |
| 629 |
|
fprintf(stderr, "dosource: bad lamp specification\n"); |
| 630 |
|
return(-1); |
| 631 |
|
} |
| 632 |
+ |
sinf->mult = multiplier*mult*bfactor*pfactor; |
| 633 |
|
if (nangles[0] < 2 || nangles[1] < 1) { |
| 634 |
|
fprintf(stderr, "dosource: too few measured angles\n"); |
| 635 |
|
return(-1); |
| 639 |
|
length *= F_M; |
| 640 |
|
height *= F_M; |
| 641 |
|
} |
| 642 |
< |
if (makeshape(&srcshape, width, length, height) != 0) { |
| 642 |
> |
if (makeshape(sinf, width, length, height) != 0) { |
| 643 |
|
fprintf(stderr, "dosource: illegal source dimensions"); |
| 644 |
|
return(-1); |
| 645 |
|
} |
| 647 |
|
perror(buf); |
| 648 |
|
return(-1); |
| 649 |
|
} |
| 650 |
< |
if (cvdata(in, datout, 2, nangles, 1./683., bounds) != 0) { |
| 650 |
> |
if (cvdata(in, datout, 2, nangles, 1./WHTEFFICACY, bounds) != 0) { |
| 651 |
|
fprintf(stderr, "dosource: bad distribution data\n"); |
| 652 |
|
fclose(datout); |
| 653 |
|
unlink(fullname(buf,name,T_DST)); |
| 663 |
|
else if (pmtype == PM_B) |
| 664 |
|
fprintf(out, "5 "); |
| 665 |
|
else if (FEQ(bounds[1][0],90.) && FEQ(bounds[1][1],270.)) |
| 666 |
< |
fprintf(out, "8 "); |
| 666 |
> |
fprintf(out, "7 "); |
| 667 |
|
else |
| 668 |
< |
fprintf(out, "6 "); |
| 668 |
> |
fprintf(out, "5 "); |
| 669 |
|
fprintf(out, "%s %s source.cal ", |
| 670 |
< |
srcshape.type==SPHERE ? "corr" : "flatcorr", |
| 670 |
> |
sinf->type==SPHERE ? "corr" : "flatcorr", |
| 671 |
|
libname(buf,name,T_DST)); |
| 672 |
|
if (pmtype == PM_B) { |
| 673 |
|
if (FEQ(bounds[1][0],0.)) |
| 684 |
|
fprintf(out, "src_phi2 "); |
| 685 |
|
else |
| 686 |
|
fprintf(out, "src_phi "); |
| 687 |
< |
fprintf(out, "src_theta -my "); |
| 687 |
> |
fprintf(out, "src_theta "); |
| 688 |
|
if (FEQ(bounds[1][0],90.) && FEQ(bounds[1][1],270.)) |
| 689 |
|
fprintf(out, "-rz -90 "); |
| 690 |
|
} else |
| 691 |
|
fprintf(out, "src_theta "); |
| 692 |
|
} |
| 693 |
< |
fprintf(out, "\n0\n1 %g\n", multiplier*mult*bfactor*pfactor); |
| 694 |
< |
if (putsource(&srcshape, out, id, filename(name), |
| 693 |
> |
fprintf(out, "\n0\n1 %g\n", sinf->mult); |
| 694 |
> |
if (putsource(sinf, out, id, filename(name), |
| 695 |
|
bounds[0][0]<90., bounds[0][1]>90.) != 0) |
| 696 |
|
return(-1); |
| 697 |
|
return(0); |
| 699 |
|
|
| 700 |
|
|
| 701 |
|
putsource(shp, fp, mod, name, dolower, doupper) /* put out source */ |
| 702 |
< |
SHAPE *shp; |
| 702 |
> |
SRCINFO *shp; |
| 703 |
|
FILE *fp; |
| 704 |
|
char *mod, *name; |
| 705 |
|
int dolower, doupper; |
| 707 |
|
char buf[MAXWORD]; |
| 708 |
|
|
| 709 |
|
fprintf(fp, "\n%s %s %s_light\n", mod, |
| 710 |
< |
illumrad>=MINDIM/2. ? "illum" : "light", |
| 710 |
> |
shp->isillum ? "illum" : "light", |
| 711 |
|
name); |
| 712 |
|
fprintf(fp, "0\n0\n3 %g %g %g\n", |
| 713 |
|
lampcolor[0]/shp->area, |
| 714 |
|
lampcolor[1]/shp->area, |
| 715 |
|
lampcolor[2]/shp->area); |
| 716 |
< |
if (doupper && dolower && shp->type != SPHERE && shp->h > MINDIM) { |
| 717 |
< |
fprintf(fp, "\n%s glow %s_glow\n", mod, name); |
| 718 |
< |
fprintf(fp, "0\n0\n4 %g %g %g 0\n", |
| 719 |
< |
lampcolor[0]/shp->area, |
| 720 |
< |
lampcolor[1]/shp->area, |
| 721 |
< |
lampcolor[2]/shp->area); |
| 722 |
< |
} |
| 716 |
> |
if (doupper && dolower && shp->type != SPHERE && shp->h > MINDIM) |
| 717 |
> |
if (shp->isillum) { |
| 718 |
> |
fprintf(fp, "\nvoid illum %s_glow\n", name); |
| 719 |
> |
fprintf(fp, "0\n0\n3 0 0 0\n"); |
| 720 |
> |
} else { |
| 721 |
> |
fprintf(fp, "\n%s glow %s_glow\n", mod, name); |
| 722 |
> |
fprintf(fp, "0\n0\n4 %g %g %g -1\n", |
| 723 |
> |
lampcolor[0]/shp->area, |
| 724 |
> |
lampcolor[1]/shp->area, |
| 725 |
> |
lampcolor[2]/shp->area); |
| 726 |
> |
} |
| 727 |
|
switch (shp->type) { |
| 728 |
|
case RECT: |
| 729 |
|
strcat(strcpy(buf, name), "_light"); |
| 757 |
|
|
| 758 |
|
|
| 759 |
|
makeshape(shp, width, length, height) /* make source shape */ |
| 760 |
< |
register SHAPE *shp; |
| 760 |
> |
register SRCINFO *shp; |
| 761 |
|
double width, length, height; |
| 762 |
|
{ |
| 763 |
< |
if (illumrad >= MINDIM/2.) { |
| 763 |
> |
if (illumrad/meters2out >= MINDIM/2.) { |
| 764 |
> |
shp->isillum = 1; |
| 765 |
|
shp->type = SPHERE; |
| 766 |
< |
shp->w = shp->l = shp->h = 2.*illumrad; |
| 766 |
> |
shp->w = shp->l = shp->h = 2.*illumrad / meters2out; |
| 767 |
|
} else if (width < MINDIM) { |
| 768 |
|
width = -width; |
| 769 |
|
if (width < MINDIM) { |
| 806 |
|
|
| 807 |
|
|
| 808 |
|
putrectsrc(shp, fp, mod, name, up) /* rectangular source */ |
| 809 |
< |
SHAPE *shp; |
| 809 |
> |
SRCINFO *shp; |
| 810 |
|
FILE *fp; |
| 811 |
|
char *mod, *name; |
| 812 |
|
int up; |
| 819 |
|
|
| 820 |
|
|
| 821 |
|
putsides(shp, fp, mod, name) /* put out sides of box */ |
| 822 |
< |
register SHAPE *shp; |
| 822 |
> |
register SRCINFO *shp; |
| 823 |
|
FILE *fp; |
| 824 |
|
char *mod, *name; |
| 825 |
|
{ |
| 831 |
|
|
| 832 |
|
|
| 833 |
|
putrect(shp, fp, mod, name, suffix, a, b, c, d) /* put out a rectangle */ |
| 834 |
< |
SHAPE *shp; |
| 834 |
> |
SRCINFO *shp; |
| 835 |
|
FILE *fp; |
| 836 |
|
char *mod, *name, *suffix; |
| 837 |
|
int a, b, c, d; |
| 845 |
|
|
| 846 |
|
|
| 847 |
|
putpoint(shp, fp, p) /* put out a point */ |
| 848 |
< |
register SHAPE *shp; |
| 848 |
> |
register SRCINFO *shp; |
| 849 |
|
FILE *fp; |
| 850 |
|
int p; |
| 851 |
|
{ |
| 859 |
|
|
| 860 |
|
|
| 861 |
|
putdisksrc(shp, fp, mod, name, up) /* put out a disk source */ |
| 862 |
< |
register SHAPE *shp; |
| 862 |
> |
register SRCINFO *shp; |
| 863 |
|
FILE *fp; |
| 864 |
|
char *mod, *name; |
| 865 |
|
int up; |
| 881 |
|
|
| 882 |
|
|
| 883 |
|
putcyl(shp, fp, mod, name) /* put out a cylinder */ |
| 884 |
< |
register SHAPE *shp; |
| 884 |
> |
register SRCINFO *shp; |
| 885 |
|
FILE *fp; |
| 886 |
|
char *mod, *name; |
| 887 |
|
{ |
| 894 |
|
|
| 895 |
|
|
| 896 |
|
putspheresrc(shp, fp, mod, name) /* put out a sphere source */ |
| 897 |
< |
SHAPE *shp; |
| 897 |
> |
SRCINFO *shp; |
| 898 |
|
FILE *fp; |
| 899 |
|
char *mod, *name; |
| 900 |
|
{ |
| 908 |
|
int ndim, npts[]; |
| 909 |
|
double mult, lim[][2]; |
| 910 |
|
{ |
| 911 |
< |
register double *pt[4]; |
| 911 |
> |
double *pt[4]; |
| 912 |
|
register int i, j; |
| 913 |
|
double val; |
| 914 |
|
int total; |
| 924 |
|
for (i = 0; i < ndim; i++) { |
| 925 |
|
pt[i] = (double *)malloc(npts[i]*sizeof(double)); |
| 926 |
|
for (j = 0; j < npts[i]; j++) |
| 927 |
< |
fscanf(in, "%lf", &pt[i][j]); |
| 927 |
> |
if (!scnflt(in, &pt[i][j])) |
| 928 |
> |
return(-1); |
| 929 |
|
if (lim != NULL) { |
| 930 |
|
lim[i][0] = pt[i][0]; |
| 931 |
|
lim[i][1] = pt[i][npts[i]-1]; |
| 956 |
|
for (i = 0; i < total; i++) { |
| 957 |
|
if (i%4 == 0) |
| 958 |
|
putc('\n', out); |
| 959 |
< |
if (fscanf(in, "%lf", &val) != 1) |
| 959 |
> |
if (!scnflt(in, &val)) |
| 960 |
|
return(-1); |
| 961 |
|
fprintf(out, "\t%g", val*mult); |
| 962 |
|
} |
| 963 |
|
putc('\n', out); |
| 964 |
+ |
return(0); |
| 965 |
+ |
} |
| 966 |
+ |
|
| 967 |
+ |
|
| 968 |
+ |
char * |
| 969 |
+ |
getword(fp) /* scan a word from fp */ |
| 970 |
+ |
register FILE *fp; |
| 971 |
+ |
{ |
| 972 |
+ |
static char word[MAXWORD]; |
| 973 |
+ |
register char *cp; |
| 974 |
+ |
register int c; |
| 975 |
+ |
|
| 976 |
+ |
while (isspace(c=getc(fp))) |
| 977 |
+ |
; |
| 978 |
+ |
for (cp = word; c != EOF && cp < word+MAXWORD-1; |
| 979 |
+ |
*cp++ = c, c = getc(fp)) |
| 980 |
+ |
if (isspace(c) || c == ',') { |
| 981 |
+ |
while (isspace(c)) |
| 982 |
+ |
c = getc(fp); |
| 983 |
+ |
if (c != EOF & c != ',') |
| 984 |
+ |
ungetc(c, fp); |
| 985 |
+ |
*cp = '\0'; |
| 986 |
+ |
return(word); |
| 987 |
+ |
} |
| 988 |
+ |
*cp = '\0'; |
| 989 |
+ |
return(cp > word ? word : NULL); |
| 990 |
+ |
} |
| 991 |
+ |
|
| 992 |
+ |
|
| 993 |
+ |
cvtint(ip, word) /* convert a word to an integer */ |
| 994 |
+ |
int *ip; |
| 995 |
+ |
char *word; |
| 996 |
+ |
{ |
| 997 |
+ |
if (word == NULL || !isint(word)) |
| 998 |
+ |
return(0); |
| 999 |
+ |
*ip = atoi(word); |
| 1000 |
+ |
return(1); |
| 1001 |
+ |
} |
| 1002 |
+ |
|
| 1003 |
+ |
|
| 1004 |
+ |
cvtflt(rp, word) /* convert a word to a double */ |
| 1005 |
+ |
double *rp; |
| 1006 |
+ |
char *word; |
| 1007 |
+ |
{ |
| 1008 |
+ |
if (word == NULL || !isflt(word)) |
| 1009 |
+ |
return(0); |
| 1010 |
+ |
*rp = atof(word); |
| 1011 |
+ |
return(1); |
| 1012 |
+ |
} |
| 1013 |
+ |
|
| 1014 |
+ |
|
| 1015 |
+ |
cvgeometry(inpname, sinf, outname, outfp) |
| 1016 |
+ |
char *inpname; |
| 1017 |
+ |
register SRCINFO *sinf; |
| 1018 |
+ |
char *outname; |
| 1019 |
+ |
FILE *outfp; /* close output file upon return */ |
| 1020 |
+ |
{ |
| 1021 |
+ |
char buf[256]; |
| 1022 |
+ |
register char *cp; |
| 1023 |
+ |
|
| 1024 |
+ |
if (inpname == NULL || !inpname[0]) { /* no geometry file */ |
| 1025 |
+ |
fclose(outfp); |
| 1026 |
+ |
return(0); |
| 1027 |
+ |
} |
| 1028 |
+ |
putc('\n', outfp); |
| 1029 |
+ |
strcpy(buf, "mgf2rad "); /* build mgf2rad command */ |
| 1030 |
+ |
cp = buf+8; |
| 1031 |
+ |
if (!FEQ(sinf->mult, 1.0)) { |
| 1032 |
+ |
sprintf(cp, "-m %f ", sinf->mult); |
| 1033 |
+ |
cp += strlen(cp); |
| 1034 |
+ |
} |
| 1035 |
+ |
sprintf(cp, "-g %f %s ", |
| 1036 |
+ |
sqrt(sinf->w*sinf->w + sinf->h*sinf->h + sinf->l*sinf->l), |
| 1037 |
+ |
inpname); |
| 1038 |
+ |
cp += strlen(cp); |
| 1039 |
+ |
if (instantiate) { /* instantiate octree */ |
| 1040 |
+ |
strcpy(cp, "| oconv - > "); |
| 1041 |
+ |
cp += 12; |
| 1042 |
+ |
fullname(cp,outname,T_OCT); |
| 1043 |
+ |
if (system(buf)) { /* create octree */ |
| 1044 |
+ |
fclose(outfp); |
| 1045 |
+ |
return(-1); |
| 1046 |
+ |
} |
| 1047 |
+ |
fprintf(outfp, "void instance %s_inst\n", outname); |
| 1048 |
+ |
if (!FEQ(meters2out, 1.0)) |
| 1049 |
+ |
fprintf(outfp, "3 %s -s %f\n", |
| 1050 |
+ |
libname(buf,outname,T_OCT), |
| 1051 |
+ |
meters2out); |
| 1052 |
+ |
else |
| 1053 |
+ |
fprintf(outfp, "1 %s\n", libname(buf,outname,T_OCT)); |
| 1054 |
+ |
fprintf(outfp, "0\n0\n"); |
| 1055 |
+ |
fclose(outfp); |
| 1056 |
+ |
} else { /* else append to luminaire file */ |
| 1057 |
+ |
fclose(outfp); |
| 1058 |
+ |
if (!FEQ(meters2out, 1.0)) { /* apply scalefactor */ |
| 1059 |
+ |
sprintf(cp, "| xform -s %f ", meters2out); |
| 1060 |
+ |
cp += strlen(cp); |
| 1061 |
+ |
} |
| 1062 |
+ |
strcpy(cp, ">> "); /* append works for DOS? */ |
| 1063 |
+ |
cp += 3; |
| 1064 |
+ |
fullname(cp,outname,T_RAD); |
| 1065 |
+ |
if (system(buf)) |
| 1066 |
+ |
return(-1); |
| 1067 |
+ |
} |
| 1068 |
|
return(0); |
| 1069 |
|
} |