1 |
< |
/* Copyright (c) 1992 Regents of the University of California */ |
1 |
> |
/* Copyright (c) 1996 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 <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 |
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 */ |
128 |
|
*filename(), *libname(), *fullname(), *malloc(), |
129 |
|
*getword(), *atos(); |
130 |
|
extern float *matchlamp(); |
131 |
+ |
extern time_t fdate(); |
132 |
|
|
133 |
|
#define scnint(fp,ip) cvtint(ip,getword(fp)) |
134 |
|
#define scnflt(fp,rp) cvtflt(rp,getword(fp)) |
206 |
|
case 'f': /* lamp data file */ |
207 |
|
lampdat = argv[++i]; |
208 |
|
break; |
209 |
< |
case 'o': /* output file name */ |
209 |
> |
case 'o': /* output file root name */ |
210 |
|
outfile = argv[++i]; |
211 |
|
break; |
212 |
+ |
case 's': /* output to stdout */ |
213 |
+ |
out2stdout = !out2stdout; |
214 |
+ |
break; |
215 |
|
case 'i': /* illum */ |
216 |
|
illumrad = atof(argv[++i]); |
164 |
– |
if (illumrad < MINDIM) |
165 |
– |
illumrad = MINDIM; |
217 |
|
break; |
218 |
+ |
case 'g': /* instatiate geometry? */ |
219 |
+ |
instantiate = !instantiate; |
220 |
+ |
break; |
221 |
|
case 't': /* override lamp type */ |
222 |
|
lamptype = argv[++i]; |
223 |
|
break; |
247 |
|
exit(ies2rad(NULL, outfile) == 0 ? 0 : 1); |
248 |
|
else if (i == argc-1) |
249 |
|
exit(ies2rad(argv[i], outfile) == 0 ? 0 : 1); |
250 |
< |
else { |
251 |
< |
fprintf(stderr, "%s: single input file required\n", |
198 |
< |
argv[0]); |
199 |
< |
exit(1); |
200 |
< |
} |
250 |
> |
else |
251 |
> |
goto needsingle; |
252 |
|
} else if (i >= argc) { |
253 |
|
fprintf(stderr, "%s: missing output file specification\n", |
254 |
|
argv[0]); |
255 |
|
exit(1); |
256 |
|
} |
257 |
+ |
if (out2stdout && i != argc-1) |
258 |
+ |
goto needsingle; |
259 |
|
status = 0; |
260 |
|
for ( ; i < argc; i++) { |
261 |
|
tailtrunc(strcpy(outname,filename(argv[i]))); |
263 |
|
status = 1; |
264 |
|
} |
265 |
|
exit(status); |
266 |
+ |
needsingle: |
267 |
+ |
fprintf(stderr, "%s: single input file required\n", argv[0]); |
268 |
+ |
exit(1); |
269 |
|
} |
270 |
|
|
271 |
|
|
376 |
|
for (p1 = p2 = path; *p2; p2++) |
377 |
|
if (ISDIRSEP(*p2)) |
378 |
|
p1 = p2; |
379 |
+ |
if (p1 == path && ISDIRSEP(*p1)) |
380 |
+ |
p1++; |
381 |
|
*p1 = '\0'; |
382 |
|
return(path); |
383 |
|
} |
414 |
|
} |
415 |
|
|
416 |
|
|
417 |
+ |
k_match(kwd, hdl) /* header line matches keyword? */ |
418 |
+ |
register char *kwd, *hdl; |
419 |
+ |
{ |
420 |
+ |
if (!*hdl++ == '[') |
421 |
+ |
return(0); |
422 |
+ |
while (islower(*hdl) ? toupper(*hdl) == *kwd++ : *hdl == *kwd++) |
423 |
+ |
if (!*hdl++) |
424 |
+ |
return(0); |
425 |
+ |
return(!*kwd & *hdl == ']'); |
426 |
+ |
} |
427 |
+ |
|
428 |
+ |
|
429 |
+ |
char * |
430 |
+ |
keyargs(hdl) /* return keyword arguments */ |
431 |
+ |
register char *hdl; |
432 |
+ |
{ |
433 |
+ |
while (*hdl && *hdl++ != ']') |
434 |
+ |
; |
435 |
+ |
while (isspace(*hdl)) |
436 |
+ |
hdl++; |
437 |
+ |
return(hdl); |
438 |
+ |
} |
439 |
+ |
|
440 |
+ |
|
441 |
|
putheader(out) /* print header */ |
442 |
|
FILE *out; |
443 |
|
{ |
457 |
|
ies2rad(inpname, outname) /* convert IES file */ |
458 |
|
char *inpname, *outname; |
459 |
|
{ |
460 |
+ |
SRCINFO srcinfo; |
461 |
|
char buf[MAXLINE], tltid[MAXWORD]; |
462 |
+ |
char geomfile[128]; |
463 |
|
FILE *inpfp, *outfp; |
464 |
+ |
int lineno = 0; |
465 |
|
|
466 |
+ |
geomfile[0] = '\0'; |
467 |
+ |
srcinfo.isillum = 0; |
468 |
|
if (inpname == NULL) { |
469 |
|
inpname = "<stdin>"; |
470 |
|
inpfp = stdin; |
472 |
|
perror(inpname); |
473 |
|
return(-1); |
474 |
|
} |
475 |
< |
if ((outfp = fopen(fullname(buf,outname,T_RAD), "w")) == NULL) { |
475 |
> |
if (out2stdout) |
476 |
> |
outfp = stdout; |
477 |
> |
else if ((outfp = fopen(fullname(buf,outname,T_RAD), "w")) == NULL) { |
478 |
|
perror(buf); |
479 |
|
fclose(inpfp); |
480 |
|
return(-1); |
487 |
|
blanktrunc(buf); |
488 |
|
if (!buf[0]) |
489 |
|
continue; |
490 |
+ |
if (!lineno++ && !strncmp(buf, MAGICID, LMAGICID)) { |
491 |
+ |
filerev = atoi(buf+LMAGICID); |
492 |
+ |
if (filerev < FIRSTREV) |
493 |
+ |
filerev = FIRSTREV; |
494 |
+ |
else if (filerev > LASTREV) |
495 |
+ |
filerev = LASTREV; |
496 |
+ |
} |
497 |
|
fputs("#<", outfp); |
498 |
|
fputs(buf, outfp); |
499 |
|
putc('\n', outfp); |
500 |
< |
if (lampcolor == NULL) |
501 |
< |
lampcolor = matchlamp(buf); |
500 |
> |
if (lampcolor == NULL && checklamp(buf)) |
501 |
> |
lampcolor = matchlamp( buf[0] == '[' ? |
502 |
> |
keyargs(buf) : buf ); |
503 |
> |
if (keymatch(K_LMG, buf)) { /* geometry file */ |
504 |
> |
strcpy(geomfile, inpname); |
505 |
> |
strcpy(filename(geomfile), keyargs(buf)); |
506 |
> |
srcinfo.isillum = 1; |
507 |
> |
} |
508 |
|
} |
509 |
|
if (lampcolor == NULL) { |
510 |
|
fprintf(stderr, "%s: warning - no lamp type\n", inpname); |
511 |
+ |
fputs("# Unknown lamp type (used default)\n", outfp); |
512 |
|
lampcolor = defcolor; |
513 |
< |
} |
513 |
> |
} else if (lamptype == NULL) |
514 |
> |
fprintf(outfp,"# CIE(x,y) = (%f,%f)\n# Depreciation = %.1f%%\n", |
515 |
> |
lampcolor[3], lampcolor[4], 100.*lampcolor[5]); |
516 |
|
if (feof(inpfp)) { |
517 |
|
fprintf(stderr, "%s: not in IES format\n", inpname); |
518 |
|
goto readerr; |
526 |
|
fprintf(stderr, "%s: bad tilt data\n", inpname); |
527 |
|
goto readerr; |
528 |
|
} |
529 |
< |
if (dosource(inpfp, outfp, tltid, outname) != 0) { |
529 |
> |
if (dosource(&srcinfo, inpfp, outfp, tltid, outname) != 0) { |
530 |
|
fprintf(stderr, "%s: bad luminaire data\n", inpname); |
531 |
|
goto readerr; |
532 |
|
} |
428 |
– |
fclose(outfp); |
533 |
|
fclose(inpfp); |
534 |
+ |
/* cvgeometry closes outfp */ |
535 |
+ |
if (cvgeometry(geomfile, &srcinfo, outname, outfp) != 0) { |
536 |
+ |
fprintf(stderr, "%s: bad geometry file\n", geomfile); |
537 |
+ |
return(-1); |
538 |
+ |
} |
539 |
|
return(0); |
540 |
|
readerr: |
432 |
– |
fclose(outfp); |
541 |
|
fclose(inpfp); |
542 |
+ |
fclose(outfp); |
543 |
|
unlink(fullname(buf,outname,T_RAD)); |
544 |
|
return(-1); |
545 |
|
} |
618 |
|
} |
619 |
|
|
620 |
|
|
621 |
< |
dosource(in, out, mod, name) /* create source and distribution */ |
621 |
> |
dosource(sinf, in, out, mod, name) /* create source and distribution */ |
622 |
> |
SRCINFO *sinf; |
623 |
|
FILE *in, *out; |
624 |
|
char *mod, *name; |
625 |
|
{ |
516 |
– |
SHAPE srcshape; |
626 |
|
char buf[MAXPATH], id[MAXWORD]; |
627 |
|
FILE *datout; |
628 |
|
double mult, bfactor, pfactor, width, length, height, wattage; |
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 |
|
} |
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 |
|
fprintf(out, "%s %s source.cal ", |
680 |
< |
srcshape.type==SPHERE ? "corr" : "flatcorr", |
680 |
> |
sinf->type==SPHERE ? "corr" : |
681 |
> |
sinf->type==DISK ? "cylcorr" : "boxcorr", |
682 |
|
libname(buf,name,T_DST)); |
683 |
|
if (pmtype == PM_B) { |
684 |
|
if (FEQ(bounds[1][0],0.)) |
695 |
|
fprintf(out, "src_phi2 "); |
696 |
|
else |
697 |
|
fprintf(out, "src_phi "); |
698 |
< |
fprintf(out, "src_theta -my "); |
698 |
> |
fprintf(out, "src_theta "); |
699 |
|
if (FEQ(bounds[1][0],90.) && FEQ(bounds[1][1],270.)) |
700 |
|
fprintf(out, "-rz -90 "); |
701 |
|
} else |
702 |
|
fprintf(out, "src_theta "); |
703 |
|
} |
704 |
< |
fprintf(out, "\n0\n1 %g\n", multiplier*mult*bfactor*pfactor); |
705 |
< |
if (putsource(&srcshape, out, id, filename(name), |
704 |
> |
if (sinf->type == SPHERE) |
705 |
> |
fprintf(out, "\n0\n1 %g\n", sinf->mult/sinf->area); |
706 |
> |
else if (sinf->type == DISK) |
707 |
> |
fprintf(out, "\n0\n3 %g %g %g\n", sinf->mult, |
708 |
> |
sinf->l, sinf->h); |
709 |
> |
else |
710 |
> |
fprintf(out, "\n0\n4 %g %g %g %g\n", sinf->mult, |
711 |
> |
sinf->l, sinf->w, sinf->h); |
712 |
> |
if (putsource(sinf, out, id, filename(name), |
713 |
|
bounds[0][0]<90., bounds[0][1]>90.) != 0) |
714 |
|
return(-1); |
715 |
|
return(0); |
717 |
|
|
718 |
|
|
719 |
|
putsource(shp, fp, mod, name, dolower, doupper) /* put out source */ |
720 |
< |
SHAPE *shp; |
720 |
> |
SRCINFO *shp; |
721 |
|
FILE *fp; |
722 |
|
char *mod, *name; |
723 |
|
int dolower, doupper; |
724 |
|
{ |
725 |
< |
char buf[MAXWORD]; |
725 |
> |
int dosides = doupper && dolower && shp->h > MINDIM; |
726 |
> |
char lname[MAXWORD]; |
727 |
|
|
728 |
< |
fprintf(fp, "\n%s %s %s_light\n", mod, |
729 |
< |
illumrad>=MINDIM/2. ? "illum" : "light", |
730 |
< |
name); |
728 |
> |
strcat(strcpy(lname, name), "_light"); |
729 |
> |
fprintf(fp, "\n%s %s %s\n", mod, |
730 |
> |
shp->isillum ? "illum" : "light", lname); |
731 |
|
fprintf(fp, "0\n0\n3 %g %g %g\n", |
732 |
< |
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 |
< |
} |
732 |
> |
lampcolor[0], lampcolor[1], lampcolor[2]); |
733 |
|
switch (shp->type) { |
734 |
|
case RECT: |
625 |
– |
strcat(strcpy(buf, name), "_light"); |
735 |
|
if (dolower) |
736 |
< |
putrectsrc(shp, fp, buf, name, 0); |
736 |
> |
putrectsrc(shp, fp, lname, name, 0); |
737 |
|
if (doupper) |
738 |
< |
putrectsrc(shp, fp, buf, name, 1); |
739 |
< |
if (doupper && dolower && shp->h > MINDIM) { |
740 |
< |
strcat(strcpy(buf, name), "_glow"); |
632 |
< |
putsides(shp, fp, buf, name); |
633 |
< |
} |
738 |
> |
putrectsrc(shp, fp, lname, name, 1); |
739 |
> |
if (dosides) |
740 |
> |
putsides(shp, fp, lname, name); |
741 |
|
break; |
742 |
|
case DISK: |
636 |
– |
strcat(strcpy(buf, name), "_light"); |
743 |
|
if (dolower) |
744 |
< |
putdisksrc(shp, fp, buf, name, 0); |
744 |
> |
putdisksrc(shp, fp, lname, name, 0); |
745 |
|
if (doupper) |
746 |
< |
putdisksrc(shp, fp, buf, name, 1); |
747 |
< |
if (doupper && dolower && shp->h > MINDIM) { |
748 |
< |
strcat(strcpy(buf, name), "_glow"); |
643 |
< |
putcyl(shp, fp, buf, name); |
644 |
< |
} |
746 |
> |
putdisksrc(shp, fp, lname, name, 1); |
747 |
> |
if (dosides) |
748 |
> |
putcyl(shp, fp, lname, name); |
749 |
|
break; |
750 |
|
case SPHERE: |
751 |
< |
strcat(strcpy(buf, name), "_light"); |
648 |
< |
putspheresrc(shp, fp, buf, name); |
751 |
> |
putspheresrc(shp, fp, lname, name); |
752 |
|
break; |
753 |
|
} |
754 |
|
return(0); |
756 |
|
|
757 |
|
|
758 |
|
makeshape(shp, width, length, height) /* make source shape */ |
759 |
< |
register SHAPE *shp; |
759 |
> |
register SRCINFO *shp; |
760 |
|
double width, length, height; |
761 |
|
{ |
762 |
< |
if (illumrad >= MINDIM/2.) { |
762 |
> |
if (illumrad/meters2out >= MINDIM/2.) { |
763 |
> |
shp->isillum = 1; |
764 |
|
shp->type = SPHERE; |
765 |
< |
shp->w = shp->l = shp->h = 2.*illumrad; |
765 |
> |
shp->w = shp->l = shp->h = 2.*illumrad / meters2out; |
766 |
|
} else if (width < MINDIM) { |
767 |
|
width = -width; |
768 |
|
if (width < MINDIM) { |
805 |
|
|
806 |
|
|
807 |
|
putrectsrc(shp, fp, mod, name, up) /* rectangular source */ |
808 |
< |
SHAPE *shp; |
808 |
> |
SRCINFO *shp; |
809 |
|
FILE *fp; |
810 |
|
char *mod, *name; |
811 |
|
int up; |
818 |
|
|
819 |
|
|
820 |
|
putsides(shp, fp, mod, name) /* put out sides of box */ |
821 |
< |
register SHAPE *shp; |
821 |
> |
register SRCINFO *shp; |
822 |
|
FILE *fp; |
823 |
|
char *mod, *name; |
824 |
|
{ |
830 |
|
|
831 |
|
|
832 |
|
putrect(shp, fp, mod, name, suffix, a, b, c, d) /* put out a rectangle */ |
833 |
< |
SHAPE *shp; |
833 |
> |
SRCINFO *shp; |
834 |
|
FILE *fp; |
835 |
|
char *mod, *name, *suffix; |
836 |
|
int a, b, c, d; |
844 |
|
|
845 |
|
|
846 |
|
putpoint(shp, fp, p) /* put out a point */ |
847 |
< |
register SHAPE *shp; |
847 |
> |
register SRCINFO *shp; |
848 |
|
FILE *fp; |
849 |
|
int p; |
850 |
|
{ |
858 |
|
|
859 |
|
|
860 |
|
putdisksrc(shp, fp, mod, name, up) /* put out a disk source */ |
861 |
< |
register SHAPE *shp; |
861 |
> |
register SRCINFO *shp; |
862 |
|
FILE *fp; |
863 |
|
char *mod, *name; |
864 |
|
int up; |
880 |
|
|
881 |
|
|
882 |
|
putcyl(shp, fp, mod, name) /* put out a cylinder */ |
883 |
< |
register SHAPE *shp; |
883 |
> |
register SRCINFO *shp; |
884 |
|
FILE *fp; |
885 |
|
char *mod, *name; |
886 |
|
{ |
893 |
|
|
894 |
|
|
895 |
|
putspheresrc(shp, fp, mod, name) /* put out a sphere source */ |
896 |
< |
SHAPE *shp; |
896 |
> |
SRCINFO *shp; |
897 |
|
FILE *fp; |
898 |
|
char *mod, *name; |
899 |
|
{ |
1008 |
|
return(0); |
1009 |
|
*rp = atof(word); |
1010 |
|
return(1); |
1011 |
+ |
} |
1012 |
+ |
|
1013 |
+ |
|
1014 |
+ |
cvgeometry(inpname, sinf, outname, outfp) |
1015 |
+ |
char *inpname; |
1016 |
+ |
register SRCINFO *sinf; |
1017 |
+ |
char *outname; |
1018 |
+ |
FILE *outfp; /* close output file upon return */ |
1019 |
+ |
{ |
1020 |
+ |
char buf[256]; |
1021 |
+ |
register char *cp; |
1022 |
+ |
|
1023 |
+ |
if (inpname == NULL || !inpname[0]) { /* no geometry file */ |
1024 |
+ |
fclose(outfp); |
1025 |
+ |
return(0); |
1026 |
+ |
} |
1027 |
+ |
putc('\n', outfp); |
1028 |
+ |
strcpy(buf, "mgf2rad "); /* build mgf2rad command */ |
1029 |
+ |
cp = buf+8; |
1030 |
+ |
if (!FEQ(sinf->mult, 1.0)) { |
1031 |
+ |
sprintf(cp, "-m %f ", sinf->mult); |
1032 |
+ |
cp += strlen(cp); |
1033 |
+ |
} |
1034 |
+ |
sprintf(cp, "-g %f %s ", |
1035 |
+ |
sqrt(sinf->w*sinf->w + sinf->h*sinf->h + sinf->l*sinf->l), |
1036 |
+ |
inpname); |
1037 |
+ |
cp += strlen(cp); |
1038 |
+ |
if (instantiate) { /* instantiate octree */ |
1039 |
+ |
strcpy(cp, "| oconv - > "); |
1040 |
+ |
cp += 12; |
1041 |
+ |
fullname(cp,outname,T_OCT); |
1042 |
+ |
if (fdate(inpname) > fdate(outname) && |
1043 |
+ |
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 |
+ |
if (!FEQ(meters2out, 1.0)) { /* apply scalefactor */ |
1058 |
+ |
sprintf(cp, "| xform -s %f ", meters2out); |
1059 |
+ |
cp += strlen(cp); |
1060 |
+ |
} |
1061 |
+ |
if (!out2stdout) { |
1062 |
+ |
fclose(outfp); |
1063 |
+ |
strcpy(cp, ">> "); /* append works for DOS? */ |
1064 |
+ |
cp += 3; |
1065 |
+ |
fullname(cp,outname,T_RAD); |
1066 |
+ |
} |
1067 |
+ |
if (system(buf)) |
1068 |
+ |
return(-1); |
1069 |
+ |
} |
1070 |
+ |
return(0); |
1071 |
|
} |