| 1 |
– |
/* Copyright (c) 1992 Regents of the University of California */ |
| 2 |
– |
|
| 1 |
|
#ifndef lint |
| 2 |
< |
static char SCCSid[] = "$SunId$ LBL"; |
| 2 |
> |
static const char RCSid[] = "$Id$"; |
| 3 |
|
#endif |
| 6 |
– |
|
| 4 |
|
/* |
| 5 |
|
* Convert IES luminaire data to Radiance description |
| 6 |
|
* |
| 7 |
|
* 07Apr90 Greg Ward |
| 8 |
+ |
* |
| 9 |
+ |
* Fixed correction factor for flat sources 29Oct2001 GW |
| 10 |
|
*/ |
| 11 |
|
|
| 12 |
|
#include <stdio.h> |
| 13 |
+ |
#include <string.h> |
| 14 |
+ |
#include <math.h> |
| 15 |
+ |
#include <sys/types.h> |
| 16 |
|
#include <ctype.h> |
| 17 |
|
#include "color.h" |
| 18 |
|
#include "paths.h" |
| 21 |
|
/* floating comparisons */ |
| 22 |
|
#define FTINY 1e-6 |
| 23 |
|
#define FEQ(a,b) ((a)<=(b)+FTINY&&(a)>=(b)-FTINY) |
| 24 |
+ |
/* keywords */ |
| 25 |
+ |
#define MAGICID "IESNA" |
| 26 |
+ |
#define LMAGICID 5 |
| 27 |
+ |
#define FIRSTREV 86 |
| 28 |
+ |
#define LASTREV 95 |
| 29 |
+ |
|
| 30 |
+ |
#define D86 0 /* keywords defined in LM-63-1986 */ |
| 31 |
+ |
|
| 32 |
+ |
#define K_TST 0 |
| 33 |
+ |
#define K_MAN 1 |
| 34 |
+ |
#define K_LMC 2 |
| 35 |
+ |
#define K_LMN 3 |
| 36 |
+ |
#define K_LPC 4 |
| 37 |
+ |
#define K_LMP 5 |
| 38 |
+ |
#define K_BAL 6 |
| 39 |
+ |
#define K_MTC 7 |
| 40 |
+ |
#define K_OTH 8 |
| 41 |
+ |
#define K_SCH 9 |
| 42 |
+ |
#define K_MOR 10 |
| 43 |
+ |
#define K_BLK 11 |
| 44 |
+ |
#define K_EBK 12 |
| 45 |
+ |
|
| 46 |
+ |
#define D91 ((1L<<13)-1) /* keywords defined in LM-63-1991 */ |
| 47 |
+ |
|
| 48 |
+ |
#define K_LMG 13 |
| 49 |
+ |
|
| 50 |
+ |
#define D95 ((1L<<14)-1) /* keywords defined in LM-63-1995 */ |
| 51 |
+ |
|
| 52 |
+ |
char k_kwd[][20] = {"TEST", "MANUFAC", "LUMCAT", "LUMINAIRE", "LAMPCAT", |
| 53 |
+ |
"LAMP", "BALLAST", "MAINTCAT", "OTHER", "SEARCH", |
| 54 |
+ |
"MORE", "BLOCK", "ENDBLOCK", "LUMINOUSGEOMETRY"}; |
| 55 |
+ |
|
| 56 |
+ |
long k_defined[] = {D86, D86, D86, D86, D86, D91, D91, D91, D91, D95}; |
| 57 |
+ |
|
| 58 |
+ |
int filerev = FIRSTREV; |
| 59 |
+ |
|
| 60 |
+ |
#define keymatch(i,s) (k_defined[filerev-FIRSTREV]&1L<<(i) &&\ |
| 61 |
+ |
k_match(k_kwd[i],s)) |
| 62 |
+ |
|
| 63 |
+ |
#define checklamp(s) (!(k_defined[filerev-FIRSTREV]&(1<<K_LMP|1<<K_LPC)) ||\ |
| 64 |
+ |
keymatch(K_LMP,s) || keymatch(K_LPC,s)) |
| 65 |
+ |
|
| 66 |
|
/* tilt specs */ |
| 67 |
|
#define TLTSTR "TILT=" |
| 68 |
|
#define TLTSTRLEN 5 |
| 79 |
|
#define U_METERS 2 |
| 80 |
|
/* string lengths */ |
| 81 |
|
#define MAXLINE 132 |
| 82 |
< |
#define MAXWORD 76 |
| 82 |
> |
#define RMAXWORD 76 |
| 83 |
|
/* file types */ |
| 84 |
|
#define T_RAD ".rad" |
| 85 |
|
#define T_DST ".dat" |
| 86 |
< |
#define T_TLT "+.dat" |
| 86 |
> |
#define T_TLT "%.dat" |
| 87 |
> |
#define T_OCT ".oct" |
| 88 |
|
/* shape types */ |
| 89 |
|
#define RECT 1 |
| 90 |
|
#define DISK 2 |
| 109 |
|
float *lampcolor = defcolor; /* pointer to current lamp color */ |
| 110 |
|
double multiplier = 1.0; /* multiplier for all light sources */ |
| 111 |
|
char units[64] = "meters"; /* output units */ |
| 112 |
+ |
int out2stdout = 0; /* put out to stdout r.t. file */ |
| 113 |
+ |
int instantiate = 0; /* instantiate geometry */ |
| 114 |
|
double illumrad = 0.0; /* radius for illum sphere */ |
| 115 |
|
|
| 116 |
|
typedef struct { |
| 117 |
+ |
int isillum; /* do as illum */ |
| 118 |
|
int type; /* RECT, DISK, SPHERE */ |
| 119 |
+ |
double mult; /* candela multiplier */ |
| 120 |
|
double w, l, h; /* width, length, height */ |
| 121 |
|
double area; /* max. projected area */ |
| 122 |
< |
} SHAPE; /* a source shape */ |
| 122 |
> |
} SRCINFO; /* a source shape (units=meters) */ |
| 123 |
|
|
| 124 |
|
int gargc; /* global argc (minus filenames) */ |
| 125 |
|
char **gargv; /* global argv */ |
| 126 |
|
|
| 127 |
< |
extern char *strcpy(), *strcat(), *stradd(), *tailtrunc(), *filetrunc(), |
| 128 |
< |
*filename(), *libname(), *fullname(), *malloc(), |
| 80 |
< |
*getword(), *atos(); |
| 127 |
> |
extern char *stradd(), *tailtrunc(), *filetrunc(), |
| 128 |
> |
*filename(), *libname(), *fullnam(), *getword(), *atos(); |
| 129 |
|
extern float *matchlamp(); |
| 130 |
+ |
extern time_t fdate(); |
| 131 |
|
|
| 132 |
|
#define scnint(fp,ip) cvtint(ip,getword(fp)) |
| 133 |
|
#define scnflt(fp,rp) cvtflt(rp,getword(fp)) |
| 140 |
|
{ |
| 141 |
|
char *outfile = NULL; |
| 142 |
|
int status; |
| 143 |
< |
char outname[MAXWORD]; |
| 143 |
> |
char outname[RMAXWORD]; |
| 144 |
|
double d1; |
| 145 |
|
int i; |
| 146 |
|
|
| 205 |
|
case 'f': /* lamp data file */ |
| 206 |
|
lampdat = argv[++i]; |
| 207 |
|
break; |
| 208 |
< |
case 'o': /* output file name */ |
| 208 |
> |
case 'o': /* output file root name */ |
| 209 |
|
outfile = argv[++i]; |
| 210 |
|
break; |
| 211 |
+ |
case 's': /* output to stdout */ |
| 212 |
+ |
out2stdout = !out2stdout; |
| 213 |
+ |
break; |
| 214 |
|
case 'i': /* illum */ |
| 215 |
|
illumrad = atof(argv[++i]); |
| 164 |
– |
if (illumrad < MINDIM) |
| 165 |
– |
illumrad = MINDIM; |
| 216 |
|
break; |
| 217 |
+ |
case 'g': /* instatiate geometry? */ |
| 218 |
+ |
instantiate = !instantiate; |
| 219 |
+ |
break; |
| 220 |
|
case 't': /* override lamp type */ |
| 221 |
|
lamptype = argv[++i]; |
| 222 |
|
break; |
| 246 |
|
exit(ies2rad(NULL, outfile) == 0 ? 0 : 1); |
| 247 |
|
else if (i == argc-1) |
| 248 |
|
exit(ies2rad(argv[i], outfile) == 0 ? 0 : 1); |
| 249 |
< |
else { |
| 250 |
< |
fprintf(stderr, "%s: single input file required\n", |
| 198 |
< |
argv[0]); |
| 199 |
< |
exit(1); |
| 200 |
< |
} |
| 249 |
> |
else |
| 250 |
> |
goto needsingle; |
| 251 |
|
} else if (i >= argc) { |
| 252 |
|
fprintf(stderr, "%s: missing output file specification\n", |
| 253 |
|
argv[0]); |
| 254 |
|
exit(1); |
| 255 |
|
} |
| 256 |
+ |
if (out2stdout && i != argc-1) |
| 257 |
+ |
goto needsingle; |
| 258 |
|
status = 0; |
| 259 |
|
for ( ; i < argc; i++) { |
| 260 |
|
tailtrunc(strcpy(outname,filename(argv[i]))); |
| 262 |
|
status = 1; |
| 263 |
|
} |
| 264 |
|
exit(status); |
| 265 |
+ |
needsingle: |
| 266 |
+ |
fprintf(stderr, "%s: single input file required\n", argv[0]); |
| 267 |
+ |
exit(1); |
| 268 |
|
} |
| 269 |
|
|
| 270 |
|
|
| 326 |
|
|
| 327 |
|
|
| 328 |
|
char * |
| 329 |
< |
fullname(path, fname, suffix) /* return full path name */ |
| 329 |
> |
fullnam(path, fname, suffix) /* return full path name */ |
| 330 |
|
char *path, *fname, *suffix; |
| 331 |
|
{ |
| 332 |
|
if (prefdir != NULL && abspath(prefdir)) |
| 375 |
|
for (p1 = p2 = path; *p2; p2++) |
| 376 |
|
if (ISDIRSEP(*p2)) |
| 377 |
|
p1 = p2; |
| 378 |
+ |
if (p1 == path && ISDIRSEP(*p1)) |
| 379 |
+ |
p1++; |
| 380 |
|
*p1 = '\0'; |
| 381 |
|
return(path); |
| 382 |
|
} |
| 413 |
|
} |
| 414 |
|
|
| 415 |
|
|
| 416 |
+ |
k_match(kwd, hdl) /* header line matches keyword? */ |
| 417 |
+ |
register char *kwd, *hdl; |
| 418 |
+ |
{ |
| 419 |
+ |
if (!*hdl++ == '[') |
| 420 |
+ |
return(0); |
| 421 |
+ |
while (islower(*hdl) ? toupper(*hdl) == *kwd++ : *hdl == *kwd++) |
| 422 |
+ |
if (!*hdl++) |
| 423 |
+ |
return(0); |
| 424 |
+ |
return((!*kwd) & (*hdl == ']')); |
| 425 |
+ |
} |
| 426 |
+ |
|
| 427 |
+ |
|
| 428 |
+ |
char * |
| 429 |
+ |
keyargs(hdl) /* return keyword arguments */ |
| 430 |
+ |
register char *hdl; |
| 431 |
+ |
{ |
| 432 |
+ |
while (*hdl && *hdl++ != ']') |
| 433 |
+ |
; |
| 434 |
+ |
while (isspace(*hdl)) |
| 435 |
+ |
hdl++; |
| 436 |
+ |
return(hdl); |
| 437 |
+ |
} |
| 438 |
+ |
|
| 439 |
+ |
|
| 440 |
|
putheader(out) /* print header */ |
| 441 |
|
FILE *out; |
| 442 |
|
{ |
| 456 |
|
ies2rad(inpname, outname) /* convert IES file */ |
| 457 |
|
char *inpname, *outname; |
| 458 |
|
{ |
| 459 |
< |
char buf[MAXLINE], tltid[MAXWORD]; |
| 459 |
> |
SRCINFO srcinfo; |
| 460 |
> |
char buf[MAXLINE], tltid[RMAXWORD]; |
| 461 |
> |
char geomfile[128]; |
| 462 |
|
FILE *inpfp, *outfp; |
| 463 |
+ |
int lineno = 0; |
| 464 |
|
|
| 465 |
+ |
geomfile[0] = '\0'; |
| 466 |
+ |
srcinfo.isillum = 0; |
| 467 |
|
if (inpname == NULL) { |
| 468 |
|
inpname = "<stdin>"; |
| 469 |
|
inpfp = stdin; |
| 471 |
|
perror(inpname); |
| 472 |
|
return(-1); |
| 473 |
|
} |
| 474 |
< |
if ((outfp = fopen(fullname(buf,outname,T_RAD), "w")) == NULL) { |
| 474 |
> |
if (out2stdout) |
| 475 |
> |
outfp = stdout; |
| 476 |
> |
else if ((outfp = fopen(fullnam(buf,outname,T_RAD), "w")) == NULL) { |
| 477 |
|
perror(buf); |
| 478 |
|
fclose(inpfp); |
| 479 |
|
return(-1); |
| 486 |
|
blanktrunc(buf); |
| 487 |
|
if (!buf[0]) |
| 488 |
|
continue; |
| 489 |
+ |
if (!lineno++ && !strncmp(buf, MAGICID, LMAGICID)) { |
| 490 |
+ |
filerev = atoi(buf+LMAGICID); |
| 491 |
+ |
if (filerev < FIRSTREV) |
| 492 |
+ |
filerev = FIRSTREV; |
| 493 |
+ |
else if (filerev > LASTREV) |
| 494 |
+ |
filerev = LASTREV; |
| 495 |
+ |
} |
| 496 |
|
fputs("#<", outfp); |
| 497 |
|
fputs(buf, outfp); |
| 498 |
|
putc('\n', outfp); |
| 499 |
< |
if (lampcolor == NULL) |
| 500 |
< |
lampcolor = matchlamp(buf); |
| 499 |
> |
if (lampcolor == NULL && checklamp(buf)) |
| 500 |
> |
lampcolor = matchlamp( buf[0] == '[' ? |
| 501 |
> |
keyargs(buf) : buf ); |
| 502 |
> |
if (keymatch(K_LMG, buf)) { /* geometry file */ |
| 503 |
> |
strcpy(geomfile, inpname); |
| 504 |
> |
strcpy(filename(geomfile), keyargs(buf)); |
| 505 |
> |
srcinfo.isillum = 1; |
| 506 |
> |
} |
| 507 |
|
} |
| 508 |
|
if (lampcolor == NULL) { |
| 509 |
|
fprintf(stderr, "%s: warning - no lamp type\n", inpname); |
| 510 |
+ |
fputs("# Unknown lamp type (used default)\n", outfp); |
| 511 |
|
lampcolor = defcolor; |
| 512 |
< |
} |
| 512 |
> |
} else if (lamptype == NULL) |
| 513 |
> |
fprintf(outfp,"# CIE(x,y) = (%f,%f)\n# Depreciation = %.1f%%\n", |
| 514 |
> |
lampcolor[3], lampcolor[4], 100.*lampcolor[5]); |
| 515 |
|
if (feof(inpfp)) { |
| 516 |
|
fprintf(stderr, "%s: not in IES format\n", inpname); |
| 517 |
|
goto readerr; |
| 518 |
|
} |
| 519 |
< |
atos(tltid, MAXWORD, buf+TLTSTRLEN); |
| 519 |
> |
atos(tltid, RMAXWORD, buf+TLTSTRLEN); |
| 520 |
|
if (inpfp == stdin) |
| 521 |
|
buf[0] = '\0'; |
| 522 |
|
else |
| 525 |
|
fprintf(stderr, "%s: bad tilt data\n", inpname); |
| 526 |
|
goto readerr; |
| 527 |
|
} |
| 528 |
< |
if (dosource(inpfp, outfp, tltid, outname) != 0) { |
| 528 |
> |
if (dosource(&srcinfo, inpfp, outfp, tltid, outname) != 0) { |
| 529 |
|
fprintf(stderr, "%s: bad luminaire data\n", inpname); |
| 530 |
|
goto readerr; |
| 531 |
|
} |
| 428 |
– |
fclose(outfp); |
| 532 |
|
fclose(inpfp); |
| 533 |
+ |
/* cvgeometry closes outfp */ |
| 534 |
+ |
if (cvgeometry(geomfile, &srcinfo, outname, outfp) != 0) { |
| 535 |
+ |
fprintf(stderr, "%s: bad geometry file\n", geomfile); |
| 536 |
+ |
return(-1); |
| 537 |
+ |
} |
| 538 |
|
return(0); |
| 539 |
|
readerr: |
| 432 |
– |
fclose(outfp); |
| 540 |
|
fclose(inpfp); |
| 541 |
< |
unlink(fullname(buf,outname,T_RAD)); |
| 541 |
> |
fclose(outfp); |
| 542 |
> |
unlink(fullnam(buf,outname,T_RAD)); |
| 543 |
|
return(-1); |
| 544 |
|
} |
| 545 |
|
|
| 550 |
|
{ |
| 551 |
|
int nangles, tlt_type; |
| 552 |
|
double minmax[2]; |
| 553 |
< |
char buf[MAXPATH], tltname[MAXWORD]; |
| 553 |
> |
char buf[PATH_MAX], tltname[RMAXWORD]; |
| 554 |
|
FILE *datin, *datout; |
| 555 |
|
|
| 556 |
|
if (!strcmp(tltspec, TLTNONE)) { |
| 571 |
|
tailtrunc(strcpy(tltname,filename(tltspec))); |
| 572 |
|
} |
| 573 |
|
if (datin != NULL) { |
| 574 |
< |
if ((datout = fopen(fullname(buf,tltname,T_TLT),"w")) == NULL) { |
| 574 |
> |
if ((datout = fopen(fullnam(buf,tltname,T_TLT),"w")) == NULL) { |
| 575 |
|
perror(buf); |
| 576 |
|
if (datin != in) |
| 577 |
|
fclose(datin); |
| 583 |
|
fclose(datout); |
| 584 |
|
if (datin != in) |
| 585 |
|
fclose(datin); |
| 586 |
< |
unlink(fullname(buf,tltname,T_TLT)); |
| 586 |
> |
unlink(fullnam(buf,tltname,T_TLT)); |
| 587 |
|
return(-1); |
| 588 |
|
} |
| 589 |
|
fclose(datout); |
| 617 |
|
} |
| 618 |
|
|
| 619 |
|
|
| 620 |
< |
dosource(in, out, mod, name) /* create source and distribution */ |
| 620 |
> |
dosource(sinf, in, out, mod, name) /* create source and distribution */ |
| 621 |
> |
SRCINFO *sinf; |
| 622 |
|
FILE *in, *out; |
| 623 |
|
char *mod, *name; |
| 624 |
|
{ |
| 625 |
< |
SHAPE srcshape; |
| 517 |
< |
char buf[MAXPATH], id[MAXWORD]; |
| 625 |
> |
char buf[PATH_MAX], id[RMAXWORD]; |
| 626 |
|
FILE *datout; |
| 627 |
|
double mult, bfactor, pfactor, width, length, height, wattage; |
| 628 |
|
double bounds[2][2]; |
| 629 |
|
int nangles[2], pmtype, unitype; |
| 630 |
|
double d1; |
| 631 |
+ |
int doupper, dolower, dosides; |
| 632 |
|
|
| 633 |
|
if (!isint(getword(in)) || !isflt(getword(in)) || !scnflt(in,&mult) |
| 634 |
|
|| !scnint(in,&nangles[0]) || !scnint(in,&nangles[1]) |
| 639 |
|
fprintf(stderr, "dosource: bad lamp specification\n"); |
| 640 |
|
return(-1); |
| 641 |
|
} |
| 642 |
+ |
sinf->mult = multiplier*mult*bfactor*pfactor; |
| 643 |
|
if (nangles[0] < 2 || nangles[1] < 1) { |
| 644 |
|
fprintf(stderr, "dosource: too few measured angles\n"); |
| 645 |
|
return(-1); |
| 649 |
|
length *= F_M; |
| 650 |
|
height *= F_M; |
| 651 |
|
} |
| 652 |
< |
if (makeshape(&srcshape, width, length, height) != 0) { |
| 652 |
> |
if (makeshape(sinf, width, length, height) != 0) { |
| 653 |
|
fprintf(stderr, "dosource: illegal source dimensions"); |
| 654 |
|
return(-1); |
| 655 |
|
} |
| 656 |
< |
if ((datout = fopen(fullname(buf,name,T_DST), "w")) == NULL) { |
| 656 |
> |
if ((datout = fopen(fullnam(buf,name,T_DST), "w")) == NULL) { |
| 657 |
|
perror(buf); |
| 658 |
|
return(-1); |
| 659 |
|
} |
| 660 |
|
if (cvdata(in, datout, 2, nangles, 1./WHTEFFICACY, bounds) != 0) { |
| 661 |
|
fprintf(stderr, "dosource: bad distribution data\n"); |
| 662 |
|
fclose(datout); |
| 663 |
< |
unlink(fullname(buf,name,T_DST)); |
| 663 |
> |
unlink(fullnam(buf,name,T_DST)); |
| 664 |
|
return(-1); |
| 665 |
|
} |
| 666 |
|
fclose(datout); |
| 673 |
|
else if (pmtype == PM_B) |
| 674 |
|
fprintf(out, "5 "); |
| 675 |
|
else if (FEQ(bounds[1][0],90.) && FEQ(bounds[1][1],270.)) |
| 676 |
< |
fprintf(out, "8 "); |
| 676 |
> |
fprintf(out, "7 "); |
| 677 |
|
else |
| 678 |
< |
fprintf(out, "6 "); |
| 678 |
> |
fprintf(out, "5 "); |
| 679 |
> |
dolower = (bounds[0][0] < 90.); |
| 680 |
> |
doupper = (bounds[0][1] > 90.); |
| 681 |
> |
dosides = (doupper & dolower && sinf->h > MINDIM); |
| 682 |
|
fprintf(out, "%s %s source.cal ", |
| 683 |
< |
srcshape.type==SPHERE ? "corr" : "flatcorr", |
| 683 |
> |
sinf->type==SPHERE ? "corr" : |
| 684 |
> |
!dosides ? "flatcorr" : |
| 685 |
> |
sinf->type==DISK ? "cylcorr" : "boxcorr", |
| 686 |
|
libname(buf,name,T_DST)); |
| 687 |
|
if (pmtype == PM_B) { |
| 688 |
|
if (FEQ(bounds[1][0],0.)) |
| 690 |
|
else |
| 691 |
|
fprintf(out, "srcB_horiz "); |
| 692 |
|
fprintf(out, "srcB_vert "); |
| 693 |
< |
} else { |
| 693 |
> |
} else /* pmtype == PM_A */ { |
| 694 |
|
if (nangles[1] >= 2) { |
| 695 |
|
d1 = bounds[1][1] - bounds[1][0]; |
| 696 |
|
if (d1 <= 90.+FTINY) |
| 697 |
|
fprintf(out, "src_phi4 "); |
| 698 |
< |
else if (d1 <= 180.+FTINY) |
| 699 |
< |
fprintf(out, "src_phi2 "); |
| 700 |
< |
else |
| 698 |
> |
else if (d1 <= 180.+FTINY) { |
| 699 |
> |
if (FEQ(bounds[1][0],90.)) |
| 700 |
> |
fprintf(out, "src_phi2+90 "); |
| 701 |
> |
else |
| 702 |
> |
fprintf(out, "src_phi2 "); |
| 703 |
> |
} else |
| 704 |
|
fprintf(out, "src_phi "); |
| 705 |
< |
fprintf(out, "src_theta -my "); |
| 705 |
> |
fprintf(out, "src_theta "); |
| 706 |
|
if (FEQ(bounds[1][0],90.) && FEQ(bounds[1][1],270.)) |
| 707 |
|
fprintf(out, "-rz -90 "); |
| 708 |
|
} else |
| 709 |
|
fprintf(out, "src_theta "); |
| 710 |
|
} |
| 711 |
< |
fprintf(out, "\n0\n1 %g\n", multiplier*mult*bfactor*pfactor); |
| 712 |
< |
if (putsource(&srcshape, out, id, filename(name), |
| 713 |
< |
bounds[0][0]<90., bounds[0][1]>90.) != 0) |
| 711 |
> |
if (!dosides || sinf->type == SPHERE) |
| 712 |
> |
fprintf(out, "\n0\n1 %g\n", sinf->mult/sinf->area); |
| 713 |
> |
else if (sinf->type == DISK) |
| 714 |
> |
fprintf(out, "\n0\n3 %g %g %g\n", sinf->mult, |
| 715 |
> |
sinf->w, sinf->h); |
| 716 |
> |
else |
| 717 |
> |
fprintf(out, "\n0\n4 %g %g %g %g\n", sinf->mult, |
| 718 |
> |
sinf->l, sinf->w, sinf->h); |
| 719 |
> |
if (putsource(sinf, out, id, filename(name), |
| 720 |
> |
dolower, doupper, dosides) != 0) |
| 721 |
|
return(-1); |
| 722 |
|
return(0); |
| 723 |
|
} |
| 724 |
|
|
| 725 |
|
|
| 726 |
< |
putsource(shp, fp, mod, name, dolower, doupper) /* put out source */ |
| 727 |
< |
SHAPE *shp; |
| 726 |
> |
putsource(shp, fp, mod, name, dolower, doupper, dosides) /* put out source */ |
| 727 |
> |
SRCINFO *shp; |
| 728 |
|
FILE *fp; |
| 729 |
|
char *mod, *name; |
| 730 |
|
int dolower, doupper; |
| 731 |
|
{ |
| 732 |
< |
char buf[MAXWORD]; |
| 732 |
> |
char lname[RMAXWORD]; |
| 733 |
|
|
| 734 |
< |
fprintf(fp, "\n%s %s %s_light\n", mod, |
| 735 |
< |
illumrad>=MINDIM/2. ? "illum" : "light", |
| 736 |
< |
name); |
| 734 |
> |
strcat(strcpy(lname, name), "_light"); |
| 735 |
> |
fprintf(fp, "\n%s %s %s\n", mod, |
| 736 |
> |
shp->isillum ? "illum" : "light", lname); |
| 737 |
|
fprintf(fp, "0\n0\n3 %g %g %g\n", |
| 738 |
< |
lampcolor[0]/shp->area, |
| 614 |
< |
lampcolor[1]/shp->area, |
| 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 -1\n", |
| 619 |
< |
lampcolor[0]/shp->area, |
| 620 |
< |
lampcolor[1]/shp->area, |
| 621 |
< |
lampcolor[2]/shp->area); |
| 622 |
< |
} |
| 738 |
> |
lampcolor[0], lampcolor[1], lampcolor[2]); |
| 739 |
|
switch (shp->type) { |
| 740 |
|
case RECT: |
| 625 |
– |
strcat(strcpy(buf, name), "_light"); |
| 741 |
|
if (dolower) |
| 742 |
< |
putrectsrc(shp, fp, buf, name, 0); |
| 742 |
> |
putrectsrc(shp, fp, lname, name, 0); |
| 743 |
|
if (doupper) |
| 744 |
< |
putrectsrc(shp, fp, buf, name, 1); |
| 745 |
< |
if (doupper && dolower && shp->h > MINDIM) { |
| 746 |
< |
strcat(strcpy(buf, name), "_glow"); |
| 632 |
< |
putsides(shp, fp, buf, name); |
| 633 |
< |
} |
| 744 |
> |
putrectsrc(shp, fp, lname, name, 1); |
| 745 |
> |
if (dosides) |
| 746 |
> |
putsides(shp, fp, lname, name); |
| 747 |
|
break; |
| 748 |
|
case DISK: |
| 636 |
– |
strcat(strcpy(buf, name), "_light"); |
| 749 |
|
if (dolower) |
| 750 |
< |
putdisksrc(shp, fp, buf, name, 0); |
| 750 |
> |
putdisksrc(shp, fp, lname, name, 0); |
| 751 |
|
if (doupper) |
| 752 |
< |
putdisksrc(shp, fp, buf, name, 1); |
| 753 |
< |
if (doupper && dolower && shp->h > MINDIM) { |
| 754 |
< |
strcat(strcpy(buf, name), "_glow"); |
| 643 |
< |
putcyl(shp, fp, buf, name); |
| 644 |
< |
} |
| 752 |
> |
putdisksrc(shp, fp, lname, name, 1); |
| 753 |
> |
if (dosides) |
| 754 |
> |
putcyl(shp, fp, lname, name); |
| 755 |
|
break; |
| 756 |
|
case SPHERE: |
| 757 |
< |
strcat(strcpy(buf, name), "_light"); |
| 648 |
< |
putspheresrc(shp, fp, buf, name); |
| 757 |
> |
putspheresrc(shp, fp, lname, name); |
| 758 |
|
break; |
| 759 |
|
} |
| 760 |
|
return(0); |
| 762 |
|
|
| 763 |
|
|
| 764 |
|
makeshape(shp, width, length, height) /* make source shape */ |
| 765 |
< |
register SHAPE *shp; |
| 765 |
> |
register SRCINFO *shp; |
| 766 |
|
double width, length, height; |
| 767 |
|
{ |
| 768 |
< |
if (illumrad >= MINDIM/2.) { |
| 768 |
> |
if (illumrad/meters2out >= MINDIM/2.) { |
| 769 |
> |
shp->isillum = 1; |
| 770 |
|
shp->type = SPHERE; |
| 771 |
< |
shp->w = shp->l = shp->h = 2.*illumrad; |
| 771 |
> |
shp->w = shp->l = shp->h = 2.*illumrad / meters2out; |
| 772 |
|
} else if (width < MINDIM) { |
| 773 |
|
width = -width; |
| 774 |
|
if (width < MINDIM) { |
| 811 |
|
|
| 812 |
|
|
| 813 |
|
putrectsrc(shp, fp, mod, name, up) /* rectangular source */ |
| 814 |
< |
SHAPE *shp; |
| 814 |
> |
SRCINFO *shp; |
| 815 |
|
FILE *fp; |
| 816 |
|
char *mod, *name; |
| 817 |
|
int up; |
| 824 |
|
|
| 825 |
|
|
| 826 |
|
putsides(shp, fp, mod, name) /* put out sides of box */ |
| 827 |
< |
register SHAPE *shp; |
| 827 |
> |
register SRCINFO *shp; |
| 828 |
|
FILE *fp; |
| 829 |
|
char *mod, *name; |
| 830 |
|
{ |
| 836 |
|
|
| 837 |
|
|
| 838 |
|
putrect(shp, fp, mod, name, suffix, a, b, c, d) /* put out a rectangle */ |
| 839 |
< |
SHAPE *shp; |
| 839 |
> |
SRCINFO *shp; |
| 840 |
|
FILE *fp; |
| 841 |
|
char *mod, *name, *suffix; |
| 842 |
|
int a, b, c, d; |
| 850 |
|
|
| 851 |
|
|
| 852 |
|
putpoint(shp, fp, p) /* put out a point */ |
| 853 |
< |
register SHAPE *shp; |
| 853 |
> |
register SRCINFO *shp; |
| 854 |
|
FILE *fp; |
| 855 |
|
int p; |
| 856 |
|
{ |
| 864 |
|
|
| 865 |
|
|
| 866 |
|
putdisksrc(shp, fp, mod, name, up) /* put out a disk source */ |
| 867 |
< |
register SHAPE *shp; |
| 867 |
> |
register SRCINFO *shp; |
| 868 |
|
FILE *fp; |
| 869 |
|
char *mod, *name; |
| 870 |
|
int up; |
| 886 |
|
|
| 887 |
|
|
| 888 |
|
putcyl(shp, fp, mod, name) /* put out a cylinder */ |
| 889 |
< |
register SHAPE *shp; |
| 889 |
> |
register SRCINFO *shp; |
| 890 |
|
FILE *fp; |
| 891 |
|
char *mod, *name; |
| 892 |
|
{ |
| 899 |
|
|
| 900 |
|
|
| 901 |
|
putspheresrc(shp, fp, mod, name) /* put out a sphere source */ |
| 902 |
< |
SHAPE *shp; |
| 902 |
> |
SRCINFO *shp; |
| 903 |
|
FILE *fp; |
| 904 |
|
char *mod, *name; |
| 905 |
|
{ |
| 956 |
|
putc('\n', out); |
| 957 |
|
} |
| 958 |
|
} |
| 959 |
< |
free((char *)pt[i]); |
| 959 |
> |
free((void *)pt[i]); |
| 960 |
|
} |
| 961 |
|
for (i = 0; i < total; i++) { |
| 962 |
|
if (i%4 == 0) |
| 974 |
|
getword(fp) /* scan a word from fp */ |
| 975 |
|
register FILE *fp; |
| 976 |
|
{ |
| 977 |
< |
static char word[MAXWORD]; |
| 977 |
> |
static char wrd[RMAXWORD]; |
| 978 |
|
register char *cp; |
| 979 |
|
register int c; |
| 980 |
|
|
| 981 |
|
while (isspace(c=getc(fp))) |
| 982 |
|
; |
| 983 |
< |
for (cp = word; c != EOF && cp < word+MAXWORD-1; |
| 983 |
> |
for (cp = wrd; c != EOF && cp < wrd+RMAXWORD-1; |
| 984 |
|
*cp++ = c, c = getc(fp)) |
| 985 |
|
if (isspace(c) || c == ',') { |
| 986 |
|
while (isspace(c)) |
| 987 |
|
c = getc(fp); |
| 988 |
< |
if (c != EOF & c != ',') |
| 988 |
> |
if ((c != EOF) & (c != ',')) |
| 989 |
|
ungetc(c, fp); |
| 990 |
|
*cp = '\0'; |
| 991 |
< |
return(word); |
| 991 |
> |
return(wrd); |
| 992 |
|
} |
| 993 |
|
*cp = '\0'; |
| 994 |
< |
return(cp > word ? word : NULL); |
| 994 |
> |
return(cp > wrd ? wrd : NULL); |
| 995 |
|
} |
| 996 |
|
|
| 997 |
|
|
| 998 |
< |
cvtint(ip, word) /* convert a word to an integer */ |
| 998 |
> |
cvtint(ip, wrd) /* convert a word to an integer */ |
| 999 |
|
int *ip; |
| 1000 |
< |
char *word; |
| 1000 |
> |
char *wrd; |
| 1001 |
|
{ |
| 1002 |
< |
if (word == NULL || !isint(word)) |
| 1002 |
> |
if (wrd == NULL || !isint(wrd)) |
| 1003 |
|
return(0); |
| 1004 |
< |
*ip = atoi(word); |
| 1004 |
> |
*ip = atoi(wrd); |
| 1005 |
|
return(1); |
| 1006 |
|
} |
| 1007 |
|
|
| 1008 |
|
|
| 1009 |
< |
cvtflt(rp, word) /* convert a word to a double */ |
| 1009 |
> |
cvtflt(rp, wrd) /* convert a word to a double */ |
| 1010 |
|
double *rp; |
| 1011 |
< |
char *word; |
| 1011 |
> |
char *wrd; |
| 1012 |
|
{ |
| 1013 |
< |
if (word == NULL || !isflt(word)) |
| 1013 |
> |
if (wrd == NULL || !isflt(wrd)) |
| 1014 |
|
return(0); |
| 1015 |
< |
*rp = atof(word); |
| 1015 |
> |
*rp = atof(wrd); |
| 1016 |
|
return(1); |
| 1017 |
+ |
} |
| 1018 |
+ |
|
| 1019 |
+ |
|
| 1020 |
+ |
cvgeometry(inpname, sinf, outname, outfp) |
| 1021 |
+ |
char *inpname; |
| 1022 |
+ |
register SRCINFO *sinf; |
| 1023 |
+ |
char *outname; |
| 1024 |
+ |
FILE *outfp; /* close output file upon return */ |
| 1025 |
+ |
{ |
| 1026 |
+ |
char buf[256]; |
| 1027 |
+ |
register char *cp; |
| 1028 |
+ |
|
| 1029 |
+ |
if (inpname == NULL || !inpname[0]) { /* no geometry file */ |
| 1030 |
+ |
fclose(outfp); |
| 1031 |
+ |
return(0); |
| 1032 |
+ |
} |
| 1033 |
+ |
putc('\n', outfp); |
| 1034 |
+ |
strcpy(buf, "mgf2rad "); /* build mgf2rad command */ |
| 1035 |
+ |
cp = buf+8; |
| 1036 |
+ |
if (!FEQ(sinf->mult, 1.0)) { |
| 1037 |
+ |
sprintf(cp, "-m %f ", sinf->mult); |
| 1038 |
+ |
cp += strlen(cp); |
| 1039 |
+ |
} |
| 1040 |
+ |
sprintf(cp, "-g %f %s ", |
| 1041 |
+ |
sqrt(sinf->w*sinf->w + sinf->h*sinf->h + sinf->l*sinf->l), |
| 1042 |
+ |
inpname); |
| 1043 |
+ |
cp += strlen(cp); |
| 1044 |
+ |
if (instantiate) { /* instantiate octree */ |
| 1045 |
+ |
strcpy(cp, "| oconv - > "); |
| 1046 |
+ |
cp += 12; |
| 1047 |
+ |
fullnam(cp,outname,T_OCT); |
| 1048 |
+ |
if (fdate(inpname) > fdate(outname) && |
| 1049 |
+ |
system(buf)) { /* create octree */ |
| 1050 |
+ |
fclose(outfp); |
| 1051 |
+ |
return(-1); |
| 1052 |
+ |
} |
| 1053 |
+ |
fprintf(outfp, "void instance %s_inst\n", outname); |
| 1054 |
+ |
if (!FEQ(meters2out, 1.0)) |
| 1055 |
+ |
fprintf(outfp, "3 %s -s %f\n", |
| 1056 |
+ |
libname(buf,outname,T_OCT), |
| 1057 |
+ |
meters2out); |
| 1058 |
+ |
else |
| 1059 |
+ |
fprintf(outfp, "1 %s\n", libname(buf,outname,T_OCT)); |
| 1060 |
+ |
fprintf(outfp, "0\n0\n"); |
| 1061 |
+ |
fclose(outfp); |
| 1062 |
+ |
} else { /* else append to luminaire file */ |
| 1063 |
+ |
if (!FEQ(meters2out, 1.0)) { /* apply scalefactor */ |
| 1064 |
+ |
sprintf(cp, "| xform -s %f ", meters2out); |
| 1065 |
+ |
cp += strlen(cp); |
| 1066 |
+ |
} |
| 1067 |
+ |
if (!out2stdout) { |
| 1068 |
+ |
fclose(outfp); |
| 1069 |
+ |
strcpy(cp, ">> "); /* append works for DOS? */ |
| 1070 |
+ |
cp += 3; |
| 1071 |
+ |
fullnam(cp,outname,T_RAD); |
| 1072 |
+ |
} |
| 1073 |
+ |
if (system(buf)) |
| 1074 |
+ |
return(-1); |
| 1075 |
+ |
} |
| 1076 |
+ |
return(0); |
| 1077 |
|
} |