| 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 |
| 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 |
| 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 |
+ |
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 */ |
| 208 |
|
break; |
| 209 |
|
case 'i': /* illum */ |
| 210 |
|
illumrad = atof(argv[++i]); |
| 165 |
– |
if (illumrad < MINDIM) |
| 166 |
– |
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; |
| 368 |
|
for (p1 = p2 = path; *p2; 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); |
| 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 |
|
} |
| 432 |
– |
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: |
| 436 |
– |
fclose(outfp); |
| 531 |
|
fclose(inpfp); |
| 532 |
+ |
fclose(outfp); |
| 533 |
|
unlink(fullname(buf,outname,T_RAD)); |
| 534 |
|
return(-1); |
| 535 |
|
} |
| 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 |
|
{ |
| 520 |
– |
SHAPE srcshape; |
| 616 |
|
char buf[MAXPATH], id[MAXWORD]; |
| 617 |
|
FILE *datout; |
| 618 |
|
double mult, bfactor, pfactor, width, length, height, 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 |
|
} |
| 667 |
|
else |
| 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.)) |
| 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 -1\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 |
|
{ |
| 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 |
|
} |