1 |
< |
/* Copyright (c) 1990 Regents of the University of California */ |
1 |
> |
/* Copyright (c) 1992 Regents of the University of California */ |
2 |
|
|
3 |
|
#ifndef lint |
4 |
|
static char SCCSid[] = "$SunId$ LBL"; |
13 |
|
#include <stdio.h> |
14 |
|
#include <ctype.h> |
15 |
|
#include "color.h" |
16 |
+ |
#include "paths.h" |
17 |
|
|
18 |
|
#define PI 3.14159265358979323846 |
19 |
|
/* floating comparisons */ |
36 |
|
/* string lengths */ |
37 |
|
#define MAXLINE 132 |
38 |
|
#define MAXWORD 76 |
38 |
– |
#define MAXPATH 128 |
39 |
|
/* file types */ |
40 |
|
#define T_RAD ".rad" |
41 |
|
#define T_DST ".dat" |
49 |
|
|
50 |
|
#define F_M .3048 /* feet to meters */ |
51 |
|
|
52 |
< |
#define abspath(p) ((p)[0] == '/' || (p)[0] == '.') |
52 |
> |
#define abspath(p) (ISDIRSEP((p)[0]) || (p)[0] == '.') |
53 |
|
|
54 |
|
static char default_name[] = "default"; |
55 |
|
|
64 |
|
float *lampcolor = defcolor; /* pointer to current lamp color */ |
65 |
|
double multiplier = 1.0; /* multiplier for all light sources */ |
66 |
|
char units[64] = "meters"; /* output units */ |
67 |
– |
double minaspect = 0.0; /* minimum allowed aspect ratio */ |
68 |
– |
int maxemitters = 1; /* maximum emitters per hemisphere */ |
67 |
|
double illumrad = 0.0; /* radius for illum sphere */ |
68 |
|
|
69 |
|
typedef struct { |
76 |
|
char **gargv; /* global argv */ |
77 |
|
|
78 |
|
extern char *strcpy(), *strcat(), *stradd(), *tailtrunc(), *filetrunc(), |
79 |
< |
*filename(), *libname(), *fullname(), *malloc(); |
79 |
> |
*filename(), *libname(), *fullname(), *malloc(), |
80 |
> |
*getword(), *atos(); |
81 |
|
extern float *matchlamp(); |
82 |
|
|
83 |
+ |
#define scnint(fp,ip) cvtint(ip,getword(fp)) |
84 |
+ |
#define scnflt(fp,rp) cvtflt(rp,getword(fp)) |
85 |
+ |
#define isint isflt /* IES allows real as integer */ |
86 |
|
|
87 |
+ |
|
88 |
|
main(argc, argv) |
89 |
|
int argc; |
90 |
|
char *argv[]; |
159 |
|
case 'o': /* output file name */ |
160 |
|
outfile = argv[++i]; |
161 |
|
break; |
159 |
– |
case 's': /* square emitters */ |
160 |
– |
minaspect = .6; |
161 |
– |
if (argv[i][2] == '/') { |
162 |
– |
maxemitters = atoi(argv[i]+3); |
163 |
– |
if (maxemitters < 1) |
164 |
– |
goto badopt; |
165 |
– |
} |
166 |
– |
break; |
162 |
|
case 'i': /* illum */ |
163 |
|
illumrad = atof(argv[++i]); |
164 |
|
if (illumrad < MINDIM) |
279 |
|
else if (abspath(fname)) |
280 |
|
strcpy(stradd(path, fname, 0), suffix); |
281 |
|
else |
282 |
< |
libname(stradd(path, libdir, '/'), fname, suffix); |
282 |
> |
libname(stradd(path, libdir, DIRSEP), fname, suffix); |
283 |
|
|
284 |
|
return(path); |
285 |
|
} |
292 |
|
if (abspath(fname)) |
293 |
|
strcpy(stradd(path, fname, 0), suffix); |
294 |
|
else |
295 |
< |
strcpy(stradd(stradd(path, prefdir, '/'), fname, 0), suffix); |
295 |
> |
strcpy(stradd(stradd(path, prefdir, DIRSEP), fname, 0), suffix); |
296 |
|
|
297 |
|
return(path); |
298 |
|
} |
305 |
|
register char *cp; |
306 |
|
|
307 |
|
for (cp = path; *path; path++) |
308 |
< |
if (*path == '/') |
308 |
> |
if (ISDIRSEP(*path)) |
309 |
|
cp = path+1; |
310 |
|
return(cp); |
311 |
|
} |
318 |
|
register char *p1, *p2; |
319 |
|
|
320 |
|
for (p1 = p2 = path; *p2; p2++) |
321 |
< |
if (*p2 == '/') |
321 |
> |
if (ISDIRSEP(*p2)) |
322 |
|
p1 = p2; |
323 |
|
*p1 = '\0'; |
324 |
|
return(path); |
412 |
|
fprintf(stderr, "%s: not in IES format\n", inpname); |
413 |
|
goto readerr; |
414 |
|
} |
415 |
< |
sscanf(buf+TLTSTRLEN, "%s", tltid); |
415 |
> |
atos(tltid, MAXWORD, buf+TLTSTRLEN); |
416 |
|
if (inpfp == stdin) |
417 |
|
buf[0] = '\0'; |
418 |
|
else |
452 |
|
datin = in; |
453 |
|
strcpy(tltname, dfltname); |
454 |
|
} else { |
455 |
< |
if (tltspec[0] == '/') |
455 |
> |
if (ISDIRSEP(tltspec[0])) |
456 |
|
strcpy(buf, tltspec); |
457 |
|
else |
458 |
< |
strcpy(stradd(buf, dir, '/'), tltspec); |
458 |
> |
strcpy(stradd(buf, dir, DIRSEP), tltspec); |
459 |
|
if ((datin = fopen(buf, "r")) == NULL) { |
460 |
|
perror(buf); |
461 |
|
return(-1); |
469 |
|
fclose(datin); |
470 |
|
return(-1); |
471 |
|
} |
472 |
< |
if (fscanf(datin, "%d %d", &tlt_type, &nangles) != 2 |
472 |
> |
if (!scnint(datin,&tlt_type) || !scnint(datin,&nangles) |
473 |
|
|| cvdata(datin,datout,1,&nangles,1.,minmax) != 0) { |
474 |
|
fprintf(stderr, "%s: data format error\n", tltspec); |
475 |
|
fclose(datout); |
521 |
|
int nangles[2], pmtype, unitype; |
522 |
|
double d1; |
523 |
|
|
524 |
< |
if (fscanf(in, "%*d %*f %lf %d %d %d %d %lf %lf %lf %lf %lf %lf", |
525 |
< |
&mult, &nangles[0], &nangles[1], &pmtype, &unitype, |
526 |
< |
&width, &length, &height, &bfactor, &pfactor, |
527 |
< |
&wattage) != 11) { |
524 |
> |
if (!isint(getword(in)) || !isflt(getword(in)) || !scnflt(in,&mult) |
525 |
> |
|| !scnint(in,&nangles[0]) || !scnint(in,&nangles[1]) |
526 |
> |
|| !scnint(in,&pmtype) || !scnint(in,&unitype) |
527 |
> |
|| !scnflt(in,&width) || !scnflt(in,&length) |
528 |
> |
|| !scnflt(in,&height) || !scnflt(in,&bfactor) |
529 |
> |
|| !scnflt(in,&pfactor) || !scnflt(in,&wattage)) { |
530 |
|
fprintf(stderr, "dosource: bad lamp specification\n"); |
531 |
|
return(-1); |
532 |
|
} |
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 0\n", |
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); |
819 |
|
for (i = 0; i < ndim; i++) { |
820 |
|
pt[i] = (double *)malloc(npts[i]*sizeof(double)); |
821 |
|
for (j = 0; j < npts[i]; j++) |
822 |
< |
fscanf(in, "%lf", &pt[i][j]); |
822 |
> |
if (!scnflt(in, &pt[i][j])) |
823 |
> |
return(-1); |
824 |
|
if (lim != NULL) { |
825 |
|
lim[i][0] = pt[i][0]; |
826 |
|
lim[i][1] = pt[i][npts[i]-1]; |
851 |
|
for (i = 0; i < total; i++) { |
852 |
|
if (i%4 == 0) |
853 |
|
putc('\n', out); |
854 |
< |
if (fscanf(in, "%lf", &val) != 1) |
854 |
> |
if (!scnflt(in, &val)) |
855 |
|
return(-1); |
856 |
|
fprintf(out, "\t%g", val*mult); |
857 |
|
} |
858 |
|
putc('\n', out); |
859 |
|
return(0); |
860 |
+ |
} |
861 |
+ |
|
862 |
+ |
|
863 |
+ |
char * |
864 |
+ |
getword(fp) /* scan a word from fp */ |
865 |
+ |
register FILE *fp; |
866 |
+ |
{ |
867 |
+ |
static char word[MAXWORD]; |
868 |
+ |
register char *cp; |
869 |
+ |
register int c; |
870 |
+ |
|
871 |
+ |
while (isspace(c=getc(fp))) |
872 |
+ |
; |
873 |
+ |
for (cp = word; c != EOF && cp < word+MAXWORD-1; |
874 |
+ |
*cp++ = c, c = getc(fp)) |
875 |
+ |
if (isspace(c) || c == ',') { |
876 |
+ |
while (isspace(c)) |
877 |
+ |
c = getc(fp); |
878 |
+ |
if (c != EOF & c != ',') |
879 |
+ |
ungetc(c, fp); |
880 |
+ |
*cp = '\0'; |
881 |
+ |
return(word); |
882 |
+ |
} |
883 |
+ |
*cp = '\0'; |
884 |
+ |
return(cp > word ? word : NULL); |
885 |
+ |
} |
886 |
+ |
|
887 |
+ |
|
888 |
+ |
cvtint(ip, word) /* convert a word to an integer */ |
889 |
+ |
int *ip; |
890 |
+ |
char *word; |
891 |
+ |
{ |
892 |
+ |
if (word == NULL || !isint(word)) |
893 |
+ |
return(0); |
894 |
+ |
*ip = atoi(word); |
895 |
+ |
return(1); |
896 |
+ |
} |
897 |
+ |
|
898 |
+ |
|
899 |
+ |
cvtflt(rp, word) /* convert a word to a double */ |
900 |
+ |
double *rp; |
901 |
+ |
char *word; |
902 |
+ |
{ |
903 |
+ |
if (word == NULL || !isflt(word)) |
904 |
+ |
return(0); |
905 |
+ |
*rp = atof(word); |
906 |
+ |
return(1); |
907 |
|
} |