--- ray/src/cv/ies2rad.c 2018/06/04 18:53:09 2.29 +++ ray/src/cv/ies2rad.c 2019/12/28 18:05:14 2.32 @@ -1,5 +1,5 @@ #ifndef lint -static const char RCSid[] = "$Id: ies2rad.c,v 2.29 2018/06/04 18:53:09 greg Exp $"; +static const char RCSid[] = "$Id: ies2rad.c,v 2.32 2019/12/28 18:05:14 greg Exp $"; #endif /* * ies2rad -- Convert IES luminaire data to Radiance description @@ -20,10 +20,9 @@ static const char RCSid[] = "$Id: ies2rad.c,v 2.29 201 * Radiance (θ,φ) luminaire coordinates and then apply photometric and * tilt data to generate Radiance light. θ is altitude from the * negative z-axis and φ is azimuth from the positive x-axis, - * increasing towards the positive y-axis. [??? Greg, is there a - * source for this convention?] This system matches none of the usual - * goniophotometric conventions, but it is closest to IES type C; V in - * type C photometry is θ in Radiance and L is -φ. + * increasing towards the positive y-axis. This system matches none of + * the usual goniophotometric conventions, but it is closest to IES + * type C; V in type C photometry is θ in Radiance and L is -φ. * * The ies2rad scene description for a luminaire LUM, with tilt data, * uses the following Radiance scene description primitives: @@ -70,10 +69,7 @@ static const char RCSid[] = "$Id: ies2rad.c,v 2.29 201 * Extensive comments added by Randolph Fritz May2018 */ -#include -#include #include -#include #include #include "rtio.h" @@ -92,6 +88,9 @@ static const char RCSid[] = "$Id: ies2rad.c,v 2.29 201 /* Since 1991, LM-63 files have begun with the magic keyword IESNA */ #define MAGICID "IESNA" #define LMAGICID 5 +/* But newer files start with IESNA:LM-63- */ +#define MAGICID2 "IESNA:LM-63-" +#define LMAGICID2 12 /* ies2rad supports the 1986, 1991, and 1995 versions of * LM-63. FIRSTREV describes the first version; LASTREV describes the * 1995 version. */ @@ -204,8 +203,8 @@ int filerev = FIRSTREV; #define U_METERS 2 /* string lengths */ -/* Maximum input line is 132 characters including CR LF at end. */ -#define MAXLINE 133 +/* Maximum input line is 256 characters including CR LF at end. */ +#define MAXLINE 257 #define RMAXWORD 76 /* End of LM-63-related #defines */ @@ -725,6 +724,9 @@ k_match( char *hdl /* header line */ ) { + /* Skip leading spaces */ + while (isspace(*hdl)) + hdl++; /* The line has to begin with '[' */ if (*hdl++ != '[') return(0); @@ -840,11 +842,11 @@ ies2rad( /* convert IES file */ continue; /* increment the header line count, and check for the * "TILT=" line that terminates the header */ - if (!lineno++ && strncmp(buf, MAGICID, LMAGICID) == 0) { - /* This code doesn't work for LM-63-95 and - * LM-63-02 files and will instead default to - * LM-63-86. */ - filerev = atoi(buf+LMAGICID); + if (!lineno++) { /* first line may be magic */ + if (!strncmp(buf, MAGICID2, LMAGICID2)) + filerev = atoi(buf+LMAGICID2) - 1900; + else if (!strncmp(buf, MAGICID, LMAGICID)) + filerev = atoi(buf+LMAGICID); if (filerev < FIRSTREV) filerev = FIRSTREV; else if (filerev > LASTREV) @@ -860,7 +862,7 @@ ies2rad( /* convert IES file */ * in the "[LAMP]" and "[LAMPCAT]" keyword lines; * otherwise check all lines. */ if (lampcolor == NULL && checklamp(buf)) - lampcolor = matchlamp( buf[0] == '[' ? + lampcolor = matchlamp(*sskip2(buf,0) == '[' ? keyargs(buf) : buf ); /* Look for a materials and geometry file in the keywords. */ if (keymatch(K_LMG, buf)) { @@ -881,6 +883,7 @@ ies2rad( /* convert IES file */ } else if (lamptype == NULL) fprintf(outfp,"# CIE(x,y) = (%f,%f)\n# Depreciation = %.1f%%\n", lampcolor[3], lampcolor[4], 100.*lampcolor[5]); + /* If the file ended before a "TILT=" line, that's an error. */ if (feof(inpfp)) { fprintf(stderr, "%s: not in IES format\n", inpname);