| 1 | 
< | 
/* Copyright (c) 1990 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 <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 */ | 
| 112 | 
< | 
int     maxemitters = 1;                /* maximum emitters per hemisphere */ | 
| 111 | 
> | 
int     out2stdout = 0;                 /* put out to stdout r.t. file */ | 
| 112 | 
> | 
int     instantiate = 0;                /* instantiate geometry */ | 
| 113 | 
  | 
double  illumrad = 0.0;                 /* radius for illum sphere */ | 
| 114 | 
  | 
 | 
| 115 | 
  | 
typedef struct { | 
| 116 | 
+ | 
        int     isillum;                        /* do as illum */ | 
| 117 | 
  | 
        int     type;                           /* RECT, DISK, SPHERE */ | 
| 118 | 
+ | 
        double  mult;                           /* candela multiplier */ | 
| 119 | 
  | 
        double  w, l, h;                        /* width, length, height */ | 
| 120 | 
  | 
        double  area;                           /* max. projected area */ | 
| 121 | 
< | 
} SHAPE;                                /* a source shape */ | 
| 121 | 
> | 
} SRCINFO;                              /* a source shape (units=meters) */ | 
| 122 | 
  | 
 | 
| 123 | 
  | 
int     gargc;                          /* global argc (minus filenames) */ | 
| 124 | 
  | 
char    **gargv;                        /* global argv */ | 
| 125 | 
  | 
 | 
| 126 | 
  | 
extern char     *strcpy(), *strcat(), *stradd(), *tailtrunc(), *filetrunc(), | 
| 127 | 
< | 
                *filename(), *libname(), *fullname(), *malloc(); | 
| 128 | 
< | 
extern double   atof(); | 
| 127 | 
> | 
                *filename(), *libname(), *fullname(), *malloc(), | 
| 128 | 
> | 
                *getword(), *atos(); | 
| 129 | 
  | 
extern float    *matchlamp(); | 
| 130 | 
  | 
 | 
| 131 | 
+ | 
#define scnint(fp,ip)   cvtint(ip,getword(fp)) | 
| 132 | 
+ | 
#define scnflt(fp,rp)   cvtflt(rp,getword(fp)) | 
| 133 | 
+ | 
#define isint           isflt                   /* IES allows real as integer */ | 
| 134 | 
  | 
 | 
| 135 | 
+ | 
 | 
| 136 | 
  | 
main(argc, argv) | 
| 137 | 
  | 
int     argc; | 
| 138 | 
  | 
char    *argv[]; | 
| 204 | 
  | 
                case 'f':               /* lamp data file */ | 
| 205 | 
  | 
                        lampdat = argv[++i]; | 
| 206 | 
  | 
                        break; | 
| 207 | 
< | 
                case 'o':               /* output file name */ | 
| 207 | 
> | 
                case 'o':               /* output file root name */ | 
| 208 | 
  | 
                        outfile = argv[++i]; | 
| 209 | 
  | 
                        break; | 
| 210 | 
< | 
                case 's':               /* square emitters */ | 
| 211 | 
< | 
                        minaspect = .6; | 
| 162 | 
< | 
                        if (argv[i][2] == '/') { | 
| 163 | 
< | 
                                maxemitters = atoi(argv[i]+3); | 
| 164 | 
< | 
                                if (maxemitters < 1) | 
| 165 | 
< | 
                                        goto badopt; | 
| 166 | 
< | 
                        } | 
| 210 | 
> | 
                case 's':               /* output to stdout */ | 
| 211 | 
> | 
                        out2stdout = !out2stdout; | 
| 212 | 
  | 
                        break; | 
| 213 | 
  | 
                case 'i':               /* illum */ | 
| 214 | 
  | 
                        illumrad = atof(argv[++i]); | 
| 170 | 
– | 
                        if (illumrad < MINDIM) | 
| 171 | 
– | 
                                illumrad = MINDIM; | 
| 215 | 
  | 
                        break; | 
| 216 | 
+ | 
                case 'g':               /* instatiate geometry? */ | 
| 217 | 
+ | 
                        instantiate = !instantiate; | 
| 218 | 
+ | 
                        break; | 
| 219 | 
  | 
                case 't':               /* override lamp type */ | 
| 220 | 
  | 
                        lamptype = argv[++i]; | 
| 221 | 
  | 
                        break; | 
| 245 | 
  | 
                        exit(ies2rad(NULL, outfile) == 0 ? 0 : 1); | 
| 246 | 
  | 
                else if (i == argc-1) | 
| 247 | 
  | 
                        exit(ies2rad(argv[i], outfile) == 0 ? 0 : 1); | 
| 248 | 
< | 
                else { | 
| 249 | 
< | 
                        fprintf(stderr, "%s: single input file required\n", | 
| 204 | 
< | 
                                        argv[0]); | 
| 205 | 
< | 
                        exit(1); | 
| 206 | 
< | 
                } | 
| 248 | 
> | 
                else | 
| 249 | 
> | 
                        goto needsingle; | 
| 250 | 
  | 
        } else if (i >= argc) { | 
| 251 | 
  | 
                fprintf(stderr, "%s: missing output file specification\n", | 
| 252 | 
  | 
                                argv[0]); | 
| 253 | 
  | 
                exit(1); | 
| 254 | 
  | 
        } | 
| 255 | 
+ | 
        if (out2stdout && i != argc-1) | 
| 256 | 
+ | 
                goto needsingle; | 
| 257 | 
  | 
        status = 0; | 
| 258 | 
  | 
        for ( ; i < argc; i++) { | 
| 259 | 
  | 
                tailtrunc(strcpy(outname,filename(argv[i]))); | 
| 261 | 
  | 
                        status = 1; | 
| 262 | 
  | 
        } | 
| 263 | 
  | 
        exit(status); | 
| 264 | 
+ | 
needsingle: | 
| 265 | 
+ | 
        fprintf(stderr, "%s: single input file required\n", argv[0]); | 
| 266 | 
+ | 
        exit(1); | 
| 267 | 
  | 
} | 
| 268 | 
  | 
 | 
| 269 | 
  | 
 | 
| 333 | 
  | 
        else if (abspath(fname)) | 
| 334 | 
  | 
                strcpy(stradd(path, fname, 0), suffix); | 
| 335 | 
  | 
        else | 
| 336 | 
< | 
                libname(stradd(path, libdir, '/'), fname, suffix); | 
| 336 | 
> | 
                libname(stradd(path, libdir, DIRSEP), fname, suffix); | 
| 337 | 
  | 
 | 
| 338 | 
  | 
        return(path); | 
| 339 | 
  | 
} | 
| 346 | 
  | 
        if (abspath(fname)) | 
| 347 | 
  | 
                strcpy(stradd(path, fname, 0), suffix); | 
| 348 | 
  | 
        else | 
| 349 | 
< | 
                strcpy(stradd(stradd(path, prefdir, '/'), fname, 0), suffix); | 
| 349 | 
> | 
                strcpy(stradd(stradd(path, prefdir, DIRSEP), fname, 0), suffix); | 
| 350 | 
  | 
 | 
| 351 | 
  | 
        return(path); | 
| 352 | 
  | 
} | 
| 359 | 
  | 
        register char   *cp; | 
| 360 | 
  | 
 | 
| 361 | 
  | 
        for (cp = path; *path; path++) | 
| 362 | 
< | 
                if (*path == '/') | 
| 362 | 
> | 
                if (ISDIRSEP(*path)) | 
| 363 | 
  | 
                        cp = path+1; | 
| 364 | 
  | 
        return(cp); | 
| 365 | 
  | 
} | 
| 372 | 
  | 
        register char   *p1, *p2; | 
| 373 | 
  | 
 | 
| 374 | 
  | 
        for (p1 = p2 = path; *p2; p2++) | 
| 375 | 
< | 
                if (*p2 == '/') | 
| 375 | 
> | 
                if (ISDIRSEP(*p2)) | 
| 376 | 
  | 
                        p1 = p2; | 
| 377 | 
+ | 
        if (p1 == path && ISDIRSEP(*p1)) | 
| 378 | 
+ | 
                p1++; | 
| 379 | 
  | 
        *p1 = '\0'; | 
| 380 | 
  | 
        return(path); | 
| 381 | 
  | 
} | 
| 412 | 
  | 
} | 
| 413 | 
  | 
 | 
| 414 | 
  | 
 | 
| 415 | 
+ | 
k_match(kwd, hdl)                       /* header line matches keyword? */ | 
| 416 | 
+ | 
register char   *kwd, *hdl; | 
| 417 | 
+ | 
{ | 
| 418 | 
+ | 
        if (!*hdl++ == '[') | 
| 419 | 
+ | 
                return(0); | 
| 420 | 
+ | 
        while (islower(*hdl) ? toupper(*hdl) == *kwd++ : *hdl == *kwd++) | 
| 421 | 
+ | 
                if (!*hdl++) | 
| 422 | 
+ | 
                        return(0); | 
| 423 | 
+ | 
        return(!*kwd & *hdl == ']'); | 
| 424 | 
+ | 
} | 
| 425 | 
+ | 
 | 
| 426 | 
+ | 
 | 
| 427 | 
+ | 
char * | 
| 428 | 
+ | 
keyargs(hdl)                            /* return keyword arguments */ | 
| 429 | 
+ | 
register char   *hdl; | 
| 430 | 
+ | 
{ | 
| 431 | 
+ | 
        while (*hdl && *hdl++ != ']') | 
| 432 | 
+ | 
                ; | 
| 433 | 
+ | 
        while (isspace(*hdl)) | 
| 434 | 
+ | 
                hdl++; | 
| 435 | 
+ | 
        return(hdl); | 
| 436 | 
+ | 
} | 
| 437 | 
+ | 
 | 
| 438 | 
+ | 
 | 
| 439 | 
  | 
putheader(out)                          /* print header */ | 
| 440 | 
  | 
FILE    *out; | 
| 441 | 
  | 
{ | 
| 455 | 
  | 
ies2rad(inpname, outname)               /* convert IES file */ | 
| 456 | 
  | 
char    *inpname, *outname; | 
| 457 | 
  | 
{ | 
| 458 | 
+ | 
        SRCINFO srcinfo; | 
| 459 | 
  | 
        char    buf[MAXLINE], tltid[MAXWORD]; | 
| 460 | 
+ | 
        char    geomfile[128]; | 
| 461 | 
  | 
        FILE    *inpfp, *outfp; | 
| 462 | 
+ | 
        int     lineno = 0; | 
| 463 | 
  | 
 | 
| 464 | 
+ | 
        geomfile[0] = '\0'; | 
| 465 | 
+ | 
        srcinfo.isillum = 0; | 
| 466 | 
  | 
        if (inpname == NULL) { | 
| 467 | 
  | 
                inpname = "<stdin>"; | 
| 468 | 
  | 
                inpfp = stdin; | 
| 470 | 
  | 
                perror(inpname); | 
| 471 | 
  | 
                return(-1); | 
| 472 | 
  | 
        } | 
| 473 | 
< | 
        if ((outfp = fopen(fullname(buf,outname,T_RAD), "w")) == NULL) { | 
| 473 | 
> | 
        if (out2stdout) | 
| 474 | 
> | 
                outfp = stdout; | 
| 475 | 
> | 
        else if ((outfp = fopen(fullname(buf,outname,T_RAD), "w")) == NULL) { | 
| 476 | 
  | 
                perror(buf); | 
| 477 | 
  | 
                fclose(inpfp); | 
| 478 | 
  | 
                return(-1); | 
| 485 | 
  | 
                blanktrunc(buf); | 
| 486 | 
  | 
                if (!buf[0]) | 
| 487 | 
  | 
                        continue; | 
| 488 | 
+ | 
                if (!lineno++ && !strncmp(buf, MAGICID, LMAGICID)) { | 
| 489 | 
+ | 
                        filerev = atoi(buf+LMAGICID); | 
| 490 | 
+ | 
                        if (filerev < FIRSTREV) | 
| 491 | 
+ | 
                                filerev = FIRSTREV; | 
| 492 | 
+ | 
                        else if (filerev > LASTREV) | 
| 493 | 
+ | 
                                filerev = LASTREV; | 
| 494 | 
+ | 
                } | 
| 495 | 
  | 
                fputs("#<", outfp); | 
| 496 | 
  | 
                fputs(buf, outfp); | 
| 497 | 
  | 
                putc('\n', outfp); | 
| 498 | 
< | 
                if (lampcolor == NULL) | 
| 499 | 
< | 
                        lampcolor = matchlamp(buf); | 
| 498 | 
> | 
                if (lampcolor == NULL && checklamp(buf)) | 
| 499 | 
> | 
                        lampcolor = matchlamp( buf[0] == '[' ? | 
| 500 | 
> | 
                                                keyargs(buf) : buf ); | 
| 501 | 
> | 
                if (keymatch(K_LMG, buf)) {             /* geometry file */ | 
| 502 | 
> | 
                        strcpy(geomfile, inpname); | 
| 503 | 
> | 
                        strcpy(filename(geomfile), keyargs(buf)); | 
| 504 | 
> | 
                        srcinfo.isillum = 1; | 
| 505 | 
> | 
                } | 
| 506 | 
  | 
        } | 
| 507 | 
  | 
        if (lampcolor == NULL) { | 
| 508 | 
  | 
                fprintf(stderr, "%s: warning - no lamp type\n", inpname); | 
| 509 | 
+ | 
                fputs("# Unknown lamp type (used default)\n", outfp); | 
| 510 | 
  | 
                lampcolor = defcolor; | 
| 511 | 
< | 
        } | 
| 511 | 
> | 
        } else if (lamptype == NULL) | 
| 512 | 
> | 
                fprintf(outfp,"# CIE(x,y) = (%f,%f)\n# Depreciation = %.1f%%\n", | 
| 513 | 
> | 
                                lampcolor[3], lampcolor[4], 100.*lampcolor[5]); | 
| 514 | 
  | 
        if (feof(inpfp)) { | 
| 515 | 
  | 
                fprintf(stderr, "%s: not in IES format\n", inpname); | 
| 516 | 
  | 
                goto readerr; | 
| 517 | 
  | 
        } | 
| 518 | 
< | 
        sscanf(buf+TLTSTRLEN, "%s", tltid); | 
| 518 | 
> | 
        atos(tltid, MAXWORD, buf+TLTSTRLEN); | 
| 519 | 
  | 
        if (inpfp == stdin) | 
| 520 | 
  | 
                buf[0] = '\0'; | 
| 521 | 
  | 
        else | 
| 524 | 
  | 
                fprintf(stderr, "%s: bad tilt data\n", inpname); | 
| 525 | 
  | 
                goto readerr; | 
| 526 | 
  | 
        } | 
| 527 | 
< | 
        if (dosource(inpfp, outfp, tltid, outname) != 0) { | 
| 527 | 
> | 
        if (dosource(&srcinfo, inpfp, outfp, tltid, outname) != 0) { | 
| 528 | 
  | 
                fprintf(stderr, "%s: bad luminaire data\n", inpname); | 
| 529 | 
  | 
                goto readerr; | 
| 530 | 
  | 
        } | 
| 434 | 
– | 
        fclose(outfp); | 
| 531 | 
  | 
        fclose(inpfp); | 
| 532 | 
+ | 
                                        /* cvgeometry closes outfp */ | 
| 533 | 
+ | 
        if (cvgeometry(geomfile, &srcinfo, outname, outfp) != 0) { | 
| 534 | 
+ | 
                fprintf(stderr, "%s: bad geometry file\n", geomfile); | 
| 535 | 
+ | 
                return(-1); | 
| 536 | 
+ | 
        } | 
| 537 | 
  | 
        return(0); | 
| 538 | 
  | 
readerr: | 
| 438 | 
– | 
        fclose(outfp); | 
| 539 | 
  | 
        fclose(inpfp); | 
| 540 | 
+ | 
        fclose(outfp); | 
| 541 | 
  | 
        unlink(fullname(buf,outname,T_RAD)); | 
| 542 | 
  | 
        return(-1); | 
| 543 | 
  | 
} | 
| 559 | 
  | 
                datin = in; | 
| 560 | 
  | 
                strcpy(tltname, dfltname); | 
| 561 | 
  | 
        } else { | 
| 562 | 
< | 
                if (tltspec[0] == '/') | 
| 562 | 
> | 
                if (ISDIRSEP(tltspec[0])) | 
| 563 | 
  | 
                        strcpy(buf, tltspec); | 
| 564 | 
  | 
                else | 
| 565 | 
< | 
                        strcpy(stradd(buf, dir, '/'), tltspec); | 
| 565 | 
> | 
                        strcpy(stradd(buf, dir, DIRSEP), tltspec); | 
| 566 | 
  | 
                if ((datin = fopen(buf, "r")) == NULL) { | 
| 567 | 
  | 
                        perror(buf); | 
| 568 | 
  | 
                        return(-1); | 
| 576 | 
  | 
                                fclose(datin); | 
| 577 | 
  | 
                        return(-1); | 
| 578 | 
  | 
                } | 
| 579 | 
< | 
                if (fscanf(datin, "%d %d", &tlt_type, &nangles) != 2 | 
| 579 | 
> | 
                if (!scnint(datin,&tlt_type) || !scnint(datin,&nangles) | 
| 580 | 
  | 
                        || cvdata(datin,datout,1,&nangles,1.,minmax) != 0) { | 
| 581 | 
  | 
                        fprintf(stderr, "%s: data format error\n", tltspec); | 
| 582 | 
  | 
                        fclose(datout); | 
| 616 | 
  | 
} | 
| 617 | 
  | 
 | 
| 618 | 
  | 
 | 
| 619 | 
< | 
dosource(in, out, mod, name)            /* create source and distribution */ | 
| 619 | 
> | 
dosource(sinf, in, out, mod, name)      /* create source and distribution */ | 
| 620 | 
> | 
SRCINFO *sinf; | 
| 621 | 
  | 
FILE    *in, *out; | 
| 622 | 
  | 
char    *mod, *name; | 
| 623 | 
  | 
{ | 
| 522 | 
– | 
        SHAPE   srcshape; | 
| 624 | 
  | 
        char    buf[MAXPATH], id[MAXWORD]; | 
| 625 | 
  | 
        FILE    *datout; | 
| 626 | 
  | 
        double  mult, bfactor, pfactor, width, length, height, wattage; | 
| 628 | 
  | 
        int     nangles[2], pmtype, unitype; | 
| 629 | 
  | 
        double  d1; | 
| 630 | 
  | 
 | 
| 631 | 
< | 
        if (fscanf(in, "%*d %*f %lf %d %d %d %d %lf %lf %lf %lf %lf %lf", | 
| 632 | 
< | 
                        &mult, &nangles[0], &nangles[1], &pmtype, &unitype, | 
| 633 | 
< | 
                        &width, &length, &height, &bfactor, &pfactor, | 
| 634 | 
< | 
                        &wattage) != 11) { | 
| 631 | 
> | 
        if (!isint(getword(in)) || !isflt(getword(in)) || !scnflt(in,&mult) | 
| 632 | 
> | 
                        || !scnint(in,&nangles[0]) || !scnint(in,&nangles[1]) | 
| 633 | 
> | 
                        || !scnint(in,&pmtype) || !scnint(in,&unitype) | 
| 634 | 
> | 
                        || !scnflt(in,&width) || !scnflt(in,&length) | 
| 635 | 
> | 
                        || !scnflt(in,&height) || !scnflt(in,&bfactor) | 
| 636 | 
> | 
                        || !scnflt(in,&pfactor) || !scnflt(in,&wattage)) { | 
| 637 | 
  | 
                fprintf(stderr, "dosource: bad lamp specification\n"); | 
| 638 | 
  | 
                return(-1); | 
| 639 | 
  | 
        } | 
| 640 | 
+ | 
        sinf->mult = multiplier*mult*bfactor*pfactor; | 
| 641 | 
  | 
        if (nangles[0] < 2 || nangles[1] < 1) { | 
| 642 | 
  | 
                fprintf(stderr, "dosource: too few measured angles\n"); | 
| 643 | 
  | 
                return(-1); | 
| 647 | 
  | 
                length *= F_M; | 
| 648 | 
  | 
                height *= F_M; | 
| 649 | 
  | 
        } | 
| 650 | 
< | 
        if (makeshape(&srcshape, width, length, height) != 0) { | 
| 650 | 
> | 
        if (makeshape(sinf, width, length, height) != 0) { | 
| 651 | 
  | 
                fprintf(stderr, "dosource: illegal source dimensions"); | 
| 652 | 
  | 
                return(-1); | 
| 653 | 
  | 
        } | 
| 655 | 
  | 
                perror(buf); | 
| 656 | 
  | 
                return(-1); | 
| 657 | 
  | 
        } | 
| 658 | 
< | 
        if (cvdata(in, datout, 2, nangles, 1./470., bounds) != 0) { | 
| 658 | 
> | 
        if (cvdata(in, datout, 2, nangles, 1./WHTEFFICACY, bounds) != 0) { | 
| 659 | 
  | 
                fprintf(stderr, "dosource: bad distribution data\n"); | 
| 660 | 
  | 
                fclose(datout); | 
| 661 | 
  | 
                unlink(fullname(buf,name,T_DST)); | 
| 671 | 
  | 
        else if (pmtype == PM_B) | 
| 672 | 
  | 
                fprintf(out, "5 "); | 
| 673 | 
  | 
        else if (FEQ(bounds[1][0],90.) && FEQ(bounds[1][1],270.)) | 
| 674 | 
< | 
                fprintf(out, "8 "); | 
| 674 | 
> | 
                fprintf(out, "7 "); | 
| 675 | 
  | 
        else | 
| 676 | 
< | 
                fprintf(out, "6 "); | 
| 676 | 
> | 
                fprintf(out, "5 "); | 
| 677 | 
  | 
        fprintf(out, "%s %s source.cal ", | 
| 678 | 
< | 
                        srcshape.type==SPHERE ? "corr" : "flatcorr", | 
| 678 | 
> | 
                        sinf->type==SPHERE ? "corr" : "flatcorr", | 
| 679 | 
  | 
                        libname(buf,name,T_DST)); | 
| 680 | 
  | 
        if (pmtype == PM_B) { | 
| 681 | 
  | 
                if (FEQ(bounds[1][0],0.)) | 
| 692 | 
  | 
                                fprintf(out, "src_phi2 "); | 
| 693 | 
  | 
                        else | 
| 694 | 
  | 
                                fprintf(out, "src_phi "); | 
| 695 | 
< | 
                        fprintf(out, "src_theta -my "); | 
| 695 | 
> | 
                        fprintf(out, "src_theta "); | 
| 696 | 
  | 
                        if (FEQ(bounds[1][0],90.) && FEQ(bounds[1][1],270.)) | 
| 697 | 
  | 
                                fprintf(out, "-rz -90 "); | 
| 698 | 
  | 
                } else | 
| 699 | 
  | 
                        fprintf(out, "src_theta "); | 
| 700 | 
  | 
        } | 
| 701 | 
< | 
        fprintf(out, "\n0\n1 %g\n", multiplier*mult*bfactor*pfactor); | 
| 702 | 
< | 
        if (putsource(&srcshape, out, id, filename(name), | 
| 701 | 
> | 
        fprintf(out, "\n0\n1 %g\n", sinf->mult); | 
| 702 | 
> | 
        if (putsource(sinf, out, id, filename(name), | 
| 703 | 
  | 
                        bounds[0][0]<90., bounds[0][1]>90.) != 0) | 
| 704 | 
  | 
                return(-1); | 
| 705 | 
  | 
        return(0); | 
| 707 | 
  | 
 | 
| 708 | 
  | 
 | 
| 709 | 
  | 
putsource(shp, fp, mod, name, dolower, doupper)         /* put out source */ | 
| 710 | 
< | 
SHAPE   *shp; | 
| 710 | 
> | 
SRCINFO *shp; | 
| 711 | 
  | 
FILE    *fp; | 
| 712 | 
  | 
char    *mod, *name; | 
| 713 | 
  | 
int     dolower, doupper; | 
| 715 | 
  | 
        char    buf[MAXWORD]; | 
| 716 | 
  | 
         | 
| 717 | 
  | 
        fprintf(fp, "\n%s %s %s_light\n", mod, | 
| 718 | 
< | 
                        illumrad>=MINDIM/2. ? "illum" : "light", | 
| 718 | 
> | 
                        shp->isillum ? "illum" : "light", | 
| 719 | 
  | 
                        name); | 
| 720 | 
  | 
        fprintf(fp, "0\n0\n3 %g %g %g\n", | 
| 721 | 
  | 
                        lampcolor[0]/shp->area, | 
| 722 | 
  | 
                        lampcolor[1]/shp->area, | 
| 723 | 
  | 
                        lampcolor[2]/shp->area); | 
| 724 | 
< | 
        if (doupper && dolower && shp->type != SPHERE && shp->h > MINDIM) { | 
| 725 | 
< | 
                fprintf(fp, "\n%s glow %s_glow\n", mod, name); | 
| 726 | 
< | 
                fprintf(fp, "0\n0\n4 %g %g %g 0\n", | 
| 727 | 
< | 
                                lampcolor[0]/shp->area, | 
| 728 | 
< | 
                                lampcolor[1]/shp->area, | 
| 729 | 
< | 
                                lampcolor[2]/shp->area); | 
| 730 | 
< | 
        } | 
| 724 | 
> | 
        if (doupper && dolower && shp->type != SPHERE && shp->h > MINDIM) | 
| 725 | 
> | 
                if (shp->isillum) { | 
| 726 | 
> | 
                        fprintf(fp, "\nvoid illum %s_glow\n", name); | 
| 727 | 
> | 
                        fprintf(fp, "0\n0\n3 0 0 0\n"); | 
| 728 | 
> | 
                } else { | 
| 729 | 
> | 
                        fprintf(fp, "\n%s glow %s_glow\n", mod, name); | 
| 730 | 
> | 
                        fprintf(fp, "0\n0\n4 %g %g %g -1\n", | 
| 731 | 
> | 
                                        lampcolor[0]/shp->area, | 
| 732 | 
> | 
                                        lampcolor[1]/shp->area, | 
| 733 | 
> | 
                                        lampcolor[2]/shp->area); | 
| 734 | 
> | 
                } | 
| 735 | 
  | 
        switch (shp->type) { | 
| 736 | 
  | 
        case RECT: | 
| 737 | 
  | 
                strcat(strcpy(buf, name), "_light"); | 
| 765 | 
  | 
 | 
| 766 | 
  | 
 | 
| 767 | 
  | 
makeshape(shp, width, length, height)           /* make source shape */ | 
| 768 | 
< | 
register SHAPE  *shp; | 
| 768 | 
> | 
register SRCINFO        *shp; | 
| 769 | 
  | 
double  width, length, height; | 
| 770 | 
  | 
{ | 
| 771 | 
< | 
        if (illumrad >= MINDIM/2.) { | 
| 771 | 
> | 
        if (illumrad/meters2out >= MINDIM/2.) { | 
| 772 | 
> | 
                shp->isillum = 1; | 
| 773 | 
  | 
                shp->type = SPHERE; | 
| 774 | 
< | 
                shp->w = shp->l = shp->h = 2.*illumrad; | 
| 774 | 
> | 
                shp->w = shp->l = shp->h = 2.*illumrad / meters2out; | 
| 775 | 
  | 
        } else if (width < MINDIM) { | 
| 776 | 
  | 
                width = -width; | 
| 777 | 
  | 
                if (width < MINDIM) { | 
| 814 | 
  | 
 | 
| 815 | 
  | 
 | 
| 816 | 
  | 
putrectsrc(shp, fp, mod, name, up)              /* rectangular source */ | 
| 817 | 
< | 
SHAPE   *shp; | 
| 817 | 
> | 
SRCINFO *shp; | 
| 818 | 
  | 
FILE    *fp; | 
| 819 | 
  | 
char    *mod, *name; | 
| 820 | 
  | 
int     up; | 
| 827 | 
  | 
 | 
| 828 | 
  | 
 | 
| 829 | 
  | 
putsides(shp, fp, mod, name)                    /* put out sides of box */ | 
| 830 | 
< | 
register SHAPE  *shp; | 
| 830 | 
> | 
register SRCINFO        *shp; | 
| 831 | 
  | 
FILE    *fp; | 
| 832 | 
  | 
char    *mod, *name; | 
| 833 | 
  | 
{ | 
| 839 | 
  | 
         | 
| 840 | 
  | 
 | 
| 841 | 
  | 
putrect(shp, fp, mod, name, suffix, a, b, c, d) /* put out a rectangle */ | 
| 842 | 
< | 
SHAPE   *shp; | 
| 842 | 
> | 
SRCINFO *shp; | 
| 843 | 
  | 
FILE    *fp; | 
| 844 | 
  | 
char    *mod, *name, *suffix; | 
| 845 | 
  | 
int     a, b, c, d; | 
| 853 | 
  | 
 | 
| 854 | 
  | 
 | 
| 855 | 
  | 
putpoint(shp, fp, p)                            /* put out a point */ | 
| 856 | 
< | 
register SHAPE  *shp; | 
| 856 | 
> | 
register SRCINFO        *shp; | 
| 857 | 
  | 
FILE    *fp; | 
| 858 | 
  | 
int     p; | 
| 859 | 
  | 
{ | 
| 867 | 
  | 
 | 
| 868 | 
  | 
 | 
| 869 | 
  | 
putdisksrc(shp, fp, mod, name, up)              /* put out a disk source */ | 
| 870 | 
< | 
register SHAPE  *shp; | 
| 870 | 
> | 
register SRCINFO        *shp; | 
| 871 | 
  | 
FILE    *fp; | 
| 872 | 
  | 
char    *mod, *name; | 
| 873 | 
  | 
int     up; | 
| 889 | 
  | 
 | 
| 890 | 
  | 
 | 
| 891 | 
  | 
putcyl(shp, fp, mod, name)                      /* put out a cylinder */ | 
| 892 | 
< | 
register SHAPE  *shp; | 
| 892 | 
> | 
register SRCINFO        *shp; | 
| 893 | 
  | 
FILE    *fp; | 
| 894 | 
  | 
char    *mod, *name; | 
| 895 | 
  | 
{ | 
| 902 | 
  | 
 | 
| 903 | 
  | 
 | 
| 904 | 
  | 
putspheresrc(shp, fp, mod, name)                /* put out a sphere source */ | 
| 905 | 
< | 
SHAPE   *shp; | 
| 905 | 
> | 
SRCINFO *shp; | 
| 906 | 
  | 
FILE    *fp; | 
| 907 | 
  | 
char    *mod, *name; | 
| 908 | 
  | 
{ | 
| 916 | 
  | 
int     ndim, npts[]; | 
| 917 | 
  | 
double  mult, lim[][2]; | 
| 918 | 
  | 
{ | 
| 919 | 
< | 
        register double *pt[4]; | 
| 919 | 
> | 
        double  *pt[4]; | 
| 920 | 
  | 
        register int    i, j; | 
| 921 | 
  | 
        double  val; | 
| 922 | 
  | 
        int     total; | 
| 932 | 
  | 
        for (i = 0; i < ndim; i++) { | 
| 933 | 
  | 
                pt[i] = (double *)malloc(npts[i]*sizeof(double)); | 
| 934 | 
  | 
                for (j = 0; j < npts[i]; j++) | 
| 935 | 
< | 
                        fscanf(in, "%lf", &pt[i][j]); | 
| 935 | 
> | 
                        if (!scnflt(in, &pt[i][j])) | 
| 936 | 
> | 
                                return(-1); | 
| 937 | 
  | 
                if (lim != NULL) { | 
| 938 | 
  | 
                        lim[i][0] = pt[i][0]; | 
| 939 | 
  | 
                        lim[i][1] = pt[i][npts[i]-1]; | 
| 964 | 
  | 
        for (i = 0; i < total; i++) { | 
| 965 | 
  | 
                if (i%4 == 0) | 
| 966 | 
  | 
                        putc('\n', out); | 
| 967 | 
< | 
                if (fscanf(in, "%lf", &val) != 1) | 
| 967 | 
> | 
                if (!scnflt(in, &val)) | 
| 968 | 
  | 
                        return(-1); | 
| 969 | 
  | 
                fprintf(out, "\t%g", val*mult); | 
| 970 | 
  | 
        } | 
| 971 | 
  | 
        putc('\n', out); | 
| 972 | 
+ | 
        return(0); | 
| 973 | 
+ | 
} | 
| 974 | 
+ | 
 | 
| 975 | 
+ | 
 | 
| 976 | 
+ | 
char * | 
| 977 | 
+ | 
getword(fp)                     /* scan a word from fp */ | 
| 978 | 
+ | 
register FILE   *fp; | 
| 979 | 
+ | 
{ | 
| 980 | 
+ | 
        static char     word[MAXWORD]; | 
| 981 | 
+ | 
        register char   *cp; | 
| 982 | 
+ | 
        register int    c; | 
| 983 | 
+ | 
 | 
| 984 | 
+ | 
        while (isspace(c=getc(fp))) | 
| 985 | 
+ | 
                ; | 
| 986 | 
+ | 
        for (cp = word; c != EOF && cp < word+MAXWORD-1; | 
| 987 | 
+ | 
                        *cp++ = c, c = getc(fp)) | 
| 988 | 
+ | 
                if (isspace(c) || c == ',') { | 
| 989 | 
+ | 
                        while (isspace(c)) | 
| 990 | 
+ | 
                                c = getc(fp); | 
| 991 | 
+ | 
                        if (c != EOF & c != ',') | 
| 992 | 
+ | 
                                ungetc(c, fp); | 
| 993 | 
+ | 
                        *cp = '\0'; | 
| 994 | 
+ | 
                        return(word); | 
| 995 | 
+ | 
                } | 
| 996 | 
+ | 
        *cp = '\0'; | 
| 997 | 
+ | 
        return(cp > word ? word : NULL); | 
| 998 | 
+ | 
} | 
| 999 | 
+ | 
 | 
| 1000 | 
+ | 
 | 
| 1001 | 
+ | 
cvtint(ip, word)                /* convert a word to an integer */ | 
| 1002 | 
+ | 
int     *ip; | 
| 1003 | 
+ | 
char    *word; | 
| 1004 | 
+ | 
{ | 
| 1005 | 
+ | 
        if (word == NULL || !isint(word)) | 
| 1006 | 
+ | 
                return(0); | 
| 1007 | 
+ | 
        *ip = atoi(word); | 
| 1008 | 
+ | 
        return(1); | 
| 1009 | 
+ | 
} | 
| 1010 | 
+ | 
 | 
| 1011 | 
+ | 
 | 
| 1012 | 
+ | 
cvtflt(rp, word)                /* convert a word to a double */ | 
| 1013 | 
+ | 
double  *rp; | 
| 1014 | 
+ | 
char    *word; | 
| 1015 | 
+ | 
{ | 
| 1016 | 
+ | 
        if (word == NULL || !isflt(word)) | 
| 1017 | 
+ | 
                return(0); | 
| 1018 | 
+ | 
        *rp = atof(word); | 
| 1019 | 
+ | 
        return(1); | 
| 1020 | 
+ | 
} | 
| 1021 | 
+ | 
 | 
| 1022 | 
+ | 
 | 
| 1023 | 
+ | 
cvgeometry(inpname, sinf, outname, outfp) | 
| 1024 | 
+ | 
char    *inpname; | 
| 1025 | 
+ | 
register SRCINFO        *sinf; | 
| 1026 | 
+ | 
char    *outname; | 
| 1027 | 
+ | 
FILE    *outfp;                 /* close output file upon return */ | 
| 1028 | 
+ | 
{ | 
| 1029 | 
+ | 
        char    buf[256]; | 
| 1030 | 
+ | 
        register char   *cp; | 
| 1031 | 
+ | 
 | 
| 1032 | 
+ | 
        if (inpname == NULL || !inpname[0]) {   /* no geometry file */ | 
| 1033 | 
+ | 
                fclose(outfp); | 
| 1034 | 
+ | 
                return(0); | 
| 1035 | 
+ | 
        } | 
| 1036 | 
+ | 
        putc('\n', outfp); | 
| 1037 | 
+ | 
        strcpy(buf, "mgf2rad ");                /* build mgf2rad command */ | 
| 1038 | 
+ | 
        cp = buf+8; | 
| 1039 | 
+ | 
        if (!FEQ(sinf->mult, 1.0)) { | 
| 1040 | 
+ | 
                sprintf(cp, "-m %f ", sinf->mult); | 
| 1041 | 
+ | 
                cp += strlen(cp); | 
| 1042 | 
+ | 
        } | 
| 1043 | 
+ | 
        sprintf(cp, "-g %f %s ", | 
| 1044 | 
+ | 
                sqrt(sinf->w*sinf->w + sinf->h*sinf->h + sinf->l*sinf->l), | 
| 1045 | 
+ | 
                        inpname); | 
| 1046 | 
+ | 
        cp += strlen(cp); | 
| 1047 | 
+ | 
        if (instantiate) {              /* instantiate octree */ | 
| 1048 | 
+ | 
                strcpy(cp, "| oconv - > "); | 
| 1049 | 
+ | 
                cp += 12; | 
| 1050 | 
+ | 
                fullname(cp,outname,T_OCT); | 
| 1051 | 
+ | 
                if (system(buf)) {              /* create octree */ | 
| 1052 | 
+ | 
                        fclose(outfp); | 
| 1053 | 
+ | 
                        return(-1); | 
| 1054 | 
+ | 
                } | 
| 1055 | 
+ | 
                fprintf(outfp, "void instance %s_inst\n", outname); | 
| 1056 | 
+ | 
                if (!FEQ(meters2out, 1.0)) | 
| 1057 | 
+ | 
                        fprintf(outfp, "3 %s -s %f\n", | 
| 1058 | 
+ | 
                                        libname(buf,outname,T_OCT), | 
| 1059 | 
+ | 
                                        meters2out); | 
| 1060 | 
+ | 
                else | 
| 1061 | 
+ | 
                        fprintf(outfp, "1 %s\n", libname(buf,outname,T_OCT)); | 
| 1062 | 
+ | 
                fprintf(outfp, "0\n0\n"); | 
| 1063 | 
+ | 
                fclose(outfp); | 
| 1064 | 
+ | 
        } else {                        /* else append to luminaire file */ | 
| 1065 | 
+ | 
                if (!FEQ(meters2out, 1.0)) {    /* apply scalefactor */ | 
| 1066 | 
+ | 
                        sprintf(cp, "| xform -s %f ", meters2out); | 
| 1067 | 
+ | 
                        cp += strlen(cp); | 
| 1068 | 
+ | 
                } | 
| 1069 | 
+ | 
                if (!out2stdout) { | 
| 1070 | 
+ | 
                        fclose(outfp); | 
| 1071 | 
+ | 
                        strcpy(cp, ">> ");      /* append works for DOS? */ | 
| 1072 | 
+ | 
                        cp += 3; | 
| 1073 | 
+ | 
                        fullname(cp,outname,T_RAD); | 
| 1074 | 
+ | 
                } | 
| 1075 | 
+ | 
                if (system(buf)) | 
| 1076 | 
+ | 
                        return(-1); | 
| 1077 | 
+ | 
        } | 
| 1078 | 
  | 
        return(0); | 
| 1079 | 
  | 
} |