--- ray/src/cv/ies2rad.c 1991/01/29 12:19:10 1.3 +++ ray/src/cv/ies2rad.c 1993/03/18 11:21:21 2.6 @@ -1,4 +1,4 @@ -/* Copyright (c) 1990 Regents of the University of California */ +/* Copyright (c) 1992 Regents of the University of California */ #ifndef lint static char SCCSid[] = "$SunId$ LBL"; @@ -13,6 +13,7 @@ static char SCCSid[] = "$SunId$ LBL"; #include #include #include "color.h" +#include "paths.h" #define PI 3.14159265358979323846 /* floating comparisons */ @@ -35,7 +36,6 @@ static char SCCSid[] = "$SunId$ LBL"; /* string lengths */ #define MAXLINE 132 #define MAXWORD 76 -#define MAXPATH 128 /* file types */ #define T_RAD ".rad" #define T_DST ".dat" @@ -49,7 +49,7 @@ static char SCCSid[] = "$SunId$ LBL"; #define F_M .3048 /* feet to meters */ -#define abspath(p) ((p)[0] == '/' || (p)[0] == '.') +#define abspath(p) (ISDIRSEP((p)[0]) || (p)[0] == '.') static char default_name[] = "default"; @@ -64,8 +64,6 @@ float defcolor[3] = {1.,1.,1.}; /* default lamp color float *lampcolor = defcolor; /* pointer to current lamp color */ double multiplier = 1.0; /* multiplier for all light sources */ char units[64] = "meters"; /* output units */ -double minaspect = 0.0; /* minimum allowed aspect ratio */ -int maxemitters = 1; /* maximum emitters per hemisphere */ double illumrad = 0.0; /* radius for illum sphere */ typedef struct { @@ -78,11 +76,15 @@ int gargc; /* global argc (minus filenames) */ char **gargv; /* global argv */ extern char *strcpy(), *strcat(), *stradd(), *tailtrunc(), *filetrunc(), - *filename(), *libname(), *fullname(), *malloc(); -extern double atof(); + *filename(), *libname(), *fullname(), *malloc(), + *getword(), *atos(); extern float *matchlamp(); +#define scnint(fp,ip) cvtint(ip,getword(fp)) +#define scnflt(fp,rp) cvtflt(rp,getword(fp)) +#define isint isflt /* IES allows real as integer */ + main(argc, argv) int argc; char *argv[]; @@ -157,14 +159,6 @@ char *argv[]; case 'o': /* output file name */ outfile = argv[++i]; break; - case 's': /* square emitters */ - minaspect = .6; - if (argv[i][2] == '/') { - maxemitters = atoi(argv[i]+3); - if (maxemitters < 1) - goto badopt; - } - break; case 'i': /* illum */ illumrad = atof(argv[++i]); if (illumrad < MINDIM) @@ -285,7 +279,7 @@ char *path, *fname, *suffix; else if (abspath(fname)) strcpy(stradd(path, fname, 0), suffix); else - libname(stradd(path, libdir, '/'), fname, suffix); + libname(stradd(path, libdir, DIRSEP), fname, suffix); return(path); } @@ -298,7 +292,7 @@ char *path, *fname, *suffix; if (abspath(fname)) strcpy(stradd(path, fname, 0), suffix); else - strcpy(stradd(stradd(path, prefdir, '/'), fname, 0), suffix); + strcpy(stradd(stradd(path, prefdir, DIRSEP), fname, 0), suffix); return(path); } @@ -311,7 +305,7 @@ register char *path; register char *cp; for (cp = path; *path; path++) - if (*path == '/') + if (ISDIRSEP(*path)) cp = path+1; return(cp); } @@ -324,7 +318,7 @@ char *path; register char *p1, *p2; for (p1 = p2 = path; *p2; p2++) - if (*p2 == '/') + if (ISDIRSEP(*p2)) p1 = p2; *p1 = '\0'; return(path); @@ -418,7 +412,7 @@ char *inpname, *outname; fprintf(stderr, "%s: not in IES format\n", inpname); goto readerr; } - sscanf(buf+TLTSTRLEN, "%s", tltid); + atos(tltid, MAXWORD, buf+TLTSTRLEN); if (inpfp == stdin) buf[0] = '\0'; else @@ -458,10 +452,10 @@ char *dir, *tltspec, *dfltname, *tltid; datin = in; strcpy(tltname, dfltname); } else { - if (tltspec[0] == '/') + if (ISDIRSEP(tltspec[0])) strcpy(buf, tltspec); else - strcpy(stradd(buf, dir, '/'), tltspec); + strcpy(stradd(buf, dir, DIRSEP), tltspec); if ((datin = fopen(buf, "r")) == NULL) { perror(buf); return(-1); @@ -475,7 +469,7 @@ char *dir, *tltspec, *dfltname, *tltid; fclose(datin); return(-1); } - if (fscanf(datin, "%d %d", &tlt_type, &nangles) != 2 + if (!scnint(datin,&tlt_type) || !scnint(datin,&nangles) || cvdata(datin,datout,1,&nangles,1.,minmax) != 0) { fprintf(stderr, "%s: data format error\n", tltspec); fclose(datout); @@ -527,10 +521,12 @@ char *mod, *name; int nangles[2], pmtype, unitype; double d1; - if (fscanf(in, "%*d %*f %lf %d %d %d %d %lf %lf %lf %lf %lf %lf", - &mult, &nangles[0], &nangles[1], &pmtype, &unitype, - &width, &length, &height, &bfactor, &pfactor, - &wattage) != 11) { + if (!isint(getword(in)) || !isflt(getword(in)) || !scnflt(in,&mult) + || !scnint(in,&nangles[0]) || !scnint(in,&nangles[1]) + || !scnint(in,&pmtype) || !scnint(in,&unitype) + || !scnflt(in,&width) || !scnflt(in,&length) + || !scnflt(in,&height) || !scnflt(in,&bfactor) + || !scnflt(in,&pfactor) || !scnflt(in,&wattage)) { fprintf(stderr, "dosource: bad lamp specification\n"); return(-1); } @@ -551,7 +547,7 @@ char *mod, *name; perror(buf); return(-1); } - if (cvdata(in, datout, 2, nangles, 1./683., bounds) != 0) { + if (cvdata(in, datout, 2, nangles, 1./WHTEFFICACY, bounds) != 0) { fprintf(stderr, "dosource: bad distribution data\n"); fclose(datout); unlink(fullname(buf,name,T_DST)); @@ -619,7 +615,7 @@ int dolower, doupper; lampcolor[2]/shp->area); if (doupper && dolower && shp->type != SPHERE && shp->h > MINDIM) { fprintf(fp, "\n%s glow %s_glow\n", mod, name); - fprintf(fp, "0\n0\n4 %g %g %g 0\n", + fprintf(fp, "0\n0\n4 %g %g %g -1\n", lampcolor[0]/shp->area, lampcolor[1]/shp->area, lampcolor[2]/shp->area); @@ -807,7 +803,7 @@ FILE *in, *out; int ndim, npts[]; double mult, lim[][2]; { - register double *pt[4]; + double *pt[4]; register int i, j; double val; int total; @@ -823,7 +819,8 @@ double mult, lim[][2]; for (i = 0; i < ndim; i++) { pt[i] = (double *)malloc(npts[i]*sizeof(double)); for (j = 0; j < npts[i]; j++) - fscanf(in, "%lf", &pt[i][j]); + if (!scnflt(in, &pt[i][j])) + return(-1); if (lim != NULL) { lim[i][0] = pt[i][0]; lim[i][1] = pt[i][npts[i]-1]; @@ -854,10 +851,57 @@ double mult, lim[][2]; for (i = 0; i < total; i++) { if (i%4 == 0) putc('\n', out); - if (fscanf(in, "%lf", &val) != 1) + if (!scnflt(in, &val)) return(-1); fprintf(out, "\t%g", val*mult); } putc('\n', out); return(0); +} + + +char * +getword(fp) /* scan a word from fp */ +register FILE *fp; +{ + static char word[MAXWORD]; + register char *cp; + register int c; + + while (isspace(c=getc(fp))) + ; + for (cp = word; c != EOF && cp < word+MAXWORD-1; + *cp++ = c, c = getc(fp)) + if (isspace(c) || c == ',') { + while (isspace(c)) + c = getc(fp); + if (c != EOF & c != ',') + ungetc(c, fp); + *cp = '\0'; + return(word); + } + *cp = '\0'; + return(cp > word ? word : NULL); +} + + +cvtint(ip, word) /* convert a word to an integer */ +int *ip; +char *word; +{ + if (word == NULL || !isint(word)) + return(0); + *ip = atoi(word); + return(1); +} + + +cvtflt(rp, word) /* convert a word to a double */ +double *rp; +char *word; +{ + if (word == NULL || !isflt(word)) + return(0); + *rp = atof(word); + return(1); }